]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.13.8-201404031157.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.8-201404031157.patch
CommitLineData
29df678a
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 4cab13b..b7d5e41 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..b6b4b38 100644
12504--- a/arch/x86/boot/compressed/misc.c
12505+++ b/arch/x86/boot/compressed/misc.c
12506@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12507 * Calculate the delta between where vmlinux was linked to load
12508 * and where it was actually loaded.
12509 */
12510- delta = min_addr - LOAD_PHYSICAL_ADDR;
12511+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12512 if (!delta) {
12513 debug_putstr("No relocation needed... ");
12514 return;
12515@@ -380,7 +380,7 @@ static void parse_elf(void *output)
12516 case PT_LOAD:
12517 #ifdef CONFIG_RELOCATABLE
12518 dest = output;
12519- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12520+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12521 #else
12522 dest = (void *)(phdr->p_paddr);
12523 #endif
12524@@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12525 error("Destination address too large");
12526 #endif
12527 #ifndef CONFIG_RELOCATABLE
12528- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12529+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12530 error("Wrong destination address");
12531 #endif
12532
12533diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12534index 4d3ff03..e4972ff 100644
12535--- a/arch/x86/boot/cpucheck.c
12536+++ b/arch/x86/boot/cpucheck.c
12537@@ -74,7 +74,7 @@ static int has_fpu(void)
12538 u16 fcw = -1, fsw = -1;
12539 u32 cr0;
12540
12541- asm("movl %%cr0,%0" : "=r" (cr0));
12542+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12543 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12544 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12545 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12546@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12547 {
12548 u32 f0, f1;
12549
12550- asm("pushfl ; "
12551+ asm volatile("pushfl ; "
12552 "pushfl ; "
12553 "popl %0 ; "
12554 "movl %0,%1 ; "
12555@@ -115,7 +115,7 @@ static void get_flags(void)
12556 set_bit(X86_FEATURE_FPU, cpu.flags);
12557
12558 if (has_eflag(X86_EFLAGS_ID)) {
12559- asm("cpuid"
12560+ asm volatile("cpuid"
12561 : "=a" (max_intel_level),
12562 "=b" (cpu_vendor[0]),
12563 "=d" (cpu_vendor[1]),
12564@@ -124,7 +124,7 @@ static void get_flags(void)
12565
12566 if (max_intel_level >= 0x00000001 &&
12567 max_intel_level <= 0x0000ffff) {
12568- asm("cpuid"
12569+ asm volatile("cpuid"
12570 : "=a" (tfms),
12571 "=c" (cpu.flags[4]),
12572 "=d" (cpu.flags[0])
12573@@ -136,7 +136,7 @@ static void get_flags(void)
12574 cpu.model += ((tfms >> 16) & 0xf) << 4;
12575 }
12576
12577- asm("cpuid"
12578+ asm volatile("cpuid"
12579 : "=a" (max_amd_level)
12580 : "a" (0x80000000)
12581 : "ebx", "ecx", "edx");
12582@@ -144,7 +144,7 @@ static void get_flags(void)
12583 if (max_amd_level >= 0x80000001 &&
12584 max_amd_level <= 0x8000ffff) {
12585 u32 eax = 0x80000001;
12586- asm("cpuid"
12587+ asm volatile("cpuid"
12588 : "+a" (eax),
12589 "=c" (cpu.flags[6]),
12590 "=d" (cpu.flags[1])
12591@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12592 u32 ecx = MSR_K7_HWCR;
12593 u32 eax, edx;
12594
12595- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12596+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12597 eax &= ~(1 << 15);
12598- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12599+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12600
12601 get_flags(); /* Make sure it really did something */
12602 err = check_flags();
12603@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12604 u32 ecx = MSR_VIA_FCR;
12605 u32 eax, edx;
12606
12607- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12608+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12609 eax |= (1<<1)|(1<<7);
12610- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12611+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12612
12613 set_bit(X86_FEATURE_CX8, cpu.flags);
12614 err = check_flags();
12615@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12616 u32 eax, edx;
12617 u32 level = 1;
12618
12619- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12620- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12621- asm("cpuid"
12622+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12623+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12624+ asm volatile("cpuid"
12625 : "+a" (level), "=d" (cpu.flags[0])
12626 : : "ecx", "ebx");
12627- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12628+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12629
12630 err = check_flags();
12631 }
12632diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12633index 9ec06a1..2c25e79 100644
12634--- a/arch/x86/boot/header.S
12635+++ b/arch/x86/boot/header.S
12636@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12637 # single linked list of
12638 # struct setup_data
12639
12640-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12641+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12642
12643 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12644+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12645+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12646+#else
12647 #define VO_INIT_SIZE (VO__end - VO__text)
12648+#endif
12649 #if ZO_INIT_SIZE > VO_INIT_SIZE
12650 #define INIT_SIZE ZO_INIT_SIZE
12651 #else
12652diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12653index db75d07..8e6d0af 100644
12654--- a/arch/x86/boot/memory.c
12655+++ b/arch/x86/boot/memory.c
12656@@ -19,7 +19,7 @@
12657
12658 static int detect_memory_e820(void)
12659 {
12660- int count = 0;
12661+ unsigned int count = 0;
12662 struct biosregs ireg, oreg;
12663 struct e820entry *desc = boot_params.e820_map;
12664 static struct e820entry buf; /* static so it is zeroed */
12665diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12666index 11e8c6e..fdbb1ed 100644
12667--- a/arch/x86/boot/video-vesa.c
12668+++ b/arch/x86/boot/video-vesa.c
12669@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12670
12671 boot_params.screen_info.vesapm_seg = oreg.es;
12672 boot_params.screen_info.vesapm_off = oreg.di;
12673+ boot_params.screen_info.vesapm_size = oreg.cx;
12674 }
12675
12676 /*
12677diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12678index 43eda28..5ab5fdb 100644
12679--- a/arch/x86/boot/video.c
12680+++ b/arch/x86/boot/video.c
12681@@ -96,7 +96,7 @@ static void store_mode_params(void)
12682 static unsigned int get_entry(void)
12683 {
12684 char entry_buf[4];
12685- int i, len = 0;
12686+ unsigned int i, len = 0;
12687 int key;
12688 unsigned int v;
12689
12690diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12691index 9105655..41779c1 100644
12692--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12693+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12694@@ -8,6 +8,8 @@
12695 * including this sentence is retained in full.
12696 */
12697
12698+#include <asm/alternative-asm.h>
12699+
12700 .extern crypto_ft_tab
12701 .extern crypto_it_tab
12702 .extern crypto_fl_tab
12703@@ -70,6 +72,8 @@
12704 je B192; \
12705 leaq 32(r9),r9;
12706
12707+#define ret pax_force_retaddr; ret
12708+
12709 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12710 movq r1,r2; \
12711 movq r3,r4; \
12712diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12713index 477e9d7..c92c7d8 100644
12714--- a/arch/x86/crypto/aesni-intel_asm.S
12715+++ b/arch/x86/crypto/aesni-intel_asm.S
12716@@ -31,6 +31,7 @@
12717
12718 #include <linux/linkage.h>
12719 #include <asm/inst.h>
12720+#include <asm/alternative-asm.h>
12721
12722 #ifdef __x86_64__
12723 .data
12724@@ -205,7 +206,7 @@ enc: .octa 0x2
12725 * num_initial_blocks = b mod 4
12726 * encrypt the initial num_initial_blocks blocks and apply ghash on
12727 * the ciphertext
12728-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12729+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12730 * are clobbered
12731 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12732 */
12733@@ -214,8 +215,8 @@ enc: .octa 0x2
12734 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12735 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12736 mov arg7, %r10 # %r10 = AAD
12737- mov arg8, %r12 # %r12 = aadLen
12738- mov %r12, %r11
12739+ mov arg8, %r15 # %r15 = aadLen
12740+ mov %r15, %r11
12741 pxor %xmm\i, %xmm\i
12742 _get_AAD_loop\num_initial_blocks\operation:
12743 movd (%r10), \TMP1
12744@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12745 psrldq $4, %xmm\i
12746 pxor \TMP1, %xmm\i
12747 add $4, %r10
12748- sub $4, %r12
12749+ sub $4, %r15
12750 jne _get_AAD_loop\num_initial_blocks\operation
12751 cmp $16, %r11
12752 je _get_AAD_loop2_done\num_initial_blocks\operation
12753- mov $16, %r12
12754+ mov $16, %r15
12755 _get_AAD_loop2\num_initial_blocks\operation:
12756 psrldq $4, %xmm\i
12757- sub $4, %r12
12758- cmp %r11, %r12
12759+ sub $4, %r15
12760+ cmp %r11, %r15
12761 jne _get_AAD_loop2\num_initial_blocks\operation
12762 _get_AAD_loop2_done\num_initial_blocks\operation:
12763 movdqa SHUF_MASK(%rip), %xmm14
12764@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12765 * num_initial_blocks = b mod 4
12766 * encrypt the initial num_initial_blocks blocks and apply ghash on
12767 * the ciphertext
12768-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12769+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12770 * are clobbered
12771 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12772 */
12773@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12774 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12775 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12776 mov arg7, %r10 # %r10 = AAD
12777- mov arg8, %r12 # %r12 = aadLen
12778- mov %r12, %r11
12779+ mov arg8, %r15 # %r15 = aadLen
12780+ mov %r15, %r11
12781 pxor %xmm\i, %xmm\i
12782 _get_AAD_loop\num_initial_blocks\operation:
12783 movd (%r10), \TMP1
12784@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12785 psrldq $4, %xmm\i
12786 pxor \TMP1, %xmm\i
12787 add $4, %r10
12788- sub $4, %r12
12789+ sub $4, %r15
12790 jne _get_AAD_loop\num_initial_blocks\operation
12791 cmp $16, %r11
12792 je _get_AAD_loop2_done\num_initial_blocks\operation
12793- mov $16, %r12
12794+ mov $16, %r15
12795 _get_AAD_loop2\num_initial_blocks\operation:
12796 psrldq $4, %xmm\i
12797- sub $4, %r12
12798- cmp %r11, %r12
12799+ sub $4, %r15
12800+ cmp %r11, %r15
12801 jne _get_AAD_loop2\num_initial_blocks\operation
12802 _get_AAD_loop2_done\num_initial_blocks\operation:
12803 movdqa SHUF_MASK(%rip), %xmm14
12804@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12805 *
12806 *****************************************************************************/
12807 ENTRY(aesni_gcm_dec)
12808- push %r12
12809+ push %r15
12810 push %r13
12811 push %r14
12812 mov %rsp, %r14
12813@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12814 */
12815 sub $VARIABLE_OFFSET, %rsp
12816 and $~63, %rsp # align rsp to 64 bytes
12817- mov %arg6, %r12
12818- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12819+ mov %arg6, %r15
12820+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12821 movdqa SHUF_MASK(%rip), %xmm2
12822 PSHUFB_XMM %xmm2, %xmm13
12823
12824@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12825 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12826 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12827 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12828- mov %r13, %r12
12829- and $(3<<4), %r12
12830+ mov %r13, %r15
12831+ and $(3<<4), %r15
12832 jz _initial_num_blocks_is_0_decrypt
12833- cmp $(2<<4), %r12
12834+ cmp $(2<<4), %r15
12835 jb _initial_num_blocks_is_1_decrypt
12836 je _initial_num_blocks_is_2_decrypt
12837 _initial_num_blocks_is_3_decrypt:
12838@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12839 sub $16, %r11
12840 add %r13, %r11
12841 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12842- lea SHIFT_MASK+16(%rip), %r12
12843- sub %r13, %r12
12844+ lea SHIFT_MASK+16(%rip), %r15
12845+ sub %r13, %r15
12846 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12847 # (%r13 is the number of bytes in plaintext mod 16)
12848- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12849+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12850 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12851
12852 movdqa %xmm1, %xmm2
12853 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12854- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12855+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12856 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12857 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12858 pand %xmm1, %xmm2
12859@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12860 sub $1, %r13
12861 jne _less_than_8_bytes_left_decrypt
12862 _multiple_of_16_bytes_decrypt:
12863- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12864- shl $3, %r12 # convert into number of bits
12865- movd %r12d, %xmm15 # len(A) in %xmm15
12866+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12867+ shl $3, %r15 # convert into number of bits
12868+ movd %r15d, %xmm15 # len(A) in %xmm15
12869 shl $3, %arg4 # len(C) in bits (*128)
12870 MOVQ_R64_XMM %arg4, %xmm1
12871 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12872@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12873 mov %r14, %rsp
12874 pop %r14
12875 pop %r13
12876- pop %r12
12877+ pop %r15
12878+ pax_force_retaddr
12879 ret
12880 ENDPROC(aesni_gcm_dec)
12881
12882@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12883 * poly = x^128 + x^127 + x^126 + x^121 + 1
12884 ***************************************************************************/
12885 ENTRY(aesni_gcm_enc)
12886- push %r12
12887+ push %r15
12888 push %r13
12889 push %r14
12890 mov %rsp, %r14
12891@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12892 #
12893 sub $VARIABLE_OFFSET, %rsp
12894 and $~63, %rsp
12895- mov %arg6, %r12
12896- movdqu (%r12), %xmm13
12897+ mov %arg6, %r15
12898+ movdqu (%r15), %xmm13
12899 movdqa SHUF_MASK(%rip), %xmm2
12900 PSHUFB_XMM %xmm2, %xmm13
12901
12902@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12903 movdqa %xmm13, HashKey(%rsp)
12904 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12905 and $-16, %r13
12906- mov %r13, %r12
12907+ mov %r13, %r15
12908
12909 # Encrypt first few blocks
12910
12911- and $(3<<4), %r12
12912+ and $(3<<4), %r15
12913 jz _initial_num_blocks_is_0_encrypt
12914- cmp $(2<<4), %r12
12915+ cmp $(2<<4), %r15
12916 jb _initial_num_blocks_is_1_encrypt
12917 je _initial_num_blocks_is_2_encrypt
12918 _initial_num_blocks_is_3_encrypt:
12919@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12920 sub $16, %r11
12921 add %r13, %r11
12922 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12923- lea SHIFT_MASK+16(%rip), %r12
12924- sub %r13, %r12
12925+ lea SHIFT_MASK+16(%rip), %r15
12926+ sub %r13, %r15
12927 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12928 # (%r13 is the number of bytes in plaintext mod 16)
12929- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12930+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12931 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12932 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12933- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12934+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12935 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12936 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12937 movdqa SHUF_MASK(%rip), %xmm10
12938@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12939 sub $1, %r13
12940 jne _less_than_8_bytes_left_encrypt
12941 _multiple_of_16_bytes_encrypt:
12942- mov arg8, %r12 # %r12 = addLen (number of bytes)
12943- shl $3, %r12
12944- movd %r12d, %xmm15 # len(A) in %xmm15
12945+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12946+ shl $3, %r15
12947+ movd %r15d, %xmm15 # len(A) in %xmm15
12948 shl $3, %arg4 # len(C) in bits (*128)
12949 MOVQ_R64_XMM %arg4, %xmm1
12950 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12951@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12952 mov %r14, %rsp
12953 pop %r14
12954 pop %r13
12955- pop %r12
12956+ pop %r15
12957+ pax_force_retaddr
12958 ret
12959 ENDPROC(aesni_gcm_enc)
12960
12961@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12962 pxor %xmm1, %xmm0
12963 movaps %xmm0, (TKEYP)
12964 add $0x10, TKEYP
12965+ pax_force_retaddr
12966 ret
12967 ENDPROC(_key_expansion_128)
12968 ENDPROC(_key_expansion_256a)
12969@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12970 shufps $0b01001110, %xmm2, %xmm1
12971 movaps %xmm1, 0x10(TKEYP)
12972 add $0x20, TKEYP
12973+ pax_force_retaddr
12974 ret
12975 ENDPROC(_key_expansion_192a)
12976
12977@@ -1768,6 +1773,7 @@ _key_expansion_192b:
12978
12979 movaps %xmm0, (TKEYP)
12980 add $0x10, TKEYP
12981+ pax_force_retaddr
12982 ret
12983 ENDPROC(_key_expansion_192b)
12984
12985@@ -1781,6 +1787,7 @@ _key_expansion_256b:
12986 pxor %xmm1, %xmm2
12987 movaps %xmm2, (TKEYP)
12988 add $0x10, TKEYP
12989+ pax_force_retaddr
12990 ret
12991 ENDPROC(_key_expansion_256b)
12992
12993@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12994 #ifndef __x86_64__
12995 popl KEYP
12996 #endif
12997+ pax_force_retaddr
12998 ret
12999 ENDPROC(aesni_set_key)
13000
13001@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13002 popl KLEN
13003 popl KEYP
13004 #endif
13005+ pax_force_retaddr
13006 ret
13007 ENDPROC(aesni_enc)
13008
13009@@ -1974,6 +1983,7 @@ _aesni_enc1:
13010 AESENC KEY STATE
13011 movaps 0x70(TKEYP), KEY
13012 AESENCLAST KEY STATE
13013+ pax_force_retaddr
13014 ret
13015 ENDPROC(_aesni_enc1)
13016
13017@@ -2083,6 +2093,7 @@ _aesni_enc4:
13018 AESENCLAST KEY STATE2
13019 AESENCLAST KEY STATE3
13020 AESENCLAST KEY STATE4
13021+ pax_force_retaddr
13022 ret
13023 ENDPROC(_aesni_enc4)
13024
13025@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13026 popl KLEN
13027 popl KEYP
13028 #endif
13029+ pax_force_retaddr
13030 ret
13031 ENDPROC(aesni_dec)
13032
13033@@ -2164,6 +2176,7 @@ _aesni_dec1:
13034 AESDEC KEY STATE
13035 movaps 0x70(TKEYP), KEY
13036 AESDECLAST KEY STATE
13037+ pax_force_retaddr
13038 ret
13039 ENDPROC(_aesni_dec1)
13040
13041@@ -2273,6 +2286,7 @@ _aesni_dec4:
13042 AESDECLAST KEY STATE2
13043 AESDECLAST KEY STATE3
13044 AESDECLAST KEY STATE4
13045+ pax_force_retaddr
13046 ret
13047 ENDPROC(_aesni_dec4)
13048
13049@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13050 popl KEYP
13051 popl LEN
13052 #endif
13053+ pax_force_retaddr
13054 ret
13055 ENDPROC(aesni_ecb_enc)
13056
13057@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13058 popl KEYP
13059 popl LEN
13060 #endif
13061+ pax_force_retaddr
13062 ret
13063 ENDPROC(aesni_ecb_dec)
13064
13065@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13066 popl LEN
13067 popl IVP
13068 #endif
13069+ pax_force_retaddr
13070 ret
13071 ENDPROC(aesni_cbc_enc)
13072
13073@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13074 popl LEN
13075 popl IVP
13076 #endif
13077+ pax_force_retaddr
13078 ret
13079 ENDPROC(aesni_cbc_dec)
13080
13081@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13082 mov $1, TCTR_LOW
13083 MOVQ_R64_XMM TCTR_LOW INC
13084 MOVQ_R64_XMM CTR TCTR_LOW
13085+ pax_force_retaddr
13086 ret
13087 ENDPROC(_aesni_inc_init)
13088
13089@@ -2579,6 +2598,7 @@ _aesni_inc:
13090 .Linc_low:
13091 movaps CTR, IV
13092 PSHUFB_XMM BSWAP_MASK IV
13093+ pax_force_retaddr
13094 ret
13095 ENDPROC(_aesni_inc)
13096
13097@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13098 .Lctr_enc_ret:
13099 movups IV, (IVP)
13100 .Lctr_enc_just_ret:
13101+ pax_force_retaddr
13102 ret
13103 ENDPROC(aesni_ctr_enc)
13104
13105@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13106 pxor INC, STATE4
13107 movdqu STATE4, 0x70(OUTP)
13108
13109+ pax_force_retaddr
13110 ret
13111 ENDPROC(aesni_xts_crypt8)
13112
13113diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13114index 246c670..466e2d6 100644
13115--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13116+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13117@@ -21,6 +21,7 @@
13118 */
13119
13120 #include <linux/linkage.h>
13121+#include <asm/alternative-asm.h>
13122
13123 .file "blowfish-x86_64-asm.S"
13124 .text
13125@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13126 jnz .L__enc_xor;
13127
13128 write_block();
13129+ pax_force_retaddr
13130 ret;
13131 .L__enc_xor:
13132 xor_block();
13133+ pax_force_retaddr
13134 ret;
13135 ENDPROC(__blowfish_enc_blk)
13136
13137@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13138
13139 movq %r11, %rbp;
13140
13141+ pax_force_retaddr
13142 ret;
13143 ENDPROC(blowfish_dec_blk)
13144
13145@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13146
13147 popq %rbx;
13148 popq %rbp;
13149+ pax_force_retaddr
13150 ret;
13151
13152 .L__enc_xor4:
13153@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13154
13155 popq %rbx;
13156 popq %rbp;
13157+ pax_force_retaddr
13158 ret;
13159 ENDPROC(__blowfish_enc_blk_4way)
13160
13161@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13162 popq %rbx;
13163 popq %rbp;
13164
13165+ pax_force_retaddr
13166 ret;
13167 ENDPROC(blowfish_dec_blk_4way)
13168diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13169index ce71f92..1dce7ec 100644
13170--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13171+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13172@@ -16,6 +16,7 @@
13173 */
13174
13175 #include <linux/linkage.h>
13176+#include <asm/alternative-asm.h>
13177
13178 #define CAMELLIA_TABLE_BYTE_LEN 272
13179
13180@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13181 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13182 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13183 %rcx, (%r9));
13184+ pax_force_retaddr
13185 ret;
13186 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13187
13188@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13189 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13190 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13191 %rax, (%r9));
13192+ pax_force_retaddr
13193 ret;
13194 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13195
13196@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13197 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13198 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13199
13200+ pax_force_retaddr
13201 ret;
13202
13203 .align 8
13204@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13205 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13206 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13207
13208+ pax_force_retaddr
13209 ret;
13210
13211 .align 8
13212@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13213 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13214 %xmm8, %rsi);
13215
13216+ pax_force_retaddr
13217 ret;
13218 ENDPROC(camellia_ecb_enc_16way)
13219
13220@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13221 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13222 %xmm8, %rsi);
13223
13224+ pax_force_retaddr
13225 ret;
13226 ENDPROC(camellia_ecb_dec_16way)
13227
13228@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13229 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13230 %xmm8, %rsi);
13231
13232+ pax_force_retaddr
13233 ret;
13234 ENDPROC(camellia_cbc_dec_16way)
13235
13236@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13237 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13238 %xmm8, %rsi);
13239
13240+ pax_force_retaddr
13241 ret;
13242 ENDPROC(camellia_ctr_16way)
13243
13244@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13245 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13246 %xmm8, %rsi);
13247
13248+ pax_force_retaddr
13249 ret;
13250 ENDPROC(camellia_xts_crypt_16way)
13251
13252diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13253index 0e0b886..5a3123c 100644
13254--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13255+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13256@@ -11,6 +11,7 @@
13257 */
13258
13259 #include <linux/linkage.h>
13260+#include <asm/alternative-asm.h>
13261
13262 #define CAMELLIA_TABLE_BYTE_LEN 272
13263
13264@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13265 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13266 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13267 %rcx, (%r9));
13268+ pax_force_retaddr
13269 ret;
13270 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13271
13272@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13273 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13274 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13275 %rax, (%r9));
13276+ pax_force_retaddr
13277 ret;
13278 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13279
13280@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13281 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13282 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13283
13284+ pax_force_retaddr
13285 ret;
13286
13287 .align 8
13288@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13289 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13290 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13291
13292+ pax_force_retaddr
13293 ret;
13294
13295 .align 8
13296@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13297
13298 vzeroupper;
13299
13300+ pax_force_retaddr
13301 ret;
13302 ENDPROC(camellia_ecb_enc_32way)
13303
13304@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13305
13306 vzeroupper;
13307
13308+ pax_force_retaddr
13309 ret;
13310 ENDPROC(camellia_ecb_dec_32way)
13311
13312@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13313
13314 vzeroupper;
13315
13316+ pax_force_retaddr
13317 ret;
13318 ENDPROC(camellia_cbc_dec_32way)
13319
13320@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13321
13322 vzeroupper;
13323
13324+ pax_force_retaddr
13325 ret;
13326 ENDPROC(camellia_ctr_32way)
13327
13328@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13329
13330 vzeroupper;
13331
13332+ pax_force_retaddr
13333 ret;
13334 ENDPROC(camellia_xts_crypt_32way)
13335
13336diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13337index 310319c..db3d7b5 100644
13338--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13339+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13340@@ -21,6 +21,7 @@
13341 */
13342
13343 #include <linux/linkage.h>
13344+#include <asm/alternative-asm.h>
13345
13346 .file "camellia-x86_64-asm_64.S"
13347 .text
13348@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13349 enc_outunpack(mov, RT1);
13350
13351 movq RRBP, %rbp;
13352+ pax_force_retaddr
13353 ret;
13354
13355 .L__enc_xor:
13356 enc_outunpack(xor, RT1);
13357
13358 movq RRBP, %rbp;
13359+ pax_force_retaddr
13360 ret;
13361 ENDPROC(__camellia_enc_blk)
13362
13363@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13364 dec_outunpack();
13365
13366 movq RRBP, %rbp;
13367+ pax_force_retaddr
13368 ret;
13369 ENDPROC(camellia_dec_blk)
13370
13371@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13372
13373 movq RRBP, %rbp;
13374 popq %rbx;
13375+ pax_force_retaddr
13376 ret;
13377
13378 .L__enc2_xor:
13379@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13380
13381 movq RRBP, %rbp;
13382 popq %rbx;
13383+ pax_force_retaddr
13384 ret;
13385 ENDPROC(__camellia_enc_blk_2way)
13386
13387@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13388
13389 movq RRBP, %rbp;
13390 movq RXOR, %rbx;
13391+ pax_force_retaddr
13392 ret;
13393 ENDPROC(camellia_dec_blk_2way)
13394diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13395index c35fd5d..2d8c7db 100644
13396--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13397+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13398@@ -24,6 +24,7 @@
13399 */
13400
13401 #include <linux/linkage.h>
13402+#include <asm/alternative-asm.h>
13403
13404 .file "cast5-avx-x86_64-asm_64.S"
13405
13406@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13407 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13408 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13409
13410+ pax_force_retaddr
13411 ret;
13412 ENDPROC(__cast5_enc_blk16)
13413
13414@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13415 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13416 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13417
13418+ pax_force_retaddr
13419 ret;
13420
13421 .L__skip_dec:
13422@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13423 vmovdqu RR4, (6*4*4)(%r11);
13424 vmovdqu RL4, (7*4*4)(%r11);
13425
13426+ pax_force_retaddr
13427 ret;
13428 ENDPROC(cast5_ecb_enc_16way)
13429
13430@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13431 vmovdqu RR4, (6*4*4)(%r11);
13432 vmovdqu RL4, (7*4*4)(%r11);
13433
13434+ pax_force_retaddr
13435 ret;
13436 ENDPROC(cast5_ecb_dec_16way)
13437
13438@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13439 * %rdx: src
13440 */
13441
13442- pushq %r12;
13443+ pushq %r14;
13444
13445 movq %rsi, %r11;
13446- movq %rdx, %r12;
13447+ movq %rdx, %r14;
13448
13449 vmovdqu (0*16)(%rdx), RL1;
13450 vmovdqu (1*16)(%rdx), RR1;
13451@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13452 call __cast5_dec_blk16;
13453
13454 /* xor with src */
13455- vmovq (%r12), RX;
13456+ vmovq (%r14), RX;
13457 vpshufd $0x4f, RX, RX;
13458 vpxor RX, RR1, RR1;
13459- vpxor 0*16+8(%r12), RL1, RL1;
13460- vpxor 1*16+8(%r12), RR2, RR2;
13461- vpxor 2*16+8(%r12), RL2, RL2;
13462- vpxor 3*16+8(%r12), RR3, RR3;
13463- vpxor 4*16+8(%r12), RL3, RL3;
13464- vpxor 5*16+8(%r12), RR4, RR4;
13465- vpxor 6*16+8(%r12), RL4, RL4;
13466+ vpxor 0*16+8(%r14), RL1, RL1;
13467+ vpxor 1*16+8(%r14), RR2, RR2;
13468+ vpxor 2*16+8(%r14), RL2, RL2;
13469+ vpxor 3*16+8(%r14), RR3, RR3;
13470+ vpxor 4*16+8(%r14), RL3, RL3;
13471+ vpxor 5*16+8(%r14), RR4, RR4;
13472+ vpxor 6*16+8(%r14), RL4, RL4;
13473
13474 vmovdqu RR1, (0*16)(%r11);
13475 vmovdqu RL1, (1*16)(%r11);
13476@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13477 vmovdqu RR4, (6*16)(%r11);
13478 vmovdqu RL4, (7*16)(%r11);
13479
13480- popq %r12;
13481+ popq %r14;
13482
13483+ pax_force_retaddr
13484 ret;
13485 ENDPROC(cast5_cbc_dec_16way)
13486
13487@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13488 * %rcx: iv (big endian, 64bit)
13489 */
13490
13491- pushq %r12;
13492+ pushq %r14;
13493
13494 movq %rsi, %r11;
13495- movq %rdx, %r12;
13496+ movq %rdx, %r14;
13497
13498 vpcmpeqd RTMP, RTMP, RTMP;
13499 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13500@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13501 call __cast5_enc_blk16;
13502
13503 /* dst = src ^ iv */
13504- vpxor (0*16)(%r12), RR1, RR1;
13505- vpxor (1*16)(%r12), RL1, RL1;
13506- vpxor (2*16)(%r12), RR2, RR2;
13507- vpxor (3*16)(%r12), RL2, RL2;
13508- vpxor (4*16)(%r12), RR3, RR3;
13509- vpxor (5*16)(%r12), RL3, RL3;
13510- vpxor (6*16)(%r12), RR4, RR4;
13511- vpxor (7*16)(%r12), RL4, RL4;
13512+ vpxor (0*16)(%r14), RR1, RR1;
13513+ vpxor (1*16)(%r14), RL1, RL1;
13514+ vpxor (2*16)(%r14), RR2, RR2;
13515+ vpxor (3*16)(%r14), RL2, RL2;
13516+ vpxor (4*16)(%r14), RR3, RR3;
13517+ vpxor (5*16)(%r14), RL3, RL3;
13518+ vpxor (6*16)(%r14), RR4, RR4;
13519+ vpxor (7*16)(%r14), RL4, RL4;
13520 vmovdqu RR1, (0*16)(%r11);
13521 vmovdqu RL1, (1*16)(%r11);
13522 vmovdqu RR2, (2*16)(%r11);
13523@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13524 vmovdqu RR4, (6*16)(%r11);
13525 vmovdqu RL4, (7*16)(%r11);
13526
13527- popq %r12;
13528+ popq %r14;
13529
13530+ pax_force_retaddr
13531 ret;
13532 ENDPROC(cast5_ctr_16way)
13533diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13534index e3531f8..e123f35 100644
13535--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13536+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13537@@ -24,6 +24,7 @@
13538 */
13539
13540 #include <linux/linkage.h>
13541+#include <asm/alternative-asm.h>
13542 #include "glue_helper-asm-avx.S"
13543
13544 .file "cast6-avx-x86_64-asm_64.S"
13545@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13546 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13547 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13548
13549+ pax_force_retaddr
13550 ret;
13551 ENDPROC(__cast6_enc_blk8)
13552
13553@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13554 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13555 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13556
13557+ pax_force_retaddr
13558 ret;
13559 ENDPROC(__cast6_dec_blk8)
13560
13561@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13562
13563 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13564
13565+ pax_force_retaddr
13566 ret;
13567 ENDPROC(cast6_ecb_enc_8way)
13568
13569@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13570
13571 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13572
13573+ pax_force_retaddr
13574 ret;
13575 ENDPROC(cast6_ecb_dec_8way)
13576
13577@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13578 * %rdx: src
13579 */
13580
13581- pushq %r12;
13582+ pushq %r14;
13583
13584 movq %rsi, %r11;
13585- movq %rdx, %r12;
13586+ movq %rdx, %r14;
13587
13588 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13589
13590 call __cast6_dec_blk8;
13591
13592- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13593+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13594
13595- popq %r12;
13596+ popq %r14;
13597
13598+ pax_force_retaddr
13599 ret;
13600 ENDPROC(cast6_cbc_dec_8way)
13601
13602@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13603 * %rcx: iv (little endian, 128bit)
13604 */
13605
13606- pushq %r12;
13607+ pushq %r14;
13608
13609 movq %rsi, %r11;
13610- movq %rdx, %r12;
13611+ movq %rdx, %r14;
13612
13613 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13614 RD2, RX, RKR, RKM);
13615
13616 call __cast6_enc_blk8;
13617
13618- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13619+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13620
13621- popq %r12;
13622+ popq %r14;
13623
13624+ pax_force_retaddr
13625 ret;
13626 ENDPROC(cast6_ctr_8way)
13627
13628@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13629 /* dst <= regs xor IVs(in dst) */
13630 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13631
13632+ pax_force_retaddr
13633 ret;
13634 ENDPROC(cast6_xts_enc_8way)
13635
13636@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13637 /* dst <= regs xor IVs(in dst) */
13638 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13639
13640+ pax_force_retaddr
13641 ret;
13642 ENDPROC(cast6_xts_dec_8way)
13643diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13644index dbc4339..de6e120 100644
13645--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13646+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13647@@ -45,6 +45,7 @@
13648
13649 #include <asm/inst.h>
13650 #include <linux/linkage.h>
13651+#include <asm/alternative-asm.h>
13652
13653 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13654
13655@@ -312,6 +313,7 @@ do_return:
13656 popq %rsi
13657 popq %rdi
13658 popq %rbx
13659+ pax_force_retaddr
13660 ret
13661
13662 ################################################################
13663diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13664index 586f41a..d02851e 100644
13665--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13666+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13667@@ -18,6 +18,7 @@
13668
13669 #include <linux/linkage.h>
13670 #include <asm/inst.h>
13671+#include <asm/alternative-asm.h>
13672
13673 .data
13674
13675@@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13676 psrlq $1, T2
13677 pxor T2, T1
13678 pxor T1, DATA
13679+ pax_force_retaddr
13680 ret
13681 ENDPROC(__clmul_gf128mul_ble)
13682
13683@@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13684 call __clmul_gf128mul_ble
13685 PSHUFB_XMM BSWAP DATA
13686 movups DATA, (%rdi)
13687+ pax_force_retaddr
13688 ret
13689 ENDPROC(clmul_ghash_mul)
13690
13691@@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13692 PSHUFB_XMM BSWAP DATA
13693 movups DATA, (%rdi)
13694 .Lupdate_just_ret:
13695+ pax_force_retaddr
13696 ret
13697 ENDPROC(clmul_ghash_update)
13698
13699@@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13700 pand .Lpoly, %xmm1
13701 pxor %xmm1, %xmm0
13702 movups %xmm0, (%rdi)
13703+ pax_force_retaddr
13704 ret
13705 ENDPROC(clmul_ghash_setkey)
13706diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13707index 9279e0b..c4b3d2c 100644
13708--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13709+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13710@@ -1,4 +1,5 @@
13711 #include <linux/linkage.h>
13712+#include <asm/alternative-asm.h>
13713
13714 # enter salsa20_encrypt_bytes
13715 ENTRY(salsa20_encrypt_bytes)
13716@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13717 add %r11,%rsp
13718 mov %rdi,%rax
13719 mov %rsi,%rdx
13720+ pax_force_retaddr
13721 ret
13722 # bytesatleast65:
13723 ._bytesatleast65:
13724@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13725 add %r11,%rsp
13726 mov %rdi,%rax
13727 mov %rsi,%rdx
13728+ pax_force_retaddr
13729 ret
13730 ENDPROC(salsa20_keysetup)
13731
13732@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13733 add %r11,%rsp
13734 mov %rdi,%rax
13735 mov %rsi,%rdx
13736+ pax_force_retaddr
13737 ret
13738 ENDPROC(salsa20_ivsetup)
13739diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13740index 2f202f4..d9164d6 100644
13741--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13742+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13743@@ -24,6 +24,7 @@
13744 */
13745
13746 #include <linux/linkage.h>
13747+#include <asm/alternative-asm.h>
13748 #include "glue_helper-asm-avx.S"
13749
13750 .file "serpent-avx-x86_64-asm_64.S"
13751@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13752 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13753 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13754
13755+ pax_force_retaddr
13756 ret;
13757 ENDPROC(__serpent_enc_blk8_avx)
13758
13759@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13760 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13761 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13762
13763+ pax_force_retaddr
13764 ret;
13765 ENDPROC(__serpent_dec_blk8_avx)
13766
13767@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13768
13769 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13770
13771+ pax_force_retaddr
13772 ret;
13773 ENDPROC(serpent_ecb_enc_8way_avx)
13774
13775@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13776
13777 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13778
13779+ pax_force_retaddr
13780 ret;
13781 ENDPROC(serpent_ecb_dec_8way_avx)
13782
13783@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13784
13785 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13786
13787+ pax_force_retaddr
13788 ret;
13789 ENDPROC(serpent_cbc_dec_8way_avx)
13790
13791@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13792
13793 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13794
13795+ pax_force_retaddr
13796 ret;
13797 ENDPROC(serpent_ctr_8way_avx)
13798
13799@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13800 /* dst <= regs xor IVs(in dst) */
13801 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13802
13803+ pax_force_retaddr
13804 ret;
13805 ENDPROC(serpent_xts_enc_8way_avx)
13806
13807@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13808 /* dst <= regs xor IVs(in dst) */
13809 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13810
13811+ pax_force_retaddr
13812 ret;
13813 ENDPROC(serpent_xts_dec_8way_avx)
13814diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13815index b222085..abd483c 100644
13816--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13817+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13818@@ -15,6 +15,7 @@
13819 */
13820
13821 #include <linux/linkage.h>
13822+#include <asm/alternative-asm.h>
13823 #include "glue_helper-asm-avx2.S"
13824
13825 .file "serpent-avx2-asm_64.S"
13826@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13827 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13828 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13829
13830+ pax_force_retaddr
13831 ret;
13832 ENDPROC(__serpent_enc_blk16)
13833
13834@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13835 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13836 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13837
13838+ pax_force_retaddr
13839 ret;
13840 ENDPROC(__serpent_dec_blk16)
13841
13842@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13843
13844 vzeroupper;
13845
13846+ pax_force_retaddr
13847 ret;
13848 ENDPROC(serpent_ecb_enc_16way)
13849
13850@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13851
13852 vzeroupper;
13853
13854+ pax_force_retaddr
13855 ret;
13856 ENDPROC(serpent_ecb_dec_16way)
13857
13858@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13859
13860 vzeroupper;
13861
13862+ pax_force_retaddr
13863 ret;
13864 ENDPROC(serpent_cbc_dec_16way)
13865
13866@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13867
13868 vzeroupper;
13869
13870+ pax_force_retaddr
13871 ret;
13872 ENDPROC(serpent_ctr_16way)
13873
13874@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13875
13876 vzeroupper;
13877
13878+ pax_force_retaddr
13879 ret;
13880 ENDPROC(serpent_xts_enc_16way)
13881
13882@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13883
13884 vzeroupper;
13885
13886+ pax_force_retaddr
13887 ret;
13888 ENDPROC(serpent_xts_dec_16way)
13889diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13890index acc066c..1559cc4 100644
13891--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13892+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13893@@ -25,6 +25,7 @@
13894 */
13895
13896 #include <linux/linkage.h>
13897+#include <asm/alternative-asm.h>
13898
13899 .file "serpent-sse2-x86_64-asm_64.S"
13900 .text
13901@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13902 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13903 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13904
13905+ pax_force_retaddr
13906 ret;
13907
13908 .L__enc_xor8:
13909 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13910 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13911
13912+ pax_force_retaddr
13913 ret;
13914 ENDPROC(__serpent_enc_blk_8way)
13915
13916@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13917 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13918 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13919
13920+ pax_force_retaddr
13921 ret;
13922 ENDPROC(serpent_dec_blk_8way)
13923diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13924index a410950..9dfe7ad 100644
13925--- a/arch/x86/crypto/sha1_ssse3_asm.S
13926+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13927@@ -29,6 +29,7 @@
13928 */
13929
13930 #include <linux/linkage.h>
13931+#include <asm/alternative-asm.h>
13932
13933 #define CTX %rdi // arg1
13934 #define BUF %rsi // arg2
13935@@ -75,9 +76,9 @@
13936
13937 push %rbx
13938 push %rbp
13939- push %r12
13940+ push %r14
13941
13942- mov %rsp, %r12
13943+ mov %rsp, %r14
13944 sub $64, %rsp # allocate workspace
13945 and $~15, %rsp # align stack
13946
13947@@ -99,11 +100,12 @@
13948 xor %rax, %rax
13949 rep stosq
13950
13951- mov %r12, %rsp # deallocate workspace
13952+ mov %r14, %rsp # deallocate workspace
13953
13954- pop %r12
13955+ pop %r14
13956 pop %rbp
13957 pop %rbx
13958+ pax_force_retaddr
13959 ret
13960
13961 ENDPROC(\name)
13962diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13963index 642f156..51a513c 100644
13964--- a/arch/x86/crypto/sha256-avx-asm.S
13965+++ b/arch/x86/crypto/sha256-avx-asm.S
13966@@ -49,6 +49,7 @@
13967
13968 #ifdef CONFIG_AS_AVX
13969 #include <linux/linkage.h>
13970+#include <asm/alternative-asm.h>
13971
13972 ## assume buffers not aligned
13973 #define VMOVDQ vmovdqu
13974@@ -460,6 +461,7 @@ done_hash:
13975 popq %r13
13976 popq %rbp
13977 popq %rbx
13978+ pax_force_retaddr
13979 ret
13980 ENDPROC(sha256_transform_avx)
13981
13982diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13983index 9e86944..3795e6a 100644
13984--- a/arch/x86/crypto/sha256-avx2-asm.S
13985+++ b/arch/x86/crypto/sha256-avx2-asm.S
13986@@ -50,6 +50,7 @@
13987
13988 #ifdef CONFIG_AS_AVX2
13989 #include <linux/linkage.h>
13990+#include <asm/alternative-asm.h>
13991
13992 ## assume buffers not aligned
13993 #define VMOVDQ vmovdqu
13994@@ -720,6 +721,7 @@ done_hash:
13995 popq %r12
13996 popq %rbp
13997 popq %rbx
13998+ pax_force_retaddr
13999 ret
14000 ENDPROC(sha256_transform_rorx)
14001
14002diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14003index f833b74..8c62a9e 100644
14004--- a/arch/x86/crypto/sha256-ssse3-asm.S
14005+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14006@@ -47,6 +47,7 @@
14007 ########################################################################
14008
14009 #include <linux/linkage.h>
14010+#include <asm/alternative-asm.h>
14011
14012 ## assume buffers not aligned
14013 #define MOVDQ movdqu
14014@@ -471,6 +472,7 @@ done_hash:
14015 popq %rbp
14016 popq %rbx
14017
14018+ pax_force_retaddr
14019 ret
14020 ENDPROC(sha256_transform_ssse3)
14021
14022diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14023index 974dde9..a823ff9 100644
14024--- a/arch/x86/crypto/sha512-avx-asm.S
14025+++ b/arch/x86/crypto/sha512-avx-asm.S
14026@@ -49,6 +49,7 @@
14027
14028 #ifdef CONFIG_AS_AVX
14029 #include <linux/linkage.h>
14030+#include <asm/alternative-asm.h>
14031
14032 .text
14033
14034@@ -364,6 +365,7 @@ updateblock:
14035 mov frame_RSPSAVE(%rsp), %rsp
14036
14037 nowork:
14038+ pax_force_retaddr
14039 ret
14040 ENDPROC(sha512_transform_avx)
14041
14042diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14043index 568b961..ed20c37 100644
14044--- a/arch/x86/crypto/sha512-avx2-asm.S
14045+++ b/arch/x86/crypto/sha512-avx2-asm.S
14046@@ -51,6 +51,7 @@
14047
14048 #ifdef CONFIG_AS_AVX2
14049 #include <linux/linkage.h>
14050+#include <asm/alternative-asm.h>
14051
14052 .text
14053
14054@@ -678,6 +679,7 @@ done_hash:
14055
14056 # Restore Stack Pointer
14057 mov frame_RSPSAVE(%rsp), %rsp
14058+ pax_force_retaddr
14059 ret
14060 ENDPROC(sha512_transform_rorx)
14061
14062diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14063index fb56855..6edd768 100644
14064--- a/arch/x86/crypto/sha512-ssse3-asm.S
14065+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14066@@ -48,6 +48,7 @@
14067 ########################################################################
14068
14069 #include <linux/linkage.h>
14070+#include <asm/alternative-asm.h>
14071
14072 .text
14073
14074@@ -363,6 +364,7 @@ updateblock:
14075 mov frame_RSPSAVE(%rsp), %rsp
14076
14077 nowork:
14078+ pax_force_retaddr
14079 ret
14080 ENDPROC(sha512_transform_ssse3)
14081
14082diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14083index 0505813..b067311 100644
14084--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14085+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14086@@ -24,6 +24,7 @@
14087 */
14088
14089 #include <linux/linkage.h>
14090+#include <asm/alternative-asm.h>
14091 #include "glue_helper-asm-avx.S"
14092
14093 .file "twofish-avx-x86_64-asm_64.S"
14094@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14095 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14096 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14097
14098+ pax_force_retaddr
14099 ret;
14100 ENDPROC(__twofish_enc_blk8)
14101
14102@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14103 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14104 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14105
14106+ pax_force_retaddr
14107 ret;
14108 ENDPROC(__twofish_dec_blk8)
14109
14110@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14111
14112 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14113
14114+ pax_force_retaddr
14115 ret;
14116 ENDPROC(twofish_ecb_enc_8way)
14117
14118@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14119
14120 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14121
14122+ pax_force_retaddr
14123 ret;
14124 ENDPROC(twofish_ecb_dec_8way)
14125
14126@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14127 * %rdx: src
14128 */
14129
14130- pushq %r12;
14131+ pushq %r14;
14132
14133 movq %rsi, %r11;
14134- movq %rdx, %r12;
14135+ movq %rdx, %r14;
14136
14137 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14138
14139 call __twofish_dec_blk8;
14140
14141- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14142+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14143
14144- popq %r12;
14145+ popq %r14;
14146
14147+ pax_force_retaddr
14148 ret;
14149 ENDPROC(twofish_cbc_dec_8way)
14150
14151@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14152 * %rcx: iv (little endian, 128bit)
14153 */
14154
14155- pushq %r12;
14156+ pushq %r14;
14157
14158 movq %rsi, %r11;
14159- movq %rdx, %r12;
14160+ movq %rdx, %r14;
14161
14162 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14163 RD2, RX0, RX1, RY0);
14164
14165 call __twofish_enc_blk8;
14166
14167- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14168+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14169
14170- popq %r12;
14171+ popq %r14;
14172
14173+ pax_force_retaddr
14174 ret;
14175 ENDPROC(twofish_ctr_8way)
14176
14177@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14178 /* dst <= regs xor IVs(in dst) */
14179 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14180
14181+ pax_force_retaddr
14182 ret;
14183 ENDPROC(twofish_xts_enc_8way)
14184
14185@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14186 /* dst <= regs xor IVs(in dst) */
14187 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14188
14189+ pax_force_retaddr
14190 ret;
14191 ENDPROC(twofish_xts_dec_8way)
14192diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14193index 1c3b7ce..02f578d 100644
14194--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14195+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14196@@ -21,6 +21,7 @@
14197 */
14198
14199 #include <linux/linkage.h>
14200+#include <asm/alternative-asm.h>
14201
14202 .file "twofish-x86_64-asm-3way.S"
14203 .text
14204@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14205 popq %r13;
14206 popq %r14;
14207 popq %r15;
14208+ pax_force_retaddr
14209 ret;
14210
14211 .L__enc_xor3:
14212@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14213 popq %r13;
14214 popq %r14;
14215 popq %r15;
14216+ pax_force_retaddr
14217 ret;
14218 ENDPROC(__twofish_enc_blk_3way)
14219
14220@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14221 popq %r13;
14222 popq %r14;
14223 popq %r15;
14224+ pax_force_retaddr
14225 ret;
14226 ENDPROC(twofish_dec_blk_3way)
14227diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14228index a039d21..524b8b2 100644
14229--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14230+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14231@@ -22,6 +22,7 @@
14232
14233 #include <linux/linkage.h>
14234 #include <asm/asm-offsets.h>
14235+#include <asm/alternative-asm.h>
14236
14237 #define a_offset 0
14238 #define b_offset 4
14239@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14240
14241 popq R1
14242 movq $1,%rax
14243+ pax_force_retaddr
14244 ret
14245 ENDPROC(twofish_enc_blk)
14246
14247@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14248
14249 popq R1
14250 movq $1,%rax
14251+ pax_force_retaddr
14252 ret
14253 ENDPROC(twofish_dec_blk)
14254diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14255index d21ff89..6da8e6e 100644
14256--- a/arch/x86/ia32/ia32_aout.c
14257+++ b/arch/x86/ia32/ia32_aout.c
14258@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14259 unsigned long dump_start, dump_size;
14260 struct user32 dump;
14261
14262+ memset(&dump, 0, sizeof(dump));
14263+
14264 fs = get_fs();
14265 set_fs(KERNEL_DS);
14266 has_dumped = 1;
14267diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14268index 2206757..85cbcfa 100644
14269--- a/arch/x86/ia32/ia32_signal.c
14270+++ b/arch/x86/ia32/ia32_signal.c
14271@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14272 if (__get_user(set.sig[0], &frame->sc.oldmask)
14273 || (_COMPAT_NSIG_WORDS > 1
14274 && __copy_from_user((((char *) &set.sig) + 4),
14275- &frame->extramask,
14276+ frame->extramask,
14277 sizeof(frame->extramask))))
14278 goto badframe;
14279
14280@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14281 sp -= frame_size;
14282 /* Align the stack pointer according to the i386 ABI,
14283 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14284- sp = ((sp + 4) & -16ul) - 4;
14285+ sp = ((sp - 12) & -16ul) - 4;
14286 return (void __user *) sp;
14287 }
14288
14289@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14290 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14291 sigreturn);
14292 else
14293- restorer = &frame->retcode;
14294+ restorer = frame->retcode;
14295 }
14296
14297 put_user_try {
14298@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14299 * These are actually not used anymore, but left because some
14300 * gdb versions depend on them as a marker.
14301 */
14302- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14303+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14304 } put_user_catch(err);
14305
14306 if (err)
14307@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14308 0xb8,
14309 __NR_ia32_rt_sigreturn,
14310 0x80cd,
14311- 0,
14312+ 0
14313 };
14314
14315 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14316@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14317
14318 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14319 restorer = ksig->ka.sa.sa_restorer;
14320+ else if (current->mm->context.vdso)
14321+ /* Return stub is in 32bit vsyscall page */
14322+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14323 else
14324- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14325- rt_sigreturn);
14326+ restorer = frame->retcode;
14327 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14328
14329 /*
14330 * Not actually used anymore, but left because some gdb
14331 * versions need it.
14332 */
14333- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14334+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14335 } put_user_catch(err);
14336
14337 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14338diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14339index 4299eb0..c0687a7 100644
14340--- a/arch/x86/ia32/ia32entry.S
14341+++ b/arch/x86/ia32/ia32entry.S
14342@@ -15,8 +15,10 @@
14343 #include <asm/irqflags.h>
14344 #include <asm/asm.h>
14345 #include <asm/smap.h>
14346+#include <asm/pgtable.h>
14347 #include <linux/linkage.h>
14348 #include <linux/err.h>
14349+#include <asm/alternative-asm.h>
14350
14351 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14352 #include <linux/elf-em.h>
14353@@ -62,12 +64,12 @@
14354 */
14355 .macro LOAD_ARGS32 offset, _r9=0
14356 .if \_r9
14357- movl \offset+16(%rsp),%r9d
14358+ movl \offset+R9(%rsp),%r9d
14359 .endif
14360- movl \offset+40(%rsp),%ecx
14361- movl \offset+48(%rsp),%edx
14362- movl \offset+56(%rsp),%esi
14363- movl \offset+64(%rsp),%edi
14364+ movl \offset+RCX(%rsp),%ecx
14365+ movl \offset+RDX(%rsp),%edx
14366+ movl \offset+RSI(%rsp),%esi
14367+ movl \offset+RDI(%rsp),%edi
14368 movl %eax,%eax /* zero extension */
14369 .endm
14370
14371@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14372 ENDPROC(native_irq_enable_sysexit)
14373 #endif
14374
14375+ .macro pax_enter_kernel_user
14376+ pax_set_fptr_mask
14377+#ifdef CONFIG_PAX_MEMORY_UDEREF
14378+ call pax_enter_kernel_user
14379+#endif
14380+ .endm
14381+
14382+ .macro pax_exit_kernel_user
14383+#ifdef CONFIG_PAX_MEMORY_UDEREF
14384+ call pax_exit_kernel_user
14385+#endif
14386+#ifdef CONFIG_PAX_RANDKSTACK
14387+ pushq %rax
14388+ pushq %r11
14389+ call pax_randomize_kstack
14390+ popq %r11
14391+ popq %rax
14392+#endif
14393+ .endm
14394+
14395+ .macro pax_erase_kstack
14396+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14397+ call pax_erase_kstack
14398+#endif
14399+ .endm
14400+
14401 /*
14402 * 32bit SYSENTER instruction entry.
14403 *
14404@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14405 CFI_REGISTER rsp,rbp
14406 SWAPGS_UNSAFE_STACK
14407 movq PER_CPU_VAR(kernel_stack), %rsp
14408- addq $(KERNEL_STACK_OFFSET),%rsp
14409- /*
14410- * No need to follow this irqs on/off section: the syscall
14411- * disabled irqs, here we enable it straight after entry:
14412- */
14413- ENABLE_INTERRUPTS(CLBR_NONE)
14414 movl %ebp,%ebp /* zero extension */
14415 pushq_cfi $__USER32_DS
14416 /*CFI_REL_OFFSET ss,0*/
14417@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14418 CFI_REL_OFFSET rsp,0
14419 pushfq_cfi
14420 /*CFI_REL_OFFSET rflags,0*/
14421- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14422- CFI_REGISTER rip,r10
14423+ orl $X86_EFLAGS_IF,(%rsp)
14424+ GET_THREAD_INFO(%r11)
14425+ movl TI_sysenter_return(%r11), %r11d
14426+ CFI_REGISTER rip,r11
14427 pushq_cfi $__USER32_CS
14428 /*CFI_REL_OFFSET cs,0*/
14429 movl %eax, %eax
14430- pushq_cfi %r10
14431+ pushq_cfi %r11
14432 CFI_REL_OFFSET rip,0
14433 pushq_cfi %rax
14434 cld
14435 SAVE_ARGS 0,1,0
14436+ pax_enter_kernel_user
14437+
14438+#ifdef CONFIG_PAX_RANDKSTACK
14439+ pax_erase_kstack
14440+#endif
14441+
14442+ /*
14443+ * No need to follow this irqs on/off section: the syscall
14444+ * disabled irqs, here we enable it straight after entry:
14445+ */
14446+ ENABLE_INTERRUPTS(CLBR_NONE)
14447 /* no need to do an access_ok check here because rbp has been
14448 32bit zero extended */
14449+
14450+#ifdef CONFIG_PAX_MEMORY_UDEREF
14451+ addq pax_user_shadow_base,%rbp
14452+ ASM_PAX_OPEN_USERLAND
14453+#endif
14454+
14455 ASM_STAC
14456 1: movl (%rbp),%ebp
14457 _ASM_EXTABLE(1b,ia32_badarg)
14458 ASM_CLAC
14459- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14460- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14461+
14462+#ifdef CONFIG_PAX_MEMORY_UDEREF
14463+ ASM_PAX_CLOSE_USERLAND
14464+#endif
14465+
14466+ GET_THREAD_INFO(%r11)
14467+ orl $TS_COMPAT,TI_status(%r11)
14468+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14469 CFI_REMEMBER_STATE
14470 jnz sysenter_tracesys
14471 cmpq $(IA32_NR_syscalls-1),%rax
14472@@ -162,15 +209,18 @@ sysenter_do_call:
14473 sysenter_dispatch:
14474 call *ia32_sys_call_table(,%rax,8)
14475 movq %rax,RAX-ARGOFFSET(%rsp)
14476+ GET_THREAD_INFO(%r11)
14477 DISABLE_INTERRUPTS(CLBR_NONE)
14478 TRACE_IRQS_OFF
14479- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14480+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14481 jnz sysexit_audit
14482 sysexit_from_sys_call:
14483- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14484+ pax_exit_kernel_user
14485+ pax_erase_kstack
14486+ andl $~TS_COMPAT,TI_status(%r11)
14487 /* clear IF, that popfq doesn't enable interrupts early */
14488- andl $~0x200,EFLAGS-R11(%rsp)
14489- movl RIP-R11(%rsp),%edx /* User %eip */
14490+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14491+ movl RIP(%rsp),%edx /* User %eip */
14492 CFI_REGISTER rip,rdx
14493 RESTORE_ARGS 0,24,0,0,0,0
14494 xorq %r8,%r8
14495@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14496 movl %eax,%esi /* 2nd arg: syscall number */
14497 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14498 call __audit_syscall_entry
14499+
14500+ pax_erase_kstack
14501+
14502 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14503 cmpq $(IA32_NR_syscalls-1),%rax
14504 ja ia32_badsys
14505@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14506 .endm
14507
14508 .macro auditsys_exit exit
14509- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14510+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14511 jnz ia32_ret_from_sys_call
14512 TRACE_IRQS_ON
14513 ENABLE_INTERRUPTS(CLBR_NONE)
14514@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14515 1: setbe %al /* 1 if error, 0 if not */
14516 movzbl %al,%edi /* zero-extend that into %edi */
14517 call __audit_syscall_exit
14518+ GET_THREAD_INFO(%r11)
14519 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14520 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14521 DISABLE_INTERRUPTS(CLBR_NONE)
14522 TRACE_IRQS_OFF
14523- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14524+ testl %edi,TI_flags(%r11)
14525 jz \exit
14526 CLEAR_RREGS -ARGOFFSET
14527 jmp int_with_check
14528@@ -237,7 +291,7 @@ sysexit_audit:
14529
14530 sysenter_tracesys:
14531 #ifdef CONFIG_AUDITSYSCALL
14532- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14533+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14534 jz sysenter_auditsys
14535 #endif
14536 SAVE_REST
14537@@ -249,6 +303,9 @@ sysenter_tracesys:
14538 RESTORE_REST
14539 cmpq $(IA32_NR_syscalls-1),%rax
14540 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14541+
14542+ pax_erase_kstack
14543+
14544 jmp sysenter_do_call
14545 CFI_ENDPROC
14546 ENDPROC(ia32_sysenter_target)
14547@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14548 ENTRY(ia32_cstar_target)
14549 CFI_STARTPROC32 simple
14550 CFI_SIGNAL_FRAME
14551- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14552+ CFI_DEF_CFA rsp,0
14553 CFI_REGISTER rip,rcx
14554 /*CFI_REGISTER rflags,r11*/
14555 SWAPGS_UNSAFE_STACK
14556 movl %esp,%r8d
14557 CFI_REGISTER rsp,r8
14558 movq PER_CPU_VAR(kernel_stack),%rsp
14559+ SAVE_ARGS 8*6,0,0
14560+ pax_enter_kernel_user
14561+
14562+#ifdef CONFIG_PAX_RANDKSTACK
14563+ pax_erase_kstack
14564+#endif
14565+
14566 /*
14567 * No need to follow this irqs on/off section: the syscall
14568 * disabled irqs and here we enable it straight after entry:
14569 */
14570 ENABLE_INTERRUPTS(CLBR_NONE)
14571- SAVE_ARGS 8,0,0
14572 movl %eax,%eax /* zero extension */
14573 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14574 movq %rcx,RIP-ARGOFFSET(%rsp)
14575@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14576 /* no need to do an access_ok check here because r8 has been
14577 32bit zero extended */
14578 /* hardware stack frame is complete now */
14579+
14580+#ifdef CONFIG_PAX_MEMORY_UDEREF
14581+ ASM_PAX_OPEN_USERLAND
14582+ movq pax_user_shadow_base,%r8
14583+ addq RSP-ARGOFFSET(%rsp),%r8
14584+#endif
14585+
14586 ASM_STAC
14587 1: movl (%r8),%r9d
14588 _ASM_EXTABLE(1b,ia32_badarg)
14589 ASM_CLAC
14590- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14591- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14592+
14593+#ifdef CONFIG_PAX_MEMORY_UDEREF
14594+ ASM_PAX_CLOSE_USERLAND
14595+#endif
14596+
14597+ GET_THREAD_INFO(%r11)
14598+ orl $TS_COMPAT,TI_status(%r11)
14599+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14600 CFI_REMEMBER_STATE
14601 jnz cstar_tracesys
14602 cmpq $IA32_NR_syscalls-1,%rax
14603@@ -319,13 +395,16 @@ cstar_do_call:
14604 cstar_dispatch:
14605 call *ia32_sys_call_table(,%rax,8)
14606 movq %rax,RAX-ARGOFFSET(%rsp)
14607+ GET_THREAD_INFO(%r11)
14608 DISABLE_INTERRUPTS(CLBR_NONE)
14609 TRACE_IRQS_OFF
14610- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14611+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14612 jnz sysretl_audit
14613 sysretl_from_sys_call:
14614- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14615- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14616+ pax_exit_kernel_user
14617+ pax_erase_kstack
14618+ andl $~TS_COMPAT,TI_status(%r11)
14619+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14620 movl RIP-ARGOFFSET(%rsp),%ecx
14621 CFI_REGISTER rip,rcx
14622 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14623@@ -352,7 +431,7 @@ sysretl_audit:
14624
14625 cstar_tracesys:
14626 #ifdef CONFIG_AUDITSYSCALL
14627- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14628+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14629 jz cstar_auditsys
14630 #endif
14631 xchgl %r9d,%ebp
14632@@ -366,11 +445,19 @@ cstar_tracesys:
14633 xchgl %ebp,%r9d
14634 cmpq $(IA32_NR_syscalls-1),%rax
14635 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14636+
14637+ pax_erase_kstack
14638+
14639 jmp cstar_do_call
14640 END(ia32_cstar_target)
14641
14642 ia32_badarg:
14643 ASM_CLAC
14644+
14645+#ifdef CONFIG_PAX_MEMORY_UDEREF
14646+ ASM_PAX_CLOSE_USERLAND
14647+#endif
14648+
14649 movq $-EFAULT,%rax
14650 jmp ia32_sysret
14651 CFI_ENDPROC
14652@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14653 CFI_REL_OFFSET rip,RIP-RIP
14654 PARAVIRT_ADJUST_EXCEPTION_FRAME
14655 SWAPGS
14656- /*
14657- * No need to follow this irqs on/off section: the syscall
14658- * disabled irqs and here we enable it straight after entry:
14659- */
14660- ENABLE_INTERRUPTS(CLBR_NONE)
14661 movl %eax,%eax
14662 pushq_cfi %rax
14663 cld
14664 /* note the registers are not zero extended to the sf.
14665 this could be a problem. */
14666 SAVE_ARGS 0,1,0
14667- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14668- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14669+ pax_enter_kernel_user
14670+
14671+#ifdef CONFIG_PAX_RANDKSTACK
14672+ pax_erase_kstack
14673+#endif
14674+
14675+ /*
14676+ * No need to follow this irqs on/off section: the syscall
14677+ * disabled irqs and here we enable it straight after entry:
14678+ */
14679+ ENABLE_INTERRUPTS(CLBR_NONE)
14680+ GET_THREAD_INFO(%r11)
14681+ orl $TS_COMPAT,TI_status(%r11)
14682+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14683 jnz ia32_tracesys
14684 cmpq $(IA32_NR_syscalls-1),%rax
14685 ja ia32_badsys
14686@@ -442,6 +536,9 @@ ia32_tracesys:
14687 RESTORE_REST
14688 cmpq $(IA32_NR_syscalls-1),%rax
14689 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14690+
14691+ pax_erase_kstack
14692+
14693 jmp ia32_do_call
14694 END(ia32_syscall)
14695
14696diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14697index 8e0ceec..af13504 100644
14698--- a/arch/x86/ia32/sys_ia32.c
14699+++ b/arch/x86/ia32/sys_ia32.c
14700@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14701 */
14702 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14703 {
14704- typeof(ubuf->st_uid) uid = 0;
14705- typeof(ubuf->st_gid) gid = 0;
14706+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14707+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14708 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14709 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14710 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14711diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14712index 372231c..51b537d 100644
14713--- a/arch/x86/include/asm/alternative-asm.h
14714+++ b/arch/x86/include/asm/alternative-asm.h
14715@@ -18,6 +18,45 @@
14716 .endm
14717 #endif
14718
14719+#ifdef KERNEXEC_PLUGIN
14720+ .macro pax_force_retaddr_bts rip=0
14721+ btsq $63,\rip(%rsp)
14722+ .endm
14723+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14724+ .macro pax_force_retaddr rip=0, reload=0
14725+ btsq $63,\rip(%rsp)
14726+ .endm
14727+ .macro pax_force_fptr ptr
14728+ btsq $63,\ptr
14729+ .endm
14730+ .macro pax_set_fptr_mask
14731+ .endm
14732+#endif
14733+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14734+ .macro pax_force_retaddr rip=0, reload=0
14735+ .if \reload
14736+ pax_set_fptr_mask
14737+ .endif
14738+ orq %r12,\rip(%rsp)
14739+ .endm
14740+ .macro pax_force_fptr ptr
14741+ orq %r12,\ptr
14742+ .endm
14743+ .macro pax_set_fptr_mask
14744+ movabs $0x8000000000000000,%r12
14745+ .endm
14746+#endif
14747+#else
14748+ .macro pax_force_retaddr rip=0, reload=0
14749+ .endm
14750+ .macro pax_force_fptr ptr
14751+ .endm
14752+ .macro pax_force_retaddr_bts rip=0
14753+ .endm
14754+ .macro pax_set_fptr_mask
14755+ .endm
14756+#endif
14757+
14758 .macro altinstruction_entry orig alt feature orig_len alt_len
14759 .long \orig - .
14760 .long \alt - .
14761diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14762index 0a3f9c9..c9d081d 100644
14763--- a/arch/x86/include/asm/alternative.h
14764+++ b/arch/x86/include/asm/alternative.h
14765@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14766 ".pushsection .discard,\"aw\",@progbits\n" \
14767 DISCARD_ENTRY(1) \
14768 ".popsection\n" \
14769- ".pushsection .altinstr_replacement, \"ax\"\n" \
14770+ ".pushsection .altinstr_replacement, \"a\"\n" \
14771 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14772 ".popsection"
14773
14774@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14775 DISCARD_ENTRY(1) \
14776 DISCARD_ENTRY(2) \
14777 ".popsection\n" \
14778- ".pushsection .altinstr_replacement, \"ax\"\n" \
14779+ ".pushsection .altinstr_replacement, \"a\"\n" \
14780 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14781 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14782 ".popsection"
14783diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14784index 1d2091a..f5074c1 100644
14785--- a/arch/x86/include/asm/apic.h
14786+++ b/arch/x86/include/asm/apic.h
14787@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14788
14789 #ifdef CONFIG_X86_LOCAL_APIC
14790
14791-extern unsigned int apic_verbosity;
14792+extern int apic_verbosity;
14793 extern int local_apic_timer_c2_ok;
14794
14795 extern int disable_apic;
14796diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14797index 20370c6..a2eb9b0 100644
14798--- a/arch/x86/include/asm/apm.h
14799+++ b/arch/x86/include/asm/apm.h
14800@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14801 __asm__ __volatile__(APM_DO_ZERO_SEGS
14802 "pushl %%edi\n\t"
14803 "pushl %%ebp\n\t"
14804- "lcall *%%cs:apm_bios_entry\n\t"
14805+ "lcall *%%ss:apm_bios_entry\n\t"
14806 "setc %%al\n\t"
14807 "popl %%ebp\n\t"
14808 "popl %%edi\n\t"
14809@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14810 __asm__ __volatile__(APM_DO_ZERO_SEGS
14811 "pushl %%edi\n\t"
14812 "pushl %%ebp\n\t"
14813- "lcall *%%cs:apm_bios_entry\n\t"
14814+ "lcall *%%ss:apm_bios_entry\n\t"
14815 "setc %%bl\n\t"
14816 "popl %%ebp\n\t"
14817 "popl %%edi\n\t"
14818diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14819index b17f4f4..9620151 100644
14820--- a/arch/x86/include/asm/atomic.h
14821+++ b/arch/x86/include/asm/atomic.h
14822@@ -23,7 +23,18 @@
14823 */
14824 static inline int atomic_read(const atomic_t *v)
14825 {
14826- return (*(volatile int *)&(v)->counter);
14827+ return (*(volatile const int *)&(v)->counter);
14828+}
14829+
14830+/**
14831+ * atomic_read_unchecked - read atomic variable
14832+ * @v: pointer of type atomic_unchecked_t
14833+ *
14834+ * Atomically reads the value of @v.
14835+ */
14836+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14837+{
14838+ return (*(volatile const int *)&(v)->counter);
14839 }
14840
14841 /**
14842@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14843 }
14844
14845 /**
14846+ * atomic_set_unchecked - set atomic variable
14847+ * @v: pointer of type atomic_unchecked_t
14848+ * @i: required value
14849+ *
14850+ * Atomically sets the value of @v to @i.
14851+ */
14852+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14853+{
14854+ v->counter = i;
14855+}
14856+
14857+/**
14858 * atomic_add - add integer to atomic variable
14859 * @i: integer value to add
14860 * @v: pointer of type atomic_t
14861@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14862 */
14863 static inline void atomic_add(int i, atomic_t *v)
14864 {
14865- asm volatile(LOCK_PREFIX "addl %1,%0"
14866+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14867+
14868+#ifdef CONFIG_PAX_REFCOUNT
14869+ "jno 0f\n"
14870+ LOCK_PREFIX "subl %1,%0\n"
14871+ "int $4\n0:\n"
14872+ _ASM_EXTABLE(0b, 0b)
14873+#endif
14874+
14875+ : "+m" (v->counter)
14876+ : "ir" (i));
14877+}
14878+
14879+/**
14880+ * atomic_add_unchecked - add integer to atomic variable
14881+ * @i: integer value to add
14882+ * @v: pointer of type atomic_unchecked_t
14883+ *
14884+ * Atomically adds @i to @v.
14885+ */
14886+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14887+{
14888+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14889 : "+m" (v->counter)
14890 : "ir" (i));
14891 }
14892@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14893 */
14894 static inline void atomic_sub(int i, atomic_t *v)
14895 {
14896- asm volatile(LOCK_PREFIX "subl %1,%0"
14897+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14898+
14899+#ifdef CONFIG_PAX_REFCOUNT
14900+ "jno 0f\n"
14901+ LOCK_PREFIX "addl %1,%0\n"
14902+ "int $4\n0:\n"
14903+ _ASM_EXTABLE(0b, 0b)
14904+#endif
14905+
14906+ : "+m" (v->counter)
14907+ : "ir" (i));
14908+}
14909+
14910+/**
14911+ * atomic_sub_unchecked - subtract integer from atomic variable
14912+ * @i: integer value to subtract
14913+ * @v: pointer of type atomic_unchecked_t
14914+ *
14915+ * Atomically subtracts @i from @v.
14916+ */
14917+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14918+{
14919+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14920 : "+m" (v->counter)
14921 : "ir" (i));
14922 }
14923@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14924 */
14925 static inline int atomic_sub_and_test(int i, atomic_t *v)
14926 {
14927- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14928+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14929 }
14930
14931 /**
14932@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14933 */
14934 static inline void atomic_inc(atomic_t *v)
14935 {
14936- asm volatile(LOCK_PREFIX "incl %0"
14937+ asm volatile(LOCK_PREFIX "incl %0\n"
14938+
14939+#ifdef CONFIG_PAX_REFCOUNT
14940+ "jno 0f\n"
14941+ LOCK_PREFIX "decl %0\n"
14942+ "int $4\n0:\n"
14943+ _ASM_EXTABLE(0b, 0b)
14944+#endif
14945+
14946+ : "+m" (v->counter));
14947+}
14948+
14949+/**
14950+ * atomic_inc_unchecked - increment atomic variable
14951+ * @v: pointer of type atomic_unchecked_t
14952+ *
14953+ * Atomically increments @v by 1.
14954+ */
14955+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14956+{
14957+ asm volatile(LOCK_PREFIX "incl %0\n"
14958 : "+m" (v->counter));
14959 }
14960
14961@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14962 */
14963 static inline void atomic_dec(atomic_t *v)
14964 {
14965- asm volatile(LOCK_PREFIX "decl %0"
14966+ asm volatile(LOCK_PREFIX "decl %0\n"
14967+
14968+#ifdef CONFIG_PAX_REFCOUNT
14969+ "jno 0f\n"
14970+ LOCK_PREFIX "incl %0\n"
14971+ "int $4\n0:\n"
14972+ _ASM_EXTABLE(0b, 0b)
14973+#endif
14974+
14975+ : "+m" (v->counter));
14976+}
14977+
14978+/**
14979+ * atomic_dec_unchecked - decrement atomic variable
14980+ * @v: pointer of type atomic_unchecked_t
14981+ *
14982+ * Atomically decrements @v by 1.
14983+ */
14984+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14985+{
14986+ asm volatile(LOCK_PREFIX "decl %0\n"
14987 : "+m" (v->counter));
14988 }
14989
14990@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14991 */
14992 static inline int atomic_dec_and_test(atomic_t *v)
14993 {
14994- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14995+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14996 }
14997
14998 /**
14999@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15000 */
15001 static inline int atomic_inc_and_test(atomic_t *v)
15002 {
15003- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15004+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15005+}
15006+
15007+/**
15008+ * atomic_inc_and_test_unchecked - increment and test
15009+ * @v: pointer of type atomic_unchecked_t
15010+ *
15011+ * Atomically increments @v by 1
15012+ * and returns true if the result is zero, or false for all
15013+ * other cases.
15014+ */
15015+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15016+{
15017+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15018 }
15019
15020 /**
15021@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15022 */
15023 static inline int atomic_add_negative(int i, atomic_t *v)
15024 {
15025- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15026+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15027 }
15028
15029 /**
15030@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15031 */
15032 static inline int atomic_add_return(int i, atomic_t *v)
15033 {
15034+ return i + xadd_check_overflow(&v->counter, i);
15035+}
15036+
15037+/**
15038+ * atomic_add_return_unchecked - add integer and return
15039+ * @i: integer value to add
15040+ * @v: pointer of type atomic_unchecked_t
15041+ *
15042+ * Atomically adds @i to @v and returns @i + @v
15043+ */
15044+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15045+{
15046 return i + xadd(&v->counter, i);
15047 }
15048
15049@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15050 }
15051
15052 #define atomic_inc_return(v) (atomic_add_return(1, v))
15053+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15054+{
15055+ return atomic_add_return_unchecked(1, v);
15056+}
15057 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15058
15059-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15060+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15061+{
15062+ return cmpxchg(&v->counter, old, new);
15063+}
15064+
15065+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15066 {
15067 return cmpxchg(&v->counter, old, new);
15068 }
15069@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15070 return xchg(&v->counter, new);
15071 }
15072
15073+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15074+{
15075+ return xchg(&v->counter, new);
15076+}
15077+
15078 /**
15079 * __atomic_add_unless - add unless the number is already a given value
15080 * @v: pointer of type atomic_t
15081@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15082 * Atomically adds @a to @v, so long as @v was not already @u.
15083 * Returns the old value of @v.
15084 */
15085-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15086+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15087 {
15088- int c, old;
15089+ int c, old, new;
15090 c = atomic_read(v);
15091 for (;;) {
15092- if (unlikely(c == (u)))
15093+ if (unlikely(c == u))
15094 break;
15095- old = atomic_cmpxchg((v), c, c + (a));
15096+
15097+ asm volatile("addl %2,%0\n"
15098+
15099+#ifdef CONFIG_PAX_REFCOUNT
15100+ "jno 0f\n"
15101+ "subl %2,%0\n"
15102+ "int $4\n0:\n"
15103+ _ASM_EXTABLE(0b, 0b)
15104+#endif
15105+
15106+ : "=r" (new)
15107+ : "0" (c), "ir" (a));
15108+
15109+ old = atomic_cmpxchg(v, c, new);
15110 if (likely(old == c))
15111 break;
15112 c = old;
15113@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15114 }
15115
15116 /**
15117+ * atomic_inc_not_zero_hint - increment if not null
15118+ * @v: pointer of type atomic_t
15119+ * @hint: probable value of the atomic before the increment
15120+ *
15121+ * This version of atomic_inc_not_zero() gives a hint of probable
15122+ * value of the atomic. This helps processor to not read the memory
15123+ * before doing the atomic read/modify/write cycle, lowering
15124+ * number of bus transactions on some arches.
15125+ *
15126+ * Returns: 0 if increment was not done, 1 otherwise.
15127+ */
15128+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15129+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15130+{
15131+ int val, c = hint, new;
15132+
15133+ /* sanity test, should be removed by compiler if hint is a constant */
15134+ if (!hint)
15135+ return __atomic_add_unless(v, 1, 0);
15136+
15137+ do {
15138+ asm volatile("incl %0\n"
15139+
15140+#ifdef CONFIG_PAX_REFCOUNT
15141+ "jno 0f\n"
15142+ "decl %0\n"
15143+ "int $4\n0:\n"
15144+ _ASM_EXTABLE(0b, 0b)
15145+#endif
15146+
15147+ : "=r" (new)
15148+ : "0" (c));
15149+
15150+ val = atomic_cmpxchg(v, c, new);
15151+ if (val == c)
15152+ return 1;
15153+ c = val;
15154+ } while (c);
15155+
15156+ return 0;
15157+}
15158+
15159+/**
15160 * atomic_inc_short - increment of a short integer
15161 * @v: pointer to type int
15162 *
15163@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15164 #endif
15165
15166 /* These are x86-specific, used by some header files */
15167-#define atomic_clear_mask(mask, addr) \
15168- asm volatile(LOCK_PREFIX "andl %0,%1" \
15169- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15170+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15171+{
15172+ asm volatile(LOCK_PREFIX "andl %1,%0"
15173+ : "+m" (v->counter)
15174+ : "r" (~(mask))
15175+ : "memory");
15176+}
15177
15178-#define atomic_set_mask(mask, addr) \
15179- asm volatile(LOCK_PREFIX "orl %0,%1" \
15180- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15181- : "memory")
15182+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15183+{
15184+ asm volatile(LOCK_PREFIX "andl %1,%0"
15185+ : "+m" (v->counter)
15186+ : "r" (~(mask))
15187+ : "memory");
15188+}
15189+
15190+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15191+{
15192+ asm volatile(LOCK_PREFIX "orl %1,%0"
15193+ : "+m" (v->counter)
15194+ : "r" (mask)
15195+ : "memory");
15196+}
15197+
15198+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15199+{
15200+ asm volatile(LOCK_PREFIX "orl %1,%0"
15201+ : "+m" (v->counter)
15202+ : "r" (mask)
15203+ : "memory");
15204+}
15205
15206 /* Atomic operations are already serializing on x86 */
15207 #define smp_mb__before_atomic_dec() barrier()
15208diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15209index b154de7..bf18a5a 100644
15210--- a/arch/x86/include/asm/atomic64_32.h
15211+++ b/arch/x86/include/asm/atomic64_32.h
15212@@ -12,6 +12,14 @@ typedef struct {
15213 u64 __aligned(8) counter;
15214 } atomic64_t;
15215
15216+#ifdef CONFIG_PAX_REFCOUNT
15217+typedef struct {
15218+ u64 __aligned(8) counter;
15219+} atomic64_unchecked_t;
15220+#else
15221+typedef atomic64_t atomic64_unchecked_t;
15222+#endif
15223+
15224 #define ATOMIC64_INIT(val) { (val) }
15225
15226 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15227@@ -37,21 +45,31 @@ typedef struct {
15228 ATOMIC64_DECL_ONE(sym##_386)
15229
15230 ATOMIC64_DECL_ONE(add_386);
15231+ATOMIC64_DECL_ONE(add_unchecked_386);
15232 ATOMIC64_DECL_ONE(sub_386);
15233+ATOMIC64_DECL_ONE(sub_unchecked_386);
15234 ATOMIC64_DECL_ONE(inc_386);
15235+ATOMIC64_DECL_ONE(inc_unchecked_386);
15236 ATOMIC64_DECL_ONE(dec_386);
15237+ATOMIC64_DECL_ONE(dec_unchecked_386);
15238 #endif
15239
15240 #define alternative_atomic64(f, out, in...) \
15241 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15242
15243 ATOMIC64_DECL(read);
15244+ATOMIC64_DECL(read_unchecked);
15245 ATOMIC64_DECL(set);
15246+ATOMIC64_DECL(set_unchecked);
15247 ATOMIC64_DECL(xchg);
15248 ATOMIC64_DECL(add_return);
15249+ATOMIC64_DECL(add_return_unchecked);
15250 ATOMIC64_DECL(sub_return);
15251+ATOMIC64_DECL(sub_return_unchecked);
15252 ATOMIC64_DECL(inc_return);
15253+ATOMIC64_DECL(inc_return_unchecked);
15254 ATOMIC64_DECL(dec_return);
15255+ATOMIC64_DECL(dec_return_unchecked);
15256 ATOMIC64_DECL(dec_if_positive);
15257 ATOMIC64_DECL(inc_not_zero);
15258 ATOMIC64_DECL(add_unless);
15259@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15260 }
15261
15262 /**
15263+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15264+ * @p: pointer to type atomic64_unchecked_t
15265+ * @o: expected value
15266+ * @n: new value
15267+ *
15268+ * Atomically sets @v to @n if it was equal to @o and returns
15269+ * the old value.
15270+ */
15271+
15272+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15273+{
15274+ return cmpxchg64(&v->counter, o, n);
15275+}
15276+
15277+/**
15278 * atomic64_xchg - xchg atomic64 variable
15279 * @v: pointer to type atomic64_t
15280 * @n: value to assign
15281@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15282 }
15283
15284 /**
15285+ * atomic64_set_unchecked - set atomic64 variable
15286+ * @v: pointer to type atomic64_unchecked_t
15287+ * @n: value to assign
15288+ *
15289+ * Atomically sets the value of @v to @n.
15290+ */
15291+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15292+{
15293+ unsigned high = (unsigned)(i >> 32);
15294+ unsigned low = (unsigned)i;
15295+ alternative_atomic64(set, /* no output */,
15296+ "S" (v), "b" (low), "c" (high)
15297+ : "eax", "edx", "memory");
15298+}
15299+
15300+/**
15301 * atomic64_read - read atomic64 variable
15302 * @v: pointer to type atomic64_t
15303 *
15304@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15305 }
15306
15307 /**
15308+ * atomic64_read_unchecked - read atomic64 variable
15309+ * @v: pointer to type atomic64_unchecked_t
15310+ *
15311+ * Atomically reads the value of @v and returns it.
15312+ */
15313+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15314+{
15315+ long long r;
15316+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15317+ return r;
15318+ }
15319+
15320+/**
15321 * atomic64_add_return - add and return
15322 * @i: integer value to add
15323 * @v: pointer to type atomic64_t
15324@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15325 return i;
15326 }
15327
15328+/**
15329+ * atomic64_add_return_unchecked - add and return
15330+ * @i: integer value to add
15331+ * @v: pointer to type atomic64_unchecked_t
15332+ *
15333+ * Atomically adds @i to @v and returns @i + *@v
15334+ */
15335+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15336+{
15337+ alternative_atomic64(add_return_unchecked,
15338+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15339+ ASM_NO_INPUT_CLOBBER("memory"));
15340+ return i;
15341+}
15342+
15343 /*
15344 * Other variants with different arithmetic operators:
15345 */
15346@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15347 return a;
15348 }
15349
15350+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15351+{
15352+ long long a;
15353+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15354+ "S" (v) : "memory", "ecx");
15355+ return a;
15356+}
15357+
15358 static inline long long atomic64_dec_return(atomic64_t *v)
15359 {
15360 long long a;
15361@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15362 }
15363
15364 /**
15365+ * atomic64_add_unchecked - add integer to atomic64 variable
15366+ * @i: integer value to add
15367+ * @v: pointer to type atomic64_unchecked_t
15368+ *
15369+ * Atomically adds @i to @v.
15370+ */
15371+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15372+{
15373+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15374+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15375+ ASM_NO_INPUT_CLOBBER("memory"));
15376+ return i;
15377+}
15378+
15379+/**
15380 * atomic64_sub - subtract the atomic64 variable
15381 * @i: integer value to subtract
15382 * @v: pointer to type atomic64_t
15383diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15384index 46e9052..ae45136 100644
15385--- a/arch/x86/include/asm/atomic64_64.h
15386+++ b/arch/x86/include/asm/atomic64_64.h
15387@@ -18,7 +18,19 @@
15388 */
15389 static inline long atomic64_read(const atomic64_t *v)
15390 {
15391- return (*(volatile long *)&(v)->counter);
15392+ return (*(volatile const long *)&(v)->counter);
15393+}
15394+
15395+/**
15396+ * atomic64_read_unchecked - read atomic64 variable
15397+ * @v: pointer of type atomic64_unchecked_t
15398+ *
15399+ * Atomically reads the value of @v.
15400+ * Doesn't imply a read memory barrier.
15401+ */
15402+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15403+{
15404+ return (*(volatile const long *)&(v)->counter);
15405 }
15406
15407 /**
15408@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15409 }
15410
15411 /**
15412+ * atomic64_set_unchecked - set atomic64 variable
15413+ * @v: pointer to type atomic64_unchecked_t
15414+ * @i: required value
15415+ *
15416+ * Atomically sets the value of @v to @i.
15417+ */
15418+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15419+{
15420+ v->counter = i;
15421+}
15422+
15423+/**
15424 * atomic64_add - add integer to atomic64 variable
15425 * @i: integer value to add
15426 * @v: pointer to type atomic64_t
15427@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15428 */
15429 static inline void atomic64_add(long i, atomic64_t *v)
15430 {
15431+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15432+
15433+#ifdef CONFIG_PAX_REFCOUNT
15434+ "jno 0f\n"
15435+ LOCK_PREFIX "subq %1,%0\n"
15436+ "int $4\n0:\n"
15437+ _ASM_EXTABLE(0b, 0b)
15438+#endif
15439+
15440+ : "=m" (v->counter)
15441+ : "er" (i), "m" (v->counter));
15442+}
15443+
15444+/**
15445+ * atomic64_add_unchecked - add integer to atomic64 variable
15446+ * @i: integer value to add
15447+ * @v: pointer to type atomic64_unchecked_t
15448+ *
15449+ * Atomically adds @i to @v.
15450+ */
15451+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15452+{
15453 asm volatile(LOCK_PREFIX "addq %1,%0"
15454 : "=m" (v->counter)
15455 : "er" (i), "m" (v->counter));
15456@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15457 */
15458 static inline void atomic64_sub(long i, atomic64_t *v)
15459 {
15460- asm volatile(LOCK_PREFIX "subq %1,%0"
15461+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15462+
15463+#ifdef CONFIG_PAX_REFCOUNT
15464+ "jno 0f\n"
15465+ LOCK_PREFIX "addq %1,%0\n"
15466+ "int $4\n0:\n"
15467+ _ASM_EXTABLE(0b, 0b)
15468+#endif
15469+
15470+ : "=m" (v->counter)
15471+ : "er" (i), "m" (v->counter));
15472+}
15473+
15474+/**
15475+ * atomic64_sub_unchecked - subtract the atomic64 variable
15476+ * @i: integer value to subtract
15477+ * @v: pointer to type atomic64_unchecked_t
15478+ *
15479+ * Atomically subtracts @i from @v.
15480+ */
15481+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15482+{
15483+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15484 : "=m" (v->counter)
15485 : "er" (i), "m" (v->counter));
15486 }
15487@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15488 */
15489 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15490 {
15491- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15492+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15493 }
15494
15495 /**
15496@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15497 */
15498 static inline void atomic64_inc(atomic64_t *v)
15499 {
15500+ asm volatile(LOCK_PREFIX "incq %0\n"
15501+
15502+#ifdef CONFIG_PAX_REFCOUNT
15503+ "jno 0f\n"
15504+ LOCK_PREFIX "decq %0\n"
15505+ "int $4\n0:\n"
15506+ _ASM_EXTABLE(0b, 0b)
15507+#endif
15508+
15509+ : "=m" (v->counter)
15510+ : "m" (v->counter));
15511+}
15512+
15513+/**
15514+ * atomic64_inc_unchecked - increment atomic64 variable
15515+ * @v: pointer to type atomic64_unchecked_t
15516+ *
15517+ * Atomically increments @v by 1.
15518+ */
15519+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15520+{
15521 asm volatile(LOCK_PREFIX "incq %0"
15522 : "=m" (v->counter)
15523 : "m" (v->counter));
15524@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15525 */
15526 static inline void atomic64_dec(atomic64_t *v)
15527 {
15528- asm volatile(LOCK_PREFIX "decq %0"
15529+ asm volatile(LOCK_PREFIX "decq %0\n"
15530+
15531+#ifdef CONFIG_PAX_REFCOUNT
15532+ "jno 0f\n"
15533+ LOCK_PREFIX "incq %0\n"
15534+ "int $4\n0:\n"
15535+ _ASM_EXTABLE(0b, 0b)
15536+#endif
15537+
15538+ : "=m" (v->counter)
15539+ : "m" (v->counter));
15540+}
15541+
15542+/**
15543+ * atomic64_dec_unchecked - decrement atomic64 variable
15544+ * @v: pointer to type atomic64_t
15545+ *
15546+ * Atomically decrements @v by 1.
15547+ */
15548+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15549+{
15550+ asm volatile(LOCK_PREFIX "decq %0\n"
15551 : "=m" (v->counter)
15552 : "m" (v->counter));
15553 }
15554@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15555 */
15556 static inline int atomic64_dec_and_test(atomic64_t *v)
15557 {
15558- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15559+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15560 }
15561
15562 /**
15563@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15564 */
15565 static inline int atomic64_inc_and_test(atomic64_t *v)
15566 {
15567- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15568+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15569 }
15570
15571 /**
15572@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15573 */
15574 static inline int atomic64_add_negative(long i, atomic64_t *v)
15575 {
15576- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15577+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15578 }
15579
15580 /**
15581@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15582 */
15583 static inline long atomic64_add_return(long i, atomic64_t *v)
15584 {
15585+ return i + xadd_check_overflow(&v->counter, i);
15586+}
15587+
15588+/**
15589+ * atomic64_add_return_unchecked - add and return
15590+ * @i: integer value to add
15591+ * @v: pointer to type atomic64_unchecked_t
15592+ *
15593+ * Atomically adds @i to @v and returns @i + @v
15594+ */
15595+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15596+{
15597 return i + xadd(&v->counter, i);
15598 }
15599
15600@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15601 }
15602
15603 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15604+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15605+{
15606+ return atomic64_add_return_unchecked(1, v);
15607+}
15608 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15609
15610 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15611@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15612 return cmpxchg(&v->counter, old, new);
15613 }
15614
15615+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15616+{
15617+ return cmpxchg(&v->counter, old, new);
15618+}
15619+
15620 static inline long atomic64_xchg(atomic64_t *v, long new)
15621 {
15622 return xchg(&v->counter, new);
15623@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15624 */
15625 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15626 {
15627- long c, old;
15628+ long c, old, new;
15629 c = atomic64_read(v);
15630 for (;;) {
15631- if (unlikely(c == (u)))
15632+ if (unlikely(c == u))
15633 break;
15634- old = atomic64_cmpxchg((v), c, c + (a));
15635+
15636+ asm volatile("add %2,%0\n"
15637+
15638+#ifdef CONFIG_PAX_REFCOUNT
15639+ "jno 0f\n"
15640+ "sub %2,%0\n"
15641+ "int $4\n0:\n"
15642+ _ASM_EXTABLE(0b, 0b)
15643+#endif
15644+
15645+ : "=r" (new)
15646+ : "0" (c), "ir" (a));
15647+
15648+ old = atomic64_cmpxchg(v, c, new);
15649 if (likely(old == c))
15650 break;
15651 c = old;
15652 }
15653- return c != (u);
15654+ return c != u;
15655 }
15656
15657 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15658diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15659index 9fc1af7..fc71228 100644
15660--- a/arch/x86/include/asm/bitops.h
15661+++ b/arch/x86/include/asm/bitops.h
15662@@ -49,7 +49,7 @@
15663 * a mask operation on a byte.
15664 */
15665 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15666-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15667+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15668 #define CONST_MASK(nr) (1 << ((nr) & 7))
15669
15670 /**
15671@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15672 */
15673 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15674 {
15675- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15676+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15677 }
15678
15679 /**
15680@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15681 */
15682 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15683 {
15684- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15685+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15686 }
15687
15688 /**
15689@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15690 */
15691 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15692 {
15693- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15694+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15695 }
15696
15697 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15698@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15699 *
15700 * Undefined if no bit exists, so code should check against 0 first.
15701 */
15702-static inline unsigned long __ffs(unsigned long word)
15703+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15704 {
15705 asm("rep; bsf %1,%0"
15706 : "=r" (word)
15707@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15708 *
15709 * Undefined if no zero exists, so code should check against ~0UL first.
15710 */
15711-static inline unsigned long ffz(unsigned long word)
15712+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15713 {
15714 asm("rep; bsf %1,%0"
15715 : "=r" (word)
15716@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15717 *
15718 * Undefined if no set bit exists, so code should check against 0 first.
15719 */
15720-static inline unsigned long __fls(unsigned long word)
15721+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15722 {
15723 asm("bsr %1,%0"
15724 : "=r" (word)
15725@@ -436,7 +436,7 @@ static inline int ffs(int x)
15726 * set bit if value is nonzero. The last (most significant) bit is
15727 * at position 32.
15728 */
15729-static inline int fls(int x)
15730+static inline int __intentional_overflow(-1) fls(int x)
15731 {
15732 int r;
15733
15734@@ -478,7 +478,7 @@ static inline int fls(int x)
15735 * at position 64.
15736 */
15737 #ifdef CONFIG_X86_64
15738-static __always_inline int fls64(__u64 x)
15739+static __always_inline long fls64(__u64 x)
15740 {
15741 int bitpos = -1;
15742 /*
15743diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15744index 4fa687a..60f2d39 100644
15745--- a/arch/x86/include/asm/boot.h
15746+++ b/arch/x86/include/asm/boot.h
15747@@ -6,10 +6,15 @@
15748 #include <uapi/asm/boot.h>
15749
15750 /* Physical address where kernel should be loaded. */
15751-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15752+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15753 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15754 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15755
15756+#ifndef __ASSEMBLY__
15757+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15758+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15759+#endif
15760+
15761 /* Minimum kernel alignment, as a power of two */
15762 #ifdef CONFIG_X86_64
15763 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15764diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15765index 48f99f1..d78ebf9 100644
15766--- a/arch/x86/include/asm/cache.h
15767+++ b/arch/x86/include/asm/cache.h
15768@@ -5,12 +5,13 @@
15769
15770 /* L1 cache line size */
15771 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15772-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15773+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15774
15775 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15776+#define __read_only __attribute__((__section__(".data..read_only")))
15777
15778 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15779-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15780+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15781
15782 #ifdef CONFIG_X86_VSMP
15783 #ifdef CONFIG_SMP
15784diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15785index 9863ee3..4a1f8e1 100644
15786--- a/arch/x86/include/asm/cacheflush.h
15787+++ b/arch/x86/include/asm/cacheflush.h
15788@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15789 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15790
15791 if (pg_flags == _PGMT_DEFAULT)
15792- return -1;
15793+ return ~0UL;
15794 else if (pg_flags == _PGMT_WC)
15795 return _PAGE_CACHE_WC;
15796 else if (pg_flags == _PGMT_UC_MINUS)
15797diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15798index cb4c73b..c473c29 100644
15799--- a/arch/x86/include/asm/calling.h
15800+++ b/arch/x86/include/asm/calling.h
15801@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15802 #define RSP 152
15803 #define SS 160
15804
15805-#define ARGOFFSET R11
15806-#define SWFRAME ORIG_RAX
15807+#define ARGOFFSET R15
15808
15809 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15810- subq $9*8+\addskip, %rsp
15811- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15812- movq_cfi rdi, 8*8
15813- movq_cfi rsi, 7*8
15814- movq_cfi rdx, 6*8
15815+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15816+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15817+ movq_cfi rdi, RDI
15818+ movq_cfi rsi, RSI
15819+ movq_cfi rdx, RDX
15820
15821 .if \save_rcx
15822- movq_cfi rcx, 5*8
15823+ movq_cfi rcx, RCX
15824 .endif
15825
15826- movq_cfi rax, 4*8
15827+ movq_cfi rax, RAX
15828
15829 .if \save_r891011
15830- movq_cfi r8, 3*8
15831- movq_cfi r9, 2*8
15832- movq_cfi r10, 1*8
15833- movq_cfi r11, 0*8
15834+ movq_cfi r8, R8
15835+ movq_cfi r9, R9
15836+ movq_cfi r10, R10
15837+ movq_cfi r11, R11
15838 .endif
15839
15840+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15841+ movq_cfi r12, R12
15842+#endif
15843+
15844 .endm
15845
15846-#define ARG_SKIP (9*8)
15847+#define ARG_SKIP ORIG_RAX
15848
15849 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15850 rstor_r8910=1, rstor_rdx=1
15851+
15852+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15853+ movq_cfi_restore R12, r12
15854+#endif
15855+
15856 .if \rstor_r11
15857- movq_cfi_restore 0*8, r11
15858+ movq_cfi_restore R11, r11
15859 .endif
15860
15861 .if \rstor_r8910
15862- movq_cfi_restore 1*8, r10
15863- movq_cfi_restore 2*8, r9
15864- movq_cfi_restore 3*8, r8
15865+ movq_cfi_restore R10, r10
15866+ movq_cfi_restore R9, r9
15867+ movq_cfi_restore R8, r8
15868 .endif
15869
15870 .if \rstor_rax
15871- movq_cfi_restore 4*8, rax
15872+ movq_cfi_restore RAX, rax
15873 .endif
15874
15875 .if \rstor_rcx
15876- movq_cfi_restore 5*8, rcx
15877+ movq_cfi_restore RCX, rcx
15878 .endif
15879
15880 .if \rstor_rdx
15881- movq_cfi_restore 6*8, rdx
15882+ movq_cfi_restore RDX, rdx
15883 .endif
15884
15885- movq_cfi_restore 7*8, rsi
15886- movq_cfi_restore 8*8, rdi
15887+ movq_cfi_restore RSI, rsi
15888+ movq_cfi_restore RDI, rdi
15889
15890- .if ARG_SKIP+\addskip > 0
15891- addq $ARG_SKIP+\addskip, %rsp
15892- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15893+ .if ORIG_RAX+\addskip > 0
15894+ addq $ORIG_RAX+\addskip, %rsp
15895+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15896 .endif
15897 .endm
15898
15899- .macro LOAD_ARGS offset, skiprax=0
15900- movq \offset(%rsp), %r11
15901- movq \offset+8(%rsp), %r10
15902- movq \offset+16(%rsp), %r9
15903- movq \offset+24(%rsp), %r8
15904- movq \offset+40(%rsp), %rcx
15905- movq \offset+48(%rsp), %rdx
15906- movq \offset+56(%rsp), %rsi
15907- movq \offset+64(%rsp), %rdi
15908+ .macro LOAD_ARGS skiprax=0
15909+ movq R11(%rsp), %r11
15910+ movq R10(%rsp), %r10
15911+ movq R9(%rsp), %r9
15912+ movq R8(%rsp), %r8
15913+ movq RCX(%rsp), %rcx
15914+ movq RDX(%rsp), %rdx
15915+ movq RSI(%rsp), %rsi
15916+ movq RDI(%rsp), %rdi
15917 .if \skiprax
15918 .else
15919- movq \offset+72(%rsp), %rax
15920+ movq RAX(%rsp), %rax
15921 .endif
15922 .endm
15923
15924-#define REST_SKIP (6*8)
15925-
15926 .macro SAVE_REST
15927- subq $REST_SKIP, %rsp
15928- CFI_ADJUST_CFA_OFFSET REST_SKIP
15929- movq_cfi rbx, 5*8
15930- movq_cfi rbp, 4*8
15931- movq_cfi r12, 3*8
15932- movq_cfi r13, 2*8
15933- movq_cfi r14, 1*8
15934- movq_cfi r15, 0*8
15935+ movq_cfi rbx, RBX
15936+ movq_cfi rbp, RBP
15937+
15938+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15939+ movq_cfi r12, R12
15940+#endif
15941+
15942+ movq_cfi r13, R13
15943+ movq_cfi r14, R14
15944+ movq_cfi r15, R15
15945 .endm
15946
15947 .macro RESTORE_REST
15948- movq_cfi_restore 0*8, r15
15949- movq_cfi_restore 1*8, r14
15950- movq_cfi_restore 2*8, r13
15951- movq_cfi_restore 3*8, r12
15952- movq_cfi_restore 4*8, rbp
15953- movq_cfi_restore 5*8, rbx
15954- addq $REST_SKIP, %rsp
15955- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15956+ movq_cfi_restore R15, r15
15957+ movq_cfi_restore R14, r14
15958+ movq_cfi_restore R13, r13
15959+
15960+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15961+ movq_cfi_restore R12, r12
15962+#endif
15963+
15964+ movq_cfi_restore RBP, rbp
15965+ movq_cfi_restore RBX, rbx
15966 .endm
15967
15968 .macro SAVE_ALL
15969diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15970index f50de69..2b0a458 100644
15971--- a/arch/x86/include/asm/checksum_32.h
15972+++ b/arch/x86/include/asm/checksum_32.h
15973@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15974 int len, __wsum sum,
15975 int *src_err_ptr, int *dst_err_ptr);
15976
15977+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15978+ int len, __wsum sum,
15979+ int *src_err_ptr, int *dst_err_ptr);
15980+
15981+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15982+ int len, __wsum sum,
15983+ int *src_err_ptr, int *dst_err_ptr);
15984+
15985 /*
15986 * Note: when you get a NULL pointer exception here this means someone
15987 * passed in an incorrect kernel address to one of these functions.
15988@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15989
15990 might_sleep();
15991 stac();
15992- ret = csum_partial_copy_generic((__force void *)src, dst,
15993+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15994 len, sum, err_ptr, NULL);
15995 clac();
15996
15997@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15998 might_sleep();
15999 if (access_ok(VERIFY_WRITE, dst, len)) {
16000 stac();
16001- ret = csum_partial_copy_generic(src, (__force void *)dst,
16002+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16003 len, sum, NULL, err_ptr);
16004 clac();
16005 return ret;
16006diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16007index d47786a..ce1b05d 100644
16008--- a/arch/x86/include/asm/cmpxchg.h
16009+++ b/arch/x86/include/asm/cmpxchg.h
16010@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16011 __compiletime_error("Bad argument size for cmpxchg");
16012 extern void __xadd_wrong_size(void)
16013 __compiletime_error("Bad argument size for xadd");
16014+extern void __xadd_check_overflow_wrong_size(void)
16015+ __compiletime_error("Bad argument size for xadd_check_overflow");
16016 extern void __add_wrong_size(void)
16017 __compiletime_error("Bad argument size for add");
16018+extern void __add_check_overflow_wrong_size(void)
16019+ __compiletime_error("Bad argument size for add_check_overflow");
16020
16021 /*
16022 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16023@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16024 __ret; \
16025 })
16026
16027+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16028+ ({ \
16029+ __typeof__ (*(ptr)) __ret = (arg); \
16030+ switch (sizeof(*(ptr))) { \
16031+ case __X86_CASE_L: \
16032+ asm volatile (lock #op "l %0, %1\n" \
16033+ "jno 0f\n" \
16034+ "mov %0,%1\n" \
16035+ "int $4\n0:\n" \
16036+ _ASM_EXTABLE(0b, 0b) \
16037+ : "+r" (__ret), "+m" (*(ptr)) \
16038+ : : "memory", "cc"); \
16039+ break; \
16040+ case __X86_CASE_Q: \
16041+ asm volatile (lock #op "q %q0, %1\n" \
16042+ "jno 0f\n" \
16043+ "mov %0,%1\n" \
16044+ "int $4\n0:\n" \
16045+ _ASM_EXTABLE(0b, 0b) \
16046+ : "+r" (__ret), "+m" (*(ptr)) \
16047+ : : "memory", "cc"); \
16048+ break; \
16049+ default: \
16050+ __ ## op ## _check_overflow_wrong_size(); \
16051+ } \
16052+ __ret; \
16053+ })
16054+
16055 /*
16056 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16057 * Since this is generally used to protect other memory information, we
16058@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16059 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16060 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16061
16062+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16063+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16064+
16065 #define __add(ptr, inc, lock) \
16066 ({ \
16067 __typeof__ (*(ptr)) __ret = (inc); \
16068diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16069index 59c6c40..5e0b22c 100644
16070--- a/arch/x86/include/asm/compat.h
16071+++ b/arch/x86/include/asm/compat.h
16072@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16073 typedef u32 compat_uint_t;
16074 typedef u32 compat_ulong_t;
16075 typedef u64 __attribute__((aligned(4))) compat_u64;
16076-typedef u32 compat_uptr_t;
16077+typedef u32 __user compat_uptr_t;
16078
16079 struct compat_timespec {
16080 compat_time_t tv_sec;
16081diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16082index 89270b4..f0abf8e 100644
16083--- a/arch/x86/include/asm/cpufeature.h
16084+++ b/arch/x86/include/asm/cpufeature.h
16085@@ -203,7 +203,7 @@
16086 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16087 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16088 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16089-
16090+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16091
16092 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16093 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16094@@ -211,7 +211,7 @@
16095 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16096 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16097 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16098-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16099+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16100 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16101 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16102 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16103@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16104 #undef cpu_has_centaur_mcr
16105 #define cpu_has_centaur_mcr 0
16106
16107+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16108 #endif /* CONFIG_X86_64 */
16109
16110 #if __GNUC__ >= 4
16111@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16112
16113 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16114 t_warn:
16115- warn_pre_alternatives();
16116+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16117+ warn_pre_alternatives();
16118 return false;
16119 #endif
16120
16121@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16122 ".section .discard,\"aw\",@progbits\n"
16123 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16124 ".previous\n"
16125- ".section .altinstr_replacement,\"ax\"\n"
16126+ ".section .altinstr_replacement,\"a\"\n"
16127 "3: movb $1,%0\n"
16128 "4:\n"
16129 ".previous\n"
16130@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16131 " .byte 2b - 1b\n" /* src len */
16132 " .byte 4f - 3f\n" /* repl len */
16133 ".previous\n"
16134- ".section .altinstr_replacement,\"ax\"\n"
16135+ ".section .altinstr_replacement,\"a\"\n"
16136 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16137 "4:\n"
16138 ".previous\n"
16139@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16140 ".section .discard,\"aw\",@progbits\n"
16141 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16142 ".previous\n"
16143- ".section .altinstr_replacement,\"ax\"\n"
16144+ ".section .altinstr_replacement,\"a\"\n"
16145 "3: movb $0,%0\n"
16146 "4:\n"
16147 ".previous\n"
16148@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16149 ".section .discard,\"aw\",@progbits\n"
16150 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16151 ".previous\n"
16152- ".section .altinstr_replacement,\"ax\"\n"
16153+ ".section .altinstr_replacement,\"a\"\n"
16154 "5: movb $1,%0\n"
16155 "6:\n"
16156 ".previous\n"
16157diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16158index 50d033a..37deb26 100644
16159--- a/arch/x86/include/asm/desc.h
16160+++ b/arch/x86/include/asm/desc.h
16161@@ -4,6 +4,7 @@
16162 #include <asm/desc_defs.h>
16163 #include <asm/ldt.h>
16164 #include <asm/mmu.h>
16165+#include <asm/pgtable.h>
16166
16167 #include <linux/smp.h>
16168 #include <linux/percpu.h>
16169@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16170
16171 desc->type = (info->read_exec_only ^ 1) << 1;
16172 desc->type |= info->contents << 2;
16173+ desc->type |= info->seg_not_present ^ 1;
16174
16175 desc->s = 1;
16176 desc->dpl = 0x3;
16177@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16178 }
16179
16180 extern struct desc_ptr idt_descr;
16181-extern gate_desc idt_table[];
16182-extern struct desc_ptr debug_idt_descr;
16183-extern gate_desc debug_idt_table[];
16184-
16185-struct gdt_page {
16186- struct desc_struct gdt[GDT_ENTRIES];
16187-} __attribute__((aligned(PAGE_SIZE)));
16188-
16189-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16190+extern gate_desc idt_table[IDT_ENTRIES];
16191+extern const struct desc_ptr debug_idt_descr;
16192+extern gate_desc debug_idt_table[IDT_ENTRIES];
16193
16194+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16195 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16196 {
16197- return per_cpu(gdt_page, cpu).gdt;
16198+ return cpu_gdt_table[cpu];
16199 }
16200
16201 #ifdef CONFIG_X86_64
16202@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16203 unsigned long base, unsigned dpl, unsigned flags,
16204 unsigned short seg)
16205 {
16206- gate->a = (seg << 16) | (base & 0xffff);
16207- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16208+ gate->gate.offset_low = base;
16209+ gate->gate.seg = seg;
16210+ gate->gate.reserved = 0;
16211+ gate->gate.type = type;
16212+ gate->gate.s = 0;
16213+ gate->gate.dpl = dpl;
16214+ gate->gate.p = 1;
16215+ gate->gate.offset_high = base >> 16;
16216 }
16217
16218 #endif
16219@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16220
16221 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16222 {
16223+ pax_open_kernel();
16224 memcpy(&idt[entry], gate, sizeof(*gate));
16225+ pax_close_kernel();
16226 }
16227
16228 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16229 {
16230+ pax_open_kernel();
16231 memcpy(&ldt[entry], desc, 8);
16232+ pax_close_kernel();
16233 }
16234
16235 static inline void
16236@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16237 default: size = sizeof(*gdt); break;
16238 }
16239
16240+ pax_open_kernel();
16241 memcpy(&gdt[entry], desc, size);
16242+ pax_close_kernel();
16243 }
16244
16245 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16246@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16247
16248 static inline void native_load_tr_desc(void)
16249 {
16250+ pax_open_kernel();
16251 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16252+ pax_close_kernel();
16253 }
16254
16255 static inline void native_load_gdt(const struct desc_ptr *dtr)
16256@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16257 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16258 unsigned int i;
16259
16260+ pax_open_kernel();
16261 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16262 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16263+ pax_close_kernel();
16264 }
16265
16266 #define _LDT_empty(info) \
16267@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16268 preempt_enable();
16269 }
16270
16271-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16272+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16273 {
16274 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16275 }
16276@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16277 }
16278
16279 #ifdef CONFIG_X86_64
16280-static inline void set_nmi_gate(int gate, void *addr)
16281+static inline void set_nmi_gate(int gate, const void *addr)
16282 {
16283 gate_desc s;
16284
16285@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16286 #endif
16287
16288 #ifdef CONFIG_TRACING
16289-extern struct desc_ptr trace_idt_descr;
16290-extern gate_desc trace_idt_table[];
16291+extern const struct desc_ptr trace_idt_descr;
16292+extern gate_desc trace_idt_table[IDT_ENTRIES];
16293 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16294 {
16295 write_idt_entry(trace_idt_table, entry, gate);
16296 }
16297
16298-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16299+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16300 unsigned dpl, unsigned ist, unsigned seg)
16301 {
16302 gate_desc s;
16303@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16304 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16305 #endif
16306
16307-static inline void _set_gate(int gate, unsigned type, void *addr,
16308+static inline void _set_gate(int gate, unsigned type, const void *addr,
16309 unsigned dpl, unsigned ist, unsigned seg)
16310 {
16311 gate_desc s;
16312@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16313 #define set_intr_gate(n, addr) \
16314 do { \
16315 BUG_ON((unsigned)n > 0xFF); \
16316- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16317+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16318 __KERNEL_CS); \
16319- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16320+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16321 0, 0, __KERNEL_CS); \
16322 } while (0)
16323
16324@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16325 /*
16326 * This routine sets up an interrupt gate at directory privilege level 3.
16327 */
16328-static inline void set_system_intr_gate(unsigned int n, void *addr)
16329+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16330 {
16331 BUG_ON((unsigned)n > 0xFF);
16332 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16333 }
16334
16335-static inline void set_system_trap_gate(unsigned int n, void *addr)
16336+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16337 {
16338 BUG_ON((unsigned)n > 0xFF);
16339 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16340 }
16341
16342-static inline void set_trap_gate(unsigned int n, void *addr)
16343+static inline void set_trap_gate(unsigned int n, const void *addr)
16344 {
16345 BUG_ON((unsigned)n > 0xFF);
16346 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16347@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16348 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16349 {
16350 BUG_ON((unsigned)n > 0xFF);
16351- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16352+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16353 }
16354
16355-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16356+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16357 {
16358 BUG_ON((unsigned)n > 0xFF);
16359 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16360 }
16361
16362-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16363+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16364 {
16365 BUG_ON((unsigned)n > 0xFF);
16366 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16367@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16368 else
16369 load_idt((const struct desc_ptr *)&idt_descr);
16370 }
16371+
16372+#ifdef CONFIG_X86_32
16373+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16374+{
16375+ struct desc_struct d;
16376+
16377+ if (likely(limit))
16378+ limit = (limit - 1UL) >> PAGE_SHIFT;
16379+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16380+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16381+}
16382+#endif
16383+
16384 #endif /* _ASM_X86_DESC_H */
16385diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16386index 278441f..b95a174 100644
16387--- a/arch/x86/include/asm/desc_defs.h
16388+++ b/arch/x86/include/asm/desc_defs.h
16389@@ -31,6 +31,12 @@ struct desc_struct {
16390 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16391 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16392 };
16393+ struct {
16394+ u16 offset_low;
16395+ u16 seg;
16396+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16397+ unsigned offset_high: 16;
16398+ } gate;
16399 };
16400 } __attribute__((packed));
16401
16402diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16403index ced283a..ffe04cc 100644
16404--- a/arch/x86/include/asm/div64.h
16405+++ b/arch/x86/include/asm/div64.h
16406@@ -39,7 +39,7 @@
16407 __mod; \
16408 })
16409
16410-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16411+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16412 {
16413 union {
16414 u64 v64;
16415diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16416index 9c999c1..3860cb8 100644
16417--- a/arch/x86/include/asm/elf.h
16418+++ b/arch/x86/include/asm/elf.h
16419@@ -243,7 +243,25 @@ extern int force_personality32;
16420 the loader. We need to make sure that it is out of the way of the program
16421 that it will "exec", and that there is sufficient room for the brk. */
16422
16423+#ifdef CONFIG_PAX_SEGMEXEC
16424+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16425+#else
16426 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16427+#endif
16428+
16429+#ifdef CONFIG_PAX_ASLR
16430+#ifdef CONFIG_X86_32
16431+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16432+
16433+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16434+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16435+#else
16436+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16437+
16438+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16439+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16440+#endif
16441+#endif
16442
16443 /* This yields a mask that user programs can use to figure out what
16444 instruction set this CPU supports. This could be done in user space,
16445@@ -296,16 +314,12 @@ do { \
16446
16447 #define ARCH_DLINFO \
16448 do { \
16449- if (vdso_enabled) \
16450- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16451- (unsigned long)current->mm->context.vdso); \
16452+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16453 } while (0)
16454
16455 #define ARCH_DLINFO_X32 \
16456 do { \
16457- if (vdso_enabled) \
16458- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16459- (unsigned long)current->mm->context.vdso); \
16460+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16461 } while (0)
16462
16463 #define AT_SYSINFO 32
16464@@ -320,7 +334,7 @@ else \
16465
16466 #endif /* !CONFIG_X86_32 */
16467
16468-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16469+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16470
16471 #define VDSO_ENTRY \
16472 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16473@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16474 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16475 #define compat_arch_setup_additional_pages syscall32_setup_pages
16476
16477-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16478-#define arch_randomize_brk arch_randomize_brk
16479-
16480 /*
16481 * True on X86_32 or when emulating IA32 on X86_64
16482 */
16483diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16484index 77a99ac..39ff7f5 100644
16485--- a/arch/x86/include/asm/emergency-restart.h
16486+++ b/arch/x86/include/asm/emergency-restart.h
16487@@ -1,6 +1,6 @@
16488 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16489 #define _ASM_X86_EMERGENCY_RESTART_H
16490
16491-extern void machine_emergency_restart(void);
16492+extern void machine_emergency_restart(void) __noreturn;
16493
16494 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16495diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16496index d3d7469..677ef72 100644
16497--- a/arch/x86/include/asm/floppy.h
16498+++ b/arch/x86/include/asm/floppy.h
16499@@ -229,18 +229,18 @@ static struct fd_routine_l {
16500 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16501 } fd_routine[] = {
16502 {
16503- request_dma,
16504- free_dma,
16505- get_dma_residue,
16506- dma_mem_alloc,
16507- hard_dma_setup
16508+ ._request_dma = request_dma,
16509+ ._free_dma = free_dma,
16510+ ._get_dma_residue = get_dma_residue,
16511+ ._dma_mem_alloc = dma_mem_alloc,
16512+ ._dma_setup = hard_dma_setup
16513 },
16514 {
16515- vdma_request_dma,
16516- vdma_nop,
16517- vdma_get_dma_residue,
16518- vdma_mem_alloc,
16519- vdma_dma_setup
16520+ ._request_dma = vdma_request_dma,
16521+ ._free_dma = vdma_nop,
16522+ ._get_dma_residue = vdma_get_dma_residue,
16523+ ._dma_mem_alloc = vdma_mem_alloc,
16524+ ._dma_setup = vdma_dma_setup
16525 }
16526 };
16527
16528diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16529index cea1c76..6c0d79b 100644
16530--- a/arch/x86/include/asm/fpu-internal.h
16531+++ b/arch/x86/include/asm/fpu-internal.h
16532@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16533 #define user_insn(insn, output, input...) \
16534 ({ \
16535 int err; \
16536+ pax_open_userland(); \
16537 asm volatile(ASM_STAC "\n" \
16538- "1:" #insn "\n\t" \
16539+ "1:" \
16540+ __copyuser_seg \
16541+ #insn "\n\t" \
16542 "2: " ASM_CLAC "\n" \
16543 ".section .fixup,\"ax\"\n" \
16544 "3: movl $-1,%[err]\n" \
16545@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16546 _ASM_EXTABLE(1b, 3b) \
16547 : [err] "=r" (err), output \
16548 : "0"(0), input); \
16549+ pax_close_userland(); \
16550 err; \
16551 })
16552
16553@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16554 "fnclex\n\t"
16555 "emms\n\t"
16556 "fildl %P[addr]" /* set F?P to defined value */
16557- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16558+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16559 }
16560
16561 return fpu_restore_checking(&tsk->thread.fpu);
16562diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16563index be27ba1..04a8801 100644
16564--- a/arch/x86/include/asm/futex.h
16565+++ b/arch/x86/include/asm/futex.h
16566@@ -12,6 +12,7 @@
16567 #include <asm/smap.h>
16568
16569 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16570+ typecheck(u32 __user *, uaddr); \
16571 asm volatile("\t" ASM_STAC "\n" \
16572 "1:\t" insn "\n" \
16573 "2:\t" ASM_CLAC "\n" \
16574@@ -20,15 +21,16 @@
16575 "\tjmp\t2b\n" \
16576 "\t.previous\n" \
16577 _ASM_EXTABLE(1b, 3b) \
16578- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16579+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16580 : "i" (-EFAULT), "0" (oparg), "1" (0))
16581
16582 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16583+ typecheck(u32 __user *, uaddr); \
16584 asm volatile("\t" ASM_STAC "\n" \
16585 "1:\tmovl %2, %0\n" \
16586 "\tmovl\t%0, %3\n" \
16587 "\t" insn "\n" \
16588- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16589+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16590 "\tjnz\t1b\n" \
16591 "3:\t" ASM_CLAC "\n" \
16592 "\t.section .fixup,\"ax\"\n" \
16593@@ -38,7 +40,7 @@
16594 _ASM_EXTABLE(1b, 4b) \
16595 _ASM_EXTABLE(2b, 4b) \
16596 : "=&a" (oldval), "=&r" (ret), \
16597- "+m" (*uaddr), "=&r" (tem) \
16598+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16599 : "r" (oparg), "i" (-EFAULT), "1" (0))
16600
16601 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16602@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16603
16604 pagefault_disable();
16605
16606+ pax_open_userland();
16607 switch (op) {
16608 case FUTEX_OP_SET:
16609- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16610+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16611 break;
16612 case FUTEX_OP_ADD:
16613- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16614+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16615 uaddr, oparg);
16616 break;
16617 case FUTEX_OP_OR:
16618@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16619 default:
16620 ret = -ENOSYS;
16621 }
16622+ pax_close_userland();
16623
16624 pagefault_enable();
16625
16626@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16627 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16628 return -EFAULT;
16629
16630+ pax_open_userland();
16631 asm volatile("\t" ASM_STAC "\n"
16632- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16633+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16634 "2:\t" ASM_CLAC "\n"
16635 "\t.section .fixup, \"ax\"\n"
16636 "3:\tmov %3, %0\n"
16637 "\tjmp 2b\n"
16638 "\t.previous\n"
16639 _ASM_EXTABLE(1b, 3b)
16640- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16641+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16642 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16643 : "memory"
16644 );
16645+ pax_close_userland();
16646
16647 *uval = oldval;
16648 return ret;
16649diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16650index cba45d9..86344ba 100644
16651--- a/arch/x86/include/asm/hw_irq.h
16652+++ b/arch/x86/include/asm/hw_irq.h
16653@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16654 extern void enable_IO_APIC(void);
16655
16656 /* Statistics */
16657-extern atomic_t irq_err_count;
16658-extern atomic_t irq_mis_count;
16659+extern atomic_unchecked_t irq_err_count;
16660+extern atomic_unchecked_t irq_mis_count;
16661
16662 /* EISA */
16663 extern void eisa_set_level_irq(unsigned int irq);
16664diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16665index a203659..9889f1c 100644
16666--- a/arch/x86/include/asm/i8259.h
16667+++ b/arch/x86/include/asm/i8259.h
16668@@ -62,7 +62,7 @@ struct legacy_pic {
16669 void (*init)(int auto_eoi);
16670 int (*irq_pending)(unsigned int irq);
16671 void (*make_irq)(unsigned int irq);
16672-};
16673+} __do_const;
16674
16675 extern struct legacy_pic *legacy_pic;
16676 extern struct legacy_pic null_legacy_pic;
16677diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16678index 34f69cb..6d95446 100644
16679--- a/arch/x86/include/asm/io.h
16680+++ b/arch/x86/include/asm/io.h
16681@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16682 "m" (*(volatile type __force *)addr) barrier); }
16683
16684 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16685-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16686-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16687+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16688+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16689
16690 build_mmio_read(__readb, "b", unsigned char, "=q", )
16691-build_mmio_read(__readw, "w", unsigned short, "=r", )
16692-build_mmio_read(__readl, "l", unsigned int, "=r", )
16693+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16694+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16695
16696 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16697 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16698@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16699 return ioremap_nocache(offset, size);
16700 }
16701
16702-extern void iounmap(volatile void __iomem *addr);
16703+extern void iounmap(const volatile void __iomem *addr);
16704
16705 extern void set_iounmap_nonlazy(void);
16706
16707@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16708
16709 #include <linux/vmalloc.h>
16710
16711+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16712+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16713+{
16714+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16715+}
16716+
16717+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16718+{
16719+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16720+}
16721+
16722 /*
16723 * Convert a virtual cached pointer to an uncached pointer
16724 */
16725diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16726index bba3cf8..06bc8da 100644
16727--- a/arch/x86/include/asm/irqflags.h
16728+++ b/arch/x86/include/asm/irqflags.h
16729@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16730 sti; \
16731 sysexit
16732
16733+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16734+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16735+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16736+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16737+
16738 #else
16739 #define INTERRUPT_RETURN iret
16740 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16741diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16742index 9454c16..e4100e3 100644
16743--- a/arch/x86/include/asm/kprobes.h
16744+++ b/arch/x86/include/asm/kprobes.h
16745@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16746 #define RELATIVEJUMP_SIZE 5
16747 #define RELATIVECALL_OPCODE 0xe8
16748 #define RELATIVE_ADDR_SIZE 4
16749-#define MAX_STACK_SIZE 64
16750-#define MIN_STACK_SIZE(ADDR) \
16751- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16752- THREAD_SIZE - (unsigned long)(ADDR))) \
16753- ? (MAX_STACK_SIZE) \
16754- : (((unsigned long)current_thread_info()) + \
16755- THREAD_SIZE - (unsigned long)(ADDR)))
16756+#define MAX_STACK_SIZE 64UL
16757+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16758
16759 #define flush_insn_slot(p) do { } while (0)
16760
16761diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16762index 4ad6560..75c7bdd 100644
16763--- a/arch/x86/include/asm/local.h
16764+++ b/arch/x86/include/asm/local.h
16765@@ -10,33 +10,97 @@ typedef struct {
16766 atomic_long_t a;
16767 } local_t;
16768
16769+typedef struct {
16770+ atomic_long_unchecked_t a;
16771+} local_unchecked_t;
16772+
16773 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16774
16775 #define local_read(l) atomic_long_read(&(l)->a)
16776+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16777 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16778+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16779
16780 static inline void local_inc(local_t *l)
16781 {
16782- asm volatile(_ASM_INC "%0"
16783+ asm volatile(_ASM_INC "%0\n"
16784+
16785+#ifdef CONFIG_PAX_REFCOUNT
16786+ "jno 0f\n"
16787+ _ASM_DEC "%0\n"
16788+ "int $4\n0:\n"
16789+ _ASM_EXTABLE(0b, 0b)
16790+#endif
16791+
16792+ : "+m" (l->a.counter));
16793+}
16794+
16795+static inline void local_inc_unchecked(local_unchecked_t *l)
16796+{
16797+ asm volatile(_ASM_INC "%0\n"
16798 : "+m" (l->a.counter));
16799 }
16800
16801 static inline void local_dec(local_t *l)
16802 {
16803- asm volatile(_ASM_DEC "%0"
16804+ asm volatile(_ASM_DEC "%0\n"
16805+
16806+#ifdef CONFIG_PAX_REFCOUNT
16807+ "jno 0f\n"
16808+ _ASM_INC "%0\n"
16809+ "int $4\n0:\n"
16810+ _ASM_EXTABLE(0b, 0b)
16811+#endif
16812+
16813+ : "+m" (l->a.counter));
16814+}
16815+
16816+static inline void local_dec_unchecked(local_unchecked_t *l)
16817+{
16818+ asm volatile(_ASM_DEC "%0\n"
16819 : "+m" (l->a.counter));
16820 }
16821
16822 static inline void local_add(long i, local_t *l)
16823 {
16824- asm volatile(_ASM_ADD "%1,%0"
16825+ asm volatile(_ASM_ADD "%1,%0\n"
16826+
16827+#ifdef CONFIG_PAX_REFCOUNT
16828+ "jno 0f\n"
16829+ _ASM_SUB "%1,%0\n"
16830+ "int $4\n0:\n"
16831+ _ASM_EXTABLE(0b, 0b)
16832+#endif
16833+
16834+ : "+m" (l->a.counter)
16835+ : "ir" (i));
16836+}
16837+
16838+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16839+{
16840+ asm volatile(_ASM_ADD "%1,%0\n"
16841 : "+m" (l->a.counter)
16842 : "ir" (i));
16843 }
16844
16845 static inline void local_sub(long i, local_t *l)
16846 {
16847- asm volatile(_ASM_SUB "%1,%0"
16848+ asm volatile(_ASM_SUB "%1,%0\n"
16849+
16850+#ifdef CONFIG_PAX_REFCOUNT
16851+ "jno 0f\n"
16852+ _ASM_ADD "%1,%0\n"
16853+ "int $4\n0:\n"
16854+ _ASM_EXTABLE(0b, 0b)
16855+#endif
16856+
16857+ : "+m" (l->a.counter)
16858+ : "ir" (i));
16859+}
16860+
16861+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16862+{
16863+ asm volatile(_ASM_SUB "%1,%0\n"
16864 : "+m" (l->a.counter)
16865 : "ir" (i));
16866 }
16867@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16868 */
16869 static inline int local_sub_and_test(long i, local_t *l)
16870 {
16871- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16872+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16873 }
16874
16875 /**
16876@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16877 */
16878 static inline int local_dec_and_test(local_t *l)
16879 {
16880- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16881+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16882 }
16883
16884 /**
16885@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16886 */
16887 static inline int local_inc_and_test(local_t *l)
16888 {
16889- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16890+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16891 }
16892
16893 /**
16894@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16895 */
16896 static inline int local_add_negative(long i, local_t *l)
16897 {
16898- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16899+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16900 }
16901
16902 /**
16903@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16904 static inline long local_add_return(long i, local_t *l)
16905 {
16906 long __i = i;
16907+ asm volatile(_ASM_XADD "%0, %1\n"
16908+
16909+#ifdef CONFIG_PAX_REFCOUNT
16910+ "jno 0f\n"
16911+ _ASM_MOV "%0,%1\n"
16912+ "int $4\n0:\n"
16913+ _ASM_EXTABLE(0b, 0b)
16914+#endif
16915+
16916+ : "+r" (i), "+m" (l->a.counter)
16917+ : : "memory");
16918+ return i + __i;
16919+}
16920+
16921+/**
16922+ * local_add_return_unchecked - add and return
16923+ * @i: integer value to add
16924+ * @l: pointer to type local_unchecked_t
16925+ *
16926+ * Atomically adds @i to @l and returns @i + @l
16927+ */
16928+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16929+{
16930+ long __i = i;
16931 asm volatile(_ASM_XADD "%0, %1;"
16932 : "+r" (i), "+m" (l->a.counter)
16933 : : "memory");
16934@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16935
16936 #define local_cmpxchg(l, o, n) \
16937 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16938+#define local_cmpxchg_unchecked(l, o, n) \
16939+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16940 /* Always has a lock prefix */
16941 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16942
16943diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16944new file mode 100644
16945index 0000000..2bfd3ba
16946--- /dev/null
16947+++ b/arch/x86/include/asm/mman.h
16948@@ -0,0 +1,15 @@
16949+#ifndef _X86_MMAN_H
16950+#define _X86_MMAN_H
16951+
16952+#include <uapi/asm/mman.h>
16953+
16954+#ifdef __KERNEL__
16955+#ifndef __ASSEMBLY__
16956+#ifdef CONFIG_X86_32
16957+#define arch_mmap_check i386_mmap_check
16958+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16959+#endif
16960+#endif
16961+#endif
16962+
16963+#endif /* X86_MMAN_H */
16964diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16965index 5f55e69..e20bfb1 100644
16966--- a/arch/x86/include/asm/mmu.h
16967+++ b/arch/x86/include/asm/mmu.h
16968@@ -9,7 +9,7 @@
16969 * we put the segment information here.
16970 */
16971 typedef struct {
16972- void *ldt;
16973+ struct desc_struct *ldt;
16974 int size;
16975
16976 #ifdef CONFIG_X86_64
16977@@ -18,7 +18,19 @@ typedef struct {
16978 #endif
16979
16980 struct mutex lock;
16981- void *vdso;
16982+ unsigned long vdso;
16983+
16984+#ifdef CONFIG_X86_32
16985+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16986+ unsigned long user_cs_base;
16987+ unsigned long user_cs_limit;
16988+
16989+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16990+ cpumask_t cpu_user_cs_mask;
16991+#endif
16992+
16993+#endif
16994+#endif
16995 } mm_context_t;
16996
16997 #ifdef CONFIG_SMP
16998diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16999index be12c53..4d24039 100644
17000--- a/arch/x86/include/asm/mmu_context.h
17001+++ b/arch/x86/include/asm/mmu_context.h
17002@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17003
17004 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17005 {
17006+
17007+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17008+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17009+ unsigned int i;
17010+ pgd_t *pgd;
17011+
17012+ pax_open_kernel();
17013+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17014+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17015+ set_pgd_batched(pgd+i, native_make_pgd(0));
17016+ pax_close_kernel();
17017+ }
17018+#endif
17019+
17020 #ifdef CONFIG_SMP
17021 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17022 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17023@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17024 struct task_struct *tsk)
17025 {
17026 unsigned cpu = smp_processor_id();
17027+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17028+ int tlbstate = TLBSTATE_OK;
17029+#endif
17030
17031 if (likely(prev != next)) {
17032 #ifdef CONFIG_SMP
17033+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17034+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17035+#endif
17036 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17037 this_cpu_write(cpu_tlbstate.active_mm, next);
17038 #endif
17039 cpumask_set_cpu(cpu, mm_cpumask(next));
17040
17041 /* Re-load page tables */
17042+#ifdef CONFIG_PAX_PER_CPU_PGD
17043+ pax_open_kernel();
17044+
17045+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17046+ if (static_cpu_has(X86_FEATURE_PCID))
17047+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17048+ else
17049+#endif
17050+
17051+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17052+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17053+ pax_close_kernel();
17054+ 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));
17055+
17056+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17057+ if (static_cpu_has(X86_FEATURE_PCID)) {
17058+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17059+ u64 descriptor[2];
17060+ descriptor[0] = PCID_USER;
17061+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17062+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17063+ descriptor[0] = PCID_KERNEL;
17064+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17065+ }
17066+ } else {
17067+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17068+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17069+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17070+ else
17071+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17072+ }
17073+ } else
17074+#endif
17075+
17076+ load_cr3(get_cpu_pgd(cpu, kernel));
17077+#else
17078 load_cr3(next->pgd);
17079+#endif
17080
17081 /* Stop flush ipis for the previous mm */
17082 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17083@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17084 /* Load the LDT, if the LDT is different: */
17085 if (unlikely(prev->context.ldt != next->context.ldt))
17086 load_LDT_nolock(&next->context);
17087+
17088+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17089+ if (!(__supported_pte_mask & _PAGE_NX)) {
17090+ smp_mb__before_clear_bit();
17091+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17092+ smp_mb__after_clear_bit();
17093+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17094+ }
17095+#endif
17096+
17097+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17098+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17099+ prev->context.user_cs_limit != next->context.user_cs_limit))
17100+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17101+#ifdef CONFIG_SMP
17102+ else if (unlikely(tlbstate != TLBSTATE_OK))
17103+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17104+#endif
17105+#endif
17106+
17107 }
17108+ else {
17109+
17110+#ifdef CONFIG_PAX_PER_CPU_PGD
17111+ pax_open_kernel();
17112+
17113+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17114+ if (static_cpu_has(X86_FEATURE_PCID))
17115+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17116+ else
17117+#endif
17118+
17119+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17120+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17121+ pax_close_kernel();
17122+ 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));
17123+
17124+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17125+ if (static_cpu_has(X86_FEATURE_PCID)) {
17126+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17127+ u64 descriptor[2];
17128+ descriptor[0] = PCID_USER;
17129+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17130+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17131+ descriptor[0] = PCID_KERNEL;
17132+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17133+ }
17134+ } else {
17135+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17136+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17137+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17138+ else
17139+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17140+ }
17141+ } else
17142+#endif
17143+
17144+ load_cr3(get_cpu_pgd(cpu, kernel));
17145+#endif
17146+
17147 #ifdef CONFIG_SMP
17148- else {
17149 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17150 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17151
17152@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17153 * tlb flush IPI delivery. We must reload CR3
17154 * to make sure to use no freed page tables.
17155 */
17156+
17157+#ifndef CONFIG_PAX_PER_CPU_PGD
17158 load_cr3(next->pgd);
17159+#endif
17160+
17161 load_LDT_nolock(&next->context);
17162+
17163+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17164+ if (!(__supported_pte_mask & _PAGE_NX))
17165+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17166+#endif
17167+
17168+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17169+#ifdef CONFIG_PAX_PAGEEXEC
17170+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17171+#endif
17172+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17173+#endif
17174+
17175 }
17176+#endif
17177 }
17178-#endif
17179 }
17180
17181 #define activate_mm(prev, next) \
17182diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17183index e3b7819..b257c64 100644
17184--- a/arch/x86/include/asm/module.h
17185+++ b/arch/x86/include/asm/module.h
17186@@ -5,6 +5,7 @@
17187
17188 #ifdef CONFIG_X86_64
17189 /* X86_64 does not define MODULE_PROC_FAMILY */
17190+#define MODULE_PROC_FAMILY ""
17191 #elif defined CONFIG_M486
17192 #define MODULE_PROC_FAMILY "486 "
17193 #elif defined CONFIG_M586
17194@@ -57,8 +58,20 @@
17195 #error unknown processor family
17196 #endif
17197
17198-#ifdef CONFIG_X86_32
17199-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17200+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17201+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17202+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17203+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17204+#else
17205+#define MODULE_PAX_KERNEXEC ""
17206 #endif
17207
17208+#ifdef CONFIG_PAX_MEMORY_UDEREF
17209+#define MODULE_PAX_UDEREF "UDEREF "
17210+#else
17211+#define MODULE_PAX_UDEREF ""
17212+#endif
17213+
17214+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17215+
17216 #endif /* _ASM_X86_MODULE_H */
17217diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17218index 86f9301..b365cda 100644
17219--- a/arch/x86/include/asm/nmi.h
17220+++ b/arch/x86/include/asm/nmi.h
17221@@ -40,11 +40,11 @@ struct nmiaction {
17222 nmi_handler_t handler;
17223 unsigned long flags;
17224 const char *name;
17225-};
17226+} __do_const;
17227
17228 #define register_nmi_handler(t, fn, fg, n, init...) \
17229 ({ \
17230- static struct nmiaction init fn##_na = { \
17231+ static const struct nmiaction init fn##_na = { \
17232 .handler = (fn), \
17233 .name = (n), \
17234 .flags = (fg), \
17235@@ -52,7 +52,7 @@ struct nmiaction {
17236 __register_nmi_handler((t), &fn##_na); \
17237 })
17238
17239-int __register_nmi_handler(unsigned int, struct nmiaction *);
17240+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17241
17242 void unregister_nmi_handler(unsigned int, const char *);
17243
17244diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17245index c878924..21f4889 100644
17246--- a/arch/x86/include/asm/page.h
17247+++ b/arch/x86/include/asm/page.h
17248@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17249 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17250
17251 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17252+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17253
17254 #define __boot_va(x) __va(x)
17255 #define __boot_pa(x) __pa(x)
17256diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17257index 0f1ddee..e2fc3d1 100644
17258--- a/arch/x86/include/asm/page_64.h
17259+++ b/arch/x86/include/asm/page_64.h
17260@@ -7,9 +7,9 @@
17261
17262 /* duplicated to the one in bootmem.h */
17263 extern unsigned long max_pfn;
17264-extern unsigned long phys_base;
17265+extern const unsigned long phys_base;
17266
17267-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17268+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17269 {
17270 unsigned long y = x - __START_KERNEL_map;
17271
17272diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17273index 401f350..dee5d13 100644
17274--- a/arch/x86/include/asm/paravirt.h
17275+++ b/arch/x86/include/asm/paravirt.h
17276@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17277 return (pmd_t) { ret };
17278 }
17279
17280-static inline pmdval_t pmd_val(pmd_t pmd)
17281+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17282 {
17283 pmdval_t ret;
17284
17285@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17286 val);
17287 }
17288
17289+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17290+{
17291+ pgdval_t val = native_pgd_val(pgd);
17292+
17293+ if (sizeof(pgdval_t) > sizeof(long))
17294+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17295+ val, (u64)val >> 32);
17296+ else
17297+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17298+ val);
17299+}
17300+
17301 static inline void pgd_clear(pgd_t *pgdp)
17302 {
17303 set_pgd(pgdp, __pgd(0));
17304@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17305 pv_mmu_ops.set_fixmap(idx, phys, flags);
17306 }
17307
17308+#ifdef CONFIG_PAX_KERNEXEC
17309+static inline unsigned long pax_open_kernel(void)
17310+{
17311+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17312+}
17313+
17314+static inline unsigned long pax_close_kernel(void)
17315+{
17316+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17317+}
17318+#else
17319+static inline unsigned long pax_open_kernel(void) { return 0; }
17320+static inline unsigned long pax_close_kernel(void) { return 0; }
17321+#endif
17322+
17323 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17324
17325 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17326@@ -906,7 +933,7 @@ extern void default_banner(void);
17327
17328 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17329 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17330-#define PARA_INDIRECT(addr) *%cs:addr
17331+#define PARA_INDIRECT(addr) *%ss:addr
17332 #endif
17333
17334 #define INTERRUPT_RETURN \
17335@@ -981,6 +1008,21 @@ extern void default_banner(void);
17336 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17337 CLBR_NONE, \
17338 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17339+
17340+#define GET_CR0_INTO_RDI \
17341+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17342+ mov %rax,%rdi
17343+
17344+#define SET_RDI_INTO_CR0 \
17345+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17346+
17347+#define GET_CR3_INTO_RDI \
17348+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17349+ mov %rax,%rdi
17350+
17351+#define SET_RDI_INTO_CR3 \
17352+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17353+
17354 #endif /* CONFIG_X86_32 */
17355
17356 #endif /* __ASSEMBLY__ */
17357diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17358index aab8f67..0fb0ee4 100644
17359--- a/arch/x86/include/asm/paravirt_types.h
17360+++ b/arch/x86/include/asm/paravirt_types.h
17361@@ -84,7 +84,7 @@ struct pv_init_ops {
17362 */
17363 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17364 unsigned long addr, unsigned len);
17365-};
17366+} __no_const __no_randomize_layout;
17367
17368
17369 struct pv_lazy_ops {
17370@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17371 void (*enter)(void);
17372 void (*leave)(void);
17373 void (*flush)(void);
17374-};
17375+} __no_randomize_layout;
17376
17377 struct pv_time_ops {
17378 unsigned long long (*sched_clock)(void);
17379 unsigned long long (*steal_clock)(int cpu);
17380 unsigned long (*get_tsc_khz)(void);
17381-};
17382+} __no_const __no_randomize_layout;
17383
17384 struct pv_cpu_ops {
17385 /* hooks for various privileged instructions */
17386@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17387
17388 void (*start_context_switch)(struct task_struct *prev);
17389 void (*end_context_switch)(struct task_struct *next);
17390-};
17391+} __no_const __no_randomize_layout;
17392
17393 struct pv_irq_ops {
17394 /*
17395@@ -215,7 +215,7 @@ struct pv_irq_ops {
17396 #ifdef CONFIG_X86_64
17397 void (*adjust_exception_frame)(void);
17398 #endif
17399-};
17400+} __no_randomize_layout;
17401
17402 struct pv_apic_ops {
17403 #ifdef CONFIG_X86_LOCAL_APIC
17404@@ -223,7 +223,7 @@ struct pv_apic_ops {
17405 unsigned long start_eip,
17406 unsigned long start_esp);
17407 #endif
17408-};
17409+} __no_const __no_randomize_layout;
17410
17411 struct pv_mmu_ops {
17412 unsigned long (*read_cr2)(void);
17413@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17414 struct paravirt_callee_save make_pud;
17415
17416 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17417+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17418 #endif /* PAGETABLE_LEVELS == 4 */
17419 #endif /* PAGETABLE_LEVELS >= 3 */
17420
17421@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17422 an mfn. We can tell which is which from the index. */
17423 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17424 phys_addr_t phys, pgprot_t flags);
17425-};
17426+
17427+#ifdef CONFIG_PAX_KERNEXEC
17428+ unsigned long (*pax_open_kernel)(void);
17429+ unsigned long (*pax_close_kernel)(void);
17430+#endif
17431+
17432+} __no_randomize_layout;
17433
17434 struct arch_spinlock;
17435 #ifdef CONFIG_SMP
17436@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17437 struct pv_lock_ops {
17438 struct paravirt_callee_save lock_spinning;
17439 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17440-};
17441+} __no_randomize_layout;
17442
17443 /* This contains all the paravirt structures: we get a convenient
17444 * number for each function using the offset which we use to indicate
17445- * what to patch. */
17446+ * what to patch.
17447+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17448+ */
17449+
17450 struct paravirt_patch_template {
17451 struct pv_init_ops pv_init_ops;
17452 struct pv_time_ops pv_time_ops;
17453@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17454 struct pv_apic_ops pv_apic_ops;
17455 struct pv_mmu_ops pv_mmu_ops;
17456 struct pv_lock_ops pv_lock_ops;
17457-};
17458+} __no_randomize_layout;
17459
17460 extern struct pv_info pv_info;
17461 extern struct pv_init_ops pv_init_ops;
17462diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17463index c4412e9..90e88c5 100644
17464--- a/arch/x86/include/asm/pgalloc.h
17465+++ b/arch/x86/include/asm/pgalloc.h
17466@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17467 pmd_t *pmd, pte_t *pte)
17468 {
17469 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17470+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17471+}
17472+
17473+static inline void pmd_populate_user(struct mm_struct *mm,
17474+ pmd_t *pmd, pte_t *pte)
17475+{
17476+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17477 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17478 }
17479
17480@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17481
17482 #ifdef CONFIG_X86_PAE
17483 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17484+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17485+{
17486+ pud_populate(mm, pudp, pmd);
17487+}
17488 #else /* !CONFIG_X86_PAE */
17489 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17490 {
17491 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17492 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17493 }
17494+
17495+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17496+{
17497+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17498+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17499+}
17500 #endif /* CONFIG_X86_PAE */
17501
17502 #if PAGETABLE_LEVELS > 3
17503@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17504 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17505 }
17506
17507+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17508+{
17509+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17510+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17511+}
17512+
17513 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17514 {
17515 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17516diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17517index 3bf2dd0..23d2a9f 100644
17518--- a/arch/x86/include/asm/pgtable-2level.h
17519+++ b/arch/x86/include/asm/pgtable-2level.h
17520@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17521
17522 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17523 {
17524+ pax_open_kernel();
17525 *pmdp = pmd;
17526+ pax_close_kernel();
17527 }
17528
17529 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17530diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17531index 81bb91b..9392125 100644
17532--- a/arch/x86/include/asm/pgtable-3level.h
17533+++ b/arch/x86/include/asm/pgtable-3level.h
17534@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17535
17536 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17537 {
17538+ pax_open_kernel();
17539 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17540+ pax_close_kernel();
17541 }
17542
17543 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17544 {
17545+ pax_open_kernel();
17546 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17547+ pax_close_kernel();
17548 }
17549
17550 /*
17551diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17552index 5ad38ad..f228861 100644
17553--- a/arch/x86/include/asm/pgtable.h
17554+++ b/arch/x86/include/asm/pgtable.h
17555@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17556
17557 #ifndef __PAGETABLE_PUD_FOLDED
17558 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17559+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17560 #define pgd_clear(pgd) native_pgd_clear(pgd)
17561 #endif
17562
17563@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17564
17565 #define arch_end_context_switch(prev) do {} while(0)
17566
17567+#define pax_open_kernel() native_pax_open_kernel()
17568+#define pax_close_kernel() native_pax_close_kernel()
17569 #endif /* CONFIG_PARAVIRT */
17570
17571+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17572+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17573+
17574+#ifdef CONFIG_PAX_KERNEXEC
17575+static inline unsigned long native_pax_open_kernel(void)
17576+{
17577+ unsigned long cr0;
17578+
17579+ preempt_disable();
17580+ barrier();
17581+ cr0 = read_cr0() ^ X86_CR0_WP;
17582+ BUG_ON(cr0 & X86_CR0_WP);
17583+ write_cr0(cr0);
17584+ return cr0 ^ X86_CR0_WP;
17585+}
17586+
17587+static inline unsigned long native_pax_close_kernel(void)
17588+{
17589+ unsigned long cr0;
17590+
17591+ cr0 = read_cr0() ^ X86_CR0_WP;
17592+ BUG_ON(!(cr0 & X86_CR0_WP));
17593+ write_cr0(cr0);
17594+ barrier();
17595+ preempt_enable_no_resched();
17596+ return cr0 ^ X86_CR0_WP;
17597+}
17598+#else
17599+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17600+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17601+#endif
17602+
17603 /*
17604 * The following only work if pte_present() is true.
17605 * Undefined behaviour if not..
17606 */
17607+static inline int pte_user(pte_t pte)
17608+{
17609+ return pte_val(pte) & _PAGE_USER;
17610+}
17611+
17612 static inline int pte_dirty(pte_t pte)
17613 {
17614 return pte_flags(pte) & _PAGE_DIRTY;
17615@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17616 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17617 }
17618
17619+static inline unsigned long pgd_pfn(pgd_t pgd)
17620+{
17621+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17622+}
17623+
17624 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17625
17626 static inline int pmd_large(pmd_t pte)
17627@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17628 return pte_clear_flags(pte, _PAGE_RW);
17629 }
17630
17631+static inline pte_t pte_mkread(pte_t pte)
17632+{
17633+ return __pte(pte_val(pte) | _PAGE_USER);
17634+}
17635+
17636 static inline pte_t pte_mkexec(pte_t pte)
17637 {
17638- return pte_clear_flags(pte, _PAGE_NX);
17639+#ifdef CONFIG_X86_PAE
17640+ if (__supported_pte_mask & _PAGE_NX)
17641+ return pte_clear_flags(pte, _PAGE_NX);
17642+ else
17643+#endif
17644+ return pte_set_flags(pte, _PAGE_USER);
17645+}
17646+
17647+static inline pte_t pte_exprotect(pte_t pte)
17648+{
17649+#ifdef CONFIG_X86_PAE
17650+ if (__supported_pte_mask & _PAGE_NX)
17651+ return pte_set_flags(pte, _PAGE_NX);
17652+ else
17653+#endif
17654+ return pte_clear_flags(pte, _PAGE_USER);
17655 }
17656
17657 static inline pte_t pte_mkdirty(pte_t pte)
17658@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17659 #endif
17660
17661 #ifndef __ASSEMBLY__
17662+
17663+#ifdef CONFIG_PAX_PER_CPU_PGD
17664+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17665+enum cpu_pgd_type {kernel = 0, user = 1};
17666+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17667+{
17668+ return cpu_pgd[cpu][type];
17669+}
17670+#endif
17671+
17672 #include <linux/mm_types.h>
17673 #include <linux/mmdebug.h>
17674 #include <linux/log2.h>
17675@@ -445,20 +520,10 @@ static inline int pte_same(pte_t a, pte_t b)
17676 return a.pte == b.pte;
17677 }
17678
17679-static inline int pteval_present(pteval_t pteval)
17680-{
17681- /*
17682- * Yes Linus, _PAGE_PROTNONE == _PAGE_NUMA. Expressing it this
17683- * way clearly states that the intent is that protnone and numa
17684- * hinting ptes are considered present for the purposes of
17685- * pagetable operations like zapping, protection changes, gup etc.
17686- */
17687- return pteval & (_PAGE_PRESENT | _PAGE_PROTNONE | _PAGE_NUMA);
17688-}
17689-
17690 static inline int pte_present(pte_t a)
17691 {
17692- return pteval_present(pte_flags(a));
17693+ return pte_flags(a) & (_PAGE_PRESENT | _PAGE_PROTNONE |
17694+ _PAGE_NUMA);
17695 }
17696
17697 #define pte_accessible pte_accessible
17698@@ -580,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17699 * Currently stuck as a macro due to indirect forward reference to
17700 * linux/mmzone.h's __section_mem_map_addr() definition:
17701 */
17702-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17703+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17704
17705 /* Find an entry in the second-level page table.. */
17706 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17707@@ -620,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17708 * Currently stuck as a macro due to indirect forward reference to
17709 * linux/mmzone.h's __section_mem_map_addr() definition:
17710 */
17711-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17712+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17713
17714 /* to find an entry in a page-table-directory. */
17715 static inline unsigned long pud_index(unsigned long address)
17716@@ -635,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17717
17718 static inline int pgd_bad(pgd_t pgd)
17719 {
17720- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17721+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17722 }
17723
17724 static inline int pgd_none(pgd_t pgd)
17725@@ -658,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17726 * pgd_offset() returns a (pgd_t *)
17727 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17728 */
17729-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17730+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17731+
17732+#ifdef CONFIG_PAX_PER_CPU_PGD
17733+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17734+#endif
17735+
17736 /*
17737 * a shortcut which implies the use of the kernel's pgd, instead
17738 * of a process's
17739@@ -669,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17740 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17741 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17742
17743+#ifdef CONFIG_X86_32
17744+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17745+#else
17746+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17747+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17748+
17749+#ifdef CONFIG_PAX_MEMORY_UDEREF
17750+#ifdef __ASSEMBLY__
17751+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17752+#else
17753+extern unsigned long pax_user_shadow_base;
17754+extern pgdval_t clone_pgd_mask;
17755+#endif
17756+#endif
17757+
17758+#endif
17759+
17760 #ifndef __ASSEMBLY__
17761
17762 extern int direct_gbpages;
17763@@ -835,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17764 * dst and src can be on the same page, but the range must not overlap,
17765 * and must not cross a page boundary.
17766 */
17767-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17768+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17769 {
17770- memcpy(dst, src, count * sizeof(pgd_t));
17771+ pax_open_kernel();
17772+ while (count--)
17773+ *dst++ = *src++;
17774+ pax_close_kernel();
17775 }
17776
17777+#ifdef CONFIG_PAX_PER_CPU_PGD
17778+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17779+#endif
17780+
17781+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17782+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17783+#else
17784+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17785+#endif
17786+
17787 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17788 static inline int page_level_shift(enum pg_level level)
17789 {
17790diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17791index 9ee3221..b979c6b 100644
17792--- a/arch/x86/include/asm/pgtable_32.h
17793+++ b/arch/x86/include/asm/pgtable_32.h
17794@@ -25,9 +25,6 @@
17795 struct mm_struct;
17796 struct vm_area_struct;
17797
17798-extern pgd_t swapper_pg_dir[1024];
17799-extern pgd_t initial_page_table[1024];
17800-
17801 static inline void pgtable_cache_init(void) { }
17802 static inline void check_pgt_cache(void) { }
17803 void paging_init(void);
17804@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17805 # include <asm/pgtable-2level.h>
17806 #endif
17807
17808+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17809+extern pgd_t initial_page_table[PTRS_PER_PGD];
17810+#ifdef CONFIG_X86_PAE
17811+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17812+#endif
17813+
17814 #if defined(CONFIG_HIGHPTE)
17815 #define pte_offset_map(dir, address) \
17816 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17817@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17818 /* Clear a kernel PTE and flush it from the TLB */
17819 #define kpte_clear_flush(ptep, vaddr) \
17820 do { \
17821+ pax_open_kernel(); \
17822 pte_clear(&init_mm, (vaddr), (ptep)); \
17823+ pax_close_kernel(); \
17824 __flush_tlb_one((vaddr)); \
17825 } while (0)
17826
17827 #endif /* !__ASSEMBLY__ */
17828
17829+#define HAVE_ARCH_UNMAPPED_AREA
17830+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17831+
17832 /*
17833 * kern_addr_valid() is (1) for FLATMEM and (0) for
17834 * SPARSEMEM and DISCONTIGMEM
17835diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17836index ed5903b..c7fe163 100644
17837--- a/arch/x86/include/asm/pgtable_32_types.h
17838+++ b/arch/x86/include/asm/pgtable_32_types.h
17839@@ -8,7 +8,7 @@
17840 */
17841 #ifdef CONFIG_X86_PAE
17842 # include <asm/pgtable-3level_types.h>
17843-# define PMD_SIZE (1UL << PMD_SHIFT)
17844+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17845 # define PMD_MASK (~(PMD_SIZE - 1))
17846 #else
17847 # include <asm/pgtable-2level_types.h>
17848@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17849 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17850 #endif
17851
17852+#ifdef CONFIG_PAX_KERNEXEC
17853+#ifndef __ASSEMBLY__
17854+extern unsigned char MODULES_EXEC_VADDR[];
17855+extern unsigned char MODULES_EXEC_END[];
17856+#endif
17857+#include <asm/boot.h>
17858+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17859+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17860+#else
17861+#define ktla_ktva(addr) (addr)
17862+#define ktva_ktla(addr) (addr)
17863+#endif
17864+
17865 #define MODULES_VADDR VMALLOC_START
17866 #define MODULES_END VMALLOC_END
17867 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17868diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17869index e22c1db..23a625a 100644
17870--- a/arch/x86/include/asm/pgtable_64.h
17871+++ b/arch/x86/include/asm/pgtable_64.h
17872@@ -16,10 +16,14 @@
17873
17874 extern pud_t level3_kernel_pgt[512];
17875 extern pud_t level3_ident_pgt[512];
17876+extern pud_t level3_vmalloc_start_pgt[512];
17877+extern pud_t level3_vmalloc_end_pgt[512];
17878+extern pud_t level3_vmemmap_pgt[512];
17879+extern pud_t level2_vmemmap_pgt[512];
17880 extern pmd_t level2_kernel_pgt[512];
17881 extern pmd_t level2_fixmap_pgt[512];
17882-extern pmd_t level2_ident_pgt[512];
17883-extern pgd_t init_level4_pgt[];
17884+extern pmd_t level2_ident_pgt[512*2];
17885+extern pgd_t init_level4_pgt[512];
17886
17887 #define swapper_pg_dir init_level4_pgt
17888
17889@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17890
17891 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17892 {
17893+ pax_open_kernel();
17894 *pmdp = pmd;
17895+ pax_close_kernel();
17896 }
17897
17898 static inline void native_pmd_clear(pmd_t *pmd)
17899@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17900
17901 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17902 {
17903+ pax_open_kernel();
17904 *pudp = pud;
17905+ pax_close_kernel();
17906 }
17907
17908 static inline void native_pud_clear(pud_t *pud)
17909@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17910
17911 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17912 {
17913+ pax_open_kernel();
17914+ *pgdp = pgd;
17915+ pax_close_kernel();
17916+}
17917+
17918+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17919+{
17920 *pgdp = pgd;
17921 }
17922
17923diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17924index 2d88344..4679fc3 100644
17925--- a/arch/x86/include/asm/pgtable_64_types.h
17926+++ b/arch/x86/include/asm/pgtable_64_types.h
17927@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17928 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17929 #define MODULES_END _AC(0xffffffffff000000, UL)
17930 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17931+#define MODULES_EXEC_VADDR MODULES_VADDR
17932+#define MODULES_EXEC_END MODULES_END
17933+
17934+#define ktla_ktva(addr) (addr)
17935+#define ktva_ktla(addr) (addr)
17936
17937 #define EARLY_DYNAMIC_PAGE_TABLES 64
17938
17939diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17940index 840c127..a8f297b 100644
17941--- a/arch/x86/include/asm/pgtable_types.h
17942+++ b/arch/x86/include/asm/pgtable_types.h
17943@@ -16,13 +16,12 @@
17944 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17945 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17946 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17947-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17948+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17949 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17950 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17951 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17952-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17953-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17954-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17955+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17956+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17957 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17958
17959 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17960@@ -40,7 +39,6 @@
17961 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17962 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17963 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17964-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17965 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17966 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17967 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17968@@ -87,8 +85,10 @@
17969
17970 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17971 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17972-#else
17973+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17974 #define _PAGE_NX (_AT(pteval_t, 0))
17975+#else
17976+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17977 #endif
17978
17979 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17980@@ -147,6 +147,9 @@
17981 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17982 _PAGE_ACCESSED)
17983
17984+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17985+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17986+
17987 #define __PAGE_KERNEL_EXEC \
17988 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17989 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17990@@ -157,7 +160,7 @@
17991 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17992 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17993 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17994-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17995+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17996 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17997 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17998 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17999@@ -219,8 +222,8 @@
18000 * bits are combined, this will alow user to access the high address mapped
18001 * VDSO in the presence of CONFIG_COMPAT_VDSO
18002 */
18003-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18004-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18005+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18006+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18007 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18008 #endif
18009
18010@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18011 {
18012 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18013 }
18014+#endif
18015
18016+#if PAGETABLE_LEVELS == 3
18017+#include <asm-generic/pgtable-nopud.h>
18018+#endif
18019+
18020+#if PAGETABLE_LEVELS == 2
18021+#include <asm-generic/pgtable-nopmd.h>
18022+#endif
18023+
18024+#ifndef __ASSEMBLY__
18025 #if PAGETABLE_LEVELS > 3
18026 typedef struct { pudval_t pud; } pud_t;
18027
18028@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18029 return pud.pud;
18030 }
18031 #else
18032-#include <asm-generic/pgtable-nopud.h>
18033-
18034 static inline pudval_t native_pud_val(pud_t pud)
18035 {
18036 return native_pgd_val(pud.pgd);
18037@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18038 return pmd.pmd;
18039 }
18040 #else
18041-#include <asm-generic/pgtable-nopmd.h>
18042-
18043 static inline pmdval_t native_pmd_val(pmd_t pmd)
18044 {
18045 return native_pgd_val(pmd.pud.pgd);
18046@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18047
18048 extern pteval_t __supported_pte_mask;
18049 extern void set_nx(void);
18050-extern int nx_enabled;
18051
18052 #define pgprot_writecombine pgprot_writecombine
18053 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18054diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18055index c8b0519..fd29e73 100644
18056--- a/arch/x86/include/asm/preempt.h
18057+++ b/arch/x86/include/asm/preempt.h
18058@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18059 */
18060 static __always_inline bool __preempt_count_dec_and_test(void)
18061 {
18062- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18063+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18064 }
18065
18066 /*
18067diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18068index 7b034a4..4fe3e3f 100644
18069--- a/arch/x86/include/asm/processor.h
18070+++ b/arch/x86/include/asm/processor.h
18071@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18072 /* Index into per_cpu list: */
18073 u16 cpu_index;
18074 u32 microcode;
18075-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18076+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18077
18078 #define X86_VENDOR_INTEL 0
18079 #define X86_VENDOR_CYRIX 1
18080@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18081 : "memory");
18082 }
18083
18084+/* invpcid (%rdx),%rax */
18085+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18086+
18087+#define INVPCID_SINGLE_ADDRESS 0UL
18088+#define INVPCID_SINGLE_CONTEXT 1UL
18089+#define INVPCID_ALL_GLOBAL 2UL
18090+#define INVPCID_ALL_MONGLOBAL 3UL
18091+
18092+#define PCID_KERNEL 0UL
18093+#define PCID_USER 1UL
18094+#define PCID_NOFLUSH (1UL << 63)
18095+
18096 static inline void load_cr3(pgd_t *pgdir)
18097 {
18098- write_cr3(__pa(pgdir));
18099+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18100 }
18101
18102 #ifdef CONFIG_X86_32
18103@@ -283,7 +295,7 @@ struct tss_struct {
18104
18105 } ____cacheline_aligned;
18106
18107-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18108+extern struct tss_struct init_tss[NR_CPUS];
18109
18110 /*
18111 * Save the original ist values for checking stack pointers during debugging
18112@@ -453,6 +465,7 @@ struct thread_struct {
18113 unsigned short ds;
18114 unsigned short fsindex;
18115 unsigned short gsindex;
18116+ unsigned short ss;
18117 #endif
18118 #ifdef CONFIG_X86_32
18119 unsigned long ip;
18120@@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18121 extern unsigned long mmu_cr4_features;
18122 extern u32 *trampoline_cr4_features;
18123
18124-static inline void set_in_cr4(unsigned long mask)
18125-{
18126- unsigned long cr4;
18127-
18128- mmu_cr4_features |= mask;
18129- if (trampoline_cr4_features)
18130- *trampoline_cr4_features = mmu_cr4_features;
18131- cr4 = read_cr4();
18132- cr4 |= mask;
18133- write_cr4(cr4);
18134-}
18135-
18136-static inline void clear_in_cr4(unsigned long mask)
18137-{
18138- unsigned long cr4;
18139-
18140- mmu_cr4_features &= ~mask;
18141- if (trampoline_cr4_features)
18142- *trampoline_cr4_features = mmu_cr4_features;
18143- cr4 = read_cr4();
18144- cr4 &= ~mask;
18145- write_cr4(cr4);
18146-}
18147+extern void set_in_cr4(unsigned long mask);
18148+extern void clear_in_cr4(unsigned long mask);
18149
18150 typedef struct {
18151 unsigned long seg;
18152@@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18153 */
18154 #define TASK_SIZE PAGE_OFFSET
18155 #define TASK_SIZE_MAX TASK_SIZE
18156+
18157+#ifdef CONFIG_PAX_SEGMEXEC
18158+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18159+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18160+#else
18161 #define STACK_TOP TASK_SIZE
18162-#define STACK_TOP_MAX STACK_TOP
18163+#endif
18164+
18165+#define STACK_TOP_MAX TASK_SIZE
18166
18167 #define INIT_THREAD { \
18168- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18169+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18170 .vm86_info = NULL, \
18171 .sysenter_cs = __KERNEL_CS, \
18172 .io_bitmap_ptr = NULL, \
18173@@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18174 */
18175 #define INIT_TSS { \
18176 .x86_tss = { \
18177- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18178+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18179 .ss0 = __KERNEL_DS, \
18180 .ss1 = __KERNEL_CS, \
18181 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18182@@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18183 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18184
18185 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18186-#define KSTK_TOP(info) \
18187-({ \
18188- unsigned long *__ptr = (unsigned long *)(info); \
18189- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18190-})
18191+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18192
18193 /*
18194 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18195@@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18196 #define task_pt_regs(task) \
18197 ({ \
18198 struct pt_regs *__regs__; \
18199- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18200+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18201 __regs__ - 1; \
18202 })
18203
18204@@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18205 /*
18206 * User space process size. 47bits minus one guard page.
18207 */
18208-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18209+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18210
18211 /* This decides where the kernel will search for a free chunk of vm
18212 * space during mmap's.
18213 */
18214 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18215- 0xc0000000 : 0xFFFFe000)
18216+ 0xc0000000 : 0xFFFFf000)
18217
18218 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18219 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18220@@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18221 #define STACK_TOP_MAX TASK_SIZE_MAX
18222
18223 #define INIT_THREAD { \
18224- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18225+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18226 }
18227
18228 #define INIT_TSS { \
18229- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18230+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18231 }
18232
18233 /*
18234@@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18235 */
18236 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18237
18238+#ifdef CONFIG_PAX_SEGMEXEC
18239+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18240+#endif
18241+
18242 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18243
18244 /* Get/set a process' ability to use the timestamp counter instruction */
18245@@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18246 return 0;
18247 }
18248
18249-extern unsigned long arch_align_stack(unsigned long sp);
18250+#define arch_align_stack(x) ((x) & ~0xfUL)
18251 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18252
18253 void default_idle(void);
18254@@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18255 #define xen_set_default_idle 0
18256 #endif
18257
18258-void stop_this_cpu(void *dummy);
18259+void stop_this_cpu(void *dummy) __noreturn;
18260 void df_debug(struct pt_regs *regs, long error_code);
18261 #endif /* _ASM_X86_PROCESSOR_H */
18262diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18263index 942a086..6c26446 100644
18264--- a/arch/x86/include/asm/ptrace.h
18265+++ b/arch/x86/include/asm/ptrace.h
18266@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18267 }
18268
18269 /*
18270- * user_mode_vm(regs) determines whether a register set came from user mode.
18271+ * user_mode(regs) determines whether a register set came from user mode.
18272 * This is true if V8086 mode was enabled OR if the register set was from
18273 * protected mode with RPL-3 CS value. This tricky test checks that with
18274 * one comparison. Many places in the kernel can bypass this full check
18275- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18276+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18277+ * be used.
18278 */
18279-static inline int user_mode(struct pt_regs *regs)
18280+static inline int user_mode_novm(struct pt_regs *regs)
18281 {
18282 #ifdef CONFIG_X86_32
18283 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18284 #else
18285- return !!(regs->cs & 3);
18286+ return !!(regs->cs & SEGMENT_RPL_MASK);
18287 #endif
18288 }
18289
18290-static inline int user_mode_vm(struct pt_regs *regs)
18291+static inline int user_mode(struct pt_regs *regs)
18292 {
18293 #ifdef CONFIG_X86_32
18294 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18295 USER_RPL;
18296 #else
18297- return user_mode(regs);
18298+ return user_mode_novm(regs);
18299 #endif
18300 }
18301
18302@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18303 #ifdef CONFIG_X86_64
18304 static inline bool user_64bit_mode(struct pt_regs *regs)
18305 {
18306+ unsigned long cs = regs->cs & 0xffff;
18307 #ifndef CONFIG_PARAVIRT
18308 /*
18309 * On non-paravirt systems, this is the only long mode CPL 3
18310 * selector. We do not allow long mode selectors in the LDT.
18311 */
18312- return regs->cs == __USER_CS;
18313+ return cs == __USER_CS;
18314 #else
18315 /* Headers are too twisted for this to go in paravirt.h. */
18316- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18317+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18318 #endif
18319 }
18320
18321@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18322 * Traps from the kernel do not save sp and ss.
18323 * Use the helper function to retrieve sp.
18324 */
18325- if (offset == offsetof(struct pt_regs, sp) &&
18326- regs->cs == __KERNEL_CS)
18327- return kernel_stack_pointer(regs);
18328+ if (offset == offsetof(struct pt_regs, sp)) {
18329+ unsigned long cs = regs->cs & 0xffff;
18330+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18331+ return kernel_stack_pointer(regs);
18332+ }
18333 #endif
18334 return *(unsigned long *)((unsigned long)regs + offset);
18335 }
18336diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18337index 9c6b890..5305f53 100644
18338--- a/arch/x86/include/asm/realmode.h
18339+++ b/arch/x86/include/asm/realmode.h
18340@@ -22,16 +22,14 @@ struct real_mode_header {
18341 #endif
18342 /* APM/BIOS reboot */
18343 u32 machine_real_restart_asm;
18344-#ifdef CONFIG_X86_64
18345 u32 machine_real_restart_seg;
18346-#endif
18347 };
18348
18349 /* This must match data at trampoline_32/64.S */
18350 struct trampoline_header {
18351 #ifdef CONFIG_X86_32
18352 u32 start;
18353- u16 gdt_pad;
18354+ u16 boot_cs;
18355 u16 gdt_limit;
18356 u32 gdt_base;
18357 #else
18358diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18359index a82c4f1..ac45053 100644
18360--- a/arch/x86/include/asm/reboot.h
18361+++ b/arch/x86/include/asm/reboot.h
18362@@ -6,13 +6,13 @@
18363 struct pt_regs;
18364
18365 struct machine_ops {
18366- void (*restart)(char *cmd);
18367- void (*halt)(void);
18368- void (*power_off)(void);
18369+ void (* __noreturn restart)(char *cmd);
18370+ void (* __noreturn halt)(void);
18371+ void (* __noreturn power_off)(void);
18372 void (*shutdown)(void);
18373 void (*crash_shutdown)(struct pt_regs *);
18374- void (*emergency_restart)(void);
18375-};
18376+ void (* __noreturn emergency_restart)(void);
18377+} __no_const;
18378
18379 extern struct machine_ops machine_ops;
18380
18381diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18382index 8f7866a..e442f20 100644
18383--- a/arch/x86/include/asm/rmwcc.h
18384+++ b/arch/x86/include/asm/rmwcc.h
18385@@ -3,7 +3,34 @@
18386
18387 #ifdef CC_HAVE_ASM_GOTO
18388
18389-#define __GEN_RMWcc(fullop, var, cc, ...) \
18390+#ifdef CONFIG_PAX_REFCOUNT
18391+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18392+do { \
18393+ asm_volatile_goto (fullop \
18394+ ";jno 0f\n" \
18395+ fullantiop \
18396+ ";int $4\n0:\n" \
18397+ _ASM_EXTABLE(0b, 0b) \
18398+ ";j" cc " %l[cc_label]" \
18399+ : : "m" (var), ## __VA_ARGS__ \
18400+ : "memory" : cc_label); \
18401+ return 0; \
18402+cc_label: \
18403+ return 1; \
18404+} while (0)
18405+#else
18406+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18407+do { \
18408+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18409+ : : "m" (var), ## __VA_ARGS__ \
18410+ : "memory" : cc_label); \
18411+ return 0; \
18412+cc_label: \
18413+ return 1; \
18414+} while (0)
18415+#endif
18416+
18417+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18418 do { \
18419 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18420 : : "m" (var), ## __VA_ARGS__ \
18421@@ -13,15 +40,46 @@ cc_label: \
18422 return 1; \
18423 } while (0)
18424
18425-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18426- __GEN_RMWcc(op " " arg0, var, cc)
18427+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18428+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18429
18430-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18431- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18432+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18433+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18434+
18435+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18436+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18437+
18438+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18439+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18440
18441 #else /* !CC_HAVE_ASM_GOTO */
18442
18443-#define __GEN_RMWcc(fullop, var, cc, ...) \
18444+#ifdef CONFIG_PAX_REFCOUNT
18445+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18446+do { \
18447+ char c; \
18448+ asm volatile (fullop \
18449+ ";jno 0f\n" \
18450+ fullantiop \
18451+ ";int $4\n0:\n" \
18452+ _ASM_EXTABLE(0b, 0b) \
18453+ "; set" cc " %1" \
18454+ : "+m" (var), "=qm" (c) \
18455+ : __VA_ARGS__ : "memory"); \
18456+ return c != 0; \
18457+} while (0)
18458+#else
18459+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18460+do { \
18461+ char c; \
18462+ asm volatile (fullop "; set" cc " %1" \
18463+ : "+m" (var), "=qm" (c) \
18464+ : __VA_ARGS__ : "memory"); \
18465+ return c != 0; \
18466+} while (0)
18467+#endif
18468+
18469+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18470 do { \
18471 char c; \
18472 asm volatile (fullop "; set" cc " %1" \
18473@@ -30,11 +88,17 @@ do { \
18474 return c != 0; \
18475 } while (0)
18476
18477-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18478- __GEN_RMWcc(op " " arg0, var, cc)
18479+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18480+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18481+
18482+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18483+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18484+
18485+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18486+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18487
18488-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18489- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18490+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18491+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18492
18493 #endif /* CC_HAVE_ASM_GOTO */
18494
18495diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18496index cad82c9..2e5c5c1 100644
18497--- a/arch/x86/include/asm/rwsem.h
18498+++ b/arch/x86/include/asm/rwsem.h
18499@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18500 {
18501 asm volatile("# beginning down_read\n\t"
18502 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18503+
18504+#ifdef CONFIG_PAX_REFCOUNT
18505+ "jno 0f\n"
18506+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18507+ "int $4\n0:\n"
18508+ _ASM_EXTABLE(0b, 0b)
18509+#endif
18510+
18511 /* adds 0x00000001 */
18512 " jns 1f\n"
18513 " call call_rwsem_down_read_failed\n"
18514@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18515 "1:\n\t"
18516 " mov %1,%2\n\t"
18517 " add %3,%2\n\t"
18518+
18519+#ifdef CONFIG_PAX_REFCOUNT
18520+ "jno 0f\n"
18521+ "sub %3,%2\n"
18522+ "int $4\n0:\n"
18523+ _ASM_EXTABLE(0b, 0b)
18524+#endif
18525+
18526 " jle 2f\n\t"
18527 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18528 " jnz 1b\n\t"
18529@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18530 long tmp;
18531 asm volatile("# beginning down_write\n\t"
18532 LOCK_PREFIX " xadd %1,(%2)\n\t"
18533+
18534+#ifdef CONFIG_PAX_REFCOUNT
18535+ "jno 0f\n"
18536+ "mov %1,(%2)\n"
18537+ "int $4\n0:\n"
18538+ _ASM_EXTABLE(0b, 0b)
18539+#endif
18540+
18541 /* adds 0xffff0001, returns the old value */
18542 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18543 /* was the active mask 0 before? */
18544@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18545 long tmp;
18546 asm volatile("# beginning __up_read\n\t"
18547 LOCK_PREFIX " xadd %1,(%2)\n\t"
18548+
18549+#ifdef CONFIG_PAX_REFCOUNT
18550+ "jno 0f\n"
18551+ "mov %1,(%2)\n"
18552+ "int $4\n0:\n"
18553+ _ASM_EXTABLE(0b, 0b)
18554+#endif
18555+
18556 /* subtracts 1, returns the old value */
18557 " jns 1f\n\t"
18558 " call call_rwsem_wake\n" /* expects old value in %edx */
18559@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18560 long tmp;
18561 asm volatile("# beginning __up_write\n\t"
18562 LOCK_PREFIX " xadd %1,(%2)\n\t"
18563+
18564+#ifdef CONFIG_PAX_REFCOUNT
18565+ "jno 0f\n"
18566+ "mov %1,(%2)\n"
18567+ "int $4\n0:\n"
18568+ _ASM_EXTABLE(0b, 0b)
18569+#endif
18570+
18571 /* subtracts 0xffff0001, returns the old value */
18572 " jns 1f\n\t"
18573 " call call_rwsem_wake\n" /* expects old value in %edx */
18574@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18575 {
18576 asm volatile("# beginning __downgrade_write\n\t"
18577 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18578+
18579+#ifdef CONFIG_PAX_REFCOUNT
18580+ "jno 0f\n"
18581+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18582+ "int $4\n0:\n"
18583+ _ASM_EXTABLE(0b, 0b)
18584+#endif
18585+
18586 /*
18587 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18588 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18589@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18590 */
18591 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18592 {
18593- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18594+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18595+
18596+#ifdef CONFIG_PAX_REFCOUNT
18597+ "jno 0f\n"
18598+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18599+ "int $4\n0:\n"
18600+ _ASM_EXTABLE(0b, 0b)
18601+#endif
18602+
18603 : "+m" (sem->count)
18604 : "er" (delta));
18605 }
18606@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18607 */
18608 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18609 {
18610- return delta + xadd(&sem->count, delta);
18611+ return delta + xadd_check_overflow(&sem->count, delta);
18612 }
18613
18614 #endif /* __KERNEL__ */
18615diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18616index 6f1c3a8..7744f19 100644
18617--- a/arch/x86/include/asm/segment.h
18618+++ b/arch/x86/include/asm/segment.h
18619@@ -64,10 +64,15 @@
18620 * 26 - ESPFIX small SS
18621 * 27 - per-cpu [ offset to per-cpu data area ]
18622 * 28 - stack_canary-20 [ for stack protector ]
18623- * 29 - unused
18624- * 30 - unused
18625+ * 29 - PCI BIOS CS
18626+ * 30 - PCI BIOS DS
18627 * 31 - TSS for double fault handler
18628 */
18629+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18630+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18631+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18632+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18633+
18634 #define GDT_ENTRY_TLS_MIN 6
18635 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18636
18637@@ -79,6 +84,8 @@
18638
18639 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18640
18641+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18642+
18643 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18644
18645 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18646@@ -104,6 +111,12 @@
18647 #define __KERNEL_STACK_CANARY 0
18648 #endif
18649
18650+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18651+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18652+
18653+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18654+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18655+
18656 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18657
18658 /*
18659@@ -141,7 +154,7 @@
18660 */
18661
18662 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18663-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18664+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18665
18666
18667 #else
18668@@ -165,6 +178,8 @@
18669 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18670 #define __USER32_DS __USER_DS
18671
18672+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18673+
18674 #define GDT_ENTRY_TSS 8 /* needs two entries */
18675 #define GDT_ENTRY_LDT 10 /* needs two entries */
18676 #define GDT_ENTRY_TLS_MIN 12
18677@@ -173,6 +188,8 @@
18678 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18679 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18680
18681+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18682+
18683 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18684 #define FS_TLS 0
18685 #define GS_TLS 1
18686@@ -180,12 +197,14 @@
18687 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18688 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18689
18690-#define GDT_ENTRIES 16
18691+#define GDT_ENTRIES 17
18692
18693 #endif
18694
18695 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18696+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18697 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18698+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18699 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18700 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18701 #ifndef CONFIG_PARAVIRT
18702@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18703 {
18704 unsigned long __limit;
18705 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18706- return __limit + 1;
18707+ return __limit;
18708 }
18709
18710 #endif /* !__ASSEMBLY__ */
18711diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18712index 8d3120f..352b440 100644
18713--- a/arch/x86/include/asm/smap.h
18714+++ b/arch/x86/include/asm/smap.h
18715@@ -25,11 +25,40 @@
18716
18717 #include <asm/alternative-asm.h>
18718
18719+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18720+#define ASM_PAX_OPEN_USERLAND \
18721+ 661: jmp 663f; \
18722+ .pushsection .altinstr_replacement, "a" ; \
18723+ 662: pushq %rax; nop; \
18724+ .popsection ; \
18725+ .pushsection .altinstructions, "a" ; \
18726+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18727+ .popsection ; \
18728+ call __pax_open_userland; \
18729+ popq %rax; \
18730+ 663:
18731+
18732+#define ASM_PAX_CLOSE_USERLAND \
18733+ 661: jmp 663f; \
18734+ .pushsection .altinstr_replacement, "a" ; \
18735+ 662: pushq %rax; nop; \
18736+ .popsection; \
18737+ .pushsection .altinstructions, "a" ; \
18738+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18739+ .popsection; \
18740+ call __pax_close_userland; \
18741+ popq %rax; \
18742+ 663:
18743+#else
18744+#define ASM_PAX_OPEN_USERLAND
18745+#define ASM_PAX_CLOSE_USERLAND
18746+#endif
18747+
18748 #ifdef CONFIG_X86_SMAP
18749
18750 #define ASM_CLAC \
18751 661: ASM_NOP3 ; \
18752- .pushsection .altinstr_replacement, "ax" ; \
18753+ .pushsection .altinstr_replacement, "a" ; \
18754 662: __ASM_CLAC ; \
18755 .popsection ; \
18756 .pushsection .altinstructions, "a" ; \
18757@@ -38,7 +67,7 @@
18758
18759 #define ASM_STAC \
18760 661: ASM_NOP3 ; \
18761- .pushsection .altinstr_replacement, "ax" ; \
18762+ .pushsection .altinstr_replacement, "a" ; \
18763 662: __ASM_STAC ; \
18764 .popsection ; \
18765 .pushsection .altinstructions, "a" ; \
18766@@ -56,6 +85,37 @@
18767
18768 #include <asm/alternative.h>
18769
18770+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18771+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18772+
18773+extern void __pax_open_userland(void);
18774+static __always_inline unsigned long pax_open_userland(void)
18775+{
18776+
18777+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18778+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18779+ :
18780+ : [open] "i" (__pax_open_userland)
18781+ : "memory", "rax");
18782+#endif
18783+
18784+ return 0;
18785+}
18786+
18787+extern void __pax_close_userland(void);
18788+static __always_inline unsigned long pax_close_userland(void)
18789+{
18790+
18791+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18792+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18793+ :
18794+ : [close] "i" (__pax_close_userland)
18795+ : "memory", "rax");
18796+#endif
18797+
18798+ return 0;
18799+}
18800+
18801 #ifdef CONFIG_X86_SMAP
18802
18803 static __always_inline void clac(void)
18804diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18805index 4137890..03fa172 100644
18806--- a/arch/x86/include/asm/smp.h
18807+++ b/arch/x86/include/asm/smp.h
18808@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18809 /* cpus sharing the last level cache: */
18810 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18811 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18812-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18813+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18814
18815 static inline struct cpumask *cpu_sibling_mask(int cpu)
18816 {
18817@@ -79,7 +79,7 @@ struct smp_ops {
18818
18819 void (*send_call_func_ipi)(const struct cpumask *mask);
18820 void (*send_call_func_single_ipi)(int cpu);
18821-};
18822+} __no_const;
18823
18824 /* Globals due to paravirt */
18825 extern void set_cpu_sibling_map(int cpu);
18826@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18827 extern int safe_smp_processor_id(void);
18828
18829 #elif defined(CONFIG_X86_64_SMP)
18830-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18831-
18832-#define stack_smp_processor_id() \
18833-({ \
18834- struct thread_info *ti; \
18835- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18836- ti->cpu; \
18837-})
18838+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18839+#define stack_smp_processor_id() raw_smp_processor_id()
18840 #define safe_smp_processor_id() smp_processor_id()
18841
18842 #endif
18843diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18844index bf156de..1a782ab 100644
18845--- a/arch/x86/include/asm/spinlock.h
18846+++ b/arch/x86/include/asm/spinlock.h
18847@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18848 static inline void arch_read_lock(arch_rwlock_t *rw)
18849 {
18850 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18851+
18852+#ifdef CONFIG_PAX_REFCOUNT
18853+ "jno 0f\n"
18854+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18855+ "int $4\n0:\n"
18856+ _ASM_EXTABLE(0b, 0b)
18857+#endif
18858+
18859 "jns 1f\n"
18860 "call __read_lock_failed\n\t"
18861 "1:\n"
18862@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18863 static inline void arch_write_lock(arch_rwlock_t *rw)
18864 {
18865 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18866+
18867+#ifdef CONFIG_PAX_REFCOUNT
18868+ "jno 0f\n"
18869+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18870+ "int $4\n0:\n"
18871+ _ASM_EXTABLE(0b, 0b)
18872+#endif
18873+
18874 "jz 1f\n"
18875 "call __write_lock_failed\n\t"
18876 "1:\n"
18877@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18878
18879 static inline void arch_read_unlock(arch_rwlock_t *rw)
18880 {
18881- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18882+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18883+
18884+#ifdef CONFIG_PAX_REFCOUNT
18885+ "jno 0f\n"
18886+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18887+ "int $4\n0:\n"
18888+ _ASM_EXTABLE(0b, 0b)
18889+#endif
18890+
18891 :"+m" (rw->lock) : : "memory");
18892 }
18893
18894 static inline void arch_write_unlock(arch_rwlock_t *rw)
18895 {
18896- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18897+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18898+
18899+#ifdef CONFIG_PAX_REFCOUNT
18900+ "jno 0f\n"
18901+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18902+ "int $4\n0:\n"
18903+ _ASM_EXTABLE(0b, 0b)
18904+#endif
18905+
18906 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18907 }
18908
18909diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18910index 6a99859..03cb807 100644
18911--- a/arch/x86/include/asm/stackprotector.h
18912+++ b/arch/x86/include/asm/stackprotector.h
18913@@ -47,7 +47,7 @@
18914 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18915 */
18916 #define GDT_STACK_CANARY_INIT \
18917- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18918+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18919
18920 /*
18921 * Initialize the stackprotector canary value.
18922@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18923
18924 static inline void load_stack_canary_segment(void)
18925 {
18926-#ifdef CONFIG_X86_32
18927+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18928 asm volatile ("mov %0, %%gs" : : "r" (0));
18929 #endif
18930 }
18931diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18932index 70bbe39..4ae2bd4 100644
18933--- a/arch/x86/include/asm/stacktrace.h
18934+++ b/arch/x86/include/asm/stacktrace.h
18935@@ -11,28 +11,20 @@
18936
18937 extern int kstack_depth_to_print;
18938
18939-struct thread_info;
18940+struct task_struct;
18941 struct stacktrace_ops;
18942
18943-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18944- unsigned long *stack,
18945- unsigned long bp,
18946- const struct stacktrace_ops *ops,
18947- void *data,
18948- unsigned long *end,
18949- int *graph);
18950+typedef unsigned long walk_stack_t(struct task_struct *task,
18951+ void *stack_start,
18952+ unsigned long *stack,
18953+ unsigned long bp,
18954+ const struct stacktrace_ops *ops,
18955+ void *data,
18956+ unsigned long *end,
18957+ int *graph);
18958
18959-extern unsigned long
18960-print_context_stack(struct thread_info *tinfo,
18961- unsigned long *stack, unsigned long bp,
18962- const struct stacktrace_ops *ops, void *data,
18963- unsigned long *end, int *graph);
18964-
18965-extern unsigned long
18966-print_context_stack_bp(struct thread_info *tinfo,
18967- unsigned long *stack, unsigned long bp,
18968- const struct stacktrace_ops *ops, void *data,
18969- unsigned long *end, int *graph);
18970+extern walk_stack_t print_context_stack;
18971+extern walk_stack_t print_context_stack_bp;
18972
18973 /* Generic stack tracer with callbacks */
18974
18975@@ -40,7 +32,7 @@ struct stacktrace_ops {
18976 void (*address)(void *data, unsigned long address, int reliable);
18977 /* On negative return stop dumping */
18978 int (*stack)(void *data, char *name);
18979- walk_stack_t walk_stack;
18980+ walk_stack_t *walk_stack;
18981 };
18982
18983 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18984diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18985index d7f3b3b..3cc39f1 100644
18986--- a/arch/x86/include/asm/switch_to.h
18987+++ b/arch/x86/include/asm/switch_to.h
18988@@ -108,7 +108,7 @@ do { \
18989 "call __switch_to\n\t" \
18990 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18991 __switch_canary \
18992- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18993+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18994 "movq %%rax,%%rdi\n\t" \
18995 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18996 "jnz ret_from_fork\n\t" \
18997@@ -119,7 +119,7 @@ do { \
18998 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18999 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19000 [_tif_fork] "i" (_TIF_FORK), \
19001- [thread_info] "i" (offsetof(struct task_struct, stack)), \
19002+ [thread_info] "m" (current_tinfo), \
19003 [current_task] "m" (current_task) \
19004 __switch_canary_iparam \
19005 : "memory", "cc" __EXTRA_CLOBBER)
19006diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19007index 3ba3de4..6c113b2 100644
19008--- a/arch/x86/include/asm/thread_info.h
19009+++ b/arch/x86/include/asm/thread_info.h
19010@@ -10,6 +10,7 @@
19011 #include <linux/compiler.h>
19012 #include <asm/page.h>
19013 #include <asm/types.h>
19014+#include <asm/percpu.h>
19015
19016 /*
19017 * low level task data that entry.S needs immediate access to
19018@@ -23,7 +24,6 @@ struct exec_domain;
19019 #include <linux/atomic.h>
19020
19021 struct thread_info {
19022- struct task_struct *task; /* main task structure */
19023 struct exec_domain *exec_domain; /* execution domain */
19024 __u32 flags; /* low level flags */
19025 __u32 status; /* thread synchronous flags */
19026@@ -32,19 +32,13 @@ struct thread_info {
19027 mm_segment_t addr_limit;
19028 struct restart_block restart_block;
19029 void __user *sysenter_return;
19030-#ifdef CONFIG_X86_32
19031- unsigned long previous_esp; /* ESP of the previous stack in
19032- case of nested (IRQ) stacks
19033- */
19034- __u8 supervisor_stack[0];
19035-#endif
19036+ unsigned long lowest_stack;
19037 unsigned int sig_on_uaccess_error:1;
19038 unsigned int uaccess_err:1; /* uaccess failed */
19039 };
19040
19041-#define INIT_THREAD_INFO(tsk) \
19042+#define INIT_THREAD_INFO \
19043 { \
19044- .task = &tsk, \
19045 .exec_domain = &default_exec_domain, \
19046 .flags = 0, \
19047 .cpu = 0, \
19048@@ -55,7 +49,7 @@ struct thread_info {
19049 }, \
19050 }
19051
19052-#define init_thread_info (init_thread_union.thread_info)
19053+#define init_thread_info (init_thread_union.stack)
19054 #define init_stack (init_thread_union.stack)
19055
19056 #else /* !__ASSEMBLY__ */
19057@@ -95,6 +89,7 @@ struct thread_info {
19058 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19059 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19060 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19061+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19062
19063 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19064 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19065@@ -118,17 +113,18 @@ struct thread_info {
19066 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19067 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19068 #define _TIF_X32 (1 << TIF_X32)
19069+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19070
19071 /* work to do in syscall_trace_enter() */
19072 #define _TIF_WORK_SYSCALL_ENTRY \
19073 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19074 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19075- _TIF_NOHZ)
19076+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19077
19078 /* work to do in syscall_trace_leave() */
19079 #define _TIF_WORK_SYSCALL_EXIT \
19080 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19081- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19082+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19083
19084 /* work to do on interrupt/exception return */
19085 #define _TIF_WORK_MASK \
19086@@ -139,7 +135,7 @@ struct thread_info {
19087 /* work to do on any return to user space */
19088 #define _TIF_ALLWORK_MASK \
19089 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19090- _TIF_NOHZ)
19091+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19092
19093 /* Only used for 64 bit */
19094 #define _TIF_DO_NOTIFY_MASK \
19095@@ -153,45 +149,40 @@ struct thread_info {
19096 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19097 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19098
19099-#ifdef CONFIG_X86_32
19100-
19101-#define STACK_WARN (THREAD_SIZE/8)
19102-/*
19103- * macros/functions for gaining access to the thread information structure
19104- *
19105- * preempt_count needs to be 1 initially, until the scheduler is functional.
19106- */
19107-#ifndef __ASSEMBLY__
19108-
19109-
19110-/* how to get the current stack pointer from C */
19111-register unsigned long current_stack_pointer asm("esp") __used;
19112-
19113-/* how to get the thread information struct from C */
19114-static inline struct thread_info *current_thread_info(void)
19115-{
19116- return (struct thread_info *)
19117- (current_stack_pointer & ~(THREAD_SIZE - 1));
19118-}
19119-
19120-#else /* !__ASSEMBLY__ */
19121-
19122+#ifdef __ASSEMBLY__
19123 /* how to get the thread information struct from ASM */
19124 #define GET_THREAD_INFO(reg) \
19125- movl $-THREAD_SIZE, reg; \
19126- andl %esp, reg
19127+ mov PER_CPU_VAR(current_tinfo), reg
19128
19129 /* use this one if reg already contains %esp */
19130-#define GET_THREAD_INFO_WITH_ESP(reg) \
19131- andl $-THREAD_SIZE, reg
19132+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19133+#else
19134+/* how to get the thread information struct from C */
19135+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19136+
19137+static __always_inline struct thread_info *current_thread_info(void)
19138+{
19139+ return this_cpu_read_stable(current_tinfo);
19140+}
19141+#endif
19142+
19143+#ifdef CONFIG_X86_32
19144+
19145+#define STACK_WARN (THREAD_SIZE/8)
19146+/*
19147+ * macros/functions for gaining access to the thread information structure
19148+ *
19149+ * preempt_count needs to be 1 initially, until the scheduler is functional.
19150+ */
19151+#ifndef __ASSEMBLY__
19152+
19153+/* how to get the current stack pointer from C */
19154+register unsigned long current_stack_pointer asm("esp") __used;
19155
19156 #endif
19157
19158 #else /* X86_32 */
19159
19160-#include <asm/percpu.h>
19161-#define KERNEL_STACK_OFFSET (5*8)
19162-
19163 /*
19164 * macros/functions for gaining access to the thread information structure
19165 * preempt_count needs to be 1 initially, until the scheduler is functional.
19166@@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19167 #ifndef __ASSEMBLY__
19168 DECLARE_PER_CPU(unsigned long, kernel_stack);
19169
19170-static inline struct thread_info *current_thread_info(void)
19171-{
19172- struct thread_info *ti;
19173- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19174- KERNEL_STACK_OFFSET - THREAD_SIZE);
19175- return ti;
19176-}
19177-
19178-#else /* !__ASSEMBLY__ */
19179-
19180-/* how to get the thread information struct from ASM */
19181-#define GET_THREAD_INFO(reg) \
19182- movq PER_CPU_VAR(kernel_stack),reg ; \
19183- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19184-
19185-/*
19186- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19187- * a certain register (to be used in assembler memory operands).
19188- */
19189-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19190-
19191+/* how to get the current stack pointer from C */
19192+register unsigned long current_stack_pointer asm("rsp") __used;
19193 #endif
19194
19195 #endif /* !X86_32 */
19196@@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19197 extern void arch_task_cache_init(void);
19198 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19199 extern void arch_release_task_struct(struct task_struct *tsk);
19200+
19201+#define __HAVE_THREAD_FUNCTIONS
19202+#define task_thread_info(task) (&(task)->tinfo)
19203+#define task_stack_page(task) ((task)->stack)
19204+#define setup_thread_stack(p, org) do {} while (0)
19205+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19206+
19207 #endif
19208 #endif /* _ASM_X86_THREAD_INFO_H */
19209diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19210index e6d90ba..f81f114 100644
19211--- a/arch/x86/include/asm/tlbflush.h
19212+++ b/arch/x86/include/asm/tlbflush.h
19213@@ -17,18 +17,44 @@
19214
19215 static inline void __native_flush_tlb(void)
19216 {
19217+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19218+ u64 descriptor[2];
19219+
19220+ descriptor[0] = PCID_KERNEL;
19221+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19222+ return;
19223+ }
19224+
19225+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19226+ if (static_cpu_has(X86_FEATURE_PCID)) {
19227+ unsigned int cpu = raw_get_cpu();
19228+
19229+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19230+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19231+ raw_put_cpu_no_resched();
19232+ return;
19233+ }
19234+#endif
19235+
19236 native_write_cr3(native_read_cr3());
19237 }
19238
19239 static inline void __native_flush_tlb_global_irq_disabled(void)
19240 {
19241- unsigned long cr4;
19242+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19243+ u64 descriptor[2];
19244
19245- cr4 = native_read_cr4();
19246- /* clear PGE */
19247- native_write_cr4(cr4 & ~X86_CR4_PGE);
19248- /* write old PGE again and flush TLBs */
19249- native_write_cr4(cr4);
19250+ descriptor[0] = PCID_KERNEL;
19251+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19252+ } else {
19253+ unsigned long cr4;
19254+
19255+ cr4 = native_read_cr4();
19256+ /* clear PGE */
19257+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19258+ /* write old PGE again and flush TLBs */
19259+ native_write_cr4(cr4);
19260+ }
19261 }
19262
19263 static inline void __native_flush_tlb_global(void)
19264@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19265
19266 static inline void __native_flush_tlb_single(unsigned long addr)
19267 {
19268+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19269+ u64 descriptor[2];
19270+
19271+ descriptor[0] = PCID_KERNEL;
19272+ descriptor[1] = addr;
19273+
19274+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19275+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19276+ if (addr < TASK_SIZE_MAX)
19277+ descriptor[1] += pax_user_shadow_base;
19278+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19279+ }
19280+
19281+ descriptor[0] = PCID_USER;
19282+ descriptor[1] = addr;
19283+#endif
19284+
19285+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19286+ return;
19287+ }
19288+
19289+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19290+ if (static_cpu_has(X86_FEATURE_PCID)) {
19291+ unsigned int cpu = raw_get_cpu();
19292+
19293+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19294+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19295+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19296+ raw_put_cpu_no_resched();
19297+
19298+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19299+ addr += pax_user_shadow_base;
19300+ }
19301+#endif
19302+
19303 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19304 }
19305
19306diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19307index 8ec57c0..451bcfc 100644
19308--- a/arch/x86/include/asm/uaccess.h
19309+++ b/arch/x86/include/asm/uaccess.h
19310@@ -7,6 +7,7 @@
19311 #include <linux/compiler.h>
19312 #include <linux/thread_info.h>
19313 #include <linux/string.h>
19314+#include <linux/spinlock.h>
19315 #include <asm/asm.h>
19316 #include <asm/page.h>
19317 #include <asm/smap.h>
19318@@ -29,7 +30,12 @@
19319
19320 #define get_ds() (KERNEL_DS)
19321 #define get_fs() (current_thread_info()->addr_limit)
19322+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19323+void __set_fs(mm_segment_t x);
19324+void set_fs(mm_segment_t x);
19325+#else
19326 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19327+#endif
19328
19329 #define segment_eq(a, b) ((a).seg == (b).seg)
19330
19331@@ -77,8 +83,34 @@
19332 * checks that the pointer is in the user space range - after calling
19333 * this function, memory access functions may still return -EFAULT.
19334 */
19335-#define access_ok(type, addr, size) \
19336- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19337+extern int _cond_resched(void);
19338+#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19339+#define access_ok(type, addr, size) \
19340+({ \
19341+ long __size = size; \
19342+ unsigned long __addr = (unsigned long)addr; \
19343+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19344+ unsigned long __end_ao = __addr + __size - 1; \
19345+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19346+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19347+ while(__addr_ao <= __end_ao) { \
19348+ char __c_ao; \
19349+ __addr_ao += PAGE_SIZE; \
19350+ if (__size > PAGE_SIZE) \
19351+ _cond_resched(); \
19352+ if (__get_user(__c_ao, (char __user *)__addr)) \
19353+ break; \
19354+ if (type != VERIFY_WRITE) { \
19355+ __addr = __addr_ao; \
19356+ continue; \
19357+ } \
19358+ if (__put_user(__c_ao, (char __user *)__addr)) \
19359+ break; \
19360+ __addr = __addr_ao; \
19361+ } \
19362+ } \
19363+ __ret_ao; \
19364+})
19365
19366 /*
19367 * The exception table consists of pairs of addresses relative to the
19368@@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19369 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19370 __chk_user_ptr(ptr); \
19371 might_fault(); \
19372+ pax_open_userland(); \
19373 asm volatile("call __get_user_%P3" \
19374 : "=a" (__ret_gu), "=r" (__val_gu) \
19375 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19376 (x) = (__typeof__(*(ptr))) __val_gu; \
19377+ pax_close_userland(); \
19378 __ret_gu; \
19379 })
19380
19381@@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19382 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19383 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19384
19385-
19386+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19387+#define __copyuser_seg "gs;"
19388+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19389+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19390+#else
19391+#define __copyuser_seg
19392+#define __COPYUSER_SET_ES
19393+#define __COPYUSER_RESTORE_ES
19394+#endif
19395
19396 #ifdef CONFIG_X86_32
19397 #define __put_user_asm_u64(x, addr, err, errret) \
19398 asm volatile(ASM_STAC "\n" \
19399- "1: movl %%eax,0(%2)\n" \
19400- "2: movl %%edx,4(%2)\n" \
19401+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19402+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19403 "3: " ASM_CLAC "\n" \
19404 ".section .fixup,\"ax\"\n" \
19405 "4: movl %3,%0\n" \
19406@@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19407
19408 #define __put_user_asm_ex_u64(x, addr) \
19409 asm volatile(ASM_STAC "\n" \
19410- "1: movl %%eax,0(%1)\n" \
19411- "2: movl %%edx,4(%1)\n" \
19412+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19413+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19414 "3: " ASM_CLAC "\n" \
19415 _ASM_EXTABLE_EX(1b, 2b) \
19416 _ASM_EXTABLE_EX(2b, 3b) \
19417@@ -249,7 +291,8 @@ extern void __put_user_8(void);
19418 __typeof__(*(ptr)) __pu_val; \
19419 __chk_user_ptr(ptr); \
19420 might_fault(); \
19421- __pu_val = x; \
19422+ __pu_val = (x); \
19423+ pax_open_userland(); \
19424 switch (sizeof(*(ptr))) { \
19425 case 1: \
19426 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19427@@ -267,6 +310,7 @@ extern void __put_user_8(void);
19428 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19429 break; \
19430 } \
19431+ pax_close_userland(); \
19432 __ret_pu; \
19433 })
19434
19435@@ -347,8 +391,10 @@ do { \
19436 } while (0)
19437
19438 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19439+do { \
19440+ pax_open_userland(); \
19441 asm volatile(ASM_STAC "\n" \
19442- "1: mov"itype" %2,%"rtype"1\n" \
19443+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19444 "2: " ASM_CLAC "\n" \
19445 ".section .fixup,\"ax\"\n" \
19446 "3: mov %3,%0\n" \
19447@@ -356,8 +402,10 @@ do { \
19448 " jmp 2b\n" \
19449 ".previous\n" \
19450 _ASM_EXTABLE(1b, 3b) \
19451- : "=r" (err), ltype(x) \
19452- : "m" (__m(addr)), "i" (errret), "0" (err))
19453+ : "=r" (err), ltype (x) \
19454+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19455+ pax_close_userland(); \
19456+} while (0)
19457
19458 #define __get_user_size_ex(x, ptr, size) \
19459 do { \
19460@@ -381,7 +429,7 @@ do { \
19461 } while (0)
19462
19463 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19464- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19465+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19466 "2:\n" \
19467 _ASM_EXTABLE_EX(1b, 2b) \
19468 : ltype(x) : "m" (__m(addr)))
19469@@ -398,13 +446,24 @@ do { \
19470 int __gu_err; \
19471 unsigned long __gu_val; \
19472 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19473- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19474+ (x) = (__typeof__(*(ptr)))__gu_val; \
19475 __gu_err; \
19476 })
19477
19478 /* FIXME: this hack is definitely wrong -AK */
19479 struct __large_struct { unsigned long buf[100]; };
19480-#define __m(x) (*(struct __large_struct __user *)(x))
19481+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19482+#define ____m(x) \
19483+({ \
19484+ unsigned long ____x = (unsigned long)(x); \
19485+ if (____x < pax_user_shadow_base) \
19486+ ____x += pax_user_shadow_base; \
19487+ (typeof(x))____x; \
19488+})
19489+#else
19490+#define ____m(x) (x)
19491+#endif
19492+#define __m(x) (*(struct __large_struct __user *)____m(x))
19493
19494 /*
19495 * Tell gcc we read from memory instead of writing: this is because
19496@@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19497 * aliasing issues.
19498 */
19499 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19500+do { \
19501+ pax_open_userland(); \
19502 asm volatile(ASM_STAC "\n" \
19503- "1: mov"itype" %"rtype"1,%2\n" \
19504+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19505 "2: " ASM_CLAC "\n" \
19506 ".section .fixup,\"ax\"\n" \
19507 "3: mov %3,%0\n" \
19508@@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19509 ".previous\n" \
19510 _ASM_EXTABLE(1b, 3b) \
19511 : "=r"(err) \
19512- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19513+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19514+ pax_close_userland(); \
19515+} while (0)
19516
19517 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19518- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19519+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19520 "2:\n" \
19521 _ASM_EXTABLE_EX(1b, 2b) \
19522 : : ltype(x), "m" (__m(addr)))
19523@@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19524 */
19525 #define uaccess_try do { \
19526 current_thread_info()->uaccess_err = 0; \
19527+ pax_open_userland(); \
19528 stac(); \
19529 barrier();
19530
19531 #define uaccess_catch(err) \
19532 clac(); \
19533+ pax_close_userland(); \
19534 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19535 } while (0)
19536
19537@@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19538 * On error, the variable @x is set to zero.
19539 */
19540
19541+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19542+#define __get_user(x, ptr) get_user((x), (ptr))
19543+#else
19544 #define __get_user(x, ptr) \
19545 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19546+#endif
19547
19548 /**
19549 * __put_user: - Write a simple value into user space, with less checking.
19550@@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19551 * Returns zero on success, or -EFAULT on error.
19552 */
19553
19554+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19555+#define __put_user(x, ptr) put_user((x), (ptr))
19556+#else
19557 #define __put_user(x, ptr) \
19558 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19559+#endif
19560
19561 #define __get_user_unaligned __get_user
19562 #define __put_user_unaligned __put_user
19563@@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19564 #define get_user_ex(x, ptr) do { \
19565 unsigned long __gue_val; \
19566 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19567- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19568+ (x) = (__typeof__(*(ptr)))__gue_val; \
19569 } while (0)
19570
19571 #define put_user_try uaccess_try
19572@@ -536,17 +609,6 @@ extern struct movsl_mask {
19573
19574 #define ARCH_HAS_NOCACHE_UACCESS 1
19575
19576-#ifdef CONFIG_X86_32
19577-# include <asm/uaccess_32.h>
19578-#else
19579-# include <asm/uaccess_64.h>
19580-#endif
19581-
19582-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19583- unsigned n);
19584-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19585- unsigned n);
19586-
19587 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19588 # define copy_user_diag __compiletime_error
19589 #else
19590@@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19591 extern void copy_user_diag("copy_from_user() buffer size is too small")
19592 copy_from_user_overflow(void);
19593 extern void copy_user_diag("copy_to_user() buffer size is too small")
19594-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19595+copy_to_user_overflow(void);
19596
19597 #undef copy_user_diag
19598
19599@@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19600
19601 extern void
19602 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19603-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19604+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19605 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19606
19607 #else
19608@@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19609
19610 #endif
19611
19612+#ifdef CONFIG_X86_32
19613+# include <asm/uaccess_32.h>
19614+#else
19615+# include <asm/uaccess_64.h>
19616+#endif
19617+
19618 static inline unsigned long __must_check
19619 copy_from_user(void *to, const void __user *from, unsigned long n)
19620 {
19621- int sz = __compiletime_object_size(to);
19622+ size_t sz = __compiletime_object_size(to);
19623
19624 might_fault();
19625
19626@@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19627 * case, and do only runtime checking for non-constant sizes.
19628 */
19629
19630- if (likely(sz < 0 || sz >= n))
19631- n = _copy_from_user(to, from, n);
19632- else if(__builtin_constant_p(n))
19633- copy_from_user_overflow();
19634- else
19635- __copy_from_user_overflow(sz, n);
19636+ if (likely(sz != (size_t)-1 && sz < n)) {
19637+ if(__builtin_constant_p(n))
19638+ copy_from_user_overflow();
19639+ else
19640+ __copy_from_user_overflow(sz, n);
19641+ } if (access_ok(VERIFY_READ, from, n))
19642+ n = __copy_from_user(to, from, n);
19643+ else if ((long)n > 0)
19644+ memset(to, 0, n);
19645
19646 return n;
19647 }
19648@@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19649 static inline unsigned long __must_check
19650 copy_to_user(void __user *to, const void *from, unsigned long n)
19651 {
19652- int sz = __compiletime_object_size(from);
19653+ size_t sz = __compiletime_object_size(from);
19654
19655 might_fault();
19656
19657 /* See the comment in copy_from_user() above. */
19658- if (likely(sz < 0 || sz >= n))
19659- n = _copy_to_user(to, from, n);
19660- else if(__builtin_constant_p(n))
19661- copy_to_user_overflow();
19662- else
19663- __copy_to_user_overflow(sz, n);
19664+ if (likely(sz != (size_t)-1 && sz < n)) {
19665+ if(__builtin_constant_p(n))
19666+ copy_to_user_overflow();
19667+ else
19668+ __copy_to_user_overflow(sz, n);
19669+ } else if (access_ok(VERIFY_WRITE, to, n))
19670+ n = __copy_to_user(to, from, n);
19671
19672 return n;
19673 }
19674diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19675index 3c03a5d..1071638 100644
19676--- a/arch/x86/include/asm/uaccess_32.h
19677+++ b/arch/x86/include/asm/uaccess_32.h
19678@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19679 static __always_inline unsigned long __must_check
19680 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19681 {
19682+ if ((long)n < 0)
19683+ return n;
19684+
19685+ check_object_size(from, n, true);
19686+
19687 if (__builtin_constant_p(n)) {
19688 unsigned long ret;
19689
19690@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19691 __copy_to_user(void __user *to, const void *from, unsigned long n)
19692 {
19693 might_fault();
19694+
19695 return __copy_to_user_inatomic(to, from, n);
19696 }
19697
19698 static __always_inline unsigned long
19699 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19700 {
19701+ if ((long)n < 0)
19702+ return n;
19703+
19704 /* Avoid zeroing the tail if the copy fails..
19705 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19706 * but as the zeroing behaviour is only significant when n is not
19707@@ -137,6 +146,12 @@ static __always_inline unsigned long
19708 __copy_from_user(void *to, const void __user *from, unsigned long n)
19709 {
19710 might_fault();
19711+
19712+ if ((long)n < 0)
19713+ return n;
19714+
19715+ check_object_size(to, n, false);
19716+
19717 if (__builtin_constant_p(n)) {
19718 unsigned long ret;
19719
19720@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19721 const void __user *from, unsigned long n)
19722 {
19723 might_fault();
19724+
19725+ if ((long)n < 0)
19726+ return n;
19727+
19728 if (__builtin_constant_p(n)) {
19729 unsigned long ret;
19730
19731@@ -181,7 +200,10 @@ static __always_inline unsigned long
19732 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19733 unsigned long n)
19734 {
19735- return __copy_from_user_ll_nocache_nozero(to, from, n);
19736+ if ((long)n < 0)
19737+ return n;
19738+
19739+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19740 }
19741
19742 #endif /* _ASM_X86_UACCESS_32_H */
19743diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19744index 190413d..206c200 100644
19745--- a/arch/x86/include/asm/uaccess_64.h
19746+++ b/arch/x86/include/asm/uaccess_64.h
19747@@ -10,6 +10,9 @@
19748 #include <asm/alternative.h>
19749 #include <asm/cpufeature.h>
19750 #include <asm/page.h>
19751+#include <asm/pgtable.h>
19752+
19753+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19754
19755 /*
19756 * Copy To/From Userspace
19757@@ -17,14 +20,14 @@
19758
19759 /* Handles exceptions in both to and from, but doesn't do access_ok */
19760 __must_check unsigned long
19761-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19762+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19763 __must_check unsigned long
19764-copy_user_generic_string(void *to, const void *from, unsigned len);
19765+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19766 __must_check unsigned long
19767-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19768+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19769
19770 static __always_inline __must_check unsigned long
19771-copy_user_generic(void *to, const void *from, unsigned len)
19772+copy_user_generic(void *to, const void *from, unsigned long len)
19773 {
19774 unsigned ret;
19775
19776@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19777 }
19778
19779 __must_check unsigned long
19780-copy_in_user(void __user *to, const void __user *from, unsigned len);
19781+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19782
19783 static __always_inline __must_check
19784-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19785+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19786 {
19787- int ret = 0;
19788+ size_t sz = __compiletime_object_size(dst);
19789+ unsigned ret = 0;
19790+
19791+ if (size > INT_MAX)
19792+ return size;
19793+
19794+ check_object_size(dst, size, false);
19795+
19796+#ifdef CONFIG_PAX_MEMORY_UDEREF
19797+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19798+ return size;
19799+#endif
19800+
19801+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19802+ if(__builtin_constant_p(size))
19803+ copy_from_user_overflow();
19804+ else
19805+ __copy_from_user_overflow(sz, size);
19806+ return size;
19807+ }
19808
19809 if (!__builtin_constant_p(size))
19810- return copy_user_generic(dst, (__force void *)src, size);
19811+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19812 switch (size) {
19813- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19814+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19815 ret, "b", "b", "=q", 1);
19816 return ret;
19817- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19818+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19819 ret, "w", "w", "=r", 2);
19820 return ret;
19821- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19822+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19823 ret, "l", "k", "=r", 4);
19824 return ret;
19825- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19826+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19827 ret, "q", "", "=r", 8);
19828 return ret;
19829 case 10:
19830- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19831+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19832 ret, "q", "", "=r", 10);
19833 if (unlikely(ret))
19834 return ret;
19835 __get_user_asm(*(u16 *)(8 + (char *)dst),
19836- (u16 __user *)(8 + (char __user *)src),
19837+ (const u16 __user *)(8 + (const char __user *)src),
19838 ret, "w", "w", "=r", 2);
19839 return ret;
19840 case 16:
19841- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19842+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19843 ret, "q", "", "=r", 16);
19844 if (unlikely(ret))
19845 return ret;
19846 __get_user_asm(*(u64 *)(8 + (char *)dst),
19847- (u64 __user *)(8 + (char __user *)src),
19848+ (const u64 __user *)(8 + (const char __user *)src),
19849 ret, "q", "", "=r", 8);
19850 return ret;
19851 default:
19852- return copy_user_generic(dst, (__force void *)src, size);
19853+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19854 }
19855 }
19856
19857 static __always_inline __must_check
19858-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19859+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19860 {
19861 might_fault();
19862 return __copy_from_user_nocheck(dst, src, size);
19863 }
19864
19865 static __always_inline __must_check
19866-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19867+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19868 {
19869- int ret = 0;
19870+ size_t sz = __compiletime_object_size(src);
19871+ unsigned ret = 0;
19872+
19873+ if (size > INT_MAX)
19874+ return size;
19875+
19876+ check_object_size(src, size, true);
19877+
19878+#ifdef CONFIG_PAX_MEMORY_UDEREF
19879+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19880+ return size;
19881+#endif
19882+
19883+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19884+ if(__builtin_constant_p(size))
19885+ copy_to_user_overflow();
19886+ else
19887+ __copy_to_user_overflow(sz, size);
19888+ return size;
19889+ }
19890
19891 if (!__builtin_constant_p(size))
19892- return copy_user_generic((__force void *)dst, src, size);
19893+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19894 switch (size) {
19895- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19896+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19897 ret, "b", "b", "iq", 1);
19898 return ret;
19899- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19900+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19901 ret, "w", "w", "ir", 2);
19902 return ret;
19903- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19904+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19905 ret, "l", "k", "ir", 4);
19906 return ret;
19907- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19908+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19909 ret, "q", "", "er", 8);
19910 return ret;
19911 case 10:
19912- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19913+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19914 ret, "q", "", "er", 10);
19915 if (unlikely(ret))
19916 return ret;
19917 asm("":::"memory");
19918- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19919+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19920 ret, "w", "w", "ir", 2);
19921 return ret;
19922 case 16:
19923- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19924+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19925 ret, "q", "", "er", 16);
19926 if (unlikely(ret))
19927 return ret;
19928 asm("":::"memory");
19929- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19930+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19931 ret, "q", "", "er", 8);
19932 return ret;
19933 default:
19934- return copy_user_generic((__force void *)dst, src, size);
19935+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19936 }
19937 }
19938
19939 static __always_inline __must_check
19940-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19941+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19942 {
19943 might_fault();
19944 return __copy_to_user_nocheck(dst, src, size);
19945 }
19946
19947 static __always_inline __must_check
19948-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19949+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19950 {
19951- int ret = 0;
19952+ unsigned ret = 0;
19953
19954 might_fault();
19955+
19956+ if (size > INT_MAX)
19957+ return size;
19958+
19959+#ifdef CONFIG_PAX_MEMORY_UDEREF
19960+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19961+ return size;
19962+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19963+ return size;
19964+#endif
19965+
19966 if (!__builtin_constant_p(size))
19967- return copy_user_generic((__force void *)dst,
19968- (__force void *)src, size);
19969+ return copy_user_generic((__force_kernel void *)____m(dst),
19970+ (__force_kernel const void *)____m(src), size);
19971 switch (size) {
19972 case 1: {
19973 u8 tmp;
19974- __get_user_asm(tmp, (u8 __user *)src,
19975+ __get_user_asm(tmp, (const u8 __user *)src,
19976 ret, "b", "b", "=q", 1);
19977 if (likely(!ret))
19978 __put_user_asm(tmp, (u8 __user *)dst,
19979@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19980 }
19981 case 2: {
19982 u16 tmp;
19983- __get_user_asm(tmp, (u16 __user *)src,
19984+ __get_user_asm(tmp, (const u16 __user *)src,
19985 ret, "w", "w", "=r", 2);
19986 if (likely(!ret))
19987 __put_user_asm(tmp, (u16 __user *)dst,
19988@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19989
19990 case 4: {
19991 u32 tmp;
19992- __get_user_asm(tmp, (u32 __user *)src,
19993+ __get_user_asm(tmp, (const u32 __user *)src,
19994 ret, "l", "k", "=r", 4);
19995 if (likely(!ret))
19996 __put_user_asm(tmp, (u32 __user *)dst,
19997@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19998 }
19999 case 8: {
20000 u64 tmp;
20001- __get_user_asm(tmp, (u64 __user *)src,
20002+ __get_user_asm(tmp, (const u64 __user *)src,
20003 ret, "q", "", "=r", 8);
20004 if (likely(!ret))
20005 __put_user_asm(tmp, (u64 __user *)dst,
20006@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20007 return ret;
20008 }
20009 default:
20010- return copy_user_generic((__force void *)dst,
20011- (__force void *)src, size);
20012+ return copy_user_generic((__force_kernel void *)____m(dst),
20013+ (__force_kernel const void *)____m(src), size);
20014 }
20015 }
20016
20017-static __must_check __always_inline int
20018-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20019+static __must_check __always_inline unsigned long
20020+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20021 {
20022- return __copy_from_user_nocheck(dst, (__force const void *)src, size);
20023+ return __copy_from_user_nocheck(dst, src, size);
20024 }
20025
20026-static __must_check __always_inline int
20027-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20028+static __must_check __always_inline unsigned long
20029+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20030 {
20031- return __copy_to_user_nocheck((__force void *)dst, src, size);
20032+ return __copy_to_user_nocheck(dst, src, size);
20033 }
20034
20035-extern long __copy_user_nocache(void *dst, const void __user *src,
20036- unsigned size, int zerorest);
20037+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20038+ unsigned long size, int zerorest);
20039
20040-static inline int
20041-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20042+static inline unsigned long
20043+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20044 {
20045 might_fault();
20046+
20047+ if (size > INT_MAX)
20048+ return size;
20049+
20050+#ifdef CONFIG_PAX_MEMORY_UDEREF
20051+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20052+ return size;
20053+#endif
20054+
20055 return __copy_user_nocache(dst, src, size, 1);
20056 }
20057
20058-static inline int
20059+static inline unsigned long
20060 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20061- unsigned size)
20062+ unsigned long size)
20063 {
20064+ if (size > INT_MAX)
20065+ return size;
20066+
20067+#ifdef CONFIG_PAX_MEMORY_UDEREF
20068+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20069+ return size;
20070+#endif
20071+
20072 return __copy_user_nocache(dst, src, size, 0);
20073 }
20074
20075 unsigned long
20076-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20077+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20078
20079 #endif /* _ASM_X86_UACCESS_64_H */
20080diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20081index 5b238981..77fdd78 100644
20082--- a/arch/x86/include/asm/word-at-a-time.h
20083+++ b/arch/x86/include/asm/word-at-a-time.h
20084@@ -11,7 +11,7 @@
20085 * and shift, for example.
20086 */
20087 struct word_at_a_time {
20088- const unsigned long one_bits, high_bits;
20089+ unsigned long one_bits, high_bits;
20090 };
20091
20092 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20093diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20094index 0f1be11..f7542bf 100644
20095--- a/arch/x86/include/asm/x86_init.h
20096+++ b/arch/x86/include/asm/x86_init.h
20097@@ -129,7 +129,7 @@ struct x86_init_ops {
20098 struct x86_init_timers timers;
20099 struct x86_init_iommu iommu;
20100 struct x86_init_pci pci;
20101-};
20102+} __no_const;
20103
20104 /**
20105 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20106@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20107 void (*setup_percpu_clockev)(void);
20108 void (*early_percpu_clock_init)(void);
20109 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20110-};
20111+} __no_const;
20112
20113 struct timespec;
20114
20115@@ -168,7 +168,7 @@ struct x86_platform_ops {
20116 void (*save_sched_clock_state)(void);
20117 void (*restore_sched_clock_state)(void);
20118 void (*apic_post_init)(void);
20119-};
20120+} __no_const;
20121
20122 struct pci_dev;
20123 struct msi_msg;
20124@@ -185,7 +185,7 @@ struct x86_msi_ops {
20125 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20126 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20127 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20128-};
20129+} __no_const;
20130
20131 struct IO_APIC_route_entry;
20132 struct io_apic_irq_attr;
20133@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20134 unsigned int destination, int vector,
20135 struct io_apic_irq_attr *attr);
20136 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20137-};
20138+} __no_const;
20139
20140 extern struct x86_init_ops x86_init;
20141 extern struct x86_cpuinit_ops x86_cpuinit;
20142diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20143index b913915..4f5a581 100644
20144--- a/arch/x86/include/asm/xen/page.h
20145+++ b/arch/x86/include/asm/xen/page.h
20146@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20147 extern struct page *m2p_find_override(unsigned long mfn);
20148 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20149
20150-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20151+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20152 {
20153 unsigned long mfn;
20154
20155diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20156index 0415cda..3b22adc 100644
20157--- a/arch/x86/include/asm/xsave.h
20158+++ b/arch/x86/include/asm/xsave.h
20159@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20160 if (unlikely(err))
20161 return -EFAULT;
20162
20163+ pax_open_userland();
20164 __asm__ __volatile__(ASM_STAC "\n"
20165- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20166+ "1:"
20167+ __copyuser_seg
20168+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20169 "2: " ASM_CLAC "\n"
20170 ".section .fixup,\"ax\"\n"
20171 "3: movl $-1,%[err]\n"
20172@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20173 : [err] "=r" (err)
20174 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20175 : "memory");
20176+ pax_close_userland();
20177 return err;
20178 }
20179
20180 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20181 {
20182 int err;
20183- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20184+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20185 u32 lmask = mask;
20186 u32 hmask = mask >> 32;
20187
20188+ pax_open_userland();
20189 __asm__ __volatile__(ASM_STAC "\n"
20190- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20191+ "1:"
20192+ __copyuser_seg
20193+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20194 "2: " ASM_CLAC "\n"
20195 ".section .fixup,\"ax\"\n"
20196 "3: movl $-1,%[err]\n"
20197@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20198 : [err] "=r" (err)
20199 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20200 : "memory"); /* memory required? */
20201+ pax_close_userland();
20202 return err;
20203 }
20204
20205diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20206index bbae024..e1528f9 100644
20207--- a/arch/x86/include/uapi/asm/e820.h
20208+++ b/arch/x86/include/uapi/asm/e820.h
20209@@ -63,7 +63,7 @@ struct e820map {
20210 #define ISA_START_ADDRESS 0xa0000
20211 #define ISA_END_ADDRESS 0x100000
20212
20213-#define BIOS_BEGIN 0x000a0000
20214+#define BIOS_BEGIN 0x000c0000
20215 #define BIOS_END 0x00100000
20216
20217 #define BIOS_ROM_BASE 0xffe00000
20218diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20219index 7b0a55a..ad115bf 100644
20220--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20221+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20222@@ -49,7 +49,6 @@
20223 #define EFLAGS 144
20224 #define RSP 152
20225 #define SS 160
20226-#define ARGOFFSET R11
20227 #endif /* __ASSEMBLY__ */
20228
20229 /* top of stack page */
20230diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20231index 9b0a34e..fc7e553 100644
20232--- a/arch/x86/kernel/Makefile
20233+++ b/arch/x86/kernel/Makefile
20234@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20235 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20236 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20237 obj-y += probe_roms.o
20238-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20239+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20240 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20241 obj-y += syscall_$(BITS).o
20242 obj-$(CONFIG_X86_64) += vsyscall_64.o
20243diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20244index 6c0b43b..e67bb31 100644
20245--- a/arch/x86/kernel/acpi/boot.c
20246+++ b/arch/x86/kernel/acpi/boot.c
20247@@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20248 * If your system is blacklisted here, but you find that acpi=force
20249 * works for you, please contact linux-acpi@vger.kernel.org
20250 */
20251-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20252+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20253 /*
20254 * Boxes that need ACPI disabled
20255 */
20256@@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20257 };
20258
20259 /* second table for DMI checks that should run after early-quirks */
20260-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20261+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20262 /*
20263 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20264 * which includes some code which overrides all temperature
20265diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20266index 3a2ae4c..9db31d6 100644
20267--- a/arch/x86/kernel/acpi/sleep.c
20268+++ b/arch/x86/kernel/acpi/sleep.c
20269@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20270 #else /* CONFIG_64BIT */
20271 #ifdef CONFIG_SMP
20272 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20273+
20274+ pax_open_kernel();
20275 early_gdt_descr.address =
20276 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20277+ pax_close_kernel();
20278+
20279 initial_gs = per_cpu_offset(smp_processor_id());
20280 #endif
20281 initial_code = (unsigned long)wakeup_long64;
20282diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20283index 665c6b7..eae4d56 100644
20284--- a/arch/x86/kernel/acpi/wakeup_32.S
20285+++ b/arch/x86/kernel/acpi/wakeup_32.S
20286@@ -29,13 +29,11 @@ wakeup_pmode_return:
20287 # and restore the stack ... but you need gdt for this to work
20288 movl saved_context_esp, %esp
20289
20290- movl %cs:saved_magic, %eax
20291- cmpl $0x12345678, %eax
20292+ cmpl $0x12345678, saved_magic
20293 jne bogus_magic
20294
20295 # jump to place where we left off
20296- movl saved_eip, %eax
20297- jmp *%eax
20298+ jmp *(saved_eip)
20299
20300 bogus_magic:
20301 jmp bogus_magic
20302diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20303index df94598..f3b29bf 100644
20304--- a/arch/x86/kernel/alternative.c
20305+++ b/arch/x86/kernel/alternative.c
20306@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20307 */
20308 for (a = start; a < end; a++) {
20309 instr = (u8 *)&a->instr_offset + a->instr_offset;
20310+
20311+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20312+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20313+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20314+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20315+#endif
20316+
20317 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20318 BUG_ON(a->replacementlen > a->instrlen);
20319 BUG_ON(a->instrlen > sizeof(insnbuf));
20320@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20321 for (poff = start; poff < end; poff++) {
20322 u8 *ptr = (u8 *)poff + *poff;
20323
20324+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20325+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20326+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20327+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20328+#endif
20329+
20330 if (!*poff || ptr < text || ptr >= text_end)
20331 continue;
20332 /* turn DS segment override prefix into lock prefix */
20333- if (*ptr == 0x3e)
20334+ if (*ktla_ktva(ptr) == 0x3e)
20335 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20336 }
20337 mutex_unlock(&text_mutex);
20338@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20339 for (poff = start; poff < end; poff++) {
20340 u8 *ptr = (u8 *)poff + *poff;
20341
20342+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20343+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20344+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20345+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20346+#endif
20347+
20348 if (!*poff || ptr < text || ptr >= text_end)
20349 continue;
20350 /* turn lock prefix into DS segment override prefix */
20351- if (*ptr == 0xf0)
20352+ if (*ktla_ktva(ptr) == 0xf0)
20353 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20354 }
20355 mutex_unlock(&text_mutex);
20356@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20357
20358 BUG_ON(p->len > MAX_PATCH_LEN);
20359 /* prep the buffer with the original instructions */
20360- memcpy(insnbuf, p->instr, p->len);
20361+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20362 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20363 (unsigned long)p->instr, p->len);
20364
20365@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20366 if (!uniproc_patched || num_possible_cpus() == 1)
20367 free_init_pages("SMP alternatives",
20368 (unsigned long)__smp_locks,
20369- (unsigned long)__smp_locks_end);
20370+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20371 #endif
20372
20373 apply_paravirt(__parainstructions, __parainstructions_end);
20374@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20375 * instructions. And on the local CPU you need to be protected again NMI or MCE
20376 * handlers seeing an inconsistent instruction while you patch.
20377 */
20378-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20379+void *__kprobes text_poke_early(void *addr, const void *opcode,
20380 size_t len)
20381 {
20382 unsigned long flags;
20383 local_irq_save(flags);
20384- memcpy(addr, opcode, len);
20385+
20386+ pax_open_kernel();
20387+ memcpy(ktla_ktva(addr), opcode, len);
20388 sync_core();
20389+ pax_close_kernel();
20390+
20391 local_irq_restore(flags);
20392 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20393 that causes hangs on some VIA CPUs. */
20394@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20395 */
20396 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20397 {
20398- unsigned long flags;
20399- char *vaddr;
20400+ unsigned char *vaddr = ktla_ktva(addr);
20401 struct page *pages[2];
20402- int i;
20403+ size_t i;
20404
20405 if (!core_kernel_text((unsigned long)addr)) {
20406- pages[0] = vmalloc_to_page(addr);
20407- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20408+ pages[0] = vmalloc_to_page(vaddr);
20409+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20410 } else {
20411- pages[0] = virt_to_page(addr);
20412+ pages[0] = virt_to_page(vaddr);
20413 WARN_ON(!PageReserved(pages[0]));
20414- pages[1] = virt_to_page(addr + PAGE_SIZE);
20415+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20416 }
20417 BUG_ON(!pages[0]);
20418- local_irq_save(flags);
20419- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20420- if (pages[1])
20421- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20422- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20423- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20424- clear_fixmap(FIX_TEXT_POKE0);
20425- if (pages[1])
20426- clear_fixmap(FIX_TEXT_POKE1);
20427- local_flush_tlb();
20428- sync_core();
20429- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20430- that causes hangs on some VIA CPUs. */
20431+ text_poke_early(addr, opcode, len);
20432 for (i = 0; i < len; i++)
20433- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20434- local_irq_restore(flags);
20435+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20436 return addr;
20437 }
20438
20439@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20440 if (likely(!bp_patching_in_progress))
20441 return 0;
20442
20443- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20444+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20445 return 0;
20446
20447 /* set up the specified breakpoint handler */
20448@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20449 */
20450 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20451 {
20452- unsigned char int3 = 0xcc;
20453+ const unsigned char int3 = 0xcc;
20454
20455 bp_int3_handler = handler;
20456 bp_int3_addr = (u8 *)addr + sizeof(int3);
20457diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20458index d278736..0b4af9a8 100644
20459--- a/arch/x86/kernel/apic/apic.c
20460+++ b/arch/x86/kernel/apic/apic.c
20461@@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20462 /*
20463 * Debug level, exported for io_apic.c
20464 */
20465-unsigned int apic_verbosity;
20466+int apic_verbosity;
20467
20468 int pic_mode;
20469
20470@@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20471 apic_write(APIC_ESR, 0);
20472 v1 = apic_read(APIC_ESR);
20473 ack_APIC_irq();
20474- atomic_inc(&irq_err_count);
20475+ atomic_inc_unchecked(&irq_err_count);
20476
20477 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20478 smp_processor_id(), v0 , v1);
20479diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20480index 00c77cf..2dc6a2d 100644
20481--- a/arch/x86/kernel/apic/apic_flat_64.c
20482+++ b/arch/x86/kernel/apic/apic_flat_64.c
20483@@ -157,7 +157,7 @@ static int flat_probe(void)
20484 return 1;
20485 }
20486
20487-static struct apic apic_flat = {
20488+static struct apic apic_flat __read_only = {
20489 .name = "flat",
20490 .probe = flat_probe,
20491 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20492@@ -271,7 +271,7 @@ static int physflat_probe(void)
20493 return 0;
20494 }
20495
20496-static struct apic apic_physflat = {
20497+static struct apic apic_physflat __read_only = {
20498
20499 .name = "physical flat",
20500 .probe = physflat_probe,
20501diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20502index e145f28..2752888 100644
20503--- a/arch/x86/kernel/apic/apic_noop.c
20504+++ b/arch/x86/kernel/apic/apic_noop.c
20505@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20506 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20507 }
20508
20509-struct apic apic_noop = {
20510+struct apic apic_noop __read_only = {
20511 .name = "noop",
20512 .probe = noop_probe,
20513 .acpi_madt_oem_check = NULL,
20514diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20515index d50e364..543bee3 100644
20516--- a/arch/x86/kernel/apic/bigsmp_32.c
20517+++ b/arch/x86/kernel/apic/bigsmp_32.c
20518@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20519 return dmi_bigsmp;
20520 }
20521
20522-static struct apic apic_bigsmp = {
20523+static struct apic apic_bigsmp __read_only = {
20524
20525 .name = "bigsmp",
20526 .probe = probe_bigsmp,
20527diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20528index c552247..587a316 100644
20529--- a/arch/x86/kernel/apic/es7000_32.c
20530+++ b/arch/x86/kernel/apic/es7000_32.c
20531@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20532 return ret && es7000_apic_is_cluster();
20533 }
20534
20535-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20536-static struct apic __refdata apic_es7000_cluster = {
20537+static struct apic apic_es7000_cluster __read_only = {
20538
20539 .name = "es7000",
20540 .probe = probe_es7000,
20541@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20542 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20543 };
20544
20545-static struct apic __refdata apic_es7000 = {
20546+static struct apic apic_es7000 __read_only = {
20547
20548 .name = "es7000",
20549 .probe = probe_es7000,
20550diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20551index e63a5bd..c0babf8 100644
20552--- a/arch/x86/kernel/apic/io_apic.c
20553+++ b/arch/x86/kernel/apic/io_apic.c
20554@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20555 }
20556 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20557
20558-void lock_vector_lock(void)
20559+void lock_vector_lock(void) __acquires(vector_lock)
20560 {
20561 /* Used to the online set of cpus does not change
20562 * during assign_irq_vector.
20563@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20564 raw_spin_lock(&vector_lock);
20565 }
20566
20567-void unlock_vector_lock(void)
20568+void unlock_vector_lock(void) __releases(vector_lock)
20569 {
20570 raw_spin_unlock(&vector_lock);
20571 }
20572@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20573 ack_APIC_irq();
20574 }
20575
20576-atomic_t irq_mis_count;
20577+atomic_unchecked_t irq_mis_count;
20578
20579 #ifdef CONFIG_GENERIC_PENDING_IRQ
20580 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20581@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20582 * at the cpu.
20583 */
20584 if (!(v & (1 << (i & 0x1f)))) {
20585- atomic_inc(&irq_mis_count);
20586+ atomic_inc_unchecked(&irq_mis_count);
20587
20588 eoi_ioapic_irq(irq, cfg);
20589 }
20590diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20591index 1e42e8f..daacf44 100644
20592--- a/arch/x86/kernel/apic/numaq_32.c
20593+++ b/arch/x86/kernel/apic/numaq_32.c
20594@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20595 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20596 }
20597
20598-/* Use __refdata to keep false positive warning calm. */
20599-static struct apic __refdata apic_numaq = {
20600+static struct apic apic_numaq __read_only = {
20601
20602 .name = "NUMAQ",
20603 .probe = probe_numaq,
20604diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20605index eb35ef9..f184a21 100644
20606--- a/arch/x86/kernel/apic/probe_32.c
20607+++ b/arch/x86/kernel/apic/probe_32.c
20608@@ -72,7 +72,7 @@ static int probe_default(void)
20609 return 1;
20610 }
20611
20612-static struct apic apic_default = {
20613+static struct apic apic_default __read_only = {
20614
20615 .name = "default",
20616 .probe = probe_default,
20617diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20618index 77c95c0..434f8a4 100644
20619--- a/arch/x86/kernel/apic/summit_32.c
20620+++ b/arch/x86/kernel/apic/summit_32.c
20621@@ -486,7 +486,7 @@ void setup_summit(void)
20622 }
20623 #endif
20624
20625-static struct apic apic_summit = {
20626+static struct apic apic_summit __read_only = {
20627
20628 .name = "summit",
20629 .probe = probe_summit,
20630diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20631index 140e29d..d88bc95 100644
20632--- a/arch/x86/kernel/apic/x2apic_cluster.c
20633+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20634@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20635 return notifier_from_errno(err);
20636 }
20637
20638-static struct notifier_block __refdata x2apic_cpu_notifier = {
20639+static struct notifier_block x2apic_cpu_notifier = {
20640 .notifier_call = update_clusterinfo,
20641 };
20642
20643@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20644 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20645 }
20646
20647-static struct apic apic_x2apic_cluster = {
20648+static struct apic apic_x2apic_cluster __read_only = {
20649
20650 .name = "cluster x2apic",
20651 .probe = x2apic_cluster_probe,
20652diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20653index 562a76d..a003c0f 100644
20654--- a/arch/x86/kernel/apic/x2apic_phys.c
20655+++ b/arch/x86/kernel/apic/x2apic_phys.c
20656@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20657 return apic == &apic_x2apic_phys;
20658 }
20659
20660-static struct apic apic_x2apic_phys = {
20661+static struct apic apic_x2apic_phys __read_only = {
20662
20663 .name = "physical x2apic",
20664 .probe = x2apic_phys_probe,
20665diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20666index ad0dc04..0d9cc56 100644
20667--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20668+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20669@@ -350,7 +350,7 @@ static int uv_probe(void)
20670 return apic == &apic_x2apic_uv_x;
20671 }
20672
20673-static struct apic __refdata apic_x2apic_uv_x = {
20674+static struct apic apic_x2apic_uv_x __read_only = {
20675
20676 .name = "UV large system",
20677 .probe = uv_probe,
20678diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20679index 3ab0343..814c4787 100644
20680--- a/arch/x86/kernel/apm_32.c
20681+++ b/arch/x86/kernel/apm_32.c
20682@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20683 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20684 * even though they are called in protected mode.
20685 */
20686-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20687+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20688 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20689
20690 static const char driver_version[] = "1.16ac"; /* no spaces */
20691@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20692 BUG_ON(cpu != 0);
20693 gdt = get_cpu_gdt_table(cpu);
20694 save_desc_40 = gdt[0x40 / 8];
20695+
20696+ pax_open_kernel();
20697 gdt[0x40 / 8] = bad_bios_desc;
20698+ pax_close_kernel();
20699
20700 apm_irq_save(flags);
20701 APM_DO_SAVE_SEGS;
20702@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20703 &call->esi);
20704 APM_DO_RESTORE_SEGS;
20705 apm_irq_restore(flags);
20706+
20707+ pax_open_kernel();
20708 gdt[0x40 / 8] = save_desc_40;
20709+ pax_close_kernel();
20710+
20711 put_cpu();
20712
20713 return call->eax & 0xff;
20714@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20715 BUG_ON(cpu != 0);
20716 gdt = get_cpu_gdt_table(cpu);
20717 save_desc_40 = gdt[0x40 / 8];
20718+
20719+ pax_open_kernel();
20720 gdt[0x40 / 8] = bad_bios_desc;
20721+ pax_close_kernel();
20722
20723 apm_irq_save(flags);
20724 APM_DO_SAVE_SEGS;
20725@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20726 &call->eax);
20727 APM_DO_RESTORE_SEGS;
20728 apm_irq_restore(flags);
20729+
20730+ pax_open_kernel();
20731 gdt[0x40 / 8] = save_desc_40;
20732+ pax_close_kernel();
20733+
20734 put_cpu();
20735 return error;
20736 }
20737@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20738 * code to that CPU.
20739 */
20740 gdt = get_cpu_gdt_table(0);
20741+
20742+ pax_open_kernel();
20743 set_desc_base(&gdt[APM_CS >> 3],
20744 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20745 set_desc_base(&gdt[APM_CS_16 >> 3],
20746 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20747 set_desc_base(&gdt[APM_DS >> 3],
20748 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20749+ pax_close_kernel();
20750
20751 proc_create("apm", 0, NULL, &apm_file_ops);
20752
20753diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20754index 9f6b934..cf5ffb3 100644
20755--- a/arch/x86/kernel/asm-offsets.c
20756+++ b/arch/x86/kernel/asm-offsets.c
20757@@ -32,6 +32,8 @@ void common(void) {
20758 OFFSET(TI_flags, thread_info, flags);
20759 OFFSET(TI_status, thread_info, status);
20760 OFFSET(TI_addr_limit, thread_info, addr_limit);
20761+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20762+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20763
20764 BLANK();
20765 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20766@@ -52,8 +54,26 @@ void common(void) {
20767 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20768 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20769 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20770+
20771+#ifdef CONFIG_PAX_KERNEXEC
20772+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20773 #endif
20774
20775+#ifdef CONFIG_PAX_MEMORY_UDEREF
20776+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20777+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20778+#ifdef CONFIG_X86_64
20779+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20780+#endif
20781+#endif
20782+
20783+#endif
20784+
20785+ BLANK();
20786+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20787+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20788+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20789+
20790 #ifdef CONFIG_XEN
20791 BLANK();
20792 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20793diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20794index e7c798b..2b2019b 100644
20795--- a/arch/x86/kernel/asm-offsets_64.c
20796+++ b/arch/x86/kernel/asm-offsets_64.c
20797@@ -77,6 +77,7 @@ int main(void)
20798 BLANK();
20799 #undef ENTRY
20800
20801+ DEFINE(TSS_size, sizeof(struct tss_struct));
20802 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20803 BLANK();
20804
20805diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20806index 47b56a7..efc2bc6 100644
20807--- a/arch/x86/kernel/cpu/Makefile
20808+++ b/arch/x86/kernel/cpu/Makefile
20809@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20810 CFLAGS_REMOVE_perf_event.o = -pg
20811 endif
20812
20813-# Make sure load_percpu_segment has no stackprotector
20814-nostackp := $(call cc-option, -fno-stack-protector)
20815-CFLAGS_common.o := $(nostackp)
20816-
20817 obj-y := intel_cacheinfo.o scattered.o topology.o
20818 obj-y += proc.o capflags.o powerflags.o common.o
20819 obj-y += rdrand.o
20820diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20821index 59bfebc..d8f27bd 100644
20822--- a/arch/x86/kernel/cpu/amd.c
20823+++ b/arch/x86/kernel/cpu/amd.c
20824@@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20825 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20826 {
20827 /* AMD errata T13 (order #21922) */
20828- if ((c->x86 == 6)) {
20829+ if (c->x86 == 6) {
20830 /* Duron Rev A0 */
20831 if (c->x86_model == 3 && c->x86_mask == 0)
20832 size = 64;
20833diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20834index fe2bdd0..77b0d1b 100644
20835--- a/arch/x86/kernel/cpu/common.c
20836+++ b/arch/x86/kernel/cpu/common.c
20837@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20838
20839 static const struct cpu_dev *this_cpu = &default_cpu;
20840
20841-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20842-#ifdef CONFIG_X86_64
20843- /*
20844- * We need valid kernel segments for data and code in long mode too
20845- * IRET will check the segment types kkeil 2000/10/28
20846- * Also sysret mandates a special GDT layout
20847- *
20848- * TLS descriptors are currently at a different place compared to i386.
20849- * Hopefully nobody expects them at a fixed place (Wine?)
20850- */
20851- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20852- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20853- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20854- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20855- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20856- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20857-#else
20858- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20859- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20860- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20861- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20862- /*
20863- * Segments used for calling PnP BIOS have byte granularity.
20864- * They code segments and data segments have fixed 64k limits,
20865- * the transfer segment sizes are set at run time.
20866- */
20867- /* 32-bit code */
20868- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20869- /* 16-bit code */
20870- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20871- /* 16-bit data */
20872- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20873- /* 16-bit data */
20874- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20875- /* 16-bit data */
20876- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20877- /*
20878- * The APM segments have byte granularity and their bases
20879- * are set at run time. All have 64k limits.
20880- */
20881- /* 32-bit code */
20882- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20883- /* 16-bit code */
20884- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20885- /* data */
20886- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20887-
20888- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20889- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20890- GDT_STACK_CANARY_INIT
20891-#endif
20892-} };
20893-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20894-
20895 static int __init x86_xsave_setup(char *s)
20896 {
20897 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20898@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20899 }
20900 }
20901
20902+#ifdef CONFIG_X86_64
20903+static __init int setup_disable_pcid(char *arg)
20904+{
20905+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20906+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20907+
20908+#ifdef CONFIG_PAX_MEMORY_UDEREF
20909+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20910+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20911+#endif
20912+
20913+ return 1;
20914+}
20915+__setup("nopcid", setup_disable_pcid);
20916+
20917+static void setup_pcid(struct cpuinfo_x86 *c)
20918+{
20919+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20920+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20921+
20922+#ifdef CONFIG_PAX_MEMORY_UDEREF
20923+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20924+ pax_open_kernel();
20925+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20926+ pax_close_kernel();
20927+ printk("PAX: slow and weak UDEREF enabled\n");
20928+ } else
20929+ printk("PAX: UDEREF disabled\n");
20930+#endif
20931+
20932+ return;
20933+ }
20934+
20935+ printk("PAX: PCID detected\n");
20936+ set_in_cr4(X86_CR4_PCIDE);
20937+
20938+#ifdef CONFIG_PAX_MEMORY_UDEREF
20939+ pax_open_kernel();
20940+ clone_pgd_mask = ~(pgdval_t)0UL;
20941+ pax_close_kernel();
20942+ if (pax_user_shadow_base)
20943+ printk("PAX: weak UDEREF enabled\n");
20944+ else {
20945+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20946+ printk("PAX: strong UDEREF enabled\n");
20947+ }
20948+#endif
20949+
20950+ if (cpu_has(c, X86_FEATURE_INVPCID))
20951+ printk("PAX: INVPCID detected\n");
20952+}
20953+#endif
20954+
20955 /*
20956 * Some CPU features depend on higher CPUID levels, which may not always
20957 * be available due to CPUID level capping or broken virtualization
20958@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20959 {
20960 struct desc_ptr gdt_descr;
20961
20962- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20963+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20964 gdt_descr.size = GDT_SIZE - 1;
20965 load_gdt(&gdt_descr);
20966 /* Reload the per-cpu base */
20967@@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20968 setup_smep(c);
20969 setup_smap(c);
20970
20971+#ifdef CONFIG_X86_64
20972+ setup_pcid(c);
20973+#endif
20974+
20975 /*
20976 * The vendor-specific functions might have changed features.
20977 * Now we do "generic changes."
20978@@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20979 /* Filter out anything that depends on CPUID levels we don't have */
20980 filter_cpuid_features(c, true);
20981
20982+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20983+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20984+#endif
20985+
20986 /* If the model name is still unset, do table lookup. */
20987 if (!c->x86_model_id[0]) {
20988 const char *p;
20989@@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20990 }
20991 __setup("clearcpuid=", setup_disablecpuid);
20992
20993+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20994+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20995+
20996 #ifdef CONFIG_X86_64
20997-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20998-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20999- (unsigned long) debug_idt_table };
21000+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21001+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21002
21003 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21004 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21005@@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21006 EXPORT_PER_CPU_SYMBOL(current_task);
21007
21008 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21009- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21010+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21011 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21012
21013 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21014@@ -1244,7 +1253,7 @@ void cpu_init(void)
21015 load_ucode_ap();
21016
21017 cpu = stack_smp_processor_id();
21018- t = &per_cpu(init_tss, cpu);
21019+ t = init_tss + cpu;
21020 oist = &per_cpu(orig_ist, cpu);
21021
21022 #ifdef CONFIG_NUMA
21023@@ -1279,7 +1288,6 @@ void cpu_init(void)
21024 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21025 barrier();
21026
21027- x86_configure_nx();
21028 enable_x2apic();
21029
21030 /*
21031@@ -1331,7 +1339,7 @@ void cpu_init(void)
21032 {
21033 int cpu = smp_processor_id();
21034 struct task_struct *curr = current;
21035- struct tss_struct *t = &per_cpu(init_tss, cpu);
21036+ struct tss_struct *t = init_tss + cpu;
21037 struct thread_struct *thread = &curr->thread;
21038
21039 show_ucode_info_early();
21040diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21041index 0641113..06f5ba4 100644
21042--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21043+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21044@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21045 };
21046
21047 #ifdef CONFIG_AMD_NB
21048+static struct attribute *default_attrs_amd_nb[] = {
21049+ &type.attr,
21050+ &level.attr,
21051+ &coherency_line_size.attr,
21052+ &physical_line_partition.attr,
21053+ &ways_of_associativity.attr,
21054+ &number_of_sets.attr,
21055+ &size.attr,
21056+ &shared_cpu_map.attr,
21057+ &shared_cpu_list.attr,
21058+ NULL,
21059+ NULL,
21060+ NULL,
21061+ NULL
21062+};
21063+
21064 static struct attribute **amd_l3_attrs(void)
21065 {
21066 static struct attribute **attrs;
21067@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21068
21069 n = ARRAY_SIZE(default_attrs);
21070
21071- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21072- n += 2;
21073-
21074- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21075- n += 1;
21076-
21077- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21078- if (attrs == NULL)
21079- return attrs = default_attrs;
21080-
21081- for (n = 0; default_attrs[n]; n++)
21082- attrs[n] = default_attrs[n];
21083+ attrs = default_attrs_amd_nb;
21084
21085 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21086 attrs[n++] = &cache_disable_0.attr;
21087@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21088 .default_attrs = default_attrs,
21089 };
21090
21091+#ifdef CONFIG_AMD_NB
21092+static struct kobj_type ktype_cache_amd_nb = {
21093+ .sysfs_ops = &sysfs_ops,
21094+ .default_attrs = default_attrs_amd_nb,
21095+};
21096+#endif
21097+
21098 static struct kobj_type ktype_percpu_entry = {
21099 .sysfs_ops = &sysfs_ops,
21100 };
21101@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21102 return retval;
21103 }
21104
21105+#ifdef CONFIG_AMD_NB
21106+ amd_l3_attrs();
21107+#endif
21108+
21109 for (i = 0; i < num_cache_leaves; i++) {
21110+ struct kobj_type *ktype;
21111+
21112 this_object = INDEX_KOBJECT_PTR(cpu, i);
21113 this_object->cpu = cpu;
21114 this_object->index = i;
21115
21116 this_leaf = CPUID4_INFO_IDX(cpu, i);
21117
21118- ktype_cache.default_attrs = default_attrs;
21119+ ktype = &ktype_cache;
21120 #ifdef CONFIG_AMD_NB
21121 if (this_leaf->base.nb)
21122- ktype_cache.default_attrs = amd_l3_attrs();
21123+ ktype = &ktype_cache_amd_nb;
21124 #endif
21125 retval = kobject_init_and_add(&(this_object->kobj),
21126- &ktype_cache,
21127+ ktype,
21128 per_cpu(ici_cache_kobject, cpu),
21129 "index%1lu", i);
21130 if (unlikely(retval)) {
21131diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21132index b3218cd..99a75de 100644
21133--- a/arch/x86/kernel/cpu/mcheck/mce.c
21134+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21135@@ -45,6 +45,7 @@
21136 #include <asm/processor.h>
21137 #include <asm/mce.h>
21138 #include <asm/msr.h>
21139+#include <asm/local.h>
21140
21141 #include "mce-internal.h"
21142
21143@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21144 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21145 m->cs, m->ip);
21146
21147- if (m->cs == __KERNEL_CS)
21148+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21149 print_symbol("{%s}", m->ip);
21150 pr_cont("\n");
21151 }
21152@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21153
21154 #define PANIC_TIMEOUT 5 /* 5 seconds */
21155
21156-static atomic_t mce_paniced;
21157+static atomic_unchecked_t mce_paniced;
21158
21159 static int fake_panic;
21160-static atomic_t mce_fake_paniced;
21161+static atomic_unchecked_t mce_fake_paniced;
21162
21163 /* Panic in progress. Enable interrupts and wait for final IPI */
21164 static void wait_for_panic(void)
21165@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21166 /*
21167 * Make sure only one CPU runs in machine check panic
21168 */
21169- if (atomic_inc_return(&mce_paniced) > 1)
21170+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21171 wait_for_panic();
21172 barrier();
21173
21174@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21175 console_verbose();
21176 } else {
21177 /* Don't log too much for fake panic */
21178- if (atomic_inc_return(&mce_fake_paniced) > 1)
21179+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21180 return;
21181 }
21182 /* First print corrected ones that are still unlogged */
21183@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21184 if (!fake_panic) {
21185 if (panic_timeout == 0)
21186 panic_timeout = mca_cfg.panic_timeout;
21187- panic(msg);
21188+ panic("%s", msg);
21189 } else
21190 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21191 }
21192@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21193 * might have been modified by someone else.
21194 */
21195 rmb();
21196- if (atomic_read(&mce_paniced))
21197+ if (atomic_read_unchecked(&mce_paniced))
21198 wait_for_panic();
21199 if (!mca_cfg.monarch_timeout)
21200 goto out;
21201@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21202 }
21203
21204 /* Call the installed machine check handler for this CPU setup. */
21205-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21206+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21207 unexpected_machine_check;
21208
21209 /*
21210@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21211 return;
21212 }
21213
21214+ pax_open_kernel();
21215 machine_check_vector = do_machine_check;
21216+ pax_close_kernel();
21217
21218 __mcheck_cpu_init_generic();
21219 __mcheck_cpu_init_vendor(c);
21220@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21221 */
21222
21223 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21224-static int mce_chrdev_open_count; /* #times opened */
21225+static local_t mce_chrdev_open_count; /* #times opened */
21226 static int mce_chrdev_open_exclu; /* already open exclusive? */
21227
21228 static int mce_chrdev_open(struct inode *inode, struct file *file)
21229@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21230 spin_lock(&mce_chrdev_state_lock);
21231
21232 if (mce_chrdev_open_exclu ||
21233- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21234+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21235 spin_unlock(&mce_chrdev_state_lock);
21236
21237 return -EBUSY;
21238@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21239
21240 if (file->f_flags & O_EXCL)
21241 mce_chrdev_open_exclu = 1;
21242- mce_chrdev_open_count++;
21243+ local_inc(&mce_chrdev_open_count);
21244
21245 spin_unlock(&mce_chrdev_state_lock);
21246
21247@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21248 {
21249 spin_lock(&mce_chrdev_state_lock);
21250
21251- mce_chrdev_open_count--;
21252+ local_dec(&mce_chrdev_open_count);
21253 mce_chrdev_open_exclu = 0;
21254
21255 spin_unlock(&mce_chrdev_state_lock);
21256@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21257
21258 for (i = 0; i < mca_cfg.banks; i++) {
21259 struct mce_bank *b = &mce_banks[i];
21260- struct device_attribute *a = &b->attr;
21261+ device_attribute_no_const *a = &b->attr;
21262
21263 sysfs_attr_init(&a->attr);
21264 a->attr.name = b->attrname;
21265@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21266 static void mce_reset(void)
21267 {
21268 cpu_missing = 0;
21269- atomic_set(&mce_fake_paniced, 0);
21270+ atomic_set_unchecked(&mce_fake_paniced, 0);
21271 atomic_set(&mce_executing, 0);
21272 atomic_set(&mce_callin, 0);
21273 atomic_set(&global_nwo, 0);
21274diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21275index 1c044b1..37a2a43 100644
21276--- a/arch/x86/kernel/cpu/mcheck/p5.c
21277+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21278@@ -11,6 +11,7 @@
21279 #include <asm/processor.h>
21280 #include <asm/mce.h>
21281 #include <asm/msr.h>
21282+#include <asm/pgtable.h>
21283
21284 /* By default disabled */
21285 int mce_p5_enabled __read_mostly;
21286@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21287 if (!cpu_has(c, X86_FEATURE_MCE))
21288 return;
21289
21290+ pax_open_kernel();
21291 machine_check_vector = pentium_machine_check;
21292+ pax_close_kernel();
21293 /* Make sure the vector pointer is visible before we enable MCEs: */
21294 wmb();
21295
21296diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21297index e9a701a..35317d6 100644
21298--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21299+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21300@@ -10,6 +10,7 @@
21301 #include <asm/processor.h>
21302 #include <asm/mce.h>
21303 #include <asm/msr.h>
21304+#include <asm/pgtable.h>
21305
21306 /* Machine check handler for WinChip C6: */
21307 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21308@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21309 {
21310 u32 lo, hi;
21311
21312+ pax_open_kernel();
21313 machine_check_vector = winchip_machine_check;
21314+ pax_close_kernel();
21315 /* Make sure the vector pointer is visible before we enable MCEs: */
21316 wmb();
21317
21318diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21319index f961de9..8a9d332 100644
21320--- a/arch/x86/kernel/cpu/mtrr/main.c
21321+++ b/arch/x86/kernel/cpu/mtrr/main.c
21322@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21323 u64 size_or_mask, size_and_mask;
21324 static bool mtrr_aps_delayed_init;
21325
21326-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21327+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21328
21329 const struct mtrr_ops *mtrr_if;
21330
21331diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21332index df5e41f..816c719 100644
21333--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21334+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21335@@ -25,7 +25,7 @@ struct mtrr_ops {
21336 int (*validate_add_page)(unsigned long base, unsigned long size,
21337 unsigned int type);
21338 int (*have_wrcomb)(void);
21339-};
21340+} __do_const;
21341
21342 extern int generic_get_free_region(unsigned long base, unsigned long size,
21343 int replace_reg);
21344diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21345index db6cdbe..faaf834 100644
21346--- a/arch/x86/kernel/cpu/perf_event.c
21347+++ b/arch/x86/kernel/cpu/perf_event.c
21348@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21349 pr_info("no hardware sampling interrupt available.\n");
21350 }
21351
21352-static struct attribute_group x86_pmu_format_group = {
21353+static attribute_group_no_const x86_pmu_format_group = {
21354 .name = "format",
21355 .attrs = NULL,
21356 };
21357@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21358 NULL,
21359 };
21360
21361-static struct attribute_group x86_pmu_events_group = {
21362+static attribute_group_no_const x86_pmu_events_group = {
21363 .name = "events",
21364 .attrs = events_attr,
21365 };
21366@@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21367 if (idx > GDT_ENTRIES)
21368 return 0;
21369
21370- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21371+ desc = get_cpu_gdt_table(smp_processor_id());
21372 }
21373
21374 return get_desc_base(desc + idx);
21375@@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21376 break;
21377
21378 perf_callchain_store(entry, frame.return_address);
21379- fp = frame.next_frame;
21380+ fp = (const void __force_user *)frame.next_frame;
21381 }
21382 }
21383
21384diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21385index 639d128..e92d7e5 100644
21386--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21387+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21388@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21389 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21390 {
21391 struct attribute **attrs;
21392- struct attribute_group *attr_group;
21393+ attribute_group_no_const *attr_group;
21394 int i = 0, j;
21395
21396 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21397diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21398index 0fa4f24..17990ed 100644
21399--- a/arch/x86/kernel/cpu/perf_event_intel.c
21400+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21401@@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21402 * v2 and above have a perf capabilities MSR
21403 */
21404 if (version > 1) {
21405- u64 capabilities;
21406+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21407
21408- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21409- x86_pmu.intel_cap.capabilities = capabilities;
21410+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21411+ x86_pmu.intel_cap.capabilities = capabilities;
21412 }
21413
21414 intel_ds_init();
21415diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21416index 29c2487..a5606fa 100644
21417--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21418+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21419@@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21420 static int __init uncore_type_init(struct intel_uncore_type *type)
21421 {
21422 struct intel_uncore_pmu *pmus;
21423- struct attribute_group *attr_group;
21424+ attribute_group_no_const *attr_group;
21425 struct attribute **attrs;
21426 int i, j;
21427
21428diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21429index a80ab71..4089da5 100644
21430--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21431+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21432@@ -498,7 +498,7 @@ struct intel_uncore_box {
21433 struct uncore_event_desc {
21434 struct kobj_attribute attr;
21435 const char *config;
21436-};
21437+} __do_const;
21438
21439 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21440 { \
21441diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21442index 7d9481c..99c7e4b 100644
21443--- a/arch/x86/kernel/cpuid.c
21444+++ b/arch/x86/kernel/cpuid.c
21445@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21446 return notifier_from_errno(err);
21447 }
21448
21449-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21450+static struct notifier_block cpuid_class_cpu_notifier =
21451 {
21452 .notifier_call = cpuid_class_cpu_callback,
21453 };
21454diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21455index 18677a9..f67c45b 100644
21456--- a/arch/x86/kernel/crash.c
21457+++ b/arch/x86/kernel/crash.c
21458@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21459 {
21460 #ifdef CONFIG_X86_32
21461 struct pt_regs fixed_regs;
21462-#endif
21463
21464-#ifdef CONFIG_X86_32
21465- if (!user_mode_vm(regs)) {
21466+ if (!user_mode(regs)) {
21467 crash_fixup_ss_esp(&fixed_regs, regs);
21468 regs = &fixed_regs;
21469 }
21470diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21471index afa64ad..dce67dd 100644
21472--- a/arch/x86/kernel/crash_dump_64.c
21473+++ b/arch/x86/kernel/crash_dump_64.c
21474@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21475 return -ENOMEM;
21476
21477 if (userbuf) {
21478- if (copy_to_user(buf, vaddr + offset, csize)) {
21479+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21480 iounmap(vaddr);
21481 return -EFAULT;
21482 }
21483diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21484index 5d3fe8d..02e1429 100644
21485--- a/arch/x86/kernel/doublefault.c
21486+++ b/arch/x86/kernel/doublefault.c
21487@@ -13,7 +13,7 @@
21488
21489 #define DOUBLEFAULT_STACKSIZE (1024)
21490 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21491-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21492+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21493
21494 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21495
21496@@ -23,7 +23,7 @@ static void doublefault_fn(void)
21497 unsigned long gdt, tss;
21498
21499 native_store_gdt(&gdt_desc);
21500- gdt = gdt_desc.address;
21501+ gdt = (unsigned long)gdt_desc.address;
21502
21503 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21504
21505@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21506 /* 0x2 bit is always set */
21507 .flags = X86_EFLAGS_SF | 0x2,
21508 .sp = STACK_START,
21509- .es = __USER_DS,
21510+ .es = __KERNEL_DS,
21511 .cs = __KERNEL_CS,
21512 .ss = __KERNEL_DS,
21513- .ds = __USER_DS,
21514+ .ds = __KERNEL_DS,
21515 .fs = __KERNEL_PERCPU,
21516
21517 .__cr3 = __pa_nodebug(swapper_pg_dir),
21518diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21519index d9c12d3..7858b62 100644
21520--- a/arch/x86/kernel/dumpstack.c
21521+++ b/arch/x86/kernel/dumpstack.c
21522@@ -2,6 +2,9 @@
21523 * Copyright (C) 1991, 1992 Linus Torvalds
21524 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21525 */
21526+#ifdef CONFIG_GRKERNSEC_HIDESYM
21527+#define __INCLUDED_BY_HIDESYM 1
21528+#endif
21529 #include <linux/kallsyms.h>
21530 #include <linux/kprobes.h>
21531 #include <linux/uaccess.h>
21532@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21533 static void
21534 print_ftrace_graph_addr(unsigned long addr, void *data,
21535 const struct stacktrace_ops *ops,
21536- struct thread_info *tinfo, int *graph)
21537+ struct task_struct *task, int *graph)
21538 {
21539- struct task_struct *task;
21540 unsigned long ret_addr;
21541 int index;
21542
21543 if (addr != (unsigned long)return_to_handler)
21544 return;
21545
21546- task = tinfo->task;
21547 index = task->curr_ret_stack;
21548
21549 if (!task->ret_stack || index < *graph)
21550@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21551 static inline void
21552 print_ftrace_graph_addr(unsigned long addr, void *data,
21553 const struct stacktrace_ops *ops,
21554- struct thread_info *tinfo, int *graph)
21555+ struct task_struct *task, int *graph)
21556 { }
21557 #endif
21558
21559@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21560 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21561 */
21562
21563-static inline int valid_stack_ptr(struct thread_info *tinfo,
21564- void *p, unsigned int size, void *end)
21565+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21566 {
21567- void *t = tinfo;
21568 if (end) {
21569 if (p < end && p >= (end-THREAD_SIZE))
21570 return 1;
21571@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21572 }
21573
21574 unsigned long
21575-print_context_stack(struct thread_info *tinfo,
21576+print_context_stack(struct task_struct *task, void *stack_start,
21577 unsigned long *stack, unsigned long bp,
21578 const struct stacktrace_ops *ops, void *data,
21579 unsigned long *end, int *graph)
21580 {
21581 struct stack_frame *frame = (struct stack_frame *)bp;
21582
21583- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21584+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21585 unsigned long addr;
21586
21587 addr = *stack;
21588@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21589 } else {
21590 ops->address(data, addr, 0);
21591 }
21592- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21593+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21594 }
21595 stack++;
21596 }
21597@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21598 EXPORT_SYMBOL_GPL(print_context_stack);
21599
21600 unsigned long
21601-print_context_stack_bp(struct thread_info *tinfo,
21602+print_context_stack_bp(struct task_struct *task, void *stack_start,
21603 unsigned long *stack, unsigned long bp,
21604 const struct stacktrace_ops *ops, void *data,
21605 unsigned long *end, int *graph)
21606@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21607 struct stack_frame *frame = (struct stack_frame *)bp;
21608 unsigned long *ret_addr = &frame->return_address;
21609
21610- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21611+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21612 unsigned long addr = *ret_addr;
21613
21614 if (!__kernel_text_address(addr))
21615@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21616 ops->address(data, addr, 1);
21617 frame = frame->next_frame;
21618 ret_addr = &frame->return_address;
21619- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21620+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21621 }
21622
21623 return (unsigned long)frame;
21624@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21625 static void print_trace_address(void *data, unsigned long addr, int reliable)
21626 {
21627 touch_nmi_watchdog();
21628- printk(data);
21629+ printk("%s", (char *)data);
21630 printk_stack_address(addr, reliable);
21631 }
21632
21633@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21634 }
21635 EXPORT_SYMBOL_GPL(oops_begin);
21636
21637+extern void gr_handle_kernel_exploit(void);
21638+
21639 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21640 {
21641 if (regs && kexec_should_crash(current))
21642@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21643 panic("Fatal exception in interrupt");
21644 if (panic_on_oops)
21645 panic("Fatal exception");
21646- do_exit(signr);
21647+
21648+ gr_handle_kernel_exploit();
21649+
21650+ do_group_exit(signr);
21651 }
21652
21653 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21654@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21655 print_modules();
21656 show_regs(regs);
21657 #ifdef CONFIG_X86_32
21658- if (user_mode_vm(regs)) {
21659+ if (user_mode(regs)) {
21660 sp = regs->sp;
21661 ss = regs->ss & 0xffff;
21662 } else {
21663@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21664 unsigned long flags = oops_begin();
21665 int sig = SIGSEGV;
21666
21667- if (!user_mode_vm(regs))
21668+ if (!user_mode(regs))
21669 report_bug(regs->ip, regs);
21670
21671 if (__die(str, regs, err))
21672diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21673index f2a1770..540657f 100644
21674--- a/arch/x86/kernel/dumpstack_32.c
21675+++ b/arch/x86/kernel/dumpstack_32.c
21676@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21677 bp = stack_frame(task, regs);
21678
21679 for (;;) {
21680- struct thread_info *context;
21681+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21682
21683- context = (struct thread_info *)
21684- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21685- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21686+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21687
21688- stack = (unsigned long *)context->previous_esp;
21689- if (!stack)
21690+ if (stack_start == task_stack_page(task))
21691 break;
21692+ stack = *(unsigned long **)stack_start;
21693 if (ops->stack(data, "IRQ") < 0)
21694 break;
21695 touch_nmi_watchdog();
21696@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21697 int i;
21698
21699 show_regs_print_info(KERN_EMERG);
21700- __show_regs(regs, !user_mode_vm(regs));
21701+ __show_regs(regs, !user_mode(regs));
21702
21703 /*
21704 * When in-kernel, we also print out the stack and code at the
21705 * time of the fault..
21706 */
21707- if (!user_mode_vm(regs)) {
21708+ if (!user_mode(regs)) {
21709 unsigned int code_prologue = code_bytes * 43 / 64;
21710 unsigned int code_len = code_bytes;
21711 unsigned char c;
21712 u8 *ip;
21713+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21714
21715 pr_emerg("Stack:\n");
21716 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21717
21718 pr_emerg("Code:");
21719
21720- ip = (u8 *)regs->ip - code_prologue;
21721+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21722 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21723 /* try starting at IP */
21724- ip = (u8 *)regs->ip;
21725+ ip = (u8 *)regs->ip + cs_base;
21726 code_len = code_len - code_prologue + 1;
21727 }
21728 for (i = 0; i < code_len; i++, ip++) {
21729@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21730 pr_cont(" Bad EIP value.");
21731 break;
21732 }
21733- if (ip == (u8 *)regs->ip)
21734+ if (ip == (u8 *)regs->ip + cs_base)
21735 pr_cont(" <%02x>", c);
21736 else
21737 pr_cont(" %02x", c);
21738@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21739 {
21740 unsigned short ud2;
21741
21742+ ip = ktla_ktva(ip);
21743 if (ip < PAGE_OFFSET)
21744 return 0;
21745 if (probe_kernel_address((unsigned short *)ip, ud2))
21746@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21747
21748 return ud2 == 0x0b0f;
21749 }
21750+
21751+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21752+void pax_check_alloca(unsigned long size)
21753+{
21754+ unsigned long sp = (unsigned long)&sp, stack_left;
21755+
21756+ /* all kernel stacks are of the same size */
21757+ stack_left = sp & (THREAD_SIZE - 1);
21758+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21759+}
21760+EXPORT_SYMBOL(pax_check_alloca);
21761+#endif
21762diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21763index addb207..99635fa 100644
21764--- a/arch/x86/kernel/dumpstack_64.c
21765+++ b/arch/x86/kernel/dumpstack_64.c
21766@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21767 unsigned long *irq_stack_end =
21768 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21769 unsigned used = 0;
21770- struct thread_info *tinfo;
21771 int graph = 0;
21772 unsigned long dummy;
21773+ void *stack_start;
21774
21775 if (!task)
21776 task = current;
21777@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21778 * current stack address. If the stacks consist of nested
21779 * exceptions
21780 */
21781- tinfo = task_thread_info(task);
21782 for (;;) {
21783 char *id;
21784 unsigned long *estack_end;
21785+
21786 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21787 &used, &id);
21788
21789@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21790 if (ops->stack(data, id) < 0)
21791 break;
21792
21793- bp = ops->walk_stack(tinfo, stack, bp, ops,
21794+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21795 data, estack_end, &graph);
21796 ops->stack(data, "<EOE>");
21797 /*
21798@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21799 * second-to-last pointer (index -2 to end) in the
21800 * exception stack:
21801 */
21802+ if ((u16)estack_end[-1] != __KERNEL_DS)
21803+ goto out;
21804 stack = (unsigned long *) estack_end[-2];
21805 continue;
21806 }
21807@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21808 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21809 if (ops->stack(data, "IRQ") < 0)
21810 break;
21811- bp = ops->walk_stack(tinfo, stack, bp,
21812+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21813 ops, data, irq_stack_end, &graph);
21814 /*
21815 * We link to the next stack (which would be
21816@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21817 /*
21818 * This handles the process stack:
21819 */
21820- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21821+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21822+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21823+out:
21824 put_cpu();
21825 }
21826 EXPORT_SYMBOL(dump_trace);
21827@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21828
21829 return ud2 == 0x0b0f;
21830 }
21831+
21832+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21833+void pax_check_alloca(unsigned long size)
21834+{
21835+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21836+ unsigned cpu, used;
21837+ char *id;
21838+
21839+ /* check the process stack first */
21840+ stack_start = (unsigned long)task_stack_page(current);
21841+ stack_end = stack_start + THREAD_SIZE;
21842+ if (likely(stack_start <= sp && sp < stack_end)) {
21843+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21844+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21845+ return;
21846+ }
21847+
21848+ cpu = get_cpu();
21849+
21850+ /* check the irq stacks */
21851+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21852+ stack_start = stack_end - IRQ_STACK_SIZE;
21853+ if (stack_start <= sp && sp < stack_end) {
21854+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21855+ put_cpu();
21856+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21857+ return;
21858+ }
21859+
21860+ /* check the exception stacks */
21861+ used = 0;
21862+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21863+ stack_start = stack_end - EXCEPTION_STKSZ;
21864+ if (stack_end && stack_start <= sp && sp < stack_end) {
21865+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21866+ put_cpu();
21867+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21868+ return;
21869+ }
21870+
21871+ put_cpu();
21872+
21873+ /* unknown stack */
21874+ BUG();
21875+}
21876+EXPORT_SYMBOL(pax_check_alloca);
21877+#endif
21878diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21879index 174da5f..5e55606 100644
21880--- a/arch/x86/kernel/e820.c
21881+++ b/arch/x86/kernel/e820.c
21882@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21883
21884 static void early_panic(char *msg)
21885 {
21886- early_printk(msg);
21887- panic(msg);
21888+ early_printk("%s", msg);
21889+ panic("%s", msg);
21890 }
21891
21892 static int userdef __initdata;
21893diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21894index 01d1c18..8073693 100644
21895--- a/arch/x86/kernel/early_printk.c
21896+++ b/arch/x86/kernel/early_printk.c
21897@@ -7,6 +7,7 @@
21898 #include <linux/pci_regs.h>
21899 #include <linux/pci_ids.h>
21900 #include <linux/errno.h>
21901+#include <linux/sched.h>
21902 #include <asm/io.h>
21903 #include <asm/processor.h>
21904 #include <asm/fcntl.h>
21905diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21906index a2a4f46..6cab058 100644
21907--- a/arch/x86/kernel/entry_32.S
21908+++ b/arch/x86/kernel/entry_32.S
21909@@ -177,13 +177,153 @@
21910 /*CFI_REL_OFFSET gs, PT_GS*/
21911 .endm
21912 .macro SET_KERNEL_GS reg
21913+
21914+#ifdef CONFIG_CC_STACKPROTECTOR
21915 movl $(__KERNEL_STACK_CANARY), \reg
21916+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21917+ movl $(__USER_DS), \reg
21918+#else
21919+ xorl \reg, \reg
21920+#endif
21921+
21922 movl \reg, %gs
21923 .endm
21924
21925 #endif /* CONFIG_X86_32_LAZY_GS */
21926
21927-.macro SAVE_ALL
21928+.macro pax_enter_kernel
21929+#ifdef CONFIG_PAX_KERNEXEC
21930+ call pax_enter_kernel
21931+#endif
21932+.endm
21933+
21934+.macro pax_exit_kernel
21935+#ifdef CONFIG_PAX_KERNEXEC
21936+ call pax_exit_kernel
21937+#endif
21938+.endm
21939+
21940+#ifdef CONFIG_PAX_KERNEXEC
21941+ENTRY(pax_enter_kernel)
21942+#ifdef CONFIG_PARAVIRT
21943+ pushl %eax
21944+ pushl %ecx
21945+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21946+ mov %eax, %esi
21947+#else
21948+ mov %cr0, %esi
21949+#endif
21950+ bts $16, %esi
21951+ jnc 1f
21952+ mov %cs, %esi
21953+ cmp $__KERNEL_CS, %esi
21954+ jz 3f
21955+ ljmp $__KERNEL_CS, $3f
21956+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21957+2:
21958+#ifdef CONFIG_PARAVIRT
21959+ mov %esi, %eax
21960+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21961+#else
21962+ mov %esi, %cr0
21963+#endif
21964+3:
21965+#ifdef CONFIG_PARAVIRT
21966+ popl %ecx
21967+ popl %eax
21968+#endif
21969+ ret
21970+ENDPROC(pax_enter_kernel)
21971+
21972+ENTRY(pax_exit_kernel)
21973+#ifdef CONFIG_PARAVIRT
21974+ pushl %eax
21975+ pushl %ecx
21976+#endif
21977+ mov %cs, %esi
21978+ cmp $__KERNEXEC_KERNEL_CS, %esi
21979+ jnz 2f
21980+#ifdef CONFIG_PARAVIRT
21981+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21982+ mov %eax, %esi
21983+#else
21984+ mov %cr0, %esi
21985+#endif
21986+ btr $16, %esi
21987+ ljmp $__KERNEL_CS, $1f
21988+1:
21989+#ifdef CONFIG_PARAVIRT
21990+ mov %esi, %eax
21991+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21992+#else
21993+ mov %esi, %cr0
21994+#endif
21995+2:
21996+#ifdef CONFIG_PARAVIRT
21997+ popl %ecx
21998+ popl %eax
21999+#endif
22000+ ret
22001+ENDPROC(pax_exit_kernel)
22002+#endif
22003+
22004+ .macro pax_erase_kstack
22005+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22006+ call pax_erase_kstack
22007+#endif
22008+ .endm
22009+
22010+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22011+/*
22012+ * ebp: thread_info
22013+ */
22014+ENTRY(pax_erase_kstack)
22015+ pushl %edi
22016+ pushl %ecx
22017+ pushl %eax
22018+
22019+ mov TI_lowest_stack(%ebp), %edi
22020+ mov $-0xBEEF, %eax
22021+ std
22022+
22023+1: mov %edi, %ecx
22024+ and $THREAD_SIZE_asm - 1, %ecx
22025+ shr $2, %ecx
22026+ repne scasl
22027+ jecxz 2f
22028+
22029+ cmp $2*16, %ecx
22030+ jc 2f
22031+
22032+ mov $2*16, %ecx
22033+ repe scasl
22034+ jecxz 2f
22035+ jne 1b
22036+
22037+2: cld
22038+ mov %esp, %ecx
22039+ sub %edi, %ecx
22040+
22041+ cmp $THREAD_SIZE_asm, %ecx
22042+ jb 3f
22043+ ud2
22044+3:
22045+
22046+ shr $2, %ecx
22047+ rep stosl
22048+
22049+ mov TI_task_thread_sp0(%ebp), %edi
22050+ sub $128, %edi
22051+ mov %edi, TI_lowest_stack(%ebp)
22052+
22053+ popl %eax
22054+ popl %ecx
22055+ popl %edi
22056+ ret
22057+ENDPROC(pax_erase_kstack)
22058+#endif
22059+
22060+.macro __SAVE_ALL _DS
22061 cld
22062 PUSH_GS
22063 pushl_cfi %fs
22064@@ -206,7 +346,7 @@
22065 CFI_REL_OFFSET ecx, 0
22066 pushl_cfi %ebx
22067 CFI_REL_OFFSET ebx, 0
22068- movl $(__USER_DS), %edx
22069+ movl $\_DS, %edx
22070 movl %edx, %ds
22071 movl %edx, %es
22072 movl $(__KERNEL_PERCPU), %edx
22073@@ -214,6 +354,15 @@
22074 SET_KERNEL_GS %edx
22075 .endm
22076
22077+.macro SAVE_ALL
22078+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22079+ __SAVE_ALL __KERNEL_DS
22080+ pax_enter_kernel
22081+#else
22082+ __SAVE_ALL __USER_DS
22083+#endif
22084+.endm
22085+
22086 .macro RESTORE_INT_REGS
22087 popl_cfi %ebx
22088 CFI_RESTORE ebx
22089@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22090 popfl_cfi
22091 jmp syscall_exit
22092 CFI_ENDPROC
22093-END(ret_from_fork)
22094+ENDPROC(ret_from_fork)
22095
22096 ENTRY(ret_from_kernel_thread)
22097 CFI_STARTPROC
22098@@ -344,7 +493,15 @@ ret_from_intr:
22099 andl $SEGMENT_RPL_MASK, %eax
22100 #endif
22101 cmpl $USER_RPL, %eax
22102+
22103+#ifdef CONFIG_PAX_KERNEXEC
22104+ jae resume_userspace
22105+
22106+ pax_exit_kernel
22107+ jmp resume_kernel
22108+#else
22109 jb resume_kernel # not returning to v8086 or userspace
22110+#endif
22111
22112 ENTRY(resume_userspace)
22113 LOCKDEP_SYS_EXIT
22114@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22115 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22116 # int/exception return?
22117 jne work_pending
22118- jmp restore_all
22119-END(ret_from_exception)
22120+ jmp restore_all_pax
22121+ENDPROC(ret_from_exception)
22122
22123 #ifdef CONFIG_PREEMPT
22124 ENTRY(resume_kernel)
22125@@ -369,7 +526,7 @@ need_resched:
22126 jz restore_all
22127 call preempt_schedule_irq
22128 jmp need_resched
22129-END(resume_kernel)
22130+ENDPROC(resume_kernel)
22131 #endif
22132 CFI_ENDPROC
22133 /*
22134@@ -403,30 +560,45 @@ sysenter_past_esp:
22135 /*CFI_REL_OFFSET cs, 0*/
22136 /*
22137 * Push current_thread_info()->sysenter_return to the stack.
22138- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22139- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22140 */
22141- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22142+ pushl_cfi $0
22143 CFI_REL_OFFSET eip, 0
22144
22145 pushl_cfi %eax
22146 SAVE_ALL
22147+ GET_THREAD_INFO(%ebp)
22148+ movl TI_sysenter_return(%ebp),%ebp
22149+ movl %ebp,PT_EIP(%esp)
22150 ENABLE_INTERRUPTS(CLBR_NONE)
22151
22152 /*
22153 * Load the potential sixth argument from user stack.
22154 * Careful about security.
22155 */
22156+ movl PT_OLDESP(%esp),%ebp
22157+
22158+#ifdef CONFIG_PAX_MEMORY_UDEREF
22159+ mov PT_OLDSS(%esp),%ds
22160+1: movl %ds:(%ebp),%ebp
22161+ push %ss
22162+ pop %ds
22163+#else
22164 cmpl $__PAGE_OFFSET-3,%ebp
22165 jae syscall_fault
22166 ASM_STAC
22167 1: movl (%ebp),%ebp
22168 ASM_CLAC
22169+#endif
22170+
22171 movl %ebp,PT_EBP(%esp)
22172 _ASM_EXTABLE(1b,syscall_fault)
22173
22174 GET_THREAD_INFO(%ebp)
22175
22176+#ifdef CONFIG_PAX_RANDKSTACK
22177+ pax_erase_kstack
22178+#endif
22179+
22180 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22181 jnz sysenter_audit
22182 sysenter_do_call:
22183@@ -441,12 +613,24 @@ sysenter_do_call:
22184 testl $_TIF_ALLWORK_MASK, %ecx
22185 jne sysexit_audit
22186 sysenter_exit:
22187+
22188+#ifdef CONFIG_PAX_RANDKSTACK
22189+ pushl_cfi %eax
22190+ movl %esp, %eax
22191+ call pax_randomize_kstack
22192+ popl_cfi %eax
22193+#endif
22194+
22195+ pax_erase_kstack
22196+
22197 /* if something modifies registers it must also disable sysexit */
22198 movl PT_EIP(%esp), %edx
22199 movl PT_OLDESP(%esp), %ecx
22200 xorl %ebp,%ebp
22201 TRACE_IRQS_ON
22202 1: mov PT_FS(%esp), %fs
22203+2: mov PT_DS(%esp), %ds
22204+3: mov PT_ES(%esp), %es
22205 PTGS_TO_GS
22206 ENABLE_INTERRUPTS_SYSEXIT
22207
22208@@ -463,6 +647,9 @@ sysenter_audit:
22209 movl %eax,%edx /* 2nd arg: syscall number */
22210 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22211 call __audit_syscall_entry
22212+
22213+ pax_erase_kstack
22214+
22215 pushl_cfi %ebx
22216 movl PT_EAX(%esp),%eax /* reload syscall number */
22217 jmp sysenter_do_call
22218@@ -488,10 +675,16 @@ sysexit_audit:
22219
22220 CFI_ENDPROC
22221 .pushsection .fixup,"ax"
22222-2: movl $0,PT_FS(%esp)
22223+4: movl $0,PT_FS(%esp)
22224+ jmp 1b
22225+5: movl $0,PT_DS(%esp)
22226+ jmp 1b
22227+6: movl $0,PT_ES(%esp)
22228 jmp 1b
22229 .popsection
22230- _ASM_EXTABLE(1b,2b)
22231+ _ASM_EXTABLE(1b,4b)
22232+ _ASM_EXTABLE(2b,5b)
22233+ _ASM_EXTABLE(3b,6b)
22234 PTGS_TO_GS_EX
22235 ENDPROC(ia32_sysenter_target)
22236
22237@@ -506,6 +699,11 @@ ENTRY(system_call)
22238 pushl_cfi %eax # save orig_eax
22239 SAVE_ALL
22240 GET_THREAD_INFO(%ebp)
22241+
22242+#ifdef CONFIG_PAX_RANDKSTACK
22243+ pax_erase_kstack
22244+#endif
22245+
22246 # system call tracing in operation / emulation
22247 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22248 jnz syscall_trace_entry
22249@@ -524,6 +722,15 @@ syscall_exit:
22250 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22251 jne syscall_exit_work
22252
22253+restore_all_pax:
22254+
22255+#ifdef CONFIG_PAX_RANDKSTACK
22256+ movl %esp, %eax
22257+ call pax_randomize_kstack
22258+#endif
22259+
22260+ pax_erase_kstack
22261+
22262 restore_all:
22263 TRACE_IRQS_IRET
22264 restore_all_notrace:
22265@@ -580,14 +787,34 @@ ldt_ss:
22266 * compensating for the offset by changing to the ESPFIX segment with
22267 * a base address that matches for the difference.
22268 */
22269-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22270+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22271 mov %esp, %edx /* load kernel esp */
22272 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22273 mov %dx, %ax /* eax: new kernel esp */
22274 sub %eax, %edx /* offset (low word is 0) */
22275+#ifdef CONFIG_SMP
22276+ movl PER_CPU_VAR(cpu_number), %ebx
22277+ shll $PAGE_SHIFT_asm, %ebx
22278+ addl $cpu_gdt_table, %ebx
22279+#else
22280+ movl $cpu_gdt_table, %ebx
22281+#endif
22282 shr $16, %edx
22283- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22284- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22285+
22286+#ifdef CONFIG_PAX_KERNEXEC
22287+ mov %cr0, %esi
22288+ btr $16, %esi
22289+ mov %esi, %cr0
22290+#endif
22291+
22292+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22293+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22294+
22295+#ifdef CONFIG_PAX_KERNEXEC
22296+ bts $16, %esi
22297+ mov %esi, %cr0
22298+#endif
22299+
22300 pushl_cfi $__ESPFIX_SS
22301 pushl_cfi %eax /* new kernel esp */
22302 /* Disable interrupts, but do not irqtrace this section: we
22303@@ -616,20 +843,18 @@ work_resched:
22304 movl TI_flags(%ebp), %ecx
22305 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22306 # than syscall tracing?
22307- jz restore_all
22308+ jz restore_all_pax
22309 testb $_TIF_NEED_RESCHED, %cl
22310 jnz work_resched
22311
22312 work_notifysig: # deal with pending signals and
22313 # notify-resume requests
22314+ movl %esp, %eax
22315 #ifdef CONFIG_VM86
22316 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22317- movl %esp, %eax
22318 jne work_notifysig_v86 # returning to kernel-space or
22319 # vm86-space
22320 1:
22321-#else
22322- movl %esp, %eax
22323 #endif
22324 TRACE_IRQS_ON
22325 ENABLE_INTERRUPTS(CLBR_NONE)
22326@@ -650,7 +875,7 @@ work_notifysig_v86:
22327 movl %eax, %esp
22328 jmp 1b
22329 #endif
22330-END(work_pending)
22331+ENDPROC(work_pending)
22332
22333 # perform syscall exit tracing
22334 ALIGN
22335@@ -658,11 +883,14 @@ syscall_trace_entry:
22336 movl $-ENOSYS,PT_EAX(%esp)
22337 movl %esp, %eax
22338 call syscall_trace_enter
22339+
22340+ pax_erase_kstack
22341+
22342 /* What it returned is what we'll actually use. */
22343 cmpl $(NR_syscalls), %eax
22344 jnae syscall_call
22345 jmp syscall_exit
22346-END(syscall_trace_entry)
22347+ENDPROC(syscall_trace_entry)
22348
22349 # perform syscall exit tracing
22350 ALIGN
22351@@ -675,21 +903,25 @@ syscall_exit_work:
22352 movl %esp, %eax
22353 call syscall_trace_leave
22354 jmp resume_userspace
22355-END(syscall_exit_work)
22356+ENDPROC(syscall_exit_work)
22357 CFI_ENDPROC
22358
22359 RING0_INT_FRAME # can't unwind into user space anyway
22360 syscall_fault:
22361+#ifdef CONFIG_PAX_MEMORY_UDEREF
22362+ push %ss
22363+ pop %ds
22364+#endif
22365 ASM_CLAC
22366 GET_THREAD_INFO(%ebp)
22367 movl $-EFAULT,PT_EAX(%esp)
22368 jmp resume_userspace
22369-END(syscall_fault)
22370+ENDPROC(syscall_fault)
22371
22372 syscall_badsys:
22373 movl $-ENOSYS,PT_EAX(%esp)
22374 jmp resume_userspace
22375-END(syscall_badsys)
22376+ENDPROC(syscall_badsys)
22377 CFI_ENDPROC
22378 /*
22379 * End of kprobes section
22380@@ -705,8 +937,15 @@ END(syscall_badsys)
22381 * normal stack and adjusts ESP with the matching offset.
22382 */
22383 /* fixup the stack */
22384- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22385- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22386+#ifdef CONFIG_SMP
22387+ movl PER_CPU_VAR(cpu_number), %ebx
22388+ shll $PAGE_SHIFT_asm, %ebx
22389+ addl $cpu_gdt_table, %ebx
22390+#else
22391+ movl $cpu_gdt_table, %ebx
22392+#endif
22393+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22394+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22395 shl $16, %eax
22396 addl %esp, %eax /* the adjusted stack pointer */
22397 pushl_cfi $__KERNEL_DS
22398@@ -759,7 +998,7 @@ vector=vector+1
22399 .endr
22400 2: jmp common_interrupt
22401 .endr
22402-END(irq_entries_start)
22403+ENDPROC(irq_entries_start)
22404
22405 .previous
22406 END(interrupt)
22407@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22408 pushl_cfi $do_coprocessor_error
22409 jmp error_code
22410 CFI_ENDPROC
22411-END(coprocessor_error)
22412+ENDPROC(coprocessor_error)
22413
22414 ENTRY(simd_coprocessor_error)
22415 RING0_INT_FRAME
22416@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22417 .section .altinstructions,"a"
22418 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22419 .previous
22420-.section .altinstr_replacement,"ax"
22421+.section .altinstr_replacement,"a"
22422 663: pushl $do_simd_coprocessor_error
22423 664:
22424 .previous
22425@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22426 #endif
22427 jmp error_code
22428 CFI_ENDPROC
22429-END(simd_coprocessor_error)
22430+ENDPROC(simd_coprocessor_error)
22431
22432 ENTRY(device_not_available)
22433 RING0_INT_FRAME
22434@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22435 pushl_cfi $do_device_not_available
22436 jmp error_code
22437 CFI_ENDPROC
22438-END(device_not_available)
22439+ENDPROC(device_not_available)
22440
22441 #ifdef CONFIG_PARAVIRT
22442 ENTRY(native_iret)
22443 iret
22444 _ASM_EXTABLE(native_iret, iret_exc)
22445-END(native_iret)
22446+ENDPROC(native_iret)
22447
22448 ENTRY(native_irq_enable_sysexit)
22449 sti
22450 sysexit
22451-END(native_irq_enable_sysexit)
22452+ENDPROC(native_irq_enable_sysexit)
22453 #endif
22454
22455 ENTRY(overflow)
22456@@ -872,7 +1111,7 @@ ENTRY(overflow)
22457 pushl_cfi $do_overflow
22458 jmp error_code
22459 CFI_ENDPROC
22460-END(overflow)
22461+ENDPROC(overflow)
22462
22463 ENTRY(bounds)
22464 RING0_INT_FRAME
22465@@ -881,7 +1120,7 @@ ENTRY(bounds)
22466 pushl_cfi $do_bounds
22467 jmp error_code
22468 CFI_ENDPROC
22469-END(bounds)
22470+ENDPROC(bounds)
22471
22472 ENTRY(invalid_op)
22473 RING0_INT_FRAME
22474@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22475 pushl_cfi $do_invalid_op
22476 jmp error_code
22477 CFI_ENDPROC
22478-END(invalid_op)
22479+ENDPROC(invalid_op)
22480
22481 ENTRY(coprocessor_segment_overrun)
22482 RING0_INT_FRAME
22483@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22484 pushl_cfi $do_coprocessor_segment_overrun
22485 jmp error_code
22486 CFI_ENDPROC
22487-END(coprocessor_segment_overrun)
22488+ENDPROC(coprocessor_segment_overrun)
22489
22490 ENTRY(invalid_TSS)
22491 RING0_EC_FRAME
22492@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22493 pushl_cfi $do_invalid_TSS
22494 jmp error_code
22495 CFI_ENDPROC
22496-END(invalid_TSS)
22497+ENDPROC(invalid_TSS)
22498
22499 ENTRY(segment_not_present)
22500 RING0_EC_FRAME
22501@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22502 pushl_cfi $do_segment_not_present
22503 jmp error_code
22504 CFI_ENDPROC
22505-END(segment_not_present)
22506+ENDPROC(segment_not_present)
22507
22508 ENTRY(stack_segment)
22509 RING0_EC_FRAME
22510@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22511 pushl_cfi $do_stack_segment
22512 jmp error_code
22513 CFI_ENDPROC
22514-END(stack_segment)
22515+ENDPROC(stack_segment)
22516
22517 ENTRY(alignment_check)
22518 RING0_EC_FRAME
22519@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22520 pushl_cfi $do_alignment_check
22521 jmp error_code
22522 CFI_ENDPROC
22523-END(alignment_check)
22524+ENDPROC(alignment_check)
22525
22526 ENTRY(divide_error)
22527 RING0_INT_FRAME
22528@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22529 pushl_cfi $do_divide_error
22530 jmp error_code
22531 CFI_ENDPROC
22532-END(divide_error)
22533+ENDPROC(divide_error)
22534
22535 #ifdef CONFIG_X86_MCE
22536 ENTRY(machine_check)
22537@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22538 pushl_cfi machine_check_vector
22539 jmp error_code
22540 CFI_ENDPROC
22541-END(machine_check)
22542+ENDPROC(machine_check)
22543 #endif
22544
22545 ENTRY(spurious_interrupt_bug)
22546@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22547 pushl_cfi $do_spurious_interrupt_bug
22548 jmp error_code
22549 CFI_ENDPROC
22550-END(spurious_interrupt_bug)
22551+ENDPROC(spurious_interrupt_bug)
22552 /*
22553 * End of kprobes section
22554 */
22555@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22556
22557 ENTRY(mcount)
22558 ret
22559-END(mcount)
22560+ENDPROC(mcount)
22561
22562 ENTRY(ftrace_caller)
22563 cmpl $0, function_trace_stop
22564@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22565 .globl ftrace_stub
22566 ftrace_stub:
22567 ret
22568-END(ftrace_caller)
22569+ENDPROC(ftrace_caller)
22570
22571 ENTRY(ftrace_regs_caller)
22572 pushf /* push flags before compare (in cs location) */
22573@@ -1207,7 +1446,7 @@ trace:
22574 popl %ecx
22575 popl %eax
22576 jmp ftrace_stub
22577-END(mcount)
22578+ENDPROC(mcount)
22579 #endif /* CONFIG_DYNAMIC_FTRACE */
22580 #endif /* CONFIG_FUNCTION_TRACER */
22581
22582@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22583 popl %ecx
22584 popl %eax
22585 ret
22586-END(ftrace_graph_caller)
22587+ENDPROC(ftrace_graph_caller)
22588
22589 .globl return_to_handler
22590 return_to_handler:
22591@@ -1291,15 +1530,18 @@ error_code:
22592 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22593 REG_TO_PTGS %ecx
22594 SET_KERNEL_GS %ecx
22595- movl $(__USER_DS), %ecx
22596+ movl $(__KERNEL_DS), %ecx
22597 movl %ecx, %ds
22598 movl %ecx, %es
22599+
22600+ pax_enter_kernel
22601+
22602 TRACE_IRQS_OFF
22603 movl %esp,%eax # pt_regs pointer
22604 call *%edi
22605 jmp ret_from_exception
22606 CFI_ENDPROC
22607-END(page_fault)
22608+ENDPROC(page_fault)
22609
22610 /*
22611 * Debug traps and NMI can happen at the one SYSENTER instruction
22612@@ -1342,7 +1584,7 @@ debug_stack_correct:
22613 call do_debug
22614 jmp ret_from_exception
22615 CFI_ENDPROC
22616-END(debug)
22617+ENDPROC(debug)
22618
22619 /*
22620 * NMI is doubly nasty. It can happen _while_ we're handling
22621@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22622 xorl %edx,%edx # zero error code
22623 movl %esp,%eax # pt_regs pointer
22624 call do_nmi
22625+
22626+ pax_exit_kernel
22627+
22628 jmp restore_all_notrace
22629 CFI_ENDPROC
22630
22631@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22632 FIXUP_ESPFIX_STACK # %eax == %esp
22633 xorl %edx,%edx # zero error code
22634 call do_nmi
22635+
22636+ pax_exit_kernel
22637+
22638 RESTORE_REGS
22639 lss 12+4(%esp), %esp # back to espfix stack
22640 CFI_ADJUST_CFA_OFFSET -24
22641 jmp irq_return
22642 CFI_ENDPROC
22643-END(nmi)
22644+ENDPROC(nmi)
22645
22646 ENTRY(int3)
22647 RING0_INT_FRAME
22648@@ -1434,14 +1682,14 @@ ENTRY(int3)
22649 call do_int3
22650 jmp ret_from_exception
22651 CFI_ENDPROC
22652-END(int3)
22653+ENDPROC(int3)
22654
22655 ENTRY(general_protection)
22656 RING0_EC_FRAME
22657 pushl_cfi $do_general_protection
22658 jmp error_code
22659 CFI_ENDPROC
22660-END(general_protection)
22661+ENDPROC(general_protection)
22662
22663 #ifdef CONFIG_KVM_GUEST
22664 ENTRY(async_page_fault)
22665@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22666 pushl_cfi $do_async_page_fault
22667 jmp error_code
22668 CFI_ENDPROC
22669-END(async_page_fault)
22670+ENDPROC(async_page_fault)
22671 #endif
22672
22673 /*
22674diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22675index 1e96c36..3ff710a 100644
22676--- a/arch/x86/kernel/entry_64.S
22677+++ b/arch/x86/kernel/entry_64.S
22678@@ -59,6 +59,8 @@
22679 #include <asm/context_tracking.h>
22680 #include <asm/smap.h>
22681 #include <linux/err.h>
22682+#include <asm/pgtable.h>
22683+#include <asm/alternative-asm.h>
22684
22685 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22686 #include <linux/elf-em.h>
22687@@ -80,8 +82,9 @@
22688 #ifdef CONFIG_DYNAMIC_FTRACE
22689
22690 ENTRY(function_hook)
22691+ pax_force_retaddr
22692 retq
22693-END(function_hook)
22694+ENDPROC(function_hook)
22695
22696 /* skip is set if stack has been adjusted */
22697 .macro ftrace_caller_setup skip=0
22698@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22699 #endif
22700
22701 GLOBAL(ftrace_stub)
22702+ pax_force_retaddr
22703 retq
22704-END(ftrace_caller)
22705+ENDPROC(ftrace_caller)
22706
22707 ENTRY(ftrace_regs_caller)
22708 /* Save the current flags before compare (in SS location)*/
22709@@ -191,7 +195,7 @@ ftrace_restore_flags:
22710 popfq
22711 jmp ftrace_stub
22712
22713-END(ftrace_regs_caller)
22714+ENDPROC(ftrace_regs_caller)
22715
22716
22717 #else /* ! CONFIG_DYNAMIC_FTRACE */
22718@@ -212,6 +216,7 @@ ENTRY(function_hook)
22719 #endif
22720
22721 GLOBAL(ftrace_stub)
22722+ pax_force_retaddr
22723 retq
22724
22725 trace:
22726@@ -225,12 +230,13 @@ trace:
22727 #endif
22728 subq $MCOUNT_INSN_SIZE, %rdi
22729
22730+ pax_force_fptr ftrace_trace_function
22731 call *ftrace_trace_function
22732
22733 MCOUNT_RESTORE_FRAME
22734
22735 jmp ftrace_stub
22736-END(function_hook)
22737+ENDPROC(function_hook)
22738 #endif /* CONFIG_DYNAMIC_FTRACE */
22739 #endif /* CONFIG_FUNCTION_TRACER */
22740
22741@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22742
22743 MCOUNT_RESTORE_FRAME
22744
22745+ pax_force_retaddr
22746 retq
22747-END(ftrace_graph_caller)
22748+ENDPROC(ftrace_graph_caller)
22749
22750 GLOBAL(return_to_handler)
22751 subq $24, %rsp
22752@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22753 movq 8(%rsp), %rdx
22754 movq (%rsp), %rax
22755 addq $24, %rsp
22756+ pax_force_fptr %rdi
22757 jmp *%rdi
22758+ENDPROC(return_to_handler)
22759 #endif
22760
22761
22762@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22763 ENDPROC(native_usergs_sysret64)
22764 #endif /* CONFIG_PARAVIRT */
22765
22766+ .macro ljmpq sel, off
22767+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22768+ .byte 0x48; ljmp *1234f(%rip)
22769+ .pushsection .rodata
22770+ .align 16
22771+ 1234: .quad \off; .word \sel
22772+ .popsection
22773+#else
22774+ pushq $\sel
22775+ pushq $\off
22776+ lretq
22777+#endif
22778+ .endm
22779+
22780+ .macro pax_enter_kernel
22781+ pax_set_fptr_mask
22782+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22783+ call pax_enter_kernel
22784+#endif
22785+ .endm
22786+
22787+ .macro pax_exit_kernel
22788+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22789+ call pax_exit_kernel
22790+#endif
22791+
22792+ .endm
22793+
22794+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22795+ENTRY(pax_enter_kernel)
22796+ pushq %rdi
22797+
22798+#ifdef CONFIG_PARAVIRT
22799+ PV_SAVE_REGS(CLBR_RDI)
22800+#endif
22801+
22802+#ifdef CONFIG_PAX_KERNEXEC
22803+ GET_CR0_INTO_RDI
22804+ bts $16,%rdi
22805+ jnc 3f
22806+ mov %cs,%edi
22807+ cmp $__KERNEL_CS,%edi
22808+ jnz 2f
22809+1:
22810+#endif
22811+
22812+#ifdef CONFIG_PAX_MEMORY_UDEREF
22813+ 661: jmp 111f
22814+ .pushsection .altinstr_replacement, "a"
22815+ 662: ASM_NOP2
22816+ .popsection
22817+ .pushsection .altinstructions, "a"
22818+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22819+ .popsection
22820+ GET_CR3_INTO_RDI
22821+ cmp $0,%dil
22822+ jnz 112f
22823+ mov $__KERNEL_DS,%edi
22824+ mov %edi,%ss
22825+ jmp 111f
22826+112: cmp $1,%dil
22827+ jz 113f
22828+ ud2
22829+113: sub $4097,%rdi
22830+ bts $63,%rdi
22831+ SET_RDI_INTO_CR3
22832+ mov $__UDEREF_KERNEL_DS,%edi
22833+ mov %edi,%ss
22834+111:
22835+#endif
22836+
22837+#ifdef CONFIG_PARAVIRT
22838+ PV_RESTORE_REGS(CLBR_RDI)
22839+#endif
22840+
22841+ popq %rdi
22842+ pax_force_retaddr
22843+ retq
22844+
22845+#ifdef CONFIG_PAX_KERNEXEC
22846+2: ljmpq __KERNEL_CS,1b
22847+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22848+4: SET_RDI_INTO_CR0
22849+ jmp 1b
22850+#endif
22851+ENDPROC(pax_enter_kernel)
22852+
22853+ENTRY(pax_exit_kernel)
22854+ pushq %rdi
22855+
22856+#ifdef CONFIG_PARAVIRT
22857+ PV_SAVE_REGS(CLBR_RDI)
22858+#endif
22859+
22860+#ifdef CONFIG_PAX_KERNEXEC
22861+ mov %cs,%rdi
22862+ cmp $__KERNEXEC_KERNEL_CS,%edi
22863+ jz 2f
22864+ GET_CR0_INTO_RDI
22865+ bts $16,%rdi
22866+ jnc 4f
22867+1:
22868+#endif
22869+
22870+#ifdef CONFIG_PAX_MEMORY_UDEREF
22871+ 661: jmp 111f
22872+ .pushsection .altinstr_replacement, "a"
22873+ 662: ASM_NOP2
22874+ .popsection
22875+ .pushsection .altinstructions, "a"
22876+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22877+ .popsection
22878+ mov %ss,%edi
22879+ cmp $__UDEREF_KERNEL_DS,%edi
22880+ jnz 111f
22881+ GET_CR3_INTO_RDI
22882+ cmp $0,%dil
22883+ jz 112f
22884+ ud2
22885+112: add $4097,%rdi
22886+ bts $63,%rdi
22887+ SET_RDI_INTO_CR3
22888+ mov $__KERNEL_DS,%edi
22889+ mov %edi,%ss
22890+111:
22891+#endif
22892+
22893+#ifdef CONFIG_PARAVIRT
22894+ PV_RESTORE_REGS(CLBR_RDI);
22895+#endif
22896+
22897+ popq %rdi
22898+ pax_force_retaddr
22899+ retq
22900+
22901+#ifdef CONFIG_PAX_KERNEXEC
22902+2: GET_CR0_INTO_RDI
22903+ btr $16,%rdi
22904+ jnc 4f
22905+ ljmpq __KERNEL_CS,3f
22906+3: SET_RDI_INTO_CR0
22907+ jmp 1b
22908+4: ud2
22909+ jmp 4b
22910+#endif
22911+ENDPROC(pax_exit_kernel)
22912+#endif
22913+
22914+ .macro pax_enter_kernel_user
22915+ pax_set_fptr_mask
22916+#ifdef CONFIG_PAX_MEMORY_UDEREF
22917+ call pax_enter_kernel_user
22918+#endif
22919+ .endm
22920+
22921+ .macro pax_exit_kernel_user
22922+#ifdef CONFIG_PAX_MEMORY_UDEREF
22923+ call pax_exit_kernel_user
22924+#endif
22925+#ifdef CONFIG_PAX_RANDKSTACK
22926+ pushq %rax
22927+ pushq %r11
22928+ call pax_randomize_kstack
22929+ popq %r11
22930+ popq %rax
22931+#endif
22932+ .endm
22933+
22934+#ifdef CONFIG_PAX_MEMORY_UDEREF
22935+ENTRY(pax_enter_kernel_user)
22936+ pushq %rdi
22937+ pushq %rbx
22938+
22939+#ifdef CONFIG_PARAVIRT
22940+ PV_SAVE_REGS(CLBR_RDI)
22941+#endif
22942+
22943+ 661: jmp 111f
22944+ .pushsection .altinstr_replacement, "a"
22945+ 662: ASM_NOP2
22946+ .popsection
22947+ .pushsection .altinstructions, "a"
22948+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22949+ .popsection
22950+ GET_CR3_INTO_RDI
22951+ cmp $1,%dil
22952+ jnz 4f
22953+ sub $4097,%rdi
22954+ bts $63,%rdi
22955+ SET_RDI_INTO_CR3
22956+ jmp 3f
22957+111:
22958+
22959+ GET_CR3_INTO_RDI
22960+ mov %rdi,%rbx
22961+ add $__START_KERNEL_map,%rbx
22962+ sub phys_base(%rip),%rbx
22963+
22964+#ifdef CONFIG_PARAVIRT
22965+ cmpl $0, pv_info+PARAVIRT_enabled
22966+ jz 1f
22967+ pushq %rdi
22968+ i = 0
22969+ .rept USER_PGD_PTRS
22970+ mov i*8(%rbx),%rsi
22971+ mov $0,%sil
22972+ lea i*8(%rbx),%rdi
22973+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22974+ i = i + 1
22975+ .endr
22976+ popq %rdi
22977+ jmp 2f
22978+1:
22979+#endif
22980+
22981+ i = 0
22982+ .rept USER_PGD_PTRS
22983+ movb $0,i*8(%rbx)
22984+ i = i + 1
22985+ .endr
22986+
22987+2: SET_RDI_INTO_CR3
22988+
22989+#ifdef CONFIG_PAX_KERNEXEC
22990+ GET_CR0_INTO_RDI
22991+ bts $16,%rdi
22992+ SET_RDI_INTO_CR0
22993+#endif
22994+
22995+3:
22996+
22997+#ifdef CONFIG_PARAVIRT
22998+ PV_RESTORE_REGS(CLBR_RDI)
22999+#endif
23000+
23001+ popq %rbx
23002+ popq %rdi
23003+ pax_force_retaddr
23004+ retq
23005+4: ud2
23006+ENDPROC(pax_enter_kernel_user)
23007+
23008+ENTRY(pax_exit_kernel_user)
23009+ pushq %rdi
23010+ pushq %rbx
23011+
23012+#ifdef CONFIG_PARAVIRT
23013+ PV_SAVE_REGS(CLBR_RDI)
23014+#endif
23015+
23016+ GET_CR3_INTO_RDI
23017+ 661: jmp 1f
23018+ .pushsection .altinstr_replacement, "a"
23019+ 662: ASM_NOP2
23020+ .popsection
23021+ .pushsection .altinstructions, "a"
23022+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23023+ .popsection
23024+ cmp $0,%dil
23025+ jnz 3f
23026+ add $4097,%rdi
23027+ bts $63,%rdi
23028+ SET_RDI_INTO_CR3
23029+ jmp 2f
23030+1:
23031+
23032+ mov %rdi,%rbx
23033+
23034+#ifdef CONFIG_PAX_KERNEXEC
23035+ GET_CR0_INTO_RDI
23036+ btr $16,%rdi
23037+ jnc 3f
23038+ SET_RDI_INTO_CR0
23039+#endif
23040+
23041+ add $__START_KERNEL_map,%rbx
23042+ sub phys_base(%rip),%rbx
23043+
23044+#ifdef CONFIG_PARAVIRT
23045+ cmpl $0, pv_info+PARAVIRT_enabled
23046+ jz 1f
23047+ i = 0
23048+ .rept USER_PGD_PTRS
23049+ mov i*8(%rbx),%rsi
23050+ mov $0x67,%sil
23051+ lea i*8(%rbx),%rdi
23052+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23053+ i = i + 1
23054+ .endr
23055+ jmp 2f
23056+1:
23057+#endif
23058+
23059+ i = 0
23060+ .rept USER_PGD_PTRS
23061+ movb $0x67,i*8(%rbx)
23062+ i = i + 1
23063+ .endr
23064+2:
23065+
23066+#ifdef CONFIG_PARAVIRT
23067+ PV_RESTORE_REGS(CLBR_RDI)
23068+#endif
23069+
23070+ popq %rbx
23071+ popq %rdi
23072+ pax_force_retaddr
23073+ retq
23074+3: ud2
23075+ENDPROC(pax_exit_kernel_user)
23076+#endif
23077+
23078+ .macro pax_enter_kernel_nmi
23079+ pax_set_fptr_mask
23080+
23081+#ifdef CONFIG_PAX_KERNEXEC
23082+ GET_CR0_INTO_RDI
23083+ bts $16,%rdi
23084+ jc 110f
23085+ SET_RDI_INTO_CR0
23086+ or $2,%ebx
23087+110:
23088+#endif
23089+
23090+#ifdef CONFIG_PAX_MEMORY_UDEREF
23091+ 661: jmp 111f
23092+ .pushsection .altinstr_replacement, "a"
23093+ 662: ASM_NOP2
23094+ .popsection
23095+ .pushsection .altinstructions, "a"
23096+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23097+ .popsection
23098+ GET_CR3_INTO_RDI
23099+ cmp $0,%dil
23100+ jz 111f
23101+ sub $4097,%rdi
23102+ or $4,%ebx
23103+ bts $63,%rdi
23104+ SET_RDI_INTO_CR3
23105+ mov $__UDEREF_KERNEL_DS,%edi
23106+ mov %edi,%ss
23107+111:
23108+#endif
23109+ .endm
23110+
23111+ .macro pax_exit_kernel_nmi
23112+#ifdef CONFIG_PAX_KERNEXEC
23113+ btr $1,%ebx
23114+ jnc 110f
23115+ GET_CR0_INTO_RDI
23116+ btr $16,%rdi
23117+ SET_RDI_INTO_CR0
23118+110:
23119+#endif
23120+
23121+#ifdef CONFIG_PAX_MEMORY_UDEREF
23122+ btr $2,%ebx
23123+ jnc 111f
23124+ GET_CR3_INTO_RDI
23125+ add $4097,%rdi
23126+ bts $63,%rdi
23127+ SET_RDI_INTO_CR3
23128+ mov $__KERNEL_DS,%edi
23129+ mov %edi,%ss
23130+111:
23131+#endif
23132+ .endm
23133+
23134+ .macro pax_erase_kstack
23135+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23136+ call pax_erase_kstack
23137+#endif
23138+ .endm
23139+
23140+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23141+ENTRY(pax_erase_kstack)
23142+ pushq %rdi
23143+ pushq %rcx
23144+ pushq %rax
23145+ pushq %r11
23146+
23147+ GET_THREAD_INFO(%r11)
23148+ mov TI_lowest_stack(%r11), %rdi
23149+ mov $-0xBEEF, %rax
23150+ std
23151+
23152+1: mov %edi, %ecx
23153+ and $THREAD_SIZE_asm - 1, %ecx
23154+ shr $3, %ecx
23155+ repne scasq
23156+ jecxz 2f
23157+
23158+ cmp $2*8, %ecx
23159+ jc 2f
23160+
23161+ mov $2*8, %ecx
23162+ repe scasq
23163+ jecxz 2f
23164+ jne 1b
23165+
23166+2: cld
23167+ mov %esp, %ecx
23168+ sub %edi, %ecx
23169+
23170+ cmp $THREAD_SIZE_asm, %rcx
23171+ jb 3f
23172+ ud2
23173+3:
23174+
23175+ shr $3, %ecx
23176+ rep stosq
23177+
23178+ mov TI_task_thread_sp0(%r11), %rdi
23179+ sub $256, %rdi
23180+ mov %rdi, TI_lowest_stack(%r11)
23181+
23182+ popq %r11
23183+ popq %rax
23184+ popq %rcx
23185+ popq %rdi
23186+ pax_force_retaddr
23187+ ret
23188+ENDPROC(pax_erase_kstack)
23189+#endif
23190
23191 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23192 #ifdef CONFIG_TRACE_IRQFLAGS
23193@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23194 .endm
23195
23196 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23197- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23198+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23199 jnc 1f
23200 TRACE_IRQS_ON_DEBUG
23201 1:
23202@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23203 movq \tmp,R11+\offset(%rsp)
23204 .endm
23205
23206- .macro FAKE_STACK_FRAME child_rip
23207- /* push in order ss, rsp, eflags, cs, rip */
23208- xorl %eax, %eax
23209- pushq_cfi $__KERNEL_DS /* ss */
23210- /*CFI_REL_OFFSET ss,0*/
23211- pushq_cfi %rax /* rsp */
23212- CFI_REL_OFFSET rsp,0
23213- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23214- /*CFI_REL_OFFSET rflags,0*/
23215- pushq_cfi $__KERNEL_CS /* cs */
23216- /*CFI_REL_OFFSET cs,0*/
23217- pushq_cfi \child_rip /* rip */
23218- CFI_REL_OFFSET rip,0
23219- pushq_cfi %rax /* orig rax */
23220- .endm
23221-
23222- .macro UNFAKE_STACK_FRAME
23223- addq $8*6, %rsp
23224- CFI_ADJUST_CFA_OFFSET -(6*8)
23225- .endm
23226-
23227 /*
23228 * initial frame state for interrupts (and exceptions without error code)
23229 */
23230@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23231 /* save partial stack frame */
23232 .macro SAVE_ARGS_IRQ
23233 cld
23234- /* start from rbp in pt_regs and jump over */
23235- movq_cfi rdi, (RDI-RBP)
23236- movq_cfi rsi, (RSI-RBP)
23237- movq_cfi rdx, (RDX-RBP)
23238- movq_cfi rcx, (RCX-RBP)
23239- movq_cfi rax, (RAX-RBP)
23240- movq_cfi r8, (R8-RBP)
23241- movq_cfi r9, (R9-RBP)
23242- movq_cfi r10, (R10-RBP)
23243- movq_cfi r11, (R11-RBP)
23244+ /* start from r15 in pt_regs and jump over */
23245+ movq_cfi rdi, RDI
23246+ movq_cfi rsi, RSI
23247+ movq_cfi rdx, RDX
23248+ movq_cfi rcx, RCX
23249+ movq_cfi rax, RAX
23250+ movq_cfi r8, R8
23251+ movq_cfi r9, R9
23252+ movq_cfi r10, R10
23253+ movq_cfi r11, R11
23254+ movq_cfi r12, R12
23255
23256 /* Save rbp so that we can unwind from get_irq_regs() */
23257- movq_cfi rbp, 0
23258+ movq_cfi rbp, RBP
23259
23260 /* Save previous stack value */
23261 movq %rsp, %rsi
23262
23263- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23264- testl $3, CS-RBP(%rsi)
23265+ movq %rsp,%rdi /* arg1 for handler */
23266+ testb $3, CS(%rsi)
23267 je 1f
23268 SWAPGS
23269 /*
23270@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23271 0x06 /* DW_OP_deref */, \
23272 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23273 0x22 /* DW_OP_plus */
23274+
23275+#ifdef CONFIG_PAX_MEMORY_UDEREF
23276+ testb $3, CS(%rdi)
23277+ jnz 1f
23278+ pax_enter_kernel
23279+ jmp 2f
23280+1: pax_enter_kernel_user
23281+2:
23282+#else
23283+ pax_enter_kernel
23284+#endif
23285+
23286 /* We entered an interrupt context - irqs are off: */
23287 TRACE_IRQS_OFF
23288 .endm
23289@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23290 js 1f /* negative -> in kernel */
23291 SWAPGS
23292 xorl %ebx,%ebx
23293-1: ret
23294+1:
23295+#ifdef CONFIG_PAX_MEMORY_UDEREF
23296+ testb $3, CS+8(%rsp)
23297+ jnz 1f
23298+ pax_enter_kernel
23299+ jmp 2f
23300+1: pax_enter_kernel_user
23301+2:
23302+#else
23303+ pax_enter_kernel
23304+#endif
23305+ pax_force_retaddr
23306+ ret
23307 CFI_ENDPROC
23308-END(save_paranoid)
23309+ENDPROC(save_paranoid)
23310+
23311+ENTRY(save_paranoid_nmi)
23312+ XCPT_FRAME 1 RDI+8
23313+ cld
23314+ movq_cfi rdi, RDI+8
23315+ movq_cfi rsi, RSI+8
23316+ movq_cfi rdx, RDX+8
23317+ movq_cfi rcx, RCX+8
23318+ movq_cfi rax, RAX+8
23319+ movq_cfi r8, R8+8
23320+ movq_cfi r9, R9+8
23321+ movq_cfi r10, R10+8
23322+ movq_cfi r11, R11+8
23323+ movq_cfi rbx, RBX+8
23324+ movq_cfi rbp, RBP+8
23325+ movq_cfi r12, R12+8
23326+ movq_cfi r13, R13+8
23327+ movq_cfi r14, R14+8
23328+ movq_cfi r15, R15+8
23329+ movl $1,%ebx
23330+ movl $MSR_GS_BASE,%ecx
23331+ rdmsr
23332+ testl %edx,%edx
23333+ js 1f /* negative -> in kernel */
23334+ SWAPGS
23335+ xorl %ebx,%ebx
23336+1: pax_enter_kernel_nmi
23337+ pax_force_retaddr
23338+ ret
23339+ CFI_ENDPROC
23340+ENDPROC(save_paranoid_nmi)
23341 .popsection
23342
23343 /*
23344@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23345
23346 RESTORE_REST
23347
23348- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23349+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23350 jz 1f
23351
23352 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23353@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23354 jmp ret_from_sys_call # go to the SYSRET fastpath
23355
23356 1:
23357- subq $REST_SKIP, %rsp # leave space for volatiles
23358- CFI_ADJUST_CFA_OFFSET REST_SKIP
23359 movq %rbp, %rdi
23360 call *%rbx
23361 movl $0, RAX(%rsp)
23362 RESTORE_REST
23363 jmp int_ret_from_sys_call
23364 CFI_ENDPROC
23365-END(ret_from_fork)
23366+ENDPROC(ret_from_fork)
23367
23368 /*
23369 * System call entry. Up to 6 arguments in registers are supported.
23370@@ -593,7 +1059,7 @@ END(ret_from_fork)
23371 ENTRY(system_call)
23372 CFI_STARTPROC simple
23373 CFI_SIGNAL_FRAME
23374- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23375+ CFI_DEF_CFA rsp,0
23376 CFI_REGISTER rip,rcx
23377 /*CFI_REGISTER rflags,r11*/
23378 SWAPGS_UNSAFE_STACK
23379@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23380
23381 movq %rsp,PER_CPU_VAR(old_rsp)
23382 movq PER_CPU_VAR(kernel_stack),%rsp
23383+ SAVE_ARGS 8*6,0
23384+ pax_enter_kernel_user
23385+
23386+#ifdef CONFIG_PAX_RANDKSTACK
23387+ pax_erase_kstack
23388+#endif
23389+
23390 /*
23391 * No need to follow this irqs off/on section - it's straight
23392 * and short:
23393 */
23394 ENABLE_INTERRUPTS(CLBR_NONE)
23395- SAVE_ARGS 8,0
23396 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23397 movq %rcx,RIP-ARGOFFSET(%rsp)
23398 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23399- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23400+ GET_THREAD_INFO(%rcx)
23401+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23402 jnz tracesys
23403 system_call_fastpath:
23404 #if __SYSCALL_MASK == ~0
23405@@ -639,10 +1112,13 @@ sysret_check:
23406 LOCKDEP_SYS_EXIT
23407 DISABLE_INTERRUPTS(CLBR_NONE)
23408 TRACE_IRQS_OFF
23409- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23410+ GET_THREAD_INFO(%rcx)
23411+ movl TI_flags(%rcx),%edx
23412 andl %edi,%edx
23413 jnz sysret_careful
23414 CFI_REMEMBER_STATE
23415+ pax_exit_kernel_user
23416+ pax_erase_kstack
23417 /*
23418 * sysretq will re-enable interrupts:
23419 */
23420@@ -701,6 +1177,9 @@ auditsys:
23421 movq %rax,%rsi /* 2nd arg: syscall number */
23422 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23423 call __audit_syscall_entry
23424+
23425+ pax_erase_kstack
23426+
23427 LOAD_ARGS 0 /* reload call-clobbered registers */
23428 jmp system_call_fastpath
23429
23430@@ -722,7 +1201,7 @@ sysret_audit:
23431 /* Do syscall tracing */
23432 tracesys:
23433 #ifdef CONFIG_AUDITSYSCALL
23434- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23435+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23436 jz auditsys
23437 #endif
23438 SAVE_REST
23439@@ -730,12 +1209,15 @@ tracesys:
23440 FIXUP_TOP_OF_STACK %rdi
23441 movq %rsp,%rdi
23442 call syscall_trace_enter
23443+
23444+ pax_erase_kstack
23445+
23446 /*
23447 * Reload arg registers from stack in case ptrace changed them.
23448 * We don't reload %rax because syscall_trace_enter() returned
23449 * the value it wants us to use in the table lookup.
23450 */
23451- LOAD_ARGS ARGOFFSET, 1
23452+ LOAD_ARGS 1
23453 RESTORE_REST
23454 #if __SYSCALL_MASK == ~0
23455 cmpq $__NR_syscall_max,%rax
23456@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23457 andl %edi,%edx
23458 jnz int_careful
23459 andl $~TS_COMPAT,TI_status(%rcx)
23460- jmp retint_swapgs
23461+ pax_exit_kernel_user
23462+ pax_erase_kstack
23463+ jmp retint_swapgs_pax
23464
23465 /* Either reschedule or signal or syscall exit tracking needed. */
23466 /* First do a reschedule test. */
23467@@ -811,7 +1295,7 @@ int_restore_rest:
23468 TRACE_IRQS_OFF
23469 jmp int_with_check
23470 CFI_ENDPROC
23471-END(system_call)
23472+ENDPROC(system_call)
23473
23474 .macro FORK_LIKE func
23475 ENTRY(stub_\func)
23476@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23477 DEFAULT_FRAME 0 8 /* offset 8: return address */
23478 call sys_\func
23479 RESTORE_TOP_OF_STACK %r11, 8
23480- ret $REST_SKIP /* pop extended registers */
23481+ pax_force_retaddr
23482+ ret
23483 CFI_ENDPROC
23484-END(stub_\func)
23485+ENDPROC(stub_\func)
23486 .endm
23487
23488 .macro FIXED_FRAME label,func
23489@@ -836,9 +1321,10 @@ ENTRY(\label)
23490 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23491 call \func
23492 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23493+ pax_force_retaddr
23494 ret
23495 CFI_ENDPROC
23496-END(\label)
23497+ENDPROC(\label)
23498 .endm
23499
23500 FORK_LIKE clone
23501@@ -846,19 +1332,6 @@ END(\label)
23502 FORK_LIKE vfork
23503 FIXED_FRAME stub_iopl, sys_iopl
23504
23505-ENTRY(ptregscall_common)
23506- DEFAULT_FRAME 1 8 /* offset 8: return address */
23507- RESTORE_TOP_OF_STACK %r11, 8
23508- movq_cfi_restore R15+8, r15
23509- movq_cfi_restore R14+8, r14
23510- movq_cfi_restore R13+8, r13
23511- movq_cfi_restore R12+8, r12
23512- movq_cfi_restore RBP+8, rbp
23513- movq_cfi_restore RBX+8, rbx
23514- ret $REST_SKIP /* pop extended registers */
23515- CFI_ENDPROC
23516-END(ptregscall_common)
23517-
23518 ENTRY(stub_execve)
23519 CFI_STARTPROC
23520 addq $8, %rsp
23521@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23522 RESTORE_REST
23523 jmp int_ret_from_sys_call
23524 CFI_ENDPROC
23525-END(stub_execve)
23526+ENDPROC(stub_execve)
23527
23528 /*
23529 * sigreturn is special because it needs to restore all registers on return.
23530@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23531 RESTORE_REST
23532 jmp int_ret_from_sys_call
23533 CFI_ENDPROC
23534-END(stub_rt_sigreturn)
23535+ENDPROC(stub_rt_sigreturn)
23536
23537 #ifdef CONFIG_X86_X32_ABI
23538 ENTRY(stub_x32_rt_sigreturn)
23539@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23540 RESTORE_REST
23541 jmp int_ret_from_sys_call
23542 CFI_ENDPROC
23543-END(stub_x32_rt_sigreturn)
23544+ENDPROC(stub_x32_rt_sigreturn)
23545
23546 ENTRY(stub_x32_execve)
23547 CFI_STARTPROC
23548@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23549 RESTORE_REST
23550 jmp int_ret_from_sys_call
23551 CFI_ENDPROC
23552-END(stub_x32_execve)
23553+ENDPROC(stub_x32_execve)
23554
23555 #endif
23556
23557@@ -952,7 +1425,7 @@ vector=vector+1
23558 2: jmp common_interrupt
23559 .endr
23560 CFI_ENDPROC
23561-END(irq_entries_start)
23562+ENDPROC(irq_entries_start)
23563
23564 .previous
23565 END(interrupt)
23566@@ -969,8 +1442,8 @@ END(interrupt)
23567 /* 0(%rsp): ~(interrupt number) */
23568 .macro interrupt func
23569 /* reserve pt_regs for scratch regs and rbp */
23570- subq $ORIG_RAX-RBP, %rsp
23571- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23572+ subq $ORIG_RAX, %rsp
23573+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23574 SAVE_ARGS_IRQ
23575 call \func
23576 .endm
23577@@ -997,14 +1470,14 @@ ret_from_intr:
23578
23579 /* Restore saved previous stack */
23580 popq %rsi
23581- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23582- leaq ARGOFFSET-RBP(%rsi), %rsp
23583+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23584+ movq %rsi, %rsp
23585 CFI_DEF_CFA_REGISTER rsp
23586- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23587+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23588
23589 exit_intr:
23590 GET_THREAD_INFO(%rcx)
23591- testl $3,CS-ARGOFFSET(%rsp)
23592+ testb $3,CS-ARGOFFSET(%rsp)
23593 je retint_kernel
23594
23595 /* Interrupt came from user space */
23596@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23597 * The iretq could re-enable interrupts:
23598 */
23599 DISABLE_INTERRUPTS(CLBR_ANY)
23600+ pax_exit_kernel_user
23601+retint_swapgs_pax:
23602 TRACE_IRQS_IRETQ
23603 SWAPGS
23604 jmp restore_args
23605
23606 retint_restore_args: /* return to kernel space */
23607 DISABLE_INTERRUPTS(CLBR_ANY)
23608+ pax_exit_kernel
23609+ pax_force_retaddr (RIP-ARGOFFSET)
23610 /*
23611 * The iretq could re-enable interrupts:
23612 */
23613@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23614 #endif
23615
23616 CFI_ENDPROC
23617-END(common_interrupt)
23618+ENDPROC(common_interrupt)
23619 /*
23620 * End of kprobes section
23621 */
23622@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23623 interrupt \do_sym
23624 jmp ret_from_intr
23625 CFI_ENDPROC
23626-END(\sym)
23627+ENDPROC(\sym)
23628 .endm
23629
23630 #ifdef CONFIG_TRACING
23631@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23632 call \do_sym
23633 jmp error_exit /* %ebx: no swapgs flag */
23634 CFI_ENDPROC
23635-END(\sym)
23636+ENDPROC(\sym)
23637 .endm
23638
23639 .macro paranoidzeroentry sym do_sym
23640@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23641 call \do_sym
23642 jmp paranoid_exit /* %ebx: no swapgs flag */
23643 CFI_ENDPROC
23644-END(\sym)
23645+ENDPROC(\sym)
23646 .endm
23647
23648-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23649+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23650 .macro paranoidzeroentry_ist sym do_sym ist
23651 ENTRY(\sym)
23652 INTR_FRAME
23653@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23654 TRACE_IRQS_OFF_DEBUG
23655 movq %rsp,%rdi /* pt_regs pointer */
23656 xorl %esi,%esi /* no error code */
23657+#ifdef CONFIG_SMP
23658+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23659+ lea init_tss(%r13), %r13
23660+#else
23661+ lea init_tss(%rip), %r13
23662+#endif
23663 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23664 call \do_sym
23665 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23666 jmp paranoid_exit /* %ebx: no swapgs flag */
23667 CFI_ENDPROC
23668-END(\sym)
23669+ENDPROC(\sym)
23670 .endm
23671
23672 .macro errorentry sym do_sym
23673@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23674 call \do_sym
23675 jmp error_exit /* %ebx: no swapgs flag */
23676 CFI_ENDPROC
23677-END(\sym)
23678+ENDPROC(\sym)
23679 .endm
23680
23681 #ifdef CONFIG_TRACING
23682@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23683 call \do_sym
23684 jmp paranoid_exit /* %ebx: no swapgs flag */
23685 CFI_ENDPROC
23686-END(\sym)
23687+ENDPROC(\sym)
23688 .endm
23689
23690 zeroentry divide_error do_divide_error
23691@@ -1336,9 +1819,10 @@ gs_change:
23692 2: mfence /* workaround */
23693 SWAPGS
23694 popfq_cfi
23695+ pax_force_retaddr
23696 ret
23697 CFI_ENDPROC
23698-END(native_load_gs_index)
23699+ENDPROC(native_load_gs_index)
23700
23701 _ASM_EXTABLE(gs_change,bad_gs)
23702 .section .fixup,"ax"
23703@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23704 CFI_DEF_CFA_REGISTER rsp
23705 CFI_ADJUST_CFA_OFFSET -8
23706 decl PER_CPU_VAR(irq_count)
23707+ pax_force_retaddr
23708 ret
23709 CFI_ENDPROC
23710-END(do_softirq_own_stack)
23711+ENDPROC(do_softirq_own_stack)
23712
23713 #ifdef CONFIG_XEN
23714 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23715@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23716 decl PER_CPU_VAR(irq_count)
23717 jmp error_exit
23718 CFI_ENDPROC
23719-END(xen_do_hypervisor_callback)
23720+ENDPROC(xen_do_hypervisor_callback)
23721
23722 /*
23723 * Hypervisor uses this for application faults while it executes.
23724@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23725 SAVE_ALL
23726 jmp error_exit
23727 CFI_ENDPROC
23728-END(xen_failsafe_callback)
23729+ENDPROC(xen_failsafe_callback)
23730
23731 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23732 xen_hvm_callback_vector xen_evtchn_do_upcall
23733@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23734 DEFAULT_FRAME
23735 DISABLE_INTERRUPTS(CLBR_NONE)
23736 TRACE_IRQS_OFF_DEBUG
23737- testl %ebx,%ebx /* swapgs needed? */
23738+ testl $1,%ebx /* swapgs needed? */
23739 jnz paranoid_restore
23740- testl $3,CS(%rsp)
23741+ testb $3,CS(%rsp)
23742 jnz paranoid_userspace
23743+#ifdef CONFIG_PAX_MEMORY_UDEREF
23744+ pax_exit_kernel
23745+ TRACE_IRQS_IRETQ 0
23746+ SWAPGS_UNSAFE_STACK
23747+ RESTORE_ALL 8
23748+ pax_force_retaddr_bts
23749+ jmp irq_return
23750+#endif
23751 paranoid_swapgs:
23752+#ifdef CONFIG_PAX_MEMORY_UDEREF
23753+ pax_exit_kernel_user
23754+#else
23755+ pax_exit_kernel
23756+#endif
23757 TRACE_IRQS_IRETQ 0
23758 SWAPGS_UNSAFE_STACK
23759 RESTORE_ALL 8
23760 jmp irq_return
23761 paranoid_restore:
23762+ pax_exit_kernel
23763 TRACE_IRQS_IRETQ_DEBUG 0
23764 RESTORE_ALL 8
23765+ pax_force_retaddr_bts
23766 jmp irq_return
23767 paranoid_userspace:
23768 GET_THREAD_INFO(%rcx)
23769@@ -1557,7 +2057,7 @@ paranoid_schedule:
23770 TRACE_IRQS_OFF
23771 jmp paranoid_userspace
23772 CFI_ENDPROC
23773-END(paranoid_exit)
23774+ENDPROC(paranoid_exit)
23775
23776 /*
23777 * Exception entry point. This expects an error code/orig_rax on the stack.
23778@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23779 movq_cfi r14, R14+8
23780 movq_cfi r15, R15+8
23781 xorl %ebx,%ebx
23782- testl $3,CS+8(%rsp)
23783+ testb $3,CS+8(%rsp)
23784 je error_kernelspace
23785 error_swapgs:
23786 SWAPGS
23787 error_sti:
23788+#ifdef CONFIG_PAX_MEMORY_UDEREF
23789+ testb $3, CS+8(%rsp)
23790+ jnz 1f
23791+ pax_enter_kernel
23792+ jmp 2f
23793+1: pax_enter_kernel_user
23794+2:
23795+#else
23796+ pax_enter_kernel
23797+#endif
23798 TRACE_IRQS_OFF
23799+ pax_force_retaddr
23800 ret
23801
23802 /*
23803@@ -1616,7 +2127,7 @@ bstep_iret:
23804 movq %rcx,RIP+8(%rsp)
23805 jmp error_swapgs
23806 CFI_ENDPROC
23807-END(error_entry)
23808+ENDPROC(error_entry)
23809
23810
23811 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23812@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23813 DISABLE_INTERRUPTS(CLBR_NONE)
23814 TRACE_IRQS_OFF
23815 GET_THREAD_INFO(%rcx)
23816- testl %eax,%eax
23817+ testl $1,%eax
23818 jne retint_kernel
23819 LOCKDEP_SYS_EXIT_IRQ
23820 movl TI_flags(%rcx),%edx
23821@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23822 jnz retint_careful
23823 jmp retint_swapgs
23824 CFI_ENDPROC
23825-END(error_exit)
23826+ENDPROC(error_exit)
23827
23828 /*
23829 * Test if a given stack is an NMI stack or not.
23830@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23831 * If %cs was not the kernel segment, then the NMI triggered in user
23832 * space, which means it is definitely not nested.
23833 */
23834+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23835+ je 1f
23836 cmpl $__KERNEL_CS, 16(%rsp)
23837 jne first_nmi
23838-
23839+1:
23840 /*
23841 * Check the special variable on the stack to see if NMIs are
23842 * executing.
23843@@ -1730,8 +2243,7 @@ nested_nmi:
23844
23845 1:
23846 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23847- leaq -1*8(%rsp), %rdx
23848- movq %rdx, %rsp
23849+ subq $8, %rsp
23850 CFI_ADJUST_CFA_OFFSET 1*8
23851 leaq -10*8(%rsp), %rdx
23852 pushq_cfi $__KERNEL_DS
23853@@ -1749,6 +2261,7 @@ nested_nmi_out:
23854 CFI_RESTORE rdx
23855
23856 /* No need to check faults here */
23857+# pax_force_retaddr_bts
23858 INTERRUPT_RETURN
23859
23860 CFI_RESTORE_STATE
23861@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23862 subq $ORIG_RAX-R15, %rsp
23863 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23864 /*
23865- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23866+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23867 * as we should not be calling schedule in NMI context.
23868 * Even with normal interrupts enabled. An NMI should not be
23869 * setting NEED_RESCHED or anything that normal interrupts and
23870 * exceptions might do.
23871 */
23872- call save_paranoid
23873+ call save_paranoid_nmi
23874 DEFAULT_FRAME 0
23875
23876 /*
23877@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23878 * NMI itself takes a page fault, the page fault that was preempted
23879 * will read the information from the NMI page fault and not the
23880 * origin fault. Save it off and restore it if it changes.
23881- * Use the r12 callee-saved register.
23882+ * Use the r13 callee-saved register.
23883 */
23884- movq %cr2, %r12
23885+ movq %cr2, %r13
23886
23887 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23888 movq %rsp,%rdi
23889@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23890
23891 /* Did the NMI take a page fault? Restore cr2 if it did */
23892 movq %cr2, %rcx
23893- cmpq %rcx, %r12
23894+ cmpq %rcx, %r13
23895 je 1f
23896- movq %r12, %cr2
23897+ movq %r13, %cr2
23898 1:
23899
23900- testl %ebx,%ebx /* swapgs needed? */
23901+ testl $1,%ebx /* swapgs needed? */
23902 jnz nmi_restore
23903 nmi_swapgs:
23904 SWAPGS_UNSAFE_STACK
23905 nmi_restore:
23906+ pax_exit_kernel_nmi
23907 /* Pop the extra iret frame at once */
23908 RESTORE_ALL 6*8
23909+ testb $3, 8(%rsp)
23910+ jnz 1f
23911+ pax_force_retaddr_bts
23912+1:
23913
23914 /* Clear the NMI executing stack variable */
23915 movq $0, 5*8(%rsp)
23916 jmp irq_return
23917 CFI_ENDPROC
23918-END(nmi)
23919+ENDPROC(nmi)
23920
23921 ENTRY(ignore_sysret)
23922 CFI_STARTPROC
23923 mov $-ENOSYS,%eax
23924 sysret
23925 CFI_ENDPROC
23926-END(ignore_sysret)
23927+ENDPROC(ignore_sysret)
23928
23929 /*
23930 * End of kprobes section
23931diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23932index e625319..b9abb9d 100644
23933--- a/arch/x86/kernel/ftrace.c
23934+++ b/arch/x86/kernel/ftrace.c
23935@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23936 {
23937 unsigned char replaced[MCOUNT_INSN_SIZE];
23938
23939+ ip = ktla_ktva(ip);
23940+
23941 /*
23942 * Note: Due to modules and __init, code can
23943 * disappear and change, we need to protect against faulting
23944@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23945 unsigned char old[MCOUNT_INSN_SIZE];
23946 int ret;
23947
23948- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23949+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23950
23951 ftrace_update_func = ip;
23952 /* Make sure the breakpoints see the ftrace_update_func update */
23953@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23954 * kernel identity mapping to modify code.
23955 */
23956 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23957- ip = (unsigned long)__va(__pa_symbol(ip));
23958+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23959
23960 return probe_kernel_write((void *)ip, val, size);
23961 }
23962@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23963 unsigned char replaced[MCOUNT_INSN_SIZE];
23964 unsigned char brk = BREAKPOINT_INSTRUCTION;
23965
23966- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23967+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23968 return -EFAULT;
23969
23970 /* Make sure it is what we expect it to be */
23971@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23972 return ret;
23973
23974 fail_update:
23975- probe_kernel_write((void *)ip, &old_code[0], 1);
23976+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23977 goto out;
23978 }
23979
23980diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23981index 85126cc..1bbce17 100644
23982--- a/arch/x86/kernel/head64.c
23983+++ b/arch/x86/kernel/head64.c
23984@@ -67,12 +67,12 @@ again:
23985 pgd = *pgd_p;
23986
23987 /*
23988- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23989- * critical -- __PAGE_OFFSET would point us back into the dynamic
23990+ * The use of __early_va rather than __va here is critical:
23991+ * __va would point us back into the dynamic
23992 * range and we might end up looping forever...
23993 */
23994 if (pgd)
23995- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23996+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23997 else {
23998 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23999 reset_early_page_tables();
24000@@ -82,13 +82,13 @@ again:
24001 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24002 for (i = 0; i < PTRS_PER_PUD; i++)
24003 pud_p[i] = 0;
24004- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24005+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24006 }
24007 pud_p += pud_index(address);
24008 pud = *pud_p;
24009
24010 if (pud)
24011- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24012+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24013 else {
24014 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24015 reset_early_page_tables();
24016@@ -98,7 +98,7 @@ again:
24017 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24018 for (i = 0; i < PTRS_PER_PMD; i++)
24019 pmd_p[i] = 0;
24020- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24021+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24022 }
24023 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24024 pmd_p[pmd_index(address)] = pmd;
24025@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24026 if (console_loglevel == 10)
24027 early_printk("Kernel alive\n");
24028
24029- clear_page(init_level4_pgt);
24030 /* set init_level4_pgt kernel high mapping*/
24031 init_level4_pgt[511] = early_level4_pgt[511];
24032
24033diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24034index f36bd42..56ee1534 100644
24035--- a/arch/x86/kernel/head_32.S
24036+++ b/arch/x86/kernel/head_32.S
24037@@ -26,6 +26,12 @@
24038 /* Physical address */
24039 #define pa(X) ((X) - __PAGE_OFFSET)
24040
24041+#ifdef CONFIG_PAX_KERNEXEC
24042+#define ta(X) (X)
24043+#else
24044+#define ta(X) ((X) - __PAGE_OFFSET)
24045+#endif
24046+
24047 /*
24048 * References to members of the new_cpu_data structure.
24049 */
24050@@ -55,11 +61,7 @@
24051 * and small than max_low_pfn, otherwise will waste some page table entries
24052 */
24053
24054-#if PTRS_PER_PMD > 1
24055-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24056-#else
24057-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24058-#endif
24059+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24060
24061 /* Number of possible pages in the lowmem region */
24062 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24063@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24064 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24065
24066 /*
24067+ * Real beginning of normal "text" segment
24068+ */
24069+ENTRY(stext)
24070+ENTRY(_stext)
24071+
24072+/*
24073 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24074 * %esi points to the real-mode code as a 32-bit pointer.
24075 * CS and DS must be 4 GB flat segments, but we don't depend on
24076@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24077 * can.
24078 */
24079 __HEAD
24080+
24081+#ifdef CONFIG_PAX_KERNEXEC
24082+ jmp startup_32
24083+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24084+.fill PAGE_SIZE-5,1,0xcc
24085+#endif
24086+
24087 ENTRY(startup_32)
24088 movl pa(stack_start),%ecx
24089
24090@@ -106,6 +121,59 @@ ENTRY(startup_32)
24091 2:
24092 leal -__PAGE_OFFSET(%ecx),%esp
24093
24094+#ifdef CONFIG_SMP
24095+ movl $pa(cpu_gdt_table),%edi
24096+ movl $__per_cpu_load,%eax
24097+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24098+ rorl $16,%eax
24099+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24100+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24101+ movl $__per_cpu_end - 1,%eax
24102+ subl $__per_cpu_start,%eax
24103+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24104+#endif
24105+
24106+#ifdef CONFIG_PAX_MEMORY_UDEREF
24107+ movl $NR_CPUS,%ecx
24108+ movl $pa(cpu_gdt_table),%edi
24109+1:
24110+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24111+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24112+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24113+ addl $PAGE_SIZE_asm,%edi
24114+ loop 1b
24115+#endif
24116+
24117+#ifdef CONFIG_PAX_KERNEXEC
24118+ movl $pa(boot_gdt),%edi
24119+ movl $__LOAD_PHYSICAL_ADDR,%eax
24120+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24121+ rorl $16,%eax
24122+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24123+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24124+ rorl $16,%eax
24125+
24126+ ljmp $(__BOOT_CS),$1f
24127+1:
24128+
24129+ movl $NR_CPUS,%ecx
24130+ movl $pa(cpu_gdt_table),%edi
24131+ addl $__PAGE_OFFSET,%eax
24132+1:
24133+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24134+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24135+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24136+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24137+ rorl $16,%eax
24138+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24139+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24140+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24141+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24142+ rorl $16,%eax
24143+ addl $PAGE_SIZE_asm,%edi
24144+ loop 1b
24145+#endif
24146+
24147 /*
24148 * Clear BSS first so that there are no surprises...
24149 */
24150@@ -201,8 +269,11 @@ ENTRY(startup_32)
24151 movl %eax, pa(max_pfn_mapped)
24152
24153 /* Do early initialization of the fixmap area */
24154- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24155- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24156+#ifdef CONFIG_COMPAT_VDSO
24157+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24158+#else
24159+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24160+#endif
24161 #else /* Not PAE */
24162
24163 page_pde_offset = (__PAGE_OFFSET >> 20);
24164@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24165 movl %eax, pa(max_pfn_mapped)
24166
24167 /* Do early initialization of the fixmap area */
24168- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24169- movl %eax,pa(initial_page_table+0xffc)
24170+#ifdef CONFIG_COMPAT_VDSO
24171+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24172+#else
24173+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24174+#endif
24175 #endif
24176
24177 #ifdef CONFIG_PARAVIRT
24178@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24179 cmpl $num_subarch_entries, %eax
24180 jae bad_subarch
24181
24182- movl pa(subarch_entries)(,%eax,4), %eax
24183- subl $__PAGE_OFFSET, %eax
24184- jmp *%eax
24185+ jmp *pa(subarch_entries)(,%eax,4)
24186
24187 bad_subarch:
24188 WEAK(lguest_entry)
24189@@ -261,10 +333,10 @@ WEAK(xen_entry)
24190 __INITDATA
24191
24192 subarch_entries:
24193- .long default_entry /* normal x86/PC */
24194- .long lguest_entry /* lguest hypervisor */
24195- .long xen_entry /* Xen hypervisor */
24196- .long default_entry /* Moorestown MID */
24197+ .long ta(default_entry) /* normal x86/PC */
24198+ .long ta(lguest_entry) /* lguest hypervisor */
24199+ .long ta(xen_entry) /* Xen hypervisor */
24200+ .long ta(default_entry) /* Moorestown MID */
24201 num_subarch_entries = (. - subarch_entries) / 4
24202 .previous
24203 #else
24204@@ -354,6 +426,7 @@ default_entry:
24205 movl pa(mmu_cr4_features),%eax
24206 movl %eax,%cr4
24207
24208+#ifdef CONFIG_X86_PAE
24209 testb $X86_CR4_PAE, %al # check if PAE is enabled
24210 jz enable_paging
24211
24212@@ -382,6 +455,9 @@ default_entry:
24213 /* Make changes effective */
24214 wrmsr
24215
24216+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24217+#endif
24218+
24219 enable_paging:
24220
24221 /*
24222@@ -449,14 +525,20 @@ is486:
24223 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24224 movl %eax,%ss # after changing gdt.
24225
24226- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24227+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24228 movl %eax,%ds
24229 movl %eax,%es
24230
24231 movl $(__KERNEL_PERCPU), %eax
24232 movl %eax,%fs # set this cpu's percpu
24233
24234+#ifdef CONFIG_CC_STACKPROTECTOR
24235 movl $(__KERNEL_STACK_CANARY),%eax
24236+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24237+ movl $(__USER_DS),%eax
24238+#else
24239+ xorl %eax,%eax
24240+#endif
24241 movl %eax,%gs
24242
24243 xorl %eax,%eax # Clear LDT
24244@@ -512,8 +594,11 @@ setup_once:
24245 * relocation. Manually set base address in stack canary
24246 * segment descriptor.
24247 */
24248- movl $gdt_page,%eax
24249+ movl $cpu_gdt_table,%eax
24250 movl $stack_canary,%ecx
24251+#ifdef CONFIG_SMP
24252+ addl $__per_cpu_load,%ecx
24253+#endif
24254 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24255 shrl $16, %ecx
24256 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24257@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24258 cmpl $2,(%esp) # X86_TRAP_NMI
24259 je is_nmi # Ignore NMI
24260
24261- cmpl $2,%ss:early_recursion_flag
24262+ cmpl $1,%ss:early_recursion_flag
24263 je hlt_loop
24264 incl %ss:early_recursion_flag
24265
24266@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24267 pushl (20+6*4)(%esp) /* trapno */
24268 pushl $fault_msg
24269 call printk
24270-#endif
24271 call dump_stack
24272+#endif
24273 hlt_loop:
24274 hlt
24275 jmp hlt_loop
24276@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24277 /* This is the default interrupt "handler" :-) */
24278 ALIGN
24279 ignore_int:
24280- cld
24281 #ifdef CONFIG_PRINTK
24282+ cmpl $2,%ss:early_recursion_flag
24283+ je hlt_loop
24284+ incl %ss:early_recursion_flag
24285+ cld
24286 pushl %eax
24287 pushl %ecx
24288 pushl %edx
24289@@ -617,9 +705,6 @@ ignore_int:
24290 movl $(__KERNEL_DS),%eax
24291 movl %eax,%ds
24292 movl %eax,%es
24293- cmpl $2,early_recursion_flag
24294- je hlt_loop
24295- incl early_recursion_flag
24296 pushl 16(%esp)
24297 pushl 24(%esp)
24298 pushl 32(%esp)
24299@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24300 /*
24301 * BSS section
24302 */
24303-__PAGE_ALIGNED_BSS
24304- .align PAGE_SIZE
24305 #ifdef CONFIG_X86_PAE
24306+.section .initial_pg_pmd,"a",@progbits
24307 initial_pg_pmd:
24308 .fill 1024*KPMDS,4,0
24309 #else
24310+.section .initial_page_table,"a",@progbits
24311 ENTRY(initial_page_table)
24312 .fill 1024,4,0
24313 #endif
24314+.section .initial_pg_fixmap,"a",@progbits
24315 initial_pg_fixmap:
24316 .fill 1024,4,0
24317+.section .empty_zero_page,"a",@progbits
24318 ENTRY(empty_zero_page)
24319 .fill 4096,1,0
24320+.section .swapper_pg_dir,"a",@progbits
24321 ENTRY(swapper_pg_dir)
24322+#ifdef CONFIG_X86_PAE
24323+ .fill 4,8,0
24324+#else
24325 .fill 1024,4,0
24326+#endif
24327
24328 /*
24329 * This starts the data section.
24330 */
24331 #ifdef CONFIG_X86_PAE
24332-__PAGE_ALIGNED_DATA
24333- /* Page-aligned for the benefit of paravirt? */
24334- .align PAGE_SIZE
24335+.section .initial_page_table,"a",@progbits
24336 ENTRY(initial_page_table)
24337 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24338 # if KPMDS == 3
24339@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24340 # error "Kernel PMDs should be 1, 2 or 3"
24341 # endif
24342 .align PAGE_SIZE /* needs to be page-sized too */
24343+
24344+#ifdef CONFIG_PAX_PER_CPU_PGD
24345+ENTRY(cpu_pgd)
24346+ .rept 2*NR_CPUS
24347+ .fill 4,8,0
24348+ .endr
24349+#endif
24350+
24351 #endif
24352
24353 .data
24354 .balign 4
24355 ENTRY(stack_start)
24356- .long init_thread_union+THREAD_SIZE
24357+ .long init_thread_union+THREAD_SIZE-8
24358
24359 __INITRODATA
24360 int_msg:
24361@@ -727,7 +825,7 @@ fault_msg:
24362 * segment size, and 32-bit linear address value:
24363 */
24364
24365- .data
24366+.section .rodata,"a",@progbits
24367 .globl boot_gdt_descr
24368 .globl idt_descr
24369
24370@@ -736,7 +834,7 @@ fault_msg:
24371 .word 0 # 32 bit align gdt_desc.address
24372 boot_gdt_descr:
24373 .word __BOOT_DS+7
24374- .long boot_gdt - __PAGE_OFFSET
24375+ .long pa(boot_gdt)
24376
24377 .word 0 # 32-bit align idt_desc.address
24378 idt_descr:
24379@@ -747,7 +845,7 @@ idt_descr:
24380 .word 0 # 32 bit align gdt_desc.address
24381 ENTRY(early_gdt_descr)
24382 .word GDT_ENTRIES*8-1
24383- .long gdt_page /* Overwritten for secondary CPUs */
24384+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24385
24386 /*
24387 * The boot_gdt must mirror the equivalent in setup.S and is
24388@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24389 .align L1_CACHE_BYTES
24390 ENTRY(boot_gdt)
24391 .fill GDT_ENTRY_BOOT_CS,8,0
24392- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24393- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24394+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24395+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24396+
24397+ .align PAGE_SIZE_asm
24398+ENTRY(cpu_gdt_table)
24399+ .rept NR_CPUS
24400+ .quad 0x0000000000000000 /* NULL descriptor */
24401+ .quad 0x0000000000000000 /* 0x0b reserved */
24402+ .quad 0x0000000000000000 /* 0x13 reserved */
24403+ .quad 0x0000000000000000 /* 0x1b reserved */
24404+
24405+#ifdef CONFIG_PAX_KERNEXEC
24406+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24407+#else
24408+ .quad 0x0000000000000000 /* 0x20 unused */
24409+#endif
24410+
24411+ .quad 0x0000000000000000 /* 0x28 unused */
24412+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24413+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24414+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24415+ .quad 0x0000000000000000 /* 0x4b reserved */
24416+ .quad 0x0000000000000000 /* 0x53 reserved */
24417+ .quad 0x0000000000000000 /* 0x5b reserved */
24418+
24419+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24420+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24421+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24422+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24423+
24424+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24425+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24426+
24427+ /*
24428+ * Segments used for calling PnP BIOS have byte granularity.
24429+ * The code segments and data segments have fixed 64k limits,
24430+ * the transfer segment sizes are set at run time.
24431+ */
24432+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24433+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24434+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24435+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24436+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24437+
24438+ /*
24439+ * The APM segments have byte granularity and their bases
24440+ * are set at run time. All have 64k limits.
24441+ */
24442+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24443+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24444+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24445+
24446+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24447+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24448+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24449+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24450+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24451+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24452+
24453+ /* Be sure this is zeroed to avoid false validations in Xen */
24454+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24455+ .endr
24456diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24457index a468c0a..c7dec74 100644
24458--- a/arch/x86/kernel/head_64.S
24459+++ b/arch/x86/kernel/head_64.S
24460@@ -20,6 +20,8 @@
24461 #include <asm/processor-flags.h>
24462 #include <asm/percpu.h>
24463 #include <asm/nops.h>
24464+#include <asm/cpufeature.h>
24465+#include <asm/alternative-asm.h>
24466
24467 #ifdef CONFIG_PARAVIRT
24468 #include <asm/asm-offsets.h>
24469@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24470 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24471 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24472 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24473+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24474+L3_VMALLOC_START = pud_index(VMALLOC_START)
24475+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24476+L3_VMALLOC_END = pud_index(VMALLOC_END)
24477+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24478+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24479
24480 .text
24481 __HEAD
24482@@ -89,11 +97,24 @@ startup_64:
24483 * Fixup the physical addresses in the page table
24484 */
24485 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24486+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24487+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24488+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24489+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24490+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24491
24492- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24493- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24494+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24495+#ifndef CONFIG_XEN
24496+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24497+#endif
24498+
24499+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24500+
24501+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24502+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24503
24504 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24505+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24506
24507 /*
24508 * Set up the identity mapping for the switchover. These
24509@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24510 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24511 1:
24512
24513- /* Enable PAE mode and PGE */
24514- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24515+ /* Enable PAE mode and PSE/PGE */
24516+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24517 movq %rcx, %cr4
24518
24519 /* Setup early boot stage 4 level pagetables. */
24520@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24521 movl $MSR_EFER, %ecx
24522 rdmsr
24523 btsl $_EFER_SCE, %eax /* Enable System Call */
24524- btl $20,%edi /* No Execute supported? */
24525+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24526 jnc 1f
24527 btsl $_EFER_NX, %eax
24528 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24529+#ifndef CONFIG_EFI
24530+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24531+#endif
24532+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24533+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24534+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24535+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24536+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24537+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24538 1: wrmsr /* Make changes effective */
24539
24540 /* Setup cr0 */
24541@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24542 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24543 * address given in m16:64.
24544 */
24545+ pax_set_fptr_mask
24546 movq initial_code(%rip),%rax
24547 pushq $0 # fake return address to stop unwinder
24548 pushq $__KERNEL_CS # set correct cs
24549@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24550 .quad INIT_PER_CPU_VAR(irq_stack_union)
24551
24552 GLOBAL(stack_start)
24553- .quad init_thread_union+THREAD_SIZE-8
24554+ .quad init_thread_union+THREAD_SIZE-16
24555 .word 0
24556 __FINITDATA
24557
24558@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24559 call dump_stack
24560 #ifdef CONFIG_KALLSYMS
24561 leaq early_idt_ripmsg(%rip),%rdi
24562- movq 40(%rsp),%rsi # %rip again
24563+ movq 88(%rsp),%rsi # %rip again
24564 call __print_symbol
24565 #endif
24566 #endif /* EARLY_PRINTK */
24567@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24568 early_recursion_flag:
24569 .long 0
24570
24571+ .section .rodata,"a",@progbits
24572 #ifdef CONFIG_EARLY_PRINTK
24573 early_idt_msg:
24574 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24575@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24576 NEXT_PAGE(early_dynamic_pgts)
24577 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24578
24579- .data
24580+ .section .rodata,"a",@progbits
24581
24582-#ifndef CONFIG_XEN
24583 NEXT_PAGE(init_level4_pgt)
24584- .fill 512,8,0
24585-#else
24586-NEXT_PAGE(init_level4_pgt)
24587- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24588 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24589 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24590+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24591+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24593+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24594+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24595+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24596 .org init_level4_pgt + L4_START_KERNEL*8, 0
24597 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24598 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24599
24600+#ifdef CONFIG_PAX_PER_CPU_PGD
24601+NEXT_PAGE(cpu_pgd)
24602+ .rept 2*NR_CPUS
24603+ .fill 512,8,0
24604+ .endr
24605+#endif
24606+
24607 NEXT_PAGE(level3_ident_pgt)
24608 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24609+#ifdef CONFIG_XEN
24610 .fill 511, 8, 0
24611+#else
24612+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24613+ .fill 510,8,0
24614+#endif
24615+
24616+NEXT_PAGE(level3_vmalloc_start_pgt)
24617+ .fill 512,8,0
24618+
24619+NEXT_PAGE(level3_vmalloc_end_pgt)
24620+ .fill 512,8,0
24621+
24622+NEXT_PAGE(level3_vmemmap_pgt)
24623+ .fill L3_VMEMMAP_START,8,0
24624+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24625+
24626 NEXT_PAGE(level2_ident_pgt)
24627- /* Since I easily can, map the first 1G.
24628+ /* Since I easily can, map the first 2G.
24629 * Don't set NX because code runs from these pages.
24630 */
24631- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24632-#endif
24633+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24634
24635 NEXT_PAGE(level3_kernel_pgt)
24636 .fill L3_START_KERNEL,8,0
24637@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24638 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24639 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24640
24641+NEXT_PAGE(level2_vmemmap_pgt)
24642+ .fill 512,8,0
24643+
24644 NEXT_PAGE(level2_kernel_pgt)
24645 /*
24646 * 512 MB kernel mapping. We spend a full page on this pagetable
24647@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24648 NEXT_PAGE(level2_fixmap_pgt)
24649 .fill 506,8,0
24650 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24651- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24652- .fill 5,8,0
24653+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24654+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24655+ .fill 4,8,0
24656
24657 NEXT_PAGE(level1_fixmap_pgt)
24658 .fill 512,8,0
24659
24660+NEXT_PAGE(level1_vsyscall_pgt)
24661+ .fill 512,8,0
24662+
24663 #undef PMDS
24664
24665- .data
24666+ .align PAGE_SIZE
24667+ENTRY(cpu_gdt_table)
24668+ .rept NR_CPUS
24669+ .quad 0x0000000000000000 /* NULL descriptor */
24670+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24671+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24672+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24673+ .quad 0x00cffb000000ffff /* __USER32_CS */
24674+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24675+ .quad 0x00affb000000ffff /* __USER_CS */
24676+
24677+#ifdef CONFIG_PAX_KERNEXEC
24678+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24679+#else
24680+ .quad 0x0 /* unused */
24681+#endif
24682+
24683+ .quad 0,0 /* TSS */
24684+ .quad 0,0 /* LDT */
24685+ .quad 0,0,0 /* three TLS descriptors */
24686+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24687+ /* asm/segment.h:GDT_ENTRIES must match this */
24688+
24689+#ifdef CONFIG_PAX_MEMORY_UDEREF
24690+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24691+#else
24692+ .quad 0x0 /* unused */
24693+#endif
24694+
24695+ /* zero the remaining page */
24696+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24697+ .endr
24698+
24699 .align 16
24700 .globl early_gdt_descr
24701 early_gdt_descr:
24702 .word GDT_ENTRIES*8-1
24703 early_gdt_descr_base:
24704- .quad INIT_PER_CPU_VAR(gdt_page)
24705+ .quad cpu_gdt_table
24706
24707 ENTRY(phys_base)
24708 /* This must match the first entry in level2_kernel_pgt */
24709 .quad 0x0000000000000000
24710
24711 #include "../../x86/xen/xen-head.S"
24712-
24713- __PAGE_ALIGNED_BSS
24714+
24715+ .section .rodata,"a",@progbits
24716 NEXT_PAGE(empty_zero_page)
24717 .skip PAGE_SIZE
24718diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24719index 05fd74f..c3548b1 100644
24720--- a/arch/x86/kernel/i386_ksyms_32.c
24721+++ b/arch/x86/kernel/i386_ksyms_32.c
24722@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24723 EXPORT_SYMBOL(cmpxchg8b_emu);
24724 #endif
24725
24726+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24727+
24728 /* Networking helper routines. */
24729 EXPORT_SYMBOL(csum_partial_copy_generic);
24730+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24731+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24732
24733 EXPORT_SYMBOL(__get_user_1);
24734 EXPORT_SYMBOL(__get_user_2);
24735@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24736 EXPORT_SYMBOL(___preempt_schedule_context);
24737 #endif
24738 #endif
24739+
24740+#ifdef CONFIG_PAX_KERNEXEC
24741+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24742+#endif
24743+
24744+#ifdef CONFIG_PAX_PER_CPU_PGD
24745+EXPORT_SYMBOL(cpu_pgd);
24746+#endif
24747diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24748index d5dd808..b6432cf 100644
24749--- a/arch/x86/kernel/i387.c
24750+++ b/arch/x86/kernel/i387.c
24751@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24752 static inline bool interrupted_user_mode(void)
24753 {
24754 struct pt_regs *regs = get_irq_regs();
24755- return regs && user_mode_vm(regs);
24756+ return regs && user_mode(regs);
24757 }
24758
24759 /*
24760diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24761index 2e977b5..5f2c273 100644
24762--- a/arch/x86/kernel/i8259.c
24763+++ b/arch/x86/kernel/i8259.c
24764@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24765 static void make_8259A_irq(unsigned int irq)
24766 {
24767 disable_irq_nosync(irq);
24768- io_apic_irqs &= ~(1<<irq);
24769+ io_apic_irqs &= ~(1UL<<irq);
24770 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24771 i8259A_chip.name);
24772 enable_irq(irq);
24773@@ -209,7 +209,7 @@ spurious_8259A_irq:
24774 "spurious 8259A interrupt: IRQ%d.\n", irq);
24775 spurious_irq_mask |= irqmask;
24776 }
24777- atomic_inc(&irq_err_count);
24778+ atomic_inc_unchecked(&irq_err_count);
24779 /*
24780 * Theoretically we do not have to handle this IRQ,
24781 * but in Linux this does not cause problems and is
24782@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24783 /* (slave's support for AEOI in flat mode is to be investigated) */
24784 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24785
24786+ pax_open_kernel();
24787 if (auto_eoi)
24788 /*
24789 * In AEOI mode we just have to mask the interrupt
24790 * when acking.
24791 */
24792- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24793+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24794 else
24795- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24796+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24797+ pax_close_kernel();
24798
24799 udelay(100); /* wait for 8259A to initialize */
24800
24801diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24802index a979b5b..1d6db75 100644
24803--- a/arch/x86/kernel/io_delay.c
24804+++ b/arch/x86/kernel/io_delay.c
24805@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24806 * Quirk table for systems that misbehave (lock up, etc.) if port
24807 * 0x80 is used:
24808 */
24809-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24810+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24811 {
24812 .callback = dmi_io_delay_0xed_port,
24813 .ident = "Compaq Presario V6000",
24814diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24815index 4ddaf66..49d5c18 100644
24816--- a/arch/x86/kernel/ioport.c
24817+++ b/arch/x86/kernel/ioport.c
24818@@ -6,6 +6,7 @@
24819 #include <linux/sched.h>
24820 #include <linux/kernel.h>
24821 #include <linux/capability.h>
24822+#include <linux/security.h>
24823 #include <linux/errno.h>
24824 #include <linux/types.h>
24825 #include <linux/ioport.h>
24826@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24827 return -EINVAL;
24828 if (turn_on && !capable(CAP_SYS_RAWIO))
24829 return -EPERM;
24830+#ifdef CONFIG_GRKERNSEC_IO
24831+ if (turn_on && grsec_disable_privio) {
24832+ gr_handle_ioperm();
24833+ return -ENODEV;
24834+ }
24835+#endif
24836
24837 /*
24838 * If it's the first ioperm() call in this thread's lifetime, set the
24839@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24840 * because the ->io_bitmap_max value must match the bitmap
24841 * contents:
24842 */
24843- tss = &per_cpu(init_tss, get_cpu());
24844+ tss = init_tss + get_cpu();
24845
24846 if (turn_on)
24847 bitmap_clear(t->io_bitmap_ptr, from, num);
24848@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24849 if (level > old) {
24850 if (!capable(CAP_SYS_RAWIO))
24851 return -EPERM;
24852+#ifdef CONFIG_GRKERNSEC_IO
24853+ if (grsec_disable_privio) {
24854+ gr_handle_iopl();
24855+ return -ENODEV;
24856+ }
24857+#endif
24858 }
24859 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24860 t->iopl = level << 12;
24861diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24862index 22d0687..e07b2a5 100644
24863--- a/arch/x86/kernel/irq.c
24864+++ b/arch/x86/kernel/irq.c
24865@@ -21,7 +21,7 @@
24866 #define CREATE_TRACE_POINTS
24867 #include <asm/trace/irq_vectors.h>
24868
24869-atomic_t irq_err_count;
24870+atomic_unchecked_t irq_err_count;
24871
24872 /* Function pointer for generic interrupt vector handling */
24873 void (*x86_platform_ipi_callback)(void) = NULL;
24874@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24875 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24876 seq_printf(p, " Machine check polls\n");
24877 #endif
24878- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24879+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24880 #if defined(CONFIG_X86_IO_APIC)
24881- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24882+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24883 #endif
24884 return 0;
24885 }
24886@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24887
24888 u64 arch_irq_stat(void)
24889 {
24890- u64 sum = atomic_read(&irq_err_count);
24891+ u64 sum = atomic_read_unchecked(&irq_err_count);
24892 return sum;
24893 }
24894
24895diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24896index d7fcbed..1f747f7 100644
24897--- a/arch/x86/kernel/irq_32.c
24898+++ b/arch/x86/kernel/irq_32.c
24899@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24900 __asm__ __volatile__("andl %%esp,%0" :
24901 "=r" (sp) : "0" (THREAD_SIZE - 1));
24902
24903- return sp < (sizeof(struct thread_info) + STACK_WARN);
24904+ return sp < STACK_WARN;
24905 }
24906
24907 static void print_stack_overflow(void)
24908@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24909 * per-CPU IRQ handling contexts (thread information and stack)
24910 */
24911 union irq_ctx {
24912- struct thread_info tinfo;
24913- u32 stack[THREAD_SIZE/sizeof(u32)];
24914+ unsigned long previous_esp;
24915+ u32 stack[THREAD_SIZE/sizeof(u32)];
24916 } __attribute__((aligned(THREAD_SIZE)));
24917
24918 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24919@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24920 static inline int
24921 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24922 {
24923- union irq_ctx *curctx, *irqctx;
24924+ union irq_ctx *irqctx;
24925 u32 *isp, arg1, arg2;
24926
24927- curctx = (union irq_ctx *) current_thread_info();
24928 irqctx = __this_cpu_read(hardirq_ctx);
24929
24930 /*
24931@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24932 * handler) we can't do that and just have to keep using the
24933 * current stack (which is the irq stack already after all)
24934 */
24935- if (unlikely(curctx == irqctx))
24936+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24937 return 0;
24938
24939 /* build the stack frame on the IRQ stack */
24940- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24941- irqctx->tinfo.task = curctx->tinfo.task;
24942- irqctx->tinfo.previous_esp = current_stack_pointer;
24943+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24944+ irqctx->previous_esp = current_stack_pointer;
24945+
24946+#ifdef CONFIG_PAX_MEMORY_UDEREF
24947+ __set_fs(MAKE_MM_SEG(0));
24948+#endif
24949
24950 if (unlikely(overflow))
24951 call_on_stack(print_stack_overflow, isp);
24952@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24953 : "0" (irq), "1" (desc), "2" (isp),
24954 "D" (desc->handle_irq)
24955 : "memory", "cc", "ecx");
24956+
24957+#ifdef CONFIG_PAX_MEMORY_UDEREF
24958+ __set_fs(current_thread_info()->addr_limit);
24959+#endif
24960+
24961 return 1;
24962 }
24963
24964@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24965 */
24966 void irq_ctx_init(int cpu)
24967 {
24968- union irq_ctx *irqctx;
24969-
24970 if (per_cpu(hardirq_ctx, cpu))
24971 return;
24972
24973- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24974- THREADINFO_GFP,
24975- THREAD_SIZE_ORDER));
24976- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24977- irqctx->tinfo.cpu = cpu;
24978- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24979-
24980- per_cpu(hardirq_ctx, cpu) = irqctx;
24981-
24982- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24983- THREADINFO_GFP,
24984- THREAD_SIZE_ORDER));
24985- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24986- irqctx->tinfo.cpu = cpu;
24987- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24988-
24989- per_cpu(softirq_ctx, cpu) = irqctx;
24990-
24991- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24992- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24993+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24994+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24995 }
24996
24997 void do_softirq_own_stack(void)
24998 {
24999- struct thread_info *curctx;
25000 union irq_ctx *irqctx;
25001 u32 *isp;
25002
25003- curctx = current_thread_info();
25004 irqctx = __this_cpu_read(softirq_ctx);
25005- irqctx->tinfo.task = curctx->task;
25006- irqctx->tinfo.previous_esp = current_stack_pointer;
25007+ irqctx->previous_esp = current_stack_pointer;
25008
25009 /* build the stack frame on the softirq stack */
25010- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25011+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25012+
25013+#ifdef CONFIG_PAX_MEMORY_UDEREF
25014+ __set_fs(MAKE_MM_SEG(0));
25015+#endif
25016
25017 call_on_stack(__do_softirq, isp);
25018+
25019+#ifdef CONFIG_PAX_MEMORY_UDEREF
25020+ __set_fs(current_thread_info()->addr_limit);
25021+#endif
25022+
25023 }
25024
25025 bool handle_irq(unsigned irq, struct pt_regs *regs)
25026@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25027 if (unlikely(!desc))
25028 return false;
25029
25030- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25031+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25032 if (unlikely(overflow))
25033 print_stack_overflow();
25034 desc->handle_irq(irq, desc);
25035diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25036index 4d1c746..232961d 100644
25037--- a/arch/x86/kernel/irq_64.c
25038+++ b/arch/x86/kernel/irq_64.c
25039@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25040 u64 estack_top, estack_bottom;
25041 u64 curbase = (u64)task_stack_page(current);
25042
25043- if (user_mode_vm(regs))
25044+ if (user_mode(regs))
25045 return;
25046
25047 if (regs->sp >= curbase + sizeof(struct thread_info) +
25048diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25049index 26d5a55..a01160a 100644
25050--- a/arch/x86/kernel/jump_label.c
25051+++ b/arch/x86/kernel/jump_label.c
25052@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25053 * Jump label is enabled for the first time.
25054 * So we expect a default_nop...
25055 */
25056- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25057+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25058 != 0))
25059 bug_at((void *)entry->code, __LINE__);
25060 } else {
25061@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25062 * ...otherwise expect an ideal_nop. Otherwise
25063 * something went horribly wrong.
25064 */
25065- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25066+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25067 != 0))
25068 bug_at((void *)entry->code, __LINE__);
25069 }
25070@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25071 * are converting the default nop to the ideal nop.
25072 */
25073 if (init) {
25074- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25075+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25076 bug_at((void *)entry->code, __LINE__);
25077 } else {
25078 code.jump = 0xe9;
25079 code.offset = entry->target -
25080 (entry->code + JUMP_LABEL_NOP_SIZE);
25081- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25082+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25083 bug_at((void *)entry->code, __LINE__);
25084 }
25085 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25086diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25087index 836f832..a8bda67 100644
25088--- a/arch/x86/kernel/kgdb.c
25089+++ b/arch/x86/kernel/kgdb.c
25090@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25091 #ifdef CONFIG_X86_32
25092 switch (regno) {
25093 case GDB_SS:
25094- if (!user_mode_vm(regs))
25095+ if (!user_mode(regs))
25096 *(unsigned long *)mem = __KERNEL_DS;
25097 break;
25098 case GDB_SP:
25099- if (!user_mode_vm(regs))
25100+ if (!user_mode(regs))
25101 *(unsigned long *)mem = kernel_stack_pointer(regs);
25102 break;
25103 case GDB_GS:
25104@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25105 bp->attr.bp_addr = breakinfo[breakno].addr;
25106 bp->attr.bp_len = breakinfo[breakno].len;
25107 bp->attr.bp_type = breakinfo[breakno].type;
25108- info->address = breakinfo[breakno].addr;
25109+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25110+ info->address = ktla_ktva(breakinfo[breakno].addr);
25111+ else
25112+ info->address = breakinfo[breakno].addr;
25113 info->len = breakinfo[breakno].len;
25114 info->type = breakinfo[breakno].type;
25115 val = arch_install_hw_breakpoint(bp);
25116@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25117 case 'k':
25118 /* clear the trace bit */
25119 linux_regs->flags &= ~X86_EFLAGS_TF;
25120- atomic_set(&kgdb_cpu_doing_single_step, -1);
25121+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25122
25123 /* set the trace bit if we're stepping */
25124 if (remcomInBuffer[0] == 's') {
25125 linux_regs->flags |= X86_EFLAGS_TF;
25126- atomic_set(&kgdb_cpu_doing_single_step,
25127+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25128 raw_smp_processor_id());
25129 }
25130
25131@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25132
25133 switch (cmd) {
25134 case DIE_DEBUG:
25135- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25136+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25137 if (user_mode(regs))
25138 return single_step_cont(regs, args);
25139 break;
25140@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25141 #endif /* CONFIG_DEBUG_RODATA */
25142
25143 bpt->type = BP_BREAKPOINT;
25144- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25145+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25146 BREAK_INSTR_SIZE);
25147 if (err)
25148 return err;
25149- err = probe_kernel_write((char *)bpt->bpt_addr,
25150+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25151 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25152 #ifdef CONFIG_DEBUG_RODATA
25153 if (!err)
25154@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25155 return -EBUSY;
25156 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25157 BREAK_INSTR_SIZE);
25158- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25159+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25160 if (err)
25161 return err;
25162 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25163@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25164 if (mutex_is_locked(&text_mutex))
25165 goto knl_write;
25166 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25167- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25168+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25169 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25170 goto knl_write;
25171 return err;
25172 knl_write:
25173 #endif /* CONFIG_DEBUG_RODATA */
25174- return probe_kernel_write((char *)bpt->bpt_addr,
25175+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25176 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25177 }
25178
25179diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25180index 79a3f96..6ba030a 100644
25181--- a/arch/x86/kernel/kprobes/core.c
25182+++ b/arch/x86/kernel/kprobes/core.c
25183@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25184 s32 raddr;
25185 } __packed *insn;
25186
25187- insn = (struct __arch_relative_insn *)from;
25188+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25189+
25190+ pax_open_kernel();
25191 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25192 insn->op = op;
25193+ pax_close_kernel();
25194 }
25195
25196 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25197@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25198 kprobe_opcode_t opcode;
25199 kprobe_opcode_t *orig_opcodes = opcodes;
25200
25201- if (search_exception_tables((unsigned long)opcodes))
25202+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25203 return 0; /* Page fault may occur on this address. */
25204
25205 retry:
25206@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25207 * for the first byte, we can recover the original instruction
25208 * from it and kp->opcode.
25209 */
25210- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25211+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25212 buf[0] = kp->opcode;
25213- return (unsigned long)buf;
25214+ return ktva_ktla((unsigned long)buf);
25215 }
25216
25217 /*
25218@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25219 /* Another subsystem puts a breakpoint, failed to recover */
25220 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25221 return 0;
25222+ pax_open_kernel();
25223 memcpy(dest, insn.kaddr, insn.length);
25224+ pax_close_kernel();
25225
25226 #ifdef CONFIG_X86_64
25227 if (insn_rip_relative(&insn)) {
25228@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25229 return 0;
25230 }
25231 disp = (u8 *) dest + insn_offset_displacement(&insn);
25232+ pax_open_kernel();
25233 *(s32 *) disp = (s32) newdisp;
25234+ pax_close_kernel();
25235 }
25236 #endif
25237 return insn.length;
25238@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25239 * nor set current_kprobe, because it doesn't use single
25240 * stepping.
25241 */
25242- regs->ip = (unsigned long)p->ainsn.insn;
25243+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25244 preempt_enable_no_resched();
25245 return;
25246 }
25247@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25248 regs->flags &= ~X86_EFLAGS_IF;
25249 /* single step inline if the instruction is an int3 */
25250 if (p->opcode == BREAKPOINT_INSTRUCTION)
25251- regs->ip = (unsigned long)p->addr;
25252+ regs->ip = ktla_ktva((unsigned long)p->addr);
25253 else
25254- regs->ip = (unsigned long)p->ainsn.insn;
25255+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25256 }
25257
25258 /*
25259@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25260 setup_singlestep(p, regs, kcb, 0);
25261 return 1;
25262 }
25263- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25264+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25265 /*
25266 * The breakpoint instruction was removed right
25267 * after we hit it. Another cpu has removed
25268@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25269 " movq %rax, 152(%rsp)\n"
25270 RESTORE_REGS_STRING
25271 " popfq\n"
25272+#ifdef KERNEXEC_PLUGIN
25273+ " btsq $63,(%rsp)\n"
25274+#endif
25275 #else
25276 " pushf\n"
25277 SAVE_REGS_STRING
25278@@ -779,7 +789,7 @@ static void __kprobes
25279 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25280 {
25281 unsigned long *tos = stack_addr(regs);
25282- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25283+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25284 unsigned long orig_ip = (unsigned long)p->addr;
25285 kprobe_opcode_t *insn = p->ainsn.insn;
25286
25287@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25288 struct die_args *args = data;
25289 int ret = NOTIFY_DONE;
25290
25291- if (args->regs && user_mode_vm(args->regs))
25292+ if (args->regs && user_mode(args->regs))
25293 return ret;
25294
25295 switch (val) {
25296diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25297index 898160b..758cde8 100644
25298--- a/arch/x86/kernel/kprobes/opt.c
25299+++ b/arch/x86/kernel/kprobes/opt.c
25300@@ -79,6 +79,7 @@ found:
25301 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25302 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25303 {
25304+ pax_open_kernel();
25305 #ifdef CONFIG_X86_64
25306 *addr++ = 0x48;
25307 *addr++ = 0xbf;
25308@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25309 *addr++ = 0xb8;
25310 #endif
25311 *(unsigned long *)addr = val;
25312+ pax_close_kernel();
25313 }
25314
25315 asm (
25316@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25317 * Verify if the address gap is in 2GB range, because this uses
25318 * a relative jump.
25319 */
25320- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25321+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25322 if (abs(rel) > 0x7fffffff)
25323 return -ERANGE;
25324
25325@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25326 op->optinsn.size = ret;
25327
25328 /* Copy arch-dep-instance from template */
25329- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25330+ pax_open_kernel();
25331+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25332+ pax_close_kernel();
25333
25334 /* Set probe information */
25335 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25336
25337 /* Set probe function call */
25338- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25339+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25340
25341 /* Set returning jmp instruction at the tail of out-of-line buffer */
25342- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25343+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25344 (u8 *)op->kp.addr + op->optinsn.size);
25345
25346 flush_icache_range((unsigned long) buf,
25347@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25348 WARN_ON(kprobe_disabled(&op->kp));
25349
25350 /* Backup instructions which will be replaced by jump address */
25351- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25352+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25353 RELATIVE_ADDR_SIZE);
25354
25355 insn_buf[0] = RELATIVEJUMP_OPCODE;
25356@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25357 /* This kprobe is really able to run optimized path. */
25358 op = container_of(p, struct optimized_kprobe, kp);
25359 /* Detour through copied instructions */
25360- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25361+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25362 if (!reenter)
25363 reset_current_kprobe();
25364 preempt_enable_no_resched();
25365diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25366index ebc9873..1b9724b 100644
25367--- a/arch/x86/kernel/ldt.c
25368+++ b/arch/x86/kernel/ldt.c
25369@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25370 if (reload) {
25371 #ifdef CONFIG_SMP
25372 preempt_disable();
25373- load_LDT(pc);
25374+ load_LDT_nolock(pc);
25375 if (!cpumask_equal(mm_cpumask(current->mm),
25376 cpumask_of(smp_processor_id())))
25377 smp_call_function(flush_ldt, current->mm, 1);
25378 preempt_enable();
25379 #else
25380- load_LDT(pc);
25381+ load_LDT_nolock(pc);
25382 #endif
25383 }
25384 if (oldsize) {
25385@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25386 return err;
25387
25388 for (i = 0; i < old->size; i++)
25389- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25390+ write_ldt_entry(new->ldt, i, old->ldt + i);
25391 return 0;
25392 }
25393
25394@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25395 retval = copy_ldt(&mm->context, &old_mm->context);
25396 mutex_unlock(&old_mm->context.lock);
25397 }
25398+
25399+ if (tsk == current) {
25400+ mm->context.vdso = 0;
25401+
25402+#ifdef CONFIG_X86_32
25403+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25404+ mm->context.user_cs_base = 0UL;
25405+ mm->context.user_cs_limit = ~0UL;
25406+
25407+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25408+ cpus_clear(mm->context.cpu_user_cs_mask);
25409+#endif
25410+
25411+#endif
25412+#endif
25413+
25414+ }
25415+
25416 return retval;
25417 }
25418
25419@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25420 }
25421 }
25422
25423+#ifdef CONFIG_PAX_SEGMEXEC
25424+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25425+ error = -EINVAL;
25426+ goto out_unlock;
25427+ }
25428+#endif
25429+
25430 fill_ldt(&ldt, &ldt_info);
25431 if (oldmode)
25432 ldt.avl = 0;
25433diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25434index 5b19e4d..6476a76 100644
25435--- a/arch/x86/kernel/machine_kexec_32.c
25436+++ b/arch/x86/kernel/machine_kexec_32.c
25437@@ -26,7 +26,7 @@
25438 #include <asm/cacheflush.h>
25439 #include <asm/debugreg.h>
25440
25441-static void set_idt(void *newidt, __u16 limit)
25442+static void set_idt(struct desc_struct *newidt, __u16 limit)
25443 {
25444 struct desc_ptr curidt;
25445
25446@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25447 }
25448
25449
25450-static void set_gdt(void *newgdt, __u16 limit)
25451+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25452 {
25453 struct desc_ptr curgdt;
25454
25455@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25456 }
25457
25458 control_page = page_address(image->control_code_page);
25459- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25460+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25461
25462 relocate_kernel_ptr = control_page;
25463 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25464diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25465index 15c9876..0a43909 100644
25466--- a/arch/x86/kernel/microcode_core.c
25467+++ b/arch/x86/kernel/microcode_core.c
25468@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25469 return NOTIFY_OK;
25470 }
25471
25472-static struct notifier_block __refdata mc_cpu_notifier = {
25473+static struct notifier_block mc_cpu_notifier = {
25474 .notifier_call = mc_cpu_callback,
25475 };
25476
25477diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25478index 5fb2ceb..3ae90bb 100644
25479--- a/arch/x86/kernel/microcode_intel.c
25480+++ b/arch/x86/kernel/microcode_intel.c
25481@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25482
25483 static int get_ucode_user(void *to, const void *from, size_t n)
25484 {
25485- return copy_from_user(to, from, n);
25486+ return copy_from_user(to, (const void __force_user *)from, n);
25487 }
25488
25489 static enum ucode_state
25490 request_microcode_user(int cpu, const void __user *buf, size_t size)
25491 {
25492- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25493+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25494 }
25495
25496 static void microcode_fini_cpu(int cpu)
25497diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25498index 18be189..4a9fe40 100644
25499--- a/arch/x86/kernel/module.c
25500+++ b/arch/x86/kernel/module.c
25501@@ -43,15 +43,60 @@ do { \
25502 } while (0)
25503 #endif
25504
25505-void *module_alloc(unsigned long size)
25506+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25507 {
25508- if (PAGE_ALIGN(size) > MODULES_LEN)
25509+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25510 return NULL;
25511 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25512- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25513+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25514 NUMA_NO_NODE, __builtin_return_address(0));
25515 }
25516
25517+void *module_alloc(unsigned long size)
25518+{
25519+
25520+#ifdef CONFIG_PAX_KERNEXEC
25521+ return __module_alloc(size, PAGE_KERNEL);
25522+#else
25523+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25524+#endif
25525+
25526+}
25527+
25528+#ifdef CONFIG_PAX_KERNEXEC
25529+#ifdef CONFIG_X86_32
25530+void *module_alloc_exec(unsigned long size)
25531+{
25532+ struct vm_struct *area;
25533+
25534+ if (size == 0)
25535+ return NULL;
25536+
25537+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25538+ return area ? area->addr : NULL;
25539+}
25540+EXPORT_SYMBOL(module_alloc_exec);
25541+
25542+void module_free_exec(struct module *mod, void *module_region)
25543+{
25544+ vunmap(module_region);
25545+}
25546+EXPORT_SYMBOL(module_free_exec);
25547+#else
25548+void module_free_exec(struct module *mod, void *module_region)
25549+{
25550+ module_free(mod, module_region);
25551+}
25552+EXPORT_SYMBOL(module_free_exec);
25553+
25554+void *module_alloc_exec(unsigned long size)
25555+{
25556+ return __module_alloc(size, PAGE_KERNEL_RX);
25557+}
25558+EXPORT_SYMBOL(module_alloc_exec);
25559+#endif
25560+#endif
25561+
25562 #ifdef CONFIG_X86_32
25563 int apply_relocate(Elf32_Shdr *sechdrs,
25564 const char *strtab,
25565@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25566 unsigned int i;
25567 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25568 Elf32_Sym *sym;
25569- uint32_t *location;
25570+ uint32_t *plocation, location;
25571
25572 DEBUGP("Applying relocate section %u to %u\n",
25573 relsec, sechdrs[relsec].sh_info);
25574 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25575 /* This is where to make the change */
25576- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25577- + rel[i].r_offset;
25578+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25579+ location = (uint32_t)plocation;
25580+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25581+ plocation = ktla_ktva((void *)plocation);
25582 /* This is the symbol it is referring to. Note that all
25583 undefined symbols have been resolved. */
25584 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25585@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25586 switch (ELF32_R_TYPE(rel[i].r_info)) {
25587 case R_386_32:
25588 /* We add the value into the location given */
25589- *location += sym->st_value;
25590+ pax_open_kernel();
25591+ *plocation += sym->st_value;
25592+ pax_close_kernel();
25593 break;
25594 case R_386_PC32:
25595 /* Add the value, subtract its position */
25596- *location += sym->st_value - (uint32_t)location;
25597+ pax_open_kernel();
25598+ *plocation += sym->st_value - location;
25599+ pax_close_kernel();
25600 break;
25601 default:
25602 pr_err("%s: Unknown relocation: %u\n",
25603@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25604 case R_X86_64_NONE:
25605 break;
25606 case R_X86_64_64:
25607+ pax_open_kernel();
25608 *(u64 *)loc = val;
25609+ pax_close_kernel();
25610 break;
25611 case R_X86_64_32:
25612+ pax_open_kernel();
25613 *(u32 *)loc = val;
25614+ pax_close_kernel();
25615 if (val != *(u32 *)loc)
25616 goto overflow;
25617 break;
25618 case R_X86_64_32S:
25619+ pax_open_kernel();
25620 *(s32 *)loc = val;
25621+ pax_close_kernel();
25622 if ((s64)val != *(s32 *)loc)
25623 goto overflow;
25624 break;
25625 case R_X86_64_PC32:
25626 val -= (u64)loc;
25627+ pax_open_kernel();
25628 *(u32 *)loc = val;
25629+ pax_close_kernel();
25630+
25631 #if 0
25632 if ((s64)val != *(s32 *)loc)
25633 goto overflow;
25634diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25635index 05266b5..3432443 100644
25636--- a/arch/x86/kernel/msr.c
25637+++ b/arch/x86/kernel/msr.c
25638@@ -37,6 +37,7 @@
25639 #include <linux/notifier.h>
25640 #include <linux/uaccess.h>
25641 #include <linux/gfp.h>
25642+#include <linux/grsecurity.h>
25643
25644 #include <asm/processor.h>
25645 #include <asm/msr.h>
25646@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25647 int err = 0;
25648 ssize_t bytes = 0;
25649
25650+#ifdef CONFIG_GRKERNSEC_KMEM
25651+ gr_handle_msr_write();
25652+ return -EPERM;
25653+#endif
25654+
25655 if (count % 8)
25656 return -EINVAL; /* Invalid chunk size */
25657
25658@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25659 err = -EBADF;
25660 break;
25661 }
25662+#ifdef CONFIG_GRKERNSEC_KMEM
25663+ gr_handle_msr_write();
25664+ return -EPERM;
25665+#endif
25666 if (copy_from_user(&regs, uregs, sizeof regs)) {
25667 err = -EFAULT;
25668 break;
25669@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25670 return notifier_from_errno(err);
25671 }
25672
25673-static struct notifier_block __refdata msr_class_cpu_notifier = {
25674+static struct notifier_block msr_class_cpu_notifier = {
25675 .notifier_call = msr_class_cpu_callback,
25676 };
25677
25678diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25679index 6fcb49c..5b3f4ff 100644
25680--- a/arch/x86/kernel/nmi.c
25681+++ b/arch/x86/kernel/nmi.c
25682@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25683 return handled;
25684 }
25685
25686-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25687+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25688 {
25689 struct nmi_desc *desc = nmi_to_desc(type);
25690 unsigned long flags;
25691@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25692 * event confuses some handlers (kdump uses this flag)
25693 */
25694 if (action->flags & NMI_FLAG_FIRST)
25695- list_add_rcu(&action->list, &desc->head);
25696+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25697 else
25698- list_add_tail_rcu(&action->list, &desc->head);
25699+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25700
25701 spin_unlock_irqrestore(&desc->lock, flags);
25702 return 0;
25703@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25704 if (!strcmp(n->name, name)) {
25705 WARN(in_nmi(),
25706 "Trying to free NMI (%s) from NMI context!\n", n->name);
25707- list_del_rcu(&n->list);
25708+ pax_list_del_rcu((struct list_head *)&n->list);
25709 break;
25710 }
25711 }
25712@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25713 dotraplinkage notrace __kprobes void
25714 do_nmi(struct pt_regs *regs, long error_code)
25715 {
25716+
25717+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25718+ if (!user_mode(regs)) {
25719+ unsigned long cs = regs->cs & 0xFFFF;
25720+ unsigned long ip = ktva_ktla(regs->ip);
25721+
25722+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25723+ regs->ip = ip;
25724+ }
25725+#endif
25726+
25727 nmi_nesting_preprocess(regs);
25728
25729 nmi_enter();
25730diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25731index 6d9582e..f746287 100644
25732--- a/arch/x86/kernel/nmi_selftest.c
25733+++ b/arch/x86/kernel/nmi_selftest.c
25734@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25735 {
25736 /* trap all the unknown NMIs we may generate */
25737 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25738- __initdata);
25739+ __initconst);
25740 }
25741
25742 static void __init cleanup_nmi_testsuite(void)
25743@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25744 unsigned long timeout;
25745
25746 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25747- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25748+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25749 nmi_fail = FAILURE;
25750 return;
25751 }
25752diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25753index bbb6c73..24a58ef 100644
25754--- a/arch/x86/kernel/paravirt-spinlocks.c
25755+++ b/arch/x86/kernel/paravirt-spinlocks.c
25756@@ -8,7 +8,7 @@
25757
25758 #include <asm/paravirt.h>
25759
25760-struct pv_lock_ops pv_lock_ops = {
25761+struct pv_lock_ops pv_lock_ops __read_only = {
25762 #ifdef CONFIG_SMP
25763 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25764 .unlock_kick = paravirt_nop,
25765diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25766index 1b10af8..0b58cbc 100644
25767--- a/arch/x86/kernel/paravirt.c
25768+++ b/arch/x86/kernel/paravirt.c
25769@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25770 {
25771 return x;
25772 }
25773+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25774+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25775+#endif
25776
25777 void __init default_banner(void)
25778 {
25779@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25780 if (opfunc == NULL)
25781 /* If there's no function, patch it with a ud2a (BUG) */
25782 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25783- else if (opfunc == _paravirt_nop)
25784+ else if (opfunc == (void *)_paravirt_nop)
25785 /* If the operation is a nop, then nop the callsite */
25786 ret = paravirt_patch_nop();
25787
25788 /* identity functions just return their single argument */
25789- else if (opfunc == _paravirt_ident_32)
25790+ else if (opfunc == (void *)_paravirt_ident_32)
25791 ret = paravirt_patch_ident_32(insnbuf, len);
25792- else if (opfunc == _paravirt_ident_64)
25793+ else if (opfunc == (void *)_paravirt_ident_64)
25794 ret = paravirt_patch_ident_64(insnbuf, len);
25795+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25796+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25797+ ret = paravirt_patch_ident_64(insnbuf, len);
25798+#endif
25799
25800 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25801 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25802@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25803 if (insn_len > len || start == NULL)
25804 insn_len = len;
25805 else
25806- memcpy(insnbuf, start, insn_len);
25807+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25808
25809 return insn_len;
25810 }
25811@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25812 return this_cpu_read(paravirt_lazy_mode);
25813 }
25814
25815-struct pv_info pv_info = {
25816+struct pv_info pv_info __read_only = {
25817 .name = "bare hardware",
25818 .paravirt_enabled = 0,
25819 .kernel_rpl = 0,
25820@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25821 #endif
25822 };
25823
25824-struct pv_init_ops pv_init_ops = {
25825+struct pv_init_ops pv_init_ops __read_only = {
25826 .patch = native_patch,
25827 };
25828
25829-struct pv_time_ops pv_time_ops = {
25830+struct pv_time_ops pv_time_ops __read_only = {
25831 .sched_clock = native_sched_clock,
25832 .steal_clock = native_steal_clock,
25833 };
25834
25835-__visible struct pv_irq_ops pv_irq_ops = {
25836+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25837 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25838 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25839 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25840@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25841 #endif
25842 };
25843
25844-__visible struct pv_cpu_ops pv_cpu_ops = {
25845+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25846 .cpuid = native_cpuid,
25847 .get_debugreg = native_get_debugreg,
25848 .set_debugreg = native_set_debugreg,
25849@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25850 .end_context_switch = paravirt_nop,
25851 };
25852
25853-struct pv_apic_ops pv_apic_ops = {
25854+struct pv_apic_ops pv_apic_ops __read_only= {
25855 #ifdef CONFIG_X86_LOCAL_APIC
25856 .startup_ipi_hook = paravirt_nop,
25857 #endif
25858 };
25859
25860-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25861+#ifdef CONFIG_X86_32
25862+#ifdef CONFIG_X86_PAE
25863+/* 64-bit pagetable entries */
25864+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25865+#else
25866 /* 32-bit pagetable entries */
25867 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25868+#endif
25869 #else
25870 /* 64-bit pagetable entries */
25871 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25872 #endif
25873
25874-struct pv_mmu_ops pv_mmu_ops = {
25875+struct pv_mmu_ops pv_mmu_ops __read_only = {
25876
25877 .read_cr2 = native_read_cr2,
25878 .write_cr2 = native_write_cr2,
25879@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25880 .make_pud = PTE_IDENT,
25881
25882 .set_pgd = native_set_pgd,
25883+ .set_pgd_batched = native_set_pgd_batched,
25884 #endif
25885 #endif /* PAGETABLE_LEVELS >= 3 */
25886
25887@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25888 },
25889
25890 .set_fixmap = native_set_fixmap,
25891+
25892+#ifdef CONFIG_PAX_KERNEXEC
25893+ .pax_open_kernel = native_pax_open_kernel,
25894+ .pax_close_kernel = native_pax_close_kernel,
25895+#endif
25896+
25897 };
25898
25899 EXPORT_SYMBOL_GPL(pv_time_ops);
25900diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25901index 299d493..2ccb0ee 100644
25902--- a/arch/x86/kernel/pci-calgary_64.c
25903+++ b/arch/x86/kernel/pci-calgary_64.c
25904@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25905 tce_space = be64_to_cpu(readq(target));
25906 tce_space = tce_space & TAR_SW_BITS;
25907
25908- tce_space = tce_space & (~specified_table_size);
25909+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25910 info->tce_space = (u64 *)__va(tce_space);
25911 }
25912 }
25913diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25914index 35ccf75..7a15747 100644
25915--- a/arch/x86/kernel/pci-iommu_table.c
25916+++ b/arch/x86/kernel/pci-iommu_table.c
25917@@ -2,7 +2,7 @@
25918 #include <asm/iommu_table.h>
25919 #include <linux/string.h>
25920 #include <linux/kallsyms.h>
25921-
25922+#include <linux/sched.h>
25923
25924 #define DEBUG 1
25925
25926diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25927index 6c483ba..d10ce2f 100644
25928--- a/arch/x86/kernel/pci-swiotlb.c
25929+++ b/arch/x86/kernel/pci-swiotlb.c
25930@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25931 void *vaddr, dma_addr_t dma_addr,
25932 struct dma_attrs *attrs)
25933 {
25934- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25935+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25936 }
25937
25938 static struct dma_map_ops swiotlb_dma_ops = {
25939diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25940index ca7f0d5..8996469 100644
25941--- a/arch/x86/kernel/preempt.S
25942+++ b/arch/x86/kernel/preempt.S
25943@@ -3,12 +3,14 @@
25944 #include <asm/dwarf2.h>
25945 #include <asm/asm.h>
25946 #include <asm/calling.h>
25947+#include <asm/alternative-asm.h>
25948
25949 ENTRY(___preempt_schedule)
25950 CFI_STARTPROC
25951 SAVE_ALL
25952 call preempt_schedule
25953 RESTORE_ALL
25954+ pax_force_retaddr
25955 ret
25956 CFI_ENDPROC
25957
25958@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25959 SAVE_ALL
25960 call preempt_schedule_context
25961 RESTORE_ALL
25962+ pax_force_retaddr
25963 ret
25964 CFI_ENDPROC
25965
25966diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25967index 3fb8d95..254dc51 100644
25968--- a/arch/x86/kernel/process.c
25969+++ b/arch/x86/kernel/process.c
25970@@ -36,7 +36,8 @@
25971 * section. Since TSS's are completely CPU-local, we want them
25972 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25973 */
25974-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25975+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25976+EXPORT_SYMBOL(init_tss);
25977
25978 #ifdef CONFIG_X86_64
25979 static DEFINE_PER_CPU(unsigned char, is_idle);
25980@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25981 task_xstate_cachep =
25982 kmem_cache_create("task_xstate", xstate_size,
25983 __alignof__(union thread_xstate),
25984- SLAB_PANIC | SLAB_NOTRACK, NULL);
25985+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25986 }
25987
25988 /*
25989@@ -105,7 +106,7 @@ void exit_thread(void)
25990 unsigned long *bp = t->io_bitmap_ptr;
25991
25992 if (bp) {
25993- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25994+ struct tss_struct *tss = init_tss + get_cpu();
25995
25996 t->io_bitmap_ptr = NULL;
25997 clear_thread_flag(TIF_IO_BITMAP);
25998@@ -125,6 +126,9 @@ void flush_thread(void)
25999 {
26000 struct task_struct *tsk = current;
26001
26002+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26003+ loadsegment(gs, 0);
26004+#endif
26005 flush_ptrace_hw_breakpoint(tsk);
26006 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26007 drop_init_fpu(tsk);
26008@@ -271,7 +275,7 @@ static void __exit_idle(void)
26009 void exit_idle(void)
26010 {
26011 /* idle loop has pid 0 */
26012- if (current->pid)
26013+ if (task_pid_nr(current))
26014 return;
26015 __exit_idle();
26016 }
26017@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26018 return ret;
26019 }
26020 #endif
26021-void stop_this_cpu(void *dummy)
26022+__noreturn void stop_this_cpu(void *dummy)
26023 {
26024 local_irq_disable();
26025 /*
26026@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26027 }
26028 early_param("idle", idle_setup);
26029
26030-unsigned long arch_align_stack(unsigned long sp)
26031+#ifdef CONFIG_PAX_RANDKSTACK
26032+void pax_randomize_kstack(struct pt_regs *regs)
26033 {
26034- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26035- sp -= get_random_int() % 8192;
26036- return sp & ~0xf;
26037-}
26038+ struct thread_struct *thread = &current->thread;
26039+ unsigned long time;
26040
26041-unsigned long arch_randomize_brk(struct mm_struct *mm)
26042-{
26043- unsigned long range_end = mm->brk + 0x02000000;
26044- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26045-}
26046+ if (!randomize_va_space)
26047+ return;
26048+
26049+ if (v8086_mode(regs))
26050+ return;
26051
26052+ rdtscl(time);
26053+
26054+ /* P4 seems to return a 0 LSB, ignore it */
26055+#ifdef CONFIG_MPENTIUM4
26056+ time &= 0x3EUL;
26057+ time <<= 2;
26058+#elif defined(CONFIG_X86_64)
26059+ time &= 0xFUL;
26060+ time <<= 4;
26061+#else
26062+ time &= 0x1FUL;
26063+ time <<= 3;
26064+#endif
26065+
26066+ thread->sp0 ^= time;
26067+ load_sp0(init_tss + smp_processor_id(), thread);
26068+
26069+#ifdef CONFIG_X86_64
26070+ this_cpu_write(kernel_stack, thread->sp0);
26071+#endif
26072+}
26073+#endif
26074diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26075index 6f1236c..fd448d4 100644
26076--- a/arch/x86/kernel/process_32.c
26077+++ b/arch/x86/kernel/process_32.c
26078@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26079 unsigned long thread_saved_pc(struct task_struct *tsk)
26080 {
26081 return ((unsigned long *)tsk->thread.sp)[3];
26082+//XXX return tsk->thread.eip;
26083 }
26084
26085 void __show_regs(struct pt_regs *regs, int all)
26086@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26087 unsigned long sp;
26088 unsigned short ss, gs;
26089
26090- if (user_mode_vm(regs)) {
26091+ if (user_mode(regs)) {
26092 sp = regs->sp;
26093 ss = regs->ss & 0xffff;
26094- gs = get_user_gs(regs);
26095 } else {
26096 sp = kernel_stack_pointer(regs);
26097 savesegment(ss, ss);
26098- savesegment(gs, gs);
26099 }
26100+ gs = get_user_gs(regs);
26101
26102 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26103 (u16)regs->cs, regs->ip, regs->flags,
26104- smp_processor_id());
26105+ raw_smp_processor_id());
26106 print_symbol("EIP is at %s\n", regs->ip);
26107
26108 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26109@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26110 int copy_thread(unsigned long clone_flags, unsigned long sp,
26111 unsigned long arg, struct task_struct *p)
26112 {
26113- struct pt_regs *childregs = task_pt_regs(p);
26114+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26115 struct task_struct *tsk;
26116 int err;
26117
26118 p->thread.sp = (unsigned long) childregs;
26119 p->thread.sp0 = (unsigned long) (childregs+1);
26120+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26121
26122 if (unlikely(p->flags & PF_KTHREAD)) {
26123 /* kernel thread */
26124 memset(childregs, 0, sizeof(struct pt_regs));
26125 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26126- task_user_gs(p) = __KERNEL_STACK_CANARY;
26127- childregs->ds = __USER_DS;
26128- childregs->es = __USER_DS;
26129+ savesegment(gs, childregs->gs);
26130+ childregs->ds = __KERNEL_DS;
26131+ childregs->es = __KERNEL_DS;
26132 childregs->fs = __KERNEL_PERCPU;
26133 childregs->bx = sp; /* function */
26134 childregs->bp = arg;
26135@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26136 struct thread_struct *prev = &prev_p->thread,
26137 *next = &next_p->thread;
26138 int cpu = smp_processor_id();
26139- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26140+ struct tss_struct *tss = init_tss + cpu;
26141 fpu_switch_t fpu;
26142
26143 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26144@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26145 */
26146 lazy_save_gs(prev->gs);
26147
26148+#ifdef CONFIG_PAX_MEMORY_UDEREF
26149+ __set_fs(task_thread_info(next_p)->addr_limit);
26150+#endif
26151+
26152 /*
26153 * Load the per-thread Thread-Local Storage descriptor.
26154 */
26155@@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26156 */
26157 arch_end_context_switch(next_p);
26158
26159+ this_cpu_write(current_task, next_p);
26160+ this_cpu_write(current_tinfo, &next_p->tinfo);
26161+
26162 /*
26163 * Restore %gs if needed (which is common)
26164 */
26165@@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26166
26167 switch_fpu_finish(next_p, fpu);
26168
26169- this_cpu_write(current_task, next_p);
26170-
26171 return prev_p;
26172 }
26173
26174@@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26175 } while (count++ < 16);
26176 return 0;
26177 }
26178-
26179diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26180index 9c0280f..5bbb1c0 100644
26181--- a/arch/x86/kernel/process_64.c
26182+++ b/arch/x86/kernel/process_64.c
26183@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26184 struct pt_regs *childregs;
26185 struct task_struct *me = current;
26186
26187- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26188+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26189 childregs = task_pt_regs(p);
26190 p->thread.sp = (unsigned long) childregs;
26191 p->thread.usersp = me->thread.usersp;
26192+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26193 set_tsk_thread_flag(p, TIF_FORK);
26194 p->thread.fpu_counter = 0;
26195 p->thread.io_bitmap_ptr = NULL;
26196@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26197 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26198 savesegment(es, p->thread.es);
26199 savesegment(ds, p->thread.ds);
26200+ savesegment(ss, p->thread.ss);
26201+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26202 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26203
26204 if (unlikely(p->flags & PF_KTHREAD)) {
26205@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26206 struct thread_struct *prev = &prev_p->thread;
26207 struct thread_struct *next = &next_p->thread;
26208 int cpu = smp_processor_id();
26209- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26210+ struct tss_struct *tss = init_tss + cpu;
26211 unsigned fsindex, gsindex;
26212 fpu_switch_t fpu;
26213
26214@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26215 if (unlikely(next->ds | prev->ds))
26216 loadsegment(ds, next->ds);
26217
26218+ savesegment(ss, prev->ss);
26219+ if (unlikely(next->ss != prev->ss))
26220+ loadsegment(ss, next->ss);
26221
26222 /* We must save %fs and %gs before load_TLS() because
26223 * %fs and %gs may be cleared by load_TLS().
26224@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26225 prev->usersp = this_cpu_read(old_rsp);
26226 this_cpu_write(old_rsp, next->usersp);
26227 this_cpu_write(current_task, next_p);
26228+ this_cpu_write(current_tinfo, &next_p->tinfo);
26229
26230 /*
26231 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26232@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26233 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26234 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26235
26236- this_cpu_write(kernel_stack,
26237- (unsigned long)task_stack_page(next_p) +
26238- THREAD_SIZE - KERNEL_STACK_OFFSET);
26239+ this_cpu_write(kernel_stack, next->sp0);
26240
26241 /*
26242 * Now maybe reload the debug registers and handle I/O bitmaps
26243@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26244 if (!p || p == current || p->state == TASK_RUNNING)
26245 return 0;
26246 stack = (unsigned long)task_stack_page(p);
26247- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26248+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26249 return 0;
26250 fp = *(u64 *)(p->thread.sp);
26251 do {
26252- if (fp < (unsigned long)stack ||
26253- fp >= (unsigned long)stack+THREAD_SIZE)
26254+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26255 return 0;
26256 ip = *(u64 *)(fp+8);
26257 if (!in_sched_functions(ip))
26258diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26259index 7461f50..1334029 100644
26260--- a/arch/x86/kernel/ptrace.c
26261+++ b/arch/x86/kernel/ptrace.c
26262@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26263 {
26264 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26265 unsigned long sp = (unsigned long)&regs->sp;
26266- struct thread_info *tinfo;
26267
26268- if (context == (sp & ~(THREAD_SIZE - 1)))
26269+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26270 return sp;
26271
26272- tinfo = (struct thread_info *)context;
26273- if (tinfo->previous_esp)
26274- return tinfo->previous_esp;
26275+ sp = *(unsigned long *)context;
26276+ if (sp)
26277+ return sp;
26278
26279 return (unsigned long)regs;
26280 }
26281@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26282 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26283 {
26284 int i;
26285- int dr7 = 0;
26286+ unsigned long dr7 = 0;
26287 struct arch_hw_breakpoint *info;
26288
26289 for (i = 0; i < HBP_NUM; i++) {
26290@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26291 unsigned long addr, unsigned long data)
26292 {
26293 int ret;
26294- unsigned long __user *datap = (unsigned long __user *)data;
26295+ unsigned long __user *datap = (__force unsigned long __user *)data;
26296
26297 switch (request) {
26298 /* read the word at location addr in the USER area. */
26299@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26300 if ((int) addr < 0)
26301 return -EIO;
26302 ret = do_get_thread_area(child, addr,
26303- (struct user_desc __user *)data);
26304+ (__force struct user_desc __user *) data);
26305 break;
26306
26307 case PTRACE_SET_THREAD_AREA:
26308 if ((int) addr < 0)
26309 return -EIO;
26310 ret = do_set_thread_area(child, addr,
26311- (struct user_desc __user *)data, 0);
26312+ (__force struct user_desc __user *) data, 0);
26313 break;
26314 #endif
26315
26316@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26317
26318 #ifdef CONFIG_X86_64
26319
26320-static struct user_regset x86_64_regsets[] __read_mostly = {
26321+static user_regset_no_const x86_64_regsets[] __read_only = {
26322 [REGSET_GENERAL] = {
26323 .core_note_type = NT_PRSTATUS,
26324 .n = sizeof(struct user_regs_struct) / sizeof(long),
26325@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26326 #endif /* CONFIG_X86_64 */
26327
26328 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26329-static struct user_regset x86_32_regsets[] __read_mostly = {
26330+static user_regset_no_const x86_32_regsets[] __read_only = {
26331 [REGSET_GENERAL] = {
26332 .core_note_type = NT_PRSTATUS,
26333 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26334@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26335 */
26336 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26337
26338-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26339+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26340 {
26341 #ifdef CONFIG_X86_64
26342 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26343@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26344 memset(info, 0, sizeof(*info));
26345 info->si_signo = SIGTRAP;
26346 info->si_code = si_code;
26347- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26348+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26349 }
26350
26351 void user_single_step_siginfo(struct task_struct *tsk,
26352@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26353 # define IS_IA32 0
26354 #endif
26355
26356+#ifdef CONFIG_GRKERNSEC_SETXID
26357+extern void gr_delayed_cred_worker(void);
26358+#endif
26359+
26360 /*
26361 * We must return the syscall number to actually look up in the table.
26362 * This can be -1L to skip running any syscall at all.
26363@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26364
26365 user_exit();
26366
26367+#ifdef CONFIG_GRKERNSEC_SETXID
26368+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26369+ gr_delayed_cred_worker();
26370+#endif
26371+
26372 /*
26373 * If we stepped into a sysenter/syscall insn, it trapped in
26374 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26375@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26376 */
26377 user_exit();
26378
26379+#ifdef CONFIG_GRKERNSEC_SETXID
26380+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26381+ gr_delayed_cred_worker();
26382+#endif
26383+
26384 audit_syscall_exit(regs);
26385
26386 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26387diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26388index 2f355d2..e75ed0a 100644
26389--- a/arch/x86/kernel/pvclock.c
26390+++ b/arch/x86/kernel/pvclock.c
26391@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26392 reset_hung_task_detector();
26393 }
26394
26395-static atomic64_t last_value = ATOMIC64_INIT(0);
26396+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26397
26398 void pvclock_resume(void)
26399 {
26400- atomic64_set(&last_value, 0);
26401+ atomic64_set_unchecked(&last_value, 0);
26402 }
26403
26404 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26405@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26406 * updating at the same time, and one of them could be slightly behind,
26407 * making the assumption that last_value always go forward fail to hold.
26408 */
26409- last = atomic64_read(&last_value);
26410+ last = atomic64_read_unchecked(&last_value);
26411 do {
26412 if (ret < last)
26413 return last;
26414- last = atomic64_cmpxchg(&last_value, last, ret);
26415+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26416 } while (unlikely(last != ret));
26417
26418 return ret;
26419diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26420index c752cb4..866c432 100644
26421--- a/arch/x86/kernel/reboot.c
26422+++ b/arch/x86/kernel/reboot.c
26423@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26424
26425 void __noreturn machine_real_restart(unsigned int type)
26426 {
26427+
26428+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26429+ struct desc_struct *gdt;
26430+#endif
26431+
26432 local_irq_disable();
26433
26434 /*
26435@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26436
26437 /* Jump to the identity-mapped low memory code */
26438 #ifdef CONFIG_X86_32
26439- asm volatile("jmpl *%0" : :
26440+
26441+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26442+ gdt = get_cpu_gdt_table(smp_processor_id());
26443+ pax_open_kernel();
26444+#ifdef CONFIG_PAX_MEMORY_UDEREF
26445+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26446+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26447+ loadsegment(ds, __KERNEL_DS);
26448+ loadsegment(es, __KERNEL_DS);
26449+ loadsegment(ss, __KERNEL_DS);
26450+#endif
26451+#ifdef CONFIG_PAX_KERNEXEC
26452+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26453+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26454+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26455+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26456+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26457+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26458+#endif
26459+ pax_close_kernel();
26460+#endif
26461+
26462+ asm volatile("ljmpl *%0" : :
26463 "rm" (real_mode_header->machine_real_restart_asm),
26464 "a" (type));
26465 #else
26466@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26467 * try to force a triple fault and then cycle between hitting the keyboard
26468 * controller and doing that
26469 */
26470-static void native_machine_emergency_restart(void)
26471+static void __noreturn native_machine_emergency_restart(void)
26472 {
26473 int i;
26474 int attempt = 0;
26475@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26476 #endif
26477 }
26478
26479-static void __machine_emergency_restart(int emergency)
26480+static void __noreturn __machine_emergency_restart(int emergency)
26481 {
26482 reboot_emergency = emergency;
26483 machine_ops.emergency_restart();
26484 }
26485
26486-static void native_machine_restart(char *__unused)
26487+static void __noreturn native_machine_restart(char *__unused)
26488 {
26489 pr_notice("machine restart\n");
26490
26491@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26492 __machine_emergency_restart(0);
26493 }
26494
26495-static void native_machine_halt(void)
26496+static void __noreturn native_machine_halt(void)
26497 {
26498 /* Stop other cpus and apics */
26499 machine_shutdown();
26500@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26501 stop_this_cpu(NULL);
26502 }
26503
26504-static void native_machine_power_off(void)
26505+static void __noreturn native_machine_power_off(void)
26506 {
26507 if (pm_power_off) {
26508 if (!reboot_force)
26509@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26510 }
26511 /* A fallback in case there is no PM info available */
26512 tboot_shutdown(TB_SHUTDOWN_HALT);
26513+ unreachable();
26514 }
26515
26516-struct machine_ops machine_ops = {
26517+struct machine_ops machine_ops __read_only = {
26518 .power_off = native_machine_power_off,
26519 .shutdown = native_machine_shutdown,
26520 .emergency_restart = native_machine_emergency_restart,
26521diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26522index c8e41e9..64049ef 100644
26523--- a/arch/x86/kernel/reboot_fixups_32.c
26524+++ b/arch/x86/kernel/reboot_fixups_32.c
26525@@ -57,7 +57,7 @@ struct device_fixup {
26526 unsigned int vendor;
26527 unsigned int device;
26528 void (*reboot_fixup)(struct pci_dev *);
26529-};
26530+} __do_const;
26531
26532 /*
26533 * PCI ids solely used for fixups_table go here
26534diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26535index 3fd2c69..a444264 100644
26536--- a/arch/x86/kernel/relocate_kernel_64.S
26537+++ b/arch/x86/kernel/relocate_kernel_64.S
26538@@ -96,8 +96,7 @@ relocate_kernel:
26539
26540 /* jump to identity mapped page */
26541 addq $(identity_mapped - relocate_kernel), %r8
26542- pushq %r8
26543- ret
26544+ jmp *%r8
26545
26546 identity_mapped:
26547 /* set return address to 0 if not preserving context */
26548diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26549index cb233bc..23b4879 100644
26550--- a/arch/x86/kernel/setup.c
26551+++ b/arch/x86/kernel/setup.c
26552@@ -110,6 +110,7 @@
26553 #include <asm/mce.h>
26554 #include <asm/alternative.h>
26555 #include <asm/prom.h>
26556+#include <asm/boot.h>
26557
26558 /*
26559 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26560@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26561 #endif
26562
26563
26564-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26565-__visible unsigned long mmu_cr4_features;
26566+#ifdef CONFIG_X86_64
26567+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26568+#elif defined(CONFIG_X86_PAE)
26569+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26570 #else
26571-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26572+__visible unsigned long mmu_cr4_features __read_only;
26573 #endif
26574
26575+void set_in_cr4(unsigned long mask)
26576+{
26577+ unsigned long cr4 = read_cr4();
26578+
26579+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26580+ return;
26581+
26582+ pax_open_kernel();
26583+ mmu_cr4_features |= mask;
26584+ pax_close_kernel();
26585+
26586+ if (trampoline_cr4_features)
26587+ *trampoline_cr4_features = mmu_cr4_features;
26588+ cr4 |= mask;
26589+ write_cr4(cr4);
26590+}
26591+EXPORT_SYMBOL(set_in_cr4);
26592+
26593+void clear_in_cr4(unsigned long mask)
26594+{
26595+ unsigned long cr4 = read_cr4();
26596+
26597+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26598+ return;
26599+
26600+ pax_open_kernel();
26601+ mmu_cr4_features &= ~mask;
26602+ pax_close_kernel();
26603+
26604+ if (trampoline_cr4_features)
26605+ *trampoline_cr4_features = mmu_cr4_features;
26606+ cr4 &= ~mask;
26607+ write_cr4(cr4);
26608+}
26609+EXPORT_SYMBOL(clear_in_cr4);
26610+
26611 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26612 int bootloader_type, bootloader_version;
26613
26614@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26615 * area (640->1Mb) as ram even though it is not.
26616 * take them out.
26617 */
26618- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26619+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26620
26621 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26622 }
26623@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26624 /* called before trim_bios_range() to spare extra sanitize */
26625 static void __init e820_add_kernel_range(void)
26626 {
26627- u64 start = __pa_symbol(_text);
26628+ u64 start = __pa_symbol(ktla_ktva(_text));
26629 u64 size = __pa_symbol(_end) - start;
26630
26631 /*
26632@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26633
26634 void __init setup_arch(char **cmdline_p)
26635 {
26636+#ifdef CONFIG_X86_32
26637+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26638+#else
26639 memblock_reserve(__pa_symbol(_text),
26640 (unsigned long)__bss_stop - (unsigned long)_text);
26641+#endif
26642
26643 early_reserve_initrd();
26644
26645@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26646
26647 if (!boot_params.hdr.root_flags)
26648 root_mountflags &= ~MS_RDONLY;
26649- init_mm.start_code = (unsigned long) _text;
26650- init_mm.end_code = (unsigned long) _etext;
26651+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26652+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26653 init_mm.end_data = (unsigned long) _edata;
26654 init_mm.brk = _brk_end;
26655
26656- code_resource.start = __pa_symbol(_text);
26657- code_resource.end = __pa_symbol(_etext)-1;
26658- data_resource.start = __pa_symbol(_etext);
26659+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26660+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26661+ data_resource.start = __pa_symbol(_sdata);
26662 data_resource.end = __pa_symbol(_edata)-1;
26663 bss_resource.start = __pa_symbol(__bss_start);
26664 bss_resource.end = __pa_symbol(__bss_stop)-1;
26665diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26666index 5cdff03..80fa283 100644
26667--- a/arch/x86/kernel/setup_percpu.c
26668+++ b/arch/x86/kernel/setup_percpu.c
26669@@ -21,19 +21,17 @@
26670 #include <asm/cpu.h>
26671 #include <asm/stackprotector.h>
26672
26673-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26674+#ifdef CONFIG_SMP
26675+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26676 EXPORT_PER_CPU_SYMBOL(cpu_number);
26677+#endif
26678
26679-#ifdef CONFIG_X86_64
26680 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26681-#else
26682-#define BOOT_PERCPU_OFFSET 0
26683-#endif
26684
26685 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26686 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26687
26688-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26689+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26690 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26691 };
26692 EXPORT_SYMBOL(__per_cpu_offset);
26693@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26694 {
26695 #ifdef CONFIG_NEED_MULTIPLE_NODES
26696 pg_data_t *last = NULL;
26697- unsigned int cpu;
26698+ int cpu;
26699
26700 for_each_possible_cpu(cpu) {
26701 int node = early_cpu_to_node(cpu);
26702@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26703 {
26704 #ifdef CONFIG_X86_32
26705 struct desc_struct gdt;
26706+ unsigned long base = per_cpu_offset(cpu);
26707
26708- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26709- 0x2 | DESCTYPE_S, 0x8);
26710- gdt.s = 1;
26711+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26712+ 0x83 | DESCTYPE_S, 0xC);
26713 write_gdt_entry(get_cpu_gdt_table(cpu),
26714 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26715 #endif
26716@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26717 /* alrighty, percpu areas up and running */
26718 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26719 for_each_possible_cpu(cpu) {
26720+#ifdef CONFIG_CC_STACKPROTECTOR
26721+#ifdef CONFIG_X86_32
26722+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26723+#endif
26724+#endif
26725 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26726 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26727 per_cpu(cpu_number, cpu) = cpu;
26728@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26729 */
26730 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26731 #endif
26732+#ifdef CONFIG_CC_STACKPROTECTOR
26733+#ifdef CONFIG_X86_32
26734+ if (!cpu)
26735+ per_cpu(stack_canary.canary, cpu) = canary;
26736+#endif
26737+#endif
26738 /*
26739 * Up to this point, the boot CPU has been using .init.data
26740 * area. Reload any changed state for the boot CPU.
26741diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26742index 9e5de68..16c53cb 100644
26743--- a/arch/x86/kernel/signal.c
26744+++ b/arch/x86/kernel/signal.c
26745@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26746 * Align the stack pointer according to the i386 ABI,
26747 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26748 */
26749- sp = ((sp + 4) & -16ul) - 4;
26750+ sp = ((sp - 12) & -16ul) - 4;
26751 #else /* !CONFIG_X86_32 */
26752 sp = round_down(sp, 16) - 8;
26753 #endif
26754@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26755 }
26756
26757 if (current->mm->context.vdso)
26758- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26759+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26760 else
26761- restorer = &frame->retcode;
26762+ restorer = (void __user *)&frame->retcode;
26763 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26764 restorer = ksig->ka.sa.sa_restorer;
26765
26766@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26767 * reasons and because gdb uses it as a signature to notice
26768 * signal handler stack frames.
26769 */
26770- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26771+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26772
26773 if (err)
26774 return -EFAULT;
26775@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26776 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26777
26778 /* Set up to return from userspace. */
26779- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26780+ if (current->mm->context.vdso)
26781+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26782+ else
26783+ restorer = (void __user *)&frame->retcode;
26784 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26785 restorer = ksig->ka.sa.sa_restorer;
26786 put_user_ex(restorer, &frame->pretcode);
26787@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26788 * reasons and because gdb uses it as a signature to notice
26789 * signal handler stack frames.
26790 */
26791- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26792+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26793 } put_user_catch(err);
26794
26795 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26796@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26797 {
26798 int usig = signr_convert(ksig->sig);
26799 sigset_t *set = sigmask_to_save();
26800- compat_sigset_t *cset = (compat_sigset_t *) set;
26801+ sigset_t sigcopy;
26802+ compat_sigset_t *cset;
26803+
26804+ sigcopy = *set;
26805+
26806+ cset = (compat_sigset_t *) &sigcopy;
26807
26808 /* Set up the stack frame */
26809 if (is_ia32_frame()) {
26810@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26811 } else if (is_x32_frame()) {
26812 return x32_setup_rt_frame(ksig, cset, regs);
26813 } else {
26814- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26815+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26816 }
26817 }
26818
26819diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26820index 7c3a5a6..f0a8961 100644
26821--- a/arch/x86/kernel/smp.c
26822+++ b/arch/x86/kernel/smp.c
26823@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26824
26825 __setup("nonmi_ipi", nonmi_ipi_setup);
26826
26827-struct smp_ops smp_ops = {
26828+struct smp_ops smp_ops __read_only = {
26829 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26830 .smp_prepare_cpus = native_smp_prepare_cpus,
26831 .smp_cpus_done = native_smp_cpus_done,
26832diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26833index 85dc05a..f8c96f6 100644
26834--- a/arch/x86/kernel/smpboot.c
26835+++ b/arch/x86/kernel/smpboot.c
26836@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26837
26838 enable_start_cpu0 = 0;
26839
26840-#ifdef CONFIG_X86_32
26841- /* switch away from the initial page table */
26842- load_cr3(swapper_pg_dir);
26843- __flush_tlb_all();
26844-#endif
26845-
26846 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26847 barrier();
26848+
26849+ /* switch away from the initial page table */
26850+#ifdef CONFIG_PAX_PER_CPU_PGD
26851+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26852+ __flush_tlb_all();
26853+#elif defined(CONFIG_X86_32)
26854+ load_cr3(swapper_pg_dir);
26855+ __flush_tlb_all();
26856+#endif
26857+
26858 /*
26859 * Check TSC synchronization with the BP:
26860 */
26861@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26862 alternatives_enable_smp();
26863
26864 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26865- (THREAD_SIZE + task_stack_page(idle))) - 1);
26866+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26867 per_cpu(current_task, cpu) = idle;
26868+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26869
26870 #ifdef CONFIG_X86_32
26871 /* Stack for startup_32 can be just as for start_secondary onwards */
26872@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26873 #else
26874 clear_tsk_thread_flag(idle, TIF_FORK);
26875 initial_gs = per_cpu_offset(cpu);
26876- per_cpu(kernel_stack, cpu) =
26877- (unsigned long)task_stack_page(idle) -
26878- KERNEL_STACK_OFFSET + THREAD_SIZE;
26879+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26880 #endif
26881+
26882+ pax_open_kernel();
26883 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26884+ pax_close_kernel();
26885+
26886 initial_code = (unsigned long)start_secondary;
26887 stack_start = idle->thread.sp;
26888
26889@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26890 /* the FPU context is blank, nobody can own it */
26891 __cpu_disable_lazy_restore(cpu);
26892
26893+#ifdef CONFIG_PAX_PER_CPU_PGD
26894+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26895+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26896+ KERNEL_PGD_PTRS);
26897+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26898+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26899+ KERNEL_PGD_PTRS);
26900+#endif
26901+
26902 err = do_boot_cpu(apicid, cpu, tidle);
26903 if (err) {
26904 pr_debug("do_boot_cpu failed %d\n", err);
26905diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26906index 9b4d51d..5d28b58 100644
26907--- a/arch/x86/kernel/step.c
26908+++ b/arch/x86/kernel/step.c
26909@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26910 struct desc_struct *desc;
26911 unsigned long base;
26912
26913- seg &= ~7UL;
26914+ seg >>= 3;
26915
26916 mutex_lock(&child->mm->context.lock);
26917- if (unlikely((seg >> 3) >= child->mm->context.size))
26918+ if (unlikely(seg >= child->mm->context.size))
26919 addr = -1L; /* bogus selector, access would fault */
26920 else {
26921 desc = child->mm->context.ldt + seg;
26922@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26923 addr += base;
26924 }
26925 mutex_unlock(&child->mm->context.lock);
26926- }
26927+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26928+ addr = ktla_ktva(addr);
26929
26930 return addr;
26931 }
26932@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26933 unsigned char opcode[15];
26934 unsigned long addr = convert_ip_to_linear(child, regs);
26935
26936+ if (addr == -EINVAL)
26937+ return 0;
26938+
26939 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26940 for (i = 0; i < copied; i++) {
26941 switch (opcode[i]) {
26942diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26943new file mode 100644
26944index 0000000..5877189
26945--- /dev/null
26946+++ b/arch/x86/kernel/sys_i386_32.c
26947@@ -0,0 +1,189 @@
26948+/*
26949+ * This file contains various random system calls that
26950+ * have a non-standard calling sequence on the Linux/i386
26951+ * platform.
26952+ */
26953+
26954+#include <linux/errno.h>
26955+#include <linux/sched.h>
26956+#include <linux/mm.h>
26957+#include <linux/fs.h>
26958+#include <linux/smp.h>
26959+#include <linux/sem.h>
26960+#include <linux/msg.h>
26961+#include <linux/shm.h>
26962+#include <linux/stat.h>
26963+#include <linux/syscalls.h>
26964+#include <linux/mman.h>
26965+#include <linux/file.h>
26966+#include <linux/utsname.h>
26967+#include <linux/ipc.h>
26968+#include <linux/elf.h>
26969+
26970+#include <linux/uaccess.h>
26971+#include <linux/unistd.h>
26972+
26973+#include <asm/syscalls.h>
26974+
26975+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26976+{
26977+ unsigned long pax_task_size = TASK_SIZE;
26978+
26979+#ifdef CONFIG_PAX_SEGMEXEC
26980+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26981+ pax_task_size = SEGMEXEC_TASK_SIZE;
26982+#endif
26983+
26984+ if (flags & MAP_FIXED)
26985+ if (len > pax_task_size || addr > pax_task_size - len)
26986+ return -EINVAL;
26987+
26988+ return 0;
26989+}
26990+
26991+/*
26992+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26993+ */
26994+static unsigned long get_align_mask(void)
26995+{
26996+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26997+ return 0;
26998+
26999+ if (!(current->flags & PF_RANDOMIZE))
27000+ return 0;
27001+
27002+ return va_align.mask;
27003+}
27004+
27005+unsigned long
27006+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27007+ unsigned long len, unsigned long pgoff, unsigned long flags)
27008+{
27009+ struct mm_struct *mm = current->mm;
27010+ struct vm_area_struct *vma;
27011+ unsigned long pax_task_size = TASK_SIZE;
27012+ struct vm_unmapped_area_info info;
27013+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27014+
27015+#ifdef CONFIG_PAX_SEGMEXEC
27016+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27017+ pax_task_size = SEGMEXEC_TASK_SIZE;
27018+#endif
27019+
27020+ pax_task_size -= PAGE_SIZE;
27021+
27022+ if (len > pax_task_size)
27023+ return -ENOMEM;
27024+
27025+ if (flags & MAP_FIXED)
27026+ return addr;
27027+
27028+#ifdef CONFIG_PAX_RANDMMAP
27029+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27030+#endif
27031+
27032+ if (addr) {
27033+ addr = PAGE_ALIGN(addr);
27034+ if (pax_task_size - len >= addr) {
27035+ vma = find_vma(mm, addr);
27036+ if (check_heap_stack_gap(vma, addr, len, offset))
27037+ return addr;
27038+ }
27039+ }
27040+
27041+ info.flags = 0;
27042+ info.length = len;
27043+ info.align_mask = filp ? get_align_mask() : 0;
27044+ info.align_offset = pgoff << PAGE_SHIFT;
27045+ info.threadstack_offset = offset;
27046+
27047+#ifdef CONFIG_PAX_PAGEEXEC
27048+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27049+ info.low_limit = 0x00110000UL;
27050+ info.high_limit = mm->start_code;
27051+
27052+#ifdef CONFIG_PAX_RANDMMAP
27053+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27054+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27055+#endif
27056+
27057+ if (info.low_limit < info.high_limit) {
27058+ addr = vm_unmapped_area(&info);
27059+ if (!IS_ERR_VALUE(addr))
27060+ return addr;
27061+ }
27062+ } else
27063+#endif
27064+
27065+ info.low_limit = mm->mmap_base;
27066+ info.high_limit = pax_task_size;
27067+
27068+ return vm_unmapped_area(&info);
27069+}
27070+
27071+unsigned long
27072+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27073+ const unsigned long len, const unsigned long pgoff,
27074+ const unsigned long flags)
27075+{
27076+ struct vm_area_struct *vma;
27077+ struct mm_struct *mm = current->mm;
27078+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27079+ struct vm_unmapped_area_info info;
27080+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27081+
27082+#ifdef CONFIG_PAX_SEGMEXEC
27083+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27084+ pax_task_size = SEGMEXEC_TASK_SIZE;
27085+#endif
27086+
27087+ pax_task_size -= PAGE_SIZE;
27088+
27089+ /* requested length too big for entire address space */
27090+ if (len > pax_task_size)
27091+ return -ENOMEM;
27092+
27093+ if (flags & MAP_FIXED)
27094+ return addr;
27095+
27096+#ifdef CONFIG_PAX_PAGEEXEC
27097+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27098+ goto bottomup;
27099+#endif
27100+
27101+#ifdef CONFIG_PAX_RANDMMAP
27102+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27103+#endif
27104+
27105+ /* requesting a specific address */
27106+ if (addr) {
27107+ addr = PAGE_ALIGN(addr);
27108+ if (pax_task_size - len >= addr) {
27109+ vma = find_vma(mm, addr);
27110+ if (check_heap_stack_gap(vma, addr, len, offset))
27111+ return addr;
27112+ }
27113+ }
27114+
27115+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27116+ info.length = len;
27117+ info.low_limit = PAGE_SIZE;
27118+ info.high_limit = mm->mmap_base;
27119+ info.align_mask = filp ? get_align_mask() : 0;
27120+ info.align_offset = pgoff << PAGE_SHIFT;
27121+ info.threadstack_offset = offset;
27122+
27123+ addr = vm_unmapped_area(&info);
27124+ if (!(addr & ~PAGE_MASK))
27125+ return addr;
27126+ VM_BUG_ON(addr != -ENOMEM);
27127+
27128+bottomup:
27129+ /*
27130+ * A failed mmap() very likely causes application failure,
27131+ * so fall back to the bottom-up function here. This scenario
27132+ * can happen with large stack limits and large mmap()
27133+ * allocations.
27134+ */
27135+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27136+}
27137diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27138index 30277e2..5664a29 100644
27139--- a/arch/x86/kernel/sys_x86_64.c
27140+++ b/arch/x86/kernel/sys_x86_64.c
27141@@ -81,8 +81,8 @@ out:
27142 return error;
27143 }
27144
27145-static void find_start_end(unsigned long flags, unsigned long *begin,
27146- unsigned long *end)
27147+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27148+ unsigned long *begin, unsigned long *end)
27149 {
27150 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27151 unsigned long new_begin;
27152@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27153 *begin = new_begin;
27154 }
27155 } else {
27156- *begin = current->mm->mmap_legacy_base;
27157+ *begin = mm->mmap_legacy_base;
27158 *end = TASK_SIZE;
27159 }
27160 }
27161@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27162 struct vm_area_struct *vma;
27163 struct vm_unmapped_area_info info;
27164 unsigned long begin, end;
27165+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27166
27167 if (flags & MAP_FIXED)
27168 return addr;
27169
27170- find_start_end(flags, &begin, &end);
27171+ find_start_end(mm, flags, &begin, &end);
27172
27173 if (len > end)
27174 return -ENOMEM;
27175
27176+#ifdef CONFIG_PAX_RANDMMAP
27177+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27178+#endif
27179+
27180 if (addr) {
27181 addr = PAGE_ALIGN(addr);
27182 vma = find_vma(mm, addr);
27183- if (end - len >= addr &&
27184- (!vma || addr + len <= vma->vm_start))
27185+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27186 return addr;
27187 }
27188
27189@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27190 info.high_limit = end;
27191 info.align_mask = filp ? get_align_mask() : 0;
27192 info.align_offset = pgoff << PAGE_SHIFT;
27193+ info.threadstack_offset = offset;
27194 return vm_unmapped_area(&info);
27195 }
27196
27197@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27198 struct mm_struct *mm = current->mm;
27199 unsigned long addr = addr0;
27200 struct vm_unmapped_area_info info;
27201+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27202
27203 /* requested length too big for entire address space */
27204 if (len > TASK_SIZE)
27205@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27206 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27207 goto bottomup;
27208
27209+#ifdef CONFIG_PAX_RANDMMAP
27210+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27211+#endif
27212+
27213 /* requesting a specific address */
27214 if (addr) {
27215 addr = PAGE_ALIGN(addr);
27216 vma = find_vma(mm, addr);
27217- if (TASK_SIZE - len >= addr &&
27218- (!vma || addr + len <= vma->vm_start))
27219+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27220 return addr;
27221 }
27222
27223@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27224 info.high_limit = mm->mmap_base;
27225 info.align_mask = filp ? get_align_mask() : 0;
27226 info.align_offset = pgoff << PAGE_SHIFT;
27227+ info.threadstack_offset = offset;
27228 addr = vm_unmapped_area(&info);
27229 if (!(addr & ~PAGE_MASK))
27230 return addr;
27231diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27232index 91a4496..bb87552 100644
27233--- a/arch/x86/kernel/tboot.c
27234+++ b/arch/x86/kernel/tboot.c
27235@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27236
27237 void tboot_shutdown(u32 shutdown_type)
27238 {
27239- void (*shutdown)(void);
27240+ void (* __noreturn shutdown)(void);
27241
27242 if (!tboot_enabled())
27243 return;
27244@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27245
27246 switch_to_tboot_pt();
27247
27248- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27249+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27250 shutdown();
27251
27252 /* should not reach here */
27253@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27254 return -ENODEV;
27255 }
27256
27257-static atomic_t ap_wfs_count;
27258+static atomic_unchecked_t ap_wfs_count;
27259
27260 static int tboot_wait_for_aps(int num_aps)
27261 {
27262@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27263 {
27264 switch (action) {
27265 case CPU_DYING:
27266- atomic_inc(&ap_wfs_count);
27267+ atomic_inc_unchecked(&ap_wfs_count);
27268 if (num_online_cpus() == 1)
27269- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27270+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27271 return NOTIFY_BAD;
27272 break;
27273 }
27274@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27275
27276 tboot_create_trampoline();
27277
27278- atomic_set(&ap_wfs_count, 0);
27279+ atomic_set_unchecked(&ap_wfs_count, 0);
27280 register_hotcpu_notifier(&tboot_cpu_notifier);
27281
27282 #ifdef CONFIG_DEBUG_FS
27283diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27284index 24d3c91..d06b473 100644
27285--- a/arch/x86/kernel/time.c
27286+++ b/arch/x86/kernel/time.c
27287@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27288 {
27289 unsigned long pc = instruction_pointer(regs);
27290
27291- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27292+ if (!user_mode(regs) && in_lock_functions(pc)) {
27293 #ifdef CONFIG_FRAME_POINTER
27294- return *(unsigned long *)(regs->bp + sizeof(long));
27295+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27296 #else
27297 unsigned long *sp =
27298 (unsigned long *)kernel_stack_pointer(regs);
27299@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27300 * or above a saved flags. Eflags has bits 22-31 zero,
27301 * kernel addresses don't.
27302 */
27303+
27304+#ifdef CONFIG_PAX_KERNEXEC
27305+ return ktla_ktva(sp[0]);
27306+#else
27307 if (sp[0] >> 22)
27308 return sp[0];
27309 if (sp[1] >> 22)
27310 return sp[1];
27311 #endif
27312+
27313+#endif
27314 }
27315 return pc;
27316 }
27317diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27318index f7fec09..9991981 100644
27319--- a/arch/x86/kernel/tls.c
27320+++ b/arch/x86/kernel/tls.c
27321@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27322 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27323 return -EINVAL;
27324
27325+#ifdef CONFIG_PAX_SEGMEXEC
27326+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27327+ return -EINVAL;
27328+#endif
27329+
27330 set_tls_desc(p, idx, &info, 1);
27331
27332 return 0;
27333@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27334
27335 if (kbuf)
27336 info = kbuf;
27337- else if (__copy_from_user(infobuf, ubuf, count))
27338+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27339 return -EFAULT;
27340 else
27341 info = infobuf;
27342diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27343index 1c113db..287b42e 100644
27344--- a/arch/x86/kernel/tracepoint.c
27345+++ b/arch/x86/kernel/tracepoint.c
27346@@ -9,11 +9,11 @@
27347 #include <linux/atomic.h>
27348
27349 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27350-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27351+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27352 (unsigned long) trace_idt_table };
27353
27354 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27355-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27356+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27357
27358 static int trace_irq_vector_refcount;
27359 static DEFINE_MUTEX(irq_vector_mutex);
27360diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27361index b857ed8..51ae4cb 100644
27362--- a/arch/x86/kernel/traps.c
27363+++ b/arch/x86/kernel/traps.c
27364@@ -66,7 +66,7 @@
27365 #include <asm/proto.h>
27366
27367 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27368-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27369+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27370 #else
27371 #include <asm/processor-flags.h>
27372 #include <asm/setup.h>
27373@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27374 #endif
27375
27376 /* Must be page-aligned because the real IDT is used in a fixmap. */
27377-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27378+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27379
27380 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27381 EXPORT_SYMBOL_GPL(used_vectors);
27382@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27383 }
27384
27385 static int __kprobes
27386-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27387+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27388 struct pt_regs *regs, long error_code)
27389 {
27390 #ifdef CONFIG_X86_32
27391- if (regs->flags & X86_VM_MASK) {
27392+ if (v8086_mode(regs)) {
27393 /*
27394 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27395 * On nmi (interrupt 2), do_trap should not be called.
27396@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27397 return -1;
27398 }
27399 #endif
27400- if (!user_mode(regs)) {
27401+ if (!user_mode_novm(regs)) {
27402 if (!fixup_exception(regs)) {
27403 tsk->thread.error_code = error_code;
27404 tsk->thread.trap_nr = trapnr;
27405+
27406+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27407+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27408+ str = "PAX: suspicious stack segment fault";
27409+#endif
27410+
27411 die(str, regs, error_code);
27412 }
27413+
27414+#ifdef CONFIG_PAX_REFCOUNT
27415+ if (trapnr == 4)
27416+ pax_report_refcount_overflow(regs);
27417+#endif
27418+
27419 return 0;
27420 }
27421
27422@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27423 }
27424
27425 static void __kprobes
27426-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27427+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27428 long error_code, siginfo_t *info)
27429 {
27430 struct task_struct *tsk = current;
27431@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27432 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27433 printk_ratelimit()) {
27434 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27435- tsk->comm, tsk->pid, str,
27436+ tsk->comm, task_pid_nr(tsk), str,
27437 regs->ip, regs->sp, error_code);
27438 print_vma_addr(" in ", regs->ip);
27439 pr_cont("\n");
27440@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27441 conditional_sti(regs);
27442
27443 #ifdef CONFIG_X86_32
27444- if (regs->flags & X86_VM_MASK) {
27445+ if (v8086_mode(regs)) {
27446 local_irq_enable();
27447 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27448 goto exit;
27449@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27450 #endif
27451
27452 tsk = current;
27453- if (!user_mode(regs)) {
27454+ if (!user_mode_novm(regs)) {
27455 if (fixup_exception(regs))
27456 goto exit;
27457
27458 tsk->thread.error_code = error_code;
27459 tsk->thread.trap_nr = X86_TRAP_GP;
27460 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27461- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27462+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27463+
27464+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27465+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27466+ die("PAX: suspicious general protection fault", regs, error_code);
27467+ else
27468+#endif
27469+
27470 die("general protection fault", regs, error_code);
27471+ }
27472 goto exit;
27473 }
27474
27475+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27476+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27477+ struct mm_struct *mm = tsk->mm;
27478+ unsigned long limit;
27479+
27480+ down_write(&mm->mmap_sem);
27481+ limit = mm->context.user_cs_limit;
27482+ if (limit < TASK_SIZE) {
27483+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27484+ up_write(&mm->mmap_sem);
27485+ return;
27486+ }
27487+ up_write(&mm->mmap_sem);
27488+ }
27489+#endif
27490+
27491 tsk->thread.error_code = error_code;
27492 tsk->thread.trap_nr = X86_TRAP_GP;
27493
27494@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27495 /* It's safe to allow irq's after DR6 has been saved */
27496 preempt_conditional_sti(regs);
27497
27498- if (regs->flags & X86_VM_MASK) {
27499+ if (v8086_mode(regs)) {
27500 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27501 X86_TRAP_DB);
27502 preempt_conditional_cli(regs);
27503@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27504 * We already checked v86 mode above, so we can check for kernel mode
27505 * by just checking the CPL of CS.
27506 */
27507- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27508+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27509 tsk->thread.debugreg6 &= ~DR_STEP;
27510 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27511 regs->flags &= ~X86_EFLAGS_TF;
27512@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27513 return;
27514 conditional_sti(regs);
27515
27516- if (!user_mode_vm(regs))
27517+ if (!user_mode(regs))
27518 {
27519 if (!fixup_exception(regs)) {
27520 task->thread.error_code = error_code;
27521diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27522index 2ed8459..7cf329f 100644
27523--- a/arch/x86/kernel/uprobes.c
27524+++ b/arch/x86/kernel/uprobes.c
27525@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27526 int ret = NOTIFY_DONE;
27527
27528 /* We are only interested in userspace traps */
27529- if (regs && !user_mode_vm(regs))
27530+ if (regs && !user_mode(regs))
27531 return NOTIFY_DONE;
27532
27533 switch (val) {
27534@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27535
27536 if (ncopied != rasize) {
27537 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27538- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27539+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27540
27541 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27542 }
27543diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27544index b9242ba..50c5edd 100644
27545--- a/arch/x86/kernel/verify_cpu.S
27546+++ b/arch/x86/kernel/verify_cpu.S
27547@@ -20,6 +20,7 @@
27548 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27549 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27550 * arch/x86/kernel/head_32.S: processor startup
27551+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27552 *
27553 * verify_cpu, returns the status of longmode and SSE in register %eax.
27554 * 0: Success 1: Failure
27555diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27556index e8edcf5..27f9344 100644
27557--- a/arch/x86/kernel/vm86_32.c
27558+++ b/arch/x86/kernel/vm86_32.c
27559@@ -44,6 +44,7 @@
27560 #include <linux/ptrace.h>
27561 #include <linux/audit.h>
27562 #include <linux/stddef.h>
27563+#include <linux/grsecurity.h>
27564
27565 #include <asm/uaccess.h>
27566 #include <asm/io.h>
27567@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27568 do_exit(SIGSEGV);
27569 }
27570
27571- tss = &per_cpu(init_tss, get_cpu());
27572+ tss = init_tss + get_cpu();
27573 current->thread.sp0 = current->thread.saved_sp0;
27574 current->thread.sysenter_cs = __KERNEL_CS;
27575 load_sp0(tss, &current->thread);
27576@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27577
27578 if (tsk->thread.saved_sp0)
27579 return -EPERM;
27580+
27581+#ifdef CONFIG_GRKERNSEC_VM86
27582+ if (!capable(CAP_SYS_RAWIO)) {
27583+ gr_handle_vm86();
27584+ return -EPERM;
27585+ }
27586+#endif
27587+
27588 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27589 offsetof(struct kernel_vm86_struct, vm86plus) -
27590 sizeof(info.regs));
27591@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27592 int tmp;
27593 struct vm86plus_struct __user *v86;
27594
27595+#ifdef CONFIG_GRKERNSEC_VM86
27596+ if (!capable(CAP_SYS_RAWIO)) {
27597+ gr_handle_vm86();
27598+ return -EPERM;
27599+ }
27600+#endif
27601+
27602 tsk = current;
27603 switch (cmd) {
27604 case VM86_REQUEST_IRQ:
27605@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27606 tsk->thread.saved_fs = info->regs32->fs;
27607 tsk->thread.saved_gs = get_user_gs(info->regs32);
27608
27609- tss = &per_cpu(init_tss, get_cpu());
27610+ tss = init_tss + get_cpu();
27611 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27612 if (cpu_has_sep)
27613 tsk->thread.sysenter_cs = 0;
27614@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27615 goto cannot_handle;
27616 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27617 goto cannot_handle;
27618- intr_ptr = (unsigned long __user *) (i << 2);
27619+ intr_ptr = (__force unsigned long __user *) (i << 2);
27620 if (get_user(segoffs, intr_ptr))
27621 goto cannot_handle;
27622 if ((segoffs >> 16) == BIOSSEG)
27623diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27624index da6b35a..977e9cf 100644
27625--- a/arch/x86/kernel/vmlinux.lds.S
27626+++ b/arch/x86/kernel/vmlinux.lds.S
27627@@ -26,6 +26,13 @@
27628 #include <asm/page_types.h>
27629 #include <asm/cache.h>
27630 #include <asm/boot.h>
27631+#include <asm/segment.h>
27632+
27633+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27634+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27635+#else
27636+#define __KERNEL_TEXT_OFFSET 0
27637+#endif
27638
27639 #undef i386 /* in case the preprocessor is a 32bit one */
27640
27641@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27642
27643 PHDRS {
27644 text PT_LOAD FLAGS(5); /* R_E */
27645+#ifdef CONFIG_X86_32
27646+ module PT_LOAD FLAGS(5); /* R_E */
27647+#endif
27648+#ifdef CONFIG_XEN
27649+ rodata PT_LOAD FLAGS(5); /* R_E */
27650+#else
27651+ rodata PT_LOAD FLAGS(4); /* R__ */
27652+#endif
27653 data PT_LOAD FLAGS(6); /* RW_ */
27654-#ifdef CONFIG_X86_64
27655+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27656 #ifdef CONFIG_SMP
27657 percpu PT_LOAD FLAGS(6); /* RW_ */
27658 #endif
27659+ text.init PT_LOAD FLAGS(5); /* R_E */
27660+ text.exit PT_LOAD FLAGS(5); /* R_E */
27661 init PT_LOAD FLAGS(7); /* RWE */
27662-#endif
27663 note PT_NOTE FLAGS(0); /* ___ */
27664 }
27665
27666 SECTIONS
27667 {
27668 #ifdef CONFIG_X86_32
27669- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27670- phys_startup_32 = startup_32 - LOAD_OFFSET;
27671+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27672 #else
27673- . = __START_KERNEL;
27674- phys_startup_64 = startup_64 - LOAD_OFFSET;
27675+ . = __START_KERNEL;
27676 #endif
27677
27678 /* Text and read-only data */
27679- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27680- _text = .;
27681+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27682 /* bootstrapping code */
27683+#ifdef CONFIG_X86_32
27684+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27685+#else
27686+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27687+#endif
27688+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27689+ _text = .;
27690 HEAD_TEXT
27691 . = ALIGN(8);
27692 _stext = .;
27693@@ -104,13 +124,47 @@ SECTIONS
27694 IRQENTRY_TEXT
27695 *(.fixup)
27696 *(.gnu.warning)
27697- /* End of text section */
27698- _etext = .;
27699 } :text = 0x9090
27700
27701- NOTES :text :note
27702+ . += __KERNEL_TEXT_OFFSET;
27703
27704- EXCEPTION_TABLE(16) :text = 0x9090
27705+#ifdef CONFIG_X86_32
27706+ . = ALIGN(PAGE_SIZE);
27707+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27708+
27709+#ifdef CONFIG_PAX_KERNEXEC
27710+ MODULES_EXEC_VADDR = .;
27711+ BYTE(0)
27712+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27713+ . = ALIGN(HPAGE_SIZE) - 1;
27714+ MODULES_EXEC_END = .;
27715+#endif
27716+
27717+ } :module
27718+#endif
27719+
27720+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27721+ /* End of text section */
27722+ BYTE(0)
27723+ _etext = . - __KERNEL_TEXT_OFFSET;
27724+ }
27725+
27726+#ifdef CONFIG_X86_32
27727+ . = ALIGN(PAGE_SIZE);
27728+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27729+ . = ALIGN(PAGE_SIZE);
27730+ *(.empty_zero_page)
27731+ *(.initial_pg_fixmap)
27732+ *(.initial_pg_pmd)
27733+ *(.initial_page_table)
27734+ *(.swapper_pg_dir)
27735+ } :rodata
27736+#endif
27737+
27738+ . = ALIGN(PAGE_SIZE);
27739+ NOTES :rodata :note
27740+
27741+ EXCEPTION_TABLE(16) :rodata
27742
27743 #if defined(CONFIG_DEBUG_RODATA)
27744 /* .text should occupy whole number of pages */
27745@@ -122,16 +176,20 @@ SECTIONS
27746
27747 /* Data */
27748 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27749+
27750+#ifdef CONFIG_PAX_KERNEXEC
27751+ . = ALIGN(HPAGE_SIZE);
27752+#else
27753+ . = ALIGN(PAGE_SIZE);
27754+#endif
27755+
27756 /* Start of data section */
27757 _sdata = .;
27758
27759 /* init_task */
27760 INIT_TASK_DATA(THREAD_SIZE)
27761
27762-#ifdef CONFIG_X86_32
27763- /* 32 bit has nosave before _edata */
27764 NOSAVE_DATA
27765-#endif
27766
27767 PAGE_ALIGNED_DATA(PAGE_SIZE)
27768
27769@@ -172,12 +230,19 @@ SECTIONS
27770 #endif /* CONFIG_X86_64 */
27771
27772 /* Init code and data - will be freed after init */
27773- . = ALIGN(PAGE_SIZE);
27774 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27775+ BYTE(0)
27776+
27777+#ifdef CONFIG_PAX_KERNEXEC
27778+ . = ALIGN(HPAGE_SIZE);
27779+#else
27780+ . = ALIGN(PAGE_SIZE);
27781+#endif
27782+
27783 __init_begin = .; /* paired with __init_end */
27784- }
27785+ } :init.begin
27786
27787-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27788+#ifdef CONFIG_SMP
27789 /*
27790 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27791 * output PHDR, so the next output section - .init.text - should
27792@@ -186,12 +251,27 @@ SECTIONS
27793 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27794 #endif
27795
27796- INIT_TEXT_SECTION(PAGE_SIZE)
27797-#ifdef CONFIG_X86_64
27798- :init
27799-#endif
27800+ . = ALIGN(PAGE_SIZE);
27801+ init_begin = .;
27802+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27803+ VMLINUX_SYMBOL(_sinittext) = .;
27804+ INIT_TEXT
27805+ VMLINUX_SYMBOL(_einittext) = .;
27806+ . = ALIGN(PAGE_SIZE);
27807+ } :text.init
27808
27809- INIT_DATA_SECTION(16)
27810+ /*
27811+ * .exit.text is discard at runtime, not link time, to deal with
27812+ * references from .altinstructions and .eh_frame
27813+ */
27814+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27815+ EXIT_TEXT
27816+ . = ALIGN(16);
27817+ } :text.exit
27818+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27819+
27820+ . = ALIGN(PAGE_SIZE);
27821+ INIT_DATA_SECTION(16) :init
27822
27823 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27824 __x86_cpu_dev_start = .;
27825@@ -262,19 +342,12 @@ SECTIONS
27826 }
27827
27828 . = ALIGN(8);
27829- /*
27830- * .exit.text is discard at runtime, not link time, to deal with
27831- * references from .altinstructions and .eh_frame
27832- */
27833- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27834- EXIT_TEXT
27835- }
27836
27837 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27838 EXIT_DATA
27839 }
27840
27841-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27842+#ifndef CONFIG_SMP
27843 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27844 #endif
27845
27846@@ -293,16 +366,10 @@ SECTIONS
27847 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27848 __smp_locks = .;
27849 *(.smp_locks)
27850- . = ALIGN(PAGE_SIZE);
27851 __smp_locks_end = .;
27852+ . = ALIGN(PAGE_SIZE);
27853 }
27854
27855-#ifdef CONFIG_X86_64
27856- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27857- NOSAVE_DATA
27858- }
27859-#endif
27860-
27861 /* BSS */
27862 . = ALIGN(PAGE_SIZE);
27863 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27864@@ -318,6 +385,7 @@ SECTIONS
27865 __brk_base = .;
27866 . += 64 * 1024; /* 64k alignment slop space */
27867 *(.brk_reservation) /* areas brk users have reserved */
27868+ . = ALIGN(HPAGE_SIZE);
27869 __brk_limit = .;
27870 }
27871
27872@@ -344,13 +412,12 @@ SECTIONS
27873 * for the boot processor.
27874 */
27875 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27876-INIT_PER_CPU(gdt_page);
27877 INIT_PER_CPU(irq_stack_union);
27878
27879 /*
27880 * Build-time check on the image size:
27881 */
27882-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27883+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27884 "kernel image bigger than KERNEL_IMAGE_SIZE");
27885
27886 #ifdef CONFIG_SMP
27887diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27888index 1f96f93..d5c8f7a 100644
27889--- a/arch/x86/kernel/vsyscall_64.c
27890+++ b/arch/x86/kernel/vsyscall_64.c
27891@@ -56,15 +56,13 @@
27892 DEFINE_VVAR(int, vgetcpu_mode);
27893 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27894
27895-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27896+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27897
27898 static int __init vsyscall_setup(char *str)
27899 {
27900 if (str) {
27901 if (!strcmp("emulate", str))
27902 vsyscall_mode = EMULATE;
27903- else if (!strcmp("native", str))
27904- vsyscall_mode = NATIVE;
27905 else if (!strcmp("none", str))
27906 vsyscall_mode = NONE;
27907 else
27908@@ -323,8 +321,7 @@ do_ret:
27909 return true;
27910
27911 sigsegv:
27912- force_sig(SIGSEGV, current);
27913- return true;
27914+ do_group_exit(SIGKILL);
27915 }
27916
27917 /*
27918@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27919 extern char __vvar_page;
27920 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27921
27922- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27923- vsyscall_mode == NATIVE
27924- ? PAGE_KERNEL_VSYSCALL
27925- : PAGE_KERNEL_VVAR);
27926+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27927 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27928 (unsigned long)VSYSCALL_START);
27929
27930diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27931index 04068192..4d75aa6 100644
27932--- a/arch/x86/kernel/x8664_ksyms_64.c
27933+++ b/arch/x86/kernel/x8664_ksyms_64.c
27934@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27935 EXPORT_SYMBOL(copy_user_generic_unrolled);
27936 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27937 EXPORT_SYMBOL(__copy_user_nocache);
27938-EXPORT_SYMBOL(_copy_from_user);
27939-EXPORT_SYMBOL(_copy_to_user);
27940
27941 EXPORT_SYMBOL(copy_page);
27942 EXPORT_SYMBOL(clear_page);
27943@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27944 EXPORT_SYMBOL(___preempt_schedule_context);
27945 #endif
27946 #endif
27947+
27948+#ifdef CONFIG_PAX_PER_CPU_PGD
27949+EXPORT_SYMBOL(cpu_pgd);
27950+#endif
27951diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27952index 021783b..6511282 100644
27953--- a/arch/x86/kernel/x86_init.c
27954+++ b/arch/x86/kernel/x86_init.c
27955@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27956 static void default_nmi_init(void) { };
27957 static int default_i8042_detect(void) { return 1; };
27958
27959-struct x86_platform_ops x86_platform = {
27960+struct x86_platform_ops x86_platform __read_only = {
27961 .calibrate_tsc = native_calibrate_tsc,
27962 .get_wallclock = mach_get_cmos_time,
27963 .set_wallclock = mach_set_rtc_mmss,
27964@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27965 EXPORT_SYMBOL_GPL(x86_platform);
27966
27967 #if defined(CONFIG_PCI_MSI)
27968-struct x86_msi_ops x86_msi = {
27969+struct x86_msi_ops x86_msi __read_only = {
27970 .setup_msi_irqs = native_setup_msi_irqs,
27971 .compose_msi_msg = native_compose_msi_msg,
27972 .teardown_msi_irq = native_teardown_msi_irq,
27973@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27974 }
27975 #endif
27976
27977-struct x86_io_apic_ops x86_io_apic_ops = {
27978+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27979 .init = native_io_apic_init_mappings,
27980 .read = native_io_apic_read,
27981 .write = native_io_apic_write,
27982diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27983index 422fd82..b2d262e 100644
27984--- a/arch/x86/kernel/xsave.c
27985+++ b/arch/x86/kernel/xsave.c
27986@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27987
27988 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27989 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27990- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27991+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27992
27993 if (!use_xsave())
27994 return err;
27995
27996- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27997+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27998
27999 /*
28000 * Read the xstate_bv which we copied (directly from the cpu or
28001 * from the state in task struct) to the user buffers.
28002 */
28003- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28004+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28005
28006 /*
28007 * For legacy compatible, we always set FP/SSE bits in the bit
28008@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28009 */
28010 xstate_bv |= XSTATE_FPSSE;
28011
28012- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28013+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28014
28015 return err;
28016 }
28017@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28018 {
28019 int err;
28020
28021+ buf = (struct xsave_struct __user *)____m(buf);
28022 if (use_xsave())
28023 err = xsave_user(buf);
28024 else if (use_fxsr())
28025@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28026 */
28027 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28028 {
28029+ buf = (void __user *)____m(buf);
28030 if (use_xsave()) {
28031 if ((unsigned long)buf % 64 || fx_only) {
28032 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28033diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28034index c697625..a032162 100644
28035--- a/arch/x86/kvm/cpuid.c
28036+++ b/arch/x86/kvm/cpuid.c
28037@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28038 struct kvm_cpuid2 *cpuid,
28039 struct kvm_cpuid_entry2 __user *entries)
28040 {
28041- int r;
28042+ int r, i;
28043
28044 r = -E2BIG;
28045 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28046 goto out;
28047 r = -EFAULT;
28048- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28049- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28050+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28051 goto out;
28052+ for (i = 0; i < cpuid->nent; ++i) {
28053+ struct kvm_cpuid_entry2 cpuid_entry;
28054+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28055+ goto out;
28056+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28057+ }
28058 vcpu->arch.cpuid_nent = cpuid->nent;
28059 kvm_apic_set_version(vcpu);
28060 kvm_x86_ops->cpuid_update(vcpu);
28061@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28062 struct kvm_cpuid2 *cpuid,
28063 struct kvm_cpuid_entry2 __user *entries)
28064 {
28065- int r;
28066+ int r, i;
28067
28068 r = -E2BIG;
28069 if (cpuid->nent < vcpu->arch.cpuid_nent)
28070 goto out;
28071 r = -EFAULT;
28072- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28073- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28074+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28075 goto out;
28076+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28077+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28078+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28079+ goto out;
28080+ }
28081 return 0;
28082
28083 out:
28084diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28085index d86ff15..e77b023 100644
28086--- a/arch/x86/kvm/lapic.c
28087+++ b/arch/x86/kvm/lapic.c
28088@@ -55,7 +55,7 @@
28089 #define APIC_BUS_CYCLE_NS 1
28090
28091 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28092-#define apic_debug(fmt, arg...)
28093+#define apic_debug(fmt, arg...) do {} while (0)
28094
28095 #define APIC_LVT_NUM 6
28096 /* 14 is the version for Xeon and Pentium 8.4.8*/
28097diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28098index cba218a..1cc1bed 100644
28099--- a/arch/x86/kvm/paging_tmpl.h
28100+++ b/arch/x86/kvm/paging_tmpl.h
28101@@ -331,7 +331,7 @@ retry_walk:
28102 if (unlikely(kvm_is_error_hva(host_addr)))
28103 goto error;
28104
28105- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28106+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28107 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28108 goto error;
28109 walker->ptep_user[walker->level - 1] = ptep_user;
28110diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28111index 532add1..59eb241 100644
28112--- a/arch/x86/kvm/svm.c
28113+++ b/arch/x86/kvm/svm.c
28114@@ -3495,7 +3495,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28115 int cpu = raw_smp_processor_id();
28116
28117 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28118+
28119+ pax_open_kernel();
28120 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28121+ pax_close_kernel();
28122+
28123 load_TR_desc();
28124 }
28125
28126@@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28127 #endif
28128 #endif
28129
28130+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28131+ __set_fs(current_thread_info()->addr_limit);
28132+#endif
28133+
28134 reload_tss(vcpu);
28135
28136 local_irq_disable();
28137diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28138index 31c3e8b..ca3acc6 100644
28139--- a/arch/x86/kvm/vmx.c
28140+++ b/arch/x86/kvm/vmx.c
28141@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28142 #endif
28143 }
28144
28145-static void vmcs_clear_bits(unsigned long field, u32 mask)
28146+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28147 {
28148 vmcs_writel(field, vmcs_readl(field) & ~mask);
28149 }
28150
28151-static void vmcs_set_bits(unsigned long field, u32 mask)
28152+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28153 {
28154 vmcs_writel(field, vmcs_readl(field) | mask);
28155 }
28156@@ -1522,7 +1522,11 @@ static void reload_tss(void)
28157 struct desc_struct *descs;
28158
28159 descs = (void *)gdt->address;
28160+
28161+ pax_open_kernel();
28162 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28163+ pax_close_kernel();
28164+
28165 load_TR_desc();
28166 }
28167
28168@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28169 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28170 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28171
28172+#ifdef CONFIG_PAX_PER_CPU_PGD
28173+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28174+#endif
28175+
28176 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28177 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28178 vmx->loaded_vmcs->cpu = cpu;
28179@@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28180 * reads and returns guest's timestamp counter "register"
28181 * guest_tsc = host_tsc + tsc_offset -- 21.3
28182 */
28183-static u64 guest_read_tsc(void)
28184+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28185 {
28186 u64 host_tsc, tsc_offset;
28187
28188@@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28189 if (!cpu_has_vmx_flexpriority())
28190 flexpriority_enabled = 0;
28191
28192- if (!cpu_has_vmx_tpr_shadow())
28193- kvm_x86_ops->update_cr8_intercept = NULL;
28194+ if (!cpu_has_vmx_tpr_shadow()) {
28195+ pax_open_kernel();
28196+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28197+ pax_close_kernel();
28198+ }
28199
28200 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28201 kvm_disable_largepages();
28202@@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28203 if (!cpu_has_vmx_apicv())
28204 enable_apicv = 0;
28205
28206+ pax_open_kernel();
28207 if (enable_apicv)
28208- kvm_x86_ops->update_cr8_intercept = NULL;
28209+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28210 else {
28211- kvm_x86_ops->hwapic_irr_update = NULL;
28212- kvm_x86_ops->deliver_posted_interrupt = NULL;
28213- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28214+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28215+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28216+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28217 }
28218+ pax_close_kernel();
28219
28220 if (nested)
28221 nested_vmx_setup_ctls_msrs();
28222@@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28223
28224 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28225 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28226+
28227+#ifndef CONFIG_PAX_PER_CPU_PGD
28228 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28229+#endif
28230
28231 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28232 #ifdef CONFIG_X86_64
28233@@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28234 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28235 vmx->host_idt_base = dt.address;
28236
28237- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28238+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28239
28240 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28241 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28242@@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28243 "jmp 2f \n\t"
28244 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28245 "2: "
28246+
28247+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28248+ "ljmp %[cs],$3f\n\t"
28249+ "3: "
28250+#endif
28251+
28252 /* Save guest registers, load host registers, keep flags */
28253 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28254 "pop %0 \n\t"
28255@@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28256 #endif
28257 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28258 [wordsize]"i"(sizeof(ulong))
28259+
28260+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28261+ ,[cs]"i"(__KERNEL_CS)
28262+#endif
28263+
28264 : "cc", "memory"
28265 #ifdef CONFIG_X86_64
28266 , "rax", "rbx", "rdi", "rsi"
28267@@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28268 if (debugctlmsr)
28269 update_debugctlmsr(debugctlmsr);
28270
28271-#ifndef CONFIG_X86_64
28272+#ifdef CONFIG_X86_32
28273 /*
28274 * The sysexit path does not restore ds/es, so we must set them to
28275 * a reasonable value ourselves.
28276@@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28277 * may be executed in interrupt context, which saves and restore segments
28278 * around it, nullifying its effect.
28279 */
28280- loadsegment(ds, __USER_DS);
28281- loadsegment(es, __USER_DS);
28282+ loadsegment(ds, __KERNEL_DS);
28283+ loadsegment(es, __KERNEL_DS);
28284+ loadsegment(ss, __KERNEL_DS);
28285+
28286+#ifdef CONFIG_PAX_KERNEXEC
28287+ loadsegment(fs, __KERNEL_PERCPU);
28288+#endif
28289+
28290+#ifdef CONFIG_PAX_MEMORY_UDEREF
28291+ __set_fs(current_thread_info()->addr_limit);
28292+#endif
28293+
28294 #endif
28295
28296 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28297diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28298index 4e33b85..fa94855 100644
28299--- a/arch/x86/kvm/x86.c
28300+++ b/arch/x86/kvm/x86.c
28301@@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28302 {
28303 struct kvm *kvm = vcpu->kvm;
28304 int lm = is_long_mode(vcpu);
28305- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28306- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28307+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28308+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28309 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28310 : kvm->arch.xen_hvm_config.blob_size_32;
28311 u32 page_num = data & ~PAGE_MASK;
28312@@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28313 if (n < msr_list.nmsrs)
28314 goto out;
28315 r = -EFAULT;
28316+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28317+ goto out;
28318 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28319 num_msrs_to_save * sizeof(u32)))
28320 goto out;
28321@@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28322 };
28323 #endif
28324
28325-int kvm_arch_init(void *opaque)
28326+int kvm_arch_init(const void *opaque)
28327 {
28328 int r;
28329 struct kvm_x86_ops *ops = opaque;
28330diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28331index bdf8532..f63c587 100644
28332--- a/arch/x86/lguest/boot.c
28333+++ b/arch/x86/lguest/boot.c
28334@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28335 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28336 * Launcher to reboot us.
28337 */
28338-static void lguest_restart(char *reason)
28339+static __noreturn void lguest_restart(char *reason)
28340 {
28341 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28342+ BUG();
28343 }
28344
28345 /*G:050
28346diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28347index 00933d5..3a64af9 100644
28348--- a/arch/x86/lib/atomic64_386_32.S
28349+++ b/arch/x86/lib/atomic64_386_32.S
28350@@ -48,6 +48,10 @@ BEGIN(read)
28351 movl (v), %eax
28352 movl 4(v), %edx
28353 RET_ENDP
28354+BEGIN(read_unchecked)
28355+ movl (v), %eax
28356+ movl 4(v), %edx
28357+RET_ENDP
28358 #undef v
28359
28360 #define v %esi
28361@@ -55,6 +59,10 @@ BEGIN(set)
28362 movl %ebx, (v)
28363 movl %ecx, 4(v)
28364 RET_ENDP
28365+BEGIN(set_unchecked)
28366+ movl %ebx, (v)
28367+ movl %ecx, 4(v)
28368+RET_ENDP
28369 #undef v
28370
28371 #define v %esi
28372@@ -70,6 +78,20 @@ RET_ENDP
28373 BEGIN(add)
28374 addl %eax, (v)
28375 adcl %edx, 4(v)
28376+
28377+#ifdef CONFIG_PAX_REFCOUNT
28378+ jno 0f
28379+ subl %eax, (v)
28380+ sbbl %edx, 4(v)
28381+ int $4
28382+0:
28383+ _ASM_EXTABLE(0b, 0b)
28384+#endif
28385+
28386+RET_ENDP
28387+BEGIN(add_unchecked)
28388+ addl %eax, (v)
28389+ adcl %edx, 4(v)
28390 RET_ENDP
28391 #undef v
28392
28393@@ -77,6 +99,24 @@ RET_ENDP
28394 BEGIN(add_return)
28395 addl (v), %eax
28396 adcl 4(v), %edx
28397+
28398+#ifdef CONFIG_PAX_REFCOUNT
28399+ into
28400+1234:
28401+ _ASM_EXTABLE(1234b, 2f)
28402+#endif
28403+
28404+ movl %eax, (v)
28405+ movl %edx, 4(v)
28406+
28407+#ifdef CONFIG_PAX_REFCOUNT
28408+2:
28409+#endif
28410+
28411+RET_ENDP
28412+BEGIN(add_return_unchecked)
28413+ addl (v), %eax
28414+ adcl 4(v), %edx
28415 movl %eax, (v)
28416 movl %edx, 4(v)
28417 RET_ENDP
28418@@ -86,6 +126,20 @@ RET_ENDP
28419 BEGIN(sub)
28420 subl %eax, (v)
28421 sbbl %edx, 4(v)
28422+
28423+#ifdef CONFIG_PAX_REFCOUNT
28424+ jno 0f
28425+ addl %eax, (v)
28426+ adcl %edx, 4(v)
28427+ int $4
28428+0:
28429+ _ASM_EXTABLE(0b, 0b)
28430+#endif
28431+
28432+RET_ENDP
28433+BEGIN(sub_unchecked)
28434+ subl %eax, (v)
28435+ sbbl %edx, 4(v)
28436 RET_ENDP
28437 #undef v
28438
28439@@ -96,6 +150,27 @@ BEGIN(sub_return)
28440 sbbl $0, %edx
28441 addl (v), %eax
28442 adcl 4(v), %edx
28443+
28444+#ifdef CONFIG_PAX_REFCOUNT
28445+ into
28446+1234:
28447+ _ASM_EXTABLE(1234b, 2f)
28448+#endif
28449+
28450+ movl %eax, (v)
28451+ movl %edx, 4(v)
28452+
28453+#ifdef CONFIG_PAX_REFCOUNT
28454+2:
28455+#endif
28456+
28457+RET_ENDP
28458+BEGIN(sub_return_unchecked)
28459+ negl %edx
28460+ negl %eax
28461+ sbbl $0, %edx
28462+ addl (v), %eax
28463+ adcl 4(v), %edx
28464 movl %eax, (v)
28465 movl %edx, 4(v)
28466 RET_ENDP
28467@@ -105,6 +180,20 @@ RET_ENDP
28468 BEGIN(inc)
28469 addl $1, (v)
28470 adcl $0, 4(v)
28471+
28472+#ifdef CONFIG_PAX_REFCOUNT
28473+ jno 0f
28474+ subl $1, (v)
28475+ sbbl $0, 4(v)
28476+ int $4
28477+0:
28478+ _ASM_EXTABLE(0b, 0b)
28479+#endif
28480+
28481+RET_ENDP
28482+BEGIN(inc_unchecked)
28483+ addl $1, (v)
28484+ adcl $0, 4(v)
28485 RET_ENDP
28486 #undef v
28487
28488@@ -114,6 +203,26 @@ BEGIN(inc_return)
28489 movl 4(v), %edx
28490 addl $1, %eax
28491 adcl $0, %edx
28492+
28493+#ifdef CONFIG_PAX_REFCOUNT
28494+ into
28495+1234:
28496+ _ASM_EXTABLE(1234b, 2f)
28497+#endif
28498+
28499+ movl %eax, (v)
28500+ movl %edx, 4(v)
28501+
28502+#ifdef CONFIG_PAX_REFCOUNT
28503+2:
28504+#endif
28505+
28506+RET_ENDP
28507+BEGIN(inc_return_unchecked)
28508+ movl (v), %eax
28509+ movl 4(v), %edx
28510+ addl $1, %eax
28511+ adcl $0, %edx
28512 movl %eax, (v)
28513 movl %edx, 4(v)
28514 RET_ENDP
28515@@ -123,6 +232,20 @@ RET_ENDP
28516 BEGIN(dec)
28517 subl $1, (v)
28518 sbbl $0, 4(v)
28519+
28520+#ifdef CONFIG_PAX_REFCOUNT
28521+ jno 0f
28522+ addl $1, (v)
28523+ adcl $0, 4(v)
28524+ int $4
28525+0:
28526+ _ASM_EXTABLE(0b, 0b)
28527+#endif
28528+
28529+RET_ENDP
28530+BEGIN(dec_unchecked)
28531+ subl $1, (v)
28532+ sbbl $0, 4(v)
28533 RET_ENDP
28534 #undef v
28535
28536@@ -132,6 +255,26 @@ BEGIN(dec_return)
28537 movl 4(v), %edx
28538 subl $1, %eax
28539 sbbl $0, %edx
28540+
28541+#ifdef CONFIG_PAX_REFCOUNT
28542+ into
28543+1234:
28544+ _ASM_EXTABLE(1234b, 2f)
28545+#endif
28546+
28547+ movl %eax, (v)
28548+ movl %edx, 4(v)
28549+
28550+#ifdef CONFIG_PAX_REFCOUNT
28551+2:
28552+#endif
28553+
28554+RET_ENDP
28555+BEGIN(dec_return_unchecked)
28556+ movl (v), %eax
28557+ movl 4(v), %edx
28558+ subl $1, %eax
28559+ sbbl $0, %edx
28560 movl %eax, (v)
28561 movl %edx, 4(v)
28562 RET_ENDP
28563@@ -143,6 +286,13 @@ BEGIN(add_unless)
28564 adcl %edx, %edi
28565 addl (v), %eax
28566 adcl 4(v), %edx
28567+
28568+#ifdef CONFIG_PAX_REFCOUNT
28569+ into
28570+1234:
28571+ _ASM_EXTABLE(1234b, 2f)
28572+#endif
28573+
28574 cmpl %eax, %ecx
28575 je 3f
28576 1:
28577@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28578 1:
28579 addl $1, %eax
28580 adcl $0, %edx
28581+
28582+#ifdef CONFIG_PAX_REFCOUNT
28583+ into
28584+1234:
28585+ _ASM_EXTABLE(1234b, 2f)
28586+#endif
28587+
28588 movl %eax, (v)
28589 movl %edx, 4(v)
28590 movl $1, %eax
28591@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28592 movl 4(v), %edx
28593 subl $1, %eax
28594 sbbl $0, %edx
28595+
28596+#ifdef CONFIG_PAX_REFCOUNT
28597+ into
28598+1234:
28599+ _ASM_EXTABLE(1234b, 1f)
28600+#endif
28601+
28602 js 1f
28603 movl %eax, (v)
28604 movl %edx, 4(v)
28605diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28606index f5cc9eb..51fa319 100644
28607--- a/arch/x86/lib/atomic64_cx8_32.S
28608+++ b/arch/x86/lib/atomic64_cx8_32.S
28609@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28610 CFI_STARTPROC
28611
28612 read64 %ecx
28613+ pax_force_retaddr
28614 ret
28615 CFI_ENDPROC
28616 ENDPROC(atomic64_read_cx8)
28617
28618+ENTRY(atomic64_read_unchecked_cx8)
28619+ CFI_STARTPROC
28620+
28621+ read64 %ecx
28622+ pax_force_retaddr
28623+ ret
28624+ CFI_ENDPROC
28625+ENDPROC(atomic64_read_unchecked_cx8)
28626+
28627 ENTRY(atomic64_set_cx8)
28628 CFI_STARTPROC
28629
28630@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28631 cmpxchg8b (%esi)
28632 jne 1b
28633
28634+ pax_force_retaddr
28635 ret
28636 CFI_ENDPROC
28637 ENDPROC(atomic64_set_cx8)
28638
28639+ENTRY(atomic64_set_unchecked_cx8)
28640+ CFI_STARTPROC
28641+
28642+1:
28643+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28644+ * are atomic on 586 and newer */
28645+ cmpxchg8b (%esi)
28646+ jne 1b
28647+
28648+ pax_force_retaddr
28649+ ret
28650+ CFI_ENDPROC
28651+ENDPROC(atomic64_set_unchecked_cx8)
28652+
28653 ENTRY(atomic64_xchg_cx8)
28654 CFI_STARTPROC
28655
28656@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28657 cmpxchg8b (%esi)
28658 jne 1b
28659
28660+ pax_force_retaddr
28661 ret
28662 CFI_ENDPROC
28663 ENDPROC(atomic64_xchg_cx8)
28664
28665-.macro addsub_return func ins insc
28666-ENTRY(atomic64_\func\()_return_cx8)
28667+.macro addsub_return func ins insc unchecked=""
28668+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28669 CFI_STARTPROC
28670 SAVE ebp
28671 SAVE ebx
28672@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28673 movl %edx, %ecx
28674 \ins\()l %esi, %ebx
28675 \insc\()l %edi, %ecx
28676+
28677+.ifb \unchecked
28678+#ifdef CONFIG_PAX_REFCOUNT
28679+ into
28680+2:
28681+ _ASM_EXTABLE(2b, 3f)
28682+#endif
28683+.endif
28684+
28685 LOCK_PREFIX
28686 cmpxchg8b (%ebp)
28687 jne 1b
28688-
28689-10:
28690 movl %ebx, %eax
28691 movl %ecx, %edx
28692+
28693+.ifb \unchecked
28694+#ifdef CONFIG_PAX_REFCOUNT
28695+3:
28696+#endif
28697+.endif
28698+
28699 RESTORE edi
28700 RESTORE esi
28701 RESTORE ebx
28702 RESTORE ebp
28703+ pax_force_retaddr
28704 ret
28705 CFI_ENDPROC
28706-ENDPROC(atomic64_\func\()_return_cx8)
28707+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28708 .endm
28709
28710 addsub_return add add adc
28711 addsub_return sub sub sbb
28712+addsub_return add add adc _unchecked
28713+addsub_return sub sub sbb _unchecked
28714
28715-.macro incdec_return func ins insc
28716-ENTRY(atomic64_\func\()_return_cx8)
28717+.macro incdec_return func ins insc unchecked=""
28718+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28719 CFI_STARTPROC
28720 SAVE ebx
28721
28722@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28723 movl %edx, %ecx
28724 \ins\()l $1, %ebx
28725 \insc\()l $0, %ecx
28726+
28727+.ifb \unchecked
28728+#ifdef CONFIG_PAX_REFCOUNT
28729+ into
28730+2:
28731+ _ASM_EXTABLE(2b, 3f)
28732+#endif
28733+.endif
28734+
28735 LOCK_PREFIX
28736 cmpxchg8b (%esi)
28737 jne 1b
28738
28739-10:
28740 movl %ebx, %eax
28741 movl %ecx, %edx
28742+
28743+.ifb \unchecked
28744+#ifdef CONFIG_PAX_REFCOUNT
28745+3:
28746+#endif
28747+.endif
28748+
28749 RESTORE ebx
28750+ pax_force_retaddr
28751 ret
28752 CFI_ENDPROC
28753-ENDPROC(atomic64_\func\()_return_cx8)
28754+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28755 .endm
28756
28757 incdec_return inc add adc
28758 incdec_return dec sub sbb
28759+incdec_return inc add adc _unchecked
28760+incdec_return dec sub sbb _unchecked
28761
28762 ENTRY(atomic64_dec_if_positive_cx8)
28763 CFI_STARTPROC
28764@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28765 movl %edx, %ecx
28766 subl $1, %ebx
28767 sbb $0, %ecx
28768+
28769+#ifdef CONFIG_PAX_REFCOUNT
28770+ into
28771+1234:
28772+ _ASM_EXTABLE(1234b, 2f)
28773+#endif
28774+
28775 js 2f
28776 LOCK_PREFIX
28777 cmpxchg8b (%esi)
28778@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28779 movl %ebx, %eax
28780 movl %ecx, %edx
28781 RESTORE ebx
28782+ pax_force_retaddr
28783 ret
28784 CFI_ENDPROC
28785 ENDPROC(atomic64_dec_if_positive_cx8)
28786@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28787 movl %edx, %ecx
28788 addl %ebp, %ebx
28789 adcl %edi, %ecx
28790+
28791+#ifdef CONFIG_PAX_REFCOUNT
28792+ into
28793+1234:
28794+ _ASM_EXTABLE(1234b, 3f)
28795+#endif
28796+
28797 LOCK_PREFIX
28798 cmpxchg8b (%esi)
28799 jne 1b
28800@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28801 CFI_ADJUST_CFA_OFFSET -8
28802 RESTORE ebx
28803 RESTORE ebp
28804+ pax_force_retaddr
28805 ret
28806 4:
28807 cmpl %edx, 4(%esp)
28808@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28809 xorl %ecx, %ecx
28810 addl $1, %ebx
28811 adcl %edx, %ecx
28812+
28813+#ifdef CONFIG_PAX_REFCOUNT
28814+ into
28815+1234:
28816+ _ASM_EXTABLE(1234b, 3f)
28817+#endif
28818+
28819 LOCK_PREFIX
28820 cmpxchg8b (%esi)
28821 jne 1b
28822@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28823 movl $1, %eax
28824 3:
28825 RESTORE ebx
28826+ pax_force_retaddr
28827 ret
28828 CFI_ENDPROC
28829 ENDPROC(atomic64_inc_not_zero_cx8)
28830diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28831index e78b8ee..7e173a8 100644
28832--- a/arch/x86/lib/checksum_32.S
28833+++ b/arch/x86/lib/checksum_32.S
28834@@ -29,7 +29,8 @@
28835 #include <asm/dwarf2.h>
28836 #include <asm/errno.h>
28837 #include <asm/asm.h>
28838-
28839+#include <asm/segment.h>
28840+
28841 /*
28842 * computes a partial checksum, e.g. for TCP/UDP fragments
28843 */
28844@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28845
28846 #define ARGBASE 16
28847 #define FP 12
28848-
28849-ENTRY(csum_partial_copy_generic)
28850+
28851+ENTRY(csum_partial_copy_generic_to_user)
28852 CFI_STARTPROC
28853+
28854+#ifdef CONFIG_PAX_MEMORY_UDEREF
28855+ pushl_cfi %gs
28856+ popl_cfi %es
28857+ jmp csum_partial_copy_generic
28858+#endif
28859+
28860+ENTRY(csum_partial_copy_generic_from_user)
28861+
28862+#ifdef CONFIG_PAX_MEMORY_UDEREF
28863+ pushl_cfi %gs
28864+ popl_cfi %ds
28865+#endif
28866+
28867+ENTRY(csum_partial_copy_generic)
28868 subl $4,%esp
28869 CFI_ADJUST_CFA_OFFSET 4
28870 pushl_cfi %edi
28871@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28872 jmp 4f
28873 SRC(1: movw (%esi), %bx )
28874 addl $2, %esi
28875-DST( movw %bx, (%edi) )
28876+DST( movw %bx, %es:(%edi) )
28877 addl $2, %edi
28878 addw %bx, %ax
28879 adcl $0, %eax
28880@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28881 SRC(1: movl (%esi), %ebx )
28882 SRC( movl 4(%esi), %edx )
28883 adcl %ebx, %eax
28884-DST( movl %ebx, (%edi) )
28885+DST( movl %ebx, %es:(%edi) )
28886 adcl %edx, %eax
28887-DST( movl %edx, 4(%edi) )
28888+DST( movl %edx, %es:4(%edi) )
28889
28890 SRC( movl 8(%esi), %ebx )
28891 SRC( movl 12(%esi), %edx )
28892 adcl %ebx, %eax
28893-DST( movl %ebx, 8(%edi) )
28894+DST( movl %ebx, %es:8(%edi) )
28895 adcl %edx, %eax
28896-DST( movl %edx, 12(%edi) )
28897+DST( movl %edx, %es:12(%edi) )
28898
28899 SRC( movl 16(%esi), %ebx )
28900 SRC( movl 20(%esi), %edx )
28901 adcl %ebx, %eax
28902-DST( movl %ebx, 16(%edi) )
28903+DST( movl %ebx, %es:16(%edi) )
28904 adcl %edx, %eax
28905-DST( movl %edx, 20(%edi) )
28906+DST( movl %edx, %es:20(%edi) )
28907
28908 SRC( movl 24(%esi), %ebx )
28909 SRC( movl 28(%esi), %edx )
28910 adcl %ebx, %eax
28911-DST( movl %ebx, 24(%edi) )
28912+DST( movl %ebx, %es:24(%edi) )
28913 adcl %edx, %eax
28914-DST( movl %edx, 28(%edi) )
28915+DST( movl %edx, %es:28(%edi) )
28916
28917 lea 32(%esi), %esi
28918 lea 32(%edi), %edi
28919@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28920 shrl $2, %edx # This clears CF
28921 SRC(3: movl (%esi), %ebx )
28922 adcl %ebx, %eax
28923-DST( movl %ebx, (%edi) )
28924+DST( movl %ebx, %es:(%edi) )
28925 lea 4(%esi), %esi
28926 lea 4(%edi), %edi
28927 dec %edx
28928@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28929 jb 5f
28930 SRC( movw (%esi), %cx )
28931 leal 2(%esi), %esi
28932-DST( movw %cx, (%edi) )
28933+DST( movw %cx, %es:(%edi) )
28934 leal 2(%edi), %edi
28935 je 6f
28936 shll $16,%ecx
28937 SRC(5: movb (%esi), %cl )
28938-DST( movb %cl, (%edi) )
28939+DST( movb %cl, %es:(%edi) )
28940 6: addl %ecx, %eax
28941 adcl $0, %eax
28942 7:
28943@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28944
28945 6001:
28946 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28947- movl $-EFAULT, (%ebx)
28948+ movl $-EFAULT, %ss:(%ebx)
28949
28950 # zero the complete destination - computing the rest
28951 # is too much work
28952@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28953
28954 6002:
28955 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28956- movl $-EFAULT,(%ebx)
28957+ movl $-EFAULT,%ss:(%ebx)
28958 jmp 5000b
28959
28960 .previous
28961
28962+ pushl_cfi %ss
28963+ popl_cfi %ds
28964+ pushl_cfi %ss
28965+ popl_cfi %es
28966 popl_cfi %ebx
28967 CFI_RESTORE ebx
28968 popl_cfi %esi
28969@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28970 popl_cfi %ecx # equivalent to addl $4,%esp
28971 ret
28972 CFI_ENDPROC
28973-ENDPROC(csum_partial_copy_generic)
28974+ENDPROC(csum_partial_copy_generic_to_user)
28975
28976 #else
28977
28978 /* Version for PentiumII/PPro */
28979
28980 #define ROUND1(x) \
28981+ nop; nop; nop; \
28982 SRC(movl x(%esi), %ebx ) ; \
28983 addl %ebx, %eax ; \
28984- DST(movl %ebx, x(%edi) ) ;
28985+ DST(movl %ebx, %es:x(%edi)) ;
28986
28987 #define ROUND(x) \
28988+ nop; nop; nop; \
28989 SRC(movl x(%esi), %ebx ) ; \
28990 adcl %ebx, %eax ; \
28991- DST(movl %ebx, x(%edi) ) ;
28992+ DST(movl %ebx, %es:x(%edi)) ;
28993
28994 #define ARGBASE 12
28995-
28996-ENTRY(csum_partial_copy_generic)
28997+
28998+ENTRY(csum_partial_copy_generic_to_user)
28999 CFI_STARTPROC
29000+
29001+#ifdef CONFIG_PAX_MEMORY_UDEREF
29002+ pushl_cfi %gs
29003+ popl_cfi %es
29004+ jmp csum_partial_copy_generic
29005+#endif
29006+
29007+ENTRY(csum_partial_copy_generic_from_user)
29008+
29009+#ifdef CONFIG_PAX_MEMORY_UDEREF
29010+ pushl_cfi %gs
29011+ popl_cfi %ds
29012+#endif
29013+
29014+ENTRY(csum_partial_copy_generic)
29015 pushl_cfi %ebx
29016 CFI_REL_OFFSET ebx, 0
29017 pushl_cfi %edi
29018@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29019 subl %ebx, %edi
29020 lea -1(%esi),%edx
29021 andl $-32,%edx
29022- lea 3f(%ebx,%ebx), %ebx
29023+ lea 3f(%ebx,%ebx,2), %ebx
29024 testl %esi, %esi
29025 jmp *%ebx
29026 1: addl $64,%esi
29027@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29028 jb 5f
29029 SRC( movw (%esi), %dx )
29030 leal 2(%esi), %esi
29031-DST( movw %dx, (%edi) )
29032+DST( movw %dx, %es:(%edi) )
29033 leal 2(%edi), %edi
29034 je 6f
29035 shll $16,%edx
29036 5:
29037 SRC( movb (%esi), %dl )
29038-DST( movb %dl, (%edi) )
29039+DST( movb %dl, %es:(%edi) )
29040 6: addl %edx, %eax
29041 adcl $0, %eax
29042 7:
29043 .section .fixup, "ax"
29044 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29045- movl $-EFAULT, (%ebx)
29046+ movl $-EFAULT, %ss:(%ebx)
29047 # zero the complete destination (computing the rest is too much work)
29048 movl ARGBASE+8(%esp),%edi # dst
29049 movl ARGBASE+12(%esp),%ecx # len
29050@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29051 rep; stosb
29052 jmp 7b
29053 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29054- movl $-EFAULT, (%ebx)
29055+ movl $-EFAULT, %ss:(%ebx)
29056 jmp 7b
29057 .previous
29058
29059+#ifdef CONFIG_PAX_MEMORY_UDEREF
29060+ pushl_cfi %ss
29061+ popl_cfi %ds
29062+ pushl_cfi %ss
29063+ popl_cfi %es
29064+#endif
29065+
29066 popl_cfi %esi
29067 CFI_RESTORE esi
29068 popl_cfi %edi
29069@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29070 CFI_RESTORE ebx
29071 ret
29072 CFI_ENDPROC
29073-ENDPROC(csum_partial_copy_generic)
29074+ENDPROC(csum_partial_copy_generic_to_user)
29075
29076 #undef ROUND
29077 #undef ROUND1
29078diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29079index f2145cf..cea889d 100644
29080--- a/arch/x86/lib/clear_page_64.S
29081+++ b/arch/x86/lib/clear_page_64.S
29082@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29083 movl $4096/8,%ecx
29084 xorl %eax,%eax
29085 rep stosq
29086+ pax_force_retaddr
29087 ret
29088 CFI_ENDPROC
29089 ENDPROC(clear_page_c)
29090@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29091 movl $4096,%ecx
29092 xorl %eax,%eax
29093 rep stosb
29094+ pax_force_retaddr
29095 ret
29096 CFI_ENDPROC
29097 ENDPROC(clear_page_c_e)
29098@@ -43,6 +45,7 @@ ENTRY(clear_page)
29099 leaq 64(%rdi),%rdi
29100 jnz .Lloop
29101 nop
29102+ pax_force_retaddr
29103 ret
29104 CFI_ENDPROC
29105 .Lclear_page_end:
29106@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29107
29108 #include <asm/cpufeature.h>
29109
29110- .section .altinstr_replacement,"ax"
29111+ .section .altinstr_replacement,"a"
29112 1: .byte 0xeb /* jmp <disp8> */
29113 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29114 2: .byte 0xeb /* jmp <disp8> */
29115diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29116index 1e572c5..2a162cd 100644
29117--- a/arch/x86/lib/cmpxchg16b_emu.S
29118+++ b/arch/x86/lib/cmpxchg16b_emu.S
29119@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29120
29121 popf
29122 mov $1, %al
29123+ pax_force_retaddr
29124 ret
29125
29126 not_same:
29127 popf
29128 xor %al,%al
29129+ pax_force_retaddr
29130 ret
29131
29132 CFI_ENDPROC
29133diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29134index 176cca6..e0d658e 100644
29135--- a/arch/x86/lib/copy_page_64.S
29136+++ b/arch/x86/lib/copy_page_64.S
29137@@ -9,6 +9,7 @@ copy_page_rep:
29138 CFI_STARTPROC
29139 movl $4096/8, %ecx
29140 rep movsq
29141+ pax_force_retaddr
29142 ret
29143 CFI_ENDPROC
29144 ENDPROC(copy_page_rep)
29145@@ -24,8 +25,8 @@ ENTRY(copy_page)
29146 CFI_ADJUST_CFA_OFFSET 2*8
29147 movq %rbx, (%rsp)
29148 CFI_REL_OFFSET rbx, 0
29149- movq %r12, 1*8(%rsp)
29150- CFI_REL_OFFSET r12, 1*8
29151+ movq %r13, 1*8(%rsp)
29152+ CFI_REL_OFFSET r13, 1*8
29153
29154 movl $(4096/64)-5, %ecx
29155 .p2align 4
29156@@ -38,7 +39,7 @@ ENTRY(copy_page)
29157 movq 0x8*4(%rsi), %r9
29158 movq 0x8*5(%rsi), %r10
29159 movq 0x8*6(%rsi), %r11
29160- movq 0x8*7(%rsi), %r12
29161+ movq 0x8*7(%rsi), %r13
29162
29163 prefetcht0 5*64(%rsi)
29164
29165@@ -49,7 +50,7 @@ ENTRY(copy_page)
29166 movq %r9, 0x8*4(%rdi)
29167 movq %r10, 0x8*5(%rdi)
29168 movq %r11, 0x8*6(%rdi)
29169- movq %r12, 0x8*7(%rdi)
29170+ movq %r13, 0x8*7(%rdi)
29171
29172 leaq 64 (%rsi), %rsi
29173 leaq 64 (%rdi), %rdi
29174@@ -68,7 +69,7 @@ ENTRY(copy_page)
29175 movq 0x8*4(%rsi), %r9
29176 movq 0x8*5(%rsi), %r10
29177 movq 0x8*6(%rsi), %r11
29178- movq 0x8*7(%rsi), %r12
29179+ movq 0x8*7(%rsi), %r13
29180
29181 movq %rax, 0x8*0(%rdi)
29182 movq %rbx, 0x8*1(%rdi)
29183@@ -77,7 +78,7 @@ ENTRY(copy_page)
29184 movq %r9, 0x8*4(%rdi)
29185 movq %r10, 0x8*5(%rdi)
29186 movq %r11, 0x8*6(%rdi)
29187- movq %r12, 0x8*7(%rdi)
29188+ movq %r13, 0x8*7(%rdi)
29189
29190 leaq 64(%rdi), %rdi
29191 leaq 64(%rsi), %rsi
29192@@ -85,10 +86,11 @@ ENTRY(copy_page)
29193
29194 movq (%rsp), %rbx
29195 CFI_RESTORE rbx
29196- movq 1*8(%rsp), %r12
29197- CFI_RESTORE r12
29198+ movq 1*8(%rsp), %r13
29199+ CFI_RESTORE r13
29200 addq $2*8, %rsp
29201 CFI_ADJUST_CFA_OFFSET -2*8
29202+ pax_force_retaddr
29203 ret
29204 .Lcopy_page_end:
29205 CFI_ENDPROC
29206@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29207
29208 #include <asm/cpufeature.h>
29209
29210- .section .altinstr_replacement,"ax"
29211+ .section .altinstr_replacement,"a"
29212 1: .byte 0xeb /* jmp <disp8> */
29213 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29214 2:
29215diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29216index a30ca15..407412b 100644
29217--- a/arch/x86/lib/copy_user_64.S
29218+++ b/arch/x86/lib/copy_user_64.S
29219@@ -18,31 +18,7 @@
29220 #include <asm/alternative-asm.h>
29221 #include <asm/asm.h>
29222 #include <asm/smap.h>
29223-
29224-/*
29225- * By placing feature2 after feature1 in altinstructions section, we logically
29226- * implement:
29227- * If CPU has feature2, jmp to alt2 is used
29228- * else if CPU has feature1, jmp to alt1 is used
29229- * else jmp to orig is used.
29230- */
29231- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29232-0:
29233- .byte 0xe9 /* 32bit jump */
29234- .long \orig-1f /* by default jump to orig */
29235-1:
29236- .section .altinstr_replacement,"ax"
29237-2: .byte 0xe9 /* near jump with 32bit immediate */
29238- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29239-3: .byte 0xe9 /* near jump with 32bit immediate */
29240- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29241- .previous
29242-
29243- .section .altinstructions,"a"
29244- altinstruction_entry 0b,2b,\feature1,5,5
29245- altinstruction_entry 0b,3b,\feature2,5,5
29246- .previous
29247- .endm
29248+#include <asm/pgtable.h>
29249
29250 .macro ALIGN_DESTINATION
29251 #ifdef FIX_ALIGNMENT
29252@@ -70,52 +46,6 @@
29253 #endif
29254 .endm
29255
29256-/* Standard copy_to_user with segment limit checking */
29257-ENTRY(_copy_to_user)
29258- CFI_STARTPROC
29259- GET_THREAD_INFO(%rax)
29260- movq %rdi,%rcx
29261- addq %rdx,%rcx
29262- jc bad_to_user
29263- cmpq TI_addr_limit(%rax),%rcx
29264- ja bad_to_user
29265- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29266- copy_user_generic_unrolled,copy_user_generic_string, \
29267- copy_user_enhanced_fast_string
29268- CFI_ENDPROC
29269-ENDPROC(_copy_to_user)
29270-
29271-/* Standard copy_from_user with segment limit checking */
29272-ENTRY(_copy_from_user)
29273- CFI_STARTPROC
29274- GET_THREAD_INFO(%rax)
29275- movq %rsi,%rcx
29276- addq %rdx,%rcx
29277- jc bad_from_user
29278- cmpq TI_addr_limit(%rax),%rcx
29279- ja bad_from_user
29280- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29281- copy_user_generic_unrolled,copy_user_generic_string, \
29282- copy_user_enhanced_fast_string
29283- CFI_ENDPROC
29284-ENDPROC(_copy_from_user)
29285-
29286- .section .fixup,"ax"
29287- /* must zero dest */
29288-ENTRY(bad_from_user)
29289-bad_from_user:
29290- CFI_STARTPROC
29291- movl %edx,%ecx
29292- xorl %eax,%eax
29293- rep
29294- stosb
29295-bad_to_user:
29296- movl %edx,%eax
29297- ret
29298- CFI_ENDPROC
29299-ENDPROC(bad_from_user)
29300- .previous
29301-
29302 /*
29303 * copy_user_generic_unrolled - memory copy with exception handling.
29304 * This version is for CPUs like P4 that don't have efficient micro
29305@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29306 */
29307 ENTRY(copy_user_generic_unrolled)
29308 CFI_STARTPROC
29309+ ASM_PAX_OPEN_USERLAND
29310 ASM_STAC
29311 cmpl $8,%edx
29312 jb 20f /* less then 8 bytes, go to byte copy loop */
29313@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29314 jnz 21b
29315 23: xor %eax,%eax
29316 ASM_CLAC
29317+ ASM_PAX_CLOSE_USERLAND
29318+ pax_force_retaddr
29319 ret
29320
29321 .section .fixup,"ax"
29322@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29323 */
29324 ENTRY(copy_user_generic_string)
29325 CFI_STARTPROC
29326+ ASM_PAX_OPEN_USERLAND
29327 ASM_STAC
29328 andl %edx,%edx
29329 jz 4f
29330@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29331 movsb
29332 4: xorl %eax,%eax
29333 ASM_CLAC
29334+ ASM_PAX_CLOSE_USERLAND
29335+ pax_force_retaddr
29336 ret
29337
29338 .section .fixup,"ax"
29339@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29340 */
29341 ENTRY(copy_user_enhanced_fast_string)
29342 CFI_STARTPROC
29343+ ASM_PAX_OPEN_USERLAND
29344 ASM_STAC
29345 andl %edx,%edx
29346 jz 2f
29347@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29348 movsb
29349 2: xorl %eax,%eax
29350 ASM_CLAC
29351+ ASM_PAX_CLOSE_USERLAND
29352+ pax_force_retaddr
29353 ret
29354
29355 .section .fixup,"ax"
29356diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29357index 6a4f43c..c70fb52 100644
29358--- a/arch/x86/lib/copy_user_nocache_64.S
29359+++ b/arch/x86/lib/copy_user_nocache_64.S
29360@@ -8,6 +8,7 @@
29361
29362 #include <linux/linkage.h>
29363 #include <asm/dwarf2.h>
29364+#include <asm/alternative-asm.h>
29365
29366 #define FIX_ALIGNMENT 1
29367
29368@@ -16,6 +17,7 @@
29369 #include <asm/thread_info.h>
29370 #include <asm/asm.h>
29371 #include <asm/smap.h>
29372+#include <asm/pgtable.h>
29373
29374 .macro ALIGN_DESTINATION
29375 #ifdef FIX_ALIGNMENT
29376@@ -49,6 +51,16 @@
29377 */
29378 ENTRY(__copy_user_nocache)
29379 CFI_STARTPROC
29380+
29381+#ifdef CONFIG_PAX_MEMORY_UDEREF
29382+ mov pax_user_shadow_base,%rcx
29383+ cmp %rcx,%rsi
29384+ jae 1f
29385+ add %rcx,%rsi
29386+1:
29387+#endif
29388+
29389+ ASM_PAX_OPEN_USERLAND
29390 ASM_STAC
29391 cmpl $8,%edx
29392 jb 20f /* less then 8 bytes, go to byte copy loop */
29393@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29394 jnz 21b
29395 23: xorl %eax,%eax
29396 ASM_CLAC
29397+ ASM_PAX_CLOSE_USERLAND
29398 sfence
29399+ pax_force_retaddr
29400 ret
29401
29402 .section .fixup,"ax"
29403diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29404index 2419d5f..fe52d0e 100644
29405--- a/arch/x86/lib/csum-copy_64.S
29406+++ b/arch/x86/lib/csum-copy_64.S
29407@@ -9,6 +9,7 @@
29408 #include <asm/dwarf2.h>
29409 #include <asm/errno.h>
29410 #include <asm/asm.h>
29411+#include <asm/alternative-asm.h>
29412
29413 /*
29414 * Checksum copy with exception handling.
29415@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29416 CFI_ADJUST_CFA_OFFSET 7*8
29417 movq %rbx, 2*8(%rsp)
29418 CFI_REL_OFFSET rbx, 2*8
29419- movq %r12, 3*8(%rsp)
29420- CFI_REL_OFFSET r12, 3*8
29421+ movq %r15, 3*8(%rsp)
29422+ CFI_REL_OFFSET r15, 3*8
29423 movq %r14, 4*8(%rsp)
29424 CFI_REL_OFFSET r14, 4*8
29425 movq %r13, 5*8(%rsp)
29426@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29427 movl %edx, %ecx
29428
29429 xorl %r9d, %r9d
29430- movq %rcx, %r12
29431+ movq %rcx, %r15
29432
29433- shrq $6, %r12
29434+ shrq $6, %r15
29435 jz .Lhandle_tail /* < 64 */
29436
29437 clc
29438
29439 /* main loop. clear in 64 byte blocks */
29440 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29441- /* r11: temp3, rdx: temp4, r12 loopcnt */
29442+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29443 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29444 .p2align 4
29445 .Lloop:
29446@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29447 adcq %r14, %rax
29448 adcq %r13, %rax
29449
29450- decl %r12d
29451+ decl %r15d
29452
29453 dest
29454 movq %rbx, (%rsi)
29455@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29456 .Lende:
29457 movq 2*8(%rsp), %rbx
29458 CFI_RESTORE rbx
29459- movq 3*8(%rsp), %r12
29460- CFI_RESTORE r12
29461+ movq 3*8(%rsp), %r15
29462+ CFI_RESTORE r15
29463 movq 4*8(%rsp), %r14
29464 CFI_RESTORE r14
29465 movq 5*8(%rsp), %r13
29466@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29467 CFI_RESTORE rbp
29468 addq $7*8, %rsp
29469 CFI_ADJUST_CFA_OFFSET -7*8
29470+ pax_force_retaddr
29471 ret
29472 CFI_RESTORE_STATE
29473
29474diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29475index 7609e0e..b449b98 100644
29476--- a/arch/x86/lib/csum-wrappers_64.c
29477+++ b/arch/x86/lib/csum-wrappers_64.c
29478@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29479 len -= 2;
29480 }
29481 }
29482+ pax_open_userland();
29483 stac();
29484- isum = csum_partial_copy_generic((__force const void *)src,
29485+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29486 dst, len, isum, errp, NULL);
29487 clac();
29488+ pax_close_userland();
29489 if (unlikely(*errp))
29490 goto out_err;
29491
29492@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29493 }
29494
29495 *errp = 0;
29496+ pax_open_userland();
29497 stac();
29498- ret = csum_partial_copy_generic(src, (void __force *)dst,
29499+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29500 len, isum, NULL, errp);
29501 clac();
29502+ pax_close_userland();
29503 return ret;
29504 }
29505 EXPORT_SYMBOL(csum_partial_copy_to_user);
29506diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29507index a451235..1daa956 100644
29508--- a/arch/x86/lib/getuser.S
29509+++ b/arch/x86/lib/getuser.S
29510@@ -33,17 +33,40 @@
29511 #include <asm/thread_info.h>
29512 #include <asm/asm.h>
29513 #include <asm/smap.h>
29514+#include <asm/segment.h>
29515+#include <asm/pgtable.h>
29516+#include <asm/alternative-asm.h>
29517+
29518+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29519+#define __copyuser_seg gs;
29520+#else
29521+#define __copyuser_seg
29522+#endif
29523
29524 .text
29525 ENTRY(__get_user_1)
29526 CFI_STARTPROC
29527+
29528+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29529 GET_THREAD_INFO(%_ASM_DX)
29530 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29531 jae bad_get_user
29532 ASM_STAC
29533-1: movzbl (%_ASM_AX),%edx
29534+
29535+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29536+ mov pax_user_shadow_base,%_ASM_DX
29537+ cmp %_ASM_DX,%_ASM_AX
29538+ jae 1234f
29539+ add %_ASM_DX,%_ASM_AX
29540+1234:
29541+#endif
29542+
29543+#endif
29544+
29545+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29546 xor %eax,%eax
29547 ASM_CLAC
29548+ pax_force_retaddr
29549 ret
29550 CFI_ENDPROC
29551 ENDPROC(__get_user_1)
29552@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29553 ENTRY(__get_user_2)
29554 CFI_STARTPROC
29555 add $1,%_ASM_AX
29556+
29557+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29558 jc bad_get_user
29559 GET_THREAD_INFO(%_ASM_DX)
29560 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29561 jae bad_get_user
29562 ASM_STAC
29563-2: movzwl -1(%_ASM_AX),%edx
29564+
29565+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29566+ mov pax_user_shadow_base,%_ASM_DX
29567+ cmp %_ASM_DX,%_ASM_AX
29568+ jae 1234f
29569+ add %_ASM_DX,%_ASM_AX
29570+1234:
29571+#endif
29572+
29573+#endif
29574+
29575+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29576 xor %eax,%eax
29577 ASM_CLAC
29578+ pax_force_retaddr
29579 ret
29580 CFI_ENDPROC
29581 ENDPROC(__get_user_2)
29582@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29583 ENTRY(__get_user_4)
29584 CFI_STARTPROC
29585 add $3,%_ASM_AX
29586+
29587+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29588 jc bad_get_user
29589 GET_THREAD_INFO(%_ASM_DX)
29590 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29591 jae bad_get_user
29592 ASM_STAC
29593-3: movl -3(%_ASM_AX),%edx
29594+
29595+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29596+ mov pax_user_shadow_base,%_ASM_DX
29597+ cmp %_ASM_DX,%_ASM_AX
29598+ jae 1234f
29599+ add %_ASM_DX,%_ASM_AX
29600+1234:
29601+#endif
29602+
29603+#endif
29604+
29605+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29606 xor %eax,%eax
29607 ASM_CLAC
29608+ pax_force_retaddr
29609 ret
29610 CFI_ENDPROC
29611 ENDPROC(__get_user_4)
29612@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29613 GET_THREAD_INFO(%_ASM_DX)
29614 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29615 jae bad_get_user
29616+
29617+#ifdef CONFIG_PAX_MEMORY_UDEREF
29618+ mov pax_user_shadow_base,%_ASM_DX
29619+ cmp %_ASM_DX,%_ASM_AX
29620+ jae 1234f
29621+ add %_ASM_DX,%_ASM_AX
29622+1234:
29623+#endif
29624+
29625 ASM_STAC
29626 4: movq -7(%_ASM_AX),%rdx
29627 xor %eax,%eax
29628 ASM_CLAC
29629+ pax_force_retaddr
29630 ret
29631 #else
29632 add $7,%_ASM_AX
29633@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29634 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29635 jae bad_get_user_8
29636 ASM_STAC
29637-4: movl -7(%_ASM_AX),%edx
29638-5: movl -3(%_ASM_AX),%ecx
29639+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29640+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29641 xor %eax,%eax
29642 ASM_CLAC
29643+ pax_force_retaddr
29644 ret
29645 #endif
29646 CFI_ENDPROC
29647@@ -113,6 +175,7 @@ bad_get_user:
29648 xor %edx,%edx
29649 mov $(-EFAULT),%_ASM_AX
29650 ASM_CLAC
29651+ pax_force_retaddr
29652 ret
29653 CFI_ENDPROC
29654 END(bad_get_user)
29655@@ -124,6 +187,7 @@ bad_get_user_8:
29656 xor %ecx,%ecx
29657 mov $(-EFAULT),%_ASM_AX
29658 ASM_CLAC
29659+ pax_force_retaddr
29660 ret
29661 CFI_ENDPROC
29662 END(bad_get_user_8)
29663diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29664index 54fcffe..7be149e 100644
29665--- a/arch/x86/lib/insn.c
29666+++ b/arch/x86/lib/insn.c
29667@@ -20,8 +20,10 @@
29668
29669 #ifdef __KERNEL__
29670 #include <linux/string.h>
29671+#include <asm/pgtable_types.h>
29672 #else
29673 #include <string.h>
29674+#define ktla_ktva(addr) addr
29675 #endif
29676 #include <asm/inat.h>
29677 #include <asm/insn.h>
29678@@ -53,8 +55,8 @@
29679 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29680 {
29681 memset(insn, 0, sizeof(*insn));
29682- insn->kaddr = kaddr;
29683- insn->next_byte = kaddr;
29684+ insn->kaddr = ktla_ktva(kaddr);
29685+ insn->next_byte = ktla_ktva(kaddr);
29686 insn->x86_64 = x86_64 ? 1 : 0;
29687 insn->opnd_bytes = 4;
29688 if (x86_64)
29689diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29690index 05a95e7..326f2fa 100644
29691--- a/arch/x86/lib/iomap_copy_64.S
29692+++ b/arch/x86/lib/iomap_copy_64.S
29693@@ -17,6 +17,7 @@
29694
29695 #include <linux/linkage.h>
29696 #include <asm/dwarf2.h>
29697+#include <asm/alternative-asm.h>
29698
29699 /*
29700 * override generic version in lib/iomap_copy.c
29701@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29702 CFI_STARTPROC
29703 movl %edx,%ecx
29704 rep movsd
29705+ pax_force_retaddr
29706 ret
29707 CFI_ENDPROC
29708 ENDPROC(__iowrite32_copy)
29709diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29710index 56313a3..0db417e 100644
29711--- a/arch/x86/lib/memcpy_64.S
29712+++ b/arch/x86/lib/memcpy_64.S
29713@@ -24,7 +24,7 @@
29714 * This gets patched over the unrolled variant (below) via the
29715 * alternative instructions framework:
29716 */
29717- .section .altinstr_replacement, "ax", @progbits
29718+ .section .altinstr_replacement, "a", @progbits
29719 .Lmemcpy_c:
29720 movq %rdi, %rax
29721 movq %rdx, %rcx
29722@@ -33,6 +33,7 @@
29723 rep movsq
29724 movl %edx, %ecx
29725 rep movsb
29726+ pax_force_retaddr
29727 ret
29728 .Lmemcpy_e:
29729 .previous
29730@@ -44,11 +45,12 @@
29731 * This gets patched over the unrolled variant (below) via the
29732 * alternative instructions framework:
29733 */
29734- .section .altinstr_replacement, "ax", @progbits
29735+ .section .altinstr_replacement, "a", @progbits
29736 .Lmemcpy_c_e:
29737 movq %rdi, %rax
29738 movq %rdx, %rcx
29739 rep movsb
29740+ pax_force_retaddr
29741 ret
29742 .Lmemcpy_e_e:
29743 .previous
29744@@ -136,6 +138,7 @@ ENTRY(memcpy)
29745 movq %r9, 1*8(%rdi)
29746 movq %r10, -2*8(%rdi, %rdx)
29747 movq %r11, -1*8(%rdi, %rdx)
29748+ pax_force_retaddr
29749 retq
29750 .p2align 4
29751 .Lless_16bytes:
29752@@ -148,6 +151,7 @@ ENTRY(memcpy)
29753 movq -1*8(%rsi, %rdx), %r9
29754 movq %r8, 0*8(%rdi)
29755 movq %r9, -1*8(%rdi, %rdx)
29756+ pax_force_retaddr
29757 retq
29758 .p2align 4
29759 .Lless_8bytes:
29760@@ -161,6 +165,7 @@ ENTRY(memcpy)
29761 movl -4(%rsi, %rdx), %r8d
29762 movl %ecx, (%rdi)
29763 movl %r8d, -4(%rdi, %rdx)
29764+ pax_force_retaddr
29765 retq
29766 .p2align 4
29767 .Lless_3bytes:
29768@@ -179,6 +184,7 @@ ENTRY(memcpy)
29769 movb %cl, (%rdi)
29770
29771 .Lend:
29772+ pax_force_retaddr
29773 retq
29774 CFI_ENDPROC
29775 ENDPROC(memcpy)
29776diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29777index 65268a6..dd1de11 100644
29778--- a/arch/x86/lib/memmove_64.S
29779+++ b/arch/x86/lib/memmove_64.S
29780@@ -202,14 +202,16 @@ ENTRY(memmove)
29781 movb (%rsi), %r11b
29782 movb %r11b, (%rdi)
29783 13:
29784+ pax_force_retaddr
29785 retq
29786 CFI_ENDPROC
29787
29788- .section .altinstr_replacement,"ax"
29789+ .section .altinstr_replacement,"a"
29790 .Lmemmove_begin_forward_efs:
29791 /* Forward moving data. */
29792 movq %rdx, %rcx
29793 rep movsb
29794+ pax_force_retaddr
29795 retq
29796 .Lmemmove_end_forward_efs:
29797 .previous
29798diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29799index 2dcb380..2eb79fe 100644
29800--- a/arch/x86/lib/memset_64.S
29801+++ b/arch/x86/lib/memset_64.S
29802@@ -16,7 +16,7 @@
29803 *
29804 * rax original destination
29805 */
29806- .section .altinstr_replacement, "ax", @progbits
29807+ .section .altinstr_replacement, "a", @progbits
29808 .Lmemset_c:
29809 movq %rdi,%r9
29810 movq %rdx,%rcx
29811@@ -30,6 +30,7 @@
29812 movl %edx,%ecx
29813 rep stosb
29814 movq %r9,%rax
29815+ pax_force_retaddr
29816 ret
29817 .Lmemset_e:
29818 .previous
29819@@ -45,13 +46,14 @@
29820 *
29821 * rax original destination
29822 */
29823- .section .altinstr_replacement, "ax", @progbits
29824+ .section .altinstr_replacement, "a", @progbits
29825 .Lmemset_c_e:
29826 movq %rdi,%r9
29827 movb %sil,%al
29828 movq %rdx,%rcx
29829 rep stosb
29830 movq %r9,%rax
29831+ pax_force_retaddr
29832 ret
29833 .Lmemset_e_e:
29834 .previous
29835@@ -118,6 +120,7 @@ ENTRY(__memset)
29836
29837 .Lende:
29838 movq %r10,%rax
29839+ pax_force_retaddr
29840 ret
29841
29842 CFI_RESTORE_STATE
29843diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29844index c9f2d9b..e7fd2c0 100644
29845--- a/arch/x86/lib/mmx_32.c
29846+++ b/arch/x86/lib/mmx_32.c
29847@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29848 {
29849 void *p;
29850 int i;
29851+ unsigned long cr0;
29852
29853 if (unlikely(in_interrupt()))
29854 return __memcpy(to, from, len);
29855@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29856 kernel_fpu_begin();
29857
29858 __asm__ __volatile__ (
29859- "1: prefetch (%0)\n" /* This set is 28 bytes */
29860- " prefetch 64(%0)\n"
29861- " prefetch 128(%0)\n"
29862- " prefetch 192(%0)\n"
29863- " prefetch 256(%0)\n"
29864+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29865+ " prefetch 64(%1)\n"
29866+ " prefetch 128(%1)\n"
29867+ " prefetch 192(%1)\n"
29868+ " prefetch 256(%1)\n"
29869 "2: \n"
29870 ".section .fixup, \"ax\"\n"
29871- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29872+ "3: \n"
29873+
29874+#ifdef CONFIG_PAX_KERNEXEC
29875+ " movl %%cr0, %0\n"
29876+ " movl %0, %%eax\n"
29877+ " andl $0xFFFEFFFF, %%eax\n"
29878+ " movl %%eax, %%cr0\n"
29879+#endif
29880+
29881+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29882+
29883+#ifdef CONFIG_PAX_KERNEXEC
29884+ " movl %0, %%cr0\n"
29885+#endif
29886+
29887 " jmp 2b\n"
29888 ".previous\n"
29889 _ASM_EXTABLE(1b, 3b)
29890- : : "r" (from));
29891+ : "=&r" (cr0) : "r" (from) : "ax");
29892
29893 for ( ; i > 5; i--) {
29894 __asm__ __volatile__ (
29895- "1: prefetch 320(%0)\n"
29896- "2: movq (%0), %%mm0\n"
29897- " movq 8(%0), %%mm1\n"
29898- " movq 16(%0), %%mm2\n"
29899- " movq 24(%0), %%mm3\n"
29900- " movq %%mm0, (%1)\n"
29901- " movq %%mm1, 8(%1)\n"
29902- " movq %%mm2, 16(%1)\n"
29903- " movq %%mm3, 24(%1)\n"
29904- " movq 32(%0), %%mm0\n"
29905- " movq 40(%0), %%mm1\n"
29906- " movq 48(%0), %%mm2\n"
29907- " movq 56(%0), %%mm3\n"
29908- " movq %%mm0, 32(%1)\n"
29909- " movq %%mm1, 40(%1)\n"
29910- " movq %%mm2, 48(%1)\n"
29911- " movq %%mm3, 56(%1)\n"
29912+ "1: prefetch 320(%1)\n"
29913+ "2: movq (%1), %%mm0\n"
29914+ " movq 8(%1), %%mm1\n"
29915+ " movq 16(%1), %%mm2\n"
29916+ " movq 24(%1), %%mm3\n"
29917+ " movq %%mm0, (%2)\n"
29918+ " movq %%mm1, 8(%2)\n"
29919+ " movq %%mm2, 16(%2)\n"
29920+ " movq %%mm3, 24(%2)\n"
29921+ " movq 32(%1), %%mm0\n"
29922+ " movq 40(%1), %%mm1\n"
29923+ " movq 48(%1), %%mm2\n"
29924+ " movq 56(%1), %%mm3\n"
29925+ " movq %%mm0, 32(%2)\n"
29926+ " movq %%mm1, 40(%2)\n"
29927+ " movq %%mm2, 48(%2)\n"
29928+ " movq %%mm3, 56(%2)\n"
29929 ".section .fixup, \"ax\"\n"
29930- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29931+ "3:\n"
29932+
29933+#ifdef CONFIG_PAX_KERNEXEC
29934+ " movl %%cr0, %0\n"
29935+ " movl %0, %%eax\n"
29936+ " andl $0xFFFEFFFF, %%eax\n"
29937+ " movl %%eax, %%cr0\n"
29938+#endif
29939+
29940+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29941+
29942+#ifdef CONFIG_PAX_KERNEXEC
29943+ " movl %0, %%cr0\n"
29944+#endif
29945+
29946 " jmp 2b\n"
29947 ".previous\n"
29948 _ASM_EXTABLE(1b, 3b)
29949- : : "r" (from), "r" (to) : "memory");
29950+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29951
29952 from += 64;
29953 to += 64;
29954@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29955 static void fast_copy_page(void *to, void *from)
29956 {
29957 int i;
29958+ unsigned long cr0;
29959
29960 kernel_fpu_begin();
29961
29962@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29963 * but that is for later. -AV
29964 */
29965 __asm__ __volatile__(
29966- "1: prefetch (%0)\n"
29967- " prefetch 64(%0)\n"
29968- " prefetch 128(%0)\n"
29969- " prefetch 192(%0)\n"
29970- " prefetch 256(%0)\n"
29971+ "1: prefetch (%1)\n"
29972+ " prefetch 64(%1)\n"
29973+ " prefetch 128(%1)\n"
29974+ " prefetch 192(%1)\n"
29975+ " prefetch 256(%1)\n"
29976 "2: \n"
29977 ".section .fixup, \"ax\"\n"
29978- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29979+ "3: \n"
29980+
29981+#ifdef CONFIG_PAX_KERNEXEC
29982+ " movl %%cr0, %0\n"
29983+ " movl %0, %%eax\n"
29984+ " andl $0xFFFEFFFF, %%eax\n"
29985+ " movl %%eax, %%cr0\n"
29986+#endif
29987+
29988+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29989+
29990+#ifdef CONFIG_PAX_KERNEXEC
29991+ " movl %0, %%cr0\n"
29992+#endif
29993+
29994 " jmp 2b\n"
29995 ".previous\n"
29996- _ASM_EXTABLE(1b, 3b) : : "r" (from));
29997+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29998
29999 for (i = 0; i < (4096-320)/64; i++) {
30000 __asm__ __volatile__ (
30001- "1: prefetch 320(%0)\n"
30002- "2: movq (%0), %%mm0\n"
30003- " movntq %%mm0, (%1)\n"
30004- " movq 8(%0), %%mm1\n"
30005- " movntq %%mm1, 8(%1)\n"
30006- " movq 16(%0), %%mm2\n"
30007- " movntq %%mm2, 16(%1)\n"
30008- " movq 24(%0), %%mm3\n"
30009- " movntq %%mm3, 24(%1)\n"
30010- " movq 32(%0), %%mm4\n"
30011- " movntq %%mm4, 32(%1)\n"
30012- " movq 40(%0), %%mm5\n"
30013- " movntq %%mm5, 40(%1)\n"
30014- " movq 48(%0), %%mm6\n"
30015- " movntq %%mm6, 48(%1)\n"
30016- " movq 56(%0), %%mm7\n"
30017- " movntq %%mm7, 56(%1)\n"
30018+ "1: prefetch 320(%1)\n"
30019+ "2: movq (%1), %%mm0\n"
30020+ " movntq %%mm0, (%2)\n"
30021+ " movq 8(%1), %%mm1\n"
30022+ " movntq %%mm1, 8(%2)\n"
30023+ " movq 16(%1), %%mm2\n"
30024+ " movntq %%mm2, 16(%2)\n"
30025+ " movq 24(%1), %%mm3\n"
30026+ " movntq %%mm3, 24(%2)\n"
30027+ " movq 32(%1), %%mm4\n"
30028+ " movntq %%mm4, 32(%2)\n"
30029+ " movq 40(%1), %%mm5\n"
30030+ " movntq %%mm5, 40(%2)\n"
30031+ " movq 48(%1), %%mm6\n"
30032+ " movntq %%mm6, 48(%2)\n"
30033+ " movq 56(%1), %%mm7\n"
30034+ " movntq %%mm7, 56(%2)\n"
30035 ".section .fixup, \"ax\"\n"
30036- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30037+ "3:\n"
30038+
30039+#ifdef CONFIG_PAX_KERNEXEC
30040+ " movl %%cr0, %0\n"
30041+ " movl %0, %%eax\n"
30042+ " andl $0xFFFEFFFF, %%eax\n"
30043+ " movl %%eax, %%cr0\n"
30044+#endif
30045+
30046+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30047+
30048+#ifdef CONFIG_PAX_KERNEXEC
30049+ " movl %0, %%cr0\n"
30050+#endif
30051+
30052 " jmp 2b\n"
30053 ".previous\n"
30054- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30055+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30056
30057 from += 64;
30058 to += 64;
30059@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30060 static void fast_copy_page(void *to, void *from)
30061 {
30062 int i;
30063+ unsigned long cr0;
30064
30065 kernel_fpu_begin();
30066
30067 __asm__ __volatile__ (
30068- "1: prefetch (%0)\n"
30069- " prefetch 64(%0)\n"
30070- " prefetch 128(%0)\n"
30071- " prefetch 192(%0)\n"
30072- " prefetch 256(%0)\n"
30073+ "1: prefetch (%1)\n"
30074+ " prefetch 64(%1)\n"
30075+ " prefetch 128(%1)\n"
30076+ " prefetch 192(%1)\n"
30077+ " prefetch 256(%1)\n"
30078 "2: \n"
30079 ".section .fixup, \"ax\"\n"
30080- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30081+ "3: \n"
30082+
30083+#ifdef CONFIG_PAX_KERNEXEC
30084+ " movl %%cr0, %0\n"
30085+ " movl %0, %%eax\n"
30086+ " andl $0xFFFEFFFF, %%eax\n"
30087+ " movl %%eax, %%cr0\n"
30088+#endif
30089+
30090+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30091+
30092+#ifdef CONFIG_PAX_KERNEXEC
30093+ " movl %0, %%cr0\n"
30094+#endif
30095+
30096 " jmp 2b\n"
30097 ".previous\n"
30098- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30099+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30100
30101 for (i = 0; i < 4096/64; i++) {
30102 __asm__ __volatile__ (
30103- "1: prefetch 320(%0)\n"
30104- "2: movq (%0), %%mm0\n"
30105- " movq 8(%0), %%mm1\n"
30106- " movq 16(%0), %%mm2\n"
30107- " movq 24(%0), %%mm3\n"
30108- " movq %%mm0, (%1)\n"
30109- " movq %%mm1, 8(%1)\n"
30110- " movq %%mm2, 16(%1)\n"
30111- " movq %%mm3, 24(%1)\n"
30112- " movq 32(%0), %%mm0\n"
30113- " movq 40(%0), %%mm1\n"
30114- " movq 48(%0), %%mm2\n"
30115- " movq 56(%0), %%mm3\n"
30116- " movq %%mm0, 32(%1)\n"
30117- " movq %%mm1, 40(%1)\n"
30118- " movq %%mm2, 48(%1)\n"
30119- " movq %%mm3, 56(%1)\n"
30120+ "1: prefetch 320(%1)\n"
30121+ "2: movq (%1), %%mm0\n"
30122+ " movq 8(%1), %%mm1\n"
30123+ " movq 16(%1), %%mm2\n"
30124+ " movq 24(%1), %%mm3\n"
30125+ " movq %%mm0, (%2)\n"
30126+ " movq %%mm1, 8(%2)\n"
30127+ " movq %%mm2, 16(%2)\n"
30128+ " movq %%mm3, 24(%2)\n"
30129+ " movq 32(%1), %%mm0\n"
30130+ " movq 40(%1), %%mm1\n"
30131+ " movq 48(%1), %%mm2\n"
30132+ " movq 56(%1), %%mm3\n"
30133+ " movq %%mm0, 32(%2)\n"
30134+ " movq %%mm1, 40(%2)\n"
30135+ " movq %%mm2, 48(%2)\n"
30136+ " movq %%mm3, 56(%2)\n"
30137 ".section .fixup, \"ax\"\n"
30138- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30139+ "3:\n"
30140+
30141+#ifdef CONFIG_PAX_KERNEXEC
30142+ " movl %%cr0, %0\n"
30143+ " movl %0, %%eax\n"
30144+ " andl $0xFFFEFFFF, %%eax\n"
30145+ " movl %%eax, %%cr0\n"
30146+#endif
30147+
30148+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30149+
30150+#ifdef CONFIG_PAX_KERNEXEC
30151+ " movl %0, %%cr0\n"
30152+#endif
30153+
30154 " jmp 2b\n"
30155 ".previous\n"
30156 _ASM_EXTABLE(1b, 3b)
30157- : : "r" (from), "r" (to) : "memory");
30158+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30159
30160 from += 64;
30161 to += 64;
30162diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30163index f6d13ee..d789440 100644
30164--- a/arch/x86/lib/msr-reg.S
30165+++ b/arch/x86/lib/msr-reg.S
30166@@ -3,6 +3,7 @@
30167 #include <asm/dwarf2.h>
30168 #include <asm/asm.h>
30169 #include <asm/msr.h>
30170+#include <asm/alternative-asm.h>
30171
30172 #ifdef CONFIG_X86_64
30173 /*
30174@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30175 movl %edi, 28(%r10)
30176 popq_cfi %rbp
30177 popq_cfi %rbx
30178+ pax_force_retaddr
30179 ret
30180 3:
30181 CFI_RESTORE_STATE
30182diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30183index fc6ba17..d4d989d 100644
30184--- a/arch/x86/lib/putuser.S
30185+++ b/arch/x86/lib/putuser.S
30186@@ -16,7 +16,9 @@
30187 #include <asm/errno.h>
30188 #include <asm/asm.h>
30189 #include <asm/smap.h>
30190-
30191+#include <asm/segment.h>
30192+#include <asm/pgtable.h>
30193+#include <asm/alternative-asm.h>
30194
30195 /*
30196 * __put_user_X
30197@@ -30,57 +32,125 @@
30198 * as they get called from within inline assembly.
30199 */
30200
30201-#define ENTER CFI_STARTPROC ; \
30202- GET_THREAD_INFO(%_ASM_BX)
30203-#define EXIT ASM_CLAC ; \
30204- ret ; \
30205+#define ENTER CFI_STARTPROC
30206+#define EXIT ASM_CLAC ; \
30207+ pax_force_retaddr ; \
30208+ ret ; \
30209 CFI_ENDPROC
30210
30211+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30212+#define _DEST %_ASM_CX,%_ASM_BX
30213+#else
30214+#define _DEST %_ASM_CX
30215+#endif
30216+
30217+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30218+#define __copyuser_seg gs;
30219+#else
30220+#define __copyuser_seg
30221+#endif
30222+
30223 .text
30224 ENTRY(__put_user_1)
30225 ENTER
30226+
30227+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30228+ GET_THREAD_INFO(%_ASM_BX)
30229 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30230 jae bad_put_user
30231 ASM_STAC
30232-1: movb %al,(%_ASM_CX)
30233+
30234+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30235+ mov pax_user_shadow_base,%_ASM_BX
30236+ cmp %_ASM_BX,%_ASM_CX
30237+ jb 1234f
30238+ xor %ebx,%ebx
30239+1234:
30240+#endif
30241+
30242+#endif
30243+
30244+1: __copyuser_seg movb %al,(_DEST)
30245 xor %eax,%eax
30246 EXIT
30247 ENDPROC(__put_user_1)
30248
30249 ENTRY(__put_user_2)
30250 ENTER
30251+
30252+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30253+ GET_THREAD_INFO(%_ASM_BX)
30254 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30255 sub $1,%_ASM_BX
30256 cmp %_ASM_BX,%_ASM_CX
30257 jae bad_put_user
30258 ASM_STAC
30259-2: movw %ax,(%_ASM_CX)
30260+
30261+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30262+ mov pax_user_shadow_base,%_ASM_BX
30263+ cmp %_ASM_BX,%_ASM_CX
30264+ jb 1234f
30265+ xor %ebx,%ebx
30266+1234:
30267+#endif
30268+
30269+#endif
30270+
30271+2: __copyuser_seg movw %ax,(_DEST)
30272 xor %eax,%eax
30273 EXIT
30274 ENDPROC(__put_user_2)
30275
30276 ENTRY(__put_user_4)
30277 ENTER
30278+
30279+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30280+ GET_THREAD_INFO(%_ASM_BX)
30281 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30282 sub $3,%_ASM_BX
30283 cmp %_ASM_BX,%_ASM_CX
30284 jae bad_put_user
30285 ASM_STAC
30286-3: movl %eax,(%_ASM_CX)
30287+
30288+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30289+ mov pax_user_shadow_base,%_ASM_BX
30290+ cmp %_ASM_BX,%_ASM_CX
30291+ jb 1234f
30292+ xor %ebx,%ebx
30293+1234:
30294+#endif
30295+
30296+#endif
30297+
30298+3: __copyuser_seg movl %eax,(_DEST)
30299 xor %eax,%eax
30300 EXIT
30301 ENDPROC(__put_user_4)
30302
30303 ENTRY(__put_user_8)
30304 ENTER
30305+
30306+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30307+ GET_THREAD_INFO(%_ASM_BX)
30308 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30309 sub $7,%_ASM_BX
30310 cmp %_ASM_BX,%_ASM_CX
30311 jae bad_put_user
30312 ASM_STAC
30313-4: mov %_ASM_AX,(%_ASM_CX)
30314+
30315+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30316+ mov pax_user_shadow_base,%_ASM_BX
30317+ cmp %_ASM_BX,%_ASM_CX
30318+ jb 1234f
30319+ xor %ebx,%ebx
30320+1234:
30321+#endif
30322+
30323+#endif
30324+
30325+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30326 #ifdef CONFIG_X86_32
30327-5: movl %edx,4(%_ASM_CX)
30328+5: __copyuser_seg movl %edx,4(_DEST)
30329 #endif
30330 xor %eax,%eax
30331 EXIT
30332diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30333index 1cad221..de671ee 100644
30334--- a/arch/x86/lib/rwlock.S
30335+++ b/arch/x86/lib/rwlock.S
30336@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30337 FRAME
30338 0: LOCK_PREFIX
30339 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30340+
30341+#ifdef CONFIG_PAX_REFCOUNT
30342+ jno 1234f
30343+ LOCK_PREFIX
30344+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30345+ int $4
30346+1234:
30347+ _ASM_EXTABLE(1234b, 1234b)
30348+#endif
30349+
30350 1: rep; nop
30351 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30352 jne 1b
30353 LOCK_PREFIX
30354 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30355+
30356+#ifdef CONFIG_PAX_REFCOUNT
30357+ jno 1234f
30358+ LOCK_PREFIX
30359+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30360+ int $4
30361+1234:
30362+ _ASM_EXTABLE(1234b, 1234b)
30363+#endif
30364+
30365 jnz 0b
30366 ENDFRAME
30367+ pax_force_retaddr
30368 ret
30369 CFI_ENDPROC
30370 END(__write_lock_failed)
30371@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30372 FRAME
30373 0: LOCK_PREFIX
30374 READ_LOCK_SIZE(inc) (%__lock_ptr)
30375+
30376+#ifdef CONFIG_PAX_REFCOUNT
30377+ jno 1234f
30378+ LOCK_PREFIX
30379+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30380+ int $4
30381+1234:
30382+ _ASM_EXTABLE(1234b, 1234b)
30383+#endif
30384+
30385 1: rep; nop
30386 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30387 js 1b
30388 LOCK_PREFIX
30389 READ_LOCK_SIZE(dec) (%__lock_ptr)
30390+
30391+#ifdef CONFIG_PAX_REFCOUNT
30392+ jno 1234f
30393+ LOCK_PREFIX
30394+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30395+ int $4
30396+1234:
30397+ _ASM_EXTABLE(1234b, 1234b)
30398+#endif
30399+
30400 js 0b
30401 ENDFRAME
30402+ pax_force_retaddr
30403 ret
30404 CFI_ENDPROC
30405 END(__read_lock_failed)
30406diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30407index 5dff5f0..cadebf4 100644
30408--- a/arch/x86/lib/rwsem.S
30409+++ b/arch/x86/lib/rwsem.S
30410@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30411 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30412 CFI_RESTORE __ASM_REG(dx)
30413 restore_common_regs
30414+ pax_force_retaddr
30415 ret
30416 CFI_ENDPROC
30417 ENDPROC(call_rwsem_down_read_failed)
30418@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30419 movq %rax,%rdi
30420 call rwsem_down_write_failed
30421 restore_common_regs
30422+ pax_force_retaddr
30423 ret
30424 CFI_ENDPROC
30425 ENDPROC(call_rwsem_down_write_failed)
30426@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30427 movq %rax,%rdi
30428 call rwsem_wake
30429 restore_common_regs
30430-1: ret
30431+1: pax_force_retaddr
30432+ ret
30433 CFI_ENDPROC
30434 ENDPROC(call_rwsem_wake)
30435
30436@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30437 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30438 CFI_RESTORE __ASM_REG(dx)
30439 restore_common_regs
30440+ pax_force_retaddr
30441 ret
30442 CFI_ENDPROC
30443 ENDPROC(call_rwsem_downgrade_wake)
30444diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30445index a63efd6..8149fbe 100644
30446--- a/arch/x86/lib/thunk_64.S
30447+++ b/arch/x86/lib/thunk_64.S
30448@@ -8,6 +8,7 @@
30449 #include <linux/linkage.h>
30450 #include <asm/dwarf2.h>
30451 #include <asm/calling.h>
30452+#include <asm/alternative-asm.h>
30453
30454 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30455 .macro THUNK name, func, put_ret_addr_in_rdi=0
30456@@ -15,11 +16,11 @@
30457 \name:
30458 CFI_STARTPROC
30459
30460- /* this one pushes 9 elems, the next one would be %rIP */
30461- SAVE_ARGS
30462+ /* this one pushes 15+1 elems, the next one would be %rIP */
30463+ SAVE_ARGS 8
30464
30465 .if \put_ret_addr_in_rdi
30466- movq_cfi_restore 9*8, rdi
30467+ movq_cfi_restore RIP, rdi
30468 .endif
30469
30470 call \func
30471@@ -38,8 +39,9 @@
30472
30473 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30474 CFI_STARTPROC
30475- SAVE_ARGS
30476+ SAVE_ARGS 8
30477 restore:
30478- RESTORE_ARGS
30479+ RESTORE_ARGS 1,8
30480+ pax_force_retaddr
30481 ret
30482 CFI_ENDPROC
30483diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30484index e2f5e21..4b22130 100644
30485--- a/arch/x86/lib/usercopy_32.c
30486+++ b/arch/x86/lib/usercopy_32.c
30487@@ -42,11 +42,13 @@ do { \
30488 int __d0; \
30489 might_fault(); \
30490 __asm__ __volatile__( \
30491+ __COPYUSER_SET_ES \
30492 ASM_STAC "\n" \
30493 "0: rep; stosl\n" \
30494 " movl %2,%0\n" \
30495 "1: rep; stosb\n" \
30496 "2: " ASM_CLAC "\n" \
30497+ __COPYUSER_RESTORE_ES \
30498 ".section .fixup,\"ax\"\n" \
30499 "3: lea 0(%2,%0,4),%0\n" \
30500 " jmp 2b\n" \
30501@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30502
30503 #ifdef CONFIG_X86_INTEL_USERCOPY
30504 static unsigned long
30505-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30506+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30507 {
30508 int d0, d1;
30509 __asm__ __volatile__(
30510@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30511 " .align 2,0x90\n"
30512 "3: movl 0(%4), %%eax\n"
30513 "4: movl 4(%4), %%edx\n"
30514- "5: movl %%eax, 0(%3)\n"
30515- "6: movl %%edx, 4(%3)\n"
30516+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30517+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30518 "7: movl 8(%4), %%eax\n"
30519 "8: movl 12(%4),%%edx\n"
30520- "9: movl %%eax, 8(%3)\n"
30521- "10: movl %%edx, 12(%3)\n"
30522+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30523+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30524 "11: movl 16(%4), %%eax\n"
30525 "12: movl 20(%4), %%edx\n"
30526- "13: movl %%eax, 16(%3)\n"
30527- "14: movl %%edx, 20(%3)\n"
30528+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30529+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30530 "15: movl 24(%4), %%eax\n"
30531 "16: movl 28(%4), %%edx\n"
30532- "17: movl %%eax, 24(%3)\n"
30533- "18: movl %%edx, 28(%3)\n"
30534+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30535+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30536 "19: movl 32(%4), %%eax\n"
30537 "20: movl 36(%4), %%edx\n"
30538- "21: movl %%eax, 32(%3)\n"
30539- "22: movl %%edx, 36(%3)\n"
30540+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30541+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30542 "23: movl 40(%4), %%eax\n"
30543 "24: movl 44(%4), %%edx\n"
30544- "25: movl %%eax, 40(%3)\n"
30545- "26: movl %%edx, 44(%3)\n"
30546+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30547+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30548 "27: movl 48(%4), %%eax\n"
30549 "28: movl 52(%4), %%edx\n"
30550- "29: movl %%eax, 48(%3)\n"
30551- "30: movl %%edx, 52(%3)\n"
30552+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30553+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30554 "31: movl 56(%4), %%eax\n"
30555 "32: movl 60(%4), %%edx\n"
30556- "33: movl %%eax, 56(%3)\n"
30557- "34: movl %%edx, 60(%3)\n"
30558+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30559+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30560 " addl $-64, %0\n"
30561 " addl $64, %4\n"
30562 " addl $64, %3\n"
30563@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30564 " shrl $2, %0\n"
30565 " andl $3, %%eax\n"
30566 " cld\n"
30567+ __COPYUSER_SET_ES
30568 "99: rep; movsl\n"
30569 "36: movl %%eax, %0\n"
30570 "37: rep; movsb\n"
30571 "100:\n"
30572+ __COPYUSER_RESTORE_ES
30573+ ".section .fixup,\"ax\"\n"
30574+ "101: lea 0(%%eax,%0,4),%0\n"
30575+ " jmp 100b\n"
30576+ ".previous\n"
30577+ _ASM_EXTABLE(1b,100b)
30578+ _ASM_EXTABLE(2b,100b)
30579+ _ASM_EXTABLE(3b,100b)
30580+ _ASM_EXTABLE(4b,100b)
30581+ _ASM_EXTABLE(5b,100b)
30582+ _ASM_EXTABLE(6b,100b)
30583+ _ASM_EXTABLE(7b,100b)
30584+ _ASM_EXTABLE(8b,100b)
30585+ _ASM_EXTABLE(9b,100b)
30586+ _ASM_EXTABLE(10b,100b)
30587+ _ASM_EXTABLE(11b,100b)
30588+ _ASM_EXTABLE(12b,100b)
30589+ _ASM_EXTABLE(13b,100b)
30590+ _ASM_EXTABLE(14b,100b)
30591+ _ASM_EXTABLE(15b,100b)
30592+ _ASM_EXTABLE(16b,100b)
30593+ _ASM_EXTABLE(17b,100b)
30594+ _ASM_EXTABLE(18b,100b)
30595+ _ASM_EXTABLE(19b,100b)
30596+ _ASM_EXTABLE(20b,100b)
30597+ _ASM_EXTABLE(21b,100b)
30598+ _ASM_EXTABLE(22b,100b)
30599+ _ASM_EXTABLE(23b,100b)
30600+ _ASM_EXTABLE(24b,100b)
30601+ _ASM_EXTABLE(25b,100b)
30602+ _ASM_EXTABLE(26b,100b)
30603+ _ASM_EXTABLE(27b,100b)
30604+ _ASM_EXTABLE(28b,100b)
30605+ _ASM_EXTABLE(29b,100b)
30606+ _ASM_EXTABLE(30b,100b)
30607+ _ASM_EXTABLE(31b,100b)
30608+ _ASM_EXTABLE(32b,100b)
30609+ _ASM_EXTABLE(33b,100b)
30610+ _ASM_EXTABLE(34b,100b)
30611+ _ASM_EXTABLE(35b,100b)
30612+ _ASM_EXTABLE(36b,100b)
30613+ _ASM_EXTABLE(37b,100b)
30614+ _ASM_EXTABLE(99b,101b)
30615+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30616+ : "1"(to), "2"(from), "0"(size)
30617+ : "eax", "edx", "memory");
30618+ return size;
30619+}
30620+
30621+static unsigned long
30622+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30623+{
30624+ int d0, d1;
30625+ __asm__ __volatile__(
30626+ " .align 2,0x90\n"
30627+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30628+ " cmpl $67, %0\n"
30629+ " jbe 3f\n"
30630+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30631+ " .align 2,0x90\n"
30632+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30633+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30634+ "5: movl %%eax, 0(%3)\n"
30635+ "6: movl %%edx, 4(%3)\n"
30636+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30637+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30638+ "9: movl %%eax, 8(%3)\n"
30639+ "10: movl %%edx, 12(%3)\n"
30640+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30641+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30642+ "13: movl %%eax, 16(%3)\n"
30643+ "14: movl %%edx, 20(%3)\n"
30644+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30645+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30646+ "17: movl %%eax, 24(%3)\n"
30647+ "18: movl %%edx, 28(%3)\n"
30648+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30649+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30650+ "21: movl %%eax, 32(%3)\n"
30651+ "22: movl %%edx, 36(%3)\n"
30652+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30653+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30654+ "25: movl %%eax, 40(%3)\n"
30655+ "26: movl %%edx, 44(%3)\n"
30656+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30657+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30658+ "29: movl %%eax, 48(%3)\n"
30659+ "30: movl %%edx, 52(%3)\n"
30660+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30661+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30662+ "33: movl %%eax, 56(%3)\n"
30663+ "34: movl %%edx, 60(%3)\n"
30664+ " addl $-64, %0\n"
30665+ " addl $64, %4\n"
30666+ " addl $64, %3\n"
30667+ " cmpl $63, %0\n"
30668+ " ja 1b\n"
30669+ "35: movl %0, %%eax\n"
30670+ " shrl $2, %0\n"
30671+ " andl $3, %%eax\n"
30672+ " cld\n"
30673+ "99: rep; "__copyuser_seg" movsl\n"
30674+ "36: movl %%eax, %0\n"
30675+ "37: rep; "__copyuser_seg" movsb\n"
30676+ "100:\n"
30677 ".section .fixup,\"ax\"\n"
30678 "101: lea 0(%%eax,%0,4),%0\n"
30679 " jmp 100b\n"
30680@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30681 int d0, d1;
30682 __asm__ __volatile__(
30683 " .align 2,0x90\n"
30684- "0: movl 32(%4), %%eax\n"
30685+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30686 " cmpl $67, %0\n"
30687 " jbe 2f\n"
30688- "1: movl 64(%4), %%eax\n"
30689+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30690 " .align 2,0x90\n"
30691- "2: movl 0(%4), %%eax\n"
30692- "21: movl 4(%4), %%edx\n"
30693+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30694+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30695 " movl %%eax, 0(%3)\n"
30696 " movl %%edx, 4(%3)\n"
30697- "3: movl 8(%4), %%eax\n"
30698- "31: movl 12(%4),%%edx\n"
30699+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30700+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30701 " movl %%eax, 8(%3)\n"
30702 " movl %%edx, 12(%3)\n"
30703- "4: movl 16(%4), %%eax\n"
30704- "41: movl 20(%4), %%edx\n"
30705+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30706+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30707 " movl %%eax, 16(%3)\n"
30708 " movl %%edx, 20(%3)\n"
30709- "10: movl 24(%4), %%eax\n"
30710- "51: movl 28(%4), %%edx\n"
30711+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30712+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30713 " movl %%eax, 24(%3)\n"
30714 " movl %%edx, 28(%3)\n"
30715- "11: movl 32(%4), %%eax\n"
30716- "61: movl 36(%4), %%edx\n"
30717+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30718+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30719 " movl %%eax, 32(%3)\n"
30720 " movl %%edx, 36(%3)\n"
30721- "12: movl 40(%4), %%eax\n"
30722- "71: movl 44(%4), %%edx\n"
30723+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30724+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30725 " movl %%eax, 40(%3)\n"
30726 " movl %%edx, 44(%3)\n"
30727- "13: movl 48(%4), %%eax\n"
30728- "81: movl 52(%4), %%edx\n"
30729+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30730+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30731 " movl %%eax, 48(%3)\n"
30732 " movl %%edx, 52(%3)\n"
30733- "14: movl 56(%4), %%eax\n"
30734- "91: movl 60(%4), %%edx\n"
30735+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30736+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30737 " movl %%eax, 56(%3)\n"
30738 " movl %%edx, 60(%3)\n"
30739 " addl $-64, %0\n"
30740@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30741 " shrl $2, %0\n"
30742 " andl $3, %%eax\n"
30743 " cld\n"
30744- "6: rep; movsl\n"
30745+ "6: rep; "__copyuser_seg" movsl\n"
30746 " movl %%eax,%0\n"
30747- "7: rep; movsb\n"
30748+ "7: rep; "__copyuser_seg" movsb\n"
30749 "8:\n"
30750 ".section .fixup,\"ax\"\n"
30751 "9: lea 0(%%eax,%0,4),%0\n"
30752@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30753
30754 __asm__ __volatile__(
30755 " .align 2,0x90\n"
30756- "0: movl 32(%4), %%eax\n"
30757+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30758 " cmpl $67, %0\n"
30759 " jbe 2f\n"
30760- "1: movl 64(%4), %%eax\n"
30761+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30762 " .align 2,0x90\n"
30763- "2: movl 0(%4), %%eax\n"
30764- "21: movl 4(%4), %%edx\n"
30765+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30766+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30767 " movnti %%eax, 0(%3)\n"
30768 " movnti %%edx, 4(%3)\n"
30769- "3: movl 8(%4), %%eax\n"
30770- "31: movl 12(%4),%%edx\n"
30771+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30772+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30773 " movnti %%eax, 8(%3)\n"
30774 " movnti %%edx, 12(%3)\n"
30775- "4: movl 16(%4), %%eax\n"
30776- "41: movl 20(%4), %%edx\n"
30777+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30778+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30779 " movnti %%eax, 16(%3)\n"
30780 " movnti %%edx, 20(%3)\n"
30781- "10: movl 24(%4), %%eax\n"
30782- "51: movl 28(%4), %%edx\n"
30783+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30784+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30785 " movnti %%eax, 24(%3)\n"
30786 " movnti %%edx, 28(%3)\n"
30787- "11: movl 32(%4), %%eax\n"
30788- "61: movl 36(%4), %%edx\n"
30789+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30790+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30791 " movnti %%eax, 32(%3)\n"
30792 " movnti %%edx, 36(%3)\n"
30793- "12: movl 40(%4), %%eax\n"
30794- "71: movl 44(%4), %%edx\n"
30795+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30796+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30797 " movnti %%eax, 40(%3)\n"
30798 " movnti %%edx, 44(%3)\n"
30799- "13: movl 48(%4), %%eax\n"
30800- "81: movl 52(%4), %%edx\n"
30801+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30802+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30803 " movnti %%eax, 48(%3)\n"
30804 " movnti %%edx, 52(%3)\n"
30805- "14: movl 56(%4), %%eax\n"
30806- "91: movl 60(%4), %%edx\n"
30807+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30808+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30809 " movnti %%eax, 56(%3)\n"
30810 " movnti %%edx, 60(%3)\n"
30811 " addl $-64, %0\n"
30812@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30813 " shrl $2, %0\n"
30814 " andl $3, %%eax\n"
30815 " cld\n"
30816- "6: rep; movsl\n"
30817+ "6: rep; "__copyuser_seg" movsl\n"
30818 " movl %%eax,%0\n"
30819- "7: rep; movsb\n"
30820+ "7: rep; "__copyuser_seg" movsb\n"
30821 "8:\n"
30822 ".section .fixup,\"ax\"\n"
30823 "9: lea 0(%%eax,%0,4),%0\n"
30824@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30825
30826 __asm__ __volatile__(
30827 " .align 2,0x90\n"
30828- "0: movl 32(%4), %%eax\n"
30829+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30830 " cmpl $67, %0\n"
30831 " jbe 2f\n"
30832- "1: movl 64(%4), %%eax\n"
30833+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30834 " .align 2,0x90\n"
30835- "2: movl 0(%4), %%eax\n"
30836- "21: movl 4(%4), %%edx\n"
30837+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30838+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30839 " movnti %%eax, 0(%3)\n"
30840 " movnti %%edx, 4(%3)\n"
30841- "3: movl 8(%4), %%eax\n"
30842- "31: movl 12(%4),%%edx\n"
30843+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30844+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30845 " movnti %%eax, 8(%3)\n"
30846 " movnti %%edx, 12(%3)\n"
30847- "4: movl 16(%4), %%eax\n"
30848- "41: movl 20(%4), %%edx\n"
30849+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30850+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30851 " movnti %%eax, 16(%3)\n"
30852 " movnti %%edx, 20(%3)\n"
30853- "10: movl 24(%4), %%eax\n"
30854- "51: movl 28(%4), %%edx\n"
30855+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30856+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30857 " movnti %%eax, 24(%3)\n"
30858 " movnti %%edx, 28(%3)\n"
30859- "11: movl 32(%4), %%eax\n"
30860- "61: movl 36(%4), %%edx\n"
30861+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30862+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30863 " movnti %%eax, 32(%3)\n"
30864 " movnti %%edx, 36(%3)\n"
30865- "12: movl 40(%4), %%eax\n"
30866- "71: movl 44(%4), %%edx\n"
30867+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30868+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30869 " movnti %%eax, 40(%3)\n"
30870 " movnti %%edx, 44(%3)\n"
30871- "13: movl 48(%4), %%eax\n"
30872- "81: movl 52(%4), %%edx\n"
30873+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30874+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30875 " movnti %%eax, 48(%3)\n"
30876 " movnti %%edx, 52(%3)\n"
30877- "14: movl 56(%4), %%eax\n"
30878- "91: movl 60(%4), %%edx\n"
30879+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30880+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30881 " movnti %%eax, 56(%3)\n"
30882 " movnti %%edx, 60(%3)\n"
30883 " addl $-64, %0\n"
30884@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30885 " shrl $2, %0\n"
30886 " andl $3, %%eax\n"
30887 " cld\n"
30888- "6: rep; movsl\n"
30889+ "6: rep; "__copyuser_seg" movsl\n"
30890 " movl %%eax,%0\n"
30891- "7: rep; movsb\n"
30892+ "7: rep; "__copyuser_seg" movsb\n"
30893 "8:\n"
30894 ".section .fixup,\"ax\"\n"
30895 "9: lea 0(%%eax,%0,4),%0\n"
30896@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30897 */
30898 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30899 unsigned long size);
30900-unsigned long __copy_user_intel(void __user *to, const void *from,
30901+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30902+ unsigned long size);
30903+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30904 unsigned long size);
30905 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30906 const void __user *from, unsigned long size);
30907 #endif /* CONFIG_X86_INTEL_USERCOPY */
30908
30909 /* Generic arbitrary sized copy. */
30910-#define __copy_user(to, from, size) \
30911+#define __copy_user(to, from, size, prefix, set, restore) \
30912 do { \
30913 int __d0, __d1, __d2; \
30914 __asm__ __volatile__( \
30915+ set \
30916 " cmp $7,%0\n" \
30917 " jbe 1f\n" \
30918 " movl %1,%0\n" \
30919 " negl %0\n" \
30920 " andl $7,%0\n" \
30921 " subl %0,%3\n" \
30922- "4: rep; movsb\n" \
30923+ "4: rep; "prefix"movsb\n" \
30924 " movl %3,%0\n" \
30925 " shrl $2,%0\n" \
30926 " andl $3,%3\n" \
30927 " .align 2,0x90\n" \
30928- "0: rep; movsl\n" \
30929+ "0: rep; "prefix"movsl\n" \
30930 " movl %3,%0\n" \
30931- "1: rep; movsb\n" \
30932+ "1: rep; "prefix"movsb\n" \
30933 "2:\n" \
30934+ restore \
30935 ".section .fixup,\"ax\"\n" \
30936 "5: addl %3,%0\n" \
30937 " jmp 2b\n" \
30938@@ -538,14 +650,14 @@ do { \
30939 " negl %0\n" \
30940 " andl $7,%0\n" \
30941 " subl %0,%3\n" \
30942- "4: rep; movsb\n" \
30943+ "4: rep; "__copyuser_seg"movsb\n" \
30944 " movl %3,%0\n" \
30945 " shrl $2,%0\n" \
30946 " andl $3,%3\n" \
30947 " .align 2,0x90\n" \
30948- "0: rep; movsl\n" \
30949+ "0: rep; "__copyuser_seg"movsl\n" \
30950 " movl %3,%0\n" \
30951- "1: rep; movsb\n" \
30952+ "1: rep; "__copyuser_seg"movsb\n" \
30953 "2:\n" \
30954 ".section .fixup,\"ax\"\n" \
30955 "5: addl %3,%0\n" \
30956@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30957 {
30958 stac();
30959 if (movsl_is_ok(to, from, n))
30960- __copy_user(to, from, n);
30961+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30962 else
30963- n = __copy_user_intel(to, from, n);
30964+ n = __generic_copy_to_user_intel(to, from, n);
30965 clac();
30966 return n;
30967 }
30968@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30969 {
30970 stac();
30971 if (movsl_is_ok(to, from, n))
30972- __copy_user(to, from, n);
30973+ __copy_user(to, from, n, __copyuser_seg, "", "");
30974 else
30975- n = __copy_user_intel((void __user *)to,
30976- (const void *)from, n);
30977+ n = __generic_copy_from_user_intel(to, from, n);
30978 clac();
30979 return n;
30980 }
30981@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30982 if (n > 64 && cpu_has_xmm2)
30983 n = __copy_user_intel_nocache(to, from, n);
30984 else
30985- __copy_user(to, from, n);
30986+ __copy_user(to, from, n, __copyuser_seg, "", "");
30987 #else
30988- __copy_user(to, from, n);
30989+ __copy_user(to, from, n, __copyuser_seg, "", "");
30990 #endif
30991 clac();
30992 return n;
30993 }
30994 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30995
30996-/**
30997- * copy_to_user: - Copy a block of data into user space.
30998- * @to: Destination address, in user space.
30999- * @from: Source address, in kernel space.
31000- * @n: Number of bytes to copy.
31001- *
31002- * Context: User context only. This function may sleep.
31003- *
31004- * Copy data from kernel space to user space.
31005- *
31006- * Returns number of bytes that could not be copied.
31007- * On success, this will be zero.
31008- */
31009-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31010+#ifdef CONFIG_PAX_MEMORY_UDEREF
31011+void __set_fs(mm_segment_t x)
31012 {
31013- if (access_ok(VERIFY_WRITE, to, n))
31014- n = __copy_to_user(to, from, n);
31015- return n;
31016+ switch (x.seg) {
31017+ case 0:
31018+ loadsegment(gs, 0);
31019+ break;
31020+ case TASK_SIZE_MAX:
31021+ loadsegment(gs, __USER_DS);
31022+ break;
31023+ case -1UL:
31024+ loadsegment(gs, __KERNEL_DS);
31025+ break;
31026+ default:
31027+ BUG();
31028+ }
31029 }
31030-EXPORT_SYMBOL(_copy_to_user);
31031+EXPORT_SYMBOL(__set_fs);
31032
31033-/**
31034- * copy_from_user: - Copy a block of data from user space.
31035- * @to: Destination address, in kernel space.
31036- * @from: Source address, in user space.
31037- * @n: Number of bytes to copy.
31038- *
31039- * Context: User context only. This function may sleep.
31040- *
31041- * Copy data from user space to kernel space.
31042- *
31043- * Returns number of bytes that could not be copied.
31044- * On success, this will be zero.
31045- *
31046- * If some data could not be copied, this function will pad the copied
31047- * data to the requested size using zero bytes.
31048- */
31049-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31050+void set_fs(mm_segment_t x)
31051 {
31052- if (access_ok(VERIFY_READ, from, n))
31053- n = __copy_from_user(to, from, n);
31054- else
31055- memset(to, 0, n);
31056- return n;
31057+ current_thread_info()->addr_limit = x;
31058+ __set_fs(x);
31059 }
31060-EXPORT_SYMBOL(_copy_from_user);
31061+EXPORT_SYMBOL(set_fs);
31062+#endif
31063diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31064index c905e89..01ab928 100644
31065--- a/arch/x86/lib/usercopy_64.c
31066+++ b/arch/x86/lib/usercopy_64.c
31067@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31068 might_fault();
31069 /* no memory constraint because it doesn't change any memory gcc knows
31070 about */
31071+ pax_open_userland();
31072 stac();
31073 asm volatile(
31074 " testq %[size8],%[size8]\n"
31075@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31076 _ASM_EXTABLE(0b,3b)
31077 _ASM_EXTABLE(1b,2b)
31078 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31079- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31080+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31081 [zero] "r" (0UL), [eight] "r" (8UL));
31082 clac();
31083+ pax_close_userland();
31084 return size;
31085 }
31086 EXPORT_SYMBOL(__clear_user);
31087@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31088 }
31089 EXPORT_SYMBOL(clear_user);
31090
31091-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31092+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31093 {
31094- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31095- return copy_user_generic((__force void *)to, (__force void *)from, len);
31096- }
31097- return len;
31098+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31099+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31100+ return len;
31101 }
31102 EXPORT_SYMBOL(copy_in_user);
31103
31104@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31105 * it is not necessary to optimize tail handling.
31106 */
31107 __visible unsigned long
31108-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31109+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31110 {
31111 char c;
31112 unsigned zero_len;
31113
31114+ clac();
31115+ pax_close_userland();
31116 for (; len; --len, to++) {
31117 if (__get_user_nocheck(c, from++, sizeof(char)))
31118 break;
31119@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31120 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31121 if (__put_user_nocheck(c, to++, sizeof(char)))
31122 break;
31123- clac();
31124 return len;
31125 }
31126diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31127index 6a19ad9..1c48f9a 100644
31128--- a/arch/x86/mm/Makefile
31129+++ b/arch/x86/mm/Makefile
31130@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31131 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31132
31133 obj-$(CONFIG_MEMTEST) += memtest.o
31134+
31135+quote:="
31136+obj-$(CONFIG_X86_64) += uderef_64.o
31137+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31138diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31139index 903ec1e..c4166b2 100644
31140--- a/arch/x86/mm/extable.c
31141+++ b/arch/x86/mm/extable.c
31142@@ -6,12 +6,24 @@
31143 static inline unsigned long
31144 ex_insn_addr(const struct exception_table_entry *x)
31145 {
31146- return (unsigned long)&x->insn + x->insn;
31147+ unsigned long reloc = 0;
31148+
31149+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31150+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31151+#endif
31152+
31153+ return (unsigned long)&x->insn + x->insn + reloc;
31154 }
31155 static inline unsigned long
31156 ex_fixup_addr(const struct exception_table_entry *x)
31157 {
31158- return (unsigned long)&x->fixup + x->fixup;
31159+ unsigned long reloc = 0;
31160+
31161+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31162+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31163+#endif
31164+
31165+ return (unsigned long)&x->fixup + x->fixup + reloc;
31166 }
31167
31168 int fixup_exception(struct pt_regs *regs)
31169@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31170 unsigned long new_ip;
31171
31172 #ifdef CONFIG_PNPBIOS
31173- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31174+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31175 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31176 extern u32 pnp_bios_is_utter_crap;
31177 pnp_bios_is_utter_crap = 1;
31178@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31179 i += 4;
31180 p->fixup -= i;
31181 i += 4;
31182+
31183+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31184+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31185+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31186+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31187+#endif
31188+
31189 }
31190 }
31191
31192diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31193index 6dea040..31e52ff 100644
31194--- a/arch/x86/mm/fault.c
31195+++ b/arch/x86/mm/fault.c
31196@@ -14,11 +14,18 @@
31197 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31198 #include <linux/prefetch.h> /* prefetchw */
31199 #include <linux/context_tracking.h> /* exception_enter(), ... */
31200+#include <linux/unistd.h>
31201+#include <linux/compiler.h>
31202
31203 #include <asm/traps.h> /* dotraplinkage, ... */
31204 #include <asm/pgalloc.h> /* pgd_*(), ... */
31205 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31206 #include <asm/fixmap.h> /* VSYSCALL_START */
31207+#include <asm/tlbflush.h>
31208+
31209+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31210+#include <asm/stacktrace.h>
31211+#endif
31212
31213 #define CREATE_TRACE_POINTS
31214 #include <asm/trace/exceptions.h>
31215@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31216 int ret = 0;
31217
31218 /* kprobe_running() needs smp_processor_id() */
31219- if (kprobes_built_in() && !user_mode_vm(regs)) {
31220+ if (kprobes_built_in() && !user_mode(regs)) {
31221 preempt_disable();
31222 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31223 ret = 1;
31224@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31225 return !instr_lo || (instr_lo>>1) == 1;
31226 case 0x00:
31227 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31228- if (probe_kernel_address(instr, opcode))
31229+ if (user_mode(regs)) {
31230+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31231+ return 0;
31232+ } else if (probe_kernel_address(instr, opcode))
31233 return 0;
31234
31235 *prefetch = (instr_lo == 0xF) &&
31236@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31237 while (instr < max_instr) {
31238 unsigned char opcode;
31239
31240- if (probe_kernel_address(instr, opcode))
31241+ if (user_mode(regs)) {
31242+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31243+ break;
31244+ } else if (probe_kernel_address(instr, opcode))
31245 break;
31246
31247 instr++;
31248@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31249 force_sig_info(si_signo, &info, tsk);
31250 }
31251
31252+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31253+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31254+#endif
31255+
31256+#ifdef CONFIG_PAX_EMUTRAMP
31257+static int pax_handle_fetch_fault(struct pt_regs *regs);
31258+#endif
31259+
31260+#ifdef CONFIG_PAX_PAGEEXEC
31261+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31262+{
31263+ pgd_t *pgd;
31264+ pud_t *pud;
31265+ pmd_t *pmd;
31266+
31267+ pgd = pgd_offset(mm, address);
31268+ if (!pgd_present(*pgd))
31269+ return NULL;
31270+ pud = pud_offset(pgd, address);
31271+ if (!pud_present(*pud))
31272+ return NULL;
31273+ pmd = pmd_offset(pud, address);
31274+ if (!pmd_present(*pmd))
31275+ return NULL;
31276+ return pmd;
31277+}
31278+#endif
31279+
31280 DEFINE_SPINLOCK(pgd_lock);
31281 LIST_HEAD(pgd_list);
31282
31283@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31284 for (address = VMALLOC_START & PMD_MASK;
31285 address >= TASK_SIZE && address < FIXADDR_TOP;
31286 address += PMD_SIZE) {
31287+
31288+#ifdef CONFIG_PAX_PER_CPU_PGD
31289+ unsigned long cpu;
31290+#else
31291 struct page *page;
31292+#endif
31293
31294 spin_lock(&pgd_lock);
31295+
31296+#ifdef CONFIG_PAX_PER_CPU_PGD
31297+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31298+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31299+ pmd_t *ret;
31300+
31301+ ret = vmalloc_sync_one(pgd, address);
31302+ if (!ret)
31303+ break;
31304+ pgd = get_cpu_pgd(cpu, kernel);
31305+#else
31306 list_for_each_entry(page, &pgd_list, lru) {
31307+ pgd_t *pgd;
31308 spinlock_t *pgt_lock;
31309 pmd_t *ret;
31310
31311@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31312 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31313
31314 spin_lock(pgt_lock);
31315- ret = vmalloc_sync_one(page_address(page), address);
31316+ pgd = page_address(page);
31317+#endif
31318+
31319+ ret = vmalloc_sync_one(pgd, address);
31320+
31321+#ifndef CONFIG_PAX_PER_CPU_PGD
31322 spin_unlock(pgt_lock);
31323+#endif
31324
31325 if (!ret)
31326 break;
31327@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31328 * an interrupt in the middle of a task switch..
31329 */
31330 pgd_paddr = read_cr3();
31331+
31332+#ifdef CONFIG_PAX_PER_CPU_PGD
31333+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31334+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31335+#endif
31336+
31337 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31338 if (!pmd_k)
31339 return -1;
31340@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31341 * happen within a race in page table update. In the later
31342 * case just flush:
31343 */
31344- pgd = pgd_offset(current->active_mm, address);
31345+
31346 pgd_ref = pgd_offset_k(address);
31347 if (pgd_none(*pgd_ref))
31348 return -1;
31349
31350+#ifdef CONFIG_PAX_PER_CPU_PGD
31351+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31352+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31353+ if (pgd_none(*pgd)) {
31354+ set_pgd(pgd, *pgd_ref);
31355+ arch_flush_lazy_mmu_mode();
31356+ } else {
31357+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31358+ }
31359+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31360+#else
31361+ pgd = pgd_offset(current->active_mm, address);
31362+#endif
31363+
31364 if (pgd_none(*pgd)) {
31365 set_pgd(pgd, *pgd_ref);
31366 arch_flush_lazy_mmu_mode();
31367@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31368 static int is_errata100(struct pt_regs *regs, unsigned long address)
31369 {
31370 #ifdef CONFIG_X86_64
31371- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31372+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31373 return 1;
31374 #endif
31375 return 0;
31376@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31377 }
31378
31379 static const char nx_warning[] = KERN_CRIT
31380-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31381+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31382
31383 static void
31384 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31385@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31386 if (!oops_may_print())
31387 return;
31388
31389- if (error_code & PF_INSTR) {
31390+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31391 unsigned int level;
31392
31393 pte_t *pte = lookup_address(address, &level);
31394
31395 if (pte && pte_present(*pte) && !pte_exec(*pte))
31396- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31397+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31398 }
31399
31400+#ifdef CONFIG_PAX_KERNEXEC
31401+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31402+ if (current->signal->curr_ip)
31403+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31404+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31405+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31406+ else
31407+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31408+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31409+ }
31410+#endif
31411+
31412 printk(KERN_ALERT "BUG: unable to handle kernel ");
31413 if (address < PAGE_SIZE)
31414 printk(KERN_CONT "NULL pointer dereference");
31415@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31416 return;
31417 }
31418 #endif
31419+
31420+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31421+ if (pax_is_fetch_fault(regs, error_code, address)) {
31422+
31423+#ifdef CONFIG_PAX_EMUTRAMP
31424+ switch (pax_handle_fetch_fault(regs)) {
31425+ case 2:
31426+ return;
31427+ }
31428+#endif
31429+
31430+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31431+ do_group_exit(SIGKILL);
31432+ }
31433+#endif
31434+
31435 /* Kernel addresses are always protection faults: */
31436 if (address >= TASK_SIZE)
31437 error_code |= PF_PROT;
31438@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31439 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31440 printk(KERN_ERR
31441 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31442- tsk->comm, tsk->pid, address);
31443+ tsk->comm, task_pid_nr(tsk), address);
31444 code = BUS_MCEERR_AR;
31445 }
31446 #endif
31447@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31448 return 1;
31449 }
31450
31451+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31452+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31453+{
31454+ pte_t *pte;
31455+ pmd_t *pmd;
31456+ spinlock_t *ptl;
31457+ unsigned char pte_mask;
31458+
31459+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31460+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31461+ return 0;
31462+
31463+ /* PaX: it's our fault, let's handle it if we can */
31464+
31465+ /* PaX: take a look at read faults before acquiring any locks */
31466+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31467+ /* instruction fetch attempt from a protected page in user mode */
31468+ up_read(&mm->mmap_sem);
31469+
31470+#ifdef CONFIG_PAX_EMUTRAMP
31471+ switch (pax_handle_fetch_fault(regs)) {
31472+ case 2:
31473+ return 1;
31474+ }
31475+#endif
31476+
31477+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31478+ do_group_exit(SIGKILL);
31479+ }
31480+
31481+ pmd = pax_get_pmd(mm, address);
31482+ if (unlikely(!pmd))
31483+ return 0;
31484+
31485+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31486+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31487+ pte_unmap_unlock(pte, ptl);
31488+ return 0;
31489+ }
31490+
31491+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31492+ /* write attempt to a protected page in user mode */
31493+ pte_unmap_unlock(pte, ptl);
31494+ return 0;
31495+ }
31496+
31497+#ifdef CONFIG_SMP
31498+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31499+#else
31500+ if (likely(address > get_limit(regs->cs)))
31501+#endif
31502+ {
31503+ set_pte(pte, pte_mkread(*pte));
31504+ __flush_tlb_one(address);
31505+ pte_unmap_unlock(pte, ptl);
31506+ up_read(&mm->mmap_sem);
31507+ return 1;
31508+ }
31509+
31510+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31511+
31512+ /*
31513+ * PaX: fill DTLB with user rights and retry
31514+ */
31515+ __asm__ __volatile__ (
31516+ "orb %2,(%1)\n"
31517+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31518+/*
31519+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31520+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31521+ * page fault when examined during a TLB load attempt. this is true not only
31522+ * for PTEs holding a non-present entry but also present entries that will
31523+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31524+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31525+ * for our target pages since their PTEs are simply not in the TLBs at all.
31526+
31527+ * the best thing in omitting it is that we gain around 15-20% speed in the
31528+ * fast path of the page fault handler and can get rid of tracing since we
31529+ * can no longer flush unintended entries.
31530+ */
31531+ "invlpg (%0)\n"
31532+#endif
31533+ __copyuser_seg"testb $0,(%0)\n"
31534+ "xorb %3,(%1)\n"
31535+ :
31536+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31537+ : "memory", "cc");
31538+ pte_unmap_unlock(pte, ptl);
31539+ up_read(&mm->mmap_sem);
31540+ return 1;
31541+}
31542+#endif
31543+
31544 /*
31545 * Handle a spurious fault caused by a stale TLB entry.
31546 *
31547@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31548 static inline int
31549 access_error(unsigned long error_code, struct vm_area_struct *vma)
31550 {
31551+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31552+ return 1;
31553+
31554 if (error_code & PF_WRITE) {
31555 /* write, present and write, not present: */
31556 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31557@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31558 if (error_code & PF_USER)
31559 return false;
31560
31561- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31562+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31563 return false;
31564
31565 return true;
31566@@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31567 /* Get the faulting address: */
31568 address = read_cr2();
31569
31570+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31571+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31572+ if (!search_exception_tables(regs->ip)) {
31573+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31574+ bad_area_nosemaphore(regs, error_code, address);
31575+ return;
31576+ }
31577+ if (address < pax_user_shadow_base) {
31578+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31579+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31580+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31581+ } else
31582+ address -= pax_user_shadow_base;
31583+ }
31584+#endif
31585+
31586 /*
31587 * Detect and handle instructions that would cause a page fault for
31588 * both a tracked kernel page and a userspace page.
31589@@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31590 * User-mode registers count as a user access even for any
31591 * potential system fault or CPU buglet:
31592 */
31593- if (user_mode_vm(regs)) {
31594+ if (user_mode(regs)) {
31595 local_irq_enable();
31596 error_code |= PF_USER;
31597 flags |= FAULT_FLAG_USER;
31598@@ -1161,6 +1385,11 @@ retry:
31599 might_sleep();
31600 }
31601
31602+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31603+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31604+ return;
31605+#endif
31606+
31607 vma = find_vma(mm, address);
31608 if (unlikely(!vma)) {
31609 bad_area(regs, error_code, address);
31610@@ -1172,18 +1401,24 @@ retry:
31611 bad_area(regs, error_code, address);
31612 return;
31613 }
31614- if (error_code & PF_USER) {
31615- /*
31616- * Accessing the stack below %sp is always a bug.
31617- * The large cushion allows instructions like enter
31618- * and pusha to work. ("enter $65535, $31" pushes
31619- * 32 pointers and then decrements %sp by 65535.)
31620- */
31621- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31622- bad_area(regs, error_code, address);
31623- return;
31624- }
31625+ /*
31626+ * Accessing the stack below %sp is always a bug.
31627+ * The large cushion allows instructions like enter
31628+ * and pusha to work. ("enter $65535, $31" pushes
31629+ * 32 pointers and then decrements %sp by 65535.)
31630+ */
31631+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31632+ bad_area(regs, error_code, address);
31633+ return;
31634 }
31635+
31636+#ifdef CONFIG_PAX_SEGMEXEC
31637+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31638+ bad_area(regs, error_code, address);
31639+ return;
31640+ }
31641+#endif
31642+
31643 if (unlikely(expand_stack(vma, address))) {
31644 bad_area(regs, error_code, address);
31645 return;
31646@@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31647 __do_page_fault(regs, error_code);
31648 exception_exit(prev_state);
31649 }
31650+
31651+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31652+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31653+{
31654+ struct mm_struct *mm = current->mm;
31655+ unsigned long ip = regs->ip;
31656+
31657+ if (v8086_mode(regs))
31658+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31659+
31660+#ifdef CONFIG_PAX_PAGEEXEC
31661+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31662+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31663+ return true;
31664+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31665+ return true;
31666+ return false;
31667+ }
31668+#endif
31669+
31670+#ifdef CONFIG_PAX_SEGMEXEC
31671+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31672+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31673+ return true;
31674+ return false;
31675+ }
31676+#endif
31677+
31678+ return false;
31679+}
31680+#endif
31681+
31682+#ifdef CONFIG_PAX_EMUTRAMP
31683+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31684+{
31685+ int err;
31686+
31687+ do { /* PaX: libffi trampoline emulation */
31688+ unsigned char mov, jmp;
31689+ unsigned int addr1, addr2;
31690+
31691+#ifdef CONFIG_X86_64
31692+ if ((regs->ip + 9) >> 32)
31693+ break;
31694+#endif
31695+
31696+ err = get_user(mov, (unsigned char __user *)regs->ip);
31697+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31698+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31699+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31700+
31701+ if (err)
31702+ break;
31703+
31704+ if (mov == 0xB8 && jmp == 0xE9) {
31705+ regs->ax = addr1;
31706+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31707+ return 2;
31708+ }
31709+ } while (0);
31710+
31711+ do { /* PaX: gcc trampoline emulation #1 */
31712+ unsigned char mov1, mov2;
31713+ unsigned short jmp;
31714+ unsigned int addr1, addr2;
31715+
31716+#ifdef CONFIG_X86_64
31717+ if ((regs->ip + 11) >> 32)
31718+ break;
31719+#endif
31720+
31721+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31722+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31723+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31724+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31725+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31726+
31727+ if (err)
31728+ break;
31729+
31730+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31731+ regs->cx = addr1;
31732+ regs->ax = addr2;
31733+ regs->ip = addr2;
31734+ return 2;
31735+ }
31736+ } while (0);
31737+
31738+ do { /* PaX: gcc trampoline emulation #2 */
31739+ unsigned char mov, jmp;
31740+ unsigned int addr1, addr2;
31741+
31742+#ifdef CONFIG_X86_64
31743+ if ((regs->ip + 9) >> 32)
31744+ break;
31745+#endif
31746+
31747+ err = get_user(mov, (unsigned char __user *)regs->ip);
31748+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31749+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31750+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31751+
31752+ if (err)
31753+ break;
31754+
31755+ if (mov == 0xB9 && jmp == 0xE9) {
31756+ regs->cx = addr1;
31757+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31758+ return 2;
31759+ }
31760+ } while (0);
31761+
31762+ return 1; /* PaX in action */
31763+}
31764+
31765+#ifdef CONFIG_X86_64
31766+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31767+{
31768+ int err;
31769+
31770+ do { /* PaX: libffi trampoline emulation */
31771+ unsigned short mov1, mov2, jmp1;
31772+ unsigned char stcclc, jmp2;
31773+ unsigned long addr1, addr2;
31774+
31775+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31776+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31777+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31778+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31779+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31780+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31781+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31782+
31783+ if (err)
31784+ break;
31785+
31786+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31787+ regs->r11 = addr1;
31788+ regs->r10 = addr2;
31789+ if (stcclc == 0xF8)
31790+ regs->flags &= ~X86_EFLAGS_CF;
31791+ else
31792+ regs->flags |= X86_EFLAGS_CF;
31793+ regs->ip = addr1;
31794+ return 2;
31795+ }
31796+ } while (0);
31797+
31798+ do { /* PaX: gcc trampoline emulation #1 */
31799+ unsigned short mov1, mov2, jmp1;
31800+ unsigned char jmp2;
31801+ unsigned int addr1;
31802+ unsigned long addr2;
31803+
31804+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31805+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31806+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31807+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31808+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31809+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31810+
31811+ if (err)
31812+ break;
31813+
31814+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31815+ regs->r11 = addr1;
31816+ regs->r10 = addr2;
31817+ regs->ip = addr1;
31818+ return 2;
31819+ }
31820+ } while (0);
31821+
31822+ do { /* PaX: gcc trampoline emulation #2 */
31823+ unsigned short mov1, mov2, jmp1;
31824+ unsigned char jmp2;
31825+ unsigned long addr1, addr2;
31826+
31827+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31828+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31829+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31830+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31831+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31832+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31833+
31834+ if (err)
31835+ break;
31836+
31837+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31838+ regs->r11 = addr1;
31839+ regs->r10 = addr2;
31840+ regs->ip = addr1;
31841+ return 2;
31842+ }
31843+ } while (0);
31844+
31845+ return 1; /* PaX in action */
31846+}
31847+#endif
31848+
31849+/*
31850+ * PaX: decide what to do with offenders (regs->ip = fault address)
31851+ *
31852+ * returns 1 when task should be killed
31853+ * 2 when gcc trampoline was detected
31854+ */
31855+static int pax_handle_fetch_fault(struct pt_regs *regs)
31856+{
31857+ if (v8086_mode(regs))
31858+ return 1;
31859+
31860+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31861+ return 1;
31862+
31863+#ifdef CONFIG_X86_32
31864+ return pax_handle_fetch_fault_32(regs);
31865+#else
31866+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31867+ return pax_handle_fetch_fault_32(regs);
31868+ else
31869+ return pax_handle_fetch_fault_64(regs);
31870+#endif
31871+}
31872+#endif
31873+
31874+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31875+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31876+{
31877+ long i;
31878+
31879+ printk(KERN_ERR "PAX: bytes at PC: ");
31880+ for (i = 0; i < 20; i++) {
31881+ unsigned char c;
31882+ if (get_user(c, (unsigned char __force_user *)pc+i))
31883+ printk(KERN_CONT "?? ");
31884+ else
31885+ printk(KERN_CONT "%02x ", c);
31886+ }
31887+ printk("\n");
31888+
31889+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31890+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31891+ unsigned long c;
31892+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31893+#ifdef CONFIG_X86_32
31894+ printk(KERN_CONT "???????? ");
31895+#else
31896+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31897+ printk(KERN_CONT "???????? ???????? ");
31898+ else
31899+ printk(KERN_CONT "???????????????? ");
31900+#endif
31901+ } else {
31902+#ifdef CONFIG_X86_64
31903+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31904+ printk(KERN_CONT "%08x ", (unsigned int)c);
31905+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31906+ } else
31907+#endif
31908+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31909+ }
31910+ }
31911+ printk("\n");
31912+}
31913+#endif
31914+
31915+/**
31916+ * probe_kernel_write(): safely attempt to write to a location
31917+ * @dst: address to write to
31918+ * @src: pointer to the data that shall be written
31919+ * @size: size of the data chunk
31920+ *
31921+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31922+ * happens, handle that and return -EFAULT.
31923+ */
31924+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31925+{
31926+ long ret;
31927+ mm_segment_t old_fs = get_fs();
31928+
31929+ set_fs(KERNEL_DS);
31930+ pagefault_disable();
31931+ pax_open_kernel();
31932+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31933+ pax_close_kernel();
31934+ pagefault_enable();
31935+ set_fs(old_fs);
31936+
31937+ return ret ? -EFAULT : 0;
31938+}
31939diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31940index 0596e8e..5626789 100644
31941--- a/arch/x86/mm/gup.c
31942+++ b/arch/x86/mm/gup.c
31943@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31944 addr = start;
31945 len = (unsigned long) nr_pages << PAGE_SHIFT;
31946 end = start + len;
31947- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31948+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31949 (void __user *)start, len)))
31950 return 0;
31951
31952@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31953 goto slow_irqon;
31954 #endif
31955
31956+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31957+ (void __user *)start, len)))
31958+ return 0;
31959+
31960 /*
31961 * XXX: batch / limit 'nr', to avoid large irq off latency
31962 * needs some instrumenting to determine the common sizes used by
31963diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31964index 4500142..53a363c 100644
31965--- a/arch/x86/mm/highmem_32.c
31966+++ b/arch/x86/mm/highmem_32.c
31967@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31968 idx = type + KM_TYPE_NR*smp_processor_id();
31969 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31970 BUG_ON(!pte_none(*(kmap_pte-idx)));
31971+
31972+ pax_open_kernel();
31973 set_pte(kmap_pte-idx, mk_pte(page, prot));
31974+ pax_close_kernel();
31975+
31976 arch_flush_lazy_mmu_mode();
31977
31978 return (void *)vaddr;
31979diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31980index 9d980d8..6bbfacb 100644
31981--- a/arch/x86/mm/hugetlbpage.c
31982+++ b/arch/x86/mm/hugetlbpage.c
31983@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31984 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31985 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31986 unsigned long addr, unsigned long len,
31987- unsigned long pgoff, unsigned long flags)
31988+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31989 {
31990 struct hstate *h = hstate_file(file);
31991 struct vm_unmapped_area_info info;
31992-
31993+
31994 info.flags = 0;
31995 info.length = len;
31996 info.low_limit = TASK_UNMAPPED_BASE;
31997+
31998+#ifdef CONFIG_PAX_RANDMMAP
31999+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32000+ info.low_limit += current->mm->delta_mmap;
32001+#endif
32002+
32003 info.high_limit = TASK_SIZE;
32004 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32005 info.align_offset = 0;
32006+ info.threadstack_offset = offset;
32007 return vm_unmapped_area(&info);
32008 }
32009
32010 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32011 unsigned long addr0, unsigned long len,
32012- unsigned long pgoff, unsigned long flags)
32013+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32014 {
32015 struct hstate *h = hstate_file(file);
32016 struct vm_unmapped_area_info info;
32017@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32018 info.high_limit = current->mm->mmap_base;
32019 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32020 info.align_offset = 0;
32021+ info.threadstack_offset = offset;
32022 addr = vm_unmapped_area(&info);
32023
32024 /*
32025@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32026 VM_BUG_ON(addr != -ENOMEM);
32027 info.flags = 0;
32028 info.low_limit = TASK_UNMAPPED_BASE;
32029+
32030+#ifdef CONFIG_PAX_RANDMMAP
32031+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32032+ info.low_limit += current->mm->delta_mmap;
32033+#endif
32034+
32035 info.high_limit = TASK_SIZE;
32036 addr = vm_unmapped_area(&info);
32037 }
32038@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32039 struct hstate *h = hstate_file(file);
32040 struct mm_struct *mm = current->mm;
32041 struct vm_area_struct *vma;
32042+ unsigned long pax_task_size = TASK_SIZE;
32043+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32044
32045 if (len & ~huge_page_mask(h))
32046 return -EINVAL;
32047- if (len > TASK_SIZE)
32048+
32049+#ifdef CONFIG_PAX_SEGMEXEC
32050+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32051+ pax_task_size = SEGMEXEC_TASK_SIZE;
32052+#endif
32053+
32054+ pax_task_size -= PAGE_SIZE;
32055+
32056+ if (len > pax_task_size)
32057 return -ENOMEM;
32058
32059 if (flags & MAP_FIXED) {
32060@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32061 return addr;
32062 }
32063
32064+#ifdef CONFIG_PAX_RANDMMAP
32065+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32066+#endif
32067+
32068 if (addr) {
32069 addr = ALIGN(addr, huge_page_size(h));
32070 vma = find_vma(mm, addr);
32071- if (TASK_SIZE - len >= addr &&
32072- (!vma || addr + len <= vma->vm_start))
32073+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32074 return addr;
32075 }
32076 if (mm->get_unmapped_area == arch_get_unmapped_area)
32077 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32078- pgoff, flags);
32079+ pgoff, flags, offset);
32080 else
32081 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32082- pgoff, flags);
32083+ pgoff, flags, offset);
32084 }
32085
32086 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32087diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32088index f971306..e83e0f6 100644
32089--- a/arch/x86/mm/init.c
32090+++ b/arch/x86/mm/init.c
32091@@ -4,6 +4,7 @@
32092 #include <linux/swap.h>
32093 #include <linux/memblock.h>
32094 #include <linux/bootmem.h> /* for max_low_pfn */
32095+#include <linux/tboot.h>
32096
32097 #include <asm/cacheflush.h>
32098 #include <asm/e820.h>
32099@@ -17,6 +18,8 @@
32100 #include <asm/proto.h>
32101 #include <asm/dma.h> /* for MAX_DMA_PFN */
32102 #include <asm/microcode.h>
32103+#include <asm/desc.h>
32104+#include <asm/bios_ebda.h>
32105
32106 #include "mm_internal.h"
32107
32108@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32109 early_ioremap_page_table_range_init();
32110 #endif
32111
32112+#ifdef CONFIG_PAX_PER_CPU_PGD
32113+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32114+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32115+ KERNEL_PGD_PTRS);
32116+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32117+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32118+ KERNEL_PGD_PTRS);
32119+ load_cr3(get_cpu_pgd(0, kernel));
32120+#else
32121 load_cr3(swapper_pg_dir);
32122+#endif
32123+
32124 __flush_tlb_all();
32125
32126 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32127@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32128 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32129 * mmio resources as well as potential bios/acpi data regions.
32130 */
32131+
32132+#ifdef CONFIG_GRKERNSEC_KMEM
32133+static unsigned int ebda_start __read_only;
32134+static unsigned int ebda_end __read_only;
32135+#endif
32136+
32137 int devmem_is_allowed(unsigned long pagenr)
32138 {
32139- if (pagenr < 256)
32140+#ifdef CONFIG_GRKERNSEC_KMEM
32141+ /* allow BDA */
32142+ if (!pagenr)
32143 return 1;
32144+ /* allow EBDA */
32145+ if (pagenr >= ebda_start && pagenr < ebda_end)
32146+ return 1;
32147+ /* if tboot is in use, allow access to its hardcoded serial log range */
32148+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32149+ return 1;
32150+#else
32151+ if (!pagenr)
32152+ return 1;
32153+#ifdef CONFIG_VM86
32154+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32155+ return 1;
32156+#endif
32157+#endif
32158+
32159+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32160+ return 1;
32161+#ifdef CONFIG_GRKERNSEC_KMEM
32162+ /* throw out everything else below 1MB */
32163+ if (pagenr <= 256)
32164+ return 0;
32165+#endif
32166 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32167 return 0;
32168 if (!page_is_ram(pagenr))
32169@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32170 #endif
32171 }
32172
32173+#ifdef CONFIG_GRKERNSEC_KMEM
32174+static inline void gr_init_ebda(void)
32175+{
32176+ unsigned int ebda_addr;
32177+ unsigned int ebda_size = 0;
32178+
32179+ ebda_addr = get_bios_ebda();
32180+ if (ebda_addr) {
32181+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32182+ ebda_size <<= 10;
32183+ }
32184+ if (ebda_addr && ebda_size) {
32185+ ebda_start = ebda_addr >> PAGE_SHIFT;
32186+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32187+ } else {
32188+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32189+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32190+ }
32191+}
32192+#else
32193+static inline void gr_init_ebda(void) { }
32194+#endif
32195+
32196 void free_initmem(void)
32197 {
32198+#ifdef CONFIG_PAX_KERNEXEC
32199+#ifdef CONFIG_X86_32
32200+ /* PaX: limit KERNEL_CS to actual size */
32201+ unsigned long addr, limit;
32202+ struct desc_struct d;
32203+ int cpu;
32204+#else
32205+ pgd_t *pgd;
32206+ pud_t *pud;
32207+ pmd_t *pmd;
32208+ unsigned long addr, end;
32209+#endif
32210+#endif
32211+
32212+ gr_init_ebda();
32213+
32214+#ifdef CONFIG_PAX_KERNEXEC
32215+#ifdef CONFIG_X86_32
32216+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32217+ limit = (limit - 1UL) >> PAGE_SHIFT;
32218+
32219+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32220+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32221+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32222+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32223+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32224+ }
32225+
32226+ /* PaX: make KERNEL_CS read-only */
32227+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32228+ if (!paravirt_enabled())
32229+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32230+/*
32231+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32232+ pgd = pgd_offset_k(addr);
32233+ pud = pud_offset(pgd, addr);
32234+ pmd = pmd_offset(pud, addr);
32235+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32236+ }
32237+*/
32238+#ifdef CONFIG_X86_PAE
32239+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32240+/*
32241+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32242+ pgd = pgd_offset_k(addr);
32243+ pud = pud_offset(pgd, addr);
32244+ pmd = pmd_offset(pud, addr);
32245+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32246+ }
32247+*/
32248+#endif
32249+
32250+#ifdef CONFIG_MODULES
32251+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32252+#endif
32253+
32254+#else
32255+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32256+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32257+ pgd = pgd_offset_k(addr);
32258+ pud = pud_offset(pgd, addr);
32259+ pmd = pmd_offset(pud, addr);
32260+ if (!pmd_present(*pmd))
32261+ continue;
32262+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32263+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32264+ else
32265+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32266+ }
32267+
32268+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32269+ end = addr + KERNEL_IMAGE_SIZE;
32270+ for (; addr < end; addr += PMD_SIZE) {
32271+ pgd = pgd_offset_k(addr);
32272+ pud = pud_offset(pgd, addr);
32273+ pmd = pmd_offset(pud, addr);
32274+ if (!pmd_present(*pmd))
32275+ continue;
32276+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32277+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32278+ }
32279+#endif
32280+
32281+ flush_tlb_all();
32282+#endif
32283+
32284 free_init_pages("unused kernel",
32285 (unsigned long)(&__init_begin),
32286 (unsigned long)(&__init_end));
32287diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32288index 4287f1f..3b99c71 100644
32289--- a/arch/x86/mm/init_32.c
32290+++ b/arch/x86/mm/init_32.c
32291@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32292 bool __read_mostly __vmalloc_start_set = false;
32293
32294 /*
32295- * Creates a middle page table and puts a pointer to it in the
32296- * given global directory entry. This only returns the gd entry
32297- * in non-PAE compilation mode, since the middle layer is folded.
32298- */
32299-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32300-{
32301- pud_t *pud;
32302- pmd_t *pmd_table;
32303-
32304-#ifdef CONFIG_X86_PAE
32305- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32306- pmd_table = (pmd_t *)alloc_low_page();
32307- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32308- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32309- pud = pud_offset(pgd, 0);
32310- BUG_ON(pmd_table != pmd_offset(pud, 0));
32311-
32312- return pmd_table;
32313- }
32314-#endif
32315- pud = pud_offset(pgd, 0);
32316- pmd_table = pmd_offset(pud, 0);
32317-
32318- return pmd_table;
32319-}
32320-
32321-/*
32322 * Create a page table and place a pointer to it in a middle page
32323 * directory entry:
32324 */
32325@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32326 pte_t *page_table = (pte_t *)alloc_low_page();
32327
32328 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32329+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32330+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32331+#else
32332 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32333+#endif
32334 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32335 }
32336
32337 return pte_offset_kernel(pmd, 0);
32338 }
32339
32340+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32341+{
32342+ pud_t *pud;
32343+ pmd_t *pmd_table;
32344+
32345+ pud = pud_offset(pgd, 0);
32346+ pmd_table = pmd_offset(pud, 0);
32347+
32348+ return pmd_table;
32349+}
32350+
32351 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32352 {
32353 int pgd_idx = pgd_index(vaddr);
32354@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32355 int pgd_idx, pmd_idx;
32356 unsigned long vaddr;
32357 pgd_t *pgd;
32358+ pud_t *pud;
32359 pmd_t *pmd;
32360 pte_t *pte = NULL;
32361 unsigned long count = page_table_range_init_count(start, end);
32362@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32363 pgd = pgd_base + pgd_idx;
32364
32365 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32366- pmd = one_md_table_init(pgd);
32367- pmd = pmd + pmd_index(vaddr);
32368+ pud = pud_offset(pgd, vaddr);
32369+ pmd = pmd_offset(pud, vaddr);
32370+
32371+#ifdef CONFIG_X86_PAE
32372+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32373+#endif
32374+
32375 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32376 pmd++, pmd_idx++) {
32377 pte = page_table_kmap_check(one_page_table_init(pmd),
32378@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32379 }
32380 }
32381
32382-static inline int is_kernel_text(unsigned long addr)
32383+static inline int is_kernel_text(unsigned long start, unsigned long end)
32384 {
32385- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32386- return 1;
32387- return 0;
32388+ if ((start > ktla_ktva((unsigned long)_etext) ||
32389+ end <= ktla_ktva((unsigned long)_stext)) &&
32390+ (start > ktla_ktva((unsigned long)_einittext) ||
32391+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32392+
32393+#ifdef CONFIG_ACPI_SLEEP
32394+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32395+#endif
32396+
32397+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32398+ return 0;
32399+ return 1;
32400 }
32401
32402 /*
32403@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32404 unsigned long last_map_addr = end;
32405 unsigned long start_pfn, end_pfn;
32406 pgd_t *pgd_base = swapper_pg_dir;
32407- int pgd_idx, pmd_idx, pte_ofs;
32408+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32409 unsigned long pfn;
32410 pgd_t *pgd;
32411+ pud_t *pud;
32412 pmd_t *pmd;
32413 pte_t *pte;
32414 unsigned pages_2m, pages_4k;
32415@@ -291,8 +295,13 @@ repeat:
32416 pfn = start_pfn;
32417 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32418 pgd = pgd_base + pgd_idx;
32419- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32420- pmd = one_md_table_init(pgd);
32421+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32422+ pud = pud_offset(pgd, 0);
32423+ pmd = pmd_offset(pud, 0);
32424+
32425+#ifdef CONFIG_X86_PAE
32426+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32427+#endif
32428
32429 if (pfn >= end_pfn)
32430 continue;
32431@@ -304,14 +313,13 @@ repeat:
32432 #endif
32433 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32434 pmd++, pmd_idx++) {
32435- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32436+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32437
32438 /*
32439 * Map with big pages if possible, otherwise
32440 * create normal page tables:
32441 */
32442 if (use_pse) {
32443- unsigned int addr2;
32444 pgprot_t prot = PAGE_KERNEL_LARGE;
32445 /*
32446 * first pass will use the same initial
32447@@ -322,11 +330,7 @@ repeat:
32448 _PAGE_PSE);
32449
32450 pfn &= PMD_MASK >> PAGE_SHIFT;
32451- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32452- PAGE_OFFSET + PAGE_SIZE-1;
32453-
32454- if (is_kernel_text(addr) ||
32455- is_kernel_text(addr2))
32456+ if (is_kernel_text(address, address + PMD_SIZE))
32457 prot = PAGE_KERNEL_LARGE_EXEC;
32458
32459 pages_2m++;
32460@@ -343,7 +347,7 @@ repeat:
32461 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32462 pte += pte_ofs;
32463 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32464- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32465+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32466 pgprot_t prot = PAGE_KERNEL;
32467 /*
32468 * first pass will use the same initial
32469@@ -351,7 +355,7 @@ repeat:
32470 */
32471 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32472
32473- if (is_kernel_text(addr))
32474+ if (is_kernel_text(address, address + PAGE_SIZE))
32475 prot = PAGE_KERNEL_EXEC;
32476
32477 pages_4k++;
32478@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32479
32480 pud = pud_offset(pgd, va);
32481 pmd = pmd_offset(pud, va);
32482- if (!pmd_present(*pmd))
32483+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32484 break;
32485
32486 /* should not be large page here */
32487@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32488
32489 static void __init pagetable_init(void)
32490 {
32491- pgd_t *pgd_base = swapper_pg_dir;
32492-
32493- permanent_kmaps_init(pgd_base);
32494+ permanent_kmaps_init(swapper_pg_dir);
32495 }
32496
32497-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32498+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32499 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32500
32501 /* user-defined highmem size */
32502@@ -787,10 +789,10 @@ void __init mem_init(void)
32503 ((unsigned long)&__init_end -
32504 (unsigned long)&__init_begin) >> 10,
32505
32506- (unsigned long)&_etext, (unsigned long)&_edata,
32507- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32508+ (unsigned long)&_sdata, (unsigned long)&_edata,
32509+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32510
32511- (unsigned long)&_text, (unsigned long)&_etext,
32512+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32513 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32514
32515 /*
32516@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32517 if (!kernel_set_to_readonly)
32518 return;
32519
32520+ start = ktla_ktva(start);
32521 pr_debug("Set kernel text: %lx - %lx for read write\n",
32522 start, start+size);
32523
32524@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32525 if (!kernel_set_to_readonly)
32526 return;
32527
32528+ start = ktla_ktva(start);
32529 pr_debug("Set kernel text: %lx - %lx for read only\n",
32530 start, start+size);
32531
32532@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32533 unsigned long start = PFN_ALIGN(_text);
32534 unsigned long size = PFN_ALIGN(_etext) - start;
32535
32536+ start = ktla_ktva(start);
32537 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32538 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32539 size >> 10);
32540diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32541index 104d56a..62ba13f1 100644
32542--- a/arch/x86/mm/init_64.c
32543+++ b/arch/x86/mm/init_64.c
32544@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32545 * around without checking the pgd every time.
32546 */
32547
32548-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32549+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32550 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32551
32552 int force_personality32;
32553@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32554
32555 for (address = start; address <= end; address += PGDIR_SIZE) {
32556 const pgd_t *pgd_ref = pgd_offset_k(address);
32557+
32558+#ifdef CONFIG_PAX_PER_CPU_PGD
32559+ unsigned long cpu;
32560+#else
32561 struct page *page;
32562+#endif
32563
32564 if (pgd_none(*pgd_ref))
32565 continue;
32566
32567 spin_lock(&pgd_lock);
32568+
32569+#ifdef CONFIG_PAX_PER_CPU_PGD
32570+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32571+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32572+
32573+ if (pgd_none(*pgd))
32574+ set_pgd(pgd, *pgd_ref);
32575+ else
32576+ BUG_ON(pgd_page_vaddr(*pgd)
32577+ != pgd_page_vaddr(*pgd_ref));
32578+ pgd = pgd_offset_cpu(cpu, kernel, address);
32579+#else
32580 list_for_each_entry(page, &pgd_list, lru) {
32581 pgd_t *pgd;
32582 spinlock_t *pgt_lock;
32583@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32584 /* the pgt_lock only for Xen */
32585 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32586 spin_lock(pgt_lock);
32587+#endif
32588
32589 if (pgd_none(*pgd))
32590 set_pgd(pgd, *pgd_ref);
32591@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32592 BUG_ON(pgd_page_vaddr(*pgd)
32593 != pgd_page_vaddr(*pgd_ref));
32594
32595+#ifndef CONFIG_PAX_PER_CPU_PGD
32596 spin_unlock(pgt_lock);
32597+#endif
32598+
32599 }
32600 spin_unlock(&pgd_lock);
32601 }
32602@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32603 {
32604 if (pgd_none(*pgd)) {
32605 pud_t *pud = (pud_t *)spp_getpage();
32606- pgd_populate(&init_mm, pgd, pud);
32607+ pgd_populate_kernel(&init_mm, pgd, pud);
32608 if (pud != pud_offset(pgd, 0))
32609 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32610 pud, pud_offset(pgd, 0));
32611@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32612 {
32613 if (pud_none(*pud)) {
32614 pmd_t *pmd = (pmd_t *) spp_getpage();
32615- pud_populate(&init_mm, pud, pmd);
32616+ pud_populate_kernel(&init_mm, pud, pmd);
32617 if (pmd != pmd_offset(pud, 0))
32618 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32619 pmd, pmd_offset(pud, 0));
32620@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32621 pmd = fill_pmd(pud, vaddr);
32622 pte = fill_pte(pmd, vaddr);
32623
32624+ pax_open_kernel();
32625 set_pte(pte, new_pte);
32626+ pax_close_kernel();
32627
32628 /*
32629 * It's enough to flush this one mapping.
32630@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32631 pgd = pgd_offset_k((unsigned long)__va(phys));
32632 if (pgd_none(*pgd)) {
32633 pud = (pud_t *) spp_getpage();
32634- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32635- _PAGE_USER));
32636+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32637 }
32638 pud = pud_offset(pgd, (unsigned long)__va(phys));
32639 if (pud_none(*pud)) {
32640 pmd = (pmd_t *) spp_getpage();
32641- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32642- _PAGE_USER));
32643+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32644 }
32645 pmd = pmd_offset(pud, phys);
32646 BUG_ON(!pmd_none(*pmd));
32647@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32648 prot);
32649
32650 spin_lock(&init_mm.page_table_lock);
32651- pud_populate(&init_mm, pud, pmd);
32652+ pud_populate_kernel(&init_mm, pud, pmd);
32653 spin_unlock(&init_mm.page_table_lock);
32654 }
32655 __flush_tlb_all();
32656@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32657 page_size_mask);
32658
32659 spin_lock(&init_mm.page_table_lock);
32660- pgd_populate(&init_mm, pgd, pud);
32661+ pgd_populate_kernel(&init_mm, pgd, pud);
32662 spin_unlock(&init_mm.page_table_lock);
32663 pgd_changed = true;
32664 }
32665@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32666 static struct vm_area_struct gate_vma = {
32667 .vm_start = VSYSCALL_START,
32668 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32669- .vm_page_prot = PAGE_READONLY_EXEC,
32670- .vm_flags = VM_READ | VM_EXEC
32671+ .vm_page_prot = PAGE_READONLY,
32672+ .vm_flags = VM_READ
32673 };
32674
32675 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32676@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32677
32678 const char *arch_vma_name(struct vm_area_struct *vma)
32679 {
32680- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32681+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32682 return "[vdso]";
32683 if (vma == &gate_vma)
32684 return "[vsyscall]";
32685diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32686index 7b179b4..6bd17777 100644
32687--- a/arch/x86/mm/iomap_32.c
32688+++ b/arch/x86/mm/iomap_32.c
32689@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32690 type = kmap_atomic_idx_push();
32691 idx = type + KM_TYPE_NR * smp_processor_id();
32692 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32693+
32694+ pax_open_kernel();
32695 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32696+ pax_close_kernel();
32697+
32698 arch_flush_lazy_mmu_mode();
32699
32700 return (void *)vaddr;
32701diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32702index 799580c..72f9fe0 100644
32703--- a/arch/x86/mm/ioremap.c
32704+++ b/arch/x86/mm/ioremap.c
32705@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32706 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32707 int is_ram = page_is_ram(pfn);
32708
32709- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32710+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32711 return NULL;
32712 WARN_ON_ONCE(is_ram);
32713 }
32714@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32715 *
32716 * Caller must ensure there is only one unmapping for the same pointer.
32717 */
32718-void iounmap(volatile void __iomem *addr)
32719+void iounmap(const volatile void __iomem *addr)
32720 {
32721 struct vm_struct *p, *o;
32722
32723@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32724
32725 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32726 if (page_is_ram(start >> PAGE_SHIFT))
32727+#ifdef CONFIG_HIGHMEM
32728+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32729+#endif
32730 return __va(phys);
32731
32732 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32733@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32734 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32735 {
32736 if (page_is_ram(phys >> PAGE_SHIFT))
32737+#ifdef CONFIG_HIGHMEM
32738+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32739+#endif
32740 return;
32741
32742 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32743@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32744 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32745
32746 static __initdata int after_paging_init;
32747-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32748+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32749
32750 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32751 {
32752@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32753 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32754
32755 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32756- memset(bm_pte, 0, sizeof(bm_pte));
32757- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32758+ pmd_populate_user(&init_mm, pmd, bm_pte);
32759
32760 /*
32761 * The boot-ioremap range spans multiple pmds, for which
32762diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32763index d87dd6d..bf3fa66 100644
32764--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32765+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32766@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32767 * memory (e.g. tracked pages)? For now, we need this to avoid
32768 * invoking kmemcheck for PnP BIOS calls.
32769 */
32770- if (regs->flags & X86_VM_MASK)
32771+ if (v8086_mode(regs))
32772 return false;
32773- if (regs->cs != __KERNEL_CS)
32774+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32775 return false;
32776
32777 pte = kmemcheck_pte_lookup(address);
32778diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32779index 25e7e13..1964579 100644
32780--- a/arch/x86/mm/mmap.c
32781+++ b/arch/x86/mm/mmap.c
32782@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32783 * Leave an at least ~128 MB hole with possible stack randomization.
32784 */
32785 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32786-#define MAX_GAP (TASK_SIZE/6*5)
32787+#define MAX_GAP (pax_task_size/6*5)
32788
32789 static int mmap_is_legacy(void)
32790 {
32791@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32792 return rnd << PAGE_SHIFT;
32793 }
32794
32795-static unsigned long mmap_base(void)
32796+static unsigned long mmap_base(struct mm_struct *mm)
32797 {
32798 unsigned long gap = rlimit(RLIMIT_STACK);
32799+ unsigned long pax_task_size = TASK_SIZE;
32800+
32801+#ifdef CONFIG_PAX_SEGMEXEC
32802+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32803+ pax_task_size = SEGMEXEC_TASK_SIZE;
32804+#endif
32805
32806 if (gap < MIN_GAP)
32807 gap = MIN_GAP;
32808 else if (gap > MAX_GAP)
32809 gap = MAX_GAP;
32810
32811- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32812+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32813 }
32814
32815 /*
32816 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32817 * does, but not when emulating X86_32
32818 */
32819-static unsigned long mmap_legacy_base(void)
32820+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32821 {
32822- if (mmap_is_ia32())
32823+ if (mmap_is_ia32()) {
32824+
32825+#ifdef CONFIG_PAX_SEGMEXEC
32826+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32827+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32828+ else
32829+#endif
32830+
32831 return TASK_UNMAPPED_BASE;
32832- else
32833+ } else
32834 return TASK_UNMAPPED_BASE + mmap_rnd();
32835 }
32836
32837@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32838 */
32839 void arch_pick_mmap_layout(struct mm_struct *mm)
32840 {
32841- mm->mmap_legacy_base = mmap_legacy_base();
32842- mm->mmap_base = mmap_base();
32843+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32844+ mm->mmap_base = mmap_base(mm);
32845+
32846+#ifdef CONFIG_PAX_RANDMMAP
32847+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32848+ mm->mmap_legacy_base += mm->delta_mmap;
32849+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32850+ }
32851+#endif
32852
32853 if (mmap_is_legacy()) {
32854 mm->mmap_base = mm->mmap_legacy_base;
32855diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32856index 0057a7a..95c7edd 100644
32857--- a/arch/x86/mm/mmio-mod.c
32858+++ b/arch/x86/mm/mmio-mod.c
32859@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32860 break;
32861 default:
32862 {
32863- unsigned char *ip = (unsigned char *)instptr;
32864+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32865 my_trace->opcode = MMIO_UNKNOWN_OP;
32866 my_trace->width = 0;
32867 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32868@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32869 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32870 void __iomem *addr)
32871 {
32872- static atomic_t next_id;
32873+ static atomic_unchecked_t next_id;
32874 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32875 /* These are page-unaligned. */
32876 struct mmiotrace_map map = {
32877@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32878 .private = trace
32879 },
32880 .phys = offset,
32881- .id = atomic_inc_return(&next_id)
32882+ .id = atomic_inc_return_unchecked(&next_id)
32883 };
32884 map.map_id = trace->id;
32885
32886@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32887 ioremap_trace_core(offset, size, addr);
32888 }
32889
32890-static void iounmap_trace_core(volatile void __iomem *addr)
32891+static void iounmap_trace_core(const volatile void __iomem *addr)
32892 {
32893 struct mmiotrace_map map = {
32894 .phys = 0,
32895@@ -328,7 +328,7 @@ not_enabled:
32896 }
32897 }
32898
32899-void mmiotrace_iounmap(volatile void __iomem *addr)
32900+void mmiotrace_iounmap(const volatile void __iomem *addr)
32901 {
32902 might_sleep();
32903 if (is_enabled()) /* recheck and proper locking in *_core() */
32904diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32905index 24aec58..c39fe8b 100644
32906--- a/arch/x86/mm/numa.c
32907+++ b/arch/x86/mm/numa.c
32908@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32909 return true;
32910 }
32911
32912-static int __init numa_register_memblks(struct numa_meminfo *mi)
32913+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32914 {
32915 unsigned long uninitialized_var(pfn_align);
32916 int i, nid;
32917diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32918index d0b1773..4c3327c 100644
32919--- a/arch/x86/mm/pageattr-test.c
32920+++ b/arch/x86/mm/pageattr-test.c
32921@@ -36,7 +36,7 @@ enum {
32922
32923 static int pte_testbit(pte_t pte)
32924 {
32925- return pte_flags(pte) & _PAGE_UNUSED1;
32926+ return pte_flags(pte) & _PAGE_CPA_TEST;
32927 }
32928
32929 struct split_state {
32930diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32931index bb32480..75f2f5e 100644
32932--- a/arch/x86/mm/pageattr.c
32933+++ b/arch/x86/mm/pageattr.c
32934@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32935 */
32936 #ifdef CONFIG_PCI_BIOS
32937 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32938- pgprot_val(forbidden) |= _PAGE_NX;
32939+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32940 #endif
32941
32942 /*
32943@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32944 * Does not cover __inittext since that is gone later on. On
32945 * 64bit we do not enforce !NX on the low mapping
32946 */
32947- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32948- pgprot_val(forbidden) |= _PAGE_NX;
32949+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32950+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32951
32952+#ifdef CONFIG_DEBUG_RODATA
32953 /*
32954 * The .rodata section needs to be read-only. Using the pfn
32955 * catches all aliases.
32956@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32957 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32958 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32959 pgprot_val(forbidden) |= _PAGE_RW;
32960+#endif
32961
32962 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32963 /*
32964@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32965 }
32966 #endif
32967
32968+#ifdef CONFIG_PAX_KERNEXEC
32969+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32970+ pgprot_val(forbidden) |= _PAGE_RW;
32971+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32972+ }
32973+#endif
32974+
32975 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32976
32977 return prot;
32978@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32979 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32980 {
32981 /* change init_mm */
32982+ pax_open_kernel();
32983 set_pte_atomic(kpte, pte);
32984+
32985 #ifdef CONFIG_X86_32
32986 if (!SHARED_KERNEL_PMD) {
32987+
32988+#ifdef CONFIG_PAX_PER_CPU_PGD
32989+ unsigned long cpu;
32990+#else
32991 struct page *page;
32992+#endif
32993
32994+#ifdef CONFIG_PAX_PER_CPU_PGD
32995+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32996+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32997+#else
32998 list_for_each_entry(page, &pgd_list, lru) {
32999- pgd_t *pgd;
33000+ pgd_t *pgd = (pgd_t *)page_address(page);
33001+#endif
33002+
33003 pud_t *pud;
33004 pmd_t *pmd;
33005
33006- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33007+ pgd += pgd_index(address);
33008 pud = pud_offset(pgd, address);
33009 pmd = pmd_offset(pud, address);
33010 set_pte_atomic((pte_t *)pmd, pte);
33011 }
33012 }
33013 #endif
33014+ pax_close_kernel();
33015 }
33016
33017 static int
33018diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33019index 6574388..87e9bef 100644
33020--- a/arch/x86/mm/pat.c
33021+++ b/arch/x86/mm/pat.c
33022@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33023
33024 if (!entry) {
33025 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33026- current->comm, current->pid, start, end - 1);
33027+ current->comm, task_pid_nr(current), start, end - 1);
33028 return -EINVAL;
33029 }
33030
33031@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33032
33033 while (cursor < to) {
33034 if (!devmem_is_allowed(pfn)) {
33035- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33036- current->comm, from, to - 1);
33037+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33038+ current->comm, from, to - 1, cursor);
33039 return 0;
33040 }
33041 cursor += PAGE_SIZE;
33042@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33043 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33044 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33045 "for [mem %#010Lx-%#010Lx]\n",
33046- current->comm, current->pid,
33047+ current->comm, task_pid_nr(current),
33048 cattr_name(flags),
33049 base, (unsigned long long)(base + size-1));
33050 return -EINVAL;
33051@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33052 flags = lookup_memtype(paddr);
33053 if (want_flags != flags) {
33054 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33055- current->comm, current->pid,
33056+ current->comm, task_pid_nr(current),
33057 cattr_name(want_flags),
33058 (unsigned long long)paddr,
33059 (unsigned long long)(paddr + size - 1),
33060@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33061 free_memtype(paddr, paddr + size);
33062 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33063 " for [mem %#010Lx-%#010Lx], got %s\n",
33064- current->comm, current->pid,
33065+ current->comm, task_pid_nr(current),
33066 cattr_name(want_flags),
33067 (unsigned long long)paddr,
33068 (unsigned long long)(paddr + size - 1),
33069diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33070index 415f6c4..d319983 100644
33071--- a/arch/x86/mm/pat_rbtree.c
33072+++ b/arch/x86/mm/pat_rbtree.c
33073@@ -160,7 +160,7 @@ success:
33074
33075 failure:
33076 printk(KERN_INFO "%s:%d conflicting memory types "
33077- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33078+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33079 end, cattr_name(found_type), cattr_name(match->type));
33080 return -EBUSY;
33081 }
33082diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33083index 9f0614d..92ae64a 100644
33084--- a/arch/x86/mm/pf_in.c
33085+++ b/arch/x86/mm/pf_in.c
33086@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33087 int i;
33088 enum reason_type rv = OTHERS;
33089
33090- p = (unsigned char *)ins_addr;
33091+ p = (unsigned char *)ktla_ktva(ins_addr);
33092 p += skip_prefix(p, &prf);
33093 p += get_opcode(p, &opcode);
33094
33095@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33096 struct prefix_bits prf;
33097 int i;
33098
33099- p = (unsigned char *)ins_addr;
33100+ p = (unsigned char *)ktla_ktva(ins_addr);
33101 p += skip_prefix(p, &prf);
33102 p += get_opcode(p, &opcode);
33103
33104@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33105 struct prefix_bits prf;
33106 int i;
33107
33108- p = (unsigned char *)ins_addr;
33109+ p = (unsigned char *)ktla_ktva(ins_addr);
33110 p += skip_prefix(p, &prf);
33111 p += get_opcode(p, &opcode);
33112
33113@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33114 struct prefix_bits prf;
33115 int i;
33116
33117- p = (unsigned char *)ins_addr;
33118+ p = (unsigned char *)ktla_ktva(ins_addr);
33119 p += skip_prefix(p, &prf);
33120 p += get_opcode(p, &opcode);
33121 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33122@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33123 struct prefix_bits prf;
33124 int i;
33125
33126- p = (unsigned char *)ins_addr;
33127+ p = (unsigned char *)ktla_ktva(ins_addr);
33128 p += skip_prefix(p, &prf);
33129 p += get_opcode(p, &opcode);
33130 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33131diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33132index c96314a..433b127 100644
33133--- a/arch/x86/mm/pgtable.c
33134+++ b/arch/x86/mm/pgtable.c
33135@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33136 list_del(&page->lru);
33137 }
33138
33139-#define UNSHARED_PTRS_PER_PGD \
33140- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33141+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33142+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33143
33144+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33145+{
33146+ unsigned int count = USER_PGD_PTRS;
33147
33148+ if (!pax_user_shadow_base)
33149+ return;
33150+
33151+ while (count--)
33152+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33153+}
33154+#endif
33155+
33156+#ifdef CONFIG_PAX_PER_CPU_PGD
33157+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33158+{
33159+ unsigned int count = USER_PGD_PTRS;
33160+
33161+ while (count--) {
33162+ pgd_t pgd;
33163+
33164+#ifdef CONFIG_X86_64
33165+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33166+#else
33167+ pgd = *src++;
33168+#endif
33169+
33170+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33171+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33172+#endif
33173+
33174+ *dst++ = pgd;
33175+ }
33176+
33177+}
33178+#endif
33179+
33180+#ifdef CONFIG_X86_64
33181+#define pxd_t pud_t
33182+#define pyd_t pgd_t
33183+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33184+#define pgtable_pxd_page_ctor(page) true
33185+#define pgtable_pxd_page_dtor(page)
33186+#define pxd_free(mm, pud) pud_free((mm), (pud))
33187+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33188+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33189+#define PYD_SIZE PGDIR_SIZE
33190+#else
33191+#define pxd_t pmd_t
33192+#define pyd_t pud_t
33193+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33194+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33195+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33196+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33197+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33198+#define pyd_offset(mm, address) pud_offset((mm), (address))
33199+#define PYD_SIZE PUD_SIZE
33200+#endif
33201+
33202+#ifdef CONFIG_PAX_PER_CPU_PGD
33203+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33204+static inline void pgd_dtor(pgd_t *pgd) {}
33205+#else
33206 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33207 {
33208 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33209@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33210 pgd_list_del(pgd);
33211 spin_unlock(&pgd_lock);
33212 }
33213+#endif
33214
33215 /*
33216 * List of all pgd's needed for non-PAE so it can invalidate entries
33217@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33218 * -- nyc
33219 */
33220
33221-#ifdef CONFIG_X86_PAE
33222+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33223 /*
33224 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33225 * updating the top-level pagetable entries to guarantee the
33226@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33227 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33228 * and initialize the kernel pmds here.
33229 */
33230-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33231+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33232
33233 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33234 {
33235@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33236 */
33237 flush_tlb_mm(mm);
33238 }
33239+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33240+#define PREALLOCATED_PXDS USER_PGD_PTRS
33241 #else /* !CONFIG_X86_PAE */
33242
33243 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33244-#define PREALLOCATED_PMDS 0
33245+#define PREALLOCATED_PXDS 0
33246
33247 #endif /* CONFIG_X86_PAE */
33248
33249-static void free_pmds(pmd_t *pmds[])
33250+static void free_pxds(pxd_t *pxds[])
33251 {
33252 int i;
33253
33254- for(i = 0; i < PREALLOCATED_PMDS; i++)
33255- if (pmds[i]) {
33256- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33257- free_page((unsigned long)pmds[i]);
33258+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33259+ if (pxds[i]) {
33260+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33261+ free_page((unsigned long)pxds[i]);
33262 }
33263 }
33264
33265-static int preallocate_pmds(pmd_t *pmds[])
33266+static int preallocate_pxds(pxd_t *pxds[])
33267 {
33268 int i;
33269 bool failed = false;
33270
33271- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33272- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33273- if (!pmd)
33274+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33275+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33276+ if (!pxd)
33277 failed = true;
33278- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33279- free_page((unsigned long)pmd);
33280- pmd = NULL;
33281+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33282+ free_page((unsigned long)pxd);
33283+ pxd = NULL;
33284 failed = true;
33285 }
33286- pmds[i] = pmd;
33287+ pxds[i] = pxd;
33288 }
33289
33290 if (failed) {
33291- free_pmds(pmds);
33292+ free_pxds(pxds);
33293 return -ENOMEM;
33294 }
33295
33296@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33297 * preallocate which never got a corresponding vma will need to be
33298 * freed manually.
33299 */
33300-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33301+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33302 {
33303 int i;
33304
33305- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33306+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33307 pgd_t pgd = pgdp[i];
33308
33309 if (pgd_val(pgd) != 0) {
33310- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33311+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33312
33313- pgdp[i] = native_make_pgd(0);
33314+ set_pgd(pgdp + i, native_make_pgd(0));
33315
33316- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33317- pmd_free(mm, pmd);
33318+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33319+ pxd_free(mm, pxd);
33320 }
33321 }
33322 }
33323
33324-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33325+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33326 {
33327- pud_t *pud;
33328+ pyd_t *pyd;
33329 int i;
33330
33331- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33332+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33333 return;
33334
33335- pud = pud_offset(pgd, 0);
33336-
33337- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33338- pmd_t *pmd = pmds[i];
33339+#ifdef CONFIG_X86_64
33340+ pyd = pyd_offset(mm, 0L);
33341+#else
33342+ pyd = pyd_offset(pgd, 0L);
33343+#endif
33344
33345+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33346+ pxd_t *pxd = pxds[i];
33347 if (i >= KERNEL_PGD_BOUNDARY)
33348- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33349- sizeof(pmd_t) * PTRS_PER_PMD);
33350+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33351+ sizeof(pxd_t) * PTRS_PER_PMD);
33352
33353- pud_populate(mm, pud, pmd);
33354+ pyd_populate(mm, pyd, pxd);
33355 }
33356 }
33357
33358 pgd_t *pgd_alloc(struct mm_struct *mm)
33359 {
33360 pgd_t *pgd;
33361- pmd_t *pmds[PREALLOCATED_PMDS];
33362+ pxd_t *pxds[PREALLOCATED_PXDS];
33363
33364 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33365
33366@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33367
33368 mm->pgd = pgd;
33369
33370- if (preallocate_pmds(pmds) != 0)
33371+ if (preallocate_pxds(pxds) != 0)
33372 goto out_free_pgd;
33373
33374 if (paravirt_pgd_alloc(mm) != 0)
33375- goto out_free_pmds;
33376+ goto out_free_pxds;
33377
33378 /*
33379 * Make sure that pre-populating the pmds is atomic with
33380@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33381 spin_lock(&pgd_lock);
33382
33383 pgd_ctor(mm, pgd);
33384- pgd_prepopulate_pmd(mm, pgd, pmds);
33385+ pgd_prepopulate_pxd(mm, pgd, pxds);
33386
33387 spin_unlock(&pgd_lock);
33388
33389 return pgd;
33390
33391-out_free_pmds:
33392- free_pmds(pmds);
33393+out_free_pxds:
33394+ free_pxds(pxds);
33395 out_free_pgd:
33396 free_page((unsigned long)pgd);
33397 out:
33398@@ -313,7 +380,7 @@ out:
33399
33400 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33401 {
33402- pgd_mop_up_pmds(mm, pgd);
33403+ pgd_mop_up_pxds(mm, pgd);
33404 pgd_dtor(pgd);
33405 paravirt_pgd_free(mm, pgd);
33406 free_page((unsigned long)pgd);
33407diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33408index a69bcb8..19068ab 100644
33409--- a/arch/x86/mm/pgtable_32.c
33410+++ b/arch/x86/mm/pgtable_32.c
33411@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33412 return;
33413 }
33414 pte = pte_offset_kernel(pmd, vaddr);
33415+
33416+ pax_open_kernel();
33417 if (pte_val(pteval))
33418 set_pte_at(&init_mm, vaddr, pte, pteval);
33419 else
33420 pte_clear(&init_mm, vaddr, pte);
33421+ pax_close_kernel();
33422
33423 /*
33424 * It's enough to flush this one mapping.
33425diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33426index e666cbb..61788c45 100644
33427--- a/arch/x86/mm/physaddr.c
33428+++ b/arch/x86/mm/physaddr.c
33429@@ -10,7 +10,7 @@
33430 #ifdef CONFIG_X86_64
33431
33432 #ifdef CONFIG_DEBUG_VIRTUAL
33433-unsigned long __phys_addr(unsigned long x)
33434+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33435 {
33436 unsigned long y = x - __START_KERNEL_map;
33437
33438@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33439 #else
33440
33441 #ifdef CONFIG_DEBUG_VIRTUAL
33442-unsigned long __phys_addr(unsigned long x)
33443+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33444 {
33445 unsigned long phys_addr = x - PAGE_OFFSET;
33446 /* VMALLOC_* aren't constants */
33447diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33448index 90555bf..f5f1828 100644
33449--- a/arch/x86/mm/setup_nx.c
33450+++ b/arch/x86/mm/setup_nx.c
33451@@ -5,8 +5,10 @@
33452 #include <asm/pgtable.h>
33453 #include <asm/proto.h>
33454
33455+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33456 static int disable_nx;
33457
33458+#ifndef CONFIG_PAX_PAGEEXEC
33459 /*
33460 * noexec = on|off
33461 *
33462@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33463 return 0;
33464 }
33465 early_param("noexec", noexec_setup);
33466+#endif
33467+
33468+#endif
33469
33470 void x86_configure_nx(void)
33471 {
33472+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33473 if (cpu_has_nx && !disable_nx)
33474 __supported_pte_mask |= _PAGE_NX;
33475 else
33476+#endif
33477 __supported_pte_mask &= ~_PAGE_NX;
33478 }
33479
33480diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33481index ae699b3..f1b2ad2 100644
33482--- a/arch/x86/mm/tlb.c
33483+++ b/arch/x86/mm/tlb.c
33484@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33485 BUG();
33486 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33487 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33488+
33489+#ifndef CONFIG_PAX_PER_CPU_PGD
33490 load_cr3(swapper_pg_dir);
33491+#endif
33492+
33493 }
33494 }
33495 EXPORT_SYMBOL_GPL(leave_mm);
33496diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33497new file mode 100644
33498index 0000000..dace51c
33499--- /dev/null
33500+++ b/arch/x86/mm/uderef_64.c
33501@@ -0,0 +1,37 @@
33502+#include <linux/mm.h>
33503+#include <asm/pgtable.h>
33504+#include <asm/uaccess.h>
33505+
33506+#ifdef CONFIG_PAX_MEMORY_UDEREF
33507+/* PaX: due to the special call convention these functions must
33508+ * - remain leaf functions under all configurations,
33509+ * - never be called directly, only dereferenced from the wrappers.
33510+ */
33511+void __pax_open_userland(void)
33512+{
33513+ unsigned int cpu;
33514+
33515+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33516+ return;
33517+
33518+ cpu = raw_get_cpu();
33519+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33520+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33521+ raw_put_cpu_no_resched();
33522+}
33523+EXPORT_SYMBOL(__pax_open_userland);
33524+
33525+void __pax_close_userland(void)
33526+{
33527+ unsigned int cpu;
33528+
33529+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33530+ return;
33531+
33532+ cpu = raw_get_cpu();
33533+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33534+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33535+ raw_put_cpu_no_resched();
33536+}
33537+EXPORT_SYMBOL(__pax_close_userland);
33538+#endif
33539diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33540index 0149575..f746de8 100644
33541--- a/arch/x86/net/bpf_jit.S
33542+++ b/arch/x86/net/bpf_jit.S
33543@@ -9,6 +9,7 @@
33544 */
33545 #include <linux/linkage.h>
33546 #include <asm/dwarf2.h>
33547+#include <asm/alternative-asm.h>
33548
33549 /*
33550 * Calling convention :
33551@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33552 jle bpf_slow_path_word
33553 mov (SKBDATA,%rsi),%eax
33554 bswap %eax /* ntohl() */
33555+ pax_force_retaddr
33556 ret
33557
33558 sk_load_half:
33559@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33560 jle bpf_slow_path_half
33561 movzwl (SKBDATA,%rsi),%eax
33562 rol $8,%ax # ntohs()
33563+ pax_force_retaddr
33564 ret
33565
33566 sk_load_byte:
33567@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33568 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33569 jle bpf_slow_path_byte
33570 movzbl (SKBDATA,%rsi),%eax
33571+ pax_force_retaddr
33572 ret
33573
33574 /**
33575@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33576 movzbl (SKBDATA,%rsi),%ebx
33577 and $15,%bl
33578 shl $2,%bl
33579+ pax_force_retaddr
33580 ret
33581
33582 /* rsi contains offset and can be scratched */
33583@@ -109,6 +114,7 @@ bpf_slow_path_word:
33584 js bpf_error
33585 mov -12(%rbp),%eax
33586 bswap %eax
33587+ pax_force_retaddr
33588 ret
33589
33590 bpf_slow_path_half:
33591@@ -117,12 +123,14 @@ bpf_slow_path_half:
33592 mov -12(%rbp),%ax
33593 rol $8,%ax
33594 movzwl %ax,%eax
33595+ pax_force_retaddr
33596 ret
33597
33598 bpf_slow_path_byte:
33599 bpf_slow_path_common(1)
33600 js bpf_error
33601 movzbl -12(%rbp),%eax
33602+ pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_byte_msh:
33606@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33607 and $15,%al
33608 shl $2,%al
33609 xchg %eax,%ebx
33610+ pax_force_retaddr
33611 ret
33612
33613 #define sk_negative_common(SIZE) \
33614@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33615 sk_negative_common(4)
33616 mov (%rax), %eax
33617 bswap %eax
33618+ pax_force_retaddr
33619 ret
33620
33621 bpf_slow_path_half_neg:
33622@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33623 mov (%rax),%ax
33624 rol $8,%ax
33625 movzwl %ax,%eax
33626+ pax_force_retaddr
33627 ret
33628
33629 bpf_slow_path_byte_neg:
33630@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33631 .globl sk_load_byte_negative_offset
33632 sk_negative_common(1)
33633 movzbl (%rax), %eax
33634+ pax_force_retaddr
33635 ret
33636
33637 bpf_slow_path_byte_msh_neg:
33638@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33639 and $15,%al
33640 shl $2,%al
33641 xchg %eax,%ebx
33642+ pax_force_retaddr
33643 ret
33644
33645 bpf_error:
33646@@ -197,4 +210,5 @@ bpf_error:
33647 xor %eax,%eax
33648 mov -8(%rbp),%rbx
33649 leaveq
33650+ pax_force_retaddr
33651 ret
33652diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33653index 4ed75dd..3cf24f0b 100644
33654--- a/arch/x86/net/bpf_jit_comp.c
33655+++ b/arch/x86/net/bpf_jit_comp.c
33656@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33657 return ptr + len;
33658 }
33659
33660+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33661+#define MAX_INSTR_CODE_SIZE 96
33662+#else
33663+#define MAX_INSTR_CODE_SIZE 64
33664+#endif
33665+
33666 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33667
33668 #define EMIT1(b1) EMIT(b1, 1)
33669 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33670 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33671 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33672+
33673+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33674+/* original constant will appear in ecx */
33675+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33676+do { \
33677+ /* mov ecx, randkey */ \
33678+ EMIT1(0xb9); \
33679+ EMIT(_key, 4); \
33680+ /* xor ecx, randkey ^ off */ \
33681+ EMIT2(0x81, 0xf1); \
33682+ EMIT((_key) ^ (_off), 4); \
33683+} while (0)
33684+
33685+#define EMIT1_off32(b1, _off) \
33686+do { \
33687+ switch (b1) { \
33688+ case 0x05: /* add eax, imm32 */ \
33689+ case 0x2d: /* sub eax, imm32 */ \
33690+ case 0x25: /* and eax, imm32 */ \
33691+ case 0x0d: /* or eax, imm32 */ \
33692+ case 0xb8: /* mov eax, imm32 */ \
33693+ case 0x35: /* xor eax, imm32 */ \
33694+ case 0x3d: /* cmp eax, imm32 */ \
33695+ case 0xa9: /* test eax, imm32 */ \
33696+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33697+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33698+ break; \
33699+ case 0xbb: /* mov ebx, imm32 */ \
33700+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33701+ /* mov ebx, ecx */ \
33702+ EMIT2(0x89, 0xcb); \
33703+ break; \
33704+ case 0xbe: /* mov esi, imm32 */ \
33705+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33706+ /* mov esi, ecx */ \
33707+ EMIT2(0x89, 0xce); \
33708+ break; \
33709+ case 0xe8: /* call rel imm32, always to known funcs */ \
33710+ EMIT1(b1); \
33711+ EMIT(_off, 4); \
33712+ break; \
33713+ case 0xe9: /* jmp rel imm32 */ \
33714+ EMIT1(b1); \
33715+ EMIT(_off, 4); \
33716+ /* prevent fall-through, we're not called if off = 0 */ \
33717+ EMIT(0xcccccccc, 4); \
33718+ EMIT(0xcccccccc, 4); \
33719+ break; \
33720+ default: \
33721+ BUILD_BUG(); \
33722+ } \
33723+} while (0)
33724+
33725+#define EMIT2_off32(b1, b2, _off) \
33726+do { \
33727+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33728+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33729+ EMIT(randkey, 4); \
33730+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33731+ EMIT((_off) - randkey, 4); \
33732+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33733+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33734+ /* imul eax, ecx */ \
33735+ EMIT3(0x0f, 0xaf, 0xc1); \
33736+ } else { \
33737+ BUILD_BUG(); \
33738+ } \
33739+} while (0)
33740+#else
33741 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33742+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33743+#endif
33744
33745 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33746 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33747@@ -91,6 +168,24 @@ do { \
33748 #define X86_JBE 0x76
33749 #define X86_JA 0x77
33750
33751+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33752+#define APPEND_FLOW_VERIFY() \
33753+do { \
33754+ /* mov ecx, randkey */ \
33755+ EMIT1(0xb9); \
33756+ EMIT(randkey, 4); \
33757+ /* cmp ecx, randkey */ \
33758+ EMIT2(0x81, 0xf9); \
33759+ EMIT(randkey, 4); \
33760+ /* jz after 8 int 3s */ \
33761+ EMIT2(0x74, 0x08); \
33762+ EMIT(0xcccccccc, 4); \
33763+ EMIT(0xcccccccc, 4); \
33764+} while (0)
33765+#else
33766+#define APPEND_FLOW_VERIFY() do { } while (0)
33767+#endif
33768+
33769 #define EMIT_COND_JMP(op, offset) \
33770 do { \
33771 if (is_near(offset)) \
33772@@ -98,6 +193,7 @@ do { \
33773 else { \
33774 EMIT2(0x0f, op + 0x10); \
33775 EMIT(offset, 4); /* jxx .+off32 */ \
33776+ APPEND_FLOW_VERIFY(); \
33777 } \
33778 } while (0)
33779
33780@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33781 return -1;
33782 }
33783
33784-struct bpf_binary_header {
33785- unsigned int pages;
33786- /* Note : for security reasons, bpf code will follow a randomly
33787- * sized amount of int3 instructions
33788- */
33789- u8 image[];
33790-};
33791-
33792-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33793+/* Note : for security reasons, bpf code will follow a randomly
33794+ * sized amount of int3 instructions
33795+ */
33796+static u8 *bpf_alloc_binary(unsigned int proglen,
33797 u8 **image_ptr)
33798 {
33799 unsigned int sz, hole;
33800- struct bpf_binary_header *header;
33801+ u8 *header;
33802
33803 /* Most of BPF filters are really small,
33804 * but if some of them fill a page, allow at least
33805 * 128 extra bytes to insert a random section of int3
33806 */
33807- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33808- header = module_alloc(sz);
33809+ sz = round_up(proglen + 128, PAGE_SIZE);
33810+ header = module_alloc_exec(sz);
33811 if (!header)
33812 return NULL;
33813
33814+ pax_open_kernel();
33815 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33816+ pax_close_kernel();
33817
33818- header->pages = sz / PAGE_SIZE;
33819- hole = sz - (proglen + sizeof(*header));
33820+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33821
33822 /* insert a random number of int3 instructions before BPF code */
33823- *image_ptr = &header->image[prandom_u32() % hole];
33824+ *image_ptr = &header[prandom_u32() % hole];
33825 return header;
33826 }
33827
33828 void bpf_jit_compile(struct sk_filter *fp)
33829 {
33830- u8 temp[64];
33831+ u8 temp[MAX_INSTR_CODE_SIZE];
33832 u8 *prog;
33833 unsigned int proglen, oldproglen = 0;
33834 int ilen, i;
33835 int t_offset, f_offset;
33836 u8 t_op, f_op, seen = 0, pass;
33837 u8 *image = NULL;
33838- struct bpf_binary_header *header = NULL;
33839+ u8 *header = NULL;
33840 u8 *func;
33841 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33842 unsigned int cleanup_addr; /* epilogue code offset */
33843 unsigned int *addrs;
33844 const struct sock_filter *filter = fp->insns;
33845 int flen = fp->len;
33846+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33847+ unsigned int randkey;
33848+#endif
33849
33850 if (!bpf_jit_enable)
33851 return;
33852@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33853 return;
33854
33855 /* Before first pass, make a rough estimation of addrs[]
33856- * each bpf instruction is translated to less than 64 bytes
33857+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33858 */
33859 for (proglen = 0, i = 0; i < flen; i++) {
33860- proglen += 64;
33861+ proglen += MAX_INSTR_CODE_SIZE;
33862 addrs[i] = proglen;
33863 }
33864 cleanup_addr = proglen; /* epilogue address */
33865@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33866 for (i = 0; i < flen; i++) {
33867 unsigned int K = filter[i].k;
33868
33869+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33870+ randkey = prandom_u32();
33871+#endif
33872+
33873 switch (filter[i].code) {
33874 case BPF_S_ALU_ADD_X: /* A += X; */
33875 seen |= SEEN_XREG;
33876@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33877 case BPF_S_ALU_MUL_K: /* A *= K */
33878 if (is_imm8(K))
33879 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33880- else {
33881- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33882- EMIT(K, 4);
33883- }
33884+ else
33885+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33886 break;
33887 case BPF_S_ALU_DIV_X: /* A /= X; */
33888 seen |= SEEN_XREG;
33889@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33890 break;
33891 }
33892 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33893+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33894+ DILUTE_CONST_SEQUENCE(K, randkey);
33895+#else
33896 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33897+#endif
33898 EMIT2(0xf7, 0xf1); /* div %ecx */
33899 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33900 break;
33901@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33902 if (K == 1)
33903 break;
33904 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33905+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33906+ DILUTE_CONST_SEQUENCE(K, randkey);
33907+#else
33908 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33909+#endif
33910 EMIT2(0xf7, 0xf1); /* div %ecx */
33911 break;
33912 case BPF_S_ALU_AND_X:
33913@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33914 if (is_imm8(K)) {
33915 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33916 } else {
33917- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33918- EMIT(K, 4);
33919+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33920 }
33921 } else {
33922 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33923@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33924 if (unlikely(proglen + ilen > oldproglen)) {
33925 pr_err("bpb_jit_compile fatal error\n");
33926 kfree(addrs);
33927- module_free(NULL, header);
33928+ module_free_exec(NULL, image);
33929 return;
33930 }
33931+ pax_open_kernel();
33932 memcpy(image + proglen, temp, ilen);
33933+ pax_close_kernel();
33934 }
33935 proglen += ilen;
33936 addrs[i] = proglen;
33937@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33938
33939 if (image) {
33940 bpf_flush_icache(header, image + proglen);
33941- set_memory_ro((unsigned long)header, header->pages);
33942 fp->bpf_func = (void *)image;
33943 }
33944 out:
33945@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33946 {
33947 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33948 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33949- struct bpf_binary_header *header = (void *)addr;
33950
33951- set_memory_rw(addr, header->pages);
33952- module_free(NULL, header);
33953+ set_memory_rw(addr, 1);
33954+ module_free_exec(NULL, (void *)addr);
33955 kfree(fp);
33956 }
33957
33958diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33959index 5d04be5..2beeaa2 100644
33960--- a/arch/x86/oprofile/backtrace.c
33961+++ b/arch/x86/oprofile/backtrace.c
33962@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33963 struct stack_frame_ia32 *fp;
33964 unsigned long bytes;
33965
33966- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33967+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33968 if (bytes != 0)
33969 return NULL;
33970
33971- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33972+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33973
33974 oprofile_add_trace(bufhead[0].return_address);
33975
33976@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33977 struct stack_frame bufhead[2];
33978 unsigned long bytes;
33979
33980- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33981+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33982 if (bytes != 0)
33983 return NULL;
33984
33985@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33986 {
33987 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33988
33989- if (!user_mode_vm(regs)) {
33990+ if (!user_mode(regs)) {
33991 unsigned long stack = kernel_stack_pointer(regs);
33992 if (depth)
33993 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33994diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33995index 6890d84..1dad1f1 100644
33996--- a/arch/x86/oprofile/nmi_int.c
33997+++ b/arch/x86/oprofile/nmi_int.c
33998@@ -23,6 +23,7 @@
33999 #include <asm/nmi.h>
34000 #include <asm/msr.h>
34001 #include <asm/apic.h>
34002+#include <asm/pgtable.h>
34003
34004 #include "op_counter.h"
34005 #include "op_x86_model.h"
34006@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34007 if (ret)
34008 return ret;
34009
34010- if (!model->num_virt_counters)
34011- model->num_virt_counters = model->num_counters;
34012+ if (!model->num_virt_counters) {
34013+ pax_open_kernel();
34014+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34015+ pax_close_kernel();
34016+ }
34017
34018 mux_init(ops);
34019
34020diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34021index 50d86c0..7985318 100644
34022--- a/arch/x86/oprofile/op_model_amd.c
34023+++ b/arch/x86/oprofile/op_model_amd.c
34024@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34025 num_counters = AMD64_NUM_COUNTERS;
34026 }
34027
34028- op_amd_spec.num_counters = num_counters;
34029- op_amd_spec.num_controls = num_counters;
34030- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34031+ pax_open_kernel();
34032+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34033+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34034+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34035+ pax_close_kernel();
34036
34037 return 0;
34038 }
34039diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34040index d90528e..0127e2b 100644
34041--- a/arch/x86/oprofile/op_model_ppro.c
34042+++ b/arch/x86/oprofile/op_model_ppro.c
34043@@ -19,6 +19,7 @@
34044 #include <asm/msr.h>
34045 #include <asm/apic.h>
34046 #include <asm/nmi.h>
34047+#include <asm/pgtable.h>
34048
34049 #include "op_x86_model.h"
34050 #include "op_counter.h"
34051@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34052
34053 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34054
34055- op_arch_perfmon_spec.num_counters = num_counters;
34056- op_arch_perfmon_spec.num_controls = num_counters;
34057+ pax_open_kernel();
34058+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34059+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34060+ pax_close_kernel();
34061 }
34062
34063 static int arch_perfmon_init(struct oprofile_operations *ignore)
34064diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34065index 71e8a67..6a313bb 100644
34066--- a/arch/x86/oprofile/op_x86_model.h
34067+++ b/arch/x86/oprofile/op_x86_model.h
34068@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34069 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34070 struct op_msrs const * const msrs);
34071 #endif
34072-};
34073+} __do_const;
34074
34075 struct op_counter_config;
34076
34077diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34078index 51384ca..a25f51e 100644
34079--- a/arch/x86/pci/intel_mid_pci.c
34080+++ b/arch/x86/pci/intel_mid_pci.c
34081@@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34082 pr_info("Intel MID platform detected, using MID PCI ops\n");
34083 pci_mmcfg_late_init();
34084 pcibios_enable_irq = intel_mid_pci_irq_enable;
34085- pci_root_ops = intel_mid_pci_ops;
34086+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34087 pci_soc_mode = 1;
34088 /* Continue with standard init */
34089 return 1;
34090diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34091index 372e9b8..e775a6c 100644
34092--- a/arch/x86/pci/irq.c
34093+++ b/arch/x86/pci/irq.c
34094@@ -50,7 +50,7 @@ struct irq_router {
34095 struct irq_router_handler {
34096 u16 vendor;
34097 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34098-};
34099+} __do_const;
34100
34101 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34102 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34103@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34104 return 0;
34105 }
34106
34107-static __initdata struct irq_router_handler pirq_routers[] = {
34108+static __initconst const struct irq_router_handler pirq_routers[] = {
34109 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34110 { PCI_VENDOR_ID_AL, ali_router_probe },
34111 { PCI_VENDOR_ID_ITE, ite_router_probe },
34112@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34113 static void __init pirq_find_router(struct irq_router *r)
34114 {
34115 struct irq_routing_table *rt = pirq_table;
34116- struct irq_router_handler *h;
34117+ const struct irq_router_handler *h;
34118
34119 #ifdef CONFIG_PCI_BIOS
34120 if (!rt->signature) {
34121@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34122 return 0;
34123 }
34124
34125-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34126+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34127 {
34128 .callback = fix_broken_hp_bios_irq9,
34129 .ident = "HP Pavilion N5400 Series Laptop",
34130diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34131index c77b24a..c979855 100644
34132--- a/arch/x86/pci/pcbios.c
34133+++ b/arch/x86/pci/pcbios.c
34134@@ -79,7 +79,7 @@ union bios32 {
34135 static struct {
34136 unsigned long address;
34137 unsigned short segment;
34138-} bios32_indirect = { 0, __KERNEL_CS };
34139+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34140
34141 /*
34142 * Returns the entry point for the given service, NULL on error
34143@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34144 unsigned long length; /* %ecx */
34145 unsigned long entry; /* %edx */
34146 unsigned long flags;
34147+ struct desc_struct d, *gdt;
34148
34149 local_irq_save(flags);
34150- __asm__("lcall *(%%edi); cld"
34151+
34152+ gdt = get_cpu_gdt_table(smp_processor_id());
34153+
34154+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34155+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34156+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34157+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34158+
34159+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34160 : "=a" (return_code),
34161 "=b" (address),
34162 "=c" (length),
34163 "=d" (entry)
34164 : "0" (service),
34165 "1" (0),
34166- "D" (&bios32_indirect));
34167+ "D" (&bios32_indirect),
34168+ "r"(__PCIBIOS_DS)
34169+ : "memory");
34170+
34171+ pax_open_kernel();
34172+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34173+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34174+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34175+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34176+ pax_close_kernel();
34177+
34178 local_irq_restore(flags);
34179
34180 switch (return_code) {
34181- case 0:
34182- return address + entry;
34183- case 0x80: /* Not present */
34184- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34185- return 0;
34186- default: /* Shouldn't happen */
34187- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34188- service, return_code);
34189+ case 0: {
34190+ int cpu;
34191+ unsigned char flags;
34192+
34193+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34194+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34195+ printk(KERN_WARNING "bios32_service: not valid\n");
34196 return 0;
34197+ }
34198+ address = address + PAGE_OFFSET;
34199+ length += 16UL; /* some BIOSs underreport this... */
34200+ flags = 4;
34201+ if (length >= 64*1024*1024) {
34202+ length >>= PAGE_SHIFT;
34203+ flags |= 8;
34204+ }
34205+
34206+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34207+ gdt = get_cpu_gdt_table(cpu);
34208+ pack_descriptor(&d, address, length, 0x9b, flags);
34209+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34210+ pack_descriptor(&d, address, length, 0x93, flags);
34211+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34212+ }
34213+ return entry;
34214+ }
34215+ case 0x80: /* Not present */
34216+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34217+ return 0;
34218+ default: /* Shouldn't happen */
34219+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34220+ service, return_code);
34221+ return 0;
34222 }
34223 }
34224
34225 static struct {
34226 unsigned long address;
34227 unsigned short segment;
34228-} pci_indirect = { 0, __KERNEL_CS };
34229+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34230
34231-static int pci_bios_present;
34232+static int pci_bios_present __read_only;
34233
34234 static int check_pcibios(void)
34235 {
34236@@ -131,11 +174,13 @@ static int check_pcibios(void)
34237 unsigned long flags, pcibios_entry;
34238
34239 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34240- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34241+ pci_indirect.address = pcibios_entry;
34242
34243 local_irq_save(flags);
34244- __asm__(
34245- "lcall *(%%edi); cld\n\t"
34246+ __asm__("movw %w6, %%ds\n\t"
34247+ "lcall *%%ss:(%%edi); cld\n\t"
34248+ "push %%ss\n\t"
34249+ "pop %%ds\n\t"
34250 "jc 1f\n\t"
34251 "xor %%ah, %%ah\n"
34252 "1:"
34253@@ -144,7 +189,8 @@ static int check_pcibios(void)
34254 "=b" (ebx),
34255 "=c" (ecx)
34256 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34257- "D" (&pci_indirect)
34258+ "D" (&pci_indirect),
34259+ "r" (__PCIBIOS_DS)
34260 : "memory");
34261 local_irq_restore(flags);
34262
34263@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34264
34265 switch (len) {
34266 case 1:
34267- __asm__("lcall *(%%esi); cld\n\t"
34268+ __asm__("movw %w6, %%ds\n\t"
34269+ "lcall *%%ss:(%%esi); cld\n\t"
34270+ "push %%ss\n\t"
34271+ "pop %%ds\n\t"
34272 "jc 1f\n\t"
34273 "xor %%ah, %%ah\n"
34274 "1:"
34275@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34276 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34277 "b" (bx),
34278 "D" ((long)reg),
34279- "S" (&pci_indirect));
34280+ "S" (&pci_indirect),
34281+ "r" (__PCIBIOS_DS));
34282 /*
34283 * Zero-extend the result beyond 8 bits, do not trust the
34284 * BIOS having done it:
34285@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34286 *value &= 0xff;
34287 break;
34288 case 2:
34289- __asm__("lcall *(%%esi); cld\n\t"
34290+ __asm__("movw %w6, %%ds\n\t"
34291+ "lcall *%%ss:(%%esi); cld\n\t"
34292+ "push %%ss\n\t"
34293+ "pop %%ds\n\t"
34294 "jc 1f\n\t"
34295 "xor %%ah, %%ah\n"
34296 "1:"
34297@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34298 : "1" (PCIBIOS_READ_CONFIG_WORD),
34299 "b" (bx),
34300 "D" ((long)reg),
34301- "S" (&pci_indirect));
34302+ "S" (&pci_indirect),
34303+ "r" (__PCIBIOS_DS));
34304 /*
34305 * Zero-extend the result beyond 16 bits, do not trust the
34306 * BIOS having done it:
34307@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34308 *value &= 0xffff;
34309 break;
34310 case 4:
34311- __asm__("lcall *(%%esi); cld\n\t"
34312+ __asm__("movw %w6, %%ds\n\t"
34313+ "lcall *%%ss:(%%esi); cld\n\t"
34314+ "push %%ss\n\t"
34315+ "pop %%ds\n\t"
34316 "jc 1f\n\t"
34317 "xor %%ah, %%ah\n"
34318 "1:"
34319@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34320 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34321 "b" (bx),
34322 "D" ((long)reg),
34323- "S" (&pci_indirect));
34324+ "S" (&pci_indirect),
34325+ "r" (__PCIBIOS_DS));
34326 break;
34327 }
34328
34329@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34330
34331 switch (len) {
34332 case 1:
34333- __asm__("lcall *(%%esi); cld\n\t"
34334+ __asm__("movw %w6, %%ds\n\t"
34335+ "lcall *%%ss:(%%esi); cld\n\t"
34336+ "push %%ss\n\t"
34337+ "pop %%ds\n\t"
34338 "jc 1f\n\t"
34339 "xor %%ah, %%ah\n"
34340 "1:"
34341@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34342 "c" (value),
34343 "b" (bx),
34344 "D" ((long)reg),
34345- "S" (&pci_indirect));
34346+ "S" (&pci_indirect),
34347+ "r" (__PCIBIOS_DS));
34348 break;
34349 case 2:
34350- __asm__("lcall *(%%esi); cld\n\t"
34351+ __asm__("movw %w6, %%ds\n\t"
34352+ "lcall *%%ss:(%%esi); cld\n\t"
34353+ "push %%ss\n\t"
34354+ "pop %%ds\n\t"
34355 "jc 1f\n\t"
34356 "xor %%ah, %%ah\n"
34357 "1:"
34358@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34359 "c" (value),
34360 "b" (bx),
34361 "D" ((long)reg),
34362- "S" (&pci_indirect));
34363+ "S" (&pci_indirect),
34364+ "r" (__PCIBIOS_DS));
34365 break;
34366 case 4:
34367- __asm__("lcall *(%%esi); cld\n\t"
34368+ __asm__("movw %w6, %%ds\n\t"
34369+ "lcall *%%ss:(%%esi); cld\n\t"
34370+ "push %%ss\n\t"
34371+ "pop %%ds\n\t"
34372 "jc 1f\n\t"
34373 "xor %%ah, %%ah\n"
34374 "1:"
34375@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34376 "c" (value),
34377 "b" (bx),
34378 "D" ((long)reg),
34379- "S" (&pci_indirect));
34380+ "S" (&pci_indirect),
34381+ "r" (__PCIBIOS_DS));
34382 break;
34383 }
34384
34385@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34386
34387 DBG("PCI: Fetching IRQ routing table... ");
34388 __asm__("push %%es\n\t"
34389+ "movw %w8, %%ds\n\t"
34390 "push %%ds\n\t"
34391 "pop %%es\n\t"
34392- "lcall *(%%esi); cld\n\t"
34393+ "lcall *%%ss:(%%esi); cld\n\t"
34394 "pop %%es\n\t"
34395+ "push %%ss\n\t"
34396+ "pop %%ds\n"
34397 "jc 1f\n\t"
34398 "xor %%ah, %%ah\n"
34399 "1:"
34400@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34401 "1" (0),
34402 "D" ((long) &opt),
34403 "S" (&pci_indirect),
34404- "m" (opt)
34405+ "m" (opt),
34406+ "r" (__PCIBIOS_DS)
34407 : "memory");
34408 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34409 if (ret & 0xff00)
34410@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34411 {
34412 int ret;
34413
34414- __asm__("lcall *(%%esi); cld\n\t"
34415+ __asm__("movw %w5, %%ds\n\t"
34416+ "lcall *%%ss:(%%esi); cld\n\t"
34417+ "push %%ss\n\t"
34418+ "pop %%ds\n"
34419 "jc 1f\n\t"
34420 "xor %%ah, %%ah\n"
34421 "1:"
34422@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34423 : "0" (PCIBIOS_SET_PCI_HW_INT),
34424 "b" ((dev->bus->number << 8) | dev->devfn),
34425 "c" ((irq << 8) | (pin + 10)),
34426- "S" (&pci_indirect));
34427+ "S" (&pci_indirect),
34428+ "r" (__PCIBIOS_DS));
34429 return !(ret & 0xff00);
34430 }
34431 EXPORT_SYMBOL(pcibios_set_irq_routing);
34432diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34433index 40e4469..d915bf9 100644
34434--- a/arch/x86/platform/efi/efi_32.c
34435+++ b/arch/x86/platform/efi/efi_32.c
34436@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34437 {
34438 struct desc_ptr gdt_descr;
34439
34440+#ifdef CONFIG_PAX_KERNEXEC
34441+ struct desc_struct d;
34442+#endif
34443+
34444 local_irq_save(efi_rt_eflags);
34445
34446 load_cr3(initial_page_table);
34447 __flush_tlb_all();
34448
34449+#ifdef CONFIG_PAX_KERNEXEC
34450+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34451+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34452+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34453+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34454+#endif
34455+
34456 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34457 gdt_descr.size = GDT_SIZE - 1;
34458 load_gdt(&gdt_descr);
34459@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34460 {
34461 struct desc_ptr gdt_descr;
34462
34463+#ifdef CONFIG_PAX_KERNEXEC
34464+ struct desc_struct d;
34465+
34466+ memset(&d, 0, sizeof d);
34467+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34468+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34469+#endif
34470+
34471 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34472 gdt_descr.size = GDT_SIZE - 1;
34473 load_gdt(&gdt_descr);
34474
34475+#ifdef CONFIG_PAX_PER_CPU_PGD
34476+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34477+#else
34478 load_cr3(swapper_pg_dir);
34479+#endif
34480+
34481 __flush_tlb_all();
34482
34483 local_irq_restore(efi_rt_eflags);
34484diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34485index 39a0e7f1..872396e 100644
34486--- a/arch/x86/platform/efi/efi_64.c
34487+++ b/arch/x86/platform/efi/efi_64.c
34488@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34489 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34490 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34491 }
34492+
34493+#ifdef CONFIG_PAX_PER_CPU_PGD
34494+ load_cr3(swapper_pg_dir);
34495+#endif
34496+
34497 __flush_tlb_all();
34498 }
34499
34500@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34501 for (pgd = 0; pgd < n_pgds; pgd++)
34502 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34503 kfree(save_pgd);
34504+
34505+#ifdef CONFIG_PAX_PER_CPU_PGD
34506+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34507+#endif
34508+
34509 __flush_tlb_all();
34510 local_irq_restore(efi_flags);
34511 early_code_mapping_set_exec(0);
34512diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34513index fbe66e6..eae5e38 100644
34514--- a/arch/x86/platform/efi/efi_stub_32.S
34515+++ b/arch/x86/platform/efi/efi_stub_32.S
34516@@ -6,7 +6,9 @@
34517 */
34518
34519 #include <linux/linkage.h>
34520+#include <linux/init.h>
34521 #include <asm/page_types.h>
34522+#include <asm/segment.h>
34523
34524 /*
34525 * efi_call_phys(void *, ...) is a function with variable parameters.
34526@@ -20,7 +22,7 @@
34527 * service functions will comply with gcc calling convention, too.
34528 */
34529
34530-.text
34531+__INIT
34532 ENTRY(efi_call_phys)
34533 /*
34534 * 0. The function can only be called in Linux kernel. So CS has been
34535@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34536 * The mapping of lower virtual memory has been created in prelog and
34537 * epilog.
34538 */
34539- movl $1f, %edx
34540- subl $__PAGE_OFFSET, %edx
34541- jmp *%edx
34542+#ifdef CONFIG_PAX_KERNEXEC
34543+ movl $(__KERNEXEC_EFI_DS), %edx
34544+ mov %edx, %ds
34545+ mov %edx, %es
34546+ mov %edx, %ss
34547+ addl $2f,(1f)
34548+ ljmp *(1f)
34549+
34550+__INITDATA
34551+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34552+.previous
34553+
34554+2:
34555+ subl $2b,(1b)
34556+#else
34557+ jmp 1f-__PAGE_OFFSET
34558 1:
34559+#endif
34560
34561 /*
34562 * 2. Now on the top of stack is the return
34563@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34564 * parameter 2, ..., param n. To make things easy, we save the return
34565 * address of efi_call_phys in a global variable.
34566 */
34567- popl %edx
34568- movl %edx, saved_return_addr
34569- /* get the function pointer into ECX*/
34570- popl %ecx
34571- movl %ecx, efi_rt_function_ptr
34572- movl $2f, %edx
34573- subl $__PAGE_OFFSET, %edx
34574- pushl %edx
34575+ popl (saved_return_addr)
34576+ popl (efi_rt_function_ptr)
34577
34578 /*
34579 * 3. Clear PG bit in %CR0.
34580@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34581 /*
34582 * 5. Call the physical function.
34583 */
34584- jmp *%ecx
34585+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34586
34587-2:
34588 /*
34589 * 6. After EFI runtime service returns, control will return to
34590 * following instruction. We'd better readjust stack pointer first.
34591@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34592 movl %cr0, %edx
34593 orl $0x80000000, %edx
34594 movl %edx, %cr0
34595- jmp 1f
34596-1:
34597+
34598 /*
34599 * 8. Now restore the virtual mode from flat mode by
34600 * adding EIP with PAGE_OFFSET.
34601 */
34602- movl $1f, %edx
34603- jmp *%edx
34604+#ifdef CONFIG_PAX_KERNEXEC
34605+ movl $(__KERNEL_DS), %edx
34606+ mov %edx, %ds
34607+ mov %edx, %es
34608+ mov %edx, %ss
34609+ ljmp $(__KERNEL_CS),$1f
34610+#else
34611+ jmp 1f+__PAGE_OFFSET
34612+#endif
34613 1:
34614
34615 /*
34616 * 9. Balance the stack. And because EAX contain the return value,
34617 * we'd better not clobber it.
34618 */
34619- leal efi_rt_function_ptr, %edx
34620- movl (%edx), %ecx
34621- pushl %ecx
34622+ pushl (efi_rt_function_ptr)
34623
34624 /*
34625- * 10. Push the saved return address onto the stack and return.
34626+ * 10. Return to the saved return address.
34627 */
34628- leal saved_return_addr, %edx
34629- movl (%edx), %ecx
34630- pushl %ecx
34631- ret
34632+ jmpl *(saved_return_addr)
34633 ENDPROC(efi_call_phys)
34634 .previous
34635
34636-.data
34637+__INITDATA
34638 saved_return_addr:
34639 .long 0
34640 efi_rt_function_ptr:
34641diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34642index 4c07cca..2c8427d 100644
34643--- a/arch/x86/platform/efi/efi_stub_64.S
34644+++ b/arch/x86/platform/efi/efi_stub_64.S
34645@@ -7,6 +7,7 @@
34646 */
34647
34648 #include <linux/linkage.h>
34649+#include <asm/alternative-asm.h>
34650
34651 #define SAVE_XMM \
34652 mov %rsp, %rax; \
34653@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34654 call *%rdi
34655 addq $32, %rsp
34656 RESTORE_XMM
34657+ pax_force_retaddr 0, 1
34658 ret
34659 ENDPROC(efi_call0)
34660
34661@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34662 call *%rdi
34663 addq $32, %rsp
34664 RESTORE_XMM
34665+ pax_force_retaddr 0, 1
34666 ret
34667 ENDPROC(efi_call1)
34668
34669@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34670 call *%rdi
34671 addq $32, %rsp
34672 RESTORE_XMM
34673+ pax_force_retaddr 0, 1
34674 ret
34675 ENDPROC(efi_call2)
34676
34677@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34678 call *%rdi
34679 addq $32, %rsp
34680 RESTORE_XMM
34681+ pax_force_retaddr 0, 1
34682 ret
34683 ENDPROC(efi_call3)
34684
34685@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34686 call *%rdi
34687 addq $32, %rsp
34688 RESTORE_XMM
34689+ pax_force_retaddr 0, 1
34690 ret
34691 ENDPROC(efi_call4)
34692
34693@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34694 call *%rdi
34695 addq $48, %rsp
34696 RESTORE_XMM
34697+ pax_force_retaddr 0, 1
34698 ret
34699 ENDPROC(efi_call5)
34700
34701@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34702 call *%rdi
34703 addq $48, %rsp
34704 RESTORE_XMM
34705+ pax_force_retaddr 0, 1
34706 ret
34707 ENDPROC(efi_call6)
34708diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34709index f90e290..435f0dd 100644
34710--- a/arch/x86/platform/intel-mid/intel-mid.c
34711+++ b/arch/x86/platform/intel-mid/intel-mid.c
34712@@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34713 {
34714 }
34715
34716-static void intel_mid_reboot(void)
34717+static void __noreturn intel_mid_reboot(void)
34718 {
34719 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34720+ BUG();
34721 }
34722
34723 static unsigned long __init intel_mid_calibrate_tsc(void)
34724diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34725index d6ee929..3637cb5 100644
34726--- a/arch/x86/platform/olpc/olpc_dt.c
34727+++ b/arch/x86/platform/olpc/olpc_dt.c
34728@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34729 return res;
34730 }
34731
34732-static struct of_pdt_ops prom_olpc_ops __initdata = {
34733+static struct of_pdt_ops prom_olpc_ops __initconst = {
34734 .nextprop = olpc_dt_nextprop,
34735 .getproplen = olpc_dt_getproplen,
34736 .getproperty = olpc_dt_getproperty,
34737diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34738index 424f4c9..f2a2988 100644
34739--- a/arch/x86/power/cpu.c
34740+++ b/arch/x86/power/cpu.c
34741@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34742 static void fix_processor_context(void)
34743 {
34744 int cpu = smp_processor_id();
34745- struct tss_struct *t = &per_cpu(init_tss, cpu);
34746-#ifdef CONFIG_X86_64
34747- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34748- tss_desc tss;
34749-#endif
34750+ struct tss_struct *t = init_tss + cpu;
34751+
34752 set_tss_desc(cpu, t); /*
34753 * This just modifies memory; should not be
34754 * necessary. But... This is necessary, because
34755@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34756 */
34757
34758 #ifdef CONFIG_X86_64
34759- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34760- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34761- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34762-
34763 syscall_init(); /* This sets MSR_*STAR and related */
34764 #endif
34765 load_TR_desc(); /* This does ltr */
34766diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34767index a44f457..9140171 100644
34768--- a/arch/x86/realmode/init.c
34769+++ b/arch/x86/realmode/init.c
34770@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34771 __va(real_mode_header->trampoline_header);
34772
34773 #ifdef CONFIG_X86_32
34774- trampoline_header->start = __pa_symbol(startup_32_smp);
34775+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34776+
34777+#ifdef CONFIG_PAX_KERNEXEC
34778+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34779+#endif
34780+
34781+ trampoline_header->boot_cs = __BOOT_CS;
34782 trampoline_header->gdt_limit = __BOOT_DS + 7;
34783 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34784 #else
34785@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34786 *trampoline_cr4_features = read_cr4();
34787
34788 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34789- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34790+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34791 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34792 #endif
34793 }
34794diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34795index 9cac825..4890b25 100644
34796--- a/arch/x86/realmode/rm/Makefile
34797+++ b/arch/x86/realmode/rm/Makefile
34798@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34799 $(call cc-option, -fno-unit-at-a-time)) \
34800 $(call cc-option, -fno-stack-protector) \
34801 $(call cc-option, -mpreferred-stack-boundary=2)
34802+ifdef CONSTIFY_PLUGIN
34803+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34804+endif
34805 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34806 GCOV_PROFILE := n
34807diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34808index a28221d..93c40f1 100644
34809--- a/arch/x86/realmode/rm/header.S
34810+++ b/arch/x86/realmode/rm/header.S
34811@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34812 #endif
34813 /* APM/BIOS reboot */
34814 .long pa_machine_real_restart_asm
34815-#ifdef CONFIG_X86_64
34816+#ifdef CONFIG_X86_32
34817+ .long __KERNEL_CS
34818+#else
34819 .long __KERNEL32_CS
34820 #endif
34821 END(real_mode_header)
34822diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34823index c1b2791..f9e31c7 100644
34824--- a/arch/x86/realmode/rm/trampoline_32.S
34825+++ b/arch/x86/realmode/rm/trampoline_32.S
34826@@ -25,6 +25,12 @@
34827 #include <asm/page_types.h>
34828 #include "realmode.h"
34829
34830+#ifdef CONFIG_PAX_KERNEXEC
34831+#define ta(X) (X)
34832+#else
34833+#define ta(X) (pa_ ## X)
34834+#endif
34835+
34836 .text
34837 .code16
34838
34839@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34840
34841 cli # We should be safe anyway
34842
34843- movl tr_start, %eax # where we need to go
34844-
34845 movl $0xA5A5A5A5, trampoline_status
34846 # write marker for master knows we're running
34847
34848@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34849 movw $1, %dx # protected mode (PE) bit
34850 lmsw %dx # into protected mode
34851
34852- ljmpl $__BOOT_CS, $pa_startup_32
34853+ ljmpl *(trampoline_header)
34854
34855 .section ".text32","ax"
34856 .code32
34857@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34858 .balign 8
34859 GLOBAL(trampoline_header)
34860 tr_start: .space 4
34861- tr_gdt_pad: .space 2
34862+ tr_boot_cs: .space 2
34863 tr_gdt: .space 6
34864 END(trampoline_header)
34865
34866diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34867index bb360dc..d0fd8f8 100644
34868--- a/arch/x86/realmode/rm/trampoline_64.S
34869+++ b/arch/x86/realmode/rm/trampoline_64.S
34870@@ -94,6 +94,7 @@ ENTRY(startup_32)
34871 movl %edx, %gs
34872
34873 movl pa_tr_cr4, %eax
34874+ andl $~X86_CR4_PCIDE, %eax
34875 movl %eax, %cr4 # Enable PAE mode
34876
34877 # Setup trampoline 4 level pagetables
34878@@ -107,7 +108,7 @@ ENTRY(startup_32)
34879 wrmsr
34880
34881 # Enable paging and in turn activate Long Mode
34882- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34883+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34884 movl %eax, %cr0
34885
34886 /*
34887diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34888index e812034..c747134 100644
34889--- a/arch/x86/tools/Makefile
34890+++ b/arch/x86/tools/Makefile
34891@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34892
34893 $(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
34894
34895-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34896+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34897 hostprogs-y += relocs
34898 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34899 relocs: $(obj)/relocs
34900diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34901index f7bab68..b6d9886 100644
34902--- a/arch/x86/tools/relocs.c
34903+++ b/arch/x86/tools/relocs.c
34904@@ -1,5 +1,7 @@
34905 /* This is included from relocs_32/64.c */
34906
34907+#include "../../../include/generated/autoconf.h"
34908+
34909 #define ElfW(type) _ElfW(ELF_BITS, type)
34910 #define _ElfW(bits, type) __ElfW(bits, type)
34911 #define __ElfW(bits, type) Elf##bits##_##type
34912@@ -11,6 +13,7 @@
34913 #define Elf_Sym ElfW(Sym)
34914
34915 static Elf_Ehdr ehdr;
34916+static Elf_Phdr *phdr;
34917
34918 struct relocs {
34919 uint32_t *offset;
34920@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34921 }
34922 }
34923
34924+static void read_phdrs(FILE *fp)
34925+{
34926+ unsigned int i;
34927+
34928+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34929+ if (!phdr) {
34930+ die("Unable to allocate %d program headers\n",
34931+ ehdr.e_phnum);
34932+ }
34933+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34934+ die("Seek to %d failed: %s\n",
34935+ ehdr.e_phoff, strerror(errno));
34936+ }
34937+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34938+ die("Cannot read ELF program headers: %s\n",
34939+ strerror(errno));
34940+ }
34941+ for(i = 0; i < ehdr.e_phnum; i++) {
34942+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34943+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34944+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34945+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34946+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34947+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34948+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34949+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34950+ }
34951+
34952+}
34953+
34954 static void read_shdrs(FILE *fp)
34955 {
34956- int i;
34957+ unsigned int i;
34958 Elf_Shdr shdr;
34959
34960 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34961@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34962
34963 static void read_strtabs(FILE *fp)
34964 {
34965- int i;
34966+ unsigned int i;
34967 for (i = 0; i < ehdr.e_shnum; i++) {
34968 struct section *sec = &secs[i];
34969 if (sec->shdr.sh_type != SHT_STRTAB) {
34970@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34971
34972 static void read_symtabs(FILE *fp)
34973 {
34974- int i,j;
34975+ unsigned int i,j;
34976 for (i = 0; i < ehdr.e_shnum; i++) {
34977 struct section *sec = &secs[i];
34978 if (sec->shdr.sh_type != SHT_SYMTAB) {
34979@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34980 }
34981
34982
34983-static void read_relocs(FILE *fp)
34984+static void read_relocs(FILE *fp, int use_real_mode)
34985 {
34986- int i,j;
34987+ unsigned int i,j;
34988+ uint32_t base;
34989+
34990 for (i = 0; i < ehdr.e_shnum; i++) {
34991 struct section *sec = &secs[i];
34992 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34993@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34994 die("Cannot read symbol table: %s\n",
34995 strerror(errno));
34996 }
34997+ base = 0;
34998+
34999+#ifdef CONFIG_X86_32
35000+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35001+ if (phdr[j].p_type != PT_LOAD )
35002+ continue;
35003+ 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)
35004+ continue;
35005+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35006+ break;
35007+ }
35008+#endif
35009+
35010 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35011 Elf_Rel *rel = &sec->reltab[j];
35012- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35013+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35014 rel->r_info = elf_xword_to_cpu(rel->r_info);
35015 #if (SHT_REL_TYPE == SHT_RELA)
35016 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35017@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35018
35019 static void print_absolute_symbols(void)
35020 {
35021- int i;
35022+ unsigned int i;
35023 const char *format;
35024
35025 if (ELF_BITS == 64)
35026@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35027 for (i = 0; i < ehdr.e_shnum; i++) {
35028 struct section *sec = &secs[i];
35029 char *sym_strtab;
35030- int j;
35031+ unsigned int j;
35032
35033 if (sec->shdr.sh_type != SHT_SYMTAB) {
35034 continue;
35035@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35036
35037 static void print_absolute_relocs(void)
35038 {
35039- int i, printed = 0;
35040+ unsigned int i, printed = 0;
35041 const char *format;
35042
35043 if (ELF_BITS == 64)
35044@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35045 struct section *sec_applies, *sec_symtab;
35046 char *sym_strtab;
35047 Elf_Sym *sh_symtab;
35048- int j;
35049+ unsigned int j;
35050 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35051 continue;
35052 }
35053@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35054 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35055 Elf_Sym *sym, const char *symname))
35056 {
35057- int i;
35058+ unsigned int i;
35059 /* Walk through the relocations */
35060 for (i = 0; i < ehdr.e_shnum; i++) {
35061 char *sym_strtab;
35062 Elf_Sym *sh_symtab;
35063 struct section *sec_applies, *sec_symtab;
35064- int j;
35065+ unsigned int j;
35066 struct section *sec = &secs[i];
35067
35068 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35069@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35070 {
35071 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35072 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35073+ char *sym_strtab = sec->link->link->strtab;
35074+
35075+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35076+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35077+ return 0;
35078+
35079+#ifdef CONFIG_PAX_KERNEXEC
35080+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35081+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35082+ return 0;
35083+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35084+ return 0;
35085+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35086+ return 0;
35087+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35088+ return 0;
35089+#endif
35090
35091 switch (r_type) {
35092 case R_386_NONE:
35093@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35094
35095 static void emit_relocs(int as_text, int use_real_mode)
35096 {
35097- int i;
35098+ unsigned int i;
35099 int (*write_reloc)(uint32_t, FILE *) = write32;
35100 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35101 const char *symname);
35102@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35103 {
35104 regex_init(use_real_mode);
35105 read_ehdr(fp);
35106+ read_phdrs(fp);
35107 read_shdrs(fp);
35108 read_strtabs(fp);
35109 read_symtabs(fp);
35110- read_relocs(fp);
35111+ read_relocs(fp, use_real_mode);
35112 if (ELF_BITS == 64)
35113 percpu_init();
35114 if (show_absolute_syms) {
35115diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35116index 80ffa5b..a33bd15 100644
35117--- a/arch/x86/um/tls_32.c
35118+++ b/arch/x86/um/tls_32.c
35119@@ -260,7 +260,7 @@ out:
35120 if (unlikely(task == current &&
35121 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35122 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35123- "without flushed TLS.", current->pid);
35124+ "without flushed TLS.", task_pid_nr(current));
35125 }
35126
35127 return 0;
35128diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35129index fd14be1..e3c79c0 100644
35130--- a/arch/x86/vdso/Makefile
35131+++ b/arch/x86/vdso/Makefile
35132@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35133 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35134 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35135
35136-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35137+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35138 GCOV_PROFILE := n
35139
35140 #
35141diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35142index d6bfb87..876ee18 100644
35143--- a/arch/x86/vdso/vdso32-setup.c
35144+++ b/arch/x86/vdso/vdso32-setup.c
35145@@ -25,6 +25,7 @@
35146 #include <asm/tlbflush.h>
35147 #include <asm/vdso.h>
35148 #include <asm/proto.h>
35149+#include <asm/mman.h>
35150
35151 enum {
35152 VDSO_DISABLED = 0,
35153@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35154 void enable_sep_cpu(void)
35155 {
35156 int cpu = get_cpu();
35157- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35158+ struct tss_struct *tss = init_tss + cpu;
35159
35160 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35161 put_cpu();
35162@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35163 gate_vma.vm_start = FIXADDR_USER_START;
35164 gate_vma.vm_end = FIXADDR_USER_END;
35165 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35166- gate_vma.vm_page_prot = __P101;
35167+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35168
35169 return 0;
35170 }
35171@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35172 if (compat)
35173 addr = VDSO_HIGH_BASE;
35174 else {
35175- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35176+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35177 if (IS_ERR_VALUE(addr)) {
35178 ret = addr;
35179 goto up_fail;
35180 }
35181 }
35182
35183- current->mm->context.vdso = (void *)addr;
35184+ current->mm->context.vdso = addr;
35185
35186 if (compat_uses_vma || !compat) {
35187 /*
35188@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35189 }
35190
35191 current_thread_info()->sysenter_return =
35192- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35193+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35194
35195 up_fail:
35196 if (ret)
35197- current->mm->context.vdso = NULL;
35198+ current->mm->context.vdso = 0;
35199
35200 up_write(&mm->mmap_sem);
35201
35202@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35203
35204 const char *arch_vma_name(struct vm_area_struct *vma)
35205 {
35206- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35207+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35208 return "[vdso]";
35209+
35210+#ifdef CONFIG_PAX_SEGMEXEC
35211+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35212+ return "[vdso]";
35213+#endif
35214+
35215 return NULL;
35216 }
35217
35218@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35219 * Check to see if the corresponding task was created in compat vdso
35220 * mode.
35221 */
35222- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35223+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35224 return &gate_vma;
35225 return NULL;
35226 }
35227diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35228index 431e875..cbb23f3 100644
35229--- a/arch/x86/vdso/vma.c
35230+++ b/arch/x86/vdso/vma.c
35231@@ -16,8 +16,6 @@
35232 #include <asm/vdso.h>
35233 #include <asm/page.h>
35234
35235-unsigned int __read_mostly vdso_enabled = 1;
35236-
35237 extern char vdso_start[], vdso_end[];
35238 extern unsigned short vdso_sync_cpuid;
35239
35240@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35241 * unaligned here as a result of stack start randomization.
35242 */
35243 addr = PAGE_ALIGN(addr);
35244- addr = align_vdso_addr(addr);
35245
35246 return addr;
35247 }
35248@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35249 unsigned size)
35250 {
35251 struct mm_struct *mm = current->mm;
35252- unsigned long addr;
35253+ unsigned long addr = 0;
35254 int ret;
35255
35256- if (!vdso_enabled)
35257- return 0;
35258-
35259 down_write(&mm->mmap_sem);
35260+
35261+#ifdef CONFIG_PAX_RANDMMAP
35262+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35263+#endif
35264+
35265 addr = vdso_addr(mm->start_stack, size);
35266+ addr = align_vdso_addr(addr);
35267 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35268 if (IS_ERR_VALUE(addr)) {
35269 ret = addr;
35270 goto up_fail;
35271 }
35272
35273- current->mm->context.vdso = (void *)addr;
35274+ mm->context.vdso = addr;
35275
35276 ret = install_special_mapping(mm, addr, size,
35277 VM_READ|VM_EXEC|
35278 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35279 pages);
35280- if (ret) {
35281- current->mm->context.vdso = NULL;
35282- goto up_fail;
35283- }
35284+ if (ret)
35285+ mm->context.vdso = 0;
35286
35287 up_fail:
35288 up_write(&mm->mmap_sem);
35289@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35290 vdsox32_size);
35291 }
35292 #endif
35293-
35294-static __init int vdso_setup(char *s)
35295-{
35296- vdso_enabled = simple_strtoul(s, NULL, 0);
35297- return 0;
35298-}
35299-__setup("vdso=", vdso_setup);
35300diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35301index 1a3c765..3d2e8d1 100644
35302--- a/arch/x86/xen/Kconfig
35303+++ b/arch/x86/xen/Kconfig
35304@@ -9,6 +9,7 @@ config XEN
35305 select XEN_HAVE_PVMMU
35306 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35307 depends on X86_TSC
35308+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35309 help
35310 This is the Linux Xen port. Enabling this will allow the
35311 kernel to boot in a paravirtualized environment under the
35312diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35313index fa6ade7..73da73a5 100644
35314--- a/arch/x86/xen/enlighten.c
35315+++ b/arch/x86/xen/enlighten.c
35316@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35317
35318 struct shared_info xen_dummy_shared_info;
35319
35320-void *xen_initial_gdt;
35321-
35322 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35323 __read_mostly int xen_have_vector_callback;
35324 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35325@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35326 {
35327 unsigned long va = dtr->address;
35328 unsigned int size = dtr->size + 1;
35329- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35330- unsigned long frames[pages];
35331+ unsigned long frames[65536 / PAGE_SIZE];
35332 int f;
35333
35334 /*
35335@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35336 {
35337 unsigned long va = dtr->address;
35338 unsigned int size = dtr->size + 1;
35339- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35340- unsigned long frames[pages];
35341+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35342 int f;
35343
35344 /*
35345@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35346 * 8-byte entries, or 16 4k pages..
35347 */
35348
35349- BUG_ON(size > 65536);
35350+ BUG_ON(size > GDT_SIZE);
35351 BUG_ON(va & ~PAGE_MASK);
35352
35353 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35354@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35355 return 0;
35356 }
35357
35358-static void set_xen_basic_apic_ops(void)
35359+static void __init set_xen_basic_apic_ops(void)
35360 {
35361 apic->read = xen_apic_read;
35362 apic->write = xen_apic_write;
35363@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35364 #endif
35365 };
35366
35367-static void xen_reboot(int reason)
35368+static __noreturn void xen_reboot(int reason)
35369 {
35370 struct sched_shutdown r = { .reason = reason };
35371
35372- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35373- BUG();
35374+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35375+ BUG();
35376 }
35377
35378-static void xen_restart(char *msg)
35379+static __noreturn void xen_restart(char *msg)
35380 {
35381 xen_reboot(SHUTDOWN_reboot);
35382 }
35383
35384-static void xen_emergency_restart(void)
35385+static __noreturn void xen_emergency_restart(void)
35386 {
35387 xen_reboot(SHUTDOWN_reboot);
35388 }
35389
35390-static void xen_machine_halt(void)
35391+static __noreturn void xen_machine_halt(void)
35392 {
35393 xen_reboot(SHUTDOWN_poweroff);
35394 }
35395
35396-static void xen_machine_power_off(void)
35397+static __noreturn void xen_machine_power_off(void)
35398 {
35399 if (pm_power_off)
35400 pm_power_off();
35401@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35402 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35403
35404 /* Work out if we support NX */
35405- x86_configure_nx();
35406+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35407+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35408+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35409+ unsigned l, h;
35410+
35411+ __supported_pte_mask |= _PAGE_NX;
35412+ rdmsr(MSR_EFER, l, h);
35413+ l |= EFER_NX;
35414+ wrmsr(MSR_EFER, l, h);
35415+ }
35416+#endif
35417
35418 xen_setup_features();
35419
35420@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35421
35422 machine_ops = xen_machine_ops;
35423
35424- /*
35425- * The only reliable way to retain the initial address of the
35426- * percpu gdt_page is to remember it here, so we can go and
35427- * mark it RW later, when the initial percpu area is freed.
35428- */
35429- xen_initial_gdt = &per_cpu(gdt_page, 0);
35430-
35431 xen_smp_init();
35432
35433 #ifdef CONFIG_ACPI_NUMA
35434diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35435index 3c76c3d..7327d91 100644
35436--- a/arch/x86/xen/mmu.c
35437+++ b/arch/x86/xen/mmu.c
35438@@ -365,7 +365,7 @@ void xen_ptep_modify_prot_commit(struct mm_struct *mm, unsigned long addr,
35439 /* Assume pteval_t is equivalent to all the other *val_t types. */
35440 static pteval_t pte_mfn_to_pfn(pteval_t val)
35441 {
35442- if (pteval_present(val)) {
35443+ if (val & _PAGE_PRESENT) {
35444 unsigned long mfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35445 unsigned long pfn = mfn_to_pfn(mfn);
35446
35447@@ -379,9 +379,9 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35448 return val;
35449 }
35450
35451-static pteval_t pte_pfn_to_mfn(pteval_t val)
35452+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35453 {
35454- if (pteval_present(val)) {
35455+ if (val & _PAGE_PRESENT) {
35456 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35457 pteval_t flags = val & PTE_FLAGS_MASK;
35458 unsigned long mfn;
35459@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35460 /* L3_k[510] -> level2_kernel_pgt
35461 * L3_i[511] -> level2_fixmap_pgt */
35462 convert_pfn_mfn(level3_kernel_pgt);
35463+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35464+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35465+ convert_pfn_mfn(level3_vmemmap_pgt);
35466
35467 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35468 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35469@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35470 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35471 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35472 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35473+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35474+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35475+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35476 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35477 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35478+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35479 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35480 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35481
35482@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35483 pv_mmu_ops.set_pud = xen_set_pud;
35484 #if PAGETABLE_LEVELS == 4
35485 pv_mmu_ops.set_pgd = xen_set_pgd;
35486+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35487 #endif
35488
35489 /* This will work as long as patching hasn't happened yet
35490@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35491 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35492 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35493 .set_pgd = xen_set_pgd_hyper,
35494+ .set_pgd_batched = xen_set_pgd_hyper,
35495
35496 .alloc_pud = xen_alloc_pmd_init,
35497 .release_pud = xen_release_pmd_init,
35498diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35499index c36b325..b0f1518 100644
35500--- a/arch/x86/xen/smp.c
35501+++ b/arch/x86/xen/smp.c
35502@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35503 native_smp_prepare_boot_cpu();
35504
35505 if (xen_pv_domain()) {
35506- /* We've switched to the "real" per-cpu gdt, so make sure the
35507- old memory can be recycled */
35508- make_lowmem_page_readwrite(xen_initial_gdt);
35509-
35510 #ifdef CONFIG_X86_32
35511 /*
35512 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35513 * expects __USER_DS
35514 */
35515- loadsegment(ds, __USER_DS);
35516- loadsegment(es, __USER_DS);
35517+ loadsegment(ds, __KERNEL_DS);
35518+ loadsegment(es, __KERNEL_DS);
35519 #endif
35520
35521 xen_filter_cpu_maps();
35522@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35523 ctxt->user_regs.ss = __KERNEL_DS;
35524 #ifdef CONFIG_X86_32
35525 ctxt->user_regs.fs = __KERNEL_PERCPU;
35526- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35527+ savesegment(gs, ctxt->user_regs.gs);
35528 #else
35529 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35530 #endif
35531@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35532
35533 {
35534 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35535- ctxt->user_regs.ds = __USER_DS;
35536- ctxt->user_regs.es = __USER_DS;
35537+ ctxt->user_regs.ds = __KERNEL_DS;
35538+ ctxt->user_regs.es = __KERNEL_DS;
35539
35540 xen_copy_trap_info(ctxt->trap_ctxt);
35541
35542@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35543 int rc;
35544
35545 per_cpu(current_task, cpu) = idle;
35546+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35547 #ifdef CONFIG_X86_32
35548 irq_ctx_init(cpu);
35549 #else
35550 clear_tsk_thread_flag(idle, TIF_FORK);
35551- per_cpu(kernel_stack, cpu) =
35552- (unsigned long)task_stack_page(idle) -
35553- KERNEL_STACK_OFFSET + THREAD_SIZE;
35554+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35555 #endif
35556 xen_setup_runstate_info(cpu);
35557 xen_setup_timer(cpu);
35558@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35559
35560 void __init xen_smp_init(void)
35561 {
35562- smp_ops = xen_smp_ops;
35563+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35564 xen_fill_possible_map();
35565 }
35566
35567diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35568index 33ca6e4..0ded929 100644
35569--- a/arch/x86/xen/xen-asm_32.S
35570+++ b/arch/x86/xen/xen-asm_32.S
35571@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35572 ESP_OFFSET=4 # bytes pushed onto stack
35573
35574 /*
35575- * Store vcpu_info pointer for easy access. Do it this way to
35576- * avoid having to reload %fs
35577+ * Store vcpu_info pointer for easy access.
35578 */
35579 #ifdef CONFIG_SMP
35580- GET_THREAD_INFO(%eax)
35581- movl %ss:TI_cpu(%eax), %eax
35582- movl %ss:__per_cpu_offset(,%eax,4), %eax
35583- mov %ss:xen_vcpu(%eax), %eax
35584+ push %fs
35585+ mov $(__KERNEL_PERCPU), %eax
35586+ mov %eax, %fs
35587+ mov PER_CPU_VAR(xen_vcpu), %eax
35588+ pop %fs
35589 #else
35590 movl %ss:xen_vcpu, %eax
35591 #endif
35592diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35593index 7faed58..ba4427c 100644
35594--- a/arch/x86/xen/xen-head.S
35595+++ b/arch/x86/xen/xen-head.S
35596@@ -19,6 +19,17 @@ ENTRY(startup_xen)
35597 #ifdef CONFIG_X86_32
35598 mov %esi,xen_start_info
35599 mov $init_thread_union+THREAD_SIZE,%esp
35600+#ifdef CONFIG_SMP
35601+ movl $cpu_gdt_table,%edi
35602+ movl $__per_cpu_load,%eax
35603+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35604+ rorl $16,%eax
35605+ movb %al,__KERNEL_PERCPU + 4(%edi)
35606+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35607+ movl $__per_cpu_end - 1,%eax
35608+ subl $__per_cpu_start,%eax
35609+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35610+#endif
35611 #else
35612 mov %rsi,xen_start_info
35613 mov $init_thread_union+THREAD_SIZE,%rsp
35614diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35615index 95f8c61..611d6e8 100644
35616--- a/arch/x86/xen/xen-ops.h
35617+++ b/arch/x86/xen/xen-ops.h
35618@@ -10,8 +10,6 @@
35619 extern const char xen_hypervisor_callback[];
35620 extern const char xen_failsafe_callback[];
35621
35622-extern void *xen_initial_gdt;
35623-
35624 struct trap_info;
35625 void xen_copy_trap_info(struct trap_info *traps);
35626
35627diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35628index 525bd3d..ef888b1 100644
35629--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35630+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35631@@ -119,9 +119,9 @@
35632 ----------------------------------------------------------------------*/
35633
35634 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35635-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35636 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35637 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35638+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35639
35640 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35641 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35642diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35643index 2f33760..835e50a 100644
35644--- a/arch/xtensa/variants/fsf/include/variant/core.h
35645+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35646@@ -11,6 +11,7 @@
35647 #ifndef _XTENSA_CORE_H
35648 #define _XTENSA_CORE_H
35649
35650+#include <linux/const.h>
35651
35652 /****************************************************************************
35653 Parameters Useful for Any Code, USER or PRIVILEGED
35654@@ -112,9 +113,9 @@
35655 ----------------------------------------------------------------------*/
35656
35657 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35658-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35659 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35660 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35661+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35662
35663 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35664 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35665diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35666index af00795..2bb8105 100644
35667--- a/arch/xtensa/variants/s6000/include/variant/core.h
35668+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35669@@ -11,6 +11,7 @@
35670 #ifndef _XTENSA_CORE_CONFIGURATION_H
35671 #define _XTENSA_CORE_CONFIGURATION_H
35672
35673+#include <linux/const.h>
35674
35675 /****************************************************************************
35676 Parameters Useful for Any Code, USER or PRIVILEGED
35677@@ -118,9 +119,9 @@
35678 ----------------------------------------------------------------------*/
35679
35680 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35681-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35682 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35683 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35684+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35685
35686 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35687 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35688diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35689index 4e491d9..c8e18e4 100644
35690--- a/block/blk-cgroup.c
35691+++ b/block/blk-cgroup.c
35692@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35693 static struct cgroup_subsys_state *
35694 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35695 {
35696- static atomic64_t id_seq = ATOMIC64_INIT(0);
35697+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35698 struct blkcg *blkcg;
35699
35700 if (!parent_css) {
35701@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35702
35703 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35704 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35705- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35706+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35707 done:
35708 spin_lock_init(&blkcg->lock);
35709 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35710diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35711index 1855bf5..af12b06 100644
35712--- a/block/blk-iopoll.c
35713+++ b/block/blk-iopoll.c
35714@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35715 }
35716 EXPORT_SYMBOL(blk_iopoll_complete);
35717
35718-static void blk_iopoll_softirq(struct softirq_action *h)
35719+static __latent_entropy void blk_iopoll_softirq(void)
35720 {
35721 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35722 int rearm = 0, budget = blk_iopoll_budget;
35723diff --git a/block/blk-map.c b/block/blk-map.c
35724index 623e1cd..ca1e109 100644
35725--- a/block/blk-map.c
35726+++ b/block/blk-map.c
35727@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35728 if (!len || !kbuf)
35729 return -EINVAL;
35730
35731- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35732+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35733 if (do_copy)
35734 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35735 else
35736diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35737index 57790c1..5e988dd 100644
35738--- a/block/blk-softirq.c
35739+++ b/block/blk-softirq.c
35740@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35741 * Softirq action handler - move entries to local list and loop over them
35742 * while passing them to the queue registered handler.
35743 */
35744-static void blk_done_softirq(struct softirq_action *h)
35745+static __latent_entropy void blk_done_softirq(void)
35746 {
35747 struct list_head *cpu_list, local_list;
35748
35749diff --git a/block/bsg.c b/block/bsg.c
35750index 420a5a9..23834aa 100644
35751--- a/block/bsg.c
35752+++ b/block/bsg.c
35753@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35754 struct sg_io_v4 *hdr, struct bsg_device *bd,
35755 fmode_t has_write_perm)
35756 {
35757+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35758+ unsigned char *cmdptr;
35759+
35760 if (hdr->request_len > BLK_MAX_CDB) {
35761 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35762 if (!rq->cmd)
35763 return -ENOMEM;
35764- }
35765+ cmdptr = rq->cmd;
35766+ } else
35767+ cmdptr = tmpcmd;
35768
35769- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35770+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35771 hdr->request_len))
35772 return -EFAULT;
35773
35774+ if (cmdptr != rq->cmd)
35775+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35776+
35777 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35778 if (blk_verify_command(rq->cmd, has_write_perm))
35779 return -EPERM;
35780diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35781index fbd5a67..f24fd95 100644
35782--- a/block/compat_ioctl.c
35783+++ b/block/compat_ioctl.c
35784@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35785 cgc = compat_alloc_user_space(sizeof(*cgc));
35786 cgc32 = compat_ptr(arg);
35787
35788- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35789+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35790 get_user(data, &cgc32->buffer) ||
35791 put_user(compat_ptr(data), &cgc->buffer) ||
35792 copy_in_user(&cgc->buflen, &cgc32->buflen,
35793@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35794 err |= __get_user(f->spec1, &uf->spec1);
35795 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35796 err |= __get_user(name, &uf->name);
35797- f->name = compat_ptr(name);
35798+ f->name = (void __force_kernel *)compat_ptr(name);
35799 if (err) {
35800 err = -EFAULT;
35801 goto out;
35802diff --git a/block/genhd.c b/block/genhd.c
35803index 791f419..89f21c4 100644
35804--- a/block/genhd.c
35805+++ b/block/genhd.c
35806@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35807
35808 /*
35809 * Register device numbers dev..(dev+range-1)
35810- * range must be nonzero
35811+ * Noop if @range is zero.
35812 * The hash chain is sorted on range, so that subranges can override.
35813 */
35814 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35815 struct kobject *(*probe)(dev_t, int *, void *),
35816 int (*lock)(dev_t, void *), void *data)
35817 {
35818- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35819+ if (range)
35820+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35821 }
35822
35823 EXPORT_SYMBOL(blk_register_region);
35824
35825+/* undo blk_register_region(), noop if @range is zero */
35826 void blk_unregister_region(dev_t devt, unsigned long range)
35827 {
35828- kobj_unmap(bdev_map, devt, range);
35829+ if (range)
35830+ kobj_unmap(bdev_map, devt, range);
35831 }
35832
35833 EXPORT_SYMBOL(blk_unregister_region);
35834diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35835index dc51f46..d5446a8 100644
35836--- a/block/partitions/efi.c
35837+++ b/block/partitions/efi.c
35838@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35839 if (!gpt)
35840 return NULL;
35841
35842+ if (!le32_to_cpu(gpt->num_partition_entries))
35843+ return NULL;
35844+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35845+ if (!pte)
35846+ return NULL;
35847+
35848 count = le32_to_cpu(gpt->num_partition_entries) *
35849 le32_to_cpu(gpt->sizeof_partition_entry);
35850- if (!count)
35851- return NULL;
35852- pte = kmalloc(count, GFP_KERNEL);
35853- if (!pte)
35854- return NULL;
35855-
35856 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35857 (u8 *) pte, count) < count) {
35858 kfree(pte);
35859diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35860index 625e3e4..b5339f9 100644
35861--- a/block/scsi_ioctl.c
35862+++ b/block/scsi_ioctl.c
35863@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35864 return put_user(0, p);
35865 }
35866
35867-static int sg_get_timeout(struct request_queue *q)
35868+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35869 {
35870 return jiffies_to_clock_t(q->sg_timeout);
35871 }
35872@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35873 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35874 struct sg_io_hdr *hdr, fmode_t mode)
35875 {
35876- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35877+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35878+ unsigned char *cmdptr;
35879+
35880+ if (rq->cmd != rq->__cmd)
35881+ cmdptr = rq->cmd;
35882+ else
35883+ cmdptr = tmpcmd;
35884+
35885+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35886 return -EFAULT;
35887+
35888+ if (cmdptr != rq->cmd)
35889+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35890+
35891 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35892 return -EPERM;
35893
35894@@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35895 int err;
35896 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35897 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35898+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35899+ unsigned char *cmdptr;
35900
35901 if (!sic)
35902 return -EINVAL;
35903@@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35904 */
35905 err = -EFAULT;
35906 rq->cmd_len = cmdlen;
35907- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35908+
35909+ if (rq->cmd != rq->__cmd)
35910+ cmdptr = rq->cmd;
35911+ else
35912+ cmdptr = tmpcmd;
35913+
35914+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35915 goto error;
35916
35917+ if (rq->cmd != cmdptr)
35918+ memcpy(rq->cmd, cmdptr, cmdlen);
35919+
35920 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35921 goto error;
35922
35923diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35924index 7bdd61b..afec999 100644
35925--- a/crypto/cryptd.c
35926+++ b/crypto/cryptd.c
35927@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35928
35929 struct cryptd_blkcipher_request_ctx {
35930 crypto_completion_t complete;
35931-};
35932+} __no_const;
35933
35934 struct cryptd_hash_ctx {
35935 struct crypto_shash *child;
35936@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35937
35938 struct cryptd_aead_request_ctx {
35939 crypto_completion_t complete;
35940-};
35941+} __no_const;
35942
35943 static void cryptd_queue_worker(struct work_struct *work);
35944
35945diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35946index f8c920c..ab2cb5a 100644
35947--- a/crypto/pcrypt.c
35948+++ b/crypto/pcrypt.c
35949@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35950 int ret;
35951
35952 pinst->kobj.kset = pcrypt_kset;
35953- ret = kobject_add(&pinst->kobj, NULL, name);
35954+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35955 if (!ret)
35956 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35957
35958diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35959index 15dddc1..b61cf0c 100644
35960--- a/drivers/acpi/acpica/hwxfsleep.c
35961+++ b/drivers/acpi/acpica/hwxfsleep.c
35962@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35963 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35964
35965 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35966- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35967- acpi_hw_extended_sleep},
35968- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35969- acpi_hw_extended_wake_prep},
35970- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35971+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35972+ .extended_function = acpi_hw_extended_sleep},
35973+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35974+ .extended_function = acpi_hw_extended_wake_prep},
35975+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35976+ .extended_function = acpi_hw_extended_wake}
35977 };
35978
35979 /*
35980diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35981index 21ba34a..cb05966 100644
35982--- a/drivers/acpi/apei/apei-internal.h
35983+++ b/drivers/acpi/apei/apei-internal.h
35984@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35985 struct apei_exec_ins_type {
35986 u32 flags;
35987 apei_exec_ins_func_t run;
35988-};
35989+} __do_const;
35990
35991 struct apei_exec_context {
35992 u32 ip;
35993diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35994index a30bc31..b91c4d5 100644
35995--- a/drivers/acpi/apei/ghes.c
35996+++ b/drivers/acpi/apei/ghes.c
35997@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35998 const struct acpi_hest_generic *generic,
35999 const struct acpi_generic_status *estatus)
36000 {
36001- static atomic_t seqno;
36002+ static atomic_unchecked_t seqno;
36003 unsigned int curr_seqno;
36004 char pfx_seq[64];
36005
36006@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
36007 else
36008 pfx = KERN_ERR;
36009 }
36010- curr_seqno = atomic_inc_return(&seqno);
36011+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36012 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36013 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36014 pfx_seq, generic->header.source_id);
36015diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36016index a83e3c6..c3d617f 100644
36017--- a/drivers/acpi/bgrt.c
36018+++ b/drivers/acpi/bgrt.c
36019@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36020 if (!bgrt_image)
36021 return -ENODEV;
36022
36023- bin_attr_image.private = bgrt_image;
36024- bin_attr_image.size = bgrt_image_size;
36025+ pax_open_kernel();
36026+ *(void **)&bin_attr_image.private = bgrt_image;
36027+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36028+ pax_close_kernel();
36029
36030 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36031 if (!bgrt_kobj)
36032diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36033index 078c4f7..410e272 100644
36034--- a/drivers/acpi/blacklist.c
36035+++ b/drivers/acpi/blacklist.c
36036@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36037 u32 is_critical_error;
36038 };
36039
36040-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36041+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36042
36043 /*
36044 * POLICY: If *anything* doesn't work, put it on the blacklist.
36045@@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36046 return 0;
36047 }
36048
36049-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36050+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36051 {
36052 .callback = dmi_disable_osi_vista,
36053 .ident = "Fujitsu Siemens",
36054diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36055index 12b62f2..dc2aac8 100644
36056--- a/drivers/acpi/custom_method.c
36057+++ b/drivers/acpi/custom_method.c
36058@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36059 struct acpi_table_header table;
36060 acpi_status status;
36061
36062+#ifdef CONFIG_GRKERNSEC_KMEM
36063+ return -EPERM;
36064+#endif
36065+
36066 if (!(*ppos)) {
36067 /* parse the table header to get the table length */
36068 if (count <= sizeof(struct acpi_table_header))
36069diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36070index 644516d..643937e 100644
36071--- a/drivers/acpi/processor_idle.c
36072+++ b/drivers/acpi/processor_idle.c
36073@@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36074 {
36075 int i, count = CPUIDLE_DRIVER_STATE_START;
36076 struct acpi_processor_cx *cx;
36077- struct cpuidle_state *state;
36078+ cpuidle_state_no_const *state;
36079 struct cpuidle_driver *drv = &acpi_idle_driver;
36080
36081 if (!pr->flags.power_setup_done)
36082diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36083index 6dbc3ca..b8b59a0 100644
36084--- a/drivers/acpi/sysfs.c
36085+++ b/drivers/acpi/sysfs.c
36086@@ -425,11 +425,11 @@ static u32 num_counters;
36087 static struct attribute **all_attrs;
36088 static u32 acpi_gpe_count;
36089
36090-static struct attribute_group interrupt_stats_attr_group = {
36091+static attribute_group_no_const interrupt_stats_attr_group = {
36092 .name = "interrupts",
36093 };
36094
36095-static struct kobj_attribute *counter_attrs;
36096+static kobj_attribute_no_const *counter_attrs;
36097
36098 static void delete_gpe_attr_array(void)
36099 {
36100diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36101index c482f8c..c832240 100644
36102--- a/drivers/ata/libahci.c
36103+++ b/drivers/ata/libahci.c
36104@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36105 }
36106 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36107
36108-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36109+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36110 struct ata_taskfile *tf, int is_cmd, u16 flags,
36111 unsigned long timeout_msec)
36112 {
36113diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36114index 8cb2522..a815e54 100644
36115--- a/drivers/ata/libata-core.c
36116+++ b/drivers/ata/libata-core.c
36117@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36118 static void ata_dev_xfermask(struct ata_device *dev);
36119 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36120
36121-atomic_t ata_print_id = ATOMIC_INIT(0);
36122+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36123
36124 struct ata_force_param {
36125 const char *name;
36126@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36127 struct ata_port *ap;
36128 unsigned int tag;
36129
36130- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36131+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36132 ap = qc->ap;
36133
36134 qc->flags = 0;
36135@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36136 struct ata_port *ap;
36137 struct ata_link *link;
36138
36139- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36140+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36141 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36142 ap = qc->ap;
36143 link = qc->dev->link;
36144@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36145 return;
36146
36147 spin_lock(&lock);
36148+ pax_open_kernel();
36149
36150 for (cur = ops->inherits; cur; cur = cur->inherits) {
36151 void **inherit = (void **)cur;
36152@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36153 if (IS_ERR(*pp))
36154 *pp = NULL;
36155
36156- ops->inherits = NULL;
36157+ *(struct ata_port_operations **)&ops->inherits = NULL;
36158
36159+ pax_close_kernel();
36160 spin_unlock(&lock);
36161 }
36162
36163@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36164
36165 /* give ports names and add SCSI hosts */
36166 for (i = 0; i < host->n_ports; i++) {
36167- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36168+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36169 host->ports[i]->local_port_no = i + 1;
36170 }
36171
36172diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36173index ef8567d..8bdbd03 100644
36174--- a/drivers/ata/libata-scsi.c
36175+++ b/drivers/ata/libata-scsi.c
36176@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36177
36178 if (rc)
36179 return rc;
36180- ap->print_id = atomic_inc_return(&ata_print_id);
36181+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36182 return 0;
36183 }
36184 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36185diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36186index 45b5ab3..98446b8 100644
36187--- a/drivers/ata/libata.h
36188+++ b/drivers/ata/libata.h
36189@@ -53,7 +53,7 @@ enum {
36190 ATA_DNXFER_QUIET = (1 << 31),
36191 };
36192
36193-extern atomic_t ata_print_id;
36194+extern atomic_unchecked_t ata_print_id;
36195 extern int atapi_passthru16;
36196 extern int libata_fua;
36197 extern int libata_noacpi;
36198diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36199index 73492dd..ca2bff5 100644
36200--- a/drivers/ata/pata_arasan_cf.c
36201+++ b/drivers/ata/pata_arasan_cf.c
36202@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36203 /* Handle platform specific quirks */
36204 if (quirk) {
36205 if (quirk & CF_BROKEN_PIO) {
36206- ap->ops->set_piomode = NULL;
36207+ pax_open_kernel();
36208+ *(void **)&ap->ops->set_piomode = NULL;
36209+ pax_close_kernel();
36210 ap->pio_mask = 0;
36211 }
36212 if (quirk & CF_BROKEN_MWDMA)
36213diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36214index f9b983a..887b9d8 100644
36215--- a/drivers/atm/adummy.c
36216+++ b/drivers/atm/adummy.c
36217@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36218 vcc->pop(vcc, skb);
36219 else
36220 dev_kfree_skb_any(skb);
36221- atomic_inc(&vcc->stats->tx);
36222+ atomic_inc_unchecked(&vcc->stats->tx);
36223
36224 return 0;
36225 }
36226diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36227index 62a7607..cc4be104 100644
36228--- a/drivers/atm/ambassador.c
36229+++ b/drivers/atm/ambassador.c
36230@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36231 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36232
36233 // VC layer stats
36234- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36235+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36236
36237 // free the descriptor
36238 kfree (tx_descr);
36239@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36240 dump_skb ("<<<", vc, skb);
36241
36242 // VC layer stats
36243- atomic_inc(&atm_vcc->stats->rx);
36244+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36245 __net_timestamp(skb);
36246 // end of our responsibility
36247 atm_vcc->push (atm_vcc, skb);
36248@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36249 } else {
36250 PRINTK (KERN_INFO, "dropped over-size frame");
36251 // should we count this?
36252- atomic_inc(&atm_vcc->stats->rx_drop);
36253+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36254 }
36255
36256 } else {
36257@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36258 }
36259
36260 if (check_area (skb->data, skb->len)) {
36261- atomic_inc(&atm_vcc->stats->tx_err);
36262+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36263 return -ENOMEM; // ?
36264 }
36265
36266diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36267index 0e3f8f9..765a7a5 100644
36268--- a/drivers/atm/atmtcp.c
36269+++ b/drivers/atm/atmtcp.c
36270@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36271 if (vcc->pop) vcc->pop(vcc,skb);
36272 else dev_kfree_skb(skb);
36273 if (dev_data) return 0;
36274- atomic_inc(&vcc->stats->tx_err);
36275+ atomic_inc_unchecked(&vcc->stats->tx_err);
36276 return -ENOLINK;
36277 }
36278 size = skb->len+sizeof(struct atmtcp_hdr);
36279@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36280 if (!new_skb) {
36281 if (vcc->pop) vcc->pop(vcc,skb);
36282 else dev_kfree_skb(skb);
36283- atomic_inc(&vcc->stats->tx_err);
36284+ atomic_inc_unchecked(&vcc->stats->tx_err);
36285 return -ENOBUFS;
36286 }
36287 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36288@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36289 if (vcc->pop) vcc->pop(vcc,skb);
36290 else dev_kfree_skb(skb);
36291 out_vcc->push(out_vcc,new_skb);
36292- atomic_inc(&vcc->stats->tx);
36293- atomic_inc(&out_vcc->stats->rx);
36294+ atomic_inc_unchecked(&vcc->stats->tx);
36295+ atomic_inc_unchecked(&out_vcc->stats->rx);
36296 return 0;
36297 }
36298
36299@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36300 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36301 read_unlock(&vcc_sklist_lock);
36302 if (!out_vcc) {
36303- atomic_inc(&vcc->stats->tx_err);
36304+ atomic_inc_unchecked(&vcc->stats->tx_err);
36305 goto done;
36306 }
36307 skb_pull(skb,sizeof(struct atmtcp_hdr));
36308@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36309 __net_timestamp(new_skb);
36310 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36311 out_vcc->push(out_vcc,new_skb);
36312- atomic_inc(&vcc->stats->tx);
36313- atomic_inc(&out_vcc->stats->rx);
36314+ atomic_inc_unchecked(&vcc->stats->tx);
36315+ atomic_inc_unchecked(&out_vcc->stats->rx);
36316 done:
36317 if (vcc->pop) vcc->pop(vcc,skb);
36318 else dev_kfree_skb(skb);
36319diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36320index b1955ba..b179940 100644
36321--- a/drivers/atm/eni.c
36322+++ b/drivers/atm/eni.c
36323@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36324 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36325 vcc->dev->number);
36326 length = 0;
36327- atomic_inc(&vcc->stats->rx_err);
36328+ atomic_inc_unchecked(&vcc->stats->rx_err);
36329 }
36330 else {
36331 length = ATM_CELL_SIZE-1; /* no HEC */
36332@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36333 size);
36334 }
36335 eff = length = 0;
36336- atomic_inc(&vcc->stats->rx_err);
36337+ atomic_inc_unchecked(&vcc->stats->rx_err);
36338 }
36339 else {
36340 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36341@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36342 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36343 vcc->dev->number,vcc->vci,length,size << 2,descr);
36344 length = eff = 0;
36345- atomic_inc(&vcc->stats->rx_err);
36346+ atomic_inc_unchecked(&vcc->stats->rx_err);
36347 }
36348 }
36349 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36350@@ -767,7 +767,7 @@ rx_dequeued++;
36351 vcc->push(vcc,skb);
36352 pushed++;
36353 }
36354- atomic_inc(&vcc->stats->rx);
36355+ atomic_inc_unchecked(&vcc->stats->rx);
36356 }
36357 wake_up(&eni_dev->rx_wait);
36358 }
36359@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36360 PCI_DMA_TODEVICE);
36361 if (vcc->pop) vcc->pop(vcc,skb);
36362 else dev_kfree_skb_irq(skb);
36363- atomic_inc(&vcc->stats->tx);
36364+ atomic_inc_unchecked(&vcc->stats->tx);
36365 wake_up(&eni_dev->tx_wait);
36366 dma_complete++;
36367 }
36368diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36369index b41c948..a002b17 100644
36370--- a/drivers/atm/firestream.c
36371+++ b/drivers/atm/firestream.c
36372@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36373 }
36374 }
36375
36376- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36377+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36378
36379 fs_dprintk (FS_DEBUG_TXMEM, "i");
36380 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36381@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36382 #endif
36383 skb_put (skb, qe->p1 & 0xffff);
36384 ATM_SKB(skb)->vcc = atm_vcc;
36385- atomic_inc(&atm_vcc->stats->rx);
36386+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36387 __net_timestamp(skb);
36388 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36389 atm_vcc->push (atm_vcc, skb);
36390@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36391 kfree (pe);
36392 }
36393 if (atm_vcc)
36394- atomic_inc(&atm_vcc->stats->rx_drop);
36395+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36396 break;
36397 case 0x1f: /* Reassembly abort: no buffers. */
36398 /* Silently increment error counter. */
36399 if (atm_vcc)
36400- atomic_inc(&atm_vcc->stats->rx_drop);
36401+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36402 break;
36403 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36404 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36405diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36406index 204814e..cede831 100644
36407--- a/drivers/atm/fore200e.c
36408+++ b/drivers/atm/fore200e.c
36409@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36410 #endif
36411 /* check error condition */
36412 if (*entry->status & STATUS_ERROR)
36413- atomic_inc(&vcc->stats->tx_err);
36414+ atomic_inc_unchecked(&vcc->stats->tx_err);
36415 else
36416- atomic_inc(&vcc->stats->tx);
36417+ atomic_inc_unchecked(&vcc->stats->tx);
36418 }
36419 }
36420
36421@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36422 if (skb == NULL) {
36423 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36424
36425- atomic_inc(&vcc->stats->rx_drop);
36426+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36427 return -ENOMEM;
36428 }
36429
36430@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36431
36432 dev_kfree_skb_any(skb);
36433
36434- atomic_inc(&vcc->stats->rx_drop);
36435+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36436 return -ENOMEM;
36437 }
36438
36439 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36440
36441 vcc->push(vcc, skb);
36442- atomic_inc(&vcc->stats->rx);
36443+ atomic_inc_unchecked(&vcc->stats->rx);
36444
36445 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36446
36447@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36448 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36449 fore200e->atm_dev->number,
36450 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36451- atomic_inc(&vcc->stats->rx_err);
36452+ atomic_inc_unchecked(&vcc->stats->rx_err);
36453 }
36454 }
36455
36456@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36457 goto retry_here;
36458 }
36459
36460- atomic_inc(&vcc->stats->tx_err);
36461+ atomic_inc_unchecked(&vcc->stats->tx_err);
36462
36463 fore200e->tx_sat++;
36464 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36465diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36466index 8557adc..3fb5d55 100644
36467--- a/drivers/atm/he.c
36468+++ b/drivers/atm/he.c
36469@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36470
36471 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36472 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36473- atomic_inc(&vcc->stats->rx_drop);
36474+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36475 goto return_host_buffers;
36476 }
36477
36478@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36479 RBRQ_LEN_ERR(he_dev->rbrq_head)
36480 ? "LEN_ERR" : "",
36481 vcc->vpi, vcc->vci);
36482- atomic_inc(&vcc->stats->rx_err);
36483+ atomic_inc_unchecked(&vcc->stats->rx_err);
36484 goto return_host_buffers;
36485 }
36486
36487@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36488 vcc->push(vcc, skb);
36489 spin_lock(&he_dev->global_lock);
36490
36491- atomic_inc(&vcc->stats->rx);
36492+ atomic_inc_unchecked(&vcc->stats->rx);
36493
36494 return_host_buffers:
36495 ++pdus_assembled;
36496@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36497 tpd->vcc->pop(tpd->vcc, tpd->skb);
36498 else
36499 dev_kfree_skb_any(tpd->skb);
36500- atomic_inc(&tpd->vcc->stats->tx_err);
36501+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36502 }
36503 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36504 return;
36505@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36506 vcc->pop(vcc, skb);
36507 else
36508 dev_kfree_skb_any(skb);
36509- atomic_inc(&vcc->stats->tx_err);
36510+ atomic_inc_unchecked(&vcc->stats->tx_err);
36511 return -EINVAL;
36512 }
36513
36514@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36515 vcc->pop(vcc, skb);
36516 else
36517 dev_kfree_skb_any(skb);
36518- atomic_inc(&vcc->stats->tx_err);
36519+ atomic_inc_unchecked(&vcc->stats->tx_err);
36520 return -EINVAL;
36521 }
36522 #endif
36523@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36524 vcc->pop(vcc, skb);
36525 else
36526 dev_kfree_skb_any(skb);
36527- atomic_inc(&vcc->stats->tx_err);
36528+ atomic_inc_unchecked(&vcc->stats->tx_err);
36529 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36530 return -ENOMEM;
36531 }
36532@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36533 vcc->pop(vcc, skb);
36534 else
36535 dev_kfree_skb_any(skb);
36536- atomic_inc(&vcc->stats->tx_err);
36537+ atomic_inc_unchecked(&vcc->stats->tx_err);
36538 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36539 return -ENOMEM;
36540 }
36541@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36542 __enqueue_tpd(he_dev, tpd, cid);
36543 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36544
36545- atomic_inc(&vcc->stats->tx);
36546+ atomic_inc_unchecked(&vcc->stats->tx);
36547
36548 return 0;
36549 }
36550diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36551index 1dc0519..1aadaf7 100644
36552--- a/drivers/atm/horizon.c
36553+++ b/drivers/atm/horizon.c
36554@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36555 {
36556 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36557 // VC layer stats
36558- atomic_inc(&vcc->stats->rx);
36559+ atomic_inc_unchecked(&vcc->stats->rx);
36560 __net_timestamp(skb);
36561 // end of our responsibility
36562 vcc->push (vcc, skb);
36563@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36564 dev->tx_iovec = NULL;
36565
36566 // VC layer stats
36567- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36568+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36569
36570 // free the skb
36571 hrz_kfree_skb (skb);
36572diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36573index 1bdf104..9dc44b1 100644
36574--- a/drivers/atm/idt77252.c
36575+++ b/drivers/atm/idt77252.c
36576@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36577 else
36578 dev_kfree_skb(skb);
36579
36580- atomic_inc(&vcc->stats->tx);
36581+ atomic_inc_unchecked(&vcc->stats->tx);
36582 }
36583
36584 atomic_dec(&scq->used);
36585@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36586 if ((sb = dev_alloc_skb(64)) == NULL) {
36587 printk("%s: Can't allocate buffers for aal0.\n",
36588 card->name);
36589- atomic_add(i, &vcc->stats->rx_drop);
36590+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36591 break;
36592 }
36593 if (!atm_charge(vcc, sb->truesize)) {
36594 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36595 card->name);
36596- atomic_add(i - 1, &vcc->stats->rx_drop);
36597+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36598 dev_kfree_skb(sb);
36599 break;
36600 }
36601@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36602 ATM_SKB(sb)->vcc = vcc;
36603 __net_timestamp(sb);
36604 vcc->push(vcc, sb);
36605- atomic_inc(&vcc->stats->rx);
36606+ atomic_inc_unchecked(&vcc->stats->rx);
36607
36608 cell += ATM_CELL_PAYLOAD;
36609 }
36610@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36611 "(CDC: %08x)\n",
36612 card->name, len, rpp->len, readl(SAR_REG_CDC));
36613 recycle_rx_pool_skb(card, rpp);
36614- atomic_inc(&vcc->stats->rx_err);
36615+ atomic_inc_unchecked(&vcc->stats->rx_err);
36616 return;
36617 }
36618 if (stat & SAR_RSQE_CRC) {
36619 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36620 recycle_rx_pool_skb(card, rpp);
36621- atomic_inc(&vcc->stats->rx_err);
36622+ atomic_inc_unchecked(&vcc->stats->rx_err);
36623 return;
36624 }
36625 if (skb_queue_len(&rpp->queue) > 1) {
36626@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36627 RXPRINTK("%s: Can't alloc RX skb.\n",
36628 card->name);
36629 recycle_rx_pool_skb(card, rpp);
36630- atomic_inc(&vcc->stats->rx_err);
36631+ atomic_inc_unchecked(&vcc->stats->rx_err);
36632 return;
36633 }
36634 if (!atm_charge(vcc, skb->truesize)) {
36635@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36636 __net_timestamp(skb);
36637
36638 vcc->push(vcc, skb);
36639- atomic_inc(&vcc->stats->rx);
36640+ atomic_inc_unchecked(&vcc->stats->rx);
36641
36642 return;
36643 }
36644@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36645 __net_timestamp(skb);
36646
36647 vcc->push(vcc, skb);
36648- atomic_inc(&vcc->stats->rx);
36649+ atomic_inc_unchecked(&vcc->stats->rx);
36650
36651 if (skb->truesize > SAR_FB_SIZE_3)
36652 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36653@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36654 if (vcc->qos.aal != ATM_AAL0) {
36655 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36656 card->name, vpi, vci);
36657- atomic_inc(&vcc->stats->rx_drop);
36658+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36659 goto drop;
36660 }
36661
36662 if ((sb = dev_alloc_skb(64)) == NULL) {
36663 printk("%s: Can't allocate buffers for AAL0.\n",
36664 card->name);
36665- atomic_inc(&vcc->stats->rx_err);
36666+ atomic_inc_unchecked(&vcc->stats->rx_err);
36667 goto drop;
36668 }
36669
36670@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36671 ATM_SKB(sb)->vcc = vcc;
36672 __net_timestamp(sb);
36673 vcc->push(vcc, sb);
36674- atomic_inc(&vcc->stats->rx);
36675+ atomic_inc_unchecked(&vcc->stats->rx);
36676
36677 drop:
36678 skb_pull(queue, 64);
36679@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36680
36681 if (vc == NULL) {
36682 printk("%s: NULL connection in send().\n", card->name);
36683- atomic_inc(&vcc->stats->tx_err);
36684+ atomic_inc_unchecked(&vcc->stats->tx_err);
36685 dev_kfree_skb(skb);
36686 return -EINVAL;
36687 }
36688 if (!test_bit(VCF_TX, &vc->flags)) {
36689 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36690- atomic_inc(&vcc->stats->tx_err);
36691+ atomic_inc_unchecked(&vcc->stats->tx_err);
36692 dev_kfree_skb(skb);
36693 return -EINVAL;
36694 }
36695@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36696 break;
36697 default:
36698 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
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
36705 if (skb_shinfo(skb)->nr_frags != 0) {
36706 printk("%s: No scatter-gather yet.\n", card->name);
36707- atomic_inc(&vcc->stats->tx_err);
36708+ atomic_inc_unchecked(&vcc->stats->tx_err);
36709 dev_kfree_skb(skb);
36710 return -EINVAL;
36711 }
36712@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36713
36714 err = queue_skb(card, vc, skb, oam);
36715 if (err) {
36716- atomic_inc(&vcc->stats->tx_err);
36717+ atomic_inc_unchecked(&vcc->stats->tx_err);
36718 dev_kfree_skb(skb);
36719 return err;
36720 }
36721@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36722 skb = dev_alloc_skb(64);
36723 if (!skb) {
36724 printk("%s: Out of memory in send_oam().\n", card->name);
36725- atomic_inc(&vcc->stats->tx_err);
36726+ atomic_inc_unchecked(&vcc->stats->tx_err);
36727 return -ENOMEM;
36728 }
36729 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36730diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36731index 4217f29..88f547a 100644
36732--- a/drivers/atm/iphase.c
36733+++ b/drivers/atm/iphase.c
36734@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36735 status = (u_short) (buf_desc_ptr->desc_mode);
36736 if (status & (RX_CER | RX_PTE | RX_OFL))
36737 {
36738- atomic_inc(&vcc->stats->rx_err);
36739+ atomic_inc_unchecked(&vcc->stats->rx_err);
36740 IF_ERR(printk("IA: bad packet, dropping it");)
36741 if (status & RX_CER) {
36742 IF_ERR(printk(" cause: packet CRC error\n");)
36743@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36744 len = dma_addr - buf_addr;
36745 if (len > iadev->rx_buf_sz) {
36746 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36747- atomic_inc(&vcc->stats->rx_err);
36748+ atomic_inc_unchecked(&vcc->stats->rx_err);
36749 goto out_free_desc;
36750 }
36751
36752@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36753 ia_vcc = INPH_IA_VCC(vcc);
36754 if (ia_vcc == NULL)
36755 {
36756- atomic_inc(&vcc->stats->rx_err);
36757+ atomic_inc_unchecked(&vcc->stats->rx_err);
36758 atm_return(vcc, skb->truesize);
36759 dev_kfree_skb_any(skb);
36760 goto INCR_DLE;
36761@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36762 if ((length > iadev->rx_buf_sz) || (length >
36763 (skb->len - sizeof(struct cpcs_trailer))))
36764 {
36765- atomic_inc(&vcc->stats->rx_err);
36766+ atomic_inc_unchecked(&vcc->stats->rx_err);
36767 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36768 length, skb->len);)
36769 atm_return(vcc, skb->truesize);
36770@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36771
36772 IF_RX(printk("rx_dle_intr: skb push");)
36773 vcc->push(vcc,skb);
36774- atomic_inc(&vcc->stats->rx);
36775+ atomic_inc_unchecked(&vcc->stats->rx);
36776 iadev->rx_pkt_cnt++;
36777 }
36778 INCR_DLE:
36779@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36780 {
36781 struct k_sonet_stats *stats;
36782 stats = &PRIV(_ia_dev[board])->sonet_stats;
36783- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36784- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36785- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36786- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36787- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36788- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36789- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36790- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36791- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36792+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36793+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36794+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36795+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36796+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36797+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36798+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36799+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36800+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36801 }
36802 ia_cmds.status = 0;
36803 break;
36804@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36805 if ((desc == 0) || (desc > iadev->num_tx_desc))
36806 {
36807 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36808- atomic_inc(&vcc->stats->tx);
36809+ atomic_inc_unchecked(&vcc->stats->tx);
36810 if (vcc->pop)
36811 vcc->pop(vcc, skb);
36812 else
36813@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36814 ATM_DESC(skb) = vcc->vci;
36815 skb_queue_tail(&iadev->tx_dma_q, skb);
36816
36817- atomic_inc(&vcc->stats->tx);
36818+ atomic_inc_unchecked(&vcc->stats->tx);
36819 iadev->tx_pkt_cnt++;
36820 /* Increment transaction counter */
36821 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36822
36823 #if 0
36824 /* add flow control logic */
36825- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36826+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36827 if (iavcc->vc_desc_cnt > 10) {
36828 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36829 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36830diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36831index fa7d701..1e404c7 100644
36832--- a/drivers/atm/lanai.c
36833+++ b/drivers/atm/lanai.c
36834@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36835 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36836 lanai_endtx(lanai, lvcc);
36837 lanai_free_skb(lvcc->tx.atmvcc, skb);
36838- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36839+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36840 }
36841
36842 /* Try to fill the buffer - don't call unless there is backlog */
36843@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36844 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36845 __net_timestamp(skb);
36846 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36847- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36848+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36849 out:
36850 lvcc->rx.buf.ptr = end;
36851 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36852@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36853 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36854 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36855 lanai->stats.service_rxnotaal5++;
36856- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36857+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36858 return 0;
36859 }
36860 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36861@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36862 int bytes;
36863 read_unlock(&vcc_sklist_lock);
36864 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36865- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36866+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36867 lvcc->stats.x.aal5.service_trash++;
36868 bytes = (SERVICE_GET_END(s) * 16) -
36869 (((unsigned long) lvcc->rx.buf.ptr) -
36870@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36871 }
36872 if (s & SERVICE_STREAM) {
36873 read_unlock(&vcc_sklist_lock);
36874- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36875+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36876 lvcc->stats.x.aal5.service_stream++;
36877 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36878 "PDU on VCI %d!\n", lanai->number, vci);
36879@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36880 return 0;
36881 }
36882 DPRINTK("got rx crc error on vci %d\n", vci);
36883- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36884+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36885 lvcc->stats.x.aal5.service_rxcrc++;
36886 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36887 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36888diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36889index 5aca5f4..ce3a6b0 100644
36890--- a/drivers/atm/nicstar.c
36891+++ b/drivers/atm/nicstar.c
36892@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36893 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36894 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36895 card->index);
36896- atomic_inc(&vcc->stats->tx_err);
36897+ atomic_inc_unchecked(&vcc->stats->tx_err);
36898 dev_kfree_skb_any(skb);
36899 return -EINVAL;
36900 }
36901@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36902 if (!vc->tx) {
36903 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36904 card->index);
36905- atomic_inc(&vcc->stats->tx_err);
36906+ atomic_inc_unchecked(&vcc->stats->tx_err);
36907 dev_kfree_skb_any(skb);
36908 return -EINVAL;
36909 }
36910@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36911 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36912 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36913 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
36920 if (skb_shinfo(skb)->nr_frags != 0) {
36921 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36922- atomic_inc(&vcc->stats->tx_err);
36923+ atomic_inc_unchecked(&vcc->stats->tx_err);
36924 dev_kfree_skb_any(skb);
36925 return -EINVAL;
36926 }
36927@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36928 }
36929
36930 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36931- atomic_inc(&vcc->stats->tx_err);
36932+ atomic_inc_unchecked(&vcc->stats->tx_err);
36933 dev_kfree_skb_any(skb);
36934 return -EIO;
36935 }
36936- atomic_inc(&vcc->stats->tx);
36937+ atomic_inc_unchecked(&vcc->stats->tx);
36938
36939 return 0;
36940 }
36941@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36942 printk
36943 ("nicstar%d: Can't allocate buffers for aal0.\n",
36944 card->index);
36945- atomic_add(i, &vcc->stats->rx_drop);
36946+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36947 break;
36948 }
36949 if (!atm_charge(vcc, sb->truesize)) {
36950 RXPRINTK
36951 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36952 card->index);
36953- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36954+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36955 dev_kfree_skb_any(sb);
36956 break;
36957 }
36958@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36959 ATM_SKB(sb)->vcc = vcc;
36960 __net_timestamp(sb);
36961 vcc->push(vcc, sb);
36962- atomic_inc(&vcc->stats->rx);
36963+ atomic_inc_unchecked(&vcc->stats->rx);
36964 cell += ATM_CELL_PAYLOAD;
36965 }
36966
36967@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36968 if (iovb == NULL) {
36969 printk("nicstar%d: Out of iovec buffers.\n",
36970 card->index);
36971- atomic_inc(&vcc->stats->rx_drop);
36972+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36973 recycle_rx_buf(card, skb);
36974 return;
36975 }
36976@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36977 small or large buffer itself. */
36978 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36979 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36980- atomic_inc(&vcc->stats->rx_err);
36981+ atomic_inc_unchecked(&vcc->stats->rx_err);
36982 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36983 NS_MAX_IOVECS);
36984 NS_PRV_IOVCNT(iovb) = 0;
36985@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36986 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36987 card->index);
36988 which_list(card, skb);
36989- atomic_inc(&vcc->stats->rx_err);
36990+ atomic_inc_unchecked(&vcc->stats->rx_err);
36991 recycle_rx_buf(card, skb);
36992 vc->rx_iov = NULL;
36993 recycle_iov_buf(card, iovb);
36994@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36995 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36996 card->index);
36997 which_list(card, skb);
36998- atomic_inc(&vcc->stats->rx_err);
36999+ atomic_inc_unchecked(&vcc->stats->rx_err);
37000 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37001 NS_PRV_IOVCNT(iovb));
37002 vc->rx_iov = NULL;
37003@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37004 printk(" - PDU size mismatch.\n");
37005 else
37006 printk(".\n");
37007- atomic_inc(&vcc->stats->rx_err);
37008+ atomic_inc_unchecked(&vcc->stats->rx_err);
37009 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37010 NS_PRV_IOVCNT(iovb));
37011 vc->rx_iov = NULL;
37012@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37013 /* skb points to a small buffer */
37014 if (!atm_charge(vcc, skb->truesize)) {
37015 push_rxbufs(card, skb);
37016- atomic_inc(&vcc->stats->rx_drop);
37017+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37018 } else {
37019 skb_put(skb, len);
37020 dequeue_sm_buf(card, skb);
37021@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37022 ATM_SKB(skb)->vcc = vcc;
37023 __net_timestamp(skb);
37024 vcc->push(vcc, skb);
37025- atomic_inc(&vcc->stats->rx);
37026+ atomic_inc_unchecked(&vcc->stats->rx);
37027 }
37028 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37029 struct sk_buff *sb;
37030@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37031 if (len <= NS_SMBUFSIZE) {
37032 if (!atm_charge(vcc, sb->truesize)) {
37033 push_rxbufs(card, sb);
37034- atomic_inc(&vcc->stats->rx_drop);
37035+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37036 } else {
37037 skb_put(sb, len);
37038 dequeue_sm_buf(card, sb);
37039@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37040 ATM_SKB(sb)->vcc = vcc;
37041 __net_timestamp(sb);
37042 vcc->push(vcc, sb);
37043- atomic_inc(&vcc->stats->rx);
37044+ atomic_inc_unchecked(&vcc->stats->rx);
37045 }
37046
37047 push_rxbufs(card, skb);
37048@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37049
37050 if (!atm_charge(vcc, skb->truesize)) {
37051 push_rxbufs(card, skb);
37052- atomic_inc(&vcc->stats->rx_drop);
37053+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37054 } else {
37055 dequeue_lg_buf(card, skb);
37056 #ifdef NS_USE_DESTRUCTORS
37057@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37058 ATM_SKB(skb)->vcc = vcc;
37059 __net_timestamp(skb);
37060 vcc->push(vcc, skb);
37061- atomic_inc(&vcc->stats->rx);
37062+ atomic_inc_unchecked(&vcc->stats->rx);
37063 }
37064
37065 push_rxbufs(card, sb);
37066@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37067 printk
37068 ("nicstar%d: Out of huge buffers.\n",
37069 card->index);
37070- atomic_inc(&vcc->stats->rx_drop);
37071+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37072 recycle_iovec_rx_bufs(card,
37073 (struct iovec *)
37074 iovb->data,
37075@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37076 card->hbpool.count++;
37077 } else
37078 dev_kfree_skb_any(hb);
37079- atomic_inc(&vcc->stats->rx_drop);
37080+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37081 } else {
37082 /* Copy the small buffer to the huge buffer */
37083 sb = (struct sk_buff *)iov->iov_base;
37084@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37085 #endif /* NS_USE_DESTRUCTORS */
37086 __net_timestamp(hb);
37087 vcc->push(vcc, hb);
37088- atomic_inc(&vcc->stats->rx);
37089+ atomic_inc_unchecked(&vcc->stats->rx);
37090 }
37091 }
37092
37093diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37094index 32784d1..4a8434a 100644
37095--- a/drivers/atm/solos-pci.c
37096+++ b/drivers/atm/solos-pci.c
37097@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37098 }
37099 atm_charge(vcc, skb->truesize);
37100 vcc->push(vcc, skb);
37101- atomic_inc(&vcc->stats->rx);
37102+ atomic_inc_unchecked(&vcc->stats->rx);
37103 break;
37104
37105 case PKT_STATUS:
37106@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37107 vcc = SKB_CB(oldskb)->vcc;
37108
37109 if (vcc) {
37110- atomic_inc(&vcc->stats->tx);
37111+ atomic_inc_unchecked(&vcc->stats->tx);
37112 solos_pop(vcc, oldskb);
37113 } else {
37114 dev_kfree_skb_irq(oldskb);
37115diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37116index 0215934..ce9f5b1 100644
37117--- a/drivers/atm/suni.c
37118+++ b/drivers/atm/suni.c
37119@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37120
37121
37122 #define ADD_LIMITED(s,v) \
37123- atomic_add((v),&stats->s); \
37124- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37125+ atomic_add_unchecked((v),&stats->s); \
37126+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37127
37128
37129 static void suni_hz(unsigned long from_timer)
37130diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37131index 5120a96..e2572bd 100644
37132--- a/drivers/atm/uPD98402.c
37133+++ b/drivers/atm/uPD98402.c
37134@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37135 struct sonet_stats tmp;
37136 int error = 0;
37137
37138- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37139+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37140 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37141 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37142 if (zero && !error) {
37143@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37144
37145
37146 #define ADD_LIMITED(s,v) \
37147- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37148- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37149- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37150+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37151+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37152+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37153
37154
37155 static void stat_event(struct atm_dev *dev)
37156@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37157 if (reason & uPD98402_INT_PFM) stat_event(dev);
37158 if (reason & uPD98402_INT_PCO) {
37159 (void) GET(PCOCR); /* clear interrupt cause */
37160- atomic_add(GET(HECCT),
37161+ atomic_add_unchecked(GET(HECCT),
37162 &PRIV(dev)->sonet_stats.uncorr_hcs);
37163 }
37164 if ((reason & uPD98402_INT_RFO) &&
37165@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37166 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37167 uPD98402_INT_LOS),PIMR); /* enable them */
37168 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37169- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37170- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37171- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37172+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37173+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37174+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37175 return 0;
37176 }
37177
37178diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37179index 969c3c2..9b72956 100644
37180--- a/drivers/atm/zatm.c
37181+++ b/drivers/atm/zatm.c
37182@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37183 }
37184 if (!size) {
37185 dev_kfree_skb_irq(skb);
37186- if (vcc) atomic_inc(&vcc->stats->rx_err);
37187+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37188 continue;
37189 }
37190 if (!atm_charge(vcc,skb->truesize)) {
37191@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37192 skb->len = size;
37193 ATM_SKB(skb)->vcc = vcc;
37194 vcc->push(vcc,skb);
37195- atomic_inc(&vcc->stats->rx);
37196+ atomic_inc_unchecked(&vcc->stats->rx);
37197 }
37198 zout(pos & 0xffff,MTA(mbx));
37199 #if 0 /* probably a stupid idea */
37200@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37201 skb_queue_head(&zatm_vcc->backlog,skb);
37202 break;
37203 }
37204- atomic_inc(&vcc->stats->tx);
37205+ atomic_inc_unchecked(&vcc->stats->tx);
37206 wake_up(&zatm_vcc->tx_wait);
37207 }
37208
37209diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37210index 73f6c29..b0c0e13 100644
37211--- a/drivers/base/bus.c
37212+++ b/drivers/base/bus.c
37213@@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37214 return -EINVAL;
37215
37216 mutex_lock(&subsys->p->mutex);
37217- list_add_tail(&sif->node, &subsys->p->interfaces);
37218+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37219 if (sif->add_dev) {
37220 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37221 while ((dev = subsys_dev_iter_next(&iter)))
37222@@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37223 subsys = sif->subsys;
37224
37225 mutex_lock(&subsys->p->mutex);
37226- list_del_init(&sif->node);
37227+ pax_list_del_init((struct list_head *)&sif->node);
37228 if (sif->remove_dev) {
37229 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37230 while ((dev = subsys_dev_iter_next(&iter)))
37231diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37232index 0f38201..6c2b444 100644
37233--- a/drivers/base/devtmpfs.c
37234+++ b/drivers/base/devtmpfs.c
37235@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37236 if (!thread)
37237 return 0;
37238
37239- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37240+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37241 if (err)
37242 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37243 else
37244@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37245 *err = sys_unshare(CLONE_NEWNS);
37246 if (*err)
37247 goto out;
37248- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37249+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37250 if (*err)
37251 goto out;
37252- sys_chdir("/.."); /* will traverse into overmounted root */
37253- sys_chroot(".");
37254+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37255+ sys_chroot((char __force_user *)".");
37256 complete(&setup_done);
37257 while (1) {
37258 spin_lock(&req_lock);
37259diff --git a/drivers/base/node.c b/drivers/base/node.c
37260index bc9f43b..29703b8 100644
37261--- a/drivers/base/node.c
37262+++ b/drivers/base/node.c
37263@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37264 struct node_attr {
37265 struct device_attribute attr;
37266 enum node_states state;
37267-};
37268+} __do_const;
37269
37270 static ssize_t show_node_state(struct device *dev,
37271 struct device_attribute *attr, char *buf)
37272diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37273index bfb8955..4ebff34 100644
37274--- a/drivers/base/power/domain.c
37275+++ b/drivers/base/power/domain.c
37276@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37277
37278 if (dev->power.subsys_data->domain_data) {
37279 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37280- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37281+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37282 if (clear_td)
37283- gpd_data->td = (struct gpd_timing_data){ 0 };
37284+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37285
37286 if (--gpd_data->refcount == 0) {
37287 dev->power.subsys_data->domain_data = NULL;
37288@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37289 {
37290 struct cpuidle_driver *cpuidle_drv;
37291 struct gpd_cpu_data *cpu_data;
37292- struct cpuidle_state *idle_state;
37293+ cpuidle_state_no_const *idle_state;
37294 int ret = 0;
37295
37296 if (IS_ERR_OR_NULL(genpd) || state < 0)
37297@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37298 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37299 {
37300 struct gpd_cpu_data *cpu_data;
37301- struct cpuidle_state *idle_state;
37302+ cpuidle_state_no_const *idle_state;
37303 int ret = 0;
37304
37305 if (IS_ERR_OR_NULL(genpd))
37306diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37307index 03e089a..0e9560c 100644
37308--- a/drivers/base/power/sysfs.c
37309+++ b/drivers/base/power/sysfs.c
37310@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37311 return -EIO;
37312 }
37313 }
37314- return sprintf(buf, p);
37315+ return sprintf(buf, "%s", p);
37316 }
37317
37318 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37319diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37320index 2d56f41..8830f19 100644
37321--- a/drivers/base/power/wakeup.c
37322+++ b/drivers/base/power/wakeup.c
37323@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37324 * They need to be modified together atomically, so it's better to use one
37325 * atomic variable to hold them both.
37326 */
37327-static atomic_t combined_event_count = ATOMIC_INIT(0);
37328+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37329
37330 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37331 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37332
37333 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37334 {
37335- unsigned int comb = atomic_read(&combined_event_count);
37336+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37337
37338 *cnt = (comb >> IN_PROGRESS_BITS);
37339 *inpr = comb & MAX_IN_PROGRESS;
37340@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37341 ws->start_prevent_time = ws->last_time;
37342
37343 /* Increment the counter of events in progress. */
37344- cec = atomic_inc_return(&combined_event_count);
37345+ cec = atomic_inc_return_unchecked(&combined_event_count);
37346
37347 trace_wakeup_source_activate(ws->name, cec);
37348 }
37349@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37350 * Increment the counter of registered wakeup events and decrement the
37351 * couter of wakeup events in progress simultaneously.
37352 */
37353- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37354+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37355 trace_wakeup_source_deactivate(ws->name, cec);
37356
37357 split_counters(&cnt, &inpr);
37358diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37359index e8d11b6..7b1b36f 100644
37360--- a/drivers/base/syscore.c
37361+++ b/drivers/base/syscore.c
37362@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37363 void register_syscore_ops(struct syscore_ops *ops)
37364 {
37365 mutex_lock(&syscore_ops_lock);
37366- list_add_tail(&ops->node, &syscore_ops_list);
37367+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37368 mutex_unlock(&syscore_ops_lock);
37369 }
37370 EXPORT_SYMBOL_GPL(register_syscore_ops);
37371@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37372 void unregister_syscore_ops(struct syscore_ops *ops)
37373 {
37374 mutex_lock(&syscore_ops_lock);
37375- list_del(&ops->node);
37376+ pax_list_del((struct list_head *)&ops->node);
37377 mutex_unlock(&syscore_ops_lock);
37378 }
37379 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37380diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37381index b35fc4f..c902870 100644
37382--- a/drivers/block/cciss.c
37383+++ b/drivers/block/cciss.c
37384@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37385 while (!list_empty(&h->reqQ)) {
37386 c = list_entry(h->reqQ.next, CommandList_struct, list);
37387 /* can't do anything if fifo is full */
37388- if ((h->access.fifo_full(h))) {
37389+ if ((h->access->fifo_full(h))) {
37390 dev_warn(&h->pdev->dev, "fifo full\n");
37391 break;
37392 }
37393@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37394 h->Qdepth--;
37395
37396 /* Tell the controller execute command */
37397- h->access.submit_command(h, c);
37398+ h->access->submit_command(h, c);
37399
37400 /* Put job onto the completed Q */
37401 addQ(&h->cmpQ, c);
37402@@ -3447,17 +3447,17 @@ startio:
37403
37404 static inline unsigned long get_next_completion(ctlr_info_t *h)
37405 {
37406- return h->access.command_completed(h);
37407+ return h->access->command_completed(h);
37408 }
37409
37410 static inline int interrupt_pending(ctlr_info_t *h)
37411 {
37412- return h->access.intr_pending(h);
37413+ return h->access->intr_pending(h);
37414 }
37415
37416 static inline long interrupt_not_for_us(ctlr_info_t *h)
37417 {
37418- return ((h->access.intr_pending(h) == 0) ||
37419+ return ((h->access->intr_pending(h) == 0) ||
37420 (h->interrupts_enabled == 0));
37421 }
37422
37423@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37424 u32 a;
37425
37426 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37427- return h->access.command_completed(h);
37428+ return h->access->command_completed(h);
37429
37430 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37431 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37432@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37433 trans_support & CFGTBL_Trans_use_short_tags);
37434
37435 /* Change the access methods to the performant access methods */
37436- h->access = SA5_performant_access;
37437+ h->access = &SA5_performant_access;
37438 h->transMethod = CFGTBL_Trans_Performant;
37439
37440 return;
37441@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37442 if (prod_index < 0)
37443 return -ENODEV;
37444 h->product_name = products[prod_index].product_name;
37445- h->access = *(products[prod_index].access);
37446+ h->access = products[prod_index].access;
37447
37448 if (cciss_board_disabled(h)) {
37449 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37450@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37451 }
37452
37453 /* make sure the board interrupts are off */
37454- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37455+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37456 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37457 if (rc)
37458 goto clean2;
37459@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37460 * fake ones to scoop up any residual completions.
37461 */
37462 spin_lock_irqsave(&h->lock, flags);
37463- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37464+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37465 spin_unlock_irqrestore(&h->lock, flags);
37466 free_irq(h->intr[h->intr_mode], h);
37467 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37468@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37469 dev_info(&h->pdev->dev, "Board READY.\n");
37470 dev_info(&h->pdev->dev,
37471 "Waiting for stale completions to drain.\n");
37472- h->access.set_intr_mask(h, CCISS_INTR_ON);
37473+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37474 msleep(10000);
37475- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37476+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37477
37478 rc = controller_reset_failed(h->cfgtable);
37479 if (rc)
37480@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37481 cciss_scsi_setup(h);
37482
37483 /* Turn the interrupts on so we can service requests */
37484- h->access.set_intr_mask(h, CCISS_INTR_ON);
37485+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37486
37487 /* Get the firmware version */
37488 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37489@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37490 kfree(flush_buf);
37491 if (return_code != IO_OK)
37492 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37493- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37494+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37495 free_irq(h->intr[h->intr_mode], h);
37496 }
37497
37498diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37499index 7fda30e..2f27946 100644
37500--- a/drivers/block/cciss.h
37501+++ b/drivers/block/cciss.h
37502@@ -101,7 +101,7 @@ struct ctlr_info
37503 /* information about each logical volume */
37504 drive_info_struct *drv[CISS_MAX_LUN];
37505
37506- struct access_method access;
37507+ struct access_method *access;
37508
37509 /* queue and queue Info */
37510 struct list_head reqQ;
37511@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37512 }
37513
37514 static struct access_method SA5_access = {
37515- SA5_submit_command,
37516- SA5_intr_mask,
37517- SA5_fifo_full,
37518- SA5_intr_pending,
37519- SA5_completed,
37520+ .submit_command = SA5_submit_command,
37521+ .set_intr_mask = SA5_intr_mask,
37522+ .fifo_full = SA5_fifo_full,
37523+ .intr_pending = SA5_intr_pending,
37524+ .command_completed = SA5_completed,
37525 };
37526
37527 static struct access_method SA5B_access = {
37528- SA5_submit_command,
37529- SA5B_intr_mask,
37530- SA5_fifo_full,
37531- SA5B_intr_pending,
37532- SA5_completed,
37533+ .submit_command = SA5_submit_command,
37534+ .set_intr_mask = SA5B_intr_mask,
37535+ .fifo_full = SA5_fifo_full,
37536+ .intr_pending = SA5B_intr_pending,
37537+ .command_completed = SA5_completed,
37538 };
37539
37540 static struct access_method SA5_performant_access = {
37541- SA5_submit_command,
37542- SA5_performant_intr_mask,
37543- SA5_fifo_full,
37544- SA5_performant_intr_pending,
37545- SA5_performant_completed,
37546+ .submit_command = SA5_submit_command,
37547+ .set_intr_mask = SA5_performant_intr_mask,
37548+ .fifo_full = SA5_fifo_full,
37549+ .intr_pending = SA5_performant_intr_pending,
37550+ .command_completed = SA5_performant_completed,
37551 };
37552
37553 struct board_type {
37554diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37555index 2b94403..fd6ad1f 100644
37556--- a/drivers/block/cpqarray.c
37557+++ b/drivers/block/cpqarray.c
37558@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37559 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37560 goto Enomem4;
37561 }
37562- hba[i]->access.set_intr_mask(hba[i], 0);
37563+ hba[i]->access->set_intr_mask(hba[i], 0);
37564 if (request_irq(hba[i]->intr, do_ida_intr,
37565 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37566 {
37567@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37568 add_timer(&hba[i]->timer);
37569
37570 /* Enable IRQ now that spinlock and rate limit timer are set up */
37571- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37572+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37573
37574 for(j=0; j<NWD; j++) {
37575 struct gendisk *disk = ida_gendisk[i][j];
37576@@ -694,7 +694,7 @@ DBGINFO(
37577 for(i=0; i<NR_PRODUCTS; i++) {
37578 if (board_id == products[i].board_id) {
37579 c->product_name = products[i].product_name;
37580- c->access = *(products[i].access);
37581+ c->access = products[i].access;
37582 break;
37583 }
37584 }
37585@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37586 hba[ctlr]->intr = intr;
37587 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37588 hba[ctlr]->product_name = products[j].product_name;
37589- hba[ctlr]->access = *(products[j].access);
37590+ hba[ctlr]->access = products[j].access;
37591 hba[ctlr]->ctlr = ctlr;
37592 hba[ctlr]->board_id = board_id;
37593 hba[ctlr]->pci_dev = NULL; /* not PCI */
37594@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37595
37596 while((c = h->reqQ) != NULL) {
37597 /* Can't do anything if we're busy */
37598- if (h->access.fifo_full(h) == 0)
37599+ if (h->access->fifo_full(h) == 0)
37600 return;
37601
37602 /* Get the first entry from the request Q */
37603@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37604 h->Qdepth--;
37605
37606 /* Tell the controller to do our bidding */
37607- h->access.submit_command(h, c);
37608+ h->access->submit_command(h, c);
37609
37610 /* Get onto the completion Q */
37611 addQ(&h->cmpQ, c);
37612@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37613 unsigned long flags;
37614 __u32 a,a1;
37615
37616- istat = h->access.intr_pending(h);
37617+ istat = h->access->intr_pending(h);
37618 /* Is this interrupt for us? */
37619 if (istat == 0)
37620 return IRQ_NONE;
37621@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37622 */
37623 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37624 if (istat & FIFO_NOT_EMPTY) {
37625- while((a = h->access.command_completed(h))) {
37626+ while((a = h->access->command_completed(h))) {
37627 a1 = a; a &= ~3;
37628 if ((c = h->cmpQ) == NULL)
37629 {
37630@@ -1448,11 +1448,11 @@ static int sendcmd(
37631 /*
37632 * Disable interrupt
37633 */
37634- info_p->access.set_intr_mask(info_p, 0);
37635+ info_p->access->set_intr_mask(info_p, 0);
37636 /* Make sure there is room in the command FIFO */
37637 /* Actually it should be completely empty at this time. */
37638 for (i = 200000; i > 0; i--) {
37639- temp = info_p->access.fifo_full(info_p);
37640+ temp = info_p->access->fifo_full(info_p);
37641 if (temp != 0) {
37642 break;
37643 }
37644@@ -1465,7 +1465,7 @@ DBG(
37645 /*
37646 * Send the cmd
37647 */
37648- info_p->access.submit_command(info_p, c);
37649+ info_p->access->submit_command(info_p, c);
37650 complete = pollcomplete(ctlr);
37651
37652 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37653@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37654 * we check the new geometry. Then turn interrupts back on when
37655 * we're done.
37656 */
37657- host->access.set_intr_mask(host, 0);
37658+ host->access->set_intr_mask(host, 0);
37659 getgeometry(ctlr);
37660- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37661+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37662
37663 for(i=0; i<NWD; i++) {
37664 struct gendisk *disk = ida_gendisk[ctlr][i];
37665@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37666 /* Wait (up to 2 seconds) for a command to complete */
37667
37668 for (i = 200000; i > 0; i--) {
37669- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37670+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37671 if (done == 0) {
37672 udelay(10); /* a short fixed delay */
37673 } else
37674diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37675index be73e9d..7fbf140 100644
37676--- a/drivers/block/cpqarray.h
37677+++ b/drivers/block/cpqarray.h
37678@@ -99,7 +99,7 @@ struct ctlr_info {
37679 drv_info_t drv[NWD];
37680 struct proc_dir_entry *proc;
37681
37682- struct access_method access;
37683+ struct access_method *access;
37684
37685 cmdlist_t *reqQ;
37686 cmdlist_t *cmpQ;
37687diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37688index 0e06f0c..c47b81d 100644
37689--- a/drivers/block/drbd/drbd_int.h
37690+++ b/drivers/block/drbd/drbd_int.h
37691@@ -582,7 +582,7 @@ struct drbd_epoch {
37692 struct drbd_tconn *tconn;
37693 struct list_head list;
37694 unsigned int barrier_nr;
37695- atomic_t epoch_size; /* increased on every request added. */
37696+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37697 atomic_t active; /* increased on every req. added, and dec on every finished. */
37698 unsigned long flags;
37699 };
37700@@ -1022,7 +1022,7 @@ struct drbd_conf {
37701 unsigned int al_tr_number;
37702 int al_tr_cycle;
37703 wait_queue_head_t seq_wait;
37704- atomic_t packet_seq;
37705+ atomic_unchecked_t packet_seq;
37706 unsigned int peer_seq;
37707 spinlock_t peer_seq_lock;
37708 unsigned int minor;
37709@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37710 char __user *uoptval;
37711 int err;
37712
37713- uoptval = (char __user __force *)optval;
37714+ uoptval = (char __force_user *)optval;
37715
37716 set_fs(KERNEL_DS);
37717 if (level == SOL_SOCKET)
37718diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37719index 89c497c..9c736ae 100644
37720--- a/drivers/block/drbd/drbd_interval.c
37721+++ b/drivers/block/drbd/drbd_interval.c
37722@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37723 }
37724
37725 static const struct rb_augment_callbacks augment_callbacks = {
37726- augment_propagate,
37727- augment_copy,
37728- augment_rotate,
37729+ .propagate = augment_propagate,
37730+ .copy = augment_copy,
37731+ .rotate = augment_rotate,
37732 };
37733
37734 /**
37735diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37736index 9e3818b..7b64c92 100644
37737--- a/drivers/block/drbd/drbd_main.c
37738+++ b/drivers/block/drbd/drbd_main.c
37739@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37740 p->sector = sector;
37741 p->block_id = block_id;
37742 p->blksize = blksize;
37743- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37744+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37745 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37746 }
37747
37748@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37749 return -EIO;
37750 p->sector = cpu_to_be64(req->i.sector);
37751 p->block_id = (unsigned long)req;
37752- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37753+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37754 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37755 if (mdev->state.conn >= C_SYNC_SOURCE &&
37756 mdev->state.conn <= C_PAUSED_SYNC_T)
37757@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37758 {
37759 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37760
37761- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37762- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37763+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37764+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37765 kfree(tconn->current_epoch);
37766
37767 idr_destroy(&tconn->volumes);
37768diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37769index c706d50..5e1b472 100644
37770--- a/drivers/block/drbd/drbd_nl.c
37771+++ b/drivers/block/drbd/drbd_nl.c
37772@@ -3440,7 +3440,7 @@ out:
37773
37774 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37775 {
37776- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37777+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37778 struct sk_buff *msg;
37779 struct drbd_genlmsghdr *d_out;
37780 unsigned seq;
37781@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37782 return;
37783 }
37784
37785- seq = atomic_inc_return(&drbd_genl_seq);
37786+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37787 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37788 if (!msg)
37789 goto failed;
37790diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37791index 6fa6673..b7f97e9 100644
37792--- a/drivers/block/drbd/drbd_receiver.c
37793+++ b/drivers/block/drbd/drbd_receiver.c
37794@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37795 {
37796 int err;
37797
37798- atomic_set(&mdev->packet_seq, 0);
37799+ atomic_set_unchecked(&mdev->packet_seq, 0);
37800 mdev->peer_seq = 0;
37801
37802 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37803@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37804 do {
37805 next_epoch = NULL;
37806
37807- epoch_size = atomic_read(&epoch->epoch_size);
37808+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37809
37810 switch (ev & ~EV_CLEANUP) {
37811 case EV_PUT:
37812@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37813 rv = FE_DESTROYED;
37814 } else {
37815 epoch->flags = 0;
37816- atomic_set(&epoch->epoch_size, 0);
37817+ atomic_set_unchecked(&epoch->epoch_size, 0);
37818 /* atomic_set(&epoch->active, 0); is already zero */
37819 if (rv == FE_STILL_LIVE)
37820 rv = FE_RECYCLED;
37821@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37822 conn_wait_active_ee_empty(tconn);
37823 drbd_flush(tconn);
37824
37825- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37826+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37827 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37828 if (epoch)
37829 break;
37830@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37831 }
37832
37833 epoch->flags = 0;
37834- atomic_set(&epoch->epoch_size, 0);
37835+ atomic_set_unchecked(&epoch->epoch_size, 0);
37836 atomic_set(&epoch->active, 0);
37837
37838 spin_lock(&tconn->epoch_lock);
37839- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37840+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37841 list_add(&epoch->list, &tconn->current_epoch->list);
37842 tconn->current_epoch = epoch;
37843 tconn->epochs++;
37844@@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37845
37846 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37847 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37848- atomic_inc(&tconn->current_epoch->epoch_size);
37849+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37850 err2 = drbd_drain_block(mdev, pi->size);
37851 if (!err)
37852 err = err2;
37853@@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37854
37855 spin_lock(&tconn->epoch_lock);
37856 peer_req->epoch = tconn->current_epoch;
37857- atomic_inc(&peer_req->epoch->epoch_size);
37858+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37859 atomic_inc(&peer_req->epoch->active);
37860 spin_unlock(&tconn->epoch_lock);
37861
37862@@ -4344,7 +4344,7 @@ struct data_cmd {
37863 int expect_payload;
37864 size_t pkt_size;
37865 int (*fn)(struct drbd_tconn *, struct packet_info *);
37866-};
37867+} __do_const;
37868
37869 static struct data_cmd drbd_cmd_handler[] = {
37870 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37871@@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37872 if (!list_empty(&tconn->current_epoch->list))
37873 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37874 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37875- atomic_set(&tconn->current_epoch->epoch_size, 0);
37876+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37877 tconn->send.seen_any_write_yet = false;
37878
37879 conn_info(tconn, "Connection closed\n");
37880@@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37881 struct asender_cmd {
37882 size_t pkt_size;
37883 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37884-};
37885+} __do_const;
37886
37887 static struct asender_cmd asender_tbl[] = {
37888 [P_PING] = { 0, got_Ping },
37889diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37890index c8dac73..1800093 100644
37891--- a/drivers/block/loop.c
37892+++ b/drivers/block/loop.c
37893@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37894
37895 file_start_write(file);
37896 set_fs(get_ds());
37897- bw = file->f_op->write(file, buf, len, &pos);
37898+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37899 set_fs(old_fs);
37900 file_end_write(file);
37901 if (likely(bw == len))
37902diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37903index 83a598e..2de5ce3 100644
37904--- a/drivers/block/null_blk.c
37905+++ b/drivers/block/null_blk.c
37906@@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37907 return 0;
37908 }
37909
37910-static struct blk_mq_ops null_mq_ops = {
37911- .queue_rq = null_queue_rq,
37912- .map_queue = blk_mq_map_queue,
37913+static struct blk_mq_ops null_mq_single_ops = {
37914+ .queue_rq = null_queue_rq,
37915+ .map_queue = blk_mq_map_queue,
37916 .init_hctx = null_init_hctx,
37917+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37918+ .free_hctx = blk_mq_free_single_hw_queue,
37919+};
37920+
37921+static struct blk_mq_ops null_mq_per_node_ops = {
37922+ .queue_rq = null_queue_rq,
37923+ .map_queue = blk_mq_map_queue,
37924+ .init_hctx = null_init_hctx,
37925+ .alloc_hctx = null_alloc_hctx,
37926+ .free_hctx = null_free_hctx,
37927 };
37928
37929 static struct blk_mq_reg null_mq_reg = {
37930- .ops = &null_mq_ops,
37931+ .ops = &null_mq_single_ops,
37932 .queue_depth = 64,
37933 .cmd_size = sizeof(struct nullb_cmd),
37934 .flags = BLK_MQ_F_SHOULD_MERGE,
37935@@ -545,13 +555,8 @@ static int null_add_dev(void)
37936 null_mq_reg.queue_depth = hw_queue_depth;
37937 null_mq_reg.nr_hw_queues = submit_queues;
37938
37939- if (use_per_node_hctx) {
37940- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37941- null_mq_reg.ops->free_hctx = null_free_hctx;
37942- } else {
37943- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37944- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37945- }
37946+ if (use_per_node_hctx)
37947+ null_mq_reg.ops = &null_mq_per_node_ops;
37948
37949 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37950 } else if (queue_mode == NULL_Q_BIO) {
37951diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37952index ff8668c..f62167a 100644
37953--- a/drivers/block/pktcdvd.c
37954+++ b/drivers/block/pktcdvd.c
37955@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37956
37957 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37958 {
37959- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37960+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37961 }
37962
37963 /*
37964@@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37965 return -EROFS;
37966 }
37967 pd->settings.fp = ti.fp;
37968- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37969+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37970
37971 if (ti.nwa_v) {
37972 pd->nwa = be32_to_cpu(ti.next_writable);
37973diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37974index e5565fb..71be10b4 100644
37975--- a/drivers/block/smart1,2.h
37976+++ b/drivers/block/smart1,2.h
37977@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37978 }
37979
37980 static struct access_method smart4_access = {
37981- smart4_submit_command,
37982- smart4_intr_mask,
37983- smart4_fifo_full,
37984- smart4_intr_pending,
37985- smart4_completed,
37986+ .submit_command = smart4_submit_command,
37987+ .set_intr_mask = smart4_intr_mask,
37988+ .fifo_full = smart4_fifo_full,
37989+ .intr_pending = smart4_intr_pending,
37990+ .command_completed = smart4_completed,
37991 };
37992
37993 /*
37994@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37995 }
37996
37997 static struct access_method smart2_access = {
37998- smart2_submit_command,
37999- smart2_intr_mask,
38000- smart2_fifo_full,
38001- smart2_intr_pending,
38002- smart2_completed,
38003+ .submit_command = smart2_submit_command,
38004+ .set_intr_mask = smart2_intr_mask,
38005+ .fifo_full = smart2_fifo_full,
38006+ .intr_pending = smart2_intr_pending,
38007+ .command_completed = smart2_completed,
38008 };
38009
38010 /*
38011@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38012 }
38013
38014 static struct access_method smart2e_access = {
38015- smart2e_submit_command,
38016- smart2e_intr_mask,
38017- smart2e_fifo_full,
38018- smart2e_intr_pending,
38019- smart2e_completed,
38020+ .submit_command = smart2e_submit_command,
38021+ .set_intr_mask = smart2e_intr_mask,
38022+ .fifo_full = smart2e_fifo_full,
38023+ .intr_pending = smart2e_intr_pending,
38024+ .command_completed = smart2e_completed,
38025 };
38026
38027 /*
38028@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38029 }
38030
38031 static struct access_method smart1_access = {
38032- smart1_submit_command,
38033- smart1_intr_mask,
38034- smart1_fifo_full,
38035- smart1_intr_pending,
38036- smart1_completed,
38037+ .submit_command = smart1_submit_command,
38038+ .set_intr_mask = smart1_intr_mask,
38039+ .fifo_full = smart1_fifo_full,
38040+ .intr_pending = smart1_intr_pending,
38041+ .command_completed = smart1_completed,
38042 };
38043diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38044index f038dba..bb74c08 100644
38045--- a/drivers/bluetooth/btwilink.c
38046+++ b/drivers/bluetooth/btwilink.c
38047@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38048
38049 static int bt_ti_probe(struct platform_device *pdev)
38050 {
38051- static struct ti_st *hst;
38052+ struct ti_st *hst;
38053 struct hci_dev *hdev;
38054 int err;
38055
38056diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38057index b6739cb..962fd35 100644
38058--- a/drivers/bus/arm-cci.c
38059+++ b/drivers/bus/arm-cci.c
38060@@ -979,7 +979,7 @@ static int cci_probe(void)
38061
38062 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38063
38064- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38065+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38066 if (!ports)
38067 return -ENOMEM;
38068
38069diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38070index 8a3aff7..d7538c2 100644
38071--- a/drivers/cdrom/cdrom.c
38072+++ b/drivers/cdrom/cdrom.c
38073@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38074 ENSURE(reset, CDC_RESET);
38075 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38076 cdi->mc_flags = 0;
38077- cdo->n_minors = 0;
38078 cdi->options = CDO_USE_FFLAGS;
38079
38080 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38081@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38082 else
38083 cdi->cdda_method = CDDA_OLD;
38084
38085- if (!cdo->generic_packet)
38086- cdo->generic_packet = cdrom_dummy_generic_packet;
38087+ if (!cdo->generic_packet) {
38088+ pax_open_kernel();
38089+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38090+ pax_close_kernel();
38091+ }
38092
38093 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38094 mutex_lock(&cdrom_mutex);
38095@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38096 if (cdi->exit)
38097 cdi->exit(cdi);
38098
38099- cdi->ops->n_minors--;
38100 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38101 }
38102
38103@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38104 */
38105 nr = nframes;
38106 do {
38107- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38108+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38109 if (cgc.buffer)
38110 break;
38111
38112@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38113 struct cdrom_device_info *cdi;
38114 int ret;
38115
38116- ret = scnprintf(info + *pos, max_size - *pos, header);
38117+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38118 if (!ret)
38119 return 1;
38120
38121diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38122index 5980cb9..6d7bd7e 100644
38123--- a/drivers/cdrom/gdrom.c
38124+++ b/drivers/cdrom/gdrom.c
38125@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38126 .audio_ioctl = gdrom_audio_ioctl,
38127 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38128 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38129- .n_minors = 1,
38130 };
38131
38132 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38133diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38134index fa3243d..8c98297 100644
38135--- a/drivers/char/Kconfig
38136+++ b/drivers/char/Kconfig
38137@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38138
38139 config DEVKMEM
38140 bool "/dev/kmem virtual device support"
38141- default y
38142+ default n
38143+ depends on !GRKERNSEC_KMEM
38144 help
38145 Say Y here if you want to support the /dev/kmem device. The
38146 /dev/kmem device is rarely used, but can be used for certain
38147@@ -576,6 +577,7 @@ config DEVPORT
38148 bool
38149 depends on !M68K
38150 depends on ISA || PCI
38151+ depends on !GRKERNSEC_KMEM
38152 default y
38153
38154 source "drivers/s390/char/Kconfig"
38155diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38156index a48e05b..6bac831 100644
38157--- a/drivers/char/agp/compat_ioctl.c
38158+++ b/drivers/char/agp/compat_ioctl.c
38159@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38160 return -ENOMEM;
38161 }
38162
38163- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38164+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38165 sizeof(*usegment) * ureserve.seg_count)) {
38166 kfree(usegment);
38167 kfree(ksegment);
38168diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38169index 1b19239..b87b143 100644
38170--- a/drivers/char/agp/frontend.c
38171+++ b/drivers/char/agp/frontend.c
38172@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38173 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38174 return -EFAULT;
38175
38176- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38177+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38178 return -EFAULT;
38179
38180 client = agp_find_client_by_pid(reserve.pid);
38181@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38182 if (segment == NULL)
38183 return -ENOMEM;
38184
38185- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38186+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38187 sizeof(struct agp_segment) * reserve.seg_count)) {
38188 kfree(segment);
38189 return -EFAULT;
38190diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38191index 4f94375..413694e 100644
38192--- a/drivers/char/genrtc.c
38193+++ b/drivers/char/genrtc.c
38194@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38195 switch (cmd) {
38196
38197 case RTC_PLL_GET:
38198+ memset(&pll, 0, sizeof(pll));
38199 if (get_rtc_pll(&pll))
38200 return -EINVAL;
38201 else
38202diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38203index 5d9c31d..c94ccb5 100644
38204--- a/drivers/char/hpet.c
38205+++ b/drivers/char/hpet.c
38206@@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38207 }
38208
38209 static int
38210-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38211+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38212 struct hpet_info *info)
38213 {
38214 struct hpet_timer __iomem *timer;
38215diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38216index 86fe45c..c0ea948 100644
38217--- a/drivers/char/hw_random/intel-rng.c
38218+++ b/drivers/char/hw_random/intel-rng.c
38219@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38220
38221 if (no_fwh_detect)
38222 return -ENODEV;
38223- printk(warning);
38224+ printk("%s", warning);
38225 return -EBUSY;
38226 }
38227
38228diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38229index ec4e10f..f2a763b 100644
38230--- a/drivers/char/ipmi/ipmi_msghandler.c
38231+++ b/drivers/char/ipmi/ipmi_msghandler.c
38232@@ -420,7 +420,7 @@ struct ipmi_smi {
38233 struct proc_dir_entry *proc_dir;
38234 char proc_dir_name[10];
38235
38236- atomic_t stats[IPMI_NUM_STATS];
38237+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38238
38239 /*
38240 * run_to_completion duplicate of smb_info, smi_info
38241@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38242
38243
38244 #define ipmi_inc_stat(intf, stat) \
38245- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38246+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38247 #define ipmi_get_stat(intf, stat) \
38248- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38249+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38250
38251 static int is_lan_addr(struct ipmi_addr *addr)
38252 {
38253@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38254 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38255 init_waitqueue_head(&intf->waitq);
38256 for (i = 0; i < IPMI_NUM_STATS; i++)
38257- atomic_set(&intf->stats[i], 0);
38258+ atomic_set_unchecked(&intf->stats[i], 0);
38259
38260 intf->proc_dir = NULL;
38261
38262diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38263index 15e4a60..b046093 100644
38264--- a/drivers/char/ipmi/ipmi_si_intf.c
38265+++ b/drivers/char/ipmi/ipmi_si_intf.c
38266@@ -280,7 +280,7 @@ struct smi_info {
38267 unsigned char slave_addr;
38268
38269 /* Counters and things for the proc filesystem. */
38270- atomic_t stats[SI_NUM_STATS];
38271+ atomic_unchecked_t stats[SI_NUM_STATS];
38272
38273 struct task_struct *thread;
38274
38275@@ -289,9 +289,9 @@ struct smi_info {
38276 };
38277
38278 #define smi_inc_stat(smi, stat) \
38279- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38280+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38281 #define smi_get_stat(smi, stat) \
38282- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38283+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38284
38285 #define SI_MAX_PARMS 4
38286
38287@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38288 atomic_set(&new_smi->req_events, 0);
38289 new_smi->run_to_completion = 0;
38290 for (i = 0; i < SI_NUM_STATS; i++)
38291- atomic_set(&new_smi->stats[i], 0);
38292+ atomic_set_unchecked(&new_smi->stats[i], 0);
38293
38294 new_smi->interrupt_disabled = 1;
38295 atomic_set(&new_smi->stop_operation, 0);
38296diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38297index f895a8c..2bc9147 100644
38298--- a/drivers/char/mem.c
38299+++ b/drivers/char/mem.c
38300@@ -18,6 +18,7 @@
38301 #include <linux/raw.h>
38302 #include <linux/tty.h>
38303 #include <linux/capability.h>
38304+#include <linux/security.h>
38305 #include <linux/ptrace.h>
38306 #include <linux/device.h>
38307 #include <linux/highmem.h>
38308@@ -37,6 +38,10 @@
38309
38310 #define DEVPORT_MINOR 4
38311
38312+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38313+extern const struct file_operations grsec_fops;
38314+#endif
38315+
38316 static inline unsigned long size_inside_page(unsigned long start,
38317 unsigned long size)
38318 {
38319@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38320
38321 while (cursor < to) {
38322 if (!devmem_is_allowed(pfn)) {
38323+#ifdef CONFIG_GRKERNSEC_KMEM
38324+ gr_handle_mem_readwrite(from, to);
38325+#else
38326 printk(KERN_INFO
38327 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38328 current->comm, from, to);
38329+#endif
38330 return 0;
38331 }
38332 cursor += PAGE_SIZE;
38333@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38334 }
38335 return 1;
38336 }
38337+#elif defined(CONFIG_GRKERNSEC_KMEM)
38338+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38339+{
38340+ return 0;
38341+}
38342 #else
38343 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38344 {
38345@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38346
38347 while (count > 0) {
38348 unsigned long remaining;
38349+ char *temp;
38350
38351 sz = size_inside_page(p, count);
38352
38353@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38354 if (!ptr)
38355 return -EFAULT;
38356
38357- remaining = copy_to_user(buf, ptr, sz);
38358+#ifdef CONFIG_PAX_USERCOPY
38359+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38360+ if (!temp) {
38361+ unxlate_dev_mem_ptr(p, ptr);
38362+ return -ENOMEM;
38363+ }
38364+ memcpy(temp, ptr, sz);
38365+#else
38366+ temp = ptr;
38367+#endif
38368+
38369+ remaining = copy_to_user(buf, temp, sz);
38370+
38371+#ifdef CONFIG_PAX_USERCOPY
38372+ kfree(temp);
38373+#endif
38374+
38375 unxlate_dev_mem_ptr(p, ptr);
38376 if (remaining)
38377 return -EFAULT;
38378@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38379 size_t count, loff_t *ppos)
38380 {
38381 unsigned long p = *ppos;
38382- ssize_t low_count, read, sz;
38383+ ssize_t low_count, read, sz, err = 0;
38384 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38385- int err = 0;
38386
38387 read = 0;
38388 if (p < (unsigned long) high_memory) {
38389@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38390 }
38391 #endif
38392 while (low_count > 0) {
38393+ char *temp;
38394+
38395 sz = size_inside_page(p, low_count);
38396
38397 /*
38398@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38399 */
38400 kbuf = xlate_dev_kmem_ptr((char *)p);
38401
38402- if (copy_to_user(buf, kbuf, sz))
38403+#ifdef CONFIG_PAX_USERCOPY
38404+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38405+ if (!temp)
38406+ return -ENOMEM;
38407+ memcpy(temp, kbuf, sz);
38408+#else
38409+ temp = kbuf;
38410+#endif
38411+
38412+ err = copy_to_user(buf, temp, sz);
38413+
38414+#ifdef CONFIG_PAX_USERCOPY
38415+ kfree(temp);
38416+#endif
38417+
38418+ if (err)
38419 return -EFAULT;
38420 buf += sz;
38421 p += sz;
38422@@ -822,6 +869,9 @@ static const struct memdev {
38423 #ifdef CONFIG_PRINTK
38424 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38425 #endif
38426+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38427+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38428+#endif
38429 };
38430
38431 static int memory_open(struct inode *inode, struct file *filp)
38432@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38433 continue;
38434
38435 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38436- NULL, devlist[minor].name);
38437+ NULL, "%s", devlist[minor].name);
38438 }
38439
38440 return tty_init();
38441diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38442index 9df78e2..01ba9ae 100644
38443--- a/drivers/char/nvram.c
38444+++ b/drivers/char/nvram.c
38445@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38446
38447 spin_unlock_irq(&rtc_lock);
38448
38449- if (copy_to_user(buf, contents, tmp - contents))
38450+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38451 return -EFAULT;
38452
38453 *ppos = i;
38454diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38455index d39cca6..8c1e269 100644
38456--- a/drivers/char/pcmcia/synclink_cs.c
38457+++ b/drivers/char/pcmcia/synclink_cs.c
38458@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38459
38460 if (debug_level >= DEBUG_LEVEL_INFO)
38461 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38462- __FILE__, __LINE__, info->device_name, port->count);
38463+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38464
38465- WARN_ON(!port->count);
38466+ WARN_ON(!atomic_read(&port->count));
38467
38468 if (tty_port_close_start(port, tty, filp) == 0)
38469 goto cleanup;
38470@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38471 cleanup:
38472 if (debug_level >= DEBUG_LEVEL_INFO)
38473 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38474- tty->driver->name, port->count);
38475+ tty->driver->name, atomic_read(&port->count));
38476 }
38477
38478 /* Wait until the transmitter is empty.
38479@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38480
38481 if (debug_level >= DEBUG_LEVEL_INFO)
38482 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38483- __FILE__, __LINE__, tty->driver->name, port->count);
38484+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38485
38486 /* If port is closing, signal caller to try again */
38487 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38488@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38489 goto cleanup;
38490 }
38491 spin_lock(&port->lock);
38492- port->count++;
38493+ atomic_inc(&port->count);
38494 spin_unlock(&port->lock);
38495 spin_unlock_irqrestore(&info->netlock, flags);
38496
38497- if (port->count == 1) {
38498+ if (atomic_read(&port->count) == 1) {
38499 /* 1st open on this device, init hardware */
38500 retval = startup(info, tty);
38501 if (retval < 0)
38502@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38503 unsigned short new_crctype;
38504
38505 /* return error if TTY interface open */
38506- if (info->port.count)
38507+ if (atomic_read(&info->port.count))
38508 return -EBUSY;
38509
38510 switch (encoding)
38511@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38512
38513 /* arbitrate between network and tty opens */
38514 spin_lock_irqsave(&info->netlock, flags);
38515- if (info->port.count != 0 || info->netcount != 0) {
38516+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38517 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38518 spin_unlock_irqrestore(&info->netlock, flags);
38519 return -EBUSY;
38520@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38521 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38522
38523 /* return error if TTY interface open */
38524- if (info->port.count)
38525+ if (atomic_read(&info->port.count))
38526 return -EBUSY;
38527
38528 if (cmd != SIOCWANDEV)
38529diff --git a/drivers/char/random.c b/drivers/char/random.c
38530index 429b75b..a7f4145 100644
38531--- a/drivers/char/random.c
38532+++ b/drivers/char/random.c
38533@@ -270,10 +270,17 @@
38534 /*
38535 * Configuration information
38536 */
38537+#ifdef CONFIG_GRKERNSEC_RANDNET
38538+#define INPUT_POOL_SHIFT 14
38539+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38540+#define OUTPUT_POOL_SHIFT 12
38541+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38542+#else
38543 #define INPUT_POOL_SHIFT 12
38544 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38545 #define OUTPUT_POOL_SHIFT 10
38546 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38547+#endif
38548 #define SEC_XFER_SIZE 512
38549 #define EXTRACT_SIZE 10
38550
38551@@ -284,9 +291,6 @@
38552 /*
38553 * To allow fractional bits to be tracked, the entropy_count field is
38554 * denominated in units of 1/8th bits.
38555- *
38556- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38557- * credit_entropy_bits() needs to be 64 bits wide.
38558 */
38559 #define ENTROPY_SHIFT 3
38560 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38561@@ -361,12 +365,19 @@ static struct poolinfo {
38562 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38563 int tap1, tap2, tap3, tap4, tap5;
38564 } poolinfo_table[] = {
38565+#ifdef CONFIG_GRKERNSEC_RANDNET
38566+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38567+ { S(512), 411, 308, 208, 104, 1 },
38568+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38569+ { S(128), 104, 76, 51, 25, 1 },
38570+#else
38571 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38572 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38573 { S(128), 104, 76, 51, 25, 1 },
38574 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38575 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38576 { S(32), 26, 19, 14, 7, 1 },
38577+#endif
38578 #if 0
38579 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38580 { S(2048), 1638, 1231, 819, 411, 1 },
38581@@ -433,9 +444,9 @@ struct entropy_store {
38582 };
38583
38584 static void push_to_pool(struct work_struct *work);
38585-static __u32 input_pool_data[INPUT_POOL_WORDS];
38586-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38587-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38588+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38589+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38590+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38591
38592 static struct entropy_store input_pool = {
38593 .poolinfo = &poolinfo_table[0],
38594@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38595 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38596 }
38597
38598- ACCESS_ONCE(r->input_rotate) = input_rotate;
38599- ACCESS_ONCE(r->add_ptr) = i;
38600+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38601+ ACCESS_ONCE_RW(r->add_ptr) = i;
38602 smp_wmb();
38603
38604 if (out)
38605@@ -632,7 +643,7 @@ retry:
38606 /* The +2 corresponds to the /4 in the denominator */
38607
38608 do {
38609- unsigned int anfrac = min(pnfrac, pool_size/2);
38610+ u64 anfrac = min(pnfrac, pool_size/2);
38611 unsigned int add =
38612 ((pool_size - entropy_count)*anfrac*3) >> s;
38613
38614@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38615
38616 extract_buf(r, tmp);
38617 i = min_t(int, nbytes, EXTRACT_SIZE);
38618- if (copy_to_user(buf, tmp, i)) {
38619+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38620 ret = -EFAULT;
38621 break;
38622 }
38623@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38624 #include <linux/sysctl.h>
38625
38626 static int min_read_thresh = 8, min_write_thresh;
38627-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38628+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38629 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38630 static char sysctl_bootid[16];
38631
38632@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38633 static int proc_do_uuid(struct ctl_table *table, int write,
38634 void __user *buffer, size_t *lenp, loff_t *ppos)
38635 {
38636- struct ctl_table fake_table;
38637+ ctl_table_no_const fake_table;
38638 unsigned char buf[64], tmp_uuid[16], *uuid;
38639
38640 uuid = table->data;
38641@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38642 static int proc_do_entropy(ctl_table *table, int write,
38643 void __user *buffer, size_t *lenp, loff_t *ppos)
38644 {
38645- ctl_table fake_table;
38646+ ctl_table_no_const fake_table;
38647 int entropy_count;
38648
38649 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38650diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38651index 7cc1fe22..b602d6b 100644
38652--- a/drivers/char/sonypi.c
38653+++ b/drivers/char/sonypi.c
38654@@ -54,6 +54,7 @@
38655
38656 #include <asm/uaccess.h>
38657 #include <asm/io.h>
38658+#include <asm/local.h>
38659
38660 #include <linux/sonypi.h>
38661
38662@@ -490,7 +491,7 @@ static struct sonypi_device {
38663 spinlock_t fifo_lock;
38664 wait_queue_head_t fifo_proc_list;
38665 struct fasync_struct *fifo_async;
38666- int open_count;
38667+ local_t open_count;
38668 int model;
38669 struct input_dev *input_jog_dev;
38670 struct input_dev *input_key_dev;
38671@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38672 static int sonypi_misc_release(struct inode *inode, struct file *file)
38673 {
38674 mutex_lock(&sonypi_device.lock);
38675- sonypi_device.open_count--;
38676+ local_dec(&sonypi_device.open_count);
38677 mutex_unlock(&sonypi_device.lock);
38678 return 0;
38679 }
38680@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38681 {
38682 mutex_lock(&sonypi_device.lock);
38683 /* Flush input queue on first open */
38684- if (!sonypi_device.open_count)
38685+ if (!local_read(&sonypi_device.open_count))
38686 kfifo_reset(&sonypi_device.fifo);
38687- sonypi_device.open_count++;
38688+ local_inc(&sonypi_device.open_count);
38689 mutex_unlock(&sonypi_device.lock);
38690
38691 return 0;
38692diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38693index 64420b3..5c40b56 100644
38694--- a/drivers/char/tpm/tpm_acpi.c
38695+++ b/drivers/char/tpm/tpm_acpi.c
38696@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38697 virt = acpi_os_map_memory(start, len);
38698 if (!virt) {
38699 kfree(log->bios_event_log);
38700+ log->bios_event_log = NULL;
38701 printk("%s: ERROR - Unable to map memory\n", __func__);
38702 return -EIO;
38703 }
38704
38705- memcpy_fromio(log->bios_event_log, virt, len);
38706+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38707
38708 acpi_os_unmap_memory(virt, len);
38709 return 0;
38710diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38711index 59f7cb2..bac8b6d 100644
38712--- a/drivers/char/tpm/tpm_eventlog.c
38713+++ b/drivers/char/tpm/tpm_eventlog.c
38714@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38715 event = addr;
38716
38717 if ((event->event_type == 0 && event->event_size == 0) ||
38718- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38719+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38720 return NULL;
38721
38722 return addr;
38723@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38724 return NULL;
38725
38726 if ((event->event_type == 0 && event->event_size == 0) ||
38727- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38728+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38729 return NULL;
38730
38731 (*pos)++;
38732@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38733 int i;
38734
38735 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38736- seq_putc(m, data[i]);
38737+ if (!seq_putc(m, data[i]))
38738+ return -EFAULT;
38739
38740 return 0;
38741 }
38742diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38743index feea87c..18aefff 100644
38744--- a/drivers/char/virtio_console.c
38745+++ b/drivers/char/virtio_console.c
38746@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38747 if (to_user) {
38748 ssize_t ret;
38749
38750- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38751+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38752 if (ret)
38753 return -EFAULT;
38754 } else {
38755@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38756 if (!port_has_data(port) && !port->host_connected)
38757 return 0;
38758
38759- return fill_readbuf(port, ubuf, count, true);
38760+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38761 }
38762
38763 static int wait_port_writable(struct port *port, bool nonblock)
38764diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38765index a33f46f..a720eed 100644
38766--- a/drivers/clk/clk-composite.c
38767+++ b/drivers/clk/clk-composite.c
38768@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38769 struct clk *clk;
38770 struct clk_init_data init;
38771 struct clk_composite *composite;
38772- struct clk_ops *clk_composite_ops;
38773+ clk_ops_no_const *clk_composite_ops;
38774
38775 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38776 if (!composite) {
38777diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38778index 81dd31a..ef5c542 100644
38779--- a/drivers/clk/socfpga/clk.c
38780+++ b/drivers/clk/socfpga/clk.c
38781@@ -22,6 +22,7 @@
38782 #include <linux/clk-provider.h>
38783 #include <linux/io.h>
38784 #include <linux/of.h>
38785+#include <asm/pgtable.h>
38786
38787 /* Clock Manager offsets */
38788 #define CLKMGR_CTRL 0x0
38789@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38790 streq(clk_name, "periph_pll") ||
38791 streq(clk_name, "sdram_pll")) {
38792 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38793- clk_pll_ops.enable = clk_gate_ops.enable;
38794- clk_pll_ops.disable = clk_gate_ops.disable;
38795+ pax_open_kernel();
38796+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38797+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38798+ pax_close_kernel();
38799 }
38800
38801 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38802@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38803 return parent_rate / div;
38804 }
38805
38806-static struct clk_ops gateclk_ops = {
38807+static clk_ops_no_const gateclk_ops __read_only = {
38808 .recalc_rate = socfpga_clk_recalc_rate,
38809 .get_parent = socfpga_clk_get_parent,
38810 .set_parent = socfpga_clk_set_parent,
38811diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38812index caf41eb..223d27a 100644
38813--- a/drivers/cpufreq/acpi-cpufreq.c
38814+++ b/drivers/cpufreq/acpi-cpufreq.c
38815@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38816 return sprintf(buf, "%u\n", boost_enabled);
38817 }
38818
38819-static struct global_attr global_boost = __ATTR(boost, 0644,
38820+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38821 show_global_boost,
38822 store_global_boost);
38823
38824@@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38825 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38826 per_cpu(acfreq_data, cpu) = data;
38827
38828- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38829- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38830+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38831+ pax_open_kernel();
38832+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38833+ pax_close_kernel();
38834+ }
38835
38836 result = acpi_processor_register_performance(data->acpi_data, cpu);
38837 if (result)
38838@@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38839 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38840 break;
38841 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38842- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38843+ pax_open_kernel();
38844+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38845+ pax_close_kernel();
38846 break;
38847 default:
38848 break;
38849diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38850index 99a443e..8cb6f02 100644
38851--- a/drivers/cpufreq/cpufreq.c
38852+++ b/drivers/cpufreq/cpufreq.c
38853@@ -1878,7 +1878,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38854 #endif
38855
38856 mutex_lock(&cpufreq_governor_mutex);
38857- list_del(&governor->governor_list);
38858+ pax_list_del(&governor->governor_list);
38859 mutex_unlock(&cpufreq_governor_mutex);
38860 return;
38861 }
38862@@ -2108,7 +2108,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38863 return NOTIFY_OK;
38864 }
38865
38866-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38867+static struct notifier_block cpufreq_cpu_notifier = {
38868 .notifier_call = cpufreq_cpu_callback,
38869 };
38870
38871@@ -2141,8 +2141,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38872
38873 pr_debug("trying to register driver %s\n", driver_data->name);
38874
38875- if (driver_data->setpolicy)
38876- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38877+ if (driver_data->setpolicy) {
38878+ pax_open_kernel();
38879+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38880+ pax_close_kernel();
38881+ }
38882
38883 write_lock_irqsave(&cpufreq_driver_lock, flags);
38884 if (cpufreq_driver) {
38885diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38886index e6be635..f8a90dc 100644
38887--- a/drivers/cpufreq/cpufreq_governor.c
38888+++ b/drivers/cpufreq/cpufreq_governor.c
38889@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38890 struct dbs_data *dbs_data;
38891 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38892 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38893- struct od_ops *od_ops = NULL;
38894+ const struct od_ops *od_ops = NULL;
38895 struct od_dbs_tuners *od_tuners = NULL;
38896 struct cs_dbs_tuners *cs_tuners = NULL;
38897 struct cpu_dbs_common_info *cpu_cdbs;
38898@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38899
38900 if ((cdata->governor == GOV_CONSERVATIVE) &&
38901 (!policy->governor->initialized)) {
38902- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38903+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38904
38905 cpufreq_register_notifier(cs_ops->notifier_block,
38906 CPUFREQ_TRANSITION_NOTIFIER);
38907@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38908
38909 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38910 (policy->governor->initialized == 1)) {
38911- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38912+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38913
38914 cpufreq_unregister_notifier(cs_ops->notifier_block,
38915 CPUFREQ_TRANSITION_NOTIFIER);
38916diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38917index b5f2b86..daa801b 100644
38918--- a/drivers/cpufreq/cpufreq_governor.h
38919+++ b/drivers/cpufreq/cpufreq_governor.h
38920@@ -205,7 +205,7 @@ struct common_dbs_data {
38921 void (*exit)(struct dbs_data *dbs_data);
38922
38923 /* Governor specific ops, see below */
38924- void *gov_ops;
38925+ const void *gov_ops;
38926 };
38927
38928 /* Governor Per policy data */
38929@@ -225,7 +225,7 @@ struct od_ops {
38930 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38931 unsigned int freq_next, unsigned int relation);
38932 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38933-};
38934+} __no_const;
38935
38936 struct cs_ops {
38937 struct notifier_block *notifier_block;
38938diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38939index 18d4091..434be15 100644
38940--- a/drivers/cpufreq/cpufreq_ondemand.c
38941+++ b/drivers/cpufreq/cpufreq_ondemand.c
38942@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38943
38944 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38945
38946-static struct od_ops od_ops = {
38947+static struct od_ops od_ops __read_only = {
38948 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38949 .powersave_bias_target = generic_powersave_bias_target,
38950 .freq_increase = dbs_freq_increase,
38951@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38952 (struct cpufreq_policy *, unsigned int, unsigned int),
38953 unsigned int powersave_bias)
38954 {
38955- od_ops.powersave_bias_target = f;
38956+ pax_open_kernel();
38957+ *(void **)&od_ops.powersave_bias_target = f;
38958+ pax_close_kernel();
38959 od_set_powersave_bias(powersave_bias);
38960 }
38961 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38962
38963 void od_unregister_powersave_bias_handler(void)
38964 {
38965- od_ops.powersave_bias_target = generic_powersave_bias_target;
38966+ pax_open_kernel();
38967+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38968+ pax_close_kernel();
38969 od_set_powersave_bias(0);
38970 }
38971 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38972diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38973index 4cf0d28..5830372 100644
38974--- a/drivers/cpufreq/cpufreq_stats.c
38975+++ b/drivers/cpufreq/cpufreq_stats.c
38976@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38977 }
38978
38979 /* priority=1 so this will get called before cpufreq_remove_dev */
38980-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38981+static struct notifier_block cpufreq_stat_cpu_notifier = {
38982 .notifier_call = cpufreq_stat_cpu_callback,
38983 .priority = 1,
38984 };
38985diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38986index b687df8..ae733fc 100644
38987--- a/drivers/cpufreq/intel_pstate.c
38988+++ b/drivers/cpufreq/intel_pstate.c
38989@@ -123,10 +123,10 @@ struct pstate_funcs {
38990 struct cpu_defaults {
38991 struct pstate_adjust_policy pid_policy;
38992 struct pstate_funcs funcs;
38993-};
38994+} __do_const;
38995
38996 static struct pstate_adjust_policy pid_params;
38997-static struct pstate_funcs pstate_funcs;
38998+static struct pstate_funcs *pstate_funcs;
38999
39000 struct perf_limits {
39001 int no_turbo;
39002@@ -517,7 +517,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39003
39004 cpu->pstate.current_pstate = pstate;
39005
39006- pstate_funcs.set(cpu, pstate);
39007+ pstate_funcs->set(cpu, pstate);
39008 }
39009
39010 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39011@@ -539,12 +539,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39012 {
39013 sprintf(cpu->name, "Intel 2nd generation core");
39014
39015- cpu->pstate.min_pstate = pstate_funcs.get_min();
39016- cpu->pstate.max_pstate = pstate_funcs.get_max();
39017- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39018+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39019+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39020+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39021
39022- if (pstate_funcs.get_vid)
39023- pstate_funcs.get_vid(cpu);
39024+ if (pstate_funcs->get_vid)
39025+ pstate_funcs->get_vid(cpu);
39026
39027 /*
39028 * goto max pstate so we don't slow up boot if we are built-in if we are
39029@@ -808,9 +808,9 @@ static int intel_pstate_msrs_not_valid(void)
39030 rdmsrl(MSR_IA32_APERF, aperf);
39031 rdmsrl(MSR_IA32_MPERF, mperf);
39032
39033- if (!pstate_funcs.get_max() ||
39034- !pstate_funcs.get_min() ||
39035- !pstate_funcs.get_turbo())
39036+ if (!pstate_funcs->get_max() ||
39037+ !pstate_funcs->get_min() ||
39038+ !pstate_funcs->get_turbo())
39039 return -ENODEV;
39040
39041 rdmsrl(MSR_IA32_APERF, tmp);
39042@@ -824,7 +824,7 @@ static int intel_pstate_msrs_not_valid(void)
39043 return 0;
39044 }
39045
39046-static void copy_pid_params(struct pstate_adjust_policy *policy)
39047+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39048 {
39049 pid_params.sample_rate_ms = policy->sample_rate_ms;
39050 pid_params.p_gain_pct = policy->p_gain_pct;
39051@@ -836,11 +836,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39052
39053 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39054 {
39055- pstate_funcs.get_max = funcs->get_max;
39056- pstate_funcs.get_min = funcs->get_min;
39057- pstate_funcs.get_turbo = funcs->get_turbo;
39058- pstate_funcs.set = funcs->set;
39059- pstate_funcs.get_vid = funcs->get_vid;
39060+ pstate_funcs = funcs;
39061 }
39062
39063 #if IS_ENABLED(CONFIG_ACPI)
39064diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39065index 3d1cba9..0ab21d2 100644
39066--- a/drivers/cpufreq/p4-clockmod.c
39067+++ b/drivers/cpufreq/p4-clockmod.c
39068@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39069 case 0x0F: /* Core Duo */
39070 case 0x16: /* Celeron Core */
39071 case 0x1C: /* Atom */
39072- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39073+ pax_open_kernel();
39074+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39075+ pax_close_kernel();
39076 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39077 case 0x0D: /* Pentium M (Dothan) */
39078- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39079+ pax_open_kernel();
39080+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39081+ pax_close_kernel();
39082 /* fall through */
39083 case 0x09: /* Pentium M (Banias) */
39084 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39085@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39086
39087 /* on P-4s, the TSC runs with constant frequency independent whether
39088 * throttling is active or not. */
39089- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39090+ pax_open_kernel();
39091+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39092+ pax_close_kernel();
39093
39094 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39095 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39096diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39097index 724ffbd..ad83692 100644
39098--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39099+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39100@@ -18,14 +18,12 @@
39101 #include <asm/head.h>
39102 #include <asm/timer.h>
39103
39104-static struct cpufreq_driver *cpufreq_us3_driver;
39105-
39106 struct us3_freq_percpu_info {
39107 struct cpufreq_frequency_table table[4];
39108 };
39109
39110 /* Indexed by cpu number. */
39111-static struct us3_freq_percpu_info *us3_freq_table;
39112+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39113
39114 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39115 * in the Safari config register.
39116@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39117
39118 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39119 {
39120- if (cpufreq_us3_driver) {
39121- cpufreq_frequency_table_put_attr(policy->cpu);
39122- us3_freq_target(policy, 0);
39123- }
39124+ cpufreq_frequency_table_put_attr(policy->cpu);
39125+ us3_freq_target(policy, 0);
39126
39127 return 0;
39128 }
39129
39130+static int __init us3_freq_init(void);
39131+static void __exit us3_freq_exit(void);
39132+
39133+static struct cpufreq_driver cpufreq_us3_driver = {
39134+ .init = us3_freq_cpu_init,
39135+ .verify = cpufreq_generic_frequency_table_verify,
39136+ .target_index = us3_freq_target,
39137+ .get = us3_freq_get,
39138+ .exit = us3_freq_cpu_exit,
39139+ .owner = THIS_MODULE,
39140+ .name = "UltraSPARC-III",
39141+
39142+};
39143+
39144 static int __init us3_freq_init(void)
39145 {
39146 unsigned long manuf, impl, ver;
39147@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39148 (impl == CHEETAH_IMPL ||
39149 impl == CHEETAH_PLUS_IMPL ||
39150 impl == JAGUAR_IMPL ||
39151- impl == PANTHER_IMPL)) {
39152- struct cpufreq_driver *driver;
39153-
39154- ret = -ENOMEM;
39155- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39156- if (!driver)
39157- goto err_out;
39158-
39159- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39160- GFP_KERNEL);
39161- if (!us3_freq_table)
39162- goto err_out;
39163-
39164- driver->init = us3_freq_cpu_init;
39165- driver->verify = cpufreq_generic_frequency_table_verify;
39166- driver->target_index = us3_freq_target;
39167- driver->get = us3_freq_get;
39168- driver->exit = us3_freq_cpu_exit;
39169- strcpy(driver->name, "UltraSPARC-III");
39170-
39171- cpufreq_us3_driver = driver;
39172- ret = cpufreq_register_driver(driver);
39173- if (ret)
39174- goto err_out;
39175-
39176- return 0;
39177-
39178-err_out:
39179- if (driver) {
39180- kfree(driver);
39181- cpufreq_us3_driver = NULL;
39182- }
39183- kfree(us3_freq_table);
39184- us3_freq_table = NULL;
39185- return ret;
39186- }
39187+ impl == PANTHER_IMPL))
39188+ return cpufreq_register_driver(&cpufreq_us3_driver);
39189
39190 return -ENODEV;
39191 }
39192
39193 static void __exit us3_freq_exit(void)
39194 {
39195- if (cpufreq_us3_driver) {
39196- cpufreq_unregister_driver(cpufreq_us3_driver);
39197- kfree(cpufreq_us3_driver);
39198- cpufreq_us3_driver = NULL;
39199- kfree(us3_freq_table);
39200- us3_freq_table = NULL;
39201- }
39202+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39203 }
39204
39205 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39206diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39207index 4e1daca..e707b61 100644
39208--- a/drivers/cpufreq/speedstep-centrino.c
39209+++ b/drivers/cpufreq/speedstep-centrino.c
39210@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39211 !cpu_has(cpu, X86_FEATURE_EST))
39212 return -ENODEV;
39213
39214- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39215- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39216+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39217+ pax_open_kernel();
39218+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39219+ pax_close_kernel();
39220+ }
39221
39222 if (policy->cpu != 0)
39223 return -ENODEV;
39224diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39225index 06dbe7c..c2c8671 100644
39226--- a/drivers/cpuidle/driver.c
39227+++ b/drivers/cpuidle/driver.c
39228@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39229
39230 static void poll_idle_init(struct cpuidle_driver *drv)
39231 {
39232- struct cpuidle_state *state = &drv->states[0];
39233+ cpuidle_state_no_const *state = &drv->states[0];
39234
39235 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39236 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39237diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39238index ca89412..a7b9c49 100644
39239--- a/drivers/cpuidle/governor.c
39240+++ b/drivers/cpuidle/governor.c
39241@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39242 mutex_lock(&cpuidle_lock);
39243 if (__cpuidle_find_governor(gov->name) == NULL) {
39244 ret = 0;
39245- list_add_tail(&gov->governor_list, &cpuidle_governors);
39246+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39247 if (!cpuidle_curr_governor ||
39248 cpuidle_curr_governor->rating < gov->rating)
39249 cpuidle_switch_governor(gov);
39250diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39251index e918b6d..f87ea80 100644
39252--- a/drivers/cpuidle/sysfs.c
39253+++ b/drivers/cpuidle/sysfs.c
39254@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39255 NULL
39256 };
39257
39258-static struct attribute_group cpuidle_attr_group = {
39259+static attribute_group_no_const cpuidle_attr_group = {
39260 .attrs = cpuidle_default_attrs,
39261 .name = "cpuidle",
39262 };
39263diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39264index 12fea3e..1e28f47 100644
39265--- a/drivers/crypto/hifn_795x.c
39266+++ b/drivers/crypto/hifn_795x.c
39267@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39268 MODULE_PARM_DESC(hifn_pll_ref,
39269 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39270
39271-static atomic_t hifn_dev_number;
39272+static atomic_unchecked_t hifn_dev_number;
39273
39274 #define ACRYPTO_OP_DECRYPT 0
39275 #define ACRYPTO_OP_ENCRYPT 1
39276@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39277 goto err_out_disable_pci_device;
39278
39279 snprintf(name, sizeof(name), "hifn%d",
39280- atomic_inc_return(&hifn_dev_number)-1);
39281+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39282
39283 err = pci_request_regions(pdev, name);
39284 if (err)
39285diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39286index a0b2f7e..1b6f028 100644
39287--- a/drivers/devfreq/devfreq.c
39288+++ b/drivers/devfreq/devfreq.c
39289@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39290 goto err_out;
39291 }
39292
39293- list_add(&governor->node, &devfreq_governor_list);
39294+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39295
39296 list_for_each_entry(devfreq, &devfreq_list, node) {
39297 int ret = 0;
39298@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39299 }
39300 }
39301
39302- list_del(&governor->node);
39303+ pax_list_del((struct list_head *)&governor->node);
39304 err_out:
39305 mutex_unlock(&devfreq_list_lock);
39306
39307diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39308index 0d765c0..60b7480 100644
39309--- a/drivers/dma/sh/shdmac.c
39310+++ b/drivers/dma/sh/shdmac.c
39311@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39312 return ret;
39313 }
39314
39315-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39316+static struct notifier_block sh_dmae_nmi_notifier = {
39317 .notifier_call = sh_dmae_nmi_handler,
39318
39319 /* Run before NMI debug handler and KGDB */
39320diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39321index 1026743..80b081c 100644
39322--- a/drivers/edac/edac_device.c
39323+++ b/drivers/edac/edac_device.c
39324@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39325 */
39326 int edac_device_alloc_index(void)
39327 {
39328- static atomic_t device_indexes = ATOMIC_INIT(0);
39329+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39330
39331- return atomic_inc_return(&device_indexes) - 1;
39332+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39333 }
39334 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39335
39336diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39337index e5bdf21..b8f9055 100644
39338--- a/drivers/edac/edac_mc_sysfs.c
39339+++ b/drivers/edac/edac_mc_sysfs.c
39340@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39341 struct dev_ch_attribute {
39342 struct device_attribute attr;
39343 int channel;
39344-};
39345+} __do_const;
39346
39347 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39348 struct dev_ch_attribute dev_attr_legacy_##_name = \
39349@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39350 }
39351
39352 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39353+ pax_open_kernel();
39354 if (mci->get_sdram_scrub_rate) {
39355- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39356- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39357+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39358+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39359 }
39360 if (mci->set_sdram_scrub_rate) {
39361- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39362- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39363+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39364+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39365 }
39366+ pax_close_kernel();
39367 err = device_create_file(&mci->dev,
39368 &dev_attr_sdram_scrub_rate);
39369 if (err) {
39370diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39371index 2cf44b4d..6dd2dc7 100644
39372--- a/drivers/edac/edac_pci.c
39373+++ b/drivers/edac/edac_pci.c
39374@@ -29,7 +29,7 @@
39375
39376 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39377 static LIST_HEAD(edac_pci_list);
39378-static atomic_t pci_indexes = ATOMIC_INIT(0);
39379+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39380
39381 /*
39382 * edac_pci_alloc_ctl_info
39383@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39384 */
39385 int edac_pci_alloc_index(void)
39386 {
39387- return atomic_inc_return(&pci_indexes) - 1;
39388+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39389 }
39390 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39391
39392diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39393index e8658e4..22746d6 100644
39394--- a/drivers/edac/edac_pci_sysfs.c
39395+++ b/drivers/edac/edac_pci_sysfs.c
39396@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39397 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39398 static int edac_pci_poll_msec = 1000; /* one second workq period */
39399
39400-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39401-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39402+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39403+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39404
39405 static struct kobject *edac_pci_top_main_kobj;
39406 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39407@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39408 void *value;
39409 ssize_t(*show) (void *, char *);
39410 ssize_t(*store) (void *, const char *, size_t);
39411-};
39412+} __do_const;
39413
39414 /* Set of show/store abstract level functions for PCI Parity object */
39415 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39416@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39417 edac_printk(KERN_CRIT, EDAC_PCI,
39418 "Signaled System Error on %s\n",
39419 pci_name(dev));
39420- atomic_inc(&pci_nonparity_count);
39421+ atomic_inc_unchecked(&pci_nonparity_count);
39422 }
39423
39424 if (status & (PCI_STATUS_PARITY)) {
39425@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39426 "Master Data Parity Error on %s\n",
39427 pci_name(dev));
39428
39429- atomic_inc(&pci_parity_count);
39430+ atomic_inc_unchecked(&pci_parity_count);
39431 }
39432
39433 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39434@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39435 "Detected Parity Error on %s\n",
39436 pci_name(dev));
39437
39438- atomic_inc(&pci_parity_count);
39439+ atomic_inc_unchecked(&pci_parity_count);
39440 }
39441 }
39442
39443@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39444 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39445 "Signaled System Error on %s\n",
39446 pci_name(dev));
39447- atomic_inc(&pci_nonparity_count);
39448+ atomic_inc_unchecked(&pci_nonparity_count);
39449 }
39450
39451 if (status & (PCI_STATUS_PARITY)) {
39452@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39453 "Master Data Parity Error on "
39454 "%s\n", pci_name(dev));
39455
39456- atomic_inc(&pci_parity_count);
39457+ atomic_inc_unchecked(&pci_parity_count);
39458 }
39459
39460 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39461@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39462 "Detected Parity Error on %s\n",
39463 pci_name(dev));
39464
39465- atomic_inc(&pci_parity_count);
39466+ atomic_inc_unchecked(&pci_parity_count);
39467 }
39468 }
39469 }
39470@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39471 if (!check_pci_errors)
39472 return;
39473
39474- before_count = atomic_read(&pci_parity_count);
39475+ before_count = atomic_read_unchecked(&pci_parity_count);
39476
39477 /* scan all PCI devices looking for a Parity Error on devices and
39478 * bridges.
39479@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39480 /* Only if operator has selected panic on PCI Error */
39481 if (edac_pci_get_panic_on_pe()) {
39482 /* If the count is different 'after' from 'before' */
39483- if (before_count != atomic_read(&pci_parity_count))
39484+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39485 panic("EDAC: PCI Parity Error");
39486 }
39487 }
39488diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39489index 51b7e3a..aa8a3e8 100644
39490--- a/drivers/edac/mce_amd.h
39491+++ b/drivers/edac/mce_amd.h
39492@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39493 bool (*mc0_mce)(u16, u8);
39494 bool (*mc1_mce)(u16, u8);
39495 bool (*mc2_mce)(u16, u8);
39496-};
39497+} __no_const;
39498
39499 void amd_report_gart_errors(bool);
39500 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39501diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39502index 57ea7f4..af06b76 100644
39503--- a/drivers/firewire/core-card.c
39504+++ b/drivers/firewire/core-card.c
39505@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39506 const struct fw_card_driver *driver,
39507 struct device *device)
39508 {
39509- static atomic_t index = ATOMIC_INIT(-1);
39510+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39511
39512- card->index = atomic_inc_return(&index);
39513+ card->index = atomic_inc_return_unchecked(&index);
39514 card->driver = driver;
39515 card->device = device;
39516 card->current_tlabel = 0;
39517@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39518
39519 void fw_core_remove_card(struct fw_card *card)
39520 {
39521- struct fw_card_driver dummy_driver = dummy_driver_template;
39522+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39523
39524 card->driver->update_phy_reg(card, 4,
39525 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39526diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39527index 2c6d5e1..a2cca6b 100644
39528--- a/drivers/firewire/core-device.c
39529+++ b/drivers/firewire/core-device.c
39530@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39531 struct config_rom_attribute {
39532 struct device_attribute attr;
39533 u32 key;
39534-};
39535+} __do_const;
39536
39537 static ssize_t show_immediate(struct device *dev,
39538 struct device_attribute *dattr, char *buf)
39539diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39540index 0e79951..b180217 100644
39541--- a/drivers/firewire/core-transaction.c
39542+++ b/drivers/firewire/core-transaction.c
39543@@ -38,6 +38,7 @@
39544 #include <linux/timer.h>
39545 #include <linux/types.h>
39546 #include <linux/workqueue.h>
39547+#include <linux/sched.h>
39548
39549 #include <asm/byteorder.h>
39550
39551diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39552index 515a42c..5ecf3ba 100644
39553--- a/drivers/firewire/core.h
39554+++ b/drivers/firewire/core.h
39555@@ -111,6 +111,7 @@ struct fw_card_driver {
39556
39557 int (*stop_iso)(struct fw_iso_context *ctx);
39558 };
39559+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39560
39561 void fw_card_initialize(struct fw_card *card,
39562 const struct fw_card_driver *driver, struct device *device);
39563diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39564index 94a58a0..f5eba42 100644
39565--- a/drivers/firmware/dmi-id.c
39566+++ b/drivers/firmware/dmi-id.c
39567@@ -16,7 +16,7 @@
39568 struct dmi_device_attribute{
39569 struct device_attribute dev_attr;
39570 int field;
39571-};
39572+} __do_const;
39573 #define to_dmi_dev_attr(_dev_attr) \
39574 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39575
39576diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39577index c7e81ff..94a7401 100644
39578--- a/drivers/firmware/dmi_scan.c
39579+++ b/drivers/firmware/dmi_scan.c
39580@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39581 if (buf == NULL)
39582 return -1;
39583
39584- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39585+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39586
39587 iounmap(buf);
39588 return 0;
39589diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39590index 1491dd4..aa910db 100644
39591--- a/drivers/firmware/efi/cper.c
39592+++ b/drivers/firmware/efi/cper.c
39593@@ -41,12 +41,12 @@
39594 */
39595 u64 cper_next_record_id(void)
39596 {
39597- static atomic64_t seq;
39598+ static atomic64_unchecked_t seq;
39599
39600- if (!atomic64_read(&seq))
39601- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39602+ if (!atomic64_read_unchecked(&seq))
39603+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39604
39605- return atomic64_inc_return(&seq);
39606+ return atomic64_inc_return_unchecked(&seq);
39607 }
39608 EXPORT_SYMBOL_GPL(cper_next_record_id);
39609
39610diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39611index 2e2fbde..7676c8b 100644
39612--- a/drivers/firmware/efi/efi.c
39613+++ b/drivers/firmware/efi/efi.c
39614@@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39615 };
39616
39617 static struct efivars generic_efivars;
39618-static struct efivar_operations generic_ops;
39619+static efivar_operations_no_const generic_ops __read_only;
39620
39621 static int generic_ops_register(void)
39622 {
39623- generic_ops.get_variable = efi.get_variable;
39624- generic_ops.set_variable = efi.set_variable;
39625- generic_ops.get_next_variable = efi.get_next_variable;
39626- generic_ops.query_variable_store = efi_query_variable_store;
39627+ pax_open_kernel();
39628+ *(void **)&generic_ops.get_variable = efi.get_variable;
39629+ *(void **)&generic_ops.set_variable = efi.set_variable;
39630+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39631+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39632+ pax_close_kernel();
39633
39634 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39635 }
39636diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39637index 3dc2482..7bd2f61 100644
39638--- a/drivers/firmware/efi/efivars.c
39639+++ b/drivers/firmware/efi/efivars.c
39640@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39641 static int
39642 create_efivars_bin_attributes(void)
39643 {
39644- struct bin_attribute *attr;
39645+ bin_attribute_no_const *attr;
39646 int error;
39647
39648 /* new_var */
39649diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39650index 2a90ba6..07f3733 100644
39651--- a/drivers/firmware/google/memconsole.c
39652+++ b/drivers/firmware/google/memconsole.c
39653@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39654 if (!found_memconsole())
39655 return -ENODEV;
39656
39657- memconsole_bin_attr.size = memconsole_length;
39658+ pax_open_kernel();
39659+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39660+ pax_close_kernel();
39661
39662 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39663
39664diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39665index ec19036..8ffafc2 100644
39666--- a/drivers/gpio/gpio-em.c
39667+++ b/drivers/gpio/gpio-em.c
39668@@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39669 struct em_gio_priv *p;
39670 struct resource *io[2], *irq[2];
39671 struct gpio_chip *gpio_chip;
39672- struct irq_chip *irq_chip;
39673+ irq_chip_no_const *irq_chip;
39674 const char *name = dev_name(&pdev->dev);
39675 int ret;
39676
39677diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39678index 814addb..0937d7f 100644
39679--- a/drivers/gpio/gpio-ich.c
39680+++ b/drivers/gpio/gpio-ich.c
39681@@ -71,7 +71,7 @@ struct ichx_desc {
39682 /* Some chipsets have quirks, let these use their own request/get */
39683 int (*request)(struct gpio_chip *chip, unsigned offset);
39684 int (*get)(struct gpio_chip *chip, unsigned offset);
39685-};
39686+} __do_const;
39687
39688 static struct {
39689 spinlock_t lock;
39690diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39691index 8b7e719..dc089dc 100644
39692--- a/drivers/gpio/gpio-rcar.c
39693+++ b/drivers/gpio/gpio-rcar.c
39694@@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39695 struct gpio_rcar_priv *p;
39696 struct resource *io, *irq;
39697 struct gpio_chip *gpio_chip;
39698- struct irq_chip *irq_chip;
39699+ irq_chip_no_const *irq_chip;
39700 const char *name = dev_name(&pdev->dev);
39701 int ret;
39702
39703diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39704index 9902732..64b62dd 100644
39705--- a/drivers/gpio/gpio-vr41xx.c
39706+++ b/drivers/gpio/gpio-vr41xx.c
39707@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39708 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39709 maskl, pendl, maskh, pendh);
39710
39711- atomic_inc(&irq_err_count);
39712+ atomic_inc_unchecked(&irq_err_count);
39713
39714 return -EINVAL;
39715 }
39716diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39717index d6cf77c..2842146 100644
39718--- a/drivers/gpu/drm/drm_crtc.c
39719+++ b/drivers/gpu/drm/drm_crtc.c
39720@@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39721 goto done;
39722 }
39723
39724- if (copy_to_user(&enum_ptr[copied].name,
39725+ if (copy_to_user(enum_ptr[copied].name,
39726 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39727 ret = -EFAULT;
39728 goto done;
39729diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39730index 01361ab..891e821 100644
39731--- a/drivers/gpu/drm/drm_crtc_helper.c
39732+++ b/drivers/gpu/drm/drm_crtc_helper.c
39733@@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39734 struct drm_crtc *tmp;
39735 int crtc_mask = 1;
39736
39737- WARN(!crtc, "checking null crtc?\n");
39738+ BUG_ON(!crtc);
39739
39740 dev = crtc->dev;
39741
39742diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39743index d9137e4..69b73a0 100644
39744--- a/drivers/gpu/drm/drm_drv.c
39745+++ b/drivers/gpu/drm/drm_drv.c
39746@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39747 /**
39748 * Copy and IOCTL return string to user space
39749 */
39750-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39751+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39752 {
39753 int len;
39754
39755@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39756 struct drm_file *file_priv = filp->private_data;
39757 struct drm_device *dev;
39758 const struct drm_ioctl_desc *ioctl = NULL;
39759- drm_ioctl_t *func;
39760+ drm_ioctl_no_const_t func;
39761 unsigned int nr = DRM_IOCTL_NR(cmd);
39762 int retcode = -EINVAL;
39763 char stack_kdata[128];
39764diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39765index c5b929c..8a3b8be 100644
39766--- a/drivers/gpu/drm/drm_fops.c
39767+++ b/drivers/gpu/drm/drm_fops.c
39768@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39769 if (drm_device_is_unplugged(dev))
39770 return -ENODEV;
39771
39772- if (!dev->open_count++)
39773+ if (local_inc_return(&dev->open_count) == 1)
39774 need_setup = 1;
39775 mutex_lock(&dev->struct_mutex);
39776 old_imapping = inode->i_mapping;
39777@@ -127,7 +127,7 @@ err_undo:
39778 iput(container_of(dev->dev_mapping, struct inode, i_data));
39779 dev->dev_mapping = old_mapping;
39780 mutex_unlock(&dev->struct_mutex);
39781- dev->open_count--;
39782+ local_dec(&dev->open_count);
39783 return retcode;
39784 }
39785 EXPORT_SYMBOL(drm_open);
39786@@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39787
39788 mutex_lock(&drm_global_mutex);
39789
39790- DRM_DEBUG("open_count = %d\n", dev->open_count);
39791+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39792
39793 if (dev->driver->preclose)
39794 dev->driver->preclose(dev, file_priv);
39795@@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39796 * Begin inline drm_release
39797 */
39798
39799- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39800+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39801 task_pid_nr(current),
39802 (long)old_encode_dev(file_priv->minor->device),
39803- dev->open_count);
39804+ local_read(&dev->open_count));
39805
39806 /* Release any auth tokens that might point to this file_priv,
39807 (do that under the drm_global_mutex) */
39808@@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39809 * End inline drm_release
39810 */
39811
39812- if (!--dev->open_count) {
39813+ if (local_dec_and_test(&dev->open_count)) {
39814 if (atomic_read(&dev->ioctl_count)) {
39815 DRM_ERROR("Device busy: %d\n",
39816 atomic_read(&dev->ioctl_count));
39817diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39818index 3d2e91c..d31c4c9 100644
39819--- a/drivers/gpu/drm/drm_global.c
39820+++ b/drivers/gpu/drm/drm_global.c
39821@@ -36,7 +36,7 @@
39822 struct drm_global_item {
39823 struct mutex mutex;
39824 void *object;
39825- int refcount;
39826+ atomic_t refcount;
39827 };
39828
39829 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39830@@ -49,7 +49,7 @@ void drm_global_init(void)
39831 struct drm_global_item *item = &glob[i];
39832 mutex_init(&item->mutex);
39833 item->object = NULL;
39834- item->refcount = 0;
39835+ atomic_set(&item->refcount, 0);
39836 }
39837 }
39838
39839@@ -59,7 +59,7 @@ void drm_global_release(void)
39840 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39841 struct drm_global_item *item = &glob[i];
39842 BUG_ON(item->object != NULL);
39843- BUG_ON(item->refcount != 0);
39844+ BUG_ON(atomic_read(&item->refcount) != 0);
39845 }
39846 }
39847
39848@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39849 struct drm_global_item *item = &glob[ref->global_type];
39850
39851 mutex_lock(&item->mutex);
39852- if (item->refcount == 0) {
39853+ if (atomic_read(&item->refcount) == 0) {
39854 item->object = kzalloc(ref->size, GFP_KERNEL);
39855 if (unlikely(item->object == NULL)) {
39856 ret = -ENOMEM;
39857@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39858 goto out_err;
39859
39860 }
39861- ++item->refcount;
39862+ atomic_inc(&item->refcount);
39863 ref->object = item->object;
39864 mutex_unlock(&item->mutex);
39865 return 0;
39866@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39867 struct drm_global_item *item = &glob[ref->global_type];
39868
39869 mutex_lock(&item->mutex);
39870- BUG_ON(item->refcount == 0);
39871+ BUG_ON(atomic_read(&item->refcount) == 0);
39872 BUG_ON(ref->object != item->object);
39873- if (--item->refcount == 0) {
39874+ if (atomic_dec_and_test(&item->refcount)) {
39875 ref->release(ref);
39876 item->object = NULL;
39877 }
39878diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39879index 7d5a152..d7186da 100644
39880--- a/drivers/gpu/drm/drm_info.c
39881+++ b/drivers/gpu/drm/drm_info.c
39882@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39883 struct drm_local_map *map;
39884 struct drm_map_list *r_list;
39885
39886- /* Hardcoded from _DRM_FRAME_BUFFER,
39887- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39888- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39889- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39890+ static const char * const types[] = {
39891+ [_DRM_FRAME_BUFFER] = "FB",
39892+ [_DRM_REGISTERS] = "REG",
39893+ [_DRM_SHM] = "SHM",
39894+ [_DRM_AGP] = "AGP",
39895+ [_DRM_SCATTER_GATHER] = "SG",
39896+ [_DRM_CONSISTENT] = "PCI",
39897+ [_DRM_GEM] = "GEM" };
39898 const char *type;
39899 int i;
39900
39901@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39902 map = r_list->map;
39903 if (!map)
39904 continue;
39905- if (map->type < 0 || map->type > 5)
39906+ if (map->type >= ARRAY_SIZE(types))
39907 type = "??";
39908 else
39909 type = types[map->type];
39910@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39911 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39912 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39913 vma->vm_flags & VM_IO ? 'i' : '-',
39914+#ifdef CONFIG_GRKERNSEC_HIDESYM
39915+ 0);
39916+#else
39917 vma->vm_pgoff);
39918+#endif
39919
39920 #if defined(__i386__)
39921 pgprot = pgprot_val(vma->vm_page_prot);
39922diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39923index 2f4c4343..dd12cd2 100644
39924--- a/drivers/gpu/drm/drm_ioc32.c
39925+++ b/drivers/gpu/drm/drm_ioc32.c
39926@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39927 request = compat_alloc_user_space(nbytes);
39928 if (!access_ok(VERIFY_WRITE, request, nbytes))
39929 return -EFAULT;
39930- list = (struct drm_buf_desc *) (request + 1);
39931+ list = (struct drm_buf_desc __user *) (request + 1);
39932
39933 if (__put_user(count, &request->count)
39934 || __put_user(list, &request->list))
39935@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39936 request = compat_alloc_user_space(nbytes);
39937 if (!access_ok(VERIFY_WRITE, request, nbytes))
39938 return -EFAULT;
39939- list = (struct drm_buf_pub *) (request + 1);
39940+ list = (struct drm_buf_pub __user *) (request + 1);
39941
39942 if (__put_user(count, &request->count)
39943 || __put_user(list, &request->list))
39944@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39945 return 0;
39946 }
39947
39948-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39949+drm_ioctl_compat_t drm_compat_ioctls[] = {
39950 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39951 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39952 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39953@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39954 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39955 {
39956 unsigned int nr = DRM_IOCTL_NR(cmd);
39957- drm_ioctl_compat_t *fn;
39958 int ret;
39959
39960 /* Assume that ioctls without an explicit compat routine will just
39961@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39962 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39963 return drm_ioctl(filp, cmd, arg);
39964
39965- fn = drm_compat_ioctls[nr];
39966-
39967- if (fn != NULL)
39968- ret = (*fn) (filp, cmd, arg);
39969+ if (drm_compat_ioctls[nr] != NULL)
39970+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39971 else
39972 ret = drm_ioctl(filp, cmd, arg);
39973
39974diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39975index 66dd3a0..3bed6c4 100644
39976--- a/drivers/gpu/drm/drm_stub.c
39977+++ b/drivers/gpu/drm/drm_stub.c
39978@@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39979
39980 drm_device_set_unplugged(dev);
39981
39982- if (dev->open_count == 0) {
39983+ if (local_read(&dev->open_count) == 0) {
39984 drm_put_dev(dev);
39985 }
39986 mutex_unlock(&drm_global_mutex);
39987diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39988index c22c309..ae758c3 100644
39989--- a/drivers/gpu/drm/drm_sysfs.c
39990+++ b/drivers/gpu/drm/drm_sysfs.c
39991@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39992 */
39993 int drm_sysfs_device_add(struct drm_minor *minor)
39994 {
39995- char *minor_str;
39996+ const char *minor_str;
39997 int r;
39998
39999 if (minor->type == DRM_MINOR_CONTROL)
40000diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40001index d4d16ed..8fb0b51 100644
40002--- a/drivers/gpu/drm/i810/i810_drv.h
40003+++ b/drivers/gpu/drm/i810/i810_drv.h
40004@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40005 int page_flipping;
40006
40007 wait_queue_head_t irq_queue;
40008- atomic_t irq_received;
40009- atomic_t irq_emitted;
40010+ atomic_unchecked_t irq_received;
40011+ atomic_unchecked_t irq_emitted;
40012
40013 int front_offset;
40014 } drm_i810_private_t;
40015diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40016index 6ed45a9..eb6dc41 100644
40017--- a/drivers/gpu/drm/i915/i915_debugfs.c
40018+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40019@@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40020 I915_READ(GTIMR));
40021 }
40022 seq_printf(m, "Interrupts received: %d\n",
40023- atomic_read(&dev_priv->irq_received));
40024+ atomic_read_unchecked(&dev_priv->irq_received));
40025 for_each_ring(ring, dev_priv, i) {
40026 if (INTEL_INFO(dev)->gen >= 6) {
40027 seq_printf(m,
40028diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40029index e02266a..e3411aa 100644
40030--- a/drivers/gpu/drm/i915/i915_dma.c
40031+++ b/drivers/gpu/drm/i915/i915_dma.c
40032@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40033 bool can_switch;
40034
40035 spin_lock(&dev->count_lock);
40036- can_switch = (dev->open_count == 0);
40037+ can_switch = (local_read(&dev->open_count) == 0);
40038 spin_unlock(&dev->count_lock);
40039 return can_switch;
40040 }
40041diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40042index 221ac62..f56acc8 100644
40043--- a/drivers/gpu/drm/i915/i915_drv.h
40044+++ b/drivers/gpu/drm/i915/i915_drv.h
40045@@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40046 drm_dma_handle_t *status_page_dmah;
40047 struct resource mch_res;
40048
40049- atomic_t irq_received;
40050+ atomic_unchecked_t irq_received;
40051
40052 /* protects the irq masks */
40053 spinlock_t irq_lock;
40054diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40055index a3ba9a8..ee52ddd 100644
40056--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40057+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40058@@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40059
40060 static int
40061 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40062- int count)
40063+ unsigned int count)
40064 {
40065- int i;
40066+ unsigned int i;
40067 unsigned relocs_total = 0;
40068 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40069
40070diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c
40071index d3c3b5b..e79720d 100644
40072--- a/drivers/gpu/drm/i915/i915_gem_gtt.c
40073+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c
40074@@ -828,7 +828,7 @@ void i915_gem_suspend_gtt_mappings(struct drm_device *dev)
40075 dev_priv->gtt.base.clear_range(&dev_priv->gtt.base,
40076 dev_priv->gtt.base.start / PAGE_SIZE,
40077 dev_priv->gtt.base.total / PAGE_SIZE,
40078- false);
40079+ true);
40080 }
40081
40082 void i915_gem_restore_gtt_mappings(struct drm_device *dev)
40083diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40084index 3c59584..500f2e9 100644
40085--- a/drivers/gpu/drm/i915/i915_ioc32.c
40086+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40087@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40088 (unsigned long)request);
40089 }
40090
40091-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40092+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40093 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40094 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40095 [DRM_I915_GETPARAM] = compat_i915_getparam,
40096@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40097 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40098 {
40099 unsigned int nr = DRM_IOCTL_NR(cmd);
40100- drm_ioctl_compat_t *fn = NULL;
40101 int ret;
40102
40103 if (nr < DRM_COMMAND_BASE)
40104 return drm_compat_ioctl(filp, cmd, arg);
40105
40106- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40107- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40108-
40109- if (fn != NULL)
40110+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40111+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40112 ret = (*fn) (filp, cmd, arg);
40113- else
40114+ } else
40115 ret = drm_ioctl(filp, cmd, arg);
40116
40117 return ret;
40118diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40119index 9702704..3fb9e40 100644
40120--- a/drivers/gpu/drm/i915/i915_irq.c
40121+++ b/drivers/gpu/drm/i915/i915_irq.c
40122@@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40123 int pipe;
40124 u32 pipe_stats[I915_MAX_PIPES];
40125
40126- atomic_inc(&dev_priv->irq_received);
40127+ atomic_inc_unchecked(&dev_priv->irq_received);
40128
40129 while (true) {
40130 iir = I915_READ(VLV_IIR);
40131@@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40132 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40133 irqreturn_t ret = IRQ_NONE;
40134
40135- atomic_inc(&dev_priv->irq_received);
40136+ atomic_inc_unchecked(&dev_priv->irq_received);
40137
40138 /* We get interrupts on unclaimed registers, so check for this before we
40139 * do any I915_{READ,WRITE}. */
40140@@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40141 uint32_t tmp = 0;
40142 enum pipe pipe;
40143
40144- atomic_inc(&dev_priv->irq_received);
40145+ atomic_inc_unchecked(&dev_priv->irq_received);
40146
40147 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40148 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40149@@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40150 {
40151 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40152
40153- atomic_set(&dev_priv->irq_received, 0);
40154+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40155
40156 I915_WRITE(HWSTAM, 0xeffe);
40157
40158@@ -2641,7 +2641,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40159 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40160 int pipe;
40161
40162- atomic_set(&dev_priv->irq_received, 0);
40163+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40164
40165 /* VLV magic */
40166 I915_WRITE(VLV_IMR, 0);
40167@@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40168 struct drm_i915_private *dev_priv = dev->dev_private;
40169 int pipe;
40170
40171- atomic_set(&dev_priv->irq_received, 0);
40172+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40173
40174 I915_WRITE(GEN8_MASTER_IRQ, 0);
40175 POSTING_READ(GEN8_MASTER_IRQ);
40176@@ -2996,7 +2996,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40177 if (!dev_priv)
40178 return;
40179
40180- atomic_set(&dev_priv->irq_received, 0);
40181+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40182
40183 I915_WRITE(GEN8_MASTER_IRQ, 0);
40184
40185@@ -3090,7 +3090,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40186 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40187 int pipe;
40188
40189- atomic_set(&dev_priv->irq_received, 0);
40190+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40191
40192 for_each_pipe(pipe)
40193 I915_WRITE(PIPESTAT(pipe), 0);
40194@@ -3176,7 +3176,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40195 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40196 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40197
40198- atomic_inc(&dev_priv->irq_received);
40199+ atomic_inc_unchecked(&dev_priv->irq_received);
40200
40201 iir = I915_READ16(IIR);
40202 if (iir == 0)
40203@@ -3251,7 +3251,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
40204 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40205 int pipe;
40206
40207- atomic_set(&dev_priv->irq_received, 0);
40208+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40209
40210 if (I915_HAS_HOTPLUG(dev)) {
40211 I915_WRITE(PORT_HOTPLUG_EN, 0);
40212@@ -3358,7 +3358,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40213 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40214 int pipe, ret = IRQ_NONE;
40215
40216- atomic_inc(&dev_priv->irq_received);
40217+ atomic_inc_unchecked(&dev_priv->irq_received);
40218
40219 iir = I915_READ(IIR);
40220 do {
40221@@ -3485,7 +3485,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
40222 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40223 int pipe;
40224
40225- atomic_set(&dev_priv->irq_received, 0);
40226+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40227
40228 I915_WRITE(PORT_HOTPLUG_EN, 0);
40229 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40230@@ -3601,7 +3601,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40231 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40232 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40233
40234- atomic_inc(&dev_priv->irq_received);
40235+ atomic_inc_unchecked(&dev_priv->irq_received);
40236
40237 iir = I915_READ(IIR);
40238
40239diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40240index 3c5ff7a..ae759ca 100644
40241--- a/drivers/gpu/drm/i915/intel_display.c
40242+++ b/drivers/gpu/drm/i915/intel_display.c
40243@@ -10506,13 +10506,13 @@ struct intel_quirk {
40244 int subsystem_vendor;
40245 int subsystem_device;
40246 void (*hook)(struct drm_device *dev);
40247-};
40248+} __do_const;
40249
40250 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40251 struct intel_dmi_quirk {
40252 void (*hook)(struct drm_device *dev);
40253 const struct dmi_system_id (*dmi_id_list)[];
40254-};
40255+} __do_const;
40256
40257 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40258 {
40259@@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40260 return 1;
40261 }
40262
40263-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40264+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40265 {
40266- .dmi_id_list = &(const struct dmi_system_id[]) {
40267- {
40268- .callback = intel_dmi_reverse_brightness,
40269- .ident = "NCR Corporation",
40270- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40271- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40272- },
40273- },
40274- { } /* terminating entry */
40275+ .callback = intel_dmi_reverse_brightness,
40276+ .ident = "NCR Corporation",
40277+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40278+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40279 },
40280+ },
40281+ { } /* terminating entry */
40282+};
40283+
40284+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40285+ {
40286+ .dmi_id_list = &intel_dmi_quirks_table,
40287 .hook = quirk_invert_brightness,
40288 },
40289 };
40290diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40291index ca4bc54..ee598a2 100644
40292--- a/drivers/gpu/drm/mga/mga_drv.h
40293+++ b/drivers/gpu/drm/mga/mga_drv.h
40294@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40295 u32 clear_cmd;
40296 u32 maccess;
40297
40298- atomic_t vbl_received; /**< Number of vblanks received. */
40299+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40300 wait_queue_head_t fence_queue;
40301- atomic_t last_fence_retired;
40302+ atomic_unchecked_t last_fence_retired;
40303 u32 next_fence_to_post;
40304
40305 unsigned int fb_cpp;
40306diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40307index 709e90d..89a1c0d 100644
40308--- a/drivers/gpu/drm/mga/mga_ioc32.c
40309+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40310@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40311 return 0;
40312 }
40313
40314-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40315+drm_ioctl_compat_t mga_compat_ioctls[] = {
40316 [DRM_MGA_INIT] = compat_mga_init,
40317 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40318 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40319@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40320 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40321 {
40322 unsigned int nr = DRM_IOCTL_NR(cmd);
40323- drm_ioctl_compat_t *fn = NULL;
40324 int ret;
40325
40326 if (nr < DRM_COMMAND_BASE)
40327 return drm_compat_ioctl(filp, cmd, arg);
40328
40329- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40330- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40331-
40332- if (fn != NULL)
40333+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40334+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40335 ret = (*fn) (filp, cmd, arg);
40336- else
40337+ } else
40338 ret = drm_ioctl(filp, cmd, arg);
40339
40340 return ret;
40341diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40342index 2b0ceb8..517e99e 100644
40343--- a/drivers/gpu/drm/mga/mga_irq.c
40344+++ b/drivers/gpu/drm/mga/mga_irq.c
40345@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40346 if (crtc != 0)
40347 return 0;
40348
40349- return atomic_read(&dev_priv->vbl_received);
40350+ return atomic_read_unchecked(&dev_priv->vbl_received);
40351 }
40352
40353
40354@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40355 /* VBLANK interrupt */
40356 if (status & MGA_VLINEPEN) {
40357 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40358- atomic_inc(&dev_priv->vbl_received);
40359+ atomic_inc_unchecked(&dev_priv->vbl_received);
40360 drm_handle_vblank(dev, 0);
40361 handled = 1;
40362 }
40363@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40364 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40365 MGA_WRITE(MGA_PRIMEND, prim_end);
40366
40367- atomic_inc(&dev_priv->last_fence_retired);
40368+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40369 DRM_WAKEUP(&dev_priv->fence_queue);
40370 handled = 1;
40371 }
40372@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40373 * using fences.
40374 */
40375 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40376- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40377+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40378 - *sequence) <= (1 << 23)));
40379
40380 *sequence = cur_fence;
40381diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40382index 4c3feaa..26391ce 100644
40383--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40384+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40385@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40386 struct bit_table {
40387 const char id;
40388 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40389-};
40390+} __no_const;
40391
40392 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40393
40394diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40395index 4b0fb6c..67667a9 100644
40396--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40397+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40398@@ -96,7 +96,6 @@ struct nouveau_drm {
40399 struct drm_global_reference mem_global_ref;
40400 struct ttm_bo_global_ref bo_global_ref;
40401 struct ttm_bo_device bdev;
40402- atomic_t validate_sequence;
40403 int (*move)(struct nouveau_channel *,
40404 struct ttm_buffer_object *,
40405 struct ttm_mem_reg *, struct ttm_mem_reg *);
40406diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40407index c1a7e5a..38b8539 100644
40408--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40409+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40410@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40411 unsigned long arg)
40412 {
40413 unsigned int nr = DRM_IOCTL_NR(cmd);
40414- drm_ioctl_compat_t *fn = NULL;
40415+ drm_ioctl_compat_t fn = NULL;
40416 int ret;
40417
40418 if (nr < DRM_COMMAND_BASE)
40419diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40420index 19e3757..ad16478 100644
40421--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40422+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40423@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40424 }
40425
40426 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40427- nouveau_vram_manager_init,
40428- nouveau_vram_manager_fini,
40429- nouveau_vram_manager_new,
40430- nouveau_vram_manager_del,
40431- nouveau_vram_manager_debug
40432+ .init = nouveau_vram_manager_init,
40433+ .takedown = nouveau_vram_manager_fini,
40434+ .get_node = nouveau_vram_manager_new,
40435+ .put_node = nouveau_vram_manager_del,
40436+ .debug = nouveau_vram_manager_debug
40437 };
40438
40439 static int
40440@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40441 }
40442
40443 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40444- nouveau_gart_manager_init,
40445- nouveau_gart_manager_fini,
40446- nouveau_gart_manager_new,
40447- nouveau_gart_manager_del,
40448- nouveau_gart_manager_debug
40449+ .init = nouveau_gart_manager_init,
40450+ .takedown = nouveau_gart_manager_fini,
40451+ .get_node = nouveau_gart_manager_new,
40452+ .put_node = nouveau_gart_manager_del,
40453+ .debug = nouveau_gart_manager_debug
40454 };
40455
40456 #include <core/subdev/vm/nv04.h>
40457@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40458 }
40459
40460 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40461- nv04_gart_manager_init,
40462- nv04_gart_manager_fini,
40463- nv04_gart_manager_new,
40464- nv04_gart_manager_del,
40465- nv04_gart_manager_debug
40466+ .init = nv04_gart_manager_init,
40467+ .takedown = nv04_gart_manager_fini,
40468+ .get_node = nv04_gart_manager_new,
40469+ .put_node = nv04_gart_manager_del,
40470+ .debug = nv04_gart_manager_debug
40471 };
40472
40473 int
40474diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40475index 81638d7..2e45854 100644
40476--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40477+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40478@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40479 bool can_switch;
40480
40481 spin_lock(&dev->count_lock);
40482- can_switch = (dev->open_count == 0);
40483+ can_switch = (local_read(&dev->open_count) == 0);
40484 spin_unlock(&dev->count_lock);
40485 return can_switch;
40486 }
40487diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40488index eb89653..613cf71 100644
40489--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40490+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40491@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40492 int ret;
40493
40494 mutex_lock(&qdev->async_io_mutex);
40495- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40496+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40497 if (qdev->last_sent_io_cmd > irq_num) {
40498 if (intr)
40499 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40500- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40501+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40502 else
40503 ret = wait_event_timeout(qdev->io_cmd_event,
40504- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40505+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40506 /* 0 is timeout, just bail the "hw" has gone away */
40507 if (ret <= 0)
40508 goto out;
40509- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40510+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40511 }
40512 outb(val, addr);
40513 qdev->last_sent_io_cmd = irq_num + 1;
40514 if (intr)
40515 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40516- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40517+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40518 else
40519 ret = wait_event_timeout(qdev->io_cmd_event,
40520- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40521+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40522 out:
40523 if (ret > 0)
40524 ret = 0;
40525diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40526index c3c2bbd..bc3c0fb 100644
40527--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40528+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40529@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40530 struct drm_info_node *node = (struct drm_info_node *) m->private;
40531 struct qxl_device *qdev = node->minor->dev->dev_private;
40532
40533- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40534- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40535- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40536- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40537+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40538+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40539+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40540+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40541 seq_printf(m, "%d\n", qdev->irq_received_error);
40542 return 0;
40543 }
40544diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40545index 7bda32f..dd98fc5 100644
40546--- a/drivers/gpu/drm/qxl/qxl_drv.h
40547+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40548@@ -290,10 +290,10 @@ struct qxl_device {
40549 unsigned int last_sent_io_cmd;
40550
40551 /* interrupt handling */
40552- atomic_t irq_received;
40553- atomic_t irq_received_display;
40554- atomic_t irq_received_cursor;
40555- atomic_t irq_received_io_cmd;
40556+ atomic_unchecked_t irq_received;
40557+ atomic_unchecked_t irq_received_display;
40558+ atomic_unchecked_t irq_received_cursor;
40559+ atomic_unchecked_t irq_received_io_cmd;
40560 unsigned irq_received_error;
40561 wait_queue_head_t display_event;
40562 wait_queue_head_t cursor_event;
40563diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40564index 7b95c75..9cffb4f 100644
40565--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40566+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40567@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40568
40569 /* TODO copy slow path code from i915 */
40570 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40571- 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);
40572+ 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);
40573
40574 {
40575 struct qxl_drawable *draw = fb_cmd;
40576@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40577 struct drm_qxl_reloc reloc;
40578
40579 if (DRM_COPY_FROM_USER(&reloc,
40580- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40581+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40582 sizeof(reloc))) {
40583 ret = -EFAULT;
40584 goto out_free_bos;
40585@@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40586 struct drm_qxl_command *commands =
40587 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40588
40589- if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40590+ if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40591 sizeof(user_cmd)))
40592 return -EFAULT;
40593
40594diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40595index 21393dc..329f3a9 100644
40596--- a/drivers/gpu/drm/qxl/qxl_irq.c
40597+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40598@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40599
40600 pending = xchg(&qdev->ram_header->int_pending, 0);
40601
40602- atomic_inc(&qdev->irq_received);
40603+ atomic_inc_unchecked(&qdev->irq_received);
40604
40605 if (pending & QXL_INTERRUPT_DISPLAY) {
40606- atomic_inc(&qdev->irq_received_display);
40607+ atomic_inc_unchecked(&qdev->irq_received_display);
40608 wake_up_all(&qdev->display_event);
40609 qxl_queue_garbage_collect(qdev, false);
40610 }
40611 if (pending & QXL_INTERRUPT_CURSOR) {
40612- atomic_inc(&qdev->irq_received_cursor);
40613+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40614 wake_up_all(&qdev->cursor_event);
40615 }
40616 if (pending & QXL_INTERRUPT_IO_CMD) {
40617- atomic_inc(&qdev->irq_received_io_cmd);
40618+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40619 wake_up_all(&qdev->io_cmd_event);
40620 }
40621 if (pending & QXL_INTERRUPT_ERROR) {
40622@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40623 init_waitqueue_head(&qdev->io_cmd_event);
40624 INIT_WORK(&qdev->client_monitors_config_work,
40625 qxl_client_monitors_config_work_func);
40626- atomic_set(&qdev->irq_received, 0);
40627- atomic_set(&qdev->irq_received_display, 0);
40628- atomic_set(&qdev->irq_received_cursor, 0);
40629- atomic_set(&qdev->irq_received_io_cmd, 0);
40630+ atomic_set_unchecked(&qdev->irq_received, 0);
40631+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40632+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40633+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40634 qdev->irq_received_error = 0;
40635 ret = drm_irq_install(qdev->ddev);
40636 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40637diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40638index c7e7e65..7dddd4d 100644
40639--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40640+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40641@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40642 }
40643 }
40644
40645-static struct vm_operations_struct qxl_ttm_vm_ops;
40646+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40647 static const struct vm_operations_struct *ttm_vm_ops;
40648
40649 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40650@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40651 return r;
40652 if (unlikely(ttm_vm_ops == NULL)) {
40653 ttm_vm_ops = vma->vm_ops;
40654+ pax_open_kernel();
40655 qxl_ttm_vm_ops = *ttm_vm_ops;
40656 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40657+ pax_close_kernel();
40658 }
40659 vma->vm_ops = &qxl_ttm_vm_ops;
40660 return 0;
40661@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40662 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40663 {
40664 #if defined(CONFIG_DEBUG_FS)
40665- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40666- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40667- unsigned i;
40668+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40669+ {
40670+ .name = "qxl_mem_mm",
40671+ .show = &qxl_mm_dump_table,
40672+ },
40673+ {
40674+ .name = "qxl_surf_mm",
40675+ .show = &qxl_mm_dump_table,
40676+ }
40677+ };
40678
40679- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40680- if (i == 0)
40681- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40682- else
40683- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40684- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40685- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40686- qxl_mem_types_list[i].driver_features = 0;
40687- if (i == 0)
40688- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40689- else
40690- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40691+ pax_open_kernel();
40692+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40693+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40694+ pax_close_kernel();
40695
40696- }
40697- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40698+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40699 #else
40700 return 0;
40701 #endif
40702diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40703index c451257..0ad2134 100644
40704--- a/drivers/gpu/drm/r128/r128_cce.c
40705+++ b/drivers/gpu/drm/r128/r128_cce.c
40706@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40707
40708 /* GH: Simple idle check.
40709 */
40710- atomic_set(&dev_priv->idle_count, 0);
40711+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40712
40713 /* We don't support anything other than bus-mastering ring mode,
40714 * but the ring can be in either AGP or PCI space for the ring
40715diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40716index 56eb5e3..c4ec43d 100644
40717--- a/drivers/gpu/drm/r128/r128_drv.h
40718+++ b/drivers/gpu/drm/r128/r128_drv.h
40719@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40720 int is_pci;
40721 unsigned long cce_buffers_offset;
40722
40723- atomic_t idle_count;
40724+ atomic_unchecked_t idle_count;
40725
40726 int page_flipping;
40727 int current_page;
40728 u32 crtc_offset;
40729 u32 crtc_offset_cntl;
40730
40731- atomic_t vbl_received;
40732+ atomic_unchecked_t vbl_received;
40733
40734 u32 color_fmt;
40735 unsigned int front_offset;
40736diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40737index a954c54..9cc595c 100644
40738--- a/drivers/gpu/drm/r128/r128_ioc32.c
40739+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40740@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40741 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40742 }
40743
40744-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40745+drm_ioctl_compat_t r128_compat_ioctls[] = {
40746 [DRM_R128_INIT] = compat_r128_init,
40747 [DRM_R128_DEPTH] = compat_r128_depth,
40748 [DRM_R128_STIPPLE] = compat_r128_stipple,
40749@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40750 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40751 {
40752 unsigned int nr = DRM_IOCTL_NR(cmd);
40753- drm_ioctl_compat_t *fn = NULL;
40754 int ret;
40755
40756 if (nr < DRM_COMMAND_BASE)
40757 return drm_compat_ioctl(filp, cmd, arg);
40758
40759- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40760- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40761-
40762- if (fn != NULL)
40763+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40764+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40765 ret = (*fn) (filp, cmd, arg);
40766- else
40767+ } else
40768 ret = drm_ioctl(filp, cmd, arg);
40769
40770 return ret;
40771diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40772index 2ea4f09..d391371 100644
40773--- a/drivers/gpu/drm/r128/r128_irq.c
40774+++ b/drivers/gpu/drm/r128/r128_irq.c
40775@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40776 if (crtc != 0)
40777 return 0;
40778
40779- return atomic_read(&dev_priv->vbl_received);
40780+ return atomic_read_unchecked(&dev_priv->vbl_received);
40781 }
40782
40783 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40784@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40785 /* VBLANK interrupt */
40786 if (status & R128_CRTC_VBLANK_INT) {
40787 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40788- atomic_inc(&dev_priv->vbl_received);
40789+ atomic_inc_unchecked(&dev_priv->vbl_received);
40790 drm_handle_vblank(dev, 0);
40791 return IRQ_HANDLED;
40792 }
40793diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40794index 01dd9ae..6352f04 100644
40795--- a/drivers/gpu/drm/r128/r128_state.c
40796+++ b/drivers/gpu/drm/r128/r128_state.c
40797@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40798
40799 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40800 {
40801- if (atomic_read(&dev_priv->idle_count) == 0)
40802+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40803 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40804 else
40805- atomic_set(&dev_priv->idle_count, 0);
40806+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40807 }
40808
40809 #endif
40810diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40811index af85299..ed9ac8d 100644
40812--- a/drivers/gpu/drm/radeon/mkregtable.c
40813+++ b/drivers/gpu/drm/radeon/mkregtable.c
40814@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40815 regex_t mask_rex;
40816 regmatch_t match[4];
40817 char buf[1024];
40818- size_t end;
40819+ long end;
40820 int len;
40821 int done = 0;
40822 int r;
40823 unsigned o;
40824 struct offset *offset;
40825 char last_reg_s[10];
40826- int last_reg;
40827+ unsigned long last_reg;
40828
40829 if (regcomp
40830 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40831diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40832index 39b033b..6efc056 100644
40833--- a/drivers/gpu/drm/radeon/radeon_device.c
40834+++ b/drivers/gpu/drm/radeon/radeon_device.c
40835@@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40836 bool can_switch;
40837
40838 spin_lock(&dev->count_lock);
40839- can_switch = (dev->open_count == 0);
40840+ can_switch = (local_read(&dev->open_count) == 0);
40841 spin_unlock(&dev->count_lock);
40842 return can_switch;
40843 }
40844diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40845index 00e0d44..08381a4 100644
40846--- a/drivers/gpu/drm/radeon/radeon_drv.h
40847+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40848@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40849
40850 /* SW interrupt */
40851 wait_queue_head_t swi_queue;
40852- atomic_t swi_emitted;
40853+ atomic_unchecked_t swi_emitted;
40854 int vblank_crtc;
40855 uint32_t irq_enable_reg;
40856 uint32_t r500_disp_irq_reg;
40857diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40858index bdb0f93..5ff558f 100644
40859--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40860+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40861@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40862 request = compat_alloc_user_space(sizeof(*request));
40863 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40864 || __put_user(req32.param, &request->param)
40865- || __put_user((void __user *)(unsigned long)req32.value,
40866+ || __put_user((unsigned long)req32.value,
40867 &request->value))
40868 return -EFAULT;
40869
40870@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40871 #define compat_radeon_cp_setparam NULL
40872 #endif /* X86_64 || IA64 */
40873
40874-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40875+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40876 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40877 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40878 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40879@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40880 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40881 {
40882 unsigned int nr = DRM_IOCTL_NR(cmd);
40883- drm_ioctl_compat_t *fn = NULL;
40884 int ret;
40885
40886 if (nr < DRM_COMMAND_BASE)
40887 return drm_compat_ioctl(filp, cmd, arg);
40888
40889- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40890- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40891-
40892- if (fn != NULL)
40893+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40894+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40895 ret = (*fn) (filp, cmd, arg);
40896- else
40897+ } else
40898 ret = drm_ioctl(filp, cmd, arg);
40899
40900 return ret;
40901diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40902index 8d68e97..9dcfed8 100644
40903--- a/drivers/gpu/drm/radeon/radeon_irq.c
40904+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40905@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40906 unsigned int ret;
40907 RING_LOCALS;
40908
40909- atomic_inc(&dev_priv->swi_emitted);
40910- ret = atomic_read(&dev_priv->swi_emitted);
40911+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40912+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40913
40914 BEGIN_RING(4);
40915 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40916@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40917 drm_radeon_private_t *dev_priv =
40918 (drm_radeon_private_t *) dev->dev_private;
40919
40920- atomic_set(&dev_priv->swi_emitted, 0);
40921+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40922 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40923
40924 dev->max_vblank_count = 0x001fffff;
40925diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40926index 4d20910..6726b6d 100644
40927--- a/drivers/gpu/drm/radeon/radeon_state.c
40928+++ b/drivers/gpu/drm/radeon/radeon_state.c
40929@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40930 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40931 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40932
40933- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40934+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40935 sarea_priv->nbox * sizeof(depth_boxes[0])))
40936 return -EFAULT;
40937
40938@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40939 {
40940 drm_radeon_private_t *dev_priv = dev->dev_private;
40941 drm_radeon_getparam_t *param = data;
40942- int value;
40943+ int value = 0;
40944
40945 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40946
40947diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40948index 84323c9..cf07baf 100644
40949--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40950+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40951@@ -787,7 +787,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40952 man->size = size >> PAGE_SHIFT;
40953 }
40954
40955-static struct vm_operations_struct radeon_ttm_vm_ops;
40956+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40957 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40958
40959 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40960@@ -828,8 +828,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40961 }
40962 if (unlikely(ttm_vm_ops == NULL)) {
40963 ttm_vm_ops = vma->vm_ops;
40964+ pax_open_kernel();
40965 radeon_ttm_vm_ops = *ttm_vm_ops;
40966 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40967+ pax_close_kernel();
40968 }
40969 vma->vm_ops = &radeon_ttm_vm_ops;
40970 return 0;
40971@@ -858,38 +860,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40972 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40973 {
40974 #if defined(CONFIG_DEBUG_FS)
40975- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40976- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40977- unsigned i;
40978+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40979+ {
40980+ .name = "radeon_vram_mm",
40981+ .show = &radeon_mm_dump_table,
40982+ },
40983+ {
40984+ .name = "radeon_gtt_mm",
40985+ .show = &radeon_mm_dump_table,
40986+ },
40987+ {
40988+ .name = "ttm_page_pool",
40989+ .show = &ttm_page_alloc_debugfs,
40990+ },
40991+ {
40992+ .name = "ttm_dma_page_pool",
40993+ .show = &ttm_dma_page_alloc_debugfs,
40994+ },
40995+ };
40996+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40997
40998- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40999- if (i == 0)
41000- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
41001- else
41002- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
41003- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41004- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
41005- radeon_mem_types_list[i].driver_features = 0;
41006- if (i == 0)
41007- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
41008- else
41009- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41010-
41011- }
41012- /* Add ttm page pool to debugfs */
41013- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
41014- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41015- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
41016- radeon_mem_types_list[i].driver_features = 0;
41017- radeon_mem_types_list[i++].data = NULL;
41018+ pax_open_kernel();
41019+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
41020+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41021+ pax_close_kernel();
41022 #ifdef CONFIG_SWIOTLB
41023- if (swiotlb_nr_tbl()) {
41024- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41025- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41026- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41027- radeon_mem_types_list[i].driver_features = 0;
41028- radeon_mem_types_list[i++].data = NULL;
41029- }
41030+ if (swiotlb_nr_tbl())
41031+ i++;
41032 #endif
41033 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41034
41035diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41036index ae1cb31..5b5b6b7c 100644
41037--- a/drivers/gpu/drm/tegra/dc.c
41038+++ b/drivers/gpu/drm/tegra/dc.c
41039@@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41040 }
41041
41042 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41043- dc->debugfs_files[i].data = dc;
41044+ *(void **)&dc->debugfs_files[i].data = dc;
41045
41046 err = drm_debugfs_create_files(dc->debugfs_files,
41047 ARRAY_SIZE(debugfs_files),
41048diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41049index 0cd9bc2..9759be4 100644
41050--- a/drivers/gpu/drm/tegra/hdmi.c
41051+++ b/drivers/gpu/drm/tegra/hdmi.c
41052@@ -57,7 +57,7 @@ struct tegra_hdmi {
41053 bool stereo;
41054 bool dvi;
41055
41056- struct drm_info_list *debugfs_files;
41057+ drm_info_list_no_const *debugfs_files;
41058 struct drm_minor *minor;
41059 struct dentry *debugfs;
41060 };
41061diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41062index c58eba33..83c2728 100644
41063--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41064+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41065@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41066 }
41067
41068 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41069- ttm_bo_man_init,
41070- ttm_bo_man_takedown,
41071- ttm_bo_man_get_node,
41072- ttm_bo_man_put_node,
41073- ttm_bo_man_debug
41074+ .init = ttm_bo_man_init,
41075+ .takedown = ttm_bo_man_takedown,
41076+ .get_node = ttm_bo_man_get_node,
41077+ .put_node = ttm_bo_man_put_node,
41078+ .debug = ttm_bo_man_debug
41079 };
41080 EXPORT_SYMBOL(ttm_bo_manager_func);
41081diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41082index dbc2def..0a9f710 100644
41083--- a/drivers/gpu/drm/ttm/ttm_memory.c
41084+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41085@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41086 zone->glob = glob;
41087 glob->zone_kernel = zone;
41088 ret = kobject_init_and_add(
41089- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41090+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41091 if (unlikely(ret != 0)) {
41092 kobject_put(&zone->kobj);
41093 return ret;
41094@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41095 zone->glob = glob;
41096 glob->zone_dma32 = zone;
41097 ret = kobject_init_and_add(
41098- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41099+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41100 if (unlikely(ret != 0)) {
41101 kobject_put(&zone->kobj);
41102 return ret;
41103diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41104index 863bef9..cba15cf 100644
41105--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41106+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41107@@ -391,9 +391,9 @@ out:
41108 static unsigned long
41109 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41110 {
41111- static atomic_t start_pool = ATOMIC_INIT(0);
41112+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41113 unsigned i;
41114- unsigned pool_offset = atomic_add_return(1, &start_pool);
41115+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41116 struct ttm_page_pool *pool;
41117 int shrink_pages = sc->nr_to_scan;
41118 unsigned long freed = 0;
41119diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41120index 97e9d61..bf23c461 100644
41121--- a/drivers/gpu/drm/udl/udl_fb.c
41122+++ b/drivers/gpu/drm/udl/udl_fb.c
41123@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41124 fb_deferred_io_cleanup(info);
41125 kfree(info->fbdefio);
41126 info->fbdefio = NULL;
41127- info->fbops->fb_mmap = udl_fb_mmap;
41128 }
41129
41130 pr_warn("released /dev/fb%d user=%d count=%d\n",
41131diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41132index a811ef2..ff99b05 100644
41133--- a/drivers/gpu/drm/via/via_drv.h
41134+++ b/drivers/gpu/drm/via/via_drv.h
41135@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41136 typedef uint32_t maskarray_t[5];
41137
41138 typedef struct drm_via_irq {
41139- atomic_t irq_received;
41140+ atomic_unchecked_t irq_received;
41141 uint32_t pending_mask;
41142 uint32_t enable_mask;
41143 wait_queue_head_t irq_queue;
41144@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41145 struct timeval last_vblank;
41146 int last_vblank_valid;
41147 unsigned usec_per_vblank;
41148- atomic_t vbl_received;
41149+ atomic_unchecked_t vbl_received;
41150 drm_via_state_t hc_state;
41151 char pci_buf[VIA_PCI_BUF_SIZE];
41152 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41153diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41154index ac98964..5dbf512 100644
41155--- a/drivers/gpu/drm/via/via_irq.c
41156+++ b/drivers/gpu/drm/via/via_irq.c
41157@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41158 if (crtc != 0)
41159 return 0;
41160
41161- return atomic_read(&dev_priv->vbl_received);
41162+ return atomic_read_unchecked(&dev_priv->vbl_received);
41163 }
41164
41165 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41166@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41167
41168 status = VIA_READ(VIA_REG_INTERRUPT);
41169 if (status & VIA_IRQ_VBLANK_PENDING) {
41170- atomic_inc(&dev_priv->vbl_received);
41171- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41172+ atomic_inc_unchecked(&dev_priv->vbl_received);
41173+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41174 do_gettimeofday(&cur_vblank);
41175 if (dev_priv->last_vblank_valid) {
41176 dev_priv->usec_per_vblank =
41177@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41178 dev_priv->last_vblank = cur_vblank;
41179 dev_priv->last_vblank_valid = 1;
41180 }
41181- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41182+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41183 DRM_DEBUG("US per vblank is: %u\n",
41184 dev_priv->usec_per_vblank);
41185 }
41186@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41187
41188 for (i = 0; i < dev_priv->num_irqs; ++i) {
41189 if (status & cur_irq->pending_mask) {
41190- atomic_inc(&cur_irq->irq_received);
41191+ atomic_inc_unchecked(&cur_irq->irq_received);
41192 DRM_WAKEUP(&cur_irq->irq_queue);
41193 handled = 1;
41194 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41195@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41196 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41197 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41198 masks[irq][4]));
41199- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41200+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41201 } else {
41202 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41203 (((cur_irq_sequence =
41204- atomic_read(&cur_irq->irq_received)) -
41205+ atomic_read_unchecked(&cur_irq->irq_received)) -
41206 *sequence) <= (1 << 23)));
41207 }
41208 *sequence = cur_irq_sequence;
41209@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41210 }
41211
41212 for (i = 0; i < dev_priv->num_irqs; ++i) {
41213- atomic_set(&cur_irq->irq_received, 0);
41214+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41215 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41216 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41217 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41218@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41219 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41220 case VIA_IRQ_RELATIVE:
41221 irqwait->request.sequence +=
41222- atomic_read(&cur_irq->irq_received);
41223+ atomic_read_unchecked(&cur_irq->irq_received);
41224 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41225 case VIA_IRQ_ABSOLUTE:
41226 break;
41227diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41228index c0b73b9..f6f7f34 100644
41229--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41230+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41231@@ -341,7 +341,7 @@ struct vmw_private {
41232 * Fencing and IRQs.
41233 */
41234
41235- atomic_t marker_seq;
41236+ atomic_unchecked_t marker_seq;
41237 wait_queue_head_t fence_queue;
41238 wait_queue_head_t fifo_queue;
41239 int fence_queue_waiters; /* Protected by hw_mutex */
41240diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41241index 3eb1486..0a47ee9 100644
41242--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41243+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41244@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41245 (unsigned int) min,
41246 (unsigned int) fifo->capabilities);
41247
41248- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41249+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41250 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41251 vmw_marker_queue_init(&fifo->marker_queue);
41252 return vmw_fifo_send_fence(dev_priv, &dummy);
41253@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41254 if (reserveable)
41255 iowrite32(bytes, fifo_mem +
41256 SVGA_FIFO_RESERVED);
41257- return fifo_mem + (next_cmd >> 2);
41258+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41259 } else {
41260 need_bounce = true;
41261 }
41262@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41263
41264 fm = vmw_fifo_reserve(dev_priv, bytes);
41265 if (unlikely(fm == NULL)) {
41266- *seqno = atomic_read(&dev_priv->marker_seq);
41267+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41268 ret = -ENOMEM;
41269 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41270 false, 3*HZ);
41271@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41272 }
41273
41274 do {
41275- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41276+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41277 } while (*seqno == 0);
41278
41279 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41280diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41281index c5c054a..46f0548 100644
41282--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41283+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41284@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41285 }
41286
41287 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41288- vmw_gmrid_man_init,
41289- vmw_gmrid_man_takedown,
41290- vmw_gmrid_man_get_node,
41291- vmw_gmrid_man_put_node,
41292- vmw_gmrid_man_debug
41293+ .init = vmw_gmrid_man_init,
41294+ .takedown = vmw_gmrid_man_takedown,
41295+ .get_node = vmw_gmrid_man_get_node,
41296+ .put_node = vmw_gmrid_man_put_node,
41297+ .debug = vmw_gmrid_man_debug
41298 };
41299diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41300index 45d5b5a..f3f5e4e 100644
41301--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41302+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41303@@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41304 int ret;
41305
41306 num_clips = arg->num_clips;
41307- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41308+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41309
41310 if (unlikely(num_clips == 0))
41311 return 0;
41312@@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41313 int ret;
41314
41315 num_clips = arg->num_clips;
41316- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41317+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41318
41319 if (unlikely(num_clips == 0))
41320 return 0;
41321diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41322index 4640adb..e1384ed 100644
41323--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41324+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41325@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41326 * emitted. Then the fence is stale and signaled.
41327 */
41328
41329- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41330+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41331 > VMW_FENCE_WRAP);
41332
41333 return ret;
41334@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41335
41336 if (fifo_idle)
41337 down_read(&fifo_state->rwsem);
41338- signal_seq = atomic_read(&dev_priv->marker_seq);
41339+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41340 ret = 0;
41341
41342 for (;;) {
41343diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41344index 8a8725c2..afed796 100644
41345--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41346+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41347@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41348 while (!vmw_lag_lt(queue, us)) {
41349 spin_lock(&queue->lock);
41350 if (list_empty(&queue->head))
41351- seqno = atomic_read(&dev_priv->marker_seq);
41352+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41353 else {
41354 marker = list_first_entry(&queue->head,
41355 struct vmw_marker, head);
41356diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41357index ec0ae2d..dc0780b 100644
41358--- a/drivers/gpu/vga/vga_switcheroo.c
41359+++ b/drivers/gpu/vga/vga_switcheroo.c
41360@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41361
41362 /* this version is for the case where the power switch is separate
41363 to the device being powered down. */
41364-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41365+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41366 {
41367 /* copy over all the bus versions */
41368 if (dev->bus && dev->bus->pm) {
41369@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41370 return ret;
41371 }
41372
41373-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41374+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41375 {
41376 /* copy over all the bus versions */
41377 if (dev->bus && dev->bus->pm) {
41378diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41379index 253fe23..0dfec5f 100644
41380--- a/drivers/hid/hid-core.c
41381+++ b/drivers/hid/hid-core.c
41382@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41383
41384 int hid_add_device(struct hid_device *hdev)
41385 {
41386- static atomic_t id = ATOMIC_INIT(0);
41387+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41388 int ret;
41389
41390 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41391@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41392 /* XXX hack, any other cleaner solution after the driver core
41393 * is converted to allow more than 20 bytes as the device name? */
41394 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41395- hdev->vendor, hdev->product, atomic_inc_return(&id));
41396+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41397
41398 hid_debug_register(hdev, dev_name(&hdev->dev));
41399 ret = device_add(&hdev->dev);
41400diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41401index c13fb5b..55a3802 100644
41402--- a/drivers/hid/hid-wiimote-debug.c
41403+++ b/drivers/hid/hid-wiimote-debug.c
41404@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41405 else if (size == 0)
41406 return -EIO;
41407
41408- if (copy_to_user(u, buf, size))
41409+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41410 return -EFAULT;
41411
41412 *off += size;
41413diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41414index cedc6da..2c3da2a 100644
41415--- a/drivers/hid/uhid.c
41416+++ b/drivers/hid/uhid.c
41417@@ -47,7 +47,7 @@ struct uhid_device {
41418 struct mutex report_lock;
41419 wait_queue_head_t report_wait;
41420 atomic_t report_done;
41421- atomic_t report_id;
41422+ atomic_unchecked_t report_id;
41423 struct uhid_event report_buf;
41424 };
41425
41426@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41427
41428 spin_lock_irqsave(&uhid->qlock, flags);
41429 ev->type = UHID_FEATURE;
41430- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41431+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41432 ev->u.feature.rnum = rnum;
41433 ev->u.feature.rtype = report_type;
41434
41435@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41436 spin_lock_irqsave(&uhid->qlock, flags);
41437
41438 /* id for old report; drop it silently */
41439- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41440+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41441 goto unlock;
41442 if (atomic_read(&uhid->report_done))
41443 goto unlock;
41444diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41445index cea623c..73011b0 100644
41446--- a/drivers/hv/channel.c
41447+++ b/drivers/hv/channel.c
41448@@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41449 int ret = 0;
41450 int t;
41451
41452- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41453- atomic_inc(&vmbus_connection.next_gpadl_handle);
41454+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41455+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41456
41457 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41458 if (ret)
41459diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41460index f0c5e07..49a4d4a 100644
41461--- a/drivers/hv/hv.c
41462+++ b/drivers/hv/hv.c
41463@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41464 u64 output_address = (output) ? virt_to_phys(output) : 0;
41465 u32 output_address_hi = output_address >> 32;
41466 u32 output_address_lo = output_address & 0xFFFFFFFF;
41467- void *hypercall_page = hv_context.hypercall_page;
41468+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41469
41470 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41471 "=a"(hv_status_lo) : "d" (control_hi),
41472@@ -154,7 +154,7 @@ int hv_init(void)
41473 /* See if the hypercall page is already set */
41474 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41475
41476- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41477+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41478
41479 if (!virtaddr)
41480 goto cleanup;
41481diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41482index 7e17a54..a50a33d 100644
41483--- a/drivers/hv/hv_balloon.c
41484+++ b/drivers/hv/hv_balloon.c
41485@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41486
41487 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41488 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41489-static atomic_t trans_id = ATOMIC_INIT(0);
41490+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41491
41492 static int dm_ring_size = (5 * PAGE_SIZE);
41493
41494@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41495 pr_info("Memory hot add failed\n");
41496
41497 dm->state = DM_INITIALIZED;
41498- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41499+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41500 vmbus_sendpacket(dm->dev->channel, &resp,
41501 sizeof(struct dm_hot_add_response),
41502 (unsigned long)NULL,
41503@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41504 memset(&status, 0, sizeof(struct dm_status));
41505 status.hdr.type = DM_STATUS_REPORT;
41506 status.hdr.size = sizeof(struct dm_status);
41507- status.hdr.trans_id = atomic_inc_return(&trans_id);
41508+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41509
41510 /*
41511 * The host expects the guest to report free memory.
41512@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41513 * send the status. This can happen if we were interrupted
41514 * after we picked our transaction ID.
41515 */
41516- if (status.hdr.trans_id != atomic_read(&trans_id))
41517+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41518 return;
41519
41520 vmbus_sendpacket(dm->dev->channel, &status,
41521@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41522 */
41523
41524 do {
41525- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41526+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41527 ret = vmbus_sendpacket(dm_device.dev->channel,
41528 bl_resp,
41529 bl_resp->hdr.size,
41530@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41531
41532 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41533 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41534- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41535+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41536 resp.hdr.size = sizeof(struct dm_unballoon_response);
41537
41538 vmbus_sendpacket(dm_device.dev->channel, &resp,
41539@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41540 memset(&version_req, 0, sizeof(struct dm_version_request));
41541 version_req.hdr.type = DM_VERSION_REQUEST;
41542 version_req.hdr.size = sizeof(struct dm_version_request);
41543- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41544+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41545 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41546 version_req.is_last_attempt = 1;
41547
41548@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41549 memset(&version_req, 0, sizeof(struct dm_version_request));
41550 version_req.hdr.type = DM_VERSION_REQUEST;
41551 version_req.hdr.size = sizeof(struct dm_version_request);
41552- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41553+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41554 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41555 version_req.is_last_attempt = 0;
41556
41557@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41558 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41559 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41560 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41561- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41562+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41563
41564 cap_msg.caps.cap_bits.balloon = 1;
41565 cap_msg.caps.cap_bits.hot_add = 1;
41566diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41567index e055176..c22ff1f 100644
41568--- a/drivers/hv/hyperv_vmbus.h
41569+++ b/drivers/hv/hyperv_vmbus.h
41570@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41571 struct vmbus_connection {
41572 enum vmbus_connect_state conn_state;
41573
41574- atomic_t next_gpadl_handle;
41575+ atomic_unchecked_t next_gpadl_handle;
41576
41577 /*
41578 * Represents channel interrupts. Each bit position represents a
41579diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41580index 48aad4f..c768fb2 100644
41581--- a/drivers/hv/vmbus_drv.c
41582+++ b/drivers/hv/vmbus_drv.c
41583@@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41584 {
41585 int ret = 0;
41586
41587- static atomic_t device_num = ATOMIC_INIT(0);
41588+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41589
41590 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41591- atomic_inc_return(&device_num));
41592+ atomic_inc_return_unchecked(&device_num));
41593
41594 child_device_obj->device.bus = &hv_bus;
41595 child_device_obj->device.parent = &hv_acpi_dev->dev;
41596diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41597index 6a34f7f..aa4c3a6 100644
41598--- a/drivers/hwmon/acpi_power_meter.c
41599+++ b/drivers/hwmon/acpi_power_meter.c
41600@@ -117,7 +117,7 @@ struct sensor_template {
41601 struct device_attribute *devattr,
41602 const char *buf, size_t count);
41603 int index;
41604-};
41605+} __do_const;
41606
41607 /* Averaging interval */
41608 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41609@@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41610 struct sensor_template *attrs)
41611 {
41612 struct device *dev = &resource->acpi_dev->dev;
41613- struct sensor_device_attribute *sensors =
41614+ sensor_device_attribute_no_const *sensors =
41615 &resource->sensors[resource->num_sensors];
41616 int res = 0;
41617
41618diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41619index 3288f13..71cfb4e 100644
41620--- a/drivers/hwmon/applesmc.c
41621+++ b/drivers/hwmon/applesmc.c
41622@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41623 {
41624 struct applesmc_node_group *grp;
41625 struct applesmc_dev_attr *node;
41626- struct attribute *attr;
41627+ attribute_no_const *attr;
41628 int ret, i;
41629
41630 for (grp = groups; grp->format; grp++) {
41631diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41632index dafc63c..4abb96c 100644
41633--- a/drivers/hwmon/asus_atk0110.c
41634+++ b/drivers/hwmon/asus_atk0110.c
41635@@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41636 struct atk_sensor_data {
41637 struct list_head list;
41638 struct atk_data *data;
41639- struct device_attribute label_attr;
41640- struct device_attribute input_attr;
41641- struct device_attribute limit1_attr;
41642- struct device_attribute limit2_attr;
41643+ device_attribute_no_const label_attr;
41644+ device_attribute_no_const input_attr;
41645+ device_attribute_no_const limit1_attr;
41646+ device_attribute_no_const limit2_attr;
41647 char label_attr_name[ATTR_NAME_SIZE];
41648 char input_attr_name[ATTR_NAME_SIZE];
41649 char limit1_attr_name[ATTR_NAME_SIZE];
41650@@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41651 static struct device_attribute atk_name_attr =
41652 __ATTR(name, 0444, atk_name_show, NULL);
41653
41654-static void atk_init_attribute(struct device_attribute *attr, char *name,
41655+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41656 sysfs_show_func show)
41657 {
41658 sysfs_attr_init(&attr->attr);
41659diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41660index 9425098..7646cc5 100644
41661--- a/drivers/hwmon/coretemp.c
41662+++ b/drivers/hwmon/coretemp.c
41663@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41664 return NOTIFY_OK;
41665 }
41666
41667-static struct notifier_block coretemp_cpu_notifier __refdata = {
41668+static struct notifier_block coretemp_cpu_notifier = {
41669 .notifier_call = coretemp_cpu_callback,
41670 };
41671
41672diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41673index 632f1dc..57e6a58 100644
41674--- a/drivers/hwmon/ibmaem.c
41675+++ b/drivers/hwmon/ibmaem.c
41676@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41677 struct aem_rw_sensor_template *rw)
41678 {
41679 struct device *dev = &data->pdev->dev;
41680- struct sensor_device_attribute *sensors = data->sensors;
41681+ sensor_device_attribute_no_const *sensors = data->sensors;
41682 int err;
41683
41684 /* Set up read-only sensors */
41685diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41686index 708081b..fe2d4ab 100644
41687--- a/drivers/hwmon/iio_hwmon.c
41688+++ b/drivers/hwmon/iio_hwmon.c
41689@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41690 {
41691 struct device *dev = &pdev->dev;
41692 struct iio_hwmon_state *st;
41693- struct sensor_device_attribute *a;
41694+ sensor_device_attribute_no_const *a;
41695 int ret, i;
41696 int in_i = 1, temp_i = 1, curr_i = 1;
41697 enum iio_chan_type type;
41698diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41699index cf811c1..4c17110 100644
41700--- a/drivers/hwmon/nct6775.c
41701+++ b/drivers/hwmon/nct6775.c
41702@@ -944,10 +944,10 @@ static struct attribute_group *
41703 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41704 int repeat)
41705 {
41706- struct attribute_group *group;
41707+ attribute_group_no_const *group;
41708 struct sensor_device_attr_u *su;
41709- struct sensor_device_attribute *a;
41710- struct sensor_device_attribute_2 *a2;
41711+ sensor_device_attribute_no_const *a;
41712+ sensor_device_attribute_2_no_const *a2;
41713 struct attribute **attrs;
41714 struct sensor_device_template **t;
41715 int i, count;
41716diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41717index 3cbf66e..8c5cc2a 100644
41718--- a/drivers/hwmon/pmbus/pmbus_core.c
41719+++ b/drivers/hwmon/pmbus/pmbus_core.c
41720@@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41721 return 0;
41722 }
41723
41724-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41725+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41726 const char *name,
41727 umode_t mode,
41728 ssize_t (*show)(struct device *dev,
41729@@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41730 dev_attr->store = store;
41731 }
41732
41733-static void pmbus_attr_init(struct sensor_device_attribute *a,
41734+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41735 const char *name,
41736 umode_t mode,
41737 ssize_t (*show)(struct device *dev,
41738@@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41739 u16 reg, u8 mask)
41740 {
41741 struct pmbus_boolean *boolean;
41742- struct sensor_device_attribute *a;
41743+ sensor_device_attribute_no_const *a;
41744
41745 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41746 if (!boolean)
41747@@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41748 bool update, bool readonly)
41749 {
41750 struct pmbus_sensor *sensor;
41751- struct device_attribute *a;
41752+ device_attribute_no_const *a;
41753
41754 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41755 if (!sensor)
41756@@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41757 const char *lstring, int index)
41758 {
41759 struct pmbus_label *label;
41760- struct device_attribute *a;
41761+ device_attribute_no_const *a;
41762
41763 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41764 if (!label)
41765diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41766index 97cd45a..ac54d8b 100644
41767--- a/drivers/hwmon/sht15.c
41768+++ b/drivers/hwmon/sht15.c
41769@@ -169,7 +169,7 @@ struct sht15_data {
41770 int supply_uv;
41771 bool supply_uv_valid;
41772 struct work_struct update_supply_work;
41773- atomic_t interrupt_handled;
41774+ atomic_unchecked_t interrupt_handled;
41775 };
41776
41777 /**
41778@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41779 ret = gpio_direction_input(data->pdata->gpio_data);
41780 if (ret)
41781 return ret;
41782- atomic_set(&data->interrupt_handled, 0);
41783+ atomic_set_unchecked(&data->interrupt_handled, 0);
41784
41785 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41786 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41787 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41788 /* Only relevant if the interrupt hasn't occurred. */
41789- if (!atomic_read(&data->interrupt_handled))
41790+ if (!atomic_read_unchecked(&data->interrupt_handled))
41791 schedule_work(&data->read_work);
41792 }
41793 ret = wait_event_timeout(data->wait_queue,
41794@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41795
41796 /* First disable the interrupt */
41797 disable_irq_nosync(irq);
41798- atomic_inc(&data->interrupt_handled);
41799+ atomic_inc_unchecked(&data->interrupt_handled);
41800 /* Then schedule a reading work struct */
41801 if (data->state != SHT15_READING_NOTHING)
41802 schedule_work(&data->read_work);
41803@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41804 * If not, then start the interrupt again - care here as could
41805 * have gone low in meantime so verify it hasn't!
41806 */
41807- atomic_set(&data->interrupt_handled, 0);
41808+ atomic_set_unchecked(&data->interrupt_handled, 0);
41809 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41810 /* If still not occurred or another handler was scheduled */
41811 if (gpio_get_value(data->pdata->gpio_data)
41812- || atomic_read(&data->interrupt_handled))
41813+ || atomic_read_unchecked(&data->interrupt_handled))
41814 return;
41815 }
41816
41817diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41818index 38944e9..ae9e5ed 100644
41819--- a/drivers/hwmon/via-cputemp.c
41820+++ b/drivers/hwmon/via-cputemp.c
41821@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41822 return NOTIFY_OK;
41823 }
41824
41825-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41826+static struct notifier_block via_cputemp_cpu_notifier = {
41827 .notifier_call = via_cputemp_cpu_callback,
41828 };
41829
41830diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41831index 07f01ac..d79ad3d 100644
41832--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41833+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41834@@ -43,7 +43,7 @@
41835 extern struct i2c_adapter amd756_smbus;
41836
41837 static struct i2c_adapter *s4882_adapter;
41838-static struct i2c_algorithm *s4882_algo;
41839+static i2c_algorithm_no_const *s4882_algo;
41840
41841 /* Wrapper access functions for multiplexed SMBus */
41842 static DEFINE_MUTEX(amd756_lock);
41843diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41844index 721f7eb..0fd2a09 100644
41845--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41846+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41847@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41848 /* usb layer */
41849
41850 /* Send command to device, and get response. */
41851-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41852+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41853 {
41854 int ret = 0;
41855 int actual;
41856diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41857index 2ca268d..c6acbdf 100644
41858--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41859+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41860@@ -41,7 +41,7 @@
41861 extern struct i2c_adapter *nforce2_smbus;
41862
41863 static struct i2c_adapter *s4985_adapter;
41864-static struct i2c_algorithm *s4985_algo;
41865+static i2c_algorithm_no_const *s4985_algo;
41866
41867 /* Wrapper access functions for multiplexed SMBus */
41868 static DEFINE_MUTEX(nforce2_lock);
41869diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41870index 80b47e8..1a6040d9 100644
41871--- a/drivers/i2c/i2c-dev.c
41872+++ b/drivers/i2c/i2c-dev.c
41873@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41874 break;
41875 }
41876
41877- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41878+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41879 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41880 if (IS_ERR(rdwr_pa[i].buf)) {
41881 res = PTR_ERR(rdwr_pa[i].buf);
41882diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41883index 0b510ba..4fbb5085 100644
41884--- a/drivers/ide/ide-cd.c
41885+++ b/drivers/ide/ide-cd.c
41886@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41887 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41888 if ((unsigned long)buf & alignment
41889 || blk_rq_bytes(rq) & q->dma_pad_mask
41890- || object_is_on_stack(buf))
41891+ || object_starts_on_stack(buf))
41892 drive->dma = 0;
41893 }
41894 }
41895diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41896index 18f72e3..3722327 100644
41897--- a/drivers/iio/industrialio-core.c
41898+++ b/drivers/iio/industrialio-core.c
41899@@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41900 }
41901
41902 static
41903-int __iio_device_attr_init(struct device_attribute *dev_attr,
41904+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41905 const char *postfix,
41906 struct iio_chan_spec const *chan,
41907 ssize_t (*readfunc)(struct device *dev,
41908diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41909index f2ef7ef..743d02f 100644
41910--- a/drivers/infiniband/core/cm.c
41911+++ b/drivers/infiniband/core/cm.c
41912@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41913
41914 struct cm_counter_group {
41915 struct kobject obj;
41916- atomic_long_t counter[CM_ATTR_COUNT];
41917+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41918 };
41919
41920 struct cm_counter_attribute {
41921@@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41922 struct ib_mad_send_buf *msg = NULL;
41923 int ret;
41924
41925- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41926+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41927 counter[CM_REQ_COUNTER]);
41928
41929 /* Quick state check to discard duplicate REQs. */
41930@@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41931 if (!cm_id_priv)
41932 return;
41933
41934- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41935+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41936 counter[CM_REP_COUNTER]);
41937 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41938 if (ret)
41939@@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41940 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41941 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41942 spin_unlock_irq(&cm_id_priv->lock);
41943- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41944+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41945 counter[CM_RTU_COUNTER]);
41946 goto out;
41947 }
41948@@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41949 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41950 dreq_msg->local_comm_id);
41951 if (!cm_id_priv) {
41952- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41953+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41954 counter[CM_DREQ_COUNTER]);
41955 cm_issue_drep(work->port, work->mad_recv_wc);
41956 return -EINVAL;
41957@@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41958 case IB_CM_MRA_REP_RCVD:
41959 break;
41960 case IB_CM_TIMEWAIT:
41961- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41962+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41963 counter[CM_DREQ_COUNTER]);
41964 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41965 goto unlock;
41966@@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41967 cm_free_msg(msg);
41968 goto deref;
41969 case IB_CM_DREQ_RCVD:
41970- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41971+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41972 counter[CM_DREQ_COUNTER]);
41973 goto unlock;
41974 default:
41975@@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41976 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41977 cm_id_priv->msg, timeout)) {
41978 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41979- atomic_long_inc(&work->port->
41980+ atomic_long_inc_unchecked(&work->port->
41981 counter_group[CM_RECV_DUPLICATES].
41982 counter[CM_MRA_COUNTER]);
41983 goto out;
41984@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41985 break;
41986 case IB_CM_MRA_REQ_RCVD:
41987 case IB_CM_MRA_REP_RCVD:
41988- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41989+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41990 counter[CM_MRA_COUNTER]);
41991 /* fall through */
41992 default:
41993@@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41994 case IB_CM_LAP_IDLE:
41995 break;
41996 case IB_CM_MRA_LAP_SENT:
41997- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41998+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41999 counter[CM_LAP_COUNTER]);
42000 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42001 goto unlock;
42002@@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
42003 cm_free_msg(msg);
42004 goto deref;
42005 case IB_CM_LAP_RCVD:
42006- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42007+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42008 counter[CM_LAP_COUNTER]);
42009 goto unlock;
42010 default:
42011@@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42012 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42013 if (cur_cm_id_priv) {
42014 spin_unlock_irq(&cm.lock);
42015- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42016+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42017 counter[CM_SIDR_REQ_COUNTER]);
42018 goto out; /* Duplicate message. */
42019 }
42020@@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42021 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42022 msg->retries = 1;
42023
42024- atomic_long_add(1 + msg->retries,
42025+ atomic_long_add_unchecked(1 + msg->retries,
42026 &port->counter_group[CM_XMIT].counter[attr_index]);
42027 if (msg->retries)
42028- atomic_long_add(msg->retries,
42029+ atomic_long_add_unchecked(msg->retries,
42030 &port->counter_group[CM_XMIT_RETRIES].
42031 counter[attr_index]);
42032
42033@@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42034 }
42035
42036 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42037- atomic_long_inc(&port->counter_group[CM_RECV].
42038+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42039 counter[attr_id - CM_ATTR_ID_OFFSET]);
42040
42041 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42042@@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42043 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42044
42045 return sprintf(buf, "%ld\n",
42046- atomic_long_read(&group->counter[cm_attr->index]));
42047+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42048 }
42049
42050 static const struct sysfs_ops cm_counter_ops = {
42051diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42052index 9f5ad7c..588cd84 100644
42053--- a/drivers/infiniband/core/fmr_pool.c
42054+++ b/drivers/infiniband/core/fmr_pool.c
42055@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42056
42057 struct task_struct *thread;
42058
42059- atomic_t req_ser;
42060- atomic_t flush_ser;
42061+ atomic_unchecked_t req_ser;
42062+ atomic_unchecked_t flush_ser;
42063
42064 wait_queue_head_t force_wait;
42065 };
42066@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42067 struct ib_fmr_pool *pool = pool_ptr;
42068
42069 do {
42070- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42071+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42072 ib_fmr_batch_release(pool);
42073
42074- atomic_inc(&pool->flush_ser);
42075+ atomic_inc_unchecked(&pool->flush_ser);
42076 wake_up_interruptible(&pool->force_wait);
42077
42078 if (pool->flush_function)
42079@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42080 }
42081
42082 set_current_state(TASK_INTERRUPTIBLE);
42083- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42084+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42085 !kthread_should_stop())
42086 schedule();
42087 __set_current_state(TASK_RUNNING);
42088@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42089 pool->dirty_watermark = params->dirty_watermark;
42090 pool->dirty_len = 0;
42091 spin_lock_init(&pool->pool_lock);
42092- atomic_set(&pool->req_ser, 0);
42093- atomic_set(&pool->flush_ser, 0);
42094+ atomic_set_unchecked(&pool->req_ser, 0);
42095+ atomic_set_unchecked(&pool->flush_ser, 0);
42096 init_waitqueue_head(&pool->force_wait);
42097
42098 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42099@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42100 }
42101 spin_unlock_irq(&pool->pool_lock);
42102
42103- serial = atomic_inc_return(&pool->req_ser);
42104+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42105 wake_up_process(pool->thread);
42106
42107 if (wait_event_interruptible(pool->force_wait,
42108- atomic_read(&pool->flush_ser) - serial >= 0))
42109+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42110 return -EINTR;
42111
42112 return 0;
42113@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42114 } else {
42115 list_add_tail(&fmr->list, &pool->dirty_list);
42116 if (++pool->dirty_len >= pool->dirty_watermark) {
42117- atomic_inc(&pool->req_ser);
42118+ atomic_inc_unchecked(&pool->req_ser);
42119 wake_up_process(pool->thread);
42120 }
42121 }
42122diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42123index 84e4500..2c9beeb 100644
42124--- a/drivers/infiniband/hw/cxgb4/mem.c
42125+++ b/drivers/infiniband/hw/cxgb4/mem.c
42126@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42127 int err;
42128 struct fw_ri_tpte tpt;
42129 u32 stag_idx;
42130- static atomic_t key;
42131+ static atomic_unchecked_t key;
42132
42133 if (c4iw_fatal_error(rdev))
42134 return -EIO;
42135@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42136 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42137 rdev->stats.stag.max = rdev->stats.stag.cur;
42138 mutex_unlock(&rdev->stats.lock);
42139- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42140+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42141 }
42142 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42143 __func__, stag_state, type, pdid, stag_idx);
42144diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42145index 644c2c7..ecf0879 100644
42146--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42147+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42148@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42149 }
42150
42151 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42152- ipath_mapping_error,
42153- ipath_dma_map_single,
42154- ipath_dma_unmap_single,
42155- ipath_dma_map_page,
42156- ipath_dma_unmap_page,
42157- ipath_map_sg,
42158- ipath_unmap_sg,
42159- ipath_sg_dma_address,
42160- ipath_sg_dma_len,
42161- ipath_sync_single_for_cpu,
42162- ipath_sync_single_for_device,
42163- ipath_dma_alloc_coherent,
42164- ipath_dma_free_coherent
42165+ .mapping_error = ipath_mapping_error,
42166+ .map_single = ipath_dma_map_single,
42167+ .unmap_single = ipath_dma_unmap_single,
42168+ .map_page = ipath_dma_map_page,
42169+ .unmap_page = ipath_dma_unmap_page,
42170+ .map_sg = ipath_map_sg,
42171+ .unmap_sg = ipath_unmap_sg,
42172+ .dma_address = ipath_sg_dma_address,
42173+ .dma_len = ipath_sg_dma_len,
42174+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42175+ .sync_single_for_device = ipath_sync_single_for_device,
42176+ .alloc_coherent = ipath_dma_alloc_coherent,
42177+ .free_coherent = ipath_dma_free_coherent
42178 };
42179diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42180index 79b3dbc..96e5fcc 100644
42181--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42182+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42183@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42184 struct ib_atomic_eth *ateth;
42185 struct ipath_ack_entry *e;
42186 u64 vaddr;
42187- atomic64_t *maddr;
42188+ atomic64_unchecked_t *maddr;
42189 u64 sdata;
42190 u32 rkey;
42191 u8 next;
42192@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42193 IB_ACCESS_REMOTE_ATOMIC)))
42194 goto nack_acc_unlck;
42195 /* Perform atomic OP and save result. */
42196- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42197+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42198 sdata = be64_to_cpu(ateth->swap_data);
42199 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42200 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42201- (u64) atomic64_add_return(sdata, maddr) - sdata :
42202+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42203 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42204 be64_to_cpu(ateth->compare_data),
42205 sdata);
42206diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42207index 1f95bba..9530f87 100644
42208--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42209+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42210@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42211 unsigned long flags;
42212 struct ib_wc wc;
42213 u64 sdata;
42214- atomic64_t *maddr;
42215+ atomic64_unchecked_t *maddr;
42216 enum ib_wc_status send_status;
42217
42218 /*
42219@@ -382,11 +382,11 @@ again:
42220 IB_ACCESS_REMOTE_ATOMIC)))
42221 goto acc_err;
42222 /* Perform atomic OP and save result. */
42223- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42224+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42225 sdata = wqe->wr.wr.atomic.compare_add;
42226 *(u64 *) sqp->s_sge.sge.vaddr =
42227 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42228- (u64) atomic64_add_return(sdata, maddr) - sdata :
42229+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42230 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42231 sdata, wqe->wr.wr.atomic.swap);
42232 goto send_comp;
42233diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42234index f2a3f48..673ec79 100644
42235--- a/drivers/infiniband/hw/mlx4/mad.c
42236+++ b/drivers/infiniband/hw/mlx4/mad.c
42237@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42238
42239 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42240 {
42241- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42242+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42243 cpu_to_be64(0xff00000000000000LL);
42244 }
42245
42246diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42247index 25b2cdf..099ff97 100644
42248--- a/drivers/infiniband/hw/mlx4/mcg.c
42249+++ b/drivers/infiniband/hw/mlx4/mcg.c
42250@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42251 {
42252 char name[20];
42253
42254- atomic_set(&ctx->tid, 0);
42255+ atomic_set_unchecked(&ctx->tid, 0);
42256 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42257 ctx->mcg_wq = create_singlethread_workqueue(name);
42258 if (!ctx->mcg_wq)
42259diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42260index 036b663..c9a8c73 100644
42261--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42262+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42263@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42264 struct list_head mcg_mgid0_list;
42265 struct workqueue_struct *mcg_wq;
42266 struct mlx4_ib_demux_pv_ctx **tun;
42267- atomic_t tid;
42268+ atomic_unchecked_t tid;
42269 int flushing; /* flushing the work queue */
42270 };
42271
42272diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42273index 9d3e5c1..6f166df 100644
42274--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42275+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42276@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42277 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42278 }
42279
42280-int mthca_QUERY_FW(struct mthca_dev *dev)
42281+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42282 {
42283 struct mthca_mailbox *mailbox;
42284 u32 *outbox;
42285@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42286 CMD_TIME_CLASS_B);
42287 }
42288
42289-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42290+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42291 int num_mtt)
42292 {
42293 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42294@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42295 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42296 }
42297
42298-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42299+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42300 int eq_num)
42301 {
42302 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42303@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42304 CMD_TIME_CLASS_B);
42305 }
42306
42307-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42308+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42309 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42310 void *in_mad, void *response_mad)
42311 {
42312diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42313index 87897b9..7e79542 100644
42314--- a/drivers/infiniband/hw/mthca/mthca_main.c
42315+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42316@@ -692,7 +692,7 @@ err_close:
42317 return err;
42318 }
42319
42320-static int mthca_setup_hca(struct mthca_dev *dev)
42321+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42322 {
42323 int err;
42324
42325diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42326index ed9a989..6aa5dc2 100644
42327--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42328+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42329@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42330 * through the bitmaps)
42331 */
42332
42333-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42334+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42335 {
42336 int o;
42337 int m;
42338@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42339 return key;
42340 }
42341
42342-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42343+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42344 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42345 {
42346 struct mthca_mailbox *mailbox;
42347@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42348 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42349 }
42350
42351-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42352+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42353 u64 *buffer_list, int buffer_size_shift,
42354 int list_len, u64 iova, u64 total_size,
42355 u32 access, struct mthca_mr *mr)
42356diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42357index 5b71d43..35a9e14 100644
42358--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42359+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42360@@ -763,7 +763,7 @@ unlock:
42361 return 0;
42362 }
42363
42364-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42365+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42366 {
42367 struct mthca_dev *dev = to_mdev(ibcq->device);
42368 struct mthca_cq *cq = to_mcq(ibcq);
42369diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42370index 4291410..d2ab1fb 100644
42371--- a/drivers/infiniband/hw/nes/nes.c
42372+++ b/drivers/infiniband/hw/nes/nes.c
42373@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42374 LIST_HEAD(nes_adapter_list);
42375 static LIST_HEAD(nes_dev_list);
42376
42377-atomic_t qps_destroyed;
42378+atomic_unchecked_t qps_destroyed;
42379
42380 static unsigned int ee_flsh_adapter;
42381 static unsigned int sysfs_nonidx_addr;
42382@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42383 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42384 struct nes_adapter *nesadapter = nesdev->nesadapter;
42385
42386- atomic_inc(&qps_destroyed);
42387+ atomic_inc_unchecked(&qps_destroyed);
42388
42389 /* Free the control structures */
42390
42391diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42392index 33cc589..3bd6538 100644
42393--- a/drivers/infiniband/hw/nes/nes.h
42394+++ b/drivers/infiniband/hw/nes/nes.h
42395@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42396 extern unsigned int wqm_quanta;
42397 extern struct list_head nes_adapter_list;
42398
42399-extern atomic_t cm_connects;
42400-extern atomic_t cm_accepts;
42401-extern atomic_t cm_disconnects;
42402-extern atomic_t cm_closes;
42403-extern atomic_t cm_connecteds;
42404-extern atomic_t cm_connect_reqs;
42405-extern atomic_t cm_rejects;
42406-extern atomic_t mod_qp_timouts;
42407-extern atomic_t qps_created;
42408-extern atomic_t qps_destroyed;
42409-extern atomic_t sw_qps_destroyed;
42410+extern atomic_unchecked_t cm_connects;
42411+extern atomic_unchecked_t cm_accepts;
42412+extern atomic_unchecked_t cm_disconnects;
42413+extern atomic_unchecked_t cm_closes;
42414+extern atomic_unchecked_t cm_connecteds;
42415+extern atomic_unchecked_t cm_connect_reqs;
42416+extern atomic_unchecked_t cm_rejects;
42417+extern atomic_unchecked_t mod_qp_timouts;
42418+extern atomic_unchecked_t qps_created;
42419+extern atomic_unchecked_t qps_destroyed;
42420+extern atomic_unchecked_t sw_qps_destroyed;
42421 extern u32 mh_detected;
42422 extern u32 mh_pauses_sent;
42423 extern u32 cm_packets_sent;
42424@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42425 extern u32 cm_packets_received;
42426 extern u32 cm_packets_dropped;
42427 extern u32 cm_packets_retrans;
42428-extern atomic_t cm_listens_created;
42429-extern atomic_t cm_listens_destroyed;
42430+extern atomic_unchecked_t cm_listens_created;
42431+extern atomic_unchecked_t cm_listens_destroyed;
42432 extern u32 cm_backlog_drops;
42433-extern atomic_t cm_loopbacks;
42434-extern atomic_t cm_nodes_created;
42435-extern atomic_t cm_nodes_destroyed;
42436-extern atomic_t cm_accel_dropped_pkts;
42437-extern atomic_t cm_resets_recvd;
42438-extern atomic_t pau_qps_created;
42439-extern atomic_t pau_qps_destroyed;
42440+extern atomic_unchecked_t cm_loopbacks;
42441+extern atomic_unchecked_t cm_nodes_created;
42442+extern atomic_unchecked_t cm_nodes_destroyed;
42443+extern atomic_unchecked_t cm_accel_dropped_pkts;
42444+extern atomic_unchecked_t cm_resets_recvd;
42445+extern atomic_unchecked_t pau_qps_created;
42446+extern atomic_unchecked_t pau_qps_destroyed;
42447
42448 extern u32 int_mod_timer_init;
42449 extern u32 int_mod_cq_depth_256;
42450diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42451index 6b29249..461d143 100644
42452--- a/drivers/infiniband/hw/nes/nes_cm.c
42453+++ b/drivers/infiniband/hw/nes/nes_cm.c
42454@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42455 u32 cm_packets_retrans;
42456 u32 cm_packets_created;
42457 u32 cm_packets_received;
42458-atomic_t cm_listens_created;
42459-atomic_t cm_listens_destroyed;
42460+atomic_unchecked_t cm_listens_created;
42461+atomic_unchecked_t cm_listens_destroyed;
42462 u32 cm_backlog_drops;
42463-atomic_t cm_loopbacks;
42464-atomic_t cm_nodes_created;
42465-atomic_t cm_nodes_destroyed;
42466-atomic_t cm_accel_dropped_pkts;
42467-atomic_t cm_resets_recvd;
42468+atomic_unchecked_t cm_loopbacks;
42469+atomic_unchecked_t cm_nodes_created;
42470+atomic_unchecked_t cm_nodes_destroyed;
42471+atomic_unchecked_t cm_accel_dropped_pkts;
42472+atomic_unchecked_t cm_resets_recvd;
42473
42474 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42475 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42476@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42477 /* instance of function pointers for client API */
42478 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42479 static struct nes_cm_ops nes_cm_api = {
42480- mini_cm_accelerated,
42481- mini_cm_listen,
42482- mini_cm_del_listen,
42483- mini_cm_connect,
42484- mini_cm_close,
42485- mini_cm_accept,
42486- mini_cm_reject,
42487- mini_cm_recv_pkt,
42488- mini_cm_dealloc_core,
42489- mini_cm_get,
42490- mini_cm_set
42491+ .accelerated = mini_cm_accelerated,
42492+ .listen = mini_cm_listen,
42493+ .stop_listener = mini_cm_del_listen,
42494+ .connect = mini_cm_connect,
42495+ .close = mini_cm_close,
42496+ .accept = mini_cm_accept,
42497+ .reject = mini_cm_reject,
42498+ .recv_pkt = mini_cm_recv_pkt,
42499+ .destroy_cm_core = mini_cm_dealloc_core,
42500+ .get = mini_cm_get,
42501+ .set = mini_cm_set
42502 };
42503
42504 static struct nes_cm_core *g_cm_core;
42505
42506-atomic_t cm_connects;
42507-atomic_t cm_accepts;
42508-atomic_t cm_disconnects;
42509-atomic_t cm_closes;
42510-atomic_t cm_connecteds;
42511-atomic_t cm_connect_reqs;
42512-atomic_t cm_rejects;
42513+atomic_unchecked_t cm_connects;
42514+atomic_unchecked_t cm_accepts;
42515+atomic_unchecked_t cm_disconnects;
42516+atomic_unchecked_t cm_closes;
42517+atomic_unchecked_t cm_connecteds;
42518+atomic_unchecked_t cm_connect_reqs;
42519+atomic_unchecked_t cm_rejects;
42520
42521 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42522 {
42523@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42524 kfree(listener);
42525 listener = NULL;
42526 ret = 0;
42527- atomic_inc(&cm_listens_destroyed);
42528+ atomic_inc_unchecked(&cm_listens_destroyed);
42529 } else {
42530 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42531 }
42532@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42533 cm_node->rem_mac);
42534
42535 add_hte_node(cm_core, cm_node);
42536- atomic_inc(&cm_nodes_created);
42537+ atomic_inc_unchecked(&cm_nodes_created);
42538
42539 return cm_node;
42540 }
42541@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42542 }
42543
42544 atomic_dec(&cm_core->node_cnt);
42545- atomic_inc(&cm_nodes_destroyed);
42546+ atomic_inc_unchecked(&cm_nodes_destroyed);
42547 nesqp = cm_node->nesqp;
42548 if (nesqp) {
42549 nesqp->cm_node = NULL;
42550@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42551
42552 static void drop_packet(struct sk_buff *skb)
42553 {
42554- atomic_inc(&cm_accel_dropped_pkts);
42555+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42556 dev_kfree_skb_any(skb);
42557 }
42558
42559@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42560 {
42561
42562 int reset = 0; /* whether to send reset in case of err.. */
42563- atomic_inc(&cm_resets_recvd);
42564+ atomic_inc_unchecked(&cm_resets_recvd);
42565 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42566 " refcnt=%d\n", cm_node, cm_node->state,
42567 atomic_read(&cm_node->ref_count));
42568@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42569 rem_ref_cm_node(cm_node->cm_core, cm_node);
42570 return NULL;
42571 }
42572- atomic_inc(&cm_loopbacks);
42573+ atomic_inc_unchecked(&cm_loopbacks);
42574 loopbackremotenode->loopbackpartner = cm_node;
42575 loopbackremotenode->tcp_cntxt.rcv_wscale =
42576 NES_CM_DEFAULT_RCV_WND_SCALE;
42577@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42578 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42579 else {
42580 rem_ref_cm_node(cm_core, cm_node);
42581- atomic_inc(&cm_accel_dropped_pkts);
42582+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42583 dev_kfree_skb_any(skb);
42584 }
42585 break;
42586@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42587
42588 if ((cm_id) && (cm_id->event_handler)) {
42589 if (issue_disconn) {
42590- atomic_inc(&cm_disconnects);
42591+ atomic_inc_unchecked(&cm_disconnects);
42592 cm_event.event = IW_CM_EVENT_DISCONNECT;
42593 cm_event.status = disconn_status;
42594 cm_event.local_addr = cm_id->local_addr;
42595@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42596 }
42597
42598 if (issue_close) {
42599- atomic_inc(&cm_closes);
42600+ atomic_inc_unchecked(&cm_closes);
42601 nes_disconnect(nesqp, 1);
42602
42603 cm_id->provider_data = nesqp;
42604@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42605
42606 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42607 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42608- atomic_inc(&cm_accepts);
42609+ atomic_inc_unchecked(&cm_accepts);
42610
42611 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42612 netdev_refcnt_read(nesvnic->netdev));
42613@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42614 struct nes_cm_core *cm_core;
42615 u8 *start_buff;
42616
42617- atomic_inc(&cm_rejects);
42618+ atomic_inc_unchecked(&cm_rejects);
42619 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42620 loopback = cm_node->loopbackpartner;
42621 cm_core = cm_node->cm_core;
42622@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42623 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42624 ntohs(laddr->sin_port));
42625
42626- atomic_inc(&cm_connects);
42627+ atomic_inc_unchecked(&cm_connects);
42628 nesqp->active_conn = 1;
42629
42630 /* cache the cm_id in the qp */
42631@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42632 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42633 return err;
42634 }
42635- atomic_inc(&cm_listens_created);
42636+ atomic_inc_unchecked(&cm_listens_created);
42637 }
42638
42639 cm_id->add_ref(cm_id);
42640@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42641
42642 if (nesqp->destroyed)
42643 return;
42644- atomic_inc(&cm_connecteds);
42645+ atomic_inc_unchecked(&cm_connecteds);
42646 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42647 " local port 0x%04X. jiffies = %lu.\n",
42648 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42649@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42650
42651 cm_id->add_ref(cm_id);
42652 ret = cm_id->event_handler(cm_id, &cm_event);
42653- atomic_inc(&cm_closes);
42654+ atomic_inc_unchecked(&cm_closes);
42655 cm_event.event = IW_CM_EVENT_CLOSE;
42656 cm_event.status = 0;
42657 cm_event.provider_data = cm_id->provider_data;
42658@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42659 return;
42660 cm_id = cm_node->cm_id;
42661
42662- atomic_inc(&cm_connect_reqs);
42663+ atomic_inc_unchecked(&cm_connect_reqs);
42664 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42665 cm_node, cm_id, jiffies);
42666
42667@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42668 return;
42669 cm_id = cm_node->cm_id;
42670
42671- atomic_inc(&cm_connect_reqs);
42672+ atomic_inc_unchecked(&cm_connect_reqs);
42673 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42674 cm_node, cm_id, jiffies);
42675
42676diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42677index 4166452..fc952c3 100644
42678--- a/drivers/infiniband/hw/nes/nes_mgt.c
42679+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42680@@ -40,8 +40,8 @@
42681 #include "nes.h"
42682 #include "nes_mgt.h"
42683
42684-atomic_t pau_qps_created;
42685-atomic_t pau_qps_destroyed;
42686+atomic_unchecked_t pau_qps_created;
42687+atomic_unchecked_t pau_qps_destroyed;
42688
42689 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42690 {
42691@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42692 {
42693 struct sk_buff *skb;
42694 unsigned long flags;
42695- atomic_inc(&pau_qps_destroyed);
42696+ atomic_inc_unchecked(&pau_qps_destroyed);
42697
42698 /* Free packets that have not yet been forwarded */
42699 /* Lock is acquired by skb_dequeue when removing the skb */
42700@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42701 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42702 skb_queue_head_init(&nesqp->pau_list);
42703 spin_lock_init(&nesqp->pau_lock);
42704- atomic_inc(&pau_qps_created);
42705+ atomic_inc_unchecked(&pau_qps_created);
42706 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42707 }
42708
42709diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42710index 49eb511..a774366 100644
42711--- a/drivers/infiniband/hw/nes/nes_nic.c
42712+++ b/drivers/infiniband/hw/nes/nes_nic.c
42713@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42714 target_stat_values[++index] = mh_detected;
42715 target_stat_values[++index] = mh_pauses_sent;
42716 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42717- target_stat_values[++index] = atomic_read(&cm_connects);
42718- target_stat_values[++index] = atomic_read(&cm_accepts);
42719- target_stat_values[++index] = atomic_read(&cm_disconnects);
42720- target_stat_values[++index] = atomic_read(&cm_connecteds);
42721- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42722- target_stat_values[++index] = atomic_read(&cm_rejects);
42723- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42724- target_stat_values[++index] = atomic_read(&qps_created);
42725- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42726- target_stat_values[++index] = atomic_read(&qps_destroyed);
42727- target_stat_values[++index] = atomic_read(&cm_closes);
42728+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42729+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42730+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42731+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42732+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42733+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42734+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42735+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42736+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42737+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42738+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42739 target_stat_values[++index] = cm_packets_sent;
42740 target_stat_values[++index] = cm_packets_bounced;
42741 target_stat_values[++index] = cm_packets_created;
42742 target_stat_values[++index] = cm_packets_received;
42743 target_stat_values[++index] = cm_packets_dropped;
42744 target_stat_values[++index] = cm_packets_retrans;
42745- target_stat_values[++index] = atomic_read(&cm_listens_created);
42746- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42747+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42748+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42749 target_stat_values[++index] = cm_backlog_drops;
42750- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42751- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42752- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42753- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42754- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42755+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42756+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42757+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42758+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42759+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42760 target_stat_values[++index] = nesadapter->free_4kpbl;
42761 target_stat_values[++index] = nesadapter->free_256pbl;
42762 target_stat_values[++index] = int_mod_timer_init;
42763 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42764 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42765 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42766- target_stat_values[++index] = atomic_read(&pau_qps_created);
42767- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42768+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42769+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42770 }
42771
42772 /**
42773diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42774index 8308e36..ae0d3b5 100644
42775--- a/drivers/infiniband/hw/nes/nes_verbs.c
42776+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42777@@ -46,9 +46,9 @@
42778
42779 #include <rdma/ib_umem.h>
42780
42781-atomic_t mod_qp_timouts;
42782-atomic_t qps_created;
42783-atomic_t sw_qps_destroyed;
42784+atomic_unchecked_t mod_qp_timouts;
42785+atomic_unchecked_t qps_created;
42786+atomic_unchecked_t sw_qps_destroyed;
42787
42788 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42789
42790@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42791 if (init_attr->create_flags)
42792 return ERR_PTR(-EINVAL);
42793
42794- atomic_inc(&qps_created);
42795+ atomic_inc_unchecked(&qps_created);
42796 switch (init_attr->qp_type) {
42797 case IB_QPT_RC:
42798 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42799@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42800 struct iw_cm_event cm_event;
42801 int ret = 0;
42802
42803- atomic_inc(&sw_qps_destroyed);
42804+ atomic_inc_unchecked(&sw_qps_destroyed);
42805 nesqp->destroyed = 1;
42806
42807 /* Blow away the connection if it exists. */
42808diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42809index 1946101..09766d2 100644
42810--- a/drivers/infiniband/hw/qib/qib.h
42811+++ b/drivers/infiniband/hw/qib/qib.h
42812@@ -52,6 +52,7 @@
42813 #include <linux/kref.h>
42814 #include <linux/sched.h>
42815 #include <linux/kthread.h>
42816+#include <linux/slab.h>
42817
42818 #include "qib_common.h"
42819 #include "qib_verbs.h"
42820diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42821index 24c41ba..102d71f 100644
42822--- a/drivers/input/gameport/gameport.c
42823+++ b/drivers/input/gameport/gameport.c
42824@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42825 */
42826 static void gameport_init_port(struct gameport *gameport)
42827 {
42828- static atomic_t gameport_no = ATOMIC_INIT(0);
42829+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42830
42831 __module_get(THIS_MODULE);
42832
42833 mutex_init(&gameport->drv_mutex);
42834 device_initialize(&gameport->dev);
42835 dev_set_name(&gameport->dev, "gameport%lu",
42836- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42837+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42838 gameport->dev.bus = &gameport_bus;
42839 gameport->dev.release = gameport_release_port;
42840 if (gameport->parent)
42841diff --git a/drivers/input/input.c b/drivers/input/input.c
42842index d2965e4..f52b7d7 100644
42843--- a/drivers/input/input.c
42844+++ b/drivers/input/input.c
42845@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42846 */
42847 struct input_dev *input_allocate_device(void)
42848 {
42849- static atomic_t input_no = ATOMIC_INIT(0);
42850+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42851 struct input_dev *dev;
42852
42853 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42854@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42855 INIT_LIST_HEAD(&dev->node);
42856
42857 dev_set_name(&dev->dev, "input%ld",
42858- (unsigned long) atomic_inc_return(&input_no) - 1);
42859+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42860
42861 __module_get(THIS_MODULE);
42862 }
42863diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42864index 04c69af..5f92d00 100644
42865--- a/drivers/input/joystick/sidewinder.c
42866+++ b/drivers/input/joystick/sidewinder.c
42867@@ -30,6 +30,7 @@
42868 #include <linux/kernel.h>
42869 #include <linux/module.h>
42870 #include <linux/slab.h>
42871+#include <linux/sched.h>
42872 #include <linux/init.h>
42873 #include <linux/input.h>
42874 #include <linux/gameport.h>
42875diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42876index 75e3b10..fb390fd 100644
42877--- a/drivers/input/joystick/xpad.c
42878+++ b/drivers/input/joystick/xpad.c
42879@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42880
42881 static int xpad_led_probe(struct usb_xpad *xpad)
42882 {
42883- static atomic_t led_seq = ATOMIC_INIT(0);
42884+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42885 long led_no;
42886 struct xpad_led *led;
42887 struct led_classdev *led_cdev;
42888@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42889 if (!led)
42890 return -ENOMEM;
42891
42892- led_no = (long)atomic_inc_return(&led_seq) - 1;
42893+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42894
42895 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42896 led->xpad = xpad;
42897diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42898index e204f26..8459f15 100644
42899--- a/drivers/input/misc/ims-pcu.c
42900+++ b/drivers/input/misc/ims-pcu.c
42901@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42902
42903 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42904 {
42905- static atomic_t device_no = ATOMIC_INIT(0);
42906+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42907
42908 const struct ims_pcu_device_info *info;
42909 u8 device_id;
42910@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42911 }
42912
42913 /* Device appears to be operable, complete initialization */
42914- pcu->device_no = atomic_inc_return(&device_no) - 1;
42915+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42916
42917 error = ims_pcu_setup_backlight(pcu);
42918 if (error)
42919diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42920index 2f0b39d..7370f13 100644
42921--- a/drivers/input/mouse/psmouse.h
42922+++ b/drivers/input/mouse/psmouse.h
42923@@ -116,7 +116,7 @@ struct psmouse_attribute {
42924 ssize_t (*set)(struct psmouse *psmouse, void *data,
42925 const char *buf, size_t count);
42926 bool protect;
42927-};
42928+} __do_const;
42929 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42930
42931 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42932diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42933index 4c842c3..590b0bf 100644
42934--- a/drivers/input/mousedev.c
42935+++ b/drivers/input/mousedev.c
42936@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42937
42938 spin_unlock_irq(&client->packet_lock);
42939
42940- if (copy_to_user(buffer, data, count))
42941+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42942 return -EFAULT;
42943
42944 return count;
42945diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42946index 8f4c4ab..5fc8a45 100644
42947--- a/drivers/input/serio/serio.c
42948+++ b/drivers/input/serio/serio.c
42949@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42950 */
42951 static void serio_init_port(struct serio *serio)
42952 {
42953- static atomic_t serio_no = ATOMIC_INIT(0);
42954+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42955
42956 __module_get(THIS_MODULE);
42957
42958@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42959 mutex_init(&serio->drv_mutex);
42960 device_initialize(&serio->dev);
42961 dev_set_name(&serio->dev, "serio%ld",
42962- (long)atomic_inc_return(&serio_no) - 1);
42963+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42964 serio->dev.bus = &serio_bus;
42965 serio->dev.release = serio_release_port;
42966 serio->dev.groups = serio_device_attr_groups;
42967diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42968index 59df2e7..8f1cafb 100644
42969--- a/drivers/input/serio/serio_raw.c
42970+++ b/drivers/input/serio/serio_raw.c
42971@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42972
42973 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42974 {
42975- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42976+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42977 struct serio_raw *serio_raw;
42978 int err;
42979
42980@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42981 }
42982
42983 snprintf(serio_raw->name, sizeof(serio_raw->name),
42984- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42985+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42986 kref_init(&serio_raw->kref);
42987 INIT_LIST_HEAD(&serio_raw->client_list);
42988 init_waitqueue_head(&serio_raw->wait);
42989diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42990index e5555fc..937986d 100644
42991--- a/drivers/iommu/iommu.c
42992+++ b/drivers/iommu/iommu.c
42993@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42994 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42995 {
42996 bus_register_notifier(bus, &iommu_bus_nb);
42997- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42998+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42999 }
43000
43001 /**
43002diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43003index 39f81ae..2660096 100644
43004--- a/drivers/iommu/irq_remapping.c
43005+++ b/drivers/iommu/irq_remapping.c
43006@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43007 void panic_if_irq_remap(const char *msg)
43008 {
43009 if (irq_remapping_enabled)
43010- panic(msg);
43011+ panic("%s", msg);
43012 }
43013
43014 static void ir_ack_apic_edge(struct irq_data *data)
43015@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43016
43017 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43018 {
43019- chip->irq_print_chip = ir_print_prefix;
43020- chip->irq_ack = ir_ack_apic_edge;
43021- chip->irq_eoi = ir_ack_apic_level;
43022- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43023+ pax_open_kernel();
43024+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43025+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43026+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43027+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43028+ pax_close_kernel();
43029 }
43030
43031 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43032diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43033index 341c601..e5f407e 100644
43034--- a/drivers/irqchip/irq-gic.c
43035+++ b/drivers/irqchip/irq-gic.c
43036@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43037 * Supported arch specific GIC irq extension.
43038 * Default make them NULL.
43039 */
43040-struct irq_chip gic_arch_extn = {
43041+irq_chip_no_const gic_arch_extn = {
43042 .irq_eoi = NULL,
43043 .irq_mask = NULL,
43044 .irq_unmask = NULL,
43045@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43046 chained_irq_exit(chip, desc);
43047 }
43048
43049-static struct irq_chip gic_chip = {
43050+static irq_chip_no_const gic_chip __read_only = {
43051 .name = "GIC",
43052 .irq_mask = gic_mask_irq,
43053 .irq_unmask = gic_unmask_irq,
43054diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43055index ac6f72b..81150f2 100644
43056--- a/drivers/isdn/capi/capi.c
43057+++ b/drivers/isdn/capi/capi.c
43058@@ -81,8 +81,8 @@ struct capiminor {
43059
43060 struct capi20_appl *ap;
43061 u32 ncci;
43062- atomic_t datahandle;
43063- atomic_t msgid;
43064+ atomic_unchecked_t datahandle;
43065+ atomic_unchecked_t msgid;
43066
43067 struct tty_port port;
43068 int ttyinstop;
43069@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43070 capimsg_setu16(s, 2, mp->ap->applid);
43071 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43072 capimsg_setu8 (s, 5, CAPI_RESP);
43073- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43074+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43075 capimsg_setu32(s, 8, mp->ncci);
43076 capimsg_setu16(s, 12, datahandle);
43077 }
43078@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43079 mp->outbytes -= len;
43080 spin_unlock_bh(&mp->outlock);
43081
43082- datahandle = atomic_inc_return(&mp->datahandle);
43083+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43084 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43085 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43086 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43087 capimsg_setu16(skb->data, 2, mp->ap->applid);
43088 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43089 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43090- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43091+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43092 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43093 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43094 capimsg_setu16(skb->data, 16, len); /* Data length */
43095diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43096index c44950d..10ac276 100644
43097--- a/drivers/isdn/gigaset/bas-gigaset.c
43098+++ b/drivers/isdn/gigaset/bas-gigaset.c
43099@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43100
43101
43102 static const struct gigaset_ops gigops = {
43103- gigaset_write_cmd,
43104- gigaset_write_room,
43105- gigaset_chars_in_buffer,
43106- gigaset_brkchars,
43107- gigaset_init_bchannel,
43108- gigaset_close_bchannel,
43109- gigaset_initbcshw,
43110- gigaset_freebcshw,
43111- gigaset_reinitbcshw,
43112- gigaset_initcshw,
43113- gigaset_freecshw,
43114- gigaset_set_modem_ctrl,
43115- gigaset_baud_rate,
43116- gigaset_set_line_ctrl,
43117- gigaset_isoc_send_skb,
43118- gigaset_isoc_input,
43119+ .write_cmd = gigaset_write_cmd,
43120+ .write_room = gigaset_write_room,
43121+ .chars_in_buffer = gigaset_chars_in_buffer,
43122+ .brkchars = gigaset_brkchars,
43123+ .init_bchannel = gigaset_init_bchannel,
43124+ .close_bchannel = gigaset_close_bchannel,
43125+ .initbcshw = gigaset_initbcshw,
43126+ .freebcshw = gigaset_freebcshw,
43127+ .reinitbcshw = gigaset_reinitbcshw,
43128+ .initcshw = gigaset_initcshw,
43129+ .freecshw = gigaset_freecshw,
43130+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43131+ .baud_rate = gigaset_baud_rate,
43132+ .set_line_ctrl = gigaset_set_line_ctrl,
43133+ .send_skb = gigaset_isoc_send_skb,
43134+ .handle_input = gigaset_isoc_input,
43135 };
43136
43137 /* bas_gigaset_init
43138diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43139index 600c79b..3752bab 100644
43140--- a/drivers/isdn/gigaset/interface.c
43141+++ b/drivers/isdn/gigaset/interface.c
43142@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43143 }
43144 tty->driver_data = cs;
43145
43146- ++cs->port.count;
43147+ atomic_inc(&cs->port.count);
43148
43149- if (cs->port.count == 1) {
43150+ if (atomic_read(&cs->port.count) == 1) {
43151 tty_port_tty_set(&cs->port, tty);
43152 cs->port.low_latency = 1;
43153 }
43154@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43155
43156 if (!cs->connected)
43157 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43158- else if (!cs->port.count)
43159+ else if (!atomic_read(&cs->port.count))
43160 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43161- else if (!--cs->port.count)
43162+ else if (!atomic_dec_return(&cs->port.count))
43163 tty_port_tty_set(&cs->port, NULL);
43164
43165 mutex_unlock(&cs->mutex);
43166diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43167index 8c91fd5..14f13ce 100644
43168--- a/drivers/isdn/gigaset/ser-gigaset.c
43169+++ b/drivers/isdn/gigaset/ser-gigaset.c
43170@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43171 }
43172
43173 static const struct gigaset_ops ops = {
43174- gigaset_write_cmd,
43175- gigaset_write_room,
43176- gigaset_chars_in_buffer,
43177- gigaset_brkchars,
43178- gigaset_init_bchannel,
43179- gigaset_close_bchannel,
43180- gigaset_initbcshw,
43181- gigaset_freebcshw,
43182- gigaset_reinitbcshw,
43183- gigaset_initcshw,
43184- gigaset_freecshw,
43185- gigaset_set_modem_ctrl,
43186- gigaset_baud_rate,
43187- gigaset_set_line_ctrl,
43188- gigaset_m10x_send_skb, /* asyncdata.c */
43189- gigaset_m10x_input, /* asyncdata.c */
43190+ .write_cmd = gigaset_write_cmd,
43191+ .write_room = gigaset_write_room,
43192+ .chars_in_buffer = gigaset_chars_in_buffer,
43193+ .brkchars = gigaset_brkchars,
43194+ .init_bchannel = gigaset_init_bchannel,
43195+ .close_bchannel = gigaset_close_bchannel,
43196+ .initbcshw = gigaset_initbcshw,
43197+ .freebcshw = gigaset_freebcshw,
43198+ .reinitbcshw = gigaset_reinitbcshw,
43199+ .initcshw = gigaset_initcshw,
43200+ .freecshw = gigaset_freecshw,
43201+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43202+ .baud_rate = gigaset_baud_rate,
43203+ .set_line_ctrl = gigaset_set_line_ctrl,
43204+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43205+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43206 };
43207
43208
43209diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43210index d0a41cb..b953e50 100644
43211--- a/drivers/isdn/gigaset/usb-gigaset.c
43212+++ b/drivers/isdn/gigaset/usb-gigaset.c
43213@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43214 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43215 memcpy(cs->hw.usb->bchars, buf, 6);
43216 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43217- 0, 0, &buf, 6, 2000);
43218+ 0, 0, buf, 6, 2000);
43219 }
43220
43221 static void gigaset_freebcshw(struct bc_state *bcs)
43222@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43223 }
43224
43225 static const struct gigaset_ops ops = {
43226- gigaset_write_cmd,
43227- gigaset_write_room,
43228- gigaset_chars_in_buffer,
43229- gigaset_brkchars,
43230- gigaset_init_bchannel,
43231- gigaset_close_bchannel,
43232- gigaset_initbcshw,
43233- gigaset_freebcshw,
43234- gigaset_reinitbcshw,
43235- gigaset_initcshw,
43236- gigaset_freecshw,
43237- gigaset_set_modem_ctrl,
43238- gigaset_baud_rate,
43239- gigaset_set_line_ctrl,
43240- gigaset_m10x_send_skb,
43241- gigaset_m10x_input,
43242+ .write_cmd = gigaset_write_cmd,
43243+ .write_room = gigaset_write_room,
43244+ .chars_in_buffer = gigaset_chars_in_buffer,
43245+ .brkchars = gigaset_brkchars,
43246+ .init_bchannel = gigaset_init_bchannel,
43247+ .close_bchannel = gigaset_close_bchannel,
43248+ .initbcshw = gigaset_initbcshw,
43249+ .freebcshw = gigaset_freebcshw,
43250+ .reinitbcshw = gigaset_reinitbcshw,
43251+ .initcshw = gigaset_initcshw,
43252+ .freecshw = gigaset_freecshw,
43253+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43254+ .baud_rate = gigaset_baud_rate,
43255+ .set_line_ctrl = gigaset_set_line_ctrl,
43256+ .send_skb = gigaset_m10x_send_skb,
43257+ .handle_input = gigaset_m10x_input,
43258 };
43259
43260 /*
43261diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43262index 4d9b195..455075c 100644
43263--- a/drivers/isdn/hardware/avm/b1.c
43264+++ b/drivers/isdn/hardware/avm/b1.c
43265@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43266 }
43267 if (left) {
43268 if (t4file->user) {
43269- if (copy_from_user(buf, dp, left))
43270+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43271 return -EFAULT;
43272 } else {
43273 memcpy(buf, dp, left);
43274@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43275 }
43276 if (left) {
43277 if (config->user) {
43278- if (copy_from_user(buf, dp, left))
43279+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43280 return -EFAULT;
43281 } else {
43282 memcpy(buf, dp, left);
43283diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43284index 9bb12ba..d4262f7 100644
43285--- a/drivers/isdn/i4l/isdn_common.c
43286+++ b/drivers/isdn/i4l/isdn_common.c
43287@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43288 } else
43289 return -EINVAL;
43290 case IIOCDBGVAR:
43291+ if (!capable(CAP_SYS_RAWIO))
43292+ return -EPERM;
43293 if (arg) {
43294 if (copy_to_user(argp, &dev, sizeof(ulong)))
43295 return -EFAULT;
43296diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43297index 91d5730..336523e 100644
43298--- a/drivers/isdn/i4l/isdn_concap.c
43299+++ b/drivers/isdn/i4l/isdn_concap.c
43300@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43301 }
43302
43303 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43304- &isdn_concap_dl_data_req,
43305- &isdn_concap_dl_connect_req,
43306- &isdn_concap_dl_disconn_req
43307+ .data_req = &isdn_concap_dl_data_req,
43308+ .connect_req = &isdn_concap_dl_connect_req,
43309+ .disconn_req = &isdn_concap_dl_disconn_req
43310 };
43311
43312 /* The following should better go into a dedicated source file such that
43313diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43314index 3c5f249..5fac4d0 100644
43315--- a/drivers/isdn/i4l/isdn_tty.c
43316+++ b/drivers/isdn/i4l/isdn_tty.c
43317@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43318
43319 #ifdef ISDN_DEBUG_MODEM_OPEN
43320 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43321- port->count);
43322+ atomic_read(&port->count));
43323 #endif
43324- port->count++;
43325+ atomic_inc(&port->count);
43326 port->tty = tty;
43327 /*
43328 * Start up serial port
43329@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43330 #endif
43331 return;
43332 }
43333- if ((tty->count == 1) && (port->count != 1)) {
43334+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43335 /*
43336 * Uh, oh. tty->count is 1, which means that the tty
43337 * structure will be freed. Info->count should always
43338@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43339 * serial port won't be shutdown.
43340 */
43341 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43342- "info->count is %d\n", port->count);
43343- port->count = 1;
43344+ "info->count is %d\n", atomic_read(&port->count));
43345+ atomic_set(&port->count, 1);
43346 }
43347- if (--port->count < 0) {
43348+ if (atomic_dec_return(&port->count) < 0) {
43349 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43350- info->line, port->count);
43351- port->count = 0;
43352+ info->line, atomic_read(&port->count));
43353+ atomic_set(&port->count, 0);
43354 }
43355- if (port->count) {
43356+ if (atomic_read(&port->count)) {
43357 #ifdef ISDN_DEBUG_MODEM_OPEN
43358 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43359 #endif
43360@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43361 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43362 return;
43363 isdn_tty_shutdown(info);
43364- port->count = 0;
43365+ atomic_set(&port->count, 0);
43366 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43367 port->tty = NULL;
43368 wake_up_interruptible(&port->open_wait);
43369@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43370 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43371 modem_info *info = &dev->mdm.info[i];
43372
43373- if (info->port.count == 0)
43374+ if (atomic_read(&info->port.count) == 0)
43375 continue;
43376 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43377 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43378diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43379index e2d4e58..40cd045 100644
43380--- a/drivers/isdn/i4l/isdn_x25iface.c
43381+++ b/drivers/isdn/i4l/isdn_x25iface.c
43382@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43383
43384
43385 static struct concap_proto_ops ix25_pops = {
43386- &isdn_x25iface_proto_new,
43387- &isdn_x25iface_proto_del,
43388- &isdn_x25iface_proto_restart,
43389- &isdn_x25iface_proto_close,
43390- &isdn_x25iface_xmit,
43391- &isdn_x25iface_receive,
43392- &isdn_x25iface_connect_ind,
43393- &isdn_x25iface_disconn_ind
43394+ .proto_new = &isdn_x25iface_proto_new,
43395+ .proto_del = &isdn_x25iface_proto_del,
43396+ .restart = &isdn_x25iface_proto_restart,
43397+ .close = &isdn_x25iface_proto_close,
43398+ .encap_and_xmit = &isdn_x25iface_xmit,
43399+ .data_ind = &isdn_x25iface_receive,
43400+ .connect_ind = &isdn_x25iface_connect_ind,
43401+ .disconn_ind = &isdn_x25iface_disconn_ind
43402 };
43403
43404 /* error message helper function */
43405diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43406index 53d487f..f020f41 100644
43407--- a/drivers/isdn/icn/icn.c
43408+++ b/drivers/isdn/icn/icn.c
43409@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43410 if (count > len)
43411 count = len;
43412 if (user) {
43413- if (copy_from_user(msg, buf, count))
43414+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43415 return -EFAULT;
43416 } else
43417 memcpy(msg, buf, count);
43418diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43419index a4f05c5..1433bc5 100644
43420--- a/drivers/isdn/mISDN/dsp_cmx.c
43421+++ b/drivers/isdn/mISDN/dsp_cmx.c
43422@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43423 static u16 dsp_count; /* last sample count */
43424 static int dsp_count_valid; /* if we have last sample count */
43425
43426-void
43427+void __intentional_overflow(-1)
43428 dsp_cmx_send(void *arg)
43429 {
43430 struct dsp_conf *conf;
43431diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43432index d93e245..e7ece6b 100644
43433--- a/drivers/leds/leds-clevo-mail.c
43434+++ b/drivers/leds/leds-clevo-mail.c
43435@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43436 * detected as working, but in reality it is not) as low as
43437 * possible.
43438 */
43439-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43440+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43441 {
43442 .callback = clevo_mail_led_dmi_callback,
43443 .ident = "Clevo D410J",
43444diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43445index 5b8f938..b73d657 100644
43446--- a/drivers/leds/leds-ss4200.c
43447+++ b/drivers/leds/leds-ss4200.c
43448@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43449 * detected as working, but in reality it is not) as low as
43450 * possible.
43451 */
43452-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43453+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43454 {
43455 .callback = ss4200_led_dmi_callback,
43456 .ident = "Intel SS4200-E",
43457diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43458index 0bf1e4e..b4bf44e 100644
43459--- a/drivers/lguest/core.c
43460+++ b/drivers/lguest/core.c
43461@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43462 * The end address needs +1 because __get_vm_area allocates an
43463 * extra guard page, so we need space for that.
43464 */
43465+
43466+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43467+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43468+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43469+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43470+#else
43471 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43472 VM_ALLOC, switcher_addr, switcher_addr
43473 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43474+#endif
43475+
43476 if (!switcher_vma) {
43477 err = -ENOMEM;
43478 printk("lguest: could not map switcher pages high\n");
43479@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43480 * Now the Switcher is mapped at the right address, we can't fail!
43481 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43482 */
43483- memcpy(switcher_vma->addr, start_switcher_text,
43484+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43485 end_switcher_text - start_switcher_text);
43486
43487 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43488diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43489index bfb39bb..08a603b 100644
43490--- a/drivers/lguest/page_tables.c
43491+++ b/drivers/lguest/page_tables.c
43492@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43493 /*:*/
43494
43495 #ifdef CONFIG_X86_PAE
43496-static void release_pmd(pmd_t *spmd)
43497+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43498 {
43499 /* If the entry's not present, there's nothing to release. */
43500 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43501diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43502index 922a1ac..9dd0c2a 100644
43503--- a/drivers/lguest/x86/core.c
43504+++ b/drivers/lguest/x86/core.c
43505@@ -59,7 +59,7 @@ static struct {
43506 /* Offset from where switcher.S was compiled to where we've copied it */
43507 static unsigned long switcher_offset(void)
43508 {
43509- return switcher_addr - (unsigned long)start_switcher_text;
43510+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43511 }
43512
43513 /* This cpu's struct lguest_pages (after the Switcher text page) */
43514@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43515 * These copies are pretty cheap, so we do them unconditionally: */
43516 /* Save the current Host top-level page directory.
43517 */
43518+
43519+#ifdef CONFIG_PAX_PER_CPU_PGD
43520+ pages->state.host_cr3 = read_cr3();
43521+#else
43522 pages->state.host_cr3 = __pa(current->mm->pgd);
43523+#endif
43524+
43525 /*
43526 * Set up the Guest's page tables to see this CPU's pages (and no
43527 * other CPU's pages).
43528@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43529 * compiled-in switcher code and the high-mapped copy we just made.
43530 */
43531 for (i = 0; i < IDT_ENTRIES; i++)
43532- default_idt_entries[i] += switcher_offset();
43533+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43534
43535 /*
43536 * Set up the Switcher's per-cpu areas.
43537@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43538 * it will be undisturbed when we switch. To change %cs and jump we
43539 * need this structure to feed to Intel's "lcall" instruction.
43540 */
43541- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43542+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43543 lguest_entry.segment = LGUEST_CS;
43544
43545 /*
43546diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43547index 40634b0..4f5855e 100644
43548--- a/drivers/lguest/x86/switcher_32.S
43549+++ b/drivers/lguest/x86/switcher_32.S
43550@@ -87,6 +87,7 @@
43551 #include <asm/page.h>
43552 #include <asm/segment.h>
43553 #include <asm/lguest.h>
43554+#include <asm/processor-flags.h>
43555
43556 // We mark the start of the code to copy
43557 // It's placed in .text tho it's never run here
43558@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43559 // Changes type when we load it: damn Intel!
43560 // For after we switch over our page tables
43561 // That entry will be read-only: we'd crash.
43562+
43563+#ifdef CONFIG_PAX_KERNEXEC
43564+ mov %cr0, %edx
43565+ xor $X86_CR0_WP, %edx
43566+ mov %edx, %cr0
43567+#endif
43568+
43569 movl $(GDT_ENTRY_TSS*8), %edx
43570 ltr %dx
43571
43572@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43573 // Let's clear it again for our return.
43574 // The GDT descriptor of the Host
43575 // Points to the table after two "size" bytes
43576- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43577+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43578 // Clear "used" from type field (byte 5, bit 2)
43579- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43580+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43581+
43582+#ifdef CONFIG_PAX_KERNEXEC
43583+ mov %cr0, %eax
43584+ xor $X86_CR0_WP, %eax
43585+ mov %eax, %cr0
43586+#endif
43587
43588 // Once our page table's switched, the Guest is live!
43589 // The Host fades as we run this final step.
43590@@ -295,13 +309,12 @@ deliver_to_host:
43591 // I consulted gcc, and it gave
43592 // These instructions, which I gladly credit:
43593 leal (%edx,%ebx,8), %eax
43594- movzwl (%eax),%edx
43595- movl 4(%eax), %eax
43596- xorw %ax, %ax
43597- orl %eax, %edx
43598+ movl 4(%eax), %edx
43599+ movw (%eax), %dx
43600 // Now the address of the handler's in %edx
43601 // We call it now: its "iret" drops us home.
43602- jmp *%edx
43603+ ljmp $__KERNEL_CS, $1f
43604+1: jmp *%edx
43605
43606 // Every interrupt can come to us here
43607 // But we must truly tell each apart.
43608diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43609index 9762f1b..3e79734 100644
43610--- a/drivers/md/bcache/closure.h
43611+++ b/drivers/md/bcache/closure.h
43612@@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43613 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43614 struct workqueue_struct *wq)
43615 {
43616- BUG_ON(object_is_on_stack(cl));
43617+ BUG_ON(object_starts_on_stack(cl));
43618 closure_set_ip(cl);
43619 cl->fn = fn;
43620 cl->wq = wq;
43621diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43622index 12dc29b..1596277 100644
43623--- a/drivers/md/bitmap.c
43624+++ b/drivers/md/bitmap.c
43625@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43626 chunk_kb ? "KB" : "B");
43627 if (bitmap->storage.file) {
43628 seq_printf(seq, ", file: ");
43629- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43630+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43631 }
43632
43633 seq_printf(seq, "\n");
43634diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43635index 5152142..623d141 100644
43636--- a/drivers/md/dm-ioctl.c
43637+++ b/drivers/md/dm-ioctl.c
43638@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43639 cmd == DM_LIST_VERSIONS_CMD)
43640 return 0;
43641
43642- if ((cmd == DM_DEV_CREATE_CMD)) {
43643+ if (cmd == DM_DEV_CREATE_CMD) {
43644 if (!*param->name) {
43645 DMWARN("name not supplied when creating device");
43646 return -EINVAL;
43647diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43648index 9584443..9fc9ac9 100644
43649--- a/drivers/md/dm-raid1.c
43650+++ b/drivers/md/dm-raid1.c
43651@@ -40,7 +40,7 @@ enum dm_raid1_error {
43652
43653 struct mirror {
43654 struct mirror_set *ms;
43655- atomic_t error_count;
43656+ atomic_unchecked_t error_count;
43657 unsigned long error_type;
43658 struct dm_dev *dev;
43659 sector_t offset;
43660@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43661 struct mirror *m;
43662
43663 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43664- if (!atomic_read(&m->error_count))
43665+ if (!atomic_read_unchecked(&m->error_count))
43666 return m;
43667
43668 return NULL;
43669@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43670 * simple way to tell if a device has encountered
43671 * errors.
43672 */
43673- atomic_inc(&m->error_count);
43674+ atomic_inc_unchecked(&m->error_count);
43675
43676 if (test_and_set_bit(error_type, &m->error_type))
43677 return;
43678@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43679 struct mirror *m = get_default_mirror(ms);
43680
43681 do {
43682- if (likely(!atomic_read(&m->error_count)))
43683+ if (likely(!atomic_read_unchecked(&m->error_count)))
43684 return m;
43685
43686 if (m-- == ms->mirror)
43687@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43688 {
43689 struct mirror *default_mirror = get_default_mirror(m->ms);
43690
43691- return !atomic_read(&default_mirror->error_count);
43692+ return !atomic_read_unchecked(&default_mirror->error_count);
43693 }
43694
43695 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43696@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43697 */
43698 if (likely(region_in_sync(ms, region, 1)))
43699 m = choose_mirror(ms, bio->bi_sector);
43700- else if (m && atomic_read(&m->error_count))
43701+ else if (m && atomic_read_unchecked(&m->error_count))
43702 m = NULL;
43703
43704 if (likely(m))
43705@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43706 }
43707
43708 ms->mirror[mirror].ms = ms;
43709- atomic_set(&(ms->mirror[mirror].error_count), 0);
43710+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43711 ms->mirror[mirror].error_type = 0;
43712 ms->mirror[mirror].offset = offset;
43713
43714@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43715 */
43716 static char device_status_char(struct mirror *m)
43717 {
43718- if (!atomic_read(&(m->error_count)))
43719+ if (!atomic_read_unchecked(&(m->error_count)))
43720 return 'A';
43721
43722 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43723diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43724index 28a9012..9c0f6a5 100644
43725--- a/drivers/md/dm-stats.c
43726+++ b/drivers/md/dm-stats.c
43727@@ -382,7 +382,7 @@ do_sync_free:
43728 synchronize_rcu_expedited();
43729 dm_stat_free(&s->rcu_head);
43730 } else {
43731- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43732+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43733 call_rcu(&s->rcu_head, dm_stat_free);
43734 }
43735 return 0;
43736@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43737 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43738 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43739 ));
43740- ACCESS_ONCE(last->last_sector) = end_sector;
43741- ACCESS_ONCE(last->last_rw) = bi_rw;
43742+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43743+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43744 }
43745
43746 rcu_read_lock();
43747diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43748index 73c1712..7347292 100644
43749--- a/drivers/md/dm-stripe.c
43750+++ b/drivers/md/dm-stripe.c
43751@@ -21,7 +21,7 @@ struct stripe {
43752 struct dm_dev *dev;
43753 sector_t physical_start;
43754
43755- atomic_t error_count;
43756+ atomic_unchecked_t error_count;
43757 };
43758
43759 struct stripe_c {
43760@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43761 kfree(sc);
43762 return r;
43763 }
43764- atomic_set(&(sc->stripe[i].error_count), 0);
43765+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43766 }
43767
43768 ti->private = sc;
43769@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43770 DMEMIT("%d ", sc->stripes);
43771 for (i = 0; i < sc->stripes; i++) {
43772 DMEMIT("%s ", sc->stripe[i].dev->name);
43773- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43774+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43775 'D' : 'A';
43776 }
43777 buffer[i] = '\0';
43778@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43779 */
43780 for (i = 0; i < sc->stripes; i++)
43781 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43782- atomic_inc(&(sc->stripe[i].error_count));
43783- if (atomic_read(&(sc->stripe[i].error_count)) <
43784+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43785+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43786 DM_IO_ERROR_THRESHOLD)
43787 schedule_work(&sc->trigger_event);
43788 }
43789diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43790index 3ba6a38..b0fa9b0 100644
43791--- a/drivers/md/dm-table.c
43792+++ b/drivers/md/dm-table.c
43793@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43794 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43795 struct mapped_device *md)
43796 {
43797- static char *_claim_ptr = "I belong to device-mapper";
43798+ static char _claim_ptr[] = "I belong to device-mapper";
43799 struct block_device *bdev;
43800
43801 int r;
43802@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43803 if (!dev_size)
43804 return 0;
43805
43806- if ((start >= dev_size) || (start + len > dev_size)) {
43807+ if ((start >= dev_size) || (len > dev_size - start)) {
43808 DMWARN("%s: %s too small for target: "
43809 "start=%llu, len=%llu, dev_size=%llu",
43810 dm_device_name(ti->table->md), bdevname(bdev, b),
43811diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43812index 3bb4506..56e20cc 100644
43813--- a/drivers/md/dm-thin-metadata.c
43814+++ b/drivers/md/dm-thin-metadata.c
43815@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43816 {
43817 pmd->info.tm = pmd->tm;
43818 pmd->info.levels = 2;
43819- pmd->info.value_type.context = pmd->data_sm;
43820+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43821 pmd->info.value_type.size = sizeof(__le64);
43822 pmd->info.value_type.inc = data_block_inc;
43823 pmd->info.value_type.dec = data_block_dec;
43824@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43825
43826 pmd->bl_info.tm = pmd->tm;
43827 pmd->bl_info.levels = 1;
43828- pmd->bl_info.value_type.context = pmd->data_sm;
43829+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43830 pmd->bl_info.value_type.size = sizeof(__le64);
43831 pmd->bl_info.value_type.inc = data_block_inc;
43832 pmd->bl_info.value_type.dec = data_block_dec;
43833diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43834index b49c762..c9503cf 100644
43835--- a/drivers/md/dm.c
43836+++ b/drivers/md/dm.c
43837@@ -185,9 +185,9 @@ struct mapped_device {
43838 /*
43839 * Event handling.
43840 */
43841- atomic_t event_nr;
43842+ atomic_unchecked_t event_nr;
43843 wait_queue_head_t eventq;
43844- atomic_t uevent_seq;
43845+ atomic_unchecked_t uevent_seq;
43846 struct list_head uevent_list;
43847 spinlock_t uevent_lock; /* Protect access to uevent_list */
43848
43849@@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43850 spin_lock_init(&md->deferred_lock);
43851 atomic_set(&md->holders, 1);
43852 atomic_set(&md->open_count, 0);
43853- atomic_set(&md->event_nr, 0);
43854- atomic_set(&md->uevent_seq, 0);
43855+ atomic_set_unchecked(&md->event_nr, 0);
43856+ atomic_set_unchecked(&md->uevent_seq, 0);
43857 INIT_LIST_HEAD(&md->uevent_list);
43858 spin_lock_init(&md->uevent_lock);
43859
43860@@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43861
43862 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43863
43864- atomic_inc(&md->event_nr);
43865+ atomic_inc_unchecked(&md->event_nr);
43866 wake_up(&md->eventq);
43867 }
43868
43869@@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43870
43871 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43872 {
43873- return atomic_add_return(1, &md->uevent_seq);
43874+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43875 }
43876
43877 uint32_t dm_get_event_nr(struct mapped_device *md)
43878 {
43879- return atomic_read(&md->event_nr);
43880+ return atomic_read_unchecked(&md->event_nr);
43881 }
43882
43883 int dm_wait_event(struct mapped_device *md, int event_nr)
43884 {
43885 return wait_event_interruptible(md->eventq,
43886- (event_nr != atomic_read(&md->event_nr)));
43887+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43888 }
43889
43890 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43891diff --git a/drivers/md/md.c b/drivers/md/md.c
43892index 369d919..ba7049c 100644
43893--- a/drivers/md/md.c
43894+++ b/drivers/md/md.c
43895@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43896 * start build, activate spare
43897 */
43898 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43899-static atomic_t md_event_count;
43900+static atomic_unchecked_t md_event_count;
43901 void md_new_event(struct mddev *mddev)
43902 {
43903- atomic_inc(&md_event_count);
43904+ atomic_inc_unchecked(&md_event_count);
43905 wake_up(&md_event_waiters);
43906 }
43907 EXPORT_SYMBOL_GPL(md_new_event);
43908@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43909 */
43910 static void md_new_event_inintr(struct mddev *mddev)
43911 {
43912- atomic_inc(&md_event_count);
43913+ atomic_inc_unchecked(&md_event_count);
43914 wake_up(&md_event_waiters);
43915 }
43916
43917@@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43918 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43919 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43920 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43921- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43922+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43923
43924 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43925 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43926@@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43927 else
43928 sb->resync_offset = cpu_to_le64(0);
43929
43930- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43931+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43932
43933 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43934 sb->size = cpu_to_le64(mddev->dev_sectors);
43935@@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43936 static ssize_t
43937 errors_show(struct md_rdev *rdev, char *page)
43938 {
43939- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43940+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43941 }
43942
43943 static ssize_t
43944@@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43945 char *e;
43946 unsigned long n = simple_strtoul(buf, &e, 10);
43947 if (*buf && (*e == 0 || *e == '\n')) {
43948- atomic_set(&rdev->corrected_errors, n);
43949+ atomic_set_unchecked(&rdev->corrected_errors, n);
43950 return len;
43951 }
43952 return -EINVAL;
43953@@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43954 rdev->sb_loaded = 0;
43955 rdev->bb_page = NULL;
43956 atomic_set(&rdev->nr_pending, 0);
43957- atomic_set(&rdev->read_errors, 0);
43958- atomic_set(&rdev->corrected_errors, 0);
43959+ atomic_set_unchecked(&rdev->read_errors, 0);
43960+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43961
43962 INIT_LIST_HEAD(&rdev->same_set);
43963 init_waitqueue_head(&rdev->blocked_wait);
43964@@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43965
43966 spin_unlock(&pers_lock);
43967 seq_printf(seq, "\n");
43968- seq->poll_event = atomic_read(&md_event_count);
43969+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43970 return 0;
43971 }
43972 if (v == (void*)2) {
43973@@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43974 return error;
43975
43976 seq = file->private_data;
43977- seq->poll_event = atomic_read(&md_event_count);
43978+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43979 return error;
43980 }
43981
43982@@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43983 /* always allow read */
43984 mask = POLLIN | POLLRDNORM;
43985
43986- if (seq->poll_event != atomic_read(&md_event_count))
43987+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43988 mask |= POLLERR | POLLPRI;
43989 return mask;
43990 }
43991@@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43992 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43993 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43994 (int)part_stat_read(&disk->part0, sectors[1]) -
43995- atomic_read(&disk->sync_io);
43996+ atomic_read_unchecked(&disk->sync_io);
43997 /* sync IO will cause sync_io to increase before the disk_stats
43998 * as sync_io is counted when a request starts, and
43999 * disk_stats is counted when it completes.
44000diff --git a/drivers/md/md.h b/drivers/md/md.h
44001index 0095ec8..c89277a 100644
44002--- a/drivers/md/md.h
44003+++ b/drivers/md/md.h
44004@@ -94,13 +94,13 @@ struct md_rdev {
44005 * only maintained for arrays that
44006 * support hot removal
44007 */
44008- atomic_t read_errors; /* number of consecutive read errors that
44009+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
44010 * we have tried to ignore.
44011 */
44012 struct timespec last_read_error; /* monotonic time since our
44013 * last read error
44014 */
44015- atomic_t corrected_errors; /* number of corrected read errors,
44016+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44017 * for reporting to userspace and storing
44018 * in superblock.
44019 */
44020@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44021
44022 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44023 {
44024- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44025+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44026 }
44027
44028 struct md_personality
44029diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44030index 3e6d115..ffecdeb 100644
44031--- a/drivers/md/persistent-data/dm-space-map.h
44032+++ b/drivers/md/persistent-data/dm-space-map.h
44033@@ -71,6 +71,7 @@ struct dm_space_map {
44034 dm_sm_threshold_fn fn,
44035 void *context);
44036 };
44037+typedef struct dm_space_map __no_const dm_space_map_no_const;
44038
44039 /*----------------------------------------------------------------*/
44040
44041diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44042index 63b2e8d..225f16b 100644
44043--- a/drivers/md/raid1.c
44044+++ b/drivers/md/raid1.c
44045@@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44046 if (r1_sync_page_io(rdev, sect, s,
44047 bio->bi_io_vec[idx].bv_page,
44048 READ) != 0)
44049- atomic_add(s, &rdev->corrected_errors);
44050+ atomic_add_unchecked(s, &rdev->corrected_errors);
44051 }
44052 sectors -= s;
44053 sect += s;
44054@@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44055 test_bit(In_sync, &rdev->flags)) {
44056 if (r1_sync_page_io(rdev, sect, s,
44057 conf->tmppage, READ)) {
44058- atomic_add(s, &rdev->corrected_errors);
44059+ atomic_add_unchecked(s, &rdev->corrected_errors);
44060 printk(KERN_INFO
44061 "md/raid1:%s: read error corrected "
44062 "(%d sectors at %llu on %s)\n",
44063diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44064index 06eeb99..770613e 100644
44065--- a/drivers/md/raid10.c
44066+++ b/drivers/md/raid10.c
44067@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44068 /* The write handler will notice the lack of
44069 * R10BIO_Uptodate and record any errors etc
44070 */
44071- atomic_add(r10_bio->sectors,
44072+ atomic_add_unchecked(r10_bio->sectors,
44073 &conf->mirrors[d].rdev->corrected_errors);
44074
44075 /* for reconstruct, we always reschedule after a read.
44076@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44077 {
44078 struct timespec cur_time_mon;
44079 unsigned long hours_since_last;
44080- unsigned int read_errors = atomic_read(&rdev->read_errors);
44081+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44082
44083 ktime_get_ts(&cur_time_mon);
44084
44085@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44086 * overflowing the shift of read_errors by hours_since_last.
44087 */
44088 if (hours_since_last >= 8 * sizeof(read_errors))
44089- atomic_set(&rdev->read_errors, 0);
44090+ atomic_set_unchecked(&rdev->read_errors, 0);
44091 else
44092- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44093+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44094 }
44095
44096 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44097@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44098 return;
44099
44100 check_decay_read_errors(mddev, rdev);
44101- atomic_inc(&rdev->read_errors);
44102- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44103+ atomic_inc_unchecked(&rdev->read_errors);
44104+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44105 char b[BDEVNAME_SIZE];
44106 bdevname(rdev->bdev, b);
44107
44108@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44109 "md/raid10:%s: %s: Raid device exceeded "
44110 "read_error threshold [cur %d:max %d]\n",
44111 mdname(mddev), b,
44112- atomic_read(&rdev->read_errors), max_read_errors);
44113+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44114 printk(KERN_NOTICE
44115 "md/raid10:%s: %s: Failing raid device\n",
44116 mdname(mddev), b);
44117@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44118 sect +
44119 choose_data_offset(r10_bio, rdev)),
44120 bdevname(rdev->bdev, b));
44121- atomic_add(s, &rdev->corrected_errors);
44122+ atomic_add_unchecked(s, &rdev->corrected_errors);
44123 }
44124
44125 rdev_dec_pending(rdev, mddev);
44126diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44127index 48cdec8..c7726b1 100644
44128--- a/drivers/md/raid5.c
44129+++ b/drivers/md/raid5.c
44130@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44131 mdname(conf->mddev), STRIPE_SECTORS,
44132 (unsigned long long)s,
44133 bdevname(rdev->bdev, b));
44134- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44135+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44136 clear_bit(R5_ReadError, &sh->dev[i].flags);
44137 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44138 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44139 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44140
44141- if (atomic_read(&rdev->read_errors))
44142- atomic_set(&rdev->read_errors, 0);
44143+ if (atomic_read_unchecked(&rdev->read_errors))
44144+ atomic_set_unchecked(&rdev->read_errors, 0);
44145 } else {
44146 const char *bdn = bdevname(rdev->bdev, b);
44147 int retry = 0;
44148 int set_bad = 0;
44149
44150 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44151- atomic_inc(&rdev->read_errors);
44152+ atomic_inc_unchecked(&rdev->read_errors);
44153 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44154 printk_ratelimited(
44155 KERN_WARNING
44156@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44157 mdname(conf->mddev),
44158 (unsigned long long)s,
44159 bdn);
44160- } else if (atomic_read(&rdev->read_errors)
44161+ } else if (atomic_read_unchecked(&rdev->read_errors)
44162 > conf->max_nr_stripes)
44163 printk(KERN_WARNING
44164 "md/raid:%s: Too many read errors, failing device %s.\n",
44165diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44166index 983db75..ef9248c 100644
44167--- a/drivers/media/dvb-core/dvbdev.c
44168+++ b/drivers/media/dvb-core/dvbdev.c
44169@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44170 const struct dvb_device *template, void *priv, int type)
44171 {
44172 struct dvb_device *dvbdev;
44173- struct file_operations *dvbdevfops;
44174+ file_operations_no_const *dvbdevfops;
44175 struct device *clsdev;
44176 int minor;
44177 int id;
44178diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44179index 9b6c3bb..baeb5c7 100644
44180--- a/drivers/media/dvb-frontends/dib3000.h
44181+++ b/drivers/media/dvb-frontends/dib3000.h
44182@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44183 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44184 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44185 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44186-};
44187+} __no_const;
44188
44189 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44190 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44191diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44192index ed8cb90..5ef7f79 100644
44193--- a/drivers/media/pci/cx88/cx88-video.c
44194+++ b/drivers/media/pci/cx88/cx88-video.c
44195@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44196
44197 /* ------------------------------------------------------------------ */
44198
44199-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44200-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44201-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44202+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44203+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44204+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44205
44206 module_param_array(video_nr, int, NULL, 0444);
44207 module_param_array(vbi_nr, int, NULL, 0444);
44208diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44209index 802642d..5534900 100644
44210--- a/drivers/media/pci/ivtv/ivtv-driver.c
44211+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44212@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44213 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44214
44215 /* ivtv instance counter */
44216-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44217+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44218
44219 /* Parameter declarations */
44220 static int cardtype[IVTV_MAX_CARDS];
44221diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44222index dfd0a21..6bbb465 100644
44223--- a/drivers/media/platform/omap/omap_vout.c
44224+++ b/drivers/media/platform/omap/omap_vout.c
44225@@ -63,7 +63,6 @@ enum omap_vout_channels {
44226 OMAP_VIDEO2,
44227 };
44228
44229-static struct videobuf_queue_ops video_vbq_ops;
44230 /* Variables configurable through module params*/
44231 static u32 video1_numbuffers = 3;
44232 static u32 video2_numbuffers = 3;
44233@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44234 {
44235 struct videobuf_queue *q;
44236 struct omap_vout_device *vout = NULL;
44237+ static struct videobuf_queue_ops video_vbq_ops = {
44238+ .buf_setup = omap_vout_buffer_setup,
44239+ .buf_prepare = omap_vout_buffer_prepare,
44240+ .buf_release = omap_vout_buffer_release,
44241+ .buf_queue = omap_vout_buffer_queue,
44242+ };
44243
44244 vout = video_drvdata(file);
44245 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44246@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44247 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44248
44249 q = &vout->vbq;
44250- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44251- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44252- video_vbq_ops.buf_release = omap_vout_buffer_release;
44253- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44254 spin_lock_init(&vout->vbq_lock);
44255
44256 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44257diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44258index fb2acc5..a2fcbdc4 100644
44259--- a/drivers/media/platform/s5p-tv/mixer.h
44260+++ b/drivers/media/platform/s5p-tv/mixer.h
44261@@ -156,7 +156,7 @@ struct mxr_layer {
44262 /** layer index (unique identifier) */
44263 int idx;
44264 /** callbacks for layer methods */
44265- struct mxr_layer_ops ops;
44266+ struct mxr_layer_ops *ops;
44267 /** format array */
44268 const struct mxr_format **fmt_array;
44269 /** size of format array */
44270diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44271index 74344c7..a39e70e 100644
44272--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44273+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44274@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44275 {
44276 struct mxr_layer *layer;
44277 int ret;
44278- struct mxr_layer_ops ops = {
44279+ static struct mxr_layer_ops ops = {
44280 .release = mxr_graph_layer_release,
44281 .buffer_set = mxr_graph_buffer_set,
44282 .stream_set = mxr_graph_stream_set,
44283diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44284index b713403..53cb5ad 100644
44285--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44286+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44287@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44288 layer->update_buf = next;
44289 }
44290
44291- layer->ops.buffer_set(layer, layer->update_buf);
44292+ layer->ops->buffer_set(layer, layer->update_buf);
44293
44294 if (done && done != layer->shadow_buf)
44295 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44296diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44297index 81b97db..b089ccd 100644
44298--- a/drivers/media/platform/s5p-tv/mixer_video.c
44299+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44300@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44301 layer->geo.src.height = layer->geo.src.full_height;
44302
44303 mxr_geometry_dump(mdev, &layer->geo);
44304- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44305+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44306 mxr_geometry_dump(mdev, &layer->geo);
44307 }
44308
44309@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44310 layer->geo.dst.full_width = mbus_fmt.width;
44311 layer->geo.dst.full_height = mbus_fmt.height;
44312 layer->geo.dst.field = mbus_fmt.field;
44313- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44314+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44315
44316 mxr_geometry_dump(mdev, &layer->geo);
44317 }
44318@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44319 /* set source size to highest accepted value */
44320 geo->src.full_width = max(geo->dst.full_width, pix->width);
44321 geo->src.full_height = max(geo->dst.full_height, pix->height);
44322- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44323+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44324 mxr_geometry_dump(mdev, &layer->geo);
44325 /* set cropping to total visible screen */
44326 geo->src.width = pix->width;
44327@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44328 geo->src.x_offset = 0;
44329 geo->src.y_offset = 0;
44330 /* assure consistency of geometry */
44331- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44332+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44333 mxr_geometry_dump(mdev, &layer->geo);
44334 /* set full size to lowest possible value */
44335 geo->src.full_width = 0;
44336 geo->src.full_height = 0;
44337- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44338+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44339 mxr_geometry_dump(mdev, &layer->geo);
44340
44341 /* returning results */
44342@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44343 target->width = s->r.width;
44344 target->height = s->r.height;
44345
44346- layer->ops.fix_geometry(layer, stage, s->flags);
44347+ layer->ops->fix_geometry(layer, stage, s->flags);
44348
44349 /* retrieve update selection rectangle */
44350 res.left = target->x_offset;
44351@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44352 mxr_output_get(mdev);
44353
44354 mxr_layer_update_output(layer);
44355- layer->ops.format_set(layer);
44356+ layer->ops->format_set(layer);
44357 /* enabling layer in hardware */
44358 spin_lock_irqsave(&layer->enq_slock, flags);
44359 layer->state = MXR_LAYER_STREAMING;
44360 spin_unlock_irqrestore(&layer->enq_slock, flags);
44361
44362- layer->ops.stream_set(layer, MXR_ENABLE);
44363+ layer->ops->stream_set(layer, MXR_ENABLE);
44364 mxr_streamer_get(mdev);
44365
44366 return 0;
44367@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44368 spin_unlock_irqrestore(&layer->enq_slock, flags);
44369
44370 /* disabling layer in hardware */
44371- layer->ops.stream_set(layer, MXR_DISABLE);
44372+ layer->ops->stream_set(layer, MXR_DISABLE);
44373 /* remove one streamer */
44374 mxr_streamer_put(mdev);
44375 /* allow changes in output configuration */
44376@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44377
44378 void mxr_layer_release(struct mxr_layer *layer)
44379 {
44380- if (layer->ops.release)
44381- layer->ops.release(layer);
44382+ if (layer->ops->release)
44383+ layer->ops->release(layer);
44384 }
44385
44386 void mxr_base_layer_release(struct mxr_layer *layer)
44387@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44388
44389 layer->mdev = mdev;
44390 layer->idx = idx;
44391- layer->ops = *ops;
44392+ layer->ops = ops;
44393
44394 spin_lock_init(&layer->enq_slock);
44395 INIT_LIST_HEAD(&layer->enq_list);
44396diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44397index c9388c4..ce71ece 100644
44398--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44399+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44400@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44401 {
44402 struct mxr_layer *layer;
44403 int ret;
44404- struct mxr_layer_ops ops = {
44405+ static struct mxr_layer_ops ops = {
44406 .release = mxr_vp_layer_release,
44407 .buffer_set = mxr_vp_buffer_set,
44408 .stream_set = mxr_vp_stream_set,
44409diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44410index 2d4e73b..8b4d5b6 100644
44411--- a/drivers/media/platform/vivi.c
44412+++ b/drivers/media/platform/vivi.c
44413@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44414 MODULE_LICENSE("Dual BSD/GPL");
44415 MODULE_VERSION(VIVI_VERSION);
44416
44417-static unsigned video_nr = -1;
44418-module_param(video_nr, uint, 0644);
44419+static int video_nr = -1;
44420+module_param(video_nr, int, 0644);
44421 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44422
44423 static unsigned n_devs = 1;
44424diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44425index 545c04c..a14bded 100644
44426--- a/drivers/media/radio/radio-cadet.c
44427+++ b/drivers/media/radio/radio-cadet.c
44428@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44429 unsigned char readbuf[RDS_BUFFER];
44430 int i = 0;
44431
44432+ if (count > RDS_BUFFER)
44433+ return -EFAULT;
44434 mutex_lock(&dev->lock);
44435 if (dev->rdsstat == 0)
44436 cadet_start_rds(dev);
44437@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44438 while (i < count && dev->rdsin != dev->rdsout)
44439 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44440
44441- if (i && copy_to_user(data, readbuf, i))
44442+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44443 i = -EFAULT;
44444 unlock:
44445 mutex_unlock(&dev->lock);
44446diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44447index 5236035..c622c74 100644
44448--- a/drivers/media/radio/radio-maxiradio.c
44449+++ b/drivers/media/radio/radio-maxiradio.c
44450@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44451 /* TEA5757 pin mappings */
44452 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44453
44454-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44455+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44456
44457 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44458 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44459diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44460index 050b3bb..79f62b9 100644
44461--- a/drivers/media/radio/radio-shark.c
44462+++ b/drivers/media/radio/radio-shark.c
44463@@ -79,7 +79,7 @@ struct shark_device {
44464 u32 last_val;
44465 };
44466
44467-static atomic_t shark_instance = ATOMIC_INIT(0);
44468+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44469
44470 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44471 {
44472diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44473index 8654e0d..0608a64 100644
44474--- a/drivers/media/radio/radio-shark2.c
44475+++ b/drivers/media/radio/radio-shark2.c
44476@@ -74,7 +74,7 @@ struct shark_device {
44477 u8 *transfer_buffer;
44478 };
44479
44480-static atomic_t shark_instance = ATOMIC_INIT(0);
44481+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44482
44483 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44484 {
44485diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44486index 2fd9009..278cc1e 100644
44487--- a/drivers/media/radio/radio-si476x.c
44488+++ b/drivers/media/radio/radio-si476x.c
44489@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44490 struct si476x_radio *radio;
44491 struct v4l2_ctrl *ctrl;
44492
44493- static atomic_t instance = ATOMIC_INIT(0);
44494+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44495
44496 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44497 if (!radio)
44498diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44499index 46da365..3ba4206 100644
44500--- a/drivers/media/rc/rc-main.c
44501+++ b/drivers/media/rc/rc-main.c
44502@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44503 int rc_register_device(struct rc_dev *dev)
44504 {
44505 static bool raw_init = false; /* raw decoders loaded? */
44506- static atomic_t devno = ATOMIC_INIT(0);
44507+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
44508 struct rc_map *rc_map;
44509 const char *path;
44510 int rc;
44511@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44512 */
44513 mutex_lock(&dev->lock);
44514
44515- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44516+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44517 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44518 dev_set_drvdata(&dev->dev, dev);
44519 rc = device_add(&dev->dev);
44520diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44521index a1c641e..3007da9 100644
44522--- a/drivers/media/usb/dvb-usb/cxusb.c
44523+++ b/drivers/media/usb/dvb-usb/cxusb.c
44524@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44525
44526 struct dib0700_adapter_state {
44527 int (*set_param_save) (struct dvb_frontend *);
44528-};
44529+} __no_const;
44530
44531 static int dib7070_set_param_override(struct dvb_frontend *fe)
44532 {
44533diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44534index f272ed8..6289f9c 100644
44535--- a/drivers/media/usb/dvb-usb/dw2102.c
44536+++ b/drivers/media/usb/dvb-usb/dw2102.c
44537@@ -121,7 +121,7 @@ struct su3000_state {
44538
44539 struct s6x0_state {
44540 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44541-};
44542+} __no_const;
44543
44544 /* debug */
44545 static int dvb_usb_dw2102_debug;
44546diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44547index 8f7a6a4..eb0e1d4 100644
44548--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44549+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44550@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44551 __u32 reserved;
44552 };
44553
44554-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44555+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44556 enum v4l2_memory memory)
44557 {
44558 void __user *up_pln;
44559@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44560 return 0;
44561 }
44562
44563-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44564+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44565 enum v4l2_memory memory)
44566 {
44567 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44568@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44569 * by passing a very big num_planes value */
44570 uplane = compat_alloc_user_space(num_planes *
44571 sizeof(struct v4l2_plane));
44572- kp->m.planes = uplane;
44573+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44574
44575 while (--num_planes >= 0) {
44576 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44577@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44578 if (num_planes == 0)
44579 return 0;
44580
44581- uplane = kp->m.planes;
44582+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44583 if (get_user(p, &up->m.planes))
44584 return -EFAULT;
44585 uplane32 = compat_ptr(p);
44586@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44587 get_user(kp->capability, &up->capability) ||
44588 get_user(kp->flags, &up->flags))
44589 return -EFAULT;
44590- kp->base = compat_ptr(tmp);
44591+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44592 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44593 return 0;
44594 }
44595@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44596 n * sizeof(struct v4l2_ext_control32)))
44597 return -EFAULT;
44598 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44599- kp->controls = kcontrols;
44600+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44601 while (--n >= 0) {
44602 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44603 return -EFAULT;
44604@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44605 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44606 {
44607 struct v4l2_ext_control32 __user *ucontrols;
44608- struct v4l2_ext_control __user *kcontrols = kp->controls;
44609+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44610 int n = kp->count;
44611 compat_caddr_t p;
44612
44613@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44614 put_user(kp->start_block, &up->start_block) ||
44615 put_user(kp->blocks, &up->blocks) ||
44616 put_user(tmp, &up->edid) ||
44617- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44618+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44619 return -EFAULT;
44620 return 0;
44621 }
44622diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44623index fb46790..ae1f8fa 100644
44624--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44625+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44626@@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44627 return 0;
44628
44629 case V4L2_CTRL_TYPE_STRING:
44630- len = strlen(c->string);
44631- if (len < ctrl->minimum)
44632+ len = strlen_user(c->string);
44633+ if (!len || len < ctrl->minimum)
44634 return -ERANGE;
44635 if ((len - ctrl->minimum) % ctrl->step)
44636 return -ERANGE;
44637diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44638index 02d1b63..5fd6b16 100644
44639--- a/drivers/media/v4l2-core/v4l2-device.c
44640+++ b/drivers/media/v4l2-core/v4l2-device.c
44641@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44642 EXPORT_SYMBOL_GPL(v4l2_device_put);
44643
44644 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44645- atomic_t *instance)
44646+ atomic_unchecked_t *instance)
44647 {
44648- int num = atomic_inc_return(instance) - 1;
44649+ int num = atomic_inc_return_unchecked(instance) - 1;
44650 int len = strlen(basename);
44651
44652 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44653diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44654index 68e6b5e..8eb2aec 100644
44655--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44656+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44657@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44658 struct file *file, void *fh, void *p);
44659 } u;
44660 void (*debug)(const void *arg, bool write_only);
44661-};
44662+} __do_const;
44663+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44664
44665 /* This control needs a priority check */
44666 #define INFO_FL_PRIO (1 << 0)
44667@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44668 struct video_device *vfd = video_devdata(file);
44669 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44670 bool write_only = false;
44671- struct v4l2_ioctl_info default_info;
44672+ v4l2_ioctl_info_no_const default_info;
44673 const struct v4l2_ioctl_info *info;
44674 void *fh = file->private_data;
44675 struct v4l2_fh *vfh = NULL;
44676@@ -2194,7 +2195,7 @@ done:
44677 }
44678
44679 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44680- void * __user *user_ptr, void ***kernel_ptr)
44681+ void __user **user_ptr, void ***kernel_ptr)
44682 {
44683 int ret = 0;
44684
44685@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44686 ret = -EINVAL;
44687 break;
44688 }
44689- *user_ptr = (void __user *)buf->m.planes;
44690+ *user_ptr = (void __force_user *)buf->m.planes;
44691 *kernel_ptr = (void *)&buf->m.planes;
44692 *array_size = sizeof(struct v4l2_plane) * buf->length;
44693 ret = 1;
44694@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44695 ret = -EINVAL;
44696 break;
44697 }
44698- *user_ptr = (void __user *)ctrls->controls;
44699+ *user_ptr = (void __force_user *)ctrls->controls;
44700 *kernel_ptr = (void *)&ctrls->controls;
44701 *array_size = sizeof(struct v4l2_ext_control)
44702 * ctrls->count;
44703@@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44704 err = -ENOTTY;
44705
44706 if (has_array_args) {
44707- *kernel_ptr = user_ptr;
44708+ *kernel_ptr = (void __force_kernel *)user_ptr;
44709 if (copy_to_user(user_ptr, mbuf, array_size))
44710 err = -EFAULT;
44711 goto out_array_args;
44712diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44713index 767ff4d..c69d259 100644
44714--- a/drivers/message/fusion/mptbase.c
44715+++ b/drivers/message/fusion/mptbase.c
44716@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44717 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44718 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44719
44720+#ifdef CONFIG_GRKERNSEC_HIDESYM
44721+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44722+#else
44723 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44724 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44725+#endif
44726+
44727 /*
44728 * Rounding UP to nearest 4-kB boundary here...
44729 */
44730@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44731 ioc->facts.GlobalCredits);
44732
44733 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44734+#ifdef CONFIG_GRKERNSEC_HIDESYM
44735+ NULL, NULL);
44736+#else
44737 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44738+#endif
44739 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44740 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44741 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44742diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44743index dd239bd..689c4f7 100644
44744--- a/drivers/message/fusion/mptsas.c
44745+++ b/drivers/message/fusion/mptsas.c
44746@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44747 return 0;
44748 }
44749
44750+static inline void
44751+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44752+{
44753+ if (phy_info->port_details) {
44754+ phy_info->port_details->rphy = rphy;
44755+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44756+ ioc->name, rphy));
44757+ }
44758+
44759+ if (rphy) {
44760+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44761+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44762+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44763+ ioc->name, rphy, rphy->dev.release));
44764+ }
44765+}
44766+
44767 /* no mutex */
44768 static void
44769 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44770@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44771 return NULL;
44772 }
44773
44774-static inline void
44775-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44776-{
44777- if (phy_info->port_details) {
44778- phy_info->port_details->rphy = rphy;
44779- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44780- ioc->name, rphy));
44781- }
44782-
44783- if (rphy) {
44784- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44785- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44786- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44787- ioc->name, rphy, rphy->dev.release));
44788- }
44789-}
44790-
44791 static inline struct sas_port *
44792 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44793 {
44794diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44795index 727819c..ad74694 100644
44796--- a/drivers/message/fusion/mptscsih.c
44797+++ b/drivers/message/fusion/mptscsih.c
44798@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44799
44800 h = shost_priv(SChost);
44801
44802- if (h) {
44803- if (h->info_kbuf == NULL)
44804- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44805- return h->info_kbuf;
44806- h->info_kbuf[0] = '\0';
44807+ if (!h)
44808+ return NULL;
44809
44810- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44811- h->info_kbuf[size-1] = '\0';
44812- }
44813+ if (h->info_kbuf == NULL)
44814+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44815+ return h->info_kbuf;
44816+ h->info_kbuf[0] = '\0';
44817+
44818+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44819+ h->info_kbuf[size-1] = '\0';
44820
44821 return h->info_kbuf;
44822 }
44823diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44824index b7d87cd..3fb36da 100644
44825--- a/drivers/message/i2o/i2o_proc.c
44826+++ b/drivers/message/i2o/i2o_proc.c
44827@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44828 "Array Controller Device"
44829 };
44830
44831-static char *chtostr(char *tmp, u8 *chars, int n)
44832-{
44833- tmp[0] = 0;
44834- return strncat(tmp, (char *)chars, n);
44835-}
44836-
44837 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44838 char *group)
44839 {
44840@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44841 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44842 {
44843 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44844- static u32 work32[5];
44845- static u8 *work8 = (u8 *) work32;
44846- static u16 *work16 = (u16 *) work32;
44847+ u32 work32[5];
44848+ u8 *work8 = (u8 *) work32;
44849+ u16 *work16 = (u16 *) work32;
44850 int token;
44851 u32 hwcap;
44852
44853@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44854 } *result;
44855
44856 i2o_exec_execute_ddm_table ddm_table;
44857- char tmp[28 + 1];
44858
44859 result = kmalloc(sizeof(*result), GFP_KERNEL);
44860 if (!result)
44861@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44862
44863 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44864 seq_printf(seq, "%-#8x", ddm_table.module_id);
44865- seq_printf(seq, "%-29s",
44866- chtostr(tmp, ddm_table.module_name_version, 28));
44867+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44868 seq_printf(seq, "%9d ", ddm_table.data_size);
44869 seq_printf(seq, "%8d", ddm_table.code_size);
44870
44871@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44872
44873 i2o_driver_result_table *result;
44874 i2o_driver_store_table *dst;
44875- char tmp[28 + 1];
44876
44877 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44878 if (result == NULL)
44879@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44880
44881 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44882 seq_printf(seq, "%-#8x", dst->module_id);
44883- seq_printf(seq, "%-29s",
44884- chtostr(tmp, dst->module_name_version, 28));
44885- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44886+ seq_printf(seq, "%-.28s", dst->module_name_version);
44887+ seq_printf(seq, "%-.8s", dst->date);
44888 seq_printf(seq, "%8d ", dst->module_size);
44889 seq_printf(seq, "%8d ", dst->mpb_size);
44890 seq_printf(seq, "0x%04x", dst->module_flags);
44891@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44892 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44893 {
44894 struct i2o_device *d = (struct i2o_device *)seq->private;
44895- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44896+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44897 // == (allow) 512d bytes (max)
44898- static u16 *work16 = (u16 *) work32;
44899+ u16 *work16 = (u16 *) work32;
44900 int token;
44901- char tmp[16 + 1];
44902
44903 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44904
44905@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44906 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44907 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44908 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44909- seq_printf(seq, "Vendor info : %s\n",
44910- chtostr(tmp, (u8 *) (work32 + 2), 16));
44911- seq_printf(seq, "Product info : %s\n",
44912- chtostr(tmp, (u8 *) (work32 + 6), 16));
44913- seq_printf(seq, "Description : %s\n",
44914- chtostr(tmp, (u8 *) (work32 + 10), 16));
44915- seq_printf(seq, "Product rev. : %s\n",
44916- chtostr(tmp, (u8 *) (work32 + 14), 8));
44917+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44918+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44919+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44920+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44921
44922 seq_printf(seq, "Serial number : ");
44923 print_serial_number(seq, (u8 *) (work32 + 16),
44924@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44925 u8 pad[256]; // allow up to 256 byte (max) serial number
44926 } result;
44927
44928- char tmp[24 + 1];
44929-
44930 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44931
44932 if (token < 0) {
44933@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44934 }
44935
44936 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44937- seq_printf(seq, "Module name : %s\n",
44938- chtostr(tmp, result.module_name, 24));
44939- seq_printf(seq, "Module revision : %s\n",
44940- chtostr(tmp, result.module_rev, 8));
44941+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44942+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44943
44944 seq_printf(seq, "Serial number : ");
44945 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44946@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44947 u8 instance_number[4];
44948 } result;
44949
44950- char tmp[64 + 1];
44951-
44952 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44953
44954 if (token < 0) {
44955@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44956 return 0;
44957 }
44958
44959- seq_printf(seq, "Device name : %s\n",
44960- chtostr(tmp, result.device_name, 64));
44961- seq_printf(seq, "Service name : %s\n",
44962- chtostr(tmp, result.service_name, 64));
44963- seq_printf(seq, "Physical name : %s\n",
44964- chtostr(tmp, result.physical_location, 64));
44965- seq_printf(seq, "Instance number : %s\n",
44966- chtostr(tmp, result.instance_number, 4));
44967+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44968+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44969+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44970+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44971
44972 return 0;
44973 }
44974@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44975 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44976 {
44977 struct i2o_device *d = (struct i2o_device *)seq->private;
44978- static u32 work32[12];
44979- static u16 *work16 = (u16 *) work32;
44980- static u8 *work8 = (u8 *) work32;
44981+ u32 work32[12];
44982+ u16 *work16 = (u16 *) work32;
44983+ u8 *work8 = (u8 *) work32;
44984 int token;
44985
44986 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44987diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44988index a8c08f3..155fe3d 100644
44989--- a/drivers/message/i2o/iop.c
44990+++ b/drivers/message/i2o/iop.c
44991@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44992
44993 spin_lock_irqsave(&c->context_list_lock, flags);
44994
44995- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44996- atomic_inc(&c->context_list_counter);
44997+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44998+ atomic_inc_unchecked(&c->context_list_counter);
44999
45000- entry->context = atomic_read(&c->context_list_counter);
45001+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45002
45003 list_add(&entry->list, &c->context_list);
45004
45005@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45006
45007 #if BITS_PER_LONG == 64
45008 spin_lock_init(&c->context_list_lock);
45009- atomic_set(&c->context_list_counter, 0);
45010+ atomic_set_unchecked(&c->context_list_counter, 0);
45011 INIT_LIST_HEAD(&c->context_list);
45012 #endif
45013
45014diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45015index e33e385..28dfd23 100644
45016--- a/drivers/mfd/ab8500-debugfs.c
45017+++ b/drivers/mfd/ab8500-debugfs.c
45018@@ -100,7 +100,7 @@ static int irq_last;
45019 static u32 *irq_count;
45020 static int num_irqs;
45021
45022-static struct device_attribute **dev_attr;
45023+static device_attribute_no_const **dev_attr;
45024 static char **event_name;
45025
45026 static u8 avg_sample = SAMPLE_16;
45027diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45028index fcbb2e9..2635e11 100644
45029--- a/drivers/mfd/janz-cmodio.c
45030+++ b/drivers/mfd/janz-cmodio.c
45031@@ -13,6 +13,7 @@
45032
45033 #include <linux/kernel.h>
45034 #include <linux/module.h>
45035+#include <linux/slab.h>
45036 #include <linux/init.h>
45037 #include <linux/pci.h>
45038 #include <linux/interrupt.h>
45039diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45040index 176aa26..27811b2 100644
45041--- a/drivers/mfd/max8925-i2c.c
45042+++ b/drivers/mfd/max8925-i2c.c
45043@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45044 const struct i2c_device_id *id)
45045 {
45046 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45047- static struct max8925_chip *chip;
45048+ struct max8925_chip *chip;
45049 struct device_node *node = client->dev.of_node;
45050
45051 if (node && !pdata) {
45052diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45053index c0f608e..286f8ec 100644
45054--- a/drivers/mfd/tps65910.c
45055+++ b/drivers/mfd/tps65910.c
45056@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45057 struct tps65910_platform_data *pdata)
45058 {
45059 int ret = 0;
45060- static struct regmap_irq_chip *tps6591x_irqs_chip;
45061+ struct regmap_irq_chip *tps6591x_irqs_chip;
45062
45063 if (!irq) {
45064 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45065diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45066index 9aa6d1e..1631bfc 100644
45067--- a/drivers/mfd/twl4030-irq.c
45068+++ b/drivers/mfd/twl4030-irq.c
45069@@ -35,6 +35,7 @@
45070 #include <linux/of.h>
45071 #include <linux/irqdomain.h>
45072 #include <linux/i2c/twl.h>
45073+#include <asm/pgtable.h>
45074
45075 #include "twl-core.h"
45076
45077@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45078 * Install an irq handler for each of the SIH modules;
45079 * clone dummy irq_chip since PIH can't *do* anything
45080 */
45081- twl4030_irq_chip = dummy_irq_chip;
45082- twl4030_irq_chip.name = "twl4030";
45083+ pax_open_kernel();
45084+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45085+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45086
45087- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45088+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45089+ pax_close_kernel();
45090
45091 for (i = irq_base; i < irq_end; i++) {
45092 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45093diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45094index 464419b..64bae8d 100644
45095--- a/drivers/misc/c2port/core.c
45096+++ b/drivers/misc/c2port/core.c
45097@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45098 goto error_idr_alloc;
45099 c2dev->id = ret;
45100
45101- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45102+ pax_open_kernel();
45103+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45104+ pax_close_kernel();
45105
45106 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45107 "c2port%d", c2dev->id);
45108diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45109index 9c34e57..b981cda 100644
45110--- a/drivers/misc/eeprom/sunxi_sid.c
45111+++ b/drivers/misc/eeprom/sunxi_sid.c
45112@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45113
45114 platform_set_drvdata(pdev, sid_data);
45115
45116- sid_bin_attr.size = sid_data->keysize;
45117+ pax_open_kernel();
45118+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45119+ pax_close_kernel();
45120 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45121 return -ENODEV;
45122
45123diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45124index 36f5d52..32311c3 100644
45125--- a/drivers/misc/kgdbts.c
45126+++ b/drivers/misc/kgdbts.c
45127@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45128 char before[BREAK_INSTR_SIZE];
45129 char after[BREAK_INSTR_SIZE];
45130
45131- probe_kernel_read(before, (char *)kgdbts_break_test,
45132+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45133 BREAK_INSTR_SIZE);
45134 init_simple_test();
45135 ts.tst = plant_and_detach_test;
45136@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45137 /* Activate test with initial breakpoint */
45138 if (!is_early)
45139 kgdb_breakpoint();
45140- probe_kernel_read(after, (char *)kgdbts_break_test,
45141+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45142 BREAK_INSTR_SIZE);
45143 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45144 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45145diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45146index 036effe..b3a6336 100644
45147--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45148+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45149@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45150 * the lid is closed. This leads to interrupts as soon as a little move
45151 * is done.
45152 */
45153- atomic_inc(&lis3->count);
45154+ atomic_inc_unchecked(&lis3->count);
45155
45156 wake_up_interruptible(&lis3->misc_wait);
45157 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45158@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45159 if (lis3->pm_dev)
45160 pm_runtime_get_sync(lis3->pm_dev);
45161
45162- atomic_set(&lis3->count, 0);
45163+ atomic_set_unchecked(&lis3->count, 0);
45164 return 0;
45165 }
45166
45167@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45168 add_wait_queue(&lis3->misc_wait, &wait);
45169 while (true) {
45170 set_current_state(TASK_INTERRUPTIBLE);
45171- data = atomic_xchg(&lis3->count, 0);
45172+ data = atomic_xchg_unchecked(&lis3->count, 0);
45173 if (data)
45174 break;
45175
45176@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45177 struct lis3lv02d, miscdev);
45178
45179 poll_wait(file, &lis3->misc_wait, wait);
45180- if (atomic_read(&lis3->count))
45181+ if (atomic_read_unchecked(&lis3->count))
45182 return POLLIN | POLLRDNORM;
45183 return 0;
45184 }
45185diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45186index c439c82..1f20f57 100644
45187--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45188+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45189@@ -297,7 +297,7 @@ struct lis3lv02d {
45190 struct input_polled_dev *idev; /* input device */
45191 struct platform_device *pdev; /* platform device */
45192 struct regulator_bulk_data regulators[2];
45193- atomic_t count; /* interrupt count after last read */
45194+ atomic_unchecked_t count; /* interrupt count after last read */
45195 union axis_conversion ac; /* hw -> logical axis */
45196 int mapped_btns[3];
45197
45198diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45199index 2f30bad..c4c13d0 100644
45200--- a/drivers/misc/sgi-gru/gruhandles.c
45201+++ b/drivers/misc/sgi-gru/gruhandles.c
45202@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45203 unsigned long nsec;
45204
45205 nsec = CLKS2NSEC(clks);
45206- atomic_long_inc(&mcs_op_statistics[op].count);
45207- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45208+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45209+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45210 if (mcs_op_statistics[op].max < nsec)
45211 mcs_op_statistics[op].max = nsec;
45212 }
45213diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45214index 4f76359..cdfcb2e 100644
45215--- a/drivers/misc/sgi-gru/gruprocfs.c
45216+++ b/drivers/misc/sgi-gru/gruprocfs.c
45217@@ -32,9 +32,9 @@
45218
45219 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45220
45221-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45222+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45223 {
45224- unsigned long val = atomic_long_read(v);
45225+ unsigned long val = atomic_long_read_unchecked(v);
45226
45227 seq_printf(s, "%16lu %s\n", val, id);
45228 }
45229@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45230
45231 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45232 for (op = 0; op < mcsop_last; op++) {
45233- count = atomic_long_read(&mcs_op_statistics[op].count);
45234- total = atomic_long_read(&mcs_op_statistics[op].total);
45235+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45236+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45237 max = mcs_op_statistics[op].max;
45238 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45239 count ? total / count : 0, max);
45240diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45241index 5c3ce24..4915ccb 100644
45242--- a/drivers/misc/sgi-gru/grutables.h
45243+++ b/drivers/misc/sgi-gru/grutables.h
45244@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45245 * GRU statistics.
45246 */
45247 struct gru_stats_s {
45248- atomic_long_t vdata_alloc;
45249- atomic_long_t vdata_free;
45250- atomic_long_t gts_alloc;
45251- atomic_long_t gts_free;
45252- atomic_long_t gms_alloc;
45253- atomic_long_t gms_free;
45254- atomic_long_t gts_double_allocate;
45255- atomic_long_t assign_context;
45256- atomic_long_t assign_context_failed;
45257- atomic_long_t free_context;
45258- atomic_long_t load_user_context;
45259- atomic_long_t load_kernel_context;
45260- atomic_long_t lock_kernel_context;
45261- atomic_long_t unlock_kernel_context;
45262- atomic_long_t steal_user_context;
45263- atomic_long_t steal_kernel_context;
45264- atomic_long_t steal_context_failed;
45265- atomic_long_t nopfn;
45266- atomic_long_t asid_new;
45267- atomic_long_t asid_next;
45268- atomic_long_t asid_wrap;
45269- atomic_long_t asid_reuse;
45270- atomic_long_t intr;
45271- atomic_long_t intr_cbr;
45272- atomic_long_t intr_tfh;
45273- atomic_long_t intr_spurious;
45274- atomic_long_t intr_mm_lock_failed;
45275- atomic_long_t call_os;
45276- atomic_long_t call_os_wait_queue;
45277- atomic_long_t user_flush_tlb;
45278- atomic_long_t user_unload_context;
45279- atomic_long_t user_exception;
45280- atomic_long_t set_context_option;
45281- atomic_long_t check_context_retarget_intr;
45282- atomic_long_t check_context_unload;
45283- atomic_long_t tlb_dropin;
45284- atomic_long_t tlb_preload_page;
45285- atomic_long_t tlb_dropin_fail_no_asid;
45286- atomic_long_t tlb_dropin_fail_upm;
45287- atomic_long_t tlb_dropin_fail_invalid;
45288- atomic_long_t tlb_dropin_fail_range_active;
45289- atomic_long_t tlb_dropin_fail_idle;
45290- atomic_long_t tlb_dropin_fail_fmm;
45291- atomic_long_t tlb_dropin_fail_no_exception;
45292- atomic_long_t tfh_stale_on_fault;
45293- atomic_long_t mmu_invalidate_range;
45294- atomic_long_t mmu_invalidate_page;
45295- atomic_long_t flush_tlb;
45296- atomic_long_t flush_tlb_gru;
45297- atomic_long_t flush_tlb_gru_tgh;
45298- atomic_long_t flush_tlb_gru_zero_asid;
45299+ atomic_long_unchecked_t vdata_alloc;
45300+ atomic_long_unchecked_t vdata_free;
45301+ atomic_long_unchecked_t gts_alloc;
45302+ atomic_long_unchecked_t gts_free;
45303+ atomic_long_unchecked_t gms_alloc;
45304+ atomic_long_unchecked_t gms_free;
45305+ atomic_long_unchecked_t gts_double_allocate;
45306+ atomic_long_unchecked_t assign_context;
45307+ atomic_long_unchecked_t assign_context_failed;
45308+ atomic_long_unchecked_t free_context;
45309+ atomic_long_unchecked_t load_user_context;
45310+ atomic_long_unchecked_t load_kernel_context;
45311+ atomic_long_unchecked_t lock_kernel_context;
45312+ atomic_long_unchecked_t unlock_kernel_context;
45313+ atomic_long_unchecked_t steal_user_context;
45314+ atomic_long_unchecked_t steal_kernel_context;
45315+ atomic_long_unchecked_t steal_context_failed;
45316+ atomic_long_unchecked_t nopfn;
45317+ atomic_long_unchecked_t asid_new;
45318+ atomic_long_unchecked_t asid_next;
45319+ atomic_long_unchecked_t asid_wrap;
45320+ atomic_long_unchecked_t asid_reuse;
45321+ atomic_long_unchecked_t intr;
45322+ atomic_long_unchecked_t intr_cbr;
45323+ atomic_long_unchecked_t intr_tfh;
45324+ atomic_long_unchecked_t intr_spurious;
45325+ atomic_long_unchecked_t intr_mm_lock_failed;
45326+ atomic_long_unchecked_t call_os;
45327+ atomic_long_unchecked_t call_os_wait_queue;
45328+ atomic_long_unchecked_t user_flush_tlb;
45329+ atomic_long_unchecked_t user_unload_context;
45330+ atomic_long_unchecked_t user_exception;
45331+ atomic_long_unchecked_t set_context_option;
45332+ atomic_long_unchecked_t check_context_retarget_intr;
45333+ atomic_long_unchecked_t check_context_unload;
45334+ atomic_long_unchecked_t tlb_dropin;
45335+ atomic_long_unchecked_t tlb_preload_page;
45336+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45337+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45338+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45339+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45340+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45341+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45342+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45343+ atomic_long_unchecked_t tfh_stale_on_fault;
45344+ atomic_long_unchecked_t mmu_invalidate_range;
45345+ atomic_long_unchecked_t mmu_invalidate_page;
45346+ atomic_long_unchecked_t flush_tlb;
45347+ atomic_long_unchecked_t flush_tlb_gru;
45348+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45349+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45350
45351- atomic_long_t copy_gpa;
45352- atomic_long_t read_gpa;
45353+ atomic_long_unchecked_t copy_gpa;
45354+ atomic_long_unchecked_t read_gpa;
45355
45356- atomic_long_t mesq_receive;
45357- atomic_long_t mesq_receive_none;
45358- atomic_long_t mesq_send;
45359- atomic_long_t mesq_send_failed;
45360- atomic_long_t mesq_noop;
45361- atomic_long_t mesq_send_unexpected_error;
45362- atomic_long_t mesq_send_lb_overflow;
45363- atomic_long_t mesq_send_qlimit_reached;
45364- atomic_long_t mesq_send_amo_nacked;
45365- atomic_long_t mesq_send_put_nacked;
45366- atomic_long_t mesq_page_overflow;
45367- atomic_long_t mesq_qf_locked;
45368- atomic_long_t mesq_qf_noop_not_full;
45369- atomic_long_t mesq_qf_switch_head_failed;
45370- atomic_long_t mesq_qf_unexpected_error;
45371- atomic_long_t mesq_noop_unexpected_error;
45372- atomic_long_t mesq_noop_lb_overflow;
45373- atomic_long_t mesq_noop_qlimit_reached;
45374- atomic_long_t mesq_noop_amo_nacked;
45375- atomic_long_t mesq_noop_put_nacked;
45376- atomic_long_t mesq_noop_page_overflow;
45377+ atomic_long_unchecked_t mesq_receive;
45378+ atomic_long_unchecked_t mesq_receive_none;
45379+ atomic_long_unchecked_t mesq_send;
45380+ atomic_long_unchecked_t mesq_send_failed;
45381+ atomic_long_unchecked_t mesq_noop;
45382+ atomic_long_unchecked_t mesq_send_unexpected_error;
45383+ atomic_long_unchecked_t mesq_send_lb_overflow;
45384+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45385+ atomic_long_unchecked_t mesq_send_amo_nacked;
45386+ atomic_long_unchecked_t mesq_send_put_nacked;
45387+ atomic_long_unchecked_t mesq_page_overflow;
45388+ atomic_long_unchecked_t mesq_qf_locked;
45389+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45390+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45391+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45392+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45393+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45394+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45395+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45396+ atomic_long_unchecked_t mesq_noop_put_nacked;
45397+ atomic_long_unchecked_t mesq_noop_page_overflow;
45398
45399 };
45400
45401@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45402 tghop_invalidate, mcsop_last};
45403
45404 struct mcs_op_statistic {
45405- atomic_long_t count;
45406- atomic_long_t total;
45407+ atomic_long_unchecked_t count;
45408+ atomic_long_unchecked_t total;
45409 unsigned long max;
45410 };
45411
45412@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45413
45414 #define STAT(id) do { \
45415 if (gru_options & OPT_STATS) \
45416- atomic_long_inc(&gru_stats.id); \
45417+ atomic_long_inc_unchecked(&gru_stats.id); \
45418 } while (0)
45419
45420 #ifdef CONFIG_SGI_GRU_DEBUG
45421diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45422index c862cd4..0d176fe 100644
45423--- a/drivers/misc/sgi-xp/xp.h
45424+++ b/drivers/misc/sgi-xp/xp.h
45425@@ -288,7 +288,7 @@ struct xpc_interface {
45426 xpc_notify_func, void *);
45427 void (*received) (short, int, void *);
45428 enum xp_retval (*partid_to_nasids) (short, void *);
45429-};
45430+} __no_const;
45431
45432 extern struct xpc_interface xpc_interface;
45433
45434diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45435index 01be66d..e3a0c7e 100644
45436--- a/drivers/misc/sgi-xp/xp_main.c
45437+++ b/drivers/misc/sgi-xp/xp_main.c
45438@@ -78,13 +78,13 @@ xpc_notloaded(void)
45439 }
45440
45441 struct xpc_interface xpc_interface = {
45442- (void (*)(int))xpc_notloaded,
45443- (void (*)(int))xpc_notloaded,
45444- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45445- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45446+ .connect = (void (*)(int))xpc_notloaded,
45447+ .disconnect = (void (*)(int))xpc_notloaded,
45448+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45449+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45450 void *))xpc_notloaded,
45451- (void (*)(short, int, void *))xpc_notloaded,
45452- (enum xp_retval(*)(short, void *))xpc_notloaded
45453+ .received = (void (*)(short, int, void *))xpc_notloaded,
45454+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45455 };
45456 EXPORT_SYMBOL_GPL(xpc_interface);
45457
45458diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45459index b94d5f7..7f494c5 100644
45460--- a/drivers/misc/sgi-xp/xpc.h
45461+++ b/drivers/misc/sgi-xp/xpc.h
45462@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45463 void (*received_payload) (struct xpc_channel *, void *);
45464 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45465 };
45466+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45467
45468 /* struct xpc_partition act_state values (for XPC HB) */
45469
45470@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45471 /* found in xpc_main.c */
45472 extern struct device *xpc_part;
45473 extern struct device *xpc_chan;
45474-extern struct xpc_arch_operations xpc_arch_ops;
45475+extern xpc_arch_operations_no_const xpc_arch_ops;
45476 extern int xpc_disengage_timelimit;
45477 extern int xpc_disengage_timedout;
45478 extern int xpc_activate_IRQ_rcvd;
45479diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45480index 82dc574..8539ab2 100644
45481--- a/drivers/misc/sgi-xp/xpc_main.c
45482+++ b/drivers/misc/sgi-xp/xpc_main.c
45483@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45484 .notifier_call = xpc_system_die,
45485 };
45486
45487-struct xpc_arch_operations xpc_arch_ops;
45488+xpc_arch_operations_no_const xpc_arch_ops;
45489
45490 /*
45491 * Timer function to enforce the timelimit on the partition disengage.
45492@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45493
45494 if (((die_args->trapnr == X86_TRAP_MF) ||
45495 (die_args->trapnr == X86_TRAP_XF)) &&
45496- !user_mode_vm(die_args->regs))
45497+ !user_mode(die_args->regs))
45498 xpc_die_deactivate();
45499
45500 break;
45501diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45502index 7b5424f..ed1d6ac 100644
45503--- a/drivers/mmc/card/block.c
45504+++ b/drivers/mmc/card/block.c
45505@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45506 if (idata->ic.postsleep_min_us)
45507 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45508
45509- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45510+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45511 err = -EFAULT;
45512 goto cmd_rel_host;
45513 }
45514diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45515index e5b5eeb..7bf2212 100644
45516--- a/drivers/mmc/core/mmc_ops.c
45517+++ b/drivers/mmc/core/mmc_ops.c
45518@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45519 void *data_buf;
45520 int is_on_stack;
45521
45522- is_on_stack = object_is_on_stack(buf);
45523+ is_on_stack = object_starts_on_stack(buf);
45524 if (is_on_stack) {
45525 /*
45526 * dma onto stack is unsafe/nonportable, but callers to this
45527diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45528index 6bf24ab..13d0293b 100644
45529--- a/drivers/mmc/host/dw_mmc.h
45530+++ b/drivers/mmc/host/dw_mmc.h
45531@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45532 int (*parse_dt)(struct dw_mci *host);
45533 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45534 struct dw_mci_tuning_data *tuning_data);
45535-};
45536+} __do_const;
45537 #endif /* _DW_MMC_H_ */
45538diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45539index f320579..7b7ebac 100644
45540--- a/drivers/mmc/host/mmci.c
45541+++ b/drivers/mmc/host/mmci.c
45542@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45543 }
45544
45545 if (variant->busy_detect) {
45546- mmci_ops.card_busy = mmci_card_busy;
45547+ pax_open_kernel();
45548+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45549+ pax_close_kernel();
45550 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45551 }
45552
45553diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45554index 1dcaf8a..025af25 100644
45555--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45556+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45557@@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45558 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45559 }
45560
45561- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45562- sdhci_esdhc_ops.platform_execute_tuning =
45563+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45564+ pax_open_kernel();
45565+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45566 esdhc_executing_tuning;
45567+ pax_close_kernel();
45568+ }
45569 boarddata = &imx_data->boarddata;
45570 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45571 if (!host->mmc->parent->platform_data) {
45572diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45573index 6debda9..2ba7427 100644
45574--- a/drivers/mmc/host/sdhci-s3c.c
45575+++ b/drivers/mmc/host/sdhci-s3c.c
45576@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45577 * we can use overriding functions instead of default.
45578 */
45579 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45580- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45581- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45582- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45583+ pax_open_kernel();
45584+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45585+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45586+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45587+ pax_close_kernel();
45588 }
45589
45590 /* It supports additional host capabilities if needed */
45591diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45592index 096993f..f02c23b 100644
45593--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45594+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45595@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45596 size_t totlen = 0, thislen;
45597 int ret = 0;
45598 size_t buflen = 0;
45599- static char *buffer;
45600+ char *buffer;
45601
45602 if (!ECCBUF_SIZE) {
45603 /* We should fall back to a general writev implementation.
45604diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45605index 370b9dd..1a1176b 100644
45606--- a/drivers/mtd/nand/denali.c
45607+++ b/drivers/mtd/nand/denali.c
45608@@ -24,6 +24,7 @@
45609 #include <linux/slab.h>
45610 #include <linux/mtd/mtd.h>
45611 #include <linux/module.h>
45612+#include <linux/slab.h>
45613
45614 #include "denali.h"
45615
45616diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45617index 51b9d6a..52af9a7 100644
45618--- a/drivers/mtd/nftlmount.c
45619+++ b/drivers/mtd/nftlmount.c
45620@@ -24,6 +24,7 @@
45621 #include <asm/errno.h>
45622 #include <linux/delay.h>
45623 #include <linux/slab.h>
45624+#include <linux/sched.h>
45625 #include <linux/mtd/mtd.h>
45626 #include <linux/mtd/nand.h>
45627 #include <linux/mtd/nftl.h>
45628diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45629index 4b8e895..6b3c498 100644
45630--- a/drivers/mtd/sm_ftl.c
45631+++ b/drivers/mtd/sm_ftl.c
45632@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45633 #define SM_CIS_VENDOR_OFFSET 0x59
45634 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45635 {
45636- struct attribute_group *attr_group;
45637+ attribute_group_no_const *attr_group;
45638 struct attribute **attributes;
45639 struct sm_sysfs_attribute *vendor_attribute;
45640
45641diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45642index 4b8c58b..a200546 100644
45643--- a/drivers/net/bonding/bond_main.c
45644+++ b/drivers/net/bonding/bond_main.c
45645@@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45646
45647 bond_netlink_fini();
45648 unregister_pernet_subsys(&bond_net_ops);
45649+ rtnl_link_unregister(&bond_link_ops);
45650
45651 #ifdef CONFIG_NET_POLL_CONTROLLER
45652 /*
45653diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45654index 40e7b1c..6a70fff 100644
45655--- a/drivers/net/bonding/bond_netlink.c
45656+++ b/drivers/net/bonding/bond_netlink.c
45657@@ -102,7 +102,7 @@ nla_put_failure:
45658 return -EMSGSIZE;
45659 }
45660
45661-struct rtnl_link_ops bond_link_ops __read_mostly = {
45662+struct rtnl_link_ops bond_link_ops = {
45663 .kind = "bond",
45664 .priv_size = sizeof(struct bonding),
45665 .setup = bond_setup,
45666diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45667index 3c06947..fd0e5de 100644
45668--- a/drivers/net/can/Kconfig
45669+++ b/drivers/net/can/Kconfig
45670@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45671
45672 config CAN_FLEXCAN
45673 tristate "Support for Freescale FLEXCAN based chips"
45674- depends on ARM || PPC
45675+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45676 ---help---
45677 Say Y here if you want to support for Freescale FlexCAN.
45678
45679diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45680index 36fa577..a158806 100644
45681--- a/drivers/net/ethernet/8390/ax88796.c
45682+++ b/drivers/net/ethernet/8390/ax88796.c
45683@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45684 if (ax->plat->reg_offsets)
45685 ei_local->reg_offset = ax->plat->reg_offsets;
45686 else {
45687+ resource_size_t _mem_size = mem_size;
45688+ do_div(_mem_size, 0x18);
45689 ei_local->reg_offset = ax->reg_offsets;
45690 for (ret = 0; ret < 0x18; ret++)
45691- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45692+ ax->reg_offsets[ret] = _mem_size * ret;
45693 }
45694
45695 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45696diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45697index 41f3ca5a..1ee5364 100644
45698--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45699+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45700@@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45701 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45702 {
45703 /* RX_MODE controlling object */
45704- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45705+ bnx2x_init_rx_mode_obj(bp);
45706
45707 /* multicast configuration controlling object */
45708 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45709diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45710index 18438a5..c923b8e 100644
45711--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45712+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45713@@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45714 return rc;
45715 }
45716
45717-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45718- struct bnx2x_rx_mode_obj *o)
45719+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45720 {
45721 if (CHIP_IS_E1x(bp)) {
45722- o->wait_comp = bnx2x_empty_rx_mode_wait;
45723- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45724+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45725+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45726 } else {
45727- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45728- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45729+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45730+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45731 }
45732 }
45733
45734diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45735index 6a53c15..6e7d1e7 100644
45736--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45737+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45738@@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45739
45740 /********************* RX MODE ****************/
45741
45742-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45743- struct bnx2x_rx_mode_obj *o);
45744+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45745
45746 /**
45747 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45748diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45749index cf9917b..c658558 100644
45750--- a/drivers/net/ethernet/broadcom/tg3.h
45751+++ b/drivers/net/ethernet/broadcom/tg3.h
45752@@ -150,6 +150,7 @@
45753 #define CHIPREV_ID_5750_A0 0x4000
45754 #define CHIPREV_ID_5750_A1 0x4001
45755 #define CHIPREV_ID_5750_A3 0x4003
45756+#define CHIPREV_ID_5750_C1 0x4201
45757 #define CHIPREV_ID_5750_C2 0x4202
45758 #define CHIPREV_ID_5752_A0_HW 0x5000
45759 #define CHIPREV_ID_5752_A0 0x6000
45760diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45761index 3ca77fa..fcc015f 100644
45762--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45763+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45764@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45765 }
45766
45767 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45768- bna_cb_ioceth_enable,
45769- bna_cb_ioceth_disable,
45770- bna_cb_ioceth_hbfail,
45771- bna_cb_ioceth_reset
45772+ .enable_cbfn = bna_cb_ioceth_enable,
45773+ .disable_cbfn = bna_cb_ioceth_disable,
45774+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45775+ .reset_cbfn = bna_cb_ioceth_reset
45776 };
45777
45778 static void bna_attr_init(struct bna_ioceth *ioceth)
45779diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45780index 8cffcdf..aadf043 100644
45781--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45782+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45783@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45784 */
45785 struct l2t_skb_cb {
45786 arp_failure_handler_func arp_failure_handler;
45787-};
45788+} __no_const;
45789
45790 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45791
45792diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45793index fff02ed..d421412 100644
45794--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45795+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45796@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45797
45798 int i;
45799 struct adapter *ap = netdev2adap(dev);
45800- static const unsigned int *reg_ranges;
45801+ const unsigned int *reg_ranges;
45802 int arr_size = 0, buf_size = 0;
45803
45804 if (is_t4(ap->params.chip)) {
45805diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45806index c05b66d..ed69872 100644
45807--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45808+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45809@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45810 for (i=0; i<ETH_ALEN; i++) {
45811 tmp.addr[i] = dev->dev_addr[i];
45812 }
45813- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45814+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45815 break;
45816
45817 case DE4X5_SET_HWADDR: /* Set the hardware address */
45818@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45819 spin_lock_irqsave(&lp->lock, flags);
45820 memcpy(&statbuf, &lp->pktStats, ioc->len);
45821 spin_unlock_irqrestore(&lp->lock, flags);
45822- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45823+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45824 return -EFAULT;
45825 break;
45826 }
45827diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45828index a37039d..a51d7e8 100644
45829--- a/drivers/net/ethernet/emulex/benet/be_main.c
45830+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45831@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45832
45833 if (wrapped)
45834 newacc += 65536;
45835- ACCESS_ONCE(*acc) = newacc;
45836+ ACCESS_ONCE_RW(*acc) = newacc;
45837 }
45838
45839 static void populate_erx_stats(struct be_adapter *adapter,
45840diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45841index 212f44b..fb69959 100644
45842--- a/drivers/net/ethernet/faraday/ftgmac100.c
45843+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45844@@ -31,6 +31,8 @@
45845 #include <linux/netdevice.h>
45846 #include <linux/phy.h>
45847 #include <linux/platform_device.h>
45848+#include <linux/interrupt.h>
45849+#include <linux/irqreturn.h>
45850 #include <net/ip.h>
45851
45852 #include "ftgmac100.h"
45853diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45854index 8be5b40..081bc1b 100644
45855--- a/drivers/net/ethernet/faraday/ftmac100.c
45856+++ b/drivers/net/ethernet/faraday/ftmac100.c
45857@@ -31,6 +31,8 @@
45858 #include <linux/module.h>
45859 #include <linux/netdevice.h>
45860 #include <linux/platform_device.h>
45861+#include <linux/interrupt.h>
45862+#include <linux/irqreturn.h>
45863
45864 #include "ftmac100.h"
45865
45866diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45867index 5184e2a..acb28c3 100644
45868--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45869+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45870@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45871 }
45872
45873 /* update the base incval used to calculate frequency adjustment */
45874- ACCESS_ONCE(adapter->base_incval) = incval;
45875+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45876 smp_mb();
45877
45878 /* need lock to prevent incorrect read while modifying cyclecounter */
45879diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45880index fbe5363..266b4e3 100644
45881--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45882+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45883@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45884 struct __vxge_hw_fifo *fifo;
45885 struct vxge_hw_fifo_config *config;
45886 u32 txdl_size, txdl_per_memblock;
45887- struct vxge_hw_mempool_cbs fifo_mp_callback;
45888+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45889+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45890+ };
45891+
45892 struct __vxge_hw_virtualpath *vpath;
45893
45894 if ((vp == NULL) || (attr == NULL)) {
45895@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45896 goto exit;
45897 }
45898
45899- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45900-
45901 fifo->mempool =
45902 __vxge_hw_mempool_create(vpath->hldev,
45903 fifo->config->memblock_size,
45904diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45905index 918e18d..4ca3650 100644
45906--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45907+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45908@@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45909 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45910 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45911 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45912- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45913+ pax_open_kernel();
45914+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45915+ pax_close_kernel();
45916 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45917 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45918 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45919diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45920index 734d286..b017bf5 100644
45921--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45922+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45923@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45924 case QLCNIC_NON_PRIV_FUNC:
45925 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45926 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45927- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45928+ pax_open_kernel();
45929+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45930+ pax_close_kernel();
45931 break;
45932 case QLCNIC_PRIV_FUNC:
45933 ahw->op_mode = QLCNIC_PRIV_FUNC;
45934 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45935- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45936+ pax_open_kernel();
45937+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45938+ pax_close_kernel();
45939 break;
45940 case QLCNIC_MGMT_FUNC:
45941 ahw->op_mode = QLCNIC_MGMT_FUNC;
45942 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45943- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45944+ pax_open_kernel();
45945+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45946+ pax_close_kernel();
45947 break;
45948 default:
45949 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45950diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45951index 7763962..c3499a7 100644
45952--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45953+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45954@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45955 struct qlcnic_dump_entry *entry;
45956 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45957 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45958- static const struct qlcnic_dump_operations *fw_dump_ops;
45959+ const struct qlcnic_dump_operations *fw_dump_ops;
45960 struct device *dev = &adapter->pdev->dev;
45961 struct qlcnic_hardware_context *ahw;
45962 void *temp_buffer;
45963diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45964index c737f0e..32b8682 100644
45965--- a/drivers/net/ethernet/realtek/r8169.c
45966+++ b/drivers/net/ethernet/realtek/r8169.c
45967@@ -759,22 +759,22 @@ struct rtl8169_private {
45968 struct mdio_ops {
45969 void (*write)(struct rtl8169_private *, int, int);
45970 int (*read)(struct rtl8169_private *, int);
45971- } mdio_ops;
45972+ } __no_const mdio_ops;
45973
45974 struct pll_power_ops {
45975 void (*down)(struct rtl8169_private *);
45976 void (*up)(struct rtl8169_private *);
45977- } pll_power_ops;
45978+ } __no_const pll_power_ops;
45979
45980 struct jumbo_ops {
45981 void (*enable)(struct rtl8169_private *);
45982 void (*disable)(struct rtl8169_private *);
45983- } jumbo_ops;
45984+ } __no_const jumbo_ops;
45985
45986 struct csi_ops {
45987 void (*write)(struct rtl8169_private *, int, int);
45988 u32 (*read)(struct rtl8169_private *, int);
45989- } csi_ops;
45990+ } __no_const csi_ops;
45991
45992 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45993 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45994diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45995index a124103..59c74f8 100644
45996--- a/drivers/net/ethernet/sfc/ptp.c
45997+++ b/drivers/net/ethernet/sfc/ptp.c
45998@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45999 ptp->start.dma_addr);
46000
46001 /* Clear flag that signals MC ready */
46002- ACCESS_ONCE(*start) = 0;
46003+ ACCESS_ONCE_RW(*start) = 0;
46004 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46005 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46006 EFX_BUG_ON_PARANOID(rc);
46007diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46008index 50617c5..b13724c 100644
46009--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46010+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46011@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46012
46013 writel(value, ioaddr + MMC_CNTRL);
46014
46015- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46016- MMC_CNTRL, value);
46017+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46018+// MMC_CNTRL, value);
46019 }
46020
46021 /* To mask all all interrupts.*/
46022diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46023index e6fe0d8..2b7d752 100644
46024--- a/drivers/net/hyperv/hyperv_net.h
46025+++ b/drivers/net/hyperv/hyperv_net.h
46026@@ -101,7 +101,7 @@ struct rndis_device {
46027
46028 enum rndis_device_state state;
46029 bool link_state;
46030- atomic_t new_req_id;
46031+ atomic_unchecked_t new_req_id;
46032
46033 spinlock_t request_lock;
46034 struct list_head req_list;
46035diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46036index 0775f0a..d4fb316 100644
46037--- a/drivers/net/hyperv/rndis_filter.c
46038+++ b/drivers/net/hyperv/rndis_filter.c
46039@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46040 * template
46041 */
46042 set = &rndis_msg->msg.set_req;
46043- set->req_id = atomic_inc_return(&dev->new_req_id);
46044+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46045
46046 /* Add to the request list */
46047 spin_lock_irqsave(&dev->request_lock, flags);
46048@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46049
46050 /* Setup the rndis set */
46051 halt = &request->request_msg.msg.halt_req;
46052- halt->req_id = atomic_inc_return(&dev->new_req_id);
46053+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46054
46055 /* Ignore return since this msg is optional. */
46056 rndis_filter_send_request(dev, request);
46057diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46058index bf0d55e..82bcfbd1 100644
46059--- a/drivers/net/ieee802154/fakehard.c
46060+++ b/drivers/net/ieee802154/fakehard.c
46061@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46062 phy->transmit_power = 0xbf;
46063
46064 dev->netdev_ops = &fake_ops;
46065- dev->ml_priv = &fake_mlme;
46066+ dev->ml_priv = (void *)&fake_mlme;
46067
46068 priv = netdev_priv(dev);
46069 priv->phy = phy;
46070diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46071index d7e2907..1f8bfee 100644
46072--- a/drivers/net/macvlan.c
46073+++ b/drivers/net/macvlan.c
46074@@ -993,13 +993,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46075 int macvlan_link_register(struct rtnl_link_ops *ops)
46076 {
46077 /* common fields */
46078- ops->priv_size = sizeof(struct macvlan_dev);
46079- ops->validate = macvlan_validate;
46080- ops->maxtype = IFLA_MACVLAN_MAX;
46081- ops->policy = macvlan_policy;
46082- ops->changelink = macvlan_changelink;
46083- ops->get_size = macvlan_get_size;
46084- ops->fill_info = macvlan_fill_info;
46085+ pax_open_kernel();
46086+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46087+ *(void **)&ops->validate = macvlan_validate;
46088+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46089+ *(const void **)&ops->policy = macvlan_policy;
46090+ *(void **)&ops->changelink = macvlan_changelink;
46091+ *(void **)&ops->get_size = macvlan_get_size;
46092+ *(void **)&ops->fill_info = macvlan_fill_info;
46093+ pax_close_kernel();
46094
46095 return rtnl_link_register(ops);
46096 };
46097@@ -1054,7 +1056,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46098 return NOTIFY_DONE;
46099 }
46100
46101-static struct notifier_block macvlan_notifier_block __read_mostly = {
46102+static struct notifier_block macvlan_notifier_block = {
46103 .notifier_call = macvlan_device_event,
46104 };
46105
46106diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46107index 2a89da0..c17fe1d 100644
46108--- a/drivers/net/macvtap.c
46109+++ b/drivers/net/macvtap.c
46110@@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46111 }
46112
46113 ret = 0;
46114- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46115+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46116 put_user(q->flags, &ifr->ifr_flags))
46117 ret = -EFAULT;
46118 macvtap_put_vlan(vlan);
46119@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46120 return NOTIFY_DONE;
46121 }
46122
46123-static struct notifier_block macvtap_notifier_block __read_mostly = {
46124+static struct notifier_block macvtap_notifier_block = {
46125 .notifier_call = macvtap_device_event,
46126 };
46127
46128diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46129index daec9b0..6428fcb 100644
46130--- a/drivers/net/phy/mdio-bitbang.c
46131+++ b/drivers/net/phy/mdio-bitbang.c
46132@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46133 struct mdiobb_ctrl *ctrl = bus->priv;
46134
46135 module_put(ctrl->ops->owner);
46136+ mdiobus_unregister(bus);
46137 mdiobus_free(bus);
46138 }
46139 EXPORT_SYMBOL(free_mdio_bitbang);
46140diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46141index 72ff14b..11d442d 100644
46142--- a/drivers/net/ppp/ppp_generic.c
46143+++ b/drivers/net/ppp/ppp_generic.c
46144@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46145 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46146 struct ppp_stats stats;
46147 struct ppp_comp_stats cstats;
46148- char *vers;
46149
46150 switch (cmd) {
46151 case SIOCGPPPSTATS:
46152@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46153 break;
46154
46155 case SIOCGPPPVER:
46156- vers = PPP_VERSION;
46157- if (copy_to_user(addr, vers, strlen(vers) + 1))
46158+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46159 break;
46160 err = 0;
46161 break;
46162diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46163index 1252d9c..80e660b 100644
46164--- a/drivers/net/slip/slhc.c
46165+++ b/drivers/net/slip/slhc.c
46166@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46167 register struct tcphdr *thp;
46168 register struct iphdr *ip;
46169 register struct cstate *cs;
46170- int len, hdrlen;
46171+ long len, hdrlen;
46172 unsigned char *cp = icp;
46173
46174 /* We've got a compressed packet; read the change byte */
46175diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46176index b75ae5b..953c157 100644
46177--- a/drivers/net/team/team.c
46178+++ b/drivers/net/team/team.c
46179@@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46180 return NOTIFY_DONE;
46181 }
46182
46183-static struct notifier_block team_notifier_block __read_mostly = {
46184+static struct notifier_block team_notifier_block = {
46185 .notifier_call = team_device_event,
46186 };
46187
46188diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46189index 55c9238..ebb6ee5 100644
46190--- a/drivers/net/tun.c
46191+++ b/drivers/net/tun.c
46192@@ -1841,7 +1841,7 @@ unlock:
46193 }
46194
46195 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46196- unsigned long arg, int ifreq_len)
46197+ unsigned long arg, size_t ifreq_len)
46198 {
46199 struct tun_file *tfile = file->private_data;
46200 struct tun_struct *tun;
46201@@ -1854,6 +1854,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46202 unsigned int ifindex;
46203 int ret;
46204
46205+ if (ifreq_len > sizeof ifr)
46206+ return -EFAULT;
46207+
46208 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46209 if (copy_from_user(&ifr, argp, ifreq_len))
46210 return -EFAULT;
46211diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46212index 1a48234..a555339 100644
46213--- a/drivers/net/usb/hso.c
46214+++ b/drivers/net/usb/hso.c
46215@@ -71,7 +71,7 @@
46216 #include <asm/byteorder.h>
46217 #include <linux/serial_core.h>
46218 #include <linux/serial.h>
46219-
46220+#include <asm/local.h>
46221
46222 #define MOD_AUTHOR "Option Wireless"
46223 #define MOD_DESCRIPTION "USB High Speed Option driver"
46224@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46225 struct urb *urb;
46226
46227 urb = serial->rx_urb[0];
46228- if (serial->port.count > 0) {
46229+ if (atomic_read(&serial->port.count) > 0) {
46230 count = put_rxbuf_data(urb, serial);
46231 if (count == -1)
46232 return;
46233@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46234 DUMP1(urb->transfer_buffer, urb->actual_length);
46235
46236 /* Anyone listening? */
46237- if (serial->port.count == 0)
46238+ if (atomic_read(&serial->port.count) == 0)
46239 return;
46240
46241 if (status == 0) {
46242@@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46243 tty_port_tty_set(&serial->port, tty);
46244
46245 /* check for port already opened, if not set the termios */
46246- serial->port.count++;
46247- if (serial->port.count == 1) {
46248+ if (atomic_inc_return(&serial->port.count) == 1) {
46249 serial->rx_state = RX_IDLE;
46250 /* Force default termio settings */
46251 _hso_serial_set_termios(tty, NULL);
46252@@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46253 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46254 if (result) {
46255 hso_stop_serial_device(serial->parent);
46256- serial->port.count--;
46257+ atomic_dec(&serial->port.count);
46258 kref_put(&serial->parent->ref, hso_serial_ref_free);
46259 }
46260 } else {
46261@@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46262
46263 /* reset the rts and dtr */
46264 /* do the actual close */
46265- serial->port.count--;
46266+ atomic_dec(&serial->port.count);
46267
46268- if (serial->port.count <= 0) {
46269- serial->port.count = 0;
46270+ if (atomic_read(&serial->port.count) <= 0) {
46271+ atomic_set(&serial->port.count, 0);
46272 tty_port_tty_set(&serial->port, NULL);
46273 if (!usb_gone)
46274 hso_stop_serial_device(serial->parent);
46275@@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46276
46277 /* the actual setup */
46278 spin_lock_irqsave(&serial->serial_lock, flags);
46279- if (serial->port.count)
46280+ if (atomic_read(&serial->port.count))
46281 _hso_serial_set_termios(tty, old);
46282 else
46283 tty->termios = *old;
46284@@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46285 D1("Pending read interrupt on port %d\n", i);
46286 spin_lock(&serial->serial_lock);
46287 if (serial->rx_state == RX_IDLE &&
46288- serial->port.count > 0) {
46289+ atomic_read(&serial->port.count) > 0) {
46290 /* Setup and send a ctrl req read on
46291 * port i */
46292 if (!serial->rx_urb_filled[0]) {
46293@@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46294 /* Start all serial ports */
46295 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46296 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46297- if (dev2ser(serial_table[i])->port.count) {
46298+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46299 result =
46300 hso_start_serial_device(serial_table[i], GFP_NOIO);
46301 hso_kick_transmit(dev2ser(serial_table[i]));
46302diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46303index a79e9d3..78cd4fa 100644
46304--- a/drivers/net/usb/sierra_net.c
46305+++ b/drivers/net/usb/sierra_net.c
46306@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46307 /* atomic counter partially included in MAC address to make sure 2 devices
46308 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46309 */
46310-static atomic_t iface_counter = ATOMIC_INIT(0);
46311+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46312
46313 /*
46314 * SYNC Timer Delay definition used to set the expiry time
46315@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46316 dev->net->netdev_ops = &sierra_net_device_ops;
46317
46318 /* change MAC addr to include, ifacenum, and to be unique */
46319- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46320+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46321 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46322
46323 /* we will have to manufacture ethernet headers, prepare template */
46324diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46325index 0247973..088193a 100644
46326--- a/drivers/net/vxlan.c
46327+++ b/drivers/net/vxlan.c
46328@@ -2615,7 +2615,7 @@ nla_put_failure:
46329 return -EMSGSIZE;
46330 }
46331
46332-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46333+static struct rtnl_link_ops vxlan_link_ops = {
46334 .kind = "vxlan",
46335 .maxtype = IFLA_VXLAN_MAX,
46336 .policy = vxlan_policy,
46337diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46338index 5920c99..ff2e4a5 100644
46339--- a/drivers/net/wan/lmc/lmc_media.c
46340+++ b/drivers/net/wan/lmc/lmc_media.c
46341@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46342 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46343
46344 lmc_media_t lmc_ds3_media = {
46345- lmc_ds3_init, /* special media init stuff */
46346- lmc_ds3_default, /* reset to default state */
46347- lmc_ds3_set_status, /* reset status to state provided */
46348- lmc_dummy_set_1, /* set clock source */
46349- lmc_dummy_set2_1, /* set line speed */
46350- lmc_ds3_set_100ft, /* set cable length */
46351- lmc_ds3_set_scram, /* set scrambler */
46352- lmc_ds3_get_link_status, /* get link status */
46353- lmc_dummy_set_1, /* set link status */
46354- lmc_ds3_set_crc_length, /* set CRC length */
46355- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46356- lmc_ds3_watchdog
46357+ .init = lmc_ds3_init, /* special media init stuff */
46358+ .defaults = lmc_ds3_default, /* reset to default state */
46359+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46360+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46361+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46362+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46363+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46364+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46365+ .set_link_status = lmc_dummy_set_1, /* set link status */
46366+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46367+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46368+ .watchdog = lmc_ds3_watchdog
46369 };
46370
46371 lmc_media_t lmc_hssi_media = {
46372- lmc_hssi_init, /* special media init stuff */
46373- lmc_hssi_default, /* reset to default state */
46374- lmc_hssi_set_status, /* reset status to state provided */
46375- lmc_hssi_set_clock, /* set clock source */
46376- lmc_dummy_set2_1, /* set line speed */
46377- lmc_dummy_set_1, /* set cable length */
46378- lmc_dummy_set_1, /* set scrambler */
46379- lmc_hssi_get_link_status, /* get link status */
46380- lmc_hssi_set_link_status, /* set link status */
46381- lmc_hssi_set_crc_length, /* set CRC length */
46382- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46383- lmc_hssi_watchdog
46384+ .init = lmc_hssi_init, /* special media init stuff */
46385+ .defaults = lmc_hssi_default, /* reset to default state */
46386+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46387+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46388+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46389+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46390+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46391+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46392+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46393+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46394+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46395+ .watchdog = lmc_hssi_watchdog
46396 };
46397
46398-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46399- lmc_ssi_default, /* reset to default state */
46400- lmc_ssi_set_status, /* reset status to state provided */
46401- lmc_ssi_set_clock, /* set clock source */
46402- lmc_ssi_set_speed, /* set line speed */
46403- lmc_dummy_set_1, /* set cable length */
46404- lmc_dummy_set_1, /* set scrambler */
46405- lmc_ssi_get_link_status, /* get link status */
46406- lmc_ssi_set_link_status, /* set link status */
46407- lmc_ssi_set_crc_length, /* set CRC length */
46408- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46409- lmc_ssi_watchdog
46410+lmc_media_t lmc_ssi_media = {
46411+ .init = lmc_ssi_init, /* special media init stuff */
46412+ .defaults = lmc_ssi_default, /* reset to default state */
46413+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46414+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46415+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46416+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46417+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46418+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46419+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46420+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46421+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46422+ .watchdog = lmc_ssi_watchdog
46423 };
46424
46425 lmc_media_t lmc_t1_media = {
46426- lmc_t1_init, /* special media init stuff */
46427- lmc_t1_default, /* reset to default state */
46428- lmc_t1_set_status, /* reset status to state provided */
46429- lmc_t1_set_clock, /* set clock source */
46430- lmc_dummy_set2_1, /* set line speed */
46431- lmc_dummy_set_1, /* set cable length */
46432- lmc_dummy_set_1, /* set scrambler */
46433- lmc_t1_get_link_status, /* get link status */
46434- lmc_dummy_set_1, /* set link status */
46435- lmc_t1_set_crc_length, /* set CRC length */
46436- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46437- lmc_t1_watchdog
46438+ .init = lmc_t1_init, /* special media init stuff */
46439+ .defaults = lmc_t1_default, /* reset to default state */
46440+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46441+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46442+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46443+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46444+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46445+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46446+ .set_link_status = lmc_dummy_set_1, /* set link status */
46447+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46448+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46449+ .watchdog = lmc_t1_watchdog
46450 };
46451
46452 static void
46453diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46454index feacc3b..5bac0de 100644
46455--- a/drivers/net/wan/z85230.c
46456+++ b/drivers/net/wan/z85230.c
46457@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46458
46459 struct z8530_irqhandler z8530_sync =
46460 {
46461- z8530_rx,
46462- z8530_tx,
46463- z8530_status
46464+ .rx = z8530_rx,
46465+ .tx = z8530_tx,
46466+ .status = z8530_status
46467 };
46468
46469 EXPORT_SYMBOL(z8530_sync);
46470@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46471 }
46472
46473 static struct z8530_irqhandler z8530_dma_sync = {
46474- z8530_dma_rx,
46475- z8530_dma_tx,
46476- z8530_dma_status
46477+ .rx = z8530_dma_rx,
46478+ .tx = z8530_dma_tx,
46479+ .status = z8530_dma_status
46480 };
46481
46482 static struct z8530_irqhandler z8530_txdma_sync = {
46483- z8530_rx,
46484- z8530_dma_tx,
46485- z8530_dma_status
46486+ .rx = z8530_rx,
46487+ .tx = z8530_dma_tx,
46488+ .status = z8530_dma_status
46489 };
46490
46491 /**
46492@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46493
46494 struct z8530_irqhandler z8530_nop=
46495 {
46496- z8530_rx_clear,
46497- z8530_tx_clear,
46498- z8530_status_clear
46499+ .rx = z8530_rx_clear,
46500+ .tx = z8530_tx_clear,
46501+ .status = z8530_status_clear
46502 };
46503
46504
46505diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46506index 0b60295..b8bfa5b 100644
46507--- a/drivers/net/wimax/i2400m/rx.c
46508+++ b/drivers/net/wimax/i2400m/rx.c
46509@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46510 if (i2400m->rx_roq == NULL)
46511 goto error_roq_alloc;
46512
46513- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46514+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46515 GFP_KERNEL);
46516 if (rd == NULL) {
46517 result = -ENOMEM;
46518diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46519index edf4b57..68b51c0 100644
46520--- a/drivers/net/wireless/airo.c
46521+++ b/drivers/net/wireless/airo.c
46522@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46523 struct airo_info *ai = dev->ml_priv;
46524 int ridcode;
46525 int enabled;
46526- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46527+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46528 unsigned char *iobuf;
46529
46530 /* Only super-user can write RIDs */
46531diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46532index 34c8a33..3261fdc 100644
46533--- a/drivers/net/wireless/at76c50x-usb.c
46534+++ b/drivers/net/wireless/at76c50x-usb.c
46535@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46536 }
46537
46538 /* Convert timeout from the DFU status to jiffies */
46539-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46540+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46541 {
46542 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46543 | (s->poll_timeout[1] << 8)
46544diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46545index edae50b..b24278c 100644
46546--- a/drivers/net/wireless/ath/ath10k/htc.c
46547+++ b/drivers/net/wireless/ath/ath10k/htc.c
46548@@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46549 /* registered target arrival callback from the HIF layer */
46550 int ath10k_htc_init(struct ath10k *ar)
46551 {
46552- struct ath10k_hif_cb htc_callbacks;
46553+ static struct ath10k_hif_cb htc_callbacks = {
46554+ .rx_completion = ath10k_htc_rx_completion_handler,
46555+ .tx_completion = ath10k_htc_tx_completion_handler,
46556+ };
46557 struct ath10k_htc_ep *ep = NULL;
46558 struct ath10k_htc *htc = &ar->htc;
46559
46560@@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46561 ath10k_htc_reset_endpoint_states(htc);
46562
46563 /* setup HIF layer callbacks */
46564- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46565- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46566 htc->ar = ar;
46567
46568 /* Get HIF default pipe for HTC message exchange */
46569diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46570index 4716d33..a688310 100644
46571--- a/drivers/net/wireless/ath/ath10k/htc.h
46572+++ b/drivers/net/wireless/ath/ath10k/htc.h
46573@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46574
46575 struct ath10k_htc_ops {
46576 void (*target_send_suspend_complete)(struct ath10k *ar);
46577-};
46578+} __no_const;
46579
46580 struct ath10k_htc_ep_ops {
46581 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46582 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46583 void (*ep_tx_credits)(struct ath10k *);
46584-};
46585+} __no_const;
46586
46587 /* service connection information */
46588 struct ath10k_htc_svc_conn_req {
46589diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46590index a366d6b..b6f28f8 100644
46591--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46592+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46593@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46594 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46595 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46596
46597- ACCESS_ONCE(ads->ds_link) = i->link;
46598- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46599+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46600+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46601
46602 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46603 ctl6 = SM(i->keytype, AR_EncrType);
46604@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46605
46606 if ((i->is_first || i->is_last) &&
46607 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46608- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46609+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46610 | set11nTries(i->rates, 1)
46611 | set11nTries(i->rates, 2)
46612 | set11nTries(i->rates, 3)
46613 | (i->dur_update ? AR_DurUpdateEna : 0)
46614 | SM(0, AR_BurstDur);
46615
46616- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46617+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46618 | set11nRate(i->rates, 1)
46619 | set11nRate(i->rates, 2)
46620 | set11nRate(i->rates, 3);
46621 } else {
46622- ACCESS_ONCE(ads->ds_ctl2) = 0;
46623- ACCESS_ONCE(ads->ds_ctl3) = 0;
46624+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46625+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46626 }
46627
46628 if (!i->is_first) {
46629- ACCESS_ONCE(ads->ds_ctl0) = 0;
46630- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46631- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46632+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46633+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46634+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46635 return;
46636 }
46637
46638@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46639 break;
46640 }
46641
46642- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46643+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46644 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46645 | SM(i->txpower, AR_XmitPower)
46646 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46647@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46648 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46649 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46650
46651- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46652- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46653+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46654+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46655
46656 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46657 return;
46658
46659- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46660+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46661 | set11nPktDurRTSCTS(i->rates, 1);
46662
46663- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46664+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46665 | set11nPktDurRTSCTS(i->rates, 3);
46666
46667- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46668+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46669 | set11nRateFlags(i->rates, 1)
46670 | set11nRateFlags(i->rates, 2)
46671 | set11nRateFlags(i->rates, 3)
46672diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46673index f6c5c1b..6058354 100644
46674--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46675+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46676@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46677 (i->qcu << AR_TxQcuNum_S) | desc_len;
46678
46679 checksum += val;
46680- ACCESS_ONCE(ads->info) = val;
46681+ ACCESS_ONCE_RW(ads->info) = val;
46682
46683 checksum += i->link;
46684- ACCESS_ONCE(ads->link) = i->link;
46685+ ACCESS_ONCE_RW(ads->link) = i->link;
46686
46687 checksum += i->buf_addr[0];
46688- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46689+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46690 checksum += i->buf_addr[1];
46691- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46692+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46693 checksum += i->buf_addr[2];
46694- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46695+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46696 checksum += i->buf_addr[3];
46697- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46698+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46699
46700 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46701- ACCESS_ONCE(ads->ctl3) = val;
46702+ ACCESS_ONCE_RW(ads->ctl3) = val;
46703 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46704- ACCESS_ONCE(ads->ctl5) = val;
46705+ ACCESS_ONCE_RW(ads->ctl5) = val;
46706 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46707- ACCESS_ONCE(ads->ctl7) = val;
46708+ ACCESS_ONCE_RW(ads->ctl7) = val;
46709 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46710- ACCESS_ONCE(ads->ctl9) = val;
46711+ ACCESS_ONCE_RW(ads->ctl9) = val;
46712
46713 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46714- ACCESS_ONCE(ads->ctl10) = checksum;
46715+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46716
46717 if (i->is_first || i->is_last) {
46718- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46719+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46720 | set11nTries(i->rates, 1)
46721 | set11nTries(i->rates, 2)
46722 | set11nTries(i->rates, 3)
46723 | (i->dur_update ? AR_DurUpdateEna : 0)
46724 | SM(0, AR_BurstDur);
46725
46726- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46727+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46728 | set11nRate(i->rates, 1)
46729 | set11nRate(i->rates, 2)
46730 | set11nRate(i->rates, 3);
46731 } else {
46732- ACCESS_ONCE(ads->ctl13) = 0;
46733- ACCESS_ONCE(ads->ctl14) = 0;
46734+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46735+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46736 }
46737
46738 ads->ctl20 = 0;
46739@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46740
46741 ctl17 = SM(i->keytype, AR_EncrType);
46742 if (!i->is_first) {
46743- ACCESS_ONCE(ads->ctl11) = 0;
46744- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46745- ACCESS_ONCE(ads->ctl15) = 0;
46746- ACCESS_ONCE(ads->ctl16) = 0;
46747- ACCESS_ONCE(ads->ctl17) = ctl17;
46748- ACCESS_ONCE(ads->ctl18) = 0;
46749- ACCESS_ONCE(ads->ctl19) = 0;
46750+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46751+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46752+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46753+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46754+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46755+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46756+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46757 return;
46758 }
46759
46760- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46761+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46762 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46763 | SM(i->txpower, AR_XmitPower)
46764 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46765@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46766 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46767 ctl12 |= SM(val, AR_PAPRDChainMask);
46768
46769- ACCESS_ONCE(ads->ctl12) = ctl12;
46770- ACCESS_ONCE(ads->ctl17) = ctl17;
46771+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46772+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46773
46774- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46775+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46776 | set11nPktDurRTSCTS(i->rates, 1);
46777
46778- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46779+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46780 | set11nPktDurRTSCTS(i->rates, 3);
46781
46782- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46783+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46784 | set11nRateFlags(i->rates, 1)
46785 | set11nRateFlags(i->rates, 2)
46786 | set11nRateFlags(i->rates, 3)
46787 | SM(i->rtscts_rate, AR_RTSCTSRate);
46788
46789- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46790+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46791 }
46792
46793 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46794diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46795index a2c9a5d..b52273e 100644
46796--- a/drivers/net/wireless/ath/ath9k/hw.h
46797+++ b/drivers/net/wireless/ath/ath9k/hw.h
46798@@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46799
46800 /* ANI */
46801 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46802-};
46803+} __no_const;
46804
46805 /**
46806 * struct ath_spec_scan - parameters for Atheros spectral scan
46807@@ -711,7 +711,7 @@ struct ath_hw_ops {
46808 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46809 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46810 #endif
46811-};
46812+} __no_const;
46813
46814 struct ath_nf_limits {
46815 s16 max;
46816diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46817index 92190da..f3a4c4c 100644
46818--- a/drivers/net/wireless/b43/phy_lp.c
46819+++ b/drivers/net/wireless/b43/phy_lp.c
46820@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46821 {
46822 struct ssb_bus *bus = dev->dev->sdev->bus;
46823
46824- static const struct b206x_channel *chandata = NULL;
46825+ const struct b206x_channel *chandata = NULL;
46826 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46827 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46828 u16 old_comm15, scale;
46829diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46830index dea3b50..543db99 100644
46831--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46832+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46833@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46834 */
46835 if (il3945_mod_params.disable_hw_scan) {
46836 D_INFO("Disabling hw_scan\n");
46837- il3945_mac_ops.hw_scan = NULL;
46838+ pax_open_kernel();
46839+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46840+ pax_close_kernel();
46841 }
46842
46843 D_INFO("*** LOAD DRIVER ***\n");
46844diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46845index d94f8ab..5b568c8 100644
46846--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46847+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46848@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46849 {
46850 struct iwl_priv *priv = file->private_data;
46851 char buf[64];
46852- int buf_size;
46853+ size_t buf_size;
46854 u32 offset, len;
46855
46856 memset(buf, 0, sizeof(buf));
46857@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46858 struct iwl_priv *priv = file->private_data;
46859
46860 char buf[8];
46861- int buf_size;
46862+ size_t buf_size;
46863 u32 reset_flag;
46864
46865 memset(buf, 0, sizeof(buf));
46866@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46867 {
46868 struct iwl_priv *priv = file->private_data;
46869 char buf[8];
46870- int buf_size;
46871+ size_t buf_size;
46872 int ht40;
46873
46874 memset(buf, 0, sizeof(buf));
46875@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46876 {
46877 struct iwl_priv *priv = file->private_data;
46878 char buf[8];
46879- int buf_size;
46880+ size_t buf_size;
46881 int value;
46882
46883 memset(buf, 0, sizeof(buf));
46884@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46885 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46886 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46887
46888-static const char *fmt_value = " %-30s %10u\n";
46889-static const char *fmt_hex = " %-30s 0x%02X\n";
46890-static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46891-static const char *fmt_header =
46892+static const char fmt_value[] = " %-30s %10u\n";
46893+static const char fmt_hex[] = " %-30s 0x%02X\n";
46894+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46895+static const char fmt_header[] =
46896 "%-32s current cumulative delta max\n";
46897
46898 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46899@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46900 {
46901 struct iwl_priv *priv = file->private_data;
46902 char buf[8];
46903- int buf_size;
46904+ size_t buf_size;
46905 int clear;
46906
46907 memset(buf, 0, sizeof(buf));
46908@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46909 {
46910 struct iwl_priv *priv = file->private_data;
46911 char buf[8];
46912- int buf_size;
46913+ size_t buf_size;
46914 int trace;
46915
46916 memset(buf, 0, sizeof(buf));
46917@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_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 missed;
46924
46925 memset(buf, 0, sizeof(buf));
46926@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_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 plcp;
46933
46934 memset(buf, 0, sizeof(buf));
46935@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_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 flush;
46942
46943 memset(buf, 0, sizeof(buf));
46944@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_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 rts;
46951
46952 if (!priv->cfg->ht_params)
46953@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_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
46960 memset(buf, 0, sizeof(buf));
46961 buf_size = min(count, sizeof(buf) - 1);
46962@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46963 struct iwl_priv *priv = file->private_data;
46964 u32 event_log_flag;
46965 char buf[8];
46966- int buf_size;
46967+ size_t buf_size;
46968
46969 /* check that the interface is up */
46970 if (!iwl_is_ready(priv))
46971@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46972 struct iwl_priv *priv = file->private_data;
46973 char buf[8];
46974 u32 calib_disabled;
46975- int buf_size;
46976+ size_t buf_size;
46977
46978 memset(buf, 0, sizeof(buf));
46979 buf_size = min(count, sizeof(buf) - 1);
46980diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46981index 7aad766..06addb4 100644
46982--- a/drivers/net/wireless/iwlwifi/dvm/main.c
46983+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46984@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46985 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46986 {
46987 struct iwl_nvm_data *data = priv->nvm_data;
46988- char *debug_msg;
46989+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46990
46991 if (data->sku_cap_11n_enable &&
46992 !priv->cfg->ht_params) {
46993@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46994 return -EINVAL;
46995 }
46996
46997- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46998 IWL_DEBUG_INFO(priv, debug_msg,
46999 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47000 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47001diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47002index f53ef83..5e34bcb 100644
47003--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47004+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47005@@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47006 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47007
47008 char buf[8];
47009- int buf_size;
47010+ size_t buf_size;
47011 u32 reset_flag;
47012
47013 memset(buf, 0, sizeof(buf));
47014@@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47015 {
47016 struct iwl_trans *trans = file->private_data;
47017 char buf[8];
47018- int buf_size;
47019+ size_t buf_size;
47020 int csr;
47021
47022 memset(buf, 0, sizeof(buf));
47023diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47024index a1b32ee..94b3c3d 100644
47025--- a/drivers/net/wireless/mac80211_hwsim.c
47026+++ b/drivers/net/wireless/mac80211_hwsim.c
47027@@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47028
47029 if (channels > 1) {
47030 hwsim_if_comb.num_different_channels = channels;
47031- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47032- mac80211_hwsim_ops.cancel_hw_scan =
47033- mac80211_hwsim_cancel_hw_scan;
47034- mac80211_hwsim_ops.sw_scan_start = NULL;
47035- mac80211_hwsim_ops.sw_scan_complete = NULL;
47036- mac80211_hwsim_ops.remain_on_channel =
47037- mac80211_hwsim_roc;
47038- mac80211_hwsim_ops.cancel_remain_on_channel =
47039- mac80211_hwsim_croc;
47040- mac80211_hwsim_ops.add_chanctx =
47041- mac80211_hwsim_add_chanctx;
47042- mac80211_hwsim_ops.remove_chanctx =
47043- mac80211_hwsim_remove_chanctx;
47044- mac80211_hwsim_ops.change_chanctx =
47045- mac80211_hwsim_change_chanctx;
47046- mac80211_hwsim_ops.assign_vif_chanctx =
47047- mac80211_hwsim_assign_vif_chanctx;
47048- mac80211_hwsim_ops.unassign_vif_chanctx =
47049- mac80211_hwsim_unassign_vif_chanctx;
47050+ pax_open_kernel();
47051+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47052+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47053+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47054+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47055+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47056+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47057+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47058+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47059+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47060+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47061+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47062+ pax_close_kernel();
47063 }
47064
47065 spin_lock_init(&hwsim_radio_lock);
47066diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47067index 8169a85..7fa3b47 100644
47068--- a/drivers/net/wireless/rndis_wlan.c
47069+++ b/drivers/net/wireless/rndis_wlan.c
47070@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47071
47072 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47073
47074- if (rts_threshold < 0 || rts_threshold > 2347)
47075+ if (rts_threshold > 2347)
47076 rts_threshold = 2347;
47077
47078 tmp = cpu_to_le32(rts_threshold);
47079diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47080index e4ba2ce..63d7417 100644
47081--- a/drivers/net/wireless/rt2x00/rt2x00.h
47082+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47083@@ -377,7 +377,7 @@ struct rt2x00_intf {
47084 * for hardware which doesn't support hardware
47085 * sequence counting.
47086 */
47087- atomic_t seqno;
47088+ atomic_unchecked_t seqno;
47089 };
47090
47091 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47092diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47093index a5d38e8..d3c24ea 100644
47094--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47095+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47096@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47097 * sequence counter given by mac80211.
47098 */
47099 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47100- seqno = atomic_add_return(0x10, &intf->seqno);
47101+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47102 else
47103- seqno = atomic_read(&intf->seqno);
47104+ seqno = atomic_read_unchecked(&intf->seqno);
47105
47106 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47107 hdr->seq_ctrl |= cpu_to_le16(seqno);
47108diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47109index e2b3d9c..67a5184 100644
47110--- a/drivers/net/wireless/ti/wl1251/sdio.c
47111+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47112@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47113
47114 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47115
47116- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47117- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47118+ pax_open_kernel();
47119+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47120+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47121+ pax_close_kernel();
47122
47123 wl1251_info("using dedicated interrupt line");
47124 } else {
47125- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47126- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47127+ pax_open_kernel();
47128+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47129+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47130+ pax_close_kernel();
47131
47132 wl1251_info("using SDIO interrupt");
47133 }
47134diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47135index be7129b..4161356 100644
47136--- a/drivers/net/wireless/ti/wl12xx/main.c
47137+++ b/drivers/net/wireless/ti/wl12xx/main.c
47138@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47139 sizeof(wl->conf.mem));
47140
47141 /* read data preparation is only needed by wl127x */
47142- wl->ops->prepare_read = wl127x_prepare_read;
47143+ pax_open_kernel();
47144+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47145+ pax_close_kernel();
47146
47147 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47148 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47149@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47150 sizeof(wl->conf.mem));
47151
47152 /* read data preparation is only needed by wl127x */
47153- wl->ops->prepare_read = wl127x_prepare_read;
47154+ pax_open_kernel();
47155+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47156+ pax_close_kernel();
47157
47158 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47159 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47160diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47161index ec37b16..7e34d66 100644
47162--- a/drivers/net/wireless/ti/wl18xx/main.c
47163+++ b/drivers/net/wireless/ti/wl18xx/main.c
47164@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47165 }
47166
47167 if (!checksum_param) {
47168- wl18xx_ops.set_rx_csum = NULL;
47169- wl18xx_ops.init_vif = NULL;
47170+ pax_open_kernel();
47171+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47172+ *(void **)&wl18xx_ops.init_vif = NULL;
47173+ pax_close_kernel();
47174 }
47175
47176 /* Enable 11a Band only if we have 5G antennas */
47177diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47178index 84d94f5..bd6c61c 100644
47179--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47180+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47181@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47182 {
47183 struct zd_usb *usb = urb->context;
47184 struct zd_usb_interrupt *intr = &usb->intr;
47185- int len;
47186+ unsigned int len;
47187 u16 int_num;
47188
47189 ZD_ASSERT(in_interrupt());
47190diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47191index 7130864..00e64de 100644
47192--- a/drivers/nfc/nfcwilink.c
47193+++ b/drivers/nfc/nfcwilink.c
47194@@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47195
47196 static int nfcwilink_probe(struct platform_device *pdev)
47197 {
47198- static struct nfcwilink *drv;
47199+ struct nfcwilink *drv;
47200 int rc;
47201 __u32 protocols;
47202
47203diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47204index d93b2b6..ae50401 100644
47205--- a/drivers/oprofile/buffer_sync.c
47206+++ b/drivers/oprofile/buffer_sync.c
47207@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47208 if (cookie == NO_COOKIE)
47209 offset = pc;
47210 if (cookie == INVALID_COOKIE) {
47211- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47212+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47213 offset = pc;
47214 }
47215 if (cookie != last_cookie) {
47216@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47217 /* add userspace sample */
47218
47219 if (!mm) {
47220- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47221+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47222 return 0;
47223 }
47224
47225 cookie = lookup_dcookie(mm, s->eip, &offset);
47226
47227 if (cookie == INVALID_COOKIE) {
47228- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47229+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47230 return 0;
47231 }
47232
47233@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47234 /* ignore backtraces if failed to add a sample */
47235 if (state == sb_bt_start) {
47236 state = sb_bt_ignore;
47237- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47238+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47239 }
47240 }
47241 release_mm(mm);
47242diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47243index c0cc4e7..44d4e54 100644
47244--- a/drivers/oprofile/event_buffer.c
47245+++ b/drivers/oprofile/event_buffer.c
47246@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47247 }
47248
47249 if (buffer_pos == buffer_size) {
47250- atomic_inc(&oprofile_stats.event_lost_overflow);
47251+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47252 return;
47253 }
47254
47255diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47256index ed2c3ec..deda85a 100644
47257--- a/drivers/oprofile/oprof.c
47258+++ b/drivers/oprofile/oprof.c
47259@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47260 if (oprofile_ops.switch_events())
47261 return;
47262
47263- atomic_inc(&oprofile_stats.multiplex_counter);
47264+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47265 start_switch_worker();
47266 }
47267
47268diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47269index ee2cfce..7f8f699 100644
47270--- a/drivers/oprofile/oprofile_files.c
47271+++ b/drivers/oprofile/oprofile_files.c
47272@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47273
47274 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47275
47276-static ssize_t timeout_read(struct file *file, char __user *buf,
47277+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47278 size_t count, loff_t *offset)
47279 {
47280 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47281diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47282index 59659ce..6c860a0 100644
47283--- a/drivers/oprofile/oprofile_stats.c
47284+++ b/drivers/oprofile/oprofile_stats.c
47285@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47286 cpu_buf->sample_invalid_eip = 0;
47287 }
47288
47289- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47290- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47291- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47292- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47293- atomic_set(&oprofile_stats.multiplex_counter, 0);
47294+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47295+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47296+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47297+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47298+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47299 }
47300
47301
47302diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47303index 1fc622b..8c48fc3 100644
47304--- a/drivers/oprofile/oprofile_stats.h
47305+++ b/drivers/oprofile/oprofile_stats.h
47306@@ -13,11 +13,11 @@
47307 #include <linux/atomic.h>
47308
47309 struct oprofile_stat_struct {
47310- atomic_t sample_lost_no_mm;
47311- atomic_t sample_lost_no_mapping;
47312- atomic_t bt_lost_no_mapping;
47313- atomic_t event_lost_overflow;
47314- atomic_t multiplex_counter;
47315+ atomic_unchecked_t sample_lost_no_mm;
47316+ atomic_unchecked_t sample_lost_no_mapping;
47317+ atomic_unchecked_t bt_lost_no_mapping;
47318+ atomic_unchecked_t event_lost_overflow;
47319+ atomic_unchecked_t multiplex_counter;
47320 };
47321
47322 extern struct oprofile_stat_struct oprofile_stats;
47323diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47324index 3f49345..c750d0b 100644
47325--- a/drivers/oprofile/oprofilefs.c
47326+++ b/drivers/oprofile/oprofilefs.c
47327@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47328
47329 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47330 {
47331- atomic_t *val = file->private_data;
47332- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47333+ atomic_unchecked_t *val = file->private_data;
47334+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47335 }
47336
47337
47338@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47339
47340
47341 int oprofilefs_create_ro_atomic(struct dentry *root,
47342- char const *name, atomic_t *val)
47343+ char const *name, atomic_unchecked_t *val)
47344 {
47345 return __oprofilefs_create_file(root, name,
47346 &atomic_ro_fops, 0444, val);
47347diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47348index 61be1d9..dec05d7 100644
47349--- a/drivers/oprofile/timer_int.c
47350+++ b/drivers/oprofile/timer_int.c
47351@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47352 return NOTIFY_OK;
47353 }
47354
47355-static struct notifier_block __refdata oprofile_cpu_notifier = {
47356+static struct notifier_block oprofile_cpu_notifier = {
47357 .notifier_call = oprofile_cpu_notify,
47358 };
47359
47360diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47361index 92ed045..62d39bd7 100644
47362--- a/drivers/parport/procfs.c
47363+++ b/drivers/parport/procfs.c
47364@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47365
47366 *ppos += len;
47367
47368- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47369+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47370 }
47371
47372 #ifdef CONFIG_PARPORT_1284
47373@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47374
47375 *ppos += len;
47376
47377- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47378+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47379 }
47380 #endif /* IEEE1284.3 support. */
47381
47382diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47383index ecfac7e..41be7028 100644
47384--- a/drivers/pci/hotplug/acpiphp_ibm.c
47385+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47386@@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47387 goto init_cleanup;
47388 }
47389
47390- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47391+ pax_open_kernel();
47392+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47393+ pax_close_kernel();
47394 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47395
47396 return retval;
47397diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47398index 7536eef..52dc8fa 100644
47399--- a/drivers/pci/hotplug/cpcihp_generic.c
47400+++ b/drivers/pci/hotplug/cpcihp_generic.c
47401@@ -73,7 +73,6 @@ static u16 port;
47402 static unsigned int enum_bit;
47403 static u8 enum_mask;
47404
47405-static struct cpci_hp_controller_ops generic_hpc_ops;
47406 static struct cpci_hp_controller generic_hpc;
47407
47408 static int __init validate_parameters(void)
47409@@ -139,6 +138,10 @@ static int query_enum(void)
47410 return ((value & enum_mask) == enum_mask);
47411 }
47412
47413+static struct cpci_hp_controller_ops generic_hpc_ops = {
47414+ .query_enum = query_enum,
47415+};
47416+
47417 static int __init cpcihp_generic_init(void)
47418 {
47419 int status;
47420@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47421 pci_dev_put(dev);
47422
47423 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47424- generic_hpc_ops.query_enum = query_enum;
47425 generic_hpc.ops = &generic_hpc_ops;
47426
47427 status = cpci_hp_register_controller(&generic_hpc);
47428diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47429index e8c4a7c..7046f5c 100644
47430--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47431+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47432@@ -59,7 +59,6 @@
47433 /* local variables */
47434 static bool debug;
47435 static bool poll;
47436-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47437 static struct cpci_hp_controller zt5550_hpc;
47438
47439 /* Primary cPCI bus bridge device */
47440@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47441 return 0;
47442 }
47443
47444+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47445+ .query_enum = zt5550_hc_query_enum,
47446+};
47447+
47448 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47449 {
47450 int status;
47451@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47452 dbg("returned from zt5550_hc_config");
47453
47454 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47455- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47456 zt5550_hpc.ops = &zt5550_hpc_ops;
47457 if(!poll) {
47458 zt5550_hpc.irq = hc_dev->irq;
47459 zt5550_hpc.irq_flags = IRQF_SHARED;
47460 zt5550_hpc.dev_id = hc_dev;
47461
47462- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47463- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47464- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47465+ pax_open_kernel();
47466+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47467+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47468+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47469+ pax_open_kernel();
47470 } else {
47471 info("using ENUM# polling mode");
47472 }
47473diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47474index 76ba8a1..20ca857 100644
47475--- a/drivers/pci/hotplug/cpqphp_nvram.c
47476+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47477@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47478
47479 void compaq_nvram_init (void __iomem *rom_start)
47480 {
47481+
47482+#ifndef CONFIG_PAX_KERNEXEC
47483 if (rom_start) {
47484 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47485 }
47486+#endif
47487+
47488 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47489
47490 /* initialize our int15 lock */
47491diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47492index cfa92a9..29539c5 100644
47493--- a/drivers/pci/hotplug/pci_hotplug_core.c
47494+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47495@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47496 return -EINVAL;
47497 }
47498
47499- slot->ops->owner = owner;
47500- slot->ops->mod_name = mod_name;
47501+ pax_open_kernel();
47502+ *(struct module **)&slot->ops->owner = owner;
47503+ *(const char **)&slot->ops->mod_name = mod_name;
47504+ pax_close_kernel();
47505
47506 mutex_lock(&pci_hp_mutex);
47507 /*
47508diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47509index bbd48bb..6907ef4 100644
47510--- a/drivers/pci/hotplug/pciehp_core.c
47511+++ b/drivers/pci/hotplug/pciehp_core.c
47512@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47513 struct slot *slot = ctrl->slot;
47514 struct hotplug_slot *hotplug = NULL;
47515 struct hotplug_slot_info *info = NULL;
47516- struct hotplug_slot_ops *ops = NULL;
47517+ hotplug_slot_ops_no_const *ops = NULL;
47518 char name[SLOT_NAME_SIZE];
47519 int retval = -ENOMEM;
47520
47521diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47522index c91e6c1..5c723ef 100644
47523--- a/drivers/pci/pci-sysfs.c
47524+++ b/drivers/pci/pci-sysfs.c
47525@@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47526 {
47527 /* allocate attribute structure, piggyback attribute name */
47528 int name_len = write_combine ? 13 : 10;
47529- struct bin_attribute *res_attr;
47530+ bin_attribute_no_const *res_attr;
47531 int retval;
47532
47533 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47534@@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47535 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47536 {
47537 int retval;
47538- struct bin_attribute *attr;
47539+ bin_attribute_no_const *attr;
47540
47541 /* If the device has VPD, try to expose it in sysfs. */
47542 if (dev->vpd) {
47543@@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47544 {
47545 int retval;
47546 int rom_size = 0;
47547- struct bin_attribute *attr;
47548+ bin_attribute_no_const *attr;
47549
47550 if (!sysfs_initialized)
47551 return -EACCES;
47552diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47553index 9c91ecc..bda4796 100644
47554--- a/drivers/pci/pci.h
47555+++ b/drivers/pci/pci.h
47556@@ -95,7 +95,7 @@ struct pci_vpd_ops {
47557 struct pci_vpd {
47558 unsigned int len;
47559 const struct pci_vpd_ops *ops;
47560- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47561+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47562 };
47563
47564 int pci_vpd_pci22_init(struct pci_dev *dev);
47565diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47566index f1272dc..e92a1ac 100644
47567--- a/drivers/pci/pcie/aspm.c
47568+++ b/drivers/pci/pcie/aspm.c
47569@@ -27,9 +27,9 @@
47570 #define MODULE_PARAM_PREFIX "pcie_aspm."
47571
47572 /* Note: those are not register definitions */
47573-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47574-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47575-#define ASPM_STATE_L1 (4) /* L1 state */
47576+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47577+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47578+#define ASPM_STATE_L1 (4U) /* L1 state */
47579 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47580 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47581
47582diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47583index 38e403d..a2ce55a 100644
47584--- a/drivers/pci/probe.c
47585+++ b/drivers/pci/probe.c
47586@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47587 struct pci_bus_region region, inverted_region;
47588 bool bar_too_big = false, bar_disabled = false;
47589
47590- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47591+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47592
47593 /* No printks while decoding is disabled! */
47594 if (!dev->mmio_always_on) {
47595diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47596index 46d1378..30e452b 100644
47597--- a/drivers/pci/proc.c
47598+++ b/drivers/pci/proc.c
47599@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47600 static int __init pci_proc_init(void)
47601 {
47602 struct pci_dev *dev = NULL;
47603+
47604+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47605+#ifdef CONFIG_GRKERNSEC_PROC_USER
47606+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47607+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47608+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47609+#endif
47610+#else
47611 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47612+#endif
47613 proc_create("devices", 0, proc_bus_pci_dir,
47614 &proc_bus_pci_dev_operations);
47615 proc_initialized = 1;
47616diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47617index 3e5b4497..dcdfb70 100644
47618--- a/drivers/platform/chrome/chromeos_laptop.c
47619+++ b/drivers/platform/chrome/chromeos_laptop.c
47620@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47621 return 0;
47622 }
47623
47624-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47625+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47626 {
47627 .ident = "Samsung Series 5 550 - Touchpad",
47628 .matches = {
47629diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47630index 19c313b..ed28b38 100644
47631--- a/drivers/platform/x86/asus-wmi.c
47632+++ b/drivers/platform/x86/asus-wmi.c
47633@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47634 int err;
47635 u32 retval = -1;
47636
47637+#ifdef CONFIG_GRKERNSEC_KMEM
47638+ return -EPERM;
47639+#endif
47640+
47641 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47642
47643 if (err < 0)
47644@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47645 int err;
47646 u32 retval = -1;
47647
47648+#ifdef CONFIG_GRKERNSEC_KMEM
47649+ return -EPERM;
47650+#endif
47651+
47652 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47653 &retval);
47654
47655@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47656 union acpi_object *obj;
47657 acpi_status status;
47658
47659+#ifdef CONFIG_GRKERNSEC_KMEM
47660+ return -EPERM;
47661+#endif
47662+
47663 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47664 1, asus->debug.method_id,
47665 &input, &output);
47666diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47667index 62f8030..c7f2a45 100644
47668--- a/drivers/platform/x86/msi-laptop.c
47669+++ b/drivers/platform/x86/msi-laptop.c
47670@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47671
47672 if (!quirks->ec_read_only) {
47673 /* allow userland write sysfs file */
47674- dev_attr_bluetooth.store = store_bluetooth;
47675- dev_attr_wlan.store = store_wlan;
47676- dev_attr_threeg.store = store_threeg;
47677- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47678- dev_attr_wlan.attr.mode |= S_IWUSR;
47679- dev_attr_threeg.attr.mode |= S_IWUSR;
47680+ pax_open_kernel();
47681+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47682+ *(void **)&dev_attr_wlan.store = store_wlan;
47683+ *(void **)&dev_attr_threeg.store = store_threeg;
47684+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47685+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47686+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47687+ pax_close_kernel();
47688 }
47689
47690 /* disable hardware control by fn key */
47691diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47692index 70222f2..8c8ce66 100644
47693--- a/drivers/platform/x86/msi-wmi.c
47694+++ b/drivers/platform/x86/msi-wmi.c
47695@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47696 static void msi_wmi_notify(u32 value, void *context)
47697 {
47698 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47699- static struct key_entry *key;
47700+ struct key_entry *key;
47701 union acpi_object *obj;
47702 acpi_status status;
47703
47704diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47705index fb233ae..23a325c 100644
47706--- a/drivers/platform/x86/sony-laptop.c
47707+++ b/drivers/platform/x86/sony-laptop.c
47708@@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47709 }
47710
47711 /* High speed charging function */
47712-static struct device_attribute *hsc_handle;
47713+static device_attribute_no_const *hsc_handle;
47714
47715 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47716 struct device_attribute *attr,
47717diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47718index 58b0274..6704626 100644
47719--- a/drivers/platform/x86/thinkpad_acpi.c
47720+++ b/drivers/platform/x86/thinkpad_acpi.c
47721@@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47722 return 0;
47723 }
47724
47725-void static hotkey_mask_warn_incomplete_mask(void)
47726+static void hotkey_mask_warn_incomplete_mask(void)
47727 {
47728 /* log only what the user can fix... */
47729 const u32 wantedmask = hotkey_driver_mask &
47730@@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47731 }
47732 }
47733
47734-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47735- struct tp_nvram_state *newn,
47736- const u32 event_mask)
47737-{
47738-
47739 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47740 do { \
47741 if ((event_mask & (1 << __scancode)) && \
47742@@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47743 tpacpi_hotkey_send_key(__scancode); \
47744 } while (0)
47745
47746- void issue_volchange(const unsigned int oldvol,
47747- const unsigned int newvol)
47748- {
47749- unsigned int i = oldvol;
47750+static void issue_volchange(const unsigned int oldvol,
47751+ const unsigned int newvol,
47752+ const u32 event_mask)
47753+{
47754+ unsigned int i = oldvol;
47755
47756- while (i > newvol) {
47757- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47758- i--;
47759- }
47760- while (i < newvol) {
47761- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47762- i++;
47763- }
47764+ while (i > newvol) {
47765+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47766+ i--;
47767 }
47768+ while (i < newvol) {
47769+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47770+ i++;
47771+ }
47772+}
47773
47774- void issue_brightnesschange(const unsigned int oldbrt,
47775- const unsigned int newbrt)
47776- {
47777- unsigned int i = oldbrt;
47778+static void issue_brightnesschange(const unsigned int oldbrt,
47779+ const unsigned int newbrt,
47780+ const u32 event_mask)
47781+{
47782+ unsigned int i = oldbrt;
47783
47784- while (i > newbrt) {
47785- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47786- i--;
47787- }
47788- while (i < newbrt) {
47789- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47790- i++;
47791- }
47792+ while (i > newbrt) {
47793+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47794+ i--;
47795+ }
47796+ while (i < newbrt) {
47797+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47798+ i++;
47799 }
47800+}
47801
47802+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47803+ struct tp_nvram_state *newn,
47804+ const u32 event_mask)
47805+{
47806 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47807 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47808 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47809@@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47810 oldn->volume_level != newn->volume_level) {
47811 /* recently muted, or repeated mute keypress, or
47812 * multiple presses ending in mute */
47813- issue_volchange(oldn->volume_level, newn->volume_level);
47814+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47815 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47816 }
47817 } else {
47818@@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47819 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47820 }
47821 if (oldn->volume_level != newn->volume_level) {
47822- issue_volchange(oldn->volume_level, newn->volume_level);
47823+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47824 } else if (oldn->volume_toggle != newn->volume_toggle) {
47825 /* repeated vol up/down keypress at end of scale ? */
47826 if (newn->volume_level == 0)
47827@@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47828 /* handle brightness */
47829 if (oldn->brightness_level != newn->brightness_level) {
47830 issue_brightnesschange(oldn->brightness_level,
47831- newn->brightness_level);
47832+ newn->brightness_level,
47833+ event_mask);
47834 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47835 /* repeated key presses that didn't change state */
47836 if (newn->brightness_level == 0)
47837@@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47838 && !tp_features.bright_unkfw)
47839 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47840 }
47841+}
47842
47843 #undef TPACPI_COMPARE_KEY
47844 #undef TPACPI_MAY_SEND_KEY
47845-}
47846
47847 /*
47848 * Polling driver
47849diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47850index 769d265..a3a05ca 100644
47851--- a/drivers/pnp/pnpbios/bioscalls.c
47852+++ b/drivers/pnp/pnpbios/bioscalls.c
47853@@ -58,7 +58,7 @@ do { \
47854 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47855 } while(0)
47856
47857-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47858+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47859 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47860
47861 /*
47862@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47863
47864 cpu = get_cpu();
47865 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47866+
47867+ pax_open_kernel();
47868 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47869+ pax_close_kernel();
47870
47871 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47872 spin_lock_irqsave(&pnp_bios_lock, flags);
47873@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47874 :"memory");
47875 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47876
47877+ pax_open_kernel();
47878 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47879+ pax_close_kernel();
47880+
47881 put_cpu();
47882
47883 /* If we get here and this is set then the PnP BIOS faulted on us. */
47884@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47885 return status;
47886 }
47887
47888-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47889+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47890 {
47891 int i;
47892
47893@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47894 pnp_bios_callpoint.offset = header->fields.pm16offset;
47895 pnp_bios_callpoint.segment = PNP_CS16;
47896
47897+ pax_open_kernel();
47898+
47899 for_each_possible_cpu(i) {
47900 struct desc_struct *gdt = get_cpu_gdt_table(i);
47901 if (!gdt)
47902@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47903 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47904 (unsigned long)__va(header->fields.pm16dseg));
47905 }
47906+
47907+ pax_close_kernel();
47908 }
47909diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47910index d95e101..67f0c3f 100644
47911--- a/drivers/pnp/resource.c
47912+++ b/drivers/pnp/resource.c
47913@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47914 return 1;
47915
47916 /* check if the resource is valid */
47917- if (*irq < 0 || *irq > 15)
47918+ if (*irq > 15)
47919 return 0;
47920
47921 /* check if the resource is reserved */
47922@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47923 return 1;
47924
47925 /* check if the resource is valid */
47926- if (*dma < 0 || *dma == 4 || *dma > 7)
47927+ if (*dma == 4 || *dma > 7)
47928 return 0;
47929
47930 /* check if the resource is reserved */
47931diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47932index 0c52e2a..3421ab7 100644
47933--- a/drivers/power/pda_power.c
47934+++ b/drivers/power/pda_power.c
47935@@ -37,7 +37,11 @@ static int polling;
47936
47937 #if IS_ENABLED(CONFIG_USB_PHY)
47938 static struct usb_phy *transceiver;
47939-static struct notifier_block otg_nb;
47940+static int otg_handle_notification(struct notifier_block *nb,
47941+ unsigned long event, void *unused);
47942+static struct notifier_block otg_nb = {
47943+ .notifier_call = otg_handle_notification
47944+};
47945 #endif
47946
47947 static struct regulator *ac_draw;
47948@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47949
47950 #if IS_ENABLED(CONFIG_USB_PHY)
47951 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47952- otg_nb.notifier_call = otg_handle_notification;
47953 ret = usb_register_notifier(transceiver, &otg_nb);
47954 if (ret) {
47955 dev_err(dev, "failure to register otg notifier\n");
47956diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47957index cc439fd..8fa30df 100644
47958--- a/drivers/power/power_supply.h
47959+++ b/drivers/power/power_supply.h
47960@@ -16,12 +16,12 @@ struct power_supply;
47961
47962 #ifdef CONFIG_SYSFS
47963
47964-extern void power_supply_init_attrs(struct device_type *dev_type);
47965+extern void power_supply_init_attrs(void);
47966 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47967
47968 #else
47969
47970-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47971+static inline void power_supply_init_attrs(void) {}
47972 #define power_supply_uevent NULL
47973
47974 #endif /* CONFIG_SYSFS */
47975diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47976index 557af94..84dc1fe 100644
47977--- a/drivers/power/power_supply_core.c
47978+++ b/drivers/power/power_supply_core.c
47979@@ -24,7 +24,10 @@
47980 struct class *power_supply_class;
47981 EXPORT_SYMBOL_GPL(power_supply_class);
47982
47983-static struct device_type power_supply_dev_type;
47984+extern const struct attribute_group *power_supply_attr_groups[];
47985+static struct device_type power_supply_dev_type = {
47986+ .groups = power_supply_attr_groups,
47987+};
47988
47989 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47990 struct power_supply *supply)
47991@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47992 return PTR_ERR(power_supply_class);
47993
47994 power_supply_class->dev_uevent = power_supply_uevent;
47995- power_supply_init_attrs(&power_supply_dev_type);
47996+ power_supply_init_attrs();
47997
47998 return 0;
47999 }
48000diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48001index 44420d1..967126e 100644
48002--- a/drivers/power/power_supply_sysfs.c
48003+++ b/drivers/power/power_supply_sysfs.c
48004@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48005 .is_visible = power_supply_attr_is_visible,
48006 };
48007
48008-static const struct attribute_group *power_supply_attr_groups[] = {
48009+const struct attribute_group *power_supply_attr_groups[] = {
48010 &power_supply_attr_group,
48011 NULL,
48012 };
48013
48014-void power_supply_init_attrs(struct device_type *dev_type)
48015+void power_supply_init_attrs(void)
48016 {
48017 int i;
48018
48019- dev_type->groups = power_supply_attr_groups;
48020-
48021 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48022 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48023 }
48024diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48025index 84419af..268ede8 100644
48026--- a/drivers/powercap/powercap_sys.c
48027+++ b/drivers/powercap/powercap_sys.c
48028@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48029 struct device_attribute name_attr;
48030 };
48031
48032+static ssize_t show_constraint_name(struct device *dev,
48033+ struct device_attribute *dev_attr,
48034+ char *buf);
48035+
48036 static struct powercap_constraint_attr
48037- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48038+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48039+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48040+ .power_limit_attr = {
48041+ .attr = {
48042+ .name = NULL,
48043+ .mode = S_IWUSR | S_IRUGO
48044+ },
48045+ .show = show_constraint_power_limit_uw,
48046+ .store = store_constraint_power_limit_uw
48047+ },
48048+
48049+ .time_window_attr = {
48050+ .attr = {
48051+ .name = NULL,
48052+ .mode = S_IWUSR | S_IRUGO
48053+ },
48054+ .show = show_constraint_time_window_us,
48055+ .store = store_constraint_time_window_us
48056+ },
48057+
48058+ .max_power_attr = {
48059+ .attr = {
48060+ .name = NULL,
48061+ .mode = S_IRUGO
48062+ },
48063+ .show = show_constraint_max_power_uw,
48064+ .store = NULL
48065+ },
48066+
48067+ .min_power_attr = {
48068+ .attr = {
48069+ .name = NULL,
48070+ .mode = S_IRUGO
48071+ },
48072+ .show = show_constraint_min_power_uw,
48073+ .store = NULL
48074+ },
48075+
48076+ .max_time_window_attr = {
48077+ .attr = {
48078+ .name = NULL,
48079+ .mode = S_IRUGO
48080+ },
48081+ .show = show_constraint_max_time_window_us,
48082+ .store = NULL
48083+ },
48084+
48085+ .min_time_window_attr = {
48086+ .attr = {
48087+ .name = NULL,
48088+ .mode = S_IRUGO
48089+ },
48090+ .show = show_constraint_min_time_window_us,
48091+ .store = NULL
48092+ },
48093+
48094+ .name_attr = {
48095+ .attr = {
48096+ .name = NULL,
48097+ .mode = S_IRUGO
48098+ },
48099+ .show = show_constraint_name,
48100+ .store = NULL
48101+ }
48102+ }
48103+};
48104
48105 /* A list of powercap control_types */
48106 static LIST_HEAD(powercap_cntrl_list);
48107@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48108 }
48109
48110 static int create_constraint_attribute(int id, const char *name,
48111- int mode,
48112- struct device_attribute *dev_attr,
48113- ssize_t (*show)(struct device *,
48114- struct device_attribute *, char *),
48115- ssize_t (*store)(struct device *,
48116- struct device_attribute *,
48117- const char *, size_t)
48118- )
48119+ struct device_attribute *dev_attr)
48120 {
48121+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48122
48123- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48124- id, name);
48125- if (!dev_attr->attr.name)
48126+ if (!name)
48127 return -ENOMEM;
48128- dev_attr->attr.mode = mode;
48129- dev_attr->show = show;
48130- dev_attr->store = store;
48131+
48132+ pax_open_kernel();
48133+ *(const char **)&dev_attr->attr.name = name;
48134+ pax_close_kernel();
48135
48136 return 0;
48137 }
48138@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48139
48140 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48141 ret = create_constraint_attribute(i, "power_limit_uw",
48142- S_IWUSR | S_IRUGO,
48143- &constraint_attrs[i].power_limit_attr,
48144- show_constraint_power_limit_uw,
48145- store_constraint_power_limit_uw);
48146+ &constraint_attrs[i].power_limit_attr);
48147 if (ret)
48148 goto err_alloc;
48149 ret = create_constraint_attribute(i, "time_window_us",
48150- S_IWUSR | S_IRUGO,
48151- &constraint_attrs[i].time_window_attr,
48152- show_constraint_time_window_us,
48153- store_constraint_time_window_us);
48154+ &constraint_attrs[i].time_window_attr);
48155 if (ret)
48156 goto err_alloc;
48157- ret = create_constraint_attribute(i, "name", S_IRUGO,
48158- &constraint_attrs[i].name_attr,
48159- show_constraint_name,
48160- NULL);
48161+ ret = create_constraint_attribute(i, "name",
48162+ &constraint_attrs[i].name_attr);
48163 if (ret)
48164 goto err_alloc;
48165- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48166- &constraint_attrs[i].max_power_attr,
48167- show_constraint_max_power_uw,
48168- NULL);
48169+ ret = create_constraint_attribute(i, "max_power_uw",
48170+ &constraint_attrs[i].max_power_attr);
48171 if (ret)
48172 goto err_alloc;
48173- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48174- &constraint_attrs[i].min_power_attr,
48175- show_constraint_min_power_uw,
48176- NULL);
48177+ ret = create_constraint_attribute(i, "min_power_uw",
48178+ &constraint_attrs[i].min_power_attr);
48179 if (ret)
48180 goto err_alloc;
48181 ret = create_constraint_attribute(i, "max_time_window_us",
48182- S_IRUGO,
48183- &constraint_attrs[i].max_time_window_attr,
48184- show_constraint_max_time_window_us,
48185- NULL);
48186+ &constraint_attrs[i].max_time_window_attr);
48187 if (ret)
48188 goto err_alloc;
48189 ret = create_constraint_attribute(i, "min_time_window_us",
48190- S_IRUGO,
48191- &constraint_attrs[i].min_time_window_attr,
48192- show_constraint_min_time_window_us,
48193- NULL);
48194+ &constraint_attrs[i].min_time_window_attr);
48195 if (ret)
48196 goto err_alloc;
48197
48198@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48199 power_zone->zone_dev_attrs[count++] =
48200 &dev_attr_max_energy_range_uj.attr;
48201 if (power_zone->ops->get_energy_uj) {
48202+ pax_open_kernel();
48203 if (power_zone->ops->reset_energy_uj)
48204- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48205+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48206 else
48207- dev_attr_energy_uj.attr.mode = S_IRUGO;
48208+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48209+ pax_close_kernel();
48210 power_zone->zone_dev_attrs[count++] =
48211 &dev_attr_energy_uj.attr;
48212 }
48213diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48214index 7271299..20217a5 100644
48215--- a/drivers/regulator/core.c
48216+++ b/drivers/regulator/core.c
48217@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48218 {
48219 const struct regulation_constraints *constraints = NULL;
48220 const struct regulator_init_data *init_data;
48221- static atomic_t regulator_no = ATOMIC_INIT(0);
48222+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48223 struct regulator_dev *rdev;
48224 struct device *dev;
48225 int ret, i;
48226@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48227 rdev->dev.of_node = config->of_node;
48228 rdev->dev.parent = dev;
48229 dev_set_name(&rdev->dev, "regulator.%d",
48230- atomic_inc_return(&regulator_no) - 1);
48231+ atomic_inc_return_unchecked(&regulator_no) - 1);
48232 ret = device_register(&rdev->dev);
48233 if (ret != 0) {
48234 put_device(&rdev->dev);
48235diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48236index 8d94d3d..653b623 100644
48237--- a/drivers/regulator/max8660.c
48238+++ b/drivers/regulator/max8660.c
48239@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48240 max8660->shadow_regs[MAX8660_OVER1] = 5;
48241 } else {
48242 /* Otherwise devices can be toggled via software */
48243- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48244- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48245+ pax_open_kernel();
48246+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48247+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48248+ pax_close_kernel();
48249 }
48250
48251 /*
48252diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48253index 892aa1e..ebd1b9c 100644
48254--- a/drivers/regulator/max8973-regulator.c
48255+++ b/drivers/regulator/max8973-regulator.c
48256@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48257 if (!pdata || !pdata->enable_ext_control) {
48258 max->desc.enable_reg = MAX8973_VOUT;
48259 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48260- max->ops.enable = regulator_enable_regmap;
48261- max->ops.disable = regulator_disable_regmap;
48262- max->ops.is_enabled = regulator_is_enabled_regmap;
48263+ pax_open_kernel();
48264+ *(void **)&max->ops.enable = regulator_enable_regmap;
48265+ *(void **)&max->ops.disable = regulator_disable_regmap;
48266+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48267+ pax_close_kernel();
48268 }
48269
48270 if (pdata) {
48271diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48272index 96c9f80..90974ca 100644
48273--- a/drivers/regulator/mc13892-regulator.c
48274+++ b/drivers/regulator/mc13892-regulator.c
48275@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48276 }
48277 mc13xxx_unlock(mc13892);
48278
48279- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48280+ pax_open_kernel();
48281+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48282 = mc13892_vcam_set_mode;
48283- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48284+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48285 = mc13892_vcam_get_mode;
48286+ pax_close_kernel();
48287
48288 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48289 ARRAY_SIZE(mc13892_regulators));
48290diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48291index a2325bc..04c549f 100644
48292--- a/drivers/rtc/rtc-cmos.c
48293+++ b/drivers/rtc/rtc-cmos.c
48294@@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48295 hpet_rtc_timer_init();
48296
48297 /* export at least the first block of NVRAM */
48298- nvram.size = address_space - NVRAM_OFFSET;
48299+ pax_open_kernel();
48300+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48301+ pax_close_kernel();
48302 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48303 if (retval < 0) {
48304 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48305diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48306index d049393..bb20be0 100644
48307--- a/drivers/rtc/rtc-dev.c
48308+++ b/drivers/rtc/rtc-dev.c
48309@@ -16,6 +16,7 @@
48310 #include <linux/module.h>
48311 #include <linux/rtc.h>
48312 #include <linux/sched.h>
48313+#include <linux/grsecurity.h>
48314 #include "rtc-core.h"
48315
48316 static dev_t rtc_devt;
48317@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48318 if (copy_from_user(&tm, uarg, sizeof(tm)))
48319 return -EFAULT;
48320
48321+ gr_log_timechange();
48322+
48323 return rtc_set_time(rtc, &tm);
48324
48325 case RTC_PIE_ON:
48326diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48327index 4e75345..09f8663 100644
48328--- a/drivers/rtc/rtc-ds1307.c
48329+++ b/drivers/rtc/rtc-ds1307.c
48330@@ -107,7 +107,7 @@ struct ds1307 {
48331 u8 offset; /* register's offset */
48332 u8 regs[11];
48333 u16 nvram_offset;
48334- struct bin_attribute *nvram;
48335+ bin_attribute_no_const *nvram;
48336 enum ds_type type;
48337 unsigned long flags;
48338 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48339diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48340index 11880c1..b823aa4 100644
48341--- a/drivers/rtc/rtc-m48t59.c
48342+++ b/drivers/rtc/rtc-m48t59.c
48343@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48344 if (IS_ERR(m48t59->rtc))
48345 return PTR_ERR(m48t59->rtc);
48346
48347- m48t59_nvram_attr.size = pdata->offset;
48348+ pax_open_kernel();
48349+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48350+ pax_close_kernel();
48351
48352 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48353 if (ret)
48354diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48355index 14b5f8d..cc9bd26 100644
48356--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48357+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48358@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48359 for (bit = 0; bit < 8; bit++) {
48360
48361 if ((pci_status[i] & (0x1 << bit)) != 0) {
48362- static const char *s;
48363+ const char *s;
48364
48365 s = pci_status_strings[bit];
48366 if (i == 7/*TARG*/ && bit == 3)
48367@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48368
48369 for (bit = 0; bit < 8; bit++) {
48370
48371- if ((split_status[i] & (0x1 << bit)) != 0) {
48372- static const char *s;
48373-
48374- s = split_status_strings[bit];
48375- printk(s, ahd_name(ahd),
48376+ if ((split_status[i] & (0x1 << bit)) != 0)
48377+ printk(split_status_strings[bit], ahd_name(ahd),
48378 split_status_source[i]);
48379- }
48380
48381 if (i > 1)
48382 continue;
48383
48384- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48385- static const char *s;
48386-
48387- s = split_status_strings[bit];
48388- printk(s, ahd_name(ahd), "SG");
48389- }
48390+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48391+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48392 }
48393 }
48394 /*
48395diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48396index e693af6..2e525b6 100644
48397--- a/drivers/scsi/bfa/bfa_fcpim.h
48398+++ b/drivers/scsi/bfa/bfa_fcpim.h
48399@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48400
48401 struct bfa_itn_s {
48402 bfa_isr_func_t isr;
48403-};
48404+} __no_const;
48405
48406 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48407 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48408diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48409index a3ab5cc..8143622 100644
48410--- a/drivers/scsi/bfa/bfa_fcs.c
48411+++ b/drivers/scsi/bfa/bfa_fcs.c
48412@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48413 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48414
48415 static struct bfa_fcs_mod_s fcs_modules[] = {
48416- { bfa_fcs_port_attach, NULL, NULL },
48417- { bfa_fcs_uf_attach, NULL, NULL },
48418- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48419- bfa_fcs_fabric_modexit },
48420+ {
48421+ .attach = bfa_fcs_port_attach,
48422+ .modinit = NULL,
48423+ .modexit = NULL
48424+ },
48425+ {
48426+ .attach = bfa_fcs_uf_attach,
48427+ .modinit = NULL,
48428+ .modexit = NULL
48429+ },
48430+ {
48431+ .attach = bfa_fcs_fabric_attach,
48432+ .modinit = bfa_fcs_fabric_modinit,
48433+ .modexit = bfa_fcs_fabric_modexit
48434+ },
48435 };
48436
48437 /*
48438diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48439index f5e4e61..a0acaf6 100644
48440--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48441+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48442@@ -89,15 +89,26 @@ static struct {
48443 void (*offline) (struct bfa_fcs_lport_s *port);
48444 } __port_action[] = {
48445 {
48446- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48447- bfa_fcs_lport_unknown_offline}, {
48448- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48449- bfa_fcs_lport_fab_offline}, {
48450- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48451- bfa_fcs_lport_n2n_offline}, {
48452- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48453- bfa_fcs_lport_loop_offline},
48454- };
48455+ .init = bfa_fcs_lport_unknown_init,
48456+ .online = bfa_fcs_lport_unknown_online,
48457+ .offline = bfa_fcs_lport_unknown_offline
48458+ },
48459+ {
48460+ .init = bfa_fcs_lport_fab_init,
48461+ .online = bfa_fcs_lport_fab_online,
48462+ .offline = bfa_fcs_lport_fab_offline
48463+ },
48464+ {
48465+ .init = bfa_fcs_lport_n2n_init,
48466+ .online = bfa_fcs_lport_n2n_online,
48467+ .offline = bfa_fcs_lport_n2n_offline
48468+ },
48469+ {
48470+ .init = bfa_fcs_lport_loop_init,
48471+ .online = bfa_fcs_lport_loop_online,
48472+ .offline = bfa_fcs_lport_loop_offline
48473+ },
48474+};
48475
48476 /*
48477 * fcs_port_sm FCS logical port state machine
48478diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48479index 90814fe..4384138 100644
48480--- a/drivers/scsi/bfa/bfa_ioc.h
48481+++ b/drivers/scsi/bfa/bfa_ioc.h
48482@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48483 bfa_ioc_disable_cbfn_t disable_cbfn;
48484 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48485 bfa_ioc_reset_cbfn_t reset_cbfn;
48486-};
48487+} __no_const;
48488
48489 /*
48490 * IOC event notification mechanism.
48491@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48492 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48493 enum bfi_ioc_state fwstate);
48494 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48495-};
48496+} __no_const;
48497
48498 /*
48499 * Queue element to wait for room in request queue. FIFO order is
48500diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48501index a14c784..6de6790 100644
48502--- a/drivers/scsi/bfa/bfa_modules.h
48503+++ b/drivers/scsi/bfa/bfa_modules.h
48504@@ -78,12 +78,12 @@ enum {
48505 \
48506 extern struct bfa_module_s hal_mod_ ## __mod; \
48507 struct bfa_module_s hal_mod_ ## __mod = { \
48508- bfa_ ## __mod ## _meminfo, \
48509- bfa_ ## __mod ## _attach, \
48510- bfa_ ## __mod ## _detach, \
48511- bfa_ ## __mod ## _start, \
48512- bfa_ ## __mod ## _stop, \
48513- bfa_ ## __mod ## _iocdisable, \
48514+ .meminfo = bfa_ ## __mod ## _meminfo, \
48515+ .attach = bfa_ ## __mod ## _attach, \
48516+ .detach = bfa_ ## __mod ## _detach, \
48517+ .start = bfa_ ## __mod ## _start, \
48518+ .stop = bfa_ ## __mod ## _stop, \
48519+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48520 }
48521
48522 #define BFA_CACHELINE_SZ (256)
48523diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48524index 045c4e1..13de803 100644
48525--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48526+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48527@@ -33,8 +33,8 @@
48528 */
48529 #include "libfcoe.h"
48530
48531-static atomic_t ctlr_num;
48532-static atomic_t fcf_num;
48533+static atomic_unchecked_t ctlr_num;
48534+static atomic_unchecked_t fcf_num;
48535
48536 /*
48537 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48538@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48539 if (!ctlr)
48540 goto out;
48541
48542- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48543+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48544 ctlr->f = f;
48545 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48546 INIT_LIST_HEAD(&ctlr->fcfs);
48547@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48548 fcf->dev.parent = &ctlr->dev;
48549 fcf->dev.bus = &fcoe_bus_type;
48550 fcf->dev.type = &fcoe_fcf_device_type;
48551- fcf->id = atomic_inc_return(&fcf_num) - 1;
48552+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48553 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48554
48555 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48556@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48557 {
48558 int error;
48559
48560- atomic_set(&ctlr_num, 0);
48561- atomic_set(&fcf_num, 0);
48562+ atomic_set_unchecked(&ctlr_num, 0);
48563+ atomic_set_unchecked(&fcf_num, 0);
48564
48565 error = bus_register(&fcoe_bus_type);
48566 if (error)
48567diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48568index f2c5005..db36c02 100644
48569--- a/drivers/scsi/hosts.c
48570+++ b/drivers/scsi/hosts.c
48571@@ -42,7 +42,7 @@
48572 #include "scsi_logging.h"
48573
48574
48575-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48576+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48577
48578
48579 static void scsi_host_cls_release(struct device *dev)
48580@@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48581 * subtract one because we increment first then return, but we need to
48582 * know what the next host number was before increment
48583 */
48584- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48585+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48586 shost->dma_channel = 0xff;
48587
48588 /* These three are default values which can be overridden */
48589diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48590index 20a5e6e..8b23cea 100644
48591--- a/drivers/scsi/hpsa.c
48592+++ b/drivers/scsi/hpsa.c
48593@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48594 unsigned long flags;
48595
48596 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48597- return h->access.command_completed(h, q);
48598+ return h->access->command_completed(h, q);
48599
48600 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48601 a = rq->head[rq->current_entry];
48602@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48603 while (!list_empty(&h->reqQ)) {
48604 c = list_entry(h->reqQ.next, struct CommandList, list);
48605 /* can't do anything if fifo is full */
48606- if ((h->access.fifo_full(h))) {
48607+ if ((h->access->fifo_full(h))) {
48608 dev_warn(&h->pdev->dev, "fifo full\n");
48609 break;
48610 }
48611@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48612
48613 /* Tell the controller execute command */
48614 spin_unlock_irqrestore(&h->lock, flags);
48615- h->access.submit_command(h, c);
48616+ h->access->submit_command(h, c);
48617 spin_lock_irqsave(&h->lock, flags);
48618 }
48619 spin_unlock_irqrestore(&h->lock, flags);
48620@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48621
48622 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48623 {
48624- return h->access.command_completed(h, q);
48625+ return h->access->command_completed(h, q);
48626 }
48627
48628 static inline bool interrupt_pending(struct ctlr_info *h)
48629 {
48630- return h->access.intr_pending(h);
48631+ return h->access->intr_pending(h);
48632 }
48633
48634 static inline long interrupt_not_for_us(struct ctlr_info *h)
48635 {
48636- return (h->access.intr_pending(h) == 0) ||
48637+ return (h->access->intr_pending(h) == 0) ||
48638 (h->interrupts_enabled == 0);
48639 }
48640
48641@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48642 if (prod_index < 0)
48643 return -ENODEV;
48644 h->product_name = products[prod_index].product_name;
48645- h->access = *(products[prod_index].access);
48646+ h->access = products[prod_index].access;
48647
48648 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48649 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48650@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48651
48652 assert_spin_locked(&lockup_detector_lock);
48653 remove_ctlr_from_lockup_detector_list(h);
48654- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48655+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48656 spin_lock_irqsave(&h->lock, flags);
48657 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48658 spin_unlock_irqrestore(&h->lock, flags);
48659@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48660 }
48661
48662 /* make sure the board interrupts are off */
48663- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48664+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48665
48666 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48667 goto clean2;
48668@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48669 * fake ones to scoop up any residual completions.
48670 */
48671 spin_lock_irqsave(&h->lock, flags);
48672- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48673+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48674 spin_unlock_irqrestore(&h->lock, flags);
48675 free_irqs(h);
48676 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48677@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48678 dev_info(&h->pdev->dev, "Board READY.\n");
48679 dev_info(&h->pdev->dev,
48680 "Waiting for stale completions to drain.\n");
48681- h->access.set_intr_mask(h, HPSA_INTR_ON);
48682+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48683 msleep(10000);
48684- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48685+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48686
48687 rc = controller_reset_failed(h->cfgtable);
48688 if (rc)
48689@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48690 }
48691
48692 /* Turn the interrupts on so we can service requests */
48693- h->access.set_intr_mask(h, HPSA_INTR_ON);
48694+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48695
48696 hpsa_hba_inquiry(h);
48697 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48698@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48699 * To write all data in the battery backed cache to disks
48700 */
48701 hpsa_flush_cache(h);
48702- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48703+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48704 hpsa_free_irqs_and_disable_msix(h);
48705 }
48706
48707@@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48708 return;
48709 }
48710 /* Change the access methods to the performant access methods */
48711- h->access = SA5_performant_access;
48712+ h->access = &SA5_performant_access;
48713 h->transMethod = CFGTBL_Trans_Performant;
48714 }
48715
48716diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48717index bc85e72..d463049 100644
48718--- a/drivers/scsi/hpsa.h
48719+++ b/drivers/scsi/hpsa.h
48720@@ -79,7 +79,7 @@ struct ctlr_info {
48721 unsigned int msix_vector;
48722 unsigned int msi_vector;
48723 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48724- struct access_method access;
48725+ struct access_method *access;
48726
48727 /* queue and queue Info */
48728 struct list_head reqQ;
48729@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48730 }
48731
48732 static struct access_method SA5_access = {
48733- SA5_submit_command,
48734- SA5_intr_mask,
48735- SA5_fifo_full,
48736- SA5_intr_pending,
48737- SA5_completed,
48738+ .submit_command = SA5_submit_command,
48739+ .set_intr_mask = SA5_intr_mask,
48740+ .fifo_full = SA5_fifo_full,
48741+ .intr_pending = SA5_intr_pending,
48742+ .command_completed = SA5_completed,
48743 };
48744
48745 static struct access_method SA5_performant_access = {
48746- SA5_submit_command,
48747- SA5_performant_intr_mask,
48748- SA5_fifo_full,
48749- SA5_performant_intr_pending,
48750- SA5_performant_completed,
48751+ .submit_command = SA5_submit_command,
48752+ .set_intr_mask = SA5_performant_intr_mask,
48753+ .fifo_full = SA5_fifo_full,
48754+ .intr_pending = SA5_performant_intr_pending,
48755+ .command_completed = SA5_performant_completed,
48756 };
48757
48758 struct board_type {
48759diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48760index 1b3a094..068e683 100644
48761--- a/drivers/scsi/libfc/fc_exch.c
48762+++ b/drivers/scsi/libfc/fc_exch.c
48763@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48764 u16 pool_max_index;
48765
48766 struct {
48767- atomic_t no_free_exch;
48768- atomic_t no_free_exch_xid;
48769- atomic_t xid_not_found;
48770- atomic_t xid_busy;
48771- atomic_t seq_not_found;
48772- atomic_t non_bls_resp;
48773+ atomic_unchecked_t no_free_exch;
48774+ atomic_unchecked_t no_free_exch_xid;
48775+ atomic_unchecked_t xid_not_found;
48776+ atomic_unchecked_t xid_busy;
48777+ atomic_unchecked_t seq_not_found;
48778+ atomic_unchecked_t non_bls_resp;
48779 } stats;
48780 };
48781
48782@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48783 /* allocate memory for exchange */
48784 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48785 if (!ep) {
48786- atomic_inc(&mp->stats.no_free_exch);
48787+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48788 goto out;
48789 }
48790 memset(ep, 0, sizeof(*ep));
48791@@ -874,7 +874,7 @@ out:
48792 return ep;
48793 err:
48794 spin_unlock_bh(&pool->lock);
48795- atomic_inc(&mp->stats.no_free_exch_xid);
48796+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48797 mempool_free(ep, mp->ep_pool);
48798 return NULL;
48799 }
48800@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48801 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48802 ep = fc_exch_find(mp, xid);
48803 if (!ep) {
48804- atomic_inc(&mp->stats.xid_not_found);
48805+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48806 reject = FC_RJT_OX_ID;
48807 goto out;
48808 }
48809@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48810 ep = fc_exch_find(mp, xid);
48811 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48812 if (ep) {
48813- atomic_inc(&mp->stats.xid_busy);
48814+ atomic_inc_unchecked(&mp->stats.xid_busy);
48815 reject = FC_RJT_RX_ID;
48816 goto rel;
48817 }
48818@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48819 }
48820 xid = ep->xid; /* get our XID */
48821 } else if (!ep) {
48822- atomic_inc(&mp->stats.xid_not_found);
48823+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48824 reject = FC_RJT_RX_ID; /* XID not found */
48825 goto out;
48826 }
48827@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48828 } else {
48829 sp = &ep->seq;
48830 if (sp->id != fh->fh_seq_id) {
48831- atomic_inc(&mp->stats.seq_not_found);
48832+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48833 if (f_ctl & FC_FC_END_SEQ) {
48834 /*
48835 * Update sequence_id based on incoming last
48836@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48837
48838 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48839 if (!ep) {
48840- atomic_inc(&mp->stats.xid_not_found);
48841+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48842 goto out;
48843 }
48844 if (ep->esb_stat & ESB_ST_COMPLETE) {
48845- atomic_inc(&mp->stats.xid_not_found);
48846+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48847 goto rel;
48848 }
48849 if (ep->rxid == FC_XID_UNKNOWN)
48850 ep->rxid = ntohs(fh->fh_rx_id);
48851 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48852- atomic_inc(&mp->stats.xid_not_found);
48853+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48854 goto rel;
48855 }
48856 if (ep->did != ntoh24(fh->fh_s_id) &&
48857 ep->did != FC_FID_FLOGI) {
48858- atomic_inc(&mp->stats.xid_not_found);
48859+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48860 goto rel;
48861 }
48862 sof = fr_sof(fp);
48863@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48864 sp->ssb_stat |= SSB_ST_RESP;
48865 sp->id = fh->fh_seq_id;
48866 } else if (sp->id != fh->fh_seq_id) {
48867- atomic_inc(&mp->stats.seq_not_found);
48868+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48869 goto rel;
48870 }
48871
48872@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48873 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48874
48875 if (!sp)
48876- atomic_inc(&mp->stats.xid_not_found);
48877+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48878 else
48879- atomic_inc(&mp->stats.non_bls_resp);
48880+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48881
48882 fc_frame_free(fp);
48883 }
48884@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48885
48886 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48887 mp = ema->mp;
48888- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48889+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48890 st->fc_no_free_exch_xid +=
48891- atomic_read(&mp->stats.no_free_exch_xid);
48892- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48893- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48894- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48895- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48896+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48897+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48898+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48899+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48900+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48901 }
48902 }
48903 EXPORT_SYMBOL(fc_exch_update_stats);
48904diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48905index d289583..b745eec 100644
48906--- a/drivers/scsi/libsas/sas_ata.c
48907+++ b/drivers/scsi/libsas/sas_ata.c
48908@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48909 .postreset = ata_std_postreset,
48910 .error_handler = ata_std_error_handler,
48911 .post_internal_cmd = sas_ata_post_internal,
48912- .qc_defer = ata_std_qc_defer,
48913+ .qc_defer = ata_std_qc_defer,
48914 .qc_prep = ata_noop_qc_prep,
48915 .qc_issue = sas_ata_qc_issue,
48916 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48917diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48918index 4e1b75c..0bbdfa9 100644
48919--- a/drivers/scsi/lpfc/lpfc.h
48920+++ b/drivers/scsi/lpfc/lpfc.h
48921@@ -432,7 +432,7 @@ struct lpfc_vport {
48922 struct dentry *debug_nodelist;
48923 struct dentry *vport_debugfs_root;
48924 struct lpfc_debugfs_trc *disc_trc;
48925- atomic_t disc_trc_cnt;
48926+ atomic_unchecked_t disc_trc_cnt;
48927 #endif
48928 uint8_t stat_data_enabled;
48929 uint8_t stat_data_blocked;
48930@@ -865,8 +865,8 @@ struct lpfc_hba {
48931 struct timer_list fabric_block_timer;
48932 unsigned long bit_flags;
48933 #define FABRIC_COMANDS_BLOCKED 0
48934- atomic_t num_rsrc_err;
48935- atomic_t num_cmd_success;
48936+ atomic_unchecked_t num_rsrc_err;
48937+ atomic_unchecked_t num_cmd_success;
48938 unsigned long last_rsrc_error_time;
48939 unsigned long last_ramp_down_time;
48940 unsigned long last_ramp_up_time;
48941@@ -902,7 +902,7 @@ struct lpfc_hba {
48942
48943 struct dentry *debug_slow_ring_trc;
48944 struct lpfc_debugfs_trc *slow_ring_trc;
48945- atomic_t slow_ring_trc_cnt;
48946+ atomic_unchecked_t slow_ring_trc_cnt;
48947 /* iDiag debugfs sub-directory */
48948 struct dentry *idiag_root;
48949 struct dentry *idiag_pci_cfg;
48950diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48951index 60084e6..0e2e700 100644
48952--- a/drivers/scsi/lpfc/lpfc_debugfs.c
48953+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48954@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48955
48956 #include <linux/debugfs.h>
48957
48958-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48959+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48960 static unsigned long lpfc_debugfs_start_time = 0L;
48961
48962 /* iDiag */
48963@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48964 lpfc_debugfs_enable = 0;
48965
48966 len = 0;
48967- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48968+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48969 (lpfc_debugfs_max_disc_trc - 1);
48970 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48971 dtp = vport->disc_trc + i;
48972@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48973 lpfc_debugfs_enable = 0;
48974
48975 len = 0;
48976- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48977+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48978 (lpfc_debugfs_max_slow_ring_trc - 1);
48979 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48980 dtp = phba->slow_ring_trc + i;
48981@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48982 !vport || !vport->disc_trc)
48983 return;
48984
48985- index = atomic_inc_return(&vport->disc_trc_cnt) &
48986+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48987 (lpfc_debugfs_max_disc_trc - 1);
48988 dtp = vport->disc_trc + index;
48989 dtp->fmt = fmt;
48990 dtp->data1 = data1;
48991 dtp->data2 = data2;
48992 dtp->data3 = data3;
48993- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48994+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48995 dtp->jif = jiffies;
48996 #endif
48997 return;
48998@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48999 !phba || !phba->slow_ring_trc)
49000 return;
49001
49002- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49003+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49004 (lpfc_debugfs_max_slow_ring_trc - 1);
49005 dtp = phba->slow_ring_trc + index;
49006 dtp->fmt = fmt;
49007 dtp->data1 = data1;
49008 dtp->data2 = data2;
49009 dtp->data3 = data3;
49010- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49011+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49012 dtp->jif = jiffies;
49013 #endif
49014 return;
49015@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49016 "slow_ring buffer\n");
49017 goto debug_failed;
49018 }
49019- atomic_set(&phba->slow_ring_trc_cnt, 0);
49020+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49021 memset(phba->slow_ring_trc, 0,
49022 (sizeof(struct lpfc_debugfs_trc) *
49023 lpfc_debugfs_max_slow_ring_trc));
49024@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49025 "buffer\n");
49026 goto debug_failed;
49027 }
49028- atomic_set(&vport->disc_trc_cnt, 0);
49029+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49030
49031 snprintf(name, sizeof(name), "discovery_trace");
49032 vport->debug_disc_trc =
49033diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49034index 68c94cc..8c27be5 100644
49035--- a/drivers/scsi/lpfc/lpfc_init.c
49036+++ b/drivers/scsi/lpfc/lpfc_init.c
49037@@ -10949,8 +10949,10 @@ lpfc_init(void)
49038 "misc_register returned with status %d", error);
49039
49040 if (lpfc_enable_npiv) {
49041- lpfc_transport_functions.vport_create = lpfc_vport_create;
49042- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49043+ pax_open_kernel();
49044+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49045+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49046+ pax_close_kernel();
49047 }
49048 lpfc_transport_template =
49049 fc_attach_transport(&lpfc_transport_functions);
49050diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49051index b2ede05..aaf482ca 100644
49052--- a/drivers/scsi/lpfc/lpfc_scsi.c
49053+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49054@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49055 uint32_t evt_posted;
49056
49057 spin_lock_irqsave(&phba->hbalock, flags);
49058- atomic_inc(&phba->num_rsrc_err);
49059+ atomic_inc_unchecked(&phba->num_rsrc_err);
49060 phba->last_rsrc_error_time = jiffies;
49061
49062 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49063@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49064 unsigned long flags;
49065 struct lpfc_hba *phba = vport->phba;
49066 uint32_t evt_posted;
49067- atomic_inc(&phba->num_cmd_success);
49068+ atomic_inc_unchecked(&phba->num_cmd_success);
49069
49070 if (vport->cfg_lun_queue_depth <= queue_depth)
49071 return;
49072@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49073 unsigned long num_rsrc_err, num_cmd_success;
49074 int i;
49075
49076- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49077- num_cmd_success = atomic_read(&phba->num_cmd_success);
49078+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49079+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49080
49081 /*
49082 * The error and success command counters are global per
49083@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49084 }
49085 }
49086 lpfc_destroy_vport_work_array(phba, vports);
49087- atomic_set(&phba->num_rsrc_err, 0);
49088- atomic_set(&phba->num_cmd_success, 0);
49089+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49090+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49091 }
49092
49093 /**
49094@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49095 }
49096 }
49097 lpfc_destroy_vport_work_array(phba, vports);
49098- atomic_set(&phba->num_rsrc_err, 0);
49099- atomic_set(&phba->num_cmd_success, 0);
49100+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49101+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49102 }
49103
49104 /**
49105diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49106index 7f0af4f..193ac3e 100644
49107--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49108+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49109@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49110 {
49111 struct scsi_device *sdev = to_scsi_device(dev);
49112 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49113- static struct _raid_device *raid_device;
49114+ struct _raid_device *raid_device;
49115 unsigned long flags;
49116 Mpi2RaidVolPage0_t vol_pg0;
49117 Mpi2ConfigReply_t mpi_reply;
49118@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49119 {
49120 struct scsi_device *sdev = to_scsi_device(dev);
49121 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49122- static struct _raid_device *raid_device;
49123+ struct _raid_device *raid_device;
49124 unsigned long flags;
49125 Mpi2RaidVolPage0_t vol_pg0;
49126 Mpi2ConfigReply_t mpi_reply;
49127@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49128 struct fw_event_work *fw_event)
49129 {
49130 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49131- static struct _raid_device *raid_device;
49132+ struct _raid_device *raid_device;
49133 unsigned long flags;
49134 u16 handle;
49135
49136@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49137 u64 sas_address;
49138 struct _sas_device *sas_device;
49139 struct _sas_node *expander_device;
49140- static struct _raid_device *raid_device;
49141+ struct _raid_device *raid_device;
49142 u8 retry_count;
49143 unsigned long flags;
49144
49145diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49146index be8ce54..94ed33a 100644
49147--- a/drivers/scsi/pmcraid.c
49148+++ b/drivers/scsi/pmcraid.c
49149@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49150 res->scsi_dev = scsi_dev;
49151 scsi_dev->hostdata = res;
49152 res->change_detected = 0;
49153- atomic_set(&res->read_failures, 0);
49154- atomic_set(&res->write_failures, 0);
49155+ atomic_set_unchecked(&res->read_failures, 0);
49156+ atomic_set_unchecked(&res->write_failures, 0);
49157 rc = 0;
49158 }
49159 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49160@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49161
49162 /* If this was a SCSI read/write command keep count of errors */
49163 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49164- atomic_inc(&res->read_failures);
49165+ atomic_inc_unchecked(&res->read_failures);
49166 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49167- atomic_inc(&res->write_failures);
49168+ atomic_inc_unchecked(&res->write_failures);
49169
49170 if (!RES_IS_GSCSI(res->cfg_entry) &&
49171 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49172@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49173 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49174 * hrrq_id assigned here in queuecommand
49175 */
49176- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49177+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49178 pinstance->num_hrrq;
49179 cmd->cmd_done = pmcraid_io_done;
49180
49181@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49182 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49183 * hrrq_id assigned here in queuecommand
49184 */
49185- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49186+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49187 pinstance->num_hrrq;
49188
49189 if (request_size) {
49190@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49191
49192 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49193 /* add resources only after host is added into system */
49194- if (!atomic_read(&pinstance->expose_resources))
49195+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49196 return;
49197
49198 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49199@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49200 init_waitqueue_head(&pinstance->reset_wait_q);
49201
49202 atomic_set(&pinstance->outstanding_cmds, 0);
49203- atomic_set(&pinstance->last_message_id, 0);
49204- atomic_set(&pinstance->expose_resources, 0);
49205+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49206+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49207
49208 INIT_LIST_HEAD(&pinstance->free_res_q);
49209 INIT_LIST_HEAD(&pinstance->used_res_q);
49210@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49211 /* Schedule worker thread to handle CCN and take care of adding and
49212 * removing devices to OS
49213 */
49214- atomic_set(&pinstance->expose_resources, 1);
49215+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49216 schedule_work(&pinstance->worker_q);
49217 return rc;
49218
49219diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49220index e1d150f..6c6df44 100644
49221--- a/drivers/scsi/pmcraid.h
49222+++ b/drivers/scsi/pmcraid.h
49223@@ -748,7 +748,7 @@ struct pmcraid_instance {
49224 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49225
49226 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49227- atomic_t last_message_id;
49228+ atomic_unchecked_t last_message_id;
49229
49230 /* configuration table */
49231 struct pmcraid_config_table *cfg_table;
49232@@ -777,7 +777,7 @@ struct pmcraid_instance {
49233 atomic_t outstanding_cmds;
49234
49235 /* should add/delete resources to mid-layer now ?*/
49236- atomic_t expose_resources;
49237+ atomic_unchecked_t expose_resources;
49238
49239
49240
49241@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49242 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49243 };
49244 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49245- atomic_t read_failures; /* count of failed READ commands */
49246- atomic_t write_failures; /* count of failed WRITE commands */
49247+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49248+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49249
49250 /* To indicate add/delete/modify during CCN */
49251 u8 change_detected;
49252diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49253index 5f174b8..98d32b0 100644
49254--- a/drivers/scsi/qla2xxx/qla_attr.c
49255+++ b/drivers/scsi/qla2xxx/qla_attr.c
49256@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49257 return 0;
49258 }
49259
49260-struct fc_function_template qla2xxx_transport_functions = {
49261+fc_function_template_no_const qla2xxx_transport_functions = {
49262
49263 .show_host_node_name = 1,
49264 .show_host_port_name = 1,
49265@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49266 .bsg_timeout = qla24xx_bsg_timeout,
49267 };
49268
49269-struct fc_function_template qla2xxx_transport_vport_functions = {
49270+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49271
49272 .show_host_node_name = 1,
49273 .show_host_port_name = 1,
49274diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49275index 4446bf5..9a3574d 100644
49276--- a/drivers/scsi/qla2xxx/qla_gbl.h
49277+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49278@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49279 struct device_attribute;
49280 extern struct device_attribute *qla2x00_host_attrs[];
49281 struct fc_function_template;
49282-extern struct fc_function_template qla2xxx_transport_functions;
49283-extern struct fc_function_template qla2xxx_transport_vport_functions;
49284+extern fc_function_template_no_const qla2xxx_transport_functions;
49285+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49286 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49287 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49288 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49289diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49290index 52be35e..b933907 100644
49291--- a/drivers/scsi/qla2xxx/qla_os.c
49292+++ b/drivers/scsi/qla2xxx/qla_os.c
49293@@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49294 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49295 /* Ok, a 64bit DMA mask is applicable. */
49296 ha->flags.enable_64bit_addressing = 1;
49297- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49298- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49299+ pax_open_kernel();
49300+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49301+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49302+ pax_close_kernel();
49303 return;
49304 }
49305 }
49306diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49307index 084d1fd..9f939eb 100644
49308--- a/drivers/scsi/qla4xxx/ql4_def.h
49309+++ b/drivers/scsi/qla4xxx/ql4_def.h
49310@@ -296,7 +296,7 @@ struct ddb_entry {
49311 * (4000 only) */
49312 atomic_t relogin_timer; /* Max Time to wait for
49313 * relogin to complete */
49314- atomic_t relogin_retry_count; /* Num of times relogin has been
49315+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49316 * retried */
49317 uint32_t default_time2wait; /* Default Min time between
49318 * relogins (+aens) */
49319diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49320index cf174a4..128a420 100644
49321--- a/drivers/scsi/qla4xxx/ql4_os.c
49322+++ b/drivers/scsi/qla4xxx/ql4_os.c
49323@@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49324 */
49325 if (!iscsi_is_session_online(cls_sess)) {
49326 /* Reset retry relogin timer */
49327- atomic_inc(&ddb_entry->relogin_retry_count);
49328+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49329 DEBUG2(ql4_printk(KERN_INFO, ha,
49330 "%s: index[%d] relogin timed out-retrying"
49331 " relogin (%d), retry (%d)\n", __func__,
49332 ddb_entry->fw_ddb_index,
49333- atomic_read(&ddb_entry->relogin_retry_count),
49334+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49335 ddb_entry->default_time2wait + 4));
49336 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49337 atomic_set(&ddb_entry->retry_relogin_timer,
49338@@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49339
49340 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49341 atomic_set(&ddb_entry->relogin_timer, 0);
49342- atomic_set(&ddb_entry->relogin_retry_count, 0);
49343+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49344 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49345 ddb_entry->default_relogin_timeout =
49346 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49347diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49348index fe0bcb1..c9255be 100644
49349--- a/drivers/scsi/scsi.c
49350+++ b/drivers/scsi/scsi.c
49351@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49352 struct Scsi_Host *host = cmd->device->host;
49353 int rtn = 0;
49354
49355- atomic_inc(&cmd->device->iorequest_cnt);
49356+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49357
49358 /* check if the device is still usable */
49359 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49360diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49361index 62ec84b..93159d8 100644
49362--- a/drivers/scsi/scsi_lib.c
49363+++ b/drivers/scsi/scsi_lib.c
49364@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49365 shost = sdev->host;
49366 scsi_init_cmd_errh(cmd);
49367 cmd->result = DID_NO_CONNECT << 16;
49368- atomic_inc(&cmd->device->iorequest_cnt);
49369+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49370
49371 /*
49372 * SCSI request completion path will do scsi_device_unbusy(),
49373@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49374
49375 INIT_LIST_HEAD(&cmd->eh_entry);
49376
49377- atomic_inc(&cmd->device->iodone_cnt);
49378+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49379 if (cmd->result)
49380- atomic_inc(&cmd->device->ioerr_cnt);
49381+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49382
49383 disposition = scsi_decide_disposition(cmd);
49384 if (disposition != SUCCESS &&
49385diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49386index 8ff62c2..693b6f7 100644
49387--- a/drivers/scsi/scsi_sysfs.c
49388+++ b/drivers/scsi/scsi_sysfs.c
49389@@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49390 char *buf) \
49391 { \
49392 struct scsi_device *sdev = to_scsi_device(dev); \
49393- unsigned long long count = atomic_read(&sdev->field); \
49394+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49395 return snprintf(buf, 20, "0x%llx\n", count); \
49396 } \
49397 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49398diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49399index 84a1fdf..693b0d6 100644
49400--- a/drivers/scsi/scsi_tgt_lib.c
49401+++ b/drivers/scsi/scsi_tgt_lib.c
49402@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49403 int err;
49404
49405 dprintk("%lx %u\n", uaddr, len);
49406- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49407+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49408 if (err) {
49409 /*
49410 * TODO: need to fixup sg_tablesize, max_segment_size,
49411diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49412index 4628fd5..a94a1c2 100644
49413--- a/drivers/scsi/scsi_transport_fc.c
49414+++ b/drivers/scsi/scsi_transport_fc.c
49415@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49416 * Netlink Infrastructure
49417 */
49418
49419-static atomic_t fc_event_seq;
49420+static atomic_unchecked_t fc_event_seq;
49421
49422 /**
49423 * fc_get_event_number - Obtain the next sequential FC event number
49424@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49425 u32
49426 fc_get_event_number(void)
49427 {
49428- return atomic_add_return(1, &fc_event_seq);
49429+ return atomic_add_return_unchecked(1, &fc_event_seq);
49430 }
49431 EXPORT_SYMBOL(fc_get_event_number);
49432
49433@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49434 {
49435 int error;
49436
49437- atomic_set(&fc_event_seq, 0);
49438+ atomic_set_unchecked(&fc_event_seq, 0);
49439
49440 error = transport_class_register(&fc_host_class);
49441 if (error)
49442@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49443 char *cp;
49444
49445 *val = simple_strtoul(buf, &cp, 0);
49446- if ((*cp && (*cp != '\n')) || (*val < 0))
49447+ if (*cp && (*cp != '\n'))
49448 return -EINVAL;
49449 /*
49450 * Check for overflow; dev_loss_tmo is u32
49451diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49452index 63a6ca4..5d5cadd 100644
49453--- a/drivers/scsi/scsi_transport_iscsi.c
49454+++ b/drivers/scsi/scsi_transport_iscsi.c
49455@@ -79,7 +79,7 @@ struct iscsi_internal {
49456 struct transport_container session_cont;
49457 };
49458
49459-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49460+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49461 static struct workqueue_struct *iscsi_eh_timer_workq;
49462
49463 static DEFINE_IDA(iscsi_sess_ida);
49464@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49465 int err;
49466
49467 ihost = shost->shost_data;
49468- session->sid = atomic_add_return(1, &iscsi_session_nr);
49469+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49470
49471 if (target_id == ISCSI_MAX_TARGET) {
49472 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49473@@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49474 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49475 ISCSI_TRANSPORT_VERSION);
49476
49477- atomic_set(&iscsi_session_nr, 0);
49478+ atomic_set_unchecked(&iscsi_session_nr, 0);
49479
49480 err = class_register(&iscsi_transport_class);
49481 if (err)
49482diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49483index 2700a5a..752ec38 100644
49484--- a/drivers/scsi/scsi_transport_srp.c
49485+++ b/drivers/scsi/scsi_transport_srp.c
49486@@ -36,7 +36,7 @@
49487 #include "scsi_transport_srp_internal.h"
49488
49489 struct srp_host_attrs {
49490- atomic_t next_port_id;
49491+ atomic_unchecked_t next_port_id;
49492 };
49493 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49494
49495@@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49496 struct Scsi_Host *shost = dev_to_shost(dev);
49497 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49498
49499- atomic_set(&srp_host->next_port_id, 0);
49500+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49501 return 0;
49502 }
49503
49504@@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49505 rport_fast_io_fail_timedout);
49506 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49507
49508- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49509+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49510 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49511
49512 transport_setup_device(&rport->dev);
49513diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49514index 69725f7..03aaee1 100644
49515--- a/drivers/scsi/sd.c
49516+++ b/drivers/scsi/sd.c
49517@@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49518 sdkp->disk = gd;
49519 sdkp->index = index;
49520 atomic_set(&sdkp->openers, 0);
49521- atomic_set(&sdkp->device->ioerr_cnt, 0);
49522+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49523
49524 if (!sdp->request_queue->rq_timeout) {
49525 if (sdp->type != TYPE_MOD)
49526diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49527index df5e961..df6b97f 100644
49528--- a/drivers/scsi/sg.c
49529+++ b/drivers/scsi/sg.c
49530@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49531 sdp->disk->disk_name,
49532 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49533 NULL,
49534- (char *)arg);
49535+ (char __user *)arg);
49536 case BLKTRACESTART:
49537 return blk_trace_startstop(sdp->device->request_queue, 1);
49538 case BLKTRACESTOP:
49539diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49540index 349ebba..ff2a249 100644
49541--- a/drivers/spi/spi.c
49542+++ b/drivers/spi/spi.c
49543@@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49544 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49545
49546 /* portable code must never pass more than 32 bytes */
49547-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49548+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49549
49550 static u8 *buf;
49551
49552diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49553index 2c61783..4d49e4e 100644
49554--- a/drivers/staging/android/timed_output.c
49555+++ b/drivers/staging/android/timed_output.c
49556@@ -25,7 +25,7 @@
49557 #include "timed_output.h"
49558
49559 static struct class *timed_output_class;
49560-static atomic_t device_count;
49561+static atomic_unchecked_t device_count;
49562
49563 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49564 char *buf)
49565@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49566 timed_output_class = class_create(THIS_MODULE, "timed_output");
49567 if (IS_ERR(timed_output_class))
49568 return PTR_ERR(timed_output_class);
49569- atomic_set(&device_count, 0);
49570+ atomic_set_unchecked(&device_count, 0);
49571 timed_output_class->dev_groups = timed_output_groups;
49572 }
49573
49574@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49575 if (ret < 0)
49576 return ret;
49577
49578- tdev->index = atomic_inc_return(&device_count);
49579+ tdev->index = atomic_inc_return_unchecked(&device_count);
49580 tdev->dev = device_create(timed_output_class, NULL,
49581 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49582 if (IS_ERR(tdev->dev))
49583diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49584index c0f7cd7..5424212 100644
49585--- a/drivers/staging/gdm724x/gdm_tty.c
49586+++ b/drivers/staging/gdm724x/gdm_tty.c
49587@@ -45,7 +45,7 @@
49588 #define gdm_tty_send_control(n, r, v, d, l) (\
49589 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49590
49591-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49592+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49593
49594 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49595 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49596diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49597index 96e4eee..6d7c37e 100644
49598--- a/drivers/staging/imx-drm/imx-drm-core.c
49599+++ b/drivers/staging/imx-drm/imx-drm-core.c
49600@@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49601 goto err_busy;
49602 }
49603
49604- if (imxdrm->drm->open_count) {
49605+ if (local_read(&imxdrm->drm->open_count)) {
49606 ret = -EBUSY;
49607 goto err_busy;
49608 }
49609@@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49610
49611 mutex_lock(&imxdrm->mutex);
49612
49613- if (imxdrm->drm->open_count) {
49614+ if (local_read(&imxdrm->drm->open_count)) {
49615 ret = -EBUSY;
49616 goto err_busy;
49617 }
49618@@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49619
49620 mutex_lock(&imxdrm->mutex);
49621
49622- if (imxdrm->drm->open_count) {
49623+ if (local_read(&imxdrm->drm->open_count)) {
49624 ret = -EBUSY;
49625 goto err_busy;
49626 }
49627diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49628index b7613c8..c302392 100644
49629--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49630+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49631@@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49632 return 0;
49633 }
49634
49635-sfw_test_client_ops_t brw_test_client;
49636-void brw_init_test_client(void)
49637-{
49638- brw_test_client.tso_init = brw_client_init;
49639- brw_test_client.tso_fini = brw_client_fini;
49640- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49641- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49642+sfw_test_client_ops_t brw_test_client = {
49643+ .tso_init = brw_client_init,
49644+ .tso_fini = brw_client_fini,
49645+ .tso_prep_rpc = brw_client_prep_rpc,
49646+ .tso_done_rpc = brw_client_done_rpc,
49647 };
49648
49649 srpc_service_t brw_test_service;
49650diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49651index 483c785..e1a2a7b 100644
49652--- a/drivers/staging/lustre/lnet/selftest/framework.c
49653+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49654@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49655
49656 extern sfw_test_client_ops_t ping_test_client;
49657 extern srpc_service_t ping_test_service;
49658-extern void ping_init_test_client(void);
49659 extern void ping_init_test_service(void);
49660
49661 extern sfw_test_client_ops_t brw_test_client;
49662 extern srpc_service_t brw_test_service;
49663-extern void brw_init_test_client(void);
49664 extern void brw_init_test_service(void);
49665
49666
49667@@ -1684,12 +1682,10 @@ sfw_startup (void)
49668 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49669 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49670
49671- brw_init_test_client();
49672 brw_init_test_service();
49673 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49674 LASSERT (rc == 0);
49675
49676- ping_init_test_client();
49677 ping_init_test_service();
49678 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49679 LASSERT (rc == 0);
49680diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49681index f0f9194..b589047 100644
49682--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49683+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49684@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49685 return 0;
49686 }
49687
49688-sfw_test_client_ops_t ping_test_client;
49689-void ping_init_test_client(void)
49690-{
49691- ping_test_client.tso_init = ping_client_init;
49692- ping_test_client.tso_fini = ping_client_fini;
49693- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49694- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49695-}
49696+sfw_test_client_ops_t ping_test_client = {
49697+ .tso_init = ping_client_init,
49698+ .tso_fini = ping_client_fini,
49699+ .tso_prep_rpc = ping_client_prep_rpc,
49700+ .tso_done_rpc = ping_client_done_rpc,
49701+};
49702
49703 srpc_service_t ping_test_service;
49704 void ping_init_test_service(void)
49705diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49706index bc2b82f..67fd598 100644
49707--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49708+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49709@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49710 ldlm_completion_callback lcs_completion;
49711 ldlm_blocking_callback lcs_blocking;
49712 ldlm_glimpse_callback lcs_glimpse;
49713-};
49714+} __no_const;
49715
49716 /* ldlm_lockd.c */
49717 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49718diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49719index d0aea15..7af68e1 100644
49720--- a/drivers/staging/lustre/lustre/include/obd.h
49721+++ b/drivers/staging/lustre/lustre/include/obd.h
49722@@ -1417,7 +1417,7 @@ struct md_ops {
49723 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49724 * wrapper function in include/linux/obd_class.h.
49725 */
49726-};
49727+} __no_const;
49728
49729 struct lsm_operations {
49730 void (*lsm_free)(struct lov_stripe_md *);
49731diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49732index 39fcdac..222780f 100644
49733--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49734+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49735@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49736 int added = (mode == LCK_NL);
49737 int overlaps = 0;
49738 int splitted = 0;
49739- const struct ldlm_callback_suite null_cbs = { NULL };
49740+ const struct ldlm_callback_suite null_cbs = { };
49741 int rc;
49742
49743 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49744diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49745index fc6c977..df1f956 100644
49746--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49747+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49748@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49749 int LL_PROC_PROTO(proc_console_max_delay_cs)
49750 {
49751 int rc, max_delay_cs;
49752- ctl_table_t dummy = *table;
49753+ ctl_table_no_const dummy = *table;
49754 cfs_duration_t d;
49755
49756 dummy.data = &max_delay_cs;
49757@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49758 int LL_PROC_PROTO(proc_console_min_delay_cs)
49759 {
49760 int rc, min_delay_cs;
49761- ctl_table_t dummy = *table;
49762+ ctl_table_no_const dummy = *table;
49763 cfs_duration_t d;
49764
49765 dummy.data = &min_delay_cs;
49766@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49767 int LL_PROC_PROTO(proc_console_backoff)
49768 {
49769 int rc, backoff;
49770- ctl_table_t dummy = *table;
49771+ ctl_table_no_const dummy = *table;
49772
49773 dummy.data = &backoff;
49774 dummy.proc_handler = &proc_dointvec;
49775diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49776index f3108c7..cd4f9da 100644
49777--- a/drivers/staging/lustre/lustre/libcfs/module.c
49778+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49779@@ -348,11 +348,11 @@ out:
49780
49781
49782 struct cfs_psdev_ops libcfs_psdev_ops = {
49783- libcfs_psdev_open,
49784- libcfs_psdev_release,
49785- NULL,
49786- NULL,
49787- libcfs_ioctl
49788+ .p_open = libcfs_psdev_open,
49789+ .p_close = libcfs_psdev_release,
49790+ .p_read = NULL,
49791+ .p_write = NULL,
49792+ .p_ioctl = libcfs_ioctl
49793 };
49794
49795 extern int insert_proc(void);
49796diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49797index a4e0472..05d854c 100644
49798--- a/drivers/staging/lustre/lustre/llite/dir.c
49799+++ b/drivers/staging/lustre/lustre/llite/dir.c
49800@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49801 int mode;
49802 int err;
49803
49804- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49805+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49806 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49807 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49808 lump);
49809diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49810index 3675020..e80d92c 100644
49811--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49812+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49813@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49814
49815 static int solo_sysfs_init(struct solo_dev *solo_dev)
49816 {
49817- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49818+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49819 struct device *dev = &solo_dev->dev;
49820 const char *driver;
49821 int i;
49822diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49823index 1db18c7..35e6afc 100644
49824--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49825+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49826@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49827
49828 int solo_g723_init(struct solo_dev *solo_dev)
49829 {
49830- static struct snd_device_ops ops = { NULL };
49831+ static struct snd_device_ops ops = { };
49832 struct snd_card *card;
49833 struct snd_kcontrol_new kctl;
49834 char name[32];
49835diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49836index 7f2f247..d999137 100644
49837--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49838+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49839@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49840
49841 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49842 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49843- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49844+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49845 if (p2m_id < 0)
49846 p2m_id = -p2m_id;
49847 }
49848diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49849index f1bbb8c..a73eaba 100644
49850--- a/drivers/staging/media/solo6x10/solo6x10.h
49851+++ b/drivers/staging/media/solo6x10/solo6x10.h
49852@@ -237,7 +237,7 @@ struct solo_dev {
49853
49854 /* P2M DMA Engine */
49855 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49856- atomic_t p2m_count;
49857+ atomic_unchecked_t p2m_count;
49858 int p2m_jiffies;
49859 unsigned int p2m_timeouts;
49860
49861diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49862index 0315f60..ce93f406 100644
49863--- a/drivers/staging/octeon/ethernet-rx.c
49864+++ b/drivers/staging/octeon/ethernet-rx.c
49865@@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49866 /* Increment RX stats for virtual ports */
49867 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49868 #ifdef CONFIG_64BIT
49869- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49870- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49871+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49872+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49873 #else
49874- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49875- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49876+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49877+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49878 #endif
49879 }
49880 netif_receive_skb(skb);
49881@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49882 dev->name);
49883 */
49884 #ifdef CONFIG_64BIT
49885- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49886+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49887 #else
49888- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49889+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49890 #endif
49891 dev_kfree_skb_irq(skb);
49892 }
49893diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49894index bd6ca71..8f0961e 100644
49895--- a/drivers/staging/octeon/ethernet.c
49896+++ b/drivers/staging/octeon/ethernet.c
49897@@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49898 * since the RX tasklet also increments it.
49899 */
49900 #ifdef CONFIG_64BIT
49901- atomic64_add(rx_status.dropped_packets,
49902- (atomic64_t *)&priv->stats.rx_dropped);
49903+ atomic64_add_unchecked(rx_status.dropped_packets,
49904+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49905 #else
49906- atomic_add(rx_status.dropped_packets,
49907- (atomic_t *)&priv->stats.rx_dropped);
49908+ atomic_add_unchecked(rx_status.dropped_packets,
49909+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49910 #endif
49911 }
49912
49913diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49914index 439c3c9..2d74293 100644
49915--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49916+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49917@@ -271,7 +271,7 @@ struct hal_ops {
49918 s32 (*c2h_handler)(struct adapter *padapter,
49919 struct c2h_evt_hdr *c2h_evt);
49920 c2h_id_filter c2h_id_filter_ccx;
49921-};
49922+} __no_const;
49923
49924 enum rt_eeprom_type {
49925 EEPROM_93C46,
49926diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49927index eb6f0e5..e6a0958 100644
49928--- a/drivers/staging/rtl8188eu/include/rtw_io.h
49929+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49930@@ -126,7 +126,7 @@ struct _io_ops {
49931 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49932 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49933 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49934-};
49935+} __no_const;
49936
49937 struct io_req {
49938 struct list_head list;
49939diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49940index dc23395..cf7e9b1 100644
49941--- a/drivers/staging/rtl8712/rtl871x_io.h
49942+++ b/drivers/staging/rtl8712/rtl871x_io.h
49943@@ -108,7 +108,7 @@ struct _io_ops {
49944 u8 *pmem);
49945 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49946 u8 *pmem);
49947-};
49948+} __no_const;
49949
49950 struct io_req {
49951 struct list_head list;
49952diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49953index 1f5088b..0e59820 100644
49954--- a/drivers/staging/sbe-2t3e3/netdev.c
49955+++ b/drivers/staging/sbe-2t3e3/netdev.c
49956@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49957 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49958
49959 if (rlen)
49960- if (copy_to_user(data, &resp, rlen))
49961+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49962 return -EFAULT;
49963
49964 return 0;
49965diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49966index a863a98..d272795 100644
49967--- a/drivers/staging/usbip/vhci.h
49968+++ b/drivers/staging/usbip/vhci.h
49969@@ -83,7 +83,7 @@ struct vhci_hcd {
49970 unsigned resuming:1;
49971 unsigned long re_timeout;
49972
49973- atomic_t seqnum;
49974+ atomic_unchecked_t seqnum;
49975
49976 /*
49977 * NOTE:
49978diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49979index e810ad5..931336f 100644
49980--- a/drivers/staging/usbip/vhci_hcd.c
49981+++ b/drivers/staging/usbip/vhci_hcd.c
49982@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49983
49984 spin_lock(&vdev->priv_lock);
49985
49986- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49987+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49988 if (priv->seqnum == 0xffff)
49989 dev_info(&urb->dev->dev, "seqnum max\n");
49990
49991@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49992 return -ENOMEM;
49993 }
49994
49995- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49996+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49997 if (unlink->seqnum == 0xffff)
49998 pr_info("seqnum max\n");
49999
50000@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
50001 vdev->rhport = rhport;
50002 }
50003
50004- atomic_set(&vhci->seqnum, 0);
50005+ atomic_set_unchecked(&vhci->seqnum, 0);
50006 spin_lock_init(&vhci->lock);
50007
50008 hcd->power_budget = 0; /* no limit */
50009diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50010index d07fcb5..358e1e1 100644
50011--- a/drivers/staging/usbip/vhci_rx.c
50012+++ b/drivers/staging/usbip/vhci_rx.c
50013@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50014 if (!urb) {
50015 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50016 pr_info("max seqnum %d\n",
50017- atomic_read(&the_controller->seqnum));
50018+ atomic_read_unchecked(&the_controller->seqnum));
50019 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50020 return;
50021 }
50022diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50023index ab8b2ba..99184aa 100644
50024--- a/drivers/staging/vt6655/hostap.c
50025+++ b/drivers/staging/vt6655/hostap.c
50026@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50027 *
50028 */
50029
50030+static net_device_ops_no_const apdev_netdev_ops;
50031+
50032 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50033 {
50034 PSDevice apdev_priv;
50035 struct net_device *dev = pDevice->dev;
50036 int ret;
50037- const struct net_device_ops apdev_netdev_ops = {
50038- .ndo_start_xmit = pDevice->tx_80211,
50039- };
50040
50041 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50042
50043@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50044 *apdev_priv = *pDevice;
50045 eth_hw_addr_inherit(pDevice->apdev, dev);
50046
50047+ /* only half broken now */
50048+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50049 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50050
50051 pDevice->apdev->type = ARPHRD_IEEE80211;
50052diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50053index 67ba48b..24e602f 100644
50054--- a/drivers/staging/vt6656/hostap.c
50055+++ b/drivers/staging/vt6656/hostap.c
50056@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50057 *
50058 */
50059
50060+static net_device_ops_no_const apdev_netdev_ops;
50061+
50062 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50063 {
50064 struct vnt_private *apdev_priv;
50065 struct net_device *dev = pDevice->dev;
50066 int ret;
50067- const struct net_device_ops apdev_netdev_ops = {
50068- .ndo_start_xmit = pDevice->tx_80211,
50069- };
50070
50071 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50072
50073@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50074 *apdev_priv = *pDevice;
50075 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50076
50077+ /* only half broken now */
50078+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50079 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50080
50081 pDevice->apdev->type = ARPHRD_IEEE80211;
50082diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50083index 24884ca..26c8220 100644
50084--- a/drivers/target/sbp/sbp_target.c
50085+++ b/drivers/target/sbp/sbp_target.c
50086@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50087
50088 #define SESSION_MAINTENANCE_INTERVAL HZ
50089
50090-static atomic_t login_id = ATOMIC_INIT(0);
50091+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50092
50093 static void session_maintenance_work(struct work_struct *);
50094 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50095@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50096 login->lun = se_lun;
50097 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50098 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50099- login->login_id = atomic_inc_return(&login_id);
50100+ login->login_id = atomic_inc_return_unchecked(&login_id);
50101
50102 login->tgt_agt = sbp_target_agent_register(login);
50103 if (IS_ERR(login->tgt_agt)) {
50104diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50105index d06de84..fd38c9b 100644
50106--- a/drivers/target/target_core_device.c
50107+++ b/drivers/target/target_core_device.c
50108@@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50109 spin_lock_init(&dev->se_tmr_lock);
50110 spin_lock_init(&dev->qf_cmd_lock);
50111 sema_init(&dev->caw_sem, 1);
50112- atomic_set(&dev->dev_ordered_id, 0);
50113+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50114 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50115 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50116 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50117diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50118index dee2be1..f5fd8ca 100644
50119--- a/drivers/target/target_core_transport.c
50120+++ b/drivers/target/target_core_transport.c
50121@@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50122 * Used to determine when ORDERED commands should go from
50123 * Dormant to Active status.
50124 */
50125- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50126+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50127 smp_mb__after_atomic_inc();
50128 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50129 cmd->se_ordered_id, cmd->sam_task_attr,
50130diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50131index 33f83fe..d80f8e1 100644
50132--- a/drivers/tty/cyclades.c
50133+++ b/drivers/tty/cyclades.c
50134@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50135 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50136 info->port.count);
50137 #endif
50138- info->port.count++;
50139+ atomic_inc(&info->port.count);
50140 #ifdef CY_DEBUG_COUNT
50141 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50142- current->pid, info->port.count);
50143+ current->pid, atomic_read(&info->port.count));
50144 #endif
50145
50146 /*
50147@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50148 for (j = 0; j < cy_card[i].nports; j++) {
50149 info = &cy_card[i].ports[j];
50150
50151- if (info->port.count) {
50152+ if (atomic_read(&info->port.count)) {
50153 /* XXX is the ldisc num worth this? */
50154 struct tty_struct *tty;
50155 struct tty_ldisc *ld;
50156diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50157index 9eba119..5070303 100644
50158--- a/drivers/tty/hvc/hvc_console.c
50159+++ b/drivers/tty/hvc/hvc_console.c
50160@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50161
50162 spin_lock_irqsave(&hp->port.lock, flags);
50163 /* Check and then increment for fast path open. */
50164- if (hp->port.count++ > 0) {
50165+ if (atomic_inc_return(&hp->port.count) > 1) {
50166 spin_unlock_irqrestore(&hp->port.lock, flags);
50167 hvc_kick();
50168 return 0;
50169@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50170
50171 spin_lock_irqsave(&hp->port.lock, flags);
50172
50173- if (--hp->port.count == 0) {
50174+ if (atomic_dec_return(&hp->port.count) == 0) {
50175 spin_unlock_irqrestore(&hp->port.lock, flags);
50176 /* We are done with the tty pointer now. */
50177 tty_port_tty_set(&hp->port, NULL);
50178@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50179 */
50180 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50181 } else {
50182- if (hp->port.count < 0)
50183+ if (atomic_read(&hp->port.count) < 0)
50184 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50185- hp->vtermno, hp->port.count);
50186+ hp->vtermno, atomic_read(&hp->port.count));
50187 spin_unlock_irqrestore(&hp->port.lock, flags);
50188 }
50189 }
50190@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50191 * open->hangup case this can be called after the final close so prevent
50192 * that from happening for now.
50193 */
50194- if (hp->port.count <= 0) {
50195+ if (atomic_read(&hp->port.count) <= 0) {
50196 spin_unlock_irqrestore(&hp->port.lock, flags);
50197 return;
50198 }
50199
50200- hp->port.count = 0;
50201+ atomic_set(&hp->port.count, 0);
50202 spin_unlock_irqrestore(&hp->port.lock, flags);
50203 tty_port_tty_set(&hp->port, NULL);
50204
50205@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50206 return -EPIPE;
50207
50208 /* FIXME what's this (unprotected) check for? */
50209- if (hp->port.count <= 0)
50210+ if (atomic_read(&hp->port.count) <= 0)
50211 return -EIO;
50212
50213 spin_lock_irqsave(&hp->lock, flags);
50214diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50215index 81e939e..95ead10 100644
50216--- a/drivers/tty/hvc/hvcs.c
50217+++ b/drivers/tty/hvc/hvcs.c
50218@@ -83,6 +83,7 @@
50219 #include <asm/hvcserver.h>
50220 #include <asm/uaccess.h>
50221 #include <asm/vio.h>
50222+#include <asm/local.h>
50223
50224 /*
50225 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50226@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50227
50228 spin_lock_irqsave(&hvcsd->lock, flags);
50229
50230- if (hvcsd->port.count > 0) {
50231+ if (atomic_read(&hvcsd->port.count) > 0) {
50232 spin_unlock_irqrestore(&hvcsd->lock, flags);
50233 printk(KERN_INFO "HVCS: vterm state unchanged. "
50234 "The hvcs device node is still in use.\n");
50235@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50236 }
50237 }
50238
50239- hvcsd->port.count = 0;
50240+ atomic_set(&hvcsd->port.count, 0);
50241 hvcsd->port.tty = tty;
50242 tty->driver_data = hvcsd;
50243
50244@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50245 unsigned long flags;
50246
50247 spin_lock_irqsave(&hvcsd->lock, flags);
50248- hvcsd->port.count++;
50249+ atomic_inc(&hvcsd->port.count);
50250 hvcsd->todo_mask |= HVCS_SCHED_READ;
50251 spin_unlock_irqrestore(&hvcsd->lock, flags);
50252
50253@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50254 hvcsd = tty->driver_data;
50255
50256 spin_lock_irqsave(&hvcsd->lock, flags);
50257- if (--hvcsd->port.count == 0) {
50258+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50259
50260 vio_disable_interrupts(hvcsd->vdev);
50261
50262@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50263
50264 free_irq(irq, hvcsd);
50265 return;
50266- } else if (hvcsd->port.count < 0) {
50267+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50268 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50269 " is missmanaged.\n",
50270- hvcsd->vdev->unit_address, hvcsd->port.count);
50271+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50272 }
50273
50274 spin_unlock_irqrestore(&hvcsd->lock, flags);
50275@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50276
50277 spin_lock_irqsave(&hvcsd->lock, flags);
50278 /* Preserve this so that we know how many kref refs to put */
50279- temp_open_count = hvcsd->port.count;
50280+ temp_open_count = atomic_read(&hvcsd->port.count);
50281
50282 /*
50283 * Don't kref put inside the spinlock because the destruction
50284@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50285 tty->driver_data = NULL;
50286 hvcsd->port.tty = NULL;
50287
50288- hvcsd->port.count = 0;
50289+ atomic_set(&hvcsd->port.count, 0);
50290
50291 /* This will drop any buffered data on the floor which is OK in a hangup
50292 * scenario. */
50293@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50294 * the middle of a write operation? This is a crummy place to do this
50295 * but we want to keep it all in the spinlock.
50296 */
50297- if (hvcsd->port.count <= 0) {
50298+ if (atomic_read(&hvcsd->port.count) <= 0) {
50299 spin_unlock_irqrestore(&hvcsd->lock, flags);
50300 return -ENODEV;
50301 }
50302@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50303 {
50304 struct hvcs_struct *hvcsd = tty->driver_data;
50305
50306- if (!hvcsd || hvcsd->port.count <= 0)
50307+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50308 return 0;
50309
50310 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50311diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50312index 4190199..06d5bfa 100644
50313--- a/drivers/tty/hvc/hvsi.c
50314+++ b/drivers/tty/hvc/hvsi.c
50315@@ -85,7 +85,7 @@ struct hvsi_struct {
50316 int n_outbuf;
50317 uint32_t vtermno;
50318 uint32_t virq;
50319- atomic_t seqno; /* HVSI packet sequence number */
50320+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50321 uint16_t mctrl;
50322 uint8_t state; /* HVSI protocol state */
50323 uint8_t flags;
50324@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50325
50326 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50327 packet.hdr.len = sizeof(struct hvsi_query_response);
50328- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50329+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50330 packet.verb = VSV_SEND_VERSION_NUMBER;
50331 packet.u.version = HVSI_VERSION;
50332 packet.query_seqno = query_seqno+1;
50333@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50334
50335 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50336 packet.hdr.len = sizeof(struct hvsi_query);
50337- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50338+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50339 packet.verb = verb;
50340
50341 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50342@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50343 int wrote;
50344
50345 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50346- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50347+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50348 packet.hdr.len = sizeof(struct hvsi_control);
50349 packet.verb = VSV_SET_MODEM_CTL;
50350 packet.mask = HVSI_TSDTR;
50351@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50352 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50353
50354 packet.hdr.type = VS_DATA_PACKET_HEADER;
50355- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50356+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50357 packet.hdr.len = count + sizeof(struct hvsi_header);
50358 memcpy(&packet.data, buf, count);
50359
50360@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50361 struct hvsi_control packet __ALIGNED__;
50362
50363 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50364- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50365+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50366 packet.hdr.len = 6;
50367 packet.verb = VSV_CLOSE_PROTOCOL;
50368
50369@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50370
50371 tty_port_tty_set(&hp->port, tty);
50372 spin_lock_irqsave(&hp->lock, flags);
50373- hp->port.count++;
50374+ atomic_inc(&hp->port.count);
50375 atomic_set(&hp->seqno, 0);
50376 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50377 spin_unlock_irqrestore(&hp->lock, flags);
50378@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50379
50380 spin_lock_irqsave(&hp->lock, flags);
50381
50382- if (--hp->port.count == 0) {
50383+ if (atomic_dec_return(&hp->port.count) == 0) {
50384 tty_port_tty_set(&hp->port, NULL);
50385 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50386
50387@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50388
50389 spin_lock_irqsave(&hp->lock, flags);
50390 }
50391- } else if (hp->port.count < 0)
50392+ } else if (atomic_read(&hp->port.count) < 0)
50393 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50394- hp - hvsi_ports, hp->port.count);
50395+ hp - hvsi_ports, atomic_read(&hp->port.count));
50396
50397 spin_unlock_irqrestore(&hp->lock, flags);
50398 }
50399@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50400 tty_port_tty_set(&hp->port, NULL);
50401
50402 spin_lock_irqsave(&hp->lock, flags);
50403- hp->port.count = 0;
50404+ atomic_set(&hp->port.count, 0);
50405 hp->n_outbuf = 0;
50406 spin_unlock_irqrestore(&hp->lock, flags);
50407 }
50408diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50409index 347050e..14f8fbf 100644
50410--- a/drivers/tty/hvc/hvsi_lib.c
50411+++ b/drivers/tty/hvc/hvsi_lib.c
50412@@ -9,7 +9,7 @@
50413
50414 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50415 {
50416- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50417+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50418
50419 /* Assumes that always succeeds, works in practice */
50420 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50421@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50422
50423 /* Reset state */
50424 pv->established = 0;
50425- atomic_set(&pv->seqno, 0);
50426+ atomic_set_unchecked(&pv->seqno, 0);
50427
50428 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50429
50430diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50431index 8fd72ff..34a0bed 100644
50432--- a/drivers/tty/ipwireless/tty.c
50433+++ b/drivers/tty/ipwireless/tty.c
50434@@ -29,6 +29,7 @@
50435 #include <linux/tty_driver.h>
50436 #include <linux/tty_flip.h>
50437 #include <linux/uaccess.h>
50438+#include <asm/local.h>
50439
50440 #include "tty.h"
50441 #include "network.h"
50442@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50443 mutex_unlock(&tty->ipw_tty_mutex);
50444 return -ENODEV;
50445 }
50446- if (tty->port.count == 0)
50447+ if (atomic_read(&tty->port.count) == 0)
50448 tty->tx_bytes_queued = 0;
50449
50450- tty->port.count++;
50451+ atomic_inc(&tty->port.count);
50452
50453 tty->port.tty = linux_tty;
50454 linux_tty->driver_data = tty;
50455@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50456
50457 static void do_ipw_close(struct ipw_tty *tty)
50458 {
50459- tty->port.count--;
50460-
50461- if (tty->port.count == 0) {
50462+ if (atomic_dec_return(&tty->port.count) == 0) {
50463 struct tty_struct *linux_tty = tty->port.tty;
50464
50465 if (linux_tty != NULL) {
50466@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50467 return;
50468
50469 mutex_lock(&tty->ipw_tty_mutex);
50470- if (tty->port.count == 0) {
50471+ if (atomic_read(&tty->port.count) == 0) {
50472 mutex_unlock(&tty->ipw_tty_mutex);
50473 return;
50474 }
50475@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50476
50477 mutex_lock(&tty->ipw_tty_mutex);
50478
50479- if (!tty->port.count) {
50480+ if (!atomic_read(&tty->port.count)) {
50481 mutex_unlock(&tty->ipw_tty_mutex);
50482 return;
50483 }
50484@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50485 return -ENODEV;
50486
50487 mutex_lock(&tty->ipw_tty_mutex);
50488- if (!tty->port.count) {
50489+ if (!atomic_read(&tty->port.count)) {
50490 mutex_unlock(&tty->ipw_tty_mutex);
50491 return -EINVAL;
50492 }
50493@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50494 if (!tty)
50495 return -ENODEV;
50496
50497- if (!tty->port.count)
50498+ if (!atomic_read(&tty->port.count))
50499 return -EINVAL;
50500
50501 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50502@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50503 if (!tty)
50504 return 0;
50505
50506- if (!tty->port.count)
50507+ if (!atomic_read(&tty->port.count))
50508 return 0;
50509
50510 return tty->tx_bytes_queued;
50511@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50512 if (!tty)
50513 return -ENODEV;
50514
50515- if (!tty->port.count)
50516+ if (!atomic_read(&tty->port.count))
50517 return -EINVAL;
50518
50519 return get_control_lines(tty);
50520@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50521 if (!tty)
50522 return -ENODEV;
50523
50524- if (!tty->port.count)
50525+ if (!atomic_read(&tty->port.count))
50526 return -EINVAL;
50527
50528 return set_control_lines(tty, set, clear);
50529@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50530 if (!tty)
50531 return -ENODEV;
50532
50533- if (!tty->port.count)
50534+ if (!atomic_read(&tty->port.count))
50535 return -EINVAL;
50536
50537 /* FIXME: Exactly how is the tty object locked here .. */
50538@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50539 * are gone */
50540 mutex_lock(&ttyj->ipw_tty_mutex);
50541 }
50542- while (ttyj->port.count)
50543+ while (atomic_read(&ttyj->port.count))
50544 do_ipw_close(ttyj);
50545 ipwireless_disassociate_network_ttys(network,
50546 ttyj->channel_idx);
50547diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50548index 1deaca4..c8582d4 100644
50549--- a/drivers/tty/moxa.c
50550+++ b/drivers/tty/moxa.c
50551@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50552 }
50553
50554 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50555- ch->port.count++;
50556+ atomic_inc(&ch->port.count);
50557 tty->driver_data = ch;
50558 tty_port_tty_set(&ch->port, tty);
50559 mutex_lock(&ch->port.mutex);
50560diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50561index 5056090..c80ca04 100644
50562--- a/drivers/tty/n_gsm.c
50563+++ b/drivers/tty/n_gsm.c
50564@@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50565 spin_lock_init(&dlci->lock);
50566 mutex_init(&dlci->mutex);
50567 dlci->fifo = &dlci->_fifo;
50568- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50569+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50570 kfree(dlci);
50571 return NULL;
50572 }
50573@@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50574 struct gsm_dlci *dlci = tty->driver_data;
50575 struct tty_port *port = &dlci->port;
50576
50577- port->count++;
50578+ atomic_inc(&port->count);
50579 dlci_get(dlci);
50580 dlci_get(dlci->gsm->dlci[0]);
50581 mux_get(dlci->gsm);
50582diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50583index 4c10837..a40ec45 100644
50584--- a/drivers/tty/n_tty.c
50585+++ b/drivers/tty/n_tty.c
50586@@ -114,7 +114,7 @@ struct n_tty_data {
50587 int minimum_to_wake;
50588
50589 /* consumer-published */
50590- size_t read_tail;
50591+ size_t read_tail __intentional_overflow(-1);
50592 size_t line_start;
50593
50594 /* protected by output lock */
50595@@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50596 {
50597 *ops = tty_ldisc_N_TTY;
50598 ops->owner = NULL;
50599- ops->refcount = ops->flags = 0;
50600+ atomic_set(&ops->refcount, 0);
50601+ ops->flags = 0;
50602 }
50603 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50604diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50605index 25c9bc7..24077b7 100644
50606--- a/drivers/tty/pty.c
50607+++ b/drivers/tty/pty.c
50608@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50609 panic("Couldn't register Unix98 pts driver");
50610
50611 /* Now create the /dev/ptmx special device */
50612+ pax_open_kernel();
50613 tty_default_fops(&ptmx_fops);
50614- ptmx_fops.open = ptmx_open;
50615+ *(void **)&ptmx_fops.open = ptmx_open;
50616+ pax_close_kernel();
50617
50618 cdev_init(&ptmx_cdev, &ptmx_fops);
50619 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50620diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50621index 354564e..fe50d9a 100644
50622--- a/drivers/tty/rocket.c
50623+++ b/drivers/tty/rocket.c
50624@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50625 tty->driver_data = info;
50626 tty_port_tty_set(port, tty);
50627
50628- if (port->count++ == 0) {
50629+ if (atomic_inc_return(&port->count) == 1) {
50630 atomic_inc(&rp_num_ports_open);
50631
50632 #ifdef ROCKET_DEBUG_OPEN
50633@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50634 #endif
50635 }
50636 #ifdef ROCKET_DEBUG_OPEN
50637- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50638+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50639 #endif
50640
50641 /*
50642@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50643 spin_unlock_irqrestore(&info->port.lock, flags);
50644 return;
50645 }
50646- if (info->port.count)
50647+ if (atomic_read(&info->port.count))
50648 atomic_dec(&rp_num_ports_open);
50649 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50650 spin_unlock_irqrestore(&info->port.lock, flags);
50651diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50652index 1274499..f541382 100644
50653--- a/drivers/tty/serial/ioc4_serial.c
50654+++ b/drivers/tty/serial/ioc4_serial.c
50655@@ -437,7 +437,7 @@ struct ioc4_soft {
50656 } is_intr_info[MAX_IOC4_INTR_ENTS];
50657
50658 /* Number of entries active in the above array */
50659- atomic_t is_num_intrs;
50660+ atomic_unchecked_t is_num_intrs;
50661 } is_intr_type[IOC4_NUM_INTR_TYPES];
50662
50663 /* is_ir_lock must be held while
50664@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50665 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50666 || (type == IOC4_OTHER_INTR_TYPE)));
50667
50668- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50669+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50670 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50671
50672 /* Save off the lower level interrupt handler */
50673@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50674
50675 soft = arg;
50676 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50677- num_intrs = (int)atomic_read(
50678+ num_intrs = (int)atomic_read_unchecked(
50679 &soft->is_intr_type[intr_type].is_num_intrs);
50680
50681 this_mir = this_ir = pending_intrs(soft, intr_type);
50682diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50683index a260cde..6b2b5ce 100644
50684--- a/drivers/tty/serial/kgdboc.c
50685+++ b/drivers/tty/serial/kgdboc.c
50686@@ -24,8 +24,9 @@
50687 #define MAX_CONFIG_LEN 40
50688
50689 static struct kgdb_io kgdboc_io_ops;
50690+static struct kgdb_io kgdboc_io_ops_console;
50691
50692-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50693+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50694 static int configured = -1;
50695
50696 static char config[MAX_CONFIG_LEN];
50697@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50698 kgdboc_unregister_kbd();
50699 if (configured == 1)
50700 kgdb_unregister_io_module(&kgdboc_io_ops);
50701+ else if (configured == 2)
50702+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50703 }
50704
50705 static int configure_kgdboc(void)
50706@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50707 int err;
50708 char *cptr = config;
50709 struct console *cons;
50710+ int is_console = 0;
50711
50712 err = kgdboc_option_setup(config);
50713 if (err || !strlen(config) || isspace(config[0]))
50714 goto noconfig;
50715
50716 err = -ENODEV;
50717- kgdboc_io_ops.is_console = 0;
50718 kgdb_tty_driver = NULL;
50719
50720 kgdboc_use_kms = 0;
50721@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50722 int idx;
50723 if (cons->device && cons->device(cons, &idx) == p &&
50724 idx == tty_line) {
50725- kgdboc_io_ops.is_console = 1;
50726+ is_console = 1;
50727 break;
50728 }
50729 cons = cons->next;
50730@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50731 kgdb_tty_line = tty_line;
50732
50733 do_register:
50734- err = kgdb_register_io_module(&kgdboc_io_ops);
50735+ if (is_console) {
50736+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50737+ configured = 2;
50738+ } else {
50739+ err = kgdb_register_io_module(&kgdboc_io_ops);
50740+ configured = 1;
50741+ }
50742 if (err)
50743 goto noconfig;
50744
50745@@ -205,8 +214,6 @@ do_register:
50746 if (err)
50747 goto nmi_con_failed;
50748
50749- configured = 1;
50750-
50751 return 0;
50752
50753 nmi_con_failed:
50754@@ -223,7 +230,7 @@ noconfig:
50755 static int __init init_kgdboc(void)
50756 {
50757 /* Already configured? */
50758- if (configured == 1)
50759+ if (configured >= 1)
50760 return 0;
50761
50762 return configure_kgdboc();
50763@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50764 if (config[len - 1] == '\n')
50765 config[len - 1] = '\0';
50766
50767- if (configured == 1)
50768+ if (configured >= 1)
50769 cleanup_kgdboc();
50770
50771 /* Go and configure with the new params. */
50772@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50773 .post_exception = kgdboc_post_exp_handler,
50774 };
50775
50776+static struct kgdb_io kgdboc_io_ops_console = {
50777+ .name = "kgdboc",
50778+ .read_char = kgdboc_get_char,
50779+ .write_char = kgdboc_put_char,
50780+ .pre_exception = kgdboc_pre_exp_handler,
50781+ .post_exception = kgdboc_post_exp_handler,
50782+ .is_console = 1
50783+};
50784+
50785 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50786 /* This is only available if kgdboc is a built in for early debugging */
50787 static int __init kgdboc_early_init(char *opt)
50788diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50789index b5d779c..3622cfe 100644
50790--- a/drivers/tty/serial/msm_serial.c
50791+++ b/drivers/tty/serial/msm_serial.c
50792@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50793 .cons = MSM_CONSOLE,
50794 };
50795
50796-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50797+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50798
50799 static const struct of_device_id msm_uartdm_table[] = {
50800 { .compatible = "qcom,msm-uartdm" },
50801@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50802 int irq;
50803
50804 if (pdev->id == -1)
50805- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50806+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50807
50808 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50809 return -ENXIO;
50810diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50811index c1af04d..0815c8a 100644
50812--- a/drivers/tty/serial/samsung.c
50813+++ b/drivers/tty/serial/samsung.c
50814@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50815 }
50816 }
50817
50818+static int s3c64xx_serial_startup(struct uart_port *port);
50819 static int s3c24xx_serial_startup(struct uart_port *port)
50820 {
50821 struct s3c24xx_uart_port *ourport = to_ourport(port);
50822 int ret;
50823
50824+ /* Startup sequence is different for s3c64xx and higher SoC's */
50825+ if (s3c24xx_serial_has_interrupt_mask(port))
50826+ return s3c64xx_serial_startup(port);
50827+
50828 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50829 port->mapbase, port->membase);
50830
50831@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50832 /* setup info for port */
50833 port->dev = &platdev->dev;
50834
50835- /* Startup sequence is different for s3c64xx and higher SoC's */
50836- if (s3c24xx_serial_has_interrupt_mask(port))
50837- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50838-
50839 port->uartclk = 1;
50840
50841 if (cfg->uart_flags & UPF_CONS_FLOW) {
50842diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50843index 0f02351..07c59c5 100644
50844--- a/drivers/tty/serial/serial_core.c
50845+++ b/drivers/tty/serial/serial_core.c
50846@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50847 uart_flush_buffer(tty);
50848 uart_shutdown(tty, state);
50849 spin_lock_irqsave(&port->lock, flags);
50850- port->count = 0;
50851+ atomic_set(&port->count, 0);
50852 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50853 spin_unlock_irqrestore(&port->lock, flags);
50854 tty_port_tty_set(port, NULL);
50855@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50856 goto end;
50857 }
50858
50859- port->count++;
50860+ atomic_inc(&port->count);
50861 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50862 retval = -ENXIO;
50863 goto err_dec_count;
50864@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50865 /*
50866 * Make sure the device is in D0 state.
50867 */
50868- if (port->count == 1)
50869+ if (atomic_read(&port->count) == 1)
50870 uart_change_pm(state, UART_PM_STATE_ON);
50871
50872 /*
50873@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50874 end:
50875 return retval;
50876 err_dec_count:
50877- port->count--;
50878+ atomic_inc(&port->count);
50879 mutex_unlock(&port->mutex);
50880 goto end;
50881 }
50882diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50883index e1ce141..6d4ed80 100644
50884--- a/drivers/tty/synclink.c
50885+++ b/drivers/tty/synclink.c
50886@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50887
50888 if (debug_level >= DEBUG_LEVEL_INFO)
50889 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50890- __FILE__,__LINE__, info->device_name, info->port.count);
50891+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50892
50893 if (tty_port_close_start(&info->port, tty, filp) == 0)
50894 goto cleanup;
50895@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50896 cleanup:
50897 if (debug_level >= DEBUG_LEVEL_INFO)
50898 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50899- tty->driver->name, info->port.count);
50900+ tty->driver->name, atomic_read(&info->port.count));
50901
50902 } /* end of mgsl_close() */
50903
50904@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50905
50906 mgsl_flush_buffer(tty);
50907 shutdown(info);
50908-
50909- info->port.count = 0;
50910+
50911+ atomic_set(&info->port.count, 0);
50912 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50913 info->port.tty = NULL;
50914
50915@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50916
50917 if (debug_level >= DEBUG_LEVEL_INFO)
50918 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50919- __FILE__,__LINE__, tty->driver->name, port->count );
50920+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50921
50922 spin_lock_irqsave(&info->irq_spinlock, flags);
50923 if (!tty_hung_up_p(filp)) {
50924 extra_count = true;
50925- port->count--;
50926+ atomic_dec(&port->count);
50927 }
50928 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50929 port->blocked_open++;
50930@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50931
50932 if (debug_level >= DEBUG_LEVEL_INFO)
50933 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50934- __FILE__,__LINE__, tty->driver->name, port->count );
50935+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50936
50937 tty_unlock(tty);
50938 schedule();
50939@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50940
50941 /* FIXME: Racy on hangup during close wait */
50942 if (extra_count)
50943- port->count++;
50944+ atomic_inc(&port->count);
50945 port->blocked_open--;
50946
50947 if (debug_level >= DEBUG_LEVEL_INFO)
50948 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50949- __FILE__,__LINE__, tty->driver->name, port->count );
50950+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50951
50952 if (!retval)
50953 port->flags |= ASYNC_NORMAL_ACTIVE;
50954@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50955
50956 if (debug_level >= DEBUG_LEVEL_INFO)
50957 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50958- __FILE__,__LINE__,tty->driver->name, info->port.count);
50959+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50960
50961 /* If port is closing, signal caller to try again */
50962 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50963@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50964 spin_unlock_irqrestore(&info->netlock, flags);
50965 goto cleanup;
50966 }
50967- info->port.count++;
50968+ atomic_inc(&info->port.count);
50969 spin_unlock_irqrestore(&info->netlock, flags);
50970
50971- if (info->port.count == 1) {
50972+ if (atomic_read(&info->port.count) == 1) {
50973 /* 1st open on this device, init hardware */
50974 retval = startup(info);
50975 if (retval < 0)
50976@@ -3446,8 +3446,8 @@ cleanup:
50977 if (retval) {
50978 if (tty->count == 1)
50979 info->port.tty = NULL; /* tty layer will release tty struct */
50980- if(info->port.count)
50981- info->port.count--;
50982+ if (atomic_read(&info->port.count))
50983+ atomic_dec(&info->port.count);
50984 }
50985
50986 return retval;
50987@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50988 unsigned short new_crctype;
50989
50990 /* return error if TTY interface open */
50991- if (info->port.count)
50992+ if (atomic_read(&info->port.count))
50993 return -EBUSY;
50994
50995 switch (encoding)
50996@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50997
50998 /* arbitrate between network and tty opens */
50999 spin_lock_irqsave(&info->netlock, flags);
51000- if (info->port.count != 0 || info->netcount != 0) {
51001+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51002 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51003 spin_unlock_irqrestore(&info->netlock, flags);
51004 return -EBUSY;
51005@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51006 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51007
51008 /* return error if TTY interface open */
51009- if (info->port.count)
51010+ if (atomic_read(&info->port.count))
51011 return -EBUSY;
51012
51013 if (cmd != SIOCWANDEV)
51014diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51015index 1abf946..1ee34fc 100644
51016--- a/drivers/tty/synclink_gt.c
51017+++ b/drivers/tty/synclink_gt.c
51018@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51019 tty->driver_data = info;
51020 info->port.tty = tty;
51021
51022- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51023+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51024
51025 /* If port is closing, signal caller to try again */
51026 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51027@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51028 mutex_unlock(&info->port.mutex);
51029 goto cleanup;
51030 }
51031- info->port.count++;
51032+ atomic_inc(&info->port.count);
51033 spin_unlock_irqrestore(&info->netlock, flags);
51034
51035- if (info->port.count == 1) {
51036+ if (atomic_read(&info->port.count) == 1) {
51037 /* 1st open on this device, init hardware */
51038 retval = startup(info);
51039 if (retval < 0) {
51040@@ -715,8 +715,8 @@ cleanup:
51041 if (retval) {
51042 if (tty->count == 1)
51043 info->port.tty = NULL; /* tty layer will release tty struct */
51044- if(info->port.count)
51045- info->port.count--;
51046+ if(atomic_read(&info->port.count))
51047+ atomic_dec(&info->port.count);
51048 }
51049
51050 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51051@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51052
51053 if (sanity_check(info, tty->name, "close"))
51054 return;
51055- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51056+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51057
51058 if (tty_port_close_start(&info->port, tty, filp) == 0)
51059 goto cleanup;
51060@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51061 tty_port_close_end(&info->port, tty);
51062 info->port.tty = NULL;
51063 cleanup:
51064- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51065+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51066 }
51067
51068 static void hangup(struct tty_struct *tty)
51069@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51070 shutdown(info);
51071
51072 spin_lock_irqsave(&info->port.lock, flags);
51073- info->port.count = 0;
51074+ atomic_set(&info->port.count, 0);
51075 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51076 info->port.tty = NULL;
51077 spin_unlock_irqrestore(&info->port.lock, flags);
51078@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51079 unsigned short new_crctype;
51080
51081 /* return error if TTY interface open */
51082- if (info->port.count)
51083+ if (atomic_read(&info->port.count))
51084 return -EBUSY;
51085
51086 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51087@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51088
51089 /* arbitrate between network and tty opens */
51090 spin_lock_irqsave(&info->netlock, flags);
51091- if (info->port.count != 0 || info->netcount != 0) {
51092+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51093 DBGINFO(("%s hdlc_open busy\n", dev->name));
51094 spin_unlock_irqrestore(&info->netlock, flags);
51095 return -EBUSY;
51096@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51097 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51098
51099 /* return error if TTY interface open */
51100- if (info->port.count)
51101+ if (atomic_read(&info->port.count))
51102 return -EBUSY;
51103
51104 if (cmd != SIOCWANDEV)
51105@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51106 if (port == NULL)
51107 continue;
51108 spin_lock(&port->lock);
51109- if ((port->port.count || port->netcount) &&
51110+ if ((atomic_read(&port->port.count) || port->netcount) &&
51111 port->pending_bh && !port->bh_running &&
51112 !port->bh_requested) {
51113 DBGISR(("%s bh queued\n", port->device_name));
51114@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51115 spin_lock_irqsave(&info->lock, flags);
51116 if (!tty_hung_up_p(filp)) {
51117 extra_count = true;
51118- port->count--;
51119+ atomic_dec(&port->count);
51120 }
51121 spin_unlock_irqrestore(&info->lock, flags);
51122 port->blocked_open++;
51123@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51124 remove_wait_queue(&port->open_wait, &wait);
51125
51126 if (extra_count)
51127- port->count++;
51128+ atomic_inc(&port->count);
51129 port->blocked_open--;
51130
51131 if (!retval)
51132diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51133index dc6e969..5dc8786 100644
51134--- a/drivers/tty/synclinkmp.c
51135+++ b/drivers/tty/synclinkmp.c
51136@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51137
51138 if (debug_level >= DEBUG_LEVEL_INFO)
51139 printk("%s(%d):%s open(), old ref count = %d\n",
51140- __FILE__,__LINE__,tty->driver->name, info->port.count);
51141+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51142
51143 /* If port is closing, signal caller to try again */
51144 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51145@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51146 spin_unlock_irqrestore(&info->netlock, flags);
51147 goto cleanup;
51148 }
51149- info->port.count++;
51150+ atomic_inc(&info->port.count);
51151 spin_unlock_irqrestore(&info->netlock, flags);
51152
51153- if (info->port.count == 1) {
51154+ if (atomic_read(&info->port.count) == 1) {
51155 /* 1st open on this device, init hardware */
51156 retval = startup(info);
51157 if (retval < 0)
51158@@ -796,8 +796,8 @@ cleanup:
51159 if (retval) {
51160 if (tty->count == 1)
51161 info->port.tty = NULL; /* tty layer will release tty struct */
51162- if(info->port.count)
51163- info->port.count--;
51164+ if(atomic_read(&info->port.count))
51165+ atomic_dec(&info->port.count);
51166 }
51167
51168 return retval;
51169@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51170
51171 if (debug_level >= DEBUG_LEVEL_INFO)
51172 printk("%s(%d):%s close() entry, count=%d\n",
51173- __FILE__,__LINE__, info->device_name, info->port.count);
51174+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51175
51176 if (tty_port_close_start(&info->port, tty, filp) == 0)
51177 goto cleanup;
51178@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51179 cleanup:
51180 if (debug_level >= DEBUG_LEVEL_INFO)
51181 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51182- tty->driver->name, info->port.count);
51183+ tty->driver->name, atomic_read(&info->port.count));
51184 }
51185
51186 /* Called by tty_hangup() when a hangup is signaled.
51187@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51188 shutdown(info);
51189
51190 spin_lock_irqsave(&info->port.lock, flags);
51191- info->port.count = 0;
51192+ atomic_set(&info->port.count, 0);
51193 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51194 info->port.tty = NULL;
51195 spin_unlock_irqrestore(&info->port.lock, flags);
51196@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51197 unsigned short new_crctype;
51198
51199 /* return error if TTY interface open */
51200- if (info->port.count)
51201+ if (atomic_read(&info->port.count))
51202 return -EBUSY;
51203
51204 switch (encoding)
51205@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51206
51207 /* arbitrate between network and tty opens */
51208 spin_lock_irqsave(&info->netlock, flags);
51209- if (info->port.count != 0 || info->netcount != 0) {
51210+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51211 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51212 spin_unlock_irqrestore(&info->netlock, flags);
51213 return -EBUSY;
51214@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51215 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51216
51217 /* return error if TTY interface open */
51218- if (info->port.count)
51219+ if (atomic_read(&info->port.count))
51220 return -EBUSY;
51221
51222 if (cmd != SIOCWANDEV)
51223@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51224 * do not request bottom half processing if the
51225 * device is not open in a normal mode.
51226 */
51227- if ( port && (port->port.count || port->netcount) &&
51228+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51229 port->pending_bh && !port->bh_running &&
51230 !port->bh_requested ) {
51231 if ( debug_level >= DEBUG_LEVEL_ISR )
51232@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51233
51234 if (debug_level >= DEBUG_LEVEL_INFO)
51235 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51236- __FILE__,__LINE__, tty->driver->name, port->count );
51237+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51238
51239 spin_lock_irqsave(&info->lock, flags);
51240 if (!tty_hung_up_p(filp)) {
51241 extra_count = true;
51242- port->count--;
51243+ atomic_dec(&port->count);
51244 }
51245 spin_unlock_irqrestore(&info->lock, flags);
51246 port->blocked_open++;
51247@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51248
51249 if (debug_level >= DEBUG_LEVEL_INFO)
51250 printk("%s(%d):%s block_til_ready() count=%d\n",
51251- __FILE__,__LINE__, tty->driver->name, port->count );
51252+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51253
51254 tty_unlock(tty);
51255 schedule();
51256@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51257 remove_wait_queue(&port->open_wait, &wait);
51258
51259 if (extra_count)
51260- port->count++;
51261+ atomic_inc(&port->count);
51262 port->blocked_open--;
51263
51264 if (debug_level >= DEBUG_LEVEL_INFO)
51265 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51266- __FILE__,__LINE__, tty->driver->name, port->count );
51267+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51268
51269 if (!retval)
51270 port->flags |= ASYNC_NORMAL_ACTIVE;
51271diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51272index ce396ec..04a37be 100644
51273--- a/drivers/tty/sysrq.c
51274+++ b/drivers/tty/sysrq.c
51275@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51276 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51277 size_t count, loff_t *ppos)
51278 {
51279- if (count) {
51280+ if (count && capable(CAP_SYS_ADMIN)) {
51281 char c;
51282
51283 if (get_user(c, buf))
51284diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51285index c74a00a..02cf211a 100644
51286--- a/drivers/tty/tty_io.c
51287+++ b/drivers/tty/tty_io.c
51288@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51289
51290 void tty_default_fops(struct file_operations *fops)
51291 {
51292- *fops = tty_fops;
51293+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51294 }
51295
51296 /*
51297diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51298index 6458e11..6cfc218 100644
51299--- a/drivers/tty/tty_ldisc.c
51300+++ b/drivers/tty/tty_ldisc.c
51301@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51302 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51303 tty_ldiscs[disc] = new_ldisc;
51304 new_ldisc->num = disc;
51305- new_ldisc->refcount = 0;
51306+ atomic_set(&new_ldisc->refcount, 0);
51307 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51308
51309 return ret;
51310@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51311 return -EINVAL;
51312
51313 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51314- if (tty_ldiscs[disc]->refcount)
51315+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51316 ret = -EBUSY;
51317 else
51318 tty_ldiscs[disc] = NULL;
51319@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51320 if (ldops) {
51321 ret = ERR_PTR(-EAGAIN);
51322 if (try_module_get(ldops->owner)) {
51323- ldops->refcount++;
51324+ atomic_inc(&ldops->refcount);
51325 ret = ldops;
51326 }
51327 }
51328@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51329 unsigned long flags;
51330
51331 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51332- ldops->refcount--;
51333+ atomic_dec(&ldops->refcount);
51334 module_put(ldops->owner);
51335 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51336 }
51337diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51338index c94d234..8210f2d 100644
51339--- a/drivers/tty/tty_port.c
51340+++ b/drivers/tty/tty_port.c
51341@@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51342 unsigned long flags;
51343
51344 spin_lock_irqsave(&port->lock, flags);
51345- port->count = 0;
51346+ atomic_set(&port->count, 0);
51347 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51348 tty = port->tty;
51349 if (tty)
51350@@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51351 /* The port lock protects the port counts */
51352 spin_lock_irqsave(&port->lock, flags);
51353 if (!tty_hung_up_p(filp))
51354- port->count--;
51355+ atomic_dec(&port->count);
51356 port->blocked_open++;
51357 spin_unlock_irqrestore(&port->lock, flags);
51358
51359@@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51360 we must not mess that up further */
51361 spin_lock_irqsave(&port->lock, flags);
51362 if (!tty_hung_up_p(filp))
51363- port->count++;
51364+ atomic_inc(&port->count);
51365 port->blocked_open--;
51366 if (retval == 0)
51367 port->flags |= ASYNC_NORMAL_ACTIVE;
51368@@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51369 return 0;
51370 }
51371
51372- if (tty->count == 1 && port->count != 1) {
51373+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51374 printk(KERN_WARNING
51375 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51376- port->count);
51377- port->count = 1;
51378+ atomic_read(&port->count));
51379+ atomic_set(&port->count, 1);
51380 }
51381- if (--port->count < 0) {
51382+ if (atomic_dec_return(&port->count) < 0) {
51383 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51384- port->count);
51385- port->count = 0;
51386+ atomic_read(&port->count));
51387+ atomic_set(&port->count, 0);
51388 }
51389
51390- if (port->count) {
51391+ if (atomic_read(&port->count)) {
51392 spin_unlock_irqrestore(&port->lock, flags);
51393 return 0;
51394 }
51395@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51396 {
51397 spin_lock_irq(&port->lock);
51398 if (!tty_hung_up_p(filp))
51399- ++port->count;
51400+ atomic_inc(&port->count);
51401 spin_unlock_irq(&port->lock);
51402 tty_port_tty_set(port, tty);
51403
51404diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51405index d0e3a44..5f8b754 100644
51406--- a/drivers/tty/vt/keyboard.c
51407+++ b/drivers/tty/vt/keyboard.c
51408@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51409 kbd->kbdmode == VC_OFF) &&
51410 value != KVAL(K_SAK))
51411 return; /* SAK is allowed even in raw mode */
51412+
51413+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51414+ {
51415+ void *func = fn_handler[value];
51416+ if (func == fn_show_state || func == fn_show_ptregs ||
51417+ func == fn_show_mem)
51418+ return;
51419+ }
51420+#endif
51421+
51422 fn_handler[value](vc);
51423 }
51424
51425@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51426 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51427 return -EFAULT;
51428
51429- if (!capable(CAP_SYS_TTY_CONFIG))
51430- perm = 0;
51431-
51432 switch (cmd) {
51433 case KDGKBENT:
51434 /* Ensure another thread doesn't free it under us */
51435@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51436 spin_unlock_irqrestore(&kbd_event_lock, flags);
51437 return put_user(val, &user_kbe->kb_value);
51438 case KDSKBENT:
51439+ if (!capable(CAP_SYS_TTY_CONFIG))
51440+ perm = 0;
51441+
51442 if (!perm)
51443 return -EPERM;
51444 if (!i && v == K_NOSUCHMAP) {
51445@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51446 int i, j, k;
51447 int ret;
51448
51449- if (!capable(CAP_SYS_TTY_CONFIG))
51450- perm = 0;
51451-
51452 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51453 if (!kbs) {
51454 ret = -ENOMEM;
51455@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51456 kfree(kbs);
51457 return ((p && *p) ? -EOVERFLOW : 0);
51458 case KDSKBSENT:
51459+ if (!capable(CAP_SYS_TTY_CONFIG))
51460+ perm = 0;
51461+
51462 if (!perm) {
51463 ret = -EPERM;
51464 goto reterr;
51465diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51466index a673e5b..36e5d32 100644
51467--- a/drivers/uio/uio.c
51468+++ b/drivers/uio/uio.c
51469@@ -25,6 +25,7 @@
51470 #include <linux/kobject.h>
51471 #include <linux/cdev.h>
51472 #include <linux/uio_driver.h>
51473+#include <asm/local.h>
51474
51475 #define UIO_MAX_DEVICES (1U << MINORBITS)
51476
51477@@ -32,7 +33,7 @@ struct uio_device {
51478 struct module *owner;
51479 struct device *dev;
51480 int minor;
51481- atomic_t event;
51482+ atomic_unchecked_t event;
51483 struct fasync_struct *async_queue;
51484 wait_queue_head_t wait;
51485 struct uio_info *info;
51486@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51487 struct device_attribute *attr, char *buf)
51488 {
51489 struct uio_device *idev = dev_get_drvdata(dev);
51490- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51491+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51492 }
51493 static DEVICE_ATTR_RO(event);
51494
51495@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51496 {
51497 struct uio_device *idev = info->uio_dev;
51498
51499- atomic_inc(&idev->event);
51500+ atomic_inc_unchecked(&idev->event);
51501 wake_up_interruptible(&idev->wait);
51502 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51503 }
51504@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51505 }
51506
51507 listener->dev = idev;
51508- listener->event_count = atomic_read(&idev->event);
51509+ listener->event_count = atomic_read_unchecked(&idev->event);
51510 filep->private_data = listener;
51511
51512 if (idev->info->open) {
51513@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51514 return -EIO;
51515
51516 poll_wait(filep, &idev->wait, wait);
51517- if (listener->event_count != atomic_read(&idev->event))
51518+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51519 return POLLIN | POLLRDNORM;
51520 return 0;
51521 }
51522@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51523 do {
51524 set_current_state(TASK_INTERRUPTIBLE);
51525
51526- event_count = atomic_read(&idev->event);
51527+ event_count = atomic_read_unchecked(&idev->event);
51528 if (event_count != listener->event_count) {
51529 if (copy_to_user(buf, &event_count, count))
51530 retval = -EFAULT;
51531@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51532 static int uio_find_mem_index(struct vm_area_struct *vma)
51533 {
51534 struct uio_device *idev = vma->vm_private_data;
51535+ unsigned long size;
51536
51537 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51538- if (idev->info->mem[vma->vm_pgoff].size == 0)
51539+ size = idev->info->mem[vma->vm_pgoff].size;
51540+ if (size == 0)
51541+ return -1;
51542+ if (vma->vm_end - vma->vm_start > size)
51543 return -1;
51544 return (int)vma->vm_pgoff;
51545 }
51546@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51547 idev->owner = owner;
51548 idev->info = info;
51549 init_waitqueue_head(&idev->wait);
51550- atomic_set(&idev->event, 0);
51551+ atomic_set_unchecked(&idev->event, 0);
51552
51553 ret = uio_get_minor(idev);
51554 if (ret)
51555diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51556index 8a7eb77..c00402f 100644
51557--- a/drivers/usb/atm/cxacru.c
51558+++ b/drivers/usb/atm/cxacru.c
51559@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51560 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51561 if (ret < 2)
51562 return -EINVAL;
51563- if (index < 0 || index > 0x7f)
51564+ if (index > 0x7f)
51565 return -EINVAL;
51566 pos += tmp;
51567
51568diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51569index 25a7bfc..57f3cf5 100644
51570--- a/drivers/usb/atm/usbatm.c
51571+++ b/drivers/usb/atm/usbatm.c
51572@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51573 if (printk_ratelimit())
51574 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51575 __func__, vpi, vci);
51576- atomic_inc(&vcc->stats->rx_err);
51577+ atomic_inc_unchecked(&vcc->stats->rx_err);
51578 return;
51579 }
51580
51581@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51582 if (length > ATM_MAX_AAL5_PDU) {
51583 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51584 __func__, length, vcc);
51585- atomic_inc(&vcc->stats->rx_err);
51586+ atomic_inc_unchecked(&vcc->stats->rx_err);
51587 goto out;
51588 }
51589
51590@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51591 if (sarb->len < pdu_length) {
51592 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51593 __func__, pdu_length, sarb->len, vcc);
51594- atomic_inc(&vcc->stats->rx_err);
51595+ atomic_inc_unchecked(&vcc->stats->rx_err);
51596 goto out;
51597 }
51598
51599 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51600 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51601 __func__, vcc);
51602- atomic_inc(&vcc->stats->rx_err);
51603+ atomic_inc_unchecked(&vcc->stats->rx_err);
51604 goto out;
51605 }
51606
51607@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51608 if (printk_ratelimit())
51609 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51610 __func__, length);
51611- atomic_inc(&vcc->stats->rx_drop);
51612+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51613 goto out;
51614 }
51615
51616@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51617
51618 vcc->push(vcc, skb);
51619
51620- atomic_inc(&vcc->stats->rx);
51621+ atomic_inc_unchecked(&vcc->stats->rx);
51622 out:
51623 skb_trim(sarb, 0);
51624 }
51625@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51626 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51627
51628 usbatm_pop(vcc, skb);
51629- atomic_inc(&vcc->stats->tx);
51630+ atomic_inc_unchecked(&vcc->stats->tx);
51631
51632 skb = skb_dequeue(&instance->sndqueue);
51633 }
51634@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51635 if (!left--)
51636 return sprintf(page,
51637 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51638- atomic_read(&atm_dev->stats.aal5.tx),
51639- atomic_read(&atm_dev->stats.aal5.tx_err),
51640- atomic_read(&atm_dev->stats.aal5.rx),
51641- atomic_read(&atm_dev->stats.aal5.rx_err),
51642- atomic_read(&atm_dev->stats.aal5.rx_drop));
51643+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51644+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51645+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51646+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51647+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51648
51649 if (!left--) {
51650 if (instance->disconnected)
51651diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51652index 2a3bbdf..91d72cf 100644
51653--- a/drivers/usb/core/devices.c
51654+++ b/drivers/usb/core/devices.c
51655@@ -126,7 +126,7 @@ static const char format_endpt[] =
51656 * time it gets called.
51657 */
51658 static struct device_connect_event {
51659- atomic_t count;
51660+ atomic_unchecked_t count;
51661 wait_queue_head_t wait;
51662 } device_event = {
51663 .count = ATOMIC_INIT(1),
51664@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51665
51666 void usbfs_conn_disc_event(void)
51667 {
51668- atomic_add(2, &device_event.count);
51669+ atomic_add_unchecked(2, &device_event.count);
51670 wake_up(&device_event.wait);
51671 }
51672
51673@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51674
51675 poll_wait(file, &device_event.wait, wait);
51676
51677- event_count = atomic_read(&device_event.count);
51678+ event_count = atomic_read_unchecked(&device_event.count);
51679 if (file->f_version != event_count) {
51680 file->f_version = event_count;
51681 return POLLIN | POLLRDNORM;
51682diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51683index 967152a..16fa2e5 100644
51684--- a/drivers/usb/core/devio.c
51685+++ b/drivers/usb/core/devio.c
51686@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51687 struct dev_state *ps = file->private_data;
51688 struct usb_device *dev = ps->dev;
51689 ssize_t ret = 0;
51690- unsigned len;
51691+ size_t len;
51692 loff_t pos;
51693 int i;
51694
51695@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51696 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51697 struct usb_config_descriptor *config =
51698 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51699- unsigned int length = le16_to_cpu(config->wTotalLength);
51700+ size_t length = le16_to_cpu(config->wTotalLength);
51701
51702 if (*ppos < pos + length) {
51703
51704 /* The descriptor may claim to be longer than it
51705 * really is. Here is the actual allocated length. */
51706- unsigned alloclen =
51707+ size_t alloclen =
51708 le16_to_cpu(dev->config[i].desc.wTotalLength);
51709
51710- len = length - (*ppos - pos);
51711+ len = length + pos - *ppos;
51712 if (len > nbytes)
51713 len = nbytes;
51714
51715 /* Simply don't write (skip over) unallocated parts */
51716 if (alloclen > (*ppos - pos)) {
51717- alloclen -= (*ppos - pos);
51718+ alloclen = alloclen + pos - *ppos;
51719 if (copy_to_user(buf,
51720 dev->rawdescriptors[i] + (*ppos - pos),
51721 min(len, alloclen))) {
51722diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51723index d39106c..bfe13a4 100644
51724--- a/drivers/usb/core/hcd.c
51725+++ b/drivers/usb/core/hcd.c
51726@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51727 */
51728 usb_get_urb(urb);
51729 atomic_inc(&urb->use_count);
51730- atomic_inc(&urb->dev->urbnum);
51731+ atomic_inc_unchecked(&urb->dev->urbnum);
51732 usbmon_urb_submit(&hcd->self, urb);
51733
51734 /* NOTE requirements on root-hub callers (usbfs and the hub
51735@@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51736 urb->hcpriv = NULL;
51737 INIT_LIST_HEAD(&urb->urb_list);
51738 atomic_dec(&urb->use_count);
51739- atomic_dec(&urb->dev->urbnum);
51740+ atomic_dec_unchecked(&urb->dev->urbnum);
51741 if (atomic_read(&urb->reject))
51742 wake_up(&usb_kill_urb_queue);
51743 usb_put_urb(urb);
51744diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51745index ebcd3bf..be93a64 100644
51746--- a/drivers/usb/core/hub.c
51747+++ b/drivers/usb/core/hub.c
51748@@ -27,6 +27,7 @@
51749 #include <linux/freezer.h>
51750 #include <linux/random.h>
51751 #include <linux/pm_qos.h>
51752+#include <linux/grsecurity.h>
51753
51754 #include <asm/uaccess.h>
51755 #include <asm/byteorder.h>
51756@@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51757 goto done;
51758 return;
51759 }
51760+
51761+ if (gr_handle_new_usb())
51762+ goto done;
51763+
51764 if (hub_is_superspeed(hub->hdev))
51765 unit_load = 150;
51766 else
51767diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51768index bb31597..6c5ef8b 100644
51769--- a/drivers/usb/core/message.c
51770+++ b/drivers/usb/core/message.c
51771@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51772 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51773 * error number.
51774 */
51775-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51776+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51777 __u8 requesttype, __u16 value, __u16 index, void *data,
51778 __u16 size, int timeout)
51779 {
51780@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51781 * If successful, 0. Otherwise a negative error number. The number of actual
51782 * bytes transferred will be stored in the @actual_length paramater.
51783 */
51784-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51785+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51786 void *data, int len, int *actual_length, int timeout)
51787 {
51788 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51789@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51790 * bytes transferred will be stored in the @actual_length paramater.
51791 *
51792 */
51793-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51794+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51795 void *data, int len, int *actual_length, int timeout)
51796 {
51797 struct urb *urb;
51798diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51799index 52a97ad..e73330f 100644
51800--- a/drivers/usb/core/sysfs.c
51801+++ b/drivers/usb/core/sysfs.c
51802@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51803 struct usb_device *udev;
51804
51805 udev = to_usb_device(dev);
51806- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51807+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51808 }
51809 static DEVICE_ATTR_RO(urbnum);
51810
51811diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51812index 4d11449..f4ccabf 100644
51813--- a/drivers/usb/core/usb.c
51814+++ b/drivers/usb/core/usb.c
51815@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51816 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51817 dev->state = USB_STATE_ATTACHED;
51818 dev->lpm_disable_count = 1;
51819- atomic_set(&dev->urbnum, 0);
51820+ atomic_set_unchecked(&dev->urbnum, 0);
51821
51822 INIT_LIST_HEAD(&dev->ep0.urb_list);
51823 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51824diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51825index 02e44fc..3c4fe64 100644
51826--- a/drivers/usb/dwc3/gadget.c
51827+++ b/drivers/usb/dwc3/gadget.c
51828@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51829 if (!usb_endpoint_xfer_isoc(desc))
51830 return 0;
51831
51832- memset(&trb_link, 0, sizeof(trb_link));
51833-
51834 /* Link TRB for ISOC. The HWO bit is never reset */
51835 trb_st_hw = &dep->trb_pool[0];
51836
51837diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51838index 8cfc319..4868255 100644
51839--- a/drivers/usb/early/ehci-dbgp.c
51840+++ b/drivers/usb/early/ehci-dbgp.c
51841@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51842
51843 #ifdef CONFIG_KGDB
51844 static struct kgdb_io kgdbdbgp_io_ops;
51845-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51846+static struct kgdb_io kgdbdbgp_io_ops_console;
51847+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51848 #else
51849 #define dbgp_kgdb_mode (0)
51850 #endif
51851@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51852 .write_char = kgdbdbgp_write_char,
51853 };
51854
51855+static struct kgdb_io kgdbdbgp_io_ops_console = {
51856+ .name = "kgdbdbgp",
51857+ .read_char = kgdbdbgp_read_char,
51858+ .write_char = kgdbdbgp_write_char,
51859+ .is_console = 1
51860+};
51861+
51862 static int kgdbdbgp_wait_time;
51863
51864 static int __init kgdbdbgp_parse_config(char *str)
51865@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51866 ptr++;
51867 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51868 }
51869- kgdb_register_io_module(&kgdbdbgp_io_ops);
51870- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51871+ if (early_dbgp_console.index != -1)
51872+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51873+ else
51874+ kgdb_register_io_module(&kgdbdbgp_io_ops);
51875
51876 return 0;
51877 }
51878diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51879index b369292..9f3ba40 100644
51880--- a/drivers/usb/gadget/u_serial.c
51881+++ b/drivers/usb/gadget/u_serial.c
51882@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51883 spin_lock_irq(&port->port_lock);
51884
51885 /* already open? Great. */
51886- if (port->port.count) {
51887+ if (atomic_read(&port->port.count)) {
51888 status = 0;
51889- port->port.count++;
51890+ atomic_inc(&port->port.count);
51891
51892 /* currently opening/closing? wait ... */
51893 } else if (port->openclose) {
51894@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51895 tty->driver_data = port;
51896 port->port.tty = tty;
51897
51898- port->port.count = 1;
51899+ atomic_set(&port->port.count, 1);
51900 port->openclose = false;
51901
51902 /* if connected, start the I/O stream */
51903@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51904
51905 spin_lock_irq(&port->port_lock);
51906
51907- if (port->port.count != 1) {
51908- if (port->port.count == 0)
51909+ if (atomic_read(&port->port.count) != 1) {
51910+ if (atomic_read(&port->port.count) == 0)
51911 WARN_ON(1);
51912 else
51913- --port->port.count;
51914+ atomic_dec(&port->port.count);
51915 goto exit;
51916 }
51917
51918@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51919 * and sleep if necessary
51920 */
51921 port->openclose = true;
51922- port->port.count = 0;
51923+ atomic_set(&port->port.count, 0);
51924
51925 gser = port->port_usb;
51926 if (gser && gser->disconnect)
51927@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51928 int cond;
51929
51930 spin_lock_irq(&port->port_lock);
51931- cond = (port->port.count == 0) && !port->openclose;
51932+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51933 spin_unlock_irq(&port->port_lock);
51934 return cond;
51935 }
51936@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51937 /* if it's already open, start I/O ... and notify the serial
51938 * protocol about open/close status (connect/disconnect).
51939 */
51940- if (port->port.count) {
51941+ if (atomic_read(&port->port.count)) {
51942 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51943 gs_start_io(port);
51944 if (gser->connect)
51945@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51946
51947 port->port_usb = NULL;
51948 gser->ioport = NULL;
51949- if (port->port.count > 0 || port->openclose) {
51950+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
51951 wake_up_interruptible(&port->drain_wait);
51952 if (port->port.tty)
51953 tty_hangup(port->port.tty);
51954@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51955
51956 /* finally, free any unused/unusable I/O buffers */
51957 spin_lock_irqsave(&port->port_lock, flags);
51958- if (port->port.count == 0 && !port->openclose)
51959+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
51960 gs_buf_free(&port->port_write_buf);
51961 gs_free_requests(gser->out, &port->read_pool, NULL);
51962 gs_free_requests(gser->out, &port->read_queue, NULL);
51963diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51964index 1bb85be..29e28d9 100644
51965--- a/drivers/usb/host/ehci-hub.c
51966+++ b/drivers/usb/host/ehci-hub.c
51967@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51968 urb->transfer_flags = URB_DIR_IN;
51969 usb_get_urb(urb);
51970 atomic_inc(&urb->use_count);
51971- atomic_inc(&urb->dev->urbnum);
51972+ atomic_inc_unchecked(&urb->dev->urbnum);
51973 urb->setup_dma = dma_map_single(
51974 hcd->self.controller,
51975 urb->setup_packet,
51976@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51977 urb->status = -EINPROGRESS;
51978 usb_get_urb(urb);
51979 atomic_inc(&urb->use_count);
51980- atomic_inc(&urb->dev->urbnum);
51981+ atomic_inc_unchecked(&urb->dev->urbnum);
51982 retval = submit_single_step_set_feature(hcd, urb, 0);
51983 if (!retval && !wait_for_completion_timeout(&done,
51984 msecs_to_jiffies(2000))) {
51985diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51986index ba6a5d6..f88f7f3 100644
51987--- a/drivers/usb/misc/appledisplay.c
51988+++ b/drivers/usb/misc/appledisplay.c
51989@@ -83,7 +83,7 @@ struct appledisplay {
51990 spinlock_t lock;
51991 };
51992
51993-static atomic_t count_displays = ATOMIC_INIT(0);
51994+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51995 static struct workqueue_struct *wq;
51996
51997 static void appledisplay_complete(struct urb *urb)
51998@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51999
52000 /* Register backlight device */
52001 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52002- atomic_inc_return(&count_displays) - 1);
52003+ atomic_inc_return_unchecked(&count_displays) - 1);
52004 memset(&props, 0, sizeof(struct backlight_properties));
52005 props.type = BACKLIGHT_RAW;
52006 props.max_brightness = 0xff;
52007diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52008index c69bb50..215ef37 100644
52009--- a/drivers/usb/serial/console.c
52010+++ b/drivers/usb/serial/console.c
52011@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52012
52013 info->port = port;
52014
52015- ++port->port.count;
52016+ atomic_inc(&port->port.count);
52017 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52018 if (serial->type->set_termios) {
52019 /*
52020@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52021 }
52022 /* Now that any required fake tty operations are completed restore
52023 * the tty port count */
52024- --port->port.count;
52025+ atomic_dec(&port->port.count);
52026 /* The console is special in terms of closing the device so
52027 * indicate this port is now acting as a system console. */
52028 port->port.console = 1;
52029@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52030 free_tty:
52031 kfree(tty);
52032 reset_open_count:
52033- port->port.count = 0;
52034+ atomic_set(&port->port.count, 0);
52035 usb_autopm_put_interface(serial->interface);
52036 error_get_interface:
52037 usb_serial_put(serial);
52038@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52039 static void usb_console_write(struct console *co,
52040 const char *buf, unsigned count)
52041 {
52042- static struct usbcons_info *info = &usbcons_info;
52043+ struct usbcons_info *info = &usbcons_info;
52044 struct usb_serial_port *port = info->port;
52045 struct usb_serial *serial;
52046 int retval = -ENODEV;
52047diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52048index 75f70f0..d467e1a 100644
52049--- a/drivers/usb/storage/usb.h
52050+++ b/drivers/usb/storage/usb.h
52051@@ -63,7 +63,7 @@ struct us_unusual_dev {
52052 __u8 useProtocol;
52053 __u8 useTransport;
52054 int (*initFunction)(struct us_data *);
52055-};
52056+} __do_const;
52057
52058
52059 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52060diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52061index e614f02..3fd60e2 100644
52062--- a/drivers/usb/wusbcore/wa-hc.h
52063+++ b/drivers/usb/wusbcore/wa-hc.h
52064@@ -225,7 +225,7 @@ struct wahc {
52065 spinlock_t xfer_list_lock;
52066 struct work_struct xfer_enqueue_work;
52067 struct work_struct xfer_error_work;
52068- atomic_t xfer_id_count;
52069+ atomic_unchecked_t xfer_id_count;
52070
52071 kernel_ulong_t quirks;
52072 };
52073@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52074 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52075 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52076 wa->dto_in_use = 0;
52077- atomic_set(&wa->xfer_id_count, 1);
52078+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52079 }
52080
52081 /**
52082diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52083index ed5abe8..7036400 100644
52084--- a/drivers/usb/wusbcore/wa-xfer.c
52085+++ b/drivers/usb/wusbcore/wa-xfer.c
52086@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52087 */
52088 static void wa_xfer_id_init(struct wa_xfer *xfer)
52089 {
52090- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52091+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52092 }
52093
52094 /* Return the xfer's ID. */
52095diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52096index 1eab4ac..e21efc9 100644
52097--- a/drivers/vfio/vfio.c
52098+++ b/drivers/vfio/vfio.c
52099@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52100 return 0;
52101
52102 /* TODO Prevent device auto probing */
52103- WARN("Device %s added to live group %d!\n", dev_name(dev),
52104+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52105 iommu_group_id(group->iommu_group));
52106
52107 return 0;
52108diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c
52109index b12176f..e5522d9 100644
52110--- a/drivers/vhost/net.c
52111+++ b/drivers/vhost/net.c
52112@@ -528,6 +528,12 @@ static int get_rx_bufs(struct vhost_virtqueue *vq,
52113 *iovcount = seg;
52114 if (unlikely(log))
52115 *log_num = nlogs;
52116+
52117+ /* Detect overrun */
52118+ if (unlikely(datalen > 0)) {
52119+ r = UIO_MAXIOV + 1;
52120+ goto err;
52121+ }
52122 return headcount;
52123 err:
52124 vhost_discard_vq_desc(vq, headcount);
52125@@ -583,6 +589,14 @@ static void handle_rx(struct vhost_net *net)
52126 /* On error, stop handling until the next kick. */
52127 if (unlikely(headcount < 0))
52128 break;
52129+ /* On overrun, truncate and discard */
52130+ if (unlikely(headcount > UIO_MAXIOV)) {
52131+ msg.msg_iovlen = 1;
52132+ err = sock->ops->recvmsg(NULL, sock, &msg,
52133+ 1, MSG_DONTWAIT | MSG_TRUNC);
52134+ pr_debug("Discarded rx packet: len %zd\n", sock_len);
52135+ continue;
52136+ }
52137 /* OK, now we need to know about added descriptors. */
52138 if (!headcount) {
52139 if (unlikely(vhost_enable_notify(&net->dev, vq))) {
52140diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52141index 5174eba..451e6bc 100644
52142--- a/drivers/vhost/vringh.c
52143+++ b/drivers/vhost/vringh.c
52144@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52145 /* Userspace access helpers: in this case, addresses are really userspace. */
52146 static inline int getu16_user(u16 *val, const u16 *p)
52147 {
52148- return get_user(*val, (__force u16 __user *)p);
52149+ return get_user(*val, (u16 __force_user *)p);
52150 }
52151
52152 static inline int putu16_user(u16 *p, u16 val)
52153 {
52154- return put_user(val, (__force u16 __user *)p);
52155+ return put_user(val, (u16 __force_user *)p);
52156 }
52157
52158 static inline int copydesc_user(void *dst, const void *src, size_t len)
52159 {
52160- return copy_from_user(dst, (__force void __user *)src, len) ?
52161+ return copy_from_user(dst, (void __force_user *)src, len) ?
52162 -EFAULT : 0;
52163 }
52164
52165@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52166 const struct vring_used_elem *src,
52167 unsigned int num)
52168 {
52169- return copy_to_user((__force void __user *)dst, src,
52170+ return copy_to_user((void __force_user *)dst, src,
52171 sizeof(*dst) * num) ? -EFAULT : 0;
52172 }
52173
52174 static inline int xfer_from_user(void *src, void *dst, size_t len)
52175 {
52176- return copy_from_user(dst, (__force void __user *)src, len) ?
52177+ return copy_from_user(dst, (void __force_user *)src, len) ?
52178 -EFAULT : 0;
52179 }
52180
52181 static inline int xfer_to_user(void *dst, void *src, size_t len)
52182 {
52183- return copy_to_user((__force void __user *)dst, src, len) ?
52184+ return copy_to_user((void __force_user *)dst, src, len) ?
52185 -EFAULT : 0;
52186 }
52187
52188@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52189 vrh->last_used_idx = 0;
52190 vrh->vring.num = num;
52191 /* vring expects kernel addresses, but only used via accessors. */
52192- vrh->vring.desc = (__force struct vring_desc *)desc;
52193- vrh->vring.avail = (__force struct vring_avail *)avail;
52194- vrh->vring.used = (__force struct vring_used *)used;
52195+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52196+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52197+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52198 return 0;
52199 }
52200 EXPORT_SYMBOL(vringh_init_user);
52201@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52202
52203 static inline int putu16_kern(u16 *p, u16 val)
52204 {
52205- ACCESS_ONCE(*p) = val;
52206+ ACCESS_ONCE_RW(*p) = val;
52207 return 0;
52208 }
52209
52210diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52211index 1b0b233..6f34c2c 100644
52212--- a/drivers/video/arcfb.c
52213+++ b/drivers/video/arcfb.c
52214@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52215 return -ENOSPC;
52216
52217 err = 0;
52218- if ((count + p) > fbmemlength) {
52219+ if (count > (fbmemlength - p)) {
52220 count = fbmemlength - p;
52221 err = -ENOSPC;
52222 }
52223diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52224index 12ca031..84a8a74 100644
52225--- a/drivers/video/aty/aty128fb.c
52226+++ b/drivers/video/aty/aty128fb.c
52227@@ -149,7 +149,7 @@ enum {
52228 };
52229
52230 /* Must match above enum */
52231-static char * const r128_family[] = {
52232+static const char * const r128_family[] = {
52233 "AGP",
52234 "PCI",
52235 "PRO AGP",
52236diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52237index 28fafbf..ae91651 100644
52238--- a/drivers/video/aty/atyfb_base.c
52239+++ b/drivers/video/aty/atyfb_base.c
52240@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52241 par->accel_flags = var->accel_flags; /* hack */
52242
52243 if (var->accel_flags) {
52244- info->fbops->fb_sync = atyfb_sync;
52245+ pax_open_kernel();
52246+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52247+ pax_close_kernel();
52248 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52249 } else {
52250- info->fbops->fb_sync = NULL;
52251+ pax_open_kernel();
52252+ *(void **)&info->fbops->fb_sync = NULL;
52253+ pax_close_kernel();
52254 info->flags |= FBINFO_HWACCEL_DISABLED;
52255 }
52256
52257diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52258index 95ec042..e6affdd 100644
52259--- a/drivers/video/aty/mach64_cursor.c
52260+++ b/drivers/video/aty/mach64_cursor.c
52261@@ -7,6 +7,7 @@
52262 #include <linux/string.h>
52263
52264 #include <asm/io.h>
52265+#include <asm/pgtable.h>
52266
52267 #ifdef __sparc__
52268 #include <asm/fbio.h>
52269@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52270 info->sprite.buf_align = 16; /* and 64 lines tall. */
52271 info->sprite.flags = FB_PIXMAP_IO;
52272
52273- info->fbops->fb_cursor = atyfb_cursor;
52274+ pax_open_kernel();
52275+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52276+ pax_close_kernel();
52277
52278 return 0;
52279 }
52280diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52281index 7592cc2..92feb56 100644
52282--- a/drivers/video/backlight/kb3886_bl.c
52283+++ b/drivers/video/backlight/kb3886_bl.c
52284@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52285 static unsigned long kb3886bl_flags;
52286 #define KB3886BL_SUSPENDED 0x01
52287
52288-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52289+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52290 {
52291 .ident = "Sahara Touch-iT",
52292 .matches = {
52293diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52294index 900aa4e..6d49418 100644
52295--- a/drivers/video/fb_defio.c
52296+++ b/drivers/video/fb_defio.c
52297@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52298
52299 BUG_ON(!fbdefio);
52300 mutex_init(&fbdefio->lock);
52301- info->fbops->fb_mmap = fb_deferred_io_mmap;
52302+ pax_open_kernel();
52303+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52304+ pax_close_kernel();
52305 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52306 INIT_LIST_HEAD(&fbdefio->pagelist);
52307 if (fbdefio->delay == 0) /* set a default of 1 s */
52308@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52309 page->mapping = NULL;
52310 }
52311
52312- info->fbops->fb_mmap = NULL;
52313+ *(void **)&info->fbops->fb_mmap = NULL;
52314 mutex_destroy(&fbdefio->lock);
52315 }
52316 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52317diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52318index 010d191..7b8235a 100644
52319--- a/drivers/video/fbmem.c
52320+++ b/drivers/video/fbmem.c
52321@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52322 image->dx += image->width + 8;
52323 }
52324 } else if (rotate == FB_ROTATE_UD) {
52325- for (x = 0; x < num && image->dx >= 0; x++) {
52326+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52327 info->fbops->fb_imageblit(info, image);
52328 image->dx -= image->width + 8;
52329 }
52330@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52331 image->dy += image->height + 8;
52332 }
52333 } else if (rotate == FB_ROTATE_CCW) {
52334- for (x = 0; x < num && image->dy >= 0; x++) {
52335+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52336 info->fbops->fb_imageblit(info, image);
52337 image->dy -= image->height + 8;
52338 }
52339@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52340 return -EFAULT;
52341 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52342 return -EINVAL;
52343- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52344+ if (con2fb.framebuffer >= FB_MAX)
52345 return -EINVAL;
52346 if (!registered_fb[con2fb.framebuffer])
52347 request_module("fb%d", con2fb.framebuffer);
52348@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52349 __u32 data;
52350 int err;
52351
52352- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52353+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52354
52355 data = (__u32) (unsigned long) fix->smem_start;
52356 err |= put_user(data, &fix32->smem_start);
52357diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52358index 130708f..cdac1a9 100644
52359--- a/drivers/video/hyperv_fb.c
52360+++ b/drivers/video/hyperv_fb.c
52361@@ -233,7 +233,7 @@ static uint screen_fb_size;
52362 static inline int synthvid_send(struct hv_device *hdev,
52363 struct synthvid_msg *msg)
52364 {
52365- static atomic64_t request_id = ATOMIC64_INIT(0);
52366+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52367 int ret;
52368
52369 msg->pipe_hdr.type = PIPE_MSG_DATA;
52370@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52371
52372 ret = vmbus_sendpacket(hdev->channel, msg,
52373 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52374- atomic64_inc_return(&request_id),
52375+ atomic64_inc_return_unchecked(&request_id),
52376 VM_PKT_DATA_INBAND, 0);
52377
52378 if (ret)
52379diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52380index 7672d2e..b56437f 100644
52381--- a/drivers/video/i810/i810_accel.c
52382+++ b/drivers/video/i810/i810_accel.c
52383@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52384 }
52385 }
52386 printk("ringbuffer lockup!!!\n");
52387+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52388 i810_report_error(mmio);
52389 par->dev_flags |= LOCKUP;
52390 info->pixmap.scan_align = 1;
52391diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52392index 3c14e43..2630570 100644
52393--- a/drivers/video/logo/logo_linux_clut224.ppm
52394+++ b/drivers/video/logo/logo_linux_clut224.ppm
52395@@ -2,1603 +2,1123 @@ P3
52396 # Standard 224-color Linux logo
52397 80 80
52398 255
52399- 0 0 0 0 0 0 0 0 0 0 0 0
52400- 0 0 0 0 0 0 0 0 0 0 0 0
52401- 0 0 0 0 0 0 0 0 0 0 0 0
52402- 0 0 0 0 0 0 0 0 0 0 0 0
52403- 0 0 0 0 0 0 0 0 0 0 0 0
52404- 0 0 0 0 0 0 0 0 0 0 0 0
52405- 0 0 0 0 0 0 0 0 0 0 0 0
52406- 0 0 0 0 0 0 0 0 0 0 0 0
52407- 0 0 0 0 0 0 0 0 0 0 0 0
52408- 6 6 6 6 6 6 10 10 10 10 10 10
52409- 10 10 10 6 6 6 6 6 6 6 6 6
52410- 0 0 0 0 0 0 0 0 0 0 0 0
52411- 0 0 0 0 0 0 0 0 0 0 0 0
52412- 0 0 0 0 0 0 0 0 0 0 0 0
52413- 0 0 0 0 0 0 0 0 0 0 0 0
52414- 0 0 0 0 0 0 0 0 0 0 0 0
52415- 0 0 0 0 0 0 0 0 0 0 0 0
52416- 0 0 0 0 0 0 0 0 0 0 0 0
52417- 0 0 0 0 0 0 0 0 0 0 0 0
52418- 0 0 0 0 0 0 0 0 0 0 0 0
52419- 0 0 0 0 0 0 0 0 0 0 0 0
52420- 0 0 0 0 0 0 0 0 0 0 0 0
52421- 0 0 0 0 0 0 0 0 0 0 0 0
52422- 0 0 0 0 0 0 0 0 0 0 0 0
52423- 0 0 0 0 0 0 0 0 0 0 0 0
52424- 0 0 0 0 0 0 0 0 0 0 0 0
52425- 0 0 0 0 0 0 0 0 0 0 0 0
52426- 0 0 0 0 0 0 0 0 0 0 0 0
52427- 0 0 0 6 6 6 10 10 10 14 14 14
52428- 22 22 22 26 26 26 30 30 30 34 34 34
52429- 30 30 30 30 30 30 26 26 26 18 18 18
52430- 14 14 14 10 10 10 6 6 6 0 0 0
52431- 0 0 0 0 0 0 0 0 0 0 0 0
52432- 0 0 0 0 0 0 0 0 0 0 0 0
52433- 0 0 0 0 0 0 0 0 0 0 0 0
52434- 0 0 0 0 0 0 0 0 0 0 0 0
52435- 0 0 0 0 0 0 0 0 0 0 0 0
52436- 0 0 0 0 0 0 0 0 0 0 0 0
52437- 0 0 0 0 0 0 0 0 0 0 0 0
52438- 0 0 0 0 0 0 0 0 0 0 0 0
52439- 0 0 0 0 0 0 0 0 0 0 0 0
52440- 0 0 0 0 0 1 0 0 1 0 0 0
52441- 0 0 0 0 0 0 0 0 0 0 0 0
52442- 0 0 0 0 0 0 0 0 0 0 0 0
52443- 0 0 0 0 0 0 0 0 0 0 0 0
52444- 0 0 0 0 0 0 0 0 0 0 0 0
52445- 0 0 0 0 0 0 0 0 0 0 0 0
52446- 0 0 0 0 0 0 0 0 0 0 0 0
52447- 6 6 6 14 14 14 26 26 26 42 42 42
52448- 54 54 54 66 66 66 78 78 78 78 78 78
52449- 78 78 78 74 74 74 66 66 66 54 54 54
52450- 42 42 42 26 26 26 18 18 18 10 10 10
52451- 6 6 6 0 0 0 0 0 0 0 0 0
52452- 0 0 0 0 0 0 0 0 0 0 0 0
52453- 0 0 0 0 0 0 0 0 0 0 0 0
52454- 0 0 0 0 0 0 0 0 0 0 0 0
52455- 0 0 0 0 0 0 0 0 0 0 0 0
52456- 0 0 0 0 0 0 0 0 0 0 0 0
52457- 0 0 0 0 0 0 0 0 0 0 0 0
52458- 0 0 0 0 0 0 0 0 0 0 0 0
52459- 0 0 0 0 0 0 0 0 0 0 0 0
52460- 0 0 1 0 0 0 0 0 0 0 0 0
52461- 0 0 0 0 0 0 0 0 0 0 0 0
52462- 0 0 0 0 0 0 0 0 0 0 0 0
52463- 0 0 0 0 0 0 0 0 0 0 0 0
52464- 0 0 0 0 0 0 0 0 0 0 0 0
52465- 0 0 0 0 0 0 0 0 0 0 0 0
52466- 0 0 0 0 0 0 0 0 0 10 10 10
52467- 22 22 22 42 42 42 66 66 66 86 86 86
52468- 66 66 66 38 38 38 38 38 38 22 22 22
52469- 26 26 26 34 34 34 54 54 54 66 66 66
52470- 86 86 86 70 70 70 46 46 46 26 26 26
52471- 14 14 14 6 6 6 0 0 0 0 0 0
52472- 0 0 0 0 0 0 0 0 0 0 0 0
52473- 0 0 0 0 0 0 0 0 0 0 0 0
52474- 0 0 0 0 0 0 0 0 0 0 0 0
52475- 0 0 0 0 0 0 0 0 0 0 0 0
52476- 0 0 0 0 0 0 0 0 0 0 0 0
52477- 0 0 0 0 0 0 0 0 0 0 0 0
52478- 0 0 0 0 0 0 0 0 0 0 0 0
52479- 0 0 0 0 0 0 0 0 0 0 0 0
52480- 0 0 1 0 0 1 0 0 1 0 0 0
52481- 0 0 0 0 0 0 0 0 0 0 0 0
52482- 0 0 0 0 0 0 0 0 0 0 0 0
52483- 0 0 0 0 0 0 0 0 0 0 0 0
52484- 0 0 0 0 0 0 0 0 0 0 0 0
52485- 0 0 0 0 0 0 0 0 0 0 0 0
52486- 0 0 0 0 0 0 10 10 10 26 26 26
52487- 50 50 50 82 82 82 58 58 58 6 6 6
52488- 2 2 6 2 2 6 2 2 6 2 2 6
52489- 2 2 6 2 2 6 2 2 6 2 2 6
52490- 6 6 6 54 54 54 86 86 86 66 66 66
52491- 38 38 38 18 18 18 6 6 6 0 0 0
52492- 0 0 0 0 0 0 0 0 0 0 0 0
52493- 0 0 0 0 0 0 0 0 0 0 0 0
52494- 0 0 0 0 0 0 0 0 0 0 0 0
52495- 0 0 0 0 0 0 0 0 0 0 0 0
52496- 0 0 0 0 0 0 0 0 0 0 0 0
52497- 0 0 0 0 0 0 0 0 0 0 0 0
52498- 0 0 0 0 0 0 0 0 0 0 0 0
52499- 0 0 0 0 0 0 0 0 0 0 0 0
52500- 0 0 0 0 0 0 0 0 0 0 0 0
52501- 0 0 0 0 0 0 0 0 0 0 0 0
52502- 0 0 0 0 0 0 0 0 0 0 0 0
52503- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 22 22 22 50 50 50
52507- 78 78 78 34 34 34 2 2 6 2 2 6
52508- 2 2 6 2 2 6 2 2 6 2 2 6
52509- 2 2 6 2 2 6 2 2 6 2 2 6
52510- 2 2 6 2 2 6 6 6 6 70 70 70
52511- 78 78 78 46 46 46 22 22 22 6 6 6
52512- 0 0 0 0 0 0 0 0 0 0 0 0
52513- 0 0 0 0 0 0 0 0 0 0 0 0
52514- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
52527- 26 26 26 2 2 6 2 2 6 2 2 6
52528- 2 2 6 2 2 6 2 2 6 2 2 6
52529- 2 2 6 2 2 6 2 2 6 14 14 14
52530- 46 46 46 34 34 34 6 6 6 2 2 6
52531- 42 42 42 78 78 78 42 42 42 18 18 18
52532- 6 6 6 0 0 0 0 0 0 0 0 0
52533- 0 0 0 0 0 0 0 0 0 0 0 0
52534- 0 0 0 0 0 0 0 0 0 0 0 0
52535- 0 0 0 0 0 0 0 0 0 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 1 0 0 0 0 0 1 0 0 0
52541- 0 0 0 0 0 0 0 0 0 0 0 0
52542- 0 0 0 0 0 0 0 0 0 0 0 0
52543- 0 0 0 0 0 0 0 0 0 0 0 0
52544- 0 0 0 0 0 0 0 0 0 0 0 0
52545- 0 0 0 0 0 0 0 0 0 0 0 0
52546- 10 10 10 30 30 30 66 66 66 58 58 58
52547- 2 2 6 2 2 6 2 2 6 2 2 6
52548- 2 2 6 2 2 6 2 2 6 2 2 6
52549- 2 2 6 2 2 6 2 2 6 26 26 26
52550- 86 86 86 101 101 101 46 46 46 10 10 10
52551- 2 2 6 58 58 58 70 70 70 34 34 34
52552- 10 10 10 0 0 0 0 0 0 0 0 0
52553- 0 0 0 0 0 0 0 0 0 0 0 0
52554- 0 0 0 0 0 0 0 0 0 0 0 0
52555- 0 0 0 0 0 0 0 0 0 0 0 0
52556- 0 0 0 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 1 0 0 1 0 0 1 0 0 0
52561- 0 0 0 0 0 0 0 0 0 0 0 0
52562- 0 0 0 0 0 0 0 0 0 0 0 0
52563- 0 0 0 0 0 0 0 0 0 0 0 0
52564- 0 0 0 0 0 0 0 0 0 0 0 0
52565- 0 0 0 0 0 0 0 0 0 0 0 0
52566- 14 14 14 42 42 42 86 86 86 10 10 10
52567- 2 2 6 2 2 6 2 2 6 2 2 6
52568- 2 2 6 2 2 6 2 2 6 2 2 6
52569- 2 2 6 2 2 6 2 2 6 30 30 30
52570- 94 94 94 94 94 94 58 58 58 26 26 26
52571- 2 2 6 6 6 6 78 78 78 54 54 54
52572- 22 22 22 6 6 6 0 0 0 0 0 0
52573- 0 0 0 0 0 0 0 0 0 0 0 0
52574- 0 0 0 0 0 0 0 0 0 0 0 0
52575- 0 0 0 0 0 0 0 0 0 0 0 0
52576- 0 0 0 0 0 0 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 0 0 0 0 0 0 0 6 6 6
52586- 22 22 22 62 62 62 62 62 62 2 2 6
52587- 2 2 6 2 2 6 2 2 6 2 2 6
52588- 2 2 6 2 2 6 2 2 6 2 2 6
52589- 2 2 6 2 2 6 2 2 6 26 26 26
52590- 54 54 54 38 38 38 18 18 18 10 10 10
52591- 2 2 6 2 2 6 34 34 34 82 82 82
52592- 38 38 38 14 14 14 0 0 0 0 0 0
52593- 0 0 0 0 0 0 0 0 0 0 0 0
52594- 0 0 0 0 0 0 0 0 0 0 0 0
52595- 0 0 0 0 0 0 0 0 0 0 0 0
52596- 0 0 0 0 0 0 0 0 0 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 1 0 0 1 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 6 6 6
52606- 30 30 30 78 78 78 30 30 30 2 2 6
52607- 2 2 6 2 2 6 2 2 6 2 2 6
52608- 2 2 6 2 2 6 2 2 6 2 2 6
52609- 2 2 6 2 2 6 2 2 6 10 10 10
52610- 10 10 10 2 2 6 2 2 6 2 2 6
52611- 2 2 6 2 2 6 2 2 6 78 78 78
52612- 50 50 50 18 18 18 6 6 6 0 0 0
52613- 0 0 0 0 0 0 0 0 0 0 0 0
52614- 0 0 0 0 0 0 0 0 0 0 0 0
52615- 0 0 0 0 0 0 0 0 0 0 0 0
52616- 0 0 0 0 0 0 0 0 0 0 0 0
52617- 0 0 0 0 0 0 0 0 0 0 0 0
52618- 0 0 0 0 0 0 0 0 0 0 0 0
52619- 0 0 0 0 0 0 0 0 0 0 0 0
52620- 0 0 1 0 0 0 0 0 0 0 0 0
52621- 0 0 0 0 0 0 0 0 0 0 0 0
52622- 0 0 0 0 0 0 0 0 0 0 0 0
52623- 0 0 0 0 0 0 0 0 0 0 0 0
52624- 0 0 0 0 0 0 0 0 0 0 0 0
52625- 0 0 0 0 0 0 0 0 0 10 10 10
52626- 38 38 38 86 86 86 14 14 14 2 2 6
52627- 2 2 6 2 2 6 2 2 6 2 2 6
52628- 2 2 6 2 2 6 2 2 6 2 2 6
52629- 2 2 6 2 2 6 2 2 6 2 2 6
52630- 2 2 6 2 2 6 2 2 6 2 2 6
52631- 2 2 6 2 2 6 2 2 6 54 54 54
52632- 66 66 66 26 26 26 6 6 6 0 0 0
52633- 0 0 0 0 0 0 0 0 0 0 0 0
52634- 0 0 0 0 0 0 0 0 0 0 0 0
52635- 0 0 0 0 0 0 0 0 0 0 0 0
52636- 0 0 0 0 0 0 0 0 0 0 0 0
52637- 0 0 0 0 0 0 0 0 0 0 0 0
52638- 0 0 0 0 0 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 1 0 0 1 0 0 0
52641- 0 0 0 0 0 0 0 0 0 0 0 0
52642- 0 0 0 0 0 0 0 0 0 0 0 0
52643- 0 0 0 0 0 0 0 0 0 0 0 0
52644- 0 0 0 0 0 0 0 0 0 0 0 0
52645- 0 0 0 0 0 0 0 0 0 14 14 14
52646- 42 42 42 82 82 82 2 2 6 2 2 6
52647- 2 2 6 6 6 6 10 10 10 2 2 6
52648- 2 2 6 2 2 6 2 2 6 2 2 6
52649- 2 2 6 2 2 6 2 2 6 6 6 6
52650- 14 14 14 10 10 10 2 2 6 2 2 6
52651- 2 2 6 2 2 6 2 2 6 18 18 18
52652- 82 82 82 34 34 34 10 10 10 0 0 0
52653- 0 0 0 0 0 0 0 0 0 0 0 0
52654- 0 0 0 0 0 0 0 0 0 0 0 0
52655- 0 0 0 0 0 0 0 0 0 0 0 0
52656- 0 0 0 0 0 0 0 0 0 0 0 0
52657- 0 0 0 0 0 0 0 0 0 0 0 0
52658- 0 0 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 1 0 0 0 0 0 0 0 0 0
52661- 0 0 0 0 0 0 0 0 0 0 0 0
52662- 0 0 0 0 0 0 0 0 0 0 0 0
52663- 0 0 0 0 0 0 0 0 0 0 0 0
52664- 0 0 0 0 0 0 0 0 0 0 0 0
52665- 0 0 0 0 0 0 0 0 0 14 14 14
52666- 46 46 46 86 86 86 2 2 6 2 2 6
52667- 6 6 6 6 6 6 22 22 22 34 34 34
52668- 6 6 6 2 2 6 2 2 6 2 2 6
52669- 2 2 6 2 2 6 18 18 18 34 34 34
52670- 10 10 10 50 50 50 22 22 22 2 2 6
52671- 2 2 6 2 2 6 2 2 6 10 10 10
52672- 86 86 86 42 42 42 14 14 14 0 0 0
52673- 0 0 0 0 0 0 0 0 0 0 0 0
52674- 0 0 0 0 0 0 0 0 0 0 0 0
52675- 0 0 0 0 0 0 0 0 0 0 0 0
52676- 0 0 0 0 0 0 0 0 0 0 0 0
52677- 0 0 0 0 0 0 0 0 0 0 0 0
52678- 0 0 0 0 0 0 0 0 0 0 0 0
52679- 0 0 0 0 0 0 0 0 0 0 0 0
52680- 0 0 1 0 0 1 0 0 1 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 14 14 14
52686- 46 46 46 86 86 86 2 2 6 2 2 6
52687- 38 38 38 116 116 116 94 94 94 22 22 22
52688- 22 22 22 2 2 6 2 2 6 2 2 6
52689- 14 14 14 86 86 86 138 138 138 162 162 162
52690-154 154 154 38 38 38 26 26 26 6 6 6
52691- 2 2 6 2 2 6 2 2 6 2 2 6
52692- 86 86 86 46 46 46 14 14 14 0 0 0
52693- 0 0 0 0 0 0 0 0 0 0 0 0
52694- 0 0 0 0 0 0 0 0 0 0 0 0
52695- 0 0 0 0 0 0 0 0 0 0 0 0
52696- 0 0 0 0 0 0 0 0 0 0 0 0
52697- 0 0 0 0 0 0 0 0 0 0 0 0
52698- 0 0 0 0 0 0 0 0 0 0 0 0
52699- 0 0 0 0 0 0 0 0 0 0 0 0
52700- 0 0 0 0 0 0 0 0 0 0 0 0
52701- 0 0 0 0 0 0 0 0 0 0 0 0
52702- 0 0 0 0 0 0 0 0 0 0 0 0
52703- 0 0 0 0 0 0 0 0 0 0 0 0
52704- 0 0 0 0 0 0 0 0 0 0 0 0
52705- 0 0 0 0 0 0 0 0 0 14 14 14
52706- 46 46 46 86 86 86 2 2 6 14 14 14
52707-134 134 134 198 198 198 195 195 195 116 116 116
52708- 10 10 10 2 2 6 2 2 6 6 6 6
52709-101 98 89 187 187 187 210 210 210 218 218 218
52710-214 214 214 134 134 134 14 14 14 6 6 6
52711- 2 2 6 2 2 6 2 2 6 2 2 6
52712- 86 86 86 50 50 50 18 18 18 6 6 6
52713- 0 0 0 0 0 0 0 0 0 0 0 0
52714- 0 0 0 0 0 0 0 0 0 0 0 0
52715- 0 0 0 0 0 0 0 0 0 0 0 0
52716- 0 0 0 0 0 0 0 0 0 0 0 0
52717- 0 0 0 0 0 0 0 0 0 0 0 0
52718- 0 0 0 0 0 0 0 0 0 0 0 0
52719- 0 0 0 0 0 0 0 0 1 0 0 0
52720- 0 0 1 0 0 1 0 0 1 0 0 0
52721- 0 0 0 0 0 0 0 0 0 0 0 0
52722- 0 0 0 0 0 0 0 0 0 0 0 0
52723- 0 0 0 0 0 0 0 0 0 0 0 0
52724- 0 0 0 0 0 0 0 0 0 0 0 0
52725- 0 0 0 0 0 0 0 0 0 14 14 14
52726- 46 46 46 86 86 86 2 2 6 54 54 54
52727-218 218 218 195 195 195 226 226 226 246 246 246
52728- 58 58 58 2 2 6 2 2 6 30 30 30
52729-210 210 210 253 253 253 174 174 174 123 123 123
52730-221 221 221 234 234 234 74 74 74 2 2 6
52731- 2 2 6 2 2 6 2 2 6 2 2 6
52732- 70 70 70 58 58 58 22 22 22 6 6 6
52733- 0 0 0 0 0 0 0 0 0 0 0 0
52734- 0 0 0 0 0 0 0 0 0 0 0 0
52735- 0 0 0 0 0 0 0 0 0 0 0 0
52736- 0 0 0 0 0 0 0 0 0 0 0 0
52737- 0 0 0 0 0 0 0 0 0 0 0 0
52738- 0 0 0 0 0 0 0 0 0 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 0 0 0 0 14 14 14
52746- 46 46 46 82 82 82 2 2 6 106 106 106
52747-170 170 170 26 26 26 86 86 86 226 226 226
52748-123 123 123 10 10 10 14 14 14 46 46 46
52749-231 231 231 190 190 190 6 6 6 70 70 70
52750- 90 90 90 238 238 238 158 158 158 2 2 6
52751- 2 2 6 2 2 6 2 2 6 2 2 6
52752- 70 70 70 58 58 58 22 22 22 6 6 6
52753- 0 0 0 0 0 0 0 0 0 0 0 0
52754- 0 0 0 0 0 0 0 0 0 0 0 0
52755- 0 0 0 0 0 0 0 0 0 0 0 0
52756- 0 0 0 0 0 0 0 0 0 0 0 0
52757- 0 0 0 0 0 0 0 0 0 0 0 0
52758- 0 0 0 0 0 0 0 0 0 0 0 0
52759- 0 0 0 0 0 0 0 0 1 0 0 0
52760- 0 0 1 0 0 1 0 0 1 0 0 0
52761- 0 0 0 0 0 0 0 0 0 0 0 0
52762- 0 0 0 0 0 0 0 0 0 0 0 0
52763- 0 0 0 0 0 0 0 0 0 0 0 0
52764- 0 0 0 0 0 0 0 0 0 0 0 0
52765- 0 0 0 0 0 0 0 0 0 14 14 14
52766- 42 42 42 86 86 86 6 6 6 116 116 116
52767-106 106 106 6 6 6 70 70 70 149 149 149
52768-128 128 128 18 18 18 38 38 38 54 54 54
52769-221 221 221 106 106 106 2 2 6 14 14 14
52770- 46 46 46 190 190 190 198 198 198 2 2 6
52771- 2 2 6 2 2 6 2 2 6 2 2 6
52772- 74 74 74 62 62 62 22 22 22 6 6 6
52773- 0 0 0 0 0 0 0 0 0 0 0 0
52774- 0 0 0 0 0 0 0 0 0 0 0 0
52775- 0 0 0 0 0 0 0 0 0 0 0 0
52776- 0 0 0 0 0 0 0 0 0 0 0 0
52777- 0 0 0 0 0 0 0 0 0 0 0 0
52778- 0 0 0 0 0 0 0 0 0 0 0 0
52779- 0 0 0 0 0 0 0 0 1 0 0 0
52780- 0 0 1 0 0 0 0 0 1 0 0 0
52781- 0 0 0 0 0 0 0 0 0 0 0 0
52782- 0 0 0 0 0 0 0 0 0 0 0 0
52783- 0 0 0 0 0 0 0 0 0 0 0 0
52784- 0 0 0 0 0 0 0 0 0 0 0 0
52785- 0 0 0 0 0 0 0 0 0 14 14 14
52786- 42 42 42 94 94 94 14 14 14 101 101 101
52787-128 128 128 2 2 6 18 18 18 116 116 116
52788-118 98 46 121 92 8 121 92 8 98 78 10
52789-162 162 162 106 106 106 2 2 6 2 2 6
52790- 2 2 6 195 195 195 195 195 195 6 6 6
52791- 2 2 6 2 2 6 2 2 6 2 2 6
52792- 74 74 74 62 62 62 22 22 22 6 6 6
52793- 0 0 0 0 0 0 0 0 0 0 0 0
52794- 0 0 0 0 0 0 0 0 0 0 0 0
52795- 0 0 0 0 0 0 0 0 0 0 0 0
52796- 0 0 0 0 0 0 0 0 0 0 0 0
52797- 0 0 0 0 0 0 0 0 0 0 0 0
52798- 0 0 0 0 0 0 0 0 0 0 0 0
52799- 0 0 0 0 0 0 0 0 1 0 0 1
52800- 0 0 1 0 0 0 0 0 1 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 10 10 10
52806- 38 38 38 90 90 90 14 14 14 58 58 58
52807-210 210 210 26 26 26 54 38 6 154 114 10
52808-226 170 11 236 186 11 225 175 15 184 144 12
52809-215 174 15 175 146 61 37 26 9 2 2 6
52810- 70 70 70 246 246 246 138 138 138 2 2 6
52811- 2 2 6 2 2 6 2 2 6 2 2 6
52812- 70 70 70 66 66 66 26 26 26 6 6 6
52813- 0 0 0 0 0 0 0 0 0 0 0 0
52814- 0 0 0 0 0 0 0 0 0 0 0 0
52815- 0 0 0 0 0 0 0 0 0 0 0 0
52816- 0 0 0 0 0 0 0 0 0 0 0 0
52817- 0 0 0 0 0 0 0 0 0 0 0 0
52818- 0 0 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 0 0 0 0
52825- 0 0 0 0 0 0 0 0 0 10 10 10
52826- 38 38 38 86 86 86 14 14 14 10 10 10
52827-195 195 195 188 164 115 192 133 9 225 175 15
52828-239 182 13 234 190 10 232 195 16 232 200 30
52829-245 207 45 241 208 19 232 195 16 184 144 12
52830-218 194 134 211 206 186 42 42 42 2 2 6
52831- 2 2 6 2 2 6 2 2 6 2 2 6
52832- 50 50 50 74 74 74 30 30 30 6 6 6
52833- 0 0 0 0 0 0 0 0 0 0 0 0
52834- 0 0 0 0 0 0 0 0 0 0 0 0
52835- 0 0 0 0 0 0 0 0 0 0 0 0
52836- 0 0 0 0 0 0 0 0 0 0 0 0
52837- 0 0 0 0 0 0 0 0 0 0 0 0
52838- 0 0 0 0 0 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 10 10 10
52846- 34 34 34 86 86 86 14 14 14 2 2 6
52847-121 87 25 192 133 9 219 162 10 239 182 13
52848-236 186 11 232 195 16 241 208 19 244 214 54
52849-246 218 60 246 218 38 246 215 20 241 208 19
52850-241 208 19 226 184 13 121 87 25 2 2 6
52851- 2 2 6 2 2 6 2 2 6 2 2 6
52852- 50 50 50 82 82 82 34 34 34 10 10 10
52853- 0 0 0 0 0 0 0 0 0 0 0 0
52854- 0 0 0 0 0 0 0 0 0 0 0 0
52855- 0 0 0 0 0 0 0 0 0 0 0 0
52856- 0 0 0 0 0 0 0 0 0 0 0 0
52857- 0 0 0 0 0 0 0 0 0 0 0 0
52858- 0 0 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 0 0 0 0
52865- 0 0 0 0 0 0 0 0 0 10 10 10
52866- 34 34 34 82 82 82 30 30 30 61 42 6
52867-180 123 7 206 145 10 230 174 11 239 182 13
52868-234 190 10 238 202 15 241 208 19 246 218 74
52869-246 218 38 246 215 20 246 215 20 246 215 20
52870-226 184 13 215 174 15 184 144 12 6 6 6
52871- 2 2 6 2 2 6 2 2 6 2 2 6
52872- 26 26 26 94 94 94 42 42 42 14 14 14
52873- 0 0 0 0 0 0 0 0 0 0 0 0
52874- 0 0 0 0 0 0 0 0 0 0 0 0
52875- 0 0 0 0 0 0 0 0 0 0 0 0
52876- 0 0 0 0 0 0 0 0 0 0 0 0
52877- 0 0 0 0 0 0 0 0 0 0 0 0
52878- 0 0 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 0 0 0 0
52885- 0 0 0 0 0 0 0 0 0 10 10 10
52886- 30 30 30 78 78 78 50 50 50 104 69 6
52887-192 133 9 216 158 10 236 178 12 236 186 11
52888-232 195 16 241 208 19 244 214 54 245 215 43
52889-246 215 20 246 215 20 241 208 19 198 155 10
52890-200 144 11 216 158 10 156 118 10 2 2 6
52891- 2 2 6 2 2 6 2 2 6 2 2 6
52892- 6 6 6 90 90 90 54 54 54 18 18 18
52893- 6 6 6 0 0 0 0 0 0 0 0 0
52894- 0 0 0 0 0 0 0 0 0 0 0 0
52895- 0 0 0 0 0 0 0 0 0 0 0 0
52896- 0 0 0 0 0 0 0 0 0 0 0 0
52897- 0 0 0 0 0 0 0 0 0 0 0 0
52898- 0 0 0 0 0 0 0 0 0 0 0 0
52899- 0 0 0 0 0 0 0 0 0 0 0 0
52900- 0 0 0 0 0 0 0 0 0 0 0 0
52901- 0 0 0 0 0 0 0 0 0 0 0 0
52902- 0 0 0 0 0 0 0 0 0 0 0 0
52903- 0 0 0 0 0 0 0 0 0 0 0 0
52904- 0 0 0 0 0 0 0 0 0 0 0 0
52905- 0 0 0 0 0 0 0 0 0 10 10 10
52906- 30 30 30 78 78 78 46 46 46 22 22 22
52907-137 92 6 210 162 10 239 182 13 238 190 10
52908-238 202 15 241 208 19 246 215 20 246 215 20
52909-241 208 19 203 166 17 185 133 11 210 150 10
52910-216 158 10 210 150 10 102 78 10 2 2 6
52911- 6 6 6 54 54 54 14 14 14 2 2 6
52912- 2 2 6 62 62 62 74 74 74 30 30 30
52913- 10 10 10 0 0 0 0 0 0 0 0 0
52914- 0 0 0 0 0 0 0 0 0 0 0 0
52915- 0 0 0 0 0 0 0 0 0 0 0 0
52916- 0 0 0 0 0 0 0 0 0 0 0 0
52917- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10
52926- 34 34 34 78 78 78 50 50 50 6 6 6
52927- 94 70 30 139 102 15 190 146 13 226 184 13
52928-232 200 30 232 195 16 215 174 15 190 146 13
52929-168 122 10 192 133 9 210 150 10 213 154 11
52930-202 150 34 182 157 106 101 98 89 2 2 6
52931- 2 2 6 78 78 78 116 116 116 58 58 58
52932- 2 2 6 22 22 22 90 90 90 46 46 46
52933- 18 18 18 6 6 6 0 0 0 0 0 0
52934- 0 0 0 0 0 0 0 0 0 0 0 0
52935- 0 0 0 0 0 0 0 0 0 0 0 0
52936- 0 0 0 0 0 0 0 0 0 0 0 0
52937- 0 0 0 0 0 0 0 0 0 0 0 0
52938- 0 0 0 0 0 0 0 0 0 0 0 0
52939- 0 0 0 0 0 0 0 0 0 0 0 0
52940- 0 0 0 0 0 0 0 0 0 0 0 0
52941- 0 0 0 0 0 0 0 0 0 0 0 0
52942- 0 0 0 0 0 0 0 0 0 0 0 0
52943- 0 0 0 0 0 0 0 0 0 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 10 10 10
52946- 38 38 38 86 86 86 50 50 50 6 6 6
52947-128 128 128 174 154 114 156 107 11 168 122 10
52948-198 155 10 184 144 12 197 138 11 200 144 11
52949-206 145 10 206 145 10 197 138 11 188 164 115
52950-195 195 195 198 198 198 174 174 174 14 14 14
52951- 2 2 6 22 22 22 116 116 116 116 116 116
52952- 22 22 22 2 2 6 74 74 74 70 70 70
52953- 30 30 30 10 10 10 0 0 0 0 0 0
52954- 0 0 0 0 0 0 0 0 0 0 0 0
52955- 0 0 0 0 0 0 0 0 0 0 0 0
52956- 0 0 0 0 0 0 0 0 0 0 0 0
52957- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6 18 18 18
52966- 50 50 50 101 101 101 26 26 26 10 10 10
52967-138 138 138 190 190 190 174 154 114 156 107 11
52968-197 138 11 200 144 11 197 138 11 192 133 9
52969-180 123 7 190 142 34 190 178 144 187 187 187
52970-202 202 202 221 221 221 214 214 214 66 66 66
52971- 2 2 6 2 2 6 50 50 50 62 62 62
52972- 6 6 6 2 2 6 10 10 10 90 90 90
52973- 50 50 50 18 18 18 6 6 6 0 0 0
52974- 0 0 0 0 0 0 0 0 0 0 0 0
52975- 0 0 0 0 0 0 0 0 0 0 0 0
52976- 0 0 0 0 0 0 0 0 0 0 0 0
52977- 0 0 0 0 0 0 0 0 0 0 0 0
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 10 10 10 34 34 34
52986- 74 74 74 74 74 74 2 2 6 6 6 6
52987-144 144 144 198 198 198 190 190 190 178 166 146
52988-154 121 60 156 107 11 156 107 11 168 124 44
52989-174 154 114 187 187 187 190 190 190 210 210 210
52990-246 246 246 253 253 253 253 253 253 182 182 182
52991- 6 6 6 2 2 6 2 2 6 2 2 6
52992- 2 2 6 2 2 6 2 2 6 62 62 62
52993- 74 74 74 34 34 34 14 14 14 0 0 0
52994- 0 0 0 0 0 0 0 0 0 0 0 0
52995- 0 0 0 0 0 0 0 0 0 0 0 0
52996- 0 0 0 0 0 0 0 0 0 0 0 0
52997- 0 0 0 0 0 0 0 0 0 0 0 0
52998- 0 0 0 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 10 10 10 22 22 22 54 54 54
53006- 94 94 94 18 18 18 2 2 6 46 46 46
53007-234 234 234 221 221 221 190 190 190 190 190 190
53008-190 190 190 187 187 187 187 187 187 190 190 190
53009-190 190 190 195 195 195 214 214 214 242 242 242
53010-253 253 253 253 253 253 253 253 253 253 253 253
53011- 82 82 82 2 2 6 2 2 6 2 2 6
53012- 2 2 6 2 2 6 2 2 6 14 14 14
53013- 86 86 86 54 54 54 22 22 22 6 6 6
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 0 0 0
53017- 0 0 0 0 0 0 0 0 0 0 0 0
53018- 0 0 0 0 0 0 0 0 0 0 0 0
53019- 0 0 0 0 0 0 0 0 0 0 0 0
53020- 0 0 0 0 0 0 0 0 0 0 0 0
53021- 0 0 0 0 0 0 0 0 0 0 0 0
53022- 0 0 0 0 0 0 0 0 0 0 0 0
53023- 0 0 0 0 0 0 0 0 0 0 0 0
53024- 0 0 0 0 0 0 0 0 0 0 0 0
53025- 6 6 6 18 18 18 46 46 46 90 90 90
53026- 46 46 46 18 18 18 6 6 6 182 182 182
53027-253 253 253 246 246 246 206 206 206 190 190 190
53028-190 190 190 190 190 190 190 190 190 190 190 190
53029-206 206 206 231 231 231 250 250 250 253 253 253
53030-253 253 253 253 253 253 253 253 253 253 253 253
53031-202 202 202 14 14 14 2 2 6 2 2 6
53032- 2 2 6 2 2 6 2 2 6 2 2 6
53033- 42 42 42 86 86 86 42 42 42 18 18 18
53034- 6 6 6 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 0 0 0 0 0 0 0 0 0
53037- 0 0 0 0 0 0 0 0 0 0 0 0
53038- 0 0 0 0 0 0 0 0 0 0 0 0
53039- 0 0 0 0 0 0 0 0 0 0 0 0
53040- 0 0 0 0 0 0 0 0 0 0 0 0
53041- 0 0 0 0 0 0 0 0 0 0 0 0
53042- 0 0 0 0 0 0 0 0 0 0 0 0
53043- 0 0 0 0 0 0 0 0 0 0 0 0
53044- 0 0 0 0 0 0 0 0 0 6 6 6
53045- 14 14 14 38 38 38 74 74 74 66 66 66
53046- 2 2 6 6 6 6 90 90 90 250 250 250
53047-253 253 253 253 253 253 238 238 238 198 198 198
53048-190 190 190 190 190 190 195 195 195 221 221 221
53049-246 246 246 253 253 253 253 253 253 253 253 253
53050-253 253 253 253 253 253 253 253 253 253 253 253
53051-253 253 253 82 82 82 2 2 6 2 2 6
53052- 2 2 6 2 2 6 2 2 6 2 2 6
53053- 2 2 6 78 78 78 70 70 70 34 34 34
53054- 14 14 14 6 6 6 0 0 0 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 0 0 0 0 0 0 0 0 0 0 0 0
53057- 0 0 0 0 0 0 0 0 0 0 0 0
53058- 0 0 0 0 0 0 0 0 0 0 0 0
53059- 0 0 0 0 0 0 0 0 0 0 0 0
53060- 0 0 0 0 0 0 0 0 0 0 0 0
53061- 0 0 0 0 0 0 0 0 0 0 0 0
53062- 0 0 0 0 0 0 0 0 0 0 0 0
53063- 0 0 0 0 0 0 0 0 0 0 0 0
53064- 0 0 0 0 0 0 0 0 0 14 14 14
53065- 34 34 34 66 66 66 78 78 78 6 6 6
53066- 2 2 6 18 18 18 218 218 218 253 253 253
53067-253 253 253 253 253 253 253 253 253 246 246 246
53068-226 226 226 231 231 231 246 246 246 253 253 253
53069-253 253 253 253 253 253 253 253 253 253 253 253
53070-253 253 253 253 253 253 253 253 253 253 253 253
53071-253 253 253 178 178 178 2 2 6 2 2 6
53072- 2 2 6 2 2 6 2 2 6 2 2 6
53073- 2 2 6 18 18 18 90 90 90 62 62 62
53074- 30 30 30 10 10 10 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 0 0 0 0 0 0 0 0 0
53077- 0 0 0 0 0 0 0 0 0 0 0 0
53078- 0 0 0 0 0 0 0 0 0 0 0 0
53079- 0 0 0 0 0 0 0 0 0 0 0 0
53080- 0 0 0 0 0 0 0 0 0 0 0 0
53081- 0 0 0 0 0 0 0 0 0 0 0 0
53082- 0 0 0 0 0 0 0 0 0 0 0 0
53083- 0 0 0 0 0 0 0 0 0 0 0 0
53084- 0 0 0 0 0 0 10 10 10 26 26 26
53085- 58 58 58 90 90 90 18 18 18 2 2 6
53086- 2 2 6 110 110 110 253 253 253 253 253 253
53087-253 253 253 253 253 253 253 253 253 253 253 253
53088-250 250 250 253 253 253 253 253 253 253 253 253
53089-253 253 253 253 253 253 253 253 253 253 253 253
53090-253 253 253 253 253 253 253 253 253 253 253 253
53091-253 253 253 231 231 231 18 18 18 2 2 6
53092- 2 2 6 2 2 6 2 2 6 2 2 6
53093- 2 2 6 2 2 6 18 18 18 94 94 94
53094- 54 54 54 26 26 26 10 10 10 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 0 0 0 0 0 0 0 0 0 0 0 0
53097- 0 0 0 0 0 0 0 0 0 0 0 0
53098- 0 0 0 0 0 0 0 0 0 0 0 0
53099- 0 0 0 0 0 0 0 0 0 0 0 0
53100- 0 0 0 0 0 0 0 0 0 0 0 0
53101- 0 0 0 0 0 0 0 0 0 0 0 0
53102- 0 0 0 0 0 0 0 0 0 0 0 0
53103- 0 0 0 0 0 0 0 0 0 0 0 0
53104- 0 0 0 6 6 6 22 22 22 50 50 50
53105- 90 90 90 26 26 26 2 2 6 2 2 6
53106- 14 14 14 195 195 195 250 250 250 253 253 253
53107-253 253 253 253 253 253 253 253 253 253 253 253
53108-253 253 253 253 253 253 253 253 253 253 253 253
53109-253 253 253 253 253 253 253 253 253 253 253 253
53110-253 253 253 253 253 253 253 253 253 253 253 253
53111-250 250 250 242 242 242 54 54 54 2 2 6
53112- 2 2 6 2 2 6 2 2 6 2 2 6
53113- 2 2 6 2 2 6 2 2 6 38 38 38
53114- 86 86 86 50 50 50 22 22 22 6 6 6
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 0 0 0 0 0 0 0 0 0 0 0 0
53117- 0 0 0 0 0 0 0 0 0 0 0 0
53118- 0 0 0 0 0 0 0 0 0 0 0 0
53119- 0 0 0 0 0 0 0 0 0 0 0 0
53120- 0 0 0 0 0 0 0 0 0 0 0 0
53121- 0 0 0 0 0 0 0 0 0 0 0 0
53122- 0 0 0 0 0 0 0 0 0 0 0 0
53123- 0 0 0 0 0 0 0 0 0 0 0 0
53124- 6 6 6 14 14 14 38 38 38 82 82 82
53125- 34 34 34 2 2 6 2 2 6 2 2 6
53126- 42 42 42 195 195 195 246 246 246 253 253 253
53127-253 253 253 253 253 253 253 253 253 250 250 250
53128-242 242 242 242 242 242 250 250 250 253 253 253
53129-253 253 253 253 253 253 253 253 253 253 253 253
53130-253 253 253 250 250 250 246 246 246 238 238 238
53131-226 226 226 231 231 231 101 101 101 6 6 6
53132- 2 2 6 2 2 6 2 2 6 2 2 6
53133- 2 2 6 2 2 6 2 2 6 2 2 6
53134- 38 38 38 82 82 82 42 42 42 14 14 14
53135- 6 6 6 0 0 0 0 0 0 0 0 0
53136- 0 0 0 0 0 0 0 0 0 0 0 0
53137- 0 0 0 0 0 0 0 0 0 0 0 0
53138- 0 0 0 0 0 0 0 0 0 0 0 0
53139- 0 0 0 0 0 0 0 0 0 0 0 0
53140- 0 0 0 0 0 0 0 0 0 0 0 0
53141- 0 0 0 0 0 0 0 0 0 0 0 0
53142- 0 0 0 0 0 0 0 0 0 0 0 0
53143- 0 0 0 0 0 0 0 0 0 0 0 0
53144- 10 10 10 26 26 26 62 62 62 66 66 66
53145- 2 2 6 2 2 6 2 2 6 6 6 6
53146- 70 70 70 170 170 170 206 206 206 234 234 234
53147-246 246 246 250 250 250 250 250 250 238 238 238
53148-226 226 226 231 231 231 238 238 238 250 250 250
53149-250 250 250 250 250 250 246 246 246 231 231 231
53150-214 214 214 206 206 206 202 202 202 202 202 202
53151-198 198 198 202 202 202 182 182 182 18 18 18
53152- 2 2 6 2 2 6 2 2 6 2 2 6
53153- 2 2 6 2 2 6 2 2 6 2 2 6
53154- 2 2 6 62 62 62 66 66 66 30 30 30
53155- 10 10 10 0 0 0 0 0 0 0 0 0
53156- 0 0 0 0 0 0 0 0 0 0 0 0
53157- 0 0 0 0 0 0 0 0 0 0 0 0
53158- 0 0 0 0 0 0 0 0 0 0 0 0
53159- 0 0 0 0 0 0 0 0 0 0 0 0
53160- 0 0 0 0 0 0 0 0 0 0 0 0
53161- 0 0 0 0 0 0 0 0 0 0 0 0
53162- 0 0 0 0 0 0 0 0 0 0 0 0
53163- 0 0 0 0 0 0 0 0 0 0 0 0
53164- 14 14 14 42 42 42 82 82 82 18 18 18
53165- 2 2 6 2 2 6 2 2 6 10 10 10
53166- 94 94 94 182 182 182 218 218 218 242 242 242
53167-250 250 250 253 253 253 253 253 253 250 250 250
53168-234 234 234 253 253 253 253 253 253 253 253 253
53169-253 253 253 253 253 253 253 253 253 246 246 246
53170-238 238 238 226 226 226 210 210 210 202 202 202
53171-195 195 195 195 195 195 210 210 210 158 158 158
53172- 6 6 6 14 14 14 50 50 50 14 14 14
53173- 2 2 6 2 2 6 2 2 6 2 2 6
53174- 2 2 6 6 6 6 86 86 86 46 46 46
53175- 18 18 18 6 6 6 0 0 0 0 0 0
53176- 0 0 0 0 0 0 0 0 0 0 0 0
53177- 0 0 0 0 0 0 0 0 0 0 0 0
53178- 0 0 0 0 0 0 0 0 0 0 0 0
53179- 0 0 0 0 0 0 0 0 0 0 0 0
53180- 0 0 0 0 0 0 0 0 0 0 0 0
53181- 0 0 0 0 0 0 0 0 0 0 0 0
53182- 0 0 0 0 0 0 0 0 0 0 0 0
53183- 0 0 0 0 0 0 0 0 0 6 6 6
53184- 22 22 22 54 54 54 70 70 70 2 2 6
53185- 2 2 6 10 10 10 2 2 6 22 22 22
53186-166 166 166 231 231 231 250 250 250 253 253 253
53187-253 253 253 253 253 253 253 253 253 250 250 250
53188-242 242 242 253 253 253 253 253 253 253 253 253
53189-253 253 253 253 253 253 253 253 253 253 253 253
53190-253 253 253 253 253 253 253 253 253 246 246 246
53191-231 231 231 206 206 206 198 198 198 226 226 226
53192- 94 94 94 2 2 6 6 6 6 38 38 38
53193- 30 30 30 2 2 6 2 2 6 2 2 6
53194- 2 2 6 2 2 6 62 62 62 66 66 66
53195- 26 26 26 10 10 10 0 0 0 0 0 0
53196- 0 0 0 0 0 0 0 0 0 0 0 0
53197- 0 0 0 0 0 0 0 0 0 0 0 0
53198- 0 0 0 0 0 0 0 0 0 0 0 0
53199- 0 0 0 0 0 0 0 0 0 0 0 0
53200- 0 0 0 0 0 0 0 0 0 0 0 0
53201- 0 0 0 0 0 0 0 0 0 0 0 0
53202- 0 0 0 0 0 0 0 0 0 0 0 0
53203- 0 0 0 0 0 0 0 0 0 10 10 10
53204- 30 30 30 74 74 74 50 50 50 2 2 6
53205- 26 26 26 26 26 26 2 2 6 106 106 106
53206-238 238 238 253 253 253 253 253 253 253 253 253
53207-253 253 253 253 253 253 253 253 253 253 253 253
53208-253 253 253 253 253 253 253 253 253 253 253 253
53209-253 253 253 253 253 253 253 253 253 253 253 253
53210-253 253 253 253 253 253 253 253 253 253 253 253
53211-253 253 253 246 246 246 218 218 218 202 202 202
53212-210 210 210 14 14 14 2 2 6 2 2 6
53213- 30 30 30 22 22 22 2 2 6 2 2 6
53214- 2 2 6 2 2 6 18 18 18 86 86 86
53215- 42 42 42 14 14 14 0 0 0 0 0 0
53216- 0 0 0 0 0 0 0 0 0 0 0 0
53217- 0 0 0 0 0 0 0 0 0 0 0 0
53218- 0 0 0 0 0 0 0 0 0 0 0 0
53219- 0 0 0 0 0 0 0 0 0 0 0 0
53220- 0 0 0 0 0 0 0 0 0 0 0 0
53221- 0 0 0 0 0 0 0 0 0 0 0 0
53222- 0 0 0 0 0 0 0 0 0 0 0 0
53223- 0 0 0 0 0 0 0 0 0 14 14 14
53224- 42 42 42 90 90 90 22 22 22 2 2 6
53225- 42 42 42 2 2 6 18 18 18 218 218 218
53226-253 253 253 253 253 253 253 253 253 253 253 253
53227-253 253 253 253 253 253 253 253 253 253 253 253
53228-253 253 253 253 253 253 253 253 253 253 253 253
53229-253 253 253 253 253 253 253 253 253 253 253 253
53230-253 253 253 253 253 253 253 253 253 253 253 253
53231-253 253 253 253 253 253 250 250 250 221 221 221
53232-218 218 218 101 101 101 2 2 6 14 14 14
53233- 18 18 18 38 38 38 10 10 10 2 2 6
53234- 2 2 6 2 2 6 2 2 6 78 78 78
53235- 58 58 58 22 22 22 6 6 6 0 0 0
53236- 0 0 0 0 0 0 0 0 0 0 0 0
53237- 0 0 0 0 0 0 0 0 0 0 0 0
53238- 0 0 0 0 0 0 0 0 0 0 0 0
53239- 0 0 0 0 0 0 0 0 0 0 0 0
53240- 0 0 0 0 0 0 0 0 0 0 0 0
53241- 0 0 0 0 0 0 0 0 0 0 0 0
53242- 0 0 0 0 0 0 0 0 0 0 0 0
53243- 0 0 0 0 0 0 6 6 6 18 18 18
53244- 54 54 54 82 82 82 2 2 6 26 26 26
53245- 22 22 22 2 2 6 123 123 123 253 253 253
53246-253 253 253 253 253 253 253 253 253 253 253 253
53247-253 253 253 253 253 253 253 253 253 253 253 253
53248-253 253 253 253 253 253 253 253 253 253 253 253
53249-253 253 253 253 253 253 253 253 253 253 253 253
53250-253 253 253 253 253 253 253 253 253 253 253 253
53251-253 253 253 253 253 253 253 253 253 250 250 250
53252-238 238 238 198 198 198 6 6 6 38 38 38
53253- 58 58 58 26 26 26 38 38 38 2 2 6
53254- 2 2 6 2 2 6 2 2 6 46 46 46
53255- 78 78 78 30 30 30 10 10 10 0 0 0
53256- 0 0 0 0 0 0 0 0 0 0 0 0
53257- 0 0 0 0 0 0 0 0 0 0 0 0
53258- 0 0 0 0 0 0 0 0 0 0 0 0
53259- 0 0 0 0 0 0 0 0 0 0 0 0
53260- 0 0 0 0 0 0 0 0 0 0 0 0
53261- 0 0 0 0 0 0 0 0 0 0 0 0
53262- 0 0 0 0 0 0 0 0 0 0 0 0
53263- 0 0 0 0 0 0 10 10 10 30 30 30
53264- 74 74 74 58 58 58 2 2 6 42 42 42
53265- 2 2 6 22 22 22 231 231 231 253 253 253
53266-253 253 253 253 253 253 253 253 253 253 253 253
53267-253 253 253 253 253 253 253 253 253 250 250 250
53268-253 253 253 253 253 253 253 253 253 253 253 253
53269-253 253 253 253 253 253 253 253 253 253 253 253
53270-253 253 253 253 253 253 253 253 253 253 253 253
53271-253 253 253 253 253 253 253 253 253 253 253 253
53272-253 253 253 246 246 246 46 46 46 38 38 38
53273- 42 42 42 14 14 14 38 38 38 14 14 14
53274- 2 2 6 2 2 6 2 2 6 6 6 6
53275- 86 86 86 46 46 46 14 14 14 0 0 0
53276- 0 0 0 0 0 0 0 0 0 0 0 0
53277- 0 0 0 0 0 0 0 0 0 0 0 0
53278- 0 0 0 0 0 0 0 0 0 0 0 0
53279- 0 0 0 0 0 0 0 0 0 0 0 0
53280- 0 0 0 0 0 0 0 0 0 0 0 0
53281- 0 0 0 0 0 0 0 0 0 0 0 0
53282- 0 0 0 0 0 0 0 0 0 0 0 0
53283- 0 0 0 6 6 6 14 14 14 42 42 42
53284- 90 90 90 18 18 18 18 18 18 26 26 26
53285- 2 2 6 116 116 116 253 253 253 253 253 253
53286-253 253 253 253 253 253 253 253 253 253 253 253
53287-253 253 253 253 253 253 250 250 250 238 238 238
53288-253 253 253 253 253 253 253 253 253 253 253 253
53289-253 253 253 253 253 253 253 253 253 253 253 253
53290-253 253 253 253 253 253 253 253 253 253 253 253
53291-253 253 253 253 253 253 253 253 253 253 253 253
53292-253 253 253 253 253 253 94 94 94 6 6 6
53293- 2 2 6 2 2 6 10 10 10 34 34 34
53294- 2 2 6 2 2 6 2 2 6 2 2 6
53295- 74 74 74 58 58 58 22 22 22 6 6 6
53296- 0 0 0 0 0 0 0 0 0 0 0 0
53297- 0 0 0 0 0 0 0 0 0 0 0 0
53298- 0 0 0 0 0 0 0 0 0 0 0 0
53299- 0 0 0 0 0 0 0 0 0 0 0 0
53300- 0 0 0 0 0 0 0 0 0 0 0 0
53301- 0 0 0 0 0 0 0 0 0 0 0 0
53302- 0 0 0 0 0 0 0 0 0 0 0 0
53303- 0 0 0 10 10 10 26 26 26 66 66 66
53304- 82 82 82 2 2 6 38 38 38 6 6 6
53305- 14 14 14 210 210 210 253 253 253 253 253 253
53306-253 253 253 253 253 253 253 253 253 253 253 253
53307-253 253 253 253 253 253 246 246 246 242 242 242
53308-253 253 253 253 253 253 253 253 253 253 253 253
53309-253 253 253 253 253 253 253 253 253 253 253 253
53310-253 253 253 253 253 253 253 253 253 253 253 253
53311-253 253 253 253 253 253 253 253 253 253 253 253
53312-253 253 253 253 253 253 144 144 144 2 2 6
53313- 2 2 6 2 2 6 2 2 6 46 46 46
53314- 2 2 6 2 2 6 2 2 6 2 2 6
53315- 42 42 42 74 74 74 30 30 30 10 10 10
53316- 0 0 0 0 0 0 0 0 0 0 0 0
53317- 0 0 0 0 0 0 0 0 0 0 0 0
53318- 0 0 0 0 0 0 0 0 0 0 0 0
53319- 0 0 0 0 0 0 0 0 0 0 0 0
53320- 0 0 0 0 0 0 0 0 0 0 0 0
53321- 0 0 0 0 0 0 0 0 0 0 0 0
53322- 0 0 0 0 0 0 0 0 0 0 0 0
53323- 6 6 6 14 14 14 42 42 42 90 90 90
53324- 26 26 26 6 6 6 42 42 42 2 2 6
53325- 74 74 74 250 250 250 253 253 253 253 253 253
53326-253 253 253 253 253 253 253 253 253 253 253 253
53327-253 253 253 253 253 253 242 242 242 242 242 242
53328-253 253 253 253 253 253 253 253 253 253 253 253
53329-253 253 253 253 253 253 253 253 253 253 253 253
53330-253 253 253 253 253 253 253 253 253 253 253 253
53331-253 253 253 253 253 253 253 253 253 253 253 253
53332-253 253 253 253 253 253 182 182 182 2 2 6
53333- 2 2 6 2 2 6 2 2 6 46 46 46
53334- 2 2 6 2 2 6 2 2 6 2 2 6
53335- 10 10 10 86 86 86 38 38 38 10 10 10
53336- 0 0 0 0 0 0 0 0 0 0 0 0
53337- 0 0 0 0 0 0 0 0 0 0 0 0
53338- 0 0 0 0 0 0 0 0 0 0 0 0
53339- 0 0 0 0 0 0 0 0 0 0 0 0
53340- 0 0 0 0 0 0 0 0 0 0 0 0
53341- 0 0 0 0 0 0 0 0 0 0 0 0
53342- 0 0 0 0 0 0 0 0 0 0 0 0
53343- 10 10 10 26 26 26 66 66 66 82 82 82
53344- 2 2 6 22 22 22 18 18 18 2 2 6
53345-149 149 149 253 253 253 253 253 253 253 253 253
53346-253 253 253 253 253 253 253 253 253 253 253 253
53347-253 253 253 253 253 253 234 234 234 242 242 242
53348-253 253 253 253 253 253 253 253 253 253 253 253
53349-253 253 253 253 253 253 253 253 253 253 253 253
53350-253 253 253 253 253 253 253 253 253 253 253 253
53351-253 253 253 253 253 253 253 253 253 253 253 253
53352-253 253 253 253 253 253 206 206 206 2 2 6
53353- 2 2 6 2 2 6 2 2 6 38 38 38
53354- 2 2 6 2 2 6 2 2 6 2 2 6
53355- 6 6 6 86 86 86 46 46 46 14 14 14
53356- 0 0 0 0 0 0 0 0 0 0 0 0
53357- 0 0 0 0 0 0 0 0 0 0 0 0
53358- 0 0 0 0 0 0 0 0 0 0 0 0
53359- 0 0 0 0 0 0 0 0 0 0 0 0
53360- 0 0 0 0 0 0 0 0 0 0 0 0
53361- 0 0 0 0 0 0 0 0 0 0 0 0
53362- 0 0 0 0 0 0 0 0 0 6 6 6
53363- 18 18 18 46 46 46 86 86 86 18 18 18
53364- 2 2 6 34 34 34 10 10 10 6 6 6
53365-210 210 210 253 253 253 253 253 253 253 253 253
53366-253 253 253 253 253 253 253 253 253 253 253 253
53367-253 253 253 253 253 253 234 234 234 242 242 242
53368-253 253 253 253 253 253 253 253 253 253 253 253
53369-253 253 253 253 253 253 253 253 253 253 253 253
53370-253 253 253 253 253 253 253 253 253 253 253 253
53371-253 253 253 253 253 253 253 253 253 253 253 253
53372-253 253 253 253 253 253 221 221 221 6 6 6
53373- 2 2 6 2 2 6 6 6 6 30 30 30
53374- 2 2 6 2 2 6 2 2 6 2 2 6
53375- 2 2 6 82 82 82 54 54 54 18 18 18
53376- 6 6 6 0 0 0 0 0 0 0 0 0
53377- 0 0 0 0 0 0 0 0 0 0 0 0
53378- 0 0 0 0 0 0 0 0 0 0 0 0
53379- 0 0 0 0 0 0 0 0 0 0 0 0
53380- 0 0 0 0 0 0 0 0 0 0 0 0
53381- 0 0 0 0 0 0 0 0 0 0 0 0
53382- 0 0 0 0 0 0 0 0 0 10 10 10
53383- 26 26 26 66 66 66 62 62 62 2 2 6
53384- 2 2 6 38 38 38 10 10 10 26 26 26
53385-238 238 238 253 253 253 253 253 253 253 253 253
53386-253 253 253 253 253 253 253 253 253 253 253 253
53387-253 253 253 253 253 253 231 231 231 238 238 238
53388-253 253 253 253 253 253 253 253 253 253 253 253
53389-253 253 253 253 253 253 253 253 253 253 253 253
53390-253 253 253 253 253 253 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 231 231 231 6 6 6
53393- 2 2 6 2 2 6 10 10 10 30 30 30
53394- 2 2 6 2 2 6 2 2 6 2 2 6
53395- 2 2 6 66 66 66 58 58 58 22 22 22
53396- 6 6 6 0 0 0 0 0 0 0 0 0
53397- 0 0 0 0 0 0 0 0 0 0 0 0
53398- 0 0 0 0 0 0 0 0 0 0 0 0
53399- 0 0 0 0 0 0 0 0 0 0 0 0
53400- 0 0 0 0 0 0 0 0 0 0 0 0
53401- 0 0 0 0 0 0 0 0 0 0 0 0
53402- 0 0 0 0 0 0 0 0 0 10 10 10
53403- 38 38 38 78 78 78 6 6 6 2 2 6
53404- 2 2 6 46 46 46 14 14 14 42 42 42
53405-246 246 246 253 253 253 253 253 253 253 253 253
53406-253 253 253 253 253 253 253 253 253 253 253 253
53407-253 253 253 253 253 253 231 231 231 242 242 242
53408-253 253 253 253 253 253 253 253 253 253 253 253
53409-253 253 253 253 253 253 253 253 253 253 253 253
53410-253 253 253 253 253 253 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 234 234 234 10 10 10
53413- 2 2 6 2 2 6 22 22 22 14 14 14
53414- 2 2 6 2 2 6 2 2 6 2 2 6
53415- 2 2 6 66 66 66 62 62 62 22 22 22
53416- 6 6 6 0 0 0 0 0 0 0 0 0
53417- 0 0 0 0 0 0 0 0 0 0 0 0
53418- 0 0 0 0 0 0 0 0 0 0 0 0
53419- 0 0 0 0 0 0 0 0 0 0 0 0
53420- 0 0 0 0 0 0 0 0 0 0 0 0
53421- 0 0 0 0 0 0 0 0 0 0 0 0
53422- 0 0 0 0 0 0 6 6 6 18 18 18
53423- 50 50 50 74 74 74 2 2 6 2 2 6
53424- 14 14 14 70 70 70 34 34 34 62 62 62
53425-250 250 250 253 253 253 253 253 253 253 253 253
53426-253 253 253 253 253 253 253 253 253 253 253 253
53427-253 253 253 253 253 253 231 231 231 246 246 246
53428-253 253 253 253 253 253 253 253 253 253 253 253
53429-253 253 253 253 253 253 253 253 253 253 253 253
53430-253 253 253 253 253 253 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 234 234 234 14 14 14
53433- 2 2 6 2 2 6 30 30 30 2 2 6
53434- 2 2 6 2 2 6 2 2 6 2 2 6
53435- 2 2 6 66 66 66 62 62 62 22 22 22
53436- 6 6 6 0 0 0 0 0 0 0 0 0
53437- 0 0 0 0 0 0 0 0 0 0 0 0
53438- 0 0 0 0 0 0 0 0 0 0 0 0
53439- 0 0 0 0 0 0 0 0 0 0 0 0
53440- 0 0 0 0 0 0 0 0 0 0 0 0
53441- 0 0 0 0 0 0 0 0 0 0 0 0
53442- 0 0 0 0 0 0 6 6 6 18 18 18
53443- 54 54 54 62 62 62 2 2 6 2 2 6
53444- 2 2 6 30 30 30 46 46 46 70 70 70
53445-250 250 250 253 253 253 253 253 253 253 253 253
53446-253 253 253 253 253 253 253 253 253 253 253 253
53447-253 253 253 253 253 253 231 231 231 246 246 246
53448-253 253 253 253 253 253 253 253 253 253 253 253
53449-253 253 253 253 253 253 253 253 253 253 253 253
53450-253 253 253 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 226 226 226 10 10 10
53453- 2 2 6 6 6 6 30 30 30 2 2 6
53454- 2 2 6 2 2 6 2 2 6 2 2 6
53455- 2 2 6 66 66 66 58 58 58 22 22 22
53456- 6 6 6 0 0 0 0 0 0 0 0 0
53457- 0 0 0 0 0 0 0 0 0 0 0 0
53458- 0 0 0 0 0 0 0 0 0 0 0 0
53459- 0 0 0 0 0 0 0 0 0 0 0 0
53460- 0 0 0 0 0 0 0 0 0 0 0 0
53461- 0 0 0 0 0 0 0 0 0 0 0 0
53462- 0 0 0 0 0 0 6 6 6 22 22 22
53463- 58 58 58 62 62 62 2 2 6 2 2 6
53464- 2 2 6 2 2 6 30 30 30 78 78 78
53465-250 250 250 253 253 253 253 253 253 253 253 253
53466-253 253 253 253 253 253 253 253 253 253 253 253
53467-253 253 253 253 253 253 231 231 231 246 246 246
53468-253 253 253 253 253 253 253 253 253 253 253 253
53469-253 253 253 253 253 253 253 253 253 253 253 253
53470-253 253 253 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 206 206 206 2 2 6
53473- 22 22 22 34 34 34 18 14 6 22 22 22
53474- 26 26 26 18 18 18 6 6 6 2 2 6
53475- 2 2 6 82 82 82 54 54 54 18 18 18
53476- 6 6 6 0 0 0 0 0 0 0 0 0
53477- 0 0 0 0 0 0 0 0 0 0 0 0
53478- 0 0 0 0 0 0 0 0 0 0 0 0
53479- 0 0 0 0 0 0 0 0 0 0 0 0
53480- 0 0 0 0 0 0 0 0 0 0 0 0
53481- 0 0 0 0 0 0 0 0 0 0 0 0
53482- 0 0 0 0 0 0 6 6 6 26 26 26
53483- 62 62 62 106 106 106 74 54 14 185 133 11
53484-210 162 10 121 92 8 6 6 6 62 62 62
53485-238 238 238 253 253 253 253 253 253 253 253 253
53486-253 253 253 253 253 253 253 253 253 253 253 253
53487-253 253 253 253 253 253 231 231 231 246 246 246
53488-253 253 253 253 253 253 253 253 253 253 253 253
53489-253 253 253 253 253 253 253 253 253 253 253 253
53490-253 253 253 253 253 253 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 158 158 158 18 18 18
53493- 14 14 14 2 2 6 2 2 6 2 2 6
53494- 6 6 6 18 18 18 66 66 66 38 38 38
53495- 6 6 6 94 94 94 50 50 50 18 18 18
53496- 6 6 6 0 0 0 0 0 0 0 0 0
53497- 0 0 0 0 0 0 0 0 0 0 0 0
53498- 0 0 0 0 0 0 0 0 0 0 0 0
53499- 0 0 0 0 0 0 0 0 0 0 0 0
53500- 0 0 0 0 0 0 0 0 0 0 0 0
53501- 0 0 0 0 0 0 0 0 0 6 6 6
53502- 10 10 10 10 10 10 18 18 18 38 38 38
53503- 78 78 78 142 134 106 216 158 10 242 186 14
53504-246 190 14 246 190 14 156 118 10 10 10 10
53505- 90 90 90 238 238 238 253 253 253 253 253 253
53506-253 253 253 253 253 253 253 253 253 253 253 253
53507-253 253 253 253 253 253 231 231 231 250 250 250
53508-253 253 253 253 253 253 253 253 253 253 253 253
53509-253 253 253 253 253 253 253 253 253 253 253 253
53510-253 253 253 253 253 253 253 253 253 253 253 253
53511-253 253 253 253 253 253 253 253 253 246 230 190
53512-238 204 91 238 204 91 181 142 44 37 26 9
53513- 2 2 6 2 2 6 2 2 6 2 2 6
53514- 2 2 6 2 2 6 38 38 38 46 46 46
53515- 26 26 26 106 106 106 54 54 54 18 18 18
53516- 6 6 6 0 0 0 0 0 0 0 0 0
53517- 0 0 0 0 0 0 0 0 0 0 0 0
53518- 0 0 0 0 0 0 0 0 0 0 0 0
53519- 0 0 0 0 0 0 0 0 0 0 0 0
53520- 0 0 0 0 0 0 0 0 0 0 0 0
53521- 0 0 0 6 6 6 14 14 14 22 22 22
53522- 30 30 30 38 38 38 50 50 50 70 70 70
53523-106 106 106 190 142 34 226 170 11 242 186 14
53524-246 190 14 246 190 14 246 190 14 154 114 10
53525- 6 6 6 74 74 74 226 226 226 253 253 253
53526-253 253 253 253 253 253 253 253 253 253 253 253
53527-253 253 253 253 253 253 231 231 231 250 250 250
53528-253 253 253 253 253 253 253 253 253 253 253 253
53529-253 253 253 253 253 253 253 253 253 253 253 253
53530-253 253 253 253 253 253 253 253 253 253 253 253
53531-253 253 253 253 253 253 253 253 253 228 184 62
53532-241 196 14 241 208 19 232 195 16 38 30 10
53533- 2 2 6 2 2 6 2 2 6 2 2 6
53534- 2 2 6 6 6 6 30 30 30 26 26 26
53535-203 166 17 154 142 90 66 66 66 26 26 26
53536- 6 6 6 0 0 0 0 0 0 0 0 0
53537- 0 0 0 0 0 0 0 0 0 0 0 0
53538- 0 0 0 0 0 0 0 0 0 0 0 0
53539- 0 0 0 0 0 0 0 0 0 0 0 0
53540- 0 0 0 0 0 0 0 0 0 0 0 0
53541- 6 6 6 18 18 18 38 38 38 58 58 58
53542- 78 78 78 86 86 86 101 101 101 123 123 123
53543-175 146 61 210 150 10 234 174 13 246 186 14
53544-246 190 14 246 190 14 246 190 14 238 190 10
53545-102 78 10 2 2 6 46 46 46 198 198 198
53546-253 253 253 253 253 253 253 253 253 253 253 253
53547-253 253 253 253 253 253 234 234 234 242 242 242
53548-253 253 253 253 253 253 253 253 253 253 253 253
53549-253 253 253 253 253 253 253 253 253 253 253 253
53550-253 253 253 253 253 253 253 253 253 253 253 253
53551-253 253 253 253 253 253 253 253 253 224 178 62
53552-242 186 14 241 196 14 210 166 10 22 18 6
53553- 2 2 6 2 2 6 2 2 6 2 2 6
53554- 2 2 6 2 2 6 6 6 6 121 92 8
53555-238 202 15 232 195 16 82 82 82 34 34 34
53556- 10 10 10 0 0 0 0 0 0 0 0 0
53557- 0 0 0 0 0 0 0 0 0 0 0 0
53558- 0 0 0 0 0 0 0 0 0 0 0 0
53559- 0 0 0 0 0 0 0 0 0 0 0 0
53560- 0 0 0 0 0 0 0 0 0 0 0 0
53561- 14 14 14 38 38 38 70 70 70 154 122 46
53562-190 142 34 200 144 11 197 138 11 197 138 11
53563-213 154 11 226 170 11 242 186 14 246 190 14
53564-246 190 14 246 190 14 246 190 14 246 190 14
53565-225 175 15 46 32 6 2 2 6 22 22 22
53566-158 158 158 250 250 250 253 253 253 253 253 253
53567-253 253 253 253 253 253 253 253 253 253 253 253
53568-253 253 253 253 253 253 253 253 253 253 253 253
53569-253 253 253 253 253 253 253 253 253 253 253 253
53570-253 253 253 253 253 253 253 253 253 253 253 253
53571-253 253 253 250 250 250 242 242 242 224 178 62
53572-239 182 13 236 186 11 213 154 11 46 32 6
53573- 2 2 6 2 2 6 2 2 6 2 2 6
53574- 2 2 6 2 2 6 61 42 6 225 175 15
53575-238 190 10 236 186 11 112 100 78 42 42 42
53576- 14 14 14 0 0 0 0 0 0 0 0 0
53577- 0 0 0 0 0 0 0 0 0 0 0 0
53578- 0 0 0 0 0 0 0 0 0 0 0 0
53579- 0 0 0 0 0 0 0 0 0 0 0 0
53580- 0 0 0 0 0 0 0 0 0 6 6 6
53581- 22 22 22 54 54 54 154 122 46 213 154 11
53582-226 170 11 230 174 11 226 170 11 226 170 11
53583-236 178 12 242 186 14 246 190 14 246 190 14
53584-246 190 14 246 190 14 246 190 14 246 190 14
53585-241 196 14 184 144 12 10 10 10 2 2 6
53586- 6 6 6 116 116 116 242 242 242 253 253 253
53587-253 253 253 253 253 253 253 253 253 253 253 253
53588-253 253 253 253 253 253 253 253 253 253 253 253
53589-253 253 253 253 253 253 253 253 253 253 253 253
53590-253 253 253 253 253 253 253 253 253 253 253 253
53591-253 253 253 231 231 231 198 198 198 214 170 54
53592-236 178 12 236 178 12 210 150 10 137 92 6
53593- 18 14 6 2 2 6 2 2 6 2 2 6
53594- 6 6 6 70 47 6 200 144 11 236 178 12
53595-239 182 13 239 182 13 124 112 88 58 58 58
53596- 22 22 22 6 6 6 0 0 0 0 0 0
53597- 0 0 0 0 0 0 0 0 0 0 0 0
53598- 0 0 0 0 0 0 0 0 0 0 0 0
53599- 0 0 0 0 0 0 0 0 0 0 0 0
53600- 0 0 0 0 0 0 0 0 0 10 10 10
53601- 30 30 30 70 70 70 180 133 36 226 170 11
53602-239 182 13 242 186 14 242 186 14 246 186 14
53603-246 190 14 246 190 14 246 190 14 246 190 14
53604-246 190 14 246 190 14 246 190 14 246 190 14
53605-246 190 14 232 195 16 98 70 6 2 2 6
53606- 2 2 6 2 2 6 66 66 66 221 221 221
53607-253 253 253 253 253 253 253 253 253 253 253 253
53608-253 253 253 253 253 253 253 253 253 253 253 253
53609-253 253 253 253 253 253 253 253 253 253 253 253
53610-253 253 253 253 253 253 253 253 253 253 253 253
53611-253 253 253 206 206 206 198 198 198 214 166 58
53612-230 174 11 230 174 11 216 158 10 192 133 9
53613-163 110 8 116 81 8 102 78 10 116 81 8
53614-167 114 7 197 138 11 226 170 11 239 182 13
53615-242 186 14 242 186 14 162 146 94 78 78 78
53616- 34 34 34 14 14 14 6 6 6 0 0 0
53617- 0 0 0 0 0 0 0 0 0 0 0 0
53618- 0 0 0 0 0 0 0 0 0 0 0 0
53619- 0 0 0 0 0 0 0 0 0 0 0 0
53620- 0 0 0 0 0 0 0 0 0 6 6 6
53621- 30 30 30 78 78 78 190 142 34 226 170 11
53622-239 182 13 246 190 14 246 190 14 246 190 14
53623-246 190 14 246 190 14 246 190 14 246 190 14
53624-246 190 14 246 190 14 246 190 14 246 190 14
53625-246 190 14 241 196 14 203 166 17 22 18 6
53626- 2 2 6 2 2 6 2 2 6 38 38 38
53627-218 218 218 253 253 253 253 253 253 253 253 253
53628-253 253 253 253 253 253 253 253 253 253 253 253
53629-253 253 253 253 253 253 253 253 253 253 253 253
53630-253 253 253 253 253 253 253 253 253 253 253 253
53631-250 250 250 206 206 206 198 198 198 202 162 69
53632-226 170 11 236 178 12 224 166 10 210 150 10
53633-200 144 11 197 138 11 192 133 9 197 138 11
53634-210 150 10 226 170 11 242 186 14 246 190 14
53635-246 190 14 246 186 14 225 175 15 124 112 88
53636- 62 62 62 30 30 30 14 14 14 6 6 6
53637- 0 0 0 0 0 0 0 0 0 0 0 0
53638- 0 0 0 0 0 0 0 0 0 0 0 0
53639- 0 0 0 0 0 0 0 0 0 0 0 0
53640- 0 0 0 0 0 0 0 0 0 10 10 10
53641- 30 30 30 78 78 78 174 135 50 224 166 10
53642-239 182 13 246 190 14 246 190 14 246 190 14
53643-246 190 14 246 190 14 246 190 14 246 190 14
53644-246 190 14 246 190 14 246 190 14 246 190 14
53645-246 190 14 246 190 14 241 196 14 139 102 15
53646- 2 2 6 2 2 6 2 2 6 2 2 6
53647- 78 78 78 250 250 250 253 253 253 253 253 253
53648-253 253 253 253 253 253 253 253 253 253 253 253
53649-253 253 253 253 253 253 253 253 253 253 253 253
53650-253 253 253 253 253 253 253 253 253 253 253 253
53651-250 250 250 214 214 214 198 198 198 190 150 46
53652-219 162 10 236 178 12 234 174 13 224 166 10
53653-216 158 10 213 154 11 213 154 11 216 158 10
53654-226 170 11 239 182 13 246 190 14 246 190 14
53655-246 190 14 246 190 14 242 186 14 206 162 42
53656-101 101 101 58 58 58 30 30 30 14 14 14
53657- 6 6 6 0 0 0 0 0 0 0 0 0
53658- 0 0 0 0 0 0 0 0 0 0 0 0
53659- 0 0 0 0 0 0 0 0 0 0 0 0
53660- 0 0 0 0 0 0 0 0 0 10 10 10
53661- 30 30 30 74 74 74 174 135 50 216 158 10
53662-236 178 12 246 190 14 246 190 14 246 190 14
53663-246 190 14 246 190 14 246 190 14 246 190 14
53664-246 190 14 246 190 14 246 190 14 246 190 14
53665-246 190 14 246 190 14 241 196 14 226 184 13
53666- 61 42 6 2 2 6 2 2 6 2 2 6
53667- 22 22 22 238 238 238 253 253 253 253 253 253
53668-253 253 253 253 253 253 253 253 253 253 253 253
53669-253 253 253 253 253 253 253 253 253 253 253 253
53670-253 253 253 253 253 253 253 253 253 253 253 253
53671-253 253 253 226 226 226 187 187 187 180 133 36
53672-216 158 10 236 178 12 239 182 13 236 178 12
53673-230 174 11 226 170 11 226 170 11 230 174 11
53674-236 178 12 242 186 14 246 190 14 246 190 14
53675-246 190 14 246 190 14 246 186 14 239 182 13
53676-206 162 42 106 106 106 66 66 66 34 34 34
53677- 14 14 14 6 6 6 0 0 0 0 0 0
53678- 0 0 0 0 0 0 0 0 0 0 0 0
53679- 0 0 0 0 0 0 0 0 0 0 0 0
53680- 0 0 0 0 0 0 0 0 0 6 6 6
53681- 26 26 26 70 70 70 163 133 67 213 154 11
53682-236 178 12 246 190 14 246 190 14 246 190 14
53683-246 190 14 246 190 14 246 190 14 246 190 14
53684-246 190 14 246 190 14 246 190 14 246 190 14
53685-246 190 14 246 190 14 246 190 14 241 196 14
53686-190 146 13 18 14 6 2 2 6 2 2 6
53687- 46 46 46 246 246 246 253 253 253 253 253 253
53688-253 253 253 253 253 253 253 253 253 253 253 253
53689-253 253 253 253 253 253 253 253 253 253 253 253
53690-253 253 253 253 253 253 253 253 253 253 253 253
53691-253 253 253 221 221 221 86 86 86 156 107 11
53692-216 158 10 236 178 12 242 186 14 246 186 14
53693-242 186 14 239 182 13 239 182 13 242 186 14
53694-242 186 14 246 186 14 246 190 14 246 190 14
53695-246 190 14 246 190 14 246 190 14 246 190 14
53696-242 186 14 225 175 15 142 122 72 66 66 66
53697- 30 30 30 10 10 10 0 0 0 0 0 0
53698- 0 0 0 0 0 0 0 0 0 0 0 0
53699- 0 0 0 0 0 0 0 0 0 0 0 0
53700- 0 0 0 0 0 0 0 0 0 6 6 6
53701- 26 26 26 70 70 70 163 133 67 210 150 10
53702-236 178 12 246 190 14 246 190 14 246 190 14
53703-246 190 14 246 190 14 246 190 14 246 190 14
53704-246 190 14 246 190 14 246 190 14 246 190 14
53705-246 190 14 246 190 14 246 190 14 246 190 14
53706-232 195 16 121 92 8 34 34 34 106 106 106
53707-221 221 221 253 253 253 253 253 253 253 253 253
53708-253 253 253 253 253 253 253 253 253 253 253 253
53709-253 253 253 253 253 253 253 253 253 253 253 253
53710-253 253 253 253 253 253 253 253 253 253 253 253
53711-242 242 242 82 82 82 18 14 6 163 110 8
53712-216 158 10 236 178 12 242 186 14 246 190 14
53713-246 190 14 246 190 14 246 190 14 246 190 14
53714-246 190 14 246 190 14 246 190 14 246 190 14
53715-246 190 14 246 190 14 246 190 14 246 190 14
53716-246 190 14 246 190 14 242 186 14 163 133 67
53717- 46 46 46 18 18 18 6 6 6 0 0 0
53718- 0 0 0 0 0 0 0 0 0 0 0 0
53719- 0 0 0 0 0 0 0 0 0 0 0 0
53720- 0 0 0 0 0 0 0 0 0 10 10 10
53721- 30 30 30 78 78 78 163 133 67 210 150 10
53722-236 178 12 246 186 14 246 190 14 246 190 14
53723-246 190 14 246 190 14 246 190 14 246 190 14
53724-246 190 14 246 190 14 246 190 14 246 190 14
53725-246 190 14 246 190 14 246 190 14 246 190 14
53726-241 196 14 215 174 15 190 178 144 253 253 253
53727-253 253 253 253 253 253 253 253 253 253 253 253
53728-253 253 253 253 253 253 253 253 253 253 253 253
53729-253 253 253 253 253 253 253 253 253 253 253 253
53730-253 253 253 253 253 253 253 253 253 218 218 218
53731- 58 58 58 2 2 6 22 18 6 167 114 7
53732-216 158 10 236 178 12 246 186 14 246 190 14
53733-246 190 14 246 190 14 246 190 14 246 190 14
53734-246 190 14 246 190 14 246 190 14 246 190 14
53735-246 190 14 246 190 14 246 190 14 246 190 14
53736-246 190 14 246 186 14 242 186 14 190 150 46
53737- 54 54 54 22 22 22 6 6 6 0 0 0
53738- 0 0 0 0 0 0 0 0 0 0 0 0
53739- 0 0 0 0 0 0 0 0 0 0 0 0
53740- 0 0 0 0 0 0 0 0 0 14 14 14
53741- 38 38 38 86 86 86 180 133 36 213 154 11
53742-236 178 12 246 186 14 246 190 14 246 190 14
53743-246 190 14 246 190 14 246 190 14 246 190 14
53744-246 190 14 246 190 14 246 190 14 246 190 14
53745-246 190 14 246 190 14 246 190 14 246 190 14
53746-246 190 14 232 195 16 190 146 13 214 214 214
53747-253 253 253 253 253 253 253 253 253 253 253 253
53748-253 253 253 253 253 253 253 253 253 253 253 253
53749-253 253 253 253 253 253 253 253 253 253 253 253
53750-253 253 253 250 250 250 170 170 170 26 26 26
53751- 2 2 6 2 2 6 37 26 9 163 110 8
53752-219 162 10 239 182 13 246 186 14 246 190 14
53753-246 190 14 246 190 14 246 190 14 246 190 14
53754-246 190 14 246 190 14 246 190 14 246 190 14
53755-246 190 14 246 190 14 246 190 14 246 190 14
53756-246 186 14 236 178 12 224 166 10 142 122 72
53757- 46 46 46 18 18 18 6 6 6 0 0 0
53758- 0 0 0 0 0 0 0 0 0 0 0 0
53759- 0 0 0 0 0 0 0 0 0 0 0 0
53760- 0 0 0 0 0 0 6 6 6 18 18 18
53761- 50 50 50 109 106 95 192 133 9 224 166 10
53762-242 186 14 246 190 14 246 190 14 246 190 14
53763-246 190 14 246 190 14 246 190 14 246 190 14
53764-246 190 14 246 190 14 246 190 14 246 190 14
53765-246 190 14 246 190 14 246 190 14 246 190 14
53766-242 186 14 226 184 13 210 162 10 142 110 46
53767-226 226 226 253 253 253 253 253 253 253 253 253
53768-253 253 253 253 253 253 253 253 253 253 253 253
53769-253 253 253 253 253 253 253 253 253 253 253 253
53770-198 198 198 66 66 66 2 2 6 2 2 6
53771- 2 2 6 2 2 6 50 34 6 156 107 11
53772-219 162 10 239 182 13 246 186 14 246 190 14
53773-246 190 14 246 190 14 246 190 14 246 190 14
53774-246 190 14 246 190 14 246 190 14 246 190 14
53775-246 190 14 246 190 14 246 190 14 242 186 14
53776-234 174 13 213 154 11 154 122 46 66 66 66
53777- 30 30 30 10 10 10 0 0 0 0 0 0
53778- 0 0 0 0 0 0 0 0 0 0 0 0
53779- 0 0 0 0 0 0 0 0 0 0 0 0
53780- 0 0 0 0 0 0 6 6 6 22 22 22
53781- 58 58 58 154 121 60 206 145 10 234 174 13
53782-242 186 14 246 186 14 246 190 14 246 190 14
53783-246 190 14 246 190 14 246 190 14 246 190 14
53784-246 190 14 246 190 14 246 190 14 246 190 14
53785-246 190 14 246 190 14 246 190 14 246 190 14
53786-246 186 14 236 178 12 210 162 10 163 110 8
53787- 61 42 6 138 138 138 218 218 218 250 250 250
53788-253 253 253 253 253 253 253 253 253 250 250 250
53789-242 242 242 210 210 210 144 144 144 66 66 66
53790- 6 6 6 2 2 6 2 2 6 2 2 6
53791- 2 2 6 2 2 6 61 42 6 163 110 8
53792-216 158 10 236 178 12 246 190 14 246 190 14
53793-246 190 14 246 190 14 246 190 14 246 190 14
53794-246 190 14 246 190 14 246 190 14 246 190 14
53795-246 190 14 239 182 13 230 174 11 216 158 10
53796-190 142 34 124 112 88 70 70 70 38 38 38
53797- 18 18 18 6 6 6 0 0 0 0 0 0
53798- 0 0 0 0 0 0 0 0 0 0 0 0
53799- 0 0 0 0 0 0 0 0 0 0 0 0
53800- 0 0 0 0 0 0 6 6 6 22 22 22
53801- 62 62 62 168 124 44 206 145 10 224 166 10
53802-236 178 12 239 182 13 242 186 14 242 186 14
53803-246 186 14 246 190 14 246 190 14 246 190 14
53804-246 190 14 246 190 14 246 190 14 246 190 14
53805-246 190 14 246 190 14 246 190 14 246 190 14
53806-246 190 14 236 178 12 216 158 10 175 118 6
53807- 80 54 7 2 2 6 6 6 6 30 30 30
53808- 54 54 54 62 62 62 50 50 50 38 38 38
53809- 14 14 14 2 2 6 2 2 6 2 2 6
53810- 2 2 6 2 2 6 2 2 6 2 2 6
53811- 2 2 6 6 6 6 80 54 7 167 114 7
53812-213 154 11 236 178 12 246 190 14 246 190 14
53813-246 190 14 246 190 14 246 190 14 246 190 14
53814-246 190 14 242 186 14 239 182 13 239 182 13
53815-230 174 11 210 150 10 174 135 50 124 112 88
53816- 82 82 82 54 54 54 34 34 34 18 18 18
53817- 6 6 6 0 0 0 0 0 0 0 0 0
53818- 0 0 0 0 0 0 0 0 0 0 0 0
53819- 0 0 0 0 0 0 0 0 0 0 0 0
53820- 0 0 0 0 0 0 6 6 6 18 18 18
53821- 50 50 50 158 118 36 192 133 9 200 144 11
53822-216 158 10 219 162 10 224 166 10 226 170 11
53823-230 174 11 236 178 12 239 182 13 239 182 13
53824-242 186 14 246 186 14 246 190 14 246 190 14
53825-246 190 14 246 190 14 246 190 14 246 190 14
53826-246 186 14 230 174 11 210 150 10 163 110 8
53827-104 69 6 10 10 10 2 2 6 2 2 6
53828- 2 2 6 2 2 6 2 2 6 2 2 6
53829- 2 2 6 2 2 6 2 2 6 2 2 6
53830- 2 2 6 2 2 6 2 2 6 2 2 6
53831- 2 2 6 6 6 6 91 60 6 167 114 7
53832-206 145 10 230 174 11 242 186 14 246 190 14
53833-246 190 14 246 190 14 246 186 14 242 186 14
53834-239 182 13 230 174 11 224 166 10 213 154 11
53835-180 133 36 124 112 88 86 86 86 58 58 58
53836- 38 38 38 22 22 22 10 10 10 6 6 6
53837- 0 0 0 0 0 0 0 0 0 0 0 0
53838- 0 0 0 0 0 0 0 0 0 0 0 0
53839- 0 0 0 0 0 0 0 0 0 0 0 0
53840- 0 0 0 0 0 0 0 0 0 14 14 14
53841- 34 34 34 70 70 70 138 110 50 158 118 36
53842-167 114 7 180 123 7 192 133 9 197 138 11
53843-200 144 11 206 145 10 213 154 11 219 162 10
53844-224 166 10 230 174 11 239 182 13 242 186 14
53845-246 186 14 246 186 14 246 186 14 246 186 14
53846-239 182 13 216 158 10 185 133 11 152 99 6
53847-104 69 6 18 14 6 2 2 6 2 2 6
53848- 2 2 6 2 2 6 2 2 6 2 2 6
53849- 2 2 6 2 2 6 2 2 6 2 2 6
53850- 2 2 6 2 2 6 2 2 6 2 2 6
53851- 2 2 6 6 6 6 80 54 7 152 99 6
53852-192 133 9 219 162 10 236 178 12 239 182 13
53853-246 186 14 242 186 14 239 182 13 236 178 12
53854-224 166 10 206 145 10 192 133 9 154 121 60
53855- 94 94 94 62 62 62 42 42 42 22 22 22
53856- 14 14 14 6 6 6 0 0 0 0 0 0
53857- 0 0 0 0 0 0 0 0 0 0 0 0
53858- 0 0 0 0 0 0 0 0 0 0 0 0
53859- 0 0 0 0 0 0 0 0 0 0 0 0
53860- 0 0 0 0 0 0 0 0 0 6 6 6
53861- 18 18 18 34 34 34 58 58 58 78 78 78
53862-101 98 89 124 112 88 142 110 46 156 107 11
53863-163 110 8 167 114 7 175 118 6 180 123 7
53864-185 133 11 197 138 11 210 150 10 219 162 10
53865-226 170 11 236 178 12 236 178 12 234 174 13
53866-219 162 10 197 138 11 163 110 8 130 83 6
53867- 91 60 6 10 10 10 2 2 6 2 2 6
53868- 18 18 18 38 38 38 38 38 38 38 38 38
53869- 38 38 38 38 38 38 38 38 38 38 38 38
53870- 38 38 38 38 38 38 26 26 26 2 2 6
53871- 2 2 6 6 6 6 70 47 6 137 92 6
53872-175 118 6 200 144 11 219 162 10 230 174 11
53873-234 174 13 230 174 11 219 162 10 210 150 10
53874-192 133 9 163 110 8 124 112 88 82 82 82
53875- 50 50 50 30 30 30 14 14 14 6 6 6
53876- 0 0 0 0 0 0 0 0 0 0 0 0
53877- 0 0 0 0 0 0 0 0 0 0 0 0
53878- 0 0 0 0 0 0 0 0 0 0 0 0
53879- 0 0 0 0 0 0 0 0 0 0 0 0
53880- 0 0 0 0 0 0 0 0 0 0 0 0
53881- 6 6 6 14 14 14 22 22 22 34 34 34
53882- 42 42 42 58 58 58 74 74 74 86 86 86
53883-101 98 89 122 102 70 130 98 46 121 87 25
53884-137 92 6 152 99 6 163 110 8 180 123 7
53885-185 133 11 197 138 11 206 145 10 200 144 11
53886-180 123 7 156 107 11 130 83 6 104 69 6
53887- 50 34 6 54 54 54 110 110 110 101 98 89
53888- 86 86 86 82 82 82 78 78 78 78 78 78
53889- 78 78 78 78 78 78 78 78 78 78 78 78
53890- 78 78 78 82 82 82 86 86 86 94 94 94
53891-106 106 106 101 101 101 86 66 34 124 80 6
53892-156 107 11 180 123 7 192 133 9 200 144 11
53893-206 145 10 200 144 11 192 133 9 175 118 6
53894-139 102 15 109 106 95 70 70 70 42 42 42
53895- 22 22 22 10 10 10 0 0 0 0 0 0
53896- 0 0 0 0 0 0 0 0 0 0 0 0
53897- 0 0 0 0 0 0 0 0 0 0 0 0
53898- 0 0 0 0 0 0 0 0 0 0 0 0
53899- 0 0 0 0 0 0 0 0 0 0 0 0
53900- 0 0 0 0 0 0 0 0 0 0 0 0
53901- 0 0 0 0 0 0 6 6 6 10 10 10
53902- 14 14 14 22 22 22 30 30 30 38 38 38
53903- 50 50 50 62 62 62 74 74 74 90 90 90
53904-101 98 89 112 100 78 121 87 25 124 80 6
53905-137 92 6 152 99 6 152 99 6 152 99 6
53906-138 86 6 124 80 6 98 70 6 86 66 30
53907-101 98 89 82 82 82 58 58 58 46 46 46
53908- 38 38 38 34 34 34 34 34 34 34 34 34
53909- 34 34 34 34 34 34 34 34 34 34 34 34
53910- 34 34 34 34 34 34 38 38 38 42 42 42
53911- 54 54 54 82 82 82 94 86 76 91 60 6
53912-134 86 6 156 107 11 167 114 7 175 118 6
53913-175 118 6 167 114 7 152 99 6 121 87 25
53914-101 98 89 62 62 62 34 34 34 18 18 18
53915- 6 6 6 0 0 0 0 0 0 0 0 0
53916- 0 0 0 0 0 0 0 0 0 0 0 0
53917- 0 0 0 0 0 0 0 0 0 0 0 0
53918- 0 0 0 0 0 0 0 0 0 0 0 0
53919- 0 0 0 0 0 0 0 0 0 0 0 0
53920- 0 0 0 0 0 0 0 0 0 0 0 0
53921- 0 0 0 0 0 0 0 0 0 0 0 0
53922- 0 0 0 6 6 6 6 6 6 10 10 10
53923- 18 18 18 22 22 22 30 30 30 42 42 42
53924- 50 50 50 66 66 66 86 86 86 101 98 89
53925-106 86 58 98 70 6 104 69 6 104 69 6
53926-104 69 6 91 60 6 82 62 34 90 90 90
53927- 62 62 62 38 38 38 22 22 22 14 14 14
53928- 10 10 10 10 10 10 10 10 10 10 10 10
53929- 10 10 10 10 10 10 6 6 6 10 10 10
53930- 10 10 10 10 10 10 10 10 10 14 14 14
53931- 22 22 22 42 42 42 70 70 70 89 81 66
53932- 80 54 7 104 69 6 124 80 6 137 92 6
53933-134 86 6 116 81 8 100 82 52 86 86 86
53934- 58 58 58 30 30 30 14 14 14 6 6 6
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 0 0 0 0 0 0 0 0 0 0 0 0
53937- 0 0 0 0 0 0 0 0 0 0 0 0
53938- 0 0 0 0 0 0 0 0 0 0 0 0
53939- 0 0 0 0 0 0 0 0 0 0 0 0
53940- 0 0 0 0 0 0 0 0 0 0 0 0
53941- 0 0 0 0 0 0 0 0 0 0 0 0
53942- 0 0 0 0 0 0 0 0 0 0 0 0
53943- 0 0 0 6 6 6 10 10 10 14 14 14
53944- 18 18 18 26 26 26 38 38 38 54 54 54
53945- 70 70 70 86 86 86 94 86 76 89 81 66
53946- 89 81 66 86 86 86 74 74 74 50 50 50
53947- 30 30 30 14 14 14 6 6 6 0 0 0
53948- 0 0 0 0 0 0 0 0 0 0 0 0
53949- 0 0 0 0 0 0 0 0 0 0 0 0
53950- 0 0 0 0 0 0 0 0 0 0 0 0
53951- 6 6 6 18 18 18 34 34 34 58 58 58
53952- 82 82 82 89 81 66 89 81 66 89 81 66
53953- 94 86 66 94 86 76 74 74 74 50 50 50
53954- 26 26 26 14 14 14 6 6 6 0 0 0
53955- 0 0 0 0 0 0 0 0 0 0 0 0
53956- 0 0 0 0 0 0 0 0 0 0 0 0
53957- 0 0 0 0 0 0 0 0 0 0 0 0
53958- 0 0 0 0 0 0 0 0 0 0 0 0
53959- 0 0 0 0 0 0 0 0 0 0 0 0
53960- 0 0 0 0 0 0 0 0 0 0 0 0
53961- 0 0 0 0 0 0 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- 6 6 6 6 6 6 14 14 14 18 18 18
53965- 30 30 30 38 38 38 46 46 46 54 54 54
53966- 50 50 50 42 42 42 30 30 30 18 18 18
53967- 10 10 10 0 0 0 0 0 0 0 0 0
53968- 0 0 0 0 0 0 0 0 0 0 0 0
53969- 0 0 0 0 0 0 0 0 0 0 0 0
53970- 0 0 0 0 0 0 0 0 0 0 0 0
53971- 0 0 0 6 6 6 14 14 14 26 26 26
53972- 38 38 38 50 50 50 58 58 58 58 58 58
53973- 54 54 54 42 42 42 30 30 30 18 18 18
53974- 10 10 10 0 0 0 0 0 0 0 0 0
53975- 0 0 0 0 0 0 0 0 0 0 0 0
53976- 0 0 0 0 0 0 0 0 0 0 0 0
53977- 0 0 0 0 0 0 0 0 0 0 0 0
53978- 0 0 0 0 0 0 0 0 0 0 0 0
53979- 0 0 0 0 0 0 0 0 0 0 0 0
53980- 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
53985- 6 6 6 10 10 10 14 14 14 18 18 18
53986- 18 18 18 14 14 14 10 10 10 6 6 6
53987- 0 0 0 0 0 0 0 0 0 0 0 0
53988- 0 0 0 0 0 0 0 0 0 0 0 0
53989- 0 0 0 0 0 0 0 0 0 0 0 0
53990- 0 0 0 0 0 0 0 0 0 0 0 0
53991- 0 0 0 0 0 0 0 0 0 6 6 6
53992- 14 14 14 18 18 18 22 22 22 22 22 22
53993- 18 18 18 14 14 14 10 10 10 6 6 6
53994- 0 0 0 0 0 0 0 0 0 0 0 0
53995- 0 0 0 0 0 0 0 0 0 0 0 0
53996- 0 0 0 0 0 0 0 0 0 0 0 0
53997- 0 0 0 0 0 0 0 0 0 0 0 0
53998- 0 0 0 0 0 0 0 0 0 0 0 0
53999+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54006+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54008+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54009+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54011+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54012+4 4 4 4 4 4
54013+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54020+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54022+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54023+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54025+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54026+4 4 4 4 4 4
54027+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54036+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54037+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54038+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54039+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54040+4 4 4 4 4 4
54041+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54050+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54051+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54052+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54053+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54054+4 4 4 4 4 4
54055+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54056+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54057+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54064+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54065+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54066+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54067+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54068+4 4 4 4 4 4
54069+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54070+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54071+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54078+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54079+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54080+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54081+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54082+4 4 4 4 4 4
54083+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54084+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54085+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54086+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54087+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
54088+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
54089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54092+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
54093+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54094+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
54095+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54096+4 4 4 4 4 4
54097+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54098+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54099+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54100+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54101+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
54102+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54103+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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 3 3 3 0 0 0 1 1 1 6 6 6
54107+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54108+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54109+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54110+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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54116+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54117+0 0 0 3 3 3 4 4 4 4 4 4 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 0 0 0 4 4 4 41 54 63 125 124 125
54121+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54122+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54123+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
54124+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 5 5 5 5 5 5 2 2 2 0 0 0
54129+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54130+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54131+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
54134+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54135+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54136+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54137+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
54138+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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54143+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54144+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54145+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54146+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54147+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54148+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54149+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54150+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54151+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
54152+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 5 5 5
54156+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54157+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54158+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54159+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54160+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54161+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54162+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54163+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54164+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54165+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
54166+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 5 5 5 3 3 3
54170+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54171+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54172+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54173+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54174+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54175+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54176+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54177+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54178+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54179+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
54180+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 2 2 2 0 0 0 4 0 0
54184+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54185+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54186+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54187+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54188+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54189+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54190+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54191+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54192+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54193+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
54194+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54198+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54199+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54200+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54201+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54202+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54203+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54204+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54205+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54206+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54207+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54208+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54212+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54213+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54214+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54215+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54216+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54217+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54218+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54219+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54220+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54221+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
54222+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 3 3 3 0 0 0
54225+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54226+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54227+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54228+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54229+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54230+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54231+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54232+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54233+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54234+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54235+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
54236+4 4 4 4 4 4
54237+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54238+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54239+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54240+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54241+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54242+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54243+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54244+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54245+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54246+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54247+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54248+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54249+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54250+0 0 0 4 4 4
54251+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54252+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54253+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54254+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54255+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54256+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54257+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54258+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54259+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54260+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54261+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54262+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54263+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54264+2 0 0 0 0 0
54265+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54266+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54267+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54268+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54269+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54270+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54271+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54272+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54273+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54274+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54275+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54276+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54277+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54278+37 38 37 0 0 0
54279+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54280+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54281+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54282+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54283+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54284+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54285+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54286+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54287+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54288+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54289+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54290+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54291+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54292+85 115 134 4 0 0
54293+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54294+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54295+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54296+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54297+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54298+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54299+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54300+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54301+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54302+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54303+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54304+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54305+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54306+60 73 81 4 0 0
54307+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54308+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54309+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54310+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54311+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54312+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54313+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54314+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54315+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54316+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54317+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54318+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54319+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54320+16 19 21 4 0 0
54321+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54322+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54323+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54324+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54325+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54326+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54327+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54328+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54329+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54330+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54331+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54332+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54333+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54334+4 0 0 4 3 3
54335+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54336+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54337+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54338+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54339+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54340+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54341+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54342+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54343+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54344+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54345+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54346+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54347+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54348+3 2 2 4 4 4
54349+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54350+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54351+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54352+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54353+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54354+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54355+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54356+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54357+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54358+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54359+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54360+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54361+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54362+4 4 4 4 4 4
54363+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54364+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54365+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54366+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54367+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54368+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54369+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54370+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54371+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54372+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54373+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54374+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54375+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54376+4 4 4 4 4 4
54377+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54378+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54379+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54380+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54381+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54382+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54383+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54384+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54385+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54386+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54387+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54388+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54389+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54390+5 5 5 5 5 5
54391+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54392+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54393+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54394+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54395+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54396+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54397+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54398+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54399+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54400+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54401+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54402+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54403+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54404+5 5 5 4 4 4
54405+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54406+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54407+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54408+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54409+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54410+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54411+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54412+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54413+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54414+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54415+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54416+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54417+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54418+4 4 4 4 4 4
54419+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54420+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54421+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54422+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54423+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54424+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54425+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54426+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54427+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54428+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54429+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54430+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54431+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54432+4 4 4 4 4 4
54433+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54434+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54435+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54436+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54437+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54438+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54439+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54440+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54441+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54442+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54443+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54444+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54445+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54446+4 4 4 4 4 4
54447+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
54448+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54449+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54450+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54451+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54452+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54453+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54454+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
54455+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54456+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54457+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54458+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54459+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54460+4 4 4 4 4 4
54461+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54462+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54463+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54464+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
54465+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54466+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54467+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54468+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54469+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54470+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54471+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54472+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54473+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54474+4 4 4 4 4 4
54475+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54476+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54477+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54478+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54479+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54480+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54481+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54482+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54483+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54484+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54485+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
54486+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54487+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54488+4 4 4 4 4 4
54489+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54490+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54491+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54492+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54493+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54494+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54495+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54496+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54497+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54498+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54499+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
54500+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54501+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54502+4 4 4 4 4 4
54503+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54504+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54505+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54506+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54507+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54508+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54509+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54510+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54511+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54512+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54513+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54514+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54515+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54516+4 4 4 4 4 4
54517+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
54518+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54519+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54520+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54521+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54522+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54523+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54524+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54525+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54526+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54527+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54528+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54529+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54530+4 4 4 4 4 4
54531+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
54532+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54533+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54534+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54535+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54536+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54537+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54538+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54539+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54540+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54541+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54542+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54543+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54544+4 4 4 4 4 4
54545+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54546+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54547+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54548+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54549+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54550+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54551+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54552+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54553+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54554+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54555+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54556+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54557+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54558+4 4 4 4 4 4
54559+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54560+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
54561+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
54562+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54563+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54564+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54565+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54566+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54567+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54568+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54569+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54570+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54571+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54572+4 4 4 4 4 4
54573+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54574+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54575+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54576+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54577+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54578+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54579+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54580+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54581+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54582+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54583+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54584+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54585+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54586+4 4 4 4 4 4
54587+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
54588+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54589+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54590+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54591+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54592+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54593+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54594+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54595+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54596+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54597+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54598+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54599+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54600+4 4 4 4 4 4
54601+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
54602+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
54603+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54604+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54605+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54606+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54607+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54608+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54609+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54610+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54611+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54612+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54613+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54614+4 4 4 4 4 4
54615+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54616+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
54617+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54618+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
54619+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54620+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54621+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54622+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
54623+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54624+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54625+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54628+4 4 4 4 4 4
54629+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54630+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
54631+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54632+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54633+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54634+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54635+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54636+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54637+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
54638+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54639+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54642+4 4 4 4 4 4
54643+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54644+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54645+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54646+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54647+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54648+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54649+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54650+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
54651+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54652+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54653+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54656+4 4 4 4 4 4
54657+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54658+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
54659+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
54660+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
54661+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54662+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54663+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54664+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54665+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54666+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54667+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54670+4 4 4 4 4 4
54671+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54672+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54673+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54674+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54675+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54676+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54677+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54678+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
54679+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54680+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54681+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54684+4 4 4 4 4 4
54685+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54686+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54687+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54688+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54689+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54690+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54691+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54692+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
54693+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
54694+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54695+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54698+4 4 4 4 4 4
54699+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
54700+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
54701+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54702+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54703+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54704+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54705+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54706+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54707+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
54708+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54709+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54712+4 4 4 4 4 4
54713+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54714+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54715+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54716+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54717+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54718+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54719+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54720+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54721+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54722+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54723+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54726+4 4 4 4 4 4
54727+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54728+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54729+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54730+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54731+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54732+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54733+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54734+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54735+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54736+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54737+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54738+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54739+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54740+4 4 4 4 4 4
54741+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54742+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54743+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54744+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54745+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54746+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54747+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54748+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54749+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54750+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54751+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54752+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54753+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54754+4 4 4 4 4 4
54755+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54756+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54757+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54758+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54759+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54760+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54761+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54762+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54763+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54764+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54765+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54766+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54767+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54768+4 4 4 4 4 4
54769+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54770+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54771+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54772+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54773+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54774+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54775+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54776+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54777+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54778+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54779+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54780+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54781+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54782+4 4 4 4 4 4
54783+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54784+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54785+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54786+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54787+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54788+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54789+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54790+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54791+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54792+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54793+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54794+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54795+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54796+4 4 4 4 4 4
54797+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54798+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54799+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54800+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54801+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54802+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54803+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54804+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54805+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54806+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54807+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54808+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54809+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54810+4 4 4 4 4 4
54811+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54812+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54813+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54814+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54815+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54816+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54817+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54818+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54819+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54820+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54821+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54822+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54823+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54824+4 4 4 4 4 4
54825+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54826+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54827+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54828+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54829+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54830+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54831+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54832+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54833+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54834+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54835+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54836+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54837+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54838+4 4 4 4 4 4
54839+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54840+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54841+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54842+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54843+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54844+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54845+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54846+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54847+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54848+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54849+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54850+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54851+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54852+4 4 4 4 4 4
54853+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54854+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54855+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54856+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54857+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54858+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54859+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54860+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54861+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54862+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54863+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54864+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54865+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54866+4 4 4 4 4 4
54867+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54868+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54869+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54870+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54871+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54872+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54873+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54874+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54875+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54876+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54877+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54878+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54879+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54880+4 4 4 4 4 4
54881+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54882+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54883+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54884+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54885+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54886+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54887+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54888+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54889+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54890+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54891+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54892+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54893+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54894+4 4 4 4 4 4
54895+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54896+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54897+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54898+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54899+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54900+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54901+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54902+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54903+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54904+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54905+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54906+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54907+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54908+4 4 4 4 4 4
54909+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54910+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54911+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54912+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54913+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54914+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54915+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54916+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54917+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54919+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54920+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922+4 4 4 4 4 4
54923+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54924+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54925+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54926+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54927+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54928+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54929+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54930+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54931+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54933+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54934+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936+4 4 4 4 4 4
54937+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54938+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54939+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54940+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54941+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54942+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54943+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54944+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54945+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54947+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54948+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950+4 4 4 4 4 4
54951+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54953+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54954+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54955+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54956+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54957+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54958+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54959+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54961+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54962+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964+4 4 4 4 4 4
54965+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54967+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54968+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54969+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54970+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54971+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54972+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978+4 4 4 4 4 4
54979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54982+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54983+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54984+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54985+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54986+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992+4 4 4 4 4 4
54993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54996+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54997+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54998+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54999+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
55000+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55001+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55002+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55003+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55006+4 4 4 4 4 4
55007+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55008+4 4 4 4 4 4 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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55011+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55012+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55013+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
55014+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55015+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55016+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55017+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55020+4 4 4 4 4 4
55021+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55022+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6
55025+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55026+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55027+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
55028+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55029+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55030+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55031+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55034+4 4 4 4 4 4
55035+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55036+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5
55039+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55040+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55041+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
55042+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55043+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55044+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55045+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55047+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55048+4 4 4 4 4 4
55049+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55050+4 4 4 4 4 4 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 5 5 5
55053+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55054+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55055+6 6 6 4 3 3 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55058+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55059+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55060+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55062+4 4 4 4 4 4
55063+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55064+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55068+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55069+4 3 3 5 5 5 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4
55072+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55073+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55074+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55076+4 4 4 4 4 4
55077+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55078+4 4 4 4 4 4 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 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55082+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55083+5 5 5 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55087+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55088+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55090+4 4 4 4 4 4
55091+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55092+4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6
55096+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55097+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4
55101+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55102+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55104+4 4 4 4 4 4
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 5 5 5 4 3 3
55110+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55111+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55116+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55118+4 4 4 4 4 4
55119diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55120index a01147f..5d896f8 100644
55121--- a/drivers/video/matrox/matroxfb_DAC1064.c
55122+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55123@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55124
55125 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55126 struct matrox_switch matrox_mystique = {
55127- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55128+ .preinit = MGA1064_preinit,
55129+ .reset = MGA1064_reset,
55130+ .init = MGA1064_init,
55131+ .restore = MGA1064_restore,
55132 };
55133 EXPORT_SYMBOL(matrox_mystique);
55134 #endif
55135
55136 #ifdef CONFIG_FB_MATROX_G
55137 struct matrox_switch matrox_G100 = {
55138- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55139+ .preinit = MGAG100_preinit,
55140+ .reset = MGAG100_reset,
55141+ .init = MGAG100_init,
55142+ .restore = MGAG100_restore,
55143 };
55144 EXPORT_SYMBOL(matrox_G100);
55145 #endif
55146diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55147index 195ad7c..09743fc 100644
55148--- a/drivers/video/matrox/matroxfb_Ti3026.c
55149+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55150@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55151 }
55152
55153 struct matrox_switch matrox_millennium = {
55154- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55155+ .preinit = Ti3026_preinit,
55156+ .reset = Ti3026_reset,
55157+ .init = Ti3026_init,
55158+ .restore = Ti3026_restore
55159 };
55160 EXPORT_SYMBOL(matrox_millennium);
55161 #endif
55162diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55163index fe92eed..106e085 100644
55164--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55165+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55166@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55167 struct mb862xxfb_par *par = info->par;
55168
55169 if (info->var.bits_per_pixel == 32) {
55170- info->fbops->fb_fillrect = cfb_fillrect;
55171- info->fbops->fb_copyarea = cfb_copyarea;
55172- info->fbops->fb_imageblit = cfb_imageblit;
55173+ pax_open_kernel();
55174+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55175+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55176+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55177+ pax_close_kernel();
55178 } else {
55179 outreg(disp, GC_L0EM, 3);
55180- info->fbops->fb_fillrect = mb86290fb_fillrect;
55181- info->fbops->fb_copyarea = mb86290fb_copyarea;
55182- info->fbops->fb_imageblit = mb86290fb_imageblit;
55183+ pax_open_kernel();
55184+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55185+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55186+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55187+ pax_close_kernel();
55188 }
55189 outreg(draw, GDC_REG_DRAW_BASE, 0);
55190 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55191diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55192index ff22871..b129bed 100644
55193--- a/drivers/video/nvidia/nvidia.c
55194+++ b/drivers/video/nvidia/nvidia.c
55195@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55196 info->fix.line_length = (info->var.xres_virtual *
55197 info->var.bits_per_pixel) >> 3;
55198 if (info->var.accel_flags) {
55199- info->fbops->fb_imageblit = nvidiafb_imageblit;
55200- info->fbops->fb_fillrect = nvidiafb_fillrect;
55201- info->fbops->fb_copyarea = nvidiafb_copyarea;
55202- info->fbops->fb_sync = nvidiafb_sync;
55203+ pax_open_kernel();
55204+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55205+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55206+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55207+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55208+ pax_close_kernel();
55209 info->pixmap.scan_align = 4;
55210 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55211 info->flags |= FBINFO_READS_FAST;
55212 NVResetGraphics(info);
55213 } else {
55214- info->fbops->fb_imageblit = cfb_imageblit;
55215- info->fbops->fb_fillrect = cfb_fillrect;
55216- info->fbops->fb_copyarea = cfb_copyarea;
55217- info->fbops->fb_sync = NULL;
55218+ pax_open_kernel();
55219+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55220+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55221+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55222+ *(void **)&info->fbops->fb_sync = NULL;
55223+ pax_close_kernel();
55224 info->pixmap.scan_align = 1;
55225 info->flags |= FBINFO_HWACCEL_DISABLED;
55226 info->flags &= ~FBINFO_READS_FAST;
55227@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55228 info->pixmap.size = 8 * 1024;
55229 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55230
55231- if (!hwcur)
55232- info->fbops->fb_cursor = NULL;
55233+ if (!hwcur) {
55234+ pax_open_kernel();
55235+ *(void **)&info->fbops->fb_cursor = NULL;
55236+ pax_close_kernel();
55237+ }
55238
55239 info->var.accel_flags = (!noaccel);
55240
55241diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55242index 669a81f..e216d76 100644
55243--- a/drivers/video/omap2/dss/display.c
55244+++ b/drivers/video/omap2/dss/display.c
55245@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55246 snprintf(dssdev->alias, sizeof(dssdev->alias),
55247 "display%d", disp_num_counter++);
55248
55249+ pax_open_kernel();
55250 if (drv && drv->get_resolution == NULL)
55251- drv->get_resolution = omapdss_default_get_resolution;
55252+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55253 if (drv && drv->get_recommended_bpp == NULL)
55254- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55255+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55256 if (drv && drv->get_timings == NULL)
55257- drv->get_timings = omapdss_default_get_timings;
55258+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55259+ pax_close_kernel();
55260
55261 mutex_lock(&panel_list_mutex);
55262 list_add_tail(&dssdev->panel_list, &panel_list);
55263diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55264index 83433cb..71e9b98 100644
55265--- a/drivers/video/s1d13xxxfb.c
55266+++ b/drivers/video/s1d13xxxfb.c
55267@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55268
55269 switch(prod_id) {
55270 case S1D13506_PROD_ID: /* activate acceleration */
55271- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55272- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55273+ pax_open_kernel();
55274+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55275+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55276+ pax_close_kernel();
55277 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55278 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55279 break;
55280diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55281index d513ed6..90b0de9 100644
55282--- a/drivers/video/smscufx.c
55283+++ b/drivers/video/smscufx.c
55284@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55285 fb_deferred_io_cleanup(info);
55286 kfree(info->fbdefio);
55287 info->fbdefio = NULL;
55288- info->fbops->fb_mmap = ufx_ops_mmap;
55289+ pax_open_kernel();
55290+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55291+ pax_close_kernel();
55292 }
55293
55294 pr_debug("released /dev/fb%d user=%d count=%d",
55295diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55296index 025f14e..20eb4db 100644
55297--- a/drivers/video/udlfb.c
55298+++ b/drivers/video/udlfb.c
55299@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55300 dlfb_urb_completion(urb);
55301
55302 error:
55303- atomic_add(bytes_sent, &dev->bytes_sent);
55304- atomic_add(bytes_identical, &dev->bytes_identical);
55305- atomic_add(width*height*2, &dev->bytes_rendered);
55306+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55307+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55308+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55309 end_cycles = get_cycles();
55310- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55311+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55312 >> 10)), /* Kcycles */
55313 &dev->cpu_kcycles_used);
55314
55315@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55316 dlfb_urb_completion(urb);
55317
55318 error:
55319- atomic_add(bytes_sent, &dev->bytes_sent);
55320- atomic_add(bytes_identical, &dev->bytes_identical);
55321- atomic_add(bytes_rendered, &dev->bytes_rendered);
55322+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55323+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55324+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55325 end_cycles = get_cycles();
55326- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55327+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55328 >> 10)), /* Kcycles */
55329 &dev->cpu_kcycles_used);
55330 }
55331@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55332 fb_deferred_io_cleanup(info);
55333 kfree(info->fbdefio);
55334 info->fbdefio = NULL;
55335- info->fbops->fb_mmap = dlfb_ops_mmap;
55336+ pax_open_kernel();
55337+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55338+ pax_close_kernel();
55339 }
55340
55341 pr_warn("released /dev/fb%d user=%d count=%d\n",
55342@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55343 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55344 struct dlfb_data *dev = fb_info->par;
55345 return snprintf(buf, PAGE_SIZE, "%u\n",
55346- atomic_read(&dev->bytes_rendered));
55347+ atomic_read_unchecked(&dev->bytes_rendered));
55348 }
55349
55350 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55351@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55352 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55353 struct dlfb_data *dev = fb_info->par;
55354 return snprintf(buf, PAGE_SIZE, "%u\n",
55355- atomic_read(&dev->bytes_identical));
55356+ atomic_read_unchecked(&dev->bytes_identical));
55357 }
55358
55359 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55360@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55361 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55362 struct dlfb_data *dev = fb_info->par;
55363 return snprintf(buf, PAGE_SIZE, "%u\n",
55364- atomic_read(&dev->bytes_sent));
55365+ atomic_read_unchecked(&dev->bytes_sent));
55366 }
55367
55368 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55369@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55370 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55371 struct dlfb_data *dev = fb_info->par;
55372 return snprintf(buf, PAGE_SIZE, "%u\n",
55373- atomic_read(&dev->cpu_kcycles_used));
55374+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55375 }
55376
55377 static ssize_t edid_show(
55378@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55379 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55380 struct dlfb_data *dev = fb_info->par;
55381
55382- atomic_set(&dev->bytes_rendered, 0);
55383- atomic_set(&dev->bytes_identical, 0);
55384- atomic_set(&dev->bytes_sent, 0);
55385- atomic_set(&dev->cpu_kcycles_used, 0);
55386+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55387+ atomic_set_unchecked(&dev->bytes_identical, 0);
55388+ atomic_set_unchecked(&dev->bytes_sent, 0);
55389+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55390
55391 return count;
55392 }
55393diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55394index 256fba7..6e75516 100644
55395--- a/drivers/video/uvesafb.c
55396+++ b/drivers/video/uvesafb.c
55397@@ -19,6 +19,7 @@
55398 #include <linux/io.h>
55399 #include <linux/mutex.h>
55400 #include <linux/slab.h>
55401+#include <linux/moduleloader.h>
55402 #include <video/edid.h>
55403 #include <video/uvesafb.h>
55404 #ifdef CONFIG_X86
55405@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55406 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55407 par->pmi_setpal = par->ypan = 0;
55408 } else {
55409+
55410+#ifdef CONFIG_PAX_KERNEXEC
55411+#ifdef CONFIG_MODULES
55412+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55413+#endif
55414+ if (!par->pmi_code) {
55415+ par->pmi_setpal = par->ypan = 0;
55416+ return 0;
55417+ }
55418+#endif
55419+
55420 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55421 + task->t.regs.edi);
55422+
55423+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55424+ pax_open_kernel();
55425+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55426+ pax_close_kernel();
55427+
55428+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55429+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55430+#else
55431 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55432 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55433+#endif
55434+
55435 printk(KERN_INFO "uvesafb: protected mode interface info at "
55436 "%04x:%04x\n",
55437 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55438@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55439 par->ypan = ypan;
55440
55441 if (par->pmi_setpal || par->ypan) {
55442+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55443 if (__supported_pte_mask & _PAGE_NX) {
55444 par->pmi_setpal = par->ypan = 0;
55445 printk(KERN_WARNING "uvesafb: NX protection is active, "
55446 "better not use the PMI.\n");
55447- } else {
55448+ } else
55449+#endif
55450 uvesafb_vbe_getpmi(task, par);
55451- }
55452 }
55453 #else
55454 /* The protected mode interface is not available on non-x86. */
55455@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55456 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55457
55458 /* Disable blanking if the user requested so. */
55459- if (!blank)
55460- info->fbops->fb_blank = NULL;
55461+ if (!blank) {
55462+ pax_open_kernel();
55463+ *(void **)&info->fbops->fb_blank = NULL;
55464+ pax_close_kernel();
55465+ }
55466
55467 /*
55468 * Find out how much IO memory is required for the mode with
55469@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55470 info->flags = FBINFO_FLAG_DEFAULT |
55471 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55472
55473- if (!par->ypan)
55474- info->fbops->fb_pan_display = NULL;
55475+ if (!par->ypan) {
55476+ pax_open_kernel();
55477+ *(void **)&info->fbops->fb_pan_display = NULL;
55478+ pax_close_kernel();
55479+ }
55480 }
55481
55482 static void uvesafb_init_mtrr(struct fb_info *info)
55483@@ -1792,6 +1822,11 @@ out_mode:
55484 out:
55485 kfree(par->vbe_modes);
55486
55487+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55488+ if (par->pmi_code)
55489+ module_free_exec(NULL, par->pmi_code);
55490+#endif
55491+
55492 framebuffer_release(info);
55493 return err;
55494 }
55495@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55496 kfree(par->vbe_modes);
55497 kfree(par->vbe_state_orig);
55498 kfree(par->vbe_state_saved);
55499+
55500+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55501+ if (par->pmi_code)
55502+ module_free_exec(NULL, par->pmi_code);
55503+#endif
55504+
55505 }
55506
55507 framebuffer_release(info);
55508diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55509index 1c7da3b..56ea0bd 100644
55510--- a/drivers/video/vesafb.c
55511+++ b/drivers/video/vesafb.c
55512@@ -9,6 +9,7 @@
55513 */
55514
55515 #include <linux/module.h>
55516+#include <linux/moduleloader.h>
55517 #include <linux/kernel.h>
55518 #include <linux/errno.h>
55519 #include <linux/string.h>
55520@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55521 static int vram_total; /* Set total amount of memory */
55522 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55523 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55524-static void (*pmi_start)(void) __read_mostly;
55525-static void (*pmi_pal) (void) __read_mostly;
55526+static void (*pmi_start)(void) __read_only;
55527+static void (*pmi_pal) (void) __read_only;
55528 static int depth __read_mostly;
55529 static int vga_compat __read_mostly;
55530 /* --------------------------------------------------------------------- */
55531@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55532 unsigned int size_remap;
55533 unsigned int size_total;
55534 char *option = NULL;
55535+ void *pmi_code = NULL;
55536
55537 /* ignore error return of fb_get_options */
55538 fb_get_options("vesafb", &option);
55539@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55540 size_remap = size_total;
55541 vesafb_fix.smem_len = size_remap;
55542
55543-#ifndef __i386__
55544- screen_info.vesapm_seg = 0;
55545-#endif
55546-
55547 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55548 printk(KERN_WARNING
55549 "vesafb: cannot reserve video memory at 0x%lx\n",
55550@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55551 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55552 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55553
55554+#ifdef __i386__
55555+
55556+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55557+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55558+ if (!pmi_code)
55559+#elif !defined(CONFIG_PAX_KERNEXEC)
55560+ if (0)
55561+#endif
55562+
55563+#endif
55564+ screen_info.vesapm_seg = 0;
55565+
55566 if (screen_info.vesapm_seg) {
55567- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55568- screen_info.vesapm_seg,screen_info.vesapm_off);
55569+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55570+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55571 }
55572
55573 if (screen_info.vesapm_seg < 0xc000)
55574@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55575
55576 if (ypan || pmi_setpal) {
55577 unsigned short *pmi_base;
55578+
55579 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55580- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55581- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55582+
55583+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55584+ pax_open_kernel();
55585+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55586+#else
55587+ pmi_code = pmi_base;
55588+#endif
55589+
55590+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55591+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55592+
55593+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55594+ pmi_start = ktva_ktla(pmi_start);
55595+ pmi_pal = ktva_ktla(pmi_pal);
55596+ pax_close_kernel();
55597+#endif
55598+
55599 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55600 if (pmi_base[3]) {
55601 printk(KERN_INFO "vesafb: pmi: ports = ");
55602@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55603 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55604 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55605
55606- if (!ypan)
55607- info->fbops->fb_pan_display = NULL;
55608+ if (!ypan) {
55609+ pax_open_kernel();
55610+ *(void **)&info->fbops->fb_pan_display = NULL;
55611+ pax_close_kernel();
55612+ }
55613
55614 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55615 err = -ENOMEM;
55616@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55617 fb_info(info, "%s frame buffer device\n", info->fix.id);
55618 return 0;
55619 err:
55620+
55621+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55622+ module_free_exec(NULL, pmi_code);
55623+#endif
55624+
55625 if (info->screen_base)
55626 iounmap(info->screen_base);
55627 framebuffer_release(info);
55628diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55629index 88714ae..16c2e11 100644
55630--- a/drivers/video/via/via_clock.h
55631+++ b/drivers/video/via/via_clock.h
55632@@ -56,7 +56,7 @@ struct via_clock {
55633
55634 void (*set_engine_pll_state)(u8 state);
55635 void (*set_engine_pll)(struct via_pll_config config);
55636-};
55637+} __no_const;
55638
55639
55640 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55641diff --git a/drivers/xen/balloon.c b/drivers/xen/balloon.c
55642index 4c02e2b..2c85267 100644
55643--- a/drivers/xen/balloon.c
55644+++ b/drivers/xen/balloon.c
55645@@ -406,12 +406,26 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
55646 state = BP_EAGAIN;
55647 break;
55648 }
55649-
55650- pfn = page_to_pfn(page);
55651- frame_list[i] = pfn_to_mfn(pfn);
55652-
55653 scrub_page(page);
55654
55655+ frame_list[i] = page_to_pfn(page);
55656+ }
55657+
55658+ /*
55659+ * Ensure that ballooned highmem pages don't have kmaps.
55660+ *
55661+ * Do this before changing the p2m as kmap_flush_unused()
55662+ * reads PTEs to obtain pages (and hence needs the original
55663+ * p2m entry).
55664+ */
55665+ kmap_flush_unused();
55666+
55667+ /* Update direct mapping, invalidate P2M, and add to balloon. */
55668+ for (i = 0; i < nr_pages; i++) {
55669+ pfn = frame_list[i];
55670+ frame_list[i] = pfn_to_mfn(pfn);
55671+ page = pfn_to_page(pfn);
55672+
55673 #ifdef CONFIG_XEN_HAVE_PVMMU
55674 /*
55675 * Ballooned out frames are effectively replaced with
55676@@ -436,11 +450,9 @@ static enum bp_state decrease_reservation(unsigned long nr_pages, gfp_t gfp)
55677 }
55678 #endif
55679
55680- balloon_append(pfn_to_page(pfn));
55681+ balloon_append(page);
55682 }
55683
55684- /* Ensure that ballooned highmem pages don't have kmaps. */
55685- kmap_flush_unused();
55686 flush_tlb_all();
55687
55688 set_xen_guest_handle(reservation.extent_start, frame_list);
55689diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55690index fef20db..d28b1ab 100644
55691--- a/drivers/xen/xenfs/xenstored.c
55692+++ b/drivers/xen/xenfs/xenstored.c
55693@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55694 static int xsd_kva_open(struct inode *inode, struct file *file)
55695 {
55696 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55697+#ifdef CONFIG_GRKERNSEC_HIDESYM
55698+ NULL);
55699+#else
55700 xen_store_interface);
55701+#endif
55702+
55703 if (!file->private_data)
55704 return -ENOMEM;
55705 return 0;
55706diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55707index 9ff073f..05cef23 100644
55708--- a/fs/9p/vfs_addr.c
55709+++ b/fs/9p/vfs_addr.c
55710@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55711
55712 retval = v9fs_file_write_internal(inode,
55713 v9inode->writeback_fid,
55714- (__force const char __user *)buffer,
55715+ (const char __force_user *)buffer,
55716 len, &offset, 0);
55717 if (retval > 0)
55718 retval = 0;
55719diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55720index 4e65aa9..043dc9a 100644
55721--- a/fs/9p/vfs_inode.c
55722+++ b/fs/9p/vfs_inode.c
55723@@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55724 void
55725 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55726 {
55727- char *s = nd_get_link(nd);
55728+ const char *s = nd_get_link(nd);
55729
55730 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55731 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55732diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55733index 370b24c..ff0be7b 100644
55734--- a/fs/Kconfig.binfmt
55735+++ b/fs/Kconfig.binfmt
55736@@ -103,7 +103,7 @@ config HAVE_AOUT
55737
55738 config BINFMT_AOUT
55739 tristate "Kernel support for a.out and ECOFF binaries"
55740- depends on HAVE_AOUT
55741+ depends on HAVE_AOUT && BROKEN
55742 ---help---
55743 A.out (Assembler.OUTput) is a set of formats for libraries and
55744 executables used in the earliest versions of UNIX. Linux used
55745diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55746index ce25d75..dc09eeb 100644
55747--- a/fs/afs/inode.c
55748+++ b/fs/afs/inode.c
55749@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55750 struct afs_vnode *vnode;
55751 struct super_block *sb;
55752 struct inode *inode;
55753- static atomic_t afs_autocell_ino;
55754+ static atomic_unchecked_t afs_autocell_ino;
55755
55756 _enter("{%x:%u},%*.*s,",
55757 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55758@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55759 data.fid.unique = 0;
55760 data.fid.vnode = 0;
55761
55762- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55763+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55764 afs_iget5_autocell_test, afs_iget5_set,
55765 &data);
55766 if (!inode) {
55767diff --git a/fs/aio.c b/fs/aio.c
55768index 062a5f6..e5618e0 100644
55769--- a/fs/aio.c
55770+++ b/fs/aio.c
55771@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55772 size += sizeof(struct io_event) * nr_events;
55773
55774 nr_pages = PFN_UP(size);
55775- if (nr_pages < 0)
55776+ if (nr_pages <= 0)
55777 return -EINVAL;
55778
55779 file = aio_private_file(ctx, nr_pages);
55780diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
55781index 2408473..80ef38c 100644
55782--- a/fs/anon_inodes.c
55783+++ b/fs/anon_inodes.c
55784@@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
55785 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
55786 int flags, const char *dev_name, void *data)
55787 {
55788- struct dentry *root;
55789- root = mount_pseudo(fs_type, "anon_inode:", NULL,
55790+ return mount_pseudo(fs_type, "anon_inode:", NULL,
55791 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
55792- if (!IS_ERR(root)) {
55793- struct super_block *s = root->d_sb;
55794- anon_inode_inode = alloc_anon_inode(s);
55795- if (IS_ERR(anon_inode_inode)) {
55796- dput(root);
55797- deactivate_locked_super(s);
55798- root = ERR_CAST(anon_inode_inode);
55799- }
55800- }
55801- return root;
55802 }
55803
55804 static struct file_system_type anon_inode_fs_type = {
55805@@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
55806
55807 static int __init anon_inode_init(void)
55808 {
55809- int error;
55810-
55811- error = register_filesystem(&anon_inode_fs_type);
55812- if (error)
55813- goto err_exit;
55814 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
55815- if (IS_ERR(anon_inode_mnt)) {
55816- error = PTR_ERR(anon_inode_mnt);
55817- goto err_unregister_filesystem;
55818- }
55819+ if (IS_ERR(anon_inode_mnt))
55820+ panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
55821+
55822+ anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
55823+ if (IS_ERR(anon_inode_inode))
55824+ panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
55825+
55826 return 0;
55827-
55828-err_unregister_filesystem:
55829- unregister_filesystem(&anon_inode_fs_type);
55830-err_exit:
55831- panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
55832 }
55833
55834 fs_initcall(anon_inode_init);
55835diff --git a/fs/attr.c b/fs/attr.c
55836index 5d4e59d..fd02418 100644
55837--- a/fs/attr.c
55838+++ b/fs/attr.c
55839@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55840 unsigned long limit;
55841
55842 limit = rlimit(RLIMIT_FSIZE);
55843+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55844 if (limit != RLIM_INFINITY && offset > limit)
55845 goto out_sig;
55846 if (offset > inode->i_sb->s_maxbytes)
55847diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55848index 689e40d..515cac5 100644
55849--- a/fs/autofs4/waitq.c
55850+++ b/fs/autofs4/waitq.c
55851@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55852 {
55853 unsigned long sigpipe, flags;
55854 mm_segment_t fs;
55855- const char *data = (const char *)addr;
55856+ const char __user *data = (const char __force_user *)addr;
55857 ssize_t wr = 0;
55858
55859 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55860@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55861 return 1;
55862 }
55863
55864+#ifdef CONFIG_GRKERNSEC_HIDESYM
55865+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55866+#endif
55867+
55868 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55869 enum autofs_notify notify)
55870 {
55871@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55872
55873 /* If this is a direct mount request create a dummy name */
55874 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55875+#ifdef CONFIG_GRKERNSEC_HIDESYM
55876+ /* this name does get written to userland via autofs4_write() */
55877+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55878+#else
55879 qstr.len = sprintf(name, "%p", dentry);
55880+#endif
55881 else {
55882 qstr.len = autofs4_getpath(sbi, dentry, &name);
55883 if (!qstr.len) {
55884diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55885index 2722387..56059b5 100644
55886--- a/fs/befs/endian.h
55887+++ b/fs/befs/endian.h
55888@@ -11,7 +11,7 @@
55889
55890 #include <asm/byteorder.h>
55891
55892-static inline u64
55893+static inline u64 __intentional_overflow(-1)
55894 fs64_to_cpu(const struct super_block *sb, fs64 n)
55895 {
55896 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55897@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55898 return (__force fs64)cpu_to_be64(n);
55899 }
55900
55901-static inline u32
55902+static inline u32 __intentional_overflow(-1)
55903 fs32_to_cpu(const struct super_block *sb, fs32 n)
55904 {
55905 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55906@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55907 return (__force fs32)cpu_to_be32(n);
55908 }
55909
55910-static inline u16
55911+static inline u16 __intentional_overflow(-1)
55912 fs16_to_cpu(const struct super_block *sb, fs16 n)
55913 {
55914 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55915diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55916index ca0ba15..0fa3257 100644
55917--- a/fs/binfmt_aout.c
55918+++ b/fs/binfmt_aout.c
55919@@ -16,6 +16,7 @@
55920 #include <linux/string.h>
55921 #include <linux/fs.h>
55922 #include <linux/file.h>
55923+#include <linux/security.h>
55924 #include <linux/stat.h>
55925 #include <linux/fcntl.h>
55926 #include <linux/ptrace.h>
55927@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55928 #endif
55929 # define START_STACK(u) ((void __user *)u.start_stack)
55930
55931+ memset(&dump, 0, sizeof(dump));
55932+
55933 fs = get_fs();
55934 set_fs(KERNEL_DS);
55935 has_dumped = 1;
55936@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55937
55938 /* If the size of the dump file exceeds the rlimit, then see what would happen
55939 if we wrote the stack, but not the data area. */
55940+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55941 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55942 dump.u_dsize = 0;
55943
55944 /* Make sure we have enough room to write the stack and data areas. */
55945+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55946 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55947 dump.u_ssize = 0;
55948
55949@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55950 rlim = rlimit(RLIMIT_DATA);
55951 if (rlim >= RLIM_INFINITY)
55952 rlim = ~0;
55953+
55954+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55955 if (ex.a_data + ex.a_bss > rlim)
55956 return -ENOMEM;
55957
55958@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55959
55960 install_exec_creds(bprm);
55961
55962+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55963+ current->mm->pax_flags = 0UL;
55964+#endif
55965+
55966+#ifdef CONFIG_PAX_PAGEEXEC
55967+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55968+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55969+
55970+#ifdef CONFIG_PAX_EMUTRAMP
55971+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55972+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55973+#endif
55974+
55975+#ifdef CONFIG_PAX_MPROTECT
55976+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55977+ current->mm->pax_flags |= MF_PAX_MPROTECT;
55978+#endif
55979+
55980+ }
55981+#endif
55982+
55983 if (N_MAGIC(ex) == OMAGIC) {
55984 unsigned long text_addr, map_size;
55985 loff_t pos;
55986@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55987 }
55988
55989 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55990- PROT_READ | PROT_WRITE | PROT_EXEC,
55991+ PROT_READ | PROT_WRITE,
55992 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55993 fd_offset + ex.a_text);
55994 if (error != N_DATADDR(ex)) {
55995diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55996index 571a423..eed5754 100644
55997--- a/fs/binfmt_elf.c
55998+++ b/fs/binfmt_elf.c
55999@@ -34,6 +34,7 @@
56000 #include <linux/utsname.h>
56001 #include <linux/coredump.h>
56002 #include <linux/sched.h>
56003+#include <linux/xattr.h>
56004 #include <asm/uaccess.h>
56005 #include <asm/param.h>
56006 #include <asm/page.h>
56007@@ -48,7 +49,7 @@
56008 static int load_elf_binary(struct linux_binprm *bprm);
56009 static int load_elf_library(struct file *);
56010 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56011- int, int, unsigned long);
56012+ int, int, unsigned long) __intentional_overflow(-1);
56013
56014 /*
56015 * If we don't support core dumping, then supply a NULL so we
56016@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56017 #define elf_core_dump NULL
56018 #endif
56019
56020+#ifdef CONFIG_PAX_MPROTECT
56021+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56022+#endif
56023+
56024+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56025+static void elf_handle_mmap(struct file *file);
56026+#endif
56027+
56028 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56029 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56030 #else
56031@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
56032 .load_binary = load_elf_binary,
56033 .load_shlib = load_elf_library,
56034 .core_dump = elf_core_dump,
56035+
56036+#ifdef CONFIG_PAX_MPROTECT
56037+ .handle_mprotect= elf_handle_mprotect,
56038+#endif
56039+
56040+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56041+ .handle_mmap = elf_handle_mmap,
56042+#endif
56043+
56044 .min_coredump = ELF_EXEC_PAGESIZE,
56045 };
56046
56047@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
56048
56049 static int set_brk(unsigned long start, unsigned long end)
56050 {
56051+ unsigned long e = end;
56052+
56053 start = ELF_PAGEALIGN(start);
56054 end = ELF_PAGEALIGN(end);
56055 if (end > start) {
56056@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
56057 if (BAD_ADDR(addr))
56058 return addr;
56059 }
56060- current->mm->start_brk = current->mm->brk = end;
56061+ current->mm->start_brk = current->mm->brk = e;
56062 return 0;
56063 }
56064
56065@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56066 elf_addr_t __user *u_rand_bytes;
56067 const char *k_platform = ELF_PLATFORM;
56068 const char *k_base_platform = ELF_BASE_PLATFORM;
56069- unsigned char k_rand_bytes[16];
56070+ u32 k_rand_bytes[4];
56071 int items;
56072 elf_addr_t *elf_info;
56073 int ei_index = 0;
56074 const struct cred *cred = current_cred();
56075 struct vm_area_struct *vma;
56076+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56077
56078 /*
56079 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56080@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56081 * Generate 16 random bytes for userspace PRNG seeding.
56082 */
56083 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56084- u_rand_bytes = (elf_addr_t __user *)
56085- STACK_ALLOC(p, sizeof(k_rand_bytes));
56086+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56087+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56088+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56089+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56090+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56091+ u_rand_bytes = (elf_addr_t __user *) p;
56092 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56093 return -EFAULT;
56094
56095@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56096 return -EFAULT;
56097 current->mm->env_end = p;
56098
56099+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56100+
56101 /* Put the elf_info on the stack in the right place. */
56102 sp = (elf_addr_t __user *)envp + 1;
56103- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56104+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56105 return -EFAULT;
56106 return 0;
56107 }
56108@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56109 an ELF header */
56110
56111 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56112- struct file *interpreter, unsigned long *interp_map_addr,
56113- unsigned long no_base)
56114+ struct file *interpreter, unsigned long no_base)
56115 {
56116 struct elf_phdr *elf_phdata;
56117 struct elf_phdr *eppnt;
56118- unsigned long load_addr = 0;
56119+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56120 int load_addr_set = 0;
56121 unsigned long last_bss = 0, elf_bss = 0;
56122- unsigned long error = ~0UL;
56123+ unsigned long error = -EINVAL;
56124 unsigned long total_size;
56125 int retval, i, size;
56126
56127@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56128 goto out_close;
56129 }
56130
56131+#ifdef CONFIG_PAX_SEGMEXEC
56132+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56133+ pax_task_size = SEGMEXEC_TASK_SIZE;
56134+#endif
56135+
56136 eppnt = elf_phdata;
56137 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56138 if (eppnt->p_type == PT_LOAD) {
56139@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56140 map_addr = elf_map(interpreter, load_addr + vaddr,
56141 eppnt, elf_prot, elf_type, total_size);
56142 total_size = 0;
56143- if (!*interp_map_addr)
56144- *interp_map_addr = map_addr;
56145 error = map_addr;
56146 if (BAD_ADDR(map_addr))
56147 goto out_close;
56148@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56149 k = load_addr + eppnt->p_vaddr;
56150 if (BAD_ADDR(k) ||
56151 eppnt->p_filesz > eppnt->p_memsz ||
56152- eppnt->p_memsz > TASK_SIZE ||
56153- TASK_SIZE - eppnt->p_memsz < k) {
56154+ eppnt->p_memsz > pax_task_size ||
56155+ pax_task_size - eppnt->p_memsz < k) {
56156 error = -ENOMEM;
56157 goto out_close;
56158 }
56159@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56160 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56161
56162 /* Map the last of the bss segment */
56163- error = vm_brk(elf_bss, last_bss - elf_bss);
56164- if (BAD_ADDR(error))
56165- goto out_close;
56166+ if (last_bss > elf_bss) {
56167+ error = vm_brk(elf_bss, last_bss - elf_bss);
56168+ if (BAD_ADDR(error))
56169+ goto out_close;
56170+ }
56171 }
56172
56173 error = load_addr;
56174@@ -538,6 +569,336 @@ out:
56175 return error;
56176 }
56177
56178+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56179+#ifdef CONFIG_PAX_SOFTMODE
56180+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56181+{
56182+ unsigned long pax_flags = 0UL;
56183+
56184+#ifdef CONFIG_PAX_PAGEEXEC
56185+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56186+ pax_flags |= MF_PAX_PAGEEXEC;
56187+#endif
56188+
56189+#ifdef CONFIG_PAX_SEGMEXEC
56190+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56191+ pax_flags |= MF_PAX_SEGMEXEC;
56192+#endif
56193+
56194+#ifdef CONFIG_PAX_EMUTRAMP
56195+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56196+ pax_flags |= MF_PAX_EMUTRAMP;
56197+#endif
56198+
56199+#ifdef CONFIG_PAX_MPROTECT
56200+ if (elf_phdata->p_flags & PF_MPROTECT)
56201+ pax_flags |= MF_PAX_MPROTECT;
56202+#endif
56203+
56204+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56205+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56206+ pax_flags |= MF_PAX_RANDMMAP;
56207+#endif
56208+
56209+ return pax_flags;
56210+}
56211+#endif
56212+
56213+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56214+{
56215+ unsigned long pax_flags = 0UL;
56216+
56217+#ifdef CONFIG_PAX_PAGEEXEC
56218+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56219+ pax_flags |= MF_PAX_PAGEEXEC;
56220+#endif
56221+
56222+#ifdef CONFIG_PAX_SEGMEXEC
56223+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56224+ pax_flags |= MF_PAX_SEGMEXEC;
56225+#endif
56226+
56227+#ifdef CONFIG_PAX_EMUTRAMP
56228+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56229+ pax_flags |= MF_PAX_EMUTRAMP;
56230+#endif
56231+
56232+#ifdef CONFIG_PAX_MPROTECT
56233+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56234+ pax_flags |= MF_PAX_MPROTECT;
56235+#endif
56236+
56237+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56238+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56239+ pax_flags |= MF_PAX_RANDMMAP;
56240+#endif
56241+
56242+ return pax_flags;
56243+}
56244+#endif
56245+
56246+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56247+#ifdef CONFIG_PAX_SOFTMODE
56248+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56249+{
56250+ unsigned long pax_flags = 0UL;
56251+
56252+#ifdef CONFIG_PAX_PAGEEXEC
56253+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56254+ pax_flags |= MF_PAX_PAGEEXEC;
56255+#endif
56256+
56257+#ifdef CONFIG_PAX_SEGMEXEC
56258+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56259+ pax_flags |= MF_PAX_SEGMEXEC;
56260+#endif
56261+
56262+#ifdef CONFIG_PAX_EMUTRAMP
56263+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56264+ pax_flags |= MF_PAX_EMUTRAMP;
56265+#endif
56266+
56267+#ifdef CONFIG_PAX_MPROTECT
56268+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56269+ pax_flags |= MF_PAX_MPROTECT;
56270+#endif
56271+
56272+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56273+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56274+ pax_flags |= MF_PAX_RANDMMAP;
56275+#endif
56276+
56277+ return pax_flags;
56278+}
56279+#endif
56280+
56281+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56282+{
56283+ unsigned long pax_flags = 0UL;
56284+
56285+#ifdef CONFIG_PAX_PAGEEXEC
56286+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56287+ pax_flags |= MF_PAX_PAGEEXEC;
56288+#endif
56289+
56290+#ifdef CONFIG_PAX_SEGMEXEC
56291+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56292+ pax_flags |= MF_PAX_SEGMEXEC;
56293+#endif
56294+
56295+#ifdef CONFIG_PAX_EMUTRAMP
56296+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56297+ pax_flags |= MF_PAX_EMUTRAMP;
56298+#endif
56299+
56300+#ifdef CONFIG_PAX_MPROTECT
56301+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56302+ pax_flags |= MF_PAX_MPROTECT;
56303+#endif
56304+
56305+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56306+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56307+ pax_flags |= MF_PAX_RANDMMAP;
56308+#endif
56309+
56310+ return pax_flags;
56311+}
56312+#endif
56313+
56314+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56315+static unsigned long pax_parse_defaults(void)
56316+{
56317+ unsigned long pax_flags = 0UL;
56318+
56319+#ifdef CONFIG_PAX_SOFTMODE
56320+ if (pax_softmode)
56321+ return pax_flags;
56322+#endif
56323+
56324+#ifdef CONFIG_PAX_PAGEEXEC
56325+ pax_flags |= MF_PAX_PAGEEXEC;
56326+#endif
56327+
56328+#ifdef CONFIG_PAX_SEGMEXEC
56329+ pax_flags |= MF_PAX_SEGMEXEC;
56330+#endif
56331+
56332+#ifdef CONFIG_PAX_MPROTECT
56333+ pax_flags |= MF_PAX_MPROTECT;
56334+#endif
56335+
56336+#ifdef CONFIG_PAX_RANDMMAP
56337+ if (randomize_va_space)
56338+ pax_flags |= MF_PAX_RANDMMAP;
56339+#endif
56340+
56341+ return pax_flags;
56342+}
56343+
56344+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56345+{
56346+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56347+
56348+#ifdef CONFIG_PAX_EI_PAX
56349+
56350+#ifdef CONFIG_PAX_SOFTMODE
56351+ if (pax_softmode)
56352+ return pax_flags;
56353+#endif
56354+
56355+ pax_flags = 0UL;
56356+
56357+#ifdef CONFIG_PAX_PAGEEXEC
56358+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56359+ pax_flags |= MF_PAX_PAGEEXEC;
56360+#endif
56361+
56362+#ifdef CONFIG_PAX_SEGMEXEC
56363+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56364+ pax_flags |= MF_PAX_SEGMEXEC;
56365+#endif
56366+
56367+#ifdef CONFIG_PAX_EMUTRAMP
56368+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56369+ pax_flags |= MF_PAX_EMUTRAMP;
56370+#endif
56371+
56372+#ifdef CONFIG_PAX_MPROTECT
56373+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56374+ pax_flags |= MF_PAX_MPROTECT;
56375+#endif
56376+
56377+#ifdef CONFIG_PAX_ASLR
56378+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56379+ pax_flags |= MF_PAX_RANDMMAP;
56380+#endif
56381+
56382+#endif
56383+
56384+ return pax_flags;
56385+
56386+}
56387+
56388+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56389+{
56390+
56391+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56392+ unsigned long i;
56393+
56394+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56395+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56396+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56397+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56398+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56399+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56400+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56401+ return PAX_PARSE_FLAGS_FALLBACK;
56402+
56403+#ifdef CONFIG_PAX_SOFTMODE
56404+ if (pax_softmode)
56405+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56406+ else
56407+#endif
56408+
56409+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56410+ break;
56411+ }
56412+#endif
56413+
56414+ return PAX_PARSE_FLAGS_FALLBACK;
56415+}
56416+
56417+static unsigned long pax_parse_xattr_pax(struct file * const file)
56418+{
56419+
56420+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56421+ ssize_t xattr_size, i;
56422+ unsigned char xattr_value[sizeof("pemrs") - 1];
56423+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56424+
56425+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56426+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56427+ return PAX_PARSE_FLAGS_FALLBACK;
56428+
56429+ for (i = 0; i < xattr_size; i++)
56430+ switch (xattr_value[i]) {
56431+ default:
56432+ return PAX_PARSE_FLAGS_FALLBACK;
56433+
56434+#define parse_flag(option1, option2, flag) \
56435+ case option1: \
56436+ if (pax_flags_hardmode & MF_PAX_##flag) \
56437+ return PAX_PARSE_FLAGS_FALLBACK;\
56438+ pax_flags_hardmode |= MF_PAX_##flag; \
56439+ break; \
56440+ case option2: \
56441+ if (pax_flags_softmode & MF_PAX_##flag) \
56442+ return PAX_PARSE_FLAGS_FALLBACK;\
56443+ pax_flags_softmode |= MF_PAX_##flag; \
56444+ break;
56445+
56446+ parse_flag('p', 'P', PAGEEXEC);
56447+ parse_flag('e', 'E', EMUTRAMP);
56448+ parse_flag('m', 'M', MPROTECT);
56449+ parse_flag('r', 'R', RANDMMAP);
56450+ parse_flag('s', 'S', SEGMEXEC);
56451+
56452+#undef parse_flag
56453+ }
56454+
56455+ if (pax_flags_hardmode & pax_flags_softmode)
56456+ return PAX_PARSE_FLAGS_FALLBACK;
56457+
56458+#ifdef CONFIG_PAX_SOFTMODE
56459+ if (pax_softmode)
56460+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56461+ else
56462+#endif
56463+
56464+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56465+#else
56466+ return PAX_PARSE_FLAGS_FALLBACK;
56467+#endif
56468+
56469+}
56470+
56471+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56472+{
56473+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56474+
56475+ pax_flags = pax_parse_defaults();
56476+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56477+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56478+ xattr_pax_flags = pax_parse_xattr_pax(file);
56479+
56480+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56481+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56482+ pt_pax_flags != xattr_pax_flags)
56483+ return -EINVAL;
56484+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56485+ pax_flags = xattr_pax_flags;
56486+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56487+ pax_flags = pt_pax_flags;
56488+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56489+ pax_flags = ei_pax_flags;
56490+
56491+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56492+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56493+ if ((__supported_pte_mask & _PAGE_NX))
56494+ pax_flags &= ~MF_PAX_SEGMEXEC;
56495+ else
56496+ pax_flags &= ~MF_PAX_PAGEEXEC;
56497+ }
56498+#endif
56499+
56500+ if (0 > pax_check_flags(&pax_flags))
56501+ return -EINVAL;
56502+
56503+ current->mm->pax_flags = pax_flags;
56504+ return 0;
56505+}
56506+#endif
56507+
56508 /*
56509 * These are the functions used to load ELF style executables and shared
56510 * libraries. There is no binary dependent code anywhere else.
56511@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56512 {
56513 unsigned int random_variable = 0;
56514
56515+#ifdef CONFIG_PAX_RANDUSTACK
56516+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56517+ return stack_top - current->mm->delta_stack;
56518+#endif
56519+
56520 if ((current->flags & PF_RANDOMIZE) &&
56521 !(current->personality & ADDR_NO_RANDOMIZE)) {
56522 random_variable = get_random_int() & STACK_RND_MASK;
56523@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56524 unsigned long load_addr = 0, load_bias = 0;
56525 int load_addr_set = 0;
56526 char * elf_interpreter = NULL;
56527- unsigned long error;
56528+ unsigned long error = 0;
56529 struct elf_phdr *elf_ppnt, *elf_phdata;
56530 unsigned long elf_bss, elf_brk;
56531 int retval, i;
56532@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56533 unsigned long start_code, end_code, start_data, end_data;
56534 unsigned long reloc_func_desc __maybe_unused = 0;
56535 int executable_stack = EXSTACK_DEFAULT;
56536- unsigned long def_flags = 0;
56537 struct pt_regs *regs = current_pt_regs();
56538 struct {
56539 struct elfhdr elf_ex;
56540 struct elfhdr interp_elf_ex;
56541 } *loc;
56542+ unsigned long pax_task_size;
56543
56544 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56545 if (!loc) {
56546@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56547 goto out_free_dentry;
56548
56549 /* OK, This is the point of no return */
56550- current->mm->def_flags = def_flags;
56551+ current->mm->def_flags = 0;
56552
56553 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56554 may depend on the personality. */
56555 SET_PERSONALITY(loc->elf_ex);
56556+
56557+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56558+ current->mm->pax_flags = 0UL;
56559+#endif
56560+
56561+#ifdef CONFIG_PAX_DLRESOLVE
56562+ current->mm->call_dl_resolve = 0UL;
56563+#endif
56564+
56565+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56566+ current->mm->call_syscall = 0UL;
56567+#endif
56568+
56569+#ifdef CONFIG_PAX_ASLR
56570+ current->mm->delta_mmap = 0UL;
56571+ current->mm->delta_stack = 0UL;
56572+#endif
56573+
56574+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56575+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56576+ send_sig(SIGKILL, current, 0);
56577+ goto out_free_dentry;
56578+ }
56579+#endif
56580+
56581+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56582+ pax_set_initial_flags(bprm);
56583+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56584+ if (pax_set_initial_flags_func)
56585+ (pax_set_initial_flags_func)(bprm);
56586+#endif
56587+
56588+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56589+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56590+ current->mm->context.user_cs_limit = PAGE_SIZE;
56591+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56592+ }
56593+#endif
56594+
56595+#ifdef CONFIG_PAX_SEGMEXEC
56596+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56597+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56598+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56599+ pax_task_size = SEGMEXEC_TASK_SIZE;
56600+ current->mm->def_flags |= VM_NOHUGEPAGE;
56601+ } else
56602+#endif
56603+
56604+ pax_task_size = TASK_SIZE;
56605+
56606+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56607+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56608+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56609+ put_cpu();
56610+ }
56611+#endif
56612+
56613+#ifdef CONFIG_PAX_ASLR
56614+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56615+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56616+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56617+ }
56618+#endif
56619+
56620+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56621+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56622+ executable_stack = EXSTACK_DISABLE_X;
56623+ current->personality &= ~READ_IMPLIES_EXEC;
56624+ } else
56625+#endif
56626+
56627 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56628 current->personality |= READ_IMPLIES_EXEC;
56629
56630@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56631 #else
56632 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56633 #endif
56634+
56635+#ifdef CONFIG_PAX_RANDMMAP
56636+ /* PaX: randomize base address at the default exe base if requested */
56637+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56638+#ifdef CONFIG_SPARC64
56639+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56640+#else
56641+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56642+#endif
56643+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56644+ elf_flags |= MAP_FIXED;
56645+ }
56646+#endif
56647+
56648 }
56649
56650 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56651@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56652 * allowed task size. Note that p_filesz must always be
56653 * <= p_memsz so it is only necessary to check p_memsz.
56654 */
56655- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56656- elf_ppnt->p_memsz > TASK_SIZE ||
56657- TASK_SIZE - elf_ppnt->p_memsz < k) {
56658+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56659+ elf_ppnt->p_memsz > pax_task_size ||
56660+ pax_task_size - elf_ppnt->p_memsz < k) {
56661 /* set_brk can never work. Avoid overflows. */
56662 send_sig(SIGKILL, current, 0);
56663 retval = -EINVAL;
56664@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56665 goto out_free_dentry;
56666 }
56667 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56668- send_sig(SIGSEGV, current, 0);
56669- retval = -EFAULT; /* Nobody gets to see this, but.. */
56670- goto out_free_dentry;
56671+ /*
56672+ * This bss-zeroing can fail if the ELF
56673+ * file specifies odd protections. So
56674+ * we don't check the return value
56675+ */
56676 }
56677
56678+#ifdef CONFIG_PAX_RANDMMAP
56679+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56680+ unsigned long start, size, flags;
56681+ vm_flags_t vm_flags;
56682+
56683+ start = ELF_PAGEALIGN(elf_brk);
56684+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56685+ flags = MAP_FIXED | MAP_PRIVATE;
56686+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56687+
56688+ down_write(&current->mm->mmap_sem);
56689+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56690+ retval = -ENOMEM;
56691+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56692+// if (current->personality & ADDR_NO_RANDOMIZE)
56693+// vm_flags |= VM_READ | VM_MAYREAD;
56694+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56695+ retval = IS_ERR_VALUE(start) ? start : 0;
56696+ }
56697+ up_write(&current->mm->mmap_sem);
56698+ if (retval == 0)
56699+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56700+ if (retval < 0) {
56701+ send_sig(SIGKILL, current, 0);
56702+ goto out_free_dentry;
56703+ }
56704+ }
56705+#endif
56706+
56707 if (elf_interpreter) {
56708- unsigned long interp_map_addr = 0;
56709-
56710 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56711 interpreter,
56712- &interp_map_addr,
56713 load_bias);
56714 if (!IS_ERR((void *)elf_entry)) {
56715 /*
56716@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56717 * Decide what to dump of a segment, part, all or none.
56718 */
56719 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56720- unsigned long mm_flags)
56721+ unsigned long mm_flags, long signr)
56722 {
56723 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56724
56725@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56726 if (vma->vm_file == NULL)
56727 return 0;
56728
56729- if (FILTER(MAPPED_PRIVATE))
56730+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56731 goto whole;
56732
56733 /*
56734@@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56735 {
56736 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56737 int i = 0;
56738- do
56739+ do {
56740 i += 2;
56741- while (auxv[i - 2] != AT_NULL);
56742+ } while (auxv[i - 2] != AT_NULL);
56743 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56744 }
56745
56746@@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56747 {
56748 mm_segment_t old_fs = get_fs();
56749 set_fs(KERNEL_DS);
56750- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56751+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56752 set_fs(old_fs);
56753 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56754 }
56755@@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56756 }
56757
56758 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56759- unsigned long mm_flags)
56760+ struct coredump_params *cprm)
56761 {
56762 struct vm_area_struct *vma;
56763 size_t size = 0;
56764
56765 for (vma = first_vma(current, gate_vma); vma != NULL;
56766 vma = next_vma(vma, gate_vma))
56767- size += vma_dump_size(vma, mm_flags);
56768+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56769 return size;
56770 }
56771
56772@@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56773
56774 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56775
56776- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56777+ offset += elf_core_vma_data_size(gate_vma, cprm);
56778 offset += elf_core_extra_data_size();
56779 e_shoff = offset;
56780
56781@@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56782 phdr.p_offset = offset;
56783 phdr.p_vaddr = vma->vm_start;
56784 phdr.p_paddr = 0;
56785- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56786+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56787 phdr.p_memsz = vma->vm_end - vma->vm_start;
56788 offset += phdr.p_filesz;
56789 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56790@@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56791 unsigned long addr;
56792 unsigned long end;
56793
56794- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56795+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56796
56797 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56798 struct page *page;
56799@@ -2202,6 +2681,167 @@ out:
56800
56801 #endif /* CONFIG_ELF_CORE */
56802
56803+#ifdef CONFIG_PAX_MPROTECT
56804+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56805+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56806+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56807+ *
56808+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56809+ * basis because we want to allow the common case and not the special ones.
56810+ */
56811+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56812+{
56813+ struct elfhdr elf_h;
56814+ struct elf_phdr elf_p;
56815+ unsigned long i;
56816+ unsigned long oldflags;
56817+ bool is_textrel_rw, is_textrel_rx, is_relro;
56818+
56819+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56820+ return;
56821+
56822+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56823+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56824+
56825+#ifdef CONFIG_PAX_ELFRELOCS
56826+ /* possible TEXTREL */
56827+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56828+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56829+#else
56830+ is_textrel_rw = false;
56831+ is_textrel_rx = false;
56832+#endif
56833+
56834+ /* possible RELRO */
56835+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56836+
56837+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56838+ return;
56839+
56840+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56841+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56842+
56843+#ifdef CONFIG_PAX_ETEXECRELOCS
56844+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56845+#else
56846+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56847+#endif
56848+
56849+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56850+ !elf_check_arch(&elf_h) ||
56851+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56852+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56853+ return;
56854+
56855+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56856+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56857+ return;
56858+ switch (elf_p.p_type) {
56859+ case PT_DYNAMIC:
56860+ if (!is_textrel_rw && !is_textrel_rx)
56861+ continue;
56862+ i = 0UL;
56863+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56864+ elf_dyn dyn;
56865+
56866+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56867+ break;
56868+ if (dyn.d_tag == DT_NULL)
56869+ break;
56870+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56871+ gr_log_textrel(vma);
56872+ if (is_textrel_rw)
56873+ vma->vm_flags |= VM_MAYWRITE;
56874+ else
56875+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56876+ vma->vm_flags &= ~VM_MAYWRITE;
56877+ break;
56878+ }
56879+ i++;
56880+ }
56881+ is_textrel_rw = false;
56882+ is_textrel_rx = false;
56883+ continue;
56884+
56885+ case PT_GNU_RELRO:
56886+ if (!is_relro)
56887+ continue;
56888+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56889+ vma->vm_flags &= ~VM_MAYWRITE;
56890+ is_relro = false;
56891+ continue;
56892+
56893+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56894+ case PT_PAX_FLAGS: {
56895+ const char *msg_mprotect = "", *msg_emutramp = "";
56896+ char *buffer_lib, *buffer_exe;
56897+
56898+ if (elf_p.p_flags & PF_NOMPROTECT)
56899+ msg_mprotect = "MPROTECT disabled";
56900+
56901+#ifdef CONFIG_PAX_EMUTRAMP
56902+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56903+ msg_emutramp = "EMUTRAMP enabled";
56904+#endif
56905+
56906+ if (!msg_mprotect[0] && !msg_emutramp[0])
56907+ continue;
56908+
56909+ if (!printk_ratelimit())
56910+ continue;
56911+
56912+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56913+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56914+ if (buffer_lib && buffer_exe) {
56915+ char *path_lib, *path_exe;
56916+
56917+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56918+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56919+
56920+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56921+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56922+
56923+ }
56924+ free_page((unsigned long)buffer_exe);
56925+ free_page((unsigned long)buffer_lib);
56926+ continue;
56927+ }
56928+#endif
56929+
56930+ }
56931+ }
56932+}
56933+#endif
56934+
56935+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56936+
56937+extern int grsec_enable_log_rwxmaps;
56938+
56939+static void elf_handle_mmap(struct file *file)
56940+{
56941+ struct elfhdr elf_h;
56942+ struct elf_phdr elf_p;
56943+ unsigned long i;
56944+
56945+ if (!grsec_enable_log_rwxmaps)
56946+ return;
56947+
56948+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56949+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56950+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56951+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56952+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56953+ return;
56954+
56955+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56956+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56957+ return;
56958+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56959+ gr_log_ptgnustack(file);
56960+ }
56961+}
56962+#endif
56963+
56964 static int __init init_elf_binfmt(void)
56965 {
56966 register_binfmt(&elf_format);
56967diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56968index d50bbe5..af3b649 100644
56969--- a/fs/binfmt_flat.c
56970+++ b/fs/binfmt_flat.c
56971@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56972 realdatastart = (unsigned long) -ENOMEM;
56973 printk("Unable to allocate RAM for process data, errno %d\n",
56974 (int)-realdatastart);
56975+ down_write(&current->mm->mmap_sem);
56976 vm_munmap(textpos, text_len);
56977+ up_write(&current->mm->mmap_sem);
56978 ret = realdatastart;
56979 goto err;
56980 }
56981@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56982 }
56983 if (IS_ERR_VALUE(result)) {
56984 printk("Unable to read data+bss, errno %d\n", (int)-result);
56985+ down_write(&current->mm->mmap_sem);
56986 vm_munmap(textpos, text_len);
56987 vm_munmap(realdatastart, len);
56988+ up_write(&current->mm->mmap_sem);
56989 ret = result;
56990 goto err;
56991 }
56992@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56993 }
56994 if (IS_ERR_VALUE(result)) {
56995 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56996+ down_write(&current->mm->mmap_sem);
56997 vm_munmap(textpos, text_len + data_len + extra +
56998 MAX_SHARED_LIBS * sizeof(unsigned long));
56999+ up_write(&current->mm->mmap_sem);
57000 ret = result;
57001 goto err;
57002 }
57003diff --git a/fs/bio.c b/fs/bio.c
57004index 33d79a4..c3c9893 100644
57005--- a/fs/bio.c
57006+++ b/fs/bio.c
57007@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57008 /*
57009 * Overflow, abort
57010 */
57011- if (end < start)
57012+ if (end < start || end - start > INT_MAX - nr_pages)
57013 return ERR_PTR(-EINVAL);
57014
57015 nr_pages += end - start;
57016@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57017 /*
57018 * Overflow, abort
57019 */
57020- if (end < start)
57021+ if (end < start || end - start > INT_MAX - nr_pages)
57022 return ERR_PTR(-EINVAL);
57023
57024 nr_pages += end - start;
57025@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57026 const int read = bio_data_dir(bio) == READ;
57027 struct bio_map_data *bmd = bio->bi_private;
57028 int i;
57029- char *p = bmd->sgvecs[0].iov_base;
57030+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57031
57032 bio_for_each_segment_all(bvec, bio, i) {
57033 char *addr = page_address(bvec->bv_page);
57034diff --git a/fs/block_dev.c b/fs/block_dev.c
57035index 1e86823..8e34695 100644
57036--- a/fs/block_dev.c
57037+++ b/fs/block_dev.c
57038@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57039 else if (bdev->bd_contains == bdev)
57040 return true; /* is a whole device which isn't held */
57041
57042- else if (whole->bd_holder == bd_may_claim)
57043+ else if (whole->bd_holder == (void *)bd_may_claim)
57044 return true; /* is a partition of a device that is being partitioned */
57045 else if (whole->bd_holder != NULL)
57046 return false; /* is a partition of a held device */
57047diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57048index 3de01b4..6547c39 100644
57049--- a/fs/btrfs/ctree.c
57050+++ b/fs/btrfs/ctree.c
57051@@ -1217,9 +1217,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57052 free_extent_buffer(buf);
57053 add_root_to_dirty_list(root);
57054 } else {
57055- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57056- parent_start = parent->start;
57057- else
57058+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57059+ if (parent)
57060+ parent_start = parent->start;
57061+ else
57062+ parent_start = 0;
57063+ } else
57064 parent_start = 0;
57065
57066 WARN_ON(trans->transid != btrfs_header_generation(parent));
57067diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57068index 8d292fb..bc205c2 100644
57069--- a/fs/btrfs/delayed-inode.c
57070+++ b/fs/btrfs/delayed-inode.c
57071@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57072
57073 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57074 {
57075- int seq = atomic_inc_return(&delayed_root->items_seq);
57076+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57077 if ((atomic_dec_return(&delayed_root->items) <
57078 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57079 waitqueue_active(&delayed_root->wait))
57080@@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57081 static int refs_newer(struct btrfs_delayed_root *delayed_root,
57082 int seq, int count)
57083 {
57084- int val = atomic_read(&delayed_root->items_seq);
57085+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57086
57087 if (val < seq || val >= seq + count)
57088 return 1;
57089@@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57090 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
57091 return;
57092
57093- seq = atomic_read(&delayed_root->items_seq);
57094+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57095
57096 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
57097 int ret;
57098diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57099index a4b38f9..f86a509 100644
57100--- a/fs/btrfs/delayed-inode.h
57101+++ b/fs/btrfs/delayed-inode.h
57102@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57103 */
57104 struct list_head prepare_list;
57105 atomic_t items; /* for delayed items */
57106- atomic_t items_seq; /* for delayed items */
57107+ atomic_unchecked_t items_seq; /* for delayed items */
57108 int nodes; /* for delayed nodes */
57109 wait_queue_head_t wait;
57110 };
57111@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
57112 struct btrfs_delayed_root *delayed_root)
57113 {
57114 atomic_set(&delayed_root->items, 0);
57115- atomic_set(&delayed_root->items_seq, 0);
57116+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57117 delayed_root->nodes = 0;
57118 spin_lock_init(&delayed_root->lock);
57119 init_waitqueue_head(&delayed_root->wait);
57120diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57121index 9f831bb..14afde5 100644
57122--- a/fs/btrfs/ioctl.c
57123+++ b/fs/btrfs/ioctl.c
57124@@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57125 for (i = 0; i < num_types; i++) {
57126 struct btrfs_space_info *tmp;
57127
57128+ /* Don't copy in more than we allocated */
57129 if (!slot_count)
57130 break;
57131
57132+ slot_count--;
57133+
57134 info = NULL;
57135 rcu_read_lock();
57136 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57137@@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57138 memcpy(dest, &space, sizeof(space));
57139 dest++;
57140 space_args.total_spaces++;
57141- slot_count--;
57142 }
57143- if (!slot_count)
57144- break;
57145 }
57146 up_read(&info->groups_sem);
57147 }
57148diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57149index d71a11d..384e2c4 100644
57150--- a/fs/btrfs/super.c
57151+++ b/fs/btrfs/super.c
57152@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57153 function, line, errstr);
57154 return;
57155 }
57156- ACCESS_ONCE(trans->transaction->aborted) = errno;
57157+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57158 /* Wake up anybody who may be waiting on this transaction */
57159 wake_up(&root->fs_info->transaction_wait);
57160 wake_up(&root->fs_info->transaction_blocked_wait);
57161diff --git a/fs/buffer.c b/fs/buffer.c
57162index aeeea65..7651d590 100644
57163--- a/fs/buffer.c
57164+++ b/fs/buffer.c
57165@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57166 bh_cachep = kmem_cache_create("buffer_head",
57167 sizeof(struct buffer_head), 0,
57168 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57169- SLAB_MEM_SPREAD),
57170+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57171 NULL);
57172
57173 /*
57174diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57175index 622f469..e8d2d55 100644
57176--- a/fs/cachefiles/bind.c
57177+++ b/fs/cachefiles/bind.c
57178@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57179 args);
57180
57181 /* start by checking things over */
57182- ASSERT(cache->fstop_percent >= 0 &&
57183- cache->fstop_percent < cache->fcull_percent &&
57184+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57185 cache->fcull_percent < cache->frun_percent &&
57186 cache->frun_percent < 100);
57187
57188- ASSERT(cache->bstop_percent >= 0 &&
57189- cache->bstop_percent < cache->bcull_percent &&
57190+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57191 cache->bcull_percent < cache->brun_percent &&
57192 cache->brun_percent < 100);
57193
57194diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57195index 0a1467b..6a53245 100644
57196--- a/fs/cachefiles/daemon.c
57197+++ b/fs/cachefiles/daemon.c
57198@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57199 if (n > buflen)
57200 return -EMSGSIZE;
57201
57202- if (copy_to_user(_buffer, buffer, n) != 0)
57203+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57204 return -EFAULT;
57205
57206 return n;
57207@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57208 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57209 return -EIO;
57210
57211- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57212+ if (datalen > PAGE_SIZE - 1)
57213 return -EOPNOTSUPP;
57214
57215 /* drag the command string into the kernel so we can parse it */
57216@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57217 if (args[0] != '%' || args[1] != '\0')
57218 return -EINVAL;
57219
57220- if (fstop < 0 || fstop >= cache->fcull_percent)
57221+ if (fstop >= cache->fcull_percent)
57222 return cachefiles_daemon_range_error(cache, args);
57223
57224 cache->fstop_percent = fstop;
57225@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57226 if (args[0] != '%' || args[1] != '\0')
57227 return -EINVAL;
57228
57229- if (bstop < 0 || bstop >= cache->bcull_percent)
57230+ if (bstop >= cache->bcull_percent)
57231 return cachefiles_daemon_range_error(cache, args);
57232
57233 cache->bstop_percent = bstop;
57234diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57235index 5349473..d6c0b93 100644
57236--- a/fs/cachefiles/internal.h
57237+++ b/fs/cachefiles/internal.h
57238@@ -59,7 +59,7 @@ struct cachefiles_cache {
57239 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57240 struct rb_root active_nodes; /* active nodes (can't be culled) */
57241 rwlock_t active_lock; /* lock for active_nodes */
57242- atomic_t gravecounter; /* graveyard uniquifier */
57243+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57244 unsigned frun_percent; /* when to stop culling (% files) */
57245 unsigned fcull_percent; /* when to start culling (% files) */
57246 unsigned fstop_percent; /* when to stop allocating (% files) */
57247@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57248 * proc.c
57249 */
57250 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57251-extern atomic_t cachefiles_lookup_histogram[HZ];
57252-extern atomic_t cachefiles_mkdir_histogram[HZ];
57253-extern atomic_t cachefiles_create_histogram[HZ];
57254+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57255+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57256+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57257
57258 extern int __init cachefiles_proc_init(void);
57259 extern void cachefiles_proc_cleanup(void);
57260 static inline
57261-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57262+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57263 {
57264 unsigned long jif = jiffies - start_jif;
57265 if (jif >= HZ)
57266 jif = HZ - 1;
57267- atomic_inc(&histogram[jif]);
57268+ atomic_inc_unchecked(&histogram[jif]);
57269 }
57270
57271 #else
57272diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57273index ca65f39..48921e3 100644
57274--- a/fs/cachefiles/namei.c
57275+++ b/fs/cachefiles/namei.c
57276@@ -317,7 +317,7 @@ try_again:
57277 /* first step is to make up a grave dentry in the graveyard */
57278 sprintf(nbuffer, "%08x%08x",
57279 (uint32_t) get_seconds(),
57280- (uint32_t) atomic_inc_return(&cache->gravecounter));
57281+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57282
57283 /* do the multiway lock magic */
57284 trap = lock_rename(cache->graveyard, dir);
57285diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57286index eccd339..4c1d995 100644
57287--- a/fs/cachefiles/proc.c
57288+++ b/fs/cachefiles/proc.c
57289@@ -14,9 +14,9 @@
57290 #include <linux/seq_file.h>
57291 #include "internal.h"
57292
57293-atomic_t cachefiles_lookup_histogram[HZ];
57294-atomic_t cachefiles_mkdir_histogram[HZ];
57295-atomic_t cachefiles_create_histogram[HZ];
57296+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57297+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57298+atomic_unchecked_t cachefiles_create_histogram[HZ];
57299
57300 /*
57301 * display the latency histogram
57302@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57303 return 0;
57304 default:
57305 index = (unsigned long) v - 3;
57306- x = atomic_read(&cachefiles_lookup_histogram[index]);
57307- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57308- z = atomic_read(&cachefiles_create_histogram[index]);
57309+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57310+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57311+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57312 if (x == 0 && y == 0 && z == 0)
57313 return 0;
57314
57315diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57316index ebaff36..7e3ea26 100644
57317--- a/fs/cachefiles/rdwr.c
57318+++ b/fs/cachefiles/rdwr.c
57319@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57320 old_fs = get_fs();
57321 set_fs(KERNEL_DS);
57322 ret = file->f_op->write(
57323- file, (const void __user *) data, len, &pos);
57324+ file, (const void __force_user *) data, len, &pos);
57325 set_fs(old_fs);
57326 kunmap(page);
57327 file_end_write(file);
57328diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57329index 2a0bcae..34ec24e 100644
57330--- a/fs/ceph/dir.c
57331+++ b/fs/ceph/dir.c
57332@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57333 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57334 struct ceph_mds_client *mdsc = fsc->mdsc;
57335 unsigned frag = fpos_frag(ctx->pos);
57336- int off = fpos_off(ctx->pos);
57337+ unsigned int off = fpos_off(ctx->pos);
57338 int err;
57339 u32 ftype;
57340 struct ceph_mds_reply_info_parsed *rinfo;
57341diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57342index 6a0951e..03fac6d 100644
57343--- a/fs/ceph/super.c
57344+++ b/fs/ceph/super.c
57345@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57346 /*
57347 * construct our own bdi so we can control readahead, etc.
57348 */
57349-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57350+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57351
57352 static int ceph_register_bdi(struct super_block *sb,
57353 struct ceph_fs_client *fsc)
57354@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57355 default_backing_dev_info.ra_pages;
57356
57357 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57358- atomic_long_inc_return(&bdi_seq));
57359+ atomic_long_inc_return_unchecked(&bdi_seq));
57360 if (!err)
57361 sb->s_bdi = &fsc->backing_dev_info;
57362 return err;
57363diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57364index f3ac415..3d2420c 100644
57365--- a/fs/cifs/cifs_debug.c
57366+++ b/fs/cifs/cifs_debug.c
57367@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57368
57369 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57370 #ifdef CONFIG_CIFS_STATS2
57371- atomic_set(&totBufAllocCount, 0);
57372- atomic_set(&totSmBufAllocCount, 0);
57373+ atomic_set_unchecked(&totBufAllocCount, 0);
57374+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57375 #endif /* CONFIG_CIFS_STATS2 */
57376 spin_lock(&cifs_tcp_ses_lock);
57377 list_for_each(tmp1, &cifs_tcp_ses_list) {
57378@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57379 tcon = list_entry(tmp3,
57380 struct cifs_tcon,
57381 tcon_list);
57382- atomic_set(&tcon->num_smbs_sent, 0);
57383+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57384 if (server->ops->clear_stats)
57385 server->ops->clear_stats(tcon);
57386 }
57387@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57388 smBufAllocCount.counter, cifs_min_small);
57389 #ifdef CONFIG_CIFS_STATS2
57390 seq_printf(m, "Total Large %d Small %d Allocations\n",
57391- atomic_read(&totBufAllocCount),
57392- atomic_read(&totSmBufAllocCount));
57393+ atomic_read_unchecked(&totBufAllocCount),
57394+ atomic_read_unchecked(&totSmBufAllocCount));
57395 #endif /* CONFIG_CIFS_STATS2 */
57396
57397 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57398@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57399 if (tcon->need_reconnect)
57400 seq_puts(m, "\tDISCONNECTED ");
57401 seq_printf(m, "\nSMBs: %d",
57402- atomic_read(&tcon->num_smbs_sent));
57403+ atomic_read_unchecked(&tcon->num_smbs_sent));
57404 if (server->ops->print_stats)
57405 server->ops->print_stats(m, tcon);
57406 }
57407diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57408index 849f613..eae6dec 100644
57409--- a/fs/cifs/cifsfs.c
57410+++ b/fs/cifs/cifsfs.c
57411@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57412 */
57413 cifs_req_cachep = kmem_cache_create("cifs_request",
57414 CIFSMaxBufSize + max_hdr_size, 0,
57415- SLAB_HWCACHE_ALIGN, NULL);
57416+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57417 if (cifs_req_cachep == NULL)
57418 return -ENOMEM;
57419
57420@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57421 efficient to alloc 1 per page off the slab compared to 17K (5page)
57422 alloc of large cifs buffers even when page debugging is on */
57423 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57424- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57425+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57426 NULL);
57427 if (cifs_sm_req_cachep == NULL) {
57428 mempool_destroy(cifs_req_poolp);
57429@@ -1168,8 +1168,8 @@ init_cifs(void)
57430 atomic_set(&bufAllocCount, 0);
57431 atomic_set(&smBufAllocCount, 0);
57432 #ifdef CONFIG_CIFS_STATS2
57433- atomic_set(&totBufAllocCount, 0);
57434- atomic_set(&totSmBufAllocCount, 0);
57435+ atomic_set_unchecked(&totBufAllocCount, 0);
57436+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57437 #endif /* CONFIG_CIFS_STATS2 */
57438
57439 atomic_set(&midCount, 0);
57440diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57441index 579c6d5..95b6d03353 100644
57442--- a/fs/cifs/cifsglob.h
57443+++ b/fs/cifs/cifsglob.h
57444@@ -797,35 +797,35 @@ struct cifs_tcon {
57445 __u16 Flags; /* optional support bits */
57446 enum statusEnum tidStatus;
57447 #ifdef CONFIG_CIFS_STATS
57448- atomic_t num_smbs_sent;
57449+ atomic_unchecked_t num_smbs_sent;
57450 union {
57451 struct {
57452- atomic_t num_writes;
57453- atomic_t num_reads;
57454- atomic_t num_flushes;
57455- atomic_t num_oplock_brks;
57456- atomic_t num_opens;
57457- atomic_t num_closes;
57458- atomic_t num_deletes;
57459- atomic_t num_mkdirs;
57460- atomic_t num_posixopens;
57461- atomic_t num_posixmkdirs;
57462- atomic_t num_rmdirs;
57463- atomic_t num_renames;
57464- atomic_t num_t2renames;
57465- atomic_t num_ffirst;
57466- atomic_t num_fnext;
57467- atomic_t num_fclose;
57468- atomic_t num_hardlinks;
57469- atomic_t num_symlinks;
57470- atomic_t num_locks;
57471- atomic_t num_acl_get;
57472- atomic_t num_acl_set;
57473+ atomic_unchecked_t num_writes;
57474+ atomic_unchecked_t num_reads;
57475+ atomic_unchecked_t num_flushes;
57476+ atomic_unchecked_t num_oplock_brks;
57477+ atomic_unchecked_t num_opens;
57478+ atomic_unchecked_t num_closes;
57479+ atomic_unchecked_t num_deletes;
57480+ atomic_unchecked_t num_mkdirs;
57481+ atomic_unchecked_t num_posixopens;
57482+ atomic_unchecked_t num_posixmkdirs;
57483+ atomic_unchecked_t num_rmdirs;
57484+ atomic_unchecked_t num_renames;
57485+ atomic_unchecked_t num_t2renames;
57486+ atomic_unchecked_t num_ffirst;
57487+ atomic_unchecked_t num_fnext;
57488+ atomic_unchecked_t num_fclose;
57489+ atomic_unchecked_t num_hardlinks;
57490+ atomic_unchecked_t num_symlinks;
57491+ atomic_unchecked_t num_locks;
57492+ atomic_unchecked_t num_acl_get;
57493+ atomic_unchecked_t num_acl_set;
57494 } cifs_stats;
57495 #ifdef CONFIG_CIFS_SMB2
57496 struct {
57497- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57498- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57499+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57500+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57501 } smb2_stats;
57502 #endif /* CONFIG_CIFS_SMB2 */
57503 } stats;
57504@@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57505 }
57506
57507 #ifdef CONFIG_CIFS_STATS
57508-#define cifs_stats_inc atomic_inc
57509+#define cifs_stats_inc atomic_inc_unchecked
57510
57511 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57512 unsigned int bytes)
57513@@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57514 /* Various Debug counters */
57515 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57516 #ifdef CONFIG_CIFS_STATS2
57517-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57518-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57519+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57520+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57521 #endif
57522 GLOBAL_EXTERN atomic_t smBufAllocCount;
57523 GLOBAL_EXTERN atomic_t midCount;
57524diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57525index a1c9ead..63e4c62 100644
57526--- a/fs/cifs/file.c
57527+++ b/fs/cifs/file.c
57528@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57529 index = mapping->writeback_index; /* Start from prev offset */
57530 end = -1;
57531 } else {
57532- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57533- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57534- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57535+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57536 range_whole = true;
57537+ index = 0;
57538+ end = ULONG_MAX;
57539+ } else {
57540+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57541+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57542+ }
57543 scanned = true;
57544 }
57545 retry:
57546diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57547index 2f9f379..43f8025 100644
57548--- a/fs/cifs/misc.c
57549+++ b/fs/cifs/misc.c
57550@@ -170,7 +170,7 @@ cifs_buf_get(void)
57551 memset(ret_buf, 0, buf_size + 3);
57552 atomic_inc(&bufAllocCount);
57553 #ifdef CONFIG_CIFS_STATS2
57554- atomic_inc(&totBufAllocCount);
57555+ atomic_inc_unchecked(&totBufAllocCount);
57556 #endif /* CONFIG_CIFS_STATS2 */
57557 }
57558
57559@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57560 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57561 atomic_inc(&smBufAllocCount);
57562 #ifdef CONFIG_CIFS_STATS2
57563- atomic_inc(&totSmBufAllocCount);
57564+ atomic_inc_unchecked(&totSmBufAllocCount);
57565 #endif /* CONFIG_CIFS_STATS2 */
57566
57567 }
57568diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57569index ffc9ef9..b3c992b 100644
57570--- a/fs/cifs/smb1ops.c
57571+++ b/fs/cifs/smb1ops.c
57572@@ -609,27 +609,27 @@ static void
57573 cifs_clear_stats(struct cifs_tcon *tcon)
57574 {
57575 #ifdef CONFIG_CIFS_STATS
57576- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57577- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57578- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57579- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57580- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57581- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57582- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57583- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57584- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57585- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57586- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57587- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57588- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57589- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57590- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57591- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57592- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57593- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57594- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57595- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57596- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57597+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57598+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57599+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57600+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57601+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57602+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57603+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57604+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57605+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57606+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57607+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57608+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57609+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57610+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57611+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57612+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57613+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57614+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57615+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57616+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57617+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57618 #endif
57619 }
57620
57621@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57622 {
57623 #ifdef CONFIG_CIFS_STATS
57624 seq_printf(m, " Oplocks breaks: %d",
57625- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57626+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57627 seq_printf(m, "\nReads: %d Bytes: %llu",
57628- atomic_read(&tcon->stats.cifs_stats.num_reads),
57629+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57630 (long long)(tcon->bytes_read));
57631 seq_printf(m, "\nWrites: %d Bytes: %llu",
57632- atomic_read(&tcon->stats.cifs_stats.num_writes),
57633+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57634 (long long)(tcon->bytes_written));
57635 seq_printf(m, "\nFlushes: %d",
57636- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57637+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57638 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57639- atomic_read(&tcon->stats.cifs_stats.num_locks),
57640- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57641- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57642+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57643+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57644+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57645 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57646- atomic_read(&tcon->stats.cifs_stats.num_opens),
57647- atomic_read(&tcon->stats.cifs_stats.num_closes),
57648- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57649+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57650+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57651+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57652 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57653- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57654- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57655+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57656+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57657 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57658- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57659- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57660+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57661+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57662 seq_printf(m, "\nRenames: %d T2 Renames %d",
57663- atomic_read(&tcon->stats.cifs_stats.num_renames),
57664- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57665+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57666+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57667 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57668- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57669- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57670- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57671+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57672+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57673+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57674 #endif
57675 }
57676
57677diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57678index 192f51a..539307e 100644
57679--- a/fs/cifs/smb2ops.c
57680+++ b/fs/cifs/smb2ops.c
57681@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57682 #ifdef CONFIG_CIFS_STATS
57683 int i;
57684 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57685- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57686- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57687+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57688+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57689 }
57690 #endif
57691 }
57692@@ -405,65 +405,65 @@ static void
57693 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57694 {
57695 #ifdef CONFIG_CIFS_STATS
57696- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57697- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57698+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57699+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57700 seq_printf(m, "\nNegotiates: %d sent %d failed",
57701- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57702- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57703+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57704+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57705 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57706- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57707- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57708+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57709+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57710 seq_printf(m, "\nLogoffs: %d sent %d failed",
57711- atomic_read(&sent[SMB2_LOGOFF_HE]),
57712- atomic_read(&failed[SMB2_LOGOFF_HE]));
57713+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57714+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57715 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57716- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57717- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57718+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57719+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57720 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57721- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57722- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57723+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57724+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57725 seq_printf(m, "\nCreates: %d sent %d failed",
57726- atomic_read(&sent[SMB2_CREATE_HE]),
57727- atomic_read(&failed[SMB2_CREATE_HE]));
57728+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57729+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57730 seq_printf(m, "\nCloses: %d sent %d failed",
57731- atomic_read(&sent[SMB2_CLOSE_HE]),
57732- atomic_read(&failed[SMB2_CLOSE_HE]));
57733+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57734+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57735 seq_printf(m, "\nFlushes: %d sent %d failed",
57736- atomic_read(&sent[SMB2_FLUSH_HE]),
57737- atomic_read(&failed[SMB2_FLUSH_HE]));
57738+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57739+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57740 seq_printf(m, "\nReads: %d sent %d failed",
57741- atomic_read(&sent[SMB2_READ_HE]),
57742- atomic_read(&failed[SMB2_READ_HE]));
57743+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57744+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57745 seq_printf(m, "\nWrites: %d sent %d failed",
57746- atomic_read(&sent[SMB2_WRITE_HE]),
57747- atomic_read(&failed[SMB2_WRITE_HE]));
57748+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57749+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57750 seq_printf(m, "\nLocks: %d sent %d failed",
57751- atomic_read(&sent[SMB2_LOCK_HE]),
57752- atomic_read(&failed[SMB2_LOCK_HE]));
57753+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57754+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57755 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57756- atomic_read(&sent[SMB2_IOCTL_HE]),
57757- atomic_read(&failed[SMB2_IOCTL_HE]));
57758+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57759+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57760 seq_printf(m, "\nCancels: %d sent %d failed",
57761- atomic_read(&sent[SMB2_CANCEL_HE]),
57762- atomic_read(&failed[SMB2_CANCEL_HE]));
57763+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57764+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57765 seq_printf(m, "\nEchos: %d sent %d failed",
57766- atomic_read(&sent[SMB2_ECHO_HE]),
57767- atomic_read(&failed[SMB2_ECHO_HE]));
57768+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57769+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57770 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57771- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57772- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57773+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57774+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57775 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57776- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57777- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57778+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57779+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57780 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57781- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57782- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57783+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57784+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57785 seq_printf(m, "\nSetInfos: %d sent %d failed",
57786- atomic_read(&sent[SMB2_SET_INFO_HE]),
57787- atomic_read(&failed[SMB2_SET_INFO_HE]));
57788+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57789+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57790 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57791- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57792- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57793+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57794+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57795 #endif
57796 }
57797
57798diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57799index 787e171..31dcd0a 100644
57800--- a/fs/cifs/smb2pdu.c
57801+++ b/fs/cifs/smb2pdu.c
57802@@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57803 default:
57804 cifs_dbg(VFS, "info level %u isn't supported\n",
57805 srch_inf->info_level);
57806- rc = -EINVAL;
57807- goto qdir_exit;
57808+ return -EINVAL;
57809 }
57810
57811 req->FileIndex = cpu_to_le32(index);
57812diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57813index 1da168c..8bc7ff6 100644
57814--- a/fs/coda/cache.c
57815+++ b/fs/coda/cache.c
57816@@ -24,7 +24,7 @@
57817 #include "coda_linux.h"
57818 #include "coda_cache.h"
57819
57820-static atomic_t permission_epoch = ATOMIC_INIT(0);
57821+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57822
57823 /* replace or extend an acl cache hit */
57824 void coda_cache_enter(struct inode *inode, int mask)
57825@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57826 struct coda_inode_info *cii = ITOC(inode);
57827
57828 spin_lock(&cii->c_lock);
57829- cii->c_cached_epoch = atomic_read(&permission_epoch);
57830+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57831 if (!uid_eq(cii->c_uid, current_fsuid())) {
57832 cii->c_uid = current_fsuid();
57833 cii->c_cached_perm = mask;
57834@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57835 {
57836 struct coda_inode_info *cii = ITOC(inode);
57837 spin_lock(&cii->c_lock);
57838- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57839+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57840 spin_unlock(&cii->c_lock);
57841 }
57842
57843 /* remove all acl caches */
57844 void coda_cache_clear_all(struct super_block *sb)
57845 {
57846- atomic_inc(&permission_epoch);
57847+ atomic_inc_unchecked(&permission_epoch);
57848 }
57849
57850
57851@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57852 spin_lock(&cii->c_lock);
57853 hit = (mask & cii->c_cached_perm) == mask &&
57854 uid_eq(cii->c_uid, current_fsuid()) &&
57855- cii->c_cached_epoch == atomic_read(&permission_epoch);
57856+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57857 spin_unlock(&cii->c_lock);
57858
57859 return hit;
57860diff --git a/fs/compat.c b/fs/compat.c
57861index 6af20de..fec3fbb 100644
57862--- a/fs/compat.c
57863+++ b/fs/compat.c
57864@@ -54,7 +54,7 @@
57865 #include <asm/ioctls.h>
57866 #include "internal.h"
57867
57868-int compat_log = 1;
57869+int compat_log = 0;
57870
57871 int compat_printk(const char *fmt, ...)
57872 {
57873@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57874
57875 set_fs(KERNEL_DS);
57876 /* The __user pointer cast is valid because of the set_fs() */
57877- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57878+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57879 set_fs(oldfs);
57880 /* truncating is ok because it's a user address */
57881 if (!ret)
57882@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57883 goto out;
57884
57885 ret = -EINVAL;
57886- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57887+ if (nr_segs > UIO_MAXIOV)
57888 goto out;
57889 if (nr_segs > fast_segs) {
57890 ret = -ENOMEM;
57891@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57892 struct compat_readdir_callback {
57893 struct dir_context ctx;
57894 struct compat_old_linux_dirent __user *dirent;
57895+ struct file * file;
57896 int result;
57897 };
57898
57899@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57900 buf->result = -EOVERFLOW;
57901 return -EOVERFLOW;
57902 }
57903+
57904+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57905+ return 0;
57906+
57907 buf->result++;
57908 dirent = buf->dirent;
57909 if (!access_ok(VERIFY_WRITE, dirent,
57910@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57911 if (!f.file)
57912 return -EBADF;
57913
57914+ buf.file = f.file;
57915 error = iterate_dir(f.file, &buf.ctx);
57916 if (buf.result)
57917 error = buf.result;
57918@@ -901,6 +907,7 @@ struct compat_getdents_callback {
57919 struct dir_context ctx;
57920 struct compat_linux_dirent __user *current_dir;
57921 struct compat_linux_dirent __user *previous;
57922+ struct file * file;
57923 int count;
57924 int error;
57925 };
57926@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57927 buf->error = -EOVERFLOW;
57928 return -EOVERFLOW;
57929 }
57930+
57931+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57932+ return 0;
57933+
57934 dirent = buf->previous;
57935 if (dirent) {
57936 if (__put_user(offset, &dirent->d_off))
57937@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57938 if (!f.file)
57939 return -EBADF;
57940
57941+ buf.file = f.file;
57942 error = iterate_dir(f.file, &buf.ctx);
57943 if (error >= 0)
57944 error = buf.error;
57945@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57946 struct dir_context ctx;
57947 struct linux_dirent64 __user *current_dir;
57948 struct linux_dirent64 __user *previous;
57949+ struct file * file;
57950 int count;
57951 int error;
57952 };
57953@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57954 buf->error = -EINVAL; /* only used if we fail.. */
57955 if (reclen > buf->count)
57956 return -EINVAL;
57957+
57958+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57959+ return 0;
57960+
57961 dirent = buf->previous;
57962
57963 if (dirent) {
57964@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57965 if (!f.file)
57966 return -EBADF;
57967
57968+ buf.file = f.file;
57969 error = iterate_dir(f.file, &buf.ctx);
57970 if (error >= 0)
57971 error = buf.error;
57972diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57973index a81147e..20bf2b5 100644
57974--- a/fs/compat_binfmt_elf.c
57975+++ b/fs/compat_binfmt_elf.c
57976@@ -30,11 +30,13 @@
57977 #undef elf_phdr
57978 #undef elf_shdr
57979 #undef elf_note
57980+#undef elf_dyn
57981 #undef elf_addr_t
57982 #define elfhdr elf32_hdr
57983 #define elf_phdr elf32_phdr
57984 #define elf_shdr elf32_shdr
57985 #define elf_note elf32_note
57986+#define elf_dyn Elf32_Dyn
57987 #define elf_addr_t Elf32_Addr
57988
57989 /*
57990diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57991index dc52e13..ec61057 100644
57992--- a/fs/compat_ioctl.c
57993+++ b/fs/compat_ioctl.c
57994@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57995 return -EFAULT;
57996 if (__get_user(udata, &ss32->iomem_base))
57997 return -EFAULT;
57998- ss.iomem_base = compat_ptr(udata);
57999+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58000 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58001 __get_user(ss.port_high, &ss32->port_high))
58002 return -EFAULT;
58003@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58004 for (i = 0; i < nmsgs; i++) {
58005 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58006 return -EFAULT;
58007- if (get_user(datap, &umsgs[i].buf) ||
58008- put_user(compat_ptr(datap), &tmsgs[i].buf))
58009+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58010+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58011 return -EFAULT;
58012 }
58013 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58014@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
58015 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58016 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58017 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58018- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58019+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58020 return -EFAULT;
58021
58022 return ioctl_preallocate(file, p);
58023@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
58024 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58025 {
58026 unsigned int a, b;
58027- a = *(unsigned int *)p;
58028- b = *(unsigned int *)q;
58029+ a = *(const unsigned int *)p;
58030+ b = *(const unsigned int *)q;
58031 if (a > b)
58032 return 1;
58033 if (a < b)
58034diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58035index e081acb..911df21 100644
58036--- a/fs/configfs/dir.c
58037+++ b/fs/configfs/dir.c
58038@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58039 }
58040 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58041 struct configfs_dirent *next;
58042- const char *name;
58043+ const unsigned char * name;
58044+ char d_name[sizeof(next->s_dentry->d_iname)];
58045 int len;
58046 struct inode *inode = NULL;
58047
58048@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58049 continue;
58050
58051 name = configfs_get_name(next);
58052- len = strlen(name);
58053+ if (next->s_dentry && name == next->s_dentry->d_iname) {
58054+ len = next->s_dentry->d_name.len;
58055+ memcpy(d_name, name, len);
58056+ name = d_name;
58057+ } else
58058+ len = strlen(name);
58059
58060 /*
58061 * We'll have a dentry and an inode for
58062diff --git a/fs/coredump.c b/fs/coredump.c
58063index bc3fbcd..6031650 100644
58064--- a/fs/coredump.c
58065+++ b/fs/coredump.c
58066@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
58067 struct pipe_inode_info *pipe = file->private_data;
58068
58069 pipe_lock(pipe);
58070- pipe->readers++;
58071- pipe->writers--;
58072+ atomic_inc(&pipe->readers);
58073+ atomic_dec(&pipe->writers);
58074 wake_up_interruptible_sync(&pipe->wait);
58075 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58076 pipe_unlock(pipe);
58077@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
58078 * We actually want wait_event_freezable() but then we need
58079 * to clear TIF_SIGPENDING and improve dump_interrupted().
58080 */
58081- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58082+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58083
58084 pipe_lock(pipe);
58085- pipe->readers--;
58086- pipe->writers++;
58087+ atomic_dec(&pipe->readers);
58088+ atomic_inc(&pipe->writers);
58089 pipe_unlock(pipe);
58090 }
58091
58092@@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
58093 struct files_struct *displaced;
58094 bool need_nonrelative = false;
58095 bool core_dumped = false;
58096- static atomic_t core_dump_count = ATOMIC_INIT(0);
58097+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58098+ long signr = siginfo->si_signo;
58099+ int dumpable;
58100 struct coredump_params cprm = {
58101 .siginfo = siginfo,
58102 .regs = signal_pt_regs(),
58103@@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
58104 .mm_flags = mm->flags,
58105 };
58106
58107- audit_core_dumps(siginfo->si_signo);
58108+ audit_core_dumps(signr);
58109+
58110+ dumpable = __get_dumpable(cprm.mm_flags);
58111+
58112+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58113+ gr_handle_brute_attach(dumpable);
58114
58115 binfmt = mm->binfmt;
58116 if (!binfmt || !binfmt->core_dump)
58117 goto fail;
58118- if (!__get_dumpable(cprm.mm_flags))
58119+ if (!dumpable)
58120 goto fail;
58121
58122 cred = prepare_creds();
58123@@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
58124 need_nonrelative = true;
58125 }
58126
58127- retval = coredump_wait(siginfo->si_signo, &core_state);
58128+ retval = coredump_wait(signr, &core_state);
58129 if (retval < 0)
58130 goto fail_creds;
58131
58132@@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
58133 }
58134 cprm.limit = RLIM_INFINITY;
58135
58136- dump_count = atomic_inc_return(&core_dump_count);
58137+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58138 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58139 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58140 task_tgid_vnr(current), current->comm);
58141@@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
58142 } else {
58143 struct inode *inode;
58144
58145+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58146+
58147 if (cprm.limit < binfmt->min_coredump)
58148 goto fail_unlock;
58149
58150@@ -669,7 +678,7 @@ close_fail:
58151 filp_close(cprm.file, NULL);
58152 fail_dropcount:
58153 if (ispipe)
58154- atomic_dec(&core_dump_count);
58155+ atomic_dec_unchecked(&core_dump_count);
58156 fail_unlock:
58157 kfree(cn.corename);
58158 coredump_finish(mm, core_dumped);
58159@@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58160 struct file *file = cprm->file;
58161 loff_t pos = file->f_pos;
58162 ssize_t n;
58163+
58164+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58165 if (cprm->written + nr > cprm->limit)
58166 return 0;
58167 while (nr) {
58168diff --git a/fs/dcache.c b/fs/dcache.c
58169index fdbe230..d852932 100644
58170--- a/fs/dcache.c
58171+++ b/fs/dcache.c
58172@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58173 */
58174 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58175 if (name->len > DNAME_INLINE_LEN-1) {
58176- dname = kmalloc(name->len + 1, GFP_KERNEL);
58177+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58178 if (!dname) {
58179 kmem_cache_free(dentry_cache, dentry);
58180 return NULL;
58181@@ -2833,9 +2833,9 @@ static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58182 u32 dlen = ACCESS_ONCE(name->len);
58183 char *p;
58184
58185- if (*buflen < dlen + 1)
58186- return -ENAMETOOLONG;
58187 *buflen -= dlen + 1;
58188+ if (*buflen < 0)
58189+ return -ENAMETOOLONG;
58190 p = *buffer -= dlen + 1;
58191 *p++ = '/';
58192 while (dlen--) {
58193@@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58194 mempages -= reserve;
58195
58196 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58197- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58198+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58199+ SLAB_NO_SANITIZE, NULL);
58200
58201 dcache_init();
58202 inode_init();
58203diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58204index 9c0444c..628490c 100644
58205--- a/fs/debugfs/inode.c
58206+++ b/fs/debugfs/inode.c
58207@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58208 */
58209 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58210 {
58211+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58212+ return __create_file(name, S_IFDIR | S_IRWXU,
58213+#else
58214 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58215+#endif
58216 parent, NULL, NULL);
58217 }
58218 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58219diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58220index c36c448..fc96710 100644
58221--- a/fs/ecryptfs/inode.c
58222+++ b/fs/ecryptfs/inode.c
58223@@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58224 old_fs = get_fs();
58225 set_fs(get_ds());
58226 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58227- (char __user *)lower_buf,
58228+ (char __force_user *)lower_buf,
58229 PATH_MAX);
58230 set_fs(old_fs);
58231 if (rc < 0)
58232diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58233index e4141f2..d8263e8 100644
58234--- a/fs/ecryptfs/miscdev.c
58235+++ b/fs/ecryptfs/miscdev.c
58236@@ -304,7 +304,7 @@ check_list:
58237 goto out_unlock_msg_ctx;
58238 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58239 if (msg_ctx->msg) {
58240- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58241+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58242 goto out_unlock_msg_ctx;
58243 i += packet_length_size;
58244 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58245diff --git a/fs/exec.c b/fs/exec.c
58246index 7ea097f..0158d8a 100644
58247--- a/fs/exec.c
58248+++ b/fs/exec.c
58249@@ -55,8 +55,20 @@
58250 #include <linux/pipe_fs_i.h>
58251 #include <linux/oom.h>
58252 #include <linux/compat.h>
58253+#include <linux/random.h>
58254+#include <linux/seq_file.h>
58255+#include <linux/coredump.h>
58256+#include <linux/mman.h>
58257+
58258+#ifdef CONFIG_PAX_REFCOUNT
58259+#include <linux/kallsyms.h>
58260+#include <linux/kdebug.h>
58261+#endif
58262+
58263+#include <trace/events/fs.h>
58264
58265 #include <asm/uaccess.h>
58266+#include <asm/sections.h>
58267 #include <asm/mmu_context.h>
58268 #include <asm/tlb.h>
58269
58270@@ -66,19 +78,34 @@
58271
58272 #include <trace/events/sched.h>
58273
58274+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58275+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58276+{
58277+ 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");
58278+}
58279+#endif
58280+
58281+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58282+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58283+EXPORT_SYMBOL(pax_set_initial_flags_func);
58284+#endif
58285+
58286 int suid_dumpable = 0;
58287
58288 static LIST_HEAD(formats);
58289 static DEFINE_RWLOCK(binfmt_lock);
58290
58291+extern int gr_process_kernel_exec_ban(void);
58292+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58293+
58294 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58295 {
58296 BUG_ON(!fmt);
58297 if (WARN_ON(!fmt->load_binary))
58298 return;
58299 write_lock(&binfmt_lock);
58300- insert ? list_add(&fmt->lh, &formats) :
58301- list_add_tail(&fmt->lh, &formats);
58302+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58303+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58304 write_unlock(&binfmt_lock);
58305 }
58306
58307@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58308 void unregister_binfmt(struct linux_binfmt * fmt)
58309 {
58310 write_lock(&binfmt_lock);
58311- list_del(&fmt->lh);
58312+ pax_list_del((struct list_head *)&fmt->lh);
58313 write_unlock(&binfmt_lock);
58314 }
58315
58316@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58317 int write)
58318 {
58319 struct page *page;
58320- int ret;
58321
58322-#ifdef CONFIG_STACK_GROWSUP
58323- if (write) {
58324- ret = expand_downwards(bprm->vma, pos);
58325- if (ret < 0)
58326- return NULL;
58327- }
58328-#endif
58329- ret = get_user_pages(current, bprm->mm, pos,
58330- 1, write, 1, &page, NULL);
58331- if (ret <= 0)
58332+ if (0 > expand_downwards(bprm->vma, pos))
58333+ return NULL;
58334+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58335 return NULL;
58336
58337 if (write) {
58338@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58339 if (size <= ARG_MAX)
58340 return page;
58341
58342+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58343+ // only allow 512KB for argv+env on suid/sgid binaries
58344+ // to prevent easy ASLR exhaustion
58345+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58346+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58347+ (size > (512 * 1024))) {
58348+ put_page(page);
58349+ return NULL;
58350+ }
58351+#endif
58352+
58353 /*
58354 * Limit to 1/4-th the stack size for the argv+env strings.
58355 * This ensures that:
58356@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58357 vma->vm_end = STACK_TOP_MAX;
58358 vma->vm_start = vma->vm_end - PAGE_SIZE;
58359 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58360+
58361+#ifdef CONFIG_PAX_SEGMEXEC
58362+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58363+#endif
58364+
58365 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58366 INIT_LIST_HEAD(&vma->anon_vma_chain);
58367
58368@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58369 mm->stack_vm = mm->total_vm = 1;
58370 up_write(&mm->mmap_sem);
58371 bprm->p = vma->vm_end - sizeof(void *);
58372+
58373+#ifdef CONFIG_PAX_RANDUSTACK
58374+ if (randomize_va_space)
58375+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58376+#endif
58377+
58378 return 0;
58379 err:
58380 up_write(&mm->mmap_sem);
58381@@ -397,7 +438,7 @@ struct user_arg_ptr {
58382 } ptr;
58383 };
58384
58385-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58386+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58387 {
58388 const char __user *native;
58389
58390@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58391 compat_uptr_t compat;
58392
58393 if (get_user(compat, argv.ptr.compat + nr))
58394- return ERR_PTR(-EFAULT);
58395+ return (const char __force_user *)ERR_PTR(-EFAULT);
58396
58397 return compat_ptr(compat);
58398 }
58399 #endif
58400
58401 if (get_user(native, argv.ptr.native + nr))
58402- return ERR_PTR(-EFAULT);
58403+ return (const char __force_user *)ERR_PTR(-EFAULT);
58404
58405 return native;
58406 }
58407@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58408 if (!p)
58409 break;
58410
58411- if (IS_ERR(p))
58412+ if (IS_ERR((const char __force_kernel *)p))
58413 return -EFAULT;
58414
58415 if (i >= max)
58416@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58417
58418 ret = -EFAULT;
58419 str = get_user_arg_ptr(argv, argc);
58420- if (IS_ERR(str))
58421+ if (IS_ERR((const char __force_kernel *)str))
58422 goto out;
58423
58424 len = strnlen_user(str, MAX_ARG_STRLEN);
58425@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58426 int r;
58427 mm_segment_t oldfs = get_fs();
58428 struct user_arg_ptr argv = {
58429- .ptr.native = (const char __user *const __user *)__argv,
58430+ .ptr.native = (const char __user * const __force_user *)__argv,
58431 };
58432
58433 set_fs(KERNEL_DS);
58434@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58435 unsigned long new_end = old_end - shift;
58436 struct mmu_gather tlb;
58437
58438- BUG_ON(new_start > new_end);
58439+ if (new_start >= new_end || new_start < mmap_min_addr)
58440+ return -ENOMEM;
58441
58442 /*
58443 * ensure there are no vmas between where we want to go
58444@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58445 if (vma != find_vma(mm, new_start))
58446 return -EFAULT;
58447
58448+#ifdef CONFIG_PAX_SEGMEXEC
58449+ BUG_ON(pax_find_mirror_vma(vma));
58450+#endif
58451+
58452 /*
58453 * cover the whole range: [new_start, old_end)
58454 */
58455@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58456 stack_top = arch_align_stack(stack_top);
58457 stack_top = PAGE_ALIGN(stack_top);
58458
58459- if (unlikely(stack_top < mmap_min_addr) ||
58460- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58461- return -ENOMEM;
58462-
58463 stack_shift = vma->vm_end - stack_top;
58464
58465 bprm->p -= stack_shift;
58466@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58467 bprm->exec -= stack_shift;
58468
58469 down_write(&mm->mmap_sem);
58470+
58471+ /* Move stack pages down in memory. */
58472+ if (stack_shift) {
58473+ ret = shift_arg_pages(vma, stack_shift);
58474+ if (ret)
58475+ goto out_unlock;
58476+ }
58477+
58478 vm_flags = VM_STACK_FLAGS;
58479
58480+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58481+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58482+ vm_flags &= ~VM_EXEC;
58483+
58484+#ifdef CONFIG_PAX_MPROTECT
58485+ if (mm->pax_flags & MF_PAX_MPROTECT)
58486+ vm_flags &= ~VM_MAYEXEC;
58487+#endif
58488+
58489+ }
58490+#endif
58491+
58492 /*
58493 * Adjust stack execute permissions; explicitly enable for
58494 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58495@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58496 goto out_unlock;
58497 BUG_ON(prev != vma);
58498
58499- /* Move stack pages down in memory. */
58500- if (stack_shift) {
58501- ret = shift_arg_pages(vma, stack_shift);
58502- if (ret)
58503- goto out_unlock;
58504- }
58505-
58506 /* mprotect_fixup is overkill to remove the temporary stack flags */
58507 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58508
58509@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58510 #endif
58511 current->mm->start_stack = bprm->p;
58512 ret = expand_stack(vma, stack_base);
58513+
58514+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58515+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58516+ unsigned long size;
58517+ vm_flags_t vm_flags;
58518+
58519+ size = STACK_TOP - vma->vm_end;
58520+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58521+
58522+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58523+
58524+#ifdef CONFIG_X86
58525+ if (!ret) {
58526+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58527+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58528+ }
58529+#endif
58530+
58531+ }
58532+#endif
58533+
58534 if (ret)
58535 ret = -EFAULT;
58536
58537@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58538
58539 fsnotify_open(file);
58540
58541+ trace_open_exec(name);
58542+
58543 err = deny_write_access(file);
58544 if (err)
58545 goto exit;
58546@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58547 old_fs = get_fs();
58548 set_fs(get_ds());
58549 /* The cast to a user pointer is valid due to the set_fs() */
58550- result = vfs_read(file, (void __user *)addr, count, &pos);
58551+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58552 set_fs(old_fs);
58553 return result;
58554 }
58555@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58556 }
58557 rcu_read_unlock();
58558
58559- if (p->fs->users > n_fs) {
58560+ if (atomic_read(&p->fs->users) > n_fs) {
58561 bprm->unsafe |= LSM_UNSAFE_SHARE;
58562 } else {
58563 res = -EAGAIN;
58564@@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58565 return ret;
58566 }
58567
58568+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58569+static DEFINE_PER_CPU(u64, exec_counter);
58570+static int __init init_exec_counters(void)
58571+{
58572+ unsigned int cpu;
58573+
58574+ for_each_possible_cpu(cpu) {
58575+ per_cpu(exec_counter, cpu) = (u64)cpu;
58576+ }
58577+
58578+ return 0;
58579+}
58580+early_initcall(init_exec_counters);
58581+static inline void increment_exec_counter(void)
58582+{
58583+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58584+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58585+}
58586+#else
58587+static inline void increment_exec_counter(void) {}
58588+#endif
58589+
58590+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58591+ struct user_arg_ptr argv);
58592+
58593 /*
58594 * sys_execve() executes a new program.
58595 */
58596@@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58597 struct user_arg_ptr argv,
58598 struct user_arg_ptr envp)
58599 {
58600+#ifdef CONFIG_GRKERNSEC
58601+ struct file *old_exec_file;
58602+ struct acl_subject_label *old_acl;
58603+ struct rlimit old_rlim[RLIM_NLIMITS];
58604+#endif
58605 struct linux_binprm *bprm;
58606 struct file *file;
58607 struct files_struct *displaced;
58608 bool clear_in_exec;
58609 int retval;
58610
58611+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58612+
58613 /*
58614 * We move the actual failure in case of RLIMIT_NPROC excess from
58615 * set*uid() to execve() because too many poorly written programs
58616@@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58617 if (IS_ERR(file))
58618 goto out_unmark;
58619
58620+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58621+ retval = -EPERM;
58622+ goto out_file;
58623+ }
58624+
58625 sched_exec();
58626
58627 bprm->file = file;
58628 bprm->filename = filename;
58629 bprm->interp = filename;
58630
58631+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58632+ retval = -EACCES;
58633+ goto out_file;
58634+ }
58635+
58636 retval = bprm_mm_init(bprm);
58637 if (retval)
58638 goto out_file;
58639@@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58640 if (retval < 0)
58641 goto out;
58642
58643+#ifdef CONFIG_GRKERNSEC
58644+ old_acl = current->acl;
58645+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58646+ old_exec_file = current->exec_file;
58647+ get_file(file);
58648+ current->exec_file = file;
58649+#endif
58650+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58651+ /* limit suid stack to 8MB
58652+ * we saved the old limits above and will restore them if this exec fails
58653+ */
58654+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58655+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58656+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58657+#endif
58658+
58659+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58660+ retval = -EPERM;
58661+ goto out_fail;
58662+ }
58663+
58664+ if (!gr_tpe_allow(file)) {
58665+ retval = -EACCES;
58666+ goto out_fail;
58667+ }
58668+
58669+ if (gr_check_crash_exec(file)) {
58670+ retval = -EACCES;
58671+ goto out_fail;
58672+ }
58673+
58674+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58675+ bprm->unsafe);
58676+ if (retval < 0)
58677+ goto out_fail;
58678+
58679 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58680 if (retval < 0)
58681- goto out;
58682+ goto out_fail;
58683
58684 bprm->exec = bprm->p;
58685 retval = copy_strings(bprm->envc, envp, bprm);
58686 if (retval < 0)
58687- goto out;
58688+ goto out_fail;
58689
58690 retval = copy_strings(bprm->argc, argv, bprm);
58691 if (retval < 0)
58692- goto out;
58693+ goto out_fail;
58694+
58695+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58696+
58697+ gr_handle_exec_args(bprm, argv);
58698
58699 retval = exec_binprm(bprm);
58700 if (retval < 0)
58701- goto out;
58702+ goto out_fail;
58703+#ifdef CONFIG_GRKERNSEC
58704+ if (old_exec_file)
58705+ fput(old_exec_file);
58706+#endif
58707
58708 /* execve succeeded */
58709+
58710+ increment_exec_counter();
58711 current->fs->in_exec = 0;
58712 current->in_execve = 0;
58713 acct_update_integrals(current);
58714@@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58715 put_files_struct(displaced);
58716 return retval;
58717
58718+out_fail:
58719+#ifdef CONFIG_GRKERNSEC
58720+ current->acl = old_acl;
58721+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58722+ fput(current->exec_file);
58723+ current->exec_file = old_exec_file;
58724+#endif
58725+
58726 out:
58727 if (bprm->mm) {
58728 acct_arg_size(bprm, 0);
58729@@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58730 return error;
58731 }
58732 #endif
58733+
58734+int pax_check_flags(unsigned long *flags)
58735+{
58736+ int retval = 0;
58737+
58738+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58739+ if (*flags & MF_PAX_SEGMEXEC)
58740+ {
58741+ *flags &= ~MF_PAX_SEGMEXEC;
58742+ retval = -EINVAL;
58743+ }
58744+#endif
58745+
58746+ if ((*flags & MF_PAX_PAGEEXEC)
58747+
58748+#ifdef CONFIG_PAX_PAGEEXEC
58749+ && (*flags & MF_PAX_SEGMEXEC)
58750+#endif
58751+
58752+ )
58753+ {
58754+ *flags &= ~MF_PAX_PAGEEXEC;
58755+ retval = -EINVAL;
58756+ }
58757+
58758+ if ((*flags & MF_PAX_MPROTECT)
58759+
58760+#ifdef CONFIG_PAX_MPROTECT
58761+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58762+#endif
58763+
58764+ )
58765+ {
58766+ *flags &= ~MF_PAX_MPROTECT;
58767+ retval = -EINVAL;
58768+ }
58769+
58770+ if ((*flags & MF_PAX_EMUTRAMP)
58771+
58772+#ifdef CONFIG_PAX_EMUTRAMP
58773+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58774+#endif
58775+
58776+ )
58777+ {
58778+ *flags &= ~MF_PAX_EMUTRAMP;
58779+ retval = -EINVAL;
58780+ }
58781+
58782+ return retval;
58783+}
58784+
58785+EXPORT_SYMBOL(pax_check_flags);
58786+
58787+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58788+char *pax_get_path(const struct path *path, char *buf, int buflen)
58789+{
58790+ char *pathname = d_path(path, buf, buflen);
58791+
58792+ if (IS_ERR(pathname))
58793+ goto toolong;
58794+
58795+ pathname = mangle_path(buf, pathname, "\t\n\\");
58796+ if (!pathname)
58797+ goto toolong;
58798+
58799+ *pathname = 0;
58800+ return buf;
58801+
58802+toolong:
58803+ return "<path too long>";
58804+}
58805+EXPORT_SYMBOL(pax_get_path);
58806+
58807+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58808+{
58809+ struct task_struct *tsk = current;
58810+ struct mm_struct *mm = current->mm;
58811+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58812+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58813+ char *path_exec = NULL;
58814+ char *path_fault = NULL;
58815+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58816+ siginfo_t info = { };
58817+
58818+ if (buffer_exec && buffer_fault) {
58819+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58820+
58821+ down_read(&mm->mmap_sem);
58822+ vma = mm->mmap;
58823+ while (vma && (!vma_exec || !vma_fault)) {
58824+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58825+ vma_exec = vma;
58826+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58827+ vma_fault = vma;
58828+ vma = vma->vm_next;
58829+ }
58830+ if (vma_exec)
58831+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58832+ if (vma_fault) {
58833+ start = vma_fault->vm_start;
58834+ end = vma_fault->vm_end;
58835+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58836+ if (vma_fault->vm_file)
58837+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58838+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58839+ path_fault = "<heap>";
58840+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58841+ path_fault = "<stack>";
58842+ else
58843+ path_fault = "<anonymous mapping>";
58844+ }
58845+ up_read(&mm->mmap_sem);
58846+ }
58847+ if (tsk->signal->curr_ip)
58848+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58849+ else
58850+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58851+ 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),
58852+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58853+ free_page((unsigned long)buffer_exec);
58854+ free_page((unsigned long)buffer_fault);
58855+ pax_report_insns(regs, pc, sp);
58856+ info.si_signo = SIGKILL;
58857+ info.si_errno = 0;
58858+ info.si_code = SI_KERNEL;
58859+ info.si_pid = 0;
58860+ info.si_uid = 0;
58861+ do_coredump(&info);
58862+}
58863+#endif
58864+
58865+#ifdef CONFIG_PAX_REFCOUNT
58866+void pax_report_refcount_overflow(struct pt_regs *regs)
58867+{
58868+ if (current->signal->curr_ip)
58869+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58870+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58871+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58872+ else
58873+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58874+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58875+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58876+ preempt_disable();
58877+ show_regs(regs);
58878+ preempt_enable();
58879+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58880+}
58881+#endif
58882+
58883+#ifdef CONFIG_PAX_USERCOPY
58884+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58885+static noinline int check_stack_object(const void *obj, unsigned long len)
58886+{
58887+ const void * const stack = task_stack_page(current);
58888+ const void * const stackend = stack + THREAD_SIZE;
58889+
58890+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58891+ const void *frame = NULL;
58892+ const void *oldframe;
58893+#endif
58894+
58895+ if (obj + len < obj)
58896+ return -1;
58897+
58898+ if (obj + len <= stack || stackend <= obj)
58899+ return 0;
58900+
58901+ if (obj < stack || stackend < obj + len)
58902+ return -1;
58903+
58904+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58905+ oldframe = __builtin_frame_address(1);
58906+ if (oldframe)
58907+ frame = __builtin_frame_address(2);
58908+ /*
58909+ low ----------------------------------------------> high
58910+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58911+ ^----------------^
58912+ allow copies only within here
58913+ */
58914+ while (stack <= frame && frame < stackend) {
58915+ /* if obj + len extends past the last frame, this
58916+ check won't pass and the next frame will be 0,
58917+ causing us to bail out and correctly report
58918+ the copy as invalid
58919+ */
58920+ if (obj + len <= frame)
58921+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58922+ oldframe = frame;
58923+ frame = *(const void * const *)frame;
58924+ }
58925+ return -1;
58926+#else
58927+ return 1;
58928+#endif
58929+}
58930+
58931+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58932+{
58933+ if (current->signal->curr_ip)
58934+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58935+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58936+ else
58937+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58938+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58939+ dump_stack();
58940+ gr_handle_kernel_exploit();
58941+ do_group_exit(SIGKILL);
58942+}
58943+#endif
58944+
58945+#ifdef CONFIG_PAX_USERCOPY
58946+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58947+{
58948+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58949+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
58950+#ifdef CONFIG_MODULES
58951+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58952+#else
58953+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58954+#endif
58955+
58956+#else
58957+ unsigned long textlow = (unsigned long)_stext;
58958+ unsigned long texthigh = (unsigned long)_etext;
58959+
58960+#ifdef CONFIG_X86_64
58961+ /* check against linear mapping as well */
58962+ if (high > (unsigned long)__va(__pa(textlow)) &&
58963+ low <= (unsigned long)__va(__pa(texthigh)))
58964+ return true;
58965+#endif
58966+
58967+#endif
58968+
58969+ if (high <= textlow || low > texthigh)
58970+ return false;
58971+ else
58972+ return true;
58973+}
58974+#endif
58975+
58976+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58977+{
58978+
58979+#ifdef CONFIG_PAX_USERCOPY
58980+ const char *type;
58981+
58982+ if (!n)
58983+ return;
58984+
58985+ type = check_heap_object(ptr, n);
58986+ if (!type) {
58987+ int ret = check_stack_object(ptr, n);
58988+ if (ret == 1 || ret == 2)
58989+ return;
58990+ if (ret == 0) {
58991+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58992+ type = "<kernel text>";
58993+ else
58994+ return;
58995+ } else
58996+ type = "<process stack>";
58997+ }
58998+
58999+ pax_report_usercopy(ptr, n, to_user, type);
59000+#endif
59001+
59002+}
59003+EXPORT_SYMBOL(__check_object_size);
59004+
59005+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59006+void pax_track_stack(void)
59007+{
59008+ unsigned long sp = (unsigned long)&sp;
59009+ if (sp < current_thread_info()->lowest_stack &&
59010+ sp > (unsigned long)task_stack_page(current))
59011+ current_thread_info()->lowest_stack = sp;
59012+}
59013+EXPORT_SYMBOL(pax_track_stack);
59014+#endif
59015+
59016+#ifdef CONFIG_PAX_SIZE_OVERFLOW
59017+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59018+{
59019+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59020+ dump_stack();
59021+ do_group_exit(SIGKILL);
59022+}
59023+EXPORT_SYMBOL(report_size_overflow);
59024+#endif
59025diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59026index 9f9992b..8b59411 100644
59027--- a/fs/ext2/balloc.c
59028+++ b/fs/ext2/balloc.c
59029@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59030
59031 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59032 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59033- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59034+ if (free_blocks < root_blocks + 1 &&
59035 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59036 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59037- !in_group_p (sbi->s_resgid))) {
59038+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59039 return 0;
59040 }
59041 return 1;
59042diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59043index 2d7557d..14e38f94 100644
59044--- a/fs/ext2/xattr.c
59045+++ b/fs/ext2/xattr.c
59046@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59047 struct buffer_head *bh = NULL;
59048 struct ext2_xattr_entry *entry;
59049 char *end;
59050- size_t rest = buffer_size;
59051+ size_t rest = buffer_size, total_size = 0;
59052 int error;
59053
59054 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59055@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59056 buffer += size;
59057 }
59058 rest -= size;
59059+ total_size += size;
59060 }
59061 }
59062- error = buffer_size - rest; /* total size */
59063+ error = total_size;
59064
59065 cleanup:
59066 brelse(bh);
59067diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59068index 22548f5..41521d8 100644
59069--- a/fs/ext3/balloc.c
59070+++ b/fs/ext3/balloc.c
59071@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59072
59073 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59074 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59075- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59076+ if (free_blocks < root_blocks + 1 &&
59077 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59078 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59079- !in_group_p (sbi->s_resgid))) {
59080+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59081 return 0;
59082 }
59083 return 1;
59084diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59085index b1fc963..881228c 100644
59086--- a/fs/ext3/xattr.c
59087+++ b/fs/ext3/xattr.c
59088@@ -330,7 +330,7 @@ static int
59089 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59090 char *buffer, size_t buffer_size)
59091 {
59092- size_t rest = buffer_size;
59093+ size_t rest = buffer_size, total_size = 0;
59094
59095 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59096 const struct xattr_handler *handler =
59097@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59098 buffer += size;
59099 }
59100 rest -= size;
59101+ total_size += size;
59102 }
59103 }
59104- return buffer_size - rest;
59105+ return total_size;
59106 }
59107
59108 static int
59109diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59110index 6ea7b14..8fa16d9 100644
59111--- a/fs/ext4/balloc.c
59112+++ b/fs/ext4/balloc.c
59113@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59114 /* Hm, nope. Are (enough) root reserved clusters available? */
59115 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59116 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59117- capable(CAP_SYS_RESOURCE) ||
59118- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59119+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59120+ capable_nolog(CAP_SYS_RESOURCE)) {
59121
59122 if (free_clusters >= (nclusters + dirty_clusters +
59123 resv_clusters))
59124diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59125index d3a534f..242c50a 100644
59126--- a/fs/ext4/ext4.h
59127+++ b/fs/ext4/ext4.h
59128@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59129 unsigned long s_mb_last_start;
59130
59131 /* stats for buddy allocator */
59132- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59133- atomic_t s_bal_success; /* we found long enough chunks */
59134- atomic_t s_bal_allocated; /* in blocks */
59135- atomic_t s_bal_ex_scanned; /* total extents scanned */
59136- atomic_t s_bal_goals; /* goal hits */
59137- atomic_t s_bal_breaks; /* too long searches */
59138- atomic_t s_bal_2orders; /* 2^order hits */
59139+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59140+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59141+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59142+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59143+ atomic_unchecked_t s_bal_goals; /* goal hits */
59144+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59145+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59146 spinlock_t s_bal_lock;
59147 unsigned long s_mb_buddies_generated;
59148 unsigned long long s_mb_generation_time;
59149- atomic_t s_mb_lost_chunks;
59150- atomic_t s_mb_preallocated;
59151- atomic_t s_mb_discarded;
59152+ atomic_unchecked_t s_mb_lost_chunks;
59153+ atomic_unchecked_t s_mb_preallocated;
59154+ atomic_unchecked_t s_mb_discarded;
59155 atomic_t s_lock_busy;
59156
59157 /* locality groups */
59158diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59159index 04a5c75..09894fa 100644
59160--- a/fs/ext4/mballoc.c
59161+++ b/fs/ext4/mballoc.c
59162@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59163 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59164
59165 if (EXT4_SB(sb)->s_mb_stats)
59166- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59167+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59168
59169 break;
59170 }
59171@@ -2189,7 +2189,7 @@ repeat:
59172 ac->ac_status = AC_STATUS_CONTINUE;
59173 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59174 cr = 3;
59175- atomic_inc(&sbi->s_mb_lost_chunks);
59176+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59177 goto repeat;
59178 }
59179 }
59180@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59181 if (sbi->s_mb_stats) {
59182 ext4_msg(sb, KERN_INFO,
59183 "mballoc: %u blocks %u reqs (%u success)",
59184- atomic_read(&sbi->s_bal_allocated),
59185- atomic_read(&sbi->s_bal_reqs),
59186- atomic_read(&sbi->s_bal_success));
59187+ atomic_read_unchecked(&sbi->s_bal_allocated),
59188+ atomic_read_unchecked(&sbi->s_bal_reqs),
59189+ atomic_read_unchecked(&sbi->s_bal_success));
59190 ext4_msg(sb, KERN_INFO,
59191 "mballoc: %u extents scanned, %u goal hits, "
59192 "%u 2^N hits, %u breaks, %u lost",
59193- atomic_read(&sbi->s_bal_ex_scanned),
59194- atomic_read(&sbi->s_bal_goals),
59195- atomic_read(&sbi->s_bal_2orders),
59196- atomic_read(&sbi->s_bal_breaks),
59197- atomic_read(&sbi->s_mb_lost_chunks));
59198+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59199+ atomic_read_unchecked(&sbi->s_bal_goals),
59200+ atomic_read_unchecked(&sbi->s_bal_2orders),
59201+ atomic_read_unchecked(&sbi->s_bal_breaks),
59202+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59203 ext4_msg(sb, KERN_INFO,
59204 "mballoc: %lu generated and it took %Lu",
59205 sbi->s_mb_buddies_generated,
59206 sbi->s_mb_generation_time);
59207 ext4_msg(sb, KERN_INFO,
59208 "mballoc: %u preallocated, %u discarded",
59209- atomic_read(&sbi->s_mb_preallocated),
59210- atomic_read(&sbi->s_mb_discarded));
59211+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59212+ atomic_read_unchecked(&sbi->s_mb_discarded));
59213 }
59214
59215 free_percpu(sbi->s_locality_groups);
59216@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59217 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59218
59219 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59220- atomic_inc(&sbi->s_bal_reqs);
59221- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59222+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59223+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59224 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59225- atomic_inc(&sbi->s_bal_success);
59226- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59227+ atomic_inc_unchecked(&sbi->s_bal_success);
59228+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59229 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59230 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59231- atomic_inc(&sbi->s_bal_goals);
59232+ atomic_inc_unchecked(&sbi->s_bal_goals);
59233 if (ac->ac_found > sbi->s_mb_max_to_scan)
59234- atomic_inc(&sbi->s_bal_breaks);
59235+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59236 }
59237
59238 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59239@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59240 trace_ext4_mb_new_inode_pa(ac, pa);
59241
59242 ext4_mb_use_inode_pa(ac, pa);
59243- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59244+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59245
59246 ei = EXT4_I(ac->ac_inode);
59247 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59248@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59249 trace_ext4_mb_new_group_pa(ac, pa);
59250
59251 ext4_mb_use_group_pa(ac, pa);
59252- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59253+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59254
59255 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59256 lg = ac->ac_lg;
59257@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59258 * from the bitmap and continue.
59259 */
59260 }
59261- atomic_add(free, &sbi->s_mb_discarded);
59262+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59263
59264 return err;
59265 }
59266@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59267 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59268 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59269 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59270- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59271+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59272 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59273
59274 return 0;
59275diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59276index 04434ad..6404663 100644
59277--- a/fs/ext4/mmp.c
59278+++ b/fs/ext4/mmp.c
59279@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59280 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59281 const char *function, unsigned int line, const char *msg)
59282 {
59283- __ext4_warning(sb, function, line, msg);
59284+ __ext4_warning(sb, function, line, "%s", msg);
59285 __ext4_warning(sb, function, line,
59286 "MMP failure info: last update time: %llu, last update "
59287 "node: %s, last update device: %s\n",
59288diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59289index 710fed2..a82e4e8 100644
59290--- a/fs/ext4/super.c
59291+++ b/fs/ext4/super.c
59292@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59293 }
59294
59295 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59296-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59297+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59298 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59299
59300 #ifdef CONFIG_QUOTA
59301@@ -2450,7 +2450,7 @@ struct ext4_attr {
59302 int offset;
59303 int deprecated_val;
59304 } u;
59305-};
59306+} __do_const;
59307
59308 static int parse_strtoull(const char *buf,
59309 unsigned long long max, unsigned long long *value)
59310diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59311index 1423c48..9c0c6dc 100644
59312--- a/fs/ext4/xattr.c
59313+++ b/fs/ext4/xattr.c
59314@@ -381,7 +381,7 @@ static int
59315 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59316 char *buffer, size_t buffer_size)
59317 {
59318- size_t rest = buffer_size;
59319+ size_t rest = buffer_size, total_size = 0;
59320
59321 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59322 const struct xattr_handler *handler =
59323@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59324 buffer += size;
59325 }
59326 rest -= size;
59327+ total_size += size;
59328 }
59329 }
59330- return buffer_size - rest;
59331+ return total_size;
59332 }
59333
59334 static int
59335diff --git a/fs/fcntl.c b/fs/fcntl.c
59336index ef68665..5deacdc 100644
59337--- a/fs/fcntl.c
59338+++ b/fs/fcntl.c
59339@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59340 if (err)
59341 return err;
59342
59343+ if (gr_handle_chroot_fowner(pid, type))
59344+ return -ENOENT;
59345+ if (gr_check_protected_task_fowner(pid, type))
59346+ return -EACCES;
59347+
59348 f_modown(filp, pid, type, force);
59349 return 0;
59350 }
59351diff --git a/fs/fhandle.c b/fs/fhandle.c
59352index 999ff5c..41f4109 100644
59353--- a/fs/fhandle.c
59354+++ b/fs/fhandle.c
59355@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59356 } else
59357 retval = 0;
59358 /* copy the mount id */
59359- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59360- sizeof(*mnt_id)) ||
59361+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59362 copy_to_user(ufh, handle,
59363 sizeof(struct file_handle) + handle_bytes))
59364 retval = -EFAULT;
59365diff --git a/fs/file.c b/fs/file.c
59366index 9de2026..8e334ca 100644
59367--- a/fs/file.c
59368+++ b/fs/file.c
59369@@ -16,6 +16,7 @@
59370 #include <linux/slab.h>
59371 #include <linux/vmalloc.h>
59372 #include <linux/file.h>
59373+#include <linux/security.h>
59374 #include <linux/fdtable.h>
59375 #include <linux/bitops.h>
59376 #include <linux/interrupt.h>
59377@@ -141,7 +142,7 @@ out:
59378 * Return <0 error code on error; 1 on successful completion.
59379 * The files->file_lock should be held on entry, and will be held on exit.
59380 */
59381-static int expand_fdtable(struct files_struct *files, int nr)
59382+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59383 __releases(files->file_lock)
59384 __acquires(files->file_lock)
59385 {
59386@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59387 * expanded and execution may have blocked.
59388 * The files->file_lock should be held on entry, and will be held on exit.
59389 */
59390-static int expand_files(struct files_struct *files, int nr)
59391+static int expand_files(struct files_struct *files, unsigned int nr)
59392 {
59393 struct fdtable *fdt;
59394
59395@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59396 if (!file)
59397 return __close_fd(files, fd);
59398
59399+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59400 if (fd >= rlimit(RLIMIT_NOFILE))
59401 return -EBADF;
59402
59403@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59404 if (unlikely(oldfd == newfd))
59405 return -EINVAL;
59406
59407+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59408 if (newfd >= rlimit(RLIMIT_NOFILE))
59409 return -EBADF;
59410
59411@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59412 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59413 {
59414 int err;
59415+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59416 if (from >= rlimit(RLIMIT_NOFILE))
59417 return -EINVAL;
59418 err = alloc_fd(from, flags);
59419diff --git a/fs/filesystems.c b/fs/filesystems.c
59420index 92567d9..fcd8cbf 100644
59421--- a/fs/filesystems.c
59422+++ b/fs/filesystems.c
59423@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59424 int len = dot ? dot - name : strlen(name);
59425
59426 fs = __get_fs_type(name, len);
59427+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59428+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59429+#else
59430 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59431+#endif
59432 fs = __get_fs_type(name, len);
59433
59434 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59435diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59436index 7dca743..543d620 100644
59437--- a/fs/fs_struct.c
59438+++ b/fs/fs_struct.c
59439@@ -4,6 +4,7 @@
59440 #include <linux/path.h>
59441 #include <linux/slab.h>
59442 #include <linux/fs_struct.h>
59443+#include <linux/grsecurity.h>
59444 #include "internal.h"
59445
59446 /*
59447@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59448 write_seqcount_begin(&fs->seq);
59449 old_root = fs->root;
59450 fs->root = *path;
59451+ gr_set_chroot_entries(current, path);
59452 write_seqcount_end(&fs->seq);
59453 spin_unlock(&fs->lock);
59454 if (old_root.dentry)
59455@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59456 int hits = 0;
59457 spin_lock(&fs->lock);
59458 write_seqcount_begin(&fs->seq);
59459+ /* this root replacement is only done by pivot_root,
59460+ leave grsec's chroot tagging alone for this task
59461+ so that a pivoted root isn't treated as a chroot
59462+ */
59463 hits += replace_path(&fs->root, old_root, new_root);
59464 hits += replace_path(&fs->pwd, old_root, new_root);
59465 write_seqcount_end(&fs->seq);
59466@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59467 task_lock(tsk);
59468 spin_lock(&fs->lock);
59469 tsk->fs = NULL;
59470- kill = !--fs->users;
59471+ gr_clear_chroot_entries(tsk);
59472+ kill = !atomic_dec_return(&fs->users);
59473 spin_unlock(&fs->lock);
59474 task_unlock(tsk);
59475 if (kill)
59476@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59477 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59478 /* We don't need to lock fs - think why ;-) */
59479 if (fs) {
59480- fs->users = 1;
59481+ atomic_set(&fs->users, 1);
59482 fs->in_exec = 0;
59483 spin_lock_init(&fs->lock);
59484 seqcount_init(&fs->seq);
59485@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59486 spin_lock(&old->lock);
59487 fs->root = old->root;
59488 path_get(&fs->root);
59489+ /* instead of calling gr_set_chroot_entries here,
59490+ we call it from every caller of this function
59491+ */
59492 fs->pwd = old->pwd;
59493 path_get(&fs->pwd);
59494 spin_unlock(&old->lock);
59495@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59496
59497 task_lock(current);
59498 spin_lock(&fs->lock);
59499- kill = !--fs->users;
59500+ kill = !atomic_dec_return(&fs->users);
59501 current->fs = new_fs;
59502+ gr_set_chroot_entries(current, &new_fs->root);
59503 spin_unlock(&fs->lock);
59504 task_unlock(current);
59505
59506@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59507
59508 int current_umask(void)
59509 {
59510- return current->fs->umask;
59511+ return current->fs->umask | gr_acl_umask();
59512 }
59513 EXPORT_SYMBOL(current_umask);
59514
59515 /* to be mentioned only in INIT_TASK */
59516 struct fs_struct init_fs = {
59517- .users = 1,
59518+ .users = ATOMIC_INIT(1),
59519 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59520 .seq = SEQCNT_ZERO(init_fs.seq),
59521 .umask = 0022,
59522diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59523index 29d7feb..303644d 100644
59524--- a/fs/fscache/cookie.c
59525+++ b/fs/fscache/cookie.c
59526@@ -19,7 +19,7 @@
59527
59528 struct kmem_cache *fscache_cookie_jar;
59529
59530-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59531+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59532
59533 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59534 static int fscache_alloc_object(struct fscache_cache *cache,
59535@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59536 parent ? (char *) parent->def->name : "<no-parent>",
59537 def->name, netfs_data, enable);
59538
59539- fscache_stat(&fscache_n_acquires);
59540+ fscache_stat_unchecked(&fscache_n_acquires);
59541
59542 /* if there's no parent cookie, then we don't create one here either */
59543 if (!parent) {
59544- fscache_stat(&fscache_n_acquires_null);
59545+ fscache_stat_unchecked(&fscache_n_acquires_null);
59546 _leave(" [no parent]");
59547 return NULL;
59548 }
59549@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59550 /* allocate and initialise a cookie */
59551 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59552 if (!cookie) {
59553- fscache_stat(&fscache_n_acquires_oom);
59554+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59555 _leave(" [ENOMEM]");
59556 return NULL;
59557 }
59558@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59559
59560 switch (cookie->def->type) {
59561 case FSCACHE_COOKIE_TYPE_INDEX:
59562- fscache_stat(&fscache_n_cookie_index);
59563+ fscache_stat_unchecked(&fscache_n_cookie_index);
59564 break;
59565 case FSCACHE_COOKIE_TYPE_DATAFILE:
59566- fscache_stat(&fscache_n_cookie_data);
59567+ fscache_stat_unchecked(&fscache_n_cookie_data);
59568 break;
59569 default:
59570- fscache_stat(&fscache_n_cookie_special);
59571+ fscache_stat_unchecked(&fscache_n_cookie_special);
59572 break;
59573 }
59574
59575@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59576 } else {
59577 atomic_dec(&parent->n_children);
59578 __fscache_cookie_put(cookie);
59579- fscache_stat(&fscache_n_acquires_nobufs);
59580+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59581 _leave(" = NULL");
59582 return NULL;
59583 }
59584@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59585 }
59586 }
59587
59588- fscache_stat(&fscache_n_acquires_ok);
59589+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59590 _leave(" = %p", cookie);
59591 return cookie;
59592 }
59593@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59594 cache = fscache_select_cache_for_object(cookie->parent);
59595 if (!cache) {
59596 up_read(&fscache_addremove_sem);
59597- fscache_stat(&fscache_n_acquires_no_cache);
59598+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59599 _leave(" = -ENOMEDIUM [no cache]");
59600 return -ENOMEDIUM;
59601 }
59602@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59603 object = cache->ops->alloc_object(cache, cookie);
59604 fscache_stat_d(&fscache_n_cop_alloc_object);
59605 if (IS_ERR(object)) {
59606- fscache_stat(&fscache_n_object_no_alloc);
59607+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59608 ret = PTR_ERR(object);
59609 goto error;
59610 }
59611
59612- fscache_stat(&fscache_n_object_alloc);
59613+ fscache_stat_unchecked(&fscache_n_object_alloc);
59614
59615- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59616+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59617
59618 _debug("ALLOC OBJ%x: %s {%lx}",
59619 object->debug_id, cookie->def->name, object->events);
59620@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59621
59622 _enter("{%s}", cookie->def->name);
59623
59624- fscache_stat(&fscache_n_invalidates);
59625+ fscache_stat_unchecked(&fscache_n_invalidates);
59626
59627 /* Only permit invalidation of data files. Invalidating an index will
59628 * require the caller to release all its attachments to the tree rooted
59629@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59630 {
59631 struct fscache_object *object;
59632
59633- fscache_stat(&fscache_n_updates);
59634+ fscache_stat_unchecked(&fscache_n_updates);
59635
59636 if (!cookie) {
59637- fscache_stat(&fscache_n_updates_null);
59638+ fscache_stat_unchecked(&fscache_n_updates_null);
59639 _leave(" [no cookie]");
59640 return;
59641 }
59642@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59643 */
59644 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59645 {
59646- fscache_stat(&fscache_n_relinquishes);
59647+ fscache_stat_unchecked(&fscache_n_relinquishes);
59648 if (retire)
59649- fscache_stat(&fscache_n_relinquishes_retire);
59650+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59651
59652 if (!cookie) {
59653- fscache_stat(&fscache_n_relinquishes_null);
59654+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59655 _leave(" [no cookie]");
59656 return;
59657 }
59658@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59659 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59660 goto inconsistent;
59661
59662- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59663+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59664
59665 __fscache_use_cookie(cookie);
59666 if (fscache_submit_op(object, op) < 0)
59667diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59668index 4226f66..0fb3f45 100644
59669--- a/fs/fscache/internal.h
59670+++ b/fs/fscache/internal.h
59671@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59672 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59673 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59674 struct fscache_operation *,
59675- atomic_t *,
59676- atomic_t *,
59677+ atomic_unchecked_t *,
59678+ atomic_unchecked_t *,
59679 void (*)(struct fscache_operation *));
59680 extern void fscache_invalidate_writes(struct fscache_cookie *);
59681
59682@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59683 * stats.c
59684 */
59685 #ifdef CONFIG_FSCACHE_STATS
59686-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59687-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59688+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59689+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59690
59691-extern atomic_t fscache_n_op_pend;
59692-extern atomic_t fscache_n_op_run;
59693-extern atomic_t fscache_n_op_enqueue;
59694-extern atomic_t fscache_n_op_deferred_release;
59695-extern atomic_t fscache_n_op_release;
59696-extern atomic_t fscache_n_op_gc;
59697-extern atomic_t fscache_n_op_cancelled;
59698-extern atomic_t fscache_n_op_rejected;
59699+extern atomic_unchecked_t fscache_n_op_pend;
59700+extern atomic_unchecked_t fscache_n_op_run;
59701+extern atomic_unchecked_t fscache_n_op_enqueue;
59702+extern atomic_unchecked_t fscache_n_op_deferred_release;
59703+extern atomic_unchecked_t fscache_n_op_release;
59704+extern atomic_unchecked_t fscache_n_op_gc;
59705+extern atomic_unchecked_t fscache_n_op_cancelled;
59706+extern atomic_unchecked_t fscache_n_op_rejected;
59707
59708-extern atomic_t fscache_n_attr_changed;
59709-extern atomic_t fscache_n_attr_changed_ok;
59710-extern atomic_t fscache_n_attr_changed_nobufs;
59711-extern atomic_t fscache_n_attr_changed_nomem;
59712-extern atomic_t fscache_n_attr_changed_calls;
59713+extern atomic_unchecked_t fscache_n_attr_changed;
59714+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59715+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59716+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59717+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59718
59719-extern atomic_t fscache_n_allocs;
59720-extern atomic_t fscache_n_allocs_ok;
59721-extern atomic_t fscache_n_allocs_wait;
59722-extern atomic_t fscache_n_allocs_nobufs;
59723-extern atomic_t fscache_n_allocs_intr;
59724-extern atomic_t fscache_n_allocs_object_dead;
59725-extern atomic_t fscache_n_alloc_ops;
59726-extern atomic_t fscache_n_alloc_op_waits;
59727+extern atomic_unchecked_t fscache_n_allocs;
59728+extern atomic_unchecked_t fscache_n_allocs_ok;
59729+extern atomic_unchecked_t fscache_n_allocs_wait;
59730+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59731+extern atomic_unchecked_t fscache_n_allocs_intr;
59732+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59733+extern atomic_unchecked_t fscache_n_alloc_ops;
59734+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59735
59736-extern atomic_t fscache_n_retrievals;
59737-extern atomic_t fscache_n_retrievals_ok;
59738-extern atomic_t fscache_n_retrievals_wait;
59739-extern atomic_t fscache_n_retrievals_nodata;
59740-extern atomic_t fscache_n_retrievals_nobufs;
59741-extern atomic_t fscache_n_retrievals_intr;
59742-extern atomic_t fscache_n_retrievals_nomem;
59743-extern atomic_t fscache_n_retrievals_object_dead;
59744-extern atomic_t fscache_n_retrieval_ops;
59745-extern atomic_t fscache_n_retrieval_op_waits;
59746+extern atomic_unchecked_t fscache_n_retrievals;
59747+extern atomic_unchecked_t fscache_n_retrievals_ok;
59748+extern atomic_unchecked_t fscache_n_retrievals_wait;
59749+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59750+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59751+extern atomic_unchecked_t fscache_n_retrievals_intr;
59752+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59753+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59754+extern atomic_unchecked_t fscache_n_retrieval_ops;
59755+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59756
59757-extern atomic_t fscache_n_stores;
59758-extern atomic_t fscache_n_stores_ok;
59759-extern atomic_t fscache_n_stores_again;
59760-extern atomic_t fscache_n_stores_nobufs;
59761-extern atomic_t fscache_n_stores_oom;
59762-extern atomic_t fscache_n_store_ops;
59763-extern atomic_t fscache_n_store_calls;
59764-extern atomic_t fscache_n_store_pages;
59765-extern atomic_t fscache_n_store_radix_deletes;
59766-extern atomic_t fscache_n_store_pages_over_limit;
59767+extern atomic_unchecked_t fscache_n_stores;
59768+extern atomic_unchecked_t fscache_n_stores_ok;
59769+extern atomic_unchecked_t fscache_n_stores_again;
59770+extern atomic_unchecked_t fscache_n_stores_nobufs;
59771+extern atomic_unchecked_t fscache_n_stores_oom;
59772+extern atomic_unchecked_t fscache_n_store_ops;
59773+extern atomic_unchecked_t fscache_n_store_calls;
59774+extern atomic_unchecked_t fscache_n_store_pages;
59775+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59776+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59777
59778-extern atomic_t fscache_n_store_vmscan_not_storing;
59779-extern atomic_t fscache_n_store_vmscan_gone;
59780-extern atomic_t fscache_n_store_vmscan_busy;
59781-extern atomic_t fscache_n_store_vmscan_cancelled;
59782-extern atomic_t fscache_n_store_vmscan_wait;
59783+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59784+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59785+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59786+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59787+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59788
59789-extern atomic_t fscache_n_marks;
59790-extern atomic_t fscache_n_uncaches;
59791+extern atomic_unchecked_t fscache_n_marks;
59792+extern atomic_unchecked_t fscache_n_uncaches;
59793
59794-extern atomic_t fscache_n_acquires;
59795-extern atomic_t fscache_n_acquires_null;
59796-extern atomic_t fscache_n_acquires_no_cache;
59797-extern atomic_t fscache_n_acquires_ok;
59798-extern atomic_t fscache_n_acquires_nobufs;
59799-extern atomic_t fscache_n_acquires_oom;
59800+extern atomic_unchecked_t fscache_n_acquires;
59801+extern atomic_unchecked_t fscache_n_acquires_null;
59802+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59803+extern atomic_unchecked_t fscache_n_acquires_ok;
59804+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59805+extern atomic_unchecked_t fscache_n_acquires_oom;
59806
59807-extern atomic_t fscache_n_invalidates;
59808-extern atomic_t fscache_n_invalidates_run;
59809+extern atomic_unchecked_t fscache_n_invalidates;
59810+extern atomic_unchecked_t fscache_n_invalidates_run;
59811
59812-extern atomic_t fscache_n_updates;
59813-extern atomic_t fscache_n_updates_null;
59814-extern atomic_t fscache_n_updates_run;
59815+extern atomic_unchecked_t fscache_n_updates;
59816+extern atomic_unchecked_t fscache_n_updates_null;
59817+extern atomic_unchecked_t fscache_n_updates_run;
59818
59819-extern atomic_t fscache_n_relinquishes;
59820-extern atomic_t fscache_n_relinquishes_null;
59821-extern atomic_t fscache_n_relinquishes_waitcrt;
59822-extern atomic_t fscache_n_relinquishes_retire;
59823+extern atomic_unchecked_t fscache_n_relinquishes;
59824+extern atomic_unchecked_t fscache_n_relinquishes_null;
59825+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59826+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59827
59828-extern atomic_t fscache_n_cookie_index;
59829-extern atomic_t fscache_n_cookie_data;
59830-extern atomic_t fscache_n_cookie_special;
59831+extern atomic_unchecked_t fscache_n_cookie_index;
59832+extern atomic_unchecked_t fscache_n_cookie_data;
59833+extern atomic_unchecked_t fscache_n_cookie_special;
59834
59835-extern atomic_t fscache_n_object_alloc;
59836-extern atomic_t fscache_n_object_no_alloc;
59837-extern atomic_t fscache_n_object_lookups;
59838-extern atomic_t fscache_n_object_lookups_negative;
59839-extern atomic_t fscache_n_object_lookups_positive;
59840-extern atomic_t fscache_n_object_lookups_timed_out;
59841-extern atomic_t fscache_n_object_created;
59842-extern atomic_t fscache_n_object_avail;
59843-extern atomic_t fscache_n_object_dead;
59844+extern atomic_unchecked_t fscache_n_object_alloc;
59845+extern atomic_unchecked_t fscache_n_object_no_alloc;
59846+extern atomic_unchecked_t fscache_n_object_lookups;
59847+extern atomic_unchecked_t fscache_n_object_lookups_negative;
59848+extern atomic_unchecked_t fscache_n_object_lookups_positive;
59849+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59850+extern atomic_unchecked_t fscache_n_object_created;
59851+extern atomic_unchecked_t fscache_n_object_avail;
59852+extern atomic_unchecked_t fscache_n_object_dead;
59853
59854-extern atomic_t fscache_n_checkaux_none;
59855-extern atomic_t fscache_n_checkaux_okay;
59856-extern atomic_t fscache_n_checkaux_update;
59857-extern atomic_t fscache_n_checkaux_obsolete;
59858+extern atomic_unchecked_t fscache_n_checkaux_none;
59859+extern atomic_unchecked_t fscache_n_checkaux_okay;
59860+extern atomic_unchecked_t fscache_n_checkaux_update;
59861+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59862
59863 extern atomic_t fscache_n_cop_alloc_object;
59864 extern atomic_t fscache_n_cop_lookup_object;
59865@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59866 atomic_inc(stat);
59867 }
59868
59869+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59870+{
59871+ atomic_inc_unchecked(stat);
59872+}
59873+
59874 static inline void fscache_stat_d(atomic_t *stat)
59875 {
59876 atomic_dec(stat);
59877@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59878
59879 #define __fscache_stat(stat) (NULL)
59880 #define fscache_stat(stat) do {} while (0)
59881+#define fscache_stat_unchecked(stat) do {} while (0)
59882 #define fscache_stat_d(stat) do {} while (0)
59883 #endif
59884
59885diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59886index 53d35c5..5d68ed4 100644
59887--- a/fs/fscache/object.c
59888+++ b/fs/fscache/object.c
59889@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59890 _debug("LOOKUP \"%s\" in \"%s\"",
59891 cookie->def->name, object->cache->tag->name);
59892
59893- fscache_stat(&fscache_n_object_lookups);
59894+ fscache_stat_unchecked(&fscache_n_object_lookups);
59895 fscache_stat(&fscache_n_cop_lookup_object);
59896 ret = object->cache->ops->lookup_object(object);
59897 fscache_stat_d(&fscache_n_cop_lookup_object);
59898@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59899 if (ret == -ETIMEDOUT) {
59900 /* probably stuck behind another object, so move this one to
59901 * the back of the queue */
59902- fscache_stat(&fscache_n_object_lookups_timed_out);
59903+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59904 _leave(" [timeout]");
59905 return NO_TRANSIT;
59906 }
59907@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59908 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59909
59910 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59911- fscache_stat(&fscache_n_object_lookups_negative);
59912+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59913
59914 /* Allow write requests to begin stacking up and read requests to begin
59915 * returning ENODATA.
59916@@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59917 /* if we were still looking up, then we must have a positive lookup
59918 * result, in which case there may be data available */
59919 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59920- fscache_stat(&fscache_n_object_lookups_positive);
59921+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59922
59923 /* We do (presumably) have data */
59924 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59925@@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59926 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59927 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59928 } else {
59929- fscache_stat(&fscache_n_object_created);
59930+ fscache_stat_unchecked(&fscache_n_object_created);
59931 }
59932
59933 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59934@@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59935 fscache_stat_d(&fscache_n_cop_lookup_complete);
59936
59937 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59938- fscache_stat(&fscache_n_object_avail);
59939+ fscache_stat_unchecked(&fscache_n_object_avail);
59940
59941 _leave("");
59942 return transit_to(JUMPSTART_DEPS);
59943@@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59944
59945 /* this just shifts the object release to the work processor */
59946 fscache_put_object(object);
59947- fscache_stat(&fscache_n_object_dead);
59948+ fscache_stat_unchecked(&fscache_n_object_dead);
59949
59950 _leave("");
59951 return transit_to(OBJECT_DEAD);
59952@@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59953 enum fscache_checkaux result;
59954
59955 if (!object->cookie->def->check_aux) {
59956- fscache_stat(&fscache_n_checkaux_none);
59957+ fscache_stat_unchecked(&fscache_n_checkaux_none);
59958 return FSCACHE_CHECKAUX_OKAY;
59959 }
59960
59961@@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59962 switch (result) {
59963 /* entry okay as is */
59964 case FSCACHE_CHECKAUX_OKAY:
59965- fscache_stat(&fscache_n_checkaux_okay);
59966+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
59967 break;
59968
59969 /* entry requires update */
59970 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59971- fscache_stat(&fscache_n_checkaux_update);
59972+ fscache_stat_unchecked(&fscache_n_checkaux_update);
59973 break;
59974
59975 /* entry requires deletion */
59976 case FSCACHE_CHECKAUX_OBSOLETE:
59977- fscache_stat(&fscache_n_checkaux_obsolete);
59978+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59979 break;
59980
59981 default:
59982@@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59983 {
59984 const struct fscache_state *s;
59985
59986- fscache_stat(&fscache_n_invalidates_run);
59987+ fscache_stat_unchecked(&fscache_n_invalidates_run);
59988 fscache_stat(&fscache_n_cop_invalidate_object);
59989 s = _fscache_invalidate_object(object, event);
59990 fscache_stat_d(&fscache_n_cop_invalidate_object);
59991@@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59992 {
59993 _enter("{OBJ%x},%d", object->debug_id, event);
59994
59995- fscache_stat(&fscache_n_updates_run);
59996+ fscache_stat_unchecked(&fscache_n_updates_run);
59997 fscache_stat(&fscache_n_cop_update_object);
59998 object->cache->ops->update_object(object);
59999 fscache_stat_d(&fscache_n_cop_update_object);
60000diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60001index 318071a..379938b 100644
60002--- a/fs/fscache/operation.c
60003+++ b/fs/fscache/operation.c
60004@@ -17,7 +17,7 @@
60005 #include <linux/slab.h>
60006 #include "internal.h"
60007
60008-atomic_t fscache_op_debug_id;
60009+atomic_unchecked_t fscache_op_debug_id;
60010 EXPORT_SYMBOL(fscache_op_debug_id);
60011
60012 /**
60013@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60014 ASSERTCMP(atomic_read(&op->usage), >, 0);
60015 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60016
60017- fscache_stat(&fscache_n_op_enqueue);
60018+ fscache_stat_unchecked(&fscache_n_op_enqueue);
60019 switch (op->flags & FSCACHE_OP_TYPE) {
60020 case FSCACHE_OP_ASYNC:
60021 _debug("queue async");
60022@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60023 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60024 if (op->processor)
60025 fscache_enqueue_operation(op);
60026- fscache_stat(&fscache_n_op_run);
60027+ fscache_stat_unchecked(&fscache_n_op_run);
60028 }
60029
60030 /*
60031@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60032 if (object->n_in_progress > 0) {
60033 atomic_inc(&op->usage);
60034 list_add_tail(&op->pend_link, &object->pending_ops);
60035- fscache_stat(&fscache_n_op_pend);
60036+ fscache_stat_unchecked(&fscache_n_op_pend);
60037 } else if (!list_empty(&object->pending_ops)) {
60038 atomic_inc(&op->usage);
60039 list_add_tail(&op->pend_link, &object->pending_ops);
60040- fscache_stat(&fscache_n_op_pend);
60041+ fscache_stat_unchecked(&fscache_n_op_pend);
60042 fscache_start_operations(object);
60043 } else {
60044 ASSERTCMP(object->n_in_progress, ==, 0);
60045@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60046 object->n_exclusive++; /* reads and writes must wait */
60047 atomic_inc(&op->usage);
60048 list_add_tail(&op->pend_link, &object->pending_ops);
60049- fscache_stat(&fscache_n_op_pend);
60050+ fscache_stat_unchecked(&fscache_n_op_pend);
60051 ret = 0;
60052 } else {
60053 /* If we're in any other state, there must have been an I/O
60054@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60055 if (object->n_exclusive > 0) {
60056 atomic_inc(&op->usage);
60057 list_add_tail(&op->pend_link, &object->pending_ops);
60058- fscache_stat(&fscache_n_op_pend);
60059+ fscache_stat_unchecked(&fscache_n_op_pend);
60060 } else if (!list_empty(&object->pending_ops)) {
60061 atomic_inc(&op->usage);
60062 list_add_tail(&op->pend_link, &object->pending_ops);
60063- fscache_stat(&fscache_n_op_pend);
60064+ fscache_stat_unchecked(&fscache_n_op_pend);
60065 fscache_start_operations(object);
60066 } else {
60067 ASSERTCMP(object->n_exclusive, ==, 0);
60068@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60069 object->n_ops++;
60070 atomic_inc(&op->usage);
60071 list_add_tail(&op->pend_link, &object->pending_ops);
60072- fscache_stat(&fscache_n_op_pend);
60073+ fscache_stat_unchecked(&fscache_n_op_pend);
60074 ret = 0;
60075 } else if (fscache_object_is_dying(object)) {
60076- fscache_stat(&fscache_n_op_rejected);
60077+ fscache_stat_unchecked(&fscache_n_op_rejected);
60078 op->state = FSCACHE_OP_ST_CANCELLED;
60079 ret = -ENOBUFS;
60080 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60081@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60082 ret = -EBUSY;
60083 if (op->state == FSCACHE_OP_ST_PENDING) {
60084 ASSERT(!list_empty(&op->pend_link));
60085- fscache_stat(&fscache_n_op_cancelled);
60086+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60087 list_del_init(&op->pend_link);
60088 if (do_cancel)
60089 do_cancel(op);
60090@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60091 while (!list_empty(&object->pending_ops)) {
60092 op = list_entry(object->pending_ops.next,
60093 struct fscache_operation, pend_link);
60094- fscache_stat(&fscache_n_op_cancelled);
60095+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60096 list_del_init(&op->pend_link);
60097
60098 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60099@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60100 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60101 op->state = FSCACHE_OP_ST_DEAD;
60102
60103- fscache_stat(&fscache_n_op_release);
60104+ fscache_stat_unchecked(&fscache_n_op_release);
60105
60106 if (op->release) {
60107 op->release(op);
60108@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60109 * lock, and defer it otherwise */
60110 if (!spin_trylock(&object->lock)) {
60111 _debug("defer put");
60112- fscache_stat(&fscache_n_op_deferred_release);
60113+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60114
60115 cache = object->cache;
60116 spin_lock(&cache->op_gc_list_lock);
60117@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60118
60119 _debug("GC DEFERRED REL OBJ%x OP%x",
60120 object->debug_id, op->debug_id);
60121- fscache_stat(&fscache_n_op_gc);
60122+ fscache_stat_unchecked(&fscache_n_op_gc);
60123
60124 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60125 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60126diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60127index 7f5c658..6c1e164 100644
60128--- a/fs/fscache/page.c
60129+++ b/fs/fscache/page.c
60130@@ -61,7 +61,7 @@ try_again:
60131 val = radix_tree_lookup(&cookie->stores, page->index);
60132 if (!val) {
60133 rcu_read_unlock();
60134- fscache_stat(&fscache_n_store_vmscan_not_storing);
60135+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60136 __fscache_uncache_page(cookie, page);
60137 return true;
60138 }
60139@@ -91,11 +91,11 @@ try_again:
60140 spin_unlock(&cookie->stores_lock);
60141
60142 if (xpage) {
60143- fscache_stat(&fscache_n_store_vmscan_cancelled);
60144- fscache_stat(&fscache_n_store_radix_deletes);
60145+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60146+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60147 ASSERTCMP(xpage, ==, page);
60148 } else {
60149- fscache_stat(&fscache_n_store_vmscan_gone);
60150+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60151 }
60152
60153 wake_up_bit(&cookie->flags, 0);
60154@@ -110,11 +110,11 @@ page_busy:
60155 * sleeping on memory allocation, so we may need to impose a timeout
60156 * too. */
60157 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60158- fscache_stat(&fscache_n_store_vmscan_busy);
60159+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60160 return false;
60161 }
60162
60163- fscache_stat(&fscache_n_store_vmscan_wait);
60164+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60165 __fscache_wait_on_page_write(cookie, page);
60166 gfp &= ~__GFP_WAIT;
60167 goto try_again;
60168@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60169 FSCACHE_COOKIE_STORING_TAG);
60170 if (!radix_tree_tag_get(&cookie->stores, page->index,
60171 FSCACHE_COOKIE_PENDING_TAG)) {
60172- fscache_stat(&fscache_n_store_radix_deletes);
60173+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60174 xpage = radix_tree_delete(&cookie->stores, page->index);
60175 }
60176 spin_unlock(&cookie->stores_lock);
60177@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60178
60179 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60180
60181- fscache_stat(&fscache_n_attr_changed_calls);
60182+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60183
60184 if (fscache_object_is_active(object)) {
60185 fscache_stat(&fscache_n_cop_attr_changed);
60186@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60187
60188 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60189
60190- fscache_stat(&fscache_n_attr_changed);
60191+ fscache_stat_unchecked(&fscache_n_attr_changed);
60192
60193 op = kzalloc(sizeof(*op), GFP_KERNEL);
60194 if (!op) {
60195- fscache_stat(&fscache_n_attr_changed_nomem);
60196+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60197 _leave(" = -ENOMEM");
60198 return -ENOMEM;
60199 }
60200@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60201 if (fscache_submit_exclusive_op(object, op) < 0)
60202 goto nobufs;
60203 spin_unlock(&cookie->lock);
60204- fscache_stat(&fscache_n_attr_changed_ok);
60205+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60206 fscache_put_operation(op);
60207 _leave(" = 0");
60208 return 0;
60209@@ -225,7 +225,7 @@ nobufs:
60210 kfree(op);
60211 if (wake_cookie)
60212 __fscache_wake_unused_cookie(cookie);
60213- fscache_stat(&fscache_n_attr_changed_nobufs);
60214+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60215 _leave(" = %d", -ENOBUFS);
60216 return -ENOBUFS;
60217 }
60218@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60219 /* allocate a retrieval operation and attempt to submit it */
60220 op = kzalloc(sizeof(*op), GFP_NOIO);
60221 if (!op) {
60222- fscache_stat(&fscache_n_retrievals_nomem);
60223+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60224 return NULL;
60225 }
60226
60227@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60228 return 0;
60229 }
60230
60231- fscache_stat(&fscache_n_retrievals_wait);
60232+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60233
60234 jif = jiffies;
60235 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60236 fscache_wait_bit_interruptible,
60237 TASK_INTERRUPTIBLE) != 0) {
60238- fscache_stat(&fscache_n_retrievals_intr);
60239+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60240 _leave(" = -ERESTARTSYS");
60241 return -ERESTARTSYS;
60242 }
60243@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60244 */
60245 int fscache_wait_for_operation_activation(struct fscache_object *object,
60246 struct fscache_operation *op,
60247- atomic_t *stat_op_waits,
60248- atomic_t *stat_object_dead,
60249+ atomic_unchecked_t *stat_op_waits,
60250+ atomic_unchecked_t *stat_object_dead,
60251 void (*do_cancel)(struct fscache_operation *))
60252 {
60253 int ret;
60254@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60255
60256 _debug(">>> WT");
60257 if (stat_op_waits)
60258- fscache_stat(stat_op_waits);
60259+ fscache_stat_unchecked(stat_op_waits);
60260 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60261 fscache_wait_bit_interruptible,
60262 TASK_INTERRUPTIBLE) != 0) {
60263@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60264 check_if_dead:
60265 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60266 if (stat_object_dead)
60267- fscache_stat(stat_object_dead);
60268+ fscache_stat_unchecked(stat_object_dead);
60269 _leave(" = -ENOBUFS [cancelled]");
60270 return -ENOBUFS;
60271 }
60272@@ -366,7 +366,7 @@ check_if_dead:
60273 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60274 fscache_cancel_op(op, do_cancel);
60275 if (stat_object_dead)
60276- fscache_stat(stat_object_dead);
60277+ fscache_stat_unchecked(stat_object_dead);
60278 return -ENOBUFS;
60279 }
60280 return 0;
60281@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60282
60283 _enter("%p,%p,,,", cookie, page);
60284
60285- fscache_stat(&fscache_n_retrievals);
60286+ fscache_stat_unchecked(&fscache_n_retrievals);
60287
60288 if (hlist_empty(&cookie->backing_objects))
60289 goto nobufs;
60290@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60291 goto nobufs_unlock_dec;
60292 spin_unlock(&cookie->lock);
60293
60294- fscache_stat(&fscache_n_retrieval_ops);
60295+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60296
60297 /* pin the netfs read context in case we need to do the actual netfs
60298 * read because we've encountered a cache read failure */
60299@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60300
60301 error:
60302 if (ret == -ENOMEM)
60303- fscache_stat(&fscache_n_retrievals_nomem);
60304+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60305 else if (ret == -ERESTARTSYS)
60306- fscache_stat(&fscache_n_retrievals_intr);
60307+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60308 else if (ret == -ENODATA)
60309- fscache_stat(&fscache_n_retrievals_nodata);
60310+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60311 else if (ret < 0)
60312- fscache_stat(&fscache_n_retrievals_nobufs);
60313+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60314 else
60315- fscache_stat(&fscache_n_retrievals_ok);
60316+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60317
60318 fscache_put_retrieval(op);
60319 _leave(" = %d", ret);
60320@@ -490,7 +490,7 @@ nobufs_unlock:
60321 __fscache_wake_unused_cookie(cookie);
60322 kfree(op);
60323 nobufs:
60324- fscache_stat(&fscache_n_retrievals_nobufs);
60325+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60326 _leave(" = -ENOBUFS");
60327 return -ENOBUFS;
60328 }
60329@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60330
60331 _enter("%p,,%d,,,", cookie, *nr_pages);
60332
60333- fscache_stat(&fscache_n_retrievals);
60334+ fscache_stat_unchecked(&fscache_n_retrievals);
60335
60336 if (hlist_empty(&cookie->backing_objects))
60337 goto nobufs;
60338@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60339 goto nobufs_unlock_dec;
60340 spin_unlock(&cookie->lock);
60341
60342- fscache_stat(&fscache_n_retrieval_ops);
60343+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60344
60345 /* pin the netfs read context in case we need to do the actual netfs
60346 * read because we've encountered a cache read failure */
60347@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60348
60349 error:
60350 if (ret == -ENOMEM)
60351- fscache_stat(&fscache_n_retrievals_nomem);
60352+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60353 else if (ret == -ERESTARTSYS)
60354- fscache_stat(&fscache_n_retrievals_intr);
60355+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60356 else if (ret == -ENODATA)
60357- fscache_stat(&fscache_n_retrievals_nodata);
60358+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60359 else if (ret < 0)
60360- fscache_stat(&fscache_n_retrievals_nobufs);
60361+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60362 else
60363- fscache_stat(&fscache_n_retrievals_ok);
60364+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60365
60366 fscache_put_retrieval(op);
60367 _leave(" = %d", ret);
60368@@ -621,7 +621,7 @@ nobufs_unlock:
60369 if (wake_cookie)
60370 __fscache_wake_unused_cookie(cookie);
60371 nobufs:
60372- fscache_stat(&fscache_n_retrievals_nobufs);
60373+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60374 _leave(" = -ENOBUFS");
60375 return -ENOBUFS;
60376 }
60377@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60378
60379 _enter("%p,%p,,,", cookie, page);
60380
60381- fscache_stat(&fscache_n_allocs);
60382+ fscache_stat_unchecked(&fscache_n_allocs);
60383
60384 if (hlist_empty(&cookie->backing_objects))
60385 goto nobufs;
60386@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60387 goto nobufs_unlock_dec;
60388 spin_unlock(&cookie->lock);
60389
60390- fscache_stat(&fscache_n_alloc_ops);
60391+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60392
60393 ret = fscache_wait_for_operation_activation(
60394 object, &op->op,
60395@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60396
60397 error:
60398 if (ret == -ERESTARTSYS)
60399- fscache_stat(&fscache_n_allocs_intr);
60400+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60401 else if (ret < 0)
60402- fscache_stat(&fscache_n_allocs_nobufs);
60403+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60404 else
60405- fscache_stat(&fscache_n_allocs_ok);
60406+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60407
60408 fscache_put_retrieval(op);
60409 _leave(" = %d", ret);
60410@@ -715,7 +715,7 @@ nobufs_unlock:
60411 if (wake_cookie)
60412 __fscache_wake_unused_cookie(cookie);
60413 nobufs:
60414- fscache_stat(&fscache_n_allocs_nobufs);
60415+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60416 _leave(" = -ENOBUFS");
60417 return -ENOBUFS;
60418 }
60419@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60420
60421 spin_lock(&cookie->stores_lock);
60422
60423- fscache_stat(&fscache_n_store_calls);
60424+ fscache_stat_unchecked(&fscache_n_store_calls);
60425
60426 /* find a page to store */
60427 page = NULL;
60428@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60429 page = results[0];
60430 _debug("gang %d [%lx]", n, page->index);
60431 if (page->index > op->store_limit) {
60432- fscache_stat(&fscache_n_store_pages_over_limit);
60433+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60434 goto superseded;
60435 }
60436
60437@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60438 spin_unlock(&cookie->stores_lock);
60439 spin_unlock(&object->lock);
60440
60441- fscache_stat(&fscache_n_store_pages);
60442+ fscache_stat_unchecked(&fscache_n_store_pages);
60443 fscache_stat(&fscache_n_cop_write_page);
60444 ret = object->cache->ops->write_page(op, page);
60445 fscache_stat_d(&fscache_n_cop_write_page);
60446@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60447 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60448 ASSERT(PageFsCache(page));
60449
60450- fscache_stat(&fscache_n_stores);
60451+ fscache_stat_unchecked(&fscache_n_stores);
60452
60453 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60454 _leave(" = -ENOBUFS [invalidating]");
60455@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60456 spin_unlock(&cookie->stores_lock);
60457 spin_unlock(&object->lock);
60458
60459- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60460+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60461 op->store_limit = object->store_limit;
60462
60463 __fscache_use_cookie(cookie);
60464@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60465
60466 spin_unlock(&cookie->lock);
60467 radix_tree_preload_end();
60468- fscache_stat(&fscache_n_store_ops);
60469- fscache_stat(&fscache_n_stores_ok);
60470+ fscache_stat_unchecked(&fscache_n_store_ops);
60471+ fscache_stat_unchecked(&fscache_n_stores_ok);
60472
60473 /* the work queue now carries its own ref on the object */
60474 fscache_put_operation(&op->op);
60475@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60476 return 0;
60477
60478 already_queued:
60479- fscache_stat(&fscache_n_stores_again);
60480+ fscache_stat_unchecked(&fscache_n_stores_again);
60481 already_pending:
60482 spin_unlock(&cookie->stores_lock);
60483 spin_unlock(&object->lock);
60484 spin_unlock(&cookie->lock);
60485 radix_tree_preload_end();
60486 kfree(op);
60487- fscache_stat(&fscache_n_stores_ok);
60488+ fscache_stat_unchecked(&fscache_n_stores_ok);
60489 _leave(" = 0");
60490 return 0;
60491
60492@@ -1024,14 +1024,14 @@ nobufs:
60493 kfree(op);
60494 if (wake_cookie)
60495 __fscache_wake_unused_cookie(cookie);
60496- fscache_stat(&fscache_n_stores_nobufs);
60497+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60498 _leave(" = -ENOBUFS");
60499 return -ENOBUFS;
60500
60501 nomem_free:
60502 kfree(op);
60503 nomem:
60504- fscache_stat(&fscache_n_stores_oom);
60505+ fscache_stat_unchecked(&fscache_n_stores_oom);
60506 _leave(" = -ENOMEM");
60507 return -ENOMEM;
60508 }
60509@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60510 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60511 ASSERTCMP(page, !=, NULL);
60512
60513- fscache_stat(&fscache_n_uncaches);
60514+ fscache_stat_unchecked(&fscache_n_uncaches);
60515
60516 /* cache withdrawal may beat us to it */
60517 if (!PageFsCache(page))
60518@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60519 struct fscache_cookie *cookie = op->op.object->cookie;
60520
60521 #ifdef CONFIG_FSCACHE_STATS
60522- atomic_inc(&fscache_n_marks);
60523+ atomic_inc_unchecked(&fscache_n_marks);
60524 #endif
60525
60526 _debug("- mark %p{%lx}", page, page->index);
60527diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60528index 40d13c7..ddf52b9 100644
60529--- a/fs/fscache/stats.c
60530+++ b/fs/fscache/stats.c
60531@@ -18,99 +18,99 @@
60532 /*
60533 * operation counters
60534 */
60535-atomic_t fscache_n_op_pend;
60536-atomic_t fscache_n_op_run;
60537-atomic_t fscache_n_op_enqueue;
60538-atomic_t fscache_n_op_requeue;
60539-atomic_t fscache_n_op_deferred_release;
60540-atomic_t fscache_n_op_release;
60541-atomic_t fscache_n_op_gc;
60542-atomic_t fscache_n_op_cancelled;
60543-atomic_t fscache_n_op_rejected;
60544+atomic_unchecked_t fscache_n_op_pend;
60545+atomic_unchecked_t fscache_n_op_run;
60546+atomic_unchecked_t fscache_n_op_enqueue;
60547+atomic_unchecked_t fscache_n_op_requeue;
60548+atomic_unchecked_t fscache_n_op_deferred_release;
60549+atomic_unchecked_t fscache_n_op_release;
60550+atomic_unchecked_t fscache_n_op_gc;
60551+atomic_unchecked_t fscache_n_op_cancelled;
60552+atomic_unchecked_t fscache_n_op_rejected;
60553
60554-atomic_t fscache_n_attr_changed;
60555-atomic_t fscache_n_attr_changed_ok;
60556-atomic_t fscache_n_attr_changed_nobufs;
60557-atomic_t fscache_n_attr_changed_nomem;
60558-atomic_t fscache_n_attr_changed_calls;
60559+atomic_unchecked_t fscache_n_attr_changed;
60560+atomic_unchecked_t fscache_n_attr_changed_ok;
60561+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60562+atomic_unchecked_t fscache_n_attr_changed_nomem;
60563+atomic_unchecked_t fscache_n_attr_changed_calls;
60564
60565-atomic_t fscache_n_allocs;
60566-atomic_t fscache_n_allocs_ok;
60567-atomic_t fscache_n_allocs_wait;
60568-atomic_t fscache_n_allocs_nobufs;
60569-atomic_t fscache_n_allocs_intr;
60570-atomic_t fscache_n_allocs_object_dead;
60571-atomic_t fscache_n_alloc_ops;
60572-atomic_t fscache_n_alloc_op_waits;
60573+atomic_unchecked_t fscache_n_allocs;
60574+atomic_unchecked_t fscache_n_allocs_ok;
60575+atomic_unchecked_t fscache_n_allocs_wait;
60576+atomic_unchecked_t fscache_n_allocs_nobufs;
60577+atomic_unchecked_t fscache_n_allocs_intr;
60578+atomic_unchecked_t fscache_n_allocs_object_dead;
60579+atomic_unchecked_t fscache_n_alloc_ops;
60580+atomic_unchecked_t fscache_n_alloc_op_waits;
60581
60582-atomic_t fscache_n_retrievals;
60583-atomic_t fscache_n_retrievals_ok;
60584-atomic_t fscache_n_retrievals_wait;
60585-atomic_t fscache_n_retrievals_nodata;
60586-atomic_t fscache_n_retrievals_nobufs;
60587-atomic_t fscache_n_retrievals_intr;
60588-atomic_t fscache_n_retrievals_nomem;
60589-atomic_t fscache_n_retrievals_object_dead;
60590-atomic_t fscache_n_retrieval_ops;
60591-atomic_t fscache_n_retrieval_op_waits;
60592+atomic_unchecked_t fscache_n_retrievals;
60593+atomic_unchecked_t fscache_n_retrievals_ok;
60594+atomic_unchecked_t fscache_n_retrievals_wait;
60595+atomic_unchecked_t fscache_n_retrievals_nodata;
60596+atomic_unchecked_t fscache_n_retrievals_nobufs;
60597+atomic_unchecked_t fscache_n_retrievals_intr;
60598+atomic_unchecked_t fscache_n_retrievals_nomem;
60599+atomic_unchecked_t fscache_n_retrievals_object_dead;
60600+atomic_unchecked_t fscache_n_retrieval_ops;
60601+atomic_unchecked_t fscache_n_retrieval_op_waits;
60602
60603-atomic_t fscache_n_stores;
60604-atomic_t fscache_n_stores_ok;
60605-atomic_t fscache_n_stores_again;
60606-atomic_t fscache_n_stores_nobufs;
60607-atomic_t fscache_n_stores_oom;
60608-atomic_t fscache_n_store_ops;
60609-atomic_t fscache_n_store_calls;
60610-atomic_t fscache_n_store_pages;
60611-atomic_t fscache_n_store_radix_deletes;
60612-atomic_t fscache_n_store_pages_over_limit;
60613+atomic_unchecked_t fscache_n_stores;
60614+atomic_unchecked_t fscache_n_stores_ok;
60615+atomic_unchecked_t fscache_n_stores_again;
60616+atomic_unchecked_t fscache_n_stores_nobufs;
60617+atomic_unchecked_t fscache_n_stores_oom;
60618+atomic_unchecked_t fscache_n_store_ops;
60619+atomic_unchecked_t fscache_n_store_calls;
60620+atomic_unchecked_t fscache_n_store_pages;
60621+atomic_unchecked_t fscache_n_store_radix_deletes;
60622+atomic_unchecked_t fscache_n_store_pages_over_limit;
60623
60624-atomic_t fscache_n_store_vmscan_not_storing;
60625-atomic_t fscache_n_store_vmscan_gone;
60626-atomic_t fscache_n_store_vmscan_busy;
60627-atomic_t fscache_n_store_vmscan_cancelled;
60628-atomic_t fscache_n_store_vmscan_wait;
60629+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60630+atomic_unchecked_t fscache_n_store_vmscan_gone;
60631+atomic_unchecked_t fscache_n_store_vmscan_busy;
60632+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60633+atomic_unchecked_t fscache_n_store_vmscan_wait;
60634
60635-atomic_t fscache_n_marks;
60636-atomic_t fscache_n_uncaches;
60637+atomic_unchecked_t fscache_n_marks;
60638+atomic_unchecked_t fscache_n_uncaches;
60639
60640-atomic_t fscache_n_acquires;
60641-atomic_t fscache_n_acquires_null;
60642-atomic_t fscache_n_acquires_no_cache;
60643-atomic_t fscache_n_acquires_ok;
60644-atomic_t fscache_n_acquires_nobufs;
60645-atomic_t fscache_n_acquires_oom;
60646+atomic_unchecked_t fscache_n_acquires;
60647+atomic_unchecked_t fscache_n_acquires_null;
60648+atomic_unchecked_t fscache_n_acquires_no_cache;
60649+atomic_unchecked_t fscache_n_acquires_ok;
60650+atomic_unchecked_t fscache_n_acquires_nobufs;
60651+atomic_unchecked_t fscache_n_acquires_oom;
60652
60653-atomic_t fscache_n_invalidates;
60654-atomic_t fscache_n_invalidates_run;
60655+atomic_unchecked_t fscache_n_invalidates;
60656+atomic_unchecked_t fscache_n_invalidates_run;
60657
60658-atomic_t fscache_n_updates;
60659-atomic_t fscache_n_updates_null;
60660-atomic_t fscache_n_updates_run;
60661+atomic_unchecked_t fscache_n_updates;
60662+atomic_unchecked_t fscache_n_updates_null;
60663+atomic_unchecked_t fscache_n_updates_run;
60664
60665-atomic_t fscache_n_relinquishes;
60666-atomic_t fscache_n_relinquishes_null;
60667-atomic_t fscache_n_relinquishes_waitcrt;
60668-atomic_t fscache_n_relinquishes_retire;
60669+atomic_unchecked_t fscache_n_relinquishes;
60670+atomic_unchecked_t fscache_n_relinquishes_null;
60671+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60672+atomic_unchecked_t fscache_n_relinquishes_retire;
60673
60674-atomic_t fscache_n_cookie_index;
60675-atomic_t fscache_n_cookie_data;
60676-atomic_t fscache_n_cookie_special;
60677+atomic_unchecked_t fscache_n_cookie_index;
60678+atomic_unchecked_t fscache_n_cookie_data;
60679+atomic_unchecked_t fscache_n_cookie_special;
60680
60681-atomic_t fscache_n_object_alloc;
60682-atomic_t fscache_n_object_no_alloc;
60683-atomic_t fscache_n_object_lookups;
60684-atomic_t fscache_n_object_lookups_negative;
60685-atomic_t fscache_n_object_lookups_positive;
60686-atomic_t fscache_n_object_lookups_timed_out;
60687-atomic_t fscache_n_object_created;
60688-atomic_t fscache_n_object_avail;
60689-atomic_t fscache_n_object_dead;
60690+atomic_unchecked_t fscache_n_object_alloc;
60691+atomic_unchecked_t fscache_n_object_no_alloc;
60692+atomic_unchecked_t fscache_n_object_lookups;
60693+atomic_unchecked_t fscache_n_object_lookups_negative;
60694+atomic_unchecked_t fscache_n_object_lookups_positive;
60695+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60696+atomic_unchecked_t fscache_n_object_created;
60697+atomic_unchecked_t fscache_n_object_avail;
60698+atomic_unchecked_t fscache_n_object_dead;
60699
60700-atomic_t fscache_n_checkaux_none;
60701-atomic_t fscache_n_checkaux_okay;
60702-atomic_t fscache_n_checkaux_update;
60703-atomic_t fscache_n_checkaux_obsolete;
60704+atomic_unchecked_t fscache_n_checkaux_none;
60705+atomic_unchecked_t fscache_n_checkaux_okay;
60706+atomic_unchecked_t fscache_n_checkaux_update;
60707+atomic_unchecked_t fscache_n_checkaux_obsolete;
60708
60709 atomic_t fscache_n_cop_alloc_object;
60710 atomic_t fscache_n_cop_lookup_object;
60711@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60712 seq_puts(m, "FS-Cache statistics\n");
60713
60714 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60715- atomic_read(&fscache_n_cookie_index),
60716- atomic_read(&fscache_n_cookie_data),
60717- atomic_read(&fscache_n_cookie_special));
60718+ atomic_read_unchecked(&fscache_n_cookie_index),
60719+ atomic_read_unchecked(&fscache_n_cookie_data),
60720+ atomic_read_unchecked(&fscache_n_cookie_special));
60721
60722 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60723- atomic_read(&fscache_n_object_alloc),
60724- atomic_read(&fscache_n_object_no_alloc),
60725- atomic_read(&fscache_n_object_avail),
60726- atomic_read(&fscache_n_object_dead));
60727+ atomic_read_unchecked(&fscache_n_object_alloc),
60728+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60729+ atomic_read_unchecked(&fscache_n_object_avail),
60730+ atomic_read_unchecked(&fscache_n_object_dead));
60731 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60732- atomic_read(&fscache_n_checkaux_none),
60733- atomic_read(&fscache_n_checkaux_okay),
60734- atomic_read(&fscache_n_checkaux_update),
60735- atomic_read(&fscache_n_checkaux_obsolete));
60736+ atomic_read_unchecked(&fscache_n_checkaux_none),
60737+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60738+ atomic_read_unchecked(&fscache_n_checkaux_update),
60739+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60740
60741 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60742- atomic_read(&fscache_n_marks),
60743- atomic_read(&fscache_n_uncaches));
60744+ atomic_read_unchecked(&fscache_n_marks),
60745+ atomic_read_unchecked(&fscache_n_uncaches));
60746
60747 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60748 " oom=%u\n",
60749- atomic_read(&fscache_n_acquires),
60750- atomic_read(&fscache_n_acquires_null),
60751- atomic_read(&fscache_n_acquires_no_cache),
60752- atomic_read(&fscache_n_acquires_ok),
60753- atomic_read(&fscache_n_acquires_nobufs),
60754- atomic_read(&fscache_n_acquires_oom));
60755+ atomic_read_unchecked(&fscache_n_acquires),
60756+ atomic_read_unchecked(&fscache_n_acquires_null),
60757+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60758+ atomic_read_unchecked(&fscache_n_acquires_ok),
60759+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60760+ atomic_read_unchecked(&fscache_n_acquires_oom));
60761
60762 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60763- atomic_read(&fscache_n_object_lookups),
60764- atomic_read(&fscache_n_object_lookups_negative),
60765- atomic_read(&fscache_n_object_lookups_positive),
60766- atomic_read(&fscache_n_object_created),
60767- atomic_read(&fscache_n_object_lookups_timed_out));
60768+ atomic_read_unchecked(&fscache_n_object_lookups),
60769+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60770+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60771+ atomic_read_unchecked(&fscache_n_object_created),
60772+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60773
60774 seq_printf(m, "Invals : n=%u run=%u\n",
60775- atomic_read(&fscache_n_invalidates),
60776- atomic_read(&fscache_n_invalidates_run));
60777+ atomic_read_unchecked(&fscache_n_invalidates),
60778+ atomic_read_unchecked(&fscache_n_invalidates_run));
60779
60780 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60781- atomic_read(&fscache_n_updates),
60782- atomic_read(&fscache_n_updates_null),
60783- atomic_read(&fscache_n_updates_run));
60784+ atomic_read_unchecked(&fscache_n_updates),
60785+ atomic_read_unchecked(&fscache_n_updates_null),
60786+ atomic_read_unchecked(&fscache_n_updates_run));
60787
60788 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60789- atomic_read(&fscache_n_relinquishes),
60790- atomic_read(&fscache_n_relinquishes_null),
60791- atomic_read(&fscache_n_relinquishes_waitcrt),
60792- atomic_read(&fscache_n_relinquishes_retire));
60793+ atomic_read_unchecked(&fscache_n_relinquishes),
60794+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60795+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60796+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60797
60798 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60799- atomic_read(&fscache_n_attr_changed),
60800- atomic_read(&fscache_n_attr_changed_ok),
60801- atomic_read(&fscache_n_attr_changed_nobufs),
60802- atomic_read(&fscache_n_attr_changed_nomem),
60803- atomic_read(&fscache_n_attr_changed_calls));
60804+ atomic_read_unchecked(&fscache_n_attr_changed),
60805+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60806+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60807+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60808+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60809
60810 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60811- atomic_read(&fscache_n_allocs),
60812- atomic_read(&fscache_n_allocs_ok),
60813- atomic_read(&fscache_n_allocs_wait),
60814- atomic_read(&fscache_n_allocs_nobufs),
60815- atomic_read(&fscache_n_allocs_intr));
60816+ atomic_read_unchecked(&fscache_n_allocs),
60817+ atomic_read_unchecked(&fscache_n_allocs_ok),
60818+ atomic_read_unchecked(&fscache_n_allocs_wait),
60819+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60820+ atomic_read_unchecked(&fscache_n_allocs_intr));
60821 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60822- atomic_read(&fscache_n_alloc_ops),
60823- atomic_read(&fscache_n_alloc_op_waits),
60824- atomic_read(&fscache_n_allocs_object_dead));
60825+ atomic_read_unchecked(&fscache_n_alloc_ops),
60826+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60827+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60828
60829 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60830 " int=%u oom=%u\n",
60831- atomic_read(&fscache_n_retrievals),
60832- atomic_read(&fscache_n_retrievals_ok),
60833- atomic_read(&fscache_n_retrievals_wait),
60834- atomic_read(&fscache_n_retrievals_nodata),
60835- atomic_read(&fscache_n_retrievals_nobufs),
60836- atomic_read(&fscache_n_retrievals_intr),
60837- atomic_read(&fscache_n_retrievals_nomem));
60838+ atomic_read_unchecked(&fscache_n_retrievals),
60839+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60840+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60841+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60842+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60843+ atomic_read_unchecked(&fscache_n_retrievals_intr),
60844+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
60845 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60846- atomic_read(&fscache_n_retrieval_ops),
60847- atomic_read(&fscache_n_retrieval_op_waits),
60848- atomic_read(&fscache_n_retrievals_object_dead));
60849+ atomic_read_unchecked(&fscache_n_retrieval_ops),
60850+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60851+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60852
60853 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60854- atomic_read(&fscache_n_stores),
60855- atomic_read(&fscache_n_stores_ok),
60856- atomic_read(&fscache_n_stores_again),
60857- atomic_read(&fscache_n_stores_nobufs),
60858- atomic_read(&fscache_n_stores_oom));
60859+ atomic_read_unchecked(&fscache_n_stores),
60860+ atomic_read_unchecked(&fscache_n_stores_ok),
60861+ atomic_read_unchecked(&fscache_n_stores_again),
60862+ atomic_read_unchecked(&fscache_n_stores_nobufs),
60863+ atomic_read_unchecked(&fscache_n_stores_oom));
60864 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60865- atomic_read(&fscache_n_store_ops),
60866- atomic_read(&fscache_n_store_calls),
60867- atomic_read(&fscache_n_store_pages),
60868- atomic_read(&fscache_n_store_radix_deletes),
60869- atomic_read(&fscache_n_store_pages_over_limit));
60870+ atomic_read_unchecked(&fscache_n_store_ops),
60871+ atomic_read_unchecked(&fscache_n_store_calls),
60872+ atomic_read_unchecked(&fscache_n_store_pages),
60873+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
60874+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60875
60876 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60877- atomic_read(&fscache_n_store_vmscan_not_storing),
60878- atomic_read(&fscache_n_store_vmscan_gone),
60879- atomic_read(&fscache_n_store_vmscan_busy),
60880- atomic_read(&fscache_n_store_vmscan_cancelled),
60881- atomic_read(&fscache_n_store_vmscan_wait));
60882+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60883+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60884+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60885+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60886+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60887
60888 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60889- atomic_read(&fscache_n_op_pend),
60890- atomic_read(&fscache_n_op_run),
60891- atomic_read(&fscache_n_op_enqueue),
60892- atomic_read(&fscache_n_op_cancelled),
60893- atomic_read(&fscache_n_op_rejected));
60894+ atomic_read_unchecked(&fscache_n_op_pend),
60895+ atomic_read_unchecked(&fscache_n_op_run),
60896+ atomic_read_unchecked(&fscache_n_op_enqueue),
60897+ atomic_read_unchecked(&fscache_n_op_cancelled),
60898+ atomic_read_unchecked(&fscache_n_op_rejected));
60899 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60900- atomic_read(&fscache_n_op_deferred_release),
60901- atomic_read(&fscache_n_op_release),
60902- atomic_read(&fscache_n_op_gc));
60903+ atomic_read_unchecked(&fscache_n_op_deferred_release),
60904+ atomic_read_unchecked(&fscache_n_op_release),
60905+ atomic_read_unchecked(&fscache_n_op_gc));
60906
60907 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60908 atomic_read(&fscache_n_cop_alloc_object),
60909diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60910index b96a49b..9bfdc47 100644
60911--- a/fs/fuse/cuse.c
60912+++ b/fs/fuse/cuse.c
60913@@ -606,10 +606,12 @@ static int __init cuse_init(void)
60914 INIT_LIST_HEAD(&cuse_conntbl[i]);
60915
60916 /* inherit and extend fuse_dev_operations */
60917- cuse_channel_fops = fuse_dev_operations;
60918- cuse_channel_fops.owner = THIS_MODULE;
60919- cuse_channel_fops.open = cuse_channel_open;
60920- cuse_channel_fops.release = cuse_channel_release;
60921+ pax_open_kernel();
60922+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60923+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60924+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
60925+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
60926+ pax_close_kernel();
60927
60928 cuse_class = class_create(THIS_MODULE, "cuse");
60929 if (IS_ERR(cuse_class))
60930diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60931index fa8cb4b..4acb935 100644
60932--- a/fs/fuse/dev.c
60933+++ b/fs/fuse/dev.c
60934@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60935 ret = 0;
60936 pipe_lock(pipe);
60937
60938- if (!pipe->readers) {
60939+ if (!atomic_read(&pipe->readers)) {
60940 send_sig(SIGPIPE, current, 0);
60941 if (!ret)
60942 ret = -EPIPE;
60943@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60944 page_nr++;
60945 ret += buf->len;
60946
60947- if (pipe->files)
60948+ if (atomic_read(&pipe->files))
60949 do_wakeup = 1;
60950 }
60951
60952diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60953index c3eb2c4..98007d4 100644
60954--- a/fs/fuse/dir.c
60955+++ b/fs/fuse/dir.c
60956@@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60957 return link;
60958 }
60959
60960-static void free_link(char *link)
60961+static void free_link(const char *link)
60962 {
60963 if (!IS_ERR(link))
60964 free_page((unsigned long) link);
60965diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60966index db23ce1..9e6cd9d 100644
60967--- a/fs/hostfs/hostfs_kern.c
60968+++ b/fs/hostfs/hostfs_kern.c
60969@@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60970
60971 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60972 {
60973- char *s = nd_get_link(nd);
60974+ const char *s = nd_get_link(nd);
60975 if (!IS_ERR(s))
60976 __putname(s);
60977 }
60978diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60979index d19b30a..ef89c36 100644
60980--- a/fs/hugetlbfs/inode.c
60981+++ b/fs/hugetlbfs/inode.c
60982@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60983 struct mm_struct *mm = current->mm;
60984 struct vm_area_struct *vma;
60985 struct hstate *h = hstate_file(file);
60986+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60987 struct vm_unmapped_area_info info;
60988
60989 if (len & ~huge_page_mask(h))
60990@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60991 return addr;
60992 }
60993
60994+#ifdef CONFIG_PAX_RANDMMAP
60995+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60996+#endif
60997+
60998 if (addr) {
60999 addr = ALIGN(addr, huge_page_size(h));
61000 vma = find_vma(mm, addr);
61001- if (TASK_SIZE - len >= addr &&
61002- (!vma || addr + len <= vma->vm_start))
61003+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61004 return addr;
61005 }
61006
61007 info.flags = 0;
61008 info.length = len;
61009 info.low_limit = TASK_UNMAPPED_BASE;
61010+
61011+#ifdef CONFIG_PAX_RANDMMAP
61012+ if (mm->pax_flags & MF_PAX_RANDMMAP)
61013+ info.low_limit += mm->delta_mmap;
61014+#endif
61015+
61016 info.high_limit = TASK_SIZE;
61017 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61018 info.align_offset = 0;
61019@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61020 };
61021 MODULE_ALIAS_FS("hugetlbfs");
61022
61023-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61024+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61025
61026 static int can_do_hugetlb_shm(void)
61027 {
61028diff --git a/fs/inode.c b/fs/inode.c
61029index 4bcdad3..1883822 100644
61030--- a/fs/inode.c
61031+++ b/fs/inode.c
61032@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
61033
61034 #ifdef CONFIG_SMP
61035 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61036- static atomic_t shared_last_ino;
61037- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61038+ static atomic_unchecked_t shared_last_ino;
61039+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61040
61041 res = next - LAST_INO_BATCH;
61042 }
61043diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61044index 4a6cf28..d3a29d3 100644
61045--- a/fs/jffs2/erase.c
61046+++ b/fs/jffs2/erase.c
61047@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61048 struct jffs2_unknown_node marker = {
61049 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61050 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61051- .totlen = cpu_to_je32(c->cleanmarker_size)
61052+ .totlen = cpu_to_je32(c->cleanmarker_size),
61053+ .hdr_crc = cpu_to_je32(0)
61054 };
61055
61056 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61057diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61058index a6597d6..41b30ec 100644
61059--- a/fs/jffs2/wbuf.c
61060+++ b/fs/jffs2/wbuf.c
61061@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61062 {
61063 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61064 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61065- .totlen = constant_cpu_to_je32(8)
61066+ .totlen = constant_cpu_to_je32(8),
61067+ .hdr_crc = constant_cpu_to_je32(0)
61068 };
61069
61070 /*
61071diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61072index 6669aa2..36b033d 100644
61073--- a/fs/jfs/super.c
61074+++ b/fs/jfs/super.c
61075@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
61076
61077 jfs_inode_cachep =
61078 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61079- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61080+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61081 init_once);
61082 if (jfs_inode_cachep == NULL)
61083 return -ENOMEM;
61084diff --git a/fs/libfs.c b/fs/libfs.c
61085index a184424..944ddce 100644
61086--- a/fs/libfs.c
61087+++ b/fs/libfs.c
61088@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61089
61090 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61091 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61092+ char d_name[sizeof(next->d_iname)];
61093+ const unsigned char *name;
61094+
61095 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61096 if (!simple_positive(next)) {
61097 spin_unlock(&next->d_lock);
61098@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61099
61100 spin_unlock(&next->d_lock);
61101 spin_unlock(&dentry->d_lock);
61102- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61103+ name = next->d_name.name;
61104+ if (name == next->d_iname) {
61105+ memcpy(d_name, name, next->d_name.len);
61106+ name = d_name;
61107+ }
61108+ if (!dir_emit(ctx, name, next->d_name.len,
61109 next->d_inode->i_ino, dt_type(next->d_inode)))
61110 return 0;
61111 spin_lock(&dentry->d_lock);
61112@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61113 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61114 void *cookie)
61115 {
61116- char *s = nd_get_link(nd);
61117+ const char *s = nd_get_link(nd);
61118 if (!IS_ERR(s))
61119 kfree(s);
61120 }
61121diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61122index acd3947..1f896e2 100644
61123--- a/fs/lockd/clntproc.c
61124+++ b/fs/lockd/clntproc.c
61125@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61126 /*
61127 * Cookie counter for NLM requests
61128 */
61129-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61130+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61131
61132 void nlmclnt_next_cookie(struct nlm_cookie *c)
61133 {
61134- u32 cookie = atomic_inc_return(&nlm_cookie);
61135+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61136
61137 memcpy(c->data, &cookie, 4);
61138 c->len=4;
61139diff --git a/fs/locks.c b/fs/locks.c
61140index 92a0f0a..45a48f0 100644
61141--- a/fs/locks.c
61142+++ b/fs/locks.c
61143@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61144 return;
61145
61146 if (filp->f_op->flock) {
61147- struct file_lock fl = {
61148+ struct file_lock flock = {
61149 .fl_pid = current->tgid,
61150 .fl_file = filp,
61151 .fl_flags = FL_FLOCK,
61152 .fl_type = F_UNLCK,
61153 .fl_end = OFFSET_MAX,
61154 };
61155- filp->f_op->flock(filp, F_SETLKW, &fl);
61156- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61157- fl.fl_ops->fl_release_private(&fl);
61158+ filp->f_op->flock(filp, F_SETLKW, &flock);
61159+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61160+ flock.fl_ops->fl_release_private(&flock);
61161 }
61162
61163 spin_lock(&inode->i_lock);
61164diff --git a/fs/mount.h b/fs/mount.h
61165index a17458c..e69fb5b 100644
61166--- a/fs/mount.h
61167+++ b/fs/mount.h
61168@@ -11,7 +11,7 @@ struct mnt_namespace {
61169 u64 seq; /* Sequence number to prevent loops */
61170 wait_queue_head_t poll;
61171 int event;
61172-};
61173+} __randomize_layout;
61174
61175 struct mnt_pcp {
61176 int mnt_count;
61177@@ -57,7 +57,7 @@ struct mount {
61178 int mnt_expiry_mark; /* true if marked for expiry */
61179 int mnt_pinned;
61180 struct path mnt_ex_mountpoint;
61181-};
61182+} __randomize_layout;
61183
61184 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61185
61186diff --git a/fs/namei.c b/fs/namei.c
61187index cfe6608..a24748c 100644
61188--- a/fs/namei.c
61189+++ b/fs/namei.c
61190@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61191 if (ret != -EACCES)
61192 return ret;
61193
61194+#ifdef CONFIG_GRKERNSEC
61195+ /* we'll block if we have to log due to a denied capability use */
61196+ if (mask & MAY_NOT_BLOCK)
61197+ return -ECHILD;
61198+#endif
61199+
61200 if (S_ISDIR(inode->i_mode)) {
61201 /* DACs are overridable for directories */
61202- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61203- return 0;
61204 if (!(mask & MAY_WRITE))
61205- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61206+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61207+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61208 return 0;
61209+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61210+ return 0;
61211 return -EACCES;
61212 }
61213 /*
61214+ * Searching includes executable on directories, else just read.
61215+ */
61216+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61217+ if (mask == MAY_READ)
61218+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61219+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61220+ return 0;
61221+
61222+ /*
61223 * Read/write DACs are always overridable.
61224 * Executable DACs are overridable when there is
61225 * at least one exec bit set.
61226@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61227 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61228 return 0;
61229
61230- /*
61231- * Searching includes executable on directories, else just read.
61232- */
61233- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61234- if (mask == MAY_READ)
61235- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61236- return 0;
61237-
61238 return -EACCES;
61239 }
61240
61241@@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61242 {
61243 struct dentry *dentry = link->dentry;
61244 int error;
61245- char *s;
61246+ const char *s;
61247
61248 BUG_ON(nd->flags & LOOKUP_RCU);
61249
61250@@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61251 if (error)
61252 goto out_put_nd_path;
61253
61254+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61255+ dentry->d_inode, dentry, nd->path.mnt)) {
61256+ error = -EACCES;
61257+ goto out_put_nd_path;
61258+ }
61259+
61260 nd->last_type = LAST_BIND;
61261 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61262 error = PTR_ERR(*p);
61263@@ -1098,7 +1112,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
61264 return false;
61265
61266 if (!d_mountpoint(path->dentry))
61267- break;
61268+ return true;
61269
61270 mounted = __lookup_mnt(path->mnt, path->dentry);
61271 if (!mounted)
61272@@ -1114,20 +1128,7 @@ static bool __follow_mount_rcu(struct nameidata *nd, struct path *path,
61273 */
61274 *inode = path->dentry->d_inode;
61275 }
61276- return true;
61277-}
61278-
61279-static void follow_mount_rcu(struct nameidata *nd)
61280-{
61281- while (d_mountpoint(nd->path.dentry)) {
61282- struct mount *mounted;
61283- mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry);
61284- if (!mounted)
61285- break;
61286- nd->path.mnt = &mounted->mnt;
61287- nd->path.dentry = mounted->mnt.mnt_root;
61288- nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
61289- }
61290+ return read_seqretry(&mount_lock, nd->m_seq);
61291 }
61292
61293 static int follow_dotdot_rcu(struct nameidata *nd)
61294@@ -1155,7 +1156,17 @@ static int follow_dotdot_rcu(struct nameidata *nd)
61295 break;
61296 nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
61297 }
61298- follow_mount_rcu(nd);
61299+ while (d_mountpoint(nd->path.dentry)) {
61300+ struct mount *mounted;
61301+ mounted = __lookup_mnt(nd->path.mnt, nd->path.dentry);
61302+ if (!mounted)
61303+ break;
61304+ nd->path.mnt = &mounted->mnt;
61305+ nd->path.dentry = mounted->mnt.mnt_root;
61306+ nd->seq = read_seqcount_begin(&nd->path.dentry->d_seq);
61307+ if (!read_seqretry(&mount_lock, nd->m_seq))
61308+ goto failed;
61309+ }
61310 nd->inode = nd->path.dentry->d_inode;
61311 return 0;
61312
61313@@ -1582,6 +1593,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61314 if (res)
61315 break;
61316 res = walk_component(nd, path, LOOKUP_FOLLOW);
61317+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61318+ res = -EACCES;
61319 put_link(nd, &link, cookie);
61320 } while (res > 0);
61321
61322@@ -1655,7 +1668,7 @@ EXPORT_SYMBOL(full_name_hash);
61323 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61324 {
61325 unsigned long a, b, adata, bdata, mask, hash, len;
61326- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61327+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61328
61329 hash = a = 0;
61330 len = -sizeof(unsigned long);
61331@@ -1939,6 +1952,8 @@ static int path_lookupat(int dfd, const char *name,
61332 if (err)
61333 break;
61334 err = lookup_last(nd, &path);
61335+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61336+ err = -EACCES;
61337 put_link(nd, &link, cookie);
61338 }
61339 }
61340@@ -1946,6 +1961,13 @@ static int path_lookupat(int dfd, const char *name,
61341 if (!err)
61342 err = complete_walk(nd);
61343
61344+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61345+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61346+ path_put(&nd->path);
61347+ err = -ENOENT;
61348+ }
61349+ }
61350+
61351 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61352 if (!d_is_directory(nd->path.dentry)) {
61353 path_put(&nd->path);
61354@@ -1973,8 +1995,15 @@ static int filename_lookup(int dfd, struct filename *name,
61355 retval = path_lookupat(dfd, name->name,
61356 flags | LOOKUP_REVAL, nd);
61357
61358- if (likely(!retval))
61359+ if (likely(!retval)) {
61360 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61361+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61362+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61363+ path_put(&nd->path);
61364+ return -ENOENT;
61365+ }
61366+ }
61367+ }
61368 return retval;
61369 }
61370
61371@@ -2548,6 +2577,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61372 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61373 return -EPERM;
61374
61375+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61376+ return -EPERM;
61377+ if (gr_handle_rawio(inode))
61378+ return -EPERM;
61379+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61380+ return -EACCES;
61381+
61382 return 0;
61383 }
61384
61385@@ -2779,7 +2815,7 @@ looked_up:
61386 * cleared otherwise prior to returning.
61387 */
61388 static int lookup_open(struct nameidata *nd, struct path *path,
61389- struct file *file,
61390+ struct path *link, struct file *file,
61391 const struct open_flags *op,
61392 bool got_write, int *opened)
61393 {
61394@@ -2814,6 +2850,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61395 /* Negative dentry, just create the file */
61396 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61397 umode_t mode = op->mode;
61398+
61399+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61400+ error = -EACCES;
61401+ goto out_dput;
61402+ }
61403+
61404+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61405+ error = -EACCES;
61406+ goto out_dput;
61407+ }
61408+
61409 if (!IS_POSIXACL(dir->d_inode))
61410 mode &= ~current_umask();
61411 /*
61412@@ -2835,6 +2882,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61413 nd->flags & LOOKUP_EXCL);
61414 if (error)
61415 goto out_dput;
61416+ else
61417+ gr_handle_create(dentry, nd->path.mnt);
61418 }
61419 out_no_open:
61420 path->dentry = dentry;
61421@@ -2849,7 +2898,7 @@ out_dput:
61422 /*
61423 * Handle the last step of open()
61424 */
61425-static int do_last(struct nameidata *nd, struct path *path,
61426+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61427 struct file *file, const struct open_flags *op,
61428 int *opened, struct filename *name)
61429 {
61430@@ -2899,6 +2948,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61431 if (error)
61432 return error;
61433
61434+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61435+ error = -ENOENT;
61436+ goto out;
61437+ }
61438+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61439+ error = -EACCES;
61440+ goto out;
61441+ }
61442+
61443 audit_inode(name, dir, LOOKUP_PARENT);
61444 error = -EISDIR;
61445 /* trailing slashes? */
61446@@ -2918,7 +2976,7 @@ retry_lookup:
61447 */
61448 }
61449 mutex_lock(&dir->d_inode->i_mutex);
61450- error = lookup_open(nd, path, file, op, got_write, opened);
61451+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61452 mutex_unlock(&dir->d_inode->i_mutex);
61453
61454 if (error <= 0) {
61455@@ -2942,11 +3000,28 @@ retry_lookup:
61456 goto finish_open_created;
61457 }
61458
61459+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61460+ error = -ENOENT;
61461+ goto exit_dput;
61462+ }
61463+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61464+ error = -EACCES;
61465+ goto exit_dput;
61466+ }
61467+
61468 /*
61469 * create/update audit record if it already exists.
61470 */
61471- if (d_is_positive(path->dentry))
61472+ if (d_is_positive(path->dentry)) {
61473+ /* only check if O_CREAT is specified, all other checks need to go
61474+ into may_open */
61475+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61476+ error = -EACCES;
61477+ goto exit_dput;
61478+ }
61479+
61480 audit_inode(name, path->dentry, 0);
61481+ }
61482
61483 /*
61484 * If atomic_open() acquired write access it is dropped now due to
61485@@ -2987,6 +3062,11 @@ finish_lookup:
61486 }
61487 }
61488 BUG_ON(inode != path->dentry->d_inode);
61489+ /* if we're resolving a symlink to another symlink */
61490+ if (link && gr_handle_symlink_owner(link, inode)) {
61491+ error = -EACCES;
61492+ goto out;
61493+ }
61494 return 1;
61495 }
61496
61497@@ -2996,7 +3076,6 @@ finish_lookup:
61498 save_parent.dentry = nd->path.dentry;
61499 save_parent.mnt = mntget(path->mnt);
61500 nd->path.dentry = path->dentry;
61501-
61502 }
61503 nd->inode = inode;
61504 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61505@@ -3006,7 +3085,18 @@ finish_open:
61506 path_put(&save_parent);
61507 return error;
61508 }
61509+
61510+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61511+ error = -ENOENT;
61512+ goto out;
61513+ }
61514+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61515+ error = -EACCES;
61516+ goto out;
61517+ }
61518+
61519 audit_inode(name, nd->path.dentry, 0);
61520+
61521 error = -EISDIR;
61522 if ((open_flag & O_CREAT) &&
61523 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61524@@ -3170,7 +3260,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61525 if (unlikely(error))
61526 goto out;
61527
61528- error = do_last(nd, &path, file, op, &opened, pathname);
61529+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61530 while (unlikely(error > 0)) { /* trailing symlink */
61531 struct path link = path;
61532 void *cookie;
61533@@ -3188,7 +3278,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61534 error = follow_link(&link, nd, &cookie);
61535 if (unlikely(error))
61536 break;
61537- error = do_last(nd, &path, file, op, &opened, pathname);
61538+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61539 put_link(nd, &link, cookie);
61540 }
61541 out:
61542@@ -3288,9 +3378,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61543 goto unlock;
61544
61545 error = -EEXIST;
61546- if (d_is_positive(dentry))
61547+ if (d_is_positive(dentry)) {
61548+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61549+ error = -ENOENT;
61550 goto fail;
61551-
61552+ }
61553 /*
61554 * Special case - lookup gave negative, but... we had foo/bar/
61555 * From the vfs_mknod() POV we just have a negative dentry -
61556@@ -3342,6 +3434,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61557 }
61558 EXPORT_SYMBOL(user_path_create);
61559
61560+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61561+{
61562+ struct filename *tmp = getname(pathname);
61563+ struct dentry *res;
61564+ if (IS_ERR(tmp))
61565+ return ERR_CAST(tmp);
61566+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61567+ if (IS_ERR(res))
61568+ putname(tmp);
61569+ else
61570+ *to = tmp;
61571+ return res;
61572+}
61573+
61574 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61575 {
61576 int error = may_create(dir, dentry);
61577@@ -3404,6 +3510,17 @@ retry:
61578
61579 if (!IS_POSIXACL(path.dentry->d_inode))
61580 mode &= ~current_umask();
61581+
61582+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61583+ error = -EPERM;
61584+ goto out;
61585+ }
61586+
61587+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61588+ error = -EACCES;
61589+ goto out;
61590+ }
61591+
61592 error = security_path_mknod(&path, dentry, mode, dev);
61593 if (error)
61594 goto out;
61595@@ -3420,6 +3537,8 @@ retry:
61596 break;
61597 }
61598 out:
61599+ if (!error)
61600+ gr_handle_create(dentry, path.mnt);
61601 done_path_create(&path, dentry);
61602 if (retry_estale(error, lookup_flags)) {
61603 lookup_flags |= LOOKUP_REVAL;
61604@@ -3472,9 +3591,16 @@ retry:
61605
61606 if (!IS_POSIXACL(path.dentry->d_inode))
61607 mode &= ~current_umask();
61608+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61609+ error = -EACCES;
61610+ goto out;
61611+ }
61612 error = security_path_mkdir(&path, dentry, mode);
61613 if (!error)
61614 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61615+ if (!error)
61616+ gr_handle_create(dentry, path.mnt);
61617+out:
61618 done_path_create(&path, dentry);
61619 if (retry_estale(error, lookup_flags)) {
61620 lookup_flags |= LOOKUP_REVAL;
61621@@ -3555,6 +3681,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61622 struct filename *name;
61623 struct dentry *dentry;
61624 struct nameidata nd;
61625+ ino_t saved_ino = 0;
61626+ dev_t saved_dev = 0;
61627 unsigned int lookup_flags = 0;
61628 retry:
61629 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61630@@ -3587,10 +3715,21 @@ retry:
61631 error = -ENOENT;
61632 goto exit3;
61633 }
61634+
61635+ saved_ino = dentry->d_inode->i_ino;
61636+ saved_dev = gr_get_dev_from_dentry(dentry);
61637+
61638+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61639+ error = -EACCES;
61640+ goto exit3;
61641+ }
61642+
61643 error = security_path_rmdir(&nd.path, dentry);
61644 if (error)
61645 goto exit3;
61646 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61647+ if (!error && (saved_dev || saved_ino))
61648+ gr_handle_delete(saved_ino, saved_dev);
61649 exit3:
61650 dput(dentry);
61651 exit2:
61652@@ -3680,6 +3819,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61653 struct nameidata nd;
61654 struct inode *inode = NULL;
61655 struct inode *delegated_inode = NULL;
61656+ ino_t saved_ino = 0;
61657+ dev_t saved_dev = 0;
61658 unsigned int lookup_flags = 0;
61659 retry:
61660 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61661@@ -3706,10 +3847,22 @@ retry_deleg:
61662 if (d_is_negative(dentry))
61663 goto slashes;
61664 ihold(inode);
61665+
61666+ if (inode->i_nlink <= 1) {
61667+ saved_ino = inode->i_ino;
61668+ saved_dev = gr_get_dev_from_dentry(dentry);
61669+ }
61670+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61671+ error = -EACCES;
61672+ goto exit2;
61673+ }
61674+
61675 error = security_path_unlink(&nd.path, dentry);
61676 if (error)
61677 goto exit2;
61678 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61679+ if (!error && (saved_ino || saved_dev))
61680+ gr_handle_delete(saved_ino, saved_dev);
61681 exit2:
61682 dput(dentry);
61683 }
61684@@ -3797,9 +3950,17 @@ retry:
61685 if (IS_ERR(dentry))
61686 goto out_putname;
61687
61688+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61689+ error = -EACCES;
61690+ goto out;
61691+ }
61692+
61693 error = security_path_symlink(&path, dentry, from->name);
61694 if (!error)
61695 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61696+ if (!error)
61697+ gr_handle_create(dentry, path.mnt);
61698+out:
61699 done_path_create(&path, dentry);
61700 if (retry_estale(error, lookup_flags)) {
61701 lookup_flags |= LOOKUP_REVAL;
61702@@ -3902,6 +4063,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61703 struct dentry *new_dentry;
61704 struct path old_path, new_path;
61705 struct inode *delegated_inode = NULL;
61706+ struct filename *to = NULL;
61707 int how = 0;
61708 int error;
61709
61710@@ -3925,7 +4087,7 @@ retry:
61711 if (error)
61712 return error;
61713
61714- new_dentry = user_path_create(newdfd, newname, &new_path,
61715+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61716 (how & LOOKUP_REVAL));
61717 error = PTR_ERR(new_dentry);
61718 if (IS_ERR(new_dentry))
61719@@ -3937,11 +4099,28 @@ retry:
61720 error = may_linkat(&old_path);
61721 if (unlikely(error))
61722 goto out_dput;
61723+
61724+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61725+ old_path.dentry->d_inode,
61726+ old_path.dentry->d_inode->i_mode, to)) {
61727+ error = -EACCES;
61728+ goto out_dput;
61729+ }
61730+
61731+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61732+ old_path.dentry, old_path.mnt, to)) {
61733+ error = -EACCES;
61734+ goto out_dput;
61735+ }
61736+
61737 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61738 if (error)
61739 goto out_dput;
61740 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61741+ if (!error)
61742+ gr_handle_create(new_dentry, new_path.mnt);
61743 out_dput:
61744+ putname(to);
61745 done_path_create(&new_path, new_dentry);
61746 if (delegated_inode) {
61747 error = break_deleg_wait(&delegated_inode);
61748@@ -4228,6 +4407,12 @@ retry_deleg:
61749 if (new_dentry == trap)
61750 goto exit5;
61751
61752+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61753+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61754+ to);
61755+ if (error)
61756+ goto exit5;
61757+
61758 error = security_path_rename(&oldnd.path, old_dentry,
61759 &newnd.path, new_dentry);
61760 if (error)
61761@@ -4235,6 +4420,9 @@ retry_deleg:
61762 error = vfs_rename(old_dir->d_inode, old_dentry,
61763 new_dir->d_inode, new_dentry,
61764 &delegated_inode);
61765+ if (!error)
61766+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61767+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61768 exit5:
61769 dput(new_dentry);
61770 exit4:
61771@@ -4271,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61772
61773 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61774 {
61775+ char tmpbuf[64];
61776+ const char *newlink;
61777 int len;
61778
61779 len = PTR_ERR(link);
61780@@ -4280,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61781 len = strlen(link);
61782 if (len > (unsigned) buflen)
61783 len = buflen;
61784- if (copy_to_user(buffer, link, len))
61785+
61786+ if (len < sizeof(tmpbuf)) {
61787+ memcpy(tmpbuf, link, len);
61788+ newlink = tmpbuf;
61789+ } else
61790+ newlink = link;
61791+
61792+ if (copy_to_user(buffer, newlink, len))
61793 len = -EFAULT;
61794 out:
61795 return len;
61796diff --git a/fs/namespace.c b/fs/namespace.c
61797index be32ebc..c595734 100644
61798--- a/fs/namespace.c
61799+++ b/fs/namespace.c
61800@@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
61801 if (!(sb->s_flags & MS_RDONLY))
61802 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61803 up_write(&sb->s_umount);
61804+
61805+ gr_log_remount(mnt->mnt_devname, retval);
61806+
61807 return retval;
61808 }
61809
61810@@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
61811 }
61812 unlock_mount_hash();
61813 namespace_unlock();
61814+
61815+ gr_log_unmount(mnt->mnt_devname, retval);
61816+
61817 return retval;
61818 }
61819
61820@@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
61821 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61822 */
61823
61824-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61825+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61826 {
61827 struct path path;
61828 struct mount *mnt;
61829@@ -1376,7 +1382,7 @@ out:
61830 /*
61831 * The 2.0 compatible umount. No flags.
61832 */
61833-SYSCALL_DEFINE1(oldumount, char __user *, name)
61834+SYSCALL_DEFINE1(oldumount, const char __user *, name)
61835 {
61836 return sys_umount(name, 0);
61837 }
61838@@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61839 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61840 MS_STRICTATIME);
61841
61842+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61843+ retval = -EPERM;
61844+ goto dput_out;
61845+ }
61846+
61847+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61848+ retval = -EPERM;
61849+ goto dput_out;
61850+ }
61851+
61852 if (flags & MS_REMOUNT)
61853 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61854 data_page);
61855@@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61856 dev_name, data_page);
61857 dput_out:
61858 path_put(&path);
61859+
61860+ gr_log_mount(dev_name, dir_name, retval);
61861+
61862 return retval;
61863 }
61864
61865@@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61866 * number incrementing at 10Ghz will take 12,427 years to wrap which
61867 * is effectively never, so we can ignore the possibility.
61868 */
61869-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61870+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61871
61872 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61873 {
61874@@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61875 kfree(new_ns);
61876 return ERR_PTR(ret);
61877 }
61878- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61879+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61880 atomic_set(&new_ns->count, 1);
61881 new_ns->root = NULL;
61882 INIT_LIST_HEAD(&new_ns->list);
61883@@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61884 return new_ns;
61885 }
61886
61887-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61888+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61889 struct user_namespace *user_ns, struct fs_struct *new_fs)
61890 {
61891 struct mnt_namespace *new_ns;
61892@@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61893 }
61894 EXPORT_SYMBOL(mount_subtree);
61895
61896-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61897- char __user *, type, unsigned long, flags, void __user *, data)
61898+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61899+ const char __user *, type, unsigned long, flags, void __user *, data)
61900 {
61901 int ret;
61902 char *kernel_type;
61903@@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61904 if (error)
61905 goto out2;
61906
61907+ if (gr_handle_chroot_pivot()) {
61908+ error = -EPERM;
61909+ goto out2;
61910+ }
61911+
61912 get_fs_root(current->fs, &root);
61913 old_mp = lock_mount(&old);
61914 error = PTR_ERR(old_mp);
61915@@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61916 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61917 return -EPERM;
61918
61919- if (fs->users != 1)
61920+ if (atomic_read(&fs->users) != 1)
61921 return -EINVAL;
61922
61923 get_mnt_ns(mnt_ns);
61924diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61925index f4ccfe6..a5cf064 100644
61926--- a/fs/nfs/callback_xdr.c
61927+++ b/fs/nfs/callback_xdr.c
61928@@ -51,7 +51,7 @@ struct callback_op {
61929 callback_decode_arg_t decode_args;
61930 callback_encode_res_t encode_res;
61931 long res_maxsize;
61932-};
61933+} __do_const;
61934
61935 static struct callback_op callback_ops[];
61936
61937diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61938index 5d94c02..630214f 100644
61939--- a/fs/nfs/inode.c
61940+++ b/fs/nfs/inode.c
61941@@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61942 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61943 }
61944
61945-static atomic_long_t nfs_attr_generation_counter;
61946+static atomic_long_unchecked_t nfs_attr_generation_counter;
61947
61948 static unsigned long nfs_read_attr_generation_counter(void)
61949 {
61950- return atomic_long_read(&nfs_attr_generation_counter);
61951+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61952 }
61953
61954 unsigned long nfs_inc_attr_generation_counter(void)
61955 {
61956- return atomic_long_inc_return(&nfs_attr_generation_counter);
61957+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61958 }
61959
61960 void nfs_fattr_init(struct nfs_fattr *fattr)
61961diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61962index 419572f..5414a23 100644
61963--- a/fs/nfsd/nfs4proc.c
61964+++ b/fs/nfsd/nfs4proc.c
61965@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61966 nfsd4op_rsize op_rsize_bop;
61967 stateid_getter op_get_currentstateid;
61968 stateid_setter op_set_currentstateid;
61969-};
61970+} __do_const;
61971
61972 static struct nfsd4_operation nfsd4_ops[];
61973
61974diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61975index ee7237f..e3ae60a 100644
61976--- a/fs/nfsd/nfs4xdr.c
61977+++ b/fs/nfsd/nfs4xdr.c
61978@@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61979
61980 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61981
61982-static nfsd4_dec nfsd4_dec_ops[] = {
61983+static const nfsd4_dec nfsd4_dec_ops[] = {
61984 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61985 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61986 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61987diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61988index b6af150..f6ec5e3 100644
61989--- a/fs/nfsd/nfscache.c
61990+++ b/fs/nfsd/nfscache.c
61991@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61992 {
61993 struct svc_cacherep *rp = rqstp->rq_cacherep;
61994 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61995- int len;
61996+ long len;
61997 size_t bufsize = 0;
61998
61999 if (!rp)
62000 return;
62001
62002- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62003- len >>= 2;
62004+ if (statp) {
62005+ len = (char*)statp - (char*)resv->iov_base;
62006+ len = resv->iov_len - len;
62007+ len >>= 2;
62008+ }
62009
62010 /* Don't cache excessive amounts of data and XDR failures */
62011 if (!statp || len > (256 >> 2)) {
62012diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62013index 7eea63c..a35f4fb 100644
62014--- a/fs/nfsd/vfs.c
62015+++ b/fs/nfsd/vfs.c
62016@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62017 } else {
62018 oldfs = get_fs();
62019 set_fs(KERNEL_DS);
62020- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62021+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62022 set_fs(oldfs);
62023 }
62024
62025@@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62026
62027 /* Write the data. */
62028 oldfs = get_fs(); set_fs(KERNEL_DS);
62029- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62030+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62031 set_fs(oldfs);
62032 if (host_err < 0)
62033 goto out_nfserr;
62034@@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62035 */
62036
62037 oldfs = get_fs(); set_fs(KERNEL_DS);
62038- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62039+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62040 set_fs(oldfs);
62041
62042 if (host_err < 0)
62043diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62044index fea6bd5..8ee9d81 100644
62045--- a/fs/nls/nls_base.c
62046+++ b/fs/nls/nls_base.c
62047@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62048
62049 int register_nls(struct nls_table * nls)
62050 {
62051- struct nls_table ** tmp = &tables;
62052+ struct nls_table *tmp = tables;
62053
62054 if (nls->next)
62055 return -EBUSY;
62056
62057 spin_lock(&nls_lock);
62058- while (*tmp) {
62059- if (nls == *tmp) {
62060+ while (tmp) {
62061+ if (nls == tmp) {
62062 spin_unlock(&nls_lock);
62063 return -EBUSY;
62064 }
62065- tmp = &(*tmp)->next;
62066+ tmp = tmp->next;
62067 }
62068- nls->next = tables;
62069+ pax_open_kernel();
62070+ *(struct nls_table **)&nls->next = tables;
62071+ pax_close_kernel();
62072 tables = nls;
62073 spin_unlock(&nls_lock);
62074 return 0;
62075@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
62076
62077 int unregister_nls(struct nls_table * nls)
62078 {
62079- struct nls_table ** tmp = &tables;
62080+ struct nls_table * const * tmp = &tables;
62081
62082 spin_lock(&nls_lock);
62083 while (*tmp) {
62084 if (nls == *tmp) {
62085- *tmp = nls->next;
62086+ pax_open_kernel();
62087+ *(struct nls_table **)tmp = nls->next;
62088+ pax_close_kernel();
62089 spin_unlock(&nls_lock);
62090 return 0;
62091 }
62092diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62093index 7424929..35f6be5 100644
62094--- a/fs/nls/nls_euc-jp.c
62095+++ b/fs/nls/nls_euc-jp.c
62096@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
62097 p_nls = load_nls("cp932");
62098
62099 if (p_nls) {
62100- table.charset2upper = p_nls->charset2upper;
62101- table.charset2lower = p_nls->charset2lower;
62102+ pax_open_kernel();
62103+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62104+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62105+ pax_close_kernel();
62106 return register_nls(&table);
62107 }
62108
62109diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62110index e7bc1d7..06bd4bb 100644
62111--- a/fs/nls/nls_koi8-ru.c
62112+++ b/fs/nls/nls_koi8-ru.c
62113@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
62114 p_nls = load_nls("koi8-u");
62115
62116 if (p_nls) {
62117- table.charset2upper = p_nls->charset2upper;
62118- table.charset2lower = p_nls->charset2lower;
62119+ pax_open_kernel();
62120+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62121+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62122+ pax_close_kernel();
62123 return register_nls(&table);
62124 }
62125
62126diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62127index 6663511..7668ca4 100644
62128--- a/fs/notify/fanotify/fanotify_user.c
62129+++ b/fs/notify/fanotify/fanotify_user.c
62130@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62131
62132 fd = fanotify_event_metadata.fd;
62133 ret = -EFAULT;
62134- if (copy_to_user(buf, &fanotify_event_metadata,
62135- fanotify_event_metadata.event_len))
62136+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62137+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62138 goto out_close_fd;
62139
62140 ret = prepare_for_access_response(group, event, fd);
62141diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62142index 7b51b05..5ea5ef6 100644
62143--- a/fs/notify/notification.c
62144+++ b/fs/notify/notification.c
62145@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
62146 * get set to 0 so it will never get 'freed'
62147 */
62148 static struct fsnotify_event *q_overflow_event;
62149-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62150+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62151
62152 /**
62153 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62154@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62155 */
62156 u32 fsnotify_get_cookie(void)
62157 {
62158- return atomic_inc_return(&fsnotify_sync_cookie);
62159+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62160 }
62161 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62162
62163diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62164index 9e38daf..5727cae 100644
62165--- a/fs/ntfs/dir.c
62166+++ b/fs/ntfs/dir.c
62167@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62168 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62169 ~(s64)(ndir->itype.index.block_size - 1)));
62170 /* Bounds checks. */
62171- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62172+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62173 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62174 "inode 0x%lx or driver bug.", vdir->i_ino);
62175 goto err_out;
62176diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62177index ea4ba9d..1e13d34 100644
62178--- a/fs/ntfs/file.c
62179+++ b/fs/ntfs/file.c
62180@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62181 char *addr;
62182 size_t total = 0;
62183 unsigned len;
62184- int left;
62185+ unsigned left;
62186
62187 do {
62188 len = PAGE_CACHE_SIZE - ofs;
62189diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62190index 82650d5..db37dcf 100644
62191--- a/fs/ntfs/super.c
62192+++ b/fs/ntfs/super.c
62193@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62194 if (!silent)
62195 ntfs_error(sb, "Primary boot sector is invalid.");
62196 } else if (!silent)
62197- ntfs_error(sb, read_err_str, "primary");
62198+ ntfs_error(sb, read_err_str, "%s", "primary");
62199 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62200 if (bh_primary)
62201 brelse(bh_primary);
62202@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62203 goto hotfix_primary_boot_sector;
62204 brelse(bh_backup);
62205 } else if (!silent)
62206- ntfs_error(sb, read_err_str, "backup");
62207+ ntfs_error(sb, read_err_str, "%s", "backup");
62208 /* Try to read NT3.51- backup boot sector. */
62209 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62210 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62211@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62212 "sector.");
62213 brelse(bh_backup);
62214 } else if (!silent)
62215- ntfs_error(sb, read_err_str, "backup");
62216+ ntfs_error(sb, read_err_str, "%s", "backup");
62217 /* We failed. Cleanup and return. */
62218 if (bh_primary)
62219 brelse(bh_primary);
62220diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62221index cd5496b..26a1055 100644
62222--- a/fs/ocfs2/localalloc.c
62223+++ b/fs/ocfs2/localalloc.c
62224@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62225 goto bail;
62226 }
62227
62228- atomic_inc(&osb->alloc_stats.moves);
62229+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62230
62231 bail:
62232 if (handle)
62233diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62234index 3a90347..c40bef8 100644
62235--- a/fs/ocfs2/ocfs2.h
62236+++ b/fs/ocfs2/ocfs2.h
62237@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62238
62239 struct ocfs2_alloc_stats
62240 {
62241- atomic_t moves;
62242- atomic_t local_data;
62243- atomic_t bitmap_data;
62244- atomic_t bg_allocs;
62245- atomic_t bg_extends;
62246+ atomic_unchecked_t moves;
62247+ atomic_unchecked_t local_data;
62248+ atomic_unchecked_t bitmap_data;
62249+ atomic_unchecked_t bg_allocs;
62250+ atomic_unchecked_t bg_extends;
62251 };
62252
62253 enum ocfs2_local_alloc_state
62254diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62255index 2c91452..77a3cd2 100644
62256--- a/fs/ocfs2/suballoc.c
62257+++ b/fs/ocfs2/suballoc.c
62258@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62259 mlog_errno(status);
62260 goto bail;
62261 }
62262- atomic_inc(&osb->alloc_stats.bg_extends);
62263+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62264
62265 /* You should never ask for this much metadata */
62266 BUG_ON(bits_wanted >
62267@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62268 mlog_errno(status);
62269 goto bail;
62270 }
62271- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62272+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62273
62274 *suballoc_loc = res.sr_bg_blkno;
62275 *suballoc_bit_start = res.sr_bit_offset;
62276@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62277 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62278 res->sr_bits);
62279
62280- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62281+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62282
62283 BUG_ON(res->sr_bits != 1);
62284
62285@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62286 mlog_errno(status);
62287 goto bail;
62288 }
62289- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62290+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62291
62292 BUG_ON(res.sr_bits != 1);
62293
62294@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62295 cluster_start,
62296 num_clusters);
62297 if (!status)
62298- atomic_inc(&osb->alloc_stats.local_data);
62299+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62300 } else {
62301 if (min_clusters > (osb->bitmap_cpg - 1)) {
62302 /* The only paths asking for contiguousness
62303@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62304 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62305 res.sr_bg_blkno,
62306 res.sr_bit_offset);
62307- atomic_inc(&osb->alloc_stats.bitmap_data);
62308+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62309 *num_clusters = res.sr_bits;
62310 }
62311 }
62312diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62313index c414929..5c9ee542 100644
62314--- a/fs/ocfs2/super.c
62315+++ b/fs/ocfs2/super.c
62316@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62317 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62318 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62319 "Stats",
62320- atomic_read(&osb->alloc_stats.bitmap_data),
62321- atomic_read(&osb->alloc_stats.local_data),
62322- atomic_read(&osb->alloc_stats.bg_allocs),
62323- atomic_read(&osb->alloc_stats.moves),
62324- atomic_read(&osb->alloc_stats.bg_extends));
62325+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62326+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62327+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62328+ atomic_read_unchecked(&osb->alloc_stats.moves),
62329+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62330
62331 out += snprintf(buf + out, len - out,
62332 "%10s => State: %u Descriptor: %llu Size: %u bits "
62333@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62334 spin_lock_init(&osb->osb_xattr_lock);
62335 ocfs2_init_steal_slots(osb);
62336
62337- atomic_set(&osb->alloc_stats.moves, 0);
62338- atomic_set(&osb->alloc_stats.local_data, 0);
62339- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62340- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62341- atomic_set(&osb->alloc_stats.bg_extends, 0);
62342+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62343+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62344+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62345+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62346+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62347
62348 /* Copy the blockcheck stats from the superblock probe */
62349 osb->osb_ecc_stats = *stats;
62350diff --git a/fs/open.c b/fs/open.c
62351index 4b3e1ed..1c84599 100644
62352--- a/fs/open.c
62353+++ b/fs/open.c
62354@@ -32,6 +32,8 @@
62355 #include <linux/dnotify.h>
62356 #include <linux/compat.h>
62357
62358+#define CREATE_TRACE_POINTS
62359+#include <trace/events/fs.h>
62360 #include "internal.h"
62361
62362 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62363@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62364 error = locks_verify_truncate(inode, NULL, length);
62365 if (!error)
62366 error = security_path_truncate(path);
62367+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62368+ error = -EACCES;
62369 if (!error)
62370 error = do_truncate(path->dentry, length, 0, NULL);
62371
62372@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62373 error = locks_verify_truncate(inode, f.file, length);
62374 if (!error)
62375 error = security_path_truncate(&f.file->f_path);
62376+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62377+ error = -EACCES;
62378 if (!error)
62379 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62380 sb_end_write(inode->i_sb);
62381@@ -361,6 +367,9 @@ retry:
62382 if (__mnt_is_readonly(path.mnt))
62383 res = -EROFS;
62384
62385+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62386+ res = -EACCES;
62387+
62388 out_path_release:
62389 path_put(&path);
62390 if (retry_estale(res, lookup_flags)) {
62391@@ -392,6 +401,8 @@ retry:
62392 if (error)
62393 goto dput_and_out;
62394
62395+ gr_log_chdir(path.dentry, path.mnt);
62396+
62397 set_fs_pwd(current->fs, &path);
62398
62399 dput_and_out:
62400@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62401 goto out_putf;
62402
62403 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62404+
62405+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62406+ error = -EPERM;
62407+
62408+ if (!error)
62409+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62410+
62411 if (!error)
62412 set_fs_pwd(current->fs, &f.file->f_path);
62413 out_putf:
62414@@ -450,7 +468,13 @@ retry:
62415 if (error)
62416 goto dput_and_out;
62417
62418+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62419+ goto dput_and_out;
62420+
62421 set_fs_root(current->fs, &path);
62422+
62423+ gr_handle_chroot_chdir(&path);
62424+
62425 error = 0;
62426 dput_and_out:
62427 path_put(&path);
62428@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62429 return error;
62430 retry_deleg:
62431 mutex_lock(&inode->i_mutex);
62432+
62433+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62434+ error = -EACCES;
62435+ goto out_unlock;
62436+ }
62437+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62438+ error = -EACCES;
62439+ goto out_unlock;
62440+ }
62441+
62442 error = security_path_chmod(path, mode);
62443 if (error)
62444 goto out_unlock;
62445@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62446 uid = make_kuid(current_user_ns(), user);
62447 gid = make_kgid(current_user_ns(), group);
62448
62449+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62450+ return -EACCES;
62451+
62452 newattrs.ia_valid = ATTR_CTIME;
62453 if (user != (uid_t) -1) {
62454 if (!uid_valid(uid))
62455@@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62456 } else {
62457 fsnotify_open(f);
62458 fd_install(fd, f);
62459+ trace_do_sys_open(tmp->name, flags, mode);
62460 }
62461 }
62462 putname(tmp);
62463diff --git a/fs/pipe.c b/fs/pipe.c
62464index 0e0752e..7cfdd50 100644
62465--- a/fs/pipe.c
62466+++ b/fs/pipe.c
62467@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62468
62469 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62470 {
62471- if (pipe->files)
62472+ if (atomic_read(&pipe->files))
62473 mutex_lock_nested(&pipe->mutex, subclass);
62474 }
62475
62476@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62477
62478 void pipe_unlock(struct pipe_inode_info *pipe)
62479 {
62480- if (pipe->files)
62481+ if (atomic_read(&pipe->files))
62482 mutex_unlock(&pipe->mutex);
62483 }
62484 EXPORT_SYMBOL(pipe_unlock);
62485@@ -449,9 +449,9 @@ redo:
62486 }
62487 if (bufs) /* More to do? */
62488 continue;
62489- if (!pipe->writers)
62490+ if (!atomic_read(&pipe->writers))
62491 break;
62492- if (!pipe->waiting_writers) {
62493+ if (!atomic_read(&pipe->waiting_writers)) {
62494 /* syscall merging: Usually we must not sleep
62495 * if O_NONBLOCK is set, or if we got some data.
62496 * But if a writer sleeps in kernel space, then
62497@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62498 ret = 0;
62499 __pipe_lock(pipe);
62500
62501- if (!pipe->readers) {
62502+ if (!atomic_read(&pipe->readers)) {
62503 send_sig(SIGPIPE, current, 0);
62504 ret = -EPIPE;
62505 goto out;
62506@@ -562,7 +562,7 @@ redo1:
62507 for (;;) {
62508 int bufs;
62509
62510- if (!pipe->readers) {
62511+ if (!atomic_read(&pipe->readers)) {
62512 send_sig(SIGPIPE, current, 0);
62513 if (!ret)
62514 ret = -EPIPE;
62515@@ -653,9 +653,9 @@ redo2:
62516 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62517 do_wakeup = 0;
62518 }
62519- pipe->waiting_writers++;
62520+ atomic_inc(&pipe->waiting_writers);
62521 pipe_wait(pipe);
62522- pipe->waiting_writers--;
62523+ atomic_dec(&pipe->waiting_writers);
62524 }
62525 out:
62526 __pipe_unlock(pipe);
62527@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62528 mask = 0;
62529 if (filp->f_mode & FMODE_READ) {
62530 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62531- if (!pipe->writers && filp->f_version != pipe->w_counter)
62532+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62533 mask |= POLLHUP;
62534 }
62535
62536@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62537 * Most Unices do not set POLLERR for FIFOs but on Linux they
62538 * behave exactly like pipes for poll().
62539 */
62540- if (!pipe->readers)
62541+ if (!atomic_read(&pipe->readers))
62542 mask |= POLLERR;
62543 }
62544
62545@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62546 int kill = 0;
62547
62548 spin_lock(&inode->i_lock);
62549- if (!--pipe->files) {
62550+ if (atomic_dec_and_test(&pipe->files)) {
62551 inode->i_pipe = NULL;
62552 kill = 1;
62553 }
62554@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62555
62556 __pipe_lock(pipe);
62557 if (file->f_mode & FMODE_READ)
62558- pipe->readers--;
62559+ atomic_dec(&pipe->readers);
62560 if (file->f_mode & FMODE_WRITE)
62561- pipe->writers--;
62562+ atomic_dec(&pipe->writers);
62563
62564- if (pipe->readers || pipe->writers) {
62565+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62566 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62567 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62568 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62569@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62570 kfree(pipe);
62571 }
62572
62573-static struct vfsmount *pipe_mnt __read_mostly;
62574+struct vfsmount *pipe_mnt __read_mostly;
62575
62576 /*
62577 * pipefs_dname() is called from d_path().
62578@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62579 goto fail_iput;
62580
62581 inode->i_pipe = pipe;
62582- pipe->files = 2;
62583- pipe->readers = pipe->writers = 1;
62584+ atomic_set(&pipe->files, 2);
62585+ atomic_set(&pipe->readers, 1);
62586+ atomic_set(&pipe->writers, 1);
62587 inode->i_fop = &pipefifo_fops;
62588
62589 /*
62590@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62591 spin_lock(&inode->i_lock);
62592 if (inode->i_pipe) {
62593 pipe = inode->i_pipe;
62594- pipe->files++;
62595+ atomic_inc(&pipe->files);
62596 spin_unlock(&inode->i_lock);
62597 } else {
62598 spin_unlock(&inode->i_lock);
62599 pipe = alloc_pipe_info();
62600 if (!pipe)
62601 return -ENOMEM;
62602- pipe->files = 1;
62603+ atomic_set(&pipe->files, 1);
62604 spin_lock(&inode->i_lock);
62605 if (unlikely(inode->i_pipe)) {
62606- inode->i_pipe->files++;
62607+ atomic_inc(&inode->i_pipe->files);
62608 spin_unlock(&inode->i_lock);
62609 free_pipe_info(pipe);
62610 pipe = inode->i_pipe;
62611@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62612 * opened, even when there is no process writing the FIFO.
62613 */
62614 pipe->r_counter++;
62615- if (pipe->readers++ == 0)
62616+ if (atomic_inc_return(&pipe->readers) == 1)
62617 wake_up_partner(pipe);
62618
62619- if (!is_pipe && !pipe->writers) {
62620+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62621 if ((filp->f_flags & O_NONBLOCK)) {
62622 /* suppress POLLHUP until we have
62623 * seen a writer */
62624@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62625 * errno=ENXIO when there is no process reading the FIFO.
62626 */
62627 ret = -ENXIO;
62628- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62629+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62630 goto err;
62631
62632 pipe->w_counter++;
62633- if (!pipe->writers++)
62634+ if (atomic_inc_return(&pipe->writers) == 1)
62635 wake_up_partner(pipe);
62636
62637- if (!is_pipe && !pipe->readers) {
62638+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62639 if (wait_for_partner(pipe, &pipe->r_counter))
62640 goto err_wr;
62641 }
62642@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62643 * the process can at least talk to itself.
62644 */
62645
62646- pipe->readers++;
62647- pipe->writers++;
62648+ atomic_inc(&pipe->readers);
62649+ atomic_inc(&pipe->writers);
62650 pipe->r_counter++;
62651 pipe->w_counter++;
62652- if (pipe->readers == 1 || pipe->writers == 1)
62653+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62654 wake_up_partner(pipe);
62655 break;
62656
62657@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62658 return 0;
62659
62660 err_rd:
62661- if (!--pipe->readers)
62662+ if (atomic_dec_and_test(&pipe->readers))
62663 wake_up_interruptible(&pipe->wait);
62664 ret = -ERESTARTSYS;
62665 goto err;
62666
62667 err_wr:
62668- if (!--pipe->writers)
62669+ if (atomic_dec_and_test(&pipe->writers))
62670 wake_up_interruptible(&pipe->wait);
62671 ret = -ERESTARTSYS;
62672 goto err;
62673diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62674index 8bd2135..eab9adb 100644
62675--- a/fs/posix_acl.c
62676+++ b/fs/posix_acl.c
62677@@ -19,6 +19,7 @@
62678 #include <linux/sched.h>
62679 #include <linux/posix_acl.h>
62680 #include <linux/export.h>
62681+#include <linux/grsecurity.h>
62682
62683 #include <linux/errno.h>
62684
62685@@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62686 }
62687 }
62688 if (mode_p)
62689- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62690+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62691 return not_equiv;
62692 }
62693
62694@@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62695 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62696 }
62697
62698- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62699+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62700 return not_equiv;
62701 }
62702
62703@@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62704 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62705 int err = -ENOMEM;
62706 if (clone) {
62707+ *mode_p &= ~gr_acl_umask();
62708+
62709 err = posix_acl_create_masq(clone, mode_p);
62710 if (err < 0) {
62711 posix_acl_release(clone);
62712diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62713index 2183fcf..3c32a98 100644
62714--- a/fs/proc/Kconfig
62715+++ b/fs/proc/Kconfig
62716@@ -30,7 +30,7 @@ config PROC_FS
62717
62718 config PROC_KCORE
62719 bool "/proc/kcore support" if !ARM
62720- depends on PROC_FS && MMU
62721+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62722 help
62723 Provides a virtual ELF core file of the live kernel. This can
62724 be read with gdb and other ELF tools. No modifications can be
62725@@ -38,8 +38,8 @@ config PROC_KCORE
62726
62727 config PROC_VMCORE
62728 bool "/proc/vmcore support"
62729- depends on PROC_FS && CRASH_DUMP
62730- default y
62731+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62732+ default n
62733 help
62734 Exports the dump image of crashed kernel in ELF format.
62735
62736@@ -63,8 +63,8 @@ config PROC_SYSCTL
62737 limited in memory.
62738
62739 config PROC_PAGE_MONITOR
62740- default y
62741- depends on PROC_FS && MMU
62742+ default n
62743+ depends on PROC_FS && MMU && !GRKERNSEC
62744 bool "Enable /proc page monitoring" if EXPERT
62745 help
62746 Various /proc files exist to monitor process memory utilization:
62747diff --git a/fs/proc/array.c b/fs/proc/array.c
62748index 1bd2077..2f7cfd5 100644
62749--- a/fs/proc/array.c
62750+++ b/fs/proc/array.c
62751@@ -60,6 +60,7 @@
62752 #include <linux/tty.h>
62753 #include <linux/string.h>
62754 #include <linux/mman.h>
62755+#include <linux/grsecurity.h>
62756 #include <linux/proc_fs.h>
62757 #include <linux/ioport.h>
62758 #include <linux/uaccess.h>
62759@@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62760 seq_putc(m, '\n');
62761 }
62762
62763+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62764+static inline void task_pax(struct seq_file *m, struct task_struct *p)
62765+{
62766+ if (p->mm)
62767+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62768+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62769+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62770+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62771+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62772+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62773+ else
62774+ seq_printf(m, "PaX:\t-----\n");
62775+}
62776+#endif
62777+
62778 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62779 struct pid *pid, struct task_struct *task)
62780 {
62781@@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62782 task_cpus_allowed(m, task);
62783 cpuset_task_status_allowed(m, task);
62784 task_context_switch_counts(m, task);
62785+
62786+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62787+ task_pax(m, task);
62788+#endif
62789+
62790+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62791+ task_grsec_rbac(m, task);
62792+#endif
62793+
62794 return 0;
62795 }
62796
62797+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62798+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62799+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62800+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62801+#endif
62802+
62803 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62804 struct pid *pid, struct task_struct *task, int whole)
62805 {
62806@@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62807 char tcomm[sizeof(task->comm)];
62808 unsigned long flags;
62809
62810+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62811+ if (current->exec_id != m->exec_id) {
62812+ gr_log_badprocpid("stat");
62813+ return 0;
62814+ }
62815+#endif
62816+
62817 state = *get_task_state(task);
62818 vsize = eip = esp = 0;
62819 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62820@@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62821 gtime = task_gtime(task);
62822 }
62823
62824+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62825+ if (PAX_RAND_FLAGS(mm)) {
62826+ eip = 0;
62827+ esp = 0;
62828+ wchan = 0;
62829+ }
62830+#endif
62831+#ifdef CONFIG_GRKERNSEC_HIDESYM
62832+ wchan = 0;
62833+ eip =0;
62834+ esp =0;
62835+#endif
62836+
62837 /* scale priority and nice values from timeslices to -20..20 */
62838 /* to make it look like a "normal" Unix priority/nice value */
62839 priority = task_prio(task);
62840@@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62841 seq_put_decimal_ull(m, ' ', vsize);
62842 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62843 seq_put_decimal_ull(m, ' ', rsslim);
62844+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62845+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62846+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62847+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62848+#else
62849 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62850 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62851 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62852+#endif
62853 seq_put_decimal_ull(m, ' ', esp);
62854 seq_put_decimal_ull(m, ' ', eip);
62855 /* The signal information here is obsolete.
62856@@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62857 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62858 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62859
62860- if (mm && permitted) {
62861+ if (mm && permitted
62862+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62863+ && !PAX_RAND_FLAGS(mm)
62864+#endif
62865+ ) {
62866 seq_put_decimal_ull(m, ' ', mm->start_data);
62867 seq_put_decimal_ull(m, ' ', mm->end_data);
62868 seq_put_decimal_ull(m, ' ', mm->start_brk);
62869@@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62870 struct pid *pid, struct task_struct *task)
62871 {
62872 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62873- struct mm_struct *mm = get_task_mm(task);
62874+ struct mm_struct *mm;
62875
62876+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62877+ if (current->exec_id != m->exec_id) {
62878+ gr_log_badprocpid("statm");
62879+ return 0;
62880+ }
62881+#endif
62882+ mm = get_task_mm(task);
62883 if (mm) {
62884 size = task_statm(mm, &shared, &text, &data, &resident);
62885 mmput(mm);
62886@@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62887 return 0;
62888 }
62889
62890+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62891+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62892+{
62893+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62894+}
62895+#endif
62896+
62897 #ifdef CONFIG_CHECKPOINT_RESTORE
62898 static struct pid *
62899 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62900diff --git a/fs/proc/base.c b/fs/proc/base.c
62901index b59a34b..68a79e8 100644
62902--- a/fs/proc/base.c
62903+++ b/fs/proc/base.c
62904@@ -113,6 +113,14 @@ struct pid_entry {
62905 union proc_op op;
62906 };
62907
62908+struct getdents_callback {
62909+ struct linux_dirent __user * current_dir;
62910+ struct linux_dirent __user * previous;
62911+ struct file * file;
62912+ int count;
62913+ int error;
62914+};
62915+
62916 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62917 .name = (NAME), \
62918 .len = sizeof(NAME) - 1, \
62919@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62920 if (!mm->arg_end)
62921 goto out_mm; /* Shh! No looking before we're done */
62922
62923+ if (gr_acl_handle_procpidmem(task))
62924+ goto out_mm;
62925+
62926 len = mm->arg_end - mm->arg_start;
62927
62928 if (len > PAGE_SIZE)
62929@@ -237,12 +248,28 @@ out:
62930 return res;
62931 }
62932
62933+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62934+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62935+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62936+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62937+#endif
62938+
62939 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62940 {
62941 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62942 int res = PTR_ERR(mm);
62943 if (mm && !IS_ERR(mm)) {
62944 unsigned int nwords = 0;
62945+
62946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62947+ /* allow if we're currently ptracing this task */
62948+ if (PAX_RAND_FLAGS(mm) &&
62949+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62950+ mmput(mm);
62951+ return 0;
62952+ }
62953+#endif
62954+
62955 do {
62956 nwords += 2;
62957 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62958@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62959 }
62960
62961
62962-#ifdef CONFIG_KALLSYMS
62963+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62964 /*
62965 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62966 * Returns the resolved symbol. If that fails, simply return the address.
62967@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62968 mutex_unlock(&task->signal->cred_guard_mutex);
62969 }
62970
62971-#ifdef CONFIG_STACKTRACE
62972+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62973
62974 #define MAX_STACK_TRACE_DEPTH 64
62975
62976@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62977 return count;
62978 }
62979
62980-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62981+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62982 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62983 {
62984 long nr;
62985@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62986 /************************************************************************/
62987
62988 /* permission checks */
62989-static int proc_fd_access_allowed(struct inode *inode)
62990+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62991 {
62992 struct task_struct *task;
62993 int allowed = 0;
62994@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62995 */
62996 task = get_proc_task(inode);
62997 if (task) {
62998- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62999+ if (log)
63000+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63001+ else
63002+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63003 put_task_struct(task);
63004 }
63005 return allowed;
63006@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63007 struct task_struct *task,
63008 int hide_pid_min)
63009 {
63010+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63011+ return false;
63012+
63013+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63014+ rcu_read_lock();
63015+ {
63016+ const struct cred *tmpcred = current_cred();
63017+ const struct cred *cred = __task_cred(task);
63018+
63019+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63020+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63021+ || in_group_p(grsec_proc_gid)
63022+#endif
63023+ ) {
63024+ rcu_read_unlock();
63025+ return true;
63026+ }
63027+ }
63028+ rcu_read_unlock();
63029+
63030+ if (!pid->hide_pid)
63031+ return false;
63032+#endif
63033+
63034 if (pid->hide_pid < hide_pid_min)
63035 return true;
63036 if (in_group_p(pid->pid_gid))
63037 return true;
63038+
63039 return ptrace_may_access(task, PTRACE_MODE_READ);
63040 }
63041
63042@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63043 put_task_struct(task);
63044
63045 if (!has_perms) {
63046+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63047+ {
63048+#else
63049 if (pid->hide_pid == 2) {
63050+#endif
63051 /*
63052 * Let's make getdents(), stat(), and open()
63053 * consistent with each other. If a process
63054@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63055 if (!task)
63056 return -ESRCH;
63057
63058+ if (gr_acl_handle_procpidmem(task)) {
63059+ put_task_struct(task);
63060+ return -EPERM;
63061+ }
63062+
63063 mm = mm_access(task, mode);
63064 put_task_struct(task);
63065
63066@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63067
63068 file->private_data = mm;
63069
63070+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63071+ file->f_version = current->exec_id;
63072+#endif
63073+
63074 return 0;
63075 }
63076
63077@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63078 ssize_t copied;
63079 char *page;
63080
63081+#ifdef CONFIG_GRKERNSEC
63082+ if (write)
63083+ return -EPERM;
63084+#endif
63085+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63086+ if (file->f_version != current->exec_id) {
63087+ gr_log_badprocpid("mem");
63088+ return 0;
63089+ }
63090+#endif
63091+
63092 if (!mm)
63093 return 0;
63094
63095@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63096 goto free;
63097
63098 while (count > 0) {
63099- int this_len = min_t(int, count, PAGE_SIZE);
63100+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63101
63102 if (write && copy_from_user(page, buf, this_len)) {
63103 copied = -EFAULT;
63104@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63105 if (!mm)
63106 return 0;
63107
63108+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63109+ if (file->f_version != current->exec_id) {
63110+ gr_log_badprocpid("environ");
63111+ return 0;
63112+ }
63113+#endif
63114+
63115 page = (char *)__get_free_page(GFP_TEMPORARY);
63116 if (!page)
63117 return -ENOMEM;
63118@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63119 goto free;
63120 while (count > 0) {
63121 size_t this_len, max_len;
63122- int retval;
63123+ ssize_t retval;
63124
63125 if (src >= (mm->env_end - mm->env_start))
63126 break;
63127@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63128 int error = -EACCES;
63129
63130 /* Are we allowed to snoop on the tasks file descriptors? */
63131- if (!proc_fd_access_allowed(inode))
63132+ if (!proc_fd_access_allowed(inode, 0))
63133 goto out;
63134
63135 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63136@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63137 struct path path;
63138
63139 /* Are we allowed to snoop on the tasks file descriptors? */
63140- if (!proc_fd_access_allowed(inode))
63141- goto out;
63142+ /* logging this is needed for learning on chromium to work properly,
63143+ but we don't want to flood the logs from 'ps' which does a readlink
63144+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63145+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63146+ */
63147+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63148+ if (!proc_fd_access_allowed(inode,0))
63149+ goto out;
63150+ } else {
63151+ if (!proc_fd_access_allowed(inode,1))
63152+ goto out;
63153+ }
63154
63155 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63156 if (error)
63157@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63158 rcu_read_lock();
63159 cred = __task_cred(task);
63160 inode->i_uid = cred->euid;
63161+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63162+ inode->i_gid = grsec_proc_gid;
63163+#else
63164 inode->i_gid = cred->egid;
63165+#endif
63166 rcu_read_unlock();
63167 }
63168 security_task_to_inode(task, inode);
63169@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63170 return -ENOENT;
63171 }
63172 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63173+#ifdef CONFIG_GRKERNSEC_PROC_USER
63174+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63175+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63176+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63177+#endif
63178 task_dumpable(task)) {
63179 cred = __task_cred(task);
63180 stat->uid = cred->euid;
63181+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63182+ stat->gid = grsec_proc_gid;
63183+#else
63184 stat->gid = cred->egid;
63185+#endif
63186 }
63187 }
63188 rcu_read_unlock();
63189@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63190
63191 if (task) {
63192 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63193+#ifdef CONFIG_GRKERNSEC_PROC_USER
63194+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63195+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63196+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63197+#endif
63198 task_dumpable(task)) {
63199 rcu_read_lock();
63200 cred = __task_cred(task);
63201 inode->i_uid = cred->euid;
63202+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63203+ inode->i_gid = grsec_proc_gid;
63204+#else
63205 inode->i_gid = cred->egid;
63206+#endif
63207 rcu_read_unlock();
63208 } else {
63209 inode->i_uid = GLOBAL_ROOT_UID;
63210@@ -2173,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63211 if (!task)
63212 goto out_no_task;
63213
63214+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63215+ goto out;
63216+
63217 /*
63218 * Yes, it does not scale. And it should not. Don't add
63219 * new entries into /proc/<tgid>/ without very good reasons.
63220@@ -2203,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63221 if (!task)
63222 return -ENOENT;
63223
63224+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63225+ goto out;
63226+
63227 if (!dir_emit_dots(file, ctx))
63228 goto out;
63229
63230@@ -2592,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63231 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63232 #endif
63233 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63234-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63235+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63236 INF("syscall", S_IRUGO, proc_pid_syscall),
63237 #endif
63238 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63239@@ -2617,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63240 #ifdef CONFIG_SECURITY
63241 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63242 #endif
63243-#ifdef CONFIG_KALLSYMS
63244+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63245 INF("wchan", S_IRUGO, proc_pid_wchan),
63246 #endif
63247-#ifdef CONFIG_STACKTRACE
63248+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63249 ONE("stack", S_IRUGO, proc_pid_stack),
63250 #endif
63251 #ifdef CONFIG_SCHEDSTATS
63252@@ -2654,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63253 #ifdef CONFIG_HARDWALL
63254 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63255 #endif
63256+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63257+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63258+#endif
63259 #ifdef CONFIG_USER_NS
63260 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63261 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63262@@ -2784,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63263 if (!inode)
63264 goto out;
63265
63266+#ifdef CONFIG_GRKERNSEC_PROC_USER
63267+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63268+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63269+ inode->i_gid = grsec_proc_gid;
63270+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63271+#else
63272 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63273+#endif
63274 inode->i_op = &proc_tgid_base_inode_operations;
63275 inode->i_fop = &proc_tgid_base_operations;
63276 inode->i_flags|=S_IMMUTABLE;
63277@@ -2822,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63278 if (!task)
63279 goto out;
63280
63281+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63282+ goto out_put_task;
63283+
63284 result = proc_pid_instantiate(dir, dentry, task, NULL);
63285+out_put_task:
63286 put_task_struct(task);
63287 out:
63288 return ERR_PTR(result);
63289@@ -2928,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63290 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63291 #endif
63292 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63293-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63294+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63295 INF("syscall", S_IRUGO, proc_pid_syscall),
63296 #endif
63297 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63298@@ -2955,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63299 #ifdef CONFIG_SECURITY
63300 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63301 #endif
63302-#ifdef CONFIG_KALLSYMS
63303+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63304 INF("wchan", S_IRUGO, proc_pid_wchan),
63305 #endif
63306-#ifdef CONFIG_STACKTRACE
63307+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63308 ONE("stack", S_IRUGO, proc_pid_stack),
63309 #endif
63310 #ifdef CONFIG_SCHEDSTATS
63311diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63312index 82676e3..5f8518a 100644
63313--- a/fs/proc/cmdline.c
63314+++ b/fs/proc/cmdline.c
63315@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63316
63317 static int __init proc_cmdline_init(void)
63318 {
63319+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63320+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63321+#else
63322 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63323+#endif
63324 return 0;
63325 }
63326 module_init(proc_cmdline_init);
63327diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63328index b143471..bb105e5 100644
63329--- a/fs/proc/devices.c
63330+++ b/fs/proc/devices.c
63331@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63332
63333 static int __init proc_devices_init(void)
63334 {
63335+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63336+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63337+#else
63338 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63339+#endif
63340 return 0;
63341 }
63342 module_init(proc_devices_init);
63343diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63344index 985ea88..d118a0a 100644
63345--- a/fs/proc/fd.c
63346+++ b/fs/proc/fd.c
63347@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63348 if (!task)
63349 return -ENOENT;
63350
63351- files = get_files_struct(task);
63352+ if (!gr_acl_handle_procpidmem(task))
63353+ files = get_files_struct(task);
63354 put_task_struct(task);
63355
63356 if (files) {
63357@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63358 */
63359 int proc_fd_permission(struct inode *inode, int mask)
63360 {
63361+ struct task_struct *task;
63362 int rv = generic_permission(inode, mask);
63363- if (rv == 0)
63364- return 0;
63365+
63366 if (task_tgid(current) == proc_pid(inode))
63367 rv = 0;
63368+
63369+ task = get_proc_task(inode);
63370+ if (task == NULL)
63371+ return rv;
63372+
63373+ if (gr_acl_handle_procpidmem(task))
63374+ rv = -EACCES;
63375+
63376+ put_task_struct(task);
63377+
63378 return rv;
63379 }
63380
63381diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63382index 124fc43..8afbb02 100644
63383--- a/fs/proc/inode.c
63384+++ b/fs/proc/inode.c
63385@@ -23,11 +23,17 @@
63386 #include <linux/slab.h>
63387 #include <linux/mount.h>
63388 #include <linux/magic.h>
63389+#include <linux/grsecurity.h>
63390
63391 #include <asm/uaccess.h>
63392
63393 #include "internal.h"
63394
63395+#ifdef CONFIG_PROC_SYSCTL
63396+extern const struct inode_operations proc_sys_inode_operations;
63397+extern const struct inode_operations proc_sys_dir_operations;
63398+#endif
63399+
63400 static void proc_evict_inode(struct inode *inode)
63401 {
63402 struct proc_dir_entry *de;
63403@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63404 ns = PROC_I(inode)->ns.ns;
63405 if (ns_ops && ns)
63406 ns_ops->put(ns);
63407+
63408+#ifdef CONFIG_PROC_SYSCTL
63409+ if (inode->i_op == &proc_sys_inode_operations ||
63410+ inode->i_op == &proc_sys_dir_operations)
63411+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63412+#endif
63413+
63414 }
63415
63416 static struct kmem_cache * proc_inode_cachep;
63417@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63418 if (de->mode) {
63419 inode->i_mode = de->mode;
63420 inode->i_uid = de->uid;
63421+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63422+ inode->i_gid = grsec_proc_gid;
63423+#else
63424 inode->i_gid = de->gid;
63425+#endif
63426 }
63427 if (de->size)
63428 inode->i_size = de->size;
63429diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63430index 651d09a..3d7f0bf 100644
63431--- a/fs/proc/internal.h
63432+++ b/fs/proc/internal.h
63433@@ -48,7 +48,7 @@ struct proc_dir_entry {
63434 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63435 u8 namelen;
63436 char name[];
63437-};
63438+} __randomize_layout;
63439
63440 union proc_op {
63441 int (*proc_get_link)(struct dentry *, struct path *);
63442@@ -67,7 +67,7 @@ struct proc_inode {
63443 struct ctl_table *sysctl_entry;
63444 struct proc_ns ns;
63445 struct inode vfs_inode;
63446-};
63447+} __randomize_layout;
63448
63449 /*
63450 * General functions
63451@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63452 struct pid *, struct task_struct *);
63453 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63454 struct pid *, struct task_struct *);
63455+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63456+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63457+#endif
63458
63459 /*
63460 * base.c
63461diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63462index 05029c0..7ea1987 100644
63463--- a/fs/proc/interrupts.c
63464+++ b/fs/proc/interrupts.c
63465@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63466
63467 static int __init proc_interrupts_init(void)
63468 {
63469+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63470+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63471+#else
63472 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63473+#endif
63474 return 0;
63475 }
63476 module_init(proc_interrupts_init);
63477diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63478index 5ed0e52..a1c1f2e 100644
63479--- a/fs/proc/kcore.c
63480+++ b/fs/proc/kcore.c
63481@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63482 * the addresses in the elf_phdr on our list.
63483 */
63484 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63485- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63486+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63487+ if (tsz > buflen)
63488 tsz = buflen;
63489-
63490+
63491 while (buflen) {
63492 struct kcore_list *m;
63493
63494@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63495 kfree(elf_buf);
63496 } else {
63497 if (kern_addr_valid(start)) {
63498- unsigned long n;
63499+ char *elf_buf;
63500+ mm_segment_t oldfs;
63501
63502- n = copy_to_user(buffer, (char *)start, tsz);
63503- /*
63504- * We cannot distinguish between fault on source
63505- * and fault on destination. When this happens
63506- * we clear too and hope it will trigger the
63507- * EFAULT again.
63508- */
63509- if (n) {
63510- if (clear_user(buffer + tsz - n,
63511- n))
63512+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63513+ if (!elf_buf)
63514+ return -ENOMEM;
63515+ oldfs = get_fs();
63516+ set_fs(KERNEL_DS);
63517+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63518+ set_fs(oldfs);
63519+ if (copy_to_user(buffer, elf_buf, tsz)) {
63520+ kfree(elf_buf);
63521 return -EFAULT;
63522+ }
63523 }
63524+ set_fs(oldfs);
63525+ kfree(elf_buf);
63526 } else {
63527 if (clear_user(buffer, tsz))
63528 return -EFAULT;
63529@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63530
63531 static int open_kcore(struct inode *inode, struct file *filp)
63532 {
63533+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63534+ return -EPERM;
63535+#endif
63536 if (!capable(CAP_SYS_RAWIO))
63537 return -EPERM;
63538 if (kcore_need_update)
63539diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63540index a77d2b2..a9153f0 100644
63541--- a/fs/proc/meminfo.c
63542+++ b/fs/proc/meminfo.c
63543@@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63544 vmi.used >> 10,
63545 vmi.largest_chunk >> 10
63546 #ifdef CONFIG_MEMORY_FAILURE
63547- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63548+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63549 #endif
63550 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63551 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63552diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63553index 5f9bc8a..5c35f08 100644
63554--- a/fs/proc/nommu.c
63555+++ b/fs/proc/nommu.c
63556@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63557
63558 if (file) {
63559 seq_pad(m, ' ');
63560- seq_path(m, &file->f_path, "");
63561+ seq_path(m, &file->f_path, "\n\\");
63562 }
63563
63564 seq_putc(m, '\n');
63565diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63566index 4677bb7..408e936 100644
63567--- a/fs/proc/proc_net.c
63568+++ b/fs/proc/proc_net.c
63569@@ -23,6 +23,7 @@
63570 #include <linux/nsproxy.h>
63571 #include <net/net_namespace.h>
63572 #include <linux/seq_file.h>
63573+#include <linux/grsecurity.h>
63574
63575 #include "internal.h"
63576
63577@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63578 struct task_struct *task;
63579 struct nsproxy *ns;
63580 struct net *net = NULL;
63581+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63582+ const struct cred *cred = current_cred();
63583+#endif
63584+
63585+#ifdef CONFIG_GRKERNSEC_PROC_USER
63586+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63587+ return net;
63588+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63589+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63590+ return net;
63591+#endif
63592
63593 rcu_read_lock();
63594 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63595diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63596index 7129046..6914844 100644
63597--- a/fs/proc/proc_sysctl.c
63598+++ b/fs/proc/proc_sysctl.c
63599@@ -11,13 +11,21 @@
63600 #include <linux/namei.h>
63601 #include <linux/mm.h>
63602 #include <linux/module.h>
63603+#include <linux/nsproxy.h>
63604+#ifdef CONFIG_GRKERNSEC
63605+#include <net/net_namespace.h>
63606+#endif
63607 #include "internal.h"
63608
63609+extern int gr_handle_chroot_sysctl(const int op);
63610+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63611+ const int op);
63612+
63613 static const struct dentry_operations proc_sys_dentry_operations;
63614 static const struct file_operations proc_sys_file_operations;
63615-static const struct inode_operations proc_sys_inode_operations;
63616+const struct inode_operations proc_sys_inode_operations;
63617 static const struct file_operations proc_sys_dir_file_operations;
63618-static const struct inode_operations proc_sys_dir_operations;
63619+const struct inode_operations proc_sys_dir_operations;
63620
63621 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63622 {
63623@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63624
63625 err = NULL;
63626 d_set_d_op(dentry, &proc_sys_dentry_operations);
63627+
63628+ gr_handle_proc_create(dentry, inode);
63629+
63630 d_add(dentry, inode);
63631
63632 out:
63633@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63634 struct inode *inode = file_inode(filp);
63635 struct ctl_table_header *head = grab_header(inode);
63636 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63637+ int op = write ? MAY_WRITE : MAY_READ;
63638 ssize_t error;
63639 size_t res;
63640
63641@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63642 * and won't be until we finish.
63643 */
63644 error = -EPERM;
63645- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63646+ if (sysctl_perm(head, table, op))
63647 goto out;
63648
63649 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63650@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63651 if (!table->proc_handler)
63652 goto out;
63653
63654+#ifdef CONFIG_GRKERNSEC
63655+ error = -EPERM;
63656+ if (gr_handle_chroot_sysctl(op))
63657+ goto out;
63658+ dget(filp->f_path.dentry);
63659+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63660+ dput(filp->f_path.dentry);
63661+ goto out;
63662+ }
63663+ dput(filp->f_path.dentry);
63664+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63665+ goto out;
63666+ if (write) {
63667+ if (current->nsproxy->net_ns != table->extra2) {
63668+ if (!capable(CAP_SYS_ADMIN))
63669+ goto out;
63670+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63671+ goto out;
63672+ }
63673+#endif
63674+
63675 /* careful: calling conventions are nasty here */
63676 res = count;
63677 error = table->proc_handler(table, write, buf, &res, ppos);
63678@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63679 return false;
63680 } else {
63681 d_set_d_op(child, &proc_sys_dentry_operations);
63682+
63683+ gr_handle_proc_create(child, inode);
63684+
63685 d_add(child, inode);
63686 }
63687 } else {
63688@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63689 if ((*pos)++ < ctx->pos)
63690 return true;
63691
63692+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63693+ return 0;
63694+
63695 if (unlikely(S_ISLNK(table->mode)))
63696 res = proc_sys_link_fill_cache(file, ctx, head, table);
63697 else
63698@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63699 if (IS_ERR(head))
63700 return PTR_ERR(head);
63701
63702+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63703+ return -ENOENT;
63704+
63705 generic_fillattr(inode, stat);
63706 if (table)
63707 stat->mode = (stat->mode & S_IFMT) | table->mode;
63708@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63709 .llseek = generic_file_llseek,
63710 };
63711
63712-static const struct inode_operations proc_sys_inode_operations = {
63713+const struct inode_operations proc_sys_inode_operations = {
63714 .permission = proc_sys_permission,
63715 .setattr = proc_sys_setattr,
63716 .getattr = proc_sys_getattr,
63717 };
63718
63719-static const struct inode_operations proc_sys_dir_operations = {
63720+const struct inode_operations proc_sys_dir_operations = {
63721 .lookup = proc_sys_lookup,
63722 .permission = proc_sys_permission,
63723 .setattr = proc_sys_setattr,
63724@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63725 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63726 const char *name, int namelen)
63727 {
63728- struct ctl_table *table;
63729+ ctl_table_no_const *table;
63730 struct ctl_dir *new;
63731 struct ctl_node *node;
63732 char *new_name;
63733@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63734 return NULL;
63735
63736 node = (struct ctl_node *)(new + 1);
63737- table = (struct ctl_table *)(node + 1);
63738+ table = (ctl_table_no_const *)(node + 1);
63739 new_name = (char *)(table + 2);
63740 memcpy(new_name, name, namelen);
63741 new_name[namelen] = '\0';
63742@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63743 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63744 struct ctl_table_root *link_root)
63745 {
63746- struct ctl_table *link_table, *entry, *link;
63747+ ctl_table_no_const *link_table, *link;
63748+ struct ctl_table *entry;
63749 struct ctl_table_header *links;
63750 struct ctl_node *node;
63751 char *link_name;
63752@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63753 return NULL;
63754
63755 node = (struct ctl_node *)(links + 1);
63756- link_table = (struct ctl_table *)(node + nr_entries);
63757+ link_table = (ctl_table_no_const *)(node + nr_entries);
63758 link_name = (char *)&link_table[nr_entries + 1];
63759
63760 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63761@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63762 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63763 struct ctl_table *table)
63764 {
63765- struct ctl_table *ctl_table_arg = NULL;
63766- struct ctl_table *entry, *files;
63767+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63768+ struct ctl_table *entry;
63769 int nr_files = 0;
63770 int nr_dirs = 0;
63771 int err = -ENOMEM;
63772@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63773 nr_files++;
63774 }
63775
63776- files = table;
63777 /* If there are mixed files and directories we need a new table */
63778 if (nr_dirs && nr_files) {
63779- struct ctl_table *new;
63780+ ctl_table_no_const *new;
63781 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63782 GFP_KERNEL);
63783 if (!files)
63784@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63785 /* Register everything except a directory full of subdirectories */
63786 if (nr_files || !nr_dirs) {
63787 struct ctl_table_header *header;
63788- header = __register_sysctl_table(set, path, files);
63789+ header = __register_sysctl_table(set, path, files ? files : table);
63790 if (!header) {
63791 kfree(ctl_table_arg);
63792 goto out;
63793diff --git a/fs/proc/root.c b/fs/proc/root.c
63794index 87dbcbe..55e1b4d 100644
63795--- a/fs/proc/root.c
63796+++ b/fs/proc/root.c
63797@@ -186,7 +186,15 @@ void __init proc_root_init(void)
63798 #ifdef CONFIG_PROC_DEVICETREE
63799 proc_device_tree_init();
63800 #endif
63801+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63802+#ifdef CONFIG_GRKERNSEC_PROC_USER
63803+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63804+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63805+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63806+#endif
63807+#else
63808 proc_mkdir("bus", NULL);
63809+#endif
63810 proc_sys_init();
63811 }
63812
63813diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63814index 1cf86c0..0ee1ca5 100644
63815--- a/fs/proc/stat.c
63816+++ b/fs/proc/stat.c
63817@@ -11,6 +11,7 @@
63818 #include <linux/irqnr.h>
63819 #include <asm/cputime.h>
63820 #include <linux/tick.h>
63821+#include <linux/grsecurity.h>
63822
63823 #ifndef arch_irq_stat_cpu
63824 #define arch_irq_stat_cpu(cpu) 0
63825@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63826 u64 sum_softirq = 0;
63827 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63828 struct timespec boottime;
63829+ int unrestricted = 1;
63830+
63831+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63832+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63833+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63834+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63835+ && !in_group_p(grsec_proc_gid)
63836+#endif
63837+ )
63838+ unrestricted = 0;
63839+#endif
63840+#endif
63841
63842 user = nice = system = idle = iowait =
63843 irq = softirq = steal = 0;
63844@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63845 getboottime(&boottime);
63846 jif = boottime.tv_sec;
63847
63848+ if (unrestricted) {
63849 for_each_possible_cpu(i) {
63850 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63851 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63852@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63853 }
63854 }
63855 sum += arch_irq_stat();
63856+ }
63857
63858 seq_puts(p, "cpu ");
63859 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63860@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63861 seq_putc(p, '\n');
63862
63863 for_each_online_cpu(i) {
63864+ if (unrestricted) {
63865 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63866 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63867 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63868@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63869 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63870 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63871 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63872+ }
63873 seq_printf(p, "cpu%d", i);
63874 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63875 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63876@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63877
63878 /* sum again ? it could be updated? */
63879 for_each_irq_nr(j)
63880- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63881+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63882
63883 seq_printf(p,
63884 "\nctxt %llu\n"
63885@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63886 "processes %lu\n"
63887 "procs_running %lu\n"
63888 "procs_blocked %lu\n",
63889- nr_context_switches(),
63890+ unrestricted ? nr_context_switches() : 0ULL,
63891 (unsigned long)jif,
63892- total_forks,
63893- nr_running(),
63894- nr_iowait());
63895+ unrestricted ? total_forks : 0UL,
63896+ unrestricted ? nr_running() : 0UL,
63897+ unrestricted ? nr_iowait() : 0UL);
63898
63899 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63900
63901diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63902index fb52b54..5fc7c14 100644
63903--- a/fs/proc/task_mmu.c
63904+++ b/fs/proc/task_mmu.c
63905@@ -12,12 +12,19 @@
63906 #include <linux/swap.h>
63907 #include <linux/swapops.h>
63908 #include <linux/mmu_notifier.h>
63909+#include <linux/grsecurity.h>
63910
63911 #include <asm/elf.h>
63912 #include <asm/uaccess.h>
63913 #include <asm/tlbflush.h>
63914 #include "internal.h"
63915
63916+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63917+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63918+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63919+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63920+#endif
63921+
63922 void task_mem(struct seq_file *m, struct mm_struct *mm)
63923 {
63924 unsigned long data, text, lib, swap;
63925@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63926 "VmExe:\t%8lu kB\n"
63927 "VmLib:\t%8lu kB\n"
63928 "VmPTE:\t%8lu kB\n"
63929- "VmSwap:\t%8lu kB\n",
63930- hiwater_vm << (PAGE_SHIFT-10),
63931+ "VmSwap:\t%8lu kB\n"
63932+
63933+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63934+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63935+#endif
63936+
63937+ ,hiwater_vm << (PAGE_SHIFT-10),
63938 total_vm << (PAGE_SHIFT-10),
63939 mm->locked_vm << (PAGE_SHIFT-10),
63940 mm->pinned_vm << (PAGE_SHIFT-10),
63941@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63942 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63943 (PTRS_PER_PTE * sizeof(pte_t) *
63944 atomic_long_read(&mm->nr_ptes)) >> 10,
63945- swap << (PAGE_SHIFT-10));
63946+ swap << (PAGE_SHIFT-10)
63947+
63948+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63949+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63950+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63951+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63952+#else
63953+ , mm->context.user_cs_base
63954+ , mm->context.user_cs_limit
63955+#endif
63956+#endif
63957+
63958+ );
63959 }
63960
63961 unsigned long task_vsize(struct mm_struct *mm)
63962@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63963 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63964 }
63965
63966- /* We don't show the stack guard page in /proc/maps */
63967+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63968+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63969+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63970+#else
63971 start = vma->vm_start;
63972- if (stack_guard_page_start(vma, start))
63973- start += PAGE_SIZE;
63974 end = vma->vm_end;
63975- if (stack_guard_page_end(vma, end))
63976- end -= PAGE_SIZE;
63977+#endif
63978
63979 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63980 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63981@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63982 flags & VM_WRITE ? 'w' : '-',
63983 flags & VM_EXEC ? 'x' : '-',
63984 flags & VM_MAYSHARE ? 's' : 'p',
63985+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63986+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63987+#else
63988 pgoff,
63989+#endif
63990 MAJOR(dev), MINOR(dev), ino);
63991
63992 /*
63993@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63994 */
63995 if (file) {
63996 seq_pad(m, ' ');
63997- seq_path(m, &file->f_path, "\n");
63998+ seq_path(m, &file->f_path, "\n\\");
63999 goto done;
64000 }
64001
64002@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64003 * Thread stack in /proc/PID/task/TID/maps or
64004 * the main process stack.
64005 */
64006- if (!is_pid || (vma->vm_start <= mm->start_stack &&
64007- vma->vm_end >= mm->start_stack)) {
64008+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64009+ (vma->vm_start <= mm->start_stack &&
64010+ vma->vm_end >= mm->start_stack)) {
64011 name = "[stack]";
64012 } else {
64013 /* Thread stack in /proc/PID/maps */
64014@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64015 struct proc_maps_private *priv = m->private;
64016 struct task_struct *task = priv->task;
64017
64018+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64019+ if (current->exec_id != m->exec_id) {
64020+ gr_log_badprocpid("maps");
64021+ return 0;
64022+ }
64023+#endif
64024+
64025 show_map_vma(m, vma, is_pid);
64026
64027 if (m->count < m->size) /* vma is copied successfully */
64028@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64029 .private = &mss,
64030 };
64031
64032+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64033+ if (current->exec_id != m->exec_id) {
64034+ gr_log_badprocpid("smaps");
64035+ return 0;
64036+ }
64037+#endif
64038 memset(&mss, 0, sizeof mss);
64039- mss.vma = vma;
64040- /* mmap_sem is held in m_start */
64041- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64042- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64043-
64044+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64045+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64046+#endif
64047+ mss.vma = vma;
64048+ /* mmap_sem is held in m_start */
64049+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64050+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64051+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64052+ }
64053+#endif
64054 show_map_vma(m, vma, is_pid);
64055
64056 seq_printf(m,
64057@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64058 "KernelPageSize: %8lu kB\n"
64059 "MMUPageSize: %8lu kB\n"
64060 "Locked: %8lu kB\n",
64061+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64062+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64063+#else
64064 (vma->vm_end - vma->vm_start) >> 10,
64065+#endif
64066 mss.resident >> 10,
64067 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64068 mss.shared_clean >> 10,
64069@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64070 char buffer[64];
64071 int nid;
64072
64073+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64074+ if (current->exec_id != m->exec_id) {
64075+ gr_log_badprocpid("numa_maps");
64076+ return 0;
64077+ }
64078+#endif
64079+
64080 if (!mm)
64081 return 0;
64082
64083@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64084 mpol_to_str(buffer, sizeof(buffer), pol);
64085 mpol_cond_put(pol);
64086
64087+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64088+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64089+#else
64090 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64091+#endif
64092
64093 if (file) {
64094 seq_printf(m, " file=");
64095- seq_path(m, &file->f_path, "\n\t= ");
64096+ seq_path(m, &file->f_path, "\n\t\\= ");
64097 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64098 seq_printf(m, " heap");
64099 } else {
64100diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64101index 678455d..ebd3245 100644
64102--- a/fs/proc/task_nommu.c
64103+++ b/fs/proc/task_nommu.c
64104@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64105 else
64106 bytes += kobjsize(mm);
64107
64108- if (current->fs && current->fs->users > 1)
64109+ if (current->fs && atomic_read(&current->fs->users) > 1)
64110 sbytes += kobjsize(current->fs);
64111 else
64112 bytes += kobjsize(current->fs);
64113@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64114
64115 if (file) {
64116 seq_pad(m, ' ');
64117- seq_path(m, &file->f_path, "");
64118+ seq_path(m, &file->f_path, "\n\\");
64119 } else if (mm) {
64120 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64121
64122diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64123index 9100d69..51cd925 100644
64124--- a/fs/proc/vmcore.c
64125+++ b/fs/proc/vmcore.c
64126@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64127 nr_bytes = count;
64128
64129 /* If pfn is not ram, return zeros for sparse dump files */
64130- if (pfn_is_ram(pfn) == 0)
64131- memset(buf, 0, nr_bytes);
64132- else {
64133+ if (pfn_is_ram(pfn) == 0) {
64134+ if (userbuf) {
64135+ if (clear_user((char __force_user *)buf, nr_bytes))
64136+ return -EFAULT;
64137+ } else
64138+ memset(buf, 0, nr_bytes);
64139+ } else {
64140 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64141 offset, userbuf);
64142 if (tmp < 0)
64143@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64144 static int copy_to(void *target, void *src, size_t size, int userbuf)
64145 {
64146 if (userbuf) {
64147- if (copy_to_user((char __user *) target, src, size))
64148+ if (copy_to_user((char __force_user *) target, src, size))
64149 return -EFAULT;
64150 } else {
64151 memcpy(target, src, size);
64152@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64153 if (*fpos < m->offset + m->size) {
64154 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64155 start = m->paddr + *fpos - m->offset;
64156- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64157+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64158 if (tmp < 0)
64159 return tmp;
64160 buflen -= tsz;
64161@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64162 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64163 size_t buflen, loff_t *fpos)
64164 {
64165- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64166+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64167 }
64168
64169 /*
64170diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64171index b00fcc9..e0c6381 100644
64172--- a/fs/qnx6/qnx6.h
64173+++ b/fs/qnx6/qnx6.h
64174@@ -74,7 +74,7 @@ enum {
64175 BYTESEX_BE,
64176 };
64177
64178-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64179+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64180 {
64181 if (sbi->s_bytesex == BYTESEX_LE)
64182 return le64_to_cpu((__force __le64)n);
64183@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64184 return (__force __fs64)cpu_to_be64(n);
64185 }
64186
64187-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64188+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64189 {
64190 if (sbi->s_bytesex == BYTESEX_LE)
64191 return le32_to_cpu((__force __le32)n);
64192diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64193index 72d2917..c917c12 100644
64194--- a/fs/quota/netlink.c
64195+++ b/fs/quota/netlink.c
64196@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64197 void quota_send_warning(struct kqid qid, dev_t dev,
64198 const char warntype)
64199 {
64200- static atomic_t seq;
64201+ static atomic_unchecked_t seq;
64202 struct sk_buff *skb;
64203 void *msg_head;
64204 int ret;
64205@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64206 "VFS: Not enough memory to send quota warning.\n");
64207 return;
64208 }
64209- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64210+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64211 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64212 if (!msg_head) {
64213 printk(KERN_ERR
64214diff --git a/fs/read_write.c b/fs/read_write.c
64215index cfa18df..c110979 100644
64216--- a/fs/read_write.c
64217+++ b/fs/read_write.c
64218@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64219
64220 old_fs = get_fs();
64221 set_fs(get_ds());
64222- p = (__force const char __user *)buf;
64223+ p = (const char __force_user *)buf;
64224 if (count > MAX_RW_COUNT)
64225 count = MAX_RW_COUNT;
64226 if (file->f_op->write)
64227diff --git a/fs/readdir.c b/fs/readdir.c
64228index 5b53d99..a6c3049 100644
64229--- a/fs/readdir.c
64230+++ b/fs/readdir.c
64231@@ -17,6 +17,7 @@
64232 #include <linux/security.h>
64233 #include <linux/syscalls.h>
64234 #include <linux/unistd.h>
64235+#include <linux/namei.h>
64236
64237 #include <asm/uaccess.h>
64238
64239@@ -69,6 +70,7 @@ struct old_linux_dirent {
64240 struct readdir_callback {
64241 struct dir_context ctx;
64242 struct old_linux_dirent __user * dirent;
64243+ struct file * file;
64244 int result;
64245 };
64246
64247@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64248 buf->result = -EOVERFLOW;
64249 return -EOVERFLOW;
64250 }
64251+
64252+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64253+ return 0;
64254+
64255 buf->result++;
64256 dirent = buf->dirent;
64257 if (!access_ok(VERIFY_WRITE, dirent,
64258@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64259 if (!f.file)
64260 return -EBADF;
64261
64262+ buf.file = f.file;
64263 error = iterate_dir(f.file, &buf.ctx);
64264 if (buf.result)
64265 error = buf.result;
64266@@ -142,6 +149,7 @@ struct getdents_callback {
64267 struct dir_context ctx;
64268 struct linux_dirent __user * current_dir;
64269 struct linux_dirent __user * previous;
64270+ struct file * file;
64271 int count;
64272 int error;
64273 };
64274@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64275 buf->error = -EOVERFLOW;
64276 return -EOVERFLOW;
64277 }
64278+
64279+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64280+ return 0;
64281+
64282 dirent = buf->previous;
64283 if (dirent) {
64284 if (__put_user(offset, &dirent->d_off))
64285@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64286 if (!f.file)
64287 return -EBADF;
64288
64289+ buf.file = f.file;
64290 error = iterate_dir(f.file, &buf.ctx);
64291 if (error >= 0)
64292 error = buf.error;
64293@@ -226,6 +239,7 @@ struct getdents_callback64 {
64294 struct dir_context ctx;
64295 struct linux_dirent64 __user * current_dir;
64296 struct linux_dirent64 __user * previous;
64297+ struct file *file;
64298 int count;
64299 int error;
64300 };
64301@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64302 buf->error = -EINVAL; /* only used if we fail.. */
64303 if (reclen > buf->count)
64304 return -EINVAL;
64305+
64306+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64307+ return 0;
64308+
64309 dirent = buf->previous;
64310 if (dirent) {
64311 if (__put_user(offset, &dirent->d_off))
64312@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64313 if (!f.file)
64314 return -EBADF;
64315
64316+ buf.file = f.file;
64317 error = iterate_dir(f.file, &buf.ctx);
64318 if (error >= 0)
64319 error = buf.error;
64320diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64321index 2b7882b..1c5ef48 100644
64322--- a/fs/reiserfs/do_balan.c
64323+++ b/fs/reiserfs/do_balan.c
64324@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64325 return;
64326 }
64327
64328- atomic_inc(&(fs_generation(tb->tb_sb)));
64329+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64330 do_balance_starts(tb);
64331
64332 /* balance leaf returns 0 except if combining L R and S into
64333diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64334index ee382ef..f4eb6eb5 100644
64335--- a/fs/reiserfs/item_ops.c
64336+++ b/fs/reiserfs/item_ops.c
64337@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64338 }
64339
64340 static struct item_operations errcatch_ops = {
64341- errcatch_bytes_number,
64342- errcatch_decrement_key,
64343- errcatch_is_left_mergeable,
64344- errcatch_print_item,
64345- errcatch_check_item,
64346+ .bytes_number = errcatch_bytes_number,
64347+ .decrement_key = errcatch_decrement_key,
64348+ .is_left_mergeable = errcatch_is_left_mergeable,
64349+ .print_item = errcatch_print_item,
64350+ .check_item = errcatch_check_item,
64351
64352- errcatch_create_vi,
64353- errcatch_check_left,
64354- errcatch_check_right,
64355- errcatch_part_size,
64356- errcatch_unit_num,
64357- errcatch_print_vi
64358+ .create_vi = errcatch_create_vi,
64359+ .check_left = errcatch_check_left,
64360+ .check_right = errcatch_check_right,
64361+ .part_size = errcatch_part_size,
64362+ .unit_num = errcatch_unit_num,
64363+ .print_vi = errcatch_print_vi
64364 };
64365
64366 //////////////////////////////////////////////////////////////////////////////
64367diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64368index a958444..42b2323 100644
64369--- a/fs/reiserfs/procfs.c
64370+++ b/fs/reiserfs/procfs.c
64371@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64372 "SMALL_TAILS " : "NO_TAILS ",
64373 replay_only(sb) ? "REPLAY_ONLY " : "",
64374 convert_reiserfs(sb) ? "CONV " : "",
64375- atomic_read(&r->s_generation_counter),
64376+ atomic_read_unchecked(&r->s_generation_counter),
64377 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64378 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64379 SF(s_good_search_by_key_reada), SF(s_bmaps),
64380diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64381index f8adaee..0eeeeca 100644
64382--- a/fs/reiserfs/reiserfs.h
64383+++ b/fs/reiserfs/reiserfs.h
64384@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64385 /* Comment? -Hans */
64386 wait_queue_head_t s_wait;
64387 /* To be obsoleted soon by per buffer seals.. -Hans */
64388- atomic_t s_generation_counter; // increased by one every time the
64389+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64390 // tree gets re-balanced
64391 unsigned long s_properties; /* File system properties. Currently holds
64392 on-disk FS format */
64393@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64394 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64395
64396 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64397-#define get_generation(s) atomic_read (&fs_generation(s))
64398+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64399 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64400 #define __fs_changed(gen,s) (gen != get_generation (s))
64401 #define fs_changed(gen,s) \
64402diff --git a/fs/select.c b/fs/select.c
64403index 467bb1c..cf9d65a 100644
64404--- a/fs/select.c
64405+++ b/fs/select.c
64406@@ -20,6 +20,7 @@
64407 #include <linux/export.h>
64408 #include <linux/slab.h>
64409 #include <linux/poll.h>
64410+#include <linux/security.h>
64411 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64412 #include <linux/file.h>
64413 #include <linux/fdtable.h>
64414@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64415 struct poll_list *walk = head;
64416 unsigned long todo = nfds;
64417
64418+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64419 if (nfds > rlimit(RLIMIT_NOFILE))
64420 return -EINVAL;
64421
64422diff --git a/fs/seq_file.c b/fs/seq_file.c
64423index 1d641bb..e600623 100644
64424--- a/fs/seq_file.c
64425+++ b/fs/seq_file.c
64426@@ -10,6 +10,7 @@
64427 #include <linux/seq_file.h>
64428 #include <linux/slab.h>
64429 #include <linux/cred.h>
64430+#include <linux/sched.h>
64431
64432 #include <asm/uaccess.h>
64433 #include <asm/page.h>
64434@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64435 #ifdef CONFIG_USER_NS
64436 p->user_ns = file->f_cred->user_ns;
64437 #endif
64438+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64439+ p->exec_id = current->exec_id;
64440+#endif
64441
64442 /*
64443 * Wrappers around seq_open(e.g. swaps_open) need to be
64444@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64445 return 0;
64446 }
64447 if (!m->buf) {
64448- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64449+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64450 if (!m->buf)
64451 return -ENOMEM;
64452 }
64453@@ -137,7 +141,7 @@ Eoverflow:
64454 m->op->stop(m, p);
64455 kfree(m->buf);
64456 m->count = 0;
64457- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64458+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64459 return !m->buf ? -ENOMEM : -EAGAIN;
64460 }
64461
64462@@ -153,7 +157,7 @@ Eoverflow:
64463 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64464 {
64465 struct seq_file *m = file->private_data;
64466- size_t copied = 0;
64467+ ssize_t copied = 0;
64468 loff_t pos;
64469 size_t n;
64470 void *p;
64471@@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64472
64473 /* grab buffer if we didn't have one */
64474 if (!m->buf) {
64475- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64476+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64477 if (!m->buf)
64478 goto Enomem;
64479 }
64480@@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64481 m->op->stop(m, p);
64482 kfree(m->buf);
64483 m->count = 0;
64484- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64485+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64486 if (!m->buf)
64487 goto Enomem;
64488 m->version = 0;
64489@@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64490 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64491 void *data)
64492 {
64493- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64494+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64495 int res = -ENOMEM;
64496
64497 if (op) {
64498diff --git a/fs/splice.c b/fs/splice.c
64499index 12028fa..a6f2619 100644
64500--- a/fs/splice.c
64501+++ b/fs/splice.c
64502@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64503 pipe_lock(pipe);
64504
64505 for (;;) {
64506- if (!pipe->readers) {
64507+ if (!atomic_read(&pipe->readers)) {
64508 send_sig(SIGPIPE, current, 0);
64509 if (!ret)
64510 ret = -EPIPE;
64511@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64512 page_nr++;
64513 ret += buf->len;
64514
64515- if (pipe->files)
64516+ if (atomic_read(&pipe->files))
64517 do_wakeup = 1;
64518
64519 if (!--spd->nr_pages)
64520@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64521 do_wakeup = 0;
64522 }
64523
64524- pipe->waiting_writers++;
64525+ atomic_inc(&pipe->waiting_writers);
64526 pipe_wait(pipe);
64527- pipe->waiting_writers--;
64528+ atomic_dec(&pipe->waiting_writers);
64529 }
64530
64531 pipe_unlock(pipe);
64532@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64533 old_fs = get_fs();
64534 set_fs(get_ds());
64535 /* The cast to a user pointer is valid due to the set_fs() */
64536- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64537+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64538 set_fs(old_fs);
64539
64540 return res;
64541@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64542 old_fs = get_fs();
64543 set_fs(get_ds());
64544 /* The cast to a user pointer is valid due to the set_fs() */
64545- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64546+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64547 set_fs(old_fs);
64548
64549 return res;
64550@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64551 goto err;
64552
64553 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64554- vec[i].iov_base = (void __user *) page_address(page);
64555+ vec[i].iov_base = (void __force_user *) page_address(page);
64556 vec[i].iov_len = this_len;
64557 spd.pages[i] = page;
64558 spd.nr_pages++;
64559@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64560 ops->release(pipe, buf);
64561 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64562 pipe->nrbufs--;
64563- if (pipe->files)
64564+ if (atomic_read(&pipe->files))
64565 sd->need_wakeup = true;
64566 }
64567
64568@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64569 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64570 {
64571 while (!pipe->nrbufs) {
64572- if (!pipe->writers)
64573+ if (!atomic_read(&pipe->writers))
64574 return 0;
64575
64576- if (!pipe->waiting_writers && sd->num_spliced)
64577+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64578 return 0;
64579
64580 if (sd->flags & SPLICE_F_NONBLOCK)
64581@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64582 * out of the pipe right after the splice_to_pipe(). So set
64583 * PIPE_READERS appropriately.
64584 */
64585- pipe->readers = 1;
64586+ atomic_set(&pipe->readers, 1);
64587
64588 current->splice_pipe = pipe;
64589 }
64590@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64591
64592 partial[buffers].offset = off;
64593 partial[buffers].len = plen;
64594+ partial[buffers].private = 0;
64595
64596 off = 0;
64597 len -= plen;
64598@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64599 ret = -ERESTARTSYS;
64600 break;
64601 }
64602- if (!pipe->writers)
64603+ if (!atomic_read(&pipe->writers))
64604 break;
64605- if (!pipe->waiting_writers) {
64606+ if (!atomic_read(&pipe->waiting_writers)) {
64607 if (flags & SPLICE_F_NONBLOCK) {
64608 ret = -EAGAIN;
64609 break;
64610@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64611 pipe_lock(pipe);
64612
64613 while (pipe->nrbufs >= pipe->buffers) {
64614- if (!pipe->readers) {
64615+ if (!atomic_read(&pipe->readers)) {
64616 send_sig(SIGPIPE, current, 0);
64617 ret = -EPIPE;
64618 break;
64619@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64620 ret = -ERESTARTSYS;
64621 break;
64622 }
64623- pipe->waiting_writers++;
64624+ atomic_inc(&pipe->waiting_writers);
64625 pipe_wait(pipe);
64626- pipe->waiting_writers--;
64627+ atomic_dec(&pipe->waiting_writers);
64628 }
64629
64630 pipe_unlock(pipe);
64631@@ -1880,14 +1881,14 @@ retry:
64632 pipe_double_lock(ipipe, opipe);
64633
64634 do {
64635- if (!opipe->readers) {
64636+ if (!atomic_read(&opipe->readers)) {
64637 send_sig(SIGPIPE, current, 0);
64638 if (!ret)
64639 ret = -EPIPE;
64640 break;
64641 }
64642
64643- if (!ipipe->nrbufs && !ipipe->writers)
64644+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64645 break;
64646
64647 /*
64648@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64649 pipe_double_lock(ipipe, opipe);
64650
64651 do {
64652- if (!opipe->readers) {
64653+ if (!atomic_read(&opipe->readers)) {
64654 send_sig(SIGPIPE, current, 0);
64655 if (!ret)
64656 ret = -EPIPE;
64657@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64658 * return EAGAIN if we have the potential of some data in the
64659 * future, otherwise just return 0
64660 */
64661- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64662+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64663 ret = -EAGAIN;
64664
64665 pipe_unlock(ipipe);
64666diff --git a/fs/stat.c b/fs/stat.c
64667index ae0c3ce..9ee641c 100644
64668--- a/fs/stat.c
64669+++ b/fs/stat.c
64670@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64671 stat->gid = inode->i_gid;
64672 stat->rdev = inode->i_rdev;
64673 stat->size = i_size_read(inode);
64674- stat->atime = inode->i_atime;
64675- stat->mtime = inode->i_mtime;
64676+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64677+ stat->atime = inode->i_ctime;
64678+ stat->mtime = inode->i_ctime;
64679+ } else {
64680+ stat->atime = inode->i_atime;
64681+ stat->mtime = inode->i_mtime;
64682+ }
64683 stat->ctime = inode->i_ctime;
64684 stat->blksize = (1 << inode->i_blkbits);
64685 stat->blocks = inode->i_blocks;
64686@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64687 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64688 {
64689 struct inode *inode = path->dentry->d_inode;
64690+ int retval;
64691
64692- if (inode->i_op->getattr)
64693- return inode->i_op->getattr(path->mnt, path->dentry, stat);
64694+ if (inode->i_op->getattr) {
64695+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64696+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64697+ stat->atime = stat->ctime;
64698+ stat->mtime = stat->ctime;
64699+ }
64700+ return retval;
64701+ }
64702
64703 generic_fillattr(inode, stat);
64704 return 0;
64705diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64706index 5e73d66..4f165fd 100644
64707--- a/fs/sysfs/dir.c
64708+++ b/fs/sysfs/dir.c
64709@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64710 *
64711 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64712 */
64713-static unsigned int sysfs_name_hash(const char *name, const void *ns)
64714+static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64715 {
64716 unsigned long hash = init_name_hash();
64717 unsigned int len = strlen(name);
64718@@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64719 struct sysfs_dirent *sd;
64720 int rc;
64721
64722+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64723+ const char *parent_name = parent_sd->s_name;
64724+
64725+ mode = S_IFDIR | S_IRWXU;
64726+
64727+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64728+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64729+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64730+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64731+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64732+#endif
64733+
64734 /* allocate */
64735 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64736 if (!sd)
64737diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64738index 35e7d08..4d6e676 100644
64739--- a/fs/sysfs/file.c
64740+++ b/fs/sysfs/file.c
64741@@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64742
64743 struct sysfs_open_dirent {
64744 atomic_t refcnt;
64745- atomic_t event;
64746+ atomic_unchecked_t event;
64747 wait_queue_head_t poll;
64748 struct list_head files; /* goes through sysfs_open_file.list */
64749 };
64750@@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64751 return -ENODEV;
64752 }
64753
64754- of->event = atomic_read(&of->sd->s_attr.open->event);
64755+ of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64756
64757 /*
64758 * Lookup @ops and invoke show(). Control may reach here via seq
64759@@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64760 return ret;
64761 }
64762
64763-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64764- void *buf, int len, int write)
64765+static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64766+ void *buf, size_t len, int write)
64767 {
64768 struct file *file = vma->vm_file;
64769 struct sysfs_open_file *of = sysfs_of(file);
64770- int ret;
64771+ ssize_t ret;
64772
64773 if (!of->vm_ops)
64774 return -EINVAL;
64775@@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64776 return -ENOMEM;
64777
64778 atomic_set(&new_od->refcnt, 0);
64779- atomic_set(&new_od->event, 1);
64780+ atomic_set_unchecked(&new_od->event, 1);
64781 init_waitqueue_head(&new_od->poll);
64782 INIT_LIST_HEAD(&new_od->files);
64783 goto retry;
64784@@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64785
64786 sysfs_put_active(attr_sd);
64787
64788- if (of->event != atomic_read(&od->event))
64789+ if (of->event != atomic_read_unchecked(&od->event))
64790 goto trigger;
64791
64792 return DEFAULT_POLLMASK;
64793@@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64794 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64795 od = sd->s_attr.open;
64796 if (od) {
64797- atomic_inc(&od->event);
64798+ atomic_inc_unchecked(&od->event);
64799 wake_up_interruptible(&od->poll);
64800 }
64801 }
64802diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64803index 3ae3f1b..081a26c 100644
64804--- a/fs/sysfs/symlink.c
64805+++ b/fs/sysfs/symlink.c
64806@@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64807 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64808 void *cookie)
64809 {
64810- char *page = nd_get_link(nd);
64811+ const char *page = nd_get_link(nd);
64812 if (!IS_ERR(page))
64813 free_page((unsigned long)page);
64814 }
64815diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64816index 69d4889..a810bd4 100644
64817--- a/fs/sysv/sysv.h
64818+++ b/fs/sysv/sysv.h
64819@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64820 #endif
64821 }
64822
64823-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64824+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64825 {
64826 if (sbi->s_bytesex == BYTESEX_PDP)
64827 return PDP_swab((__force __u32)n);
64828diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64829index e18b988..f1d4ad0f 100644
64830--- a/fs/ubifs/io.c
64831+++ b/fs/ubifs/io.c
64832@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64833 return err;
64834 }
64835
64836-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64837+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64838 {
64839 int err;
64840
64841diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64842index c175b4d..8f36a16 100644
64843--- a/fs/udf/misc.c
64844+++ b/fs/udf/misc.c
64845@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64846
64847 u8 udf_tag_checksum(const struct tag *t)
64848 {
64849- u8 *data = (u8 *)t;
64850+ const u8 *data = (const u8 *)t;
64851 u8 checksum = 0;
64852 int i;
64853 for (i = 0; i < sizeof(struct tag); ++i)
64854diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64855index 8d974c4..b82f6ec 100644
64856--- a/fs/ufs/swab.h
64857+++ b/fs/ufs/swab.h
64858@@ -22,7 +22,7 @@ enum {
64859 BYTESEX_BE
64860 };
64861
64862-static inline u64
64863+static inline u64 __intentional_overflow(-1)
64864 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64865 {
64866 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64867@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64868 return (__force __fs64)cpu_to_be64(n);
64869 }
64870
64871-static inline u32
64872+static inline u32 __intentional_overflow(-1)
64873 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64874 {
64875 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64876diff --git a/fs/utimes.c b/fs/utimes.c
64877index aa138d6..5f3a811 100644
64878--- a/fs/utimes.c
64879+++ b/fs/utimes.c
64880@@ -1,6 +1,7 @@
64881 #include <linux/compiler.h>
64882 #include <linux/file.h>
64883 #include <linux/fs.h>
64884+#include <linux/security.h>
64885 #include <linux/linkage.h>
64886 #include <linux/mount.h>
64887 #include <linux/namei.h>
64888@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64889 }
64890 }
64891 retry_deleg:
64892+
64893+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64894+ error = -EACCES;
64895+ goto mnt_drop_write_and_out;
64896+ }
64897+
64898 mutex_lock(&inode->i_mutex);
64899 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64900 mutex_unlock(&inode->i_mutex);
64901diff --git a/fs/xattr.c b/fs/xattr.c
64902index 3377dff..f394815 100644
64903--- a/fs/xattr.c
64904+++ b/fs/xattr.c
64905@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64906 return rc;
64907 }
64908
64909+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64910+ssize_t
64911+pax_getxattr(struct dentry *dentry, void *value, size_t size)
64912+{
64913+ struct inode *inode = dentry->d_inode;
64914+ ssize_t error;
64915+
64916+ error = inode_permission(inode, MAY_EXEC);
64917+ if (error)
64918+ return error;
64919+
64920+ if (inode->i_op->getxattr)
64921+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64922+ else
64923+ error = -EOPNOTSUPP;
64924+
64925+ return error;
64926+}
64927+EXPORT_SYMBOL(pax_getxattr);
64928+#endif
64929+
64930 ssize_t
64931 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64932 {
64933@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64934 * Extended attribute SET operations
64935 */
64936 static long
64937-setxattr(struct dentry *d, const char __user *name, const void __user *value,
64938+setxattr(struct path *path, const char __user *name, const void __user *value,
64939 size_t size, int flags)
64940 {
64941 int error;
64942@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64943 posix_acl_fix_xattr_from_user(kvalue, size);
64944 }
64945
64946- error = vfs_setxattr(d, kname, kvalue, size, flags);
64947+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64948+ error = -EACCES;
64949+ goto out;
64950+ }
64951+
64952+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64953 out:
64954 if (vvalue)
64955 vfree(vvalue);
64956@@ -377,7 +403,7 @@ retry:
64957 return error;
64958 error = mnt_want_write(path.mnt);
64959 if (!error) {
64960- error = setxattr(path.dentry, name, value, size, flags);
64961+ error = setxattr(&path, name, value, size, flags);
64962 mnt_drop_write(path.mnt);
64963 }
64964 path_put(&path);
64965@@ -401,7 +427,7 @@ retry:
64966 return error;
64967 error = mnt_want_write(path.mnt);
64968 if (!error) {
64969- error = setxattr(path.dentry, name, value, size, flags);
64970+ error = setxattr(&path, name, value, size, flags);
64971 mnt_drop_write(path.mnt);
64972 }
64973 path_put(&path);
64974@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64975 const void __user *,value, size_t, size, int, flags)
64976 {
64977 struct fd f = fdget(fd);
64978- struct dentry *dentry;
64979 int error = -EBADF;
64980
64981 if (!f.file)
64982 return error;
64983- dentry = f.file->f_path.dentry;
64984- audit_inode(NULL, dentry, 0);
64985+ audit_inode(NULL, f.file->f_path.dentry, 0);
64986 error = mnt_want_write_file(f.file);
64987 if (!error) {
64988- error = setxattr(dentry, name, value, size, flags);
64989+ error = setxattr(&f.file->f_path, name, value, size, flags);
64990 mnt_drop_write_file(f.file);
64991 }
64992 fdput(f);
64993@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64994 * Extended attribute REMOVE operations
64995 */
64996 static long
64997-removexattr(struct dentry *d, const char __user *name)
64998+removexattr(struct path *path, const char __user *name)
64999 {
65000 int error;
65001 char kname[XATTR_NAME_MAX + 1];
65002@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65003 if (error < 0)
65004 return error;
65005
65006- return vfs_removexattr(d, kname);
65007+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65008+ return -EACCES;
65009+
65010+ return vfs_removexattr(path->dentry, kname);
65011 }
65012
65013 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65014@@ -652,7 +679,7 @@ retry:
65015 return error;
65016 error = mnt_want_write(path.mnt);
65017 if (!error) {
65018- error = removexattr(path.dentry, name);
65019+ error = removexattr(&path, name);
65020 mnt_drop_write(path.mnt);
65021 }
65022 path_put(&path);
65023@@ -675,7 +702,7 @@ retry:
65024 return error;
65025 error = mnt_want_write(path.mnt);
65026 if (!error) {
65027- error = removexattr(path.dentry, name);
65028+ error = removexattr(&path, name);
65029 mnt_drop_write(path.mnt);
65030 }
65031 path_put(&path);
65032@@ -689,16 +716,16 @@ retry:
65033 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65034 {
65035 struct fd f = fdget(fd);
65036- struct dentry *dentry;
65037+ struct path *path;
65038 int error = -EBADF;
65039
65040 if (!f.file)
65041 return error;
65042- dentry = f.file->f_path.dentry;
65043- audit_inode(NULL, dentry, 0);
65044+ path = &f.file->f_path;
65045+ audit_inode(NULL, path->dentry, 0);
65046 error = mnt_want_write_file(f.file);
65047 if (!error) {
65048- error = removexattr(dentry, name);
65049+ error = removexattr(path, name);
65050 mnt_drop_write_file(f.file);
65051 }
65052 fdput(f);
65053diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
65054index 9fbea87..417b3c2 100644
65055--- a/fs/xattr_acl.c
65056+++ b/fs/xattr_acl.c
65057@@ -10,6 +10,7 @@
65058 #include <linux/posix_acl_xattr.h>
65059 #include <linux/gfp.h>
65060 #include <linux/user_namespace.h>
65061+#include <linux/grsecurity.h>
65062
65063 /*
65064 * Fix up the uids and gids in posix acl extended attributes in place.
65065@@ -76,11 +77,12 @@ struct posix_acl *
65066 posix_acl_from_xattr(struct user_namespace *user_ns,
65067 const void *value, size_t size)
65068 {
65069- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
65070- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
65071+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
65072+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
65073 int count;
65074 struct posix_acl *acl;
65075 struct posix_acl_entry *acl_e;
65076+ umode_t umask = gr_acl_umask();
65077
65078 if (!value)
65079 return NULL;
65080@@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65081
65082 switch(acl_e->e_tag) {
65083 case ACL_USER_OBJ:
65084+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65085+ break;
65086 case ACL_GROUP_OBJ:
65087 case ACL_MASK:
65088+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65089+ break;
65090 case ACL_OTHER:
65091+ acl_e->e_perm &= ~(umask & S_IRWXO);
65092 break;
65093
65094 case ACL_USER:
65095+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65096 acl_e->e_uid =
65097 make_kuid(user_ns,
65098 le32_to_cpu(entry->e_id));
65099@@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65100 goto fail;
65101 break;
65102 case ACL_GROUP:
65103+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65104 acl_e->e_gid =
65105 make_kgid(user_ns,
65106 le32_to_cpu(entry->e_id));
65107diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65108index 3b2c14b..de031fe 100644
65109--- a/fs/xfs/xfs_bmap.c
65110+++ b/fs/xfs/xfs_bmap.c
65111@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65112
65113 #else
65114 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65115-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65116+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65117 #endif /* DEBUG */
65118
65119 /*
65120diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65121index c4e50c6..8ba93e3 100644
65122--- a/fs/xfs/xfs_dir2_readdir.c
65123+++ b/fs/xfs/xfs_dir2_readdir.c
65124@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65125 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65126 filetype = dp->d_ops->sf_get_ftype(sfep);
65127 ctx->pos = off & 0x7fffffff;
65128- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65129+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65130+ char name[sfep->namelen];
65131+ memcpy(name, sfep->name, sfep->namelen);
65132+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65133+ return 0;
65134+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65135 xfs_dir3_get_dtype(mp, filetype)))
65136 return 0;
65137 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65138diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65139index 33ad9a7..82c18ba 100644
65140--- a/fs/xfs/xfs_ioctl.c
65141+++ b/fs/xfs/xfs_ioctl.c
65142@@ -126,7 +126,7 @@ xfs_find_handle(
65143 }
65144
65145 error = -EFAULT;
65146- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65147+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65148 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65149 goto out_put;
65150
65151diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
65152index 104455b..764c512 100644
65153--- a/fs/xfs/xfs_iops.c
65154+++ b/fs/xfs/xfs_iops.c
65155@@ -397,7 +397,7 @@ xfs_vn_put_link(
65156 struct nameidata *nd,
65157 void *p)
65158 {
65159- char *s = nd_get_link(nd);
65160+ const char *s = nd_get_link(nd);
65161
65162 if (!IS_ERR(s))
65163 kfree(s);
65164diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65165new file mode 100644
65166index 0000000..81a6826
65167--- /dev/null
65168+++ b/grsecurity/Kconfig
65169@@ -0,0 +1,1160 @@
65170+#
65171+# grecurity configuration
65172+#
65173+menu "Memory Protections"
65174+depends on GRKERNSEC
65175+
65176+config GRKERNSEC_KMEM
65177+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65178+ default y if GRKERNSEC_CONFIG_AUTO
65179+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65180+ help
65181+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65182+ be written to or read from to modify or leak the contents of the running
65183+ kernel. /dev/port will also not be allowed to be opened, writing to
65184+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65185+ If you have module support disabled, enabling this will close up several
65186+ ways that are currently used to insert malicious code into the running
65187+ kernel.
65188+
65189+ Even with this feature enabled, we still highly recommend that
65190+ you use the RBAC system, as it is still possible for an attacker to
65191+ modify the running kernel through other more obscure methods.
65192+
65193+ It is highly recommended that you say Y here if you meet all the
65194+ conditions above.
65195+
65196+config GRKERNSEC_VM86
65197+ bool "Restrict VM86 mode"
65198+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65199+ depends on X86_32
65200+
65201+ help
65202+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65203+ make use of a special execution mode on 32bit x86 processors called
65204+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65205+ video cards and will still work with this option enabled. The purpose
65206+ of the option is to prevent exploitation of emulation errors in
65207+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65208+ Nearly all users should be able to enable this option.
65209+
65210+config GRKERNSEC_IO
65211+ bool "Disable privileged I/O"
65212+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65213+ depends on X86
65214+ select RTC_CLASS
65215+ select RTC_INTF_DEV
65216+ select RTC_DRV_CMOS
65217+
65218+ help
65219+ If you say Y here, all ioperm and iopl calls will return an error.
65220+ Ioperm and iopl can be used to modify the running kernel.
65221+ Unfortunately, some programs need this access to operate properly,
65222+ the most notable of which are XFree86 and hwclock. hwclock can be
65223+ remedied by having RTC support in the kernel, so real-time
65224+ clock support is enabled if this option is enabled, to ensure
65225+ that hwclock operates correctly.
65226+
65227+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65228+ you may not be able to boot into a graphical environment with this
65229+ option enabled. In this case, you should use the RBAC system instead.
65230+
65231+config GRKERNSEC_JIT_HARDEN
65232+ bool "Harden BPF JIT against spray attacks"
65233+ default y if GRKERNSEC_CONFIG_AUTO
65234+ depends on BPF_JIT && X86
65235+ help
65236+ If you say Y here, the native code generated by the kernel's Berkeley
65237+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65238+ attacks that attempt to fit attacker-beneficial instructions in
65239+ 32bit immediate fields of JIT-generated native instructions. The
65240+ attacker will generally aim to cause an unintended instruction sequence
65241+ of JIT-generated native code to execute by jumping into the middle of
65242+ a generated instruction. This feature effectively randomizes the 32bit
65243+ immediate constants present in the generated code to thwart such attacks.
65244+
65245+ If you're using KERNEXEC, it's recommended that you enable this option
65246+ to supplement the hardening of the kernel.
65247+
65248+config GRKERNSEC_PERF_HARDEN
65249+ bool "Disable unprivileged PERF_EVENTS usage by default"
65250+ default y if GRKERNSEC_CONFIG_AUTO
65251+ depends on PERF_EVENTS
65252+ help
65253+ If you say Y here, the range of acceptable values for the
65254+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65255+ default to a new value: 3. When the sysctl is set to this value, no
65256+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65257+
65258+ Though PERF_EVENTS can be used legitimately for performance monitoring
65259+ and low-level application profiling, it is forced on regardless of
65260+ configuration, has been at fault for several vulnerabilities, and
65261+ creates new opportunities for side channels and other information leaks.
65262+
65263+ This feature puts PERF_EVENTS into a secure default state and permits
65264+ the administrator to change out of it temporarily if unprivileged
65265+ application profiling is needed.
65266+
65267+config GRKERNSEC_RAND_THREADSTACK
65268+ bool "Insert random gaps between thread stacks"
65269+ default y if GRKERNSEC_CONFIG_AUTO
65270+ depends on PAX_RANDMMAP && !PPC
65271+ help
65272+ If you say Y here, a random-sized gap will be enforced between allocated
65273+ thread stacks. Glibc's NPTL and other threading libraries that
65274+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65275+ The implementation currently provides 8 bits of entropy for the gap.
65276+
65277+ Many distributions do not compile threaded remote services with the
65278+ -fstack-check argument to GCC, causing the variable-sized stack-based
65279+ allocator, alloca(), to not probe the stack on allocation. This
65280+ permits an unbounded alloca() to skip over any guard page and potentially
65281+ modify another thread's stack reliably. An enforced random gap
65282+ reduces the reliability of such an attack and increases the chance
65283+ that such a read/write to another thread's stack instead lands in
65284+ an unmapped area, causing a crash and triggering grsecurity's
65285+ anti-bruteforcing logic.
65286+
65287+config GRKERNSEC_PROC_MEMMAP
65288+ bool "Harden ASLR against information leaks and entropy reduction"
65289+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65290+ depends on PAX_NOEXEC || PAX_ASLR
65291+ help
65292+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65293+ give no information about the addresses of its mappings if
65294+ PaX features that rely on random addresses are enabled on the task.
65295+ In addition to sanitizing this information and disabling other
65296+ dangerous sources of information, this option causes reads of sensitive
65297+ /proc/<pid> entries where the file descriptor was opened in a different
65298+ task than the one performing the read. Such attempts are logged.
65299+ This option also limits argv/env strings for suid/sgid binaries
65300+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65301+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65302+ binaries to prevent alternative mmap layouts from being abused.
65303+
65304+ If you use PaX it is essential that you say Y here as it closes up
65305+ several holes that make full ASLR useless locally.
65306+
65307+config GRKERNSEC_BRUTE
65308+ bool "Deter exploit bruteforcing"
65309+ default y if GRKERNSEC_CONFIG_AUTO
65310+ help
65311+ If you say Y here, attempts to bruteforce exploits against forking
65312+ daemons such as apache or sshd, as well as against suid/sgid binaries
65313+ will be deterred. When a child of a forking daemon is killed by PaX
65314+ or crashes due to an illegal instruction or other suspicious signal,
65315+ the parent process will be delayed 30 seconds upon every subsequent
65316+ fork until the administrator is able to assess the situation and
65317+ restart the daemon.
65318+ In the suid/sgid case, the attempt is logged, the user has all their
65319+ existing instances of the suid/sgid binary terminated and will
65320+ be unable to execute any suid/sgid binaries for 15 minutes.
65321+
65322+ It is recommended that you also enable signal logging in the auditing
65323+ section so that logs are generated when a process triggers a suspicious
65324+ signal.
65325+ If the sysctl option is enabled, a sysctl option with name
65326+ "deter_bruteforce" is created.
65327+
65328+config GRKERNSEC_MODHARDEN
65329+ bool "Harden module auto-loading"
65330+ default y if GRKERNSEC_CONFIG_AUTO
65331+ depends on MODULES
65332+ help
65333+ If you say Y here, module auto-loading in response to use of some
65334+ feature implemented by an unloaded module will be restricted to
65335+ root users. Enabling this option helps defend against attacks
65336+ by unprivileged users who abuse the auto-loading behavior to
65337+ cause a vulnerable module to load that is then exploited.
65338+
65339+ If this option prevents a legitimate use of auto-loading for a
65340+ non-root user, the administrator can execute modprobe manually
65341+ with the exact name of the module mentioned in the alert log.
65342+ Alternatively, the administrator can add the module to the list
65343+ of modules loaded at boot by modifying init scripts.
65344+
65345+ Modification of init scripts will most likely be needed on
65346+ Ubuntu servers with encrypted home directory support enabled,
65347+ as the first non-root user logging in will cause the ecb(aes),
65348+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65349+
65350+config GRKERNSEC_HIDESYM
65351+ bool "Hide kernel symbols"
65352+ default y if GRKERNSEC_CONFIG_AUTO
65353+ select PAX_USERCOPY_SLABS
65354+ help
65355+ If you say Y here, getting information on loaded modules, and
65356+ displaying all kernel symbols through a syscall will be restricted
65357+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65358+ /proc/kallsyms will be restricted to the root user. The RBAC
65359+ system can hide that entry even from root.
65360+
65361+ This option also prevents leaking of kernel addresses through
65362+ several /proc entries.
65363+
65364+ Note that this option is only effective provided the following
65365+ conditions are met:
65366+ 1) The kernel using grsecurity is not precompiled by some distribution
65367+ 2) You have also enabled GRKERNSEC_DMESG
65368+ 3) You are using the RBAC system and hiding other files such as your
65369+ kernel image and System.map. Alternatively, enabling this option
65370+ causes the permissions on /boot, /lib/modules, and the kernel
65371+ source directory to change at compile time to prevent
65372+ reading by non-root users.
65373+ If the above conditions are met, this option will aid in providing a
65374+ useful protection against local kernel exploitation of overflows
65375+ and arbitrary read/write vulnerabilities.
65376+
65377+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65378+ in addition to this feature.
65379+
65380+config GRKERNSEC_RANDSTRUCT
65381+ bool "Randomize layout of sensitive kernel structures"
65382+ default y if GRKERNSEC_CONFIG_AUTO
65383+ select GRKERNSEC_HIDESYM
65384+ select MODVERSIONS if MODULES
65385+ help
65386+ If you say Y here, the layouts of a number of sensitive kernel
65387+ structures (task, fs, cred, etc) and all structures composed entirely
65388+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65389+ This can introduce the requirement of an additional infoleak
65390+ vulnerability for exploits targeting these structure types.
65391+
65392+ Enabling this feature will introduce some performance impact, slightly
65393+ increase memory usage, and prevent the use of forensic tools like
65394+ Volatility against the system (unless the kernel source tree isn't
65395+ cleaned after kernel installation).
65396+
65397+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65398+ It remains after a make clean to allow for external modules to be compiled
65399+ with the existing seed and will be removed by a make mrproper or
65400+ make distclean.
65401+
65402+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65403+ to install the supporting headers explicitly in addition to the normal
65404+ gcc package.
65405+
65406+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65407+ bool "Use cacheline-aware structure randomization"
65408+ depends on GRKERNSEC_RANDSTRUCT
65409+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65410+ help
65411+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65412+ at restricting randomization to cacheline-sized groups of elements. It
65413+ will further not randomize bitfields in structures. This reduces the
65414+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65415+
65416+config GRKERNSEC_KERN_LOCKOUT
65417+ bool "Active kernel exploit response"
65418+ default y if GRKERNSEC_CONFIG_AUTO
65419+ depends on X86 || ARM || PPC || SPARC
65420+ help
65421+ If you say Y here, when a PaX alert is triggered due to suspicious
65422+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65423+ or an OOPS occurs due to bad memory accesses, instead of just
65424+ terminating the offending process (and potentially allowing
65425+ a subsequent exploit from the same user), we will take one of two
65426+ actions:
65427+ If the user was root, we will panic the system
65428+ If the user was non-root, we will log the attempt, terminate
65429+ all processes owned by the user, then prevent them from creating
65430+ any new processes until the system is restarted
65431+ This deters repeated kernel exploitation/bruteforcing attempts
65432+ and is useful for later forensics.
65433+
65434+config GRKERNSEC_OLD_ARM_USERLAND
65435+ bool "Old ARM userland compatibility"
65436+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65437+ help
65438+ If you say Y here, stubs of executable code to perform such operations
65439+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65440+ table. This is unfortunately needed for old ARM userland meant to run
65441+ across a wide range of processors. Without this option enabled,
65442+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65443+ which is enough for Linaro userlands or other userlands designed for v6
65444+ and newer ARM CPUs. It's recommended that you try without this option enabled
65445+ first, and only enable it if your userland does not boot (it will likely fail
65446+ at init time).
65447+
65448+endmenu
65449+menu "Role Based Access Control Options"
65450+depends on GRKERNSEC
65451+
65452+config GRKERNSEC_RBAC_DEBUG
65453+ bool
65454+
65455+config GRKERNSEC_NO_RBAC
65456+ bool "Disable RBAC system"
65457+ help
65458+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65459+ preventing the RBAC system from being enabled. You should only say Y
65460+ here if you have no intention of using the RBAC system, so as to prevent
65461+ an attacker with root access from misusing the RBAC system to hide files
65462+ and processes when loadable module support and /dev/[k]mem have been
65463+ locked down.
65464+
65465+config GRKERNSEC_ACL_HIDEKERN
65466+ bool "Hide kernel processes"
65467+ help
65468+ If you say Y here, all kernel threads will be hidden to all
65469+ processes but those whose subject has the "view hidden processes"
65470+ flag.
65471+
65472+config GRKERNSEC_ACL_MAXTRIES
65473+ int "Maximum tries before password lockout"
65474+ default 3
65475+ help
65476+ This option enforces the maximum number of times a user can attempt
65477+ to authorize themselves with the grsecurity RBAC system before being
65478+ denied the ability to attempt authorization again for a specified time.
65479+ The lower the number, the harder it will be to brute-force a password.
65480+
65481+config GRKERNSEC_ACL_TIMEOUT
65482+ int "Time to wait after max password tries, in seconds"
65483+ default 30
65484+ help
65485+ This option specifies the time the user must wait after attempting to
65486+ authorize to the RBAC system with the maximum number of invalid
65487+ passwords. The higher the number, the harder it will be to brute-force
65488+ a password.
65489+
65490+endmenu
65491+menu "Filesystem Protections"
65492+depends on GRKERNSEC
65493+
65494+config GRKERNSEC_PROC
65495+ bool "Proc restrictions"
65496+ default y if GRKERNSEC_CONFIG_AUTO
65497+ help
65498+ If you say Y here, the permissions of the /proc filesystem
65499+ will be altered to enhance system security and privacy. You MUST
65500+ choose either a user only restriction or a user and group restriction.
65501+ Depending upon the option you choose, you can either restrict users to
65502+ see only the processes they themselves run, or choose a group that can
65503+ view all processes and files normally restricted to root if you choose
65504+ the "restrict to user only" option. NOTE: If you're running identd or
65505+ ntpd as a non-root user, you will have to run it as the group you
65506+ specify here.
65507+
65508+config GRKERNSEC_PROC_USER
65509+ bool "Restrict /proc to user only"
65510+ depends on GRKERNSEC_PROC
65511+ help
65512+ If you say Y here, non-root users will only be able to view their own
65513+ processes, and restricts them from viewing network-related information,
65514+ and viewing kernel symbol and module information.
65515+
65516+config GRKERNSEC_PROC_USERGROUP
65517+ bool "Allow special group"
65518+ default y if GRKERNSEC_CONFIG_AUTO
65519+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65520+ help
65521+ If you say Y here, you will be able to select a group that will be
65522+ able to view all processes and network-related information. If you've
65523+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65524+ remain hidden. This option is useful if you want to run identd as
65525+ a non-root user. The group you select may also be chosen at boot time
65526+ via "grsec_proc_gid=" on the kernel commandline.
65527+
65528+config GRKERNSEC_PROC_GID
65529+ int "GID for special group"
65530+ depends on GRKERNSEC_PROC_USERGROUP
65531+ default 1001
65532+
65533+config GRKERNSEC_PROC_ADD
65534+ bool "Additional restrictions"
65535+ default y if GRKERNSEC_CONFIG_AUTO
65536+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65537+ help
65538+ If you say Y here, additional restrictions will be placed on
65539+ /proc that keep normal users from viewing device information and
65540+ slabinfo information that could be useful for exploits.
65541+
65542+config GRKERNSEC_LINK
65543+ bool "Linking restrictions"
65544+ default y if GRKERNSEC_CONFIG_AUTO
65545+ help
65546+ If you say Y here, /tmp race exploits will be prevented, since users
65547+ will no longer be able to follow symlinks owned by other users in
65548+ world-writable +t directories (e.g. /tmp), unless the owner of the
65549+ symlink is the owner of the directory. users will also not be
65550+ able to hardlink to files they do not own. If the sysctl option is
65551+ enabled, a sysctl option with name "linking_restrictions" is created.
65552+
65553+config GRKERNSEC_SYMLINKOWN
65554+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65555+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65556+ help
65557+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65558+ that prevents it from being used as a security feature. As Apache
65559+ verifies the symlink by performing a stat() against the target of
65560+ the symlink before it is followed, an attacker can setup a symlink
65561+ to point to a same-owned file, then replace the symlink with one
65562+ that targets another user's file just after Apache "validates" the
65563+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65564+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65565+ will be in place for the group you specify. If the sysctl option
65566+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65567+ created.
65568+
65569+config GRKERNSEC_SYMLINKOWN_GID
65570+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65571+ depends on GRKERNSEC_SYMLINKOWN
65572+ default 1006
65573+ help
65574+ Setting this GID determines what group kernel-enforced
65575+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65576+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65577+
65578+config GRKERNSEC_FIFO
65579+ bool "FIFO restrictions"
65580+ default y if GRKERNSEC_CONFIG_AUTO
65581+ help
65582+ If you say Y here, users will not be able to write to FIFOs they don't
65583+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65584+ the FIFO is the same owner of the directory it's held in. If the sysctl
65585+ option is enabled, a sysctl option with name "fifo_restrictions" is
65586+ created.
65587+
65588+config GRKERNSEC_SYSFS_RESTRICT
65589+ bool "Sysfs/debugfs restriction"
65590+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65591+ depends on SYSFS
65592+ help
65593+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65594+ any filesystem normally mounted under it (e.g. debugfs) will be
65595+ mostly accessible only by root. These filesystems generally provide access
65596+ to hardware and debug information that isn't appropriate for unprivileged
65597+ users of the system. Sysfs and debugfs have also become a large source
65598+ of new vulnerabilities, ranging from infoleaks to local compromise.
65599+ There has been very little oversight with an eye toward security involved
65600+ in adding new exporters of information to these filesystems, so their
65601+ use is discouraged.
65602+ For reasons of compatibility, a few directories have been whitelisted
65603+ for access by non-root users:
65604+ /sys/fs/selinux
65605+ /sys/fs/fuse
65606+ /sys/devices/system/cpu
65607+
65608+config GRKERNSEC_ROFS
65609+ bool "Runtime read-only mount protection"
65610+ depends on SYSCTL
65611+ help
65612+ If you say Y here, a sysctl option with name "romount_protect" will
65613+ be created. By setting this option to 1 at runtime, filesystems
65614+ will be protected in the following ways:
65615+ * No new writable mounts will be allowed
65616+ * Existing read-only mounts won't be able to be remounted read/write
65617+ * Write operations will be denied on all block devices
65618+ This option acts independently of grsec_lock: once it is set to 1,
65619+ it cannot be turned off. Therefore, please be mindful of the resulting
65620+ behavior if this option is enabled in an init script on a read-only
65621+ filesystem.
65622+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65623+ and GRKERNSEC_IO should be enabled and module loading disabled via
65624+ config or at runtime.
65625+ This feature is mainly intended for secure embedded systems.
65626+
65627+
65628+config GRKERNSEC_DEVICE_SIDECHANNEL
65629+ bool "Eliminate stat/notify-based device sidechannels"
65630+ default y if GRKERNSEC_CONFIG_AUTO
65631+ help
65632+ If you say Y here, timing analyses on block or character
65633+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65634+ will be thwarted for unprivileged users. If a process without
65635+ CAP_MKNOD stats such a device, the last access and last modify times
65636+ will match the device's create time. No access or modify events
65637+ will be triggered through inotify/dnotify/fanotify for such devices.
65638+ This feature will prevent attacks that may at a minimum
65639+ allow an attacker to determine the administrator's password length.
65640+
65641+config GRKERNSEC_CHROOT
65642+ bool "Chroot jail restrictions"
65643+ default y if GRKERNSEC_CONFIG_AUTO
65644+ help
65645+ If you say Y here, you will be able to choose several options that will
65646+ make breaking out of a chrooted jail much more difficult. If you
65647+ encounter no software incompatibilities with the following options, it
65648+ is recommended that you enable each one.
65649+
65650+ Note that the chroot restrictions are not intended to apply to "chroots"
65651+ to directories that are simple bind mounts of the global root filesystem.
65652+ For several other reasons, a user shouldn't expect any significant
65653+ security by performing such a chroot.
65654+
65655+config GRKERNSEC_CHROOT_MOUNT
65656+ bool "Deny mounts"
65657+ default y if GRKERNSEC_CONFIG_AUTO
65658+ depends on GRKERNSEC_CHROOT
65659+ help
65660+ If you say Y here, processes inside a chroot will not be able to
65661+ mount or remount filesystems. If the sysctl option is enabled, a
65662+ sysctl option with name "chroot_deny_mount" is created.
65663+
65664+config GRKERNSEC_CHROOT_DOUBLE
65665+ bool "Deny double-chroots"
65666+ default y if GRKERNSEC_CONFIG_AUTO
65667+ depends on GRKERNSEC_CHROOT
65668+ help
65669+ If you say Y here, processes inside a chroot will not be able to chroot
65670+ again outside the chroot. This is a widely used method of breaking
65671+ out of a chroot jail and should not be allowed. If the sysctl
65672+ option is enabled, a sysctl option with name
65673+ "chroot_deny_chroot" is created.
65674+
65675+config GRKERNSEC_CHROOT_PIVOT
65676+ bool "Deny pivot_root in chroot"
65677+ default y if GRKERNSEC_CONFIG_AUTO
65678+ depends on GRKERNSEC_CHROOT
65679+ help
65680+ If you say Y here, processes inside a chroot will not be able to use
65681+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65682+ works similar to chroot in that it changes the root filesystem. This
65683+ function could be misused in a chrooted process to attempt to break out
65684+ of the chroot, and therefore should not be allowed. If the sysctl
65685+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
65686+ created.
65687+
65688+config GRKERNSEC_CHROOT_CHDIR
65689+ bool "Enforce chdir(\"/\") on all chroots"
65690+ default y if GRKERNSEC_CONFIG_AUTO
65691+ depends on GRKERNSEC_CHROOT
65692+ help
65693+ If you say Y here, the current working directory of all newly-chrooted
65694+ applications will be set to the the root directory of the chroot.
65695+ The man page on chroot(2) states:
65696+ Note that this call does not change the current working
65697+ directory, so that `.' can be outside the tree rooted at
65698+ `/'. In particular, the super-user can escape from a
65699+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65700+
65701+ It is recommended that you say Y here, since it's not known to break
65702+ any software. If the sysctl option is enabled, a sysctl option with
65703+ name "chroot_enforce_chdir" is created.
65704+
65705+config GRKERNSEC_CHROOT_CHMOD
65706+ bool "Deny (f)chmod +s"
65707+ default y if GRKERNSEC_CONFIG_AUTO
65708+ depends on GRKERNSEC_CHROOT
65709+ help
65710+ If you say Y here, processes inside a chroot will not be able to chmod
65711+ or fchmod files to make them have suid or sgid bits. This protects
65712+ against another published method of breaking a chroot. If the sysctl
65713+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
65714+ created.
65715+
65716+config GRKERNSEC_CHROOT_FCHDIR
65717+ bool "Deny fchdir out of chroot"
65718+ default y if GRKERNSEC_CONFIG_AUTO
65719+ depends on GRKERNSEC_CHROOT
65720+ help
65721+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
65722+ to a file descriptor of the chrooting process that points to a directory
65723+ outside the filesystem will be stopped. If the sysctl option
65724+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65725+
65726+config GRKERNSEC_CHROOT_MKNOD
65727+ bool "Deny mknod"
65728+ default y if GRKERNSEC_CONFIG_AUTO
65729+ depends on GRKERNSEC_CHROOT
65730+ help
65731+ If you say Y here, processes inside a chroot will not be allowed to
65732+ mknod. The problem with using mknod inside a chroot is that it
65733+ would allow an attacker to create a device entry that is the same
65734+ as one on the physical root of your system, which could range from
65735+ anything from the console device to a device for your harddrive (which
65736+ they could then use to wipe the drive or steal data). It is recommended
65737+ that you say Y here, unless you run into software incompatibilities.
65738+ If the sysctl option is enabled, a sysctl option with name
65739+ "chroot_deny_mknod" is created.
65740+
65741+config GRKERNSEC_CHROOT_SHMAT
65742+ bool "Deny shmat() out of chroot"
65743+ default y if GRKERNSEC_CONFIG_AUTO
65744+ depends on GRKERNSEC_CHROOT
65745+ help
65746+ If you say Y here, processes inside a chroot will not be able to attach
65747+ to shared memory segments that were created outside of the chroot jail.
65748+ It is recommended that you say Y here. If the sysctl option is enabled,
65749+ a sysctl option with name "chroot_deny_shmat" is created.
65750+
65751+config GRKERNSEC_CHROOT_UNIX
65752+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
65753+ default y if GRKERNSEC_CONFIG_AUTO
65754+ depends on GRKERNSEC_CHROOT
65755+ help
65756+ If you say Y here, processes inside a chroot will not be able to
65757+ connect to abstract (meaning not belonging to a filesystem) Unix
65758+ domain sockets that were bound outside of a chroot. It is recommended
65759+ that you say Y here. If the sysctl option is enabled, a sysctl option
65760+ with name "chroot_deny_unix" is created.
65761+
65762+config GRKERNSEC_CHROOT_FINDTASK
65763+ bool "Protect outside processes"
65764+ default y if GRKERNSEC_CONFIG_AUTO
65765+ depends on GRKERNSEC_CHROOT
65766+ help
65767+ If you say Y here, processes inside a chroot will not be able to
65768+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65769+ getsid, or view any process outside of the chroot. If the sysctl
65770+ option is enabled, a sysctl option with name "chroot_findtask" is
65771+ created.
65772+
65773+config GRKERNSEC_CHROOT_NICE
65774+ bool "Restrict priority changes"
65775+ default y if GRKERNSEC_CONFIG_AUTO
65776+ depends on GRKERNSEC_CHROOT
65777+ help
65778+ If you say Y here, processes inside a chroot will not be able to raise
65779+ the priority of processes in the chroot, or alter the priority of
65780+ processes outside the chroot. This provides more security than simply
65781+ removing CAP_SYS_NICE from the process' capability set. If the
65782+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65783+ is created.
65784+
65785+config GRKERNSEC_CHROOT_SYSCTL
65786+ bool "Deny sysctl writes"
65787+ default y if GRKERNSEC_CONFIG_AUTO
65788+ depends on GRKERNSEC_CHROOT
65789+ help
65790+ If you say Y here, an attacker in a chroot will not be able to
65791+ write to sysctl entries, either by sysctl(2) or through a /proc
65792+ interface. It is strongly recommended that you say Y here. If the
65793+ sysctl option is enabled, a sysctl option with name
65794+ "chroot_deny_sysctl" is created.
65795+
65796+config GRKERNSEC_CHROOT_CAPS
65797+ bool "Capability restrictions"
65798+ default y if GRKERNSEC_CONFIG_AUTO
65799+ depends on GRKERNSEC_CHROOT
65800+ help
65801+ If you say Y here, the capabilities on all processes within a
65802+ chroot jail will be lowered to stop module insertion, raw i/o,
65803+ system and net admin tasks, rebooting the system, modifying immutable
65804+ files, modifying IPC owned by another, and changing the system time.
65805+ This is left an option because it can break some apps. Disable this
65806+ if your chrooted apps are having problems performing those kinds of
65807+ tasks. If the sysctl option is enabled, a sysctl option with
65808+ name "chroot_caps" is created.
65809+
65810+config GRKERNSEC_CHROOT_INITRD
65811+ bool "Exempt initrd tasks from restrictions"
65812+ default y if GRKERNSEC_CONFIG_AUTO
65813+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65814+ help
65815+ If you say Y here, tasks started prior to init will be exempted from
65816+ grsecurity's chroot restrictions. This option is mainly meant to
65817+ resolve Plymouth's performing privileged operations unnecessarily
65818+ in a chroot.
65819+
65820+endmenu
65821+menu "Kernel Auditing"
65822+depends on GRKERNSEC
65823+
65824+config GRKERNSEC_AUDIT_GROUP
65825+ bool "Single group for auditing"
65826+ help
65827+ If you say Y here, the exec and chdir logging features will only operate
65828+ on a group you specify. This option is recommended if you only want to
65829+ watch certain users instead of having a large amount of logs from the
65830+ entire system. If the sysctl option is enabled, a sysctl option with
65831+ name "audit_group" is created.
65832+
65833+config GRKERNSEC_AUDIT_GID
65834+ int "GID for auditing"
65835+ depends on GRKERNSEC_AUDIT_GROUP
65836+ default 1007
65837+
65838+config GRKERNSEC_EXECLOG
65839+ bool "Exec logging"
65840+ help
65841+ If you say Y here, all execve() calls will be logged (since the
65842+ other exec*() calls are frontends to execve(), all execution
65843+ will be logged). Useful for shell-servers that like to keep track
65844+ of their users. If the sysctl option is enabled, a sysctl option with
65845+ name "exec_logging" is created.
65846+ WARNING: This option when enabled will produce a LOT of logs, especially
65847+ on an active system.
65848+
65849+config GRKERNSEC_RESLOG
65850+ bool "Resource logging"
65851+ default y if GRKERNSEC_CONFIG_AUTO
65852+ help
65853+ If you say Y here, all attempts to overstep resource limits will
65854+ be logged with the resource name, the requested size, and the current
65855+ limit. It is highly recommended that you say Y here. If the sysctl
65856+ option is enabled, a sysctl option with name "resource_logging" is
65857+ created. If the RBAC system is enabled, the sysctl value is ignored.
65858+
65859+config GRKERNSEC_CHROOT_EXECLOG
65860+ bool "Log execs within chroot"
65861+ help
65862+ If you say Y here, all executions inside a chroot jail will be logged
65863+ to syslog. This can cause a large amount of logs if certain
65864+ applications (eg. djb's daemontools) are installed on the system, and
65865+ is therefore left as an option. If the sysctl option is enabled, a
65866+ sysctl option with name "chroot_execlog" is created.
65867+
65868+config GRKERNSEC_AUDIT_PTRACE
65869+ bool "Ptrace logging"
65870+ help
65871+ If you say Y here, all attempts to attach to a process via ptrace
65872+ will be logged. If the sysctl option is enabled, a sysctl option
65873+ with name "audit_ptrace" is created.
65874+
65875+config GRKERNSEC_AUDIT_CHDIR
65876+ bool "Chdir logging"
65877+ help
65878+ If you say Y here, all chdir() calls will be logged. If the sysctl
65879+ option is enabled, a sysctl option with name "audit_chdir" is created.
65880+
65881+config GRKERNSEC_AUDIT_MOUNT
65882+ bool "(Un)Mount logging"
65883+ help
65884+ If you say Y here, all mounts and unmounts will be logged. If the
65885+ sysctl option is enabled, a sysctl option with name "audit_mount" is
65886+ created.
65887+
65888+config GRKERNSEC_SIGNAL
65889+ bool "Signal logging"
65890+ default y if GRKERNSEC_CONFIG_AUTO
65891+ help
65892+ If you say Y here, certain important signals will be logged, such as
65893+ SIGSEGV, which will as a result inform you of when a error in a program
65894+ occurred, which in some cases could mean a possible exploit attempt.
65895+ If the sysctl option is enabled, a sysctl option with name
65896+ "signal_logging" is created.
65897+
65898+config GRKERNSEC_FORKFAIL
65899+ bool "Fork failure logging"
65900+ help
65901+ If you say Y here, all failed fork() attempts will be logged.
65902+ This could suggest a fork bomb, or someone attempting to overstep
65903+ their process limit. If the sysctl option is enabled, a sysctl option
65904+ with name "forkfail_logging" is created.
65905+
65906+config GRKERNSEC_TIME
65907+ bool "Time change logging"
65908+ default y if GRKERNSEC_CONFIG_AUTO
65909+ help
65910+ If you say Y here, any changes of the system clock will be logged.
65911+ If the sysctl option is enabled, a sysctl option with name
65912+ "timechange_logging" is created.
65913+
65914+config GRKERNSEC_PROC_IPADDR
65915+ bool "/proc/<pid>/ipaddr support"
65916+ default y if GRKERNSEC_CONFIG_AUTO
65917+ help
65918+ If you say Y here, a new entry will be added to each /proc/<pid>
65919+ directory that contains the IP address of the person using the task.
65920+ The IP is carried across local TCP and AF_UNIX stream sockets.
65921+ This information can be useful for IDS/IPSes to perform remote response
65922+ to a local attack. The entry is readable by only the owner of the
65923+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65924+ the RBAC system), and thus does not create privacy concerns.
65925+
65926+config GRKERNSEC_RWXMAP_LOG
65927+ bool 'Denied RWX mmap/mprotect logging'
65928+ default y if GRKERNSEC_CONFIG_AUTO
65929+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65930+ help
65931+ If you say Y here, calls to mmap() and mprotect() with explicit
65932+ usage of PROT_WRITE and PROT_EXEC together will be logged when
65933+ denied by the PAX_MPROTECT feature. This feature will also
65934+ log other problematic scenarios that can occur when PAX_MPROTECT
65935+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
65936+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65937+ is created.
65938+
65939+endmenu
65940+
65941+menu "Executable Protections"
65942+depends on GRKERNSEC
65943+
65944+config GRKERNSEC_DMESG
65945+ bool "Dmesg(8) restriction"
65946+ default y if GRKERNSEC_CONFIG_AUTO
65947+ help
65948+ If you say Y here, non-root users will not be able to use dmesg(8)
65949+ to view the contents of the kernel's circular log buffer.
65950+ The kernel's log buffer often contains kernel addresses and other
65951+ identifying information useful to an attacker in fingerprinting a
65952+ system for a targeted exploit.
65953+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
65954+ created.
65955+
65956+config GRKERNSEC_HARDEN_PTRACE
65957+ bool "Deter ptrace-based process snooping"
65958+ default y if GRKERNSEC_CONFIG_AUTO
65959+ help
65960+ If you say Y here, TTY sniffers and other malicious monitoring
65961+ programs implemented through ptrace will be defeated. If you
65962+ have been using the RBAC system, this option has already been
65963+ enabled for several years for all users, with the ability to make
65964+ fine-grained exceptions.
65965+
65966+ This option only affects the ability of non-root users to ptrace
65967+ processes that are not a descendent of the ptracing process.
65968+ This means that strace ./binary and gdb ./binary will still work,
65969+ but attaching to arbitrary processes will not. If the sysctl
65970+ option is enabled, a sysctl option with name "harden_ptrace" is
65971+ created.
65972+
65973+config GRKERNSEC_PTRACE_READEXEC
65974+ bool "Require read access to ptrace sensitive binaries"
65975+ default y if GRKERNSEC_CONFIG_AUTO
65976+ help
65977+ If you say Y here, unprivileged users will not be able to ptrace unreadable
65978+ binaries. This option is useful in environments that
65979+ remove the read bits (e.g. file mode 4711) from suid binaries to
65980+ prevent infoleaking of their contents. This option adds
65981+ consistency to the use of that file mode, as the binary could normally
65982+ be read out when run without privileges while ptracing.
65983+
65984+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65985+ is created.
65986+
65987+config GRKERNSEC_SETXID
65988+ bool "Enforce consistent multithreaded privileges"
65989+ default y if GRKERNSEC_CONFIG_AUTO
65990+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65991+ help
65992+ If you say Y here, a change from a root uid to a non-root uid
65993+ in a multithreaded application will cause the resulting uids,
65994+ gids, supplementary groups, and capabilities in that thread
65995+ to be propagated to the other threads of the process. In most
65996+ cases this is unnecessary, as glibc will emulate this behavior
65997+ on behalf of the application. Other libcs do not act in the
65998+ same way, allowing the other threads of the process to continue
65999+ running with root privileges. If the sysctl option is enabled,
66000+ a sysctl option with name "consistent_setxid" is created.
66001+
66002+config GRKERNSEC_HARDEN_IPC
66003+ bool "Disallow access to overly-permissive IPC objects"
66004+ default y if GRKERNSEC_CONFIG_AUTO
66005+ depends on SYSVIPC
66006+ help
66007+ If you say Y here, access to overly-permissive IPC objects (shared
66008+ memory, message queues, and semaphores) will be denied for processes
66009+ given the following criteria beyond normal permission checks:
66010+ 1) If the IPC object is world-accessible and the euid doesn't match
66011+ that of the creator or current uid for the IPC object
66012+ 2) If the IPC object is group-accessible and the egid doesn't
66013+ match that of the creator or current gid for the IPC object
66014+ It's a common error to grant too much permission to these objects,
66015+ with impact ranging from denial of service and information leaking to
66016+ privilege escalation. This feature was developed in response to
66017+ research by Tim Brown:
66018+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66019+ who found hundreds of such insecure usages. Processes with
66020+ CAP_IPC_OWNER are still permitted to access these IPC objects.
66021+ If the sysctl option is enabled, a sysctl option with name
66022+ "harden_ipc" is created.
66023+
66024+config GRKERNSEC_TPE
66025+ bool "Trusted Path Execution (TPE)"
66026+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66027+ help
66028+ If you say Y here, you will be able to choose a gid to add to the
66029+ supplementary groups of users you want to mark as "untrusted."
66030+ These users will not be able to execute any files that are not in
66031+ root-owned directories writable only by root. If the sysctl option
66032+ is enabled, a sysctl option with name "tpe" is created.
66033+
66034+config GRKERNSEC_TPE_ALL
66035+ bool "Partially restrict all non-root users"
66036+ depends on GRKERNSEC_TPE
66037+ help
66038+ If you say Y here, all non-root users will be covered under
66039+ a weaker TPE restriction. This is separate from, and in addition to,
66040+ the main TPE options that you have selected elsewhere. Thus, if a
66041+ "trusted" GID is chosen, this restriction applies to even that GID.
66042+ Under this restriction, all non-root users will only be allowed to
66043+ execute files in directories they own that are not group or
66044+ world-writable, or in directories owned by root and writable only by
66045+ root. If the sysctl option is enabled, a sysctl option with name
66046+ "tpe_restrict_all" is created.
66047+
66048+config GRKERNSEC_TPE_INVERT
66049+ bool "Invert GID option"
66050+ depends on GRKERNSEC_TPE
66051+ help
66052+ If you say Y here, the group you specify in the TPE configuration will
66053+ decide what group TPE restrictions will be *disabled* for. This
66054+ option is useful if you want TPE restrictions to be applied to most
66055+ users on the system. If the sysctl option is enabled, a sysctl option
66056+ with name "tpe_invert" is created. Unlike other sysctl options, this
66057+ entry will default to on for backward-compatibility.
66058+
66059+config GRKERNSEC_TPE_GID
66060+ int
66061+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66062+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66063+
66064+config GRKERNSEC_TPE_UNTRUSTED_GID
66065+ int "GID for TPE-untrusted users"
66066+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66067+ default 1005
66068+ help
66069+ Setting this GID determines what group TPE restrictions will be
66070+ *enabled* for. If the sysctl option is enabled, a sysctl option
66071+ with name "tpe_gid" is created.
66072+
66073+config GRKERNSEC_TPE_TRUSTED_GID
66074+ int "GID for TPE-trusted users"
66075+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66076+ default 1005
66077+ help
66078+ Setting this GID determines what group TPE restrictions will be
66079+ *disabled* for. If the sysctl option is enabled, a sysctl option
66080+ with name "tpe_gid" is created.
66081+
66082+endmenu
66083+menu "Network Protections"
66084+depends on GRKERNSEC
66085+
66086+config GRKERNSEC_RANDNET
66087+ bool "Larger entropy pools"
66088+ default y if GRKERNSEC_CONFIG_AUTO
66089+ help
66090+ If you say Y here, the entropy pools used for many features of Linux
66091+ and grsecurity will be doubled in size. Since several grsecurity
66092+ features use additional randomness, it is recommended that you say Y
66093+ here. Saying Y here has a similar effect as modifying
66094+ /proc/sys/kernel/random/poolsize.
66095+
66096+config GRKERNSEC_BLACKHOLE
66097+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66098+ default y if GRKERNSEC_CONFIG_AUTO
66099+ depends on NET
66100+ help
66101+ If you say Y here, neither TCP resets nor ICMP
66102+ destination-unreachable packets will be sent in response to packets
66103+ sent to ports for which no associated listening process exists.
66104+ This feature supports both IPV4 and IPV6 and exempts the
66105+ loopback interface from blackholing. Enabling this feature
66106+ makes a host more resilient to DoS attacks and reduces network
66107+ visibility against scanners.
66108+
66109+ The blackhole feature as-implemented is equivalent to the FreeBSD
66110+ blackhole feature, as it prevents RST responses to all packets, not
66111+ just SYNs. Under most application behavior this causes no
66112+ problems, but applications (like haproxy) may not close certain
66113+ connections in a way that cleanly terminates them on the remote
66114+ end, leaving the remote host in LAST_ACK state. Because of this
66115+ side-effect and to prevent intentional LAST_ACK DoSes, this
66116+ feature also adds automatic mitigation against such attacks.
66117+ The mitigation drastically reduces the amount of time a socket
66118+ can spend in LAST_ACK state. If you're using haproxy and not
66119+ all servers it connects to have this option enabled, consider
66120+ disabling this feature on the haproxy host.
66121+
66122+ If the sysctl option is enabled, two sysctl options with names
66123+ "ip_blackhole" and "lastack_retries" will be created.
66124+ While "ip_blackhole" takes the standard zero/non-zero on/off
66125+ toggle, "lastack_retries" uses the same kinds of values as
66126+ "tcp_retries1" and "tcp_retries2". The default value of 4
66127+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66128+ state.
66129+
66130+config GRKERNSEC_NO_SIMULT_CONNECT
66131+ bool "Disable TCP Simultaneous Connect"
66132+ default y if GRKERNSEC_CONFIG_AUTO
66133+ depends on NET
66134+ help
66135+ If you say Y here, a feature by Willy Tarreau will be enabled that
66136+ removes a weakness in Linux's strict implementation of TCP that
66137+ allows two clients to connect to each other without either entering
66138+ a listening state. The weakness allows an attacker to easily prevent
66139+ a client from connecting to a known server provided the source port
66140+ for the connection is guessed correctly.
66141+
66142+ As the weakness could be used to prevent an antivirus or IPS from
66143+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66144+ it should be eliminated by enabling this option. Though Linux is
66145+ one of few operating systems supporting simultaneous connect, it
66146+ has no legitimate use in practice and is rarely supported by firewalls.
66147+
66148+config GRKERNSEC_SOCKET
66149+ bool "Socket restrictions"
66150+ depends on NET
66151+ help
66152+ If you say Y here, you will be able to choose from several options.
66153+ If you assign a GID on your system and add it to the supplementary
66154+ groups of users you want to restrict socket access to, this patch
66155+ will perform up to three things, based on the option(s) you choose.
66156+
66157+config GRKERNSEC_SOCKET_ALL
66158+ bool "Deny any sockets to group"
66159+ depends on GRKERNSEC_SOCKET
66160+ help
66161+ If you say Y here, you will be able to choose a GID of whose users will
66162+ be unable to connect to other hosts from your machine or run server
66163+ applications from your machine. If the sysctl option is enabled, a
66164+ sysctl option with name "socket_all" is created.
66165+
66166+config GRKERNSEC_SOCKET_ALL_GID
66167+ int "GID to deny all sockets for"
66168+ depends on GRKERNSEC_SOCKET_ALL
66169+ default 1004
66170+ help
66171+ Here you can choose the GID to disable socket access for. Remember to
66172+ add the users you want socket access disabled for to the GID
66173+ specified here. If the sysctl option is enabled, a sysctl option
66174+ with name "socket_all_gid" is created.
66175+
66176+config GRKERNSEC_SOCKET_CLIENT
66177+ bool "Deny client sockets to group"
66178+ depends on GRKERNSEC_SOCKET
66179+ help
66180+ If you say Y here, you will be able to choose a GID of whose users will
66181+ be unable to connect to other hosts from your machine, but will be
66182+ able to run servers. If this option is enabled, all users in the group
66183+ you specify will have to use passive mode when initiating ftp transfers
66184+ from the shell on your machine. If the sysctl option is enabled, a
66185+ sysctl option with name "socket_client" is created.
66186+
66187+config GRKERNSEC_SOCKET_CLIENT_GID
66188+ int "GID to deny client sockets for"
66189+ depends on GRKERNSEC_SOCKET_CLIENT
66190+ default 1003
66191+ help
66192+ Here you can choose the GID to disable client socket access for.
66193+ Remember to add the users you want client socket access disabled for to
66194+ the GID specified here. If the sysctl option is enabled, a sysctl
66195+ option with name "socket_client_gid" is created.
66196+
66197+config GRKERNSEC_SOCKET_SERVER
66198+ bool "Deny server sockets to group"
66199+ depends on GRKERNSEC_SOCKET
66200+ help
66201+ If you say Y here, you will be able to choose a GID of whose users will
66202+ be unable to run server applications from your machine. If the sysctl
66203+ option is enabled, a sysctl option with name "socket_server" is created.
66204+
66205+config GRKERNSEC_SOCKET_SERVER_GID
66206+ int "GID to deny server sockets for"
66207+ depends on GRKERNSEC_SOCKET_SERVER
66208+ default 1002
66209+ help
66210+ Here you can choose the GID to disable server socket access for.
66211+ Remember to add the users you want server socket access disabled for to
66212+ the GID specified here. If the sysctl option is enabled, a sysctl
66213+ option with name "socket_server_gid" is created.
66214+
66215+endmenu
66216+
66217+menu "Physical Protections"
66218+depends on GRKERNSEC
66219+
66220+config GRKERNSEC_DENYUSB
66221+ bool "Deny new USB connections after toggle"
66222+ default y if GRKERNSEC_CONFIG_AUTO
66223+ depends on SYSCTL && USB_SUPPORT
66224+ help
66225+ If you say Y here, a new sysctl option with name "deny_new_usb"
66226+ will be created. Setting its value to 1 will prevent any new
66227+ USB devices from being recognized by the OS. Any attempted USB
66228+ device insertion will be logged. This option is intended to be
66229+ used against custom USB devices designed to exploit vulnerabilities
66230+ in various USB device drivers.
66231+
66232+ For greatest effectiveness, this sysctl should be set after any
66233+ relevant init scripts. This option is safe to enable in distros
66234+ as each user can choose whether or not to toggle the sysctl.
66235+
66236+config GRKERNSEC_DENYUSB_FORCE
66237+ bool "Reject all USB devices not connected at boot"
66238+ select USB
66239+ depends on GRKERNSEC_DENYUSB
66240+ help
66241+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66242+ that doesn't involve a sysctl entry. This option should only be
66243+ enabled if you're sure you want to deny all new USB connections
66244+ at runtime and don't want to modify init scripts. This should not
66245+ be enabled by distros. It forces the core USB code to be built
66246+ into the kernel image so that all devices connected at boot time
66247+ can be recognized and new USB device connections can be prevented
66248+ prior to init running.
66249+
66250+endmenu
66251+
66252+menu "Sysctl Support"
66253+depends on GRKERNSEC && SYSCTL
66254+
66255+config GRKERNSEC_SYSCTL
66256+ bool "Sysctl support"
66257+ default y if GRKERNSEC_CONFIG_AUTO
66258+ help
66259+ If you say Y here, you will be able to change the options that
66260+ grsecurity runs with at bootup, without having to recompile your
66261+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66262+ to enable (1) or disable (0) various features. All the sysctl entries
66263+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66264+ All features enabled in the kernel configuration are disabled at boot
66265+ if you do not say Y to the "Turn on features by default" option.
66266+ All options should be set at startup, and the grsec_lock entry should
66267+ be set to a non-zero value after all the options are set.
66268+ *THIS IS EXTREMELY IMPORTANT*
66269+
66270+config GRKERNSEC_SYSCTL_DISTRO
66271+ bool "Extra sysctl support for distro makers (READ HELP)"
66272+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66273+ help
66274+ If you say Y here, additional sysctl options will be created
66275+ for features that affect processes running as root. Therefore,
66276+ it is critical when using this option that the grsec_lock entry be
66277+ enabled after boot. Only distros with prebuilt kernel packages
66278+ with this option enabled that can ensure grsec_lock is enabled
66279+ after boot should use this option.
66280+ *Failure to set grsec_lock after boot makes all grsec features
66281+ this option covers useless*
66282+
66283+ Currently this option creates the following sysctl entries:
66284+ "Disable Privileged I/O": "disable_priv_io"
66285+
66286+config GRKERNSEC_SYSCTL_ON
66287+ bool "Turn on features by default"
66288+ default y if GRKERNSEC_CONFIG_AUTO
66289+ depends on GRKERNSEC_SYSCTL
66290+ help
66291+ If you say Y here, instead of having all features enabled in the
66292+ kernel configuration disabled at boot time, the features will be
66293+ enabled at boot time. It is recommended you say Y here unless
66294+ there is some reason you would want all sysctl-tunable features to
66295+ be disabled by default. As mentioned elsewhere, it is important
66296+ to enable the grsec_lock entry once you have finished modifying
66297+ the sysctl entries.
66298+
66299+endmenu
66300+menu "Logging Options"
66301+depends on GRKERNSEC
66302+
66303+config GRKERNSEC_FLOODTIME
66304+ int "Seconds in between log messages (minimum)"
66305+ default 10
66306+ help
66307+ This option allows you to enforce the number of seconds between
66308+ grsecurity log messages. The default should be suitable for most
66309+ people, however, if you choose to change it, choose a value small enough
66310+ to allow informative logs to be produced, but large enough to
66311+ prevent flooding.
66312+
66313+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66314+ any rate limiting on grsecurity log messages.
66315+
66316+config GRKERNSEC_FLOODBURST
66317+ int "Number of messages in a burst (maximum)"
66318+ default 6
66319+ help
66320+ This option allows you to choose the maximum number of messages allowed
66321+ within the flood time interval you chose in a separate option. The
66322+ default should be suitable for most people, however if you find that
66323+ many of your logs are being interpreted as flooding, you may want to
66324+ raise this value.
66325+
66326+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66327+ any rate limiting on grsecurity log messages.
66328+
66329+endmenu
66330diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66331new file mode 100644
66332index 0000000..5307c8a
66333--- /dev/null
66334+++ b/grsecurity/Makefile
66335@@ -0,0 +1,54 @@
66336+# grsecurity – access control and security hardening for Linux
66337+# All code in this directory and various hooks located throughout the Linux kernel are
66338+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66339+# http://www.grsecurity.net spender@grsecurity.net
66340+#
66341+# This program is free software; you can redistribute it and/or
66342+# modify it under the terms of the GNU General Public License version 2
66343+# as published by the Free Software Foundation.
66344+#
66345+# This program is distributed in the hope that it will be useful,
66346+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66347+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66348+# GNU General Public License for more details.
66349+#
66350+# You should have received a copy of the GNU General Public License
66351+# along with this program; if not, write to the Free Software
66352+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66353+
66354+KBUILD_CFLAGS += -Werror
66355+
66356+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66357+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66358+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66359+ grsec_usb.o grsec_ipc.o
66360+
66361+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66362+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66363+ gracl_learn.o grsec_log.o gracl_policy.o
66364+ifdef CONFIG_COMPAT
66365+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66366+endif
66367+
66368+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66369+
66370+ifdef CONFIG_NET
66371+obj-y += grsec_sock.o
66372+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66373+endif
66374+
66375+ifndef CONFIG_GRKERNSEC
66376+obj-y += grsec_disabled.o
66377+endif
66378+
66379+ifdef CONFIG_GRKERNSEC_HIDESYM
66380+extra-y := grsec_hidesym.o
66381+$(obj)/grsec_hidesym.o:
66382+ @-chmod -f 500 /boot
66383+ @-chmod -f 500 /lib/modules
66384+ @-chmod -f 500 /lib64/modules
66385+ @-chmod -f 500 /lib32/modules
66386+ @-chmod -f 700 .
66387+ @-chmod -f 700 $(objtree)
66388+ @echo ' grsec: protected kernel image paths'
66389+endif
66390diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66391new file mode 100644
66392index 0000000..e56396f
66393--- /dev/null
66394+++ b/grsecurity/gracl.c
66395@@ -0,0 +1,2679 @@
66396+#include <linux/kernel.h>
66397+#include <linux/module.h>
66398+#include <linux/sched.h>
66399+#include <linux/mm.h>
66400+#include <linux/file.h>
66401+#include <linux/fs.h>
66402+#include <linux/namei.h>
66403+#include <linux/mount.h>
66404+#include <linux/tty.h>
66405+#include <linux/proc_fs.h>
66406+#include <linux/lglock.h>
66407+#include <linux/slab.h>
66408+#include <linux/vmalloc.h>
66409+#include <linux/types.h>
66410+#include <linux/sysctl.h>
66411+#include <linux/netdevice.h>
66412+#include <linux/ptrace.h>
66413+#include <linux/gracl.h>
66414+#include <linux/gralloc.h>
66415+#include <linux/security.h>
66416+#include <linux/grinternal.h>
66417+#include <linux/pid_namespace.h>
66418+#include <linux/stop_machine.h>
66419+#include <linux/fdtable.h>
66420+#include <linux/percpu.h>
66421+#include <linux/lglock.h>
66422+#include <linux/hugetlb.h>
66423+#include <linux/posix-timers.h>
66424+#include <linux/prefetch.h>
66425+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66426+#include <linux/magic.h>
66427+#include <linux/pagemap.h>
66428+#include "../fs/btrfs/async-thread.h"
66429+#include "../fs/btrfs/ctree.h"
66430+#include "../fs/btrfs/btrfs_inode.h"
66431+#endif
66432+#include "../fs/mount.h"
66433+
66434+#include <asm/uaccess.h>
66435+#include <asm/errno.h>
66436+#include <asm/mman.h>
66437+
66438+#define FOR_EACH_ROLE_START(role) \
66439+ role = running_polstate.role_list; \
66440+ while (role) {
66441+
66442+#define FOR_EACH_ROLE_END(role) \
66443+ role = role->prev; \
66444+ }
66445+
66446+extern struct path gr_real_root;
66447+
66448+static struct gr_policy_state running_polstate;
66449+struct gr_policy_state *polstate = &running_polstate;
66450+extern struct gr_alloc_state *current_alloc_state;
66451+
66452+extern char *gr_shared_page[4];
66453+DEFINE_RWLOCK(gr_inode_lock);
66454+
66455+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66456+
66457+#ifdef CONFIG_NET
66458+extern struct vfsmount *sock_mnt;
66459+#endif
66460+
66461+extern struct vfsmount *pipe_mnt;
66462+extern struct vfsmount *shm_mnt;
66463+
66464+#ifdef CONFIG_HUGETLBFS
66465+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66466+#endif
66467+
66468+extern u16 acl_sp_role_value;
66469+extern struct acl_object_label *fakefs_obj_rw;
66470+extern struct acl_object_label *fakefs_obj_rwx;
66471+
66472+int gr_acl_is_enabled(void)
66473+{
66474+ return (gr_status & GR_READY);
66475+}
66476+
66477+void gr_enable_rbac_system(void)
66478+{
66479+ pax_open_kernel();
66480+ gr_status |= GR_READY;
66481+ pax_close_kernel();
66482+}
66483+
66484+int gr_rbac_disable(void *unused)
66485+{
66486+ pax_open_kernel();
66487+ gr_status &= ~GR_READY;
66488+ pax_close_kernel();
66489+
66490+ return 0;
66491+}
66492+
66493+static inline dev_t __get_dev(const struct dentry *dentry)
66494+{
66495+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66496+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66497+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66498+ else
66499+#endif
66500+ return dentry->d_sb->s_dev;
66501+}
66502+
66503+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66504+{
66505+ return __get_dev(dentry);
66506+}
66507+
66508+static char gr_task_roletype_to_char(struct task_struct *task)
66509+{
66510+ switch (task->role->roletype &
66511+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66512+ GR_ROLE_SPECIAL)) {
66513+ case GR_ROLE_DEFAULT:
66514+ return 'D';
66515+ case GR_ROLE_USER:
66516+ return 'U';
66517+ case GR_ROLE_GROUP:
66518+ return 'G';
66519+ case GR_ROLE_SPECIAL:
66520+ return 'S';
66521+ }
66522+
66523+ return 'X';
66524+}
66525+
66526+char gr_roletype_to_char(void)
66527+{
66528+ return gr_task_roletype_to_char(current);
66529+}
66530+
66531+__inline__ int
66532+gr_acl_tpe_check(void)
66533+{
66534+ if (unlikely(!(gr_status & GR_READY)))
66535+ return 0;
66536+ if (current->role->roletype & GR_ROLE_TPE)
66537+ return 1;
66538+ else
66539+ return 0;
66540+}
66541+
66542+int
66543+gr_handle_rawio(const struct inode *inode)
66544+{
66545+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66546+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66547+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66548+ !capable(CAP_SYS_RAWIO))
66549+ return 1;
66550+#endif
66551+ return 0;
66552+}
66553+
66554+int
66555+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66556+{
66557+ if (likely(lena != lenb))
66558+ return 0;
66559+
66560+ return !memcmp(a, b, lena);
66561+}
66562+
66563+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66564+{
66565+ *buflen -= namelen;
66566+ if (*buflen < 0)
66567+ return -ENAMETOOLONG;
66568+ *buffer -= namelen;
66569+ memcpy(*buffer, str, namelen);
66570+ return 0;
66571+}
66572+
66573+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66574+{
66575+ return prepend(buffer, buflen, name->name, name->len);
66576+}
66577+
66578+static int prepend_path(const struct path *path, struct path *root,
66579+ char **buffer, int *buflen)
66580+{
66581+ struct dentry *dentry = path->dentry;
66582+ struct vfsmount *vfsmnt = path->mnt;
66583+ struct mount *mnt = real_mount(vfsmnt);
66584+ bool slash = false;
66585+ int error = 0;
66586+
66587+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66588+ struct dentry * parent;
66589+
66590+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66591+ /* Global root? */
66592+ if (!mnt_has_parent(mnt)) {
66593+ goto out;
66594+ }
66595+ dentry = mnt->mnt_mountpoint;
66596+ mnt = mnt->mnt_parent;
66597+ vfsmnt = &mnt->mnt;
66598+ continue;
66599+ }
66600+ parent = dentry->d_parent;
66601+ prefetch(parent);
66602+ spin_lock(&dentry->d_lock);
66603+ error = prepend_name(buffer, buflen, &dentry->d_name);
66604+ spin_unlock(&dentry->d_lock);
66605+ if (!error)
66606+ error = prepend(buffer, buflen, "/", 1);
66607+ if (error)
66608+ break;
66609+
66610+ slash = true;
66611+ dentry = parent;
66612+ }
66613+
66614+out:
66615+ if (!error && !slash)
66616+ error = prepend(buffer, buflen, "/", 1);
66617+
66618+ return error;
66619+}
66620+
66621+/* this must be called with mount_lock and rename_lock held */
66622+
66623+static char *__our_d_path(const struct path *path, struct path *root,
66624+ char *buf, int buflen)
66625+{
66626+ char *res = buf + buflen;
66627+ int error;
66628+
66629+ prepend(&res, &buflen, "\0", 1);
66630+ error = prepend_path(path, root, &res, &buflen);
66631+ if (error)
66632+ return ERR_PTR(error);
66633+
66634+ return res;
66635+}
66636+
66637+static char *
66638+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66639+{
66640+ char *retval;
66641+
66642+ retval = __our_d_path(path, root, buf, buflen);
66643+ if (unlikely(IS_ERR(retval)))
66644+ retval = strcpy(buf, "<path too long>");
66645+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66646+ retval[1] = '\0';
66647+
66648+ return retval;
66649+}
66650+
66651+static char *
66652+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66653+ char *buf, int buflen)
66654+{
66655+ struct path path;
66656+ char *res;
66657+
66658+ path.dentry = (struct dentry *)dentry;
66659+ path.mnt = (struct vfsmount *)vfsmnt;
66660+
66661+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66662+ by the RBAC system */
66663+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66664+
66665+ return res;
66666+}
66667+
66668+static char *
66669+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66670+ char *buf, int buflen)
66671+{
66672+ char *res;
66673+ struct path path;
66674+ struct path root;
66675+ struct task_struct *reaper = init_pid_ns.child_reaper;
66676+
66677+ path.dentry = (struct dentry *)dentry;
66678+ path.mnt = (struct vfsmount *)vfsmnt;
66679+
66680+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66681+ get_fs_root(reaper->fs, &root);
66682+
66683+ read_seqlock_excl(&mount_lock);
66684+ write_seqlock(&rename_lock);
66685+ res = gen_full_path(&path, &root, buf, buflen);
66686+ write_sequnlock(&rename_lock);
66687+ read_sequnlock_excl(&mount_lock);
66688+
66689+ path_put(&root);
66690+ return res;
66691+}
66692+
66693+char *
66694+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66695+{
66696+ char *ret;
66697+ read_seqlock_excl(&mount_lock);
66698+ write_seqlock(&rename_lock);
66699+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66700+ PAGE_SIZE);
66701+ write_sequnlock(&rename_lock);
66702+ read_sequnlock_excl(&mount_lock);
66703+ return ret;
66704+}
66705+
66706+static char *
66707+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66708+{
66709+ char *ret;
66710+ char *buf;
66711+ int buflen;
66712+
66713+ read_seqlock_excl(&mount_lock);
66714+ write_seqlock(&rename_lock);
66715+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66716+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66717+ buflen = (int)(ret - buf);
66718+ if (buflen >= 5)
66719+ prepend(&ret, &buflen, "/proc", 5);
66720+ else
66721+ ret = strcpy(buf, "<path too long>");
66722+ write_sequnlock(&rename_lock);
66723+ read_sequnlock_excl(&mount_lock);
66724+ return ret;
66725+}
66726+
66727+char *
66728+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66729+{
66730+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66731+ PAGE_SIZE);
66732+}
66733+
66734+char *
66735+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66736+{
66737+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66738+ PAGE_SIZE);
66739+}
66740+
66741+char *
66742+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66743+{
66744+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66745+ PAGE_SIZE);
66746+}
66747+
66748+char *
66749+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66750+{
66751+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66752+ PAGE_SIZE);
66753+}
66754+
66755+char *
66756+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66757+{
66758+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66759+ PAGE_SIZE);
66760+}
66761+
66762+__inline__ __u32
66763+to_gr_audit(const __u32 reqmode)
66764+{
66765+ /* masks off auditable permission flags, then shifts them to create
66766+ auditing flags, and adds the special case of append auditing if
66767+ we're requesting write */
66768+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66769+}
66770+
66771+struct acl_role_label *
66772+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66773+ const gid_t gid)
66774+{
66775+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66776+ struct acl_role_label *match;
66777+ struct role_allowed_ip *ipp;
66778+ unsigned int x;
66779+ u32 curr_ip = task->signal->saved_ip;
66780+
66781+ match = state->acl_role_set.r_hash[index];
66782+
66783+ while (match) {
66784+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66785+ for (x = 0; x < match->domain_child_num; x++) {
66786+ if (match->domain_children[x] == uid)
66787+ goto found;
66788+ }
66789+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66790+ break;
66791+ match = match->next;
66792+ }
66793+found:
66794+ if (match == NULL) {
66795+ try_group:
66796+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66797+ match = state->acl_role_set.r_hash[index];
66798+
66799+ while (match) {
66800+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66801+ for (x = 0; x < match->domain_child_num; x++) {
66802+ if (match->domain_children[x] == gid)
66803+ goto found2;
66804+ }
66805+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66806+ break;
66807+ match = match->next;
66808+ }
66809+found2:
66810+ if (match == NULL)
66811+ match = state->default_role;
66812+ if (match->allowed_ips == NULL)
66813+ return match;
66814+ else {
66815+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66816+ if (likely
66817+ ((ntohl(curr_ip) & ipp->netmask) ==
66818+ (ntohl(ipp->addr) & ipp->netmask)))
66819+ return match;
66820+ }
66821+ match = state->default_role;
66822+ }
66823+ } else if (match->allowed_ips == NULL) {
66824+ return match;
66825+ } else {
66826+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66827+ if (likely
66828+ ((ntohl(curr_ip) & ipp->netmask) ==
66829+ (ntohl(ipp->addr) & ipp->netmask)))
66830+ return match;
66831+ }
66832+ goto try_group;
66833+ }
66834+
66835+ return match;
66836+}
66837+
66838+static struct acl_role_label *
66839+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66840+ const gid_t gid)
66841+{
66842+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66843+}
66844+
66845+struct acl_subject_label *
66846+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66847+ const struct acl_role_label *role)
66848+{
66849+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66850+ struct acl_subject_label *match;
66851+
66852+ match = role->subj_hash[index];
66853+
66854+ while (match && (match->inode != ino || match->device != dev ||
66855+ (match->mode & GR_DELETED))) {
66856+ match = match->next;
66857+ }
66858+
66859+ if (match && !(match->mode & GR_DELETED))
66860+ return match;
66861+ else
66862+ return NULL;
66863+}
66864+
66865+struct acl_subject_label *
66866+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66867+ const struct acl_role_label *role)
66868+{
66869+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66870+ struct acl_subject_label *match;
66871+
66872+ match = role->subj_hash[index];
66873+
66874+ while (match && (match->inode != ino || match->device != dev ||
66875+ !(match->mode & GR_DELETED))) {
66876+ match = match->next;
66877+ }
66878+
66879+ if (match && (match->mode & GR_DELETED))
66880+ return match;
66881+ else
66882+ return NULL;
66883+}
66884+
66885+static struct acl_object_label *
66886+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66887+ const struct acl_subject_label *subj)
66888+{
66889+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66890+ struct acl_object_label *match;
66891+
66892+ match = subj->obj_hash[index];
66893+
66894+ while (match && (match->inode != ino || match->device != dev ||
66895+ (match->mode & GR_DELETED))) {
66896+ match = match->next;
66897+ }
66898+
66899+ if (match && !(match->mode & GR_DELETED))
66900+ return match;
66901+ else
66902+ return NULL;
66903+}
66904+
66905+static struct acl_object_label *
66906+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66907+ const struct acl_subject_label *subj)
66908+{
66909+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66910+ struct acl_object_label *match;
66911+
66912+ match = subj->obj_hash[index];
66913+
66914+ while (match && (match->inode != ino || match->device != dev ||
66915+ !(match->mode & GR_DELETED))) {
66916+ match = match->next;
66917+ }
66918+
66919+ if (match && (match->mode & GR_DELETED))
66920+ return match;
66921+
66922+ match = subj->obj_hash[index];
66923+
66924+ while (match && (match->inode != ino || match->device != dev ||
66925+ (match->mode & GR_DELETED))) {
66926+ match = match->next;
66927+ }
66928+
66929+ if (match && !(match->mode & GR_DELETED))
66930+ return match;
66931+ else
66932+ return NULL;
66933+}
66934+
66935+struct name_entry *
66936+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66937+{
66938+ unsigned int len = strlen(name);
66939+ unsigned int key = full_name_hash(name, len);
66940+ unsigned int index = key % state->name_set.n_size;
66941+ struct name_entry *match;
66942+
66943+ match = state->name_set.n_hash[index];
66944+
66945+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66946+ match = match->next;
66947+
66948+ return match;
66949+}
66950+
66951+static struct name_entry *
66952+lookup_name_entry(const char *name)
66953+{
66954+ return __lookup_name_entry(&running_polstate, name);
66955+}
66956+
66957+static struct name_entry *
66958+lookup_name_entry_create(const char *name)
66959+{
66960+ unsigned int len = strlen(name);
66961+ unsigned int key = full_name_hash(name, len);
66962+ unsigned int index = key % running_polstate.name_set.n_size;
66963+ struct name_entry *match;
66964+
66965+ match = running_polstate.name_set.n_hash[index];
66966+
66967+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66968+ !match->deleted))
66969+ match = match->next;
66970+
66971+ if (match && match->deleted)
66972+ return match;
66973+
66974+ match = running_polstate.name_set.n_hash[index];
66975+
66976+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66977+ match->deleted))
66978+ match = match->next;
66979+
66980+ if (match && !match->deleted)
66981+ return match;
66982+ else
66983+ return NULL;
66984+}
66985+
66986+static struct inodev_entry *
66987+lookup_inodev_entry(const ino_t ino, const dev_t dev)
66988+{
66989+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66990+ struct inodev_entry *match;
66991+
66992+ match = running_polstate.inodev_set.i_hash[index];
66993+
66994+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66995+ match = match->next;
66996+
66997+ return match;
66998+}
66999+
67000+void
67001+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67002+{
67003+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67004+ state->inodev_set.i_size);
67005+ struct inodev_entry **curr;
67006+
67007+ entry->prev = NULL;
67008+
67009+ curr = &state->inodev_set.i_hash[index];
67010+ if (*curr != NULL)
67011+ (*curr)->prev = entry;
67012+
67013+ entry->next = *curr;
67014+ *curr = entry;
67015+
67016+ return;
67017+}
67018+
67019+static void
67020+insert_inodev_entry(struct inodev_entry *entry)
67021+{
67022+ __insert_inodev_entry(&running_polstate, entry);
67023+}
67024+
67025+void
67026+insert_acl_obj_label(struct acl_object_label *obj,
67027+ struct acl_subject_label *subj)
67028+{
67029+ unsigned int index =
67030+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67031+ struct acl_object_label **curr;
67032+
67033+ obj->prev = NULL;
67034+
67035+ curr = &subj->obj_hash[index];
67036+ if (*curr != NULL)
67037+ (*curr)->prev = obj;
67038+
67039+ obj->next = *curr;
67040+ *curr = obj;
67041+
67042+ return;
67043+}
67044+
67045+void
67046+insert_acl_subj_label(struct acl_subject_label *obj,
67047+ struct acl_role_label *role)
67048+{
67049+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67050+ struct acl_subject_label **curr;
67051+
67052+ obj->prev = NULL;
67053+
67054+ curr = &role->subj_hash[index];
67055+ if (*curr != NULL)
67056+ (*curr)->prev = obj;
67057+
67058+ obj->next = *curr;
67059+ *curr = obj;
67060+
67061+ return;
67062+}
67063+
67064+/* derived from glibc fnmatch() 0: match, 1: no match*/
67065+
67066+static int
67067+glob_match(const char *p, const char *n)
67068+{
67069+ char c;
67070+
67071+ while ((c = *p++) != '\0') {
67072+ switch (c) {
67073+ case '?':
67074+ if (*n == '\0')
67075+ return 1;
67076+ else if (*n == '/')
67077+ return 1;
67078+ break;
67079+ case '\\':
67080+ if (*n != c)
67081+ return 1;
67082+ break;
67083+ case '*':
67084+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67085+ if (*n == '/')
67086+ return 1;
67087+ else if (c == '?') {
67088+ if (*n == '\0')
67089+ return 1;
67090+ else
67091+ ++n;
67092+ }
67093+ }
67094+ if (c == '\0') {
67095+ return 0;
67096+ } else {
67097+ const char *endp;
67098+
67099+ if ((endp = strchr(n, '/')) == NULL)
67100+ endp = n + strlen(n);
67101+
67102+ if (c == '[') {
67103+ for (--p; n < endp; ++n)
67104+ if (!glob_match(p, n))
67105+ return 0;
67106+ } else if (c == '/') {
67107+ while (*n != '\0' && *n != '/')
67108+ ++n;
67109+ if (*n == '/' && !glob_match(p, n + 1))
67110+ return 0;
67111+ } else {
67112+ for (--p; n < endp; ++n)
67113+ if (*n == c && !glob_match(p, n))
67114+ return 0;
67115+ }
67116+
67117+ return 1;
67118+ }
67119+ case '[':
67120+ {
67121+ int not;
67122+ char cold;
67123+
67124+ if (*n == '\0' || *n == '/')
67125+ return 1;
67126+
67127+ not = (*p == '!' || *p == '^');
67128+ if (not)
67129+ ++p;
67130+
67131+ c = *p++;
67132+ for (;;) {
67133+ unsigned char fn = (unsigned char)*n;
67134+
67135+ if (c == '\0')
67136+ return 1;
67137+ else {
67138+ if (c == fn)
67139+ goto matched;
67140+ cold = c;
67141+ c = *p++;
67142+
67143+ if (c == '-' && *p != ']') {
67144+ unsigned char cend = *p++;
67145+
67146+ if (cend == '\0')
67147+ return 1;
67148+
67149+ if (cold <= fn && fn <= cend)
67150+ goto matched;
67151+
67152+ c = *p++;
67153+ }
67154+ }
67155+
67156+ if (c == ']')
67157+ break;
67158+ }
67159+ if (!not)
67160+ return 1;
67161+ break;
67162+ matched:
67163+ while (c != ']') {
67164+ if (c == '\0')
67165+ return 1;
67166+
67167+ c = *p++;
67168+ }
67169+ if (not)
67170+ return 1;
67171+ }
67172+ break;
67173+ default:
67174+ if (c != *n)
67175+ return 1;
67176+ }
67177+
67178+ ++n;
67179+ }
67180+
67181+ if (*n == '\0')
67182+ return 0;
67183+
67184+ if (*n == '/')
67185+ return 0;
67186+
67187+ return 1;
67188+}
67189+
67190+static struct acl_object_label *
67191+chk_glob_label(struct acl_object_label *globbed,
67192+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67193+{
67194+ struct acl_object_label *tmp;
67195+
67196+ if (*path == NULL)
67197+ *path = gr_to_filename_nolock(dentry, mnt);
67198+
67199+ tmp = globbed;
67200+
67201+ while (tmp) {
67202+ if (!glob_match(tmp->filename, *path))
67203+ return tmp;
67204+ tmp = tmp->next;
67205+ }
67206+
67207+ return NULL;
67208+}
67209+
67210+static struct acl_object_label *
67211+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67212+ const ino_t curr_ino, const dev_t curr_dev,
67213+ const struct acl_subject_label *subj, char **path, const int checkglob)
67214+{
67215+ struct acl_subject_label *tmpsubj;
67216+ struct acl_object_label *retval;
67217+ struct acl_object_label *retval2;
67218+
67219+ tmpsubj = (struct acl_subject_label *) subj;
67220+ read_lock(&gr_inode_lock);
67221+ do {
67222+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67223+ if (retval) {
67224+ if (checkglob && retval->globbed) {
67225+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67226+ if (retval2)
67227+ retval = retval2;
67228+ }
67229+ break;
67230+ }
67231+ } while ((tmpsubj = tmpsubj->parent_subject));
67232+ read_unlock(&gr_inode_lock);
67233+
67234+ return retval;
67235+}
67236+
67237+static __inline__ struct acl_object_label *
67238+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67239+ struct dentry *curr_dentry,
67240+ const struct acl_subject_label *subj, char **path, const int checkglob)
67241+{
67242+ int newglob = checkglob;
67243+ ino_t inode;
67244+ dev_t device;
67245+
67246+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67247+ as we don't want a / * rule to match instead of the / object
67248+ don't do this for create lookups that call this function though, since they're looking up
67249+ on the parent and thus need globbing checks on all paths
67250+ */
67251+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67252+ newglob = GR_NO_GLOB;
67253+
67254+ spin_lock(&curr_dentry->d_lock);
67255+ inode = curr_dentry->d_inode->i_ino;
67256+ device = __get_dev(curr_dentry);
67257+ spin_unlock(&curr_dentry->d_lock);
67258+
67259+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67260+}
67261+
67262+#ifdef CONFIG_HUGETLBFS
67263+static inline bool
67264+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67265+{
67266+ int i;
67267+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67268+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67269+ return true;
67270+ }
67271+
67272+ return false;
67273+}
67274+#endif
67275+
67276+static struct acl_object_label *
67277+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67278+ const struct acl_subject_label *subj, char *path, const int checkglob)
67279+{
67280+ struct dentry *dentry = (struct dentry *) l_dentry;
67281+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67282+ struct mount *real_mnt = real_mount(mnt);
67283+ struct acl_object_label *retval;
67284+ struct dentry *parent;
67285+
67286+ read_seqlock_excl(&mount_lock);
67287+ write_seqlock(&rename_lock);
67288+
67289+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67290+#ifdef CONFIG_NET
67291+ mnt == sock_mnt ||
67292+#endif
67293+#ifdef CONFIG_HUGETLBFS
67294+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67295+#endif
67296+ /* ignore Eric Biederman */
67297+ IS_PRIVATE(l_dentry->d_inode))) {
67298+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67299+ goto out;
67300+ }
67301+
67302+ for (;;) {
67303+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67304+ break;
67305+
67306+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67307+ if (!mnt_has_parent(real_mnt))
67308+ break;
67309+
67310+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67311+ if (retval != NULL)
67312+ goto out;
67313+
67314+ dentry = real_mnt->mnt_mountpoint;
67315+ real_mnt = real_mnt->mnt_parent;
67316+ mnt = &real_mnt->mnt;
67317+ continue;
67318+ }
67319+
67320+ parent = dentry->d_parent;
67321+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67322+ if (retval != NULL)
67323+ goto out;
67324+
67325+ dentry = parent;
67326+ }
67327+
67328+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67329+
67330+ /* gr_real_root is pinned so we don't have to hold a reference */
67331+ if (retval == NULL)
67332+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67333+out:
67334+ write_sequnlock(&rename_lock);
67335+ read_sequnlock_excl(&mount_lock);
67336+
67337+ BUG_ON(retval == NULL);
67338+
67339+ return retval;
67340+}
67341+
67342+static __inline__ struct acl_object_label *
67343+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67344+ const struct acl_subject_label *subj)
67345+{
67346+ char *path = NULL;
67347+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67348+}
67349+
67350+static __inline__ struct acl_object_label *
67351+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67352+ const struct acl_subject_label *subj)
67353+{
67354+ char *path = NULL;
67355+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67356+}
67357+
67358+static __inline__ struct acl_object_label *
67359+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67360+ const struct acl_subject_label *subj, char *path)
67361+{
67362+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67363+}
67364+
67365+struct acl_subject_label *
67366+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67367+ const struct acl_role_label *role)
67368+{
67369+ struct dentry *dentry = (struct dentry *) l_dentry;
67370+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67371+ struct mount *real_mnt = real_mount(mnt);
67372+ struct acl_subject_label *retval;
67373+ struct dentry *parent;
67374+
67375+ read_seqlock_excl(&mount_lock);
67376+ write_seqlock(&rename_lock);
67377+
67378+ for (;;) {
67379+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67380+ break;
67381+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67382+ if (!mnt_has_parent(real_mnt))
67383+ break;
67384+
67385+ spin_lock(&dentry->d_lock);
67386+ read_lock(&gr_inode_lock);
67387+ retval =
67388+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67389+ __get_dev(dentry), role);
67390+ read_unlock(&gr_inode_lock);
67391+ spin_unlock(&dentry->d_lock);
67392+ if (retval != NULL)
67393+ goto out;
67394+
67395+ dentry = real_mnt->mnt_mountpoint;
67396+ real_mnt = real_mnt->mnt_parent;
67397+ mnt = &real_mnt->mnt;
67398+ continue;
67399+ }
67400+
67401+ spin_lock(&dentry->d_lock);
67402+ read_lock(&gr_inode_lock);
67403+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67404+ __get_dev(dentry), role);
67405+ read_unlock(&gr_inode_lock);
67406+ parent = dentry->d_parent;
67407+ spin_unlock(&dentry->d_lock);
67408+
67409+ if (retval != NULL)
67410+ goto out;
67411+
67412+ dentry = parent;
67413+ }
67414+
67415+ spin_lock(&dentry->d_lock);
67416+ read_lock(&gr_inode_lock);
67417+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67418+ __get_dev(dentry), role);
67419+ read_unlock(&gr_inode_lock);
67420+ spin_unlock(&dentry->d_lock);
67421+
67422+ if (unlikely(retval == NULL)) {
67423+ /* gr_real_root is pinned, we don't need to hold a reference */
67424+ read_lock(&gr_inode_lock);
67425+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67426+ __get_dev(gr_real_root.dentry), role);
67427+ read_unlock(&gr_inode_lock);
67428+ }
67429+out:
67430+ write_sequnlock(&rename_lock);
67431+ read_sequnlock_excl(&mount_lock);
67432+
67433+ BUG_ON(retval == NULL);
67434+
67435+ return retval;
67436+}
67437+
67438+void
67439+assign_special_role(const char *rolename)
67440+{
67441+ struct acl_object_label *obj;
67442+ struct acl_role_label *r;
67443+ struct acl_role_label *assigned = NULL;
67444+ struct task_struct *tsk;
67445+ struct file *filp;
67446+
67447+ FOR_EACH_ROLE_START(r)
67448+ if (!strcmp(rolename, r->rolename) &&
67449+ (r->roletype & GR_ROLE_SPECIAL)) {
67450+ assigned = r;
67451+ break;
67452+ }
67453+ FOR_EACH_ROLE_END(r)
67454+
67455+ if (!assigned)
67456+ return;
67457+
67458+ read_lock(&tasklist_lock);
67459+ read_lock(&grsec_exec_file_lock);
67460+
67461+ tsk = current->real_parent;
67462+ if (tsk == NULL)
67463+ goto out_unlock;
67464+
67465+ filp = tsk->exec_file;
67466+ if (filp == NULL)
67467+ goto out_unlock;
67468+
67469+ tsk->is_writable = 0;
67470+ tsk->inherited = 0;
67471+
67472+ tsk->acl_sp_role = 1;
67473+ tsk->acl_role_id = ++acl_sp_role_value;
67474+ tsk->role = assigned;
67475+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67476+
67477+ /* ignore additional mmap checks for processes that are writable
67478+ by the default ACL */
67479+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67480+ if (unlikely(obj->mode & GR_WRITE))
67481+ tsk->is_writable = 1;
67482+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67483+ if (unlikely(obj->mode & GR_WRITE))
67484+ tsk->is_writable = 1;
67485+
67486+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67487+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67488+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67489+#endif
67490+
67491+out_unlock:
67492+ read_unlock(&grsec_exec_file_lock);
67493+ read_unlock(&tasklist_lock);
67494+ return;
67495+}
67496+
67497+
67498+static void
67499+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67500+{
67501+ struct task_struct *task = current;
67502+ const struct cred *cred = current_cred();
67503+
67504+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67505+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67506+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67507+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67508+
67509+ return;
67510+}
67511+
67512+static void
67513+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67514+{
67515+ struct task_struct *task = current;
67516+ const struct cred *cred = current_cred();
67517+
67518+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67519+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67520+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67521+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67522+
67523+ return;
67524+}
67525+
67526+static void
67527+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67528+{
67529+ struct task_struct *task = current;
67530+ const struct cred *cred = current_cred();
67531+
67532+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67533+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67534+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67535+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67536+
67537+ return;
67538+}
67539+
67540+static void
67541+gr_set_proc_res(struct task_struct *task)
67542+{
67543+ struct acl_subject_label *proc;
67544+ unsigned short i;
67545+
67546+ proc = task->acl;
67547+
67548+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67549+ return;
67550+
67551+ for (i = 0; i < RLIM_NLIMITS; i++) {
67552+ if (!(proc->resmask & (1U << i)))
67553+ continue;
67554+
67555+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67556+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67557+
67558+ if (i == RLIMIT_CPU)
67559+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67560+ }
67561+
67562+ return;
67563+}
67564+
67565+/* both of the below must be called with
67566+ rcu_read_lock();
67567+ read_lock(&tasklist_lock);
67568+ read_lock(&grsec_exec_file_lock);
67569+*/
67570+
67571+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67572+{
67573+ char *tmpname;
67574+ struct acl_subject_label *tmpsubj;
67575+ struct file *filp;
67576+ struct name_entry *nmatch;
67577+
67578+ filp = task->exec_file;
67579+ if (filp == NULL)
67580+ return NULL;
67581+
67582+ /* the following is to apply the correct subject
67583+ on binaries running when the RBAC system
67584+ is enabled, when the binaries have been
67585+ replaced or deleted since their execution
67586+ -----
67587+ when the RBAC system starts, the inode/dev
67588+ from exec_file will be one the RBAC system
67589+ is unaware of. It only knows the inode/dev
67590+ of the present file on disk, or the absence
67591+ of it.
67592+ */
67593+
67594+ if (filename)
67595+ nmatch = __lookup_name_entry(state, filename);
67596+ else {
67597+ preempt_disable();
67598+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67599+
67600+ nmatch = __lookup_name_entry(state, tmpname);
67601+ preempt_enable();
67602+ }
67603+ tmpsubj = NULL;
67604+ if (nmatch) {
67605+ if (nmatch->deleted)
67606+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67607+ else
67608+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67609+ }
67610+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67611+ then we fall back to a normal lookup based on the binary's ino/dev
67612+ */
67613+ if (tmpsubj == NULL)
67614+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67615+
67616+ return tmpsubj;
67617+}
67618+
67619+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67620+{
67621+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67622+}
67623+
67624+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67625+{
67626+ struct acl_object_label *obj;
67627+ struct file *filp;
67628+
67629+ filp = task->exec_file;
67630+
67631+ task->acl = subj;
67632+ task->is_writable = 0;
67633+ /* ignore additional mmap checks for processes that are writable
67634+ by the default ACL */
67635+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67636+ if (unlikely(obj->mode & GR_WRITE))
67637+ task->is_writable = 1;
67638+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67639+ if (unlikely(obj->mode & GR_WRITE))
67640+ task->is_writable = 1;
67641+
67642+ gr_set_proc_res(task);
67643+
67644+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67645+ 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);
67646+#endif
67647+}
67648+
67649+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67650+{
67651+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67652+}
67653+
67654+__u32
67655+gr_search_file(const struct dentry * dentry, const __u32 mode,
67656+ const struct vfsmount * mnt)
67657+{
67658+ __u32 retval = mode;
67659+ struct acl_subject_label *curracl;
67660+ struct acl_object_label *currobj;
67661+
67662+ if (unlikely(!(gr_status & GR_READY)))
67663+ return (mode & ~GR_AUDITS);
67664+
67665+ curracl = current->acl;
67666+
67667+ currobj = chk_obj_label(dentry, mnt, curracl);
67668+ retval = currobj->mode & mode;
67669+
67670+ /* if we're opening a specified transfer file for writing
67671+ (e.g. /dev/initctl), then transfer our role to init
67672+ */
67673+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67674+ current->role->roletype & GR_ROLE_PERSIST)) {
67675+ struct task_struct *task = init_pid_ns.child_reaper;
67676+
67677+ if (task->role != current->role) {
67678+ struct acl_subject_label *subj;
67679+
67680+ task->acl_sp_role = 0;
67681+ task->acl_role_id = current->acl_role_id;
67682+ task->role = current->role;
67683+ rcu_read_lock();
67684+ read_lock(&grsec_exec_file_lock);
67685+ subj = gr_get_subject_for_task(task, NULL);
67686+ gr_apply_subject_to_task(task, subj);
67687+ read_unlock(&grsec_exec_file_lock);
67688+ rcu_read_unlock();
67689+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67690+ }
67691+ }
67692+
67693+ if (unlikely
67694+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67695+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67696+ __u32 new_mode = mode;
67697+
67698+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67699+
67700+ retval = new_mode;
67701+
67702+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67703+ new_mode |= GR_INHERIT;
67704+
67705+ if (!(mode & GR_NOLEARN))
67706+ gr_log_learn(dentry, mnt, new_mode);
67707+ }
67708+
67709+ return retval;
67710+}
67711+
67712+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67713+ const struct dentry *parent,
67714+ const struct vfsmount *mnt)
67715+{
67716+ struct name_entry *match;
67717+ struct acl_object_label *matchpo;
67718+ struct acl_subject_label *curracl;
67719+ char *path;
67720+
67721+ if (unlikely(!(gr_status & GR_READY)))
67722+ return NULL;
67723+
67724+ preempt_disable();
67725+ path = gr_to_filename_rbac(new_dentry, mnt);
67726+ match = lookup_name_entry_create(path);
67727+
67728+ curracl = current->acl;
67729+
67730+ if (match) {
67731+ read_lock(&gr_inode_lock);
67732+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67733+ read_unlock(&gr_inode_lock);
67734+
67735+ if (matchpo) {
67736+ preempt_enable();
67737+ return matchpo;
67738+ }
67739+ }
67740+
67741+ // lookup parent
67742+
67743+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67744+
67745+ preempt_enable();
67746+ return matchpo;
67747+}
67748+
67749+__u32
67750+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67751+ const struct vfsmount * mnt, const __u32 mode)
67752+{
67753+ struct acl_object_label *matchpo;
67754+ __u32 retval;
67755+
67756+ if (unlikely(!(gr_status & GR_READY)))
67757+ return (mode & ~GR_AUDITS);
67758+
67759+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
67760+
67761+ retval = matchpo->mode & mode;
67762+
67763+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67764+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67765+ __u32 new_mode = mode;
67766+
67767+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67768+
67769+ gr_log_learn(new_dentry, mnt, new_mode);
67770+ return new_mode;
67771+ }
67772+
67773+ return retval;
67774+}
67775+
67776+__u32
67777+gr_check_link(const struct dentry * new_dentry,
67778+ const struct dentry * parent_dentry,
67779+ const struct vfsmount * parent_mnt,
67780+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67781+{
67782+ struct acl_object_label *obj;
67783+ __u32 oldmode, newmode;
67784+ __u32 needmode;
67785+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67786+ GR_DELETE | GR_INHERIT;
67787+
67788+ if (unlikely(!(gr_status & GR_READY)))
67789+ return (GR_CREATE | GR_LINK);
67790+
67791+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67792+ oldmode = obj->mode;
67793+
67794+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67795+ newmode = obj->mode;
67796+
67797+ needmode = newmode & checkmodes;
67798+
67799+ // old name for hardlink must have at least the permissions of the new name
67800+ if ((oldmode & needmode) != needmode)
67801+ goto bad;
67802+
67803+ // if old name had restrictions/auditing, make sure the new name does as well
67804+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67805+
67806+ // don't allow hardlinking of suid/sgid/fcapped files without permission
67807+ if (is_privileged_binary(old_dentry))
67808+ needmode |= GR_SETID;
67809+
67810+ if ((newmode & needmode) != needmode)
67811+ goto bad;
67812+
67813+ // enforce minimum permissions
67814+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67815+ return newmode;
67816+bad:
67817+ needmode = oldmode;
67818+ if (is_privileged_binary(old_dentry))
67819+ needmode |= GR_SETID;
67820+
67821+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67822+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67823+ return (GR_CREATE | GR_LINK);
67824+ } else if (newmode & GR_SUPPRESS)
67825+ return GR_SUPPRESS;
67826+ else
67827+ return 0;
67828+}
67829+
67830+int
67831+gr_check_hidden_task(const struct task_struct *task)
67832+{
67833+ if (unlikely(!(gr_status & GR_READY)))
67834+ return 0;
67835+
67836+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67837+ return 1;
67838+
67839+ return 0;
67840+}
67841+
67842+int
67843+gr_check_protected_task(const struct task_struct *task)
67844+{
67845+ if (unlikely(!(gr_status & GR_READY) || !task))
67846+ return 0;
67847+
67848+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67849+ task->acl != current->acl)
67850+ return 1;
67851+
67852+ return 0;
67853+}
67854+
67855+int
67856+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67857+{
67858+ struct task_struct *p;
67859+ int ret = 0;
67860+
67861+ if (unlikely(!(gr_status & GR_READY) || !pid))
67862+ return ret;
67863+
67864+ read_lock(&tasklist_lock);
67865+ do_each_pid_task(pid, type, p) {
67866+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67867+ p->acl != current->acl) {
67868+ ret = 1;
67869+ goto out;
67870+ }
67871+ } while_each_pid_task(pid, type, p);
67872+out:
67873+ read_unlock(&tasklist_lock);
67874+
67875+ return ret;
67876+}
67877+
67878+void
67879+gr_copy_label(struct task_struct *tsk)
67880+{
67881+ struct task_struct *p = current;
67882+
67883+ tsk->inherited = p->inherited;
67884+ tsk->acl_sp_role = 0;
67885+ tsk->acl_role_id = p->acl_role_id;
67886+ tsk->acl = p->acl;
67887+ tsk->role = p->role;
67888+ tsk->signal->used_accept = 0;
67889+ tsk->signal->curr_ip = p->signal->curr_ip;
67890+ tsk->signal->saved_ip = p->signal->saved_ip;
67891+ if (p->exec_file)
67892+ get_file(p->exec_file);
67893+ tsk->exec_file = p->exec_file;
67894+ tsk->is_writable = p->is_writable;
67895+ if (unlikely(p->signal->used_accept)) {
67896+ p->signal->curr_ip = 0;
67897+ p->signal->saved_ip = 0;
67898+ }
67899+
67900+ return;
67901+}
67902+
67903+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67904+
67905+int
67906+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67907+{
67908+ unsigned int i;
67909+ __u16 num;
67910+ uid_t *uidlist;
67911+ uid_t curuid;
67912+ int realok = 0;
67913+ int effectiveok = 0;
67914+ int fsok = 0;
67915+ uid_t globalreal, globaleffective, globalfs;
67916+
67917+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67918+ struct user_struct *user;
67919+
67920+ if (!uid_valid(real))
67921+ goto skipit;
67922+
67923+ /* find user based on global namespace */
67924+
67925+ globalreal = GR_GLOBAL_UID(real);
67926+
67927+ user = find_user(make_kuid(&init_user_ns, globalreal));
67928+ if (user == NULL)
67929+ goto skipit;
67930+
67931+ if (gr_process_kernel_setuid_ban(user)) {
67932+ /* for find_user */
67933+ free_uid(user);
67934+ return 1;
67935+ }
67936+
67937+ /* for find_user */
67938+ free_uid(user);
67939+
67940+skipit:
67941+#endif
67942+
67943+ if (unlikely(!(gr_status & GR_READY)))
67944+ return 0;
67945+
67946+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67947+ gr_log_learn_uid_change(real, effective, fs);
67948+
67949+ num = current->acl->user_trans_num;
67950+ uidlist = current->acl->user_transitions;
67951+
67952+ if (uidlist == NULL)
67953+ return 0;
67954+
67955+ if (!uid_valid(real)) {
67956+ realok = 1;
67957+ globalreal = (uid_t)-1;
67958+ } else {
67959+ globalreal = GR_GLOBAL_UID(real);
67960+ }
67961+ if (!uid_valid(effective)) {
67962+ effectiveok = 1;
67963+ globaleffective = (uid_t)-1;
67964+ } else {
67965+ globaleffective = GR_GLOBAL_UID(effective);
67966+ }
67967+ if (!uid_valid(fs)) {
67968+ fsok = 1;
67969+ globalfs = (uid_t)-1;
67970+ } else {
67971+ globalfs = GR_GLOBAL_UID(fs);
67972+ }
67973+
67974+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
67975+ for (i = 0; i < num; i++) {
67976+ curuid = uidlist[i];
67977+ if (globalreal == curuid)
67978+ realok = 1;
67979+ if (globaleffective == curuid)
67980+ effectiveok = 1;
67981+ if (globalfs == curuid)
67982+ fsok = 1;
67983+ }
67984+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
67985+ for (i = 0; i < num; i++) {
67986+ curuid = uidlist[i];
67987+ if (globalreal == curuid)
67988+ break;
67989+ if (globaleffective == curuid)
67990+ break;
67991+ if (globalfs == curuid)
67992+ break;
67993+ }
67994+ /* not in deny list */
67995+ if (i == num) {
67996+ realok = 1;
67997+ effectiveok = 1;
67998+ fsok = 1;
67999+ }
68000+ }
68001+
68002+ if (realok && effectiveok && fsok)
68003+ return 0;
68004+ else {
68005+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68006+ return 1;
68007+ }
68008+}
68009+
68010+int
68011+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68012+{
68013+ unsigned int i;
68014+ __u16 num;
68015+ gid_t *gidlist;
68016+ gid_t curgid;
68017+ int realok = 0;
68018+ int effectiveok = 0;
68019+ int fsok = 0;
68020+ gid_t globalreal, globaleffective, globalfs;
68021+
68022+ if (unlikely(!(gr_status & GR_READY)))
68023+ return 0;
68024+
68025+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68026+ gr_log_learn_gid_change(real, effective, fs);
68027+
68028+ num = current->acl->group_trans_num;
68029+ gidlist = current->acl->group_transitions;
68030+
68031+ if (gidlist == NULL)
68032+ return 0;
68033+
68034+ if (!gid_valid(real)) {
68035+ realok = 1;
68036+ globalreal = (gid_t)-1;
68037+ } else {
68038+ globalreal = GR_GLOBAL_GID(real);
68039+ }
68040+ if (!gid_valid(effective)) {
68041+ effectiveok = 1;
68042+ globaleffective = (gid_t)-1;
68043+ } else {
68044+ globaleffective = GR_GLOBAL_GID(effective);
68045+ }
68046+ if (!gid_valid(fs)) {
68047+ fsok = 1;
68048+ globalfs = (gid_t)-1;
68049+ } else {
68050+ globalfs = GR_GLOBAL_GID(fs);
68051+ }
68052+
68053+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
68054+ for (i = 0; i < num; i++) {
68055+ curgid = gidlist[i];
68056+ if (globalreal == curgid)
68057+ realok = 1;
68058+ if (globaleffective == curgid)
68059+ effectiveok = 1;
68060+ if (globalfs == curgid)
68061+ fsok = 1;
68062+ }
68063+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
68064+ for (i = 0; i < num; i++) {
68065+ curgid = gidlist[i];
68066+ if (globalreal == curgid)
68067+ break;
68068+ if (globaleffective == curgid)
68069+ break;
68070+ if (globalfs == curgid)
68071+ break;
68072+ }
68073+ /* not in deny list */
68074+ if (i == num) {
68075+ realok = 1;
68076+ effectiveok = 1;
68077+ fsok = 1;
68078+ }
68079+ }
68080+
68081+ if (realok && effectiveok && fsok)
68082+ return 0;
68083+ else {
68084+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68085+ return 1;
68086+ }
68087+}
68088+
68089+extern int gr_acl_is_capable(const int cap);
68090+
68091+void
68092+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68093+{
68094+ struct acl_role_label *role = task->role;
68095+ struct acl_subject_label *subj = NULL;
68096+ struct acl_object_label *obj;
68097+ struct file *filp;
68098+ uid_t uid;
68099+ gid_t gid;
68100+
68101+ if (unlikely(!(gr_status & GR_READY)))
68102+ return;
68103+
68104+ uid = GR_GLOBAL_UID(kuid);
68105+ gid = GR_GLOBAL_GID(kgid);
68106+
68107+ filp = task->exec_file;
68108+
68109+ /* kernel process, we'll give them the kernel role */
68110+ if (unlikely(!filp)) {
68111+ task->role = running_polstate.kernel_role;
68112+ task->acl = running_polstate.kernel_role->root_label;
68113+ return;
68114+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68115+ /* save the current ip at time of role lookup so that the proper
68116+ IP will be learned for role_allowed_ip */
68117+ task->signal->saved_ip = task->signal->curr_ip;
68118+ role = lookup_acl_role_label(task, uid, gid);
68119+ }
68120+
68121+ /* don't change the role if we're not a privileged process */
68122+ if (role && task->role != role &&
68123+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68124+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68125+ return;
68126+
68127+ /* perform subject lookup in possibly new role
68128+ we can use this result below in the case where role == task->role
68129+ */
68130+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68131+
68132+ /* if we changed uid/gid, but result in the same role
68133+ and are using inheritance, don't lose the inherited subject
68134+ if current subject is other than what normal lookup
68135+ would result in, we arrived via inheritance, don't
68136+ lose subject
68137+ */
68138+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68139+ (subj == task->acl)))
68140+ task->acl = subj;
68141+
68142+ /* leave task->inherited unaffected */
68143+
68144+ task->role = role;
68145+
68146+ task->is_writable = 0;
68147+
68148+ /* ignore additional mmap checks for processes that are writable
68149+ by the default ACL */
68150+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68151+ if (unlikely(obj->mode & GR_WRITE))
68152+ task->is_writable = 1;
68153+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68154+ if (unlikely(obj->mode & GR_WRITE))
68155+ task->is_writable = 1;
68156+
68157+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68158+ 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);
68159+#endif
68160+
68161+ gr_set_proc_res(task);
68162+
68163+ return;
68164+}
68165+
68166+int
68167+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68168+ const int unsafe_flags)
68169+{
68170+ struct task_struct *task = current;
68171+ struct acl_subject_label *newacl;
68172+ struct acl_object_label *obj;
68173+ __u32 retmode;
68174+
68175+ if (unlikely(!(gr_status & GR_READY)))
68176+ return 0;
68177+
68178+ newacl = chk_subj_label(dentry, mnt, task->role);
68179+
68180+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68181+ did an exec
68182+ */
68183+ rcu_read_lock();
68184+ read_lock(&tasklist_lock);
68185+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68186+ (task->parent->acl->mode & GR_POVERRIDE))) {
68187+ read_unlock(&tasklist_lock);
68188+ rcu_read_unlock();
68189+ goto skip_check;
68190+ }
68191+ read_unlock(&tasklist_lock);
68192+ rcu_read_unlock();
68193+
68194+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68195+ !(task->role->roletype & GR_ROLE_GOD) &&
68196+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68197+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68198+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68199+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68200+ else
68201+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68202+ return -EACCES;
68203+ }
68204+
68205+skip_check:
68206+
68207+ obj = chk_obj_label(dentry, mnt, task->acl);
68208+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68209+
68210+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68211+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68212+ if (obj->nested)
68213+ task->acl = obj->nested;
68214+ else
68215+ task->acl = newacl;
68216+ task->inherited = 0;
68217+ } else {
68218+ task->inherited = 1;
68219+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68220+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68221+ }
68222+
68223+ task->is_writable = 0;
68224+
68225+ /* ignore additional mmap checks for processes that are writable
68226+ by the default ACL */
68227+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68228+ if (unlikely(obj->mode & GR_WRITE))
68229+ task->is_writable = 1;
68230+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68231+ if (unlikely(obj->mode & GR_WRITE))
68232+ task->is_writable = 1;
68233+
68234+ gr_set_proc_res(task);
68235+
68236+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68237+ 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);
68238+#endif
68239+ return 0;
68240+}
68241+
68242+/* always called with valid inodev ptr */
68243+static void
68244+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68245+{
68246+ struct acl_object_label *matchpo;
68247+ struct acl_subject_label *matchps;
68248+ struct acl_subject_label *subj;
68249+ struct acl_role_label *role;
68250+ unsigned int x;
68251+
68252+ FOR_EACH_ROLE_START(role)
68253+ FOR_EACH_SUBJECT_START(role, subj, x)
68254+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68255+ matchpo->mode |= GR_DELETED;
68256+ FOR_EACH_SUBJECT_END(subj,x)
68257+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68258+ /* nested subjects aren't in the role's subj_hash table */
68259+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68260+ matchpo->mode |= GR_DELETED;
68261+ FOR_EACH_NESTED_SUBJECT_END(subj)
68262+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68263+ matchps->mode |= GR_DELETED;
68264+ FOR_EACH_ROLE_END(role)
68265+
68266+ inodev->nentry->deleted = 1;
68267+
68268+ return;
68269+}
68270+
68271+void
68272+gr_handle_delete(const ino_t ino, const dev_t dev)
68273+{
68274+ struct inodev_entry *inodev;
68275+
68276+ if (unlikely(!(gr_status & GR_READY)))
68277+ return;
68278+
68279+ write_lock(&gr_inode_lock);
68280+ inodev = lookup_inodev_entry(ino, dev);
68281+ if (inodev != NULL)
68282+ do_handle_delete(inodev, ino, dev);
68283+ write_unlock(&gr_inode_lock);
68284+
68285+ return;
68286+}
68287+
68288+static void
68289+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68290+ const ino_t newinode, const dev_t newdevice,
68291+ struct acl_subject_label *subj)
68292+{
68293+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68294+ struct acl_object_label *match;
68295+
68296+ match = subj->obj_hash[index];
68297+
68298+ while (match && (match->inode != oldinode ||
68299+ match->device != olddevice ||
68300+ !(match->mode & GR_DELETED)))
68301+ match = match->next;
68302+
68303+ if (match && (match->inode == oldinode)
68304+ && (match->device == olddevice)
68305+ && (match->mode & GR_DELETED)) {
68306+ if (match->prev == NULL) {
68307+ subj->obj_hash[index] = match->next;
68308+ if (match->next != NULL)
68309+ match->next->prev = NULL;
68310+ } else {
68311+ match->prev->next = match->next;
68312+ if (match->next != NULL)
68313+ match->next->prev = match->prev;
68314+ }
68315+ match->prev = NULL;
68316+ match->next = NULL;
68317+ match->inode = newinode;
68318+ match->device = newdevice;
68319+ match->mode &= ~GR_DELETED;
68320+
68321+ insert_acl_obj_label(match, subj);
68322+ }
68323+
68324+ return;
68325+}
68326+
68327+static void
68328+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68329+ const ino_t newinode, const dev_t newdevice,
68330+ struct acl_role_label *role)
68331+{
68332+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68333+ struct acl_subject_label *match;
68334+
68335+ match = role->subj_hash[index];
68336+
68337+ while (match && (match->inode != oldinode ||
68338+ match->device != olddevice ||
68339+ !(match->mode & GR_DELETED)))
68340+ match = match->next;
68341+
68342+ if (match && (match->inode == oldinode)
68343+ && (match->device == olddevice)
68344+ && (match->mode & GR_DELETED)) {
68345+ if (match->prev == NULL) {
68346+ role->subj_hash[index] = match->next;
68347+ if (match->next != NULL)
68348+ match->next->prev = NULL;
68349+ } else {
68350+ match->prev->next = match->next;
68351+ if (match->next != NULL)
68352+ match->next->prev = match->prev;
68353+ }
68354+ match->prev = NULL;
68355+ match->next = NULL;
68356+ match->inode = newinode;
68357+ match->device = newdevice;
68358+ match->mode &= ~GR_DELETED;
68359+
68360+ insert_acl_subj_label(match, role);
68361+ }
68362+
68363+ return;
68364+}
68365+
68366+static void
68367+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68368+ const ino_t newinode, const dev_t newdevice)
68369+{
68370+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68371+ struct inodev_entry *match;
68372+
68373+ match = running_polstate.inodev_set.i_hash[index];
68374+
68375+ while (match && (match->nentry->inode != oldinode ||
68376+ match->nentry->device != olddevice || !match->nentry->deleted))
68377+ match = match->next;
68378+
68379+ if (match && (match->nentry->inode == oldinode)
68380+ && (match->nentry->device == olddevice) &&
68381+ match->nentry->deleted) {
68382+ if (match->prev == NULL) {
68383+ running_polstate.inodev_set.i_hash[index] = match->next;
68384+ if (match->next != NULL)
68385+ match->next->prev = NULL;
68386+ } else {
68387+ match->prev->next = match->next;
68388+ if (match->next != NULL)
68389+ match->next->prev = match->prev;
68390+ }
68391+ match->prev = NULL;
68392+ match->next = NULL;
68393+ match->nentry->inode = newinode;
68394+ match->nentry->device = newdevice;
68395+ match->nentry->deleted = 0;
68396+
68397+ insert_inodev_entry(match);
68398+ }
68399+
68400+ return;
68401+}
68402+
68403+static void
68404+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68405+{
68406+ struct acl_subject_label *subj;
68407+ struct acl_role_label *role;
68408+ unsigned int x;
68409+
68410+ FOR_EACH_ROLE_START(role)
68411+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68412+
68413+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68414+ if ((subj->inode == ino) && (subj->device == dev)) {
68415+ subj->inode = ino;
68416+ subj->device = dev;
68417+ }
68418+ /* nested subjects aren't in the role's subj_hash table */
68419+ update_acl_obj_label(matchn->inode, matchn->device,
68420+ ino, dev, subj);
68421+ FOR_EACH_NESTED_SUBJECT_END(subj)
68422+ FOR_EACH_SUBJECT_START(role, subj, x)
68423+ update_acl_obj_label(matchn->inode, matchn->device,
68424+ ino, dev, subj);
68425+ FOR_EACH_SUBJECT_END(subj,x)
68426+ FOR_EACH_ROLE_END(role)
68427+
68428+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68429+
68430+ return;
68431+}
68432+
68433+static void
68434+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68435+ const struct vfsmount *mnt)
68436+{
68437+ ino_t ino = dentry->d_inode->i_ino;
68438+ dev_t dev = __get_dev(dentry);
68439+
68440+ __do_handle_create(matchn, ino, dev);
68441+
68442+ return;
68443+}
68444+
68445+void
68446+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68447+{
68448+ struct name_entry *matchn;
68449+
68450+ if (unlikely(!(gr_status & GR_READY)))
68451+ return;
68452+
68453+ preempt_disable();
68454+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68455+
68456+ if (unlikely((unsigned long)matchn)) {
68457+ write_lock(&gr_inode_lock);
68458+ do_handle_create(matchn, dentry, mnt);
68459+ write_unlock(&gr_inode_lock);
68460+ }
68461+ preempt_enable();
68462+
68463+ return;
68464+}
68465+
68466+void
68467+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68468+{
68469+ struct name_entry *matchn;
68470+
68471+ if (unlikely(!(gr_status & GR_READY)))
68472+ return;
68473+
68474+ preempt_disable();
68475+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68476+
68477+ if (unlikely((unsigned long)matchn)) {
68478+ write_lock(&gr_inode_lock);
68479+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68480+ write_unlock(&gr_inode_lock);
68481+ }
68482+ preempt_enable();
68483+
68484+ return;
68485+}
68486+
68487+void
68488+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68489+ struct dentry *old_dentry,
68490+ struct dentry *new_dentry,
68491+ struct vfsmount *mnt, const __u8 replace)
68492+{
68493+ struct name_entry *matchn;
68494+ struct inodev_entry *inodev;
68495+ struct inode *inode = new_dentry->d_inode;
68496+ ino_t old_ino = old_dentry->d_inode->i_ino;
68497+ dev_t old_dev = __get_dev(old_dentry);
68498+
68499+ /* vfs_rename swaps the name and parent link for old_dentry and
68500+ new_dentry
68501+ at this point, old_dentry has the new name, parent link, and inode
68502+ for the renamed file
68503+ if a file is being replaced by a rename, new_dentry has the inode
68504+ and name for the replaced file
68505+ */
68506+
68507+ if (unlikely(!(gr_status & GR_READY)))
68508+ return;
68509+
68510+ preempt_disable();
68511+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68512+
68513+ /* we wouldn't have to check d_inode if it weren't for
68514+ NFS silly-renaming
68515+ */
68516+
68517+ write_lock(&gr_inode_lock);
68518+ if (unlikely(replace && inode)) {
68519+ ino_t new_ino = inode->i_ino;
68520+ dev_t new_dev = __get_dev(new_dentry);
68521+
68522+ inodev = lookup_inodev_entry(new_ino, new_dev);
68523+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68524+ do_handle_delete(inodev, new_ino, new_dev);
68525+ }
68526+
68527+ inodev = lookup_inodev_entry(old_ino, old_dev);
68528+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68529+ do_handle_delete(inodev, old_ino, old_dev);
68530+
68531+ if (unlikely((unsigned long)matchn))
68532+ do_handle_create(matchn, old_dentry, mnt);
68533+
68534+ write_unlock(&gr_inode_lock);
68535+ preempt_enable();
68536+
68537+ return;
68538+}
68539+
68540+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68541+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68542+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68543+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68544+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68545+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68546+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68547+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68548+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68549+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68550+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68551+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68552+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68553+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68554+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68555+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68556+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68557+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68558+};
68559+
68560+void
68561+gr_learn_resource(const struct task_struct *task,
68562+ const int res, const unsigned long wanted, const int gt)
68563+{
68564+ struct acl_subject_label *acl;
68565+ const struct cred *cred;
68566+
68567+ if (unlikely((gr_status & GR_READY) &&
68568+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68569+ goto skip_reslog;
68570+
68571+ gr_log_resource(task, res, wanted, gt);
68572+skip_reslog:
68573+
68574+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68575+ return;
68576+
68577+ acl = task->acl;
68578+
68579+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68580+ !(acl->resmask & (1U << (unsigned short) res))))
68581+ return;
68582+
68583+ if (wanted >= acl->res[res].rlim_cur) {
68584+ unsigned long res_add;
68585+
68586+ res_add = wanted + res_learn_bumps[res];
68587+
68588+ acl->res[res].rlim_cur = res_add;
68589+
68590+ if (wanted > acl->res[res].rlim_max)
68591+ acl->res[res].rlim_max = res_add;
68592+
68593+ /* only log the subject filename, since resource logging is supported for
68594+ single-subject learning only */
68595+ rcu_read_lock();
68596+ cred = __task_cred(task);
68597+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68598+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68599+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68600+ "", (unsigned long) res, &task->signal->saved_ip);
68601+ rcu_read_unlock();
68602+ }
68603+
68604+ return;
68605+}
68606+EXPORT_SYMBOL_GPL(gr_learn_resource);
68607+#endif
68608+
68609+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68610+void
68611+pax_set_initial_flags(struct linux_binprm *bprm)
68612+{
68613+ struct task_struct *task = current;
68614+ struct acl_subject_label *proc;
68615+ unsigned long flags;
68616+
68617+ if (unlikely(!(gr_status & GR_READY)))
68618+ return;
68619+
68620+ flags = pax_get_flags(task);
68621+
68622+ proc = task->acl;
68623+
68624+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68625+ flags &= ~MF_PAX_PAGEEXEC;
68626+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68627+ flags &= ~MF_PAX_SEGMEXEC;
68628+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68629+ flags &= ~MF_PAX_RANDMMAP;
68630+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68631+ flags &= ~MF_PAX_EMUTRAMP;
68632+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68633+ flags &= ~MF_PAX_MPROTECT;
68634+
68635+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68636+ flags |= MF_PAX_PAGEEXEC;
68637+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68638+ flags |= MF_PAX_SEGMEXEC;
68639+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68640+ flags |= MF_PAX_RANDMMAP;
68641+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68642+ flags |= MF_PAX_EMUTRAMP;
68643+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68644+ flags |= MF_PAX_MPROTECT;
68645+
68646+ pax_set_flags(task, flags);
68647+
68648+ return;
68649+}
68650+#endif
68651+
68652+int
68653+gr_handle_proc_ptrace(struct task_struct *task)
68654+{
68655+ struct file *filp;
68656+ struct task_struct *tmp = task;
68657+ struct task_struct *curtemp = current;
68658+ __u32 retmode;
68659+
68660+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68661+ if (unlikely(!(gr_status & GR_READY)))
68662+ return 0;
68663+#endif
68664+
68665+ read_lock(&tasklist_lock);
68666+ read_lock(&grsec_exec_file_lock);
68667+ filp = task->exec_file;
68668+
68669+ while (task_pid_nr(tmp) > 0) {
68670+ if (tmp == curtemp)
68671+ break;
68672+ tmp = tmp->real_parent;
68673+ }
68674+
68675+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68676+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68677+ read_unlock(&grsec_exec_file_lock);
68678+ read_unlock(&tasklist_lock);
68679+ return 1;
68680+ }
68681+
68682+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68683+ if (!(gr_status & GR_READY)) {
68684+ read_unlock(&grsec_exec_file_lock);
68685+ read_unlock(&tasklist_lock);
68686+ return 0;
68687+ }
68688+#endif
68689+
68690+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68691+ read_unlock(&grsec_exec_file_lock);
68692+ read_unlock(&tasklist_lock);
68693+
68694+ if (retmode & GR_NOPTRACE)
68695+ return 1;
68696+
68697+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68698+ && (current->acl != task->acl || (current->acl != current->role->root_label
68699+ && task_pid_nr(current) != task_pid_nr(task))))
68700+ return 1;
68701+
68702+ return 0;
68703+}
68704+
68705+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68706+{
68707+ if (unlikely(!(gr_status & GR_READY)))
68708+ return;
68709+
68710+ if (!(current->role->roletype & GR_ROLE_GOD))
68711+ return;
68712+
68713+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68714+ p->role->rolename, gr_task_roletype_to_char(p),
68715+ p->acl->filename);
68716+}
68717+
68718+int
68719+gr_handle_ptrace(struct task_struct *task, const long request)
68720+{
68721+ struct task_struct *tmp = task;
68722+ struct task_struct *curtemp = current;
68723+ __u32 retmode;
68724+
68725+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68726+ if (unlikely(!(gr_status & GR_READY)))
68727+ return 0;
68728+#endif
68729+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68730+ read_lock(&tasklist_lock);
68731+ while (task_pid_nr(tmp) > 0) {
68732+ if (tmp == curtemp)
68733+ break;
68734+ tmp = tmp->real_parent;
68735+ }
68736+
68737+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68738+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68739+ read_unlock(&tasklist_lock);
68740+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68741+ return 1;
68742+ }
68743+ read_unlock(&tasklist_lock);
68744+ }
68745+
68746+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68747+ if (!(gr_status & GR_READY))
68748+ return 0;
68749+#endif
68750+
68751+ read_lock(&grsec_exec_file_lock);
68752+ if (unlikely(!task->exec_file)) {
68753+ read_unlock(&grsec_exec_file_lock);
68754+ return 0;
68755+ }
68756+
68757+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68758+ read_unlock(&grsec_exec_file_lock);
68759+
68760+ if (retmode & GR_NOPTRACE) {
68761+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68762+ return 1;
68763+ }
68764+
68765+ if (retmode & GR_PTRACERD) {
68766+ switch (request) {
68767+ case PTRACE_SEIZE:
68768+ case PTRACE_POKETEXT:
68769+ case PTRACE_POKEDATA:
68770+ case PTRACE_POKEUSR:
68771+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68772+ case PTRACE_SETREGS:
68773+ case PTRACE_SETFPREGS:
68774+#endif
68775+#ifdef CONFIG_X86
68776+ case PTRACE_SETFPXREGS:
68777+#endif
68778+#ifdef CONFIG_ALTIVEC
68779+ case PTRACE_SETVRREGS:
68780+#endif
68781+ return 1;
68782+ default:
68783+ return 0;
68784+ }
68785+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
68786+ !(current->role->roletype & GR_ROLE_GOD) &&
68787+ (current->acl != task->acl)) {
68788+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68789+ return 1;
68790+ }
68791+
68792+ return 0;
68793+}
68794+
68795+static int is_writable_mmap(const struct file *filp)
68796+{
68797+ struct task_struct *task = current;
68798+ struct acl_object_label *obj, *obj2;
68799+
68800+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68801+ !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))) {
68802+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68803+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68804+ task->role->root_label);
68805+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68806+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68807+ return 1;
68808+ }
68809+ }
68810+ return 0;
68811+}
68812+
68813+int
68814+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68815+{
68816+ __u32 mode;
68817+
68818+ if (unlikely(!file || !(prot & PROT_EXEC)))
68819+ return 1;
68820+
68821+ if (is_writable_mmap(file))
68822+ return 0;
68823+
68824+ mode =
68825+ gr_search_file(file->f_path.dentry,
68826+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68827+ file->f_path.mnt);
68828+
68829+ if (!gr_tpe_allow(file))
68830+ return 0;
68831+
68832+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68833+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68834+ return 0;
68835+ } else if (unlikely(!(mode & GR_EXEC))) {
68836+ return 0;
68837+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68838+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68839+ return 1;
68840+ }
68841+
68842+ return 1;
68843+}
68844+
68845+int
68846+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68847+{
68848+ __u32 mode;
68849+
68850+ if (unlikely(!file || !(prot & PROT_EXEC)))
68851+ return 1;
68852+
68853+ if (is_writable_mmap(file))
68854+ return 0;
68855+
68856+ mode =
68857+ gr_search_file(file->f_path.dentry,
68858+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68859+ file->f_path.mnt);
68860+
68861+ if (!gr_tpe_allow(file))
68862+ return 0;
68863+
68864+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68865+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68866+ return 0;
68867+ } else if (unlikely(!(mode & GR_EXEC))) {
68868+ return 0;
68869+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68870+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68871+ return 1;
68872+ }
68873+
68874+ return 1;
68875+}
68876+
68877+void
68878+gr_acl_handle_psacct(struct task_struct *task, const long code)
68879+{
68880+ unsigned long runtime, cputime;
68881+ cputime_t utime, stime;
68882+ unsigned int wday, cday;
68883+ __u8 whr, chr;
68884+ __u8 wmin, cmin;
68885+ __u8 wsec, csec;
68886+ struct timespec timeval;
68887+
68888+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68889+ !(task->acl->mode & GR_PROCACCT)))
68890+ return;
68891+
68892+ do_posix_clock_monotonic_gettime(&timeval);
68893+ runtime = timeval.tv_sec - task->start_time.tv_sec;
68894+ wday = runtime / (60 * 60 * 24);
68895+ runtime -= wday * (60 * 60 * 24);
68896+ whr = runtime / (60 * 60);
68897+ runtime -= whr * (60 * 60);
68898+ wmin = runtime / 60;
68899+ runtime -= wmin * 60;
68900+ wsec = runtime;
68901+
68902+ task_cputime(task, &utime, &stime);
68903+ cputime = cputime_to_secs(utime + stime);
68904+ cday = cputime / (60 * 60 * 24);
68905+ cputime -= cday * (60 * 60 * 24);
68906+ chr = cputime / (60 * 60);
68907+ cputime -= chr * (60 * 60);
68908+ cmin = cputime / 60;
68909+ cputime -= cmin * 60;
68910+ csec = cputime;
68911+
68912+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68913+
68914+ return;
68915+}
68916+
68917+#ifdef CONFIG_TASKSTATS
68918+int gr_is_taskstats_denied(int pid)
68919+{
68920+ struct task_struct *task;
68921+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68922+ const struct cred *cred;
68923+#endif
68924+ int ret = 0;
68925+
68926+ /* restrict taskstats viewing to un-chrooted root users
68927+ who have the 'view' subject flag if the RBAC system is enabled
68928+ */
68929+
68930+ rcu_read_lock();
68931+ read_lock(&tasklist_lock);
68932+ task = find_task_by_vpid(pid);
68933+ if (task) {
68934+#ifdef CONFIG_GRKERNSEC_CHROOT
68935+ if (proc_is_chrooted(task))
68936+ ret = -EACCES;
68937+#endif
68938+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68939+ cred = __task_cred(task);
68940+#ifdef CONFIG_GRKERNSEC_PROC_USER
68941+ if (gr_is_global_nonroot(cred->uid))
68942+ ret = -EACCES;
68943+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68944+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68945+ ret = -EACCES;
68946+#endif
68947+#endif
68948+ if (gr_status & GR_READY) {
68949+ if (!(task->acl->mode & GR_VIEW))
68950+ ret = -EACCES;
68951+ }
68952+ } else
68953+ ret = -ENOENT;
68954+
68955+ read_unlock(&tasklist_lock);
68956+ rcu_read_unlock();
68957+
68958+ return ret;
68959+}
68960+#endif
68961+
68962+/* AUXV entries are filled via a descendant of search_binary_handler
68963+ after we've already applied the subject for the target
68964+*/
68965+int gr_acl_enable_at_secure(void)
68966+{
68967+ if (unlikely(!(gr_status & GR_READY)))
68968+ return 0;
68969+
68970+ if (current->acl->mode & GR_ATSECURE)
68971+ return 1;
68972+
68973+ return 0;
68974+}
68975+
68976+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68977+{
68978+ struct task_struct *task = current;
68979+ struct dentry *dentry = file->f_path.dentry;
68980+ struct vfsmount *mnt = file->f_path.mnt;
68981+ struct acl_object_label *obj, *tmp;
68982+ struct acl_subject_label *subj;
68983+ unsigned int bufsize;
68984+ int is_not_root;
68985+ char *path;
68986+ dev_t dev = __get_dev(dentry);
68987+
68988+ if (unlikely(!(gr_status & GR_READY)))
68989+ return 1;
68990+
68991+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68992+ return 1;
68993+
68994+ /* ignore Eric Biederman */
68995+ if (IS_PRIVATE(dentry->d_inode))
68996+ return 1;
68997+
68998+ subj = task->acl;
68999+ read_lock(&gr_inode_lock);
69000+ do {
69001+ obj = lookup_acl_obj_label(ino, dev, subj);
69002+ if (obj != NULL) {
69003+ read_unlock(&gr_inode_lock);
69004+ return (obj->mode & GR_FIND) ? 1 : 0;
69005+ }
69006+ } while ((subj = subj->parent_subject));
69007+ read_unlock(&gr_inode_lock);
69008+
69009+ /* this is purely an optimization since we're looking for an object
69010+ for the directory we're doing a readdir on
69011+ if it's possible for any globbed object to match the entry we're
69012+ filling into the directory, then the object we find here will be
69013+ an anchor point with attached globbed objects
69014+ */
69015+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69016+ if (obj->globbed == NULL)
69017+ return (obj->mode & GR_FIND) ? 1 : 0;
69018+
69019+ is_not_root = ((obj->filename[0] == '/') &&
69020+ (obj->filename[1] == '\0')) ? 0 : 1;
69021+ bufsize = PAGE_SIZE - namelen - is_not_root;
69022+
69023+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
69024+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69025+ return 1;
69026+
69027+ preempt_disable();
69028+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69029+ bufsize);
69030+
69031+ bufsize = strlen(path);
69032+
69033+ /* if base is "/", don't append an additional slash */
69034+ if (is_not_root)
69035+ *(path + bufsize) = '/';
69036+ memcpy(path + bufsize + is_not_root, name, namelen);
69037+ *(path + bufsize + namelen + is_not_root) = '\0';
69038+
69039+ tmp = obj->globbed;
69040+ while (tmp) {
69041+ if (!glob_match(tmp->filename, path)) {
69042+ preempt_enable();
69043+ return (tmp->mode & GR_FIND) ? 1 : 0;
69044+ }
69045+ tmp = tmp->next;
69046+ }
69047+ preempt_enable();
69048+ return (obj->mode & GR_FIND) ? 1 : 0;
69049+}
69050+
69051+void gr_put_exec_file(struct task_struct *task)
69052+{
69053+ struct file *filp;
69054+
69055+ write_lock(&grsec_exec_file_lock);
69056+ filp = task->exec_file;
69057+ task->exec_file = NULL;
69058+ write_unlock(&grsec_exec_file_lock);
69059+
69060+ if (filp)
69061+ fput(filp);
69062+
69063+ return;
69064+}
69065+
69066+
69067+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69068+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69069+#endif
69070+#ifdef CONFIG_SECURITY
69071+EXPORT_SYMBOL_GPL(gr_check_user_change);
69072+EXPORT_SYMBOL_GPL(gr_check_group_change);
69073+#endif
69074+
69075diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69076new file mode 100644
69077index 0000000..18ffbbd
69078--- /dev/null
69079+++ b/grsecurity/gracl_alloc.c
69080@@ -0,0 +1,105 @@
69081+#include <linux/kernel.h>
69082+#include <linux/mm.h>
69083+#include <linux/slab.h>
69084+#include <linux/vmalloc.h>
69085+#include <linux/gracl.h>
69086+#include <linux/grsecurity.h>
69087+
69088+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69089+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69090+
69091+static __inline__ int
69092+alloc_pop(void)
69093+{
69094+ if (current_alloc_state->alloc_stack_next == 1)
69095+ return 0;
69096+
69097+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69098+
69099+ current_alloc_state->alloc_stack_next--;
69100+
69101+ return 1;
69102+}
69103+
69104+static __inline__ int
69105+alloc_push(void *buf)
69106+{
69107+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69108+ return 1;
69109+
69110+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69111+
69112+ current_alloc_state->alloc_stack_next++;
69113+
69114+ return 0;
69115+}
69116+
69117+void *
69118+acl_alloc(unsigned long len)
69119+{
69120+ void *ret = NULL;
69121+
69122+ if (!len || len > PAGE_SIZE)
69123+ goto out;
69124+
69125+ ret = kmalloc(len, GFP_KERNEL);
69126+
69127+ if (ret) {
69128+ if (alloc_push(ret)) {
69129+ kfree(ret);
69130+ ret = NULL;
69131+ }
69132+ }
69133+
69134+out:
69135+ return ret;
69136+}
69137+
69138+void *
69139+acl_alloc_num(unsigned long num, unsigned long len)
69140+{
69141+ if (!len || (num > (PAGE_SIZE / len)))
69142+ return NULL;
69143+
69144+ return acl_alloc(num * len);
69145+}
69146+
69147+void
69148+acl_free_all(void)
69149+{
69150+ if (!current_alloc_state->alloc_stack)
69151+ return;
69152+
69153+ while (alloc_pop()) ;
69154+
69155+ if (current_alloc_state->alloc_stack) {
69156+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69157+ kfree(current_alloc_state->alloc_stack);
69158+ else
69159+ vfree(current_alloc_state->alloc_stack);
69160+ }
69161+
69162+ current_alloc_state->alloc_stack = NULL;
69163+ current_alloc_state->alloc_stack_size = 1;
69164+ current_alloc_state->alloc_stack_next = 1;
69165+
69166+ return;
69167+}
69168+
69169+int
69170+acl_alloc_stack_init(unsigned long size)
69171+{
69172+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69173+ current_alloc_state->alloc_stack =
69174+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69175+ else
69176+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69177+
69178+ current_alloc_state->alloc_stack_size = size;
69179+ current_alloc_state->alloc_stack_next = 1;
69180+
69181+ if (!current_alloc_state->alloc_stack)
69182+ return 0;
69183+ else
69184+ return 1;
69185+}
69186diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69187new file mode 100644
69188index 0000000..bdd51ea
69189--- /dev/null
69190+++ b/grsecurity/gracl_cap.c
69191@@ -0,0 +1,110 @@
69192+#include <linux/kernel.h>
69193+#include <linux/module.h>
69194+#include <linux/sched.h>
69195+#include <linux/gracl.h>
69196+#include <linux/grsecurity.h>
69197+#include <linux/grinternal.h>
69198+
69199+extern const char *captab_log[];
69200+extern int captab_log_entries;
69201+
69202+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69203+{
69204+ struct acl_subject_label *curracl;
69205+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69206+ kernel_cap_t cap_audit = __cap_empty_set;
69207+
69208+ if (!gr_acl_is_enabled())
69209+ return 1;
69210+
69211+ curracl = task->acl;
69212+
69213+ cap_drop = curracl->cap_lower;
69214+ cap_mask = curracl->cap_mask;
69215+ cap_audit = curracl->cap_invert_audit;
69216+
69217+ while ((curracl = curracl->parent_subject)) {
69218+ /* if the cap isn't specified in the current computed mask but is specified in the
69219+ current level subject, and is lowered in the current level subject, then add
69220+ it to the set of dropped capabilities
69221+ otherwise, add the current level subject's mask to the current computed mask
69222+ */
69223+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69224+ cap_raise(cap_mask, cap);
69225+ if (cap_raised(curracl->cap_lower, cap))
69226+ cap_raise(cap_drop, cap);
69227+ if (cap_raised(curracl->cap_invert_audit, cap))
69228+ cap_raise(cap_audit, cap);
69229+ }
69230+ }
69231+
69232+ if (!cap_raised(cap_drop, cap)) {
69233+ if (cap_raised(cap_audit, cap))
69234+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69235+ return 1;
69236+ }
69237+
69238+ curracl = task->acl;
69239+
69240+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69241+ && cap_raised(cred->cap_effective, cap)) {
69242+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69243+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69244+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69245+ gr_to_filename(task->exec_file->f_path.dentry,
69246+ task->exec_file->f_path.mnt) : curracl->filename,
69247+ curracl->filename, 0UL,
69248+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69249+ return 1;
69250+ }
69251+
69252+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69253+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69254+
69255+ return 0;
69256+}
69257+
69258+int
69259+gr_acl_is_capable(const int cap)
69260+{
69261+ return gr_task_acl_is_capable(current, current_cred(), cap);
69262+}
69263+
69264+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69265+{
69266+ struct acl_subject_label *curracl;
69267+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69268+
69269+ if (!gr_acl_is_enabled())
69270+ return 1;
69271+
69272+ curracl = task->acl;
69273+
69274+ cap_drop = curracl->cap_lower;
69275+ cap_mask = curracl->cap_mask;
69276+
69277+ while ((curracl = curracl->parent_subject)) {
69278+ /* if the cap isn't specified in the current computed mask but is specified in the
69279+ current level subject, and is lowered in the current level subject, then add
69280+ it to the set of dropped capabilities
69281+ otherwise, add the current level subject's mask to the current computed mask
69282+ */
69283+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69284+ cap_raise(cap_mask, cap);
69285+ if (cap_raised(curracl->cap_lower, cap))
69286+ cap_raise(cap_drop, cap);
69287+ }
69288+ }
69289+
69290+ if (!cap_raised(cap_drop, cap))
69291+ return 1;
69292+
69293+ return 0;
69294+}
69295+
69296+int
69297+gr_acl_is_capable_nolog(const int cap)
69298+{
69299+ return gr_task_acl_is_capable_nolog(current, cap);
69300+}
69301+
69302diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69303new file mode 100644
69304index 0000000..ca25605
69305--- /dev/null
69306+++ b/grsecurity/gracl_compat.c
69307@@ -0,0 +1,270 @@
69308+#include <linux/kernel.h>
69309+#include <linux/gracl.h>
69310+#include <linux/compat.h>
69311+#include <linux/gracl_compat.h>
69312+
69313+#include <asm/uaccess.h>
69314+
69315+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69316+{
69317+ struct gr_arg_wrapper_compat uwrapcompat;
69318+
69319+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69320+ return -EFAULT;
69321+
69322+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69323+ (uwrapcompat.version != 0x2901)) ||
69324+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69325+ return -EINVAL;
69326+
69327+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69328+ uwrap->version = uwrapcompat.version;
69329+ uwrap->size = sizeof(struct gr_arg);
69330+
69331+ return 0;
69332+}
69333+
69334+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69335+{
69336+ struct gr_arg_compat argcompat;
69337+
69338+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69339+ return -EFAULT;
69340+
69341+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69342+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69343+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69344+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69345+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69346+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69347+
69348+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69349+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69350+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69351+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69352+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69353+ arg->segv_device = argcompat.segv_device;
69354+ arg->segv_inode = argcompat.segv_inode;
69355+ arg->segv_uid = argcompat.segv_uid;
69356+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69357+ arg->mode = argcompat.mode;
69358+
69359+ return 0;
69360+}
69361+
69362+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69363+{
69364+ struct acl_object_label_compat objcompat;
69365+
69366+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69367+ return -EFAULT;
69368+
69369+ obj->filename = compat_ptr(objcompat.filename);
69370+ obj->inode = objcompat.inode;
69371+ obj->device = objcompat.device;
69372+ obj->mode = objcompat.mode;
69373+
69374+ obj->nested = compat_ptr(objcompat.nested);
69375+ obj->globbed = compat_ptr(objcompat.globbed);
69376+
69377+ obj->prev = compat_ptr(objcompat.prev);
69378+ obj->next = compat_ptr(objcompat.next);
69379+
69380+ return 0;
69381+}
69382+
69383+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69384+{
69385+ unsigned int i;
69386+ struct acl_subject_label_compat subjcompat;
69387+
69388+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69389+ return -EFAULT;
69390+
69391+ subj->filename = compat_ptr(subjcompat.filename);
69392+ subj->inode = subjcompat.inode;
69393+ subj->device = subjcompat.device;
69394+ subj->mode = subjcompat.mode;
69395+ subj->cap_mask = subjcompat.cap_mask;
69396+ subj->cap_lower = subjcompat.cap_lower;
69397+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69398+
69399+ for (i = 0; i < GR_NLIMITS; i++) {
69400+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69401+ subj->res[i].rlim_cur = RLIM_INFINITY;
69402+ else
69403+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69404+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69405+ subj->res[i].rlim_max = RLIM_INFINITY;
69406+ else
69407+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69408+ }
69409+ subj->resmask = subjcompat.resmask;
69410+
69411+ subj->user_trans_type = subjcompat.user_trans_type;
69412+ subj->group_trans_type = subjcompat.group_trans_type;
69413+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69414+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69415+ subj->user_trans_num = subjcompat.user_trans_num;
69416+ subj->group_trans_num = subjcompat.group_trans_num;
69417+
69418+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69419+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69420+ subj->ip_type = subjcompat.ip_type;
69421+ subj->ips = compat_ptr(subjcompat.ips);
69422+ subj->ip_num = subjcompat.ip_num;
69423+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69424+
69425+ subj->crashes = subjcompat.crashes;
69426+ subj->expires = subjcompat.expires;
69427+
69428+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69429+ subj->hash = compat_ptr(subjcompat.hash);
69430+ subj->prev = compat_ptr(subjcompat.prev);
69431+ subj->next = compat_ptr(subjcompat.next);
69432+
69433+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69434+ subj->obj_hash_size = subjcompat.obj_hash_size;
69435+ subj->pax_flags = subjcompat.pax_flags;
69436+
69437+ return 0;
69438+}
69439+
69440+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69441+{
69442+ struct acl_role_label_compat rolecompat;
69443+
69444+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69445+ return -EFAULT;
69446+
69447+ role->rolename = compat_ptr(rolecompat.rolename);
69448+ role->uidgid = rolecompat.uidgid;
69449+ role->roletype = rolecompat.roletype;
69450+
69451+ role->auth_attempts = rolecompat.auth_attempts;
69452+ role->expires = rolecompat.expires;
69453+
69454+ role->root_label = compat_ptr(rolecompat.root_label);
69455+ role->hash = compat_ptr(rolecompat.hash);
69456+
69457+ role->prev = compat_ptr(rolecompat.prev);
69458+ role->next = compat_ptr(rolecompat.next);
69459+
69460+ role->transitions = compat_ptr(rolecompat.transitions);
69461+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69462+ role->domain_children = compat_ptr(rolecompat.domain_children);
69463+ role->domain_child_num = rolecompat.domain_child_num;
69464+
69465+ role->umask = rolecompat.umask;
69466+
69467+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69468+ role->subj_hash_size = rolecompat.subj_hash_size;
69469+
69470+ return 0;
69471+}
69472+
69473+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69474+{
69475+ struct role_allowed_ip_compat roleip_compat;
69476+
69477+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69478+ return -EFAULT;
69479+
69480+ roleip->addr = roleip_compat.addr;
69481+ roleip->netmask = roleip_compat.netmask;
69482+
69483+ roleip->prev = compat_ptr(roleip_compat.prev);
69484+ roleip->next = compat_ptr(roleip_compat.next);
69485+
69486+ return 0;
69487+}
69488+
69489+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69490+{
69491+ struct role_transition_compat trans_compat;
69492+
69493+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69494+ return -EFAULT;
69495+
69496+ trans->rolename = compat_ptr(trans_compat.rolename);
69497+
69498+ trans->prev = compat_ptr(trans_compat.prev);
69499+ trans->next = compat_ptr(trans_compat.next);
69500+
69501+ return 0;
69502+
69503+}
69504+
69505+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69506+{
69507+ struct gr_hash_struct_compat hash_compat;
69508+
69509+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69510+ return -EFAULT;
69511+
69512+ hash->table = compat_ptr(hash_compat.table);
69513+ hash->nametable = compat_ptr(hash_compat.nametable);
69514+ hash->first = compat_ptr(hash_compat.first);
69515+
69516+ hash->table_size = hash_compat.table_size;
69517+ hash->used_size = hash_compat.used_size;
69518+
69519+ hash->type = hash_compat.type;
69520+
69521+ return 0;
69522+}
69523+
69524+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69525+{
69526+ compat_uptr_t ptrcompat;
69527+
69528+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69529+ return -EFAULT;
69530+
69531+ *(void **)ptr = compat_ptr(ptrcompat);
69532+
69533+ return 0;
69534+}
69535+
69536+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69537+{
69538+ struct acl_ip_label_compat ip_compat;
69539+
69540+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69541+ return -EFAULT;
69542+
69543+ ip->iface = compat_ptr(ip_compat.iface);
69544+ ip->addr = ip_compat.addr;
69545+ ip->netmask = ip_compat.netmask;
69546+ ip->low = ip_compat.low;
69547+ ip->high = ip_compat.high;
69548+ ip->mode = ip_compat.mode;
69549+ ip->type = ip_compat.type;
69550+
69551+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69552+
69553+ ip->prev = compat_ptr(ip_compat.prev);
69554+ ip->next = compat_ptr(ip_compat.next);
69555+
69556+ return 0;
69557+}
69558+
69559+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69560+{
69561+ struct sprole_pw_compat pw_compat;
69562+
69563+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69564+ return -EFAULT;
69565+
69566+ pw->rolename = compat_ptr(pw_compat.rolename);
69567+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69568+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69569+
69570+ return 0;
69571+}
69572+
69573+size_t get_gr_arg_wrapper_size_compat(void)
69574+{
69575+ return sizeof(struct gr_arg_wrapper_compat);
69576+}
69577+
69578diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69579new file mode 100644
69580index 0000000..a89b1f4
69581--- /dev/null
69582+++ b/grsecurity/gracl_fs.c
69583@@ -0,0 +1,437 @@
69584+#include <linux/kernel.h>
69585+#include <linux/sched.h>
69586+#include <linux/types.h>
69587+#include <linux/fs.h>
69588+#include <linux/file.h>
69589+#include <linux/stat.h>
69590+#include <linux/grsecurity.h>
69591+#include <linux/grinternal.h>
69592+#include <linux/gracl.h>
69593+
69594+umode_t
69595+gr_acl_umask(void)
69596+{
69597+ if (unlikely(!gr_acl_is_enabled()))
69598+ return 0;
69599+
69600+ return current->role->umask;
69601+}
69602+
69603+__u32
69604+gr_acl_handle_hidden_file(const struct dentry * dentry,
69605+ const struct vfsmount * mnt)
69606+{
69607+ __u32 mode;
69608+
69609+ if (unlikely(d_is_negative(dentry)))
69610+ return GR_FIND;
69611+
69612+ mode =
69613+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69614+
69615+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69616+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69617+ return mode;
69618+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69619+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69620+ return 0;
69621+ } else if (unlikely(!(mode & GR_FIND)))
69622+ return 0;
69623+
69624+ return GR_FIND;
69625+}
69626+
69627+__u32
69628+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69629+ int acc_mode)
69630+{
69631+ __u32 reqmode = GR_FIND;
69632+ __u32 mode;
69633+
69634+ if (unlikely(d_is_negative(dentry)))
69635+ return reqmode;
69636+
69637+ if (acc_mode & MAY_APPEND)
69638+ reqmode |= GR_APPEND;
69639+ else if (acc_mode & MAY_WRITE)
69640+ reqmode |= GR_WRITE;
69641+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69642+ reqmode |= GR_READ;
69643+
69644+ mode =
69645+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69646+ mnt);
69647+
69648+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69649+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69650+ reqmode & GR_READ ? " reading" : "",
69651+ reqmode & GR_WRITE ? " writing" : reqmode &
69652+ GR_APPEND ? " appending" : "");
69653+ return reqmode;
69654+ } else
69655+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69656+ {
69657+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69658+ reqmode & GR_READ ? " reading" : "",
69659+ reqmode & GR_WRITE ? " writing" : reqmode &
69660+ GR_APPEND ? " appending" : "");
69661+ return 0;
69662+ } else if (unlikely((mode & reqmode) != reqmode))
69663+ return 0;
69664+
69665+ return reqmode;
69666+}
69667+
69668+__u32
69669+gr_acl_handle_creat(const struct dentry * dentry,
69670+ const struct dentry * p_dentry,
69671+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69672+ const int imode)
69673+{
69674+ __u32 reqmode = GR_WRITE | GR_CREATE;
69675+ __u32 mode;
69676+
69677+ if (acc_mode & MAY_APPEND)
69678+ reqmode |= GR_APPEND;
69679+ // if a directory was required or the directory already exists, then
69680+ // don't count this open as a read
69681+ if ((acc_mode & MAY_READ) &&
69682+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69683+ reqmode |= GR_READ;
69684+ if ((open_flags & O_CREAT) &&
69685+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69686+ reqmode |= GR_SETID;
69687+
69688+ mode =
69689+ gr_check_create(dentry, p_dentry, p_mnt,
69690+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69691+
69692+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69693+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69694+ reqmode & GR_READ ? " reading" : "",
69695+ reqmode & GR_WRITE ? " writing" : reqmode &
69696+ GR_APPEND ? " appending" : "");
69697+ return reqmode;
69698+ } else
69699+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69700+ {
69701+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69702+ reqmode & GR_READ ? " reading" : "",
69703+ reqmode & GR_WRITE ? " writing" : reqmode &
69704+ GR_APPEND ? " appending" : "");
69705+ return 0;
69706+ } else if (unlikely((mode & reqmode) != reqmode))
69707+ return 0;
69708+
69709+ return reqmode;
69710+}
69711+
69712+__u32
69713+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69714+ const int fmode)
69715+{
69716+ __u32 mode, reqmode = GR_FIND;
69717+
69718+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69719+ reqmode |= GR_EXEC;
69720+ if (fmode & S_IWOTH)
69721+ reqmode |= GR_WRITE;
69722+ if (fmode & S_IROTH)
69723+ reqmode |= GR_READ;
69724+
69725+ mode =
69726+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69727+ mnt);
69728+
69729+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69730+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69731+ reqmode & GR_READ ? " reading" : "",
69732+ reqmode & GR_WRITE ? " writing" : "",
69733+ reqmode & GR_EXEC ? " executing" : "");
69734+ return reqmode;
69735+ } else
69736+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69737+ {
69738+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69739+ reqmode & GR_READ ? " reading" : "",
69740+ reqmode & GR_WRITE ? " writing" : "",
69741+ reqmode & GR_EXEC ? " executing" : "");
69742+ return 0;
69743+ } else if (unlikely((mode & reqmode) != reqmode))
69744+ return 0;
69745+
69746+ return reqmode;
69747+}
69748+
69749+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69750+{
69751+ __u32 mode;
69752+
69753+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69754+
69755+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69756+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69757+ return mode;
69758+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69759+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69760+ return 0;
69761+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69762+ return 0;
69763+
69764+ return (reqmode);
69765+}
69766+
69767+__u32
69768+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69769+{
69770+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69771+}
69772+
69773+__u32
69774+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69775+{
69776+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69777+}
69778+
69779+__u32
69780+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69781+{
69782+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69783+}
69784+
69785+__u32
69786+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69787+{
69788+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69789+}
69790+
69791+__u32
69792+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69793+ umode_t *modeptr)
69794+{
69795+ umode_t mode;
69796+
69797+ *modeptr &= ~gr_acl_umask();
69798+ mode = *modeptr;
69799+
69800+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69801+ return 1;
69802+
69803+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69804+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69805+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69806+ GR_CHMOD_ACL_MSG);
69807+ } else {
69808+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69809+ }
69810+}
69811+
69812+__u32
69813+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69814+{
69815+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69816+}
69817+
69818+__u32
69819+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69820+{
69821+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69822+}
69823+
69824+__u32
69825+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69826+{
69827+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69828+}
69829+
69830+__u32
69831+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69832+{
69833+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69834+}
69835+
69836+__u32
69837+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69838+{
69839+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69840+ GR_UNIXCONNECT_ACL_MSG);
69841+}
69842+
69843+/* hardlinks require at minimum create and link permission,
69844+ any additional privilege required is based on the
69845+ privilege of the file being linked to
69846+*/
69847+__u32
69848+gr_acl_handle_link(const struct dentry * new_dentry,
69849+ const struct dentry * parent_dentry,
69850+ const struct vfsmount * parent_mnt,
69851+ const struct dentry * old_dentry,
69852+ const struct vfsmount * old_mnt, const struct filename *to)
69853+{
69854+ __u32 mode;
69855+ __u32 needmode = GR_CREATE | GR_LINK;
69856+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69857+
69858+ mode =
69859+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69860+ old_mnt);
69861+
69862+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69863+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69864+ return mode;
69865+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69866+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69867+ return 0;
69868+ } else if (unlikely((mode & needmode) != needmode))
69869+ return 0;
69870+
69871+ return 1;
69872+}
69873+
69874+__u32
69875+gr_acl_handle_symlink(const struct dentry * new_dentry,
69876+ const struct dentry * parent_dentry,
69877+ const struct vfsmount * parent_mnt, const struct filename *from)
69878+{
69879+ __u32 needmode = GR_WRITE | GR_CREATE;
69880+ __u32 mode;
69881+
69882+ mode =
69883+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
69884+ GR_CREATE | GR_AUDIT_CREATE |
69885+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69886+
69887+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69888+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69889+ return mode;
69890+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69891+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69892+ return 0;
69893+ } else if (unlikely((mode & needmode) != needmode))
69894+ return 0;
69895+
69896+ return (GR_WRITE | GR_CREATE);
69897+}
69898+
69899+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)
69900+{
69901+ __u32 mode;
69902+
69903+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69904+
69905+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69906+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69907+ return mode;
69908+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69909+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69910+ return 0;
69911+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69912+ return 0;
69913+
69914+ return (reqmode);
69915+}
69916+
69917+__u32
69918+gr_acl_handle_mknod(const struct dentry * new_dentry,
69919+ const struct dentry * parent_dentry,
69920+ const struct vfsmount * parent_mnt,
69921+ const int mode)
69922+{
69923+ __u32 reqmode = GR_WRITE | GR_CREATE;
69924+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69925+ reqmode |= GR_SETID;
69926+
69927+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69928+ reqmode, GR_MKNOD_ACL_MSG);
69929+}
69930+
69931+__u32
69932+gr_acl_handle_mkdir(const struct dentry *new_dentry,
69933+ const struct dentry *parent_dentry,
69934+ const struct vfsmount *parent_mnt)
69935+{
69936+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69937+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69938+}
69939+
69940+#define RENAME_CHECK_SUCCESS(old, new) \
69941+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69942+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69943+
69944+int
69945+gr_acl_handle_rename(struct dentry *new_dentry,
69946+ struct dentry *parent_dentry,
69947+ const struct vfsmount *parent_mnt,
69948+ struct dentry *old_dentry,
69949+ struct inode *old_parent_inode,
69950+ struct vfsmount *old_mnt, const struct filename *newname)
69951+{
69952+ __u32 comp1, comp2;
69953+ int error = 0;
69954+
69955+ if (unlikely(!gr_acl_is_enabled()))
69956+ return 0;
69957+
69958+ if (d_is_negative(new_dentry)) {
69959+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69960+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69961+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69962+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69963+ GR_DELETE | GR_AUDIT_DELETE |
69964+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69965+ GR_SUPPRESS, old_mnt);
69966+ } else {
69967+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69968+ GR_CREATE | GR_DELETE |
69969+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69970+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69971+ GR_SUPPRESS, parent_mnt);
69972+ comp2 =
69973+ gr_search_file(old_dentry,
69974+ GR_READ | GR_WRITE | GR_AUDIT_READ |
69975+ GR_DELETE | GR_AUDIT_DELETE |
69976+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69977+ }
69978+
69979+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69980+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69981+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69982+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69983+ && !(comp2 & GR_SUPPRESS)) {
69984+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69985+ error = -EACCES;
69986+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69987+ error = -EACCES;
69988+
69989+ return error;
69990+}
69991+
69992+void
69993+gr_acl_handle_exit(void)
69994+{
69995+ u16 id;
69996+ char *rolename;
69997+
69998+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69999+ !(current->role->roletype & GR_ROLE_PERSIST))) {
70000+ id = current->acl_role_id;
70001+ rolename = current->role->rolename;
70002+ gr_set_acls(1);
70003+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70004+ }
70005+
70006+ gr_put_exec_file(current);
70007+ return;
70008+}
70009+
70010+int
70011+gr_acl_handle_procpidmem(const struct task_struct *task)
70012+{
70013+ if (unlikely(!gr_acl_is_enabled()))
70014+ return 0;
70015+
70016+ if (task != current && task->acl->mode & GR_PROTPROCFD)
70017+ return -EACCES;
70018+
70019+ return 0;
70020+}
70021diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70022new file mode 100644
70023index 0000000..f056b81
70024--- /dev/null
70025+++ b/grsecurity/gracl_ip.c
70026@@ -0,0 +1,386 @@
70027+#include <linux/kernel.h>
70028+#include <asm/uaccess.h>
70029+#include <asm/errno.h>
70030+#include <net/sock.h>
70031+#include <linux/file.h>
70032+#include <linux/fs.h>
70033+#include <linux/net.h>
70034+#include <linux/in.h>
70035+#include <linux/skbuff.h>
70036+#include <linux/ip.h>
70037+#include <linux/udp.h>
70038+#include <linux/types.h>
70039+#include <linux/sched.h>
70040+#include <linux/netdevice.h>
70041+#include <linux/inetdevice.h>
70042+#include <linux/gracl.h>
70043+#include <linux/grsecurity.h>
70044+#include <linux/grinternal.h>
70045+
70046+#define GR_BIND 0x01
70047+#define GR_CONNECT 0x02
70048+#define GR_INVERT 0x04
70049+#define GR_BINDOVERRIDE 0x08
70050+#define GR_CONNECTOVERRIDE 0x10
70051+#define GR_SOCK_FAMILY 0x20
70052+
70053+static const char * gr_protocols[IPPROTO_MAX] = {
70054+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70055+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70056+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70057+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70058+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70059+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70060+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70061+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70062+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70063+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70064+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70065+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70066+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70067+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70068+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70069+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70070+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70071+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70072+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70073+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70074+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70075+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70076+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70077+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70078+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70079+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70080+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70081+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70082+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70083+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70084+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70085+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70086+ };
70087+
70088+static const char * gr_socktypes[SOCK_MAX] = {
70089+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70090+ "unknown:7", "unknown:8", "unknown:9", "packet"
70091+ };
70092+
70093+static const char * gr_sockfamilies[AF_MAX+1] = {
70094+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70095+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70096+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70097+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70098+ };
70099+
70100+const char *
70101+gr_proto_to_name(unsigned char proto)
70102+{
70103+ return gr_protocols[proto];
70104+}
70105+
70106+const char *
70107+gr_socktype_to_name(unsigned char type)
70108+{
70109+ return gr_socktypes[type];
70110+}
70111+
70112+const char *
70113+gr_sockfamily_to_name(unsigned char family)
70114+{
70115+ return gr_sockfamilies[family];
70116+}
70117+
70118+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70119+
70120+int
70121+gr_search_socket(const int domain, const int type, const int protocol)
70122+{
70123+ struct acl_subject_label *curr;
70124+ const struct cred *cred = current_cred();
70125+
70126+ if (unlikely(!gr_acl_is_enabled()))
70127+ goto exit;
70128+
70129+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70130+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70131+ goto exit; // let the kernel handle it
70132+
70133+ curr = current->acl;
70134+
70135+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70136+ /* the family is allowed, if this is PF_INET allow it only if
70137+ the extra sock type/protocol checks pass */
70138+ if (domain == PF_INET)
70139+ goto inet_check;
70140+ goto exit;
70141+ } else {
70142+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70143+ __u32 fakeip = 0;
70144+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70145+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70146+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70147+ gr_to_filename(current->exec_file->f_path.dentry,
70148+ current->exec_file->f_path.mnt) :
70149+ curr->filename, curr->filename,
70150+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70151+ &current->signal->saved_ip);
70152+ goto exit;
70153+ }
70154+ goto exit_fail;
70155+ }
70156+
70157+inet_check:
70158+ /* the rest of this checking is for IPv4 only */
70159+ if (!curr->ips)
70160+ goto exit;
70161+
70162+ if ((curr->ip_type & (1U << type)) &&
70163+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70164+ goto exit;
70165+
70166+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70167+ /* we don't place acls on raw sockets , and sometimes
70168+ dgram/ip sockets are opened for ioctl and not
70169+ bind/connect, so we'll fake a bind learn log */
70170+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70171+ __u32 fakeip = 0;
70172+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70173+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70174+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70175+ gr_to_filename(current->exec_file->f_path.dentry,
70176+ current->exec_file->f_path.mnt) :
70177+ curr->filename, curr->filename,
70178+ &fakeip, 0, type,
70179+ protocol, GR_CONNECT, &current->signal->saved_ip);
70180+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70181+ __u32 fakeip = 0;
70182+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70183+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70184+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70185+ gr_to_filename(current->exec_file->f_path.dentry,
70186+ current->exec_file->f_path.mnt) :
70187+ curr->filename, curr->filename,
70188+ &fakeip, 0, type,
70189+ protocol, GR_BIND, &current->signal->saved_ip);
70190+ }
70191+ /* we'll log when they use connect or bind */
70192+ goto exit;
70193+ }
70194+
70195+exit_fail:
70196+ if (domain == PF_INET)
70197+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70198+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70199+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70200+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70201+ gr_socktype_to_name(type), protocol);
70202+
70203+ return 0;
70204+exit:
70205+ return 1;
70206+}
70207+
70208+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)
70209+{
70210+ if ((ip->mode & mode) &&
70211+ (ip_port >= ip->low) &&
70212+ (ip_port <= ip->high) &&
70213+ ((ntohl(ip_addr) & our_netmask) ==
70214+ (ntohl(our_addr) & our_netmask))
70215+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70216+ && (ip->type & (1U << type))) {
70217+ if (ip->mode & GR_INVERT)
70218+ return 2; // specifically denied
70219+ else
70220+ return 1; // allowed
70221+ }
70222+
70223+ return 0; // not specifically allowed, may continue parsing
70224+}
70225+
70226+static int
70227+gr_search_connectbind(const int full_mode, struct sock *sk,
70228+ struct sockaddr_in *addr, const int type)
70229+{
70230+ char iface[IFNAMSIZ] = {0};
70231+ struct acl_subject_label *curr;
70232+ struct acl_ip_label *ip;
70233+ struct inet_sock *isk;
70234+ struct net_device *dev;
70235+ struct in_device *idev;
70236+ unsigned long i;
70237+ int ret;
70238+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70239+ __u32 ip_addr = 0;
70240+ __u32 our_addr;
70241+ __u32 our_netmask;
70242+ char *p;
70243+ __u16 ip_port = 0;
70244+ const struct cred *cred = current_cred();
70245+
70246+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70247+ return 0;
70248+
70249+ curr = current->acl;
70250+ isk = inet_sk(sk);
70251+
70252+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70253+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70254+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70255+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70256+ struct sockaddr_in saddr;
70257+ int err;
70258+
70259+ saddr.sin_family = AF_INET;
70260+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70261+ saddr.sin_port = isk->inet_sport;
70262+
70263+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70264+ if (err)
70265+ return err;
70266+
70267+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70268+ if (err)
70269+ return err;
70270+ }
70271+
70272+ if (!curr->ips)
70273+ return 0;
70274+
70275+ ip_addr = addr->sin_addr.s_addr;
70276+ ip_port = ntohs(addr->sin_port);
70277+
70278+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70279+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70280+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70281+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70282+ gr_to_filename(current->exec_file->f_path.dentry,
70283+ current->exec_file->f_path.mnt) :
70284+ curr->filename, curr->filename,
70285+ &ip_addr, ip_port, type,
70286+ sk->sk_protocol, mode, &current->signal->saved_ip);
70287+ return 0;
70288+ }
70289+
70290+ for (i = 0; i < curr->ip_num; i++) {
70291+ ip = *(curr->ips + i);
70292+ if (ip->iface != NULL) {
70293+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70294+ p = strchr(iface, ':');
70295+ if (p != NULL)
70296+ *p = '\0';
70297+ dev = dev_get_by_name(sock_net(sk), iface);
70298+ if (dev == NULL)
70299+ continue;
70300+ idev = in_dev_get(dev);
70301+ if (idev == NULL) {
70302+ dev_put(dev);
70303+ continue;
70304+ }
70305+ rcu_read_lock();
70306+ for_ifa(idev) {
70307+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70308+ our_addr = ifa->ifa_address;
70309+ our_netmask = 0xffffffff;
70310+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70311+ if (ret == 1) {
70312+ rcu_read_unlock();
70313+ in_dev_put(idev);
70314+ dev_put(dev);
70315+ return 0;
70316+ } else if (ret == 2) {
70317+ rcu_read_unlock();
70318+ in_dev_put(idev);
70319+ dev_put(dev);
70320+ goto denied;
70321+ }
70322+ }
70323+ } endfor_ifa(idev);
70324+ rcu_read_unlock();
70325+ in_dev_put(idev);
70326+ dev_put(dev);
70327+ } else {
70328+ our_addr = ip->addr;
70329+ our_netmask = ip->netmask;
70330+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70331+ if (ret == 1)
70332+ return 0;
70333+ else if (ret == 2)
70334+ goto denied;
70335+ }
70336+ }
70337+
70338+denied:
70339+ if (mode == GR_BIND)
70340+ 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));
70341+ else if (mode == GR_CONNECT)
70342+ 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));
70343+
70344+ return -EACCES;
70345+}
70346+
70347+int
70348+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70349+{
70350+ /* always allow disconnection of dgram sockets with connect */
70351+ if (addr->sin_family == AF_UNSPEC)
70352+ return 0;
70353+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70354+}
70355+
70356+int
70357+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70358+{
70359+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70360+}
70361+
70362+int gr_search_listen(struct socket *sock)
70363+{
70364+ struct sock *sk = sock->sk;
70365+ struct sockaddr_in addr;
70366+
70367+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70368+ addr.sin_port = inet_sk(sk)->inet_sport;
70369+
70370+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70371+}
70372+
70373+int gr_search_accept(struct socket *sock)
70374+{
70375+ struct sock *sk = sock->sk;
70376+ struct sockaddr_in addr;
70377+
70378+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70379+ addr.sin_port = inet_sk(sk)->inet_sport;
70380+
70381+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70382+}
70383+
70384+int
70385+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70386+{
70387+ if (addr)
70388+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70389+ else {
70390+ struct sockaddr_in sin;
70391+ const struct inet_sock *inet = inet_sk(sk);
70392+
70393+ sin.sin_addr.s_addr = inet->inet_daddr;
70394+ sin.sin_port = inet->inet_dport;
70395+
70396+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70397+ }
70398+}
70399+
70400+int
70401+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70402+{
70403+ struct sockaddr_in sin;
70404+
70405+ if (unlikely(skb->len < sizeof (struct udphdr)))
70406+ return 0; // skip this packet
70407+
70408+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70409+ sin.sin_port = udp_hdr(skb)->source;
70410+
70411+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70412+}
70413diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70414new file mode 100644
70415index 0000000..25f54ef
70416--- /dev/null
70417+++ b/grsecurity/gracl_learn.c
70418@@ -0,0 +1,207 @@
70419+#include <linux/kernel.h>
70420+#include <linux/mm.h>
70421+#include <linux/sched.h>
70422+#include <linux/poll.h>
70423+#include <linux/string.h>
70424+#include <linux/file.h>
70425+#include <linux/types.h>
70426+#include <linux/vmalloc.h>
70427+#include <linux/grinternal.h>
70428+
70429+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70430+ size_t count, loff_t *ppos);
70431+extern int gr_acl_is_enabled(void);
70432+
70433+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70434+static int gr_learn_attached;
70435+
70436+/* use a 512k buffer */
70437+#define LEARN_BUFFER_SIZE (512 * 1024)
70438+
70439+static DEFINE_SPINLOCK(gr_learn_lock);
70440+static DEFINE_MUTEX(gr_learn_user_mutex);
70441+
70442+/* we need to maintain two buffers, so that the kernel context of grlearn
70443+ uses a semaphore around the userspace copying, and the other kernel contexts
70444+ use a spinlock when copying into the buffer, since they cannot sleep
70445+*/
70446+static char *learn_buffer;
70447+static char *learn_buffer_user;
70448+static int learn_buffer_len;
70449+static int learn_buffer_user_len;
70450+
70451+static ssize_t
70452+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70453+{
70454+ DECLARE_WAITQUEUE(wait, current);
70455+ ssize_t retval = 0;
70456+
70457+ add_wait_queue(&learn_wait, &wait);
70458+ set_current_state(TASK_INTERRUPTIBLE);
70459+ do {
70460+ mutex_lock(&gr_learn_user_mutex);
70461+ spin_lock(&gr_learn_lock);
70462+ if (learn_buffer_len)
70463+ break;
70464+ spin_unlock(&gr_learn_lock);
70465+ mutex_unlock(&gr_learn_user_mutex);
70466+ if (file->f_flags & O_NONBLOCK) {
70467+ retval = -EAGAIN;
70468+ goto out;
70469+ }
70470+ if (signal_pending(current)) {
70471+ retval = -ERESTARTSYS;
70472+ goto out;
70473+ }
70474+
70475+ schedule();
70476+ } while (1);
70477+
70478+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70479+ learn_buffer_user_len = learn_buffer_len;
70480+ retval = learn_buffer_len;
70481+ learn_buffer_len = 0;
70482+
70483+ spin_unlock(&gr_learn_lock);
70484+
70485+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70486+ retval = -EFAULT;
70487+
70488+ mutex_unlock(&gr_learn_user_mutex);
70489+out:
70490+ set_current_state(TASK_RUNNING);
70491+ remove_wait_queue(&learn_wait, &wait);
70492+ return retval;
70493+}
70494+
70495+static unsigned int
70496+poll_learn(struct file * file, poll_table * wait)
70497+{
70498+ poll_wait(file, &learn_wait, wait);
70499+
70500+ if (learn_buffer_len)
70501+ return (POLLIN | POLLRDNORM);
70502+
70503+ return 0;
70504+}
70505+
70506+void
70507+gr_clear_learn_entries(void)
70508+{
70509+ char *tmp;
70510+
70511+ mutex_lock(&gr_learn_user_mutex);
70512+ spin_lock(&gr_learn_lock);
70513+ tmp = learn_buffer;
70514+ learn_buffer = NULL;
70515+ spin_unlock(&gr_learn_lock);
70516+ if (tmp)
70517+ vfree(tmp);
70518+ if (learn_buffer_user != NULL) {
70519+ vfree(learn_buffer_user);
70520+ learn_buffer_user = NULL;
70521+ }
70522+ learn_buffer_len = 0;
70523+ mutex_unlock(&gr_learn_user_mutex);
70524+
70525+ return;
70526+}
70527+
70528+void
70529+gr_add_learn_entry(const char *fmt, ...)
70530+{
70531+ va_list args;
70532+ unsigned int len;
70533+
70534+ if (!gr_learn_attached)
70535+ return;
70536+
70537+ spin_lock(&gr_learn_lock);
70538+
70539+ /* leave a gap at the end so we know when it's "full" but don't have to
70540+ compute the exact length of the string we're trying to append
70541+ */
70542+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70543+ spin_unlock(&gr_learn_lock);
70544+ wake_up_interruptible(&learn_wait);
70545+ return;
70546+ }
70547+ if (learn_buffer == NULL) {
70548+ spin_unlock(&gr_learn_lock);
70549+ return;
70550+ }
70551+
70552+ va_start(args, fmt);
70553+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70554+ va_end(args);
70555+
70556+ learn_buffer_len += len + 1;
70557+
70558+ spin_unlock(&gr_learn_lock);
70559+ wake_up_interruptible(&learn_wait);
70560+
70561+ return;
70562+}
70563+
70564+static int
70565+open_learn(struct inode *inode, struct file *file)
70566+{
70567+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70568+ return -EBUSY;
70569+ if (file->f_mode & FMODE_READ) {
70570+ int retval = 0;
70571+ mutex_lock(&gr_learn_user_mutex);
70572+ if (learn_buffer == NULL)
70573+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70574+ if (learn_buffer_user == NULL)
70575+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70576+ if (learn_buffer == NULL) {
70577+ retval = -ENOMEM;
70578+ goto out_error;
70579+ }
70580+ if (learn_buffer_user == NULL) {
70581+ retval = -ENOMEM;
70582+ goto out_error;
70583+ }
70584+ learn_buffer_len = 0;
70585+ learn_buffer_user_len = 0;
70586+ gr_learn_attached = 1;
70587+out_error:
70588+ mutex_unlock(&gr_learn_user_mutex);
70589+ return retval;
70590+ }
70591+ return 0;
70592+}
70593+
70594+static int
70595+close_learn(struct inode *inode, struct file *file)
70596+{
70597+ if (file->f_mode & FMODE_READ) {
70598+ char *tmp = NULL;
70599+ mutex_lock(&gr_learn_user_mutex);
70600+ spin_lock(&gr_learn_lock);
70601+ tmp = learn_buffer;
70602+ learn_buffer = NULL;
70603+ spin_unlock(&gr_learn_lock);
70604+ if (tmp)
70605+ vfree(tmp);
70606+ if (learn_buffer_user != NULL) {
70607+ vfree(learn_buffer_user);
70608+ learn_buffer_user = NULL;
70609+ }
70610+ learn_buffer_len = 0;
70611+ learn_buffer_user_len = 0;
70612+ gr_learn_attached = 0;
70613+ mutex_unlock(&gr_learn_user_mutex);
70614+ }
70615+
70616+ return 0;
70617+}
70618+
70619+const struct file_operations grsec_fops = {
70620+ .read = read_learn,
70621+ .write = write_grsec_handler,
70622+ .open = open_learn,
70623+ .release = close_learn,
70624+ .poll = poll_learn,
70625+};
70626diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70627new file mode 100644
70628index 0000000..361a099
70629--- /dev/null
70630+++ b/grsecurity/gracl_policy.c
70631@@ -0,0 +1,1782 @@
70632+#include <linux/kernel.h>
70633+#include <linux/module.h>
70634+#include <linux/sched.h>
70635+#include <linux/mm.h>
70636+#include <linux/file.h>
70637+#include <linux/fs.h>
70638+#include <linux/namei.h>
70639+#include <linux/mount.h>
70640+#include <linux/tty.h>
70641+#include <linux/proc_fs.h>
70642+#include <linux/lglock.h>
70643+#include <linux/slab.h>
70644+#include <linux/vmalloc.h>
70645+#include <linux/types.h>
70646+#include <linux/sysctl.h>
70647+#include <linux/netdevice.h>
70648+#include <linux/ptrace.h>
70649+#include <linux/gracl.h>
70650+#include <linux/gralloc.h>
70651+#include <linux/security.h>
70652+#include <linux/grinternal.h>
70653+#include <linux/pid_namespace.h>
70654+#include <linux/stop_machine.h>
70655+#include <linux/fdtable.h>
70656+#include <linux/percpu.h>
70657+#include <linux/lglock.h>
70658+#include <linux/hugetlb.h>
70659+#include <linux/posix-timers.h>
70660+#include "../fs/mount.h"
70661+
70662+#include <asm/uaccess.h>
70663+#include <asm/errno.h>
70664+#include <asm/mman.h>
70665+
70666+extern struct gr_policy_state *polstate;
70667+
70668+#define FOR_EACH_ROLE_START(role) \
70669+ role = polstate->role_list; \
70670+ while (role) {
70671+
70672+#define FOR_EACH_ROLE_END(role) \
70673+ role = role->prev; \
70674+ }
70675+
70676+struct path gr_real_root;
70677+
70678+extern struct gr_alloc_state *current_alloc_state;
70679+
70680+u16 acl_sp_role_value;
70681+
70682+static DEFINE_MUTEX(gr_dev_mutex);
70683+
70684+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70685+extern void gr_clear_learn_entries(void);
70686+
70687+static struct gr_arg gr_usermode;
70688+static unsigned char gr_system_salt[GR_SALT_LEN];
70689+static unsigned char gr_system_sum[GR_SHA_LEN];
70690+
70691+static unsigned int gr_auth_attempts = 0;
70692+static unsigned long gr_auth_expires = 0UL;
70693+
70694+struct acl_object_label *fakefs_obj_rw;
70695+struct acl_object_label *fakefs_obj_rwx;
70696+
70697+extern int gr_init_uidset(void);
70698+extern void gr_free_uidset(void);
70699+extern void gr_remove_uid(uid_t uid);
70700+extern int gr_find_uid(uid_t uid);
70701+
70702+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70703+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70704+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70705+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70706+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);
70707+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70708+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70709+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70710+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70711+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70712+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70713+extern void assign_special_role(const char *rolename);
70714+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70715+extern int gr_rbac_disable(void *unused);
70716+extern void gr_enable_rbac_system(void);
70717+
70718+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70719+{
70720+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70721+ return -EFAULT;
70722+
70723+ return 0;
70724+}
70725+
70726+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70727+{
70728+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70729+ return -EFAULT;
70730+
70731+ return 0;
70732+}
70733+
70734+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70735+{
70736+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70737+ return -EFAULT;
70738+
70739+ return 0;
70740+}
70741+
70742+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70743+{
70744+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70745+ return -EFAULT;
70746+
70747+ return 0;
70748+}
70749+
70750+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70751+{
70752+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70753+ return -EFAULT;
70754+
70755+ return 0;
70756+}
70757+
70758+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70759+{
70760+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70761+ return -EFAULT;
70762+
70763+ return 0;
70764+}
70765+
70766+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70767+{
70768+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70769+ return -EFAULT;
70770+
70771+ return 0;
70772+}
70773+
70774+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70775+{
70776+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70777+ return -EFAULT;
70778+
70779+ return 0;
70780+}
70781+
70782+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70783+{
70784+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70785+ return -EFAULT;
70786+
70787+ return 0;
70788+}
70789+
70790+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70791+{
70792+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70793+ return -EFAULT;
70794+
70795+ if (((uwrap->version != GRSECURITY_VERSION) &&
70796+ (uwrap->version != 0x2901)) ||
70797+ (uwrap->size != sizeof(struct gr_arg)))
70798+ return -EINVAL;
70799+
70800+ return 0;
70801+}
70802+
70803+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70804+{
70805+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70806+ return -EFAULT;
70807+
70808+ return 0;
70809+}
70810+
70811+static size_t get_gr_arg_wrapper_size_normal(void)
70812+{
70813+ return sizeof(struct gr_arg_wrapper);
70814+}
70815+
70816+#ifdef CONFIG_COMPAT
70817+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70818+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70819+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70820+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70821+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70822+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70823+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70824+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70825+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70826+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70827+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70828+extern size_t get_gr_arg_wrapper_size_compat(void);
70829+
70830+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70831+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70832+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70833+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70834+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70835+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70836+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70837+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70838+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70839+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70840+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70841+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70842+
70843+#else
70844+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70845+#define copy_gr_arg copy_gr_arg_normal
70846+#define copy_gr_hash_struct copy_gr_hash_struct_normal
70847+#define copy_acl_object_label copy_acl_object_label_normal
70848+#define copy_acl_subject_label copy_acl_subject_label_normal
70849+#define copy_acl_role_label copy_acl_role_label_normal
70850+#define copy_acl_ip_label copy_acl_ip_label_normal
70851+#define copy_pointer_from_array copy_pointer_from_array_normal
70852+#define copy_sprole_pw copy_sprole_pw_normal
70853+#define copy_role_transition copy_role_transition_normal
70854+#define copy_role_allowed_ip copy_role_allowed_ip_normal
70855+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70856+#endif
70857+
70858+static struct acl_subject_label *
70859+lookup_subject_map(const struct acl_subject_label *userp)
70860+{
70861+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70862+ struct subject_map *match;
70863+
70864+ match = polstate->subj_map_set.s_hash[index];
70865+
70866+ while (match && match->user != userp)
70867+ match = match->next;
70868+
70869+ if (match != NULL)
70870+ return match->kernel;
70871+ else
70872+ return NULL;
70873+}
70874+
70875+static void
70876+insert_subj_map_entry(struct subject_map *subjmap)
70877+{
70878+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70879+ struct subject_map **curr;
70880+
70881+ subjmap->prev = NULL;
70882+
70883+ curr = &polstate->subj_map_set.s_hash[index];
70884+ if (*curr != NULL)
70885+ (*curr)->prev = subjmap;
70886+
70887+ subjmap->next = *curr;
70888+ *curr = subjmap;
70889+
70890+ return;
70891+}
70892+
70893+static void
70894+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70895+{
70896+ unsigned int index =
70897+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70898+ struct acl_role_label **curr;
70899+ struct acl_role_label *tmp, *tmp2;
70900+
70901+ curr = &polstate->acl_role_set.r_hash[index];
70902+
70903+ /* simple case, slot is empty, just set it to our role */
70904+ if (*curr == NULL) {
70905+ *curr = role;
70906+ } else {
70907+ /* example:
70908+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
70909+ 2 -> 3
70910+ */
70911+ /* first check to see if we can already be reached via this slot */
70912+ tmp = *curr;
70913+ while (tmp && tmp != role)
70914+ tmp = tmp->next;
70915+ if (tmp == role) {
70916+ /* we don't need to add ourselves to this slot's chain */
70917+ return;
70918+ }
70919+ /* we need to add ourselves to this chain, two cases */
70920+ if (role->next == NULL) {
70921+ /* simple case, append the current chain to our role */
70922+ role->next = *curr;
70923+ *curr = role;
70924+ } else {
70925+ /* 1 -> 2 -> 3 -> 4
70926+ 2 -> 3 -> 4
70927+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70928+ */
70929+ /* trickier case: walk our role's chain until we find
70930+ the role for the start of the current slot's chain */
70931+ tmp = role;
70932+ tmp2 = *curr;
70933+ while (tmp->next && tmp->next != tmp2)
70934+ tmp = tmp->next;
70935+ if (tmp->next == tmp2) {
70936+ /* from example above, we found 3, so just
70937+ replace this slot's chain with ours */
70938+ *curr = role;
70939+ } else {
70940+ /* we didn't find a subset of our role's chain
70941+ in the current slot's chain, so append their
70942+ chain to ours, and set us as the first role in
70943+ the slot's chain
70944+
70945+ we could fold this case with the case above,
70946+ but making it explicit for clarity
70947+ */
70948+ tmp->next = tmp2;
70949+ *curr = role;
70950+ }
70951+ }
70952+ }
70953+
70954+ return;
70955+}
70956+
70957+static void
70958+insert_acl_role_label(struct acl_role_label *role)
70959+{
70960+ int i;
70961+
70962+ if (polstate->role_list == NULL) {
70963+ polstate->role_list = role;
70964+ role->prev = NULL;
70965+ } else {
70966+ role->prev = polstate->role_list;
70967+ polstate->role_list = role;
70968+ }
70969+
70970+ /* used for hash chains */
70971+ role->next = NULL;
70972+
70973+ if (role->roletype & GR_ROLE_DOMAIN) {
70974+ for (i = 0; i < role->domain_child_num; i++)
70975+ __insert_acl_role_label(role, role->domain_children[i]);
70976+ } else
70977+ __insert_acl_role_label(role, role->uidgid);
70978+}
70979+
70980+static int
70981+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70982+{
70983+ struct name_entry **curr, *nentry;
70984+ struct inodev_entry *ientry;
70985+ unsigned int len = strlen(name);
70986+ unsigned int key = full_name_hash(name, len);
70987+ unsigned int index = key % polstate->name_set.n_size;
70988+
70989+ curr = &polstate->name_set.n_hash[index];
70990+
70991+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70992+ curr = &((*curr)->next);
70993+
70994+ if (*curr != NULL)
70995+ return 1;
70996+
70997+ nentry = acl_alloc(sizeof (struct name_entry));
70998+ if (nentry == NULL)
70999+ return 0;
71000+ ientry = acl_alloc(sizeof (struct inodev_entry));
71001+ if (ientry == NULL)
71002+ return 0;
71003+ ientry->nentry = nentry;
71004+
71005+ nentry->key = key;
71006+ nentry->name = name;
71007+ nentry->inode = inode;
71008+ nentry->device = device;
71009+ nentry->len = len;
71010+ nentry->deleted = deleted;
71011+
71012+ nentry->prev = NULL;
71013+ curr = &polstate->name_set.n_hash[index];
71014+ if (*curr != NULL)
71015+ (*curr)->prev = nentry;
71016+ nentry->next = *curr;
71017+ *curr = nentry;
71018+
71019+ /* insert us into the table searchable by inode/dev */
71020+ __insert_inodev_entry(polstate, ientry);
71021+
71022+ return 1;
71023+}
71024+
71025+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71026+
71027+static void *
71028+create_table(__u32 * len, int elementsize)
71029+{
71030+ unsigned int table_sizes[] = {
71031+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71032+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71033+ 4194301, 8388593, 16777213, 33554393, 67108859
71034+ };
71035+ void *newtable = NULL;
71036+ unsigned int pwr = 0;
71037+
71038+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71039+ table_sizes[pwr] <= *len)
71040+ pwr++;
71041+
71042+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71043+ return newtable;
71044+
71045+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71046+ newtable =
71047+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71048+ else
71049+ newtable = vmalloc(table_sizes[pwr] * elementsize);
71050+
71051+ *len = table_sizes[pwr];
71052+
71053+ return newtable;
71054+}
71055+
71056+static int
71057+init_variables(const struct gr_arg *arg, bool reload)
71058+{
71059+ struct task_struct *reaper = init_pid_ns.child_reaper;
71060+ unsigned int stacksize;
71061+
71062+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71063+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71064+ polstate->name_set.n_size = arg->role_db.num_objects;
71065+ polstate->inodev_set.i_size = arg->role_db.num_objects;
71066+
71067+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71068+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71069+ return 1;
71070+
71071+ if (!reload) {
71072+ if (!gr_init_uidset())
71073+ return 1;
71074+ }
71075+
71076+ /* set up the stack that holds allocation info */
71077+
71078+ stacksize = arg->role_db.num_pointers + 5;
71079+
71080+ if (!acl_alloc_stack_init(stacksize))
71081+ return 1;
71082+
71083+ if (!reload) {
71084+ /* grab reference for the real root dentry and vfsmount */
71085+ get_fs_root(reaper->fs, &gr_real_root);
71086+
71087+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71088+ 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);
71089+#endif
71090+
71091+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71092+ if (fakefs_obj_rw == NULL)
71093+ return 1;
71094+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71095+
71096+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71097+ if (fakefs_obj_rwx == NULL)
71098+ return 1;
71099+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71100+ }
71101+
71102+ polstate->subj_map_set.s_hash =
71103+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71104+ polstate->acl_role_set.r_hash =
71105+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71106+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71107+ polstate->inodev_set.i_hash =
71108+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71109+
71110+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71111+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71112+ return 1;
71113+
71114+ memset(polstate->subj_map_set.s_hash, 0,
71115+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71116+ memset(polstate->acl_role_set.r_hash, 0,
71117+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71118+ memset(polstate->name_set.n_hash, 0,
71119+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71120+ memset(polstate->inodev_set.i_hash, 0,
71121+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71122+
71123+ return 0;
71124+}
71125+
71126+/* free information not needed after startup
71127+ currently contains user->kernel pointer mappings for subjects
71128+*/
71129+
71130+static void
71131+free_init_variables(void)
71132+{
71133+ __u32 i;
71134+
71135+ if (polstate->subj_map_set.s_hash) {
71136+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71137+ if (polstate->subj_map_set.s_hash[i]) {
71138+ kfree(polstate->subj_map_set.s_hash[i]);
71139+ polstate->subj_map_set.s_hash[i] = NULL;
71140+ }
71141+ }
71142+
71143+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71144+ PAGE_SIZE)
71145+ kfree(polstate->subj_map_set.s_hash);
71146+ else
71147+ vfree(polstate->subj_map_set.s_hash);
71148+ }
71149+
71150+ return;
71151+}
71152+
71153+static void
71154+free_variables(bool reload)
71155+{
71156+ struct acl_subject_label *s;
71157+ struct acl_role_label *r;
71158+ struct task_struct *task, *task2;
71159+ unsigned int x;
71160+
71161+ if (!reload) {
71162+ gr_clear_learn_entries();
71163+
71164+ read_lock(&tasklist_lock);
71165+ do_each_thread(task2, task) {
71166+ task->acl_sp_role = 0;
71167+ task->acl_role_id = 0;
71168+ task->inherited = 0;
71169+ task->acl = NULL;
71170+ task->role = NULL;
71171+ } while_each_thread(task2, task);
71172+ read_unlock(&tasklist_lock);
71173+
71174+ kfree(fakefs_obj_rw);
71175+ fakefs_obj_rw = NULL;
71176+ kfree(fakefs_obj_rwx);
71177+ fakefs_obj_rwx = NULL;
71178+
71179+ /* release the reference to the real root dentry and vfsmount */
71180+ path_put(&gr_real_root);
71181+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71182+ }
71183+
71184+ /* free all object hash tables */
71185+
71186+ FOR_EACH_ROLE_START(r)
71187+ if (r->subj_hash == NULL)
71188+ goto next_role;
71189+ FOR_EACH_SUBJECT_START(r, s, x)
71190+ if (s->obj_hash == NULL)
71191+ break;
71192+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71193+ kfree(s->obj_hash);
71194+ else
71195+ vfree(s->obj_hash);
71196+ FOR_EACH_SUBJECT_END(s, x)
71197+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71198+ if (s->obj_hash == NULL)
71199+ break;
71200+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71201+ kfree(s->obj_hash);
71202+ else
71203+ vfree(s->obj_hash);
71204+ FOR_EACH_NESTED_SUBJECT_END(s)
71205+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71206+ kfree(r->subj_hash);
71207+ else
71208+ vfree(r->subj_hash);
71209+ r->subj_hash = NULL;
71210+next_role:
71211+ FOR_EACH_ROLE_END(r)
71212+
71213+ acl_free_all();
71214+
71215+ if (polstate->acl_role_set.r_hash) {
71216+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71217+ PAGE_SIZE)
71218+ kfree(polstate->acl_role_set.r_hash);
71219+ else
71220+ vfree(polstate->acl_role_set.r_hash);
71221+ }
71222+ if (polstate->name_set.n_hash) {
71223+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71224+ PAGE_SIZE)
71225+ kfree(polstate->name_set.n_hash);
71226+ else
71227+ vfree(polstate->name_set.n_hash);
71228+ }
71229+
71230+ if (polstate->inodev_set.i_hash) {
71231+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71232+ PAGE_SIZE)
71233+ kfree(polstate->inodev_set.i_hash);
71234+ else
71235+ vfree(polstate->inodev_set.i_hash);
71236+ }
71237+
71238+ if (!reload)
71239+ gr_free_uidset();
71240+
71241+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71242+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71243+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71244+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71245+
71246+ polstate->default_role = NULL;
71247+ polstate->kernel_role = NULL;
71248+ polstate->role_list = NULL;
71249+
71250+ return;
71251+}
71252+
71253+static struct acl_subject_label *
71254+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71255+
71256+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71257+{
71258+ unsigned int len = strnlen_user(*name, maxlen);
71259+ char *tmp;
71260+
71261+ if (!len || len >= maxlen)
71262+ return -EINVAL;
71263+
71264+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71265+ return -ENOMEM;
71266+
71267+ if (copy_from_user(tmp, *name, len))
71268+ return -EFAULT;
71269+
71270+ tmp[len-1] = '\0';
71271+ *name = tmp;
71272+
71273+ return 0;
71274+}
71275+
71276+static int
71277+copy_user_glob(struct acl_object_label *obj)
71278+{
71279+ struct acl_object_label *g_tmp, **guser;
71280+ int error;
71281+
71282+ if (obj->globbed == NULL)
71283+ return 0;
71284+
71285+ guser = &obj->globbed;
71286+ while (*guser) {
71287+ g_tmp = (struct acl_object_label *)
71288+ acl_alloc(sizeof (struct acl_object_label));
71289+ if (g_tmp == NULL)
71290+ return -ENOMEM;
71291+
71292+ if (copy_acl_object_label(g_tmp, *guser))
71293+ return -EFAULT;
71294+
71295+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71296+ if (error)
71297+ return error;
71298+
71299+ *guser = g_tmp;
71300+ guser = &(g_tmp->next);
71301+ }
71302+
71303+ return 0;
71304+}
71305+
71306+static int
71307+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71308+ struct acl_role_label *role)
71309+{
71310+ struct acl_object_label *o_tmp;
71311+ int ret;
71312+
71313+ while (userp) {
71314+ if ((o_tmp = (struct acl_object_label *)
71315+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71316+ return -ENOMEM;
71317+
71318+ if (copy_acl_object_label(o_tmp, userp))
71319+ return -EFAULT;
71320+
71321+ userp = o_tmp->prev;
71322+
71323+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71324+ if (ret)
71325+ return ret;
71326+
71327+ insert_acl_obj_label(o_tmp, subj);
71328+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71329+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71330+ return -ENOMEM;
71331+
71332+ ret = copy_user_glob(o_tmp);
71333+ if (ret)
71334+ return ret;
71335+
71336+ if (o_tmp->nested) {
71337+ int already_copied;
71338+
71339+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71340+ if (IS_ERR(o_tmp->nested))
71341+ return PTR_ERR(o_tmp->nested);
71342+
71343+ /* insert into nested subject list if we haven't copied this one yet
71344+ to prevent duplicate entries */
71345+ if (!already_copied) {
71346+ o_tmp->nested->next = role->hash->first;
71347+ role->hash->first = o_tmp->nested;
71348+ }
71349+ }
71350+ }
71351+
71352+ return 0;
71353+}
71354+
71355+static __u32
71356+count_user_subjs(struct acl_subject_label *userp)
71357+{
71358+ struct acl_subject_label s_tmp;
71359+ __u32 num = 0;
71360+
71361+ while (userp) {
71362+ if (copy_acl_subject_label(&s_tmp, userp))
71363+ break;
71364+
71365+ userp = s_tmp.prev;
71366+ }
71367+
71368+ return num;
71369+}
71370+
71371+static int
71372+copy_user_allowedips(struct acl_role_label *rolep)
71373+{
71374+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71375+
71376+ ruserip = rolep->allowed_ips;
71377+
71378+ while (ruserip) {
71379+ rlast = rtmp;
71380+
71381+ if ((rtmp = (struct role_allowed_ip *)
71382+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71383+ return -ENOMEM;
71384+
71385+ if (copy_role_allowed_ip(rtmp, ruserip))
71386+ return -EFAULT;
71387+
71388+ ruserip = rtmp->prev;
71389+
71390+ if (!rlast) {
71391+ rtmp->prev = NULL;
71392+ rolep->allowed_ips = rtmp;
71393+ } else {
71394+ rlast->next = rtmp;
71395+ rtmp->prev = rlast;
71396+ }
71397+
71398+ if (!ruserip)
71399+ rtmp->next = NULL;
71400+ }
71401+
71402+ return 0;
71403+}
71404+
71405+static int
71406+copy_user_transitions(struct acl_role_label *rolep)
71407+{
71408+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71409+ int error;
71410+
71411+ rusertp = rolep->transitions;
71412+
71413+ while (rusertp) {
71414+ rlast = rtmp;
71415+
71416+ if ((rtmp = (struct role_transition *)
71417+ acl_alloc(sizeof (struct role_transition))) == NULL)
71418+ return -ENOMEM;
71419+
71420+ if (copy_role_transition(rtmp, rusertp))
71421+ return -EFAULT;
71422+
71423+ rusertp = rtmp->prev;
71424+
71425+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71426+ if (error)
71427+ return error;
71428+
71429+ if (!rlast) {
71430+ rtmp->prev = NULL;
71431+ rolep->transitions = rtmp;
71432+ } else {
71433+ rlast->next = rtmp;
71434+ rtmp->prev = rlast;
71435+ }
71436+
71437+ if (!rusertp)
71438+ rtmp->next = NULL;
71439+ }
71440+
71441+ return 0;
71442+}
71443+
71444+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71445+{
71446+ struct acl_object_label o_tmp;
71447+ __u32 num = 0;
71448+
71449+ while (userp) {
71450+ if (copy_acl_object_label(&o_tmp, userp))
71451+ break;
71452+
71453+ userp = o_tmp.prev;
71454+ num++;
71455+ }
71456+
71457+ return num;
71458+}
71459+
71460+static struct acl_subject_label *
71461+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71462+{
71463+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71464+ __u32 num_objs;
71465+ struct acl_ip_label **i_tmp, *i_utmp2;
71466+ struct gr_hash_struct ghash;
71467+ struct subject_map *subjmap;
71468+ unsigned int i_num;
71469+ int err;
71470+
71471+ if (already_copied != NULL)
71472+ *already_copied = 0;
71473+
71474+ s_tmp = lookup_subject_map(userp);
71475+
71476+ /* we've already copied this subject into the kernel, just return
71477+ the reference to it, and don't copy it over again
71478+ */
71479+ if (s_tmp) {
71480+ if (already_copied != NULL)
71481+ *already_copied = 1;
71482+ return(s_tmp);
71483+ }
71484+
71485+ if ((s_tmp = (struct acl_subject_label *)
71486+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71487+ return ERR_PTR(-ENOMEM);
71488+
71489+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71490+ if (subjmap == NULL)
71491+ return ERR_PTR(-ENOMEM);
71492+
71493+ subjmap->user = userp;
71494+ subjmap->kernel = s_tmp;
71495+ insert_subj_map_entry(subjmap);
71496+
71497+ if (copy_acl_subject_label(s_tmp, userp))
71498+ return ERR_PTR(-EFAULT);
71499+
71500+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71501+ if (err)
71502+ return ERR_PTR(err);
71503+
71504+ if (!strcmp(s_tmp->filename, "/"))
71505+ role->root_label = s_tmp;
71506+
71507+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71508+ return ERR_PTR(-EFAULT);
71509+
71510+ /* copy user and group transition tables */
71511+
71512+ if (s_tmp->user_trans_num) {
71513+ uid_t *uidlist;
71514+
71515+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71516+ if (uidlist == NULL)
71517+ return ERR_PTR(-ENOMEM);
71518+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71519+ return ERR_PTR(-EFAULT);
71520+
71521+ s_tmp->user_transitions = uidlist;
71522+ }
71523+
71524+ if (s_tmp->group_trans_num) {
71525+ gid_t *gidlist;
71526+
71527+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71528+ if (gidlist == NULL)
71529+ return ERR_PTR(-ENOMEM);
71530+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71531+ return ERR_PTR(-EFAULT);
71532+
71533+ s_tmp->group_transitions = gidlist;
71534+ }
71535+
71536+ /* set up object hash table */
71537+ num_objs = count_user_objs(ghash.first);
71538+
71539+ s_tmp->obj_hash_size = num_objs;
71540+ s_tmp->obj_hash =
71541+ (struct acl_object_label **)
71542+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71543+
71544+ if (!s_tmp->obj_hash)
71545+ return ERR_PTR(-ENOMEM);
71546+
71547+ memset(s_tmp->obj_hash, 0,
71548+ s_tmp->obj_hash_size *
71549+ sizeof (struct acl_object_label *));
71550+
71551+ /* add in objects */
71552+ err = copy_user_objs(ghash.first, s_tmp, role);
71553+
71554+ if (err)
71555+ return ERR_PTR(err);
71556+
71557+ /* set pointer for parent subject */
71558+ if (s_tmp->parent_subject) {
71559+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71560+
71561+ if (IS_ERR(s_tmp2))
71562+ return s_tmp2;
71563+
71564+ s_tmp->parent_subject = s_tmp2;
71565+ }
71566+
71567+ /* add in ip acls */
71568+
71569+ if (!s_tmp->ip_num) {
71570+ s_tmp->ips = NULL;
71571+ goto insert;
71572+ }
71573+
71574+ i_tmp =
71575+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71576+ sizeof (struct acl_ip_label *));
71577+
71578+ if (!i_tmp)
71579+ return ERR_PTR(-ENOMEM);
71580+
71581+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71582+ *(i_tmp + i_num) =
71583+ (struct acl_ip_label *)
71584+ acl_alloc(sizeof (struct acl_ip_label));
71585+ if (!*(i_tmp + i_num))
71586+ return ERR_PTR(-ENOMEM);
71587+
71588+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71589+ return ERR_PTR(-EFAULT);
71590+
71591+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71592+ return ERR_PTR(-EFAULT);
71593+
71594+ if ((*(i_tmp + i_num))->iface == NULL)
71595+ continue;
71596+
71597+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71598+ if (err)
71599+ return ERR_PTR(err);
71600+ }
71601+
71602+ s_tmp->ips = i_tmp;
71603+
71604+insert:
71605+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71606+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71607+ return ERR_PTR(-ENOMEM);
71608+
71609+ return s_tmp;
71610+}
71611+
71612+static int
71613+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71614+{
71615+ struct acl_subject_label s_pre;
71616+ struct acl_subject_label * ret;
71617+ int err;
71618+
71619+ while (userp) {
71620+ if (copy_acl_subject_label(&s_pre, userp))
71621+ return -EFAULT;
71622+
71623+ ret = do_copy_user_subj(userp, role, NULL);
71624+
71625+ err = PTR_ERR(ret);
71626+ if (IS_ERR(ret))
71627+ return err;
71628+
71629+ insert_acl_subj_label(ret, role);
71630+
71631+ userp = s_pre.prev;
71632+ }
71633+
71634+ return 0;
71635+}
71636+
71637+static int
71638+copy_user_acl(struct gr_arg *arg)
71639+{
71640+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71641+ struct acl_subject_label *subj_list;
71642+ struct sprole_pw *sptmp;
71643+ struct gr_hash_struct *ghash;
71644+ uid_t *domainlist;
71645+ unsigned int r_num;
71646+ int err = 0;
71647+ __u16 i;
71648+ __u32 num_subjs;
71649+
71650+ /* we need a default and kernel role */
71651+ if (arg->role_db.num_roles < 2)
71652+ return -EINVAL;
71653+
71654+ /* copy special role authentication info from userspace */
71655+
71656+ polstate->num_sprole_pws = arg->num_sprole_pws;
71657+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71658+
71659+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71660+ return -ENOMEM;
71661+
71662+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71663+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71664+ if (!sptmp)
71665+ return -ENOMEM;
71666+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71667+ return -EFAULT;
71668+
71669+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71670+ if (err)
71671+ return err;
71672+
71673+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71674+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71675+#endif
71676+
71677+ polstate->acl_special_roles[i] = sptmp;
71678+ }
71679+
71680+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71681+
71682+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71683+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
71684+
71685+ if (!r_tmp)
71686+ return -ENOMEM;
71687+
71688+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71689+ return -EFAULT;
71690+
71691+ if (copy_acl_role_label(r_tmp, r_utmp2))
71692+ return -EFAULT;
71693+
71694+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71695+ if (err)
71696+ return err;
71697+
71698+ if (!strcmp(r_tmp->rolename, "default")
71699+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71700+ polstate->default_role = r_tmp;
71701+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71702+ polstate->kernel_role = r_tmp;
71703+ }
71704+
71705+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71706+ return -ENOMEM;
71707+
71708+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
71709+ return -EFAULT;
71710+
71711+ r_tmp->hash = ghash;
71712+
71713+ num_subjs = count_user_subjs(r_tmp->hash->first);
71714+
71715+ r_tmp->subj_hash_size = num_subjs;
71716+ r_tmp->subj_hash =
71717+ (struct acl_subject_label **)
71718+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71719+
71720+ if (!r_tmp->subj_hash)
71721+ return -ENOMEM;
71722+
71723+ err = copy_user_allowedips(r_tmp);
71724+ if (err)
71725+ return err;
71726+
71727+ /* copy domain info */
71728+ if (r_tmp->domain_children != NULL) {
71729+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71730+ if (domainlist == NULL)
71731+ return -ENOMEM;
71732+
71733+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71734+ return -EFAULT;
71735+
71736+ r_tmp->domain_children = domainlist;
71737+ }
71738+
71739+ err = copy_user_transitions(r_tmp);
71740+ if (err)
71741+ return err;
71742+
71743+ memset(r_tmp->subj_hash, 0,
71744+ r_tmp->subj_hash_size *
71745+ sizeof (struct acl_subject_label *));
71746+
71747+ /* acquire the list of subjects, then NULL out
71748+ the list prior to parsing the subjects for this role,
71749+ as during this parsing the list is replaced with a list
71750+ of *nested* subjects for the role
71751+ */
71752+ subj_list = r_tmp->hash->first;
71753+
71754+ /* set nested subject list to null */
71755+ r_tmp->hash->first = NULL;
71756+
71757+ err = copy_user_subjs(subj_list, r_tmp);
71758+
71759+ if (err)
71760+ return err;
71761+
71762+ insert_acl_role_label(r_tmp);
71763+ }
71764+
71765+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71766+ return -EINVAL;
71767+
71768+ return err;
71769+}
71770+
71771+static int gracl_reload_apply_policies(void *reload)
71772+{
71773+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71774+ struct task_struct *task, *task2;
71775+ struct acl_role_label *role, *rtmp;
71776+ struct acl_subject_label *subj;
71777+ const struct cred *cred;
71778+ int role_applied;
71779+ int ret = 0;
71780+
71781+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71782+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71783+
71784+ /* first make sure we'll be able to apply the new policy cleanly */
71785+ do_each_thread(task2, task) {
71786+ if (task->exec_file == NULL)
71787+ continue;
71788+ role_applied = 0;
71789+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71790+ /* preserve special roles */
71791+ FOR_EACH_ROLE_START(role)
71792+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71793+ rtmp = task->role;
71794+ task->role = role;
71795+ role_applied = 1;
71796+ break;
71797+ }
71798+ FOR_EACH_ROLE_END(role)
71799+ }
71800+ if (!role_applied) {
71801+ cred = __task_cred(task);
71802+ rtmp = task->role;
71803+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71804+ }
71805+ /* this handles non-nested inherited subjects, nested subjects will still
71806+ be dropped currently */
71807+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71808+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71809+ /* change the role back so that we've made no modifications to the policy */
71810+ task->role = rtmp;
71811+
71812+ if (subj == NULL || task->tmpacl == NULL) {
71813+ ret = -EINVAL;
71814+ goto out;
71815+ }
71816+ } while_each_thread(task2, task);
71817+
71818+ /* now actually apply the policy */
71819+
71820+ do_each_thread(task2, task) {
71821+ if (task->exec_file) {
71822+ role_applied = 0;
71823+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71824+ /* preserve special roles */
71825+ FOR_EACH_ROLE_START(role)
71826+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71827+ task->role = role;
71828+ role_applied = 1;
71829+ break;
71830+ }
71831+ FOR_EACH_ROLE_END(role)
71832+ }
71833+ if (!role_applied) {
71834+ cred = __task_cred(task);
71835+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71836+ }
71837+ /* this handles non-nested inherited subjects, nested subjects will still
71838+ be dropped currently */
71839+ if (!reload_state->oldmode && task->inherited)
71840+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71841+ else {
71842+ /* looked up and tagged to the task previously */
71843+ subj = task->tmpacl;
71844+ }
71845+ /* subj will be non-null */
71846+ __gr_apply_subject_to_task(polstate, task, subj);
71847+ if (reload_state->oldmode) {
71848+ task->acl_role_id = 0;
71849+ task->acl_sp_role = 0;
71850+ task->inherited = 0;
71851+ }
71852+ } else {
71853+ // it's a kernel process
71854+ task->role = polstate->kernel_role;
71855+ task->acl = polstate->kernel_role->root_label;
71856+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71857+ task->acl->mode &= ~GR_PROCFIND;
71858+#endif
71859+ }
71860+ } while_each_thread(task2, task);
71861+
71862+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71863+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71864+
71865+out:
71866+
71867+ return ret;
71868+}
71869+
71870+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71871+{
71872+ struct gr_reload_state new_reload_state = { };
71873+ int err;
71874+
71875+ new_reload_state.oldpolicy_ptr = polstate;
71876+ new_reload_state.oldalloc_ptr = current_alloc_state;
71877+ new_reload_state.oldmode = oldmode;
71878+
71879+ current_alloc_state = &new_reload_state.newalloc;
71880+ polstate = &new_reload_state.newpolicy;
71881+
71882+ /* everything relevant is now saved off, copy in the new policy */
71883+ if (init_variables(args, true)) {
71884+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71885+ err = -ENOMEM;
71886+ goto error;
71887+ }
71888+
71889+ err = copy_user_acl(args);
71890+ free_init_variables();
71891+ if (err)
71892+ goto error;
71893+ /* the new policy is copied in, with the old policy available via saved_state
71894+ first go through applying roles, making sure to preserve special roles
71895+ then apply new subjects, making sure to preserve inherited and nested subjects,
71896+ though currently only inherited subjects will be preserved
71897+ */
71898+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71899+ if (err)
71900+ goto error;
71901+
71902+ /* we've now applied the new policy, so restore the old policy state to free it */
71903+ polstate = &new_reload_state.oldpolicy;
71904+ current_alloc_state = &new_reload_state.oldalloc;
71905+ free_variables(true);
71906+
71907+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71908+ to running_polstate/current_alloc_state inside stop_machine
71909+ */
71910+ err = 0;
71911+ goto out;
71912+error:
71913+ /* on error of loading the new policy, we'll just keep the previous
71914+ policy set around
71915+ */
71916+ free_variables(true);
71917+
71918+ /* doesn't affect runtime, but maintains consistent state */
71919+out:
71920+ polstate = new_reload_state.oldpolicy_ptr;
71921+ current_alloc_state = new_reload_state.oldalloc_ptr;
71922+
71923+ return err;
71924+}
71925+
71926+static int
71927+gracl_init(struct gr_arg *args)
71928+{
71929+ int error = 0;
71930+
71931+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71932+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71933+
71934+ if (init_variables(args, false)) {
71935+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71936+ error = -ENOMEM;
71937+ goto out;
71938+ }
71939+
71940+ error = copy_user_acl(args);
71941+ free_init_variables();
71942+ if (error)
71943+ goto out;
71944+
71945+ error = gr_set_acls(0);
71946+ if (error)
71947+ goto out;
71948+
71949+ gr_enable_rbac_system();
71950+
71951+ return 0;
71952+
71953+out:
71954+ free_variables(false);
71955+ return error;
71956+}
71957+
71958+static int
71959+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71960+ unsigned char **sum)
71961+{
71962+ struct acl_role_label *r;
71963+ struct role_allowed_ip *ipp;
71964+ struct role_transition *trans;
71965+ unsigned int i;
71966+ int found = 0;
71967+ u32 curr_ip = current->signal->curr_ip;
71968+
71969+ current->signal->saved_ip = curr_ip;
71970+
71971+ /* check transition table */
71972+
71973+ for (trans = current->role->transitions; trans; trans = trans->next) {
71974+ if (!strcmp(rolename, trans->rolename)) {
71975+ found = 1;
71976+ break;
71977+ }
71978+ }
71979+
71980+ if (!found)
71981+ return 0;
71982+
71983+ /* handle special roles that do not require authentication
71984+ and check ip */
71985+
71986+ FOR_EACH_ROLE_START(r)
71987+ if (!strcmp(rolename, r->rolename) &&
71988+ (r->roletype & GR_ROLE_SPECIAL)) {
71989+ found = 0;
71990+ if (r->allowed_ips != NULL) {
71991+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71992+ if ((ntohl(curr_ip) & ipp->netmask) ==
71993+ (ntohl(ipp->addr) & ipp->netmask))
71994+ found = 1;
71995+ }
71996+ } else
71997+ found = 2;
71998+ if (!found)
71999+ return 0;
72000+
72001+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72002+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72003+ *salt = NULL;
72004+ *sum = NULL;
72005+ return 1;
72006+ }
72007+ }
72008+ FOR_EACH_ROLE_END(r)
72009+
72010+ for (i = 0; i < polstate->num_sprole_pws; i++) {
72011+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72012+ *salt = polstate->acl_special_roles[i]->salt;
72013+ *sum = polstate->acl_special_roles[i]->sum;
72014+ return 1;
72015+ }
72016+ }
72017+
72018+ return 0;
72019+}
72020+
72021+int gr_check_secure_terminal(struct task_struct *task)
72022+{
72023+ struct task_struct *p, *p2, *p3;
72024+ struct files_struct *files;
72025+ struct fdtable *fdt;
72026+ struct file *our_file = NULL, *file;
72027+ int i;
72028+
72029+ if (task->signal->tty == NULL)
72030+ return 1;
72031+
72032+ files = get_files_struct(task);
72033+ if (files != NULL) {
72034+ rcu_read_lock();
72035+ fdt = files_fdtable(files);
72036+ for (i=0; i < fdt->max_fds; i++) {
72037+ file = fcheck_files(files, i);
72038+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72039+ get_file(file);
72040+ our_file = file;
72041+ }
72042+ }
72043+ rcu_read_unlock();
72044+ put_files_struct(files);
72045+ }
72046+
72047+ if (our_file == NULL)
72048+ return 1;
72049+
72050+ read_lock(&tasklist_lock);
72051+ do_each_thread(p2, p) {
72052+ files = get_files_struct(p);
72053+ if (files == NULL ||
72054+ (p->signal && p->signal->tty == task->signal->tty)) {
72055+ if (files != NULL)
72056+ put_files_struct(files);
72057+ continue;
72058+ }
72059+ rcu_read_lock();
72060+ fdt = files_fdtable(files);
72061+ for (i=0; i < fdt->max_fds; i++) {
72062+ file = fcheck_files(files, i);
72063+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72064+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72065+ p3 = task;
72066+ while (task_pid_nr(p3) > 0) {
72067+ if (p3 == p)
72068+ break;
72069+ p3 = p3->real_parent;
72070+ }
72071+ if (p3 == p)
72072+ break;
72073+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72074+ gr_handle_alertkill(p);
72075+ rcu_read_unlock();
72076+ put_files_struct(files);
72077+ read_unlock(&tasklist_lock);
72078+ fput(our_file);
72079+ return 0;
72080+ }
72081+ }
72082+ rcu_read_unlock();
72083+ put_files_struct(files);
72084+ } while_each_thread(p2, p);
72085+ read_unlock(&tasklist_lock);
72086+
72087+ fput(our_file);
72088+ return 1;
72089+}
72090+
72091+ssize_t
72092+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72093+{
72094+ struct gr_arg_wrapper uwrap;
72095+ unsigned char *sprole_salt = NULL;
72096+ unsigned char *sprole_sum = NULL;
72097+ int error = 0;
72098+ int error2 = 0;
72099+ size_t req_count = 0;
72100+ unsigned char oldmode = 0;
72101+
72102+ mutex_lock(&gr_dev_mutex);
72103+
72104+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72105+ error = -EPERM;
72106+ goto out;
72107+ }
72108+
72109+#ifdef CONFIG_COMPAT
72110+ pax_open_kernel();
72111+ if (is_compat_task()) {
72112+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72113+ copy_gr_arg = &copy_gr_arg_compat;
72114+ copy_acl_object_label = &copy_acl_object_label_compat;
72115+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72116+ copy_acl_role_label = &copy_acl_role_label_compat;
72117+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72118+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72119+ copy_role_transition = &copy_role_transition_compat;
72120+ copy_sprole_pw = &copy_sprole_pw_compat;
72121+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72122+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72123+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72124+ } else {
72125+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72126+ copy_gr_arg = &copy_gr_arg_normal;
72127+ copy_acl_object_label = &copy_acl_object_label_normal;
72128+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72129+ copy_acl_role_label = &copy_acl_role_label_normal;
72130+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72131+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72132+ copy_role_transition = &copy_role_transition_normal;
72133+ copy_sprole_pw = &copy_sprole_pw_normal;
72134+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72135+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72136+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72137+ }
72138+ pax_close_kernel();
72139+#endif
72140+
72141+ req_count = get_gr_arg_wrapper_size();
72142+
72143+ if (count != req_count) {
72144+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72145+ error = -EINVAL;
72146+ goto out;
72147+ }
72148+
72149+
72150+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72151+ gr_auth_expires = 0;
72152+ gr_auth_attempts = 0;
72153+ }
72154+
72155+ error = copy_gr_arg_wrapper(buf, &uwrap);
72156+ if (error)
72157+ goto out;
72158+
72159+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72160+ if (error)
72161+ goto out;
72162+
72163+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72164+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72165+ time_after(gr_auth_expires, get_seconds())) {
72166+ error = -EBUSY;
72167+ goto out;
72168+ }
72169+
72170+ /* if non-root trying to do anything other than use a special role,
72171+ do not attempt authentication, do not count towards authentication
72172+ locking
72173+ */
72174+
72175+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72176+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72177+ gr_is_global_nonroot(current_uid())) {
72178+ error = -EPERM;
72179+ goto out;
72180+ }
72181+
72182+ /* ensure pw and special role name are null terminated */
72183+
72184+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72185+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72186+
72187+ /* Okay.
72188+ * We have our enough of the argument structure..(we have yet
72189+ * to copy_from_user the tables themselves) . Copy the tables
72190+ * only if we need them, i.e. for loading operations. */
72191+
72192+ switch (gr_usermode.mode) {
72193+ case GR_STATUS:
72194+ if (gr_acl_is_enabled()) {
72195+ error = 1;
72196+ if (!gr_check_secure_terminal(current))
72197+ error = 3;
72198+ } else
72199+ error = 2;
72200+ goto out;
72201+ case GR_SHUTDOWN:
72202+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72203+ stop_machine(gr_rbac_disable, NULL, NULL);
72204+ free_variables(false);
72205+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72206+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72207+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72208+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72209+ } else if (gr_acl_is_enabled()) {
72210+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72211+ error = -EPERM;
72212+ } else {
72213+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72214+ error = -EAGAIN;
72215+ }
72216+ break;
72217+ case GR_ENABLE:
72218+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72219+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72220+ else {
72221+ if (gr_acl_is_enabled())
72222+ error = -EAGAIN;
72223+ else
72224+ error = error2;
72225+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72226+ }
72227+ break;
72228+ case GR_OLDRELOAD:
72229+ oldmode = 1;
72230+ case GR_RELOAD:
72231+ if (!gr_acl_is_enabled()) {
72232+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72233+ error = -EAGAIN;
72234+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72235+ error2 = gracl_reload(&gr_usermode, oldmode);
72236+ if (!error2)
72237+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72238+ else {
72239+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72240+ error = error2;
72241+ }
72242+ } else {
72243+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72244+ error = -EPERM;
72245+ }
72246+ break;
72247+ case GR_SEGVMOD:
72248+ if (unlikely(!gr_acl_is_enabled())) {
72249+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72250+ error = -EAGAIN;
72251+ break;
72252+ }
72253+
72254+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72255+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72256+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72257+ struct acl_subject_label *segvacl;
72258+ segvacl =
72259+ lookup_acl_subj_label(gr_usermode.segv_inode,
72260+ gr_usermode.segv_device,
72261+ current->role);
72262+ if (segvacl) {
72263+ segvacl->crashes = 0;
72264+ segvacl->expires = 0;
72265+ }
72266+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72267+ gr_remove_uid(gr_usermode.segv_uid);
72268+ }
72269+ } else {
72270+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72271+ error = -EPERM;
72272+ }
72273+ break;
72274+ case GR_SPROLE:
72275+ case GR_SPROLEPAM:
72276+ if (unlikely(!gr_acl_is_enabled())) {
72277+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72278+ error = -EAGAIN;
72279+ break;
72280+ }
72281+
72282+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72283+ current->role->expires = 0;
72284+ current->role->auth_attempts = 0;
72285+ }
72286+
72287+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72288+ time_after(current->role->expires, get_seconds())) {
72289+ error = -EBUSY;
72290+ goto out;
72291+ }
72292+
72293+ if (lookup_special_role_auth
72294+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72295+ && ((!sprole_salt && !sprole_sum)
72296+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72297+ char *p = "";
72298+ assign_special_role(gr_usermode.sp_role);
72299+ read_lock(&tasklist_lock);
72300+ if (current->real_parent)
72301+ p = current->real_parent->role->rolename;
72302+ read_unlock(&tasklist_lock);
72303+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72304+ p, acl_sp_role_value);
72305+ } else {
72306+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72307+ error = -EPERM;
72308+ if(!(current->role->auth_attempts++))
72309+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72310+
72311+ goto out;
72312+ }
72313+ break;
72314+ case GR_UNSPROLE:
72315+ if (unlikely(!gr_acl_is_enabled())) {
72316+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72317+ error = -EAGAIN;
72318+ break;
72319+ }
72320+
72321+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72322+ char *p = "";
72323+ int i = 0;
72324+
72325+ read_lock(&tasklist_lock);
72326+ if (current->real_parent) {
72327+ p = current->real_parent->role->rolename;
72328+ i = current->real_parent->acl_role_id;
72329+ }
72330+ read_unlock(&tasklist_lock);
72331+
72332+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72333+ gr_set_acls(1);
72334+ } else {
72335+ error = -EPERM;
72336+ goto out;
72337+ }
72338+ break;
72339+ default:
72340+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72341+ error = -EINVAL;
72342+ break;
72343+ }
72344+
72345+ if (error != -EPERM)
72346+ goto out;
72347+
72348+ if(!(gr_auth_attempts++))
72349+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72350+
72351+ out:
72352+ mutex_unlock(&gr_dev_mutex);
72353+
72354+ if (!error)
72355+ error = req_count;
72356+
72357+ return error;
72358+}
72359+
72360+int
72361+gr_set_acls(const int type)
72362+{
72363+ struct task_struct *task, *task2;
72364+ struct acl_role_label *role = current->role;
72365+ struct acl_subject_label *subj;
72366+ __u16 acl_role_id = current->acl_role_id;
72367+ const struct cred *cred;
72368+ int ret;
72369+
72370+ rcu_read_lock();
72371+ read_lock(&tasklist_lock);
72372+ read_lock(&grsec_exec_file_lock);
72373+ do_each_thread(task2, task) {
72374+ /* check to see if we're called from the exit handler,
72375+ if so, only replace ACLs that have inherited the admin
72376+ ACL */
72377+
72378+ if (type && (task->role != role ||
72379+ task->acl_role_id != acl_role_id))
72380+ continue;
72381+
72382+ task->acl_role_id = 0;
72383+ task->acl_sp_role = 0;
72384+ task->inherited = 0;
72385+
72386+ if (task->exec_file) {
72387+ cred = __task_cred(task);
72388+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72389+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72390+ if (subj == NULL) {
72391+ ret = -EINVAL;
72392+ read_unlock(&grsec_exec_file_lock);
72393+ read_unlock(&tasklist_lock);
72394+ rcu_read_unlock();
72395+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72396+ return ret;
72397+ }
72398+ __gr_apply_subject_to_task(polstate, task, subj);
72399+ } else {
72400+ // it's a kernel process
72401+ task->role = polstate->kernel_role;
72402+ task->acl = polstate->kernel_role->root_label;
72403+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72404+ task->acl->mode &= ~GR_PROCFIND;
72405+#endif
72406+ }
72407+ } while_each_thread(task2, task);
72408+ read_unlock(&grsec_exec_file_lock);
72409+ read_unlock(&tasklist_lock);
72410+ rcu_read_unlock();
72411+
72412+ return 0;
72413+}
72414diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72415new file mode 100644
72416index 0000000..39645c9
72417--- /dev/null
72418+++ b/grsecurity/gracl_res.c
72419@@ -0,0 +1,68 @@
72420+#include <linux/kernel.h>
72421+#include <linux/sched.h>
72422+#include <linux/gracl.h>
72423+#include <linux/grinternal.h>
72424+
72425+static const char *restab_log[] = {
72426+ [RLIMIT_CPU] = "RLIMIT_CPU",
72427+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72428+ [RLIMIT_DATA] = "RLIMIT_DATA",
72429+ [RLIMIT_STACK] = "RLIMIT_STACK",
72430+ [RLIMIT_CORE] = "RLIMIT_CORE",
72431+ [RLIMIT_RSS] = "RLIMIT_RSS",
72432+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72433+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72434+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72435+ [RLIMIT_AS] = "RLIMIT_AS",
72436+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72437+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72438+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72439+ [RLIMIT_NICE] = "RLIMIT_NICE",
72440+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72441+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72442+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72443+};
72444+
72445+void
72446+gr_log_resource(const struct task_struct *task,
72447+ const int res, const unsigned long wanted, const int gt)
72448+{
72449+ const struct cred *cred;
72450+ unsigned long rlim;
72451+
72452+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72453+ return;
72454+
72455+ // not yet supported resource
72456+ if (unlikely(!restab_log[res]))
72457+ return;
72458+
72459+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72460+ rlim = task_rlimit_max(task, res);
72461+ else
72462+ rlim = task_rlimit(task, res);
72463+
72464+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72465+ return;
72466+
72467+ rcu_read_lock();
72468+ cred = __task_cred(task);
72469+
72470+ if (res == RLIMIT_NPROC &&
72471+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72472+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72473+ goto out_rcu_unlock;
72474+ else if (res == RLIMIT_MEMLOCK &&
72475+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72476+ goto out_rcu_unlock;
72477+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72478+ goto out_rcu_unlock;
72479+ rcu_read_unlock();
72480+
72481+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72482+
72483+ return;
72484+out_rcu_unlock:
72485+ rcu_read_unlock();
72486+ return;
72487+}
72488diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72489new file mode 100644
72490index 0000000..2040e61
72491--- /dev/null
72492+++ b/grsecurity/gracl_segv.c
72493@@ -0,0 +1,313 @@
72494+#include <linux/kernel.h>
72495+#include <linux/mm.h>
72496+#include <asm/uaccess.h>
72497+#include <asm/errno.h>
72498+#include <asm/mman.h>
72499+#include <net/sock.h>
72500+#include <linux/file.h>
72501+#include <linux/fs.h>
72502+#include <linux/net.h>
72503+#include <linux/in.h>
72504+#include <linux/slab.h>
72505+#include <linux/types.h>
72506+#include <linux/sched.h>
72507+#include <linux/timer.h>
72508+#include <linux/gracl.h>
72509+#include <linux/grsecurity.h>
72510+#include <linux/grinternal.h>
72511+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72512+#include <linux/magic.h>
72513+#include <linux/pagemap.h>
72514+#include "../fs/btrfs/async-thread.h"
72515+#include "../fs/btrfs/ctree.h"
72516+#include "../fs/btrfs/btrfs_inode.h"
72517+#endif
72518+
72519+static struct crash_uid *uid_set;
72520+static unsigned short uid_used;
72521+static DEFINE_SPINLOCK(gr_uid_lock);
72522+extern rwlock_t gr_inode_lock;
72523+extern struct acl_subject_label *
72524+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72525+ struct acl_role_label *role);
72526+
72527+static inline dev_t __get_dev(const struct dentry *dentry)
72528+{
72529+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72530+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72531+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72532+ else
72533+#endif
72534+ return dentry->d_sb->s_dev;
72535+}
72536+
72537+int
72538+gr_init_uidset(void)
72539+{
72540+ uid_set =
72541+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72542+ uid_used = 0;
72543+
72544+ return uid_set ? 1 : 0;
72545+}
72546+
72547+void
72548+gr_free_uidset(void)
72549+{
72550+ if (uid_set) {
72551+ struct crash_uid *tmpset;
72552+ spin_lock(&gr_uid_lock);
72553+ tmpset = uid_set;
72554+ uid_set = NULL;
72555+ uid_used = 0;
72556+ spin_unlock(&gr_uid_lock);
72557+ if (tmpset)
72558+ kfree(tmpset);
72559+ }
72560+
72561+ return;
72562+}
72563+
72564+int
72565+gr_find_uid(const uid_t uid)
72566+{
72567+ struct crash_uid *tmp = uid_set;
72568+ uid_t buid;
72569+ int low = 0, high = uid_used - 1, mid;
72570+
72571+ while (high >= low) {
72572+ mid = (low + high) >> 1;
72573+ buid = tmp[mid].uid;
72574+ if (buid == uid)
72575+ return mid;
72576+ if (buid > uid)
72577+ high = mid - 1;
72578+ if (buid < uid)
72579+ low = mid + 1;
72580+ }
72581+
72582+ return -1;
72583+}
72584+
72585+static __inline__ void
72586+gr_insertsort(void)
72587+{
72588+ unsigned short i, j;
72589+ struct crash_uid index;
72590+
72591+ for (i = 1; i < uid_used; i++) {
72592+ index = uid_set[i];
72593+ j = i;
72594+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72595+ uid_set[j] = uid_set[j - 1];
72596+ j--;
72597+ }
72598+ uid_set[j] = index;
72599+ }
72600+
72601+ return;
72602+}
72603+
72604+static __inline__ void
72605+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72606+{
72607+ int loc;
72608+ uid_t uid = GR_GLOBAL_UID(kuid);
72609+
72610+ if (uid_used == GR_UIDTABLE_MAX)
72611+ return;
72612+
72613+ loc = gr_find_uid(uid);
72614+
72615+ if (loc >= 0) {
72616+ uid_set[loc].expires = expires;
72617+ return;
72618+ }
72619+
72620+ uid_set[uid_used].uid = uid;
72621+ uid_set[uid_used].expires = expires;
72622+ uid_used++;
72623+
72624+ gr_insertsort();
72625+
72626+ return;
72627+}
72628+
72629+void
72630+gr_remove_uid(const unsigned short loc)
72631+{
72632+ unsigned short i;
72633+
72634+ for (i = loc + 1; i < uid_used; i++)
72635+ uid_set[i - 1] = uid_set[i];
72636+
72637+ uid_used--;
72638+
72639+ return;
72640+}
72641+
72642+int
72643+gr_check_crash_uid(const kuid_t kuid)
72644+{
72645+ int loc;
72646+ int ret = 0;
72647+ uid_t uid;
72648+
72649+ if (unlikely(!gr_acl_is_enabled()))
72650+ return 0;
72651+
72652+ uid = GR_GLOBAL_UID(kuid);
72653+
72654+ spin_lock(&gr_uid_lock);
72655+ loc = gr_find_uid(uid);
72656+
72657+ if (loc < 0)
72658+ goto out_unlock;
72659+
72660+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
72661+ gr_remove_uid(loc);
72662+ else
72663+ ret = 1;
72664+
72665+out_unlock:
72666+ spin_unlock(&gr_uid_lock);
72667+ return ret;
72668+}
72669+
72670+static __inline__ int
72671+proc_is_setxid(const struct cred *cred)
72672+{
72673+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72674+ !uid_eq(cred->uid, cred->fsuid))
72675+ return 1;
72676+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72677+ !gid_eq(cred->gid, cred->fsgid))
72678+ return 1;
72679+
72680+ return 0;
72681+}
72682+
72683+extern int gr_fake_force_sig(int sig, struct task_struct *t);
72684+
72685+void
72686+gr_handle_crash(struct task_struct *task, const int sig)
72687+{
72688+ struct acl_subject_label *curr;
72689+ struct task_struct *tsk, *tsk2;
72690+ const struct cred *cred;
72691+ const struct cred *cred2;
72692+
72693+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72694+ return;
72695+
72696+ if (unlikely(!gr_acl_is_enabled()))
72697+ return;
72698+
72699+ curr = task->acl;
72700+
72701+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
72702+ return;
72703+
72704+ if (time_before_eq(curr->expires, get_seconds())) {
72705+ curr->expires = 0;
72706+ curr->crashes = 0;
72707+ }
72708+
72709+ curr->crashes++;
72710+
72711+ if (!curr->expires)
72712+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72713+
72714+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72715+ time_after(curr->expires, get_seconds())) {
72716+ rcu_read_lock();
72717+ cred = __task_cred(task);
72718+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72719+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72720+ spin_lock(&gr_uid_lock);
72721+ gr_insert_uid(cred->uid, curr->expires);
72722+ spin_unlock(&gr_uid_lock);
72723+ curr->expires = 0;
72724+ curr->crashes = 0;
72725+ read_lock(&tasklist_lock);
72726+ do_each_thread(tsk2, tsk) {
72727+ cred2 = __task_cred(tsk);
72728+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
72729+ gr_fake_force_sig(SIGKILL, tsk);
72730+ } while_each_thread(tsk2, tsk);
72731+ read_unlock(&tasklist_lock);
72732+ } else {
72733+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72734+ read_lock(&tasklist_lock);
72735+ read_lock(&grsec_exec_file_lock);
72736+ do_each_thread(tsk2, tsk) {
72737+ if (likely(tsk != task)) {
72738+ // if this thread has the same subject as the one that triggered
72739+ // RES_CRASH and it's the same binary, kill it
72740+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72741+ gr_fake_force_sig(SIGKILL, tsk);
72742+ }
72743+ } while_each_thread(tsk2, tsk);
72744+ read_unlock(&grsec_exec_file_lock);
72745+ read_unlock(&tasklist_lock);
72746+ }
72747+ rcu_read_unlock();
72748+ }
72749+
72750+ return;
72751+}
72752+
72753+int
72754+gr_check_crash_exec(const struct file *filp)
72755+{
72756+ struct acl_subject_label *curr;
72757+
72758+ if (unlikely(!gr_acl_is_enabled()))
72759+ return 0;
72760+
72761+ read_lock(&gr_inode_lock);
72762+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72763+ __get_dev(filp->f_path.dentry),
72764+ current->role);
72765+ read_unlock(&gr_inode_lock);
72766+
72767+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72768+ (!curr->crashes && !curr->expires))
72769+ return 0;
72770+
72771+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72772+ time_after(curr->expires, get_seconds()))
72773+ return 1;
72774+ else if (time_before_eq(curr->expires, get_seconds())) {
72775+ curr->crashes = 0;
72776+ curr->expires = 0;
72777+ }
72778+
72779+ return 0;
72780+}
72781+
72782+void
72783+gr_handle_alertkill(struct task_struct *task)
72784+{
72785+ struct acl_subject_label *curracl;
72786+ __u32 curr_ip;
72787+ struct task_struct *p, *p2;
72788+
72789+ if (unlikely(!gr_acl_is_enabled()))
72790+ return;
72791+
72792+ curracl = task->acl;
72793+ curr_ip = task->signal->curr_ip;
72794+
72795+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72796+ read_lock(&tasklist_lock);
72797+ do_each_thread(p2, p) {
72798+ if (p->signal->curr_ip == curr_ip)
72799+ gr_fake_force_sig(SIGKILL, p);
72800+ } while_each_thread(p2, p);
72801+ read_unlock(&tasklist_lock);
72802+ } else if (curracl->mode & GR_KILLPROC)
72803+ gr_fake_force_sig(SIGKILL, task);
72804+
72805+ return;
72806+}
72807diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72808new file mode 100644
72809index 0000000..98011b0
72810--- /dev/null
72811+++ b/grsecurity/gracl_shm.c
72812@@ -0,0 +1,40 @@
72813+#include <linux/kernel.h>
72814+#include <linux/mm.h>
72815+#include <linux/sched.h>
72816+#include <linux/file.h>
72817+#include <linux/ipc.h>
72818+#include <linux/gracl.h>
72819+#include <linux/grsecurity.h>
72820+#include <linux/grinternal.h>
72821+
72822+int
72823+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72824+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72825+{
72826+ struct task_struct *task;
72827+
72828+ if (!gr_acl_is_enabled())
72829+ return 1;
72830+
72831+ rcu_read_lock();
72832+ read_lock(&tasklist_lock);
72833+
72834+ task = find_task_by_vpid(shm_cprid);
72835+
72836+ if (unlikely(!task))
72837+ task = find_task_by_vpid(shm_lapid);
72838+
72839+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72840+ (task_pid_nr(task) == shm_lapid)) &&
72841+ (task->acl->mode & GR_PROTSHM) &&
72842+ (task->acl != current->acl))) {
72843+ read_unlock(&tasklist_lock);
72844+ rcu_read_unlock();
72845+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72846+ return 0;
72847+ }
72848+ read_unlock(&tasklist_lock);
72849+ rcu_read_unlock();
72850+
72851+ return 1;
72852+}
72853diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72854new file mode 100644
72855index 0000000..bc0be01
72856--- /dev/null
72857+++ b/grsecurity/grsec_chdir.c
72858@@ -0,0 +1,19 @@
72859+#include <linux/kernel.h>
72860+#include <linux/sched.h>
72861+#include <linux/fs.h>
72862+#include <linux/file.h>
72863+#include <linux/grsecurity.h>
72864+#include <linux/grinternal.h>
72865+
72866+void
72867+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72868+{
72869+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72870+ if ((grsec_enable_chdir && grsec_enable_group &&
72871+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72872+ !grsec_enable_group)) {
72873+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72874+ }
72875+#endif
72876+ return;
72877+}
72878diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72879new file mode 100644
72880index 0000000..651d6c2
72881--- /dev/null
72882+++ b/grsecurity/grsec_chroot.c
72883@@ -0,0 +1,370 @@
72884+#include <linux/kernel.h>
72885+#include <linux/module.h>
72886+#include <linux/sched.h>
72887+#include <linux/file.h>
72888+#include <linux/fs.h>
72889+#include <linux/mount.h>
72890+#include <linux/types.h>
72891+#include "../fs/mount.h"
72892+#include <linux/grsecurity.h>
72893+#include <linux/grinternal.h>
72894+
72895+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72896+int gr_init_ran;
72897+#endif
72898+
72899+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72900+{
72901+#ifdef CONFIG_GRKERNSEC
72902+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72903+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72904+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72905+ && gr_init_ran
72906+#endif
72907+ )
72908+ task->gr_is_chrooted = 1;
72909+ else {
72910+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72911+ if (task_pid_nr(task) == 1 && !gr_init_ran)
72912+ gr_init_ran = 1;
72913+#endif
72914+ task->gr_is_chrooted = 0;
72915+ }
72916+
72917+ task->gr_chroot_dentry = path->dentry;
72918+#endif
72919+ return;
72920+}
72921+
72922+void gr_clear_chroot_entries(struct task_struct *task)
72923+{
72924+#ifdef CONFIG_GRKERNSEC
72925+ task->gr_is_chrooted = 0;
72926+ task->gr_chroot_dentry = NULL;
72927+#endif
72928+ return;
72929+}
72930+
72931+int
72932+gr_handle_chroot_unix(const pid_t pid)
72933+{
72934+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72935+ struct task_struct *p;
72936+
72937+ if (unlikely(!grsec_enable_chroot_unix))
72938+ return 1;
72939+
72940+ if (likely(!proc_is_chrooted(current)))
72941+ return 1;
72942+
72943+ rcu_read_lock();
72944+ read_lock(&tasklist_lock);
72945+ p = find_task_by_vpid_unrestricted(pid);
72946+ if (unlikely(p && !have_same_root(current, p))) {
72947+ read_unlock(&tasklist_lock);
72948+ rcu_read_unlock();
72949+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72950+ return 0;
72951+ }
72952+ read_unlock(&tasklist_lock);
72953+ rcu_read_unlock();
72954+#endif
72955+ return 1;
72956+}
72957+
72958+int
72959+gr_handle_chroot_nice(void)
72960+{
72961+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72962+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72963+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72964+ return -EPERM;
72965+ }
72966+#endif
72967+ return 0;
72968+}
72969+
72970+int
72971+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72972+{
72973+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72974+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72975+ && proc_is_chrooted(current)) {
72976+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72977+ return -EACCES;
72978+ }
72979+#endif
72980+ return 0;
72981+}
72982+
72983+int
72984+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72985+{
72986+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72987+ struct task_struct *p;
72988+ int ret = 0;
72989+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72990+ return ret;
72991+
72992+ read_lock(&tasklist_lock);
72993+ do_each_pid_task(pid, type, p) {
72994+ if (!have_same_root(current, p)) {
72995+ ret = 1;
72996+ goto out;
72997+ }
72998+ } while_each_pid_task(pid, type, p);
72999+out:
73000+ read_unlock(&tasklist_lock);
73001+ return ret;
73002+#endif
73003+ return 0;
73004+}
73005+
73006+int
73007+gr_pid_is_chrooted(struct task_struct *p)
73008+{
73009+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73010+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73011+ return 0;
73012+
73013+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73014+ !have_same_root(current, p)) {
73015+ return 1;
73016+ }
73017+#endif
73018+ return 0;
73019+}
73020+
73021+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73022+
73023+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73024+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73025+{
73026+ struct path path, currentroot;
73027+ int ret = 0;
73028+
73029+ path.dentry = (struct dentry *)u_dentry;
73030+ path.mnt = (struct vfsmount *)u_mnt;
73031+ get_fs_root(current->fs, &currentroot);
73032+ if (path_is_under(&path, &currentroot))
73033+ ret = 1;
73034+ path_put(&currentroot);
73035+
73036+ return ret;
73037+}
73038+#endif
73039+
73040+int
73041+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73042+{
73043+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73044+ if (!grsec_enable_chroot_fchdir)
73045+ return 1;
73046+
73047+ if (!proc_is_chrooted(current))
73048+ return 1;
73049+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73050+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73051+ return 0;
73052+ }
73053+#endif
73054+ return 1;
73055+}
73056+
73057+int
73058+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73059+ const time_t shm_createtime)
73060+{
73061+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73062+ struct task_struct *p;
73063+ time_t starttime;
73064+
73065+ if (unlikely(!grsec_enable_chroot_shmat))
73066+ return 1;
73067+
73068+ if (likely(!proc_is_chrooted(current)))
73069+ return 1;
73070+
73071+ rcu_read_lock();
73072+ read_lock(&tasklist_lock);
73073+
73074+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73075+ starttime = p->start_time.tv_sec;
73076+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73077+ if (have_same_root(current, p)) {
73078+ goto allow;
73079+ } else {
73080+ read_unlock(&tasklist_lock);
73081+ rcu_read_unlock();
73082+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73083+ return 0;
73084+ }
73085+ }
73086+ /* creator exited, pid reuse, fall through to next check */
73087+ }
73088+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73089+ if (unlikely(!have_same_root(current, p))) {
73090+ read_unlock(&tasklist_lock);
73091+ rcu_read_unlock();
73092+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73093+ return 0;
73094+ }
73095+ }
73096+
73097+allow:
73098+ read_unlock(&tasklist_lock);
73099+ rcu_read_unlock();
73100+#endif
73101+ return 1;
73102+}
73103+
73104+void
73105+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73106+{
73107+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73108+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73109+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73110+#endif
73111+ return;
73112+}
73113+
73114+int
73115+gr_handle_chroot_mknod(const struct dentry *dentry,
73116+ const struct vfsmount *mnt, const int mode)
73117+{
73118+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73119+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73120+ proc_is_chrooted(current)) {
73121+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73122+ return -EPERM;
73123+ }
73124+#endif
73125+ return 0;
73126+}
73127+
73128+int
73129+gr_handle_chroot_mount(const struct dentry *dentry,
73130+ const struct vfsmount *mnt, const char *dev_name)
73131+{
73132+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73133+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73134+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73135+ return -EPERM;
73136+ }
73137+#endif
73138+ return 0;
73139+}
73140+
73141+int
73142+gr_handle_chroot_pivot(void)
73143+{
73144+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73145+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73146+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73147+ return -EPERM;
73148+ }
73149+#endif
73150+ return 0;
73151+}
73152+
73153+int
73154+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73155+{
73156+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73157+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73158+ !gr_is_outside_chroot(dentry, mnt)) {
73159+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73160+ return -EPERM;
73161+ }
73162+#endif
73163+ return 0;
73164+}
73165+
73166+extern const char *captab_log[];
73167+extern int captab_log_entries;
73168+
73169+int
73170+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73171+{
73172+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73173+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73174+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73175+ if (cap_raised(chroot_caps, cap)) {
73176+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73177+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73178+ }
73179+ return 0;
73180+ }
73181+ }
73182+#endif
73183+ return 1;
73184+}
73185+
73186+int
73187+gr_chroot_is_capable(const int cap)
73188+{
73189+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73190+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73191+#endif
73192+ return 1;
73193+}
73194+
73195+int
73196+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73197+{
73198+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73199+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73200+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73201+ if (cap_raised(chroot_caps, cap)) {
73202+ return 0;
73203+ }
73204+ }
73205+#endif
73206+ return 1;
73207+}
73208+
73209+int
73210+gr_chroot_is_capable_nolog(const int cap)
73211+{
73212+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73213+ return gr_task_chroot_is_capable_nolog(current, cap);
73214+#endif
73215+ return 1;
73216+}
73217+
73218+int
73219+gr_handle_chroot_sysctl(const int op)
73220+{
73221+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73222+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73223+ proc_is_chrooted(current))
73224+ return -EACCES;
73225+#endif
73226+ return 0;
73227+}
73228+
73229+void
73230+gr_handle_chroot_chdir(const struct path *path)
73231+{
73232+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73233+ if (grsec_enable_chroot_chdir)
73234+ set_fs_pwd(current->fs, path);
73235+#endif
73236+ return;
73237+}
73238+
73239+int
73240+gr_handle_chroot_chmod(const struct dentry *dentry,
73241+ const struct vfsmount *mnt, const int mode)
73242+{
73243+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73244+ /* allow chmod +s on directories, but not files */
73245+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73246+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73247+ proc_is_chrooted(current)) {
73248+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73249+ return -EPERM;
73250+ }
73251+#endif
73252+ return 0;
73253+}
73254diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73255new file mode 100644
73256index 0000000..4d6fce8
73257--- /dev/null
73258+++ b/grsecurity/grsec_disabled.c
73259@@ -0,0 +1,433 @@
73260+#include <linux/kernel.h>
73261+#include <linux/module.h>
73262+#include <linux/sched.h>
73263+#include <linux/file.h>
73264+#include <linux/fs.h>
73265+#include <linux/kdev_t.h>
73266+#include <linux/net.h>
73267+#include <linux/in.h>
73268+#include <linux/ip.h>
73269+#include <linux/skbuff.h>
73270+#include <linux/sysctl.h>
73271+
73272+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73273+void
73274+pax_set_initial_flags(struct linux_binprm *bprm)
73275+{
73276+ return;
73277+}
73278+#endif
73279+
73280+#ifdef CONFIG_SYSCTL
73281+__u32
73282+gr_handle_sysctl(const struct ctl_table * table, const int op)
73283+{
73284+ return 0;
73285+}
73286+#endif
73287+
73288+#ifdef CONFIG_TASKSTATS
73289+int gr_is_taskstats_denied(int pid)
73290+{
73291+ return 0;
73292+}
73293+#endif
73294+
73295+int
73296+gr_acl_is_enabled(void)
73297+{
73298+ return 0;
73299+}
73300+
73301+void
73302+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73303+{
73304+ return;
73305+}
73306+
73307+int
73308+gr_handle_rawio(const struct inode *inode)
73309+{
73310+ return 0;
73311+}
73312+
73313+void
73314+gr_acl_handle_psacct(struct task_struct *task, const long code)
73315+{
73316+ return;
73317+}
73318+
73319+int
73320+gr_handle_ptrace(struct task_struct *task, const long request)
73321+{
73322+ return 0;
73323+}
73324+
73325+int
73326+gr_handle_proc_ptrace(struct task_struct *task)
73327+{
73328+ return 0;
73329+}
73330+
73331+int
73332+gr_set_acls(const int type)
73333+{
73334+ return 0;
73335+}
73336+
73337+int
73338+gr_check_hidden_task(const struct task_struct *tsk)
73339+{
73340+ return 0;
73341+}
73342+
73343+int
73344+gr_check_protected_task(const struct task_struct *task)
73345+{
73346+ return 0;
73347+}
73348+
73349+int
73350+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73351+{
73352+ return 0;
73353+}
73354+
73355+void
73356+gr_copy_label(struct task_struct *tsk)
73357+{
73358+ return;
73359+}
73360+
73361+void
73362+gr_set_pax_flags(struct task_struct *task)
73363+{
73364+ return;
73365+}
73366+
73367+int
73368+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73369+ const int unsafe_share)
73370+{
73371+ return 0;
73372+}
73373+
73374+void
73375+gr_handle_delete(const ino_t ino, const dev_t dev)
73376+{
73377+ return;
73378+}
73379+
73380+void
73381+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73382+{
73383+ return;
73384+}
73385+
73386+void
73387+gr_handle_crash(struct task_struct *task, const int sig)
73388+{
73389+ return;
73390+}
73391+
73392+int
73393+gr_check_crash_exec(const struct file *filp)
73394+{
73395+ return 0;
73396+}
73397+
73398+int
73399+gr_check_crash_uid(const kuid_t uid)
73400+{
73401+ return 0;
73402+}
73403+
73404+void
73405+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73406+ struct dentry *old_dentry,
73407+ struct dentry *new_dentry,
73408+ struct vfsmount *mnt, const __u8 replace)
73409+{
73410+ return;
73411+}
73412+
73413+int
73414+gr_search_socket(const int family, const int type, const int protocol)
73415+{
73416+ return 1;
73417+}
73418+
73419+int
73420+gr_search_connectbind(const int mode, const struct socket *sock,
73421+ const struct sockaddr_in *addr)
73422+{
73423+ return 0;
73424+}
73425+
73426+void
73427+gr_handle_alertkill(struct task_struct *task)
73428+{
73429+ return;
73430+}
73431+
73432+__u32
73433+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73434+{
73435+ return 1;
73436+}
73437+
73438+__u32
73439+gr_acl_handle_hidden_file(const struct dentry * dentry,
73440+ const struct vfsmount * mnt)
73441+{
73442+ return 1;
73443+}
73444+
73445+__u32
73446+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73447+ int acc_mode)
73448+{
73449+ return 1;
73450+}
73451+
73452+__u32
73453+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73454+{
73455+ return 1;
73456+}
73457+
73458+__u32
73459+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73460+{
73461+ return 1;
73462+}
73463+
73464+int
73465+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73466+ unsigned int *vm_flags)
73467+{
73468+ return 1;
73469+}
73470+
73471+__u32
73472+gr_acl_handle_truncate(const struct dentry * dentry,
73473+ const struct vfsmount * mnt)
73474+{
73475+ return 1;
73476+}
73477+
73478+__u32
73479+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73480+{
73481+ return 1;
73482+}
73483+
73484+__u32
73485+gr_acl_handle_access(const struct dentry * dentry,
73486+ const struct vfsmount * mnt, const int fmode)
73487+{
73488+ return 1;
73489+}
73490+
73491+__u32
73492+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73493+ umode_t *mode)
73494+{
73495+ return 1;
73496+}
73497+
73498+__u32
73499+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73500+{
73501+ return 1;
73502+}
73503+
73504+__u32
73505+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73506+{
73507+ return 1;
73508+}
73509+
73510+__u32
73511+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73512+{
73513+ return 1;
73514+}
73515+
73516+void
73517+grsecurity_init(void)
73518+{
73519+ return;
73520+}
73521+
73522+umode_t gr_acl_umask(void)
73523+{
73524+ return 0;
73525+}
73526+
73527+__u32
73528+gr_acl_handle_mknod(const struct dentry * new_dentry,
73529+ const struct dentry * parent_dentry,
73530+ const struct vfsmount * parent_mnt,
73531+ const int mode)
73532+{
73533+ return 1;
73534+}
73535+
73536+__u32
73537+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73538+ const struct dentry * parent_dentry,
73539+ const struct vfsmount * parent_mnt)
73540+{
73541+ return 1;
73542+}
73543+
73544+__u32
73545+gr_acl_handle_symlink(const struct dentry * new_dentry,
73546+ const struct dentry * parent_dentry,
73547+ const struct vfsmount * parent_mnt, const struct filename *from)
73548+{
73549+ return 1;
73550+}
73551+
73552+__u32
73553+gr_acl_handle_link(const struct dentry * new_dentry,
73554+ const struct dentry * parent_dentry,
73555+ const struct vfsmount * parent_mnt,
73556+ const struct dentry * old_dentry,
73557+ const struct vfsmount * old_mnt, const struct filename *to)
73558+{
73559+ return 1;
73560+}
73561+
73562+int
73563+gr_acl_handle_rename(const struct dentry *new_dentry,
73564+ const struct dentry *parent_dentry,
73565+ const struct vfsmount *parent_mnt,
73566+ const struct dentry *old_dentry,
73567+ const struct inode *old_parent_inode,
73568+ const struct vfsmount *old_mnt, const struct filename *newname)
73569+{
73570+ return 0;
73571+}
73572+
73573+int
73574+gr_acl_handle_filldir(const struct file *file, const char *name,
73575+ const int namelen, const ino_t ino)
73576+{
73577+ return 1;
73578+}
73579+
73580+int
73581+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73582+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73583+{
73584+ return 1;
73585+}
73586+
73587+int
73588+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73589+{
73590+ return 0;
73591+}
73592+
73593+int
73594+gr_search_accept(const struct socket *sock)
73595+{
73596+ return 0;
73597+}
73598+
73599+int
73600+gr_search_listen(const struct socket *sock)
73601+{
73602+ return 0;
73603+}
73604+
73605+int
73606+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73607+{
73608+ return 0;
73609+}
73610+
73611+__u32
73612+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73613+{
73614+ return 1;
73615+}
73616+
73617+__u32
73618+gr_acl_handle_creat(const struct dentry * dentry,
73619+ const struct dentry * p_dentry,
73620+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73621+ const int imode)
73622+{
73623+ return 1;
73624+}
73625+
73626+void
73627+gr_acl_handle_exit(void)
73628+{
73629+ return;
73630+}
73631+
73632+int
73633+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73634+{
73635+ return 1;
73636+}
73637+
73638+void
73639+gr_set_role_label(const kuid_t uid, const kgid_t gid)
73640+{
73641+ return;
73642+}
73643+
73644+int
73645+gr_acl_handle_procpidmem(const struct task_struct *task)
73646+{
73647+ return 0;
73648+}
73649+
73650+int
73651+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73652+{
73653+ return 0;
73654+}
73655+
73656+int
73657+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73658+{
73659+ return 0;
73660+}
73661+
73662+int
73663+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73664+{
73665+ return 0;
73666+}
73667+
73668+int
73669+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73670+{
73671+ return 0;
73672+}
73673+
73674+int gr_acl_enable_at_secure(void)
73675+{
73676+ return 0;
73677+}
73678+
73679+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73680+{
73681+ return dentry->d_sb->s_dev;
73682+}
73683+
73684+void gr_put_exec_file(struct task_struct *task)
73685+{
73686+ return;
73687+}
73688+
73689+#ifdef CONFIG_SECURITY
73690+EXPORT_SYMBOL_GPL(gr_check_user_change);
73691+EXPORT_SYMBOL_GPL(gr_check_group_change);
73692+#endif
73693diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73694new file mode 100644
73695index 0000000..f35f454
73696--- /dev/null
73697+++ b/grsecurity/grsec_exec.c
73698@@ -0,0 +1,187 @@
73699+#include <linux/kernel.h>
73700+#include <linux/sched.h>
73701+#include <linux/file.h>
73702+#include <linux/binfmts.h>
73703+#include <linux/fs.h>
73704+#include <linux/types.h>
73705+#include <linux/grdefs.h>
73706+#include <linux/grsecurity.h>
73707+#include <linux/grinternal.h>
73708+#include <linux/capability.h>
73709+#include <linux/module.h>
73710+#include <linux/compat.h>
73711+
73712+#include <asm/uaccess.h>
73713+
73714+#ifdef CONFIG_GRKERNSEC_EXECLOG
73715+static char gr_exec_arg_buf[132];
73716+static DEFINE_MUTEX(gr_exec_arg_mutex);
73717+#endif
73718+
73719+struct user_arg_ptr {
73720+#ifdef CONFIG_COMPAT
73721+ bool is_compat;
73722+#endif
73723+ union {
73724+ const char __user *const __user *native;
73725+#ifdef CONFIG_COMPAT
73726+ const compat_uptr_t __user *compat;
73727+#endif
73728+ } ptr;
73729+};
73730+
73731+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73732+
73733+void
73734+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73735+{
73736+#ifdef CONFIG_GRKERNSEC_EXECLOG
73737+ char *grarg = gr_exec_arg_buf;
73738+ unsigned int i, x, execlen = 0;
73739+ char c;
73740+
73741+ if (!((grsec_enable_execlog && grsec_enable_group &&
73742+ in_group_p(grsec_audit_gid))
73743+ || (grsec_enable_execlog && !grsec_enable_group)))
73744+ return;
73745+
73746+ mutex_lock(&gr_exec_arg_mutex);
73747+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
73748+
73749+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
73750+ const char __user *p;
73751+ unsigned int len;
73752+
73753+ p = get_user_arg_ptr(argv, i);
73754+ if (IS_ERR(p))
73755+ goto log;
73756+
73757+ len = strnlen_user(p, 128 - execlen);
73758+ if (len > 128 - execlen)
73759+ len = 128 - execlen;
73760+ else if (len > 0)
73761+ len--;
73762+ if (copy_from_user(grarg + execlen, p, len))
73763+ goto log;
73764+
73765+ /* rewrite unprintable characters */
73766+ for (x = 0; x < len; x++) {
73767+ c = *(grarg + execlen + x);
73768+ if (c < 32 || c > 126)
73769+ *(grarg + execlen + x) = ' ';
73770+ }
73771+
73772+ execlen += len;
73773+ *(grarg + execlen) = ' ';
73774+ *(grarg + execlen + 1) = '\0';
73775+ execlen++;
73776+ }
73777+
73778+ log:
73779+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73780+ bprm->file->f_path.mnt, grarg);
73781+ mutex_unlock(&gr_exec_arg_mutex);
73782+#endif
73783+ return;
73784+}
73785+
73786+#ifdef CONFIG_GRKERNSEC
73787+extern int gr_acl_is_capable(const int cap);
73788+extern int gr_acl_is_capable_nolog(const int cap);
73789+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73790+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73791+extern int gr_chroot_is_capable(const int cap);
73792+extern int gr_chroot_is_capable_nolog(const int cap);
73793+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73794+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73795+#endif
73796+
73797+const char *captab_log[] = {
73798+ "CAP_CHOWN",
73799+ "CAP_DAC_OVERRIDE",
73800+ "CAP_DAC_READ_SEARCH",
73801+ "CAP_FOWNER",
73802+ "CAP_FSETID",
73803+ "CAP_KILL",
73804+ "CAP_SETGID",
73805+ "CAP_SETUID",
73806+ "CAP_SETPCAP",
73807+ "CAP_LINUX_IMMUTABLE",
73808+ "CAP_NET_BIND_SERVICE",
73809+ "CAP_NET_BROADCAST",
73810+ "CAP_NET_ADMIN",
73811+ "CAP_NET_RAW",
73812+ "CAP_IPC_LOCK",
73813+ "CAP_IPC_OWNER",
73814+ "CAP_SYS_MODULE",
73815+ "CAP_SYS_RAWIO",
73816+ "CAP_SYS_CHROOT",
73817+ "CAP_SYS_PTRACE",
73818+ "CAP_SYS_PACCT",
73819+ "CAP_SYS_ADMIN",
73820+ "CAP_SYS_BOOT",
73821+ "CAP_SYS_NICE",
73822+ "CAP_SYS_RESOURCE",
73823+ "CAP_SYS_TIME",
73824+ "CAP_SYS_TTY_CONFIG",
73825+ "CAP_MKNOD",
73826+ "CAP_LEASE",
73827+ "CAP_AUDIT_WRITE",
73828+ "CAP_AUDIT_CONTROL",
73829+ "CAP_SETFCAP",
73830+ "CAP_MAC_OVERRIDE",
73831+ "CAP_MAC_ADMIN",
73832+ "CAP_SYSLOG",
73833+ "CAP_WAKE_ALARM"
73834+};
73835+
73836+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73837+
73838+int gr_is_capable(const int cap)
73839+{
73840+#ifdef CONFIG_GRKERNSEC
73841+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73842+ return 1;
73843+ return 0;
73844+#else
73845+ return 1;
73846+#endif
73847+}
73848+
73849+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73850+{
73851+#ifdef CONFIG_GRKERNSEC
73852+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73853+ return 1;
73854+ return 0;
73855+#else
73856+ return 1;
73857+#endif
73858+}
73859+
73860+int gr_is_capable_nolog(const int cap)
73861+{
73862+#ifdef CONFIG_GRKERNSEC
73863+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73864+ return 1;
73865+ return 0;
73866+#else
73867+ return 1;
73868+#endif
73869+}
73870+
73871+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73872+{
73873+#ifdef CONFIG_GRKERNSEC
73874+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73875+ return 1;
73876+ return 0;
73877+#else
73878+ return 1;
73879+#endif
73880+}
73881+
73882+EXPORT_SYMBOL_GPL(gr_is_capable);
73883+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73884+EXPORT_SYMBOL_GPL(gr_task_is_capable);
73885+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73886diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73887new file mode 100644
73888index 0000000..06cc6ea
73889--- /dev/null
73890+++ b/grsecurity/grsec_fifo.c
73891@@ -0,0 +1,24 @@
73892+#include <linux/kernel.h>
73893+#include <linux/sched.h>
73894+#include <linux/fs.h>
73895+#include <linux/file.h>
73896+#include <linux/grinternal.h>
73897+
73898+int
73899+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73900+ const struct dentry *dir, const int flag, const int acc_mode)
73901+{
73902+#ifdef CONFIG_GRKERNSEC_FIFO
73903+ const struct cred *cred = current_cred();
73904+
73905+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73906+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73907+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73908+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73909+ if (!inode_permission(dentry->d_inode, acc_mode))
73910+ 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));
73911+ return -EACCES;
73912+ }
73913+#endif
73914+ return 0;
73915+}
73916diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73917new file mode 100644
73918index 0000000..8ca18bf
73919--- /dev/null
73920+++ b/grsecurity/grsec_fork.c
73921@@ -0,0 +1,23 @@
73922+#include <linux/kernel.h>
73923+#include <linux/sched.h>
73924+#include <linux/grsecurity.h>
73925+#include <linux/grinternal.h>
73926+#include <linux/errno.h>
73927+
73928+void
73929+gr_log_forkfail(const int retval)
73930+{
73931+#ifdef CONFIG_GRKERNSEC_FORKFAIL
73932+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73933+ switch (retval) {
73934+ case -EAGAIN:
73935+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73936+ break;
73937+ case -ENOMEM:
73938+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73939+ break;
73940+ }
73941+ }
73942+#endif
73943+ return;
73944+}
73945diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73946new file mode 100644
73947index 0000000..ae6c028
73948--- /dev/null
73949+++ b/grsecurity/grsec_init.c
73950@@ -0,0 +1,272 @@
73951+#include <linux/kernel.h>
73952+#include <linux/sched.h>
73953+#include <linux/mm.h>
73954+#include <linux/gracl.h>
73955+#include <linux/slab.h>
73956+#include <linux/vmalloc.h>
73957+#include <linux/percpu.h>
73958+#include <linux/module.h>
73959+
73960+int grsec_enable_ptrace_readexec;
73961+int grsec_enable_setxid;
73962+int grsec_enable_symlinkown;
73963+kgid_t grsec_symlinkown_gid;
73964+int grsec_enable_brute;
73965+int grsec_enable_link;
73966+int grsec_enable_dmesg;
73967+int grsec_enable_harden_ptrace;
73968+int grsec_enable_harden_ipc;
73969+int grsec_enable_fifo;
73970+int grsec_enable_execlog;
73971+int grsec_enable_signal;
73972+int grsec_enable_forkfail;
73973+int grsec_enable_audit_ptrace;
73974+int grsec_enable_time;
73975+int grsec_enable_group;
73976+kgid_t grsec_audit_gid;
73977+int grsec_enable_chdir;
73978+int grsec_enable_mount;
73979+int grsec_enable_rofs;
73980+int grsec_deny_new_usb;
73981+int grsec_enable_chroot_findtask;
73982+int grsec_enable_chroot_mount;
73983+int grsec_enable_chroot_shmat;
73984+int grsec_enable_chroot_fchdir;
73985+int grsec_enable_chroot_double;
73986+int grsec_enable_chroot_pivot;
73987+int grsec_enable_chroot_chdir;
73988+int grsec_enable_chroot_chmod;
73989+int grsec_enable_chroot_mknod;
73990+int grsec_enable_chroot_nice;
73991+int grsec_enable_chroot_execlog;
73992+int grsec_enable_chroot_caps;
73993+int grsec_enable_chroot_sysctl;
73994+int grsec_enable_chroot_unix;
73995+int grsec_enable_tpe;
73996+kgid_t grsec_tpe_gid;
73997+int grsec_enable_blackhole;
73998+#ifdef CONFIG_IPV6_MODULE
73999+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74000+#endif
74001+int grsec_lastack_retries;
74002+int grsec_enable_tpe_all;
74003+int grsec_enable_tpe_invert;
74004+int grsec_enable_socket_all;
74005+kgid_t grsec_socket_all_gid;
74006+int grsec_enable_socket_client;
74007+kgid_t grsec_socket_client_gid;
74008+int grsec_enable_socket_server;
74009+kgid_t grsec_socket_server_gid;
74010+int grsec_resource_logging;
74011+int grsec_disable_privio;
74012+int grsec_enable_log_rwxmaps;
74013+int grsec_lock;
74014+
74015+DEFINE_SPINLOCK(grsec_alert_lock);
74016+unsigned long grsec_alert_wtime = 0;
74017+unsigned long grsec_alert_fyet = 0;
74018+
74019+DEFINE_SPINLOCK(grsec_audit_lock);
74020+
74021+DEFINE_RWLOCK(grsec_exec_file_lock);
74022+
74023+char *gr_shared_page[4];
74024+
74025+char *gr_alert_log_fmt;
74026+char *gr_audit_log_fmt;
74027+char *gr_alert_log_buf;
74028+char *gr_audit_log_buf;
74029+
74030+void __init
74031+grsecurity_init(void)
74032+{
74033+ int j;
74034+ /* create the per-cpu shared pages */
74035+
74036+#ifdef CONFIG_X86
74037+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74038+#endif
74039+
74040+ for (j = 0; j < 4; j++) {
74041+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74042+ if (gr_shared_page[j] == NULL) {
74043+ panic("Unable to allocate grsecurity shared page");
74044+ return;
74045+ }
74046+ }
74047+
74048+ /* allocate log buffers */
74049+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74050+ if (!gr_alert_log_fmt) {
74051+ panic("Unable to allocate grsecurity alert log format buffer");
74052+ return;
74053+ }
74054+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74055+ if (!gr_audit_log_fmt) {
74056+ panic("Unable to allocate grsecurity audit log format buffer");
74057+ return;
74058+ }
74059+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74060+ if (!gr_alert_log_buf) {
74061+ panic("Unable to allocate grsecurity alert log buffer");
74062+ return;
74063+ }
74064+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74065+ if (!gr_audit_log_buf) {
74066+ panic("Unable to allocate grsecurity audit log buffer");
74067+ return;
74068+ }
74069+
74070+#ifdef CONFIG_GRKERNSEC_IO
74071+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74072+ grsec_disable_privio = 1;
74073+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74074+ grsec_disable_privio = 1;
74075+#else
74076+ grsec_disable_privio = 0;
74077+#endif
74078+#endif
74079+
74080+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74081+ /* for backward compatibility, tpe_invert always defaults to on if
74082+ enabled in the kernel
74083+ */
74084+ grsec_enable_tpe_invert = 1;
74085+#endif
74086+
74087+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74088+#ifndef CONFIG_GRKERNSEC_SYSCTL
74089+ grsec_lock = 1;
74090+#endif
74091+
74092+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74093+ grsec_enable_log_rwxmaps = 1;
74094+#endif
74095+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74096+ grsec_enable_group = 1;
74097+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74098+#endif
74099+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74100+ grsec_enable_ptrace_readexec = 1;
74101+#endif
74102+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74103+ grsec_enable_chdir = 1;
74104+#endif
74105+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74106+ grsec_enable_harden_ptrace = 1;
74107+#endif
74108+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74109+ grsec_enable_harden_ipc = 1;
74110+#endif
74111+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74112+ grsec_enable_mount = 1;
74113+#endif
74114+#ifdef CONFIG_GRKERNSEC_LINK
74115+ grsec_enable_link = 1;
74116+#endif
74117+#ifdef CONFIG_GRKERNSEC_BRUTE
74118+ grsec_enable_brute = 1;
74119+#endif
74120+#ifdef CONFIG_GRKERNSEC_DMESG
74121+ grsec_enable_dmesg = 1;
74122+#endif
74123+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74124+ grsec_enable_blackhole = 1;
74125+ grsec_lastack_retries = 4;
74126+#endif
74127+#ifdef CONFIG_GRKERNSEC_FIFO
74128+ grsec_enable_fifo = 1;
74129+#endif
74130+#ifdef CONFIG_GRKERNSEC_EXECLOG
74131+ grsec_enable_execlog = 1;
74132+#endif
74133+#ifdef CONFIG_GRKERNSEC_SETXID
74134+ grsec_enable_setxid = 1;
74135+#endif
74136+#ifdef CONFIG_GRKERNSEC_SIGNAL
74137+ grsec_enable_signal = 1;
74138+#endif
74139+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74140+ grsec_enable_forkfail = 1;
74141+#endif
74142+#ifdef CONFIG_GRKERNSEC_TIME
74143+ grsec_enable_time = 1;
74144+#endif
74145+#ifdef CONFIG_GRKERNSEC_RESLOG
74146+ grsec_resource_logging = 1;
74147+#endif
74148+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74149+ grsec_enable_chroot_findtask = 1;
74150+#endif
74151+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74152+ grsec_enable_chroot_unix = 1;
74153+#endif
74154+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74155+ grsec_enable_chroot_mount = 1;
74156+#endif
74157+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74158+ grsec_enable_chroot_fchdir = 1;
74159+#endif
74160+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74161+ grsec_enable_chroot_shmat = 1;
74162+#endif
74163+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74164+ grsec_enable_audit_ptrace = 1;
74165+#endif
74166+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74167+ grsec_enable_chroot_double = 1;
74168+#endif
74169+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74170+ grsec_enable_chroot_pivot = 1;
74171+#endif
74172+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74173+ grsec_enable_chroot_chdir = 1;
74174+#endif
74175+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74176+ grsec_enable_chroot_chmod = 1;
74177+#endif
74178+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74179+ grsec_enable_chroot_mknod = 1;
74180+#endif
74181+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74182+ grsec_enable_chroot_nice = 1;
74183+#endif
74184+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74185+ grsec_enable_chroot_execlog = 1;
74186+#endif
74187+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74188+ grsec_enable_chroot_caps = 1;
74189+#endif
74190+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74191+ grsec_enable_chroot_sysctl = 1;
74192+#endif
74193+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74194+ grsec_enable_symlinkown = 1;
74195+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74196+#endif
74197+#ifdef CONFIG_GRKERNSEC_TPE
74198+ grsec_enable_tpe = 1;
74199+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74200+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74201+ grsec_enable_tpe_all = 1;
74202+#endif
74203+#endif
74204+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74205+ grsec_enable_socket_all = 1;
74206+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74207+#endif
74208+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74209+ grsec_enable_socket_client = 1;
74210+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74211+#endif
74212+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74213+ grsec_enable_socket_server = 1;
74214+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74215+#endif
74216+#endif
74217+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74218+ grsec_deny_new_usb = 1;
74219+#endif
74220+
74221+ return;
74222+}
74223diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74224new file mode 100644
74225index 0000000..1773300
74226--- /dev/null
74227+++ b/grsecurity/grsec_ipc.c
74228@@ -0,0 +1,48 @@
74229+#include <linux/kernel.h>
74230+#include <linux/mm.h>
74231+#include <linux/sched.h>
74232+#include <linux/file.h>
74233+#include <linux/ipc.h>
74234+#include <linux/ipc_namespace.h>
74235+#include <linux/grsecurity.h>
74236+#include <linux/grinternal.h>
74237+
74238+int
74239+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74240+{
74241+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74242+ int write;
74243+ int orig_granted_mode;
74244+ kuid_t euid;
74245+ kgid_t egid;
74246+
74247+ if (!grsec_enable_harden_ipc)
74248+ return 1;
74249+
74250+ euid = current_euid();
74251+ egid = current_egid();
74252+
74253+ write = requested_mode & 00002;
74254+ orig_granted_mode = ipcp->mode;
74255+
74256+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74257+ orig_granted_mode >>= 6;
74258+ else {
74259+ /* if likely wrong permissions, lock to user */
74260+ if (orig_granted_mode & 0007)
74261+ orig_granted_mode = 0;
74262+ /* otherwise do a egid-only check */
74263+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74264+ orig_granted_mode >>= 3;
74265+ /* otherwise, no access */
74266+ else
74267+ orig_granted_mode = 0;
74268+ }
74269+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74270+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74271+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74272+ return 0;
74273+ }
74274+#endif
74275+ return 1;
74276+}
74277diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74278new file mode 100644
74279index 0000000..5e05e20
74280--- /dev/null
74281+++ b/grsecurity/grsec_link.c
74282@@ -0,0 +1,58 @@
74283+#include <linux/kernel.h>
74284+#include <linux/sched.h>
74285+#include <linux/fs.h>
74286+#include <linux/file.h>
74287+#include <linux/grinternal.h>
74288+
74289+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74290+{
74291+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74292+ const struct inode *link_inode = link->dentry->d_inode;
74293+
74294+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74295+ /* ignore root-owned links, e.g. /proc/self */
74296+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74297+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74298+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74299+ return 1;
74300+ }
74301+#endif
74302+ return 0;
74303+}
74304+
74305+int
74306+gr_handle_follow_link(const struct inode *parent,
74307+ const struct inode *inode,
74308+ const struct dentry *dentry, const struct vfsmount *mnt)
74309+{
74310+#ifdef CONFIG_GRKERNSEC_LINK
74311+ const struct cred *cred = current_cred();
74312+
74313+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74314+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74315+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74316+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74317+ return -EACCES;
74318+ }
74319+#endif
74320+ return 0;
74321+}
74322+
74323+int
74324+gr_handle_hardlink(const struct dentry *dentry,
74325+ const struct vfsmount *mnt,
74326+ struct inode *inode, const int mode, const struct filename *to)
74327+{
74328+#ifdef CONFIG_GRKERNSEC_LINK
74329+ const struct cred *cred = current_cred();
74330+
74331+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74332+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74333+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74334+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74335+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74336+ return -EPERM;
74337+ }
74338+#endif
74339+ return 0;
74340+}
74341diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74342new file mode 100644
74343index 0000000..dbe0a6b
74344--- /dev/null
74345+++ b/grsecurity/grsec_log.c
74346@@ -0,0 +1,341 @@
74347+#include <linux/kernel.h>
74348+#include <linux/sched.h>
74349+#include <linux/file.h>
74350+#include <linux/tty.h>
74351+#include <linux/fs.h>
74352+#include <linux/mm.h>
74353+#include <linux/grinternal.h>
74354+
74355+#ifdef CONFIG_TREE_PREEMPT_RCU
74356+#define DISABLE_PREEMPT() preempt_disable()
74357+#define ENABLE_PREEMPT() preempt_enable()
74358+#else
74359+#define DISABLE_PREEMPT()
74360+#define ENABLE_PREEMPT()
74361+#endif
74362+
74363+#define BEGIN_LOCKS(x) \
74364+ DISABLE_PREEMPT(); \
74365+ rcu_read_lock(); \
74366+ read_lock(&tasklist_lock); \
74367+ read_lock(&grsec_exec_file_lock); \
74368+ if (x != GR_DO_AUDIT) \
74369+ spin_lock(&grsec_alert_lock); \
74370+ else \
74371+ spin_lock(&grsec_audit_lock)
74372+
74373+#define END_LOCKS(x) \
74374+ if (x != GR_DO_AUDIT) \
74375+ spin_unlock(&grsec_alert_lock); \
74376+ else \
74377+ spin_unlock(&grsec_audit_lock); \
74378+ read_unlock(&grsec_exec_file_lock); \
74379+ read_unlock(&tasklist_lock); \
74380+ rcu_read_unlock(); \
74381+ ENABLE_PREEMPT(); \
74382+ if (x == GR_DONT_AUDIT) \
74383+ gr_handle_alertkill(current)
74384+
74385+enum {
74386+ FLOODING,
74387+ NO_FLOODING
74388+};
74389+
74390+extern char *gr_alert_log_fmt;
74391+extern char *gr_audit_log_fmt;
74392+extern char *gr_alert_log_buf;
74393+extern char *gr_audit_log_buf;
74394+
74395+static int gr_log_start(int audit)
74396+{
74397+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74398+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74399+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74400+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74401+ unsigned long curr_secs = get_seconds();
74402+
74403+ if (audit == GR_DO_AUDIT)
74404+ goto set_fmt;
74405+
74406+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74407+ grsec_alert_wtime = curr_secs;
74408+ grsec_alert_fyet = 0;
74409+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74410+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74411+ grsec_alert_fyet++;
74412+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74413+ grsec_alert_wtime = curr_secs;
74414+ grsec_alert_fyet++;
74415+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74416+ return FLOODING;
74417+ }
74418+ else return FLOODING;
74419+
74420+set_fmt:
74421+#endif
74422+ memset(buf, 0, PAGE_SIZE);
74423+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74424+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74425+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74426+ } else if (current->signal->curr_ip) {
74427+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74428+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74429+ } else if (gr_acl_is_enabled()) {
74430+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74431+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74432+ } else {
74433+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74434+ strcpy(buf, fmt);
74435+ }
74436+
74437+ return NO_FLOODING;
74438+}
74439+
74440+static void gr_log_middle(int audit, const char *msg, va_list ap)
74441+ __attribute__ ((format (printf, 2, 0)));
74442+
74443+static void gr_log_middle(int audit, const char *msg, va_list ap)
74444+{
74445+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74446+ unsigned int len = strlen(buf);
74447+
74448+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74449+
74450+ return;
74451+}
74452+
74453+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74454+ __attribute__ ((format (printf, 2, 3)));
74455+
74456+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74457+{
74458+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74459+ unsigned int len = strlen(buf);
74460+ va_list ap;
74461+
74462+ va_start(ap, msg);
74463+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74464+ va_end(ap);
74465+
74466+ return;
74467+}
74468+
74469+static void gr_log_end(int audit, int append_default)
74470+{
74471+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74472+ if (append_default) {
74473+ struct task_struct *task = current;
74474+ struct task_struct *parent = task->real_parent;
74475+ const struct cred *cred = __task_cred(task);
74476+ const struct cred *pcred = __task_cred(parent);
74477+ unsigned int len = strlen(buf);
74478+
74479+ 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));
74480+ }
74481+
74482+ printk("%s\n", buf);
74483+
74484+ return;
74485+}
74486+
74487+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74488+{
74489+ int logtype;
74490+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74491+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74492+ void *voidptr = NULL;
74493+ int num1 = 0, num2 = 0;
74494+ unsigned long ulong1 = 0, ulong2 = 0;
74495+ struct dentry *dentry = NULL;
74496+ struct vfsmount *mnt = NULL;
74497+ struct file *file = NULL;
74498+ struct task_struct *task = NULL;
74499+ struct vm_area_struct *vma = NULL;
74500+ const struct cred *cred, *pcred;
74501+ va_list ap;
74502+
74503+ BEGIN_LOCKS(audit);
74504+ logtype = gr_log_start(audit);
74505+ if (logtype == FLOODING) {
74506+ END_LOCKS(audit);
74507+ return;
74508+ }
74509+ va_start(ap, argtypes);
74510+ switch (argtypes) {
74511+ case GR_TTYSNIFF:
74512+ task = va_arg(ap, struct task_struct *);
74513+ 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));
74514+ break;
74515+ case GR_SYSCTL_HIDDEN:
74516+ str1 = va_arg(ap, char *);
74517+ gr_log_middle_varargs(audit, msg, result, str1);
74518+ break;
74519+ case GR_RBAC:
74520+ dentry = va_arg(ap, struct dentry *);
74521+ mnt = va_arg(ap, struct vfsmount *);
74522+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74523+ break;
74524+ case GR_RBAC_STR:
74525+ dentry = va_arg(ap, struct dentry *);
74526+ mnt = va_arg(ap, struct vfsmount *);
74527+ str1 = va_arg(ap, char *);
74528+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74529+ break;
74530+ case GR_STR_RBAC:
74531+ str1 = va_arg(ap, char *);
74532+ dentry = va_arg(ap, struct dentry *);
74533+ mnt = va_arg(ap, struct vfsmount *);
74534+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74535+ break;
74536+ case GR_RBAC_MODE2:
74537+ dentry = va_arg(ap, struct dentry *);
74538+ mnt = va_arg(ap, struct vfsmount *);
74539+ str1 = va_arg(ap, char *);
74540+ str2 = va_arg(ap, char *);
74541+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74542+ break;
74543+ case GR_RBAC_MODE3:
74544+ dentry = va_arg(ap, struct dentry *);
74545+ mnt = va_arg(ap, struct vfsmount *);
74546+ str1 = va_arg(ap, char *);
74547+ str2 = va_arg(ap, char *);
74548+ str3 = va_arg(ap, char *);
74549+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74550+ break;
74551+ case GR_FILENAME:
74552+ dentry = va_arg(ap, struct dentry *);
74553+ mnt = va_arg(ap, struct vfsmount *);
74554+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74555+ break;
74556+ case GR_STR_FILENAME:
74557+ str1 = va_arg(ap, char *);
74558+ dentry = va_arg(ap, struct dentry *);
74559+ mnt = va_arg(ap, struct vfsmount *);
74560+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74561+ break;
74562+ case GR_FILENAME_STR:
74563+ dentry = va_arg(ap, struct dentry *);
74564+ mnt = va_arg(ap, struct vfsmount *);
74565+ str1 = va_arg(ap, char *);
74566+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74567+ break;
74568+ case GR_FILENAME_TWO_INT:
74569+ dentry = va_arg(ap, struct dentry *);
74570+ mnt = va_arg(ap, struct vfsmount *);
74571+ num1 = va_arg(ap, int);
74572+ num2 = va_arg(ap, int);
74573+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74574+ break;
74575+ case GR_FILENAME_TWO_INT_STR:
74576+ dentry = va_arg(ap, struct dentry *);
74577+ mnt = va_arg(ap, struct vfsmount *);
74578+ num1 = va_arg(ap, int);
74579+ num2 = va_arg(ap, int);
74580+ str1 = va_arg(ap, char *);
74581+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74582+ break;
74583+ case GR_TEXTREL:
74584+ file = va_arg(ap, struct file *);
74585+ ulong1 = va_arg(ap, unsigned long);
74586+ ulong2 = va_arg(ap, unsigned long);
74587+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74588+ break;
74589+ case GR_PTRACE:
74590+ task = va_arg(ap, struct task_struct *);
74591+ 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));
74592+ break;
74593+ case GR_RESOURCE:
74594+ task = va_arg(ap, struct task_struct *);
74595+ cred = __task_cred(task);
74596+ pcred = __task_cred(task->real_parent);
74597+ ulong1 = va_arg(ap, unsigned long);
74598+ str1 = va_arg(ap, char *);
74599+ ulong2 = va_arg(ap, unsigned long);
74600+ 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));
74601+ break;
74602+ case GR_CAP:
74603+ task = va_arg(ap, struct task_struct *);
74604+ cred = __task_cred(task);
74605+ pcred = __task_cred(task->real_parent);
74606+ str1 = va_arg(ap, char *);
74607+ 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));
74608+ break;
74609+ case GR_SIG:
74610+ str1 = va_arg(ap, char *);
74611+ voidptr = va_arg(ap, void *);
74612+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74613+ break;
74614+ case GR_SIG2:
74615+ task = va_arg(ap, struct task_struct *);
74616+ cred = __task_cred(task);
74617+ pcred = __task_cred(task->real_parent);
74618+ num1 = va_arg(ap, int);
74619+ 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));
74620+ break;
74621+ case GR_CRASH1:
74622+ task = va_arg(ap, struct task_struct *);
74623+ cred = __task_cred(task);
74624+ pcred = __task_cred(task->real_parent);
74625+ ulong1 = va_arg(ap, unsigned long);
74626+ 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);
74627+ break;
74628+ case GR_CRASH2:
74629+ task = va_arg(ap, struct task_struct *);
74630+ cred = __task_cred(task);
74631+ pcred = __task_cred(task->real_parent);
74632+ ulong1 = va_arg(ap, unsigned long);
74633+ 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);
74634+ break;
74635+ case GR_RWXMAP:
74636+ file = va_arg(ap, struct file *);
74637+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74638+ break;
74639+ case GR_RWXMAPVMA:
74640+ vma = va_arg(ap, struct vm_area_struct *);
74641+ if (vma->vm_file)
74642+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74643+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74644+ str1 = "<stack>";
74645+ else if (vma->vm_start <= current->mm->brk &&
74646+ vma->vm_end >= current->mm->start_brk)
74647+ str1 = "<heap>";
74648+ else
74649+ str1 = "<anonymous mapping>";
74650+ gr_log_middle_varargs(audit, msg, str1);
74651+ break;
74652+ case GR_PSACCT:
74653+ {
74654+ unsigned int wday, cday;
74655+ __u8 whr, chr;
74656+ __u8 wmin, cmin;
74657+ __u8 wsec, csec;
74658+ char cur_tty[64] = { 0 };
74659+ char parent_tty[64] = { 0 };
74660+
74661+ task = va_arg(ap, struct task_struct *);
74662+ wday = va_arg(ap, unsigned int);
74663+ cday = va_arg(ap, unsigned int);
74664+ whr = va_arg(ap, int);
74665+ chr = va_arg(ap, int);
74666+ wmin = va_arg(ap, int);
74667+ cmin = va_arg(ap, int);
74668+ wsec = va_arg(ap, int);
74669+ csec = va_arg(ap, int);
74670+ ulong1 = va_arg(ap, unsigned long);
74671+ cred = __task_cred(task);
74672+ pcred = __task_cred(task->real_parent);
74673+
74674+ 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));
74675+ }
74676+ break;
74677+ default:
74678+ gr_log_middle(audit, msg, ap);
74679+ }
74680+ va_end(ap);
74681+ // these don't need DEFAULTSECARGS printed on the end
74682+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74683+ gr_log_end(audit, 0);
74684+ else
74685+ gr_log_end(audit, 1);
74686+ END_LOCKS(audit);
74687+}
74688diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74689new file mode 100644
74690index 0000000..0e39d8c
74691--- /dev/null
74692+++ b/grsecurity/grsec_mem.c
74693@@ -0,0 +1,48 @@
74694+#include <linux/kernel.h>
74695+#include <linux/sched.h>
74696+#include <linux/mm.h>
74697+#include <linux/mman.h>
74698+#include <linux/module.h>
74699+#include <linux/grinternal.h>
74700+
74701+void gr_handle_msr_write(void)
74702+{
74703+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74704+ return;
74705+}
74706+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74707+
74708+void
74709+gr_handle_ioperm(void)
74710+{
74711+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74712+ return;
74713+}
74714+
74715+void
74716+gr_handle_iopl(void)
74717+{
74718+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74719+ return;
74720+}
74721+
74722+void
74723+gr_handle_mem_readwrite(u64 from, u64 to)
74724+{
74725+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74726+ return;
74727+}
74728+
74729+void
74730+gr_handle_vm86(void)
74731+{
74732+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74733+ return;
74734+}
74735+
74736+void
74737+gr_log_badprocpid(const char *entry)
74738+{
74739+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74740+ return;
74741+}
74742diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74743new file mode 100644
74744index 0000000..cd9e124
74745--- /dev/null
74746+++ b/grsecurity/grsec_mount.c
74747@@ -0,0 +1,65 @@
74748+#include <linux/kernel.h>
74749+#include <linux/sched.h>
74750+#include <linux/mount.h>
74751+#include <linux/major.h>
74752+#include <linux/grsecurity.h>
74753+#include <linux/grinternal.h>
74754+
74755+void
74756+gr_log_remount(const char *devname, const int retval)
74757+{
74758+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74759+ if (grsec_enable_mount && (retval >= 0))
74760+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74761+#endif
74762+ return;
74763+}
74764+
74765+void
74766+gr_log_unmount(const char *devname, const int retval)
74767+{
74768+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74769+ if (grsec_enable_mount && (retval >= 0))
74770+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74771+#endif
74772+ return;
74773+}
74774+
74775+void
74776+gr_log_mount(const char *from, const char *to, const int retval)
74777+{
74778+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74779+ if (grsec_enable_mount && (retval >= 0))
74780+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74781+#endif
74782+ return;
74783+}
74784+
74785+int
74786+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74787+{
74788+#ifdef CONFIG_GRKERNSEC_ROFS
74789+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74790+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74791+ return -EPERM;
74792+ } else
74793+ return 0;
74794+#endif
74795+ return 0;
74796+}
74797+
74798+int
74799+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74800+{
74801+#ifdef CONFIG_GRKERNSEC_ROFS
74802+ struct inode *inode = dentry->d_inode;
74803+
74804+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74805+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74806+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74807+ return -EPERM;
74808+ } else
74809+ return 0;
74810+#endif
74811+ return 0;
74812+}
74813diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74814new file mode 100644
74815index 0000000..6ee9d50
74816--- /dev/null
74817+++ b/grsecurity/grsec_pax.c
74818@@ -0,0 +1,45 @@
74819+#include <linux/kernel.h>
74820+#include <linux/sched.h>
74821+#include <linux/mm.h>
74822+#include <linux/file.h>
74823+#include <linux/grinternal.h>
74824+#include <linux/grsecurity.h>
74825+
74826+void
74827+gr_log_textrel(struct vm_area_struct * vma)
74828+{
74829+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74830+ if (grsec_enable_log_rwxmaps)
74831+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74832+#endif
74833+ return;
74834+}
74835+
74836+void gr_log_ptgnustack(struct file *file)
74837+{
74838+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74839+ if (grsec_enable_log_rwxmaps)
74840+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74841+#endif
74842+ return;
74843+}
74844+
74845+void
74846+gr_log_rwxmmap(struct file *file)
74847+{
74848+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74849+ if (grsec_enable_log_rwxmaps)
74850+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74851+#endif
74852+ return;
74853+}
74854+
74855+void
74856+gr_log_rwxmprotect(struct vm_area_struct *vma)
74857+{
74858+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74859+ if (grsec_enable_log_rwxmaps)
74860+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74861+#endif
74862+ return;
74863+}
74864diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74865new file mode 100644
74866index 0000000..f7f29aa
74867--- /dev/null
74868+++ b/grsecurity/grsec_ptrace.c
74869@@ -0,0 +1,30 @@
74870+#include <linux/kernel.h>
74871+#include <linux/sched.h>
74872+#include <linux/grinternal.h>
74873+#include <linux/security.h>
74874+
74875+void
74876+gr_audit_ptrace(struct task_struct *task)
74877+{
74878+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74879+ if (grsec_enable_audit_ptrace)
74880+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74881+#endif
74882+ return;
74883+}
74884+
74885+int
74886+gr_ptrace_readexec(struct file *file, int unsafe_flags)
74887+{
74888+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74889+ const struct dentry *dentry = file->f_path.dentry;
74890+ const struct vfsmount *mnt = file->f_path.mnt;
74891+
74892+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74893+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74894+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74895+ return -EACCES;
74896+ }
74897+#endif
74898+ return 0;
74899+}
74900diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74901new file mode 100644
74902index 0000000..3860c7e
74903--- /dev/null
74904+++ b/grsecurity/grsec_sig.c
74905@@ -0,0 +1,236 @@
74906+#include <linux/kernel.h>
74907+#include <linux/sched.h>
74908+#include <linux/fs.h>
74909+#include <linux/delay.h>
74910+#include <linux/grsecurity.h>
74911+#include <linux/grinternal.h>
74912+#include <linux/hardirq.h>
74913+
74914+char *signames[] = {
74915+ [SIGSEGV] = "Segmentation fault",
74916+ [SIGILL] = "Illegal instruction",
74917+ [SIGABRT] = "Abort",
74918+ [SIGBUS] = "Invalid alignment/Bus error"
74919+};
74920+
74921+void
74922+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74923+{
74924+#ifdef CONFIG_GRKERNSEC_SIGNAL
74925+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74926+ (sig == SIGABRT) || (sig == SIGBUS))) {
74927+ if (task_pid_nr(t) == task_pid_nr(current)) {
74928+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74929+ } else {
74930+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74931+ }
74932+ }
74933+#endif
74934+ return;
74935+}
74936+
74937+int
74938+gr_handle_signal(const struct task_struct *p, const int sig)
74939+{
74940+#ifdef CONFIG_GRKERNSEC
74941+ /* ignore the 0 signal for protected task checks */
74942+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74943+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74944+ return -EPERM;
74945+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74946+ return -EPERM;
74947+ }
74948+#endif
74949+ return 0;
74950+}
74951+
74952+#ifdef CONFIG_GRKERNSEC
74953+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74954+
74955+int gr_fake_force_sig(int sig, struct task_struct *t)
74956+{
74957+ unsigned long int flags;
74958+ int ret, blocked, ignored;
74959+ struct k_sigaction *action;
74960+
74961+ spin_lock_irqsave(&t->sighand->siglock, flags);
74962+ action = &t->sighand->action[sig-1];
74963+ ignored = action->sa.sa_handler == SIG_IGN;
74964+ blocked = sigismember(&t->blocked, sig);
74965+ if (blocked || ignored) {
74966+ action->sa.sa_handler = SIG_DFL;
74967+ if (blocked) {
74968+ sigdelset(&t->blocked, sig);
74969+ recalc_sigpending_and_wake(t);
74970+ }
74971+ }
74972+ if (action->sa.sa_handler == SIG_DFL)
74973+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
74974+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74975+
74976+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
74977+
74978+ return ret;
74979+}
74980+#endif
74981+
74982+#define GR_USER_BAN_TIME (15 * 60)
74983+#define GR_DAEMON_BRUTE_TIME (30 * 60)
74984+
74985+void gr_handle_brute_attach(int dumpable)
74986+{
74987+#ifdef CONFIG_GRKERNSEC_BRUTE
74988+ struct task_struct *p = current;
74989+ kuid_t uid = GLOBAL_ROOT_UID;
74990+ int daemon = 0;
74991+
74992+ if (!grsec_enable_brute)
74993+ return;
74994+
74995+ rcu_read_lock();
74996+ read_lock(&tasklist_lock);
74997+ read_lock(&grsec_exec_file_lock);
74998+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74999+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75000+ p->real_parent->brute = 1;
75001+ daemon = 1;
75002+ } else {
75003+ const struct cred *cred = __task_cred(p), *cred2;
75004+ struct task_struct *tsk, *tsk2;
75005+
75006+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75007+ struct user_struct *user;
75008+
75009+ uid = cred->uid;
75010+
75011+ /* this is put upon execution past expiration */
75012+ user = find_user(uid);
75013+ if (user == NULL)
75014+ goto unlock;
75015+ user->suid_banned = 1;
75016+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75017+ if (user->suid_ban_expires == ~0UL)
75018+ user->suid_ban_expires--;
75019+
75020+ /* only kill other threads of the same binary, from the same user */
75021+ do_each_thread(tsk2, tsk) {
75022+ cred2 = __task_cred(tsk);
75023+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75024+ gr_fake_force_sig(SIGKILL, tsk);
75025+ } while_each_thread(tsk2, tsk);
75026+ }
75027+ }
75028+unlock:
75029+ read_unlock(&grsec_exec_file_lock);
75030+ read_unlock(&tasklist_lock);
75031+ rcu_read_unlock();
75032+
75033+ if (gr_is_global_nonroot(uid))
75034+ 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);
75035+ else if (daemon)
75036+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75037+
75038+#endif
75039+ return;
75040+}
75041+
75042+void gr_handle_brute_check(void)
75043+{
75044+#ifdef CONFIG_GRKERNSEC_BRUTE
75045+ struct task_struct *p = current;
75046+
75047+ if (unlikely(p->brute)) {
75048+ if (!grsec_enable_brute)
75049+ p->brute = 0;
75050+ else if (time_before(get_seconds(), p->brute_expires))
75051+ msleep(30 * 1000);
75052+ }
75053+#endif
75054+ return;
75055+}
75056+
75057+void gr_handle_kernel_exploit(void)
75058+{
75059+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75060+ const struct cred *cred;
75061+ struct task_struct *tsk, *tsk2;
75062+ struct user_struct *user;
75063+ kuid_t uid;
75064+
75065+ if (in_irq() || in_serving_softirq() || in_nmi())
75066+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75067+
75068+ uid = current_uid();
75069+
75070+ if (gr_is_global_root(uid))
75071+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
75072+ else {
75073+ /* kill all the processes of this user, hold a reference
75074+ to their creds struct, and prevent them from creating
75075+ another process until system reset
75076+ */
75077+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75078+ GR_GLOBAL_UID(uid));
75079+ /* we intentionally leak this ref */
75080+ user = get_uid(current->cred->user);
75081+ if (user)
75082+ user->kernel_banned = 1;
75083+
75084+ /* kill all processes of this user */
75085+ read_lock(&tasklist_lock);
75086+ do_each_thread(tsk2, tsk) {
75087+ cred = __task_cred(tsk);
75088+ if (uid_eq(cred->uid, uid))
75089+ gr_fake_force_sig(SIGKILL, tsk);
75090+ } while_each_thread(tsk2, tsk);
75091+ read_unlock(&tasklist_lock);
75092+ }
75093+#endif
75094+}
75095+
75096+#ifdef CONFIG_GRKERNSEC_BRUTE
75097+static bool suid_ban_expired(struct user_struct *user)
75098+{
75099+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75100+ user->suid_banned = 0;
75101+ user->suid_ban_expires = 0;
75102+ free_uid(user);
75103+ return true;
75104+ }
75105+
75106+ return false;
75107+}
75108+#endif
75109+
75110+int gr_process_kernel_exec_ban(void)
75111+{
75112+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75113+ if (unlikely(current->cred->user->kernel_banned))
75114+ return -EPERM;
75115+#endif
75116+ return 0;
75117+}
75118+
75119+int gr_process_kernel_setuid_ban(struct user_struct *user)
75120+{
75121+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75122+ if (unlikely(user->kernel_banned))
75123+ gr_fake_force_sig(SIGKILL, current);
75124+#endif
75125+ return 0;
75126+}
75127+
75128+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75129+{
75130+#ifdef CONFIG_GRKERNSEC_BRUTE
75131+ struct user_struct *user = current->cred->user;
75132+ if (unlikely(user->suid_banned)) {
75133+ if (suid_ban_expired(user))
75134+ return 0;
75135+ /* disallow execution of suid binaries only */
75136+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75137+ return -EPERM;
75138+ }
75139+#endif
75140+ return 0;
75141+}
75142diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75143new file mode 100644
75144index 0000000..c0aef3a
75145--- /dev/null
75146+++ b/grsecurity/grsec_sock.c
75147@@ -0,0 +1,244 @@
75148+#include <linux/kernel.h>
75149+#include <linux/module.h>
75150+#include <linux/sched.h>
75151+#include <linux/file.h>
75152+#include <linux/net.h>
75153+#include <linux/in.h>
75154+#include <linux/ip.h>
75155+#include <net/sock.h>
75156+#include <net/inet_sock.h>
75157+#include <linux/grsecurity.h>
75158+#include <linux/grinternal.h>
75159+#include <linux/gracl.h>
75160+
75161+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75162+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75163+
75164+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75165+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75166+
75167+#ifdef CONFIG_UNIX_MODULE
75168+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75169+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75170+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75171+EXPORT_SYMBOL_GPL(gr_handle_create);
75172+#endif
75173+
75174+#ifdef CONFIG_GRKERNSEC
75175+#define gr_conn_table_size 32749
75176+struct conn_table_entry {
75177+ struct conn_table_entry *next;
75178+ struct signal_struct *sig;
75179+};
75180+
75181+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75182+DEFINE_SPINLOCK(gr_conn_table_lock);
75183+
75184+extern const char * gr_socktype_to_name(unsigned char type);
75185+extern const char * gr_proto_to_name(unsigned char proto);
75186+extern const char * gr_sockfamily_to_name(unsigned char family);
75187+
75188+static __inline__ int
75189+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75190+{
75191+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75192+}
75193+
75194+static __inline__ int
75195+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75196+ __u16 sport, __u16 dport)
75197+{
75198+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75199+ sig->gr_sport == sport && sig->gr_dport == dport))
75200+ return 1;
75201+ else
75202+ return 0;
75203+}
75204+
75205+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75206+{
75207+ struct conn_table_entry **match;
75208+ unsigned int index;
75209+
75210+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75211+ sig->gr_sport, sig->gr_dport,
75212+ gr_conn_table_size);
75213+
75214+ newent->sig = sig;
75215+
75216+ match = &gr_conn_table[index];
75217+ newent->next = *match;
75218+ *match = newent;
75219+
75220+ return;
75221+}
75222+
75223+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75224+{
75225+ struct conn_table_entry *match, *last = NULL;
75226+ unsigned int index;
75227+
75228+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75229+ sig->gr_sport, sig->gr_dport,
75230+ gr_conn_table_size);
75231+
75232+ match = gr_conn_table[index];
75233+ while (match && !conn_match(match->sig,
75234+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75235+ sig->gr_dport)) {
75236+ last = match;
75237+ match = match->next;
75238+ }
75239+
75240+ if (match) {
75241+ if (last)
75242+ last->next = match->next;
75243+ else
75244+ gr_conn_table[index] = NULL;
75245+ kfree(match);
75246+ }
75247+
75248+ return;
75249+}
75250+
75251+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75252+ __u16 sport, __u16 dport)
75253+{
75254+ struct conn_table_entry *match;
75255+ unsigned int index;
75256+
75257+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75258+
75259+ match = gr_conn_table[index];
75260+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75261+ match = match->next;
75262+
75263+ if (match)
75264+ return match->sig;
75265+ else
75266+ return NULL;
75267+}
75268+
75269+#endif
75270+
75271+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75272+{
75273+#ifdef CONFIG_GRKERNSEC
75274+ struct signal_struct *sig = task->signal;
75275+ struct conn_table_entry *newent;
75276+
75277+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75278+ if (newent == NULL)
75279+ return;
75280+ /* no bh lock needed since we are called with bh disabled */
75281+ spin_lock(&gr_conn_table_lock);
75282+ gr_del_task_from_ip_table_nolock(sig);
75283+ sig->gr_saddr = inet->inet_rcv_saddr;
75284+ sig->gr_daddr = inet->inet_daddr;
75285+ sig->gr_sport = inet->inet_sport;
75286+ sig->gr_dport = inet->inet_dport;
75287+ gr_add_to_task_ip_table_nolock(sig, newent);
75288+ spin_unlock(&gr_conn_table_lock);
75289+#endif
75290+ return;
75291+}
75292+
75293+void gr_del_task_from_ip_table(struct task_struct *task)
75294+{
75295+#ifdef CONFIG_GRKERNSEC
75296+ spin_lock_bh(&gr_conn_table_lock);
75297+ gr_del_task_from_ip_table_nolock(task->signal);
75298+ spin_unlock_bh(&gr_conn_table_lock);
75299+#endif
75300+ return;
75301+}
75302+
75303+void
75304+gr_attach_curr_ip(const struct sock *sk)
75305+{
75306+#ifdef CONFIG_GRKERNSEC
75307+ struct signal_struct *p, *set;
75308+ const struct inet_sock *inet = inet_sk(sk);
75309+
75310+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75311+ return;
75312+
75313+ set = current->signal;
75314+
75315+ spin_lock_bh(&gr_conn_table_lock);
75316+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75317+ inet->inet_dport, inet->inet_sport);
75318+ if (unlikely(p != NULL)) {
75319+ set->curr_ip = p->curr_ip;
75320+ set->used_accept = 1;
75321+ gr_del_task_from_ip_table_nolock(p);
75322+ spin_unlock_bh(&gr_conn_table_lock);
75323+ return;
75324+ }
75325+ spin_unlock_bh(&gr_conn_table_lock);
75326+
75327+ set->curr_ip = inet->inet_daddr;
75328+ set->used_accept = 1;
75329+#endif
75330+ return;
75331+}
75332+
75333+int
75334+gr_handle_sock_all(const int family, const int type, const int protocol)
75335+{
75336+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75337+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75338+ (family != AF_UNIX)) {
75339+ if (family == AF_INET)
75340+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75341+ else
75342+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75343+ return -EACCES;
75344+ }
75345+#endif
75346+ return 0;
75347+}
75348+
75349+int
75350+gr_handle_sock_server(const struct sockaddr *sck)
75351+{
75352+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75353+ if (grsec_enable_socket_server &&
75354+ in_group_p(grsec_socket_server_gid) &&
75355+ sck && (sck->sa_family != AF_UNIX) &&
75356+ (sck->sa_family != AF_LOCAL)) {
75357+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75358+ return -EACCES;
75359+ }
75360+#endif
75361+ return 0;
75362+}
75363+
75364+int
75365+gr_handle_sock_server_other(const struct sock *sck)
75366+{
75367+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75368+ if (grsec_enable_socket_server &&
75369+ in_group_p(grsec_socket_server_gid) &&
75370+ sck && (sck->sk_family != AF_UNIX) &&
75371+ (sck->sk_family != AF_LOCAL)) {
75372+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75373+ return -EACCES;
75374+ }
75375+#endif
75376+ return 0;
75377+}
75378+
75379+int
75380+gr_handle_sock_client(const struct sockaddr *sck)
75381+{
75382+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75383+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75384+ sck && (sck->sa_family != AF_UNIX) &&
75385+ (sck->sa_family != AF_LOCAL)) {
75386+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75387+ return -EACCES;
75388+ }
75389+#endif
75390+ return 0;
75391+}
75392diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75393new file mode 100644
75394index 0000000..8159888
75395--- /dev/null
75396+++ b/grsecurity/grsec_sysctl.c
75397@@ -0,0 +1,479 @@
75398+#include <linux/kernel.h>
75399+#include <linux/sched.h>
75400+#include <linux/sysctl.h>
75401+#include <linux/grsecurity.h>
75402+#include <linux/grinternal.h>
75403+
75404+int
75405+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75406+{
75407+#ifdef CONFIG_GRKERNSEC_SYSCTL
75408+ if (dirname == NULL || name == NULL)
75409+ return 0;
75410+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75411+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75412+ return -EACCES;
75413+ }
75414+#endif
75415+ return 0;
75416+}
75417+
75418+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75419+static int __maybe_unused __read_only one = 1;
75420+#endif
75421+
75422+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75423+ defined(CONFIG_GRKERNSEC_DENYUSB)
75424+struct ctl_table grsecurity_table[] = {
75425+#ifdef CONFIG_GRKERNSEC_SYSCTL
75426+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75427+#ifdef CONFIG_GRKERNSEC_IO
75428+ {
75429+ .procname = "disable_priv_io",
75430+ .data = &grsec_disable_privio,
75431+ .maxlen = sizeof(int),
75432+ .mode = 0600,
75433+ .proc_handler = &proc_dointvec,
75434+ },
75435+#endif
75436+#endif
75437+#ifdef CONFIG_GRKERNSEC_LINK
75438+ {
75439+ .procname = "linking_restrictions",
75440+ .data = &grsec_enable_link,
75441+ .maxlen = sizeof(int),
75442+ .mode = 0600,
75443+ .proc_handler = &proc_dointvec,
75444+ },
75445+#endif
75446+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75447+ {
75448+ .procname = "enforce_symlinksifowner",
75449+ .data = &grsec_enable_symlinkown,
75450+ .maxlen = sizeof(int),
75451+ .mode = 0600,
75452+ .proc_handler = &proc_dointvec,
75453+ },
75454+ {
75455+ .procname = "symlinkown_gid",
75456+ .data = &grsec_symlinkown_gid,
75457+ .maxlen = sizeof(int),
75458+ .mode = 0600,
75459+ .proc_handler = &proc_dointvec,
75460+ },
75461+#endif
75462+#ifdef CONFIG_GRKERNSEC_BRUTE
75463+ {
75464+ .procname = "deter_bruteforce",
75465+ .data = &grsec_enable_brute,
75466+ .maxlen = sizeof(int),
75467+ .mode = 0600,
75468+ .proc_handler = &proc_dointvec,
75469+ },
75470+#endif
75471+#ifdef CONFIG_GRKERNSEC_FIFO
75472+ {
75473+ .procname = "fifo_restrictions",
75474+ .data = &grsec_enable_fifo,
75475+ .maxlen = sizeof(int),
75476+ .mode = 0600,
75477+ .proc_handler = &proc_dointvec,
75478+ },
75479+#endif
75480+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75481+ {
75482+ .procname = "ptrace_readexec",
75483+ .data = &grsec_enable_ptrace_readexec,
75484+ .maxlen = sizeof(int),
75485+ .mode = 0600,
75486+ .proc_handler = &proc_dointvec,
75487+ },
75488+#endif
75489+#ifdef CONFIG_GRKERNSEC_SETXID
75490+ {
75491+ .procname = "consistent_setxid",
75492+ .data = &grsec_enable_setxid,
75493+ .maxlen = sizeof(int),
75494+ .mode = 0600,
75495+ .proc_handler = &proc_dointvec,
75496+ },
75497+#endif
75498+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75499+ {
75500+ .procname = "ip_blackhole",
75501+ .data = &grsec_enable_blackhole,
75502+ .maxlen = sizeof(int),
75503+ .mode = 0600,
75504+ .proc_handler = &proc_dointvec,
75505+ },
75506+ {
75507+ .procname = "lastack_retries",
75508+ .data = &grsec_lastack_retries,
75509+ .maxlen = sizeof(int),
75510+ .mode = 0600,
75511+ .proc_handler = &proc_dointvec,
75512+ },
75513+#endif
75514+#ifdef CONFIG_GRKERNSEC_EXECLOG
75515+ {
75516+ .procname = "exec_logging",
75517+ .data = &grsec_enable_execlog,
75518+ .maxlen = sizeof(int),
75519+ .mode = 0600,
75520+ .proc_handler = &proc_dointvec,
75521+ },
75522+#endif
75523+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75524+ {
75525+ .procname = "rwxmap_logging",
75526+ .data = &grsec_enable_log_rwxmaps,
75527+ .maxlen = sizeof(int),
75528+ .mode = 0600,
75529+ .proc_handler = &proc_dointvec,
75530+ },
75531+#endif
75532+#ifdef CONFIG_GRKERNSEC_SIGNAL
75533+ {
75534+ .procname = "signal_logging",
75535+ .data = &grsec_enable_signal,
75536+ .maxlen = sizeof(int),
75537+ .mode = 0600,
75538+ .proc_handler = &proc_dointvec,
75539+ },
75540+#endif
75541+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75542+ {
75543+ .procname = "forkfail_logging",
75544+ .data = &grsec_enable_forkfail,
75545+ .maxlen = sizeof(int),
75546+ .mode = 0600,
75547+ .proc_handler = &proc_dointvec,
75548+ },
75549+#endif
75550+#ifdef CONFIG_GRKERNSEC_TIME
75551+ {
75552+ .procname = "timechange_logging",
75553+ .data = &grsec_enable_time,
75554+ .maxlen = sizeof(int),
75555+ .mode = 0600,
75556+ .proc_handler = &proc_dointvec,
75557+ },
75558+#endif
75559+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75560+ {
75561+ .procname = "chroot_deny_shmat",
75562+ .data = &grsec_enable_chroot_shmat,
75563+ .maxlen = sizeof(int),
75564+ .mode = 0600,
75565+ .proc_handler = &proc_dointvec,
75566+ },
75567+#endif
75568+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75569+ {
75570+ .procname = "chroot_deny_unix",
75571+ .data = &grsec_enable_chroot_unix,
75572+ .maxlen = sizeof(int),
75573+ .mode = 0600,
75574+ .proc_handler = &proc_dointvec,
75575+ },
75576+#endif
75577+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75578+ {
75579+ .procname = "chroot_deny_mount",
75580+ .data = &grsec_enable_chroot_mount,
75581+ .maxlen = sizeof(int),
75582+ .mode = 0600,
75583+ .proc_handler = &proc_dointvec,
75584+ },
75585+#endif
75586+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75587+ {
75588+ .procname = "chroot_deny_fchdir",
75589+ .data = &grsec_enable_chroot_fchdir,
75590+ .maxlen = sizeof(int),
75591+ .mode = 0600,
75592+ .proc_handler = &proc_dointvec,
75593+ },
75594+#endif
75595+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75596+ {
75597+ .procname = "chroot_deny_chroot",
75598+ .data = &grsec_enable_chroot_double,
75599+ .maxlen = sizeof(int),
75600+ .mode = 0600,
75601+ .proc_handler = &proc_dointvec,
75602+ },
75603+#endif
75604+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75605+ {
75606+ .procname = "chroot_deny_pivot",
75607+ .data = &grsec_enable_chroot_pivot,
75608+ .maxlen = sizeof(int),
75609+ .mode = 0600,
75610+ .proc_handler = &proc_dointvec,
75611+ },
75612+#endif
75613+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75614+ {
75615+ .procname = "chroot_enforce_chdir",
75616+ .data = &grsec_enable_chroot_chdir,
75617+ .maxlen = sizeof(int),
75618+ .mode = 0600,
75619+ .proc_handler = &proc_dointvec,
75620+ },
75621+#endif
75622+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75623+ {
75624+ .procname = "chroot_deny_chmod",
75625+ .data = &grsec_enable_chroot_chmod,
75626+ .maxlen = sizeof(int),
75627+ .mode = 0600,
75628+ .proc_handler = &proc_dointvec,
75629+ },
75630+#endif
75631+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75632+ {
75633+ .procname = "chroot_deny_mknod",
75634+ .data = &grsec_enable_chroot_mknod,
75635+ .maxlen = sizeof(int),
75636+ .mode = 0600,
75637+ .proc_handler = &proc_dointvec,
75638+ },
75639+#endif
75640+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75641+ {
75642+ .procname = "chroot_restrict_nice",
75643+ .data = &grsec_enable_chroot_nice,
75644+ .maxlen = sizeof(int),
75645+ .mode = 0600,
75646+ .proc_handler = &proc_dointvec,
75647+ },
75648+#endif
75649+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75650+ {
75651+ .procname = "chroot_execlog",
75652+ .data = &grsec_enable_chroot_execlog,
75653+ .maxlen = sizeof(int),
75654+ .mode = 0600,
75655+ .proc_handler = &proc_dointvec,
75656+ },
75657+#endif
75658+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75659+ {
75660+ .procname = "chroot_caps",
75661+ .data = &grsec_enable_chroot_caps,
75662+ .maxlen = sizeof(int),
75663+ .mode = 0600,
75664+ .proc_handler = &proc_dointvec,
75665+ },
75666+#endif
75667+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75668+ {
75669+ .procname = "chroot_deny_sysctl",
75670+ .data = &grsec_enable_chroot_sysctl,
75671+ .maxlen = sizeof(int),
75672+ .mode = 0600,
75673+ .proc_handler = &proc_dointvec,
75674+ },
75675+#endif
75676+#ifdef CONFIG_GRKERNSEC_TPE
75677+ {
75678+ .procname = "tpe",
75679+ .data = &grsec_enable_tpe,
75680+ .maxlen = sizeof(int),
75681+ .mode = 0600,
75682+ .proc_handler = &proc_dointvec,
75683+ },
75684+ {
75685+ .procname = "tpe_gid",
75686+ .data = &grsec_tpe_gid,
75687+ .maxlen = sizeof(int),
75688+ .mode = 0600,
75689+ .proc_handler = &proc_dointvec,
75690+ },
75691+#endif
75692+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75693+ {
75694+ .procname = "tpe_invert",
75695+ .data = &grsec_enable_tpe_invert,
75696+ .maxlen = sizeof(int),
75697+ .mode = 0600,
75698+ .proc_handler = &proc_dointvec,
75699+ },
75700+#endif
75701+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75702+ {
75703+ .procname = "tpe_restrict_all",
75704+ .data = &grsec_enable_tpe_all,
75705+ .maxlen = sizeof(int),
75706+ .mode = 0600,
75707+ .proc_handler = &proc_dointvec,
75708+ },
75709+#endif
75710+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75711+ {
75712+ .procname = "socket_all",
75713+ .data = &grsec_enable_socket_all,
75714+ .maxlen = sizeof(int),
75715+ .mode = 0600,
75716+ .proc_handler = &proc_dointvec,
75717+ },
75718+ {
75719+ .procname = "socket_all_gid",
75720+ .data = &grsec_socket_all_gid,
75721+ .maxlen = sizeof(int),
75722+ .mode = 0600,
75723+ .proc_handler = &proc_dointvec,
75724+ },
75725+#endif
75726+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75727+ {
75728+ .procname = "socket_client",
75729+ .data = &grsec_enable_socket_client,
75730+ .maxlen = sizeof(int),
75731+ .mode = 0600,
75732+ .proc_handler = &proc_dointvec,
75733+ },
75734+ {
75735+ .procname = "socket_client_gid",
75736+ .data = &grsec_socket_client_gid,
75737+ .maxlen = sizeof(int),
75738+ .mode = 0600,
75739+ .proc_handler = &proc_dointvec,
75740+ },
75741+#endif
75742+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75743+ {
75744+ .procname = "socket_server",
75745+ .data = &grsec_enable_socket_server,
75746+ .maxlen = sizeof(int),
75747+ .mode = 0600,
75748+ .proc_handler = &proc_dointvec,
75749+ },
75750+ {
75751+ .procname = "socket_server_gid",
75752+ .data = &grsec_socket_server_gid,
75753+ .maxlen = sizeof(int),
75754+ .mode = 0600,
75755+ .proc_handler = &proc_dointvec,
75756+ },
75757+#endif
75758+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75759+ {
75760+ .procname = "audit_group",
75761+ .data = &grsec_enable_group,
75762+ .maxlen = sizeof(int),
75763+ .mode = 0600,
75764+ .proc_handler = &proc_dointvec,
75765+ },
75766+ {
75767+ .procname = "audit_gid",
75768+ .data = &grsec_audit_gid,
75769+ .maxlen = sizeof(int),
75770+ .mode = 0600,
75771+ .proc_handler = &proc_dointvec,
75772+ },
75773+#endif
75774+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75775+ {
75776+ .procname = "audit_chdir",
75777+ .data = &grsec_enable_chdir,
75778+ .maxlen = sizeof(int),
75779+ .mode = 0600,
75780+ .proc_handler = &proc_dointvec,
75781+ },
75782+#endif
75783+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75784+ {
75785+ .procname = "audit_mount",
75786+ .data = &grsec_enable_mount,
75787+ .maxlen = sizeof(int),
75788+ .mode = 0600,
75789+ .proc_handler = &proc_dointvec,
75790+ },
75791+#endif
75792+#ifdef CONFIG_GRKERNSEC_DMESG
75793+ {
75794+ .procname = "dmesg",
75795+ .data = &grsec_enable_dmesg,
75796+ .maxlen = sizeof(int),
75797+ .mode = 0600,
75798+ .proc_handler = &proc_dointvec,
75799+ },
75800+#endif
75801+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75802+ {
75803+ .procname = "chroot_findtask",
75804+ .data = &grsec_enable_chroot_findtask,
75805+ .maxlen = sizeof(int),
75806+ .mode = 0600,
75807+ .proc_handler = &proc_dointvec,
75808+ },
75809+#endif
75810+#ifdef CONFIG_GRKERNSEC_RESLOG
75811+ {
75812+ .procname = "resource_logging",
75813+ .data = &grsec_resource_logging,
75814+ .maxlen = sizeof(int),
75815+ .mode = 0600,
75816+ .proc_handler = &proc_dointvec,
75817+ },
75818+#endif
75819+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75820+ {
75821+ .procname = "audit_ptrace",
75822+ .data = &grsec_enable_audit_ptrace,
75823+ .maxlen = sizeof(int),
75824+ .mode = 0600,
75825+ .proc_handler = &proc_dointvec,
75826+ },
75827+#endif
75828+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75829+ {
75830+ .procname = "harden_ptrace",
75831+ .data = &grsec_enable_harden_ptrace,
75832+ .maxlen = sizeof(int),
75833+ .mode = 0600,
75834+ .proc_handler = &proc_dointvec,
75835+ },
75836+#endif
75837+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75838+ {
75839+ .procname = "harden_ipc",
75840+ .data = &grsec_enable_harden_ipc,
75841+ .maxlen = sizeof(int),
75842+ .mode = 0600,
75843+ .proc_handler = &proc_dointvec,
75844+ },
75845+#endif
75846+ {
75847+ .procname = "grsec_lock",
75848+ .data = &grsec_lock,
75849+ .maxlen = sizeof(int),
75850+ .mode = 0600,
75851+ .proc_handler = &proc_dointvec,
75852+ },
75853+#endif
75854+#ifdef CONFIG_GRKERNSEC_ROFS
75855+ {
75856+ .procname = "romount_protect",
75857+ .data = &grsec_enable_rofs,
75858+ .maxlen = sizeof(int),
75859+ .mode = 0600,
75860+ .proc_handler = &proc_dointvec_minmax,
75861+ .extra1 = &one,
75862+ .extra2 = &one,
75863+ },
75864+#endif
75865+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75866+ {
75867+ .procname = "deny_new_usb",
75868+ .data = &grsec_deny_new_usb,
75869+ .maxlen = sizeof(int),
75870+ .mode = 0600,
75871+ .proc_handler = &proc_dointvec,
75872+ },
75873+#endif
75874+ { }
75875+};
75876+#endif
75877diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75878new file mode 100644
75879index 0000000..61b514e
75880--- /dev/null
75881+++ b/grsecurity/grsec_time.c
75882@@ -0,0 +1,16 @@
75883+#include <linux/kernel.h>
75884+#include <linux/sched.h>
75885+#include <linux/grinternal.h>
75886+#include <linux/module.h>
75887+
75888+void
75889+gr_log_timechange(void)
75890+{
75891+#ifdef CONFIG_GRKERNSEC_TIME
75892+ if (grsec_enable_time)
75893+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75894+#endif
75895+ return;
75896+}
75897+
75898+EXPORT_SYMBOL_GPL(gr_log_timechange);
75899diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75900new file mode 100644
75901index 0000000..ee57dcf
75902--- /dev/null
75903+++ b/grsecurity/grsec_tpe.c
75904@@ -0,0 +1,73 @@
75905+#include <linux/kernel.h>
75906+#include <linux/sched.h>
75907+#include <linux/file.h>
75908+#include <linux/fs.h>
75909+#include <linux/grinternal.h>
75910+
75911+extern int gr_acl_tpe_check(void);
75912+
75913+int
75914+gr_tpe_allow(const struct file *file)
75915+{
75916+#ifdef CONFIG_GRKERNSEC
75917+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75918+ const struct cred *cred = current_cred();
75919+ char *msg = NULL;
75920+ char *msg2 = NULL;
75921+
75922+ // never restrict root
75923+ if (gr_is_global_root(cred->uid))
75924+ return 1;
75925+
75926+ if (grsec_enable_tpe) {
75927+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75928+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75929+ msg = "not being in trusted group";
75930+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75931+ msg = "being in untrusted group";
75932+#else
75933+ if (in_group_p(grsec_tpe_gid))
75934+ msg = "being in untrusted group";
75935+#endif
75936+ }
75937+ if (!msg && gr_acl_tpe_check())
75938+ msg = "being in untrusted role";
75939+
75940+ // not in any affected group/role
75941+ if (!msg)
75942+ goto next_check;
75943+
75944+ if (gr_is_global_nonroot(inode->i_uid))
75945+ msg2 = "file in non-root-owned directory";
75946+ else if (inode->i_mode & S_IWOTH)
75947+ msg2 = "file in world-writable directory";
75948+ else if (inode->i_mode & S_IWGRP)
75949+ msg2 = "file in group-writable directory";
75950+
75951+ if (msg && msg2) {
75952+ char fullmsg[70] = {0};
75953+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75954+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75955+ return 0;
75956+ }
75957+ msg = NULL;
75958+next_check:
75959+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75960+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75961+ return 1;
75962+
75963+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75964+ msg = "directory not owned by user";
75965+ else if (inode->i_mode & S_IWOTH)
75966+ msg = "file in world-writable directory";
75967+ else if (inode->i_mode & S_IWGRP)
75968+ msg = "file in group-writable directory";
75969+
75970+ if (msg) {
75971+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75972+ return 0;
75973+ }
75974+#endif
75975+#endif
75976+ return 1;
75977+}
75978diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75979new file mode 100644
75980index 0000000..ae02d8e
75981--- /dev/null
75982+++ b/grsecurity/grsec_usb.c
75983@@ -0,0 +1,15 @@
75984+#include <linux/kernel.h>
75985+#include <linux/grinternal.h>
75986+#include <linux/module.h>
75987+
75988+int gr_handle_new_usb(void)
75989+{
75990+#ifdef CONFIG_GRKERNSEC_DENYUSB
75991+ if (grsec_deny_new_usb) {
75992+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75993+ return 1;
75994+ }
75995+#endif
75996+ return 0;
75997+}
75998+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75999diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76000new file mode 100644
76001index 0000000..9f7b1ac
76002--- /dev/null
76003+++ b/grsecurity/grsum.c
76004@@ -0,0 +1,61 @@
76005+#include <linux/err.h>
76006+#include <linux/kernel.h>
76007+#include <linux/sched.h>
76008+#include <linux/mm.h>
76009+#include <linux/scatterlist.h>
76010+#include <linux/crypto.h>
76011+#include <linux/gracl.h>
76012+
76013+
76014+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76015+#error "crypto and sha256 must be built into the kernel"
76016+#endif
76017+
76018+int
76019+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76020+{
76021+ char *p;
76022+ struct crypto_hash *tfm;
76023+ struct hash_desc desc;
76024+ struct scatterlist sg;
76025+ unsigned char temp_sum[GR_SHA_LEN];
76026+ volatile int retval = 0;
76027+ volatile int dummy = 0;
76028+ unsigned int i;
76029+
76030+ sg_init_table(&sg, 1);
76031+
76032+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76033+ if (IS_ERR(tfm)) {
76034+ /* should never happen, since sha256 should be built in */
76035+ return 1;
76036+ }
76037+
76038+ desc.tfm = tfm;
76039+ desc.flags = 0;
76040+
76041+ crypto_hash_init(&desc);
76042+
76043+ p = salt;
76044+ sg_set_buf(&sg, p, GR_SALT_LEN);
76045+ crypto_hash_update(&desc, &sg, sg.length);
76046+
76047+ p = entry->pw;
76048+ sg_set_buf(&sg, p, strlen(p));
76049+
76050+ crypto_hash_update(&desc, &sg, sg.length);
76051+
76052+ crypto_hash_final(&desc, temp_sum);
76053+
76054+ memset(entry->pw, 0, GR_PW_LEN);
76055+
76056+ for (i = 0; i < GR_SHA_LEN; i++)
76057+ if (sum[i] != temp_sum[i])
76058+ retval = 1;
76059+ else
76060+ dummy = 1; // waste a cycle
76061+
76062+ crypto_free_hash(tfm);
76063+
76064+ return retval;
76065+}
76066diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76067index 77ff547..181834f 100644
76068--- a/include/asm-generic/4level-fixup.h
76069+++ b/include/asm-generic/4level-fixup.h
76070@@ -13,8 +13,10 @@
76071 #define pmd_alloc(mm, pud, address) \
76072 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76073 NULL: pmd_offset(pud, address))
76074+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76075
76076 #define pud_alloc(mm, pgd, address) (pgd)
76077+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76078 #define pud_offset(pgd, start) (pgd)
76079 #define pud_none(pud) 0
76080 #define pud_bad(pud) 0
76081diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76082index b7babf0..97f4c4f 100644
76083--- a/include/asm-generic/atomic-long.h
76084+++ b/include/asm-generic/atomic-long.h
76085@@ -22,6 +22,12 @@
76086
76087 typedef atomic64_t atomic_long_t;
76088
76089+#ifdef CONFIG_PAX_REFCOUNT
76090+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76091+#else
76092+typedef atomic64_t atomic_long_unchecked_t;
76093+#endif
76094+
76095 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76096
76097 static inline long atomic_long_read(atomic_long_t *l)
76098@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76099 return (long)atomic64_read(v);
76100 }
76101
76102+#ifdef CONFIG_PAX_REFCOUNT
76103+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76104+{
76105+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76106+
76107+ return (long)atomic64_read_unchecked(v);
76108+}
76109+#endif
76110+
76111 static inline void atomic_long_set(atomic_long_t *l, long i)
76112 {
76113 atomic64_t *v = (atomic64_t *)l;
76114@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76115 atomic64_set(v, i);
76116 }
76117
76118+#ifdef CONFIG_PAX_REFCOUNT
76119+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76120+{
76121+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76122+
76123+ atomic64_set_unchecked(v, i);
76124+}
76125+#endif
76126+
76127 static inline void atomic_long_inc(atomic_long_t *l)
76128 {
76129 atomic64_t *v = (atomic64_t *)l;
76130@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76131 atomic64_inc(v);
76132 }
76133
76134+#ifdef CONFIG_PAX_REFCOUNT
76135+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76136+{
76137+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76138+
76139+ atomic64_inc_unchecked(v);
76140+}
76141+#endif
76142+
76143 static inline void atomic_long_dec(atomic_long_t *l)
76144 {
76145 atomic64_t *v = (atomic64_t *)l;
76146@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76147 atomic64_dec(v);
76148 }
76149
76150+#ifdef CONFIG_PAX_REFCOUNT
76151+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76152+{
76153+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76154+
76155+ atomic64_dec_unchecked(v);
76156+}
76157+#endif
76158+
76159 static inline void atomic_long_add(long i, atomic_long_t *l)
76160 {
76161 atomic64_t *v = (atomic64_t *)l;
76162@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76163 atomic64_add(i, v);
76164 }
76165
76166+#ifdef CONFIG_PAX_REFCOUNT
76167+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76168+{
76169+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76170+
76171+ atomic64_add_unchecked(i, v);
76172+}
76173+#endif
76174+
76175 static inline void atomic_long_sub(long i, atomic_long_t *l)
76176 {
76177 atomic64_t *v = (atomic64_t *)l;
76178@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76179 atomic64_sub(i, v);
76180 }
76181
76182+#ifdef CONFIG_PAX_REFCOUNT
76183+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76184+{
76185+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76186+
76187+ atomic64_sub_unchecked(i, v);
76188+}
76189+#endif
76190+
76191 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76192 {
76193 atomic64_t *v = (atomic64_t *)l;
76194@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76195 return atomic64_add_negative(i, v);
76196 }
76197
76198-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76199+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76200 {
76201 atomic64_t *v = (atomic64_t *)l;
76202
76203 return (long)atomic64_add_return(i, v);
76204 }
76205
76206+#ifdef CONFIG_PAX_REFCOUNT
76207+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76208+{
76209+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76210+
76211+ return (long)atomic64_add_return_unchecked(i, v);
76212+}
76213+#endif
76214+
76215 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76216 {
76217 atomic64_t *v = (atomic64_t *)l;
76218@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76219 return (long)atomic64_inc_return(v);
76220 }
76221
76222+#ifdef CONFIG_PAX_REFCOUNT
76223+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76224+{
76225+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76226+
76227+ return (long)atomic64_inc_return_unchecked(v);
76228+}
76229+#endif
76230+
76231 static inline long atomic_long_dec_return(atomic_long_t *l)
76232 {
76233 atomic64_t *v = (atomic64_t *)l;
76234@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76235
76236 typedef atomic_t atomic_long_t;
76237
76238+#ifdef CONFIG_PAX_REFCOUNT
76239+typedef atomic_unchecked_t atomic_long_unchecked_t;
76240+#else
76241+typedef atomic_t atomic_long_unchecked_t;
76242+#endif
76243+
76244 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76245 static inline long atomic_long_read(atomic_long_t *l)
76246 {
76247@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76248 return (long)atomic_read(v);
76249 }
76250
76251+#ifdef CONFIG_PAX_REFCOUNT
76252+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76253+{
76254+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76255+
76256+ return (long)atomic_read_unchecked(v);
76257+}
76258+#endif
76259+
76260 static inline void atomic_long_set(atomic_long_t *l, long i)
76261 {
76262 atomic_t *v = (atomic_t *)l;
76263@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76264 atomic_set(v, i);
76265 }
76266
76267+#ifdef CONFIG_PAX_REFCOUNT
76268+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76269+{
76270+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76271+
76272+ atomic_set_unchecked(v, i);
76273+}
76274+#endif
76275+
76276 static inline void atomic_long_inc(atomic_long_t *l)
76277 {
76278 atomic_t *v = (atomic_t *)l;
76279@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76280 atomic_inc(v);
76281 }
76282
76283+#ifdef CONFIG_PAX_REFCOUNT
76284+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76285+{
76286+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76287+
76288+ atomic_inc_unchecked(v);
76289+}
76290+#endif
76291+
76292 static inline void atomic_long_dec(atomic_long_t *l)
76293 {
76294 atomic_t *v = (atomic_t *)l;
76295@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76296 atomic_dec(v);
76297 }
76298
76299+#ifdef CONFIG_PAX_REFCOUNT
76300+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76301+{
76302+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76303+
76304+ atomic_dec_unchecked(v);
76305+}
76306+#endif
76307+
76308 static inline void atomic_long_add(long i, atomic_long_t *l)
76309 {
76310 atomic_t *v = (atomic_t *)l;
76311@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76312 atomic_add(i, v);
76313 }
76314
76315+#ifdef CONFIG_PAX_REFCOUNT
76316+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76317+{
76318+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76319+
76320+ atomic_add_unchecked(i, v);
76321+}
76322+#endif
76323+
76324 static inline void atomic_long_sub(long i, atomic_long_t *l)
76325 {
76326 atomic_t *v = (atomic_t *)l;
76327@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76328 atomic_sub(i, v);
76329 }
76330
76331+#ifdef CONFIG_PAX_REFCOUNT
76332+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76333+{
76334+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76335+
76336+ atomic_sub_unchecked(i, v);
76337+}
76338+#endif
76339+
76340 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76341 {
76342 atomic_t *v = (atomic_t *)l;
76343@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76344 return (long)atomic_add_return(i, v);
76345 }
76346
76347+#ifdef CONFIG_PAX_REFCOUNT
76348+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76349+{
76350+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76351+
76352+ return (long)atomic_add_return_unchecked(i, v);
76353+}
76354+
76355+#endif
76356+
76357 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76358 {
76359 atomic_t *v = (atomic_t *)l;
76360@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76361 return (long)atomic_inc_return(v);
76362 }
76363
76364+#ifdef CONFIG_PAX_REFCOUNT
76365+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76366+{
76367+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76368+
76369+ return (long)atomic_inc_return_unchecked(v);
76370+}
76371+#endif
76372+
76373 static inline long atomic_long_dec_return(atomic_long_t *l)
76374 {
76375 atomic_t *v = (atomic_t *)l;
76376@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76377
76378 #endif /* BITS_PER_LONG == 64 */
76379
76380+#ifdef CONFIG_PAX_REFCOUNT
76381+static inline void pax_refcount_needs_these_functions(void)
76382+{
76383+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76384+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76385+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76386+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76387+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76388+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76389+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76390+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76391+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76392+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76393+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76394+#ifdef CONFIG_X86
76395+ atomic_clear_mask_unchecked(0, NULL);
76396+ atomic_set_mask_unchecked(0, NULL);
76397+#endif
76398+
76399+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76400+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76401+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76402+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76403+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76404+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76405+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76406+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76407+}
76408+#else
76409+#define atomic_read_unchecked(v) atomic_read(v)
76410+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76411+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76412+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76413+#define atomic_inc_unchecked(v) atomic_inc(v)
76414+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76415+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76416+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76417+#define atomic_dec_unchecked(v) atomic_dec(v)
76418+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76419+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76420+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76421+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76422+
76423+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76424+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76425+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76426+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76427+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76428+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76429+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76430+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76431+#endif
76432+
76433 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76434diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76435index 33bd2de..f31bff97 100644
76436--- a/include/asm-generic/atomic.h
76437+++ b/include/asm-generic/atomic.h
76438@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76439 * Atomically clears the bits set in @mask from @v
76440 */
76441 #ifndef atomic_clear_mask
76442-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76443+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76444 {
76445 unsigned long flags;
76446
76447diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76448index b18ce4f..2ee2843 100644
76449--- a/include/asm-generic/atomic64.h
76450+++ b/include/asm-generic/atomic64.h
76451@@ -16,6 +16,8 @@ typedef struct {
76452 long long counter;
76453 } atomic64_t;
76454
76455+typedef atomic64_t atomic64_unchecked_t;
76456+
76457 #define ATOMIC64_INIT(i) { (i) }
76458
76459 extern long long atomic64_read(const atomic64_t *v);
76460@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76461 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76462 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76463
76464+#define atomic64_read_unchecked(v) atomic64_read(v)
76465+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76466+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76467+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76468+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76469+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76470+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76471+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76472+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76473+
76474 #endif /* _ASM_GENERIC_ATOMIC64_H */
76475diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76476index a60a7cc..0fe12f2 100644
76477--- a/include/asm-generic/bitops/__fls.h
76478+++ b/include/asm-generic/bitops/__fls.h
76479@@ -9,7 +9,7 @@
76480 *
76481 * Undefined if no set bit exists, so code should check against 0 first.
76482 */
76483-static __always_inline unsigned long __fls(unsigned long word)
76484+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76485 {
76486 int num = BITS_PER_LONG - 1;
76487
76488diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76489index 0576d1f..dad6c71 100644
76490--- a/include/asm-generic/bitops/fls.h
76491+++ b/include/asm-generic/bitops/fls.h
76492@@ -9,7 +9,7 @@
76493 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76494 */
76495
76496-static __always_inline int fls(int x)
76497+static __always_inline int __intentional_overflow(-1) fls(int x)
76498 {
76499 int r = 32;
76500
76501diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76502index b097cf8..3d40e14 100644
76503--- a/include/asm-generic/bitops/fls64.h
76504+++ b/include/asm-generic/bitops/fls64.h
76505@@ -15,7 +15,7 @@
76506 * at position 64.
76507 */
76508 #if BITS_PER_LONG == 32
76509-static __always_inline int fls64(__u64 x)
76510+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76511 {
76512 __u32 h = x >> 32;
76513 if (h)
76514@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76515 return fls(x);
76516 }
76517 #elif BITS_PER_LONG == 64
76518-static __always_inline int fls64(__u64 x)
76519+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76520 {
76521 if (x == 0)
76522 return 0;
76523diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76524index 1bfcfe5..e04c5c9 100644
76525--- a/include/asm-generic/cache.h
76526+++ b/include/asm-generic/cache.h
76527@@ -6,7 +6,7 @@
76528 * cache lines need to provide their own cache.h.
76529 */
76530
76531-#define L1_CACHE_SHIFT 5
76532-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76533+#define L1_CACHE_SHIFT 5UL
76534+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76535
76536 #endif /* __ASM_GENERIC_CACHE_H */
76537diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76538index 0d68a1e..b74a761 100644
76539--- a/include/asm-generic/emergency-restart.h
76540+++ b/include/asm-generic/emergency-restart.h
76541@@ -1,7 +1,7 @@
76542 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76543 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76544
76545-static inline void machine_emergency_restart(void)
76546+static inline __noreturn void machine_emergency_restart(void)
76547 {
76548 machine_restart(NULL);
76549 }
76550diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76551index 90f99c7..00ce236 100644
76552--- a/include/asm-generic/kmap_types.h
76553+++ b/include/asm-generic/kmap_types.h
76554@@ -2,9 +2,9 @@
76555 #define _ASM_GENERIC_KMAP_TYPES_H
76556
76557 #ifdef __WITH_KM_FENCE
76558-# define KM_TYPE_NR 41
76559+# define KM_TYPE_NR 42
76560 #else
76561-# define KM_TYPE_NR 20
76562+# define KM_TYPE_NR 21
76563 #endif
76564
76565 #endif
76566diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76567index 9ceb03b..62b0b8f 100644
76568--- a/include/asm-generic/local.h
76569+++ b/include/asm-generic/local.h
76570@@ -23,24 +23,37 @@ typedef struct
76571 atomic_long_t a;
76572 } local_t;
76573
76574+typedef struct {
76575+ atomic_long_unchecked_t a;
76576+} local_unchecked_t;
76577+
76578 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76579
76580 #define local_read(l) atomic_long_read(&(l)->a)
76581+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76582 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76583+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76584 #define local_inc(l) atomic_long_inc(&(l)->a)
76585+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76586 #define local_dec(l) atomic_long_dec(&(l)->a)
76587+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76588 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76589+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76590 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76591+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76592
76593 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76594 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76595 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76596 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76597 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76598+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76599 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76600 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76601+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76602
76603 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76604+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76605 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76606 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76607 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76608diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76609index 725612b..9cc513a 100644
76610--- a/include/asm-generic/pgtable-nopmd.h
76611+++ b/include/asm-generic/pgtable-nopmd.h
76612@@ -1,14 +1,19 @@
76613 #ifndef _PGTABLE_NOPMD_H
76614 #define _PGTABLE_NOPMD_H
76615
76616-#ifndef __ASSEMBLY__
76617-
76618 #include <asm-generic/pgtable-nopud.h>
76619
76620-struct mm_struct;
76621-
76622 #define __PAGETABLE_PMD_FOLDED
76623
76624+#define PMD_SHIFT PUD_SHIFT
76625+#define PTRS_PER_PMD 1
76626+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76627+#define PMD_MASK (~(PMD_SIZE-1))
76628+
76629+#ifndef __ASSEMBLY__
76630+
76631+struct mm_struct;
76632+
76633 /*
76634 * Having the pmd type consist of a pud gets the size right, and allows
76635 * us to conceptually access the pud entry that this pmd is folded into
76636@@ -16,11 +21,6 @@ struct mm_struct;
76637 */
76638 typedef struct { pud_t pud; } pmd_t;
76639
76640-#define PMD_SHIFT PUD_SHIFT
76641-#define PTRS_PER_PMD 1
76642-#define PMD_SIZE (1UL << PMD_SHIFT)
76643-#define PMD_MASK (~(PMD_SIZE-1))
76644-
76645 /*
76646 * The "pud_xxx()" functions here are trivial for a folded two-level
76647 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76648diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76649index 810431d..0ec4804f 100644
76650--- a/include/asm-generic/pgtable-nopud.h
76651+++ b/include/asm-generic/pgtable-nopud.h
76652@@ -1,10 +1,15 @@
76653 #ifndef _PGTABLE_NOPUD_H
76654 #define _PGTABLE_NOPUD_H
76655
76656-#ifndef __ASSEMBLY__
76657-
76658 #define __PAGETABLE_PUD_FOLDED
76659
76660+#define PUD_SHIFT PGDIR_SHIFT
76661+#define PTRS_PER_PUD 1
76662+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76663+#define PUD_MASK (~(PUD_SIZE-1))
76664+
76665+#ifndef __ASSEMBLY__
76666+
76667 /*
76668 * Having the pud type consist of a pgd gets the size right, and allows
76669 * us to conceptually access the pgd entry that this pud is folded into
76670@@ -12,11 +17,6 @@
76671 */
76672 typedef struct { pgd_t pgd; } pud_t;
76673
76674-#define PUD_SHIFT PGDIR_SHIFT
76675-#define PTRS_PER_PUD 1
76676-#define PUD_SIZE (1UL << PUD_SHIFT)
76677-#define PUD_MASK (~(PUD_SIZE-1))
76678-
76679 /*
76680 * The "pgd_xxx()" functions here are trivial for a folded two-level
76681 * setup: the pud is never bad, and a pud always exists (as it's folded
76682@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76683 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76684
76685 #define pgd_populate(mm, pgd, pud) do { } while (0)
76686+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76687 /*
76688 * (puds are folded into pgds so this doesn't get actually called,
76689 * but the define is needed for a generic inline function.)
76690diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76691index 8e4f41d..c5e9afd 100644
76692--- a/include/asm-generic/pgtable.h
76693+++ b/include/asm-generic/pgtable.h
76694@@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76695 }
76696 #endif /* CONFIG_NUMA_BALANCING */
76697
76698+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76699+#ifdef CONFIG_PAX_KERNEXEC
76700+#error KERNEXEC requires pax_open_kernel
76701+#else
76702+static inline unsigned long pax_open_kernel(void) { return 0; }
76703+#endif
76704+#endif
76705+
76706+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76707+#ifdef CONFIG_PAX_KERNEXEC
76708+#error KERNEXEC requires pax_close_kernel
76709+#else
76710+static inline unsigned long pax_close_kernel(void) { return 0; }
76711+#endif
76712+#endif
76713+
76714 #endif /* CONFIG_MMU */
76715
76716 #endif /* !__ASSEMBLY__ */
76717diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76718index dc1269c..48a4f51 100644
76719--- a/include/asm-generic/uaccess.h
76720+++ b/include/asm-generic/uaccess.h
76721@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76722 return __clear_user(to, n);
76723 }
76724
76725+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76726+#ifdef CONFIG_PAX_MEMORY_UDEREF
76727+#error UDEREF requires pax_open_userland
76728+#else
76729+static inline unsigned long pax_open_userland(void) { return 0; }
76730+#endif
76731+#endif
76732+
76733+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76734+#ifdef CONFIG_PAX_MEMORY_UDEREF
76735+#error UDEREF requires pax_close_userland
76736+#else
76737+static inline unsigned long pax_close_userland(void) { return 0; }
76738+#endif
76739+#endif
76740+
76741 #endif /* __ASM_GENERIC_UACCESS_H */
76742diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76743index bc2121f..2f41f9a 100644
76744--- a/include/asm-generic/vmlinux.lds.h
76745+++ b/include/asm-generic/vmlinux.lds.h
76746@@ -232,6 +232,7 @@
76747 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76748 VMLINUX_SYMBOL(__start_rodata) = .; \
76749 *(.rodata) *(.rodata.*) \
76750+ *(.data..read_only) \
76751 *(__vermagic) /* Kernel version magic */ \
76752 . = ALIGN(8); \
76753 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76754@@ -716,17 +717,18 @@
76755 * section in the linker script will go there too. @phdr should have
76756 * a leading colon.
76757 *
76758- * Note that this macros defines __per_cpu_load as an absolute symbol.
76759+ * Note that this macros defines per_cpu_load as an absolute symbol.
76760 * If there is no need to put the percpu section at a predetermined
76761 * address, use PERCPU_SECTION.
76762 */
76763 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76764- VMLINUX_SYMBOL(__per_cpu_load) = .; \
76765- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76766+ per_cpu_load = .; \
76767+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76768 - LOAD_OFFSET) { \
76769+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76770 PERCPU_INPUT(cacheline) \
76771 } phdr \
76772- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76773+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76774
76775 /**
76776 * PERCPU_SECTION - define output section for percpu area, simple version
76777diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76778index e73c19e..5b89e00 100644
76779--- a/include/crypto/algapi.h
76780+++ b/include/crypto/algapi.h
76781@@ -34,7 +34,7 @@ struct crypto_type {
76782 unsigned int maskclear;
76783 unsigned int maskset;
76784 unsigned int tfmsize;
76785-};
76786+} __do_const;
76787
76788 struct crypto_instance {
76789 struct crypto_alg alg;
76790diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76791index 1d4a920..da65658 100644
76792--- a/include/drm/drmP.h
76793+++ b/include/drm/drmP.h
76794@@ -66,6 +66,7 @@
76795 #include <linux/workqueue.h>
76796 #include <linux/poll.h>
76797 #include <asm/pgalloc.h>
76798+#include <asm/local.h>
76799 #include <drm/drm.h>
76800 #include <drm/drm_sarea.h>
76801 #include <drm/drm_vma_manager.h>
76802@@ -278,10 +279,12 @@ do { \
76803 * \param cmd command.
76804 * \param arg argument.
76805 */
76806-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76807+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76808+ struct drm_file *file_priv);
76809+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76810 struct drm_file *file_priv);
76811
76812-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76813+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76814 unsigned long arg);
76815
76816 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76817@@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76818 struct drm_ioctl_desc {
76819 unsigned int cmd;
76820 int flags;
76821- drm_ioctl_t *func;
76822+ drm_ioctl_t func;
76823 unsigned int cmd_drv;
76824 const char *name;
76825-};
76826+} __do_const;
76827
76828 /**
76829 * Creates a driver or general drm_ioctl_desc array entry for the given
76830@@ -1013,7 +1016,8 @@ struct drm_info_list {
76831 int (*show)(struct seq_file*, void*); /** show callback */
76832 u32 driver_features; /**< Required driver features for this entry */
76833 void *data;
76834-};
76835+} __do_const;
76836+typedef struct drm_info_list __no_const drm_info_list_no_const;
76837
76838 /**
76839 * debugfs node structure. This structure represents a debugfs file.
76840@@ -1097,7 +1101,7 @@ struct drm_device {
76841
76842 /** \name Usage Counters */
76843 /*@{ */
76844- int open_count; /**< Outstanding files open */
76845+ local_t open_count; /**< Outstanding files open */
76846 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76847 atomic_t vma_count; /**< Outstanding vma areas open */
76848 int buf_use; /**< Buffers in use -- cannot alloc */
76849diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76850index ef6ad3a..be34b16 100644
76851--- a/include/drm/drm_crtc_helper.h
76852+++ b/include/drm/drm_crtc_helper.h
76853@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76854 struct drm_connector *connector);
76855 /* disable encoder when not in use - more explicit than dpms off */
76856 void (*disable)(struct drm_encoder *encoder);
76857-};
76858+} __no_const;
76859
76860 /**
76861 * drm_connector_helper_funcs - helper operations for connectors
76862diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76863index 940ece4..8cb727f 100644
76864--- a/include/drm/i915_pciids.h
76865+++ b/include/drm/i915_pciids.h
76866@@ -37,7 +37,7 @@
76867 */
76868 #define INTEL_VGA_DEVICE(id, info) { \
76869 0x8086, id, \
76870- ~0, ~0, \
76871+ PCI_ANY_ID, PCI_ANY_ID, \
76872 0x030000, 0xff0000, \
76873 (unsigned long) info }
76874
76875diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76876index 72dcbe8..8db58d7 100644
76877--- a/include/drm/ttm/ttm_memory.h
76878+++ b/include/drm/ttm/ttm_memory.h
76879@@ -48,7 +48,7 @@
76880
76881 struct ttm_mem_shrink {
76882 int (*do_shrink) (struct ttm_mem_shrink *);
76883-};
76884+} __no_const;
76885
76886 /**
76887 * struct ttm_mem_global - Global memory accounting structure.
76888diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76889index d1f61bf..2239439 100644
76890--- a/include/drm/ttm/ttm_page_alloc.h
76891+++ b/include/drm/ttm/ttm_page_alloc.h
76892@@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
76893 */
76894 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76895
76896+struct device;
76897 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76898 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76899
76900diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76901index 4b840e8..155d235 100644
76902--- a/include/keys/asymmetric-subtype.h
76903+++ b/include/keys/asymmetric-subtype.h
76904@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76905 /* Verify the signature on a key of this subtype (optional) */
76906 int (*verify_signature)(const struct key *key,
76907 const struct public_key_signature *sig);
76908-};
76909+} __do_const;
76910
76911 /**
76912 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76913diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76914index c1da539..1dcec55 100644
76915--- a/include/linux/atmdev.h
76916+++ b/include/linux/atmdev.h
76917@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76918 #endif
76919
76920 struct k_atm_aal_stats {
76921-#define __HANDLE_ITEM(i) atomic_t i
76922+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76923 __AAL_STAT_ITEMS
76924 #undef __HANDLE_ITEM
76925 };
76926@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76927 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76928 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76929 struct module *owner;
76930-};
76931+} __do_const ;
76932
76933 struct atmphy_ops {
76934 int (*start)(struct atm_dev *dev);
76935diff --git a/include/linux/audit.h b/include/linux/audit.h
76936index bf1ef22..2a55e1b 100644
76937--- a/include/linux/audit.h
76938+++ b/include/linux/audit.h
76939@@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
76940 extern unsigned int audit_serial(void);
76941 extern int auditsc_get_stamp(struct audit_context *ctx,
76942 struct timespec *t, unsigned int *serial);
76943-extern int audit_set_loginuid(kuid_t loginuid);
76944+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76945
76946 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76947 {
76948diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76949index fd8bf32..2cccd5a 100644
76950--- a/include/linux/binfmts.h
76951+++ b/include/linux/binfmts.h
76952@@ -74,8 +74,10 @@ struct linux_binfmt {
76953 int (*load_binary)(struct linux_binprm *);
76954 int (*load_shlib)(struct file *);
76955 int (*core_dump)(struct coredump_params *cprm);
76956+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76957+ void (*handle_mmap)(struct file *);
76958 unsigned long min_coredump; /* minimal dump size */
76959-};
76960+} __do_const;
76961
76962 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76963
76964diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76965index abc9ca7..e54ee27 100644
76966--- a/include/linux/bitops.h
76967+++ b/include/linux/bitops.h
76968@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76969 * @word: value to rotate
76970 * @shift: bits to roll
76971 */
76972-static inline __u32 rol32(__u32 word, unsigned int shift)
76973+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76974 {
76975 return (word << shift) | (word >> (32 - shift));
76976 }
76977@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76978 * @word: value to rotate
76979 * @shift: bits to roll
76980 */
76981-static inline __u32 ror32(__u32 word, unsigned int shift)
76982+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76983 {
76984 return (word >> shift) | (word << (32 - shift));
76985 }
76986@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76987 return (__s32)(value << shift) >> shift;
76988 }
76989
76990-static inline unsigned fls_long(unsigned long l)
76991+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76992 {
76993 if (sizeof(l) == 4)
76994 return fls(l);
76995diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76996index 1b135d4..59fc876 100644
76997--- a/include/linux/blkdev.h
76998+++ b/include/linux/blkdev.h
76999@@ -1578,7 +1578,7 @@ struct block_device_operations {
77000 /* this callback is with swap_lock and sometimes page table lock held */
77001 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77002 struct module *owner;
77003-};
77004+} __do_const;
77005
77006 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77007 unsigned long);
77008diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77009index afc1343..9735539 100644
77010--- a/include/linux/blktrace_api.h
77011+++ b/include/linux/blktrace_api.h
77012@@ -25,7 +25,7 @@ struct blk_trace {
77013 struct dentry *dropped_file;
77014 struct dentry *msg_file;
77015 struct list_head running_list;
77016- atomic_t dropped;
77017+ atomic_unchecked_t dropped;
77018 };
77019
77020 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77021diff --git a/include/linux/cache.h b/include/linux/cache.h
77022index 4c57065..40346da 100644
77023--- a/include/linux/cache.h
77024+++ b/include/linux/cache.h
77025@@ -16,6 +16,14 @@
77026 #define __read_mostly
77027 #endif
77028
77029+#ifndef __read_only
77030+#ifdef CONFIG_PAX_KERNEXEC
77031+#error KERNEXEC requires __read_only
77032+#else
77033+#define __read_only __read_mostly
77034+#endif
77035+#endif
77036+
77037 #ifndef ____cacheline_aligned
77038 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77039 #endif
77040diff --git a/include/linux/capability.h b/include/linux/capability.h
77041index a6ee1f9..e1ca49d 100644
77042--- a/include/linux/capability.h
77043+++ b/include/linux/capability.h
77044@@ -212,8 +212,13 @@ extern bool capable(int cap);
77045 extern bool ns_capable(struct user_namespace *ns, int cap);
77046 extern bool inode_capable(const struct inode *inode, int cap);
77047 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77048+extern bool capable_nolog(int cap);
77049+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77050+extern bool inode_capable_nolog(const struct inode *inode, int cap);
77051
77052 /* audit system wants to get cap info from files as well */
77053 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77054
77055+extern int is_privileged_binary(const struct dentry *dentry);
77056+
77057 #endif /* !_LINUX_CAPABILITY_H */
77058diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77059index 8609d57..86e4d79 100644
77060--- a/include/linux/cdrom.h
77061+++ b/include/linux/cdrom.h
77062@@ -87,7 +87,6 @@ struct cdrom_device_ops {
77063
77064 /* driver specifications */
77065 const int capability; /* capability flags */
77066- int n_minors; /* number of active minor devices */
77067 /* handle uniform packets for scsi type devices (scsi,atapi) */
77068 int (*generic_packet) (struct cdrom_device_info *,
77069 struct packet_command *);
77070diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77071index 4ce9056..86caac6 100644
77072--- a/include/linux/cleancache.h
77073+++ b/include/linux/cleancache.h
77074@@ -31,7 +31,7 @@ struct cleancache_ops {
77075 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77076 void (*invalidate_inode)(int, struct cleancache_filekey);
77077 void (*invalidate_fs)(int);
77078-};
77079+} __no_const;
77080
77081 extern struct cleancache_ops *
77082 cleancache_register_ops(struct cleancache_ops *ops);
77083diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77084index 7e59253..d6e4cae 100644
77085--- a/include/linux/clk-provider.h
77086+++ b/include/linux/clk-provider.h
77087@@ -141,6 +141,7 @@ struct clk_ops {
77088 unsigned long);
77089 void (*init)(struct clk_hw *hw);
77090 };
77091+typedef struct clk_ops __no_const clk_ops_no_const;
77092
77093 /**
77094 * struct clk_init_data - holds init data that's common to all clocks and is
77095diff --git a/include/linux/compat.h b/include/linux/compat.h
77096index 19f6003..90b64f4 100644
77097--- a/include/linux/compat.h
77098+++ b/include/linux/compat.h
77099@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77100 compat_size_t __user *len_ptr);
77101
77102 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77103-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77104+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77105 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77106 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77107 compat_ssize_t msgsz, int msgflg);
77108@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77109 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77110 compat_ulong_t addr, compat_ulong_t data);
77111 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77112- compat_long_t addr, compat_long_t data);
77113+ compat_ulong_t addr, compat_ulong_t data);
77114
77115 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77116 /*
77117diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77118index 2507fd2..55203f8 100644
77119--- a/include/linux/compiler-gcc4.h
77120+++ b/include/linux/compiler-gcc4.h
77121@@ -39,9 +39,34 @@
77122 # define __compiletime_warning(message) __attribute__((warning(message)))
77123 # define __compiletime_error(message) __attribute__((error(message)))
77124 #endif /* __CHECKER__ */
77125+
77126+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77127+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77128+#define __bos0(ptr) __bos((ptr), 0)
77129+#define __bos1(ptr) __bos((ptr), 1)
77130 #endif /* GCC_VERSION >= 40300 */
77131
77132 #if GCC_VERSION >= 40500
77133+
77134+#ifdef RANDSTRUCT_PLUGIN
77135+#define __randomize_layout __attribute__((randomize_layout))
77136+#define __no_randomize_layout __attribute__((no_randomize_layout))
77137+#endif
77138+
77139+#ifdef CONSTIFY_PLUGIN
77140+#define __no_const __attribute__((no_const))
77141+#define __do_const __attribute__((do_const))
77142+#endif
77143+
77144+#ifdef SIZE_OVERFLOW_PLUGIN
77145+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77146+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77147+#endif
77148+
77149+#ifdef LATENT_ENTROPY_PLUGIN
77150+#define __latent_entropy __attribute__((latent_entropy))
77151+#endif
77152+
77153 /*
77154 * Mark a position in code as unreachable. This can be used to
77155 * suppress control flow warnings after asm blocks that transfer
77156diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77157index 92669cd..cc564c0 100644
77158--- a/include/linux/compiler.h
77159+++ b/include/linux/compiler.h
77160@@ -5,11 +5,14 @@
77161
77162 #ifdef __CHECKER__
77163 # define __user __attribute__((noderef, address_space(1)))
77164+# define __force_user __force __user
77165 # define __kernel __attribute__((address_space(0)))
77166+# define __force_kernel __force __kernel
77167 # define __safe __attribute__((safe))
77168 # define __force __attribute__((force))
77169 # define __nocast __attribute__((nocast))
77170 # define __iomem __attribute__((noderef, address_space(2)))
77171+# define __force_iomem __force __iomem
77172 # define __must_hold(x) __attribute__((context(x,1,1)))
77173 # define __acquires(x) __attribute__((context(x,0,1)))
77174 # define __releases(x) __attribute__((context(x,1,0)))
77175@@ -17,20 +20,37 @@
77176 # define __release(x) __context__(x,-1)
77177 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77178 # define __percpu __attribute__((noderef, address_space(3)))
77179+# define __force_percpu __force __percpu
77180 #ifdef CONFIG_SPARSE_RCU_POINTER
77181 # define __rcu __attribute__((noderef, address_space(4)))
77182+# define __force_rcu __force __rcu
77183 #else
77184 # define __rcu
77185+# define __force_rcu
77186 #endif
77187 extern void __chk_user_ptr(const volatile void __user *);
77188 extern void __chk_io_ptr(const volatile void __iomem *);
77189 #else
77190-# define __user
77191-# define __kernel
77192+# ifdef CHECKER_PLUGIN
77193+//# define __user
77194+//# define __force_user
77195+//# define __kernel
77196+//# define __force_kernel
77197+# else
77198+# ifdef STRUCTLEAK_PLUGIN
77199+# define __user __attribute__((user))
77200+# else
77201+# define __user
77202+# endif
77203+# define __force_user
77204+# define __kernel
77205+# define __force_kernel
77206+# endif
77207 # define __safe
77208 # define __force
77209 # define __nocast
77210 # define __iomem
77211+# define __force_iomem
77212 # define __chk_user_ptr(x) (void)0
77213 # define __chk_io_ptr(x) (void)0
77214 # define __builtin_warning(x, y...) (1)
77215@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77216 # define __release(x) (void)0
77217 # define __cond_lock(x,c) (c)
77218 # define __percpu
77219+# define __force_percpu
77220 # define __rcu
77221+# define __force_rcu
77222 #endif
77223
77224 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77225@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77226 # define __attribute_const__ /* unimplemented */
77227 #endif
77228
77229+#ifndef __randomize_layout
77230+# define __randomize_layout
77231+#endif
77232+
77233+#ifndef __no_randomize_layout
77234+# define __no_randomize_layout
77235+#endif
77236+
77237+#ifndef __no_const
77238+# define __no_const
77239+#endif
77240+
77241+#ifndef __do_const
77242+# define __do_const
77243+#endif
77244+
77245+#ifndef __size_overflow
77246+# define __size_overflow(...)
77247+#endif
77248+
77249+#ifndef __intentional_overflow
77250+# define __intentional_overflow(...)
77251+#endif
77252+
77253+#ifndef __latent_entropy
77254+# define __latent_entropy
77255+#endif
77256+
77257 /*
77258 * Tell gcc if a function is cold. The compiler will assume any path
77259 * directly leading to the call is unlikely.
77260@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77261 #define __cold
77262 #endif
77263
77264+#ifndef __alloc_size
77265+#define __alloc_size(...)
77266+#endif
77267+
77268+#ifndef __bos
77269+#define __bos(ptr, arg)
77270+#endif
77271+
77272+#ifndef __bos0
77273+#define __bos0(ptr)
77274+#endif
77275+
77276+#ifndef __bos1
77277+#define __bos1(ptr)
77278+#endif
77279+
77280 /* Simple shorthand for a section definition */
77281 #ifndef __section
77282 # define __section(S) __attribute__ ((__section__(#S)))
77283@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77284 * use is to mediate communication between process-level code and irq/NMI
77285 * handlers, all running on the same CPU.
77286 */
77287-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77288+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77289+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77290
77291 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77292 #ifdef CONFIG_KPROBES
77293diff --git a/include/linux/completion.h b/include/linux/completion.h
77294index 5d5aaae..0ea9b84 100644
77295--- a/include/linux/completion.h
77296+++ b/include/linux/completion.h
77297@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77298
77299 extern void wait_for_completion(struct completion *);
77300 extern void wait_for_completion_io(struct completion *);
77301-extern int wait_for_completion_interruptible(struct completion *x);
77302-extern int wait_for_completion_killable(struct completion *x);
77303+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77304+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77305 extern unsigned long wait_for_completion_timeout(struct completion *x,
77306- unsigned long timeout);
77307+ unsigned long timeout) __intentional_overflow(-1);
77308 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77309- unsigned long timeout);
77310+ unsigned long timeout) __intentional_overflow(-1);
77311 extern long wait_for_completion_interruptible_timeout(
77312- struct completion *x, unsigned long timeout);
77313+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77314 extern long wait_for_completion_killable_timeout(
77315- struct completion *x, unsigned long timeout);
77316+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77317 extern bool try_wait_for_completion(struct completion *x);
77318 extern bool completion_done(struct completion *x);
77319
77320diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77321index 34025df..d94bbbc 100644
77322--- a/include/linux/configfs.h
77323+++ b/include/linux/configfs.h
77324@@ -125,7 +125,7 @@ struct configfs_attribute {
77325 const char *ca_name;
77326 struct module *ca_owner;
77327 umode_t ca_mode;
77328-};
77329+} __do_const;
77330
77331 /*
77332 * Users often need to create attribute structures for their configurable
77333diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77334index dc196bb..c55a50f 100644
77335--- a/include/linux/cpufreq.h
77336+++ b/include/linux/cpufreq.h
77337@@ -189,6 +189,7 @@ struct global_attr {
77338 ssize_t (*store)(struct kobject *a, struct attribute *b,
77339 const char *c, size_t count);
77340 };
77341+typedef struct global_attr __no_const global_attr_no_const;
77342
77343 #define define_one_global_ro(_name) \
77344 static struct global_attr _name = \
77345@@ -225,7 +226,7 @@ struct cpufreq_driver {
77346 int (*suspend) (struct cpufreq_policy *policy);
77347 int (*resume) (struct cpufreq_policy *policy);
77348 struct freq_attr **attr;
77349-};
77350+} __do_const;
77351
77352 /* flags */
77353 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77354diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77355index 50fcbb0..9d2dbd9 100644
77356--- a/include/linux/cpuidle.h
77357+++ b/include/linux/cpuidle.h
77358@@ -50,7 +50,8 @@ struct cpuidle_state {
77359 int index);
77360
77361 int (*enter_dead) (struct cpuidle_device *dev, int index);
77362-};
77363+} __do_const;
77364+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77365
77366 /* Idle State Flags */
77367 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77368@@ -192,7 +193,7 @@ struct cpuidle_governor {
77369 void (*reflect) (struct cpuidle_device *dev, int index);
77370
77371 struct module *owner;
77372-};
77373+} __do_const;
77374
77375 #ifdef CONFIG_CPU_IDLE
77376 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77377diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77378index d08e4d2..95fad61 100644
77379--- a/include/linux/cpumask.h
77380+++ b/include/linux/cpumask.h
77381@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77382 }
77383
77384 /* Valid inputs for n are -1 and 0. */
77385-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77386+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77387 {
77388 return n+1;
77389 }
77390
77391-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77392+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77393 {
77394 return n+1;
77395 }
77396
77397-static inline unsigned int cpumask_next_and(int n,
77398+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77399 const struct cpumask *srcp,
77400 const struct cpumask *andp)
77401 {
77402@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77403 *
77404 * Returns >= nr_cpu_ids if no further cpus set.
77405 */
77406-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77407+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77408 {
77409 /* -1 is a legal arg here. */
77410 if (n != -1)
77411@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77412 *
77413 * Returns >= nr_cpu_ids if no further cpus unset.
77414 */
77415-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77416+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77417 {
77418 /* -1 is a legal arg here. */
77419 if (n != -1)
77420@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77421 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77422 }
77423
77424-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77425+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77426 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77427
77428 /**
77429diff --git a/include/linux/cred.h b/include/linux/cred.h
77430index 04421e8..117e17a 100644
77431--- a/include/linux/cred.h
77432+++ b/include/linux/cred.h
77433@@ -35,7 +35,7 @@ struct group_info {
77434 int nblocks;
77435 kgid_t small_block[NGROUPS_SMALL];
77436 kgid_t *blocks[0];
77437-};
77438+} __randomize_layout;
77439
77440 /**
77441 * get_group_info - Get a reference to a group info structure
77442@@ -136,7 +136,7 @@ struct cred {
77443 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77444 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77445 struct rcu_head rcu; /* RCU deletion hook */
77446-};
77447+} __randomize_layout;
77448
77449 extern void __put_cred(struct cred *);
77450 extern void exit_creds(struct task_struct *);
77451@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77452 static inline void validate_process_creds(void)
77453 {
77454 }
77455+static inline void validate_task_creds(struct task_struct *task)
77456+{
77457+}
77458 #endif
77459
77460 /**
77461diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77462index b92eadf..b4ecdc1 100644
77463--- a/include/linux/crypto.h
77464+++ b/include/linux/crypto.h
77465@@ -373,7 +373,7 @@ struct cipher_tfm {
77466 const u8 *key, unsigned int keylen);
77467 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77468 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77469-};
77470+} __no_const;
77471
77472 struct hash_tfm {
77473 int (*init)(struct hash_desc *desc);
77474@@ -394,13 +394,13 @@ struct compress_tfm {
77475 int (*cot_decompress)(struct crypto_tfm *tfm,
77476 const u8 *src, unsigned int slen,
77477 u8 *dst, unsigned int *dlen);
77478-};
77479+} __no_const;
77480
77481 struct rng_tfm {
77482 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77483 unsigned int dlen);
77484 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77485-};
77486+} __no_const;
77487
77488 #define crt_ablkcipher crt_u.ablkcipher
77489 #define crt_aead crt_u.aead
77490diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77491index 653589e..4ef254a 100644
77492--- a/include/linux/ctype.h
77493+++ b/include/linux/ctype.h
77494@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77495 * Fast implementation of tolower() for internal usage. Do not use in your
77496 * code.
77497 */
77498-static inline char _tolower(const char c)
77499+static inline unsigned char _tolower(const unsigned char c)
77500 {
77501 return c | 0x20;
77502 }
77503diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77504index bf72e9a..4ca7927 100644
77505--- a/include/linux/dcache.h
77506+++ b/include/linux/dcache.h
77507@@ -133,7 +133,7 @@ struct dentry {
77508 } d_u;
77509 struct list_head d_subdirs; /* our children */
77510 struct hlist_node d_alias; /* inode alias list */
77511-};
77512+} __randomize_layout;
77513
77514 /*
77515 * dentry->d_lock spinlock nesting subclasses:
77516diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77517index 7925bf0..d5143d2 100644
77518--- a/include/linux/decompress/mm.h
77519+++ b/include/linux/decompress/mm.h
77520@@ -77,7 +77,7 @@ static void free(void *where)
77521 * warnings when not needed (indeed large_malloc / large_free are not
77522 * needed by inflate */
77523
77524-#define malloc(a) kmalloc(a, GFP_KERNEL)
77525+#define malloc(a) kmalloc((a), GFP_KERNEL)
77526 #define free(a) kfree(a)
77527
77528 #define large_malloc(a) vmalloc(a)
77529diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77530index d48dc00..211ee54 100644
77531--- a/include/linux/devfreq.h
77532+++ b/include/linux/devfreq.h
77533@@ -114,7 +114,7 @@ struct devfreq_governor {
77534 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77535 int (*event_handler)(struct devfreq *devfreq,
77536 unsigned int event, void *data);
77537-};
77538+} __do_const;
77539
77540 /**
77541 * struct devfreq - Device devfreq structure
77542diff --git a/include/linux/device.h b/include/linux/device.h
77543index 952b010..d5b7691 100644
77544--- a/include/linux/device.h
77545+++ b/include/linux/device.h
77546@@ -310,7 +310,7 @@ struct subsys_interface {
77547 struct list_head node;
77548 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77549 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77550-};
77551+} __do_const;
77552
77553 int subsys_interface_register(struct subsys_interface *sif);
77554 void subsys_interface_unregister(struct subsys_interface *sif);
77555@@ -506,7 +506,7 @@ struct device_type {
77556 void (*release)(struct device *dev);
77557
77558 const struct dev_pm_ops *pm;
77559-};
77560+} __do_const;
77561
77562 /* interface for exporting device attributes */
77563 struct device_attribute {
77564@@ -516,11 +516,12 @@ struct device_attribute {
77565 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77566 const char *buf, size_t count);
77567 };
77568+typedef struct device_attribute __no_const device_attribute_no_const;
77569
77570 struct dev_ext_attribute {
77571 struct device_attribute attr;
77572 void *var;
77573-};
77574+} __do_const;
77575
77576 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77577 char *buf);
77578diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77579index fd4aee2..1f28db9 100644
77580--- a/include/linux/dma-mapping.h
77581+++ b/include/linux/dma-mapping.h
77582@@ -54,7 +54,7 @@ struct dma_map_ops {
77583 u64 (*get_required_mask)(struct device *dev);
77584 #endif
77585 int is_phys;
77586-};
77587+} __do_const;
77588
77589 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77590
77591diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77592index 41cf0c3..f3b771c 100644
77593--- a/include/linux/dmaengine.h
77594+++ b/include/linux/dmaengine.h
77595@@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77596 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77597 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77598
77599-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77600+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77601 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77602-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77603+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77604 struct dma_pinned_list *pinned_list, struct page *page,
77605 unsigned int offset, size_t len);
77606
77607diff --git a/include/linux/efi.h b/include/linux/efi.h
77608index 11ce678..7b8c69c 100644
77609--- a/include/linux/efi.h
77610+++ b/include/linux/efi.h
77611@@ -764,6 +764,7 @@ struct efivar_operations {
77612 efi_set_variable_t *set_variable;
77613 efi_query_variable_store_t *query_variable_store;
77614 };
77615+typedef struct efivar_operations __no_const efivar_operations_no_const;
77616
77617 struct efivars {
77618 /*
77619diff --git a/include/linux/elf.h b/include/linux/elf.h
77620index 67a5fa7..b817372 100644
77621--- a/include/linux/elf.h
77622+++ b/include/linux/elf.h
77623@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77624 #define elf_note elf32_note
77625 #define elf_addr_t Elf32_Off
77626 #define Elf_Half Elf32_Half
77627+#define elf_dyn Elf32_Dyn
77628
77629 #else
77630
77631@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77632 #define elf_note elf64_note
77633 #define elf_addr_t Elf64_Off
77634 #define Elf_Half Elf64_Half
77635+#define elf_dyn Elf64_Dyn
77636
77637 #endif
77638
77639diff --git a/include/linux/err.h b/include/linux/err.h
77640index 15f92e0..e825a8e 100644
77641--- a/include/linux/err.h
77642+++ b/include/linux/err.h
77643@@ -19,12 +19,12 @@
77644
77645 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77646
77647-static inline void * __must_check ERR_PTR(long error)
77648+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77649 {
77650 return (void *) error;
77651 }
77652
77653-static inline long __must_check PTR_ERR(__force const void *ptr)
77654+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77655 {
77656 return (long) ptr;
77657 }
77658diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77659index 21c59af..6057a03 100644
77660--- a/include/linux/extcon.h
77661+++ b/include/linux/extcon.h
77662@@ -135,7 +135,7 @@ struct extcon_dev {
77663 /* /sys/class/extcon/.../mutually_exclusive/... */
77664 struct attribute_group attr_g_muex;
77665 struct attribute **attrs_muex;
77666- struct device_attribute *d_attrs_muex;
77667+ device_attribute_no_const *d_attrs_muex;
77668 };
77669
77670 /**
77671diff --git a/include/linux/fb.h b/include/linux/fb.h
77672index 70c4836..ff3daec 100644
77673--- a/include/linux/fb.h
77674+++ b/include/linux/fb.h
77675@@ -304,7 +304,7 @@ struct fb_ops {
77676 /* called at KDB enter and leave time to prepare the console */
77677 int (*fb_debug_enter)(struct fb_info *info);
77678 int (*fb_debug_leave)(struct fb_info *info);
77679-};
77680+} __do_const;
77681
77682 #ifdef CONFIG_FB_TILEBLITTING
77683 #define FB_TILE_CURSOR_NONE 0
77684diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77685index 085197b..0fa6f0b 100644
77686--- a/include/linux/fdtable.h
77687+++ b/include/linux/fdtable.h
77688@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77689 void put_files_struct(struct files_struct *fs);
77690 void reset_files_struct(struct files_struct *);
77691 int unshare_files(struct files_struct **);
77692-struct files_struct *dup_fd(struct files_struct *, int *);
77693+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77694 void do_close_on_exec(struct files_struct *);
77695 int iterate_fd(struct files_struct *, unsigned,
77696 int (*)(const void *, struct file *, unsigned),
77697diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77698index 8293262..2b3b8bd 100644
77699--- a/include/linux/frontswap.h
77700+++ b/include/linux/frontswap.h
77701@@ -11,7 +11,7 @@ struct frontswap_ops {
77702 int (*load)(unsigned, pgoff_t, struct page *);
77703 void (*invalidate_page)(unsigned, pgoff_t);
77704 void (*invalidate_area)(unsigned);
77705-};
77706+} __no_const;
77707
77708 extern bool frontswap_enabled;
77709 extern struct frontswap_ops *
77710diff --git a/include/linux/fs.h b/include/linux/fs.h
77711index 121f11f..0f2a863 100644
77712--- a/include/linux/fs.h
77713+++ b/include/linux/fs.h
77714@@ -423,7 +423,7 @@ struct address_space {
77715 spinlock_t private_lock; /* for use by the address_space */
77716 struct list_head private_list; /* ditto */
77717 void *private_data; /* ditto */
77718-} __attribute__((aligned(sizeof(long))));
77719+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77720 /*
77721 * On most architectures that alignment is already the case; but
77722 * must be enforced here for CRIS, to let the least significant bit
77723@@ -466,7 +466,7 @@ struct block_device {
77724 int bd_fsfreeze_count;
77725 /* Mutex for freeze */
77726 struct mutex bd_fsfreeze_mutex;
77727-};
77728+} __randomize_layout;
77729
77730 /*
77731 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77732@@ -610,7 +610,7 @@ struct inode {
77733 atomic_t i_readcount; /* struct files open RO */
77734 #endif
77735 void *i_private; /* fs or device private pointer */
77736-};
77737+} __randomize_layout;
77738
77739 static inline int inode_unhashed(struct inode *inode)
77740 {
77741@@ -808,7 +808,7 @@ struct file {
77742 #ifdef CONFIG_DEBUG_WRITECOUNT
77743 unsigned long f_mnt_write_state;
77744 #endif
77745-};
77746+} __randomize_layout;
77747
77748 struct file_handle {
77749 __u32 handle_bytes;
77750@@ -978,7 +978,7 @@ struct file_lock {
77751 int state; /* state of grant or error if -ve */
77752 } afs;
77753 } fl_u;
77754-};
77755+} __randomize_layout;
77756
77757 /* The following constant reflects the upper bound of the file/locking space */
77758 #ifndef OFFSET_MAX
77759@@ -1325,7 +1325,7 @@ struct super_block {
77760 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77761 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77762 struct rcu_head rcu;
77763-};
77764+} __randomize_layout;
77765
77766 extern struct timespec current_fs_time(struct super_block *sb);
77767
77768@@ -1547,7 +1547,8 @@ struct file_operations {
77769 long (*fallocate)(struct file *file, int mode, loff_t offset,
77770 loff_t len);
77771 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77772-};
77773+} __do_const __randomize_layout;
77774+typedef struct file_operations __no_const file_operations_no_const;
77775
77776 struct inode_operations {
77777 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77778@@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77779 return !IS_DEADDIR(inode);
77780 }
77781
77782+static inline bool is_sidechannel_device(const struct inode *inode)
77783+{
77784+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77785+ umode_t mode = inode->i_mode;
77786+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77787+#else
77788+ return false;
77789+#endif
77790+}
77791+
77792 #endif /* _LINUX_FS_H */
77793diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77794index 0efc3e6..fd23610 100644
77795--- a/include/linux/fs_struct.h
77796+++ b/include/linux/fs_struct.h
77797@@ -6,13 +6,13 @@
77798 #include <linux/seqlock.h>
77799
77800 struct fs_struct {
77801- int users;
77802+ atomic_t users;
77803 spinlock_t lock;
77804 seqcount_t seq;
77805 int umask;
77806 int in_exec;
77807 struct path root, pwd;
77808-};
77809+} __randomize_layout;
77810
77811 extern struct kmem_cache *fs_cachep;
77812
77813diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77814index 7714849..a4a5c7a 100644
77815--- a/include/linux/fscache-cache.h
77816+++ b/include/linux/fscache-cache.h
77817@@ -113,7 +113,7 @@ struct fscache_operation {
77818 fscache_operation_release_t release;
77819 };
77820
77821-extern atomic_t fscache_op_debug_id;
77822+extern atomic_unchecked_t fscache_op_debug_id;
77823 extern void fscache_op_work_func(struct work_struct *work);
77824
77825 extern void fscache_enqueue_operation(struct fscache_operation *);
77826@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77827 INIT_WORK(&op->work, fscache_op_work_func);
77828 atomic_set(&op->usage, 1);
77829 op->state = FSCACHE_OP_ST_INITIALISED;
77830- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77831+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77832 op->processor = processor;
77833 op->release = release;
77834 INIT_LIST_HEAD(&op->pend_link);
77835diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77836index 115bb81..e7b812b 100644
77837--- a/include/linux/fscache.h
77838+++ b/include/linux/fscache.h
77839@@ -152,7 +152,7 @@ struct fscache_cookie_def {
77840 * - this is mandatory for any object that may have data
77841 */
77842 void (*now_uncached)(void *cookie_netfs_data);
77843-};
77844+} __do_const;
77845
77846 /*
77847 * fscache cached network filesystem type
77848diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77849index 1c804b0..1432c2b 100644
77850--- a/include/linux/fsnotify.h
77851+++ b/include/linux/fsnotify.h
77852@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77853 struct inode *inode = file_inode(file);
77854 __u32 mask = FS_ACCESS;
77855
77856+ if (is_sidechannel_device(inode))
77857+ return;
77858+
77859 if (S_ISDIR(inode->i_mode))
77860 mask |= FS_ISDIR;
77861
77862@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77863 struct inode *inode = file_inode(file);
77864 __u32 mask = FS_MODIFY;
77865
77866+ if (is_sidechannel_device(inode))
77867+ return;
77868+
77869 if (S_ISDIR(inode->i_mode))
77870 mask |= FS_ISDIR;
77871
77872@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77873 */
77874 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77875 {
77876- return kstrdup(name, GFP_KERNEL);
77877+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77878 }
77879
77880 /*
77881diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77882index 9f3c275..8bdff5d 100644
77883--- a/include/linux/genhd.h
77884+++ b/include/linux/genhd.h
77885@@ -194,7 +194,7 @@ struct gendisk {
77886 struct kobject *slave_dir;
77887
77888 struct timer_rand_state *random;
77889- atomic_t sync_io; /* RAID */
77890+ atomic_unchecked_t sync_io; /* RAID */
77891 struct disk_events *ev;
77892 #ifdef CONFIG_BLK_DEV_INTEGRITY
77893 struct blk_integrity *integrity;
77894@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77895 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77896
77897 /* drivers/char/random.c */
77898-extern void add_disk_randomness(struct gendisk *disk);
77899+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77900 extern void rand_initialize_disk(struct gendisk *disk);
77901
77902 static inline sector_t get_start_sect(struct block_device *bdev)
77903diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77904index c0894dd..2fbf10c 100644
77905--- a/include/linux/genl_magic_func.h
77906+++ b/include/linux/genl_magic_func.h
77907@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77908 },
77909
77910 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77911-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77912+static struct genl_ops ZZZ_genl_ops[] = {
77913 #include GENL_MAGIC_INCLUDE_FILE
77914 };
77915
77916diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77917index 9b4dd49..61fd41d 100644
77918--- a/include/linux/gfp.h
77919+++ b/include/linux/gfp.h
77920@@ -35,6 +35,13 @@ struct vm_area_struct;
77921 #define ___GFP_NO_KSWAPD 0x400000u
77922 #define ___GFP_OTHER_NODE 0x800000u
77923 #define ___GFP_WRITE 0x1000000u
77924+
77925+#ifdef CONFIG_PAX_USERCOPY_SLABS
77926+#define ___GFP_USERCOPY 0x2000000u
77927+#else
77928+#define ___GFP_USERCOPY 0
77929+#endif
77930+
77931 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77932
77933 /*
77934@@ -92,6 +99,7 @@ struct vm_area_struct;
77935 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77936 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77937 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77938+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77939
77940 /*
77941 * This may seem redundant, but it's a way of annotating false positives vs.
77942@@ -99,7 +107,7 @@ struct vm_area_struct;
77943 */
77944 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77945
77946-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77947+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77948 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77949
77950 /* This equals 0, but use constants in case they ever change */
77951@@ -153,6 +161,8 @@ struct vm_area_struct;
77952 /* 4GB DMA on some platforms */
77953 #define GFP_DMA32 __GFP_DMA32
77954
77955+#define GFP_USERCOPY __GFP_USERCOPY
77956+
77957 /* Convert GFP flags to their corresponding migrate type */
77958 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77959 {
77960diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77961new file mode 100644
77962index 0000000..edb2cb6
77963--- /dev/null
77964+++ b/include/linux/gracl.h
77965@@ -0,0 +1,340 @@
77966+#ifndef GR_ACL_H
77967+#define GR_ACL_H
77968+
77969+#include <linux/grdefs.h>
77970+#include <linux/resource.h>
77971+#include <linux/capability.h>
77972+#include <linux/dcache.h>
77973+#include <asm/resource.h>
77974+
77975+/* Major status information */
77976+
77977+#define GR_VERSION "grsecurity 3.0"
77978+#define GRSECURITY_VERSION 0x3000
77979+
77980+enum {
77981+ GR_SHUTDOWN = 0,
77982+ GR_ENABLE = 1,
77983+ GR_SPROLE = 2,
77984+ GR_OLDRELOAD = 3,
77985+ GR_SEGVMOD = 4,
77986+ GR_STATUS = 5,
77987+ GR_UNSPROLE = 6,
77988+ GR_PASSSET = 7,
77989+ GR_SPROLEPAM = 8,
77990+ GR_RELOAD = 9,
77991+};
77992+
77993+/* Password setup definitions
77994+ * kernel/grhash.c */
77995+enum {
77996+ GR_PW_LEN = 128,
77997+ GR_SALT_LEN = 16,
77998+ GR_SHA_LEN = 32,
77999+};
78000+
78001+enum {
78002+ GR_SPROLE_LEN = 64,
78003+};
78004+
78005+enum {
78006+ GR_NO_GLOB = 0,
78007+ GR_REG_GLOB,
78008+ GR_CREATE_GLOB
78009+};
78010+
78011+#define GR_NLIMITS 32
78012+
78013+/* Begin Data Structures */
78014+
78015+struct sprole_pw {
78016+ unsigned char *rolename;
78017+ unsigned char salt[GR_SALT_LEN];
78018+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78019+};
78020+
78021+struct name_entry {
78022+ __u32 key;
78023+ ino_t inode;
78024+ dev_t device;
78025+ char *name;
78026+ __u16 len;
78027+ __u8 deleted;
78028+ struct name_entry *prev;
78029+ struct name_entry *next;
78030+};
78031+
78032+struct inodev_entry {
78033+ struct name_entry *nentry;
78034+ struct inodev_entry *prev;
78035+ struct inodev_entry *next;
78036+};
78037+
78038+struct acl_role_db {
78039+ struct acl_role_label **r_hash;
78040+ __u32 r_size;
78041+};
78042+
78043+struct inodev_db {
78044+ struct inodev_entry **i_hash;
78045+ __u32 i_size;
78046+};
78047+
78048+struct name_db {
78049+ struct name_entry **n_hash;
78050+ __u32 n_size;
78051+};
78052+
78053+struct crash_uid {
78054+ uid_t uid;
78055+ unsigned long expires;
78056+};
78057+
78058+struct gr_hash_struct {
78059+ void **table;
78060+ void **nametable;
78061+ void *first;
78062+ __u32 table_size;
78063+ __u32 used_size;
78064+ int type;
78065+};
78066+
78067+/* Userspace Grsecurity ACL data structures */
78068+
78069+struct acl_subject_label {
78070+ char *filename;
78071+ ino_t inode;
78072+ dev_t device;
78073+ __u32 mode;
78074+ kernel_cap_t cap_mask;
78075+ kernel_cap_t cap_lower;
78076+ kernel_cap_t cap_invert_audit;
78077+
78078+ struct rlimit res[GR_NLIMITS];
78079+ __u32 resmask;
78080+
78081+ __u8 user_trans_type;
78082+ __u8 group_trans_type;
78083+ uid_t *user_transitions;
78084+ gid_t *group_transitions;
78085+ __u16 user_trans_num;
78086+ __u16 group_trans_num;
78087+
78088+ __u32 sock_families[2];
78089+ __u32 ip_proto[8];
78090+ __u32 ip_type;
78091+ struct acl_ip_label **ips;
78092+ __u32 ip_num;
78093+ __u32 inaddr_any_override;
78094+
78095+ __u32 crashes;
78096+ unsigned long expires;
78097+
78098+ struct acl_subject_label *parent_subject;
78099+ struct gr_hash_struct *hash;
78100+ struct acl_subject_label *prev;
78101+ struct acl_subject_label *next;
78102+
78103+ struct acl_object_label **obj_hash;
78104+ __u32 obj_hash_size;
78105+ __u16 pax_flags;
78106+};
78107+
78108+struct role_allowed_ip {
78109+ __u32 addr;
78110+ __u32 netmask;
78111+
78112+ struct role_allowed_ip *prev;
78113+ struct role_allowed_ip *next;
78114+};
78115+
78116+struct role_transition {
78117+ char *rolename;
78118+
78119+ struct role_transition *prev;
78120+ struct role_transition *next;
78121+};
78122+
78123+struct acl_role_label {
78124+ char *rolename;
78125+ uid_t uidgid;
78126+ __u16 roletype;
78127+
78128+ __u16 auth_attempts;
78129+ unsigned long expires;
78130+
78131+ struct acl_subject_label *root_label;
78132+ struct gr_hash_struct *hash;
78133+
78134+ struct acl_role_label *prev;
78135+ struct acl_role_label *next;
78136+
78137+ struct role_transition *transitions;
78138+ struct role_allowed_ip *allowed_ips;
78139+ uid_t *domain_children;
78140+ __u16 domain_child_num;
78141+
78142+ umode_t umask;
78143+
78144+ struct acl_subject_label **subj_hash;
78145+ __u32 subj_hash_size;
78146+};
78147+
78148+struct user_acl_role_db {
78149+ struct acl_role_label **r_table;
78150+ __u32 num_pointers; /* Number of allocations to track */
78151+ __u32 num_roles; /* Number of roles */
78152+ __u32 num_domain_children; /* Number of domain children */
78153+ __u32 num_subjects; /* Number of subjects */
78154+ __u32 num_objects; /* Number of objects */
78155+};
78156+
78157+struct acl_object_label {
78158+ char *filename;
78159+ ino_t inode;
78160+ dev_t device;
78161+ __u32 mode;
78162+
78163+ struct acl_subject_label *nested;
78164+ struct acl_object_label *globbed;
78165+
78166+ /* next two structures not used */
78167+
78168+ struct acl_object_label *prev;
78169+ struct acl_object_label *next;
78170+};
78171+
78172+struct acl_ip_label {
78173+ char *iface;
78174+ __u32 addr;
78175+ __u32 netmask;
78176+ __u16 low, high;
78177+ __u8 mode;
78178+ __u32 type;
78179+ __u32 proto[8];
78180+
78181+ /* next two structures not used */
78182+
78183+ struct acl_ip_label *prev;
78184+ struct acl_ip_label *next;
78185+};
78186+
78187+struct gr_arg {
78188+ struct user_acl_role_db role_db;
78189+ unsigned char pw[GR_PW_LEN];
78190+ unsigned char salt[GR_SALT_LEN];
78191+ unsigned char sum[GR_SHA_LEN];
78192+ unsigned char sp_role[GR_SPROLE_LEN];
78193+ struct sprole_pw *sprole_pws;
78194+ dev_t segv_device;
78195+ ino_t segv_inode;
78196+ uid_t segv_uid;
78197+ __u16 num_sprole_pws;
78198+ __u16 mode;
78199+};
78200+
78201+struct gr_arg_wrapper {
78202+ struct gr_arg *arg;
78203+ __u32 version;
78204+ __u32 size;
78205+};
78206+
78207+struct subject_map {
78208+ struct acl_subject_label *user;
78209+ struct acl_subject_label *kernel;
78210+ struct subject_map *prev;
78211+ struct subject_map *next;
78212+};
78213+
78214+struct acl_subj_map_db {
78215+ struct subject_map **s_hash;
78216+ __u32 s_size;
78217+};
78218+
78219+struct gr_policy_state {
78220+ struct sprole_pw **acl_special_roles;
78221+ __u16 num_sprole_pws;
78222+ struct acl_role_label *kernel_role;
78223+ struct acl_role_label *role_list;
78224+ struct acl_role_label *default_role;
78225+ struct acl_role_db acl_role_set;
78226+ struct acl_subj_map_db subj_map_set;
78227+ struct name_db name_set;
78228+ struct inodev_db inodev_set;
78229+};
78230+
78231+struct gr_alloc_state {
78232+ unsigned long alloc_stack_next;
78233+ unsigned long alloc_stack_size;
78234+ void **alloc_stack;
78235+};
78236+
78237+struct gr_reload_state {
78238+ struct gr_policy_state oldpolicy;
78239+ struct gr_alloc_state oldalloc;
78240+ struct gr_policy_state newpolicy;
78241+ struct gr_alloc_state newalloc;
78242+ struct gr_policy_state *oldpolicy_ptr;
78243+ struct gr_alloc_state *oldalloc_ptr;
78244+ unsigned char oldmode;
78245+};
78246+
78247+/* End Data Structures Section */
78248+
78249+/* Hash functions generated by empirical testing by Brad Spengler
78250+ Makes good use of the low bits of the inode. Generally 0-1 times
78251+ in loop for successful match. 0-3 for unsuccessful match.
78252+ Shift/add algorithm with modulus of table size and an XOR*/
78253+
78254+static __inline__ unsigned int
78255+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78256+{
78257+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78258+}
78259+
78260+ static __inline__ unsigned int
78261+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78262+{
78263+ return ((const unsigned long)userp % sz);
78264+}
78265+
78266+static __inline__ unsigned int
78267+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78268+{
78269+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78270+}
78271+
78272+static __inline__ unsigned int
78273+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78274+{
78275+ return full_name_hash((const unsigned char *)name, len) % sz;
78276+}
78277+
78278+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78279+ subj = NULL; \
78280+ iter = 0; \
78281+ while (iter < role->subj_hash_size) { \
78282+ if (subj == NULL) \
78283+ subj = role->subj_hash[iter]; \
78284+ if (subj == NULL) { \
78285+ iter++; \
78286+ continue; \
78287+ }
78288+
78289+#define FOR_EACH_SUBJECT_END(subj,iter) \
78290+ subj = subj->next; \
78291+ if (subj == NULL) \
78292+ iter++; \
78293+ }
78294+
78295+
78296+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78297+ subj = role->hash->first; \
78298+ while (subj != NULL) {
78299+
78300+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78301+ subj = subj->next; \
78302+ }
78303+
78304+#endif
78305+
78306diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78307new file mode 100644
78308index 0000000..33ebd1f
78309--- /dev/null
78310+++ b/include/linux/gracl_compat.h
78311@@ -0,0 +1,156 @@
78312+#ifndef GR_ACL_COMPAT_H
78313+#define GR_ACL_COMPAT_H
78314+
78315+#include <linux/resource.h>
78316+#include <asm/resource.h>
78317+
78318+struct sprole_pw_compat {
78319+ compat_uptr_t rolename;
78320+ unsigned char salt[GR_SALT_LEN];
78321+ unsigned char sum[GR_SHA_LEN];
78322+};
78323+
78324+struct gr_hash_struct_compat {
78325+ compat_uptr_t table;
78326+ compat_uptr_t nametable;
78327+ compat_uptr_t first;
78328+ __u32 table_size;
78329+ __u32 used_size;
78330+ int type;
78331+};
78332+
78333+struct acl_subject_label_compat {
78334+ compat_uptr_t filename;
78335+ compat_ino_t inode;
78336+ __u32 device;
78337+ __u32 mode;
78338+ kernel_cap_t cap_mask;
78339+ kernel_cap_t cap_lower;
78340+ kernel_cap_t cap_invert_audit;
78341+
78342+ struct compat_rlimit res[GR_NLIMITS];
78343+ __u32 resmask;
78344+
78345+ __u8 user_trans_type;
78346+ __u8 group_trans_type;
78347+ compat_uptr_t user_transitions;
78348+ compat_uptr_t group_transitions;
78349+ __u16 user_trans_num;
78350+ __u16 group_trans_num;
78351+
78352+ __u32 sock_families[2];
78353+ __u32 ip_proto[8];
78354+ __u32 ip_type;
78355+ compat_uptr_t ips;
78356+ __u32 ip_num;
78357+ __u32 inaddr_any_override;
78358+
78359+ __u32 crashes;
78360+ compat_ulong_t expires;
78361+
78362+ compat_uptr_t parent_subject;
78363+ compat_uptr_t hash;
78364+ compat_uptr_t prev;
78365+ compat_uptr_t next;
78366+
78367+ compat_uptr_t obj_hash;
78368+ __u32 obj_hash_size;
78369+ __u16 pax_flags;
78370+};
78371+
78372+struct role_allowed_ip_compat {
78373+ __u32 addr;
78374+ __u32 netmask;
78375+
78376+ compat_uptr_t prev;
78377+ compat_uptr_t next;
78378+};
78379+
78380+struct role_transition_compat {
78381+ compat_uptr_t rolename;
78382+
78383+ compat_uptr_t prev;
78384+ compat_uptr_t next;
78385+};
78386+
78387+struct acl_role_label_compat {
78388+ compat_uptr_t rolename;
78389+ uid_t uidgid;
78390+ __u16 roletype;
78391+
78392+ __u16 auth_attempts;
78393+ compat_ulong_t expires;
78394+
78395+ compat_uptr_t root_label;
78396+ compat_uptr_t hash;
78397+
78398+ compat_uptr_t prev;
78399+ compat_uptr_t next;
78400+
78401+ compat_uptr_t transitions;
78402+ compat_uptr_t allowed_ips;
78403+ compat_uptr_t domain_children;
78404+ __u16 domain_child_num;
78405+
78406+ umode_t umask;
78407+
78408+ compat_uptr_t subj_hash;
78409+ __u32 subj_hash_size;
78410+};
78411+
78412+struct user_acl_role_db_compat {
78413+ compat_uptr_t r_table;
78414+ __u32 num_pointers;
78415+ __u32 num_roles;
78416+ __u32 num_domain_children;
78417+ __u32 num_subjects;
78418+ __u32 num_objects;
78419+};
78420+
78421+struct acl_object_label_compat {
78422+ compat_uptr_t filename;
78423+ compat_ino_t inode;
78424+ __u32 device;
78425+ __u32 mode;
78426+
78427+ compat_uptr_t nested;
78428+ compat_uptr_t globbed;
78429+
78430+ compat_uptr_t prev;
78431+ compat_uptr_t next;
78432+};
78433+
78434+struct acl_ip_label_compat {
78435+ compat_uptr_t iface;
78436+ __u32 addr;
78437+ __u32 netmask;
78438+ __u16 low, high;
78439+ __u8 mode;
78440+ __u32 type;
78441+ __u32 proto[8];
78442+
78443+ compat_uptr_t prev;
78444+ compat_uptr_t next;
78445+};
78446+
78447+struct gr_arg_compat {
78448+ struct user_acl_role_db_compat role_db;
78449+ unsigned char pw[GR_PW_LEN];
78450+ unsigned char salt[GR_SALT_LEN];
78451+ unsigned char sum[GR_SHA_LEN];
78452+ unsigned char sp_role[GR_SPROLE_LEN];
78453+ compat_uptr_t sprole_pws;
78454+ __u32 segv_device;
78455+ compat_ino_t segv_inode;
78456+ uid_t segv_uid;
78457+ __u16 num_sprole_pws;
78458+ __u16 mode;
78459+};
78460+
78461+struct gr_arg_wrapper_compat {
78462+ compat_uptr_t arg;
78463+ __u32 version;
78464+ __u32 size;
78465+};
78466+
78467+#endif
78468diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78469new file mode 100644
78470index 0000000..323ecf2
78471--- /dev/null
78472+++ b/include/linux/gralloc.h
78473@@ -0,0 +1,9 @@
78474+#ifndef __GRALLOC_H
78475+#define __GRALLOC_H
78476+
78477+void acl_free_all(void);
78478+int acl_alloc_stack_init(unsigned long size);
78479+void *acl_alloc(unsigned long len);
78480+void *acl_alloc_num(unsigned long num, unsigned long len);
78481+
78482+#endif
78483diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78484new file mode 100644
78485index 0000000..be66033
78486--- /dev/null
78487+++ b/include/linux/grdefs.h
78488@@ -0,0 +1,140 @@
78489+#ifndef GRDEFS_H
78490+#define GRDEFS_H
78491+
78492+/* Begin grsecurity status declarations */
78493+
78494+enum {
78495+ GR_READY = 0x01,
78496+ GR_STATUS_INIT = 0x00 // disabled state
78497+};
78498+
78499+/* Begin ACL declarations */
78500+
78501+/* Role flags */
78502+
78503+enum {
78504+ GR_ROLE_USER = 0x0001,
78505+ GR_ROLE_GROUP = 0x0002,
78506+ GR_ROLE_DEFAULT = 0x0004,
78507+ GR_ROLE_SPECIAL = 0x0008,
78508+ GR_ROLE_AUTH = 0x0010,
78509+ GR_ROLE_NOPW = 0x0020,
78510+ GR_ROLE_GOD = 0x0040,
78511+ GR_ROLE_LEARN = 0x0080,
78512+ GR_ROLE_TPE = 0x0100,
78513+ GR_ROLE_DOMAIN = 0x0200,
78514+ GR_ROLE_PAM = 0x0400,
78515+ GR_ROLE_PERSIST = 0x0800
78516+};
78517+
78518+/* ACL Subject and Object mode flags */
78519+enum {
78520+ GR_DELETED = 0x80000000
78521+};
78522+
78523+/* ACL Object-only mode flags */
78524+enum {
78525+ GR_READ = 0x00000001,
78526+ GR_APPEND = 0x00000002,
78527+ GR_WRITE = 0x00000004,
78528+ GR_EXEC = 0x00000008,
78529+ GR_FIND = 0x00000010,
78530+ GR_INHERIT = 0x00000020,
78531+ GR_SETID = 0x00000040,
78532+ GR_CREATE = 0x00000080,
78533+ GR_DELETE = 0x00000100,
78534+ GR_LINK = 0x00000200,
78535+ GR_AUDIT_READ = 0x00000400,
78536+ GR_AUDIT_APPEND = 0x00000800,
78537+ GR_AUDIT_WRITE = 0x00001000,
78538+ GR_AUDIT_EXEC = 0x00002000,
78539+ GR_AUDIT_FIND = 0x00004000,
78540+ GR_AUDIT_INHERIT= 0x00008000,
78541+ GR_AUDIT_SETID = 0x00010000,
78542+ GR_AUDIT_CREATE = 0x00020000,
78543+ GR_AUDIT_DELETE = 0x00040000,
78544+ GR_AUDIT_LINK = 0x00080000,
78545+ GR_PTRACERD = 0x00100000,
78546+ GR_NOPTRACE = 0x00200000,
78547+ GR_SUPPRESS = 0x00400000,
78548+ GR_NOLEARN = 0x00800000,
78549+ GR_INIT_TRANSFER= 0x01000000
78550+};
78551+
78552+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78553+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78554+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78555+
78556+/* ACL subject-only mode flags */
78557+enum {
78558+ GR_KILL = 0x00000001,
78559+ GR_VIEW = 0x00000002,
78560+ GR_PROTECTED = 0x00000004,
78561+ GR_LEARN = 0x00000008,
78562+ GR_OVERRIDE = 0x00000010,
78563+ /* just a placeholder, this mode is only used in userspace */
78564+ GR_DUMMY = 0x00000020,
78565+ GR_PROTSHM = 0x00000040,
78566+ GR_KILLPROC = 0x00000080,
78567+ GR_KILLIPPROC = 0x00000100,
78568+ /* just a placeholder, this mode is only used in userspace */
78569+ GR_NOTROJAN = 0x00000200,
78570+ GR_PROTPROCFD = 0x00000400,
78571+ GR_PROCACCT = 0x00000800,
78572+ GR_RELAXPTRACE = 0x00001000,
78573+ //GR_NESTED = 0x00002000,
78574+ GR_INHERITLEARN = 0x00004000,
78575+ GR_PROCFIND = 0x00008000,
78576+ GR_POVERRIDE = 0x00010000,
78577+ GR_KERNELAUTH = 0x00020000,
78578+ GR_ATSECURE = 0x00040000,
78579+ GR_SHMEXEC = 0x00080000
78580+};
78581+
78582+enum {
78583+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78584+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78585+ GR_PAX_ENABLE_MPROTECT = 0x0004,
78586+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
78587+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78588+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78589+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78590+ GR_PAX_DISABLE_MPROTECT = 0x0400,
78591+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
78592+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78593+};
78594+
78595+enum {
78596+ GR_ID_USER = 0x01,
78597+ GR_ID_GROUP = 0x02,
78598+};
78599+
78600+enum {
78601+ GR_ID_ALLOW = 0x01,
78602+ GR_ID_DENY = 0x02,
78603+};
78604+
78605+#define GR_CRASH_RES 31
78606+#define GR_UIDTABLE_MAX 500
78607+
78608+/* begin resource learning section */
78609+enum {
78610+ GR_RLIM_CPU_BUMP = 60,
78611+ GR_RLIM_FSIZE_BUMP = 50000,
78612+ GR_RLIM_DATA_BUMP = 10000,
78613+ GR_RLIM_STACK_BUMP = 1000,
78614+ GR_RLIM_CORE_BUMP = 10000,
78615+ GR_RLIM_RSS_BUMP = 500000,
78616+ GR_RLIM_NPROC_BUMP = 1,
78617+ GR_RLIM_NOFILE_BUMP = 5,
78618+ GR_RLIM_MEMLOCK_BUMP = 50000,
78619+ GR_RLIM_AS_BUMP = 500000,
78620+ GR_RLIM_LOCKS_BUMP = 2,
78621+ GR_RLIM_SIGPENDING_BUMP = 5,
78622+ GR_RLIM_MSGQUEUE_BUMP = 10000,
78623+ GR_RLIM_NICE_BUMP = 1,
78624+ GR_RLIM_RTPRIO_BUMP = 1,
78625+ GR_RLIM_RTTIME_BUMP = 1000000
78626+};
78627+
78628+#endif
78629diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78630new file mode 100644
78631index 0000000..d25522e
78632--- /dev/null
78633+++ b/include/linux/grinternal.h
78634@@ -0,0 +1,229 @@
78635+#ifndef __GRINTERNAL_H
78636+#define __GRINTERNAL_H
78637+
78638+#ifdef CONFIG_GRKERNSEC
78639+
78640+#include <linux/fs.h>
78641+#include <linux/mnt_namespace.h>
78642+#include <linux/nsproxy.h>
78643+#include <linux/gracl.h>
78644+#include <linux/grdefs.h>
78645+#include <linux/grmsg.h>
78646+
78647+void gr_add_learn_entry(const char *fmt, ...)
78648+ __attribute__ ((format (printf, 1, 2)));
78649+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78650+ const struct vfsmount *mnt);
78651+__u32 gr_check_create(const struct dentry *new_dentry,
78652+ const struct dentry *parent,
78653+ const struct vfsmount *mnt, const __u32 mode);
78654+int gr_check_protected_task(const struct task_struct *task);
78655+__u32 to_gr_audit(const __u32 reqmode);
78656+int gr_set_acls(const int type);
78657+int gr_acl_is_enabled(void);
78658+char gr_roletype_to_char(void);
78659+
78660+void gr_handle_alertkill(struct task_struct *task);
78661+char *gr_to_filename(const struct dentry *dentry,
78662+ const struct vfsmount *mnt);
78663+char *gr_to_filename1(const struct dentry *dentry,
78664+ const struct vfsmount *mnt);
78665+char *gr_to_filename2(const struct dentry *dentry,
78666+ const struct vfsmount *mnt);
78667+char *gr_to_filename3(const struct dentry *dentry,
78668+ const struct vfsmount *mnt);
78669+
78670+extern int grsec_enable_ptrace_readexec;
78671+extern int grsec_enable_harden_ptrace;
78672+extern int grsec_enable_link;
78673+extern int grsec_enable_fifo;
78674+extern int grsec_enable_execve;
78675+extern int grsec_enable_shm;
78676+extern int grsec_enable_execlog;
78677+extern int grsec_enable_signal;
78678+extern int grsec_enable_audit_ptrace;
78679+extern int grsec_enable_forkfail;
78680+extern int grsec_enable_time;
78681+extern int grsec_enable_rofs;
78682+extern int grsec_deny_new_usb;
78683+extern int grsec_enable_chroot_shmat;
78684+extern int grsec_enable_chroot_mount;
78685+extern int grsec_enable_chroot_double;
78686+extern int grsec_enable_chroot_pivot;
78687+extern int grsec_enable_chroot_chdir;
78688+extern int grsec_enable_chroot_chmod;
78689+extern int grsec_enable_chroot_mknod;
78690+extern int grsec_enable_chroot_fchdir;
78691+extern int grsec_enable_chroot_nice;
78692+extern int grsec_enable_chroot_execlog;
78693+extern int grsec_enable_chroot_caps;
78694+extern int grsec_enable_chroot_sysctl;
78695+extern int grsec_enable_chroot_unix;
78696+extern int grsec_enable_symlinkown;
78697+extern kgid_t grsec_symlinkown_gid;
78698+extern int grsec_enable_tpe;
78699+extern kgid_t grsec_tpe_gid;
78700+extern int grsec_enable_tpe_all;
78701+extern int grsec_enable_tpe_invert;
78702+extern int grsec_enable_socket_all;
78703+extern kgid_t grsec_socket_all_gid;
78704+extern int grsec_enable_socket_client;
78705+extern kgid_t grsec_socket_client_gid;
78706+extern int grsec_enable_socket_server;
78707+extern kgid_t grsec_socket_server_gid;
78708+extern kgid_t grsec_audit_gid;
78709+extern int grsec_enable_group;
78710+extern int grsec_enable_log_rwxmaps;
78711+extern int grsec_enable_mount;
78712+extern int grsec_enable_chdir;
78713+extern int grsec_resource_logging;
78714+extern int grsec_enable_blackhole;
78715+extern int grsec_lastack_retries;
78716+extern int grsec_enable_brute;
78717+extern int grsec_enable_harden_ipc;
78718+extern int grsec_lock;
78719+
78720+extern spinlock_t grsec_alert_lock;
78721+extern unsigned long grsec_alert_wtime;
78722+extern unsigned long grsec_alert_fyet;
78723+
78724+extern spinlock_t grsec_audit_lock;
78725+
78726+extern rwlock_t grsec_exec_file_lock;
78727+
78728+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78729+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78730+ (tsk)->exec_file->f_path.mnt) : "/")
78731+
78732+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78733+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78734+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78735+
78736+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78737+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
78738+ (tsk)->exec_file->f_path.mnt) : "/")
78739+
78740+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78741+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78742+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78743+
78744+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78745+
78746+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78747+
78748+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78749+{
78750+ if (file1 && file2) {
78751+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
78752+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
78753+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78754+ return true;
78755+ }
78756+
78757+ return false;
78758+}
78759+
78760+#define GR_CHROOT_CAPS {{ \
78761+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78762+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78763+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78764+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78765+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78766+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78767+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78768+
78769+#define security_learn(normal_msg,args...) \
78770+({ \
78771+ read_lock(&grsec_exec_file_lock); \
78772+ gr_add_learn_entry(normal_msg "\n", ## args); \
78773+ read_unlock(&grsec_exec_file_lock); \
78774+})
78775+
78776+enum {
78777+ GR_DO_AUDIT,
78778+ GR_DONT_AUDIT,
78779+ /* used for non-audit messages that we shouldn't kill the task on */
78780+ GR_DONT_AUDIT_GOOD
78781+};
78782+
78783+enum {
78784+ GR_TTYSNIFF,
78785+ GR_RBAC,
78786+ GR_RBAC_STR,
78787+ GR_STR_RBAC,
78788+ GR_RBAC_MODE2,
78789+ GR_RBAC_MODE3,
78790+ GR_FILENAME,
78791+ GR_SYSCTL_HIDDEN,
78792+ GR_NOARGS,
78793+ GR_ONE_INT,
78794+ GR_ONE_INT_TWO_STR,
78795+ GR_ONE_STR,
78796+ GR_STR_INT,
78797+ GR_TWO_STR_INT,
78798+ GR_TWO_INT,
78799+ GR_TWO_U64,
78800+ GR_THREE_INT,
78801+ GR_FIVE_INT_TWO_STR,
78802+ GR_TWO_STR,
78803+ GR_THREE_STR,
78804+ GR_FOUR_STR,
78805+ GR_STR_FILENAME,
78806+ GR_FILENAME_STR,
78807+ GR_FILENAME_TWO_INT,
78808+ GR_FILENAME_TWO_INT_STR,
78809+ GR_TEXTREL,
78810+ GR_PTRACE,
78811+ GR_RESOURCE,
78812+ GR_CAP,
78813+ GR_SIG,
78814+ GR_SIG2,
78815+ GR_CRASH1,
78816+ GR_CRASH2,
78817+ GR_PSACCT,
78818+ GR_RWXMAP,
78819+ GR_RWXMAPVMA
78820+};
78821+
78822+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78823+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78824+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78825+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78826+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78827+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78828+#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)
78829+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78830+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78831+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78832+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78833+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78834+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78835+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78836+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78837+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78838+#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)
78839+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78840+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78841+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78842+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78843+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78844+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78845+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78846+#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)
78847+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78848+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78849+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78850+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78851+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78852+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78853+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78854+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78855+#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)
78856+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78857+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78858+
78859+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78860+
78861+#endif
78862+
78863+#endif
78864diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78865new file mode 100644
78866index 0000000..ba93581
78867--- /dev/null
78868+++ b/include/linux/grmsg.h
78869@@ -0,0 +1,116 @@
78870+#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"
78871+#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"
78872+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78873+#define GR_STOPMOD_MSG "denied modification of module state by "
78874+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78875+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78876+#define GR_IOPERM_MSG "denied use of ioperm() by "
78877+#define GR_IOPL_MSG "denied use of iopl() by "
78878+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78879+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78880+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78881+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78882+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78883+#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"
78884+#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"
78885+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78886+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78887+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78888+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78889+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78890+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78891+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78892+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78893+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78894+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78895+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78896+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78897+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78898+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78899+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78900+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78901+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78902+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78903+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78904+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78905+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78906+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78907+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78908+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78909+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78910+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78911+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78912+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78913+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78914+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78915+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78916+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78917+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78918+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78919+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78920+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78921+#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"
78922+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78923+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78924+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78925+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78926+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78927+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78928+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78929+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78930+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78931+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78932+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78933+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78934+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78935+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78936+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78937+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78938+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78939+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78940+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78941+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78942+#define GR_FAILFORK_MSG "failed fork with errno %s by "
78943+#define GR_NICE_CHROOT_MSG "denied priority change by "
78944+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78945+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78946+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78947+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78948+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78949+#define GR_TIME_MSG "time set by "
78950+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78951+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78952+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78953+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78954+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78955+#define GR_BIND_MSG "denied bind() by "
78956+#define GR_CONNECT_MSG "denied connect() by "
78957+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78958+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78959+#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"
78960+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78961+#define GR_CAP_ACL_MSG "use of %s denied for "
78962+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78963+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78964+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78965+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78966+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78967+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78968+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78969+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78970+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78971+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78972+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78973+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78974+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78975+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78976+#define GR_VM86_MSG "denied use of vm86 by "
78977+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78978+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78979+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78980+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78981+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78982+#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 "
78983+#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 "
78984+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78985+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78986diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78987new file mode 100644
78988index 0000000..8108301
78989--- /dev/null
78990+++ b/include/linux/grsecurity.h
78991@@ -0,0 +1,246 @@
78992+#ifndef GR_SECURITY_H
78993+#define GR_SECURITY_H
78994+#include <linux/fs.h>
78995+#include <linux/fs_struct.h>
78996+#include <linux/binfmts.h>
78997+#include <linux/gracl.h>
78998+
78999+/* notify of brain-dead configs */
79000+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79001+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79002+#endif
79003+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79004+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79005+#endif
79006+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79007+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79008+#endif
79009+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79010+#error "CONFIG_PAX enabled, but no PaX options are enabled."
79011+#endif
79012+
79013+int gr_handle_new_usb(void);
79014+
79015+void gr_handle_brute_attach(int dumpable);
79016+void gr_handle_brute_check(void);
79017+void gr_handle_kernel_exploit(void);
79018+
79019+char gr_roletype_to_char(void);
79020+
79021+int gr_acl_enable_at_secure(void);
79022+
79023+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79024+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79025+
79026+void gr_del_task_from_ip_table(struct task_struct *p);
79027+
79028+int gr_pid_is_chrooted(struct task_struct *p);
79029+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79030+int gr_handle_chroot_nice(void);
79031+int gr_handle_chroot_sysctl(const int op);
79032+int gr_handle_chroot_setpriority(struct task_struct *p,
79033+ const int niceval);
79034+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79035+int gr_handle_chroot_chroot(const struct dentry *dentry,
79036+ const struct vfsmount *mnt);
79037+void gr_handle_chroot_chdir(const struct path *path);
79038+int gr_handle_chroot_chmod(const struct dentry *dentry,
79039+ const struct vfsmount *mnt, const int mode);
79040+int gr_handle_chroot_mknod(const struct dentry *dentry,
79041+ const struct vfsmount *mnt, const int mode);
79042+int gr_handle_chroot_mount(const struct dentry *dentry,
79043+ const struct vfsmount *mnt,
79044+ const char *dev_name);
79045+int gr_handle_chroot_pivot(void);
79046+int gr_handle_chroot_unix(const pid_t pid);
79047+
79048+int gr_handle_rawio(const struct inode *inode);
79049+
79050+void gr_handle_ioperm(void);
79051+void gr_handle_iopl(void);
79052+void gr_handle_msr_write(void);
79053+
79054+umode_t gr_acl_umask(void);
79055+
79056+int gr_tpe_allow(const struct file *file);
79057+
79058+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79059+void gr_clear_chroot_entries(struct task_struct *task);
79060+
79061+void gr_log_forkfail(const int retval);
79062+void gr_log_timechange(void);
79063+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79064+void gr_log_chdir(const struct dentry *dentry,
79065+ const struct vfsmount *mnt);
79066+void gr_log_chroot_exec(const struct dentry *dentry,
79067+ const struct vfsmount *mnt);
79068+void gr_log_remount(const char *devname, const int retval);
79069+void gr_log_unmount(const char *devname, const int retval);
79070+void gr_log_mount(const char *from, const char *to, const int retval);
79071+void gr_log_textrel(struct vm_area_struct *vma);
79072+void gr_log_ptgnustack(struct file *file);
79073+void gr_log_rwxmmap(struct file *file);
79074+void gr_log_rwxmprotect(struct vm_area_struct *vma);
79075+
79076+int gr_handle_follow_link(const struct inode *parent,
79077+ const struct inode *inode,
79078+ const struct dentry *dentry,
79079+ const struct vfsmount *mnt);
79080+int gr_handle_fifo(const struct dentry *dentry,
79081+ const struct vfsmount *mnt,
79082+ const struct dentry *dir, const int flag,
79083+ const int acc_mode);
79084+int gr_handle_hardlink(const struct dentry *dentry,
79085+ const struct vfsmount *mnt,
79086+ struct inode *inode,
79087+ const int mode, const struct filename *to);
79088+
79089+int gr_is_capable(const int cap);
79090+int gr_is_capable_nolog(const int cap);
79091+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79092+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79093+
79094+void gr_copy_label(struct task_struct *tsk);
79095+void gr_handle_crash(struct task_struct *task, const int sig);
79096+int gr_handle_signal(const struct task_struct *p, const int sig);
79097+int gr_check_crash_uid(const kuid_t uid);
79098+int gr_check_protected_task(const struct task_struct *task);
79099+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79100+int gr_acl_handle_mmap(const struct file *file,
79101+ const unsigned long prot);
79102+int gr_acl_handle_mprotect(const struct file *file,
79103+ const unsigned long prot);
79104+int gr_check_hidden_task(const struct task_struct *tsk);
79105+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79106+ const struct vfsmount *mnt);
79107+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79108+ const struct vfsmount *mnt);
79109+__u32 gr_acl_handle_access(const struct dentry *dentry,
79110+ const struct vfsmount *mnt, const int fmode);
79111+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79112+ const struct vfsmount *mnt, umode_t *mode);
79113+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79114+ const struct vfsmount *mnt);
79115+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79116+ const struct vfsmount *mnt);
79117+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79118+ const struct vfsmount *mnt);
79119+int gr_handle_ptrace(struct task_struct *task, const long request);
79120+int gr_handle_proc_ptrace(struct task_struct *task);
79121+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79122+ const struct vfsmount *mnt);
79123+int gr_check_crash_exec(const struct file *filp);
79124+int gr_acl_is_enabled(void);
79125+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79126+ const kgid_t gid);
79127+int gr_set_proc_label(const struct dentry *dentry,
79128+ const struct vfsmount *mnt,
79129+ const int unsafe_flags);
79130+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79131+ const struct vfsmount *mnt);
79132+__u32 gr_acl_handle_open(const struct dentry *dentry,
79133+ const struct vfsmount *mnt, int acc_mode);
79134+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79135+ const struct dentry *p_dentry,
79136+ const struct vfsmount *p_mnt,
79137+ int open_flags, int acc_mode, const int imode);
79138+void gr_handle_create(const struct dentry *dentry,
79139+ const struct vfsmount *mnt);
79140+void gr_handle_proc_create(const struct dentry *dentry,
79141+ const struct inode *inode);
79142+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79143+ const struct dentry *parent_dentry,
79144+ const struct vfsmount *parent_mnt,
79145+ const int mode);
79146+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79147+ const struct dentry *parent_dentry,
79148+ const struct vfsmount *parent_mnt);
79149+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79150+ const struct vfsmount *mnt);
79151+void gr_handle_delete(const ino_t ino, const dev_t dev);
79152+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79153+ const struct vfsmount *mnt);
79154+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79155+ const struct dentry *parent_dentry,
79156+ const struct vfsmount *parent_mnt,
79157+ const struct filename *from);
79158+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79159+ const struct dentry *parent_dentry,
79160+ const struct vfsmount *parent_mnt,
79161+ const struct dentry *old_dentry,
79162+ const struct vfsmount *old_mnt, const struct filename *to);
79163+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79164+int gr_acl_handle_rename(struct dentry *new_dentry,
79165+ struct dentry *parent_dentry,
79166+ const struct vfsmount *parent_mnt,
79167+ struct dentry *old_dentry,
79168+ struct inode *old_parent_inode,
79169+ struct vfsmount *old_mnt, const struct filename *newname);
79170+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79171+ struct dentry *old_dentry,
79172+ struct dentry *new_dentry,
79173+ struct vfsmount *mnt, const __u8 replace);
79174+__u32 gr_check_link(const struct dentry *new_dentry,
79175+ const struct dentry *parent_dentry,
79176+ const struct vfsmount *parent_mnt,
79177+ const struct dentry *old_dentry,
79178+ const struct vfsmount *old_mnt);
79179+int gr_acl_handle_filldir(const struct file *file, const char *name,
79180+ const unsigned int namelen, const ino_t ino);
79181+
79182+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79183+ const struct vfsmount *mnt);
79184+void gr_acl_handle_exit(void);
79185+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79186+int gr_acl_handle_procpidmem(const struct task_struct *task);
79187+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79188+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79189+void gr_audit_ptrace(struct task_struct *task);
79190+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79191+void gr_put_exec_file(struct task_struct *task);
79192+
79193+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79194+
79195+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79196+extern void gr_learn_resource(const struct task_struct *task, const int res,
79197+ const unsigned long wanted, const int gt);
79198+#else
79199+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79200+ const unsigned long wanted, const int gt)
79201+{
79202+}
79203+#endif
79204+
79205+#ifdef CONFIG_GRKERNSEC_RESLOG
79206+extern void gr_log_resource(const struct task_struct *task, const int res,
79207+ const unsigned long wanted, const int gt);
79208+#else
79209+static inline void gr_log_resource(const struct task_struct *task, const int res,
79210+ const unsigned long wanted, const int gt)
79211+{
79212+}
79213+#endif
79214+
79215+#ifdef CONFIG_GRKERNSEC
79216+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79217+void gr_handle_vm86(void);
79218+void gr_handle_mem_readwrite(u64 from, u64 to);
79219+
79220+void gr_log_badprocpid(const char *entry);
79221+
79222+extern int grsec_enable_dmesg;
79223+extern int grsec_disable_privio;
79224+
79225+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79226+extern kgid_t grsec_proc_gid;
79227+#endif
79228+
79229+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79230+extern int grsec_enable_chroot_findtask;
79231+#endif
79232+#ifdef CONFIG_GRKERNSEC_SETXID
79233+extern int grsec_enable_setxid;
79234+#endif
79235+#endif
79236+
79237+#endif
79238diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79239new file mode 100644
79240index 0000000..e7ffaaf
79241--- /dev/null
79242+++ b/include/linux/grsock.h
79243@@ -0,0 +1,19 @@
79244+#ifndef __GRSOCK_H
79245+#define __GRSOCK_H
79246+
79247+extern void gr_attach_curr_ip(const struct sock *sk);
79248+extern int gr_handle_sock_all(const int family, const int type,
79249+ const int protocol);
79250+extern int gr_handle_sock_server(const struct sockaddr *sck);
79251+extern int gr_handle_sock_server_other(const struct sock *sck);
79252+extern int gr_handle_sock_client(const struct sockaddr *sck);
79253+extern int gr_search_connect(struct socket * sock,
79254+ struct sockaddr_in * addr);
79255+extern int gr_search_bind(struct socket * sock,
79256+ struct sockaddr_in * addr);
79257+extern int gr_search_listen(struct socket * sock);
79258+extern int gr_search_accept(struct socket * sock);
79259+extern int gr_search_socket(const int domain, const int type,
79260+ const int protocol);
79261+
79262+#endif
79263diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79264index 7fb31da..08b5114 100644
79265--- a/include/linux/highmem.h
79266+++ b/include/linux/highmem.h
79267@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79268 kunmap_atomic(kaddr);
79269 }
79270
79271+static inline void sanitize_highpage(struct page *page)
79272+{
79273+ void *kaddr;
79274+ unsigned long flags;
79275+
79276+ local_irq_save(flags);
79277+ kaddr = kmap_atomic(page);
79278+ clear_page(kaddr);
79279+ kunmap_atomic(kaddr);
79280+ local_irq_restore(flags);
79281+}
79282+
79283 static inline void zero_user_segments(struct page *page,
79284 unsigned start1, unsigned end1,
79285 unsigned start2, unsigned end2)
79286diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79287index 1c7b89a..7dda400 100644
79288--- a/include/linux/hwmon-sysfs.h
79289+++ b/include/linux/hwmon-sysfs.h
79290@@ -25,7 +25,8 @@
79291 struct sensor_device_attribute{
79292 struct device_attribute dev_attr;
79293 int index;
79294-};
79295+} __do_const;
79296+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79297 #define to_sensor_dev_attr(_dev_attr) \
79298 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79299
79300@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79301 struct device_attribute dev_attr;
79302 u8 index;
79303 u8 nr;
79304-};
79305+} __do_const;
79306+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79307 #define to_sensor_dev_attr_2(_dev_attr) \
79308 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79309
79310diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79311index d9c8dbd3..def6e5a 100644
79312--- a/include/linux/i2c.h
79313+++ b/include/linux/i2c.h
79314@@ -364,6 +364,7 @@ struct i2c_algorithm {
79315 /* To determine what the adapter supports */
79316 u32 (*functionality) (struct i2c_adapter *);
79317 };
79318+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79319
79320 /**
79321 * struct i2c_bus_recovery_info - I2C bus recovery information
79322diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79323index d23c3c2..eb63c81 100644
79324--- a/include/linux/i2o.h
79325+++ b/include/linux/i2o.h
79326@@ -565,7 +565,7 @@ struct i2o_controller {
79327 struct i2o_device *exec; /* Executive */
79328 #if BITS_PER_LONG == 64
79329 spinlock_t context_list_lock; /* lock for context_list */
79330- atomic_t context_list_counter; /* needed for unique contexts */
79331+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79332 struct list_head context_list; /* list of context id's
79333 and pointers */
79334 #endif
79335diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79336index aff7ad8..3942bbd 100644
79337--- a/include/linux/if_pppox.h
79338+++ b/include/linux/if_pppox.h
79339@@ -76,7 +76,7 @@ struct pppox_proto {
79340 int (*ioctl)(struct socket *sock, unsigned int cmd,
79341 unsigned long arg);
79342 struct module *owner;
79343-};
79344+} __do_const;
79345
79346 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79347 extern void unregister_pppox_proto(int proto_num);
79348diff --git a/include/linux/init.h b/include/linux/init.h
79349index 8e68a64..3f977a0 100644
79350--- a/include/linux/init.h
79351+++ b/include/linux/init.h
79352@@ -37,9 +37,17 @@
79353 * section.
79354 */
79355
79356+#define add_init_latent_entropy __latent_entropy
79357+
79358+#ifdef CONFIG_MEMORY_HOTPLUG
79359+#define add_meminit_latent_entropy
79360+#else
79361+#define add_meminit_latent_entropy __latent_entropy
79362+#endif
79363+
79364 /* These are for everybody (although not all archs will actually
79365 discard it in modules) */
79366-#define __init __section(.init.text) __cold notrace
79367+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79368 #define __initdata __section(.init.data)
79369 #define __initconst __constsection(.init.rodata)
79370 #define __exitdata __section(.exit.data)
79371@@ -100,7 +108,7 @@
79372 #define __cpuexitconst
79373
79374 /* Used for MEMORY_HOTPLUG */
79375-#define __meminit __section(.meminit.text) __cold notrace
79376+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79377 #define __meminitdata __section(.meminit.data)
79378 #define __meminitconst __constsection(.meminit.rodata)
79379 #define __memexit __section(.memexit.text) __exitused __cold notrace
79380diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79381index b0ed422..d79ea23 100644
79382--- a/include/linux/init_task.h
79383+++ b/include/linux/init_task.h
79384@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79385
79386 #define INIT_TASK_COMM "swapper"
79387
79388+#ifdef CONFIG_X86
79389+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79390+#else
79391+#define INIT_TASK_THREAD_INFO
79392+#endif
79393+
79394 /*
79395 * INIT_TASK is used to set up the first task table, touch at
79396 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79397@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79398 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79399 .comm = INIT_TASK_COMM, \
79400 .thread = INIT_THREAD, \
79401+ INIT_TASK_THREAD_INFO \
79402 .fs = &init_fs, \
79403 .files = &init_files, \
79404 .signal = &init_signals, \
79405diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79406index db43b58..5d5084b 100644
79407--- a/include/linux/interrupt.h
79408+++ b/include/linux/interrupt.h
79409@@ -360,7 +360,7 @@ enum
79410 /* map softirq index to softirq name. update 'softirq_to_name' in
79411 * kernel/softirq.c when adding a new softirq.
79412 */
79413-extern char *softirq_to_name[NR_SOFTIRQS];
79414+extern const char * const softirq_to_name[NR_SOFTIRQS];
79415
79416 /* softirq mask and active fields moved to irq_cpustat_t in
79417 * asm/hardirq.h to get better cache usage. KAO
79418@@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79419
79420 struct softirq_action
79421 {
79422- void (*action)(struct softirq_action *);
79423-};
79424+ void (*action)(void);
79425+} __no_const;
79426
79427 asmlinkage void do_softirq(void);
79428 asmlinkage void __do_softirq(void);
79429@@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79430 }
79431 #endif
79432
79433-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79434+extern void open_softirq(int nr, void (*action)(void));
79435 extern void softirq_init(void);
79436 extern void __raise_softirq_irqoff(unsigned int nr);
79437
79438diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79439index a444c79..8c41ea9 100644
79440--- a/include/linux/iommu.h
79441+++ b/include/linux/iommu.h
79442@@ -130,7 +130,7 @@ struct iommu_ops {
79443 u32 (*domain_get_windows)(struct iommu_domain *domain);
79444
79445 unsigned long pgsize_bitmap;
79446-};
79447+} __do_const;
79448
79449 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79450 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79451diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79452index 89b7c24..382af74 100644
79453--- a/include/linux/ioport.h
79454+++ b/include/linux/ioport.h
79455@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79456 int adjust_resource(struct resource *res, resource_size_t start,
79457 resource_size_t size);
79458 resource_size_t resource_alignment(struct resource *res);
79459-static inline resource_size_t resource_size(const struct resource *res)
79460+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79461 {
79462 return res->end - res->start + 1;
79463 }
79464diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79465index d6ad91f..f10f279 100644
79466--- a/include/linux/ipc_namespace.h
79467+++ b/include/linux/ipc_namespace.h
79468@@ -70,7 +70,7 @@ struct ipc_namespace {
79469 struct user_namespace *user_ns;
79470
79471 unsigned int proc_inum;
79472-};
79473+} __randomize_layout;
79474
79475 extern struct ipc_namespace init_ipc_ns;
79476 extern atomic_t nr_ipc_ns;
79477diff --git a/include/linux/irq.h b/include/linux/irq.h
79478index 7dc1003..407327b 100644
79479--- a/include/linux/irq.h
79480+++ b/include/linux/irq.h
79481@@ -338,7 +338,8 @@ struct irq_chip {
79482 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79483
79484 unsigned long flags;
79485-};
79486+} __do_const;
79487+typedef struct irq_chip __no_const irq_chip_no_const;
79488
79489 /*
79490 * irq_chip specific flags
79491diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79492index cac496b..ffa0567 100644
79493--- a/include/linux/irqchip/arm-gic.h
79494+++ b/include/linux/irqchip/arm-gic.h
79495@@ -61,9 +61,11 @@
79496
79497 #ifndef __ASSEMBLY__
79498
79499+#include <linux/irq.h>
79500+
79501 struct device_node;
79502
79503-extern struct irq_chip gic_arch_extn;
79504+extern irq_chip_no_const gic_arch_extn;
79505
79506 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79507 u32 offset, struct device_node *);
79508diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79509index d235e88..8ccbe74 100644
79510--- a/include/linux/jiffies.h
79511+++ b/include/linux/jiffies.h
79512@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79513 /*
79514 * Convert various time units to each other:
79515 */
79516-extern unsigned int jiffies_to_msecs(const unsigned long j);
79517-extern unsigned int jiffies_to_usecs(const unsigned long j);
79518-extern unsigned long msecs_to_jiffies(const unsigned int m);
79519-extern unsigned long usecs_to_jiffies(const unsigned int u);
79520-extern unsigned long timespec_to_jiffies(const struct timespec *value);
79521+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79522+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79523+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79524+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79525+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79526 extern void jiffies_to_timespec(const unsigned long jiffies,
79527 struct timespec *value);
79528-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79529+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79530 extern void jiffies_to_timeval(const unsigned long jiffies,
79531 struct timeval *value);
79532
79533diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79534index 6883e19..e854fcb 100644
79535--- a/include/linux/kallsyms.h
79536+++ b/include/linux/kallsyms.h
79537@@ -15,7 +15,8 @@
79538
79539 struct module;
79540
79541-#ifdef CONFIG_KALLSYMS
79542+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79543+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79544 /* Lookup the address for a symbol. Returns 0 if not found. */
79545 unsigned long kallsyms_lookup_name(const char *name);
79546
79547@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79548 /* Stupid that this does nothing, but I didn't create this mess. */
79549 #define __print_symbol(fmt, addr)
79550 #endif /*CONFIG_KALLSYMS*/
79551+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79552+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79553+extern unsigned long kallsyms_lookup_name(const char *name);
79554+extern void __print_symbol(const char *fmt, unsigned long address);
79555+extern int sprint_backtrace(char *buffer, unsigned long address);
79556+extern int sprint_symbol(char *buffer, unsigned long address);
79557+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79558+const char *kallsyms_lookup(unsigned long addr,
79559+ unsigned long *symbolsize,
79560+ unsigned long *offset,
79561+ char **modname, char *namebuf);
79562+extern int kallsyms_lookup_size_offset(unsigned long addr,
79563+ unsigned long *symbolsize,
79564+ unsigned long *offset);
79565+#endif
79566
79567 /* This macro allows us to keep printk typechecking */
79568 static __printf(1, 2)
79569diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79570index a74c3a8..28d3f21 100644
79571--- a/include/linux/key-type.h
79572+++ b/include/linux/key-type.h
79573@@ -131,7 +131,7 @@ struct key_type {
79574 /* internal fields */
79575 struct list_head link; /* link in types list */
79576 struct lock_class_key lock_class; /* key->sem lock class */
79577-};
79578+} __do_const;
79579
79580 extern struct key_type key_type_keyring;
79581
79582diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79583index dfb4f2f..7927e62 100644
79584--- a/include/linux/kgdb.h
79585+++ b/include/linux/kgdb.h
79586@@ -52,7 +52,7 @@ extern int kgdb_connected;
79587 extern int kgdb_io_module_registered;
79588
79589 extern atomic_t kgdb_setting_breakpoint;
79590-extern atomic_t kgdb_cpu_doing_single_step;
79591+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79592
79593 extern struct task_struct *kgdb_usethread;
79594 extern struct task_struct *kgdb_contthread;
79595@@ -254,7 +254,7 @@ struct kgdb_arch {
79596 void (*correct_hw_break)(void);
79597
79598 void (*enable_nmi)(bool on);
79599-};
79600+} __do_const;
79601
79602 /**
79603 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79604@@ -279,7 +279,7 @@ struct kgdb_io {
79605 void (*pre_exception) (void);
79606 void (*post_exception) (void);
79607 int is_console;
79608-};
79609+} __do_const;
79610
79611 extern struct kgdb_arch arch_kgdb_ops;
79612
79613diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79614index 0555cc6..40116ce 100644
79615--- a/include/linux/kmod.h
79616+++ b/include/linux/kmod.h
79617@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79618 * usually useless though. */
79619 extern __printf(2, 3)
79620 int __request_module(bool wait, const char *name, ...);
79621+extern __printf(3, 4)
79622+int ___request_module(bool wait, char *param_name, const char *name, ...);
79623 #define request_module(mod...) __request_module(true, mod)
79624 #define request_module_nowait(mod...) __request_module(false, mod)
79625 #define try_then_request_module(x, mod...) \
79626@@ -57,6 +59,9 @@ struct subprocess_info {
79627 struct work_struct work;
79628 struct completion *complete;
79629 char *path;
79630+#ifdef CONFIG_GRKERNSEC
79631+ char *origpath;
79632+#endif
79633 char **argv;
79634 char **envp;
79635 int wait;
79636diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79637index e7ba650..0af3acb 100644
79638--- a/include/linux/kobject.h
79639+++ b/include/linux/kobject.h
79640@@ -116,7 +116,7 @@ struct kobj_type {
79641 struct attribute **default_attrs;
79642 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79643 const void *(*namespace)(struct kobject *kobj);
79644-};
79645+} __do_const;
79646
79647 struct kobj_uevent_env {
79648 char *envp[UEVENT_NUM_ENVP];
79649@@ -139,6 +139,7 @@ struct kobj_attribute {
79650 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79651 const char *buf, size_t count);
79652 };
79653+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79654
79655 extern const struct sysfs_ops kobj_sysfs_ops;
79656
79657@@ -166,7 +167,7 @@ struct kset {
79658 spinlock_t list_lock;
79659 struct kobject kobj;
79660 const struct kset_uevent_ops *uevent_ops;
79661-};
79662+} __randomize_layout;
79663
79664 extern void kset_init(struct kset *kset);
79665 extern int __must_check kset_register(struct kset *kset);
79666diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79667index df32d25..fb52e27 100644
79668--- a/include/linux/kobject_ns.h
79669+++ b/include/linux/kobject_ns.h
79670@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79671 const void *(*netlink_ns)(struct sock *sk);
79672 const void *(*initial_ns)(void);
79673 void (*drop_ns)(void *);
79674-};
79675+} __do_const;
79676
79677 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79678 int kobj_ns_type_registered(enum kobj_ns_type type);
79679diff --git a/include/linux/kref.h b/include/linux/kref.h
79680index 484604d..0f6c5b6 100644
79681--- a/include/linux/kref.h
79682+++ b/include/linux/kref.h
79683@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79684 static inline int kref_sub(struct kref *kref, unsigned int count,
79685 void (*release)(struct kref *kref))
79686 {
79687- WARN_ON(release == NULL);
79688+ BUG_ON(release == NULL);
79689
79690 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79691 release(kref);
79692diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79693index 9523d2a..16c0424 100644
79694--- a/include/linux/kvm_host.h
79695+++ b/include/linux/kvm_host.h
79696@@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79697 {
79698 }
79699 #endif
79700-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79701+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79702 struct module *module);
79703 void kvm_exit(void);
79704
79705@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79706 struct kvm_guest_debug *dbg);
79707 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79708
79709-int kvm_arch_init(void *opaque);
79710+int kvm_arch_init(const void *opaque);
79711 void kvm_arch_exit(void);
79712
79713 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79714diff --git a/include/linux/libata.h b/include/linux/libata.h
79715index bec6dbe..2873d64 100644
79716--- a/include/linux/libata.h
79717+++ b/include/linux/libata.h
79718@@ -975,7 +975,7 @@ struct ata_port_operations {
79719 * fields must be pointers.
79720 */
79721 const struct ata_port_operations *inherits;
79722-};
79723+} __do_const;
79724
79725 struct ata_port_info {
79726 unsigned long flags;
79727diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79728index d3e8ad2..a949f68 100644
79729--- a/include/linux/linkage.h
79730+++ b/include/linux/linkage.h
79731@@ -31,6 +31,7 @@
79732 #endif
79733
79734 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79735+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79736 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79737
79738 /*
79739diff --git a/include/linux/list.h b/include/linux/list.h
79740index ef95941..82db65a 100644
79741--- a/include/linux/list.h
79742+++ b/include/linux/list.h
79743@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79744 extern void list_del(struct list_head *entry);
79745 #endif
79746
79747+extern void __pax_list_add(struct list_head *new,
79748+ struct list_head *prev,
79749+ struct list_head *next);
79750+static inline void pax_list_add(struct list_head *new, struct list_head *head)
79751+{
79752+ __pax_list_add(new, head, head->next);
79753+}
79754+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79755+{
79756+ __pax_list_add(new, head->prev, head);
79757+}
79758+extern void pax_list_del(struct list_head *entry);
79759+
79760 /**
79761 * list_replace - replace old entry by new one
79762 * @old : the element to be replaced
79763@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79764 INIT_LIST_HEAD(entry);
79765 }
79766
79767+extern void pax_list_del_init(struct list_head *entry);
79768+
79769 /**
79770 * list_move - delete from one list and add as another's head
79771 * @list: the entry to move
79772diff --git a/include/linux/math64.h b/include/linux/math64.h
79773index c45c089..298841c 100644
79774--- a/include/linux/math64.h
79775+++ b/include/linux/math64.h
79776@@ -15,7 +15,7 @@
79777 * This is commonly provided by 32bit archs to provide an optimized 64bit
79778 * divide.
79779 */
79780-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79781+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79782 {
79783 *remainder = dividend % divisor;
79784 return dividend / divisor;
79785@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79786 /**
79787 * div64_u64 - unsigned 64bit divide with 64bit divisor
79788 */
79789-static inline u64 div64_u64(u64 dividend, u64 divisor)
79790+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79791 {
79792 return dividend / divisor;
79793 }
79794@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79795 #define div64_ul(x, y) div_u64((x), (y))
79796
79797 #ifndef div_u64_rem
79798-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79799+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79800 {
79801 *remainder = do_div(dividend, divisor);
79802 return dividend;
79803@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79804 #endif
79805
79806 #ifndef div64_u64
79807-extern u64 div64_u64(u64 dividend, u64 divisor);
79808+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79809 #endif
79810
79811 #ifndef div64_s64
79812@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79813 * divide.
79814 */
79815 #ifndef div_u64
79816-static inline u64 div_u64(u64 dividend, u32 divisor)
79817+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79818 {
79819 u32 remainder;
79820 return div_u64_rem(dividend, divisor, &remainder);
79821diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79822index 9fe426b..8148be6 100644
79823--- a/include/linux/mempolicy.h
79824+++ b/include/linux/mempolicy.h
79825@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79826 }
79827
79828 #define vma_policy(vma) ((vma)->vm_policy)
79829+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79830+{
79831+ vma->vm_policy = pol;
79832+}
79833
79834 static inline void mpol_get(struct mempolicy *pol)
79835 {
79836@@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79837 }
79838
79839 #define vma_policy(vma) NULL
79840+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79841+{
79842+}
79843
79844 static inline int
79845 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79846diff --git a/include/linux/mm.h b/include/linux/mm.h
79847index 0ab5439..2859c61 100644
79848--- a/include/linux/mm.h
79849+++ b/include/linux/mm.h
79850@@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79851 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79852 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79853 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79854+
79855+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79856+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79857+#endif
79858+
79859 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79860
79861 #ifdef CONFIG_MEM_SOFT_DIRTY
79862@@ -219,8 +224,8 @@ struct vm_operations_struct {
79863 /* called by access_process_vm when get_user_pages() fails, typically
79864 * for use by special VMAs that can switch between memory and hardware
79865 */
79866- int (*access)(struct vm_area_struct *vma, unsigned long addr,
79867- void *buf, int len, int write);
79868+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79869+ void *buf, size_t len, int write);
79870 #ifdef CONFIG_NUMA
79871 /*
79872 * set_policy() op must add a reference to any non-NULL @new mempolicy
79873@@ -250,6 +255,7 @@ struct vm_operations_struct {
79874 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79875 unsigned long size, pgoff_t pgoff);
79876 };
79877+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79878
79879 struct mmu_gather;
79880 struct inode;
79881@@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79882 unsigned long *pfn);
79883 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79884 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79885-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79886- void *buf, int len, int write);
79887+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79888+ void *buf, size_t len, int write);
79889
79890 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79891 loff_t const holebegin, loff_t const holelen)
79892@@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79893 }
79894 #endif
79895
79896-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79897-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79898- void *buf, int len, int write);
79899+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79900+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79901+ void *buf, size_t len, int write);
79902
79903 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79904 unsigned long start, unsigned long nr_pages,
79905@@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
79906 int set_page_dirty_lock(struct page *page);
79907 int clear_page_dirty_for_io(struct page *page);
79908
79909-/* Is the vma a continuation of the stack vma above it? */
79910-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79911-{
79912- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79913-}
79914-
79915-static inline int stack_guard_page_start(struct vm_area_struct *vma,
79916- unsigned long addr)
79917-{
79918- return (vma->vm_flags & VM_GROWSDOWN) &&
79919- (vma->vm_start == addr) &&
79920- !vma_growsdown(vma->vm_prev, addr);
79921-}
79922-
79923-/* Is the vma a continuation of the stack vma below it? */
79924-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79925-{
79926- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79927-}
79928-
79929-static inline int stack_guard_page_end(struct vm_area_struct *vma,
79930- unsigned long addr)
79931-{
79932- return (vma->vm_flags & VM_GROWSUP) &&
79933- (vma->vm_end == addr) &&
79934- !vma_growsup(vma->vm_next, addr);
79935-}
79936-
79937 extern pid_t
79938 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79939
79940@@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79941 }
79942 #endif
79943
79944+#ifdef CONFIG_MMU
79945+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79946+#else
79947+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79948+{
79949+ return __pgprot(0);
79950+}
79951+#endif
79952+
79953 int vma_wants_writenotify(struct vm_area_struct *vma);
79954
79955 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79956@@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79957 {
79958 return 0;
79959 }
79960+
79961+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79962+ unsigned long address)
79963+{
79964+ return 0;
79965+}
79966 #else
79967 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79968+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79969 #endif
79970
79971 #ifdef __PAGETABLE_PMD_FOLDED
79972@@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79973 {
79974 return 0;
79975 }
79976+
79977+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79978+ unsigned long address)
79979+{
79980+ return 0;
79981+}
79982 #else
79983 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79984+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79985 #endif
79986
79987 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79988@@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79989 NULL: pud_offset(pgd, address);
79990 }
79991
79992+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79993+{
79994+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79995+ NULL: pud_offset(pgd, address);
79996+}
79997+
79998 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79999 {
80000 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80001 NULL: pmd_offset(pud, address);
80002 }
80003+
80004+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80005+{
80006+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80007+ NULL: pmd_offset(pud, address);
80008+}
80009 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80010
80011 #if USE_SPLIT_PTE_PTLOCKS
80012@@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80013 unsigned long addr, unsigned long len,
80014 unsigned long flags, struct page **pages);
80015
80016-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80017+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80018
80019 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80020 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80021@@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80022 unsigned long len, unsigned long prot, unsigned long flags,
80023 unsigned long pgoff, unsigned long *populate);
80024 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80025+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80026
80027 #ifdef CONFIG_MMU
80028 extern int __mm_populate(unsigned long addr, unsigned long len,
80029@@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
80030 unsigned long high_limit;
80031 unsigned long align_mask;
80032 unsigned long align_offset;
80033+ unsigned long threadstack_offset;
80034 };
80035
80036-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80037-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80038+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80039+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80040
80041 /*
80042 * Search for an unmapped address range.
80043@@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80044 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80045 */
80046 static inline unsigned long
80047-vm_unmapped_area(struct vm_unmapped_area_info *info)
80048+vm_unmapped_area(const struct vm_unmapped_area_info *info)
80049 {
80050 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80051 return unmapped_area(info);
80052@@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80053 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80054 struct vm_area_struct **pprev);
80055
80056+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80057+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80058+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80059+
80060 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80061 NULL if none. Assume start_addr < end_addr. */
80062 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80063@@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80064 return vma;
80065 }
80066
80067-#ifdef CONFIG_MMU
80068-pgprot_t vm_get_page_prot(unsigned long vm_flags);
80069-#else
80070-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80071-{
80072- return __pgprot(0);
80073-}
80074-#endif
80075-
80076 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
80077 unsigned long change_prot_numa(struct vm_area_struct *vma,
80078 unsigned long start, unsigned long end);
80079@@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80080 static inline void vm_stat_account(struct mm_struct *mm,
80081 unsigned long flags, struct file *file, long pages)
80082 {
80083+
80084+#ifdef CONFIG_PAX_RANDMMAP
80085+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80086+#endif
80087+
80088 mm->total_vm += pages;
80089 }
80090 #endif /* CONFIG_PROC_FS */
80091@@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
80092 extern int sysctl_memory_failure_early_kill;
80093 extern int sysctl_memory_failure_recovery;
80094 extern void shake_page(struct page *p, int access);
80095-extern atomic_long_t num_poisoned_pages;
80096+extern atomic_long_unchecked_t num_poisoned_pages;
80097 extern int soft_offline_page(struct page *page, int flags);
80098
80099 extern void dump_page(struct page *page);
80100@@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
80101 static inline void setup_nr_node_ids(void) {}
80102 #endif
80103
80104+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80105+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80106+#else
80107+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80108+#endif
80109+
80110 #endif /* __KERNEL__ */
80111 #endif /* _LINUX_MM_H */
80112diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80113index 290901a..e99b01c 100644
80114--- a/include/linux/mm_types.h
80115+++ b/include/linux/mm_types.h
80116@@ -307,7 +307,9 @@ struct vm_area_struct {
80117 #ifdef CONFIG_NUMA
80118 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80119 #endif
80120-};
80121+
80122+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80123+} __randomize_layout;
80124
80125 struct core_thread {
80126 struct task_struct *task;
80127@@ -453,7 +455,25 @@ struct mm_struct {
80128 bool tlb_flush_pending;
80129 #endif
80130 struct uprobes_state uprobes_state;
80131-};
80132+
80133+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80134+ unsigned long pax_flags;
80135+#endif
80136+
80137+#ifdef CONFIG_PAX_DLRESOLVE
80138+ unsigned long call_dl_resolve;
80139+#endif
80140+
80141+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80142+ unsigned long call_syscall;
80143+#endif
80144+
80145+#ifdef CONFIG_PAX_ASLR
80146+ unsigned long delta_mmap; /* randomized offset */
80147+ unsigned long delta_stack; /* randomized offset */
80148+#endif
80149+
80150+} __randomize_layout;
80151
80152 static inline void mm_init_cpumask(struct mm_struct *mm)
80153 {
80154diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80155index c5d5278..f0b68c8 100644
80156--- a/include/linux/mmiotrace.h
80157+++ b/include/linux/mmiotrace.h
80158@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80159 /* Called from ioremap.c */
80160 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80161 void __iomem *addr);
80162-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80163+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80164
80165 /* For anyone to insert markers. Remember trailing newline. */
80166 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80167@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80168 {
80169 }
80170
80171-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80172+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80173 {
80174 }
80175
80176diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80177index bd791e4..8617c34f 100644
80178--- a/include/linux/mmzone.h
80179+++ b/include/linux/mmzone.h
80180@@ -396,7 +396,7 @@ struct zone {
80181 unsigned long flags; /* zone flags, see below */
80182
80183 /* Zone statistics */
80184- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80185+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80186
80187 /*
80188 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80189diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80190index 45e9214..a7227d6 100644
80191--- a/include/linux/mod_devicetable.h
80192+++ b/include/linux/mod_devicetable.h
80193@@ -13,7 +13,7 @@
80194 typedef unsigned long kernel_ulong_t;
80195 #endif
80196
80197-#define PCI_ANY_ID (~0)
80198+#define PCI_ANY_ID ((__u16)~0)
80199
80200 struct pci_device_id {
80201 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80202@@ -139,7 +139,7 @@ struct usb_device_id {
80203 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80204 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80205
80206-#define HID_ANY_ID (~0)
80207+#define HID_ANY_ID (~0U)
80208 #define HID_BUS_ANY 0xffff
80209 #define HID_GROUP_ANY 0x0000
80210
80211@@ -467,7 +467,7 @@ struct dmi_system_id {
80212 const char *ident;
80213 struct dmi_strmatch matches[4];
80214 void *driver_data;
80215-};
80216+} __do_const;
80217 /*
80218 * struct dmi_device_id appears during expansion of
80219 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80220diff --git a/include/linux/module.h b/include/linux/module.h
80221index 15cd6b1..f6e2e6a 100644
80222--- a/include/linux/module.h
80223+++ b/include/linux/module.h
80224@@ -17,9 +17,11 @@
80225 #include <linux/moduleparam.h>
80226 #include <linux/tracepoint.h>
80227 #include <linux/export.h>
80228+#include <linux/fs.h>
80229
80230 #include <linux/percpu.h>
80231 #include <asm/module.h>
80232+#include <asm/pgtable.h>
80233
80234 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80235 #define MODULE_SIG_STRING "~Module signature appended~\n"
80236@@ -43,7 +45,7 @@ struct module_kobject {
80237 struct kobject *drivers_dir;
80238 struct module_param_attrs *mp;
80239 struct completion *kobj_completion;
80240-};
80241+} __randomize_layout;
80242
80243 struct module_attribute {
80244 struct attribute attr;
80245@@ -55,12 +57,13 @@ struct module_attribute {
80246 int (*test)(struct module *);
80247 void (*free)(struct module *);
80248 };
80249+typedef struct module_attribute __no_const module_attribute_no_const;
80250
80251 struct module_version_attribute {
80252 struct module_attribute mattr;
80253 const char *module_name;
80254 const char *version;
80255-} __attribute__ ((__aligned__(sizeof(void *))));
80256+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80257
80258 extern ssize_t __modver_version_show(struct module_attribute *,
80259 struct module_kobject *, char *);
80260@@ -238,7 +241,7 @@ struct module
80261
80262 /* Sysfs stuff. */
80263 struct module_kobject mkobj;
80264- struct module_attribute *modinfo_attrs;
80265+ module_attribute_no_const *modinfo_attrs;
80266 const char *version;
80267 const char *srcversion;
80268 struct kobject *holders_dir;
80269@@ -287,19 +290,16 @@ struct module
80270 int (*init)(void);
80271
80272 /* If this is non-NULL, vfree after init() returns */
80273- void *module_init;
80274+ void *module_init_rx, *module_init_rw;
80275
80276 /* Here is the actual code + data, vfree'd on unload. */
80277- void *module_core;
80278+ void *module_core_rx, *module_core_rw;
80279
80280 /* Here are the sizes of the init and core sections */
80281- unsigned int init_size, core_size;
80282+ unsigned int init_size_rw, core_size_rw;
80283
80284 /* The size of the executable code in each section. */
80285- unsigned int init_text_size, core_text_size;
80286-
80287- /* Size of RO sections of the module (text+rodata) */
80288- unsigned int init_ro_size, core_ro_size;
80289+ unsigned int init_size_rx, core_size_rx;
80290
80291 /* Arch-specific module values */
80292 struct mod_arch_specific arch;
80293@@ -355,6 +355,10 @@ struct module
80294 #ifdef CONFIG_EVENT_TRACING
80295 struct ftrace_event_call **trace_events;
80296 unsigned int num_trace_events;
80297+ struct file_operations trace_id;
80298+ struct file_operations trace_enable;
80299+ struct file_operations trace_format;
80300+ struct file_operations trace_filter;
80301 #endif
80302 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80303 unsigned int num_ftrace_callsites;
80304@@ -378,7 +382,7 @@ struct module
80305 ctor_fn_t *ctors;
80306 unsigned int num_ctors;
80307 #endif
80308-};
80309+} __randomize_layout;
80310 #ifndef MODULE_ARCH_INIT
80311 #define MODULE_ARCH_INIT {}
80312 #endif
80313@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80314 bool is_module_percpu_address(unsigned long addr);
80315 bool is_module_text_address(unsigned long addr);
80316
80317+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80318+{
80319+
80320+#ifdef CONFIG_PAX_KERNEXEC
80321+ if (ktla_ktva(addr) >= (unsigned long)start &&
80322+ ktla_ktva(addr) < (unsigned long)start + size)
80323+ return 1;
80324+#endif
80325+
80326+ return ((void *)addr >= start && (void *)addr < start + size);
80327+}
80328+
80329+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80330+{
80331+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80332+}
80333+
80334+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80335+{
80336+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80337+}
80338+
80339+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80340+{
80341+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80342+}
80343+
80344+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80345+{
80346+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80347+}
80348+
80349 static inline int within_module_core(unsigned long addr, const struct module *mod)
80350 {
80351- return (unsigned long)mod->module_core <= addr &&
80352- addr < (unsigned long)mod->module_core + mod->core_size;
80353+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80354 }
80355
80356 static inline int within_module_init(unsigned long addr, const struct module *mod)
80357 {
80358- return (unsigned long)mod->module_init <= addr &&
80359- addr < (unsigned long)mod->module_init + mod->init_size;
80360+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80361 }
80362
80363 /* Search for module by name: must hold module_mutex. */
80364diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80365index 560ca53..ef621ef 100644
80366--- a/include/linux/moduleloader.h
80367+++ b/include/linux/moduleloader.h
80368@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80369 sections. Returns NULL on failure. */
80370 void *module_alloc(unsigned long size);
80371
80372+#ifdef CONFIG_PAX_KERNEXEC
80373+void *module_alloc_exec(unsigned long size);
80374+#else
80375+#define module_alloc_exec(x) module_alloc(x)
80376+#endif
80377+
80378 /* Free memory returned from module_alloc. */
80379 void module_free(struct module *mod, void *module_region);
80380
80381+#ifdef CONFIG_PAX_KERNEXEC
80382+void module_free_exec(struct module *mod, void *module_region);
80383+#else
80384+#define module_free_exec(x, y) module_free((x), (y))
80385+#endif
80386+
80387 /*
80388 * Apply the given relocation to the (simplified) ELF. Return -error
80389 * or 0.
80390@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80391 unsigned int relsec,
80392 struct module *me)
80393 {
80394+#ifdef CONFIG_MODULES
80395 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80396+#endif
80397 return -ENOEXEC;
80398 }
80399 #endif
80400@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80401 unsigned int relsec,
80402 struct module *me)
80403 {
80404+#ifdef CONFIG_MODULES
80405 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80406+#endif
80407 return -ENOEXEC;
80408 }
80409 #endif
80410diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80411index c3eb102..073c4a6 100644
80412--- a/include/linux/moduleparam.h
80413+++ b/include/linux/moduleparam.h
80414@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80415 * @len is usually just sizeof(string).
80416 */
80417 #define module_param_string(name, string, len, perm) \
80418- static const struct kparam_string __param_string_##name \
80419+ static const struct kparam_string __param_string_##name __used \
80420 = { len, string }; \
80421 __module_param_call(MODULE_PARAM_PREFIX, name, \
80422 &param_ops_string, \
80423@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80424 */
80425 #define module_param_array_named(name, array, type, nump, perm) \
80426 param_check_##type(name, &(array)[0]); \
80427- static const struct kparam_array __param_arr_##name \
80428+ static const struct kparam_array __param_arr_##name __used \
80429 = { .max = ARRAY_SIZE(array), .num = nump, \
80430 .ops = &param_ops_##type, \
80431 .elemsize = sizeof(array[0]), .elem = array }; \
80432diff --git a/include/linux/mount.h b/include/linux/mount.h
80433index 371d346..fba2819 100644
80434--- a/include/linux/mount.h
80435+++ b/include/linux/mount.h
80436@@ -56,7 +56,7 @@ struct vfsmount {
80437 struct dentry *mnt_root; /* root of the mounted tree */
80438 struct super_block *mnt_sb; /* pointer to superblock */
80439 int mnt_flags;
80440-};
80441+} __randomize_layout;
80442
80443 struct file; /* forward dec */
80444
80445diff --git a/include/linux/namei.h b/include/linux/namei.h
80446index 492de72..1bddcd4 100644
80447--- a/include/linux/namei.h
80448+++ b/include/linux/namei.h
80449@@ -19,7 +19,7 @@ struct nameidata {
80450 unsigned seq, m_seq;
80451 int last_type;
80452 unsigned depth;
80453- char *saved_names[MAX_NESTED_LINKS + 1];
80454+ const char *saved_names[MAX_NESTED_LINKS + 1];
80455 };
80456
80457 /*
80458@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80459
80460 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80461
80462-static inline void nd_set_link(struct nameidata *nd, char *path)
80463+static inline void nd_set_link(struct nameidata *nd, const char *path)
80464 {
80465 nd->saved_names[nd->depth] = path;
80466 }
80467
80468-static inline char *nd_get_link(struct nameidata *nd)
80469+static inline const char *nd_get_link(const struct nameidata *nd)
80470 {
80471 return nd->saved_names[nd->depth];
80472 }
80473diff --git a/include/linux/net.h b/include/linux/net.h
80474index 69be3e6..0fb422d 100644
80475--- a/include/linux/net.h
80476+++ b/include/linux/net.h
80477@@ -192,7 +192,7 @@ struct net_proto_family {
80478 int (*create)(struct net *net, struct socket *sock,
80479 int protocol, int kern);
80480 struct module *owner;
80481-};
80482+} __do_const;
80483
80484 struct iovec;
80485 struct kvec;
80486diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80487index 2177a6b..67fc561 100644
80488--- a/include/linux/netdevice.h
80489+++ b/include/linux/netdevice.h
80490@@ -1129,6 +1129,7 @@ struct net_device_ops {
80491 struct net_device *dev,
80492 void *priv);
80493 };
80494+typedef struct net_device_ops __no_const net_device_ops_no_const;
80495
80496 /*
80497 * The DEVICE structure.
80498@@ -1211,7 +1212,7 @@ struct net_device {
80499 int iflink;
80500
80501 struct net_device_stats stats;
80502- atomic_long_t rx_dropped; /* dropped packets by core network
80503+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80504 * Do not use this in drivers.
80505 */
80506
80507diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80508index 2077489..a15e561 100644
80509--- a/include/linux/netfilter.h
80510+++ b/include/linux/netfilter.h
80511@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80512 #endif
80513 /* Use the module struct to lock set/get code in place */
80514 struct module *owner;
80515-};
80516+} __do_const;
80517
80518 /* Function to register/unregister hook points. */
80519 int nf_register_hook(struct nf_hook_ops *reg);
80520diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80521index 28c7436..2d6156a 100644
80522--- a/include/linux/netfilter/nfnetlink.h
80523+++ b/include/linux/netfilter/nfnetlink.h
80524@@ -19,7 +19,7 @@ struct nfnl_callback {
80525 const struct nlattr * const cda[]);
80526 const struct nla_policy *policy; /* netlink attribute policy */
80527 const u_int16_t attr_count; /* number of nlattr's */
80528-};
80529+} __do_const;
80530
80531 struct nfnetlink_subsystem {
80532 const char *name;
80533diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80534new file mode 100644
80535index 0000000..33f4af8
80536--- /dev/null
80537+++ b/include/linux/netfilter/xt_gradm.h
80538@@ -0,0 +1,9 @@
80539+#ifndef _LINUX_NETFILTER_XT_GRADM_H
80540+#define _LINUX_NETFILTER_XT_GRADM_H 1
80541+
80542+struct xt_gradm_mtinfo {
80543+ __u16 flags;
80544+ __u16 invflags;
80545+};
80546+
80547+#endif
80548diff --git a/include/linux/nls.h b/include/linux/nls.h
80549index 5dc635f..35f5e11 100644
80550--- a/include/linux/nls.h
80551+++ b/include/linux/nls.h
80552@@ -31,7 +31,7 @@ struct nls_table {
80553 const unsigned char *charset2upper;
80554 struct module *owner;
80555 struct nls_table *next;
80556-};
80557+} __do_const;
80558
80559 /* this value hold the maximum octet of charset */
80560 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80561diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80562index d14a4c3..a078786 100644
80563--- a/include/linux/notifier.h
80564+++ b/include/linux/notifier.h
80565@@ -54,7 +54,8 @@ struct notifier_block {
80566 notifier_fn_t notifier_call;
80567 struct notifier_block __rcu *next;
80568 int priority;
80569-};
80570+} __do_const;
80571+typedef struct notifier_block __no_const notifier_block_no_const;
80572
80573 struct atomic_notifier_head {
80574 spinlock_t lock;
80575diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80576index b2a0f15..4d7da32 100644
80577--- a/include/linux/oprofile.h
80578+++ b/include/linux/oprofile.h
80579@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80580 int oprofilefs_create_ro_ulong(struct dentry * root,
80581 char const * name, ulong * val);
80582
80583-/** Create a file for read-only access to an atomic_t. */
80584+/** Create a file for read-only access to an atomic_unchecked_t. */
80585 int oprofilefs_create_ro_atomic(struct dentry * root,
80586- char const * name, atomic_t * val);
80587+ char const * name, atomic_unchecked_t * val);
80588
80589 /** create a directory */
80590 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80591diff --git a/include/linux/padata.h b/include/linux/padata.h
80592index 4386946..f50c615 100644
80593--- a/include/linux/padata.h
80594+++ b/include/linux/padata.h
80595@@ -129,7 +129,7 @@ struct parallel_data {
80596 struct padata_serial_queue __percpu *squeue;
80597 atomic_t reorder_objects;
80598 atomic_t refcnt;
80599- atomic_t seq_nr;
80600+ atomic_unchecked_t seq_nr;
80601 struct padata_cpumask cpumask;
80602 spinlock_t lock ____cacheline_aligned;
80603 unsigned int processed;
80604diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80605index a2e2f1d..8a391d2 100644
80606--- a/include/linux/pci_hotplug.h
80607+++ b/include/linux/pci_hotplug.h
80608@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80609 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80610 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80611 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80612-};
80613+} __do_const;
80614+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80615
80616 /**
80617 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80618diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80619index 2e069d1..27054b8 100644
80620--- a/include/linux/perf_event.h
80621+++ b/include/linux/perf_event.h
80622@@ -327,8 +327,8 @@ struct perf_event {
80623
80624 enum perf_event_active_state state;
80625 unsigned int attach_state;
80626- local64_t count;
80627- atomic64_t child_count;
80628+ local64_t count; /* PaX: fix it one day */
80629+ atomic64_unchecked_t child_count;
80630
80631 /*
80632 * These are the total time in nanoseconds that the event
80633@@ -379,8 +379,8 @@ struct perf_event {
80634 * These accumulate total time (in nanoseconds) that children
80635 * events have been enabled and running, respectively.
80636 */
80637- atomic64_t child_total_time_enabled;
80638- atomic64_t child_total_time_running;
80639+ atomic64_unchecked_t child_total_time_enabled;
80640+ atomic64_unchecked_t child_total_time_running;
80641
80642 /*
80643 * Protect attach/detach and child_list:
80644@@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80645 entry->ip[entry->nr++] = ip;
80646 }
80647
80648-extern int sysctl_perf_event_paranoid;
80649+extern int sysctl_perf_event_legitimately_concerned;
80650 extern int sysctl_perf_event_mlock;
80651 extern int sysctl_perf_event_sample_rate;
80652 extern int sysctl_perf_cpu_time_max_percent;
80653@@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80654 loff_t *ppos);
80655
80656
80657+static inline bool perf_paranoid_any(void)
80658+{
80659+ return sysctl_perf_event_legitimately_concerned > 2;
80660+}
80661+
80662 static inline bool perf_paranoid_tracepoint_raw(void)
80663 {
80664- return sysctl_perf_event_paranoid > -1;
80665+ return sysctl_perf_event_legitimately_concerned > -1;
80666 }
80667
80668 static inline bool perf_paranoid_cpu(void)
80669 {
80670- return sysctl_perf_event_paranoid > 0;
80671+ return sysctl_perf_event_legitimately_concerned > 0;
80672 }
80673
80674 static inline bool perf_paranoid_kernel(void)
80675 {
80676- return sysctl_perf_event_paranoid > 1;
80677+ return sysctl_perf_event_legitimately_concerned > 1;
80678 }
80679
80680 extern void perf_event_init(void);
80681@@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80682 struct device_attribute attr;
80683 u64 id;
80684 const char *event_str;
80685-};
80686+} __do_const;
80687
80688 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80689 static struct perf_pmu_events_attr _var = { \
80690diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80691index 7246ef3..1539ea4 100644
80692--- a/include/linux/pid_namespace.h
80693+++ b/include/linux/pid_namespace.h
80694@@ -43,7 +43,7 @@ struct pid_namespace {
80695 int hide_pid;
80696 int reboot; /* group exit code if this pidns was rebooted */
80697 unsigned int proc_inum;
80698-};
80699+} __randomize_layout;
80700
80701 extern struct pid_namespace init_pid_ns;
80702
80703diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80704index ab57526..94598804 100644
80705--- a/include/linux/pipe_fs_i.h
80706+++ b/include/linux/pipe_fs_i.h
80707@@ -47,10 +47,10 @@ struct pipe_inode_info {
80708 struct mutex mutex;
80709 wait_queue_head_t wait;
80710 unsigned int nrbufs, curbuf, buffers;
80711- unsigned int readers;
80712- unsigned int writers;
80713- unsigned int files;
80714- unsigned int waiting_writers;
80715+ atomic_t readers;
80716+ atomic_t writers;
80717+ atomic_t files;
80718+ atomic_t waiting_writers;
80719 unsigned int r_counter;
80720 unsigned int w_counter;
80721 struct page *tmp_page;
80722diff --git a/include/linux/pm.h b/include/linux/pm.h
80723index a224c7f..92d8a97 100644
80724--- a/include/linux/pm.h
80725+++ b/include/linux/pm.h
80726@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80727 struct dev_pm_domain {
80728 struct dev_pm_ops ops;
80729 };
80730+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80731
80732 /*
80733 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80734diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80735index 7c1d252..0e7061d 100644
80736--- a/include/linux/pm_domain.h
80737+++ b/include/linux/pm_domain.h
80738@@ -44,11 +44,11 @@ struct gpd_dev_ops {
80739 int (*thaw_early)(struct device *dev);
80740 int (*thaw)(struct device *dev);
80741 bool (*active_wakeup)(struct device *dev);
80742-};
80743+} __no_const;
80744
80745 struct gpd_cpu_data {
80746 unsigned int saved_exit_latency;
80747- struct cpuidle_state *idle_state;
80748+ cpuidle_state_no_const *idle_state;
80749 };
80750
80751 struct generic_pm_domain {
80752diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80753index 6fa7cea..7bf6415 100644
80754--- a/include/linux/pm_runtime.h
80755+++ b/include/linux/pm_runtime.h
80756@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80757
80758 static inline void pm_runtime_mark_last_busy(struct device *dev)
80759 {
80760- ACCESS_ONCE(dev->power.last_busy) = jiffies;
80761+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80762 }
80763
80764 #else /* !CONFIG_PM_RUNTIME */
80765diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80766index 195aafc..49a7bc2 100644
80767--- a/include/linux/pnp.h
80768+++ b/include/linux/pnp.h
80769@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80770 struct pnp_fixup {
80771 char id[7];
80772 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80773-};
80774+} __do_const;
80775
80776 /* config parameters */
80777 #define PNP_CONFIG_NORMAL 0x0001
80778diff --git a/include/linux/poison.h b/include/linux/poison.h
80779index 2110a81..13a11bb 100644
80780--- a/include/linux/poison.h
80781+++ b/include/linux/poison.h
80782@@ -19,8 +19,8 @@
80783 * under normal circumstances, used to verify that nobody uses
80784 * non-initialized list entries.
80785 */
80786-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80787-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80788+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80789+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80790
80791 /********** include/linux/timer.h **********/
80792 /*
80793diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80794index d8b187c3..9a9257a 100644
80795--- a/include/linux/power/smartreflex.h
80796+++ b/include/linux/power/smartreflex.h
80797@@ -238,7 +238,7 @@ struct omap_sr_class_data {
80798 int (*notify)(struct omap_sr *sr, u32 status);
80799 u8 notify_flags;
80800 u8 class_type;
80801-};
80802+} __do_const;
80803
80804 /**
80805 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80806diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80807index 4ea1d37..80f4b33 100644
80808--- a/include/linux/ppp-comp.h
80809+++ b/include/linux/ppp-comp.h
80810@@ -84,7 +84,7 @@ struct compressor {
80811 struct module *owner;
80812 /* Extra skb space needed by the compressor algorithm */
80813 unsigned int comp_extra;
80814-};
80815+} __do_const;
80816
80817 /*
80818 * The return value from decompress routine is the length of the
80819diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80820index a3d9dc8..8af9922 100644
80821--- a/include/linux/preempt.h
80822+++ b/include/linux/preempt.h
80823@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80824 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80825 #endif
80826
80827+#define raw_preempt_count_add(val) __preempt_count_add(val)
80828+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80829+
80830 #define __preempt_count_inc() __preempt_count_add(1)
80831 #define __preempt_count_dec() __preempt_count_sub(1)
80832
80833 #define preempt_count_inc() preempt_count_add(1)
80834+#define raw_preempt_count_inc() raw_preempt_count_add(1)
80835 #define preempt_count_dec() preempt_count_sub(1)
80836+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80837
80838 #ifdef CONFIG_PREEMPT_COUNT
80839
80840@@ -41,6 +46,12 @@ do { \
80841 barrier(); \
80842 } while (0)
80843
80844+#define raw_preempt_disable() \
80845+do { \
80846+ raw_preempt_count_inc(); \
80847+ barrier(); \
80848+} while (0)
80849+
80850 #define sched_preempt_enable_no_resched() \
80851 do { \
80852 barrier(); \
80853@@ -49,6 +60,12 @@ do { \
80854
80855 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80856
80857+#define raw_preempt_enable_no_resched() \
80858+do { \
80859+ barrier(); \
80860+ raw_preempt_count_dec(); \
80861+} while (0)
80862+
80863 #ifdef CONFIG_PREEMPT
80864 #define preempt_enable() \
80865 do { \
80866@@ -105,8 +122,10 @@ do { \
80867 * region.
80868 */
80869 #define preempt_disable() barrier()
80870+#define raw_preempt_disable() barrier()
80871 #define sched_preempt_enable_no_resched() barrier()
80872 #define preempt_enable_no_resched() barrier()
80873+#define raw_preempt_enable_no_resched() barrier()
80874 #define preempt_enable() barrier()
80875 #define preempt_check_resched() do { } while (0)
80876
80877diff --git a/include/linux/printk.h b/include/linux/printk.h
80878index 6949258..7c4730e 100644
80879--- a/include/linux/printk.h
80880+++ b/include/linux/printk.h
80881@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
80882 void early_printk(const char *s, ...) { }
80883 #endif
80884
80885+extern int kptr_restrict;
80886+
80887 #ifdef CONFIG_PRINTK
80888 asmlinkage __printf(5, 0)
80889 int vprintk_emit(int facility, int level,
80890@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80891
80892 extern int printk_delay_msec;
80893 extern int dmesg_restrict;
80894-extern int kptr_restrict;
80895
80896 extern void wake_up_klogd(void);
80897
80898diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80899index 608e60a..c26f864 100644
80900--- a/include/linux/proc_fs.h
80901+++ b/include/linux/proc_fs.h
80902@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80903 return proc_create_data(name, mode, parent, proc_fops, NULL);
80904 }
80905
80906+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80907+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80908+{
80909+#ifdef CONFIG_GRKERNSEC_PROC_USER
80910+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80911+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80912+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80913+#else
80914+ return proc_create_data(name, mode, parent, proc_fops, NULL);
80915+#endif
80916+}
80917+
80918+
80919 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80920 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80921 extern void *PDE_DATA(const struct inode *);
80922diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80923index 34a1e10..70f6bde 100644
80924--- a/include/linux/proc_ns.h
80925+++ b/include/linux/proc_ns.h
80926@@ -14,7 +14,7 @@ struct proc_ns_operations {
80927 void (*put)(void *ns);
80928 int (*install)(struct nsproxy *nsproxy, void *ns);
80929 unsigned int (*inum)(void *ns);
80930-};
80931+} __do_const __randomize_layout;
80932
80933 struct proc_ns {
80934 void *ns;
80935diff --git a/include/linux/quota.h b/include/linux/quota.h
80936index cc7494a..1e27036 100644
80937--- a/include/linux/quota.h
80938+++ b/include/linux/quota.h
80939@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80940
80941 extern bool qid_eq(struct kqid left, struct kqid right);
80942 extern bool qid_lt(struct kqid left, struct kqid right);
80943-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80944+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80945 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80946 extern bool qid_valid(struct kqid qid);
80947
80948diff --git a/include/linux/random.h b/include/linux/random.h
80949index 4002b3d..d5ad855 100644
80950--- a/include/linux/random.h
80951+++ b/include/linux/random.h
80952@@ -10,9 +10,19 @@
80953
80954
80955 extern void add_device_randomness(const void *, unsigned int);
80956+
80957+static inline void add_latent_entropy(void)
80958+{
80959+
80960+#ifdef LATENT_ENTROPY_PLUGIN
80961+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80962+#endif
80963+
80964+}
80965+
80966 extern void add_input_randomness(unsigned int type, unsigned int code,
80967- unsigned int value);
80968-extern void add_interrupt_randomness(int irq, int irq_flags);
80969+ unsigned int value) __latent_entropy;
80970+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80971
80972 extern void get_random_bytes(void *buf, int nbytes);
80973 extern void get_random_bytes_arch(void *buf, int nbytes);
80974@@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80975 extern const struct file_operations random_fops, urandom_fops;
80976 #endif
80977
80978-unsigned int get_random_int(void);
80979+unsigned int __intentional_overflow(-1) get_random_int(void);
80980 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80981
80982-u32 prandom_u32(void);
80983+u32 prandom_u32(void) __intentional_overflow(-1);
80984 void prandom_bytes(void *buf, int nbytes);
80985 void prandom_seed(u32 seed);
80986 void prandom_reseed_late(void);
80987@@ -38,6 +48,11 @@ struct rnd_state {
80988 u32 prandom_u32_state(struct rnd_state *state);
80989 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80990
80991+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80992+{
80993+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80994+}
80995+
80996 /*
80997 * Handle minimum values for seeds
80998 */
80999diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81000index fea49b5..2ac22bb 100644
81001--- a/include/linux/rbtree_augmented.h
81002+++ b/include/linux/rbtree_augmented.h
81003@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81004 old->rbaugmented = rbcompute(old); \
81005 } \
81006 rbstatic const struct rb_augment_callbacks rbname = { \
81007- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81008+ .propagate = rbname ## _propagate, \
81009+ .copy = rbname ## _copy, \
81010+ .rotate = rbname ## _rotate \
81011 };
81012
81013
81014diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81015index 45a0a9e..e83788e 100644
81016--- a/include/linux/rculist.h
81017+++ b/include/linux/rculist.h
81018@@ -29,8 +29,8 @@
81019 */
81020 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81021 {
81022- ACCESS_ONCE(list->next) = list;
81023- ACCESS_ONCE(list->prev) = list;
81024+ ACCESS_ONCE_RW(list->next) = list;
81025+ ACCESS_ONCE_RW(list->prev) = list;
81026 }
81027
81028 /*
81029@@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
81030 struct list_head *prev, struct list_head *next);
81031 #endif
81032
81033+extern void __pax_list_add_rcu(struct list_head *new,
81034+ struct list_head *prev, struct list_head *next);
81035+
81036 /**
81037 * list_add_rcu - add a new entry to rcu-protected list
81038 * @new: new entry to be added
81039@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81040 __list_add_rcu(new, head, head->next);
81041 }
81042
81043+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81044+{
81045+ __pax_list_add_rcu(new, head, head->next);
81046+}
81047+
81048 /**
81049 * list_add_tail_rcu - add a new entry to rcu-protected list
81050 * @new: new entry to be added
81051@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81052 __list_add_rcu(new, head->prev, head);
81053 }
81054
81055+static inline void pax_list_add_tail_rcu(struct list_head *new,
81056+ struct list_head *head)
81057+{
81058+ __pax_list_add_rcu(new, head->prev, head);
81059+}
81060+
81061 /**
81062 * list_del_rcu - deletes entry from list without re-initialization
81063 * @entry: the element to delete from the list.
81064@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81065 entry->prev = LIST_POISON2;
81066 }
81067
81068+extern void pax_list_del_rcu(struct list_head *entry);
81069+
81070 /**
81071 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81072 * @n: the element to delete from the hash list.
81073diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81074index 9e7db9e..7d4fd72 100644
81075--- a/include/linux/reboot.h
81076+++ b/include/linux/reboot.h
81077@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81078 */
81079
81080 extern void migrate_to_reboot_cpu(void);
81081-extern void machine_restart(char *cmd);
81082-extern void machine_halt(void);
81083-extern void machine_power_off(void);
81084+extern void machine_restart(char *cmd) __noreturn;
81085+extern void machine_halt(void) __noreturn;
81086+extern void machine_power_off(void) __noreturn;
81087
81088 extern void machine_shutdown(void);
81089 struct pt_regs;
81090@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81091 */
81092
81093 extern void kernel_restart_prepare(char *cmd);
81094-extern void kernel_restart(char *cmd);
81095-extern void kernel_halt(void);
81096-extern void kernel_power_off(void);
81097+extern void kernel_restart(char *cmd) __noreturn;
81098+extern void kernel_halt(void) __noreturn;
81099+extern void kernel_power_off(void) __noreturn;
81100
81101 extern int C_A_D; /* for sysctl */
81102 void ctrl_alt_del(void);
81103@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81104 * Emergency restart, callable from an interrupt handler.
81105 */
81106
81107-extern void emergency_restart(void);
81108+extern void emergency_restart(void) __noreturn;
81109 #include <asm/emergency-restart.h>
81110
81111 #endif /* _LINUX_REBOOT_H */
81112diff --git a/include/linux/regset.h b/include/linux/regset.h
81113index 8e0c9fe..ac4d221 100644
81114--- a/include/linux/regset.h
81115+++ b/include/linux/regset.h
81116@@ -161,7 +161,8 @@ struct user_regset {
81117 unsigned int align;
81118 unsigned int bias;
81119 unsigned int core_note_type;
81120-};
81121+} __do_const;
81122+typedef struct user_regset __no_const user_regset_no_const;
81123
81124 /**
81125 * struct user_regset_view - available regsets
81126diff --git a/include/linux/relay.h b/include/linux/relay.h
81127index d7c8359..818daf5 100644
81128--- a/include/linux/relay.h
81129+++ b/include/linux/relay.h
81130@@ -157,7 +157,7 @@ struct rchan_callbacks
81131 * The callback should return 0 if successful, negative if not.
81132 */
81133 int (*remove_buf_file)(struct dentry *dentry);
81134-};
81135+} __no_const;
81136
81137 /*
81138 * CONFIG_RELAY kernel API, kernel/relay.c
81139diff --git a/include/linux/rio.h b/include/linux/rio.h
81140index b71d573..2f940bd 100644
81141--- a/include/linux/rio.h
81142+++ b/include/linux/rio.h
81143@@ -355,7 +355,7 @@ struct rio_ops {
81144 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81145 u64 rstart, u32 size, u32 flags);
81146 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81147-};
81148+} __no_const;
81149
81150 #define RIO_RESOURCE_MEM 0x00000100
81151 #define RIO_RESOURCE_DOORBELL 0x00000200
81152diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81153index 6dacb93..6174423 100644
81154--- a/include/linux/rmap.h
81155+++ b/include/linux/rmap.h
81156@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81157 void anon_vma_init(void); /* create anon_vma_cachep */
81158 int anon_vma_prepare(struct vm_area_struct *);
81159 void unlink_anon_vmas(struct vm_area_struct *);
81160-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81161-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81162+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81163+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81164
81165 static inline void anon_vma_merge(struct vm_area_struct *vma,
81166 struct vm_area_struct *next)
81167diff --git a/include/linux/sched.h b/include/linux/sched.h
81168index 53f97eb..1d90705 100644
81169--- a/include/linux/sched.h
81170+++ b/include/linux/sched.h
81171@@ -63,6 +63,7 @@ struct bio_list;
81172 struct fs_struct;
81173 struct perf_event_context;
81174 struct blk_plug;
81175+struct linux_binprm;
81176
81177 /*
81178 * List of flags we want to share for kernel threads,
81179@@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
81180 extern int in_sched_functions(unsigned long addr);
81181
81182 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81183-extern signed long schedule_timeout(signed long timeout);
81184+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81185 extern signed long schedule_timeout_interruptible(signed long timeout);
81186 extern signed long schedule_timeout_killable(signed long timeout);
81187 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81188@@ -315,6 +316,19 @@ struct nsproxy;
81189 struct user_namespace;
81190
81191 #ifdef CONFIG_MMU
81192+
81193+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81194+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81195+#else
81196+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81197+{
81198+ return 0;
81199+}
81200+#endif
81201+
81202+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81203+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81204+
81205 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81206 extern unsigned long
81207 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81208@@ -600,6 +614,17 @@ struct signal_struct {
81209 #ifdef CONFIG_TASKSTATS
81210 struct taskstats *stats;
81211 #endif
81212+
81213+#ifdef CONFIG_GRKERNSEC
81214+ u32 curr_ip;
81215+ u32 saved_ip;
81216+ u32 gr_saddr;
81217+ u32 gr_daddr;
81218+ u16 gr_sport;
81219+ u16 gr_dport;
81220+ u8 used_accept:1;
81221+#endif
81222+
81223 #ifdef CONFIG_AUDIT
81224 unsigned audit_tty;
81225 unsigned audit_tty_log_passwd;
81226@@ -626,7 +651,7 @@ struct signal_struct {
81227 struct mutex cred_guard_mutex; /* guard against foreign influences on
81228 * credential calculations
81229 * (notably. ptrace) */
81230-};
81231+} __randomize_layout;
81232
81233 /*
81234 * Bits in flags field of signal_struct.
81235@@ -680,6 +705,14 @@ struct user_struct {
81236 struct key *session_keyring; /* UID's default session keyring */
81237 #endif
81238
81239+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81240+ unsigned char kernel_banned;
81241+#endif
81242+#ifdef CONFIG_GRKERNSEC_BRUTE
81243+ unsigned char suid_banned;
81244+ unsigned long suid_ban_expires;
81245+#endif
81246+
81247 /* Hash table maintenance information */
81248 struct hlist_node uidhash_node;
81249 kuid_t uid;
81250@@ -687,7 +720,7 @@ struct user_struct {
81251 #ifdef CONFIG_PERF_EVENTS
81252 atomic_long_t locked_vm;
81253 #endif
81254-};
81255+} __randomize_layout;
81256
81257 extern int uids_sysfs_init(void);
81258
81259@@ -1162,8 +1195,8 @@ struct task_struct {
81260 struct list_head thread_group;
81261
81262 struct completion *vfork_done; /* for vfork() */
81263- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81264- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81265+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81266+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81267
81268 cputime_t utime, stime, utimescaled, stimescaled;
81269 cputime_t gtime;
81270@@ -1188,11 +1221,6 @@ struct task_struct {
81271 struct task_cputime cputime_expires;
81272 struct list_head cpu_timers[3];
81273
81274-/* process credentials */
81275- const struct cred __rcu *real_cred; /* objective and real subjective task
81276- * credentials (COW) */
81277- const struct cred __rcu *cred; /* effective (overridable) subjective task
81278- * credentials (COW) */
81279 char comm[TASK_COMM_LEN]; /* executable name excluding path
81280 - access with [gs]et_task_comm (which lock
81281 it with task_lock())
81282@@ -1209,6 +1237,10 @@ struct task_struct {
81283 #endif
81284 /* CPU-specific state of this task */
81285 struct thread_struct thread;
81286+/* thread_info moved to task_struct */
81287+#ifdef CONFIG_X86
81288+ struct thread_info tinfo;
81289+#endif
81290 /* filesystem information */
81291 struct fs_struct *fs;
81292 /* open file information */
81293@@ -1282,6 +1314,10 @@ struct task_struct {
81294 gfp_t lockdep_reclaim_gfp;
81295 #endif
81296
81297+/* process credentials */
81298+ const struct cred __rcu *real_cred; /* objective and real subjective task
81299+ * credentials (COW) */
81300+
81301 /* journalling filesystem info */
81302 void *journal_info;
81303
81304@@ -1320,6 +1356,10 @@ struct task_struct {
81305 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81306 struct list_head cg_list;
81307 #endif
81308+
81309+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81310+ * credentials (COW) */
81311+
81312 #ifdef CONFIG_FUTEX
81313 struct robust_list_head __user *robust_list;
81314 #ifdef CONFIG_COMPAT
81315@@ -1454,7 +1494,78 @@ struct task_struct {
81316 unsigned int sequential_io;
81317 unsigned int sequential_io_avg;
81318 #endif
81319-};
81320+
81321+#ifdef CONFIG_GRKERNSEC
81322+ /* grsecurity */
81323+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81324+ u64 exec_id;
81325+#endif
81326+#ifdef CONFIG_GRKERNSEC_SETXID
81327+ const struct cred *delayed_cred;
81328+#endif
81329+ struct dentry *gr_chroot_dentry;
81330+ struct acl_subject_label *acl;
81331+ struct acl_subject_label *tmpacl;
81332+ struct acl_role_label *role;
81333+ struct file *exec_file;
81334+ unsigned long brute_expires;
81335+ u16 acl_role_id;
81336+ u8 inherited;
81337+ /* is this the task that authenticated to the special role */
81338+ u8 acl_sp_role;
81339+ u8 is_writable;
81340+ u8 brute;
81341+ u8 gr_is_chrooted;
81342+#endif
81343+
81344+} __randomize_layout;
81345+
81346+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81347+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81348+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81349+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81350+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81351+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81352+
81353+#ifdef CONFIG_PAX_SOFTMODE
81354+extern int pax_softmode;
81355+#endif
81356+
81357+extern int pax_check_flags(unsigned long *);
81358+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81359+
81360+/* if tsk != current then task_lock must be held on it */
81361+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81362+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81363+{
81364+ if (likely(tsk->mm))
81365+ return tsk->mm->pax_flags;
81366+ else
81367+ return 0UL;
81368+}
81369+
81370+/* if tsk != current then task_lock must be held on it */
81371+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81372+{
81373+ if (likely(tsk->mm)) {
81374+ tsk->mm->pax_flags = flags;
81375+ return 0;
81376+ }
81377+ return -EINVAL;
81378+}
81379+#endif
81380+
81381+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81382+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81383+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81384+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81385+#endif
81386+
81387+struct path;
81388+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81389+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81390+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81391+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81392
81393 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81394 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81395@@ -1531,7 +1642,7 @@ struct pid_namespace;
81396 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81397 struct pid_namespace *ns);
81398
81399-static inline pid_t task_pid_nr(struct task_struct *tsk)
81400+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81401 {
81402 return tsk->pid;
81403 }
81404@@ -1981,7 +2092,9 @@ void yield(void);
81405 extern struct exec_domain default_exec_domain;
81406
81407 union thread_union {
81408+#ifndef CONFIG_X86
81409 struct thread_info thread_info;
81410+#endif
81411 unsigned long stack[THREAD_SIZE/sizeof(long)];
81412 };
81413
81414@@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81415 */
81416
81417 extern struct task_struct *find_task_by_vpid(pid_t nr);
81418+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81419 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81420 struct pid_namespace *ns);
81421
81422@@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81423 extern void exit_itimers(struct signal_struct *);
81424 extern void flush_itimer_signals(void);
81425
81426-extern void do_group_exit(int);
81427+extern __noreturn void do_group_exit(int);
81428
81429 extern int allow_signal(int);
81430 extern int disallow_signal(int);
81431@@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81432
81433 #endif
81434
81435-static inline int object_is_on_stack(void *obj)
81436+static inline int object_starts_on_stack(void *obj)
81437 {
81438- void *stack = task_stack_page(current);
81439+ const void *stack = task_stack_page(current);
81440
81441 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81442 }
81443diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81444index e3347c5..f682891 100644
81445--- a/include/linux/sched/sysctl.h
81446+++ b/include/linux/sched/sysctl.h
81447@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81448 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81449
81450 extern int sysctl_max_map_count;
81451+extern unsigned long sysctl_heap_stack_gap;
81452
81453 extern unsigned int sysctl_sched_latency;
81454 extern unsigned int sysctl_sched_min_granularity;
81455diff --git a/include/linux/security.h b/include/linux/security.h
81456index 5623a7f..b352409 100644
81457--- a/include/linux/security.h
81458+++ b/include/linux/security.h
81459@@ -27,6 +27,7 @@
81460 #include <linux/slab.h>
81461 #include <linux/err.h>
81462 #include <linux/string.h>
81463+#include <linux/grsecurity.h>
81464
81465 struct linux_binprm;
81466 struct cred;
81467@@ -116,8 +117,6 @@ struct seq_file;
81468
81469 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81470
81471-void reset_security_ops(void);
81472-
81473 #ifdef CONFIG_MMU
81474 extern unsigned long mmap_min_addr;
81475 extern unsigned long dac_mmap_min_addr;
81476diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81477index dc368b8..e895209 100644
81478--- a/include/linux/semaphore.h
81479+++ b/include/linux/semaphore.h
81480@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81481 }
81482
81483 extern void down(struct semaphore *sem);
81484-extern int __must_check down_interruptible(struct semaphore *sem);
81485+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81486 extern int __must_check down_killable(struct semaphore *sem);
81487 extern int __must_check down_trylock(struct semaphore *sem);
81488 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81489diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81490index 52e0097..09625ef 100644
81491--- a/include/linux/seq_file.h
81492+++ b/include/linux/seq_file.h
81493@@ -27,6 +27,9 @@ struct seq_file {
81494 struct mutex lock;
81495 const struct seq_operations *op;
81496 int poll_event;
81497+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81498+ u64 exec_id;
81499+#endif
81500 #ifdef CONFIG_USER_NS
81501 struct user_namespace *user_ns;
81502 #endif
81503@@ -39,6 +42,7 @@ struct seq_operations {
81504 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81505 int (*show) (struct seq_file *m, void *v);
81506 };
81507+typedef struct seq_operations __no_const seq_operations_no_const;
81508
81509 #define SEQ_SKIP 1
81510
81511diff --git a/include/linux/shm.h b/include/linux/shm.h
81512index 429c199..4d42e38 100644
81513--- a/include/linux/shm.h
81514+++ b/include/linux/shm.h
81515@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81516
81517 /* The task created the shm object. NULL if the task is dead. */
81518 struct task_struct *shm_creator;
81519+#ifdef CONFIG_GRKERNSEC
81520+ time_t shm_createtime;
81521+ pid_t shm_lapid;
81522+#endif
81523 };
81524
81525 /* shm_mode upper byte flags */
81526diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81527index 37cb679..dbaebc0 100644
81528--- a/include/linux/skbuff.h
81529+++ b/include/linux/skbuff.h
81530@@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81531 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81532 int node);
81533 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81534-static inline struct sk_buff *alloc_skb(unsigned int size,
81535+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81536 gfp_t priority)
81537 {
81538 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81539@@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81540 */
81541 static inline int skb_queue_empty(const struct sk_buff_head *list)
81542 {
81543- return list->next == (struct sk_buff *)list;
81544+ return list->next == (const struct sk_buff *)list;
81545 }
81546
81547 /**
81548@@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81549 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81550 const struct sk_buff *skb)
81551 {
81552- return skb->next == (struct sk_buff *)list;
81553+ return skb->next == (const struct sk_buff *)list;
81554 }
81555
81556 /**
81557@@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81558 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81559 const struct sk_buff *skb)
81560 {
81561- return skb->prev == (struct sk_buff *)list;
81562+ return skb->prev == (const struct sk_buff *)list;
81563 }
81564
81565 /**
81566@@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81567 return skb->inner_transport_header - skb->inner_network_header;
81568 }
81569
81570-static inline int skb_network_offset(const struct sk_buff *skb)
81571+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81572 {
81573 return skb_network_header(skb) - skb->data;
81574 }
81575@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81576 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81577 */
81578 #ifndef NET_SKB_PAD
81579-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81580+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81581 #endif
81582
81583 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81584@@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81585 int *err);
81586 unsigned int datagram_poll(struct file *file, struct socket *sock,
81587 struct poll_table_struct *wait);
81588-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81589+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81590 struct iovec *to, int size);
81591 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81592 struct iovec *iov);
81593@@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81594 nf_bridge_put(skb->nf_bridge);
81595 skb->nf_bridge = NULL;
81596 #endif
81597+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81598+ skb->nf_trace = 0;
81599+#endif
81600 }
81601
81602 static inline void nf_reset_trace(struct sk_buff *skb)
81603diff --git a/include/linux/slab.h b/include/linux/slab.h
81604index 1e2f4fe..df49ca6 100644
81605--- a/include/linux/slab.h
81606+++ b/include/linux/slab.h
81607@@ -14,15 +14,29 @@
81608 #include <linux/gfp.h>
81609 #include <linux/types.h>
81610 #include <linux/workqueue.h>
81611-
81612+#include <linux/err.h>
81613
81614 /*
81615 * Flags to pass to kmem_cache_create().
81616 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81617 */
81618 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81619+
81620+#ifdef CONFIG_PAX_USERCOPY_SLABS
81621+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81622+#else
81623+#define SLAB_USERCOPY 0x00000000UL
81624+#endif
81625+
81626 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81627 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81628+
81629+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81630+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81631+#else
81632+#define SLAB_NO_SANITIZE 0x00000000UL
81633+#endif
81634+
81635 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81636 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81637 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81638@@ -98,10 +112,13 @@
81639 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81640 * Both make kfree a no-op.
81641 */
81642-#define ZERO_SIZE_PTR ((void *)16)
81643+#define ZERO_SIZE_PTR \
81644+({ \
81645+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81646+ (void *)(-MAX_ERRNO-1L); \
81647+})
81648
81649-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81650- (unsigned long)ZERO_SIZE_PTR)
81651+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81652
81653 #include <linux/kmemleak.h>
81654
81655@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81656 void kfree(const void *);
81657 void kzfree(const void *);
81658 size_t ksize(const void *);
81659+const char *check_heap_object(const void *ptr, unsigned long n);
81660+bool is_usercopy_object(const void *ptr);
81661
81662 /*
81663 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81664@@ -174,7 +193,7 @@ struct kmem_cache {
81665 unsigned int align; /* Alignment as calculated */
81666 unsigned long flags; /* Active flags on the slab */
81667 const char *name; /* Slab name for sysfs */
81668- int refcount; /* Use counter */
81669+ atomic_t refcount; /* Use counter */
81670 void (*ctor)(void *); /* Called on object slot creation */
81671 struct list_head list; /* List of all slab caches on the system */
81672 };
81673@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81674 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81675 #endif
81676
81677+#ifdef CONFIG_PAX_USERCOPY_SLABS
81678+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81679+#endif
81680+
81681 /*
81682 * Figure out which kmalloc slab an allocation of a certain size
81683 * belongs to.
81684@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81685 * 2 = 120 .. 192 bytes
81686 * n = 2^(n-1) .. 2^n -1
81687 */
81688-static __always_inline int kmalloc_index(size_t size)
81689+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81690 {
81691 if (!size)
81692 return 0;
81693@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81694 }
81695 #endif /* !CONFIG_SLOB */
81696
81697-void *__kmalloc(size_t size, gfp_t flags);
81698+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81699 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81700
81701 #ifdef CONFIG_NUMA
81702-void *__kmalloc_node(size_t size, gfp_t flags, int node);
81703+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81704 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81705 #else
81706 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81707diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81708index 09bfffb..4fc80fb 100644
81709--- a/include/linux/slab_def.h
81710+++ b/include/linux/slab_def.h
81711@@ -36,7 +36,7 @@ struct kmem_cache {
81712 /* 4) cache creation/removal */
81713 const char *name;
81714 struct list_head list;
81715- int refcount;
81716+ atomic_t refcount;
81717 int object_size;
81718 int align;
81719
81720@@ -52,10 +52,14 @@ struct kmem_cache {
81721 unsigned long node_allocs;
81722 unsigned long node_frees;
81723 unsigned long node_overflow;
81724- atomic_t allochit;
81725- atomic_t allocmiss;
81726- atomic_t freehit;
81727- atomic_t freemiss;
81728+ atomic_unchecked_t allochit;
81729+ atomic_unchecked_t allocmiss;
81730+ atomic_unchecked_t freehit;
81731+ atomic_unchecked_t freemiss;
81732+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81733+ atomic_unchecked_t sanitized;
81734+ atomic_unchecked_t not_sanitized;
81735+#endif
81736
81737 /*
81738 * If debugging is enabled, then the allocator can add additional
81739diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81740index f56bfa9..8378a26 100644
81741--- a/include/linux/slub_def.h
81742+++ b/include/linux/slub_def.h
81743@@ -74,7 +74,7 @@ struct kmem_cache {
81744 struct kmem_cache_order_objects max;
81745 struct kmem_cache_order_objects min;
81746 gfp_t allocflags; /* gfp flags to use on each alloc */
81747- int refcount; /* Refcount for slab cache destroy */
81748+ atomic_t refcount; /* Refcount for slab cache destroy */
81749 void (*ctor)(void *);
81750 int inuse; /* Offset to metadata */
81751 int align; /* Alignment */
81752diff --git a/include/linux/smp.h b/include/linux/smp.h
81753index 5da22ee..71d8a28 100644
81754--- a/include/linux/smp.h
81755+++ b/include/linux/smp.h
81756@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81757 #endif
81758
81759 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81760+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81761 #define put_cpu() preempt_enable()
81762+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81763
81764 /*
81765 * Callback to arch code if there's nosmp or maxcpus=0 on the
81766diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81767index 54f91d3..be2c379 100644
81768--- a/include/linux/sock_diag.h
81769+++ b/include/linux/sock_diag.h
81770@@ -11,7 +11,7 @@ struct sock;
81771 struct sock_diag_handler {
81772 __u8 family;
81773 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81774-};
81775+} __do_const;
81776
81777 int sock_diag_register(const struct sock_diag_handler *h);
81778 void sock_diag_unregister(const struct sock_diag_handler *h);
81779diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81780index 680f9a3..f13aeb0 100644
81781--- a/include/linux/sonet.h
81782+++ b/include/linux/sonet.h
81783@@ -7,7 +7,7 @@
81784 #include <uapi/linux/sonet.h>
81785
81786 struct k_sonet_stats {
81787-#define __HANDLE_ITEM(i) atomic_t i
81788+#define __HANDLE_ITEM(i) atomic_unchecked_t i
81789 __SONET_ITEMS
81790 #undef __HANDLE_ITEM
81791 };
81792diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81793index 07d8e53..dc934c9 100644
81794--- a/include/linux/sunrpc/addr.h
81795+++ b/include/linux/sunrpc/addr.h
81796@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81797 {
81798 switch (sap->sa_family) {
81799 case AF_INET:
81800- return ntohs(((struct sockaddr_in *)sap)->sin_port);
81801+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81802 case AF_INET6:
81803- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81804+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81805 }
81806 return 0;
81807 }
81808@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81809 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81810 const struct sockaddr *src)
81811 {
81812- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81813+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81814 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81815
81816 dsin->sin_family = ssin->sin_family;
81817@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81818 if (sa->sa_family != AF_INET6)
81819 return 0;
81820
81821- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81822+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81823 }
81824
81825 #endif /* _LINUX_SUNRPC_ADDR_H */
81826diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81827index 8af2804..c7414ef 100644
81828--- a/include/linux/sunrpc/clnt.h
81829+++ b/include/linux/sunrpc/clnt.h
81830@@ -97,7 +97,7 @@ struct rpc_procinfo {
81831 unsigned int p_timer; /* Which RTT timer to use */
81832 u32 p_statidx; /* Which procedure to account */
81833 const char * p_name; /* name of procedure */
81834-};
81835+} __do_const;
81836
81837 #ifdef __KERNEL__
81838
81839diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81840index 6eecfc2..7ada79d 100644
81841--- a/include/linux/sunrpc/svc.h
81842+++ b/include/linux/sunrpc/svc.h
81843@@ -410,7 +410,7 @@ struct svc_procedure {
81844 unsigned int pc_count; /* call count */
81845 unsigned int pc_cachetype; /* cache info (NFS) */
81846 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81847-};
81848+} __do_const;
81849
81850 /*
81851 * Function prototypes.
81852diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81853index 0b8e3e6..33e0a01 100644
81854--- a/include/linux/sunrpc/svc_rdma.h
81855+++ b/include/linux/sunrpc/svc_rdma.h
81856@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81857 extern unsigned int svcrdma_max_requests;
81858 extern unsigned int svcrdma_max_req_size;
81859
81860-extern atomic_t rdma_stat_recv;
81861-extern atomic_t rdma_stat_read;
81862-extern atomic_t rdma_stat_write;
81863-extern atomic_t rdma_stat_sq_starve;
81864-extern atomic_t rdma_stat_rq_starve;
81865-extern atomic_t rdma_stat_rq_poll;
81866-extern atomic_t rdma_stat_rq_prod;
81867-extern atomic_t rdma_stat_sq_poll;
81868-extern atomic_t rdma_stat_sq_prod;
81869+extern atomic_unchecked_t rdma_stat_recv;
81870+extern atomic_unchecked_t rdma_stat_read;
81871+extern atomic_unchecked_t rdma_stat_write;
81872+extern atomic_unchecked_t rdma_stat_sq_starve;
81873+extern atomic_unchecked_t rdma_stat_rq_starve;
81874+extern atomic_unchecked_t rdma_stat_rq_poll;
81875+extern atomic_unchecked_t rdma_stat_rq_prod;
81876+extern atomic_unchecked_t rdma_stat_sq_poll;
81877+extern atomic_unchecked_t rdma_stat_sq_prod;
81878
81879 #define RPCRDMA_VERSION 1
81880
81881diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81882index 8d71d65..f79586e 100644
81883--- a/include/linux/sunrpc/svcauth.h
81884+++ b/include/linux/sunrpc/svcauth.h
81885@@ -120,7 +120,7 @@ struct auth_ops {
81886 int (*release)(struct svc_rqst *rq);
81887 void (*domain_release)(struct auth_domain *);
81888 int (*set_client)(struct svc_rqst *rq);
81889-};
81890+} __do_const;
81891
81892 #define SVC_GARBAGE 1
81893 #define SVC_SYSERR 2
81894diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81895index a5ffd32..0935dea 100644
81896--- a/include/linux/swiotlb.h
81897+++ b/include/linux/swiotlb.h
81898@@ -60,7 +60,8 @@ extern void
81899
81900 extern void
81901 swiotlb_free_coherent(struct device *hwdev, size_t size,
81902- void *vaddr, dma_addr_t dma_handle);
81903+ void *vaddr, dma_addr_t dma_handle,
81904+ struct dma_attrs *attrs);
81905
81906 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81907 unsigned long offset, size_t size,
81908diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81909index 94273bb..c2e05fc 100644
81910--- a/include/linux/syscalls.h
81911+++ b/include/linux/syscalls.h
81912@@ -97,8 +97,14 @@ struct sigaltstack;
81913 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81914
81915 #define __SC_DECL(t, a) t a
81916+#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))
81917 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81918-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81919+#define __SC_LONG(t, a) __typeof( \
81920+ __builtin_choose_expr( \
81921+ sizeof(t) > sizeof(int), \
81922+ (t) 0, \
81923+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81924+ )) a
81925 #define __SC_CAST(t, a) (t) a
81926 #define __SC_ARGS(t, a) a
81927 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81928@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
81929 asmlinkage long sys_fsync(unsigned int fd);
81930 asmlinkage long sys_fdatasync(unsigned int fd);
81931 asmlinkage long sys_bdflush(int func, long data);
81932-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81933- char __user *type, unsigned long flags,
81934+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81935+ const char __user *type, unsigned long flags,
81936 void __user *data);
81937-asmlinkage long sys_umount(char __user *name, int flags);
81938-asmlinkage long sys_oldumount(char __user *name);
81939+asmlinkage long sys_umount(const char __user *name, int flags);
81940+asmlinkage long sys_oldumount(const char __user *name);
81941 asmlinkage long sys_truncate(const char __user *path, long length);
81942 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81943 asmlinkage long sys_stat(const char __user *filename,
81944@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81945 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81946 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81947 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81948- struct sockaddr __user *, int);
81949+ struct sockaddr __user *, int) __intentional_overflow(0);
81950 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81951 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81952 unsigned int vlen, unsigned flags);
81953diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81954index 27b3b0b..e093dd9 100644
81955--- a/include/linux/syscore_ops.h
81956+++ b/include/linux/syscore_ops.h
81957@@ -16,7 +16,7 @@ struct syscore_ops {
81958 int (*suspend)(void);
81959 void (*resume)(void);
81960 void (*shutdown)(void);
81961-};
81962+} __do_const;
81963
81964 extern void register_syscore_ops(struct syscore_ops *ops);
81965 extern void unregister_syscore_ops(struct syscore_ops *ops);
81966diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81967index 14a8ff2..fa95f3a 100644
81968--- a/include/linux/sysctl.h
81969+++ b/include/linux/sysctl.h
81970@@ -34,13 +34,13 @@ struct ctl_table_root;
81971 struct ctl_table_header;
81972 struct ctl_dir;
81973
81974-typedef struct ctl_table ctl_table;
81975-
81976 typedef int proc_handler (struct ctl_table *ctl, int write,
81977 void __user *buffer, size_t *lenp, loff_t *ppos);
81978
81979 extern int proc_dostring(struct ctl_table *, int,
81980 void __user *, size_t *, loff_t *);
81981+extern int proc_dostring_modpriv(struct ctl_table *, int,
81982+ void __user *, size_t *, loff_t *);
81983 extern int proc_dointvec(struct ctl_table *, int,
81984 void __user *, size_t *, loff_t *);
81985 extern int proc_dointvec_minmax(struct ctl_table *, int,
81986@@ -115,7 +115,9 @@ struct ctl_table
81987 struct ctl_table_poll *poll;
81988 void *extra1;
81989 void *extra2;
81990-};
81991+} __do_const __randomize_layout;
81992+typedef struct ctl_table __no_const ctl_table_no_const;
81993+typedef struct ctl_table ctl_table;
81994
81995 struct ctl_node {
81996 struct rb_node node;
81997diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81998index 6695040..3d4192d 100644
81999--- a/include/linux/sysfs.h
82000+++ b/include/linux/sysfs.h
82001@@ -33,7 +33,8 @@ struct attribute {
82002 struct lock_class_key *key;
82003 struct lock_class_key skey;
82004 #endif
82005-};
82006+} __do_const;
82007+typedef struct attribute __no_const attribute_no_const;
82008
82009 /**
82010 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82011@@ -62,7 +63,8 @@ struct attribute_group {
82012 struct attribute *, int);
82013 struct attribute **attrs;
82014 struct bin_attribute **bin_attrs;
82015-};
82016+} __do_const;
82017+typedef struct attribute_group __no_const attribute_group_no_const;
82018
82019 /**
82020 * Use these macros to make defining attributes easier. See include/linux/device.h
82021@@ -126,7 +128,8 @@ struct bin_attribute {
82022 char *, loff_t, size_t);
82023 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82024 struct vm_area_struct *vma);
82025-};
82026+} __do_const;
82027+typedef struct bin_attribute __no_const bin_attribute_no_const;
82028
82029 /**
82030 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82031diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82032index 387fa7d..3fcde6b 100644
82033--- a/include/linux/sysrq.h
82034+++ b/include/linux/sysrq.h
82035@@ -16,6 +16,7 @@
82036
82037 #include <linux/errno.h>
82038 #include <linux/types.h>
82039+#include <linux/compiler.h>
82040
82041 /* Possible values of bitmask for enabling sysrq functions */
82042 /* 0x0001 is reserved for enable everything */
82043@@ -33,7 +34,7 @@ struct sysrq_key_op {
82044 char *help_msg;
82045 char *action_msg;
82046 int enable_mask;
82047-};
82048+} __do_const;
82049
82050 #ifdef CONFIG_MAGIC_SYSRQ
82051
82052diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82053index fddbe20..0312de8 100644
82054--- a/include/linux/thread_info.h
82055+++ b/include/linux/thread_info.h
82056@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82057 #error "no set_restore_sigmask() provided and default one won't work"
82058 #endif
82059
82060+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82061+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82062+{
82063+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82064+ if (!__builtin_constant_p(n))
82065+#endif
82066+ __check_object_size(ptr, n, to_user);
82067+}
82068+
82069 #endif /* __KERNEL__ */
82070
82071 #endif /* _LINUX_THREAD_INFO_H */
82072diff --git a/include/linux/tty.h b/include/linux/tty.h
82073index 97d660e..6356755 100644
82074--- a/include/linux/tty.h
82075+++ b/include/linux/tty.h
82076@@ -196,7 +196,7 @@ struct tty_port {
82077 const struct tty_port_operations *ops; /* Port operations */
82078 spinlock_t lock; /* Lock protecting tty field */
82079 int blocked_open; /* Waiting to open */
82080- int count; /* Usage count */
82081+ atomic_t count; /* Usage count */
82082 wait_queue_head_t open_wait; /* Open waiters */
82083 wait_queue_head_t close_wait; /* Close waiters */
82084 wait_queue_head_t delta_msr_wait; /* Modem status change */
82085@@ -278,7 +278,7 @@ struct tty_struct {
82086 /* If the tty has a pending do_SAK, queue it here - akpm */
82087 struct work_struct SAK_work;
82088 struct tty_port *port;
82089-};
82090+} __randomize_layout;
82091
82092 /* Each of a tty's open files has private_data pointing to tty_file_private */
82093 struct tty_file_private {
82094@@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
82095 struct tty_struct *tty, struct file *filp);
82096 static inline int tty_port_users(struct tty_port *port)
82097 {
82098- return port->count + port->blocked_open;
82099+ return atomic_read(&port->count) + port->blocked_open;
82100 }
82101
82102 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82103diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82104index 756a609..f61242d 100644
82105--- a/include/linux/tty_driver.h
82106+++ b/include/linux/tty_driver.h
82107@@ -285,7 +285,7 @@ struct tty_operations {
82108 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82109 #endif
82110 const struct file_operations *proc_fops;
82111-};
82112+} __do_const;
82113
82114 struct tty_driver {
82115 int magic; /* magic number for this structure */
82116@@ -319,7 +319,7 @@ struct tty_driver {
82117
82118 const struct tty_operations *ops;
82119 struct list_head tty_drivers;
82120-};
82121+} __randomize_layout;
82122
82123 extern struct list_head tty_drivers;
82124
82125diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82126index f15c898..207b7d1 100644
82127--- a/include/linux/tty_ldisc.h
82128+++ b/include/linux/tty_ldisc.h
82129@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
82130
82131 struct module *owner;
82132
82133- int refcount;
82134+ atomic_t refcount;
82135 };
82136
82137 struct tty_ldisc {
82138diff --git a/include/linux/types.h b/include/linux/types.h
82139index 4d118ba..c3ee9bf 100644
82140--- a/include/linux/types.h
82141+++ b/include/linux/types.h
82142@@ -176,10 +176,26 @@ typedef struct {
82143 int counter;
82144 } atomic_t;
82145
82146+#ifdef CONFIG_PAX_REFCOUNT
82147+typedef struct {
82148+ int counter;
82149+} atomic_unchecked_t;
82150+#else
82151+typedef atomic_t atomic_unchecked_t;
82152+#endif
82153+
82154 #ifdef CONFIG_64BIT
82155 typedef struct {
82156 long counter;
82157 } atomic64_t;
82158+
82159+#ifdef CONFIG_PAX_REFCOUNT
82160+typedef struct {
82161+ long counter;
82162+} atomic64_unchecked_t;
82163+#else
82164+typedef atomic64_t atomic64_unchecked_t;
82165+#endif
82166 #endif
82167
82168 struct list_head {
82169diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82170index 9d8cf05..0ed74dd 100644
82171--- a/include/linux/uaccess.h
82172+++ b/include/linux/uaccess.h
82173@@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82174 long ret; \
82175 mm_segment_t old_fs = get_fs(); \
82176 \
82177- set_fs(KERNEL_DS); \
82178 pagefault_disable(); \
82179- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82180- pagefault_enable(); \
82181+ set_fs(KERNEL_DS); \
82182+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82183 set_fs(old_fs); \
82184+ pagefault_enable(); \
82185 ret; \
82186 })
82187
82188diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82189index 8e522cbc..aa8572d 100644
82190--- a/include/linux/uidgid.h
82191+++ b/include/linux/uidgid.h
82192@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82193
82194 #endif /* CONFIG_USER_NS */
82195
82196+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82197+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82198+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82199+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82200+
82201 #endif /* _LINUX_UIDGID_H */
82202diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82203index 99c1b4d..562e6f3 100644
82204--- a/include/linux/unaligned/access_ok.h
82205+++ b/include/linux/unaligned/access_ok.h
82206@@ -4,34 +4,34 @@
82207 #include <linux/kernel.h>
82208 #include <asm/byteorder.h>
82209
82210-static inline u16 get_unaligned_le16(const void *p)
82211+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82212 {
82213- return le16_to_cpup((__le16 *)p);
82214+ return le16_to_cpup((const __le16 *)p);
82215 }
82216
82217-static inline u32 get_unaligned_le32(const void *p)
82218+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82219 {
82220- return le32_to_cpup((__le32 *)p);
82221+ return le32_to_cpup((const __le32 *)p);
82222 }
82223
82224-static inline u64 get_unaligned_le64(const void *p)
82225+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82226 {
82227- return le64_to_cpup((__le64 *)p);
82228+ return le64_to_cpup((const __le64 *)p);
82229 }
82230
82231-static inline u16 get_unaligned_be16(const void *p)
82232+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82233 {
82234- return be16_to_cpup((__be16 *)p);
82235+ return be16_to_cpup((const __be16 *)p);
82236 }
82237
82238-static inline u32 get_unaligned_be32(const void *p)
82239+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82240 {
82241- return be32_to_cpup((__be32 *)p);
82242+ return be32_to_cpup((const __be32 *)p);
82243 }
82244
82245-static inline u64 get_unaligned_be64(const void *p)
82246+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82247 {
82248- return be64_to_cpup((__be64 *)p);
82249+ return be64_to_cpup((const __be64 *)p);
82250 }
82251
82252 static inline void put_unaligned_le16(u16 val, void *p)
82253diff --git a/include/linux/usb.h b/include/linux/usb.h
82254index 7454865..29f4bfa 100644
82255--- a/include/linux/usb.h
82256+++ b/include/linux/usb.h
82257@@ -563,7 +563,7 @@ struct usb_device {
82258 int maxchild;
82259
82260 u32 quirks;
82261- atomic_t urbnum;
82262+ atomic_unchecked_t urbnum;
82263
82264 unsigned long active_duration;
82265
82266@@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82267
82268 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82269 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82270- void *data, __u16 size, int timeout);
82271+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82272 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82273 void *data, int len, int *actual_length, int timeout);
82274 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82275diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82276index e452ba6..78f8e80 100644
82277--- a/include/linux/usb/renesas_usbhs.h
82278+++ b/include/linux/usb/renesas_usbhs.h
82279@@ -39,7 +39,7 @@ enum {
82280 */
82281 struct renesas_usbhs_driver_callback {
82282 int (*notify_hotplug)(struct platform_device *pdev);
82283-};
82284+} __no_const;
82285
82286 /*
82287 * callback functions for platform
82288diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82289index 4836ba3..603f6ee 100644
82290--- a/include/linux/user_namespace.h
82291+++ b/include/linux/user_namespace.h
82292@@ -33,7 +33,7 @@ struct user_namespace {
82293 struct key *persistent_keyring_register;
82294 struct rw_semaphore persistent_keyring_register_sem;
82295 #endif
82296-};
82297+} __randomize_layout;
82298
82299 extern struct user_namespace init_user_ns;
82300
82301diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82302index 239e277..22a5cf5 100644
82303--- a/include/linux/utsname.h
82304+++ b/include/linux/utsname.h
82305@@ -24,7 +24,7 @@ struct uts_namespace {
82306 struct new_utsname name;
82307 struct user_namespace *user_ns;
82308 unsigned int proc_inum;
82309-};
82310+} __randomize_layout;
82311 extern struct uts_namespace init_uts_ns;
82312
82313 #ifdef CONFIG_UTS_NS
82314diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82315index 6f8fbcf..4efc177 100644
82316--- a/include/linux/vermagic.h
82317+++ b/include/linux/vermagic.h
82318@@ -25,9 +25,42 @@
82319 #define MODULE_ARCH_VERMAGIC ""
82320 #endif
82321
82322+#ifdef CONFIG_PAX_REFCOUNT
82323+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82324+#else
82325+#define MODULE_PAX_REFCOUNT ""
82326+#endif
82327+
82328+#ifdef CONSTIFY_PLUGIN
82329+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82330+#else
82331+#define MODULE_CONSTIFY_PLUGIN ""
82332+#endif
82333+
82334+#ifdef STACKLEAK_PLUGIN
82335+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82336+#else
82337+#define MODULE_STACKLEAK_PLUGIN ""
82338+#endif
82339+
82340+#ifdef RANDSTRUCT_PLUGIN
82341+#include <generated/randomize_layout_hash.h>
82342+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82343+#else
82344+#define MODULE_RANDSTRUCT_PLUGIN
82345+#endif
82346+
82347+#ifdef CONFIG_GRKERNSEC
82348+#define MODULE_GRSEC "GRSEC "
82349+#else
82350+#define MODULE_GRSEC ""
82351+#endif
82352+
82353 #define VERMAGIC_STRING \
82354 UTS_RELEASE " " \
82355 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82356 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82357- MODULE_ARCH_VERMAGIC
82358+ MODULE_ARCH_VERMAGIC \
82359+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82360+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82361
82362diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82363index 502073a..a7de024 100644
82364--- a/include/linux/vga_switcheroo.h
82365+++ b/include/linux/vga_switcheroo.h
82366@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82367
82368 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82369
82370-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82371-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82372+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82373+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82374 #else
82375
82376 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82377@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82378
82379 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82380
82381-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82382-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82383+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82384+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82385
82386 #endif
82387 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82388diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82389index 4b8a891..cb8df6e 100644
82390--- a/include/linux/vmalloc.h
82391+++ b/include/linux/vmalloc.h
82392@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82393 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82394 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82395 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82396+
82397+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82398+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82399+#endif
82400+
82401 /* bits [20..32] reserved for arch specific ioremap internals */
82402
82403 /*
82404@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82405
82406 /* for /dev/kmem */
82407 extern long vread(char *buf, char *addr, unsigned long count);
82408-extern long vwrite(char *buf, char *addr, unsigned long count);
82409+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82410
82411 /*
82412 * Internals. Dont't use..
82413diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82414index a67b384..f52a537 100644
82415--- a/include/linux/vmstat.h
82416+++ b/include/linux/vmstat.h
82417@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82418 /*
82419 * Zone based page accounting with per cpu differentials.
82420 */
82421-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82422+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82423
82424 static inline void zone_page_state_add(long x, struct zone *zone,
82425 enum zone_stat_item item)
82426 {
82427- atomic_long_add(x, &zone->vm_stat[item]);
82428- atomic_long_add(x, &vm_stat[item]);
82429+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82430+ atomic_long_add_unchecked(x, &vm_stat[item]);
82431 }
82432
82433-static inline unsigned long global_page_state(enum zone_stat_item item)
82434+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82435 {
82436- long x = atomic_long_read(&vm_stat[item]);
82437+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82438 #ifdef CONFIG_SMP
82439 if (x < 0)
82440 x = 0;
82441@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82442 return x;
82443 }
82444
82445-static inline unsigned long zone_page_state(struct zone *zone,
82446+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82447 enum zone_stat_item item)
82448 {
82449- long x = atomic_long_read(&zone->vm_stat[item]);
82450+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82451 #ifdef CONFIG_SMP
82452 if (x < 0)
82453 x = 0;
82454@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82455 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82456 enum zone_stat_item item)
82457 {
82458- long x = atomic_long_read(&zone->vm_stat[item]);
82459+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82460
82461 #ifdef CONFIG_SMP
82462 int cpu;
82463@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82464
82465 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82466 {
82467- atomic_long_inc(&zone->vm_stat[item]);
82468- atomic_long_inc(&vm_stat[item]);
82469+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
82470+ atomic_long_inc_unchecked(&vm_stat[item]);
82471 }
82472
82473 static inline void __inc_zone_page_state(struct page *page,
82474@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82475
82476 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82477 {
82478- atomic_long_dec(&zone->vm_stat[item]);
82479- atomic_long_dec(&vm_stat[item]);
82480+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
82481+ atomic_long_dec_unchecked(&vm_stat[item]);
82482 }
82483
82484 static inline void __dec_zone_page_state(struct page *page,
82485diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82486index 91b0a68..0e9adf6 100644
82487--- a/include/linux/xattr.h
82488+++ b/include/linux/xattr.h
82489@@ -28,7 +28,7 @@ struct xattr_handler {
82490 size_t size, int handler_flags);
82491 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82492 size_t size, int flags, int handler_flags);
82493-};
82494+} __do_const;
82495
82496 struct xattr {
82497 const char *name;
82498@@ -37,6 +37,9 @@ struct xattr {
82499 };
82500
82501 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82502+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82503+ssize_t pax_getxattr(struct dentry *, void *, size_t);
82504+#endif
82505 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82506 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82507 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82508diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82509index 9c5a6b4..09c9438 100644
82510--- a/include/linux/zlib.h
82511+++ b/include/linux/zlib.h
82512@@ -31,6 +31,7 @@
82513 #define _ZLIB_H
82514
82515 #include <linux/zconf.h>
82516+#include <linux/compiler.h>
82517
82518 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82519 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82520@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82521
82522 /* basic functions */
82523
82524-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82525+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82526 /*
82527 Returns the number of bytes that needs to be allocated for a per-
82528 stream workspace with the specified parameters. A pointer to this
82529diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82530index c768c9f..bdcaa5a 100644
82531--- a/include/media/v4l2-dev.h
82532+++ b/include/media/v4l2-dev.h
82533@@ -76,7 +76,7 @@ struct v4l2_file_operations {
82534 int (*mmap) (struct file *, struct vm_area_struct *);
82535 int (*open) (struct file *);
82536 int (*release) (struct file *);
82537-};
82538+} __do_const;
82539
82540 /*
82541 * Newer version of video_device, handled by videodev2.c
82542diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82543index c9b1593..a572459 100644
82544--- a/include/media/v4l2-device.h
82545+++ b/include/media/v4l2-device.h
82546@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82547 this function returns 0. If the name ends with a digit (e.g. cx18),
82548 then the name will be set to cx18-0 since cx180 looks really odd. */
82549 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82550- atomic_t *instance);
82551+ atomic_unchecked_t *instance);
82552
82553 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82554 Since the parent disappears this ensures that v4l2_dev doesn't have an
82555diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82556index 9a36d92..0aafe2a 100644
82557--- a/include/net/9p/transport.h
82558+++ b/include/net/9p/transport.h
82559@@ -60,7 +60,7 @@ struct p9_trans_module {
82560 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82561 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82562 char *, char *, int , int, int, int);
82563-};
82564+} __do_const;
82565
82566 void v9fs_register_trans(struct p9_trans_module *m);
82567 void v9fs_unregister_trans(struct p9_trans_module *m);
82568diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82569index c853b16d..37fccb7 100644
82570--- a/include/net/bluetooth/l2cap.h
82571+++ b/include/net/bluetooth/l2cap.h
82572@@ -557,7 +557,7 @@ struct l2cap_ops {
82573 long (*get_sndtimeo) (struct l2cap_chan *chan);
82574 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82575 unsigned long len, int nb);
82576-};
82577+} __do_const;
82578
82579 struct l2cap_conn {
82580 struct hci_conn *hcon;
82581diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82582index f2ae33d..c457cf0 100644
82583--- a/include/net/caif/cfctrl.h
82584+++ b/include/net/caif/cfctrl.h
82585@@ -52,7 +52,7 @@ struct cfctrl_rsp {
82586 void (*radioset_rsp)(void);
82587 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82588 struct cflayer *client_layer);
82589-};
82590+} __no_const;
82591
82592 /* Link Setup Parameters for CAIF-Links. */
82593 struct cfctrl_link_param {
82594@@ -101,8 +101,8 @@ struct cfctrl_request_info {
82595 struct cfctrl {
82596 struct cfsrvl serv;
82597 struct cfctrl_rsp res;
82598- atomic_t req_seq_no;
82599- atomic_t rsp_seq_no;
82600+ atomic_unchecked_t req_seq_no;
82601+ atomic_unchecked_t rsp_seq_no;
82602 struct list_head list;
82603 /* Protects from simultaneous access to first_req list */
82604 spinlock_t info_list_lock;
82605diff --git a/include/net/flow.h b/include/net/flow.h
82606index 65ce471..b7bbe9b 100644
82607--- a/include/net/flow.h
82608+++ b/include/net/flow.h
82609@@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82610
82611 void flow_cache_flush(void);
82612 void flow_cache_flush_deferred(void);
82613-extern atomic_t flow_cache_genid;
82614+extern atomic_unchecked_t flow_cache_genid;
82615
82616 #endif
82617diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82618index 1b177ed..a24a138 100644
82619--- a/include/net/genetlink.h
82620+++ b/include/net/genetlink.h
82621@@ -118,7 +118,7 @@ struct genl_ops {
82622 u8 cmd;
82623 u8 internal_flags;
82624 u8 flags;
82625-};
82626+} __do_const;
82627
82628 int __genl_register_family(struct genl_family *family);
82629
82630diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82631index 734d9b5..48a9a4b 100644
82632--- a/include/net/gro_cells.h
82633+++ b/include/net/gro_cells.h
82634@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82635 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82636
82637 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82638- atomic_long_inc(&dev->rx_dropped);
82639+ atomic_long_inc_unchecked(&dev->rx_dropped);
82640 kfree_skb(skb);
82641 return;
82642 }
82643diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82644index c55aeed..b3393f4 100644
82645--- a/include/net/inet_connection_sock.h
82646+++ b/include/net/inet_connection_sock.h
82647@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82648 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82649 int (*bind_conflict)(const struct sock *sk,
82650 const struct inet_bind_bucket *tb, bool relax);
82651-};
82652+} __do_const;
82653
82654 /** inet_connection_sock - INET connection oriented sock
82655 *
82656diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82657index f4e127a..c3d5e9c 100644
82658--- a/include/net/inetpeer.h
82659+++ b/include/net/inetpeer.h
82660@@ -47,8 +47,8 @@ struct inet_peer {
82661 */
82662 union {
82663 struct {
82664- atomic_t rid; /* Frag reception counter */
82665- atomic_t ip_id_count; /* IP ID for the next packet */
82666+ atomic_unchecked_t rid; /* Frag reception counter */
82667+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82668 };
82669 struct rcu_head rcu;
82670 struct inet_peer *gc_next;
82671@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82672 /* can be called with or without local BH being disabled */
82673 static inline int inet_getid(struct inet_peer *p, int more)
82674 {
82675- int old, new;
82676+ int id;
82677 more++;
82678 inet_peer_refcheck(p);
82679- do {
82680- old = atomic_read(&p->ip_id_count);
82681- new = old + more;
82682- if (!new)
82683- new = 1;
82684- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82685- return new;
82686+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
82687+ if (!id)
82688+ id = atomic_inc_return_unchecked(&p->ip_id_count);
82689+ return id;
82690 }
82691
82692 #endif /* _NET_INETPEER_H */
82693diff --git a/include/net/ip.h b/include/net/ip.h
82694index 5a25f36..2e73203 100644
82695--- a/include/net/ip.h
82696+++ b/include/net/ip.h
82697@@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82698
82699 void inet_get_local_port_range(struct net *net, int *low, int *high);
82700
82701-extern unsigned long *sysctl_local_reserved_ports;
82702+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82703 static inline int inet_is_reserved_local_port(int port)
82704 {
82705 return test_bit(port, sysctl_local_reserved_ports);
82706diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82707index 9922093..a1755d6 100644
82708--- a/include/net/ip_fib.h
82709+++ b/include/net/ip_fib.h
82710@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82711
82712 #define FIB_RES_SADDR(net, res) \
82713 ((FIB_RES_NH(res).nh_saddr_genid == \
82714- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82715+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82716 FIB_RES_NH(res).nh_saddr : \
82717 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82718 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82719diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82720index 5679d92..2e7a690 100644
82721--- a/include/net/ip_vs.h
82722+++ b/include/net/ip_vs.h
82723@@ -558,7 +558,7 @@ struct ip_vs_conn {
82724 struct ip_vs_conn *control; /* Master control connection */
82725 atomic_t n_control; /* Number of controlled ones */
82726 struct ip_vs_dest *dest; /* real server */
82727- atomic_t in_pkts; /* incoming packet counter */
82728+ atomic_unchecked_t in_pkts; /* incoming packet counter */
82729
82730 /* packet transmitter for different forwarding methods. If it
82731 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82732@@ -705,7 +705,7 @@ struct ip_vs_dest {
82733 __be16 port; /* port number of the server */
82734 union nf_inet_addr addr; /* IP address of the server */
82735 volatile unsigned int flags; /* dest status flags */
82736- atomic_t conn_flags; /* flags to copy to conn */
82737+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
82738 atomic_t weight; /* server weight */
82739
82740 atomic_t refcnt; /* reference counter */
82741@@ -960,11 +960,11 @@ struct netns_ipvs {
82742 /* ip_vs_lblc */
82743 int sysctl_lblc_expiration;
82744 struct ctl_table_header *lblc_ctl_header;
82745- struct ctl_table *lblc_ctl_table;
82746+ ctl_table_no_const *lblc_ctl_table;
82747 /* ip_vs_lblcr */
82748 int sysctl_lblcr_expiration;
82749 struct ctl_table_header *lblcr_ctl_header;
82750- struct ctl_table *lblcr_ctl_table;
82751+ ctl_table_no_const *lblcr_ctl_table;
82752 /* ip_vs_est */
82753 struct list_head est_list; /* estimator list */
82754 spinlock_t est_lock;
82755diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82756index 0224402..dafaf94a 100644
82757--- a/include/net/irda/ircomm_tty.h
82758+++ b/include/net/irda/ircomm_tty.h
82759@@ -35,6 +35,7 @@
82760 #include <linux/termios.h>
82761 #include <linux/timer.h>
82762 #include <linux/tty.h> /* struct tty_struct */
82763+#include <asm/local.h>
82764
82765 #include <net/irda/irias_object.h>
82766 #include <net/irda/ircomm_core.h>
82767diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82768index 714cc9a..ea05f3e 100644
82769--- a/include/net/iucv/af_iucv.h
82770+++ b/include/net/iucv/af_iucv.h
82771@@ -149,7 +149,7 @@ struct iucv_skb_cb {
82772 struct iucv_sock_list {
82773 struct hlist_head head;
82774 rwlock_t lock;
82775- atomic_t autobind_name;
82776+ atomic_unchecked_t autobind_name;
82777 };
82778
82779 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82780diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82781index f3be818..bf46196 100644
82782--- a/include/net/llc_c_ac.h
82783+++ b/include/net/llc_c_ac.h
82784@@ -87,7 +87,7 @@
82785 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82786 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82787
82788-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82789+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82790
82791 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82792 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82793diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82794index 3948cf1..83b28c4 100644
82795--- a/include/net/llc_c_ev.h
82796+++ b/include/net/llc_c_ev.h
82797@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82798 return (struct llc_conn_state_ev *)skb->cb;
82799 }
82800
82801-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82802-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82803+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82804+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82805
82806 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82807 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82808diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82809index 0e79cfb..f46db31 100644
82810--- a/include/net/llc_c_st.h
82811+++ b/include/net/llc_c_st.h
82812@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82813 u8 next_state;
82814 llc_conn_ev_qfyr_t *ev_qualifiers;
82815 llc_conn_action_t *ev_actions;
82816-};
82817+} __do_const;
82818
82819 struct llc_conn_state {
82820 u8 current_state;
82821diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82822index a61b98c..aade1eb 100644
82823--- a/include/net/llc_s_ac.h
82824+++ b/include/net/llc_s_ac.h
82825@@ -23,7 +23,7 @@
82826 #define SAP_ACT_TEST_IND 9
82827
82828 /* All action functions must look like this */
82829-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82830+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82831
82832 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82833 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82834diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82835index 567c681..cd73ac0 100644
82836--- a/include/net/llc_s_st.h
82837+++ b/include/net/llc_s_st.h
82838@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82839 llc_sap_ev_t ev;
82840 u8 next_state;
82841 llc_sap_action_t *ev_actions;
82842-};
82843+} __do_const;
82844
82845 struct llc_sap_state {
82846 u8 curr_state;
82847diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82848index 7ceed99..d3ffaa2 100644
82849--- a/include/net/mac80211.h
82850+++ b/include/net/mac80211.h
82851@@ -4407,7 +4407,7 @@ struct rate_control_ops {
82852 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82853 struct dentry *dir);
82854 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82855-};
82856+} __do_const;
82857
82858 static inline int rate_supported(struct ieee80211_sta *sta,
82859 enum ieee80211_band band,
82860diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82861index 536501a..47b7982 100644
82862--- a/include/net/neighbour.h
82863+++ b/include/net/neighbour.h
82864@@ -123,7 +123,7 @@ struct neigh_ops {
82865 void (*error_report)(struct neighbour *, struct sk_buff *);
82866 int (*output)(struct neighbour *, struct sk_buff *);
82867 int (*connected_output)(struct neighbour *, struct sk_buff *);
82868-};
82869+} __do_const;
82870
82871 struct pneigh_entry {
82872 struct pneigh_entry *next;
82873@@ -163,7 +163,6 @@ struct neigh_table {
82874 void (*proxy_redo)(struct sk_buff *skb);
82875 char *id;
82876 struct neigh_parms parms;
82877- /* HACK. gc_* should follow parms without a gap! */
82878 int gc_interval;
82879 int gc_thresh1;
82880 int gc_thresh2;
82881@@ -178,7 +177,7 @@ struct neigh_table {
82882 struct neigh_statistics __percpu *stats;
82883 struct neigh_hash_table __rcu *nht;
82884 struct pneigh_entry **phash_buckets;
82885-};
82886+} __randomize_layout;
82887
82888 #define NEIGH_PRIV_ALIGN sizeof(long long)
82889 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
82890diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82891index da68c9a..c4a0720 100644
82892--- a/include/net/net_namespace.h
82893+++ b/include/net/net_namespace.h
82894@@ -124,8 +124,8 @@ struct net {
82895 struct netns_ipvs *ipvs;
82896 #endif
82897 struct sock *diag_nlsk;
82898- atomic_t fnhe_genid;
82899-};
82900+ atomic_unchecked_t fnhe_genid;
82901+} __randomize_layout;
82902
82903 /*
82904 * ifindex generation is per-net namespace, and loopback is
82905@@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82906 #define __net_init __init
82907 #define __net_exit __exit_refok
82908 #define __net_initdata __initdata
82909+#ifdef CONSTIFY_PLUGIN
82910 #define __net_initconst __initconst
82911+#else
82912+#define __net_initconst __initdata
82913+#endif
82914 #endif
82915
82916 struct pernet_operations {
82917@@ -291,7 +295,7 @@ struct pernet_operations {
82918 void (*exit_batch)(struct list_head *net_exit_list);
82919 int *id;
82920 size_t size;
82921-};
82922+} __do_const;
82923
82924 /*
82925 * Use these carefully. If you implement a network device and it
82926@@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82927
82928 static inline int rt_genid_ipv4(struct net *net)
82929 {
82930- return atomic_read(&net->ipv4.rt_genid);
82931+ return atomic_read_unchecked(&net->ipv4.rt_genid);
82932 }
82933
82934 static inline void rt_genid_bump_ipv4(struct net *net)
82935 {
82936- atomic_inc(&net->ipv4.rt_genid);
82937+ atomic_inc_unchecked(&net->ipv4.rt_genid);
82938 }
82939
82940 #if IS_ENABLED(CONFIG_IPV6)
82941 static inline int rt_genid_ipv6(struct net *net)
82942 {
82943- return atomic_read(&net->ipv6.rt_genid);
82944+ return atomic_read_unchecked(&net->ipv6.rt_genid);
82945 }
82946
82947 static inline void rt_genid_bump_ipv6(struct net *net)
82948 {
82949- atomic_inc(&net->ipv6.rt_genid);
82950+ atomic_inc_unchecked(&net->ipv6.rt_genid);
82951 }
82952 #else
82953 static inline int rt_genid_ipv6(struct net *net)
82954@@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
82955
82956 static inline int fnhe_genid(struct net *net)
82957 {
82958- return atomic_read(&net->fnhe_genid);
82959+ return atomic_read_unchecked(&net->fnhe_genid);
82960 }
82961
82962 static inline void fnhe_genid_bump(struct net *net)
82963 {
82964- atomic_inc(&net->fnhe_genid);
82965+ atomic_inc_unchecked(&net->fnhe_genid);
82966 }
82967
82968 #endif /* __NET_NET_NAMESPACE_H */
82969diff --git a/include/net/netdma.h b/include/net/netdma.h
82970index 8ba8ce2..99b7fff 100644
82971--- a/include/net/netdma.h
82972+++ b/include/net/netdma.h
82973@@ -24,7 +24,7 @@
82974 #include <linux/dmaengine.h>
82975 #include <linux/skbuff.h>
82976
82977-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82978+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82979 struct sk_buff *skb, int offset, struct iovec *to,
82980 size_t len, struct dma_pinned_list *pinned_list);
82981
82982diff --git a/include/net/netlink.h b/include/net/netlink.h
82983index 2b47eaa..6d5bcc2 100644
82984--- a/include/net/netlink.h
82985+++ b/include/net/netlink.h
82986@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82987 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82988 {
82989 if (mark)
82990- skb_trim(skb, (unsigned char *) mark - skb->data);
82991+ skb_trim(skb, (const unsigned char *) mark - skb->data);
82992 }
82993
82994 /**
82995diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82996index c9c0c53..53f24c3 100644
82997--- a/include/net/netns/conntrack.h
82998+++ b/include/net/netns/conntrack.h
82999@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
83000 struct nf_proto_net {
83001 #ifdef CONFIG_SYSCTL
83002 struct ctl_table_header *ctl_table_header;
83003- struct ctl_table *ctl_table;
83004+ ctl_table_no_const *ctl_table;
83005 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83006 struct ctl_table_header *ctl_compat_header;
83007- struct ctl_table *ctl_compat_table;
83008+ ctl_table_no_const *ctl_compat_table;
83009 #endif
83010 #endif
83011 unsigned int users;
83012@@ -58,7 +58,7 @@ struct nf_ip_net {
83013 struct nf_icmp_net icmpv6;
83014 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83015 struct ctl_table_header *ctl_table_header;
83016- struct ctl_table *ctl_table;
83017+ ctl_table_no_const *ctl_table;
83018 #endif
83019 };
83020
83021diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83022index ee520cb..9a0fd88 100644
83023--- a/include/net/netns/ipv4.h
83024+++ b/include/net/netns/ipv4.h
83025@@ -72,7 +72,7 @@ struct netns_ipv4 {
83026
83027 kgid_t sysctl_ping_group_range[2];
83028
83029- atomic_t dev_addr_genid;
83030+ atomic_unchecked_t dev_addr_genid;
83031
83032 #ifdef CONFIG_IP_MROUTE
83033 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83034@@ -82,6 +82,6 @@ struct netns_ipv4 {
83035 struct fib_rules_ops *mr_rules_ops;
83036 #endif
83037 #endif
83038- atomic_t rt_genid;
83039+ atomic_unchecked_t rt_genid;
83040 };
83041 #endif
83042diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83043index 0fb2401..477d81c 100644
83044--- a/include/net/netns/ipv6.h
83045+++ b/include/net/netns/ipv6.h
83046@@ -71,8 +71,8 @@ struct netns_ipv6 {
83047 struct fib_rules_ops *mr6_rules_ops;
83048 #endif
83049 #endif
83050- atomic_t dev_addr_genid;
83051- atomic_t rt_genid;
83052+ atomic_unchecked_t dev_addr_genid;
83053+ atomic_unchecked_t rt_genid;
83054 };
83055
83056 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83057diff --git a/include/net/ping.h b/include/net/ping.h
83058index 90f4841..74446a8 100644
83059--- a/include/net/ping.h
83060+++ b/include/net/ping.h
83061@@ -56,7 +56,7 @@ struct ping_iter_state {
83062 extern struct proto ping_prot;
83063 extern struct ping_table ping_table;
83064 #if IS_ENABLED(CONFIG_IPV6)
83065-extern struct pingv6_ops pingv6_ops;
83066+extern struct pingv6_ops *pingv6_ops;
83067 #endif
83068
83069 struct pingfakehdr {
83070diff --git a/include/net/protocol.h b/include/net/protocol.h
83071index fbf7676..a5e21c3 100644
83072--- a/include/net/protocol.h
83073+++ b/include/net/protocol.h
83074@@ -44,7 +44,7 @@ struct net_protocol {
83075 void (*err_handler)(struct sk_buff *skb, u32 info);
83076 unsigned int no_policy:1,
83077 netns_ok:1;
83078-};
83079+} __do_const;
83080
83081 #if IS_ENABLED(CONFIG_IPV6)
83082 struct inet6_protocol {
83083@@ -57,7 +57,7 @@ struct inet6_protocol {
83084 u8 type, u8 code, int offset,
83085 __be32 info);
83086 unsigned int flags; /* INET6_PROTO_xxx */
83087-};
83088+} __do_const;
83089
83090 #define INET6_PROTO_NOPOLICY 0x1
83091 #define INET6_PROTO_FINAL 0x2
83092diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83093index bb13a18..e734116 100644
83094--- a/include/net/rtnetlink.h
83095+++ b/include/net/rtnetlink.h
83096@@ -79,7 +79,7 @@ struct rtnl_link_ops {
83097 const struct net_device *dev);
83098 unsigned int (*get_num_tx_queues)(void);
83099 unsigned int (*get_num_rx_queues)(void);
83100-};
83101+} __do_const;
83102
83103 int __rtnl_link_register(struct rtnl_link_ops *ops);
83104 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83105diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83106index 6bd44fe..96f364e 100644
83107--- a/include/net/sctp/checksum.h
83108+++ b/include/net/sctp/checksum.h
83109@@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83110 unsigned int offset)
83111 {
83112 struct sctphdr *sh = sctp_hdr(skb);
83113- __le32 ret, old = sh->checksum;
83114- const struct skb_checksum_ops ops = {
83115+ __le32 ret, old = sh->checksum;
83116+ static const struct skb_checksum_ops ops = {
83117 .update = sctp_csum_update,
83118 .combine = sctp_csum_combine,
83119 };
83120diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83121index 4ef75af..5aa073a 100644
83122--- a/include/net/sctp/sm.h
83123+++ b/include/net/sctp/sm.h
83124@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83125 typedef struct {
83126 sctp_state_fn_t *fn;
83127 const char *name;
83128-} sctp_sm_table_entry_t;
83129+} __do_const sctp_sm_table_entry_t;
83130
83131 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83132 * currently in use.
83133@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83134 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83135
83136 /* Extern declarations for major data structures. */
83137-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83138+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83139
83140
83141 /* Get the size of a DATA chunk payload. */
83142diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83143index 0a248b3..4dcbe5c 100644
83144--- a/include/net/sctp/structs.h
83145+++ b/include/net/sctp/structs.h
83146@@ -508,7 +508,7 @@ struct sctp_pf {
83147 struct sctp_association *asoc);
83148 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83149 struct sctp_af *af;
83150-};
83151+} __do_const;
83152
83153
83154 /* Structure to track chunk fragments that have been acked, but peer
83155diff --git a/include/net/sock.h b/include/net/sock.h
83156index 2ef3c3e..e02013e 100644
83157--- a/include/net/sock.h
83158+++ b/include/net/sock.h
83159@@ -348,7 +348,7 @@ struct sock {
83160 unsigned int sk_napi_id;
83161 unsigned int sk_ll_usec;
83162 #endif
83163- atomic_t sk_drops;
83164+ atomic_unchecked_t sk_drops;
83165 int sk_rcvbuf;
83166
83167 struct sk_filter __rcu *sk_filter;
83168@@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83169 return ret >> PAGE_SHIFT;
83170 }
83171
83172-static inline long
83173+static inline long __intentional_overflow(-1)
83174 sk_memory_allocated(const struct sock *sk)
83175 {
83176 struct proto *prot = sk->sk_prot;
83177@@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
83178 }
83179
83180 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
83181- char __user *from, char *to,
83182+ char __user *from, unsigned char *to,
83183 int copy, int offset)
83184 {
83185 if (skb->ip_summed == CHECKSUM_NONE) {
83186@@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
83187 }
83188 }
83189
83190-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83191+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
83192
83193 /**
83194 * sk_page_frag - return an appropriate page_frag
83195diff --git a/include/net/tcp.h b/include/net/tcp.h
83196index 9250d62..10a7f03 100644
83197--- a/include/net/tcp.h
83198+++ b/include/net/tcp.h
83199@@ -480,20 +480,21 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
83200 #ifdef CONFIG_SYN_COOKIES
83201 #include <linux/ktime.h>
83202
83203-/* Syncookies use a monotonic timer which increments every 64 seconds.
83204+/* Syncookies use a monotonic timer which increments every 60 seconds.
83205 * This counter is used both as a hash input and partially encoded into
83206 * the cookie value. A cookie is only validated further if the delta
83207 * between the current counter value and the encoded one is less than this,
83208- * i.e. a sent cookie is valid only at most for 128 seconds (or less if
83209+ * i.e. a sent cookie is valid only at most for 2*60 seconds (or less if
83210 * the counter advances immediately after a cookie is generated).
83211 */
83212 #define MAX_SYNCOOKIE_AGE 2
83213
83214 static inline u32 tcp_cookie_time(void)
83215 {
83216- struct timespec now;
83217- getnstimeofday(&now);
83218- return now.tv_sec >> 6; /* 64 seconds granularity */
83219+ u64 val = get_jiffies_64();
83220+
83221+ do_div(val, 60 * HZ);
83222+ return val;
83223 }
83224
83225 u32 __cookie_v4_init_sequence(const struct iphdr *iph, const struct tcphdr *th,
83226@@ -540,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83227 void tcp_xmit_retransmit_queue(struct sock *);
83228 void tcp_simple_retransmit(struct sock *);
83229 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83230-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83231+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83232
83233 void tcp_send_probe0(struct sock *);
83234 void tcp_send_partial(struct sock *);
83235@@ -711,8 +712,8 @@ struct tcp_skb_cb {
83236 struct inet6_skb_parm h6;
83237 #endif
83238 } header; /* For incoming frames */
83239- __u32 seq; /* Starting sequence number */
83240- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83241+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83242+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83243 __u32 when; /* used to compute rtt's */
83244 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83245
83246@@ -726,7 +727,7 @@ struct tcp_skb_cb {
83247
83248 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83249 /* 1 byte hole */
83250- __u32 ack_seq; /* Sequence number ACK'd */
83251+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83252 };
83253
83254 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83255diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83256index 6b82fdf..14d74d2 100644
83257--- a/include/net/xfrm.h
83258+++ b/include/net/xfrm.h
83259@@ -287,7 +287,6 @@ struct xfrm_dst;
83260 struct xfrm_policy_afinfo {
83261 unsigned short family;
83262 struct dst_ops *dst_ops;
83263- void (*garbage_collect)(struct net *net);
83264 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83265 const xfrm_address_t *saddr,
83266 const xfrm_address_t *daddr);
83267@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83268 struct net_device *dev,
83269 const struct flowi *fl);
83270 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83271-};
83272+} __do_const;
83273
83274 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83275 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83276@@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83277 int (*transport_finish)(struct sk_buff *skb,
83278 int async);
83279 void (*local_error)(struct sk_buff *skb, u32 mtu);
83280-};
83281+} __do_const;
83282
83283 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83284 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83285@@ -429,7 +428,7 @@ struct xfrm_mode {
83286 struct module *owner;
83287 unsigned int encap;
83288 int flags;
83289-};
83290+} __do_const;
83291
83292 /* Flags for xfrm_mode. */
83293 enum {
83294@@ -526,7 +525,7 @@ struct xfrm_policy {
83295 struct timer_list timer;
83296
83297 struct flow_cache_object flo;
83298- atomic_t genid;
83299+ atomic_unchecked_t genid;
83300 u32 priority;
83301 u32 index;
83302 struct xfrm_mark mark;
83303@@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83304 }
83305
83306 void xfrm_garbage_collect(struct net *net);
83307+void xfrm_garbage_collect_deferred(struct net *net);
83308
83309 #else
83310
83311@@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83312 static inline void xfrm_garbage_collect(struct net *net)
83313 {
83314 }
83315+static inline void xfrm_garbage_collect_deferred(struct net *net)
83316+{
83317+}
83318 #endif
83319
83320 static __inline__
83321diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83322index 1017e0b..227aa4d 100644
83323--- a/include/rdma/iw_cm.h
83324+++ b/include/rdma/iw_cm.h
83325@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83326 int backlog);
83327
83328 int (*destroy_listen)(struct iw_cm_id *cm_id);
83329-};
83330+} __no_const;
83331
83332 /**
83333 * iw_create_cm_id - Create an IW CM identifier.
83334diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83335index 52beadf..598734c 100644
83336--- a/include/scsi/libfc.h
83337+++ b/include/scsi/libfc.h
83338@@ -771,6 +771,7 @@ struct libfc_function_template {
83339 */
83340 void (*disc_stop_final) (struct fc_lport *);
83341 };
83342+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83343
83344 /**
83345 * struct fc_disc - Discovery context
83346@@ -875,7 +876,7 @@ struct fc_lport {
83347 struct fc_vport *vport;
83348
83349 /* Operational Information */
83350- struct libfc_function_template tt;
83351+ libfc_function_template_no_const tt;
83352 u8 link_up;
83353 u8 qfull;
83354 enum fc_lport_state state;
83355diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83356index d65fbec..f80fef2 100644
83357--- a/include/scsi/scsi_device.h
83358+++ b/include/scsi/scsi_device.h
83359@@ -180,9 +180,9 @@ struct scsi_device {
83360 unsigned int max_device_blocked; /* what device_blocked counts down from */
83361 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83362
83363- atomic_t iorequest_cnt;
83364- atomic_t iodone_cnt;
83365- atomic_t ioerr_cnt;
83366+ atomic_unchecked_t iorequest_cnt;
83367+ atomic_unchecked_t iodone_cnt;
83368+ atomic_unchecked_t ioerr_cnt;
83369
83370 struct device sdev_gendev,
83371 sdev_dev;
83372diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83373index b797e8f..8e2c3aa 100644
83374--- a/include/scsi/scsi_transport_fc.h
83375+++ b/include/scsi/scsi_transport_fc.h
83376@@ -751,7 +751,8 @@ struct fc_function_template {
83377 unsigned long show_host_system_hostname:1;
83378
83379 unsigned long disable_target_scan:1;
83380-};
83381+} __do_const;
83382+typedef struct fc_function_template __no_const fc_function_template_no_const;
83383
83384
83385 /**
83386diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83387index ae6c3b8..fd748ac 100644
83388--- a/include/sound/compress_driver.h
83389+++ b/include/sound/compress_driver.h
83390@@ -128,7 +128,7 @@ struct snd_compr_ops {
83391 struct snd_compr_caps *caps);
83392 int (*get_codec_caps) (struct snd_compr_stream *stream,
83393 struct snd_compr_codec_caps *codec);
83394-};
83395+} __no_const;
83396
83397 /**
83398 * struct snd_compr: Compressed device
83399diff --git a/include/sound/soc.h b/include/sound/soc.h
83400index 1f741cb..8cefc08 100644
83401--- a/include/sound/soc.h
83402+++ b/include/sound/soc.h
83403@@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83404 /* probe ordering - for components with runtime dependencies */
83405 int probe_order;
83406 int remove_order;
83407-};
83408+} __do_const;
83409
83410 /* SoC platform interface */
83411 struct snd_soc_platform_driver {
83412@@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83413 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83414 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83415 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83416-};
83417+} __do_const;
83418
83419 struct snd_soc_platform {
83420 const char *name;
83421diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83422index e3569f8..6544ffd 100644
83423--- a/include/target/target_core_base.h
83424+++ b/include/target/target_core_base.h
83425@@ -687,7 +687,7 @@ struct se_device {
83426 atomic_long_t write_bytes;
83427 /* Active commands on this virtual SE device */
83428 atomic_t simple_cmds;
83429- atomic_t dev_ordered_id;
83430+ atomic_unchecked_t dev_ordered_id;
83431 atomic_t dev_ordered_sync;
83432 atomic_t dev_qf_count;
83433 int export_count;
83434diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83435new file mode 100644
83436index 0000000..fb634b7
83437--- /dev/null
83438+++ b/include/trace/events/fs.h
83439@@ -0,0 +1,53 @@
83440+#undef TRACE_SYSTEM
83441+#define TRACE_SYSTEM fs
83442+
83443+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83444+#define _TRACE_FS_H
83445+
83446+#include <linux/fs.h>
83447+#include <linux/tracepoint.h>
83448+
83449+TRACE_EVENT(do_sys_open,
83450+
83451+ TP_PROTO(const char *filename, int flags, int mode),
83452+
83453+ TP_ARGS(filename, flags, mode),
83454+
83455+ TP_STRUCT__entry(
83456+ __string( filename, filename )
83457+ __field( int, flags )
83458+ __field( int, mode )
83459+ ),
83460+
83461+ TP_fast_assign(
83462+ __assign_str(filename, filename);
83463+ __entry->flags = flags;
83464+ __entry->mode = mode;
83465+ ),
83466+
83467+ TP_printk("\"%s\" %x %o",
83468+ __get_str(filename), __entry->flags, __entry->mode)
83469+);
83470+
83471+TRACE_EVENT(open_exec,
83472+
83473+ TP_PROTO(const char *filename),
83474+
83475+ TP_ARGS(filename),
83476+
83477+ TP_STRUCT__entry(
83478+ __string( filename, filename )
83479+ ),
83480+
83481+ TP_fast_assign(
83482+ __assign_str(filename, filename);
83483+ ),
83484+
83485+ TP_printk("\"%s\"",
83486+ __get_str(filename))
83487+);
83488+
83489+#endif /* _TRACE_FS_H */
83490+
83491+/* This part must be outside protection */
83492+#include <trace/define_trace.h>
83493diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83494index 1c09820..7f5ec79 100644
83495--- a/include/trace/events/irq.h
83496+++ b/include/trace/events/irq.h
83497@@ -36,7 +36,7 @@ struct softirq_action;
83498 */
83499 TRACE_EVENT(irq_handler_entry,
83500
83501- TP_PROTO(int irq, struct irqaction *action),
83502+ TP_PROTO(int irq, const struct irqaction *action),
83503
83504 TP_ARGS(irq, action),
83505
83506@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83507 */
83508 TRACE_EVENT(irq_handler_exit,
83509
83510- TP_PROTO(int irq, struct irqaction *action, int ret),
83511+ TP_PROTO(int irq, const struct irqaction *action, int ret),
83512
83513 TP_ARGS(irq, action, ret),
83514
83515diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83516index 7caf44c..23c6f27 100644
83517--- a/include/uapi/linux/a.out.h
83518+++ b/include/uapi/linux/a.out.h
83519@@ -39,6 +39,14 @@ enum machine_type {
83520 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83521 };
83522
83523+/* Constants for the N_FLAGS field */
83524+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83525+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83526+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83527+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83528+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83529+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83530+
83531 #if !defined (N_MAGIC)
83532 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83533 #endif
83534diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83535index d876736..ccce5c0 100644
83536--- a/include/uapi/linux/byteorder/little_endian.h
83537+++ b/include/uapi/linux/byteorder/little_endian.h
83538@@ -42,51 +42,51 @@
83539
83540 static inline __le64 __cpu_to_le64p(const __u64 *p)
83541 {
83542- return (__force __le64)*p;
83543+ return (__force const __le64)*p;
83544 }
83545-static inline __u64 __le64_to_cpup(const __le64 *p)
83546+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83547 {
83548- return (__force __u64)*p;
83549+ return (__force const __u64)*p;
83550 }
83551 static inline __le32 __cpu_to_le32p(const __u32 *p)
83552 {
83553- return (__force __le32)*p;
83554+ return (__force const __le32)*p;
83555 }
83556 static inline __u32 __le32_to_cpup(const __le32 *p)
83557 {
83558- return (__force __u32)*p;
83559+ return (__force const __u32)*p;
83560 }
83561 static inline __le16 __cpu_to_le16p(const __u16 *p)
83562 {
83563- return (__force __le16)*p;
83564+ return (__force const __le16)*p;
83565 }
83566 static inline __u16 __le16_to_cpup(const __le16 *p)
83567 {
83568- return (__force __u16)*p;
83569+ return (__force const __u16)*p;
83570 }
83571 static inline __be64 __cpu_to_be64p(const __u64 *p)
83572 {
83573- return (__force __be64)__swab64p(p);
83574+ return (__force const __be64)__swab64p(p);
83575 }
83576 static inline __u64 __be64_to_cpup(const __be64 *p)
83577 {
83578- return __swab64p((__u64 *)p);
83579+ return __swab64p((const __u64 *)p);
83580 }
83581 static inline __be32 __cpu_to_be32p(const __u32 *p)
83582 {
83583- return (__force __be32)__swab32p(p);
83584+ return (__force const __be32)__swab32p(p);
83585 }
83586-static inline __u32 __be32_to_cpup(const __be32 *p)
83587+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83588 {
83589- return __swab32p((__u32 *)p);
83590+ return __swab32p((const __u32 *)p);
83591 }
83592 static inline __be16 __cpu_to_be16p(const __u16 *p)
83593 {
83594- return (__force __be16)__swab16p(p);
83595+ return (__force const __be16)__swab16p(p);
83596 }
83597 static inline __u16 __be16_to_cpup(const __be16 *p)
83598 {
83599- return __swab16p((__u16 *)p);
83600+ return __swab16p((const __u16 *)p);
83601 }
83602 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83603 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83604diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83605index ef6103b..d4e65dd 100644
83606--- a/include/uapi/linux/elf.h
83607+++ b/include/uapi/linux/elf.h
83608@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83609 #define PT_GNU_EH_FRAME 0x6474e550
83610
83611 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83612+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83613+
83614+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83615+
83616+/* Constants for the e_flags field */
83617+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83618+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83619+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83620+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83621+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83622+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83623
83624 /*
83625 * Extended Numbering
83626@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83627 #define DT_DEBUG 21
83628 #define DT_TEXTREL 22
83629 #define DT_JMPREL 23
83630+#define DT_FLAGS 30
83631+ #define DF_TEXTREL 0x00000004
83632 #define DT_ENCODING 32
83633 #define OLD_DT_LOOS 0x60000000
83634 #define DT_LOOS 0x6000000d
83635@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83636 #define PF_W 0x2
83637 #define PF_X 0x1
83638
83639+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83640+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83641+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83642+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83643+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83644+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83645+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83646+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83647+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83648+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83649+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83650+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83651+
83652 typedef struct elf32_phdr{
83653 Elf32_Word p_type;
83654 Elf32_Off p_offset;
83655@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83656 #define EI_OSABI 7
83657 #define EI_PAD 8
83658
83659+#define EI_PAX 14
83660+
83661 #define ELFMAG0 0x7f /* EI_MAG */
83662 #define ELFMAG1 'E'
83663 #define ELFMAG2 'L'
83664diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83665index aa169c4..6a2771d 100644
83666--- a/include/uapi/linux/personality.h
83667+++ b/include/uapi/linux/personality.h
83668@@ -30,6 +30,7 @@ enum {
83669 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83670 ADDR_NO_RANDOMIZE | \
83671 ADDR_COMPAT_LAYOUT | \
83672+ ADDR_LIMIT_3GB | \
83673 MMAP_PAGE_ZERO)
83674
83675 /*
83676diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83677index 7530e74..e714828 100644
83678--- a/include/uapi/linux/screen_info.h
83679+++ b/include/uapi/linux/screen_info.h
83680@@ -43,7 +43,8 @@ struct screen_info {
83681 __u16 pages; /* 0x32 */
83682 __u16 vesa_attributes; /* 0x34 */
83683 __u32 capabilities; /* 0x36 */
83684- __u8 _reserved[6]; /* 0x3a */
83685+ __u16 vesapm_size; /* 0x3a */
83686+ __u8 _reserved[4]; /* 0x3c */
83687 } __attribute__((packed));
83688
83689 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83690diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83691index 0e011eb..82681b1 100644
83692--- a/include/uapi/linux/swab.h
83693+++ b/include/uapi/linux/swab.h
83694@@ -43,7 +43,7 @@
83695 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83696 */
83697
83698-static inline __attribute_const__ __u16 __fswab16(__u16 val)
83699+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83700 {
83701 #ifdef __HAVE_BUILTIN_BSWAP16__
83702 return __builtin_bswap16(val);
83703@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83704 #endif
83705 }
83706
83707-static inline __attribute_const__ __u32 __fswab32(__u32 val)
83708+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83709 {
83710 #ifdef __HAVE_BUILTIN_BSWAP32__
83711 return __builtin_bswap32(val);
83712@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83713 #endif
83714 }
83715
83716-static inline __attribute_const__ __u64 __fswab64(__u64 val)
83717+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83718 {
83719 #ifdef __HAVE_BUILTIN_BSWAP64__
83720 return __builtin_bswap64(val);
83721diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83722index 6d67213..552fdd9 100644
83723--- a/include/uapi/linux/sysctl.h
83724+++ b/include/uapi/linux/sysctl.h
83725@@ -155,8 +155,6 @@ enum
83726 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83727 };
83728
83729-
83730-
83731 /* CTL_VM names: */
83732 enum
83733 {
83734diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83735index 437f1b0..0eeb38d 100644
83736--- a/include/uapi/linux/videodev2.h
83737+++ b/include/uapi/linux/videodev2.h
83738@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83739 union {
83740 __s32 value;
83741 __s64 value64;
83742- char *string;
83743+ char __user *string;
83744 };
83745 } __attribute__ ((packed));
83746
83747diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83748index e4629b9..6958086 100644
83749--- a/include/uapi/linux/xattr.h
83750+++ b/include/uapi/linux/xattr.h
83751@@ -63,5 +63,9 @@
83752 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83753 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83754
83755+/* User namespace */
83756+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83757+#define XATTR_PAX_FLAGS_SUFFIX "flags"
83758+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83759
83760 #endif /* _UAPI_LINUX_XATTR_H */
83761diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83762index f9466fa..f4e2b81 100644
83763--- a/include/video/udlfb.h
83764+++ b/include/video/udlfb.h
83765@@ -53,10 +53,10 @@ struct dlfb_data {
83766 u32 pseudo_palette[256];
83767 int blank_mode; /*one of FB_BLANK_ */
83768 /* blit-only rendering path metrics, exposed through sysfs */
83769- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83770- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83771- atomic_t bytes_sent; /* to usb, after compression including overhead */
83772- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83773+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83774+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83775+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83776+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83777 };
83778
83779 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83780diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83781index 30f5362..8ed8ac9 100644
83782--- a/include/video/uvesafb.h
83783+++ b/include/video/uvesafb.h
83784@@ -122,6 +122,7 @@ struct uvesafb_par {
83785 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83786 u8 pmi_setpal; /* PMI for palette changes */
83787 u16 *pmi_base; /* protected mode interface location */
83788+ u8 *pmi_code; /* protected mode code location */
83789 void *pmi_start;
83790 void *pmi_pal;
83791 u8 *vbe_state_orig; /*
83792diff --git a/init/Kconfig b/init/Kconfig
83793index 4e5d96a..93cd8a1 100644
83794--- a/init/Kconfig
83795+++ b/init/Kconfig
83796@@ -1079,6 +1079,7 @@ endif # CGROUPS
83797
83798 config CHECKPOINT_RESTORE
83799 bool "Checkpoint/restore support" if EXPERT
83800+ depends on !GRKERNSEC
83801 default n
83802 help
83803 Enables additional kernel features in a sake of checkpoint/restore.
83804@@ -1550,7 +1551,7 @@ config SLUB_DEBUG
83805
83806 config COMPAT_BRK
83807 bool "Disable heap randomization"
83808- default y
83809+ default n
83810 help
83811 Randomizing heap placement makes heap exploits harder, but it
83812 also breaks ancient binaries (including anything libc5 based).
83813@@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
83814 config STOP_MACHINE
83815 bool
83816 default y
83817- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83818+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83819 help
83820 Need stop_machine() primitive.
83821
83822diff --git a/init/Makefile b/init/Makefile
83823index 7bc47ee..6da2dc7 100644
83824--- a/init/Makefile
83825+++ b/init/Makefile
83826@@ -2,6 +2,9 @@
83827 # Makefile for the linux kernel.
83828 #
83829
83830+ccflags-y := $(GCC_PLUGINS_CFLAGS)
83831+asflags-y := $(GCC_PLUGINS_AFLAGS)
83832+
83833 obj-y := main.o version.o mounts.o
83834 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83835 obj-y += noinitramfs.o
83836diff --git a/init/do_mounts.c b/init/do_mounts.c
83837index 8e5addc..c96ea61 100644
83838--- a/init/do_mounts.c
83839+++ b/init/do_mounts.c
83840@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83841 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83842 {
83843 struct super_block *s;
83844- int err = sys_mount(name, "/root", fs, flags, data);
83845+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83846 if (err)
83847 return err;
83848
83849- sys_chdir("/root");
83850+ sys_chdir((const char __force_user *)"/root");
83851 s = current->fs->pwd.dentry->d_sb;
83852 ROOT_DEV = s->s_dev;
83853 printk(KERN_INFO
83854@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83855 va_start(args, fmt);
83856 vsprintf(buf, fmt, args);
83857 va_end(args);
83858- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83859+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83860 if (fd >= 0) {
83861 sys_ioctl(fd, FDEJECT, 0);
83862 sys_close(fd);
83863 }
83864 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83865- fd = sys_open("/dev/console", O_RDWR, 0);
83866+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83867 if (fd >= 0) {
83868 sys_ioctl(fd, TCGETS, (long)&termios);
83869 termios.c_lflag &= ~ICANON;
83870 sys_ioctl(fd, TCSETSF, (long)&termios);
83871- sys_read(fd, &c, 1);
83872+ sys_read(fd, (char __user *)&c, 1);
83873 termios.c_lflag |= ICANON;
83874 sys_ioctl(fd, TCSETSF, (long)&termios);
83875 sys_close(fd);
83876@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83877 mount_root();
83878 out:
83879 devtmpfs_mount("dev");
83880- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83881- sys_chroot(".");
83882+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83883+ sys_chroot((const char __force_user *)".");
83884 }
83885
83886 static bool is_tmpfs;
83887diff --git a/init/do_mounts.h b/init/do_mounts.h
83888index f5b978a..69dbfe8 100644
83889--- a/init/do_mounts.h
83890+++ b/init/do_mounts.h
83891@@ -15,15 +15,15 @@ extern int root_mountflags;
83892
83893 static inline int create_dev(char *name, dev_t dev)
83894 {
83895- sys_unlink(name);
83896- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83897+ sys_unlink((char __force_user *)name);
83898+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83899 }
83900
83901 #if BITS_PER_LONG == 32
83902 static inline u32 bstat(char *name)
83903 {
83904 struct stat64 stat;
83905- if (sys_stat64(name, &stat) != 0)
83906+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83907 return 0;
83908 if (!S_ISBLK(stat.st_mode))
83909 return 0;
83910@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83911 static inline u32 bstat(char *name)
83912 {
83913 struct stat stat;
83914- if (sys_newstat(name, &stat) != 0)
83915+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83916 return 0;
83917 if (!S_ISBLK(stat.st_mode))
83918 return 0;
83919diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83920index 3e0878e..8a9d7a0 100644
83921--- a/init/do_mounts_initrd.c
83922+++ b/init/do_mounts_initrd.c
83923@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83924 {
83925 sys_unshare(CLONE_FS | CLONE_FILES);
83926 /* stdin/stdout/stderr for /linuxrc */
83927- sys_open("/dev/console", O_RDWR, 0);
83928+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83929 sys_dup(0);
83930 sys_dup(0);
83931 /* move initrd over / and chdir/chroot in initrd root */
83932- sys_chdir("/root");
83933- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83934- sys_chroot(".");
83935+ sys_chdir((const char __force_user *)"/root");
83936+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83937+ sys_chroot((const char __force_user *)".");
83938 sys_setsid();
83939 return 0;
83940 }
83941@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83942 create_dev("/dev/root.old", Root_RAM0);
83943 /* mount initrd on rootfs' /root */
83944 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83945- sys_mkdir("/old", 0700);
83946- sys_chdir("/old");
83947+ sys_mkdir((const char __force_user *)"/old", 0700);
83948+ sys_chdir((const char __force_user *)"/old");
83949
83950 /* try loading default modules from initrd */
83951 load_default_modules();
83952@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83953 current->flags &= ~PF_FREEZER_SKIP;
83954
83955 /* move initrd to rootfs' /old */
83956- sys_mount("..", ".", NULL, MS_MOVE, NULL);
83957+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83958 /* switch root and cwd back to / of rootfs */
83959- sys_chroot("..");
83960+ sys_chroot((const char __force_user *)"..");
83961
83962 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83963- sys_chdir("/old");
83964+ sys_chdir((const char __force_user *)"/old");
83965 return;
83966 }
83967
83968- sys_chdir("/");
83969+ sys_chdir((const char __force_user *)"/");
83970 ROOT_DEV = new_decode_dev(real_root_dev);
83971 mount_root();
83972
83973 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83974- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83975+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83976 if (!error)
83977 printk("okay\n");
83978 else {
83979- int fd = sys_open("/dev/root.old", O_RDWR, 0);
83980+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83981 if (error == -ENOENT)
83982 printk("/initrd does not exist. Ignored.\n");
83983 else
83984 printk("failed\n");
83985 printk(KERN_NOTICE "Unmounting old root\n");
83986- sys_umount("/old", MNT_DETACH);
83987+ sys_umount((char __force_user *)"/old", MNT_DETACH);
83988 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83989 if (fd < 0) {
83990 error = fd;
83991@@ -127,11 +127,11 @@ int __init initrd_load(void)
83992 * mounted in the normal path.
83993 */
83994 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83995- sys_unlink("/initrd.image");
83996+ sys_unlink((const char __force_user *)"/initrd.image");
83997 handle_initrd();
83998 return 1;
83999 }
84000 }
84001- sys_unlink("/initrd.image");
84002+ sys_unlink((const char __force_user *)"/initrd.image");
84003 return 0;
84004 }
84005diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84006index 8cb6db5..d729f50 100644
84007--- a/init/do_mounts_md.c
84008+++ b/init/do_mounts_md.c
84009@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84010 partitioned ? "_d" : "", minor,
84011 md_setup_args[ent].device_names);
84012
84013- fd = sys_open(name, 0, 0);
84014+ fd = sys_open((char __force_user *)name, 0, 0);
84015 if (fd < 0) {
84016 printk(KERN_ERR "md: open failed - cannot start "
84017 "array %s\n", name);
84018@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84019 * array without it
84020 */
84021 sys_close(fd);
84022- fd = sys_open(name, 0, 0);
84023+ fd = sys_open((char __force_user *)name, 0, 0);
84024 sys_ioctl(fd, BLKRRPART, 0);
84025 }
84026 sys_close(fd);
84027@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84028
84029 wait_for_device_probe();
84030
84031- fd = sys_open("/dev/md0", 0, 0);
84032+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84033 if (fd >= 0) {
84034 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84035 sys_close(fd);
84036diff --git a/init/init_task.c b/init/init_task.c
84037index ba0a7f36..2bcf1d5 100644
84038--- a/init/init_task.c
84039+++ b/init/init_task.c
84040@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84041 * Initial thread structure. Alignment of this is handled by a special
84042 * linker map entry.
84043 */
84044+#ifdef CONFIG_X86
84045+union thread_union init_thread_union __init_task_data;
84046+#else
84047 union thread_union init_thread_union __init_task_data =
84048 { INIT_THREAD_INFO(init_task) };
84049+#endif
84050diff --git a/init/initramfs.c b/init/initramfs.c
84051index a67ef9d..2d17ed9 100644
84052--- a/init/initramfs.c
84053+++ b/init/initramfs.c
84054@@ -84,7 +84,7 @@ static void __init free_hash(void)
84055 }
84056 }
84057
84058-static long __init do_utime(char *filename, time_t mtime)
84059+static long __init do_utime(char __force_user *filename, time_t mtime)
84060 {
84061 struct timespec t[2];
84062
84063@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84064 struct dir_entry *de, *tmp;
84065 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84066 list_del(&de->list);
84067- do_utime(de->name, de->mtime);
84068+ do_utime((char __force_user *)de->name, de->mtime);
84069 kfree(de->name);
84070 kfree(de);
84071 }
84072@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84073 if (nlink >= 2) {
84074 char *old = find_link(major, minor, ino, mode, collected);
84075 if (old)
84076- return (sys_link(old, collected) < 0) ? -1 : 1;
84077+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84078 }
84079 return 0;
84080 }
84081@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84082 {
84083 struct stat st;
84084
84085- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84086+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84087 if (S_ISDIR(st.st_mode))
84088- sys_rmdir(path);
84089+ sys_rmdir((char __force_user *)path);
84090 else
84091- sys_unlink(path);
84092+ sys_unlink((char __force_user *)path);
84093 }
84094 }
84095
84096@@ -315,7 +315,7 @@ static int __init do_name(void)
84097 int openflags = O_WRONLY|O_CREAT;
84098 if (ml != 1)
84099 openflags |= O_TRUNC;
84100- wfd = sys_open(collected, openflags, mode);
84101+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84102
84103 if (wfd >= 0) {
84104 sys_fchown(wfd, uid, gid);
84105@@ -327,17 +327,17 @@ static int __init do_name(void)
84106 }
84107 }
84108 } else if (S_ISDIR(mode)) {
84109- sys_mkdir(collected, mode);
84110- sys_chown(collected, uid, gid);
84111- sys_chmod(collected, mode);
84112+ sys_mkdir((char __force_user *)collected, mode);
84113+ sys_chown((char __force_user *)collected, uid, gid);
84114+ sys_chmod((char __force_user *)collected, mode);
84115 dir_add(collected, mtime);
84116 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84117 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84118 if (maybe_link() == 0) {
84119- sys_mknod(collected, mode, rdev);
84120- sys_chown(collected, uid, gid);
84121- sys_chmod(collected, mode);
84122- do_utime(collected, mtime);
84123+ sys_mknod((char __force_user *)collected, mode, rdev);
84124+ sys_chown((char __force_user *)collected, uid, gid);
84125+ sys_chmod((char __force_user *)collected, mode);
84126+ do_utime((char __force_user *)collected, mtime);
84127 }
84128 }
84129 return 0;
84130@@ -346,15 +346,15 @@ static int __init do_name(void)
84131 static int __init do_copy(void)
84132 {
84133 if (count >= body_len) {
84134- sys_write(wfd, victim, body_len);
84135+ sys_write(wfd, (char __force_user *)victim, body_len);
84136 sys_close(wfd);
84137- do_utime(vcollected, mtime);
84138+ do_utime((char __force_user *)vcollected, mtime);
84139 kfree(vcollected);
84140 eat(body_len);
84141 state = SkipIt;
84142 return 0;
84143 } else {
84144- sys_write(wfd, victim, count);
84145+ sys_write(wfd, (char __force_user *)victim, count);
84146 body_len -= count;
84147 eat(count);
84148 return 1;
84149@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84150 {
84151 collected[N_ALIGN(name_len) + body_len] = '\0';
84152 clean_path(collected, 0);
84153- sys_symlink(collected + N_ALIGN(name_len), collected);
84154- sys_lchown(collected, uid, gid);
84155- do_utime(collected, mtime);
84156+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84157+ sys_lchown((char __force_user *)collected, uid, gid);
84158+ do_utime((char __force_user *)collected, mtime);
84159 state = SkipIt;
84160 next_state = Reset;
84161 return 0;
84162@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
84163 {
84164 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
84165 if (err)
84166- panic(err); /* Failed to decompress INTERNAL initramfs */
84167+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
84168 if (initrd_start) {
84169 #ifdef CONFIG_BLK_DEV_RAM
84170 int fd;
84171diff --git a/init/main.c b/init/main.c
84172index febc511..f0851763 100644
84173--- a/init/main.c
84174+++ b/init/main.c
84175@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
84176 extern void tc_init(void);
84177 #endif
84178
84179+extern void grsecurity_init(void);
84180+
84181 /*
84182 * Debug helper: via this flag we know that we are in 'early bootup code'
84183 * where only the boot processor is running with IRQ disabled. This means
84184@@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
84185
84186 __setup("reset_devices", set_reset_devices);
84187
84188+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84189+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84190+static int __init setup_grsec_proc_gid(char *str)
84191+{
84192+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84193+ return 1;
84194+}
84195+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84196+#endif
84197+
84198+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84199+unsigned long pax_user_shadow_base __read_only;
84200+EXPORT_SYMBOL(pax_user_shadow_base);
84201+extern char pax_enter_kernel_user[];
84202+extern char pax_exit_kernel_user[];
84203+#endif
84204+
84205+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84206+static int __init setup_pax_nouderef(char *str)
84207+{
84208+#ifdef CONFIG_X86_32
84209+ unsigned int cpu;
84210+ struct desc_struct *gdt;
84211+
84212+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84213+ gdt = get_cpu_gdt_table(cpu);
84214+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84215+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84216+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84217+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84218+ }
84219+ loadsegment(ds, __KERNEL_DS);
84220+ loadsegment(es, __KERNEL_DS);
84221+ loadsegment(ss, __KERNEL_DS);
84222+#else
84223+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84224+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84225+ clone_pgd_mask = ~(pgdval_t)0UL;
84226+ pax_user_shadow_base = 0UL;
84227+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84228+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84229+#endif
84230+
84231+ return 0;
84232+}
84233+early_param("pax_nouderef", setup_pax_nouderef);
84234+
84235+#ifdef CONFIG_X86_64
84236+static int __init setup_pax_weakuderef(char *str)
84237+{
84238+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84239+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84240+ return 1;
84241+}
84242+__setup("pax_weakuderef", setup_pax_weakuderef);
84243+#endif
84244+#endif
84245+
84246+#ifdef CONFIG_PAX_SOFTMODE
84247+int pax_softmode;
84248+
84249+static int __init setup_pax_softmode(char *str)
84250+{
84251+ get_option(&str, &pax_softmode);
84252+ return 1;
84253+}
84254+__setup("pax_softmode=", setup_pax_softmode);
84255+#endif
84256+
84257 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84258 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84259 static const char *panic_later, *panic_param;
84260@@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84261 {
84262 int count = preempt_count();
84263 int ret;
84264- char msgbuf[64];
84265+ const char *msg1 = "", *msg2 = "";
84266
84267 if (initcall_debug)
84268 ret = do_one_initcall_debug(fn);
84269 else
84270 ret = fn();
84271
84272- msgbuf[0] = 0;
84273-
84274 if (preempt_count() != count) {
84275- sprintf(msgbuf, "preemption imbalance ");
84276+ msg1 = " preemption imbalance";
84277 preempt_count_set(count);
84278 }
84279 if (irqs_disabled()) {
84280- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84281+ msg2 = " disabled interrupts";
84282 local_irq_enable();
84283 }
84284- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84285+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84286
84287+ add_latent_entropy();
84288 return ret;
84289 }
84290
84291@@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84292 {
84293 argv_init[0] = init_filename;
84294 return do_execve(init_filename,
84295- (const char __user *const __user *)argv_init,
84296- (const char __user *const __user *)envp_init);
84297+ (const char __user *const __force_user *)argv_init,
84298+ (const char __user *const __force_user *)envp_init);
84299 }
84300
84301 static int try_to_run_init_process(const char *init_filename)
84302@@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84303 return ret;
84304 }
84305
84306+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84307+extern int gr_init_ran;
84308+#endif
84309+
84310 static noinline void __init kernel_init_freeable(void);
84311
84312 static int __ref kernel_init(void *unused)
84313@@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84314 ramdisk_execute_command, ret);
84315 }
84316
84317+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84318+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84319+ gr_init_ran = 1;
84320+#endif
84321+
84322 /*
84323 * We try each of these until one succeeds.
84324 *
84325@@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84326 do_basic_setup();
84327
84328 /* Open the /dev/console on the rootfs, this should never fail */
84329- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84330+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84331 pr_err("Warning: unable to open an initial console.\n");
84332
84333 (void) sys_dup(0);
84334@@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84335 if (!ramdisk_execute_command)
84336 ramdisk_execute_command = "/init";
84337
84338- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84339+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84340 ramdisk_execute_command = NULL;
84341 prepare_namespace();
84342 }
84343
84344+ grsecurity_init();
84345+
84346 /*
84347 * Ok, we have completed the initial bootup, and
84348 * we're essentially up and running. Get rid of the
84349diff --git a/ipc/compat.c b/ipc/compat.c
84350index 892f658..e7c6320 100644
84351--- a/ipc/compat.c
84352+++ b/ipc/compat.c
84353@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84354 COMPAT_SHMLBA);
84355 if (err < 0)
84356 return err;
84357- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84358+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84359 }
84360 case SHMDT:
84361 return sys_shmdt(compat_ptr(ptr));
84362diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84363index b0e99de..09f385c 100644
84364--- a/ipc/ipc_sysctl.c
84365+++ b/ipc/ipc_sysctl.c
84366@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84367 static int proc_ipc_dointvec(ctl_table *table, int write,
84368 void __user *buffer, size_t *lenp, loff_t *ppos)
84369 {
84370- struct ctl_table ipc_table;
84371+ ctl_table_no_const ipc_table;
84372
84373 memcpy(&ipc_table, table, sizeof(ipc_table));
84374 ipc_table.data = get_ipc(table);
84375@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84376 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84377 void __user *buffer, size_t *lenp, loff_t *ppos)
84378 {
84379- struct ctl_table ipc_table;
84380+ ctl_table_no_const ipc_table;
84381
84382 memcpy(&ipc_table, table, sizeof(ipc_table));
84383 ipc_table.data = get_ipc(table);
84384@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84385 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84386 void __user *buffer, size_t *lenp, loff_t *ppos)
84387 {
84388- struct ctl_table ipc_table;
84389+ ctl_table_no_const ipc_table;
84390 size_t lenp_bef = *lenp;
84391 int rc;
84392
84393@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84394 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
84395 void __user *buffer, size_t *lenp, loff_t *ppos)
84396 {
84397- struct ctl_table ipc_table;
84398+ ctl_table_no_const ipc_table;
84399 memcpy(&ipc_table, table, sizeof(ipc_table));
84400 ipc_table.data = get_ipc(table);
84401
84402@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84403 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
84404 void __user *buffer, size_t *lenp, loff_t *ppos)
84405 {
84406- struct ctl_table ipc_table;
84407+ ctl_table_no_const ipc_table;
84408 size_t lenp_bef = *lenp;
84409 int oldval;
84410 int rc;
84411diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84412index 5bb8bfe..a38ec05 100644
84413--- a/ipc/mq_sysctl.c
84414+++ b/ipc/mq_sysctl.c
84415@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84416 static int proc_mq_dointvec(ctl_table *table, int write,
84417 void __user *buffer, size_t *lenp, loff_t *ppos)
84418 {
84419- struct ctl_table mq_table;
84420+ ctl_table_no_const mq_table;
84421 memcpy(&mq_table, table, sizeof(mq_table));
84422 mq_table.data = get_mq(table);
84423
84424@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84425 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84426 void __user *buffer, size_t *lenp, loff_t *ppos)
84427 {
84428- struct ctl_table mq_table;
84429+ ctl_table_no_const mq_table;
84430 memcpy(&mq_table, table, sizeof(mq_table));
84431 mq_table.data = get_mq(table);
84432
84433diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84434index b8d4aed..96a4fe8 100644
84435--- a/ipc/mqueue.c
84436+++ b/ipc/mqueue.c
84437@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84438 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84439 info->attr.mq_msgsize);
84440
84441+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84442 spin_lock(&mq_lock);
84443 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84444 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84445diff --git a/ipc/msg.c b/ipc/msg.c
84446index 52770bf..1c60a6f 100644
84447--- a/ipc/msg.c
84448+++ b/ipc/msg.c
84449@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84450 return security_msg_queue_associate(msq, msgflg);
84451 }
84452
84453+static struct ipc_ops msg_ops = {
84454+ .getnew = newque,
84455+ .associate = msg_security,
84456+ .more_checks = NULL
84457+};
84458+
84459 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84460 {
84461 struct ipc_namespace *ns;
84462- struct ipc_ops msg_ops;
84463 struct ipc_params msg_params;
84464
84465 ns = current->nsproxy->ipc_ns;
84466
84467- msg_ops.getnew = newque;
84468- msg_ops.associate = msg_security;
84469- msg_ops.more_checks = NULL;
84470-
84471 msg_params.key = key;
84472 msg_params.flg = msgflg;
84473
84474diff --git a/ipc/sem.c b/ipc/sem.c
84475index db9d241..bc8427c 100644
84476--- a/ipc/sem.c
84477+++ b/ipc/sem.c
84478@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84479 return 0;
84480 }
84481
84482+static struct ipc_ops sem_ops = {
84483+ .getnew = newary,
84484+ .associate = sem_security,
84485+ .more_checks = sem_more_checks
84486+};
84487+
84488 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84489 {
84490 struct ipc_namespace *ns;
84491- struct ipc_ops sem_ops;
84492 struct ipc_params sem_params;
84493
84494 ns = current->nsproxy->ipc_ns;
84495@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84496 if (nsems < 0 || nsems > ns->sc_semmsl)
84497 return -EINVAL;
84498
84499- sem_ops.getnew = newary;
84500- sem_ops.associate = sem_security;
84501- sem_ops.more_checks = sem_more_checks;
84502-
84503 sem_params.key = key;
84504 sem_params.flg = semflg;
84505 sem_params.u.nsems = nsems;
84506diff --git a/ipc/shm.c b/ipc/shm.c
84507index 7a51443..3a257d8 100644
84508--- a/ipc/shm.c
84509+++ b/ipc/shm.c
84510@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84511 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84512 #endif
84513
84514+#ifdef CONFIG_GRKERNSEC
84515+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84516+ const time_t shm_createtime, const kuid_t cuid,
84517+ const int shmid);
84518+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84519+ const time_t shm_createtime);
84520+#endif
84521+
84522 void shm_init_ns(struct ipc_namespace *ns)
84523 {
84524 ns->shm_ctlmax = SHMMAX;
84525@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84526 shp->shm_lprid = 0;
84527 shp->shm_atim = shp->shm_dtim = 0;
84528 shp->shm_ctim = get_seconds();
84529+#ifdef CONFIG_GRKERNSEC
84530+ {
84531+ struct timespec timeval;
84532+ do_posix_clock_monotonic_gettime(&timeval);
84533+
84534+ shp->shm_createtime = timeval.tv_sec;
84535+ }
84536+#endif
84537 shp->shm_segsz = size;
84538 shp->shm_nattch = 0;
84539 shp->shm_file = file;
84540@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84541 return 0;
84542 }
84543
84544+static struct ipc_ops shm_ops = {
84545+ .getnew = newseg,
84546+ .associate = shm_security,
84547+ .more_checks = shm_more_checks
84548+};
84549+
84550 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84551 {
84552 struct ipc_namespace *ns;
84553- struct ipc_ops shm_ops;
84554 struct ipc_params shm_params;
84555
84556 ns = current->nsproxy->ipc_ns;
84557
84558- shm_ops.getnew = newseg;
84559- shm_ops.associate = shm_security;
84560- shm_ops.more_checks = shm_more_checks;
84561-
84562 shm_params.key = key;
84563 shm_params.flg = shmflg;
84564 shm_params.u.size = size;
84565@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84566 f_mode = FMODE_READ | FMODE_WRITE;
84567 }
84568 if (shmflg & SHM_EXEC) {
84569+
84570+#ifdef CONFIG_PAX_MPROTECT
84571+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
84572+ goto out;
84573+#endif
84574+
84575 prot |= PROT_EXEC;
84576 acc_mode |= S_IXUGO;
84577 }
84578@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84579 if (err)
84580 goto out_unlock;
84581
84582+#ifdef CONFIG_GRKERNSEC
84583+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84584+ shp->shm_perm.cuid, shmid) ||
84585+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84586+ err = -EACCES;
84587+ goto out_unlock;
84588+ }
84589+#endif
84590+
84591 ipc_lock_object(&shp->shm_perm);
84592
84593 /* check if shm_destroy() is tearing down shp */
84594@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84595 path = shp->shm_file->f_path;
84596 path_get(&path);
84597 shp->shm_nattch++;
84598+#ifdef CONFIG_GRKERNSEC
84599+ shp->shm_lapid = current->pid;
84600+#endif
84601 size = i_size_read(path.dentry->d_inode);
84602 ipc_unlock_object(&shp->shm_perm);
84603 rcu_read_unlock();
84604diff --git a/ipc/util.c b/ipc/util.c
84605index 3ae17a4..d67c32f 100644
84606--- a/ipc/util.c
84607+++ b/ipc/util.c
84608@@ -71,6 +71,8 @@ struct ipc_proc_iface {
84609 int (*show)(struct seq_file *, void *);
84610 };
84611
84612+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84613+
84614 static void ipc_memory_notifier(struct work_struct *work)
84615 {
84616 ipcns_notify(IPCNS_MEMCHANGED);
84617@@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84618 granted_mode >>= 6;
84619 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84620 granted_mode >>= 3;
84621+
84622+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84623+ return -1;
84624+
84625 /* is there some bit set in requested_mode but not in granted_mode? */
84626 if ((requested_mode & ~granted_mode & 0007) &&
84627 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84628diff --git a/kernel/acct.c b/kernel/acct.c
84629index 8d6e145..33e0b1e 100644
84630--- a/kernel/acct.c
84631+++ b/kernel/acct.c
84632@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84633 */
84634 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84635 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84636- file->f_op->write(file, (char *)&ac,
84637+ file->f_op->write(file, (char __force_user *)&ac,
84638 sizeof(acct_t), &file->f_pos);
84639 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84640 set_fs(fs);
84641diff --git a/kernel/audit.c b/kernel/audit.c
84642index 15ec13a..986322e 100644
84643--- a/kernel/audit.c
84644+++ b/kernel/audit.c
84645@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84646 3) suppressed due to audit_rate_limit
84647 4) suppressed due to audit_backlog_limit
84648 */
84649-static atomic_t audit_lost = ATOMIC_INIT(0);
84650+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84651
84652 /* The netlink socket. */
84653 static struct sock *audit_sock;
84654@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84655 unsigned long now;
84656 int print;
84657
84658- atomic_inc(&audit_lost);
84659+ atomic_inc_unchecked(&audit_lost);
84660
84661 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84662
84663@@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84664 printk(KERN_WARNING
84665 "audit: audit_lost=%d audit_rate_limit=%d "
84666 "audit_backlog_limit=%d\n",
84667- atomic_read(&audit_lost),
84668+ atomic_read_unchecked(&audit_lost),
84669 audit_rate_limit,
84670 audit_backlog_limit);
84671 audit_panic(message);
84672@@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84673 status_set.pid = audit_pid;
84674 status_set.rate_limit = audit_rate_limit;
84675 status_set.backlog_limit = audit_backlog_limit;
84676- status_set.lost = atomic_read(&audit_lost);
84677+ status_set.lost = atomic_read_unchecked(&audit_lost);
84678 status_set.backlog = skb_queue_len(&audit_skb_queue);
84679 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84680 &status_set, sizeof(status_set));
84681@@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84682 int i, avail, new_len;
84683 unsigned char *ptr;
84684 struct sk_buff *skb;
84685- static const unsigned char *hex = "0123456789ABCDEF";
84686+ static const unsigned char hex[] = "0123456789ABCDEF";
84687
84688 if (!ab)
84689 return;
84690diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84691index ff32843..27fc708 100644
84692--- a/kernel/auditsc.c
84693+++ b/kernel/auditsc.c
84694@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84695 }
84696
84697 /* global counter which is incremented every time something logs in */
84698-static atomic_t session_id = ATOMIC_INIT(0);
84699+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84700
84701 static int audit_set_loginuid_perm(kuid_t loginuid)
84702 {
84703@@ -2011,7 +2011,7 @@ int audit_set_loginuid(kuid_t loginuid)
84704
84705 /* are we setting or clearing? */
84706 if (uid_valid(loginuid))
84707- sessionid = atomic_inc_return(&session_id);
84708+ sessionid = atomic_inc_return_unchecked(&session_id);
84709
84710 task->sessionid = sessionid;
84711 task->loginuid = loginuid;
84712diff --git a/kernel/capability.c b/kernel/capability.c
84713index 4e66bf9..cdccecf 100644
84714--- a/kernel/capability.c
84715+++ b/kernel/capability.c
84716@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84717 * before modification is attempted and the application
84718 * fails.
84719 */
84720+ if (tocopy > ARRAY_SIZE(kdata))
84721+ return -EFAULT;
84722+
84723 if (copy_to_user(dataptr, kdata, tocopy
84724 * sizeof(struct __user_cap_data_struct))) {
84725 return -EFAULT;
84726@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84727 int ret;
84728
84729 rcu_read_lock();
84730- ret = security_capable(__task_cred(t), ns, cap);
84731+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84732+ gr_task_is_capable(t, __task_cred(t), cap);
84733 rcu_read_unlock();
84734
84735- return (ret == 0);
84736+ return ret;
84737 }
84738
84739 /**
84740@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84741 int ret;
84742
84743 rcu_read_lock();
84744- ret = security_capable_noaudit(__task_cred(t), ns, cap);
84745+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84746 rcu_read_unlock();
84747
84748- return (ret == 0);
84749+ return ret;
84750 }
84751
84752 /**
84753@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84754 BUG();
84755 }
84756
84757- if (security_capable(current_cred(), ns, cap) == 0) {
84758+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84759 current->flags |= PF_SUPERPRIV;
84760 return true;
84761 }
84762@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84763 }
84764 EXPORT_SYMBOL(ns_capable);
84765
84766+bool ns_capable_nolog(struct user_namespace *ns, int cap)
84767+{
84768+ if (unlikely(!cap_valid(cap))) {
84769+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84770+ BUG();
84771+ }
84772+
84773+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84774+ current->flags |= PF_SUPERPRIV;
84775+ return true;
84776+ }
84777+ return false;
84778+}
84779+EXPORT_SYMBOL(ns_capable_nolog);
84780+
84781 /**
84782 * file_ns_capable - Determine if the file's opener had a capability in effect
84783 * @file: The file we want to check
84784@@ -432,6 +451,12 @@ bool capable(int cap)
84785 }
84786 EXPORT_SYMBOL(capable);
84787
84788+bool capable_nolog(int cap)
84789+{
84790+ return ns_capable_nolog(&init_user_ns, cap);
84791+}
84792+EXPORT_SYMBOL(capable_nolog);
84793+
84794 /**
84795 * inode_capable - Check superior capability over inode
84796 * @inode: The inode in question
84797@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84798 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84799 }
84800 EXPORT_SYMBOL(inode_capable);
84801+
84802+bool inode_capable_nolog(const struct inode *inode, int cap)
84803+{
84804+ struct user_namespace *ns = current_user_ns();
84805+
84806+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84807+}
84808+EXPORT_SYMBOL(inode_capable_nolog);
84809diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84810index 271acd8..54b70fe 100644
84811--- a/kernel/cgroup.c
84812+++ b/kernel/cgroup.c
84813@@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
84814 struct css_set *cset = link->cset;
84815 struct task_struct *task;
84816 int count = 0;
84817- seq_printf(seq, "css_set %p\n", cset);
84818+ seq_printf(seq, "css_set %pK\n", cset);
84819 list_for_each_entry(task, &cset->tasks, cg_list) {
84820 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84821 seq_puts(seq, " ...\n");
84822diff --git a/kernel/compat.c b/kernel/compat.c
84823index 0a09e48..b46b3d78 100644
84824--- a/kernel/compat.c
84825+++ b/kernel/compat.c
84826@@ -13,6 +13,7 @@
84827
84828 #include <linux/linkage.h>
84829 #include <linux/compat.h>
84830+#include <linux/module.h>
84831 #include <linux/errno.h>
84832 #include <linux/time.h>
84833 #include <linux/signal.h>
84834@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84835 mm_segment_t oldfs;
84836 long ret;
84837
84838- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84839+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84840 oldfs = get_fs();
84841 set_fs(KERNEL_DS);
84842 ret = hrtimer_nanosleep_restart(restart);
84843@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84844 oldfs = get_fs();
84845 set_fs(KERNEL_DS);
84846 ret = hrtimer_nanosleep(&tu,
84847- rmtp ? (struct timespec __user *)&rmt : NULL,
84848+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
84849 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84850 set_fs(oldfs);
84851
84852@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84853 mm_segment_t old_fs = get_fs();
84854
84855 set_fs(KERNEL_DS);
84856- ret = sys_sigpending((old_sigset_t __user *) &s);
84857+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
84858 set_fs(old_fs);
84859 if (ret == 0)
84860 ret = put_user(s, set);
84861@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84862 mm_segment_t old_fs = get_fs();
84863
84864 set_fs(KERNEL_DS);
84865- ret = sys_old_getrlimit(resource, &r);
84866+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84867 set_fs(old_fs);
84868
84869 if (!ret) {
84870@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84871 set_fs (KERNEL_DS);
84872 ret = sys_wait4(pid,
84873 (stat_addr ?
84874- (unsigned int __user *) &status : NULL),
84875- options, (struct rusage __user *) &r);
84876+ (unsigned int __force_user *) &status : NULL),
84877+ options, (struct rusage __force_user *) &r);
84878 set_fs (old_fs);
84879
84880 if (ret > 0) {
84881@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84882 memset(&info, 0, sizeof(info));
84883
84884 set_fs(KERNEL_DS);
84885- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84886- uru ? (struct rusage __user *)&ru : NULL);
84887+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84888+ uru ? (struct rusage __force_user *)&ru : NULL);
84889 set_fs(old_fs);
84890
84891 if ((ret < 0) || (info.si_signo == 0))
84892@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84893 oldfs = get_fs();
84894 set_fs(KERNEL_DS);
84895 err = sys_timer_settime(timer_id, flags,
84896- (struct itimerspec __user *) &newts,
84897- (struct itimerspec __user *) &oldts);
84898+ (struct itimerspec __force_user *) &newts,
84899+ (struct itimerspec __force_user *) &oldts);
84900 set_fs(oldfs);
84901 if (!err && old && put_compat_itimerspec(old, &oldts))
84902 return -EFAULT;
84903@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84904 oldfs = get_fs();
84905 set_fs(KERNEL_DS);
84906 err = sys_timer_gettime(timer_id,
84907- (struct itimerspec __user *) &ts);
84908+ (struct itimerspec __force_user *) &ts);
84909 set_fs(oldfs);
84910 if (!err && put_compat_itimerspec(setting, &ts))
84911 return -EFAULT;
84912@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84913 oldfs = get_fs();
84914 set_fs(KERNEL_DS);
84915 err = sys_clock_settime(which_clock,
84916- (struct timespec __user *) &ts);
84917+ (struct timespec __force_user *) &ts);
84918 set_fs(oldfs);
84919 return err;
84920 }
84921@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84922 oldfs = get_fs();
84923 set_fs(KERNEL_DS);
84924 err = sys_clock_gettime(which_clock,
84925- (struct timespec __user *) &ts);
84926+ (struct timespec __force_user *) &ts);
84927 set_fs(oldfs);
84928 if (!err && put_compat_timespec(&ts, tp))
84929 return -EFAULT;
84930@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84931
84932 oldfs = get_fs();
84933 set_fs(KERNEL_DS);
84934- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84935+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84936 set_fs(oldfs);
84937
84938 err = compat_put_timex(utp, &txc);
84939@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84940 oldfs = get_fs();
84941 set_fs(KERNEL_DS);
84942 err = sys_clock_getres(which_clock,
84943- (struct timespec __user *) &ts);
84944+ (struct timespec __force_user *) &ts);
84945 set_fs(oldfs);
84946 if (!err && tp && put_compat_timespec(&ts, tp))
84947 return -EFAULT;
84948@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84949 long err;
84950 mm_segment_t oldfs;
84951 struct timespec tu;
84952- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84953+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84954
84955- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84956+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84957 oldfs = get_fs();
84958 set_fs(KERNEL_DS);
84959 err = clock_nanosleep_restart(restart);
84960@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84961 oldfs = get_fs();
84962 set_fs(KERNEL_DS);
84963 err = sys_clock_nanosleep(which_clock, flags,
84964- (struct timespec __user *) &in,
84965- (struct timespec __user *) &out);
84966+ (struct timespec __force_user *) &in,
84967+ (struct timespec __force_user *) &out);
84968 set_fs(oldfs);
84969
84970 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84971@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84972 mm_segment_t old_fs = get_fs();
84973
84974 set_fs(KERNEL_DS);
84975- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84976+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84977 set_fs(old_fs);
84978 if (put_compat_timespec(&t, interval))
84979 return -EFAULT;
84980diff --git a/kernel/configs.c b/kernel/configs.c
84981index c18b1f1..b9a0132 100644
84982--- a/kernel/configs.c
84983+++ b/kernel/configs.c
84984@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84985 struct proc_dir_entry *entry;
84986
84987 /* create the current config file */
84988+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84989+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84990+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84991+ &ikconfig_file_ops);
84992+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84993+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84994+ &ikconfig_file_ops);
84995+#endif
84996+#else
84997 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84998 &ikconfig_file_ops);
84999+#endif
85000+
85001 if (!entry)
85002 return -ENOMEM;
85003
85004diff --git a/kernel/cred.c b/kernel/cred.c
85005index e0573a4..3874e41 100644
85006--- a/kernel/cred.c
85007+++ b/kernel/cred.c
85008@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85009 validate_creds(cred);
85010 alter_cred_subscribers(cred, -1);
85011 put_cred(cred);
85012+
85013+#ifdef CONFIG_GRKERNSEC_SETXID
85014+ cred = (struct cred *) tsk->delayed_cred;
85015+ if (cred != NULL) {
85016+ tsk->delayed_cred = NULL;
85017+ validate_creds(cred);
85018+ alter_cred_subscribers(cred, -1);
85019+ put_cred(cred);
85020+ }
85021+#endif
85022 }
85023
85024 /**
85025@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85026 * Always returns 0 thus allowing this function to be tail-called at the end
85027 * of, say, sys_setgid().
85028 */
85029-int commit_creds(struct cred *new)
85030+static int __commit_creds(struct cred *new)
85031 {
85032 struct task_struct *task = current;
85033 const struct cred *old = task->real_cred;
85034@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85035
85036 get_cred(new); /* we will require a ref for the subj creds too */
85037
85038+ gr_set_role_label(task, new->uid, new->gid);
85039+
85040 /* dumpability changes */
85041 if (!uid_eq(old->euid, new->euid) ||
85042 !gid_eq(old->egid, new->egid) ||
85043@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85044 put_cred(old);
85045 return 0;
85046 }
85047+#ifdef CONFIG_GRKERNSEC_SETXID
85048+extern int set_user(struct cred *new);
85049+
85050+void gr_delayed_cred_worker(void)
85051+{
85052+ const struct cred *new = current->delayed_cred;
85053+ struct cred *ncred;
85054+
85055+ current->delayed_cred = NULL;
85056+
85057+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85058+ // from doing get_cred on it when queueing this
85059+ put_cred(new);
85060+ return;
85061+ } else if (new == NULL)
85062+ return;
85063+
85064+ ncred = prepare_creds();
85065+ if (!ncred)
85066+ goto die;
85067+ // uids
85068+ ncred->uid = new->uid;
85069+ ncred->euid = new->euid;
85070+ ncred->suid = new->suid;
85071+ ncred->fsuid = new->fsuid;
85072+ // gids
85073+ ncred->gid = new->gid;
85074+ ncred->egid = new->egid;
85075+ ncred->sgid = new->sgid;
85076+ ncred->fsgid = new->fsgid;
85077+ // groups
85078+ if (set_groups(ncred, new->group_info) < 0) {
85079+ abort_creds(ncred);
85080+ goto die;
85081+ }
85082+ // caps
85083+ ncred->securebits = new->securebits;
85084+ ncred->cap_inheritable = new->cap_inheritable;
85085+ ncred->cap_permitted = new->cap_permitted;
85086+ ncred->cap_effective = new->cap_effective;
85087+ ncred->cap_bset = new->cap_bset;
85088+
85089+ if (set_user(ncred)) {
85090+ abort_creds(ncred);
85091+ goto die;
85092+ }
85093+
85094+ // from doing get_cred on it when queueing this
85095+ put_cred(new);
85096+
85097+ __commit_creds(ncred);
85098+ return;
85099+die:
85100+ // from doing get_cred on it when queueing this
85101+ put_cred(new);
85102+ do_group_exit(SIGKILL);
85103+}
85104+#endif
85105+
85106+int commit_creds(struct cred *new)
85107+{
85108+#ifdef CONFIG_GRKERNSEC_SETXID
85109+ int ret;
85110+ int schedule_it = 0;
85111+ struct task_struct *t;
85112+
85113+ /* we won't get called with tasklist_lock held for writing
85114+ and interrupts disabled as the cred struct in that case is
85115+ init_cred
85116+ */
85117+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85118+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85119+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85120+ schedule_it = 1;
85121+ }
85122+ ret = __commit_creds(new);
85123+ if (schedule_it) {
85124+ rcu_read_lock();
85125+ read_lock(&tasklist_lock);
85126+ for (t = next_thread(current); t != current;
85127+ t = next_thread(t)) {
85128+ if (t->delayed_cred == NULL) {
85129+ t->delayed_cred = get_cred(new);
85130+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85131+ set_tsk_need_resched(t);
85132+ }
85133+ }
85134+ read_unlock(&tasklist_lock);
85135+ rcu_read_unlock();
85136+ }
85137+ return ret;
85138+#else
85139+ return __commit_creds(new);
85140+#endif
85141+}
85142+
85143 EXPORT_SYMBOL(commit_creds);
85144
85145 /**
85146diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85147index 7d2f35e..1bafcd0 100644
85148--- a/kernel/debug/debug_core.c
85149+++ b/kernel/debug/debug_core.c
85150@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85151 */
85152 static atomic_t masters_in_kgdb;
85153 static atomic_t slaves_in_kgdb;
85154-static atomic_t kgdb_break_tasklet_var;
85155+static atomic_unchecked_t kgdb_break_tasklet_var;
85156 atomic_t kgdb_setting_breakpoint;
85157
85158 struct task_struct *kgdb_usethread;
85159@@ -133,7 +133,7 @@ int kgdb_single_step;
85160 static pid_t kgdb_sstep_pid;
85161
85162 /* to keep track of the CPU which is doing the single stepping*/
85163-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85164+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85165
85166 /*
85167 * If you are debugging a problem where roundup (the collection of
85168@@ -541,7 +541,7 @@ return_normal:
85169 * kernel will only try for the value of sstep_tries before
85170 * giving up and continuing on.
85171 */
85172- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85173+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85174 (kgdb_info[cpu].task &&
85175 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85176 atomic_set(&kgdb_active, -1);
85177@@ -639,8 +639,8 @@ cpu_master_loop:
85178 }
85179
85180 kgdb_restore:
85181- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85182- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85183+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85184+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85185 if (kgdb_info[sstep_cpu].task)
85186 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85187 else
85188@@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
85189 static void kgdb_tasklet_bpt(unsigned long ing)
85190 {
85191 kgdb_breakpoint();
85192- atomic_set(&kgdb_break_tasklet_var, 0);
85193+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85194 }
85195
85196 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85197
85198 void kgdb_schedule_breakpoint(void)
85199 {
85200- if (atomic_read(&kgdb_break_tasklet_var) ||
85201+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85202 atomic_read(&kgdb_active) != -1 ||
85203 atomic_read(&kgdb_setting_breakpoint))
85204 return;
85205- atomic_inc(&kgdb_break_tasklet_var);
85206+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85207 tasklet_schedule(&kgdb_tasklet_breakpoint);
85208 }
85209 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85210diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85211index 0b097c8..11dd5c5 100644
85212--- a/kernel/debug/kdb/kdb_main.c
85213+++ b/kernel/debug/kdb/kdb_main.c
85214@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85215 continue;
85216
85217 kdb_printf("%-20s%8u 0x%p ", mod->name,
85218- mod->core_size, (void *)mod);
85219+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85220 #ifdef CONFIG_MODULE_UNLOAD
85221 kdb_printf("%4ld ", module_refcount(mod));
85222 #endif
85223@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85224 kdb_printf(" (Loading)");
85225 else
85226 kdb_printf(" (Live)");
85227- kdb_printf(" 0x%p", mod->module_core);
85228+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85229
85230 #ifdef CONFIG_MODULE_UNLOAD
85231 {
85232diff --git a/kernel/events/core.c b/kernel/events/core.c
85233index 6ed1163..f36346e 100644
85234--- a/kernel/events/core.c
85235+++ b/kernel/events/core.c
85236@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85237 * 0 - disallow raw tracepoint access for unpriv
85238 * 1 - disallow cpu events for unpriv
85239 * 2 - disallow kernel profiling for unpriv
85240+ * 3 - disallow all unpriv perf event use
85241 */
85242-int sysctl_perf_event_paranoid __read_mostly = 1;
85243+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85244+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85245+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85246+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85247+#else
85248+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85249+#endif
85250
85251 /* Minimum for 512 kiB + 1 user control page */
85252 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85253@@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85254
85255 tmp *= sysctl_perf_cpu_time_max_percent;
85256 do_div(tmp, 100);
85257- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85258+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85259 }
85260
85261 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85262@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85263 update_perf_cpu_limits();
85264 }
85265
85266-static atomic64_t perf_event_id;
85267+static atomic64_unchecked_t perf_event_id;
85268
85269 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85270 enum event_type_t event_type);
85271@@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85272
85273 static inline u64 perf_event_count(struct perf_event *event)
85274 {
85275- return local64_read(&event->count) + atomic64_read(&event->child_count);
85276+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85277 }
85278
85279 static u64 perf_event_read(struct perf_event *event)
85280@@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85281 mutex_lock(&event->child_mutex);
85282 total += perf_event_read(event);
85283 *enabled += event->total_time_enabled +
85284- atomic64_read(&event->child_total_time_enabled);
85285+ atomic64_read_unchecked(&event->child_total_time_enabled);
85286 *running += event->total_time_running +
85287- atomic64_read(&event->child_total_time_running);
85288+ atomic64_read_unchecked(&event->child_total_time_running);
85289
85290 list_for_each_entry(child, &event->child_list, child_list) {
85291 total += perf_event_read(child);
85292@@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85293 userpg->offset -= local64_read(&event->hw.prev_count);
85294
85295 userpg->time_enabled = enabled +
85296- atomic64_read(&event->child_total_time_enabled);
85297+ atomic64_read_unchecked(&event->child_total_time_enabled);
85298
85299 userpg->time_running = running +
85300- atomic64_read(&event->child_total_time_running);
85301+ atomic64_read_unchecked(&event->child_total_time_running);
85302
85303 arch_perf_update_userpage(userpg, now);
85304
85305@@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85306
85307 /* Data. */
85308 sp = perf_user_stack_pointer(regs);
85309- rem = __output_copy_user(handle, (void *) sp, dump_size);
85310+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85311 dyn_size = dump_size - rem;
85312
85313 perf_output_skip(handle, rem);
85314@@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85315 values[n++] = perf_event_count(event);
85316 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85317 values[n++] = enabled +
85318- atomic64_read(&event->child_total_time_enabled);
85319+ atomic64_read_unchecked(&event->child_total_time_enabled);
85320 }
85321 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85322 values[n++] = running +
85323- atomic64_read(&event->child_total_time_running);
85324+ atomic64_read_unchecked(&event->child_total_time_running);
85325 }
85326 if (read_format & PERF_FORMAT_ID)
85327 values[n++] = primary_event_id(event);
85328@@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85329 event->parent = parent_event;
85330
85331 event->ns = get_pid_ns(task_active_pid_ns(current));
85332- event->id = atomic64_inc_return(&perf_event_id);
85333+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85334
85335 event->state = PERF_EVENT_STATE_INACTIVE;
85336
85337@@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85338 if (flags & ~PERF_FLAG_ALL)
85339 return -EINVAL;
85340
85341+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85342+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85343+ return -EACCES;
85344+#endif
85345+
85346 err = perf_copy_attr(attr_uptr, &attr);
85347 if (err)
85348 return err;
85349@@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85350 /*
85351 * Add back the child's count to the parent's count:
85352 */
85353- atomic64_add(child_val, &parent_event->child_count);
85354- atomic64_add(child_event->total_time_enabled,
85355+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85356+ atomic64_add_unchecked(child_event->total_time_enabled,
85357 &parent_event->child_total_time_enabled);
85358- atomic64_add(child_event->total_time_running,
85359+ atomic64_add_unchecked(child_event->total_time_running,
85360 &parent_event->child_total_time_running);
85361
85362 /*
85363diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85364index 569b2187..19940d9 100644
85365--- a/kernel/events/internal.h
85366+++ b/kernel/events/internal.h
85367@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85368 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85369 }
85370
85371-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85372+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85373 static inline unsigned long \
85374 func_name(struct perf_output_handle *handle, \
85375- const void *buf, unsigned long len) \
85376+ const void user *buf, unsigned long len) \
85377 { \
85378 unsigned long size, written; \
85379 \
85380@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85381 return 0;
85382 }
85383
85384-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85385+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85386
85387 static inline unsigned long
85388 memcpy_skip(void *dst, const void *src, unsigned long n)
85389@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85390 return 0;
85391 }
85392
85393-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85394+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85395
85396 #ifndef arch_perf_out_copy_user
85397 #define arch_perf_out_copy_user arch_perf_out_copy_user
85398@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85399 }
85400 #endif
85401
85402-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85403+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85404
85405 /* Callchain handling */
85406 extern struct perf_callchain_entry *
85407diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85408index 24b7d6c..40cf797 100644
85409--- a/kernel/events/uprobes.c
85410+++ b/kernel/events/uprobes.c
85411@@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85412 {
85413 struct page *page;
85414 uprobe_opcode_t opcode;
85415- int result;
85416+ long result;
85417
85418 pagefault_disable();
85419 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85420diff --git a/kernel/exit.c b/kernel/exit.c
85421index a949819..a5f127d 100644
85422--- a/kernel/exit.c
85423+++ b/kernel/exit.c
85424@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85425 struct task_struct *leader;
85426 int zap_leader;
85427 repeat:
85428+#ifdef CONFIG_NET
85429+ gr_del_task_from_ip_table(p);
85430+#endif
85431+
85432 /* don't need to get the RCU readlock here - the process is dead and
85433 * can't be modifying its own credentials. But shut RCU-lockdep up */
85434 rcu_read_lock();
85435@@ -329,7 +333,7 @@ int allow_signal(int sig)
85436 * know it'll be handled, so that they don't get converted to
85437 * SIGKILL or just silently dropped.
85438 */
85439- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85440+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85441 recalc_sigpending();
85442 spin_unlock_irq(&current->sighand->siglock);
85443 return 0;
85444@@ -698,6 +702,8 @@ void do_exit(long code)
85445 struct task_struct *tsk = current;
85446 int group_dead;
85447
85448+ set_fs(USER_DS);
85449+
85450 profile_task_exit(tsk);
85451
85452 WARN_ON(blk_needs_flush_plug(tsk));
85453@@ -714,7 +720,6 @@ void do_exit(long code)
85454 * mm_release()->clear_child_tid() from writing to a user-controlled
85455 * kernel address.
85456 */
85457- set_fs(USER_DS);
85458
85459 ptrace_event(PTRACE_EVENT_EXIT, code);
85460
85461@@ -773,6 +778,9 @@ void do_exit(long code)
85462 tsk->exit_code = code;
85463 taskstats_exit(tsk, group_dead);
85464
85465+ gr_acl_handle_psacct(tsk, code);
85466+ gr_acl_handle_exit();
85467+
85468 exit_mm(tsk);
85469
85470 if (group_dead)
85471@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85472 * Take down every thread in the group. This is called by fatal signals
85473 * as well as by sys_exit_group (below).
85474 */
85475-void
85476+__noreturn void
85477 do_group_exit(int exit_code)
85478 {
85479 struct signal_struct *sig = current->signal;
85480diff --git a/kernel/fork.c b/kernel/fork.c
85481index dfa736c..d170f9b 100644
85482--- a/kernel/fork.c
85483+++ b/kernel/fork.c
85484@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85485 *stackend = STACK_END_MAGIC; /* for overflow detection */
85486
85487 #ifdef CONFIG_CC_STACKPROTECTOR
85488- tsk->stack_canary = get_random_int();
85489+ tsk->stack_canary = pax_get_random_long();
85490 #endif
85491
85492 /*
85493@@ -345,12 +345,80 @@ free_tsk:
85494 }
85495
85496 #ifdef CONFIG_MMU
85497-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85498+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85499+{
85500+ struct vm_area_struct *tmp;
85501+ unsigned long charge;
85502+ struct file *file;
85503+ int retval;
85504+
85505+ charge = 0;
85506+ if (mpnt->vm_flags & VM_ACCOUNT) {
85507+ unsigned long len = vma_pages(mpnt);
85508+
85509+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85510+ goto fail_nomem;
85511+ charge = len;
85512+ }
85513+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85514+ if (!tmp)
85515+ goto fail_nomem;
85516+ *tmp = *mpnt;
85517+ tmp->vm_mm = mm;
85518+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
85519+ retval = vma_dup_policy(mpnt, tmp);
85520+ if (retval)
85521+ goto fail_nomem_policy;
85522+ if (anon_vma_fork(tmp, mpnt))
85523+ goto fail_nomem_anon_vma_fork;
85524+ tmp->vm_flags &= ~VM_LOCKED;
85525+ tmp->vm_next = tmp->vm_prev = NULL;
85526+ tmp->vm_mirror = NULL;
85527+ file = tmp->vm_file;
85528+ if (file) {
85529+ struct inode *inode = file_inode(file);
85530+ struct address_space *mapping = file->f_mapping;
85531+
85532+ get_file(file);
85533+ if (tmp->vm_flags & VM_DENYWRITE)
85534+ atomic_dec(&inode->i_writecount);
85535+ mutex_lock(&mapping->i_mmap_mutex);
85536+ if (tmp->vm_flags & VM_SHARED)
85537+ mapping->i_mmap_writable++;
85538+ flush_dcache_mmap_lock(mapping);
85539+ /* insert tmp into the share list, just after mpnt */
85540+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85541+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85542+ else
85543+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85544+ flush_dcache_mmap_unlock(mapping);
85545+ mutex_unlock(&mapping->i_mmap_mutex);
85546+ }
85547+
85548+ /*
85549+ * Clear hugetlb-related page reserves for children. This only
85550+ * affects MAP_PRIVATE mappings. Faults generated by the child
85551+ * are not guaranteed to succeed, even if read-only
85552+ */
85553+ if (is_vm_hugetlb_page(tmp))
85554+ reset_vma_resv_huge_pages(tmp);
85555+
85556+ return tmp;
85557+
85558+fail_nomem_anon_vma_fork:
85559+ mpol_put(vma_policy(tmp));
85560+fail_nomem_policy:
85561+ kmem_cache_free(vm_area_cachep, tmp);
85562+fail_nomem:
85563+ vm_unacct_memory(charge);
85564+ return NULL;
85565+}
85566+
85567+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85568 {
85569 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85570 struct rb_node **rb_link, *rb_parent;
85571 int retval;
85572- unsigned long charge;
85573
85574 uprobe_start_dup_mmap();
85575 down_write(&oldmm->mmap_sem);
85576@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85577
85578 prev = NULL;
85579 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85580- struct file *file;
85581-
85582 if (mpnt->vm_flags & VM_DONTCOPY) {
85583 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85584 -vma_pages(mpnt));
85585 continue;
85586 }
85587- charge = 0;
85588- if (mpnt->vm_flags & VM_ACCOUNT) {
85589- unsigned long len = vma_pages(mpnt);
85590-
85591- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85592- goto fail_nomem;
85593- charge = len;
85594- }
85595- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85596- if (!tmp)
85597- goto fail_nomem;
85598- *tmp = *mpnt;
85599- INIT_LIST_HEAD(&tmp->anon_vma_chain);
85600- retval = vma_dup_policy(mpnt, tmp);
85601- if (retval)
85602- goto fail_nomem_policy;
85603- tmp->vm_mm = mm;
85604- if (anon_vma_fork(tmp, mpnt))
85605- goto fail_nomem_anon_vma_fork;
85606- tmp->vm_flags &= ~VM_LOCKED;
85607- tmp->vm_next = tmp->vm_prev = NULL;
85608- file = tmp->vm_file;
85609- if (file) {
85610- struct inode *inode = file_inode(file);
85611- struct address_space *mapping = file->f_mapping;
85612-
85613- get_file(file);
85614- if (tmp->vm_flags & VM_DENYWRITE)
85615- atomic_dec(&inode->i_writecount);
85616- mutex_lock(&mapping->i_mmap_mutex);
85617- if (tmp->vm_flags & VM_SHARED)
85618- mapping->i_mmap_writable++;
85619- flush_dcache_mmap_lock(mapping);
85620- /* insert tmp into the share list, just after mpnt */
85621- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85622- vma_nonlinear_insert(tmp,
85623- &mapping->i_mmap_nonlinear);
85624- else
85625- vma_interval_tree_insert_after(tmp, mpnt,
85626- &mapping->i_mmap);
85627- flush_dcache_mmap_unlock(mapping);
85628- mutex_unlock(&mapping->i_mmap_mutex);
85629+ tmp = dup_vma(mm, oldmm, mpnt);
85630+ if (!tmp) {
85631+ retval = -ENOMEM;
85632+ goto out;
85633 }
85634
85635 /*
85636@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85637 if (retval)
85638 goto out;
85639 }
85640+
85641+#ifdef CONFIG_PAX_SEGMEXEC
85642+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85643+ struct vm_area_struct *mpnt_m;
85644+
85645+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85646+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85647+
85648+ if (!mpnt->vm_mirror)
85649+ continue;
85650+
85651+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85652+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85653+ mpnt->vm_mirror = mpnt_m;
85654+ } else {
85655+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85656+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85657+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85658+ mpnt->vm_mirror->vm_mirror = mpnt;
85659+ }
85660+ }
85661+ BUG_ON(mpnt_m);
85662+ }
85663+#endif
85664+
85665 /* a new mm has just been created */
85666 arch_dup_mmap(oldmm, mm);
85667 retval = 0;
85668@@ -468,14 +521,6 @@ out:
85669 up_write(&oldmm->mmap_sem);
85670 uprobe_end_dup_mmap();
85671 return retval;
85672-fail_nomem_anon_vma_fork:
85673- mpol_put(vma_policy(tmp));
85674-fail_nomem_policy:
85675- kmem_cache_free(vm_area_cachep, tmp);
85676-fail_nomem:
85677- retval = -ENOMEM;
85678- vm_unacct_memory(charge);
85679- goto out;
85680 }
85681
85682 static inline int mm_alloc_pgd(struct mm_struct *mm)
85683@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85684 return ERR_PTR(err);
85685
85686 mm = get_task_mm(task);
85687- if (mm && mm != current->mm &&
85688- !ptrace_may_access(task, mode)) {
85689+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85690+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85691 mmput(mm);
85692 mm = ERR_PTR(-EACCES);
85693 }
85694@@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85695 spin_unlock(&fs->lock);
85696 return -EAGAIN;
85697 }
85698- fs->users++;
85699+ atomic_inc(&fs->users);
85700 spin_unlock(&fs->lock);
85701 return 0;
85702 }
85703 tsk->fs = copy_fs_struct(fs);
85704 if (!tsk->fs)
85705 return -ENOMEM;
85706+ /* Carry through gr_chroot_dentry and is_chrooted instead
85707+ of recomputing it here. Already copied when the task struct
85708+ is duplicated. This allows pivot_root to not be treated as
85709+ a chroot
85710+ */
85711+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
85712+
85713 return 0;
85714 }
85715
85716@@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85717 * parts of the process environment (as per the clone
85718 * flags). The actual kick-off is left to the caller.
85719 */
85720-static struct task_struct *copy_process(unsigned long clone_flags,
85721+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85722 unsigned long stack_start,
85723 unsigned long stack_size,
85724 int __user *child_tidptr,
85725@@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85726 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85727 #endif
85728 retval = -EAGAIN;
85729+
85730+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85731+
85732 if (atomic_read(&p->real_cred->user->processes) >=
85733 task_rlimit(p, RLIMIT_NPROC)) {
85734 if (p->real_cred->user != INIT_USER &&
85735@@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85736 goto bad_fork_free_pid;
85737 }
85738
85739+ /* synchronizes with gr_set_acls()
85740+ we need to call this past the point of no return for fork()
85741+ */
85742+ gr_copy_label(p);
85743+
85744 if (likely(p->pid)) {
85745 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85746
85747@@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85748 bad_fork_free:
85749 free_task(p);
85750 fork_out:
85751+ gr_log_forkfail(retval);
85752+
85753 return ERR_PTR(retval);
85754 }
85755
85756@@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85757
85758 p = copy_process(clone_flags, stack_start, stack_size,
85759 child_tidptr, NULL, trace);
85760+ add_latent_entropy();
85761 /*
85762 * Do this prior waking up the new thread - the thread pointer
85763 * might get invalid after that point, if the thread exits quickly.
85764@@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85765 if (clone_flags & CLONE_PARENT_SETTID)
85766 put_user(nr, parent_tidptr);
85767
85768+ gr_handle_brute_check();
85769+
85770 if (clone_flags & CLONE_VFORK) {
85771 p->vfork_done = &vfork;
85772 init_completion(&vfork);
85773@@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85774 mm_cachep = kmem_cache_create("mm_struct",
85775 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85776 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85777- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85778+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85779 mmap_init();
85780 nsproxy_cache_init();
85781 }
85782@@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85783 return 0;
85784
85785 /* don't need lock here; in the worst case we'll do useless copy */
85786- if (fs->users == 1)
85787+ if (atomic_read(&fs->users) == 1)
85788 return 0;
85789
85790 *new_fsp = copy_fs_struct(fs);
85791@@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85792 fs = current->fs;
85793 spin_lock(&fs->lock);
85794 current->fs = new_fs;
85795- if (--fs->users)
85796+ gr_set_chroot_entries(current, &current->fs->root);
85797+ if (atomic_dec_return(&fs->users))
85798 new_fs = NULL;
85799 else
85800 new_fs = fs;
85801diff --git a/kernel/futex.c b/kernel/futex.c
85802index f6ff019..ac53307 100644
85803--- a/kernel/futex.c
85804+++ b/kernel/futex.c
85805@@ -54,6 +54,7 @@
85806 #include <linux/mount.h>
85807 #include <linux/pagemap.h>
85808 #include <linux/syscalls.h>
85809+#include <linux/ptrace.h>
85810 #include <linux/signal.h>
85811 #include <linux/export.h>
85812 #include <linux/magic.h>
85813@@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85814 struct page *page, *page_head;
85815 int err, ro = 0;
85816
85817+#ifdef CONFIG_PAX_SEGMEXEC
85818+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85819+ return -EFAULT;
85820+#endif
85821+
85822 /*
85823 * The futex address must be "naturally" aligned.
85824 */
85825@@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85826
85827 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85828 {
85829- int ret;
85830+ unsigned long ret;
85831
85832 pagefault_disable();
85833 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85834@@ -2735,6 +2741,7 @@ static int __init futex_init(void)
85835 {
85836 u32 curval;
85837 int i;
85838+ mm_segment_t oldfs;
85839
85840 /*
85841 * This will fail and we want it. Some arch implementations do
85842@@ -2746,8 +2753,11 @@ static int __init futex_init(void)
85843 * implementation, the non-functional ones will return
85844 * -ENOSYS.
85845 */
85846+ oldfs = get_fs();
85847+ set_fs(USER_DS);
85848 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85849 futex_cmpxchg_enabled = 1;
85850+ set_fs(oldfs);
85851
85852 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
85853 plist_head_init(&futex_queues[i].chain);
85854diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85855index f9f44fd..29885e4 100644
85856--- a/kernel/futex_compat.c
85857+++ b/kernel/futex_compat.c
85858@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85859 return 0;
85860 }
85861
85862-static void __user *futex_uaddr(struct robust_list __user *entry,
85863+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85864 compat_long_t futex_offset)
85865 {
85866 compat_uptr_t base = ptr_to_compat(entry);
85867diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85868index f45b75b..bfac6d5 100644
85869--- a/kernel/gcov/base.c
85870+++ b/kernel/gcov/base.c
85871@@ -108,11 +108,6 @@ void gcov_enable_events(void)
85872 }
85873
85874 #ifdef CONFIG_MODULES
85875-static inline int within(void *addr, void *start, unsigned long size)
85876-{
85877- return ((addr >= start) && (addr < start + size));
85878-}
85879-
85880 /* Update list and generate events when modules are unloaded. */
85881 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85882 void *data)
85883@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85884
85885 /* Remove entries located in module from linked list. */
85886 while ((info = gcov_info_next(info))) {
85887- if (within(info, mod->module_core, mod->core_size)) {
85888+ if (within_module_core_rw((unsigned long)info, mod)) {
85889 gcov_info_unlink(prev, info);
85890 if (gcov_events_enabled)
85891 gcov_event(GCOV_REMOVE, info);
85892diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85893index 383319b..56ebb13 100644
85894--- a/kernel/hrtimer.c
85895+++ b/kernel/hrtimer.c
85896@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
85897 local_irq_restore(flags);
85898 }
85899
85900-static void run_hrtimer_softirq(struct softirq_action *h)
85901+static __latent_entropy void run_hrtimer_softirq(void)
85902 {
85903 hrtimer_peek_ahead_timers();
85904 }
85905diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85906index 55fcce6..0e4cf34 100644
85907--- a/kernel/irq_work.c
85908+++ b/kernel/irq_work.c
85909@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85910 return NOTIFY_OK;
85911 }
85912
85913-static struct notifier_block cpu_notify;
85914+static struct notifier_block cpu_notify = {
85915+ .notifier_call = irq_work_cpu_notify,
85916+ .priority = 0,
85917+};
85918
85919 static __init int irq_work_init_cpu_notifier(void)
85920 {
85921- cpu_notify.notifier_call = irq_work_cpu_notify;
85922- cpu_notify.priority = 0;
85923 register_cpu_notifier(&cpu_notify);
85924 return 0;
85925 }
85926diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85927index 9019f15..9a3c42e 100644
85928--- a/kernel/jump_label.c
85929+++ b/kernel/jump_label.c
85930@@ -14,6 +14,7 @@
85931 #include <linux/err.h>
85932 #include <linux/static_key.h>
85933 #include <linux/jump_label_ratelimit.h>
85934+#include <linux/mm.h>
85935
85936 #ifdef HAVE_JUMP_LABEL
85937
85938@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85939
85940 size = (((unsigned long)stop - (unsigned long)start)
85941 / sizeof(struct jump_entry));
85942+ pax_open_kernel();
85943 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85944+ pax_close_kernel();
85945 }
85946
85947 static void jump_label_update(struct static_key *key, int enable);
85948@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85949 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85950 struct jump_entry *iter;
85951
85952+ pax_open_kernel();
85953 for (iter = iter_start; iter < iter_stop; iter++) {
85954 if (within_module_init(iter->code, mod))
85955 iter->code = 0;
85956 }
85957+ pax_close_kernel();
85958 }
85959
85960 static int
85961diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85962index 3127ad5..159d880 100644
85963--- a/kernel/kallsyms.c
85964+++ b/kernel/kallsyms.c
85965@@ -11,6 +11,9 @@
85966 * Changed the compression method from stem compression to "table lookup"
85967 * compression (see scripts/kallsyms.c for a more complete description)
85968 */
85969+#ifdef CONFIG_GRKERNSEC_HIDESYM
85970+#define __INCLUDED_BY_HIDESYM 1
85971+#endif
85972 #include <linux/kallsyms.h>
85973 #include <linux/module.h>
85974 #include <linux/init.h>
85975@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85976
85977 static inline int is_kernel_inittext(unsigned long addr)
85978 {
85979+ if (system_state != SYSTEM_BOOTING)
85980+ return 0;
85981+
85982 if (addr >= (unsigned long)_sinittext
85983 && addr <= (unsigned long)_einittext)
85984 return 1;
85985 return 0;
85986 }
85987
85988+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85989+#ifdef CONFIG_MODULES
85990+static inline int is_module_text(unsigned long addr)
85991+{
85992+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85993+ return 1;
85994+
85995+ addr = ktla_ktva(addr);
85996+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85997+}
85998+#else
85999+static inline int is_module_text(unsigned long addr)
86000+{
86001+ return 0;
86002+}
86003+#endif
86004+#endif
86005+
86006 static inline int is_kernel_text(unsigned long addr)
86007 {
86008 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86009@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
86010
86011 static inline int is_kernel(unsigned long addr)
86012 {
86013+
86014+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86015+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
86016+ return 1;
86017+
86018+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
86019+#else
86020 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
86021+#endif
86022+
86023 return 1;
86024 return in_gate_area_no_mm(addr);
86025 }
86026
86027 static int is_ksym_addr(unsigned long addr)
86028 {
86029+
86030+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86031+ if (is_module_text(addr))
86032+ return 0;
86033+#endif
86034+
86035 if (all_var)
86036 return is_kernel(addr);
86037
86038@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86039
86040 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86041 {
86042- iter->name[0] = '\0';
86043 iter->nameoff = get_symbol_offset(new_pos);
86044 iter->pos = new_pos;
86045 }
86046@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86047 {
86048 struct kallsym_iter *iter = m->private;
86049
86050+#ifdef CONFIG_GRKERNSEC_HIDESYM
86051+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86052+ return 0;
86053+#endif
86054+
86055 /* Some debugging symbols have no name. Ignore them. */
86056 if (!iter->name[0])
86057 return 0;
86058@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86059 */
86060 type = iter->exported ? toupper(iter->type) :
86061 tolower(iter->type);
86062+
86063 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86064 type, iter->name, iter->module_name);
86065 } else
86066@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86067 struct kallsym_iter *iter;
86068 int ret;
86069
86070- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86071+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86072 if (!iter)
86073 return -ENOMEM;
86074 reset_iter(iter, 0);
86075diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86076index e30ac0f..3528cac 100644
86077--- a/kernel/kcmp.c
86078+++ b/kernel/kcmp.c
86079@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86080 struct task_struct *task1, *task2;
86081 int ret;
86082
86083+#ifdef CONFIG_GRKERNSEC
86084+ return -ENOSYS;
86085+#endif
86086+
86087 rcu_read_lock();
86088
86089 /*
86090diff --git a/kernel/kexec.c b/kernel/kexec.c
86091index 9c97016..df438f8 100644
86092--- a/kernel/kexec.c
86093+++ b/kernel/kexec.c
86094@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86095 unsigned long flags)
86096 {
86097 struct compat_kexec_segment in;
86098- struct kexec_segment out, __user *ksegments;
86099+ struct kexec_segment out;
86100+ struct kexec_segment __user *ksegments;
86101 unsigned long i, result;
86102
86103 /* Don't allow clients that don't understand the native
86104diff --git a/kernel/kmod.c b/kernel/kmod.c
86105index b086006..b66f630 100644
86106--- a/kernel/kmod.c
86107+++ b/kernel/kmod.c
86108@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86109 kfree(info->argv);
86110 }
86111
86112-static int call_modprobe(char *module_name, int wait)
86113+static int call_modprobe(char *module_name, char *module_param, int wait)
86114 {
86115 struct subprocess_info *info;
86116 static char *envp[] = {
86117@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86118 NULL
86119 };
86120
86121- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86122+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86123 if (!argv)
86124 goto out;
86125
86126@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86127 argv[1] = "-q";
86128 argv[2] = "--";
86129 argv[3] = module_name; /* check free_modprobe_argv() */
86130- argv[4] = NULL;
86131+ argv[4] = module_param;
86132+ argv[5] = NULL;
86133
86134 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86135 NULL, free_modprobe_argv, NULL);
86136@@ -129,9 +130,8 @@ out:
86137 * If module auto-loading support is disabled then this function
86138 * becomes a no-operation.
86139 */
86140-int __request_module(bool wait, const char *fmt, ...)
86141+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86142 {
86143- va_list args;
86144 char module_name[MODULE_NAME_LEN];
86145 unsigned int max_modprobes;
86146 int ret;
86147@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86148 if (!modprobe_path[0])
86149 return 0;
86150
86151- va_start(args, fmt);
86152- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86153- va_end(args);
86154+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86155 if (ret >= MODULE_NAME_LEN)
86156 return -ENAMETOOLONG;
86157
86158@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86159 if (ret)
86160 return ret;
86161
86162+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86163+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86164+ /* hack to workaround consolekit/udisks stupidity */
86165+ read_lock(&tasklist_lock);
86166+ if (!strcmp(current->comm, "mount") &&
86167+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86168+ read_unlock(&tasklist_lock);
86169+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86170+ return -EPERM;
86171+ }
86172+ read_unlock(&tasklist_lock);
86173+ }
86174+#endif
86175+
86176 /* If modprobe needs a service that is in a module, we get a recursive
86177 * loop. Limit the number of running kmod threads to max_threads/2 or
86178 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86179@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86180
86181 trace_module_request(module_name, wait, _RET_IP_);
86182
86183- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86184+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86185
86186 atomic_dec(&kmod_concurrent);
86187 return ret;
86188 }
86189+
86190+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86191+{
86192+ va_list args;
86193+ int ret;
86194+
86195+ va_start(args, fmt);
86196+ ret = ____request_module(wait, module_param, fmt, args);
86197+ va_end(args);
86198+
86199+ return ret;
86200+}
86201+
86202+int __request_module(bool wait, const char *fmt, ...)
86203+{
86204+ va_list args;
86205+ int ret;
86206+
86207+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86208+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86209+ char module_param[MODULE_NAME_LEN];
86210+
86211+ memset(module_param, 0, sizeof(module_param));
86212+
86213+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86214+
86215+ va_start(args, fmt);
86216+ ret = ____request_module(wait, module_param, fmt, args);
86217+ va_end(args);
86218+
86219+ return ret;
86220+ }
86221+#endif
86222+
86223+ va_start(args, fmt);
86224+ ret = ____request_module(wait, NULL, fmt, args);
86225+ va_end(args);
86226+
86227+ return ret;
86228+}
86229+
86230 EXPORT_SYMBOL(__request_module);
86231 #endif /* CONFIG_MODULES */
86232
86233@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86234 */
86235 set_user_nice(current, 0);
86236
86237+#ifdef CONFIG_GRKERNSEC
86238+ /* this is race-free as far as userland is concerned as we copied
86239+ out the path to be used prior to this point and are now operating
86240+ on that copy
86241+ */
86242+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86243+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86244+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86245+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86246+ retval = -EPERM;
86247+ goto fail;
86248+ }
86249+#endif
86250+
86251 retval = -ENOMEM;
86252 new = prepare_kernel_cred(current);
86253 if (!new)
86254@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86255 commit_creds(new);
86256
86257 retval = do_execve(sub_info->path,
86258- (const char __user *const __user *)sub_info->argv,
86259- (const char __user *const __user *)sub_info->envp);
86260+ (const char __user *const __force_user *)sub_info->argv,
86261+ (const char __user *const __force_user *)sub_info->envp);
86262 if (!retval)
86263 return 0;
86264
86265@@ -260,6 +327,10 @@ static int call_helper(void *data)
86266
86267 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86268 {
86269+#ifdef CONFIG_GRKERNSEC
86270+ kfree(info->path);
86271+ info->path = info->origpath;
86272+#endif
86273 if (info->cleanup)
86274 (*info->cleanup)(info);
86275 kfree(info);
86276@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86277 *
86278 * Thus the __user pointer cast is valid here.
86279 */
86280- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86281+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86282
86283 /*
86284 * If ret is 0, either ____call_usermodehelper failed and the
86285@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86286 goto out;
86287
86288 INIT_WORK(&sub_info->work, __call_usermodehelper);
86289+#ifdef CONFIG_GRKERNSEC
86290+ sub_info->origpath = path;
86291+ sub_info->path = kstrdup(path, gfp_mask);
86292+#else
86293 sub_info->path = path;
86294+#endif
86295 sub_info->argv = argv;
86296 sub_info->envp = envp;
86297
86298@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86299 static int proc_cap_handler(struct ctl_table *table, int write,
86300 void __user *buffer, size_t *lenp, loff_t *ppos)
86301 {
86302- struct ctl_table t;
86303+ ctl_table_no_const t;
86304 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86305 kernel_cap_t new_cap;
86306 int err, i;
86307diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86308index ceeadfc..11c18b6 100644
86309--- a/kernel/kprobes.c
86310+++ b/kernel/kprobes.c
86311@@ -31,6 +31,9 @@
86312 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86313 * <prasanna@in.ibm.com> added function-return probes.
86314 */
86315+#ifdef CONFIG_GRKERNSEC_HIDESYM
86316+#define __INCLUDED_BY_HIDESYM 1
86317+#endif
86318 #include <linux/kprobes.h>
86319 #include <linux/hash.h>
86320 #include <linux/init.h>
86321@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86322
86323 static void *alloc_insn_page(void)
86324 {
86325- return module_alloc(PAGE_SIZE);
86326+ return module_alloc_exec(PAGE_SIZE);
86327 }
86328
86329 static void free_insn_page(void *page)
86330 {
86331- module_free(NULL, page);
86332+ module_free_exec(NULL, page);
86333 }
86334
86335 struct kprobe_insn_cache kprobe_insn_slots = {
86336@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86337 kprobe_type = "k";
86338
86339 if (sym)
86340- seq_printf(pi, "%p %s %s+0x%x %s ",
86341+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86342 p->addr, kprobe_type, sym, offset,
86343 (modname ? modname : " "));
86344 else
86345- seq_printf(pi, "%p %s %p ",
86346+ seq_printf(pi, "%pK %s %pK ",
86347 p->addr, kprobe_type, p->addr);
86348
86349 if (!pp)
86350diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86351index 9659d38..bffd520 100644
86352--- a/kernel/ksysfs.c
86353+++ b/kernel/ksysfs.c
86354@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86355 {
86356 if (count+1 > UEVENT_HELPER_PATH_LEN)
86357 return -ENOENT;
86358+ if (!capable(CAP_SYS_ADMIN))
86359+ return -EPERM;
86360 memcpy(uevent_helper, buf, count);
86361 uevent_helper[count] = '\0';
86362 if (count && uevent_helper[count-1] == '\n')
86363@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86364 return count;
86365 }
86366
86367-static struct bin_attribute notes_attr = {
86368+static bin_attribute_no_const notes_attr __read_only = {
86369 .attr = {
86370 .name = "notes",
86371 .mode = S_IRUGO,
86372diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86373index 576ba75..7c256e4 100644
86374--- a/kernel/locking/lockdep.c
86375+++ b/kernel/locking/lockdep.c
86376@@ -596,6 +596,10 @@ static int static_obj(void *obj)
86377 end = (unsigned long) &_end,
86378 addr = (unsigned long) obj;
86379
86380+#ifdef CONFIG_PAX_KERNEXEC
86381+ start = ktla_ktva(start);
86382+#endif
86383+
86384 /*
86385 * static variable?
86386 */
86387@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86388 if (!static_obj(lock->key)) {
86389 debug_locks_off();
86390 printk("INFO: trying to register non-static key.\n");
86391+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86392 printk("the code is fine but needs lockdep annotation.\n");
86393 printk("turning off the locking correctness validator.\n");
86394 dump_stack();
86395@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86396 if (!class)
86397 return 0;
86398 }
86399- atomic_inc((atomic_t *)&class->ops);
86400+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86401 if (very_verbose(class)) {
86402 printk("\nacquire class [%p] %s", class->key, class->name);
86403 if (class->name_version > 1)
86404diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86405index ef43ac4..2720dfa 100644
86406--- a/kernel/locking/lockdep_proc.c
86407+++ b/kernel/locking/lockdep_proc.c
86408@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86409 return 0;
86410 }
86411
86412- seq_printf(m, "%p", class->key);
86413+ seq_printf(m, "%pK", class->key);
86414 #ifdef CONFIG_DEBUG_LOCKDEP
86415 seq_printf(m, " OPS:%8ld", class->ops);
86416 #endif
86417@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86418
86419 list_for_each_entry(entry, &class->locks_after, entry) {
86420 if (entry->distance == 1) {
86421- seq_printf(m, " -> [%p] ", entry->class->key);
86422+ seq_printf(m, " -> [%pK] ", entry->class->key);
86423 print_name(m, entry->class);
86424 seq_puts(m, "\n");
86425 }
86426@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86427 if (!class->key)
86428 continue;
86429
86430- seq_printf(m, "[%p] ", class->key);
86431+ seq_printf(m, "[%pK] ", class->key);
86432 print_name(m, class);
86433 seq_puts(m, "\n");
86434 }
86435@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86436 if (!i)
86437 seq_line(m, '-', 40-namelen, namelen);
86438
86439- snprintf(ip, sizeof(ip), "[<%p>]",
86440+ snprintf(ip, sizeof(ip), "[<%pK>]",
86441 (void *)class->contention_point[i]);
86442 seq_printf(m, "%40s %14lu %29s %pS\n",
86443 name, stats->contention_point[i],
86444@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86445 if (!i)
86446 seq_line(m, '-', 40-namelen, namelen);
86447
86448- snprintf(ip, sizeof(ip), "[<%p>]",
86449+ snprintf(ip, sizeof(ip), "[<%pK>]",
86450 (void *)class->contending_point[i]);
86451 seq_printf(m, "%40s %14lu %29s %pS\n",
86452 name, stats->contending_point[i],
86453diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86454index 7e3443f..b2a1e6b 100644
86455--- a/kernel/locking/mutex-debug.c
86456+++ b/kernel/locking/mutex-debug.c
86457@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86458 }
86459
86460 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86461- struct thread_info *ti)
86462+ struct task_struct *task)
86463 {
86464 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86465
86466 /* Mark the current thread as blocked on the lock: */
86467- ti->task->blocked_on = waiter;
86468+ task->blocked_on = waiter;
86469 }
86470
86471 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86472- struct thread_info *ti)
86473+ struct task_struct *task)
86474 {
86475 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86476- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86477- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86478- ti->task->blocked_on = NULL;
86479+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
86480+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86481+ task->blocked_on = NULL;
86482
86483 list_del_init(&waiter->list);
86484 waiter->task = NULL;
86485diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86486index 0799fd3..d06ae3b 100644
86487--- a/kernel/locking/mutex-debug.h
86488+++ b/kernel/locking/mutex-debug.h
86489@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86490 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86491 extern void debug_mutex_add_waiter(struct mutex *lock,
86492 struct mutex_waiter *waiter,
86493- struct thread_info *ti);
86494+ struct task_struct *task);
86495 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86496- struct thread_info *ti);
86497+ struct task_struct *task);
86498 extern void debug_mutex_unlock(struct mutex *lock);
86499 extern void debug_mutex_init(struct mutex *lock, const char *name,
86500 struct lock_class_key *key);
86501diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86502index 4dd6e4c..df52693 100644
86503--- a/kernel/locking/mutex.c
86504+++ b/kernel/locking/mutex.c
86505@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86506 node->locked = 1;
86507 return;
86508 }
86509- ACCESS_ONCE(prev->next) = node;
86510+ ACCESS_ONCE_RW(prev->next) = node;
86511 smp_wmb();
86512 /* Wait until the lock holder passes the lock down */
86513 while (!ACCESS_ONCE(node->locked))
86514@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86515 while (!(next = ACCESS_ONCE(node->next)))
86516 arch_mutex_cpu_relax();
86517 }
86518- ACCESS_ONCE(next->locked) = 1;
86519+ ACCESS_ONCE_RW(next->locked) = 1;
86520 smp_wmb();
86521 }
86522
86523@@ -520,7 +520,7 @@ slowpath:
86524 goto skip_wait;
86525
86526 debug_mutex_lock_common(lock, &waiter);
86527- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86528+ debug_mutex_add_waiter(lock, &waiter, task);
86529
86530 /* add waiting tasks to the end of the waitqueue (FIFO): */
86531 list_add_tail(&waiter.list, &lock->wait_list);
86532@@ -564,7 +564,7 @@ slowpath:
86533 schedule_preempt_disabled();
86534 spin_lock_mutex(&lock->wait_lock, flags);
86535 }
86536- mutex_remove_waiter(lock, &waiter, current_thread_info());
86537+ mutex_remove_waiter(lock, &waiter, task);
86538 /* set it to 0 if there are no waiters left: */
86539 if (likely(list_empty(&lock->wait_list)))
86540 atomic_set(&lock->count, 0);
86541@@ -601,7 +601,7 @@ skip_wait:
86542 return 0;
86543
86544 err:
86545- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86546+ mutex_remove_waiter(lock, &waiter, task);
86547 spin_unlock_mutex(&lock->wait_lock, flags);
86548 debug_mutex_free_waiter(&waiter);
86549 mutex_release(&lock->dep_map, 1, ip);
86550diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86551index 1d96dd0..994ff19 100644
86552--- a/kernel/locking/rtmutex-tester.c
86553+++ b/kernel/locking/rtmutex-tester.c
86554@@ -22,7 +22,7 @@
86555 #define MAX_RT_TEST_MUTEXES 8
86556
86557 static spinlock_t rttest_lock;
86558-static atomic_t rttest_event;
86559+static atomic_unchecked_t rttest_event;
86560
86561 struct test_thread_data {
86562 int opcode;
86563@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86564
86565 case RTTEST_LOCKCONT:
86566 td->mutexes[td->opdata] = 1;
86567- td->event = atomic_add_return(1, &rttest_event);
86568+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86569 return 0;
86570
86571 case RTTEST_RESET:
86572@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86573 return 0;
86574
86575 case RTTEST_RESETEVENT:
86576- atomic_set(&rttest_event, 0);
86577+ atomic_set_unchecked(&rttest_event, 0);
86578 return 0;
86579
86580 default:
86581@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86582 return ret;
86583
86584 td->mutexes[id] = 1;
86585- td->event = atomic_add_return(1, &rttest_event);
86586+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86587 rt_mutex_lock(&mutexes[id]);
86588- td->event = atomic_add_return(1, &rttest_event);
86589+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86590 td->mutexes[id] = 4;
86591 return 0;
86592
86593@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86594 return ret;
86595
86596 td->mutexes[id] = 1;
86597- td->event = atomic_add_return(1, &rttest_event);
86598+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86599 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86600- td->event = atomic_add_return(1, &rttest_event);
86601+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86602 td->mutexes[id] = ret ? 0 : 4;
86603 return ret ? -EINTR : 0;
86604
86605@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86606 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86607 return ret;
86608
86609- td->event = atomic_add_return(1, &rttest_event);
86610+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86611 rt_mutex_unlock(&mutexes[id]);
86612- td->event = atomic_add_return(1, &rttest_event);
86613+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86614 td->mutexes[id] = 0;
86615 return 0;
86616
86617@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86618 break;
86619
86620 td->mutexes[dat] = 2;
86621- td->event = atomic_add_return(1, &rttest_event);
86622+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86623 break;
86624
86625 default:
86626@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86627 return;
86628
86629 td->mutexes[dat] = 3;
86630- td->event = atomic_add_return(1, &rttest_event);
86631+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86632 break;
86633
86634 case RTTEST_LOCKNOWAIT:
86635@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86636 return;
86637
86638 td->mutexes[dat] = 1;
86639- td->event = atomic_add_return(1, &rttest_event);
86640+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86641 return;
86642
86643 default:
86644diff --git a/kernel/module.c b/kernel/module.c
86645index f5a3b1e..97ebb15 100644
86646--- a/kernel/module.c
86647+++ b/kernel/module.c
86648@@ -61,6 +61,7 @@
86649 #include <linux/pfn.h>
86650 #include <linux/bsearch.h>
86651 #include <linux/fips.h>
86652+#include <linux/grsecurity.h>
86653 #include <uapi/linux/module.h>
86654 #include "module-internal.h"
86655
86656@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86657
86658 /* Bounds of module allocation, for speeding __module_address.
86659 * Protected by module_mutex. */
86660-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86661+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86662+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86663
86664 int register_module_notifier(struct notifier_block * nb)
86665 {
86666@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86667 return true;
86668
86669 list_for_each_entry_rcu(mod, &modules, list) {
86670- struct symsearch arr[] = {
86671+ struct symsearch modarr[] = {
86672 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86673 NOT_GPL_ONLY, false },
86674 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86675@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86676 if (mod->state == MODULE_STATE_UNFORMED)
86677 continue;
86678
86679- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86680+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86681 return true;
86682 }
86683 return false;
86684@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86685 if (!pcpusec->sh_size)
86686 return 0;
86687
86688- if (align > PAGE_SIZE) {
86689+ if (align-1 >= PAGE_SIZE) {
86690 pr_warn("%s: per-cpu alignment %li > %li\n",
86691 mod->name, align, PAGE_SIZE);
86692 align = PAGE_SIZE;
86693@@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86694 static ssize_t show_coresize(struct module_attribute *mattr,
86695 struct module_kobject *mk, char *buffer)
86696 {
86697- return sprintf(buffer, "%u\n", mk->mod->core_size);
86698+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86699 }
86700
86701 static struct module_attribute modinfo_coresize =
86702@@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86703 static ssize_t show_initsize(struct module_attribute *mattr,
86704 struct module_kobject *mk, char *buffer)
86705 {
86706- return sprintf(buffer, "%u\n", mk->mod->init_size);
86707+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86708 }
86709
86710 static struct module_attribute modinfo_initsize =
86711@@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86712 goto bad_version;
86713 }
86714
86715+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86716+ /*
86717+ * avoid potentially printing jibberish on attempted load
86718+ * of a module randomized with a different seed
86719+ */
86720+ pr_warn("no symbol version for %s\n", symname);
86721+#else
86722 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86723+#endif
86724 return 0;
86725
86726 bad_version:
86727+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86728+ /*
86729+ * avoid potentially printing jibberish on attempted load
86730+ * of a module randomized with a different seed
86731+ */
86732+ printk("attempted module disagrees about version of symbol %s\n",
86733+ symname);
86734+#else
86735 printk("%s: disagrees about version of symbol %s\n",
86736 mod->name, symname);
86737+#endif
86738 return 0;
86739 }
86740
86741@@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86742 */
86743 #ifdef CONFIG_SYSFS
86744
86745-#ifdef CONFIG_KALLSYMS
86746+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86747 static inline bool sect_empty(const Elf_Shdr *sect)
86748 {
86749 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86750@@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86751 {
86752 unsigned int notes, loaded, i;
86753 struct module_notes_attrs *notes_attrs;
86754- struct bin_attribute *nattr;
86755+ bin_attribute_no_const *nattr;
86756
86757 /* failed to create section attributes, so can't create notes */
86758 if (!mod->sect_attrs)
86759@@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86760 static int module_add_modinfo_attrs(struct module *mod)
86761 {
86762 struct module_attribute *attr;
86763- struct module_attribute *temp_attr;
86764+ module_attribute_no_const *temp_attr;
86765 int error = 0;
86766 int i;
86767
86768@@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86769
86770 static void unset_module_core_ro_nx(struct module *mod)
86771 {
86772- set_page_attributes(mod->module_core + mod->core_text_size,
86773- mod->module_core + mod->core_size,
86774+ set_page_attributes(mod->module_core_rw,
86775+ mod->module_core_rw + mod->core_size_rw,
86776 set_memory_x);
86777- set_page_attributes(mod->module_core,
86778- mod->module_core + mod->core_ro_size,
86779+ set_page_attributes(mod->module_core_rx,
86780+ mod->module_core_rx + mod->core_size_rx,
86781 set_memory_rw);
86782 }
86783
86784 static void unset_module_init_ro_nx(struct module *mod)
86785 {
86786- set_page_attributes(mod->module_init + mod->init_text_size,
86787- mod->module_init + mod->init_size,
86788+ set_page_attributes(mod->module_init_rw,
86789+ mod->module_init_rw + mod->init_size_rw,
86790 set_memory_x);
86791- set_page_attributes(mod->module_init,
86792- mod->module_init + mod->init_ro_size,
86793+ set_page_attributes(mod->module_init_rx,
86794+ mod->module_init_rx + mod->init_size_rx,
86795 set_memory_rw);
86796 }
86797
86798@@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86799 list_for_each_entry_rcu(mod, &modules, list) {
86800 if (mod->state == MODULE_STATE_UNFORMED)
86801 continue;
86802- if ((mod->module_core) && (mod->core_text_size)) {
86803- set_page_attributes(mod->module_core,
86804- mod->module_core + mod->core_text_size,
86805+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86806+ set_page_attributes(mod->module_core_rx,
86807+ mod->module_core_rx + mod->core_size_rx,
86808 set_memory_rw);
86809 }
86810- if ((mod->module_init) && (mod->init_text_size)) {
86811- set_page_attributes(mod->module_init,
86812- mod->module_init + mod->init_text_size,
86813+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86814+ set_page_attributes(mod->module_init_rx,
86815+ mod->module_init_rx + mod->init_size_rx,
86816 set_memory_rw);
86817 }
86818 }
86819@@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
86820 list_for_each_entry_rcu(mod, &modules, list) {
86821 if (mod->state == MODULE_STATE_UNFORMED)
86822 continue;
86823- if ((mod->module_core) && (mod->core_text_size)) {
86824- set_page_attributes(mod->module_core,
86825- mod->module_core + mod->core_text_size,
86826+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86827+ set_page_attributes(mod->module_core_rx,
86828+ mod->module_core_rx + mod->core_size_rx,
86829 set_memory_ro);
86830 }
86831- if ((mod->module_init) && (mod->init_text_size)) {
86832- set_page_attributes(mod->module_init,
86833- mod->module_init + mod->init_text_size,
86834+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86835+ set_page_attributes(mod->module_init_rx,
86836+ mod->module_init_rx + mod->init_size_rx,
86837 set_memory_ro);
86838 }
86839 }
86840@@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
86841
86842 /* This may be NULL, but that's OK */
86843 unset_module_init_ro_nx(mod);
86844- module_free(mod, mod->module_init);
86845+ module_free(mod, mod->module_init_rw);
86846+ module_free_exec(mod, mod->module_init_rx);
86847 kfree(mod->args);
86848 percpu_modfree(mod);
86849
86850 /* Free lock-classes: */
86851- lockdep_free_key_range(mod->module_core, mod->core_size);
86852+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86853+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86854
86855 /* Finally, free the core (containing the module structure) */
86856 unset_module_core_ro_nx(mod);
86857- module_free(mod, mod->module_core);
86858+ module_free_exec(mod, mod->module_core_rx);
86859+ module_free(mod, mod->module_core_rw);
86860
86861 #ifdef CONFIG_MPU
86862 update_protections(current->mm);
86863@@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86864 int ret = 0;
86865 const struct kernel_symbol *ksym;
86866
86867+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86868+ int is_fs_load = 0;
86869+ int register_filesystem_found = 0;
86870+ char *p;
86871+
86872+ p = strstr(mod->args, "grsec_modharden_fs");
86873+ if (p) {
86874+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86875+ /* copy \0 as well */
86876+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86877+ is_fs_load = 1;
86878+ }
86879+#endif
86880+
86881 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86882 const char *name = info->strtab + sym[i].st_name;
86883
86884+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86885+ /* it's a real shame this will never get ripped and copied
86886+ upstream! ;(
86887+ */
86888+ if (is_fs_load && !strcmp(name, "register_filesystem"))
86889+ register_filesystem_found = 1;
86890+#endif
86891+
86892 switch (sym[i].st_shndx) {
86893 case SHN_COMMON:
86894 /* We compiled with -fno-common. These are not
86895@@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86896 ksym = resolve_symbol_wait(mod, info, name);
86897 /* Ok if resolved. */
86898 if (ksym && !IS_ERR(ksym)) {
86899+ pax_open_kernel();
86900 sym[i].st_value = ksym->value;
86901+ pax_close_kernel();
86902 break;
86903 }
86904
86905@@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86906 secbase = (unsigned long)mod_percpu(mod);
86907 else
86908 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86909+ pax_open_kernel();
86910 sym[i].st_value += secbase;
86911+ pax_close_kernel();
86912 break;
86913 }
86914 }
86915
86916+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86917+ if (is_fs_load && !register_filesystem_found) {
86918+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86919+ ret = -EPERM;
86920+ }
86921+#endif
86922+
86923 return ret;
86924 }
86925
86926@@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86927 || s->sh_entsize != ~0UL
86928 || strstarts(sname, ".init"))
86929 continue;
86930- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86931+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86932+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86933+ else
86934+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86935 pr_debug("\t%s\n", sname);
86936 }
86937- switch (m) {
86938- case 0: /* executable */
86939- mod->core_size = debug_align(mod->core_size);
86940- mod->core_text_size = mod->core_size;
86941- break;
86942- case 1: /* RO: text and ro-data */
86943- mod->core_size = debug_align(mod->core_size);
86944- mod->core_ro_size = mod->core_size;
86945- break;
86946- case 3: /* whole core */
86947- mod->core_size = debug_align(mod->core_size);
86948- break;
86949- }
86950 }
86951
86952 pr_debug("Init section allocation order:\n");
86953@@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
86954 || s->sh_entsize != ~0UL
86955 || !strstarts(sname, ".init"))
86956 continue;
86957- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
86958- | INIT_OFFSET_MASK);
86959+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86960+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86961+ else
86962+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86963+ s->sh_entsize |= INIT_OFFSET_MASK;
86964 pr_debug("\t%s\n", sname);
86965 }
86966- switch (m) {
86967- case 0: /* executable */
86968- mod->init_size = debug_align(mod->init_size);
86969- mod->init_text_size = mod->init_size;
86970- break;
86971- case 1: /* RO: text and ro-data */
86972- mod->init_size = debug_align(mod->init_size);
86973- mod->init_ro_size = mod->init_size;
86974- break;
86975- case 3: /* whole init */
86976- mod->init_size = debug_align(mod->init_size);
86977- break;
86978- }
86979 }
86980 }
86981
86982@@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86983
86984 /* Put symbol section at end of init part of module. */
86985 symsect->sh_flags |= SHF_ALLOC;
86986- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86987+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86988 info->index.sym) | INIT_OFFSET_MASK;
86989 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86990
86991@@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86992 }
86993
86994 /* Append room for core symbols at end of core part. */
86995- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86996- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86997- mod->core_size += strtab_size;
86998+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86999+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
87000+ mod->core_size_rx += strtab_size;
87001
87002 /* Put string table section at end of init part of module. */
87003 strsect->sh_flags |= SHF_ALLOC;
87004- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
87005+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
87006 info->index.str) | INIT_OFFSET_MASK;
87007 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
87008 }
87009@@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87010 /* Make sure we get permanent strtab: don't use info->strtab. */
87011 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
87012
87013+ pax_open_kernel();
87014+
87015 /* Set types up while we still have access to sections. */
87016 for (i = 0; i < mod->num_symtab; i++)
87017 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
87018
87019- mod->core_symtab = dst = mod->module_core + info->symoffs;
87020- mod->core_strtab = s = mod->module_core + info->stroffs;
87021+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
87022+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
87023 src = mod->symtab;
87024 for (ndst = i = 0; i < mod->num_symtab; i++) {
87025 if (i == 0 ||
87026@@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87027 }
87028 }
87029 mod->core_num_syms = ndst;
87030+
87031+ pax_close_kernel();
87032 }
87033 #else
87034 static inline void layout_symtab(struct module *mod, struct load_info *info)
87035@@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
87036 return vmalloc_exec(size);
87037 }
87038
87039-static void *module_alloc_update_bounds(unsigned long size)
87040+static void *module_alloc_update_bounds_rw(unsigned long size)
87041 {
87042 void *ret = module_alloc(size);
87043
87044 if (ret) {
87045 mutex_lock(&module_mutex);
87046 /* Update module bounds. */
87047- if ((unsigned long)ret < module_addr_min)
87048- module_addr_min = (unsigned long)ret;
87049- if ((unsigned long)ret + size > module_addr_max)
87050- module_addr_max = (unsigned long)ret + size;
87051+ if ((unsigned long)ret < module_addr_min_rw)
87052+ module_addr_min_rw = (unsigned long)ret;
87053+ if ((unsigned long)ret + size > module_addr_max_rw)
87054+ module_addr_max_rw = (unsigned long)ret + size;
87055+ mutex_unlock(&module_mutex);
87056+ }
87057+ return ret;
87058+}
87059+
87060+static void *module_alloc_update_bounds_rx(unsigned long size)
87061+{
87062+ void *ret = module_alloc_exec(size);
87063+
87064+ if (ret) {
87065+ mutex_lock(&module_mutex);
87066+ /* Update module bounds. */
87067+ if ((unsigned long)ret < module_addr_min_rx)
87068+ module_addr_min_rx = (unsigned long)ret;
87069+ if ((unsigned long)ret + size > module_addr_max_rx)
87070+ module_addr_max_rx = (unsigned long)ret + size;
87071 mutex_unlock(&module_mutex);
87072 }
87073 return ret;
87074@@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87075 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87076
87077 if (info->index.sym == 0) {
87078+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87079+ /*
87080+ * avoid potentially printing jibberish on attempted load
87081+ * of a module randomized with a different seed
87082+ */
87083+ pr_warn("module has no symbols (stripped?)\n");
87084+#else
87085 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87086+#endif
87087 return ERR_PTR(-ENOEXEC);
87088 }
87089
87090@@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87091 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87092 {
87093 const char *modmagic = get_modinfo(info, "vermagic");
87094+ const char *license = get_modinfo(info, "license");
87095 int err;
87096
87097+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87098+ if (!license || !license_is_gpl_compatible(license))
87099+ return -ENOEXEC;
87100+#endif
87101+
87102 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87103 modmagic = NULL;
87104
87105@@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87106 }
87107
87108 /* Set up license info based on the info section */
87109- set_license(mod, get_modinfo(info, "license"));
87110+ set_license(mod, license);
87111
87112 return 0;
87113 }
87114@@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
87115 void *ptr;
87116
87117 /* Do the allocs. */
87118- ptr = module_alloc_update_bounds(mod->core_size);
87119+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87120 /*
87121 * The pointer to this block is stored in the module structure
87122 * which is inside the block. Just mark it as not being a
87123@@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
87124 if (!ptr)
87125 return -ENOMEM;
87126
87127- memset(ptr, 0, mod->core_size);
87128- mod->module_core = ptr;
87129+ memset(ptr, 0, mod->core_size_rw);
87130+ mod->module_core_rw = ptr;
87131
87132- if (mod->init_size) {
87133- ptr = module_alloc_update_bounds(mod->init_size);
87134+ if (mod->init_size_rw) {
87135+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87136 /*
87137 * The pointer to this block is stored in the module structure
87138 * which is inside the block. This block doesn't need to be
87139@@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
87140 */
87141 kmemleak_ignore(ptr);
87142 if (!ptr) {
87143- module_free(mod, mod->module_core);
87144+ module_free(mod, mod->module_core_rw);
87145 return -ENOMEM;
87146 }
87147- memset(ptr, 0, mod->init_size);
87148- mod->module_init = ptr;
87149+ memset(ptr, 0, mod->init_size_rw);
87150+ mod->module_init_rw = ptr;
87151 } else
87152- mod->module_init = NULL;
87153+ mod->module_init_rw = NULL;
87154+
87155+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87156+ kmemleak_not_leak(ptr);
87157+ if (!ptr) {
87158+ if (mod->module_init_rw)
87159+ module_free(mod, mod->module_init_rw);
87160+ module_free(mod, mod->module_core_rw);
87161+ return -ENOMEM;
87162+ }
87163+
87164+ pax_open_kernel();
87165+ memset(ptr, 0, mod->core_size_rx);
87166+ pax_close_kernel();
87167+ mod->module_core_rx = ptr;
87168+
87169+ if (mod->init_size_rx) {
87170+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87171+ kmemleak_ignore(ptr);
87172+ if (!ptr && mod->init_size_rx) {
87173+ module_free_exec(mod, mod->module_core_rx);
87174+ if (mod->module_init_rw)
87175+ module_free(mod, mod->module_init_rw);
87176+ module_free(mod, mod->module_core_rw);
87177+ return -ENOMEM;
87178+ }
87179+
87180+ pax_open_kernel();
87181+ memset(ptr, 0, mod->init_size_rx);
87182+ pax_close_kernel();
87183+ mod->module_init_rx = ptr;
87184+ } else
87185+ mod->module_init_rx = NULL;
87186
87187 /* Transfer each section which specifies SHF_ALLOC */
87188 pr_debug("final section addresses:\n");
87189@@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
87190 if (!(shdr->sh_flags & SHF_ALLOC))
87191 continue;
87192
87193- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87194- dest = mod->module_init
87195- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87196- else
87197- dest = mod->module_core + shdr->sh_entsize;
87198+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87199+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87200+ dest = mod->module_init_rw
87201+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87202+ else
87203+ dest = mod->module_init_rx
87204+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87205+ } else {
87206+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87207+ dest = mod->module_core_rw + shdr->sh_entsize;
87208+ else
87209+ dest = mod->module_core_rx + shdr->sh_entsize;
87210+ }
87211+
87212+ if (shdr->sh_type != SHT_NOBITS) {
87213+
87214+#ifdef CONFIG_PAX_KERNEXEC
87215+#ifdef CONFIG_X86_64
87216+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87217+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87218+#endif
87219+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87220+ pax_open_kernel();
87221+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87222+ pax_close_kernel();
87223+ } else
87224+#endif
87225
87226- if (shdr->sh_type != SHT_NOBITS)
87227 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87228+ }
87229 /* Update sh_addr to point to copy in image. */
87230- shdr->sh_addr = (unsigned long)dest;
87231+
87232+#ifdef CONFIG_PAX_KERNEXEC
87233+ if (shdr->sh_flags & SHF_EXECINSTR)
87234+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87235+ else
87236+#endif
87237+
87238+ shdr->sh_addr = (unsigned long)dest;
87239 pr_debug("\t0x%lx %s\n",
87240 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87241 }
87242@@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87243 * Do it before processing of module parameters, so the module
87244 * can provide parameter accessor functions of its own.
87245 */
87246- if (mod->module_init)
87247- flush_icache_range((unsigned long)mod->module_init,
87248- (unsigned long)mod->module_init
87249- + mod->init_size);
87250- flush_icache_range((unsigned long)mod->module_core,
87251- (unsigned long)mod->module_core + mod->core_size);
87252+ if (mod->module_init_rx)
87253+ flush_icache_range((unsigned long)mod->module_init_rx,
87254+ (unsigned long)mod->module_init_rx
87255+ + mod->init_size_rx);
87256+ flush_icache_range((unsigned long)mod->module_core_rx,
87257+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87258
87259 set_fs(old_fs);
87260 }
87261@@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87262 static void module_deallocate(struct module *mod, struct load_info *info)
87263 {
87264 percpu_modfree(mod);
87265- module_free(mod, mod->module_init);
87266- module_free(mod, mod->module_core);
87267+ module_free_exec(mod, mod->module_init_rx);
87268+ module_free_exec(mod, mod->module_core_rx);
87269+ module_free(mod, mod->module_init_rw);
87270+ module_free(mod, mod->module_core_rw);
87271 }
87272
87273 int __weak module_finalize(const Elf_Ehdr *hdr,
87274@@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87275 static int post_relocation(struct module *mod, const struct load_info *info)
87276 {
87277 /* Sort exception table now relocations are done. */
87278+ pax_open_kernel();
87279 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87280+ pax_close_kernel();
87281
87282 /* Copy relocated percpu area over. */
87283 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87284@@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87285 MODULE_STATE_COMING, mod);
87286
87287 /* Set RO and NX regions for core */
87288- set_section_ro_nx(mod->module_core,
87289- mod->core_text_size,
87290- mod->core_ro_size,
87291- mod->core_size);
87292+ set_section_ro_nx(mod->module_core_rx,
87293+ mod->core_size_rx,
87294+ mod->core_size_rx,
87295+ mod->core_size_rx);
87296
87297 /* Set RO and NX regions for init */
87298- set_section_ro_nx(mod->module_init,
87299- mod->init_text_size,
87300- mod->init_ro_size,
87301- mod->init_size);
87302+ set_section_ro_nx(mod->module_init_rx,
87303+ mod->init_size_rx,
87304+ mod->init_size_rx,
87305+ mod->init_size_rx);
87306
87307 do_mod_ctors(mod);
87308 /* Start the module */
87309@@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87310 mod->strtab = mod->core_strtab;
87311 #endif
87312 unset_module_init_ro_nx(mod);
87313- module_free(mod, mod->module_init);
87314- mod->module_init = NULL;
87315- mod->init_size = 0;
87316- mod->init_ro_size = 0;
87317- mod->init_text_size = 0;
87318+ module_free(mod, mod->module_init_rw);
87319+ module_free_exec(mod, mod->module_init_rx);
87320+ mod->module_init_rw = NULL;
87321+ mod->module_init_rx = NULL;
87322+ mod->init_size_rw = 0;
87323+ mod->init_size_rx = 0;
87324 mutex_unlock(&module_mutex);
87325 wake_up_all(&module_wq);
87326
87327@@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87328 if (err)
87329 goto free_unload;
87330
87331+ /* Now copy in args */
87332+ mod->args = strndup_user(uargs, ~0UL >> 1);
87333+ if (IS_ERR(mod->args)) {
87334+ err = PTR_ERR(mod->args);
87335+ goto free_unload;
87336+ }
87337+
87338 /* Set up MODINFO_ATTR fields */
87339 setup_modinfo(mod, info);
87340
87341+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87342+ {
87343+ char *p, *p2;
87344+
87345+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87346+ 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);
87347+ err = -EPERM;
87348+ goto free_modinfo;
87349+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87350+ p += sizeof("grsec_modharden_normal") - 1;
87351+ p2 = strstr(p, "_");
87352+ if (p2) {
87353+ *p2 = '\0';
87354+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87355+ *p2 = '_';
87356+ }
87357+ err = -EPERM;
87358+ goto free_modinfo;
87359+ }
87360+ }
87361+#endif
87362+
87363 /* Fix up syms, so that st_value is a pointer to location. */
87364 err = simplify_symbols(mod, info);
87365 if (err < 0)
87366@@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87367
87368 flush_module_icache(mod);
87369
87370- /* Now copy in args */
87371- mod->args = strndup_user(uargs, ~0UL >> 1);
87372- if (IS_ERR(mod->args)) {
87373- err = PTR_ERR(mod->args);
87374- goto free_arch_cleanup;
87375- }
87376-
87377 dynamic_debug_setup(info->debug, info->num_debug);
87378
87379 /* Finally it's fully formed, ready to start executing. */
87380@@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87381 ddebug_cleanup:
87382 dynamic_debug_remove(info->debug);
87383 synchronize_sched();
87384- kfree(mod->args);
87385- free_arch_cleanup:
87386 module_arch_cleanup(mod);
87387 free_modinfo:
87388 free_modinfo(mod);
87389+ kfree(mod->args);
87390 free_unload:
87391 module_unload_free(mod);
87392 unlink_mod:
87393@@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87394 unsigned long nextval;
87395
87396 /* At worse, next value is at end of module */
87397- if (within_module_init(addr, mod))
87398- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87399+ if (within_module_init_rx(addr, mod))
87400+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87401+ else if (within_module_init_rw(addr, mod))
87402+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87403+ else if (within_module_core_rx(addr, mod))
87404+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87405+ else if (within_module_core_rw(addr, mod))
87406+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87407 else
87408- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87409+ return NULL;
87410
87411 /* Scan for closest preceding symbol, and next symbol. (ELF
87412 starts real symbols at 1). */
87413@@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87414 return 0;
87415
87416 seq_printf(m, "%s %u",
87417- mod->name, mod->init_size + mod->core_size);
87418+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87419 print_unload_info(m, mod);
87420
87421 /* Informative for users. */
87422@@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87423 mod->state == MODULE_STATE_COMING ? "Loading":
87424 "Live");
87425 /* Used by oprofile and other similar tools. */
87426- seq_printf(m, " 0x%pK", mod->module_core);
87427+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87428
87429 /* Taints info */
87430 if (mod->taints)
87431@@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87432
87433 static int __init proc_modules_init(void)
87434 {
87435+#ifndef CONFIG_GRKERNSEC_HIDESYM
87436+#ifdef CONFIG_GRKERNSEC_PROC_USER
87437+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87438+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87439+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87440+#else
87441 proc_create("modules", 0, NULL, &proc_modules_operations);
87442+#endif
87443+#else
87444+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87445+#endif
87446 return 0;
87447 }
87448 module_init(proc_modules_init);
87449@@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87450 {
87451 struct module *mod;
87452
87453- if (addr < module_addr_min || addr > module_addr_max)
87454+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87455+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
87456 return NULL;
87457
87458 list_for_each_entry_rcu(mod, &modules, list) {
87459 if (mod->state == MODULE_STATE_UNFORMED)
87460 continue;
87461- if (within_module_core(addr, mod)
87462- || within_module_init(addr, mod))
87463+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
87464 return mod;
87465 }
87466 return NULL;
87467@@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87468 */
87469 struct module *__module_text_address(unsigned long addr)
87470 {
87471- struct module *mod = __module_address(addr);
87472+ struct module *mod;
87473+
87474+#ifdef CONFIG_X86_32
87475+ addr = ktla_ktva(addr);
87476+#endif
87477+
87478+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87479+ return NULL;
87480+
87481+ mod = __module_address(addr);
87482+
87483 if (mod) {
87484 /* Make sure it's within the text section. */
87485- if (!within(addr, mod->module_init, mod->init_text_size)
87486- && !within(addr, mod->module_core, mod->core_text_size))
87487+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87488 mod = NULL;
87489 }
87490 return mod;
87491diff --git a/kernel/notifier.c b/kernel/notifier.c
87492index 2d5cc4c..d9ea600 100644
87493--- a/kernel/notifier.c
87494+++ b/kernel/notifier.c
87495@@ -5,6 +5,7 @@
87496 #include <linux/rcupdate.h>
87497 #include <linux/vmalloc.h>
87498 #include <linux/reboot.h>
87499+#include <linux/mm.h>
87500
87501 /*
87502 * Notifier list for kernel code which wants to be called
87503@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87504 while ((*nl) != NULL) {
87505 if (n->priority > (*nl)->priority)
87506 break;
87507- nl = &((*nl)->next);
87508+ nl = (struct notifier_block **)&((*nl)->next);
87509 }
87510- n->next = *nl;
87511+ pax_open_kernel();
87512+ *(const void **)&n->next = *nl;
87513 rcu_assign_pointer(*nl, n);
87514+ pax_close_kernel();
87515 return 0;
87516 }
87517
87518@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87519 return 0;
87520 if (n->priority > (*nl)->priority)
87521 break;
87522- nl = &((*nl)->next);
87523+ nl = (struct notifier_block **)&((*nl)->next);
87524 }
87525- n->next = *nl;
87526+ pax_open_kernel();
87527+ *(const void **)&n->next = *nl;
87528 rcu_assign_pointer(*nl, n);
87529+ pax_close_kernel();
87530 return 0;
87531 }
87532
87533@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87534 {
87535 while ((*nl) != NULL) {
87536 if ((*nl) == n) {
87537+ pax_open_kernel();
87538 rcu_assign_pointer(*nl, n->next);
87539+ pax_close_kernel();
87540 return 0;
87541 }
87542- nl = &((*nl)->next);
87543+ nl = (struct notifier_block **)&((*nl)->next);
87544 }
87545 return -ENOENT;
87546 }
87547diff --git a/kernel/padata.c b/kernel/padata.c
87548index 2abd25d..02c4faa 100644
87549--- a/kernel/padata.c
87550+++ b/kernel/padata.c
87551@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87552 * seq_nr mod. number of cpus in use.
87553 */
87554
87555- seq_nr = atomic_inc_return(&pd->seq_nr);
87556+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87557 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87558
87559 return padata_index_to_cpu(pd, cpu_index);
87560@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87561 padata_init_pqueues(pd);
87562 padata_init_squeues(pd);
87563 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87564- atomic_set(&pd->seq_nr, -1);
87565+ atomic_set_unchecked(&pd->seq_nr, -1);
87566 atomic_set(&pd->reorder_objects, 0);
87567 atomic_set(&pd->refcnt, 0);
87568 pd->pinst = pinst;
87569diff --git a/kernel/panic.c b/kernel/panic.c
87570index c00b4ce..98c7d1a 100644
87571--- a/kernel/panic.c
87572+++ b/kernel/panic.c
87573@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87574 /*
87575 * Stop ourself in panic -- architecture code may override this
87576 */
87577-void __weak panic_smp_self_stop(void)
87578+void __weak __noreturn panic_smp_self_stop(void)
87579 {
87580 while (1)
87581 cpu_relax();
87582@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87583 disable_trace_on_warning();
87584
87585 pr_warn("------------[ cut here ]------------\n");
87586- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87587+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87588 raw_smp_processor_id(), current->pid, file, line, caller);
87589
87590 if (args)
87591@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87592 */
87593 void __stack_chk_fail(void)
87594 {
87595- panic("stack-protector: Kernel stack is corrupted in: %p\n",
87596+ dump_stack();
87597+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87598 __builtin_return_address(0));
87599 }
87600 EXPORT_SYMBOL(__stack_chk_fail);
87601diff --git a/kernel/pid.c b/kernel/pid.c
87602index 9b9a266..c20ef80 100644
87603--- a/kernel/pid.c
87604+++ b/kernel/pid.c
87605@@ -33,6 +33,7 @@
87606 #include <linux/rculist.h>
87607 #include <linux/bootmem.h>
87608 #include <linux/hash.h>
87609+#include <linux/security.h>
87610 #include <linux/pid_namespace.h>
87611 #include <linux/init_task.h>
87612 #include <linux/syscalls.h>
87613@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87614
87615 int pid_max = PID_MAX_DEFAULT;
87616
87617-#define RESERVED_PIDS 300
87618+#define RESERVED_PIDS 500
87619
87620 int pid_max_min = RESERVED_PIDS + 1;
87621 int pid_max_max = PID_MAX_LIMIT;
87622@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87623 */
87624 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87625 {
87626+ struct task_struct *task;
87627+
87628 rcu_lockdep_assert(rcu_read_lock_held(),
87629 "find_task_by_pid_ns() needs rcu_read_lock()"
87630 " protection");
87631- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87632+
87633+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87634+
87635+ if (gr_pid_is_chrooted(task))
87636+ return NULL;
87637+
87638+ return task;
87639 }
87640
87641 struct task_struct *find_task_by_vpid(pid_t vnr)
87642@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87643 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87644 }
87645
87646+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87647+{
87648+ rcu_lockdep_assert(rcu_read_lock_held(),
87649+ "find_task_by_pid_ns() needs rcu_read_lock()"
87650+ " protection");
87651+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87652+}
87653+
87654 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87655 {
87656 struct pid *pid;
87657diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87658index 06c62de..b08cc6c 100644
87659--- a/kernel/pid_namespace.c
87660+++ b/kernel/pid_namespace.c
87661@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87662 void __user *buffer, size_t *lenp, loff_t *ppos)
87663 {
87664 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87665- struct ctl_table tmp = *table;
87666+ ctl_table_no_const tmp = *table;
87667
87668 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87669 return -EPERM;
87670diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87671index c7f31aa..2b44977 100644
87672--- a/kernel/posix-cpu-timers.c
87673+++ b/kernel/posix-cpu-timers.c
87674@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87675
87676 static __init int init_posix_cpu_timers(void)
87677 {
87678- struct k_clock process = {
87679+ static struct k_clock process = {
87680 .clock_getres = process_cpu_clock_getres,
87681 .clock_get = process_cpu_clock_get,
87682 .timer_create = process_cpu_timer_create,
87683 .nsleep = process_cpu_nsleep,
87684 .nsleep_restart = process_cpu_nsleep_restart,
87685 };
87686- struct k_clock thread = {
87687+ static struct k_clock thread = {
87688 .clock_getres = thread_cpu_clock_getres,
87689 .clock_get = thread_cpu_clock_get,
87690 .timer_create = thread_cpu_timer_create,
87691diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87692index 424c2d4..679242f 100644
87693--- a/kernel/posix-timers.c
87694+++ b/kernel/posix-timers.c
87695@@ -43,6 +43,7 @@
87696 #include <linux/hash.h>
87697 #include <linux/posix-clock.h>
87698 #include <linux/posix-timers.h>
87699+#include <linux/grsecurity.h>
87700 #include <linux/syscalls.h>
87701 #include <linux/wait.h>
87702 #include <linux/workqueue.h>
87703@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87704 * which we beg off on and pass to do_sys_settimeofday().
87705 */
87706
87707-static struct k_clock posix_clocks[MAX_CLOCKS];
87708+static struct k_clock *posix_clocks[MAX_CLOCKS];
87709
87710 /*
87711 * These ones are defined below.
87712@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87713 */
87714 static __init int init_posix_timers(void)
87715 {
87716- struct k_clock clock_realtime = {
87717+ static struct k_clock clock_realtime = {
87718 .clock_getres = hrtimer_get_res,
87719 .clock_get = posix_clock_realtime_get,
87720 .clock_set = posix_clock_realtime_set,
87721@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87722 .timer_get = common_timer_get,
87723 .timer_del = common_timer_del,
87724 };
87725- struct k_clock clock_monotonic = {
87726+ static struct k_clock clock_monotonic = {
87727 .clock_getres = hrtimer_get_res,
87728 .clock_get = posix_ktime_get_ts,
87729 .nsleep = common_nsleep,
87730@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87731 .timer_get = common_timer_get,
87732 .timer_del = common_timer_del,
87733 };
87734- struct k_clock clock_monotonic_raw = {
87735+ static struct k_clock clock_monotonic_raw = {
87736 .clock_getres = hrtimer_get_res,
87737 .clock_get = posix_get_monotonic_raw,
87738 };
87739- struct k_clock clock_realtime_coarse = {
87740+ static struct k_clock clock_realtime_coarse = {
87741 .clock_getres = posix_get_coarse_res,
87742 .clock_get = posix_get_realtime_coarse,
87743 };
87744- struct k_clock clock_monotonic_coarse = {
87745+ static struct k_clock clock_monotonic_coarse = {
87746 .clock_getres = posix_get_coarse_res,
87747 .clock_get = posix_get_monotonic_coarse,
87748 };
87749- struct k_clock clock_tai = {
87750+ static struct k_clock clock_tai = {
87751 .clock_getres = hrtimer_get_res,
87752 .clock_get = posix_get_tai,
87753 .nsleep = common_nsleep,
87754@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87755 .timer_get = common_timer_get,
87756 .timer_del = common_timer_del,
87757 };
87758- struct k_clock clock_boottime = {
87759+ static struct k_clock clock_boottime = {
87760 .clock_getres = hrtimer_get_res,
87761 .clock_get = posix_get_boottime,
87762 .nsleep = common_nsleep,
87763@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87764 return;
87765 }
87766
87767- posix_clocks[clock_id] = *new_clock;
87768+ posix_clocks[clock_id] = new_clock;
87769 }
87770 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87771
87772@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87773 return (id & CLOCKFD_MASK) == CLOCKFD ?
87774 &clock_posix_dynamic : &clock_posix_cpu;
87775
87776- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87777+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87778 return NULL;
87779- return &posix_clocks[id];
87780+ return posix_clocks[id];
87781 }
87782
87783 static int common_timer_create(struct k_itimer *new_timer)
87784@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87785 struct k_clock *kc = clockid_to_kclock(which_clock);
87786 struct k_itimer *new_timer;
87787 int error, new_timer_id;
87788- sigevent_t event;
87789+ sigevent_t event = { };
87790 int it_id_set = IT_ID_NOT_SET;
87791
87792 if (!kc)
87793@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87794 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87795 return -EFAULT;
87796
87797+ /* only the CLOCK_REALTIME clock can be set, all other clocks
87798+ have their clock_set fptr set to a nosettime dummy function
87799+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87800+ call common_clock_set, which calls do_sys_settimeofday, which
87801+ we hook
87802+ */
87803+
87804 return kc->clock_set(which_clock, &new_tp);
87805 }
87806
87807diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87808index 2fac9cc..56fef29 100644
87809--- a/kernel/power/Kconfig
87810+++ b/kernel/power/Kconfig
87811@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87812 config HIBERNATION
87813 bool "Hibernation (aka 'suspend to disk')"
87814 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87815+ depends on !GRKERNSEC_KMEM
87816+ depends on !PAX_MEMORY_SANITIZE
87817 select HIBERNATE_CALLBACKS
87818 select LZO_COMPRESS
87819 select LZO_DECOMPRESS
87820diff --git a/kernel/power/process.c b/kernel/power/process.c
87821index 06ec886..9dba35e 100644
87822--- a/kernel/power/process.c
87823+++ b/kernel/power/process.c
87824@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87825 unsigned int elapsed_msecs;
87826 bool wakeup = false;
87827 int sleep_usecs = USEC_PER_MSEC;
87828+ bool timedout = false;
87829
87830 do_gettimeofday(&start);
87831
87832@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87833
87834 while (true) {
87835 todo = 0;
87836+ if (time_after(jiffies, end_time))
87837+ timedout = true;
87838 read_lock(&tasklist_lock);
87839 do_each_thread(g, p) {
87840 if (p == current || !freeze_task(p))
87841 continue;
87842
87843- if (!freezer_should_skip(p))
87844+ if (!freezer_should_skip(p)) {
87845 todo++;
87846+ if (timedout) {
87847+ printk(KERN_ERR "Task refusing to freeze:\n");
87848+ sched_show_task(p);
87849+ }
87850+ }
87851 } while_each_thread(g, p);
87852 read_unlock(&tasklist_lock);
87853
87854@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87855 todo += wq_busy;
87856 }
87857
87858- if (!todo || time_after(jiffies, end_time))
87859+ if (!todo || timedout)
87860 break;
87861
87862 if (pm_wakeup_pending()) {
87863diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87864index 97fb834..b972b27 100644
87865--- a/kernel/printk/printk.c
87866+++ b/kernel/printk/printk.c
87867@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87868 if (from_file && type != SYSLOG_ACTION_OPEN)
87869 return 0;
87870
87871+#ifdef CONFIG_GRKERNSEC_DMESG
87872+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87873+ return -EPERM;
87874+#endif
87875+
87876 if (syslog_action_restricted(type)) {
87877 if (capable(CAP_SYSLOG))
87878 return 0;
87879diff --git a/kernel/profile.c b/kernel/profile.c
87880index 6631e1e..310c266 100644
87881--- a/kernel/profile.c
87882+++ b/kernel/profile.c
87883@@ -37,7 +37,7 @@ struct profile_hit {
87884 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87885 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87886
87887-static atomic_t *prof_buffer;
87888+static atomic_unchecked_t *prof_buffer;
87889 static unsigned long prof_len, prof_shift;
87890
87891 int prof_on __read_mostly;
87892@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87893 hits[i].pc = 0;
87894 continue;
87895 }
87896- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87897+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87898 hits[i].hits = hits[i].pc = 0;
87899 }
87900 }
87901@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87902 * Add the current hit(s) and flush the write-queue out
87903 * to the global buffer:
87904 */
87905- atomic_add(nr_hits, &prof_buffer[pc]);
87906+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87907 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87908- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87909+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87910 hits[i].pc = hits[i].hits = 0;
87911 }
87912 out:
87913@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87914 {
87915 unsigned long pc;
87916 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87917- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87918+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87919 }
87920 #endif /* !CONFIG_SMP */
87921
87922@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87923 return -EFAULT;
87924 buf++; p++; count--; read++;
87925 }
87926- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87927+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87928 if (copy_to_user(buf, (void *)pnt, count))
87929 return -EFAULT;
87930 read += count;
87931@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87932 }
87933 #endif
87934 profile_discard_flip_buffers();
87935- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87936+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87937 return count;
87938 }
87939
87940diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87941index 1f4bcb3..99cf7ab 100644
87942--- a/kernel/ptrace.c
87943+++ b/kernel/ptrace.c
87944@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87945 if (seize)
87946 flags |= PT_SEIZED;
87947 rcu_read_lock();
87948- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87949+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87950 flags |= PT_PTRACE_CAP;
87951 rcu_read_unlock();
87952 task->ptrace = flags;
87953@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87954 break;
87955 return -EIO;
87956 }
87957- if (copy_to_user(dst, buf, retval))
87958+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87959 return -EFAULT;
87960 copied += retval;
87961 src += retval;
87962@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87963 bool seized = child->ptrace & PT_SEIZED;
87964 int ret = -EIO;
87965 siginfo_t siginfo, *si;
87966- void __user *datavp = (void __user *) data;
87967+ void __user *datavp = (__force void __user *) data;
87968 unsigned long __user *datalp = datavp;
87969 unsigned long flags;
87970
87971@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87972 goto out;
87973 }
87974
87975+ if (gr_handle_ptrace(child, request)) {
87976+ ret = -EPERM;
87977+ goto out_put_task_struct;
87978+ }
87979+
87980 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87981 ret = ptrace_attach(child, request, addr, data);
87982 /*
87983 * Some architectures need to do book-keeping after
87984 * a ptrace attach.
87985 */
87986- if (!ret)
87987+ if (!ret) {
87988 arch_ptrace_attach(child);
87989+ gr_audit_ptrace(child);
87990+ }
87991 goto out_put_task_struct;
87992 }
87993
87994@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
87995 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
87996 if (copied != sizeof(tmp))
87997 return -EIO;
87998- return put_user(tmp, (unsigned long __user *)data);
87999+ return put_user(tmp, (__force unsigned long __user *)data);
88000 }
88001
88002 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
88003@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
88004 }
88005
88006 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88007- compat_long_t addr, compat_long_t data)
88008+ compat_ulong_t addr, compat_ulong_t data)
88009 {
88010 struct task_struct *child;
88011 long ret;
88012@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
88013 goto out;
88014 }
88015
88016+ if (gr_handle_ptrace(child, request)) {
88017+ ret = -EPERM;
88018+ goto out_put_task_struct;
88019+ }
88020+
88021 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88022 ret = ptrace_attach(child, request, addr, data);
88023 /*
88024 * Some architectures need to do book-keeping after
88025 * a ptrace attach.
88026 */
88027- if (!ret)
88028+ if (!ret) {
88029 arch_ptrace_attach(child);
88030+ gr_audit_ptrace(child);
88031+ }
88032 goto out_put_task_struct;
88033 }
88034
88035diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88036index 01d5ccb..cdcbee6 100644
88037--- a/kernel/rcu/srcu.c
88038+++ b/kernel/rcu/srcu.c
88039@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88040
88041 idx = ACCESS_ONCE(sp->completed) & 0x1;
88042 preempt_disable();
88043- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88044+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88045 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88046- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88047+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88048 preempt_enable();
88049 return idx;
88050 }
88051diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88052index 1254f31..16258dc 100644
88053--- a/kernel/rcu/tiny.c
88054+++ b/kernel/rcu/tiny.c
88055@@ -46,7 +46,7 @@
88056 /* Forward declarations for tiny_plugin.h. */
88057 struct rcu_ctrlblk;
88058 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88059-static void rcu_process_callbacks(struct softirq_action *unused);
88060+static void rcu_process_callbacks(void);
88061 static void __call_rcu(struct rcu_head *head,
88062 void (*func)(struct rcu_head *rcu),
88063 struct rcu_ctrlblk *rcp);
88064@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88065 false));
88066 }
88067
88068-static void rcu_process_callbacks(struct softirq_action *unused)
88069+static __latent_entropy void rcu_process_callbacks(void)
88070 {
88071 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88072 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88073diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88074index 3929cd4..421624d 100644
88075--- a/kernel/rcu/torture.c
88076+++ b/kernel/rcu/torture.c
88077@@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88078 { 0 };
88079 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88080 { 0 };
88081-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88082-static atomic_t n_rcu_torture_alloc;
88083-static atomic_t n_rcu_torture_alloc_fail;
88084-static atomic_t n_rcu_torture_free;
88085-static atomic_t n_rcu_torture_mberror;
88086-static atomic_t n_rcu_torture_error;
88087+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88088+static atomic_unchecked_t n_rcu_torture_alloc;
88089+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88090+static atomic_unchecked_t n_rcu_torture_free;
88091+static atomic_unchecked_t n_rcu_torture_mberror;
88092+static atomic_unchecked_t n_rcu_torture_error;
88093 static long n_rcu_torture_barrier_error;
88094 static long n_rcu_torture_boost_ktrerror;
88095 static long n_rcu_torture_boost_rterror;
88096@@ -299,11 +299,11 @@ rcu_torture_alloc(void)
88097
88098 spin_lock_bh(&rcu_torture_lock);
88099 if (list_empty(&rcu_torture_freelist)) {
88100- atomic_inc(&n_rcu_torture_alloc_fail);
88101+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88102 spin_unlock_bh(&rcu_torture_lock);
88103 return NULL;
88104 }
88105- atomic_inc(&n_rcu_torture_alloc);
88106+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88107 p = rcu_torture_freelist.next;
88108 list_del_init(p);
88109 spin_unlock_bh(&rcu_torture_lock);
88110@@ -316,7 +316,7 @@ rcu_torture_alloc(void)
88111 static void
88112 rcu_torture_free(struct rcu_torture *p)
88113 {
88114- atomic_inc(&n_rcu_torture_free);
88115+ atomic_inc_unchecked(&n_rcu_torture_free);
88116 spin_lock_bh(&rcu_torture_lock);
88117 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88118 spin_unlock_bh(&rcu_torture_lock);
88119@@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
88120 i = rp->rtort_pipe_count;
88121 if (i > RCU_TORTURE_PIPE_LEN)
88122 i = RCU_TORTURE_PIPE_LEN;
88123- atomic_inc(&rcu_torture_wcount[i]);
88124+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88125 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88126 rp->rtort_mbtest = 0;
88127 rcu_torture_free(rp);
88128@@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
88129 i = old_rp->rtort_pipe_count;
88130 if (i > RCU_TORTURE_PIPE_LEN)
88131 i = RCU_TORTURE_PIPE_LEN;
88132- atomic_inc(&rcu_torture_wcount[i]);
88133+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88134 old_rp->rtort_pipe_count++;
88135 if (gp_normal == gp_exp)
88136 exp = !!(rcu_random(&rand) & 0x80);
88137@@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
88138 i = rp->rtort_pipe_count;
88139 if (i > RCU_TORTURE_PIPE_LEN)
88140 i = RCU_TORTURE_PIPE_LEN;
88141- atomic_inc(&rcu_torture_wcount[i]);
88142+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88143 if (++rp->rtort_pipe_count >=
88144 RCU_TORTURE_PIPE_LEN) {
88145 rp->rtort_mbtest = 0;
88146@@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
88147 return;
88148 }
88149 if (p->rtort_mbtest == 0)
88150- atomic_inc(&n_rcu_torture_mberror);
88151+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88152 spin_lock(&rand_lock);
88153 cur_ops->read_delay(&rand);
88154 n_rcu_torture_timers++;
88155@@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
88156 continue;
88157 }
88158 if (p->rtort_mbtest == 0)
88159- atomic_inc(&n_rcu_torture_mberror);
88160+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88161 cur_ops->read_delay(&rand);
88162 preempt_disable();
88163 pipe_count = p->rtort_pipe_count;
88164@@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
88165 rcu_torture_current,
88166 rcu_torture_current_version,
88167 list_empty(&rcu_torture_freelist),
88168- atomic_read(&n_rcu_torture_alloc),
88169- atomic_read(&n_rcu_torture_alloc_fail),
88170- atomic_read(&n_rcu_torture_free));
88171+ atomic_read_unchecked(&n_rcu_torture_alloc),
88172+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88173+ atomic_read_unchecked(&n_rcu_torture_free));
88174 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
88175- atomic_read(&n_rcu_torture_mberror),
88176+ atomic_read_unchecked(&n_rcu_torture_mberror),
88177 n_rcu_torture_boost_ktrerror,
88178 n_rcu_torture_boost_rterror);
88179 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
88180@@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
88181 n_barrier_attempts,
88182 n_rcu_torture_barrier_error);
88183 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
88184- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88185+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88186 n_rcu_torture_barrier_error != 0 ||
88187 n_rcu_torture_boost_ktrerror != 0 ||
88188 n_rcu_torture_boost_rterror != 0 ||
88189 n_rcu_torture_boost_failure != 0 ||
88190 i > 1) {
88191 cnt += sprintf(&page[cnt], "!!! ");
88192- atomic_inc(&n_rcu_torture_error);
88193+ atomic_inc_unchecked(&n_rcu_torture_error);
88194 WARN_ON_ONCE(1);
88195 }
88196 cnt += sprintf(&page[cnt], "Reader Pipe: ");
88197@@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
88198 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
88199 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88200 cnt += sprintf(&page[cnt], " %d",
88201- atomic_read(&rcu_torture_wcount[i]));
88202+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88203 }
88204 cnt += sprintf(&page[cnt], "\n");
88205 if (cur_ops->stats)
88206@@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
88207
88208 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88209
88210- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88211+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88212 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88213 else if (n_online_successes != n_online_attempts ||
88214 n_offline_successes != n_offline_attempts)
88215@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88216
88217 rcu_torture_current = NULL;
88218 rcu_torture_current_version = 0;
88219- atomic_set(&n_rcu_torture_alloc, 0);
88220- atomic_set(&n_rcu_torture_alloc_fail, 0);
88221- atomic_set(&n_rcu_torture_free, 0);
88222- atomic_set(&n_rcu_torture_mberror, 0);
88223- atomic_set(&n_rcu_torture_error, 0);
88224+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88225+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88226+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88227+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88228+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88229 n_rcu_torture_barrier_error = 0;
88230 n_rcu_torture_boost_ktrerror = 0;
88231 n_rcu_torture_boost_rterror = 0;
88232 n_rcu_torture_boost_failure = 0;
88233 n_rcu_torture_boosts = 0;
88234 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88235- atomic_set(&rcu_torture_wcount[i], 0);
88236+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88237 for_each_possible_cpu(cpu) {
88238 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88239 per_cpu(rcu_torture_count, cpu)[i] = 0;
88240diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88241index dd08198..5ccccbe 100644
88242--- a/kernel/rcu/tree.c
88243+++ b/kernel/rcu/tree.c
88244@@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88245 rcu_prepare_for_idle(smp_processor_id());
88246 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88247 smp_mb__before_atomic_inc(); /* See above. */
88248- atomic_inc(&rdtp->dynticks);
88249+ atomic_inc_unchecked(&rdtp->dynticks);
88250 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88251- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88252+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88253
88254 /*
88255 * It is illegal to enter an extended quiescent state while
88256@@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88257 int user)
88258 {
88259 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88260- atomic_inc(&rdtp->dynticks);
88261+ atomic_inc_unchecked(&rdtp->dynticks);
88262 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88263 smp_mb__after_atomic_inc(); /* See above. */
88264- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88265+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88266 rcu_cleanup_after_idle(smp_processor_id());
88267 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88268 if (!user && !is_idle_task(current)) {
88269@@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88270 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88271
88272 if (rdtp->dynticks_nmi_nesting == 0 &&
88273- (atomic_read(&rdtp->dynticks) & 0x1))
88274+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88275 return;
88276 rdtp->dynticks_nmi_nesting++;
88277 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88278- atomic_inc(&rdtp->dynticks);
88279+ atomic_inc_unchecked(&rdtp->dynticks);
88280 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88281 smp_mb__after_atomic_inc(); /* See above. */
88282- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88283+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88284 }
88285
88286 /**
88287@@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88288 return;
88289 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88290 smp_mb__before_atomic_inc(); /* See above. */
88291- atomic_inc(&rdtp->dynticks);
88292+ atomic_inc_unchecked(&rdtp->dynticks);
88293 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88294- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88295+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88296 }
88297
88298 /**
88299@@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88300 */
88301 bool notrace __rcu_is_watching(void)
88302 {
88303- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88304+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88305 }
88306
88307 /**
88308@@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88309 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88310 bool *isidle, unsigned long *maxj)
88311 {
88312- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88313+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88314 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88315 return (rdp->dynticks_snap & 0x1) == 0;
88316 }
88317@@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88318 unsigned int curr;
88319 unsigned int snap;
88320
88321- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88322+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88323 snap = (unsigned int)rdp->dynticks_snap;
88324
88325 /*
88326@@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88327 rdp = this_cpu_ptr(rsp->rda);
88328 rcu_preempt_check_blocked_tasks(rnp);
88329 rnp->qsmask = rnp->qsmaskinit;
88330- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88331+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88332 WARN_ON_ONCE(rnp->completed != rsp->completed);
88333- ACCESS_ONCE(rnp->completed) = rsp->completed;
88334+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88335 if (rnp == rdp->mynode)
88336 __note_gp_changes(rsp, rnp, rdp);
88337 rcu_preempt_boost_start_gp(rnp);
88338@@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88339 */
88340 rcu_for_each_node_breadth_first(rsp, rnp) {
88341 raw_spin_lock_irq(&rnp->lock);
88342- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88343+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88344 rdp = this_cpu_ptr(rsp->rda);
88345 if (rnp == rdp->mynode)
88346 __note_gp_changes(rsp, rnp, rdp);
88347@@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88348 rsp->qlen += rdp->qlen;
88349 rdp->n_cbs_orphaned += rdp->qlen;
88350 rdp->qlen_lazy = 0;
88351- ACCESS_ONCE(rdp->qlen) = 0;
88352+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88353 }
88354
88355 /*
88356@@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88357 }
88358 smp_mb(); /* List handling before counting for rcu_barrier(). */
88359 rdp->qlen_lazy -= count_lazy;
88360- ACCESS_ONCE(rdp->qlen) -= count;
88361+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88362 rdp->n_cbs_invoked += count;
88363
88364 /* Reinstate batch limit if we have worked down the excess. */
88365@@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88366 /*
88367 * Do RCU core processing for the current CPU.
88368 */
88369-static void rcu_process_callbacks(struct softirq_action *unused)
88370+static void rcu_process_callbacks(void)
88371 {
88372 struct rcu_state *rsp;
88373
88374@@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88375 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88376 if (debug_rcu_head_queue(head)) {
88377 /* Probable double call_rcu(), so leak the callback. */
88378- ACCESS_ONCE(head->func) = rcu_leak_callback;
88379+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88380 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88381 return;
88382 }
88383@@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88384 local_irq_restore(flags);
88385 return;
88386 }
88387- ACCESS_ONCE(rdp->qlen)++;
88388+ ACCESS_ONCE_RW(rdp->qlen)++;
88389 if (lazy)
88390 rdp->qlen_lazy++;
88391 else
88392@@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88393 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88394 * course be required on a 64-bit system.
88395 */
88396- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88397+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88398 (ulong)atomic_long_read(&rsp->expedited_done) +
88399 ULONG_MAX / 8)) {
88400 synchronize_sched();
88401- atomic_long_inc(&rsp->expedited_wrap);
88402+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88403 return;
88404 }
88405
88406@@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88407 * Take a ticket. Note that atomic_inc_return() implies a
88408 * full memory barrier.
88409 */
88410- snap = atomic_long_inc_return(&rsp->expedited_start);
88411+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88412 firstsnap = snap;
88413 get_online_cpus();
88414 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88415@@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88416 synchronize_sched_expedited_cpu_stop,
88417 NULL) == -EAGAIN) {
88418 put_online_cpus();
88419- atomic_long_inc(&rsp->expedited_tryfail);
88420+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88421
88422 /* Check to see if someone else did our work for us. */
88423 s = atomic_long_read(&rsp->expedited_done);
88424 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88425 /* ensure test happens before caller kfree */
88426 smp_mb__before_atomic_inc(); /* ^^^ */
88427- atomic_long_inc(&rsp->expedited_workdone1);
88428+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88429 return;
88430 }
88431
88432@@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88433 udelay(trycount * num_online_cpus());
88434 } else {
88435 wait_rcu_gp(call_rcu_sched);
88436- atomic_long_inc(&rsp->expedited_normal);
88437+ atomic_long_inc_unchecked(&rsp->expedited_normal);
88438 return;
88439 }
88440
88441@@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88442 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88443 /* ensure test happens before caller kfree */
88444 smp_mb__before_atomic_inc(); /* ^^^ */
88445- atomic_long_inc(&rsp->expedited_workdone2);
88446+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88447 return;
88448 }
88449
88450@@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88451 * period works for us.
88452 */
88453 get_online_cpus();
88454- snap = atomic_long_read(&rsp->expedited_start);
88455+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
88456 smp_mb(); /* ensure read is before try_stop_cpus(). */
88457 }
88458- atomic_long_inc(&rsp->expedited_stoppedcpus);
88459+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88460
88461 /*
88462 * Everyone up to our most recent fetch is covered by our grace
88463@@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88464 * than we did already did their update.
88465 */
88466 do {
88467- atomic_long_inc(&rsp->expedited_done_tries);
88468+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88469 s = atomic_long_read(&rsp->expedited_done);
88470 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88471 /* ensure test happens before caller kfree */
88472 smp_mb__before_atomic_inc(); /* ^^^ */
88473- atomic_long_inc(&rsp->expedited_done_lost);
88474+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88475 break;
88476 }
88477 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88478- atomic_long_inc(&rsp->expedited_done_exit);
88479+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88480
88481 put_online_cpus();
88482 }
88483@@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88484 * ACCESS_ONCE() to prevent the compiler from speculating
88485 * the increment to precede the early-exit check.
88486 */
88487- ACCESS_ONCE(rsp->n_barrier_done)++;
88488+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88489 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88490 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88491 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88492@@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88493
88494 /* Increment ->n_barrier_done to prevent duplicate work. */
88495 smp_mb(); /* Keep increment after above mechanism. */
88496- ACCESS_ONCE(rsp->n_barrier_done)++;
88497+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88498 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88499 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88500 smp_mb(); /* Keep increment before caller's subsequent code. */
88501@@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88502 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88503 init_callback_list(rdp);
88504 rdp->qlen_lazy = 0;
88505- ACCESS_ONCE(rdp->qlen) = 0;
88506+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88507 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88508 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88509- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88510+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88511 rdp->cpu = cpu;
88512 rdp->rsp = rsp;
88513 rcu_boot_init_nocb_percpu_data(rdp);
88514@@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88515 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88516 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88517 rcu_sysidle_init_percpu_data(rdp->dynticks);
88518- atomic_set(&rdp->dynticks->dynticks,
88519- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88520+ atomic_set_unchecked(&rdp->dynticks->dynticks,
88521+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88522 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88523
88524 /* Add CPU to rcu_node bitmasks. */
88525diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88526index 52be957..365ded3 100644
88527--- a/kernel/rcu/tree.h
88528+++ b/kernel/rcu/tree.h
88529@@ -87,11 +87,11 @@ struct rcu_dynticks {
88530 long long dynticks_nesting; /* Track irq/process nesting level. */
88531 /* Process level is worth LLONG_MAX/2. */
88532 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88533- atomic_t dynticks; /* Even value for idle, else odd. */
88534+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88535 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88536 long long dynticks_idle_nesting;
88537 /* irq/process nesting level from idle. */
88538- atomic_t dynticks_idle; /* Even value for idle, else odd. */
88539+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88540 /* "Idle" excludes userspace execution. */
88541 unsigned long dynticks_idle_jiffies;
88542 /* End of last non-NMI non-idle period. */
88543@@ -429,17 +429,17 @@ struct rcu_state {
88544 /* _rcu_barrier(). */
88545 /* End of fields guarded by barrier_mutex. */
88546
88547- atomic_long_t expedited_start; /* Starting ticket. */
88548- atomic_long_t expedited_done; /* Done ticket. */
88549- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88550- atomic_long_t expedited_tryfail; /* # acquisition failures. */
88551- atomic_long_t expedited_workdone1; /* # done by others #1. */
88552- atomic_long_t expedited_workdone2; /* # done by others #2. */
88553- atomic_long_t expedited_normal; /* # fallbacks to normal. */
88554- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88555- atomic_long_t expedited_done_tries; /* # tries to update _done. */
88556- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88557- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88558+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88559+ atomic_long_t expedited_done; /* Done ticket. */
88560+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88561+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88562+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88563+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88564+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88565+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88566+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88567+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88568+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88569
88570 unsigned long jiffies_force_qs; /* Time at which to invoke */
88571 /* force_quiescent_state(). */
88572diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88573index 08a7652..3598c7e 100644
88574--- a/kernel/rcu/tree_plugin.h
88575+++ b/kernel/rcu/tree_plugin.h
88576@@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88577 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88578 {
88579 return !rcu_preempted_readers_exp(rnp) &&
88580- ACCESS_ONCE(rnp->expmask) == 0;
88581+ ACCESS_ONCE_RW(rnp->expmask) == 0;
88582 }
88583
88584 /*
88585@@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88586
88587 /* Clean up and exit. */
88588 smp_mb(); /* ensure expedited GP seen before counter increment. */
88589- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88590+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88591 unlock_mb_ret:
88592 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88593 mb_ret:
88594@@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88595 free_cpumask_var(cm);
88596 }
88597
88598-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88599+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88600 .store = &rcu_cpu_kthread_task,
88601 .thread_should_run = rcu_cpu_kthread_should_run,
88602 .thread_fn = rcu_cpu_kthread,
88603@@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88604 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88605 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88606 cpu, ticks_value, ticks_title,
88607- atomic_read(&rdtp->dynticks) & 0xfff,
88608+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88609 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88610 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88611 fast_no_hz);
88612@@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88613
88614 /* Enqueue the callback on the nocb list and update counts. */
88615 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88616- ACCESS_ONCE(*old_rhpp) = rhp;
88617+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
88618 atomic_long_add(rhcount, &rdp->nocb_q_count);
88619 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88620
88621@@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88622 * Extract queued callbacks, update counts, and wait
88623 * for a grace period to elapse.
88624 */
88625- ACCESS_ONCE(rdp->nocb_head) = NULL;
88626+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88627 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88628 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88629 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88630- ACCESS_ONCE(rdp->nocb_p_count) += c;
88631- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88632+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88633+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88634 rcu_nocb_wait_gp(rdp);
88635
88636 /* Each pass through the following loop invokes a callback. */
88637@@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88638 list = next;
88639 }
88640 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88641- ACCESS_ONCE(rdp->nocb_p_count) -= c;
88642- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88643+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88644+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88645 rdp->n_nocbs_invoked += c;
88646 }
88647 return 0;
88648@@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88649 t = kthread_run(rcu_nocb_kthread, rdp,
88650 "rcuo%c/%d", rsp->abbr, cpu);
88651 BUG_ON(IS_ERR(t));
88652- ACCESS_ONCE(rdp->nocb_kthread) = t;
88653+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88654 }
88655 }
88656
88657@@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88658
88659 /* Record start of fully idle period. */
88660 j = jiffies;
88661- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88662+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88663 smp_mb__before_atomic_inc();
88664- atomic_inc(&rdtp->dynticks_idle);
88665+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88666 smp_mb__after_atomic_inc();
88667- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88668+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88669 }
88670
88671 /*
88672@@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88673
88674 /* Record end of idle period. */
88675 smp_mb__before_atomic_inc();
88676- atomic_inc(&rdtp->dynticks_idle);
88677+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88678 smp_mb__after_atomic_inc();
88679- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88680+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88681
88682 /*
88683 * If we are the timekeeping CPU, we are permitted to be non-idle
88684@@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88685 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88686
88687 /* Pick up current idle and NMI-nesting counter and check. */
88688- cur = atomic_read(&rdtp->dynticks_idle);
88689+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88690 if (cur & 0x1) {
88691 *isidle = false; /* We are not idle! */
88692 return;
88693@@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88694 case RCU_SYSIDLE_NOT:
88695
88696 /* First time all are idle, so note a short idle period. */
88697- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88698+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88699 break;
88700
88701 case RCU_SYSIDLE_SHORT:
88702@@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88703 static void rcu_sysidle_cancel(void)
88704 {
88705 smp_mb();
88706- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88707+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88708 }
88709
88710 /*
88711@@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88712 smp_mb(); /* grace period precedes setting inuse. */
88713
88714 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88715- ACCESS_ONCE(rshp->inuse) = 0;
88716+ ACCESS_ONCE_RW(rshp->inuse) = 0;
88717 }
88718
88719 /*
88720diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88721index 3596797..f78391c 100644
88722--- a/kernel/rcu/tree_trace.c
88723+++ b/kernel/rcu/tree_trace.c
88724@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88725 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88726 rdp->passed_quiesce, rdp->qs_pending);
88727 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88728- atomic_read(&rdp->dynticks->dynticks),
88729+ atomic_read_unchecked(&rdp->dynticks->dynticks),
88730 rdp->dynticks->dynticks_nesting,
88731 rdp->dynticks->dynticks_nmi_nesting,
88732 rdp->dynticks_fqs);
88733@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88734 struct rcu_state *rsp = (struct rcu_state *)m->private;
88735
88736 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",
88737- atomic_long_read(&rsp->expedited_start),
88738+ atomic_long_read_unchecked(&rsp->expedited_start),
88739 atomic_long_read(&rsp->expedited_done),
88740- atomic_long_read(&rsp->expedited_wrap),
88741- atomic_long_read(&rsp->expedited_tryfail),
88742- atomic_long_read(&rsp->expedited_workdone1),
88743- atomic_long_read(&rsp->expedited_workdone2),
88744- atomic_long_read(&rsp->expedited_normal),
88745- atomic_long_read(&rsp->expedited_stoppedcpus),
88746- atomic_long_read(&rsp->expedited_done_tries),
88747- atomic_long_read(&rsp->expedited_done_lost),
88748- atomic_long_read(&rsp->expedited_done_exit));
88749+ atomic_long_read_unchecked(&rsp->expedited_wrap),
88750+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
88751+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
88752+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
88753+ atomic_long_read_unchecked(&rsp->expedited_normal),
88754+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88755+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
88756+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
88757+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
88758 return 0;
88759 }
88760
88761diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88762index 6cb3dff..dc5710f 100644
88763--- a/kernel/rcu/update.c
88764+++ b/kernel/rcu/update.c
88765@@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88766 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88767 */
88768 if (till_stall_check < 3) {
88769- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88770+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88771 till_stall_check = 3;
88772 } else if (till_stall_check > 300) {
88773- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88774+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88775 till_stall_check = 300;
88776 }
88777 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88778diff --git a/kernel/resource.c b/kernel/resource.c
88779index 3f285dc..5755f62 100644
88780--- a/kernel/resource.c
88781+++ b/kernel/resource.c
88782@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88783
88784 static int __init ioresources_init(void)
88785 {
88786+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88787+#ifdef CONFIG_GRKERNSEC_PROC_USER
88788+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88789+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88790+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88791+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88792+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88793+#endif
88794+#else
88795 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88796 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88797+#endif
88798 return 0;
88799 }
88800 __initcall(ioresources_init);
88801diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88802index 4a07353..66b5291 100644
88803--- a/kernel/sched/auto_group.c
88804+++ b/kernel/sched/auto_group.c
88805@@ -11,7 +11,7 @@
88806
88807 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88808 static struct autogroup autogroup_default;
88809-static atomic_t autogroup_seq_nr;
88810+static atomic_unchecked_t autogroup_seq_nr;
88811
88812 void __init autogroup_init(struct task_struct *init_task)
88813 {
88814@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88815
88816 kref_init(&ag->kref);
88817 init_rwsem(&ag->lock);
88818- ag->id = atomic_inc_return(&autogroup_seq_nr);
88819+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88820 ag->tg = tg;
88821 #ifdef CONFIG_RT_GROUP_SCHED
88822 /*
88823diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88824index a63f4dc..349bbb0 100644
88825--- a/kernel/sched/completion.c
88826+++ b/kernel/sched/completion.c
88827@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88828 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88829 * or number of jiffies left till timeout) if completed.
88830 */
88831-long __sched
88832+long __sched __intentional_overflow(-1)
88833 wait_for_completion_interruptible_timeout(struct completion *x,
88834 unsigned long timeout)
88835 {
88836@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88837 *
88838 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88839 */
88840-int __sched wait_for_completion_killable(struct completion *x)
88841+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88842 {
88843 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88844 if (t == -ERESTARTSYS)
88845@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88846 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88847 * or number of jiffies left till timeout) if completed.
88848 */
88849-long __sched
88850+long __sched __intentional_overflow(-1)
88851 wait_for_completion_killable_timeout(struct completion *x,
88852 unsigned long timeout)
88853 {
88854diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88855index c677510..132bb14 100644
88856--- a/kernel/sched/core.c
88857+++ b/kernel/sched/core.c
88858@@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
88859 int sysctl_numa_balancing(struct ctl_table *table, int write,
88860 void __user *buffer, size_t *lenp, loff_t *ppos)
88861 {
88862- struct ctl_table t;
88863+ ctl_table_no_const t;
88864 int err;
88865 int state = numabalancing_enabled;
88866
88867@@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
88868 /* convert nice value [19,-20] to rlimit style value [1,40] */
88869 int nice_rlim = 20 - nice;
88870
88871+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88872+
88873 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88874 capable(CAP_SYS_NICE));
88875 }
88876@@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88877 if (nice > 19)
88878 nice = 19;
88879
88880- if (increment < 0 && !can_nice(current, nice))
88881+ if (increment < 0 && (!can_nice(current, nice) ||
88882+ gr_handle_chroot_nice()))
88883 return -EPERM;
88884
88885 retval = security_task_setnice(current, nice);
88886@@ -3088,6 +3091,7 @@ recheck:
88887 unsigned long rlim_rtprio =
88888 task_rlimit(p, RLIMIT_RTPRIO);
88889
88890+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
88891 /* can't set/change the rt policy */
88892 if (policy != p->policy && !rlim_rtprio)
88893 return -EPERM;
88894@@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88895
88896 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88897
88898-static struct ctl_table sd_ctl_dir[] = {
88899+static ctl_table_no_const sd_ctl_dir[] __read_only = {
88900 {
88901 .procname = "sched_domain",
88902 .mode = 0555,
88903@@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
88904 {}
88905 };
88906
88907-static struct ctl_table *sd_alloc_ctl_entry(int n)
88908+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88909 {
88910- struct ctl_table *entry =
88911+ ctl_table_no_const *entry =
88912 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88913
88914 return entry;
88915 }
88916
88917-static void sd_free_ctl_entry(struct ctl_table **tablep)
88918+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88919 {
88920- struct ctl_table *entry;
88921+ ctl_table_no_const *entry;
88922
88923 /*
88924 * In the intermediate directories, both the child directory and
88925@@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88926 * will always be set. In the lowest directory the names are
88927 * static strings and all have proc handlers.
88928 */
88929- for (entry = *tablep; entry->mode; entry++) {
88930- if (entry->child)
88931- sd_free_ctl_entry(&entry->child);
88932+ for (entry = tablep; entry->mode; entry++) {
88933+ if (entry->child) {
88934+ sd_free_ctl_entry(entry->child);
88935+ pax_open_kernel();
88936+ entry->child = NULL;
88937+ pax_close_kernel();
88938+ }
88939 if (entry->proc_handler == NULL)
88940 kfree(entry->procname);
88941 }
88942
88943- kfree(*tablep);
88944- *tablep = NULL;
88945+ kfree(tablep);
88946 }
88947
88948 static int min_load_idx = 0;
88949 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88950
88951 static void
88952-set_table_entry(struct ctl_table *entry,
88953+set_table_entry(ctl_table_no_const *entry,
88954 const char *procname, void *data, int maxlen,
88955 umode_t mode, proc_handler *proc_handler,
88956 bool load_idx)
88957@@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
88958 static struct ctl_table *
88959 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88960 {
88961- struct ctl_table *table = sd_alloc_ctl_entry(13);
88962+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88963
88964 if (table == NULL)
88965 return NULL;
88966@@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88967 return table;
88968 }
88969
88970-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88971+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88972 {
88973- struct ctl_table *entry, *table;
88974+ ctl_table_no_const *entry, *table;
88975 struct sched_domain *sd;
88976 int domain_num = 0, i;
88977 char buf[32];
88978@@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
88979 static void register_sched_domain_sysctl(void)
88980 {
88981 int i, cpu_num = num_possible_cpus();
88982- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88983+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88984 char buf[32];
88985
88986 WARN_ON(sd_ctl_dir[0].child);
88987+ pax_open_kernel();
88988 sd_ctl_dir[0].child = entry;
88989+ pax_close_kernel();
88990
88991 if (entry == NULL)
88992 return;
88993@@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
88994 if (sd_sysctl_header)
88995 unregister_sysctl_table(sd_sysctl_header);
88996 sd_sysctl_header = NULL;
88997- if (sd_ctl_dir[0].child)
88998- sd_free_ctl_entry(&sd_ctl_dir[0].child);
88999+ if (sd_ctl_dir[0].child) {
89000+ sd_free_ctl_entry(sd_ctl_dir[0].child);
89001+ pax_open_kernel();
89002+ sd_ctl_dir[0].child = NULL;
89003+ pax_close_kernel();
89004+ }
89005 }
89006 #else
89007 static void register_sched_domain_sysctl(void)
89008diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
89009index ce501de..1805320 100644
89010--- a/kernel/sched/fair.c
89011+++ b/kernel/sched/fair.c
89012@@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
89013
89014 static void reset_ptenuma_scan(struct task_struct *p)
89015 {
89016- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89017+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89018 p->mm->numa_scan_offset = 0;
89019 }
89020
89021@@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
89022 * run_rebalance_domains is triggered when needed from the scheduler tick.
89023 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89024 */
89025-static void run_rebalance_domains(struct softirq_action *h)
89026+static __latent_entropy void run_rebalance_domains(void)
89027 {
89028 int this_cpu = smp_processor_id();
89029 struct rq *this_rq = cpu_rq(this_cpu);
89030diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89031index 88c85b2..a1dec86 100644
89032--- a/kernel/sched/sched.h
89033+++ b/kernel/sched/sched.h
89034@@ -1035,7 +1035,7 @@ struct sched_class {
89035 #ifdef CONFIG_FAIR_GROUP_SCHED
89036 void (*task_move_group) (struct task_struct *p, int on_rq);
89037 #endif
89038-};
89039+} __do_const;
89040
89041 #define sched_class_highest (&stop_sched_class)
89042 #define for_each_class(class) \
89043diff --git a/kernel/signal.c b/kernel/signal.c
89044index 940b30e..7fd6041 100644
89045--- a/kernel/signal.c
89046+++ b/kernel/signal.c
89047@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89048
89049 int print_fatal_signals __read_mostly;
89050
89051-static void __user *sig_handler(struct task_struct *t, int sig)
89052+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89053 {
89054 return t->sighand->action[sig - 1].sa.sa_handler;
89055 }
89056
89057-static int sig_handler_ignored(void __user *handler, int sig)
89058+static int sig_handler_ignored(__sighandler_t handler, int sig)
89059 {
89060 /* Is it explicitly or implicitly ignored? */
89061 return handler == SIG_IGN ||
89062@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89063
89064 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89065 {
89066- void __user *handler;
89067+ __sighandler_t handler;
89068
89069 handler = sig_handler(t, sig);
89070
89071@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89072 atomic_inc(&user->sigpending);
89073 rcu_read_unlock();
89074
89075+ if (!override_rlimit)
89076+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89077+
89078 if (override_rlimit ||
89079 atomic_read(&user->sigpending) <=
89080 task_rlimit(t, RLIMIT_SIGPENDING)) {
89081@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89082
89083 int unhandled_signal(struct task_struct *tsk, int sig)
89084 {
89085- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89086+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89087 if (is_global_init(tsk))
89088 return 1;
89089 if (handler != SIG_IGN && handler != SIG_DFL)
89090@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89091 }
89092 }
89093
89094+ /* allow glibc communication via tgkill to other threads in our
89095+ thread group */
89096+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89097+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89098+ && gr_handle_signal(t, sig))
89099+ return -EPERM;
89100+
89101 return security_task_kill(t, info, sig, 0);
89102 }
89103
89104@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89105 return send_signal(sig, info, p, 1);
89106 }
89107
89108-static int
89109+int
89110 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89111 {
89112 return send_signal(sig, info, t, 0);
89113@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89114 unsigned long int flags;
89115 int ret, blocked, ignored;
89116 struct k_sigaction *action;
89117+ int is_unhandled = 0;
89118
89119 spin_lock_irqsave(&t->sighand->siglock, flags);
89120 action = &t->sighand->action[sig-1];
89121@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89122 }
89123 if (action->sa.sa_handler == SIG_DFL)
89124 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89125+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89126+ is_unhandled = 1;
89127 ret = specific_send_sig_info(sig, info, t);
89128 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89129
89130+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89131+ normal operation */
89132+ if (is_unhandled) {
89133+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89134+ gr_handle_crash(t, sig);
89135+ }
89136+
89137 return ret;
89138 }
89139
89140@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89141 ret = check_kill_permission(sig, info, p);
89142 rcu_read_unlock();
89143
89144- if (!ret && sig)
89145+ if (!ret && sig) {
89146 ret = do_send_sig_info(sig, info, p, true);
89147+ if (!ret)
89148+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89149+ }
89150
89151 return ret;
89152 }
89153@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89154 int error = -ESRCH;
89155
89156 rcu_read_lock();
89157- p = find_task_by_vpid(pid);
89158+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89159+ /* allow glibc communication via tgkill to other threads in our
89160+ thread group */
89161+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89162+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89163+ p = find_task_by_vpid_unrestricted(pid);
89164+ else
89165+#endif
89166+ p = find_task_by_vpid(pid);
89167 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89168 error = check_kill_permission(sig, info, p);
89169 /*
89170@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89171 }
89172 seg = get_fs();
89173 set_fs(KERNEL_DS);
89174- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89175- (stack_t __force __user *) &uoss,
89176+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89177+ (stack_t __force_user *) &uoss,
89178 compat_user_stack_pointer());
89179 set_fs(seg);
89180 if (ret >= 0 && uoss_ptr) {
89181diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89182index eb89e18..a4e6792 100644
89183--- a/kernel/smpboot.c
89184+++ b/kernel/smpboot.c
89185@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89186 }
89187 smpboot_unpark_thread(plug_thread, cpu);
89188 }
89189- list_add(&plug_thread->list, &hotplug_threads);
89190+ pax_list_add(&plug_thread->list, &hotplug_threads);
89191 out:
89192 mutex_unlock(&smpboot_threads_lock);
89193 return ret;
89194@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89195 {
89196 get_online_cpus();
89197 mutex_lock(&smpboot_threads_lock);
89198- list_del(&plug_thread->list);
89199+ pax_list_del(&plug_thread->list);
89200 smpboot_destroy_threads(plug_thread);
89201 mutex_unlock(&smpboot_threads_lock);
89202 put_online_cpus();
89203diff --git a/kernel/softirq.c b/kernel/softirq.c
89204index 11025cc..bc0e4dc 100644
89205--- a/kernel/softirq.c
89206+++ b/kernel/softirq.c
89207@@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89208 EXPORT_SYMBOL(irq_stat);
89209 #endif
89210
89211-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89212+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89213
89214 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89215
89216-char *softirq_to_name[NR_SOFTIRQS] = {
89217+const char * const softirq_to_name[NR_SOFTIRQS] = {
89218 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89219 "TASKLET", "SCHED", "HRTIMER", "RCU"
89220 };
89221@@ -250,7 +250,7 @@ restart:
89222 kstat_incr_softirqs_this_cpu(vec_nr);
89223
89224 trace_softirq_entry(vec_nr);
89225- h->action(h);
89226+ h->action();
89227 trace_softirq_exit(vec_nr);
89228 if (unlikely(prev_count != preempt_count())) {
89229 printk(KERN_ERR "huh, entered softirq %u %s %p"
89230@@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89231 or_softirq_pending(1UL << nr);
89232 }
89233
89234-void open_softirq(int nr, void (*action)(struct softirq_action *))
89235+void __init open_softirq(int nr, void (*action)(void))
89236 {
89237 softirq_vec[nr].action = action;
89238 }
89239@@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89240
89241 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89242
89243-static void tasklet_action(struct softirq_action *a)
89244+static __latent_entropy void tasklet_action(void)
89245 {
89246 struct tasklet_struct *list;
89247
89248@@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89249 }
89250 }
89251
89252-static void tasklet_hi_action(struct softirq_action *a)
89253+static __latent_entropy void tasklet_hi_action(void)
89254 {
89255 struct tasklet_struct *list;
89256
89257@@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89258 .notifier_call = cpu_callback
89259 };
89260
89261-static struct smp_hotplug_thread softirq_threads = {
89262+static struct smp_hotplug_thread softirq_threads __read_only = {
89263 .store = &ksoftirqd,
89264 .thread_should_run = ksoftirqd_should_run,
89265 .thread_fn = run_ksoftirqd,
89266diff --git a/kernel/sys.c b/kernel/sys.c
89267index c723113..46bf922 100644
89268--- a/kernel/sys.c
89269+++ b/kernel/sys.c
89270@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89271 error = -EACCES;
89272 goto out;
89273 }
89274+
89275+ if (gr_handle_chroot_setpriority(p, niceval)) {
89276+ error = -EACCES;
89277+ goto out;
89278+ }
89279+
89280 no_nice = security_task_setnice(p, niceval);
89281 if (no_nice) {
89282 error = no_nice;
89283@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89284 goto error;
89285 }
89286
89287+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89288+ goto error;
89289+
89290 if (rgid != (gid_t) -1 ||
89291 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89292 new->sgid = new->egid;
89293@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89294 old = current_cred();
89295
89296 retval = -EPERM;
89297+
89298+ if (gr_check_group_change(kgid, kgid, kgid))
89299+ goto error;
89300+
89301 if (ns_capable(old->user_ns, CAP_SETGID))
89302 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89303 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89304@@ -403,7 +416,7 @@ error:
89305 /*
89306 * change the user struct in a credentials set to match the new UID
89307 */
89308-static int set_user(struct cred *new)
89309+int set_user(struct cred *new)
89310 {
89311 struct user_struct *new_user;
89312
89313@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89314 goto error;
89315 }
89316
89317+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89318+ goto error;
89319+
89320 if (!uid_eq(new->uid, old->uid)) {
89321 retval = set_user(new);
89322 if (retval < 0)
89323@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89324 old = current_cred();
89325
89326 retval = -EPERM;
89327+
89328+ if (gr_check_crash_uid(kuid))
89329+ goto error;
89330+ if (gr_check_user_change(kuid, kuid, kuid))
89331+ goto error;
89332+
89333 if (ns_capable(old->user_ns, CAP_SETUID)) {
89334 new->suid = new->uid = kuid;
89335 if (!uid_eq(kuid, old->uid)) {
89336@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89337 goto error;
89338 }
89339
89340+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89341+ goto error;
89342+
89343 if (ruid != (uid_t) -1) {
89344 new->uid = kruid;
89345 if (!uid_eq(kruid, old->uid)) {
89346@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89347 goto error;
89348 }
89349
89350+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89351+ goto error;
89352+
89353 if (rgid != (gid_t) -1)
89354 new->gid = krgid;
89355 if (egid != (gid_t) -1)
89356@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89357 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89358 ns_capable(old->user_ns, CAP_SETUID)) {
89359 if (!uid_eq(kuid, old->fsuid)) {
89360+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89361+ goto error;
89362+
89363 new->fsuid = kuid;
89364 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89365 goto change_okay;
89366 }
89367 }
89368
89369+error:
89370 abort_creds(new);
89371 return old_fsuid;
89372
89373@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89374 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89375 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89376 ns_capable(old->user_ns, CAP_SETGID)) {
89377+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89378+ goto error;
89379+
89380 if (!gid_eq(kgid, old->fsgid)) {
89381 new->fsgid = kgid;
89382 goto change_okay;
89383 }
89384 }
89385
89386+error:
89387 abort_creds(new);
89388 return old_fsgid;
89389
89390@@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89391 return -EFAULT;
89392
89393 down_read(&uts_sem);
89394- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89395+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89396 __OLD_UTS_LEN);
89397 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89398- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89399+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89400 __OLD_UTS_LEN);
89401 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89402- error |= __copy_to_user(&name->release, &utsname()->release,
89403+ error |= __copy_to_user(name->release, &utsname()->release,
89404 __OLD_UTS_LEN);
89405 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89406- error |= __copy_to_user(&name->version, &utsname()->version,
89407+ error |= __copy_to_user(name->version, &utsname()->version,
89408 __OLD_UTS_LEN);
89409 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89410- error |= __copy_to_user(&name->machine, &utsname()->machine,
89411+ error |= __copy_to_user(name->machine, &utsname()->machine,
89412 __OLD_UTS_LEN);
89413 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89414 up_read(&uts_sem);
89415@@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89416 */
89417 new_rlim->rlim_cur = 1;
89418 }
89419+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89420+ is changed to a lower value. Since tasks can be created by the same
89421+ user in between this limit change and an execve by this task, force
89422+ a recheck only for this task by setting PF_NPROC_EXCEEDED
89423+ */
89424+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89425+ tsk->flags |= PF_NPROC_EXCEEDED;
89426 }
89427 if (!retval) {
89428 if (old_rlim)
89429diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89430index 06962ba..a54d45e 100644
89431--- a/kernel/sysctl.c
89432+++ b/kernel/sysctl.c
89433@@ -93,7 +93,6 @@
89434
89435
89436 #if defined(CONFIG_SYSCTL)
89437-
89438 /* External variables not in a header file. */
89439 extern int sysctl_overcommit_memory;
89440 extern int sysctl_overcommit_ratio;
89441@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89442
89443 /* Constants used for minimum and maximum */
89444 #ifdef CONFIG_LOCKUP_DETECTOR
89445-static int sixty = 60;
89446+static int sixty __read_only = 60;
89447 #endif
89448
89449-static int zero;
89450-static int __maybe_unused one = 1;
89451-static int __maybe_unused two = 2;
89452-static int __maybe_unused three = 3;
89453-static unsigned long one_ul = 1;
89454-static int one_hundred = 100;
89455+static int neg_one __read_only = -1;
89456+static int zero __read_only = 0;
89457+static int __maybe_unused one __read_only = 1;
89458+static int __maybe_unused two __read_only = 2;
89459+static int __maybe_unused three __read_only = 3;
89460+static unsigned long one_ul __read_only = 1;
89461+static int one_hundred __read_only = 100;
89462 #ifdef CONFIG_PRINTK
89463-static int ten_thousand = 10000;
89464+static int ten_thousand __read_only = 10000;
89465 #endif
89466
89467 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89468@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89469 void __user *buffer, size_t *lenp, loff_t *ppos);
89470 #endif
89471
89472-#ifdef CONFIG_PRINTK
89473 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89474 void __user *buffer, size_t *lenp, loff_t *ppos);
89475-#endif
89476
89477 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89478 void __user *buffer, size_t *lenp, loff_t *ppos);
89479@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89480
89481 #endif
89482
89483+extern struct ctl_table grsecurity_table[];
89484+
89485 static struct ctl_table kern_table[];
89486 static struct ctl_table vm_table[];
89487 static struct ctl_table fs_table[];
89488@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89489 int sysctl_legacy_va_layout;
89490 #endif
89491
89492+#ifdef CONFIG_PAX_SOFTMODE
89493+static ctl_table pax_table[] = {
89494+ {
89495+ .procname = "softmode",
89496+ .data = &pax_softmode,
89497+ .maxlen = sizeof(unsigned int),
89498+ .mode = 0600,
89499+ .proc_handler = &proc_dointvec,
89500+ },
89501+
89502+ { }
89503+};
89504+#endif
89505+
89506 /* The default sysctl tables: */
89507
89508 static struct ctl_table sysctl_base_table[] = {
89509@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89510 #endif
89511
89512 static struct ctl_table kern_table[] = {
89513+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89514+ {
89515+ .procname = "grsecurity",
89516+ .mode = 0500,
89517+ .child = grsecurity_table,
89518+ },
89519+#endif
89520+
89521+#ifdef CONFIG_PAX_SOFTMODE
89522+ {
89523+ .procname = "pax",
89524+ .mode = 0500,
89525+ .child = pax_table,
89526+ },
89527+#endif
89528+
89529 {
89530 .procname = "sched_child_runs_first",
89531 .data = &sysctl_sched_child_runs_first,
89532@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89533 .data = &modprobe_path,
89534 .maxlen = KMOD_PATH_LEN,
89535 .mode = 0644,
89536- .proc_handler = proc_dostring,
89537+ .proc_handler = proc_dostring_modpriv,
89538 },
89539 {
89540 .procname = "modules_disabled",
89541@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89542 .extra1 = &zero,
89543 .extra2 = &one,
89544 },
89545+#endif
89546 {
89547 .procname = "kptr_restrict",
89548 .data = &kptr_restrict,
89549 .maxlen = sizeof(int),
89550 .mode = 0644,
89551 .proc_handler = proc_dointvec_minmax_sysadmin,
89552+#ifdef CONFIG_GRKERNSEC_HIDESYM
89553+ .extra1 = &two,
89554+#else
89555 .extra1 = &zero,
89556+#endif
89557 .extra2 = &two,
89558 },
89559-#endif
89560 {
89561 .procname = "ngroups_max",
89562 .data = &ngroups_max,
89563@@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89564 */
89565 {
89566 .procname = "perf_event_paranoid",
89567- .data = &sysctl_perf_event_paranoid,
89568- .maxlen = sizeof(sysctl_perf_event_paranoid),
89569+ .data = &sysctl_perf_event_legitimately_concerned,
89570+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89571 .mode = 0644,
89572- .proc_handler = proc_dointvec,
89573+ /* go ahead, be a hero */
89574+ .proc_handler = proc_dointvec_minmax_sysadmin,
89575+ .extra1 = &neg_one,
89576+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89577+ .extra2 = &three,
89578+#else
89579+ .extra2 = &two,
89580+#endif
89581 },
89582 {
89583 .procname = "perf_event_mlock_kb",
89584@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89585 .proc_handler = proc_dointvec_minmax,
89586 .extra1 = &zero,
89587 },
89588+ {
89589+ .procname = "heap_stack_gap",
89590+ .data = &sysctl_heap_stack_gap,
89591+ .maxlen = sizeof(sysctl_heap_stack_gap),
89592+ .mode = 0644,
89593+ .proc_handler = proc_doulongvec_minmax,
89594+ },
89595 #else
89596 {
89597 .procname = "nr_trim_pages",
89598@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89599 buffer, lenp, ppos);
89600 }
89601
89602+int proc_dostring_modpriv(struct ctl_table *table, int write,
89603+ void __user *buffer, size_t *lenp, loff_t *ppos)
89604+{
89605+ if (write && !capable(CAP_SYS_MODULE))
89606+ return -EPERM;
89607+
89608+ return _proc_do_string(table->data, table->maxlen, write,
89609+ buffer, lenp, ppos);
89610+}
89611+
89612 static size_t proc_skip_spaces(char **buf)
89613 {
89614 size_t ret;
89615@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89616 len = strlen(tmp);
89617 if (len > *size)
89618 len = *size;
89619+ if (len > sizeof(tmp))
89620+ len = sizeof(tmp);
89621 if (copy_to_user(*buf, tmp, len))
89622 return -EFAULT;
89623 *size -= len;
89624@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89625 static int proc_taint(struct ctl_table *table, int write,
89626 void __user *buffer, size_t *lenp, loff_t *ppos)
89627 {
89628- struct ctl_table t;
89629+ ctl_table_no_const t;
89630 unsigned long tmptaint = get_taint();
89631 int err;
89632
89633@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89634 return err;
89635 }
89636
89637-#ifdef CONFIG_PRINTK
89638 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89639 void __user *buffer, size_t *lenp, loff_t *ppos)
89640 {
89641@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89642
89643 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89644 }
89645-#endif
89646
89647 struct do_proc_dointvec_minmax_conv_param {
89648 int *min;
89649@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89650 return -ENOSYS;
89651 }
89652
89653+int proc_dostring_modpriv(struct ctl_table *table, int write,
89654+ void __user *buffer, size_t *lenp, loff_t *ppos)
89655+{
89656+ return -ENOSYS;
89657+}
89658+
89659 int proc_dointvec(struct ctl_table *table, int write,
89660 void __user *buffer, size_t *lenp, loff_t *ppos)
89661 {
89662@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89663 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89664 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89665 EXPORT_SYMBOL(proc_dostring);
89666+EXPORT_SYMBOL(proc_dostring_modpriv);
89667 EXPORT_SYMBOL(proc_doulongvec_minmax);
89668 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89669diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89670index 13d2f7c..c93d0b0 100644
89671--- a/kernel/taskstats.c
89672+++ b/kernel/taskstats.c
89673@@ -28,9 +28,12 @@
89674 #include <linux/fs.h>
89675 #include <linux/file.h>
89676 #include <linux/pid_namespace.h>
89677+#include <linux/grsecurity.h>
89678 #include <net/genetlink.h>
89679 #include <linux/atomic.h>
89680
89681+extern int gr_is_taskstats_denied(int pid);
89682+
89683 /*
89684 * Maximum length of a cpumask that can be specified in
89685 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89686@@ -576,6 +579,9 @@ err:
89687
89688 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89689 {
89690+ if (gr_is_taskstats_denied(current->pid))
89691+ return -EACCES;
89692+
89693 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89694 return cmd_attr_register_cpumask(info);
89695 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89696diff --git a/kernel/time.c b/kernel/time.c
89697index 7c7964c..2a0d412 100644
89698--- a/kernel/time.c
89699+++ b/kernel/time.c
89700@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89701 return error;
89702
89703 if (tz) {
89704+ /* we log in do_settimeofday called below, so don't log twice
89705+ */
89706+ if (!tv)
89707+ gr_log_timechange();
89708+
89709 sys_tz = *tz;
89710 update_vsyscall_tz();
89711 if (firsttime) {
89712diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89713index 88c9c65..7497ebc 100644
89714--- a/kernel/time/alarmtimer.c
89715+++ b/kernel/time/alarmtimer.c
89716@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89717 struct platform_device *pdev;
89718 int error = 0;
89719 int i;
89720- struct k_clock alarm_clock = {
89721+ static struct k_clock alarm_clock = {
89722 .clock_getres = alarm_clock_getres,
89723 .clock_get = alarm_clock_get,
89724 .timer_create = alarm_timer_create,
89725diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89726index b415457..c26876d 100644
89727--- a/kernel/time/timekeeping.c
89728+++ b/kernel/time/timekeeping.c
89729@@ -15,6 +15,7 @@
89730 #include <linux/init.h>
89731 #include <linux/mm.h>
89732 #include <linux/sched.h>
89733+#include <linux/grsecurity.h>
89734 #include <linux/syscore_ops.h>
89735 #include <linux/clocksource.h>
89736 #include <linux/jiffies.h>
89737@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89738 if (!timespec_valid_strict(tv))
89739 return -EINVAL;
89740
89741+ gr_log_timechange();
89742+
89743 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89744 write_seqcount_begin(&timekeeper_seq);
89745
89746diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89747index 61ed862..3b52c65 100644
89748--- a/kernel/time/timer_list.c
89749+++ b/kernel/time/timer_list.c
89750@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89751
89752 static void print_name_offset(struct seq_file *m, void *sym)
89753 {
89754+#ifdef CONFIG_GRKERNSEC_HIDESYM
89755+ SEQ_printf(m, "<%p>", NULL);
89756+#else
89757 char symname[KSYM_NAME_LEN];
89758
89759 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89760 SEQ_printf(m, "<%pK>", sym);
89761 else
89762 SEQ_printf(m, "%s", symname);
89763+#endif
89764 }
89765
89766 static void
89767@@ -119,7 +123,11 @@ next_one:
89768 static void
89769 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89770 {
89771+#ifdef CONFIG_GRKERNSEC_HIDESYM
89772+ SEQ_printf(m, " .base: %p\n", NULL);
89773+#else
89774 SEQ_printf(m, " .base: %pK\n", base);
89775+#endif
89776 SEQ_printf(m, " .index: %d\n",
89777 base->index);
89778 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89779@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89780 {
89781 struct proc_dir_entry *pe;
89782
89783+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89784+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89785+#else
89786 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89787+#endif
89788 if (!pe)
89789 return -ENOMEM;
89790 return 0;
89791diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89792index 1fb08f2..ca4bb1e 100644
89793--- a/kernel/time/timer_stats.c
89794+++ b/kernel/time/timer_stats.c
89795@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89796 static unsigned long nr_entries;
89797 static struct entry entries[MAX_ENTRIES];
89798
89799-static atomic_t overflow_count;
89800+static atomic_unchecked_t overflow_count;
89801
89802 /*
89803 * The entries are in a hash-table, for fast lookup:
89804@@ -140,7 +140,7 @@ static void reset_entries(void)
89805 nr_entries = 0;
89806 memset(entries, 0, sizeof(entries));
89807 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89808- atomic_set(&overflow_count, 0);
89809+ atomic_set_unchecked(&overflow_count, 0);
89810 }
89811
89812 static struct entry *alloc_entry(void)
89813@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89814 if (likely(entry))
89815 entry->count++;
89816 else
89817- atomic_inc(&overflow_count);
89818+ atomic_inc_unchecked(&overflow_count);
89819
89820 out_unlock:
89821 raw_spin_unlock_irqrestore(lock, flags);
89822@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89823
89824 static void print_name_offset(struct seq_file *m, unsigned long addr)
89825 {
89826+#ifdef CONFIG_GRKERNSEC_HIDESYM
89827+ seq_printf(m, "<%p>", NULL);
89828+#else
89829 char symname[KSYM_NAME_LEN];
89830
89831 if (lookup_symbol_name(addr, symname) < 0)
89832- seq_printf(m, "<%p>", (void *)addr);
89833+ seq_printf(m, "<%pK>", (void *)addr);
89834 else
89835 seq_printf(m, "%s", symname);
89836+#endif
89837 }
89838
89839 static int tstats_show(struct seq_file *m, void *v)
89840@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89841
89842 seq_puts(m, "Timer Stats Version: v0.3\n");
89843 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89844- if (atomic_read(&overflow_count))
89845- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89846+ if (atomic_read_unchecked(&overflow_count))
89847+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89848 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89849
89850 for (i = 0; i < nr_entries; i++) {
89851@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89852 {
89853 struct proc_dir_entry *pe;
89854
89855+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89856+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89857+#else
89858 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89859+#endif
89860 if (!pe)
89861 return -ENOMEM;
89862 return 0;
89863diff --git a/kernel/timer.c b/kernel/timer.c
89864index accfd24..e00f0c0 100644
89865--- a/kernel/timer.c
89866+++ b/kernel/timer.c
89867@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89868 /*
89869 * This function runs timers and the timer-tq in bottom half context.
89870 */
89871-static void run_timer_softirq(struct softirq_action *h)
89872+static __latent_entropy void run_timer_softirq(void)
89873 {
89874 struct tvec_base *base = __this_cpu_read(tvec_bases);
89875
89876@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89877 *
89878 * In all cases the return value is guaranteed to be non-negative.
89879 */
89880-signed long __sched schedule_timeout(signed long timeout)
89881+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89882 {
89883 struct timer_list timer;
89884 unsigned long expire;
89885diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89886index f785aef..59f1b18 100644
89887--- a/kernel/trace/blktrace.c
89888+++ b/kernel/trace/blktrace.c
89889@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89890 struct blk_trace *bt = filp->private_data;
89891 char buf[16];
89892
89893- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89894+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89895
89896 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89897 }
89898@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89899 return 1;
89900
89901 bt = buf->chan->private_data;
89902- atomic_inc(&bt->dropped);
89903+ atomic_inc_unchecked(&bt->dropped);
89904 return 0;
89905 }
89906
89907@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89908
89909 bt->dir = dir;
89910 bt->dev = dev;
89911- atomic_set(&bt->dropped, 0);
89912+ atomic_set_unchecked(&bt->dropped, 0);
89913 INIT_LIST_HEAD(&bt->running_list);
89914
89915 ret = -EIO;
89916diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89917index 38463d2..68abe92 100644
89918--- a/kernel/trace/ftrace.c
89919+++ b/kernel/trace/ftrace.c
89920@@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89921 if (unlikely(ftrace_disabled))
89922 return 0;
89923
89924+ ret = ftrace_arch_code_modify_prepare();
89925+ FTRACE_WARN_ON(ret);
89926+ if (ret)
89927+ return 0;
89928+
89929 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89930+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89931 if (ret) {
89932 ftrace_bug(ret, ip);
89933- return 0;
89934 }
89935- return 1;
89936+ return ret ? 0 : 1;
89937 }
89938
89939 /*
89940@@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
89941 if (!count)
89942 return 0;
89943
89944+ pax_open_kernel();
89945 sort(start, count, sizeof(*start),
89946 ftrace_cmp_ips, ftrace_swap_ips);
89947+ pax_close_kernel();
89948
89949 start_pg = ftrace_allocate_pages(count);
89950 if (!start_pg)
89951@@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89952 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89953
89954 static int ftrace_graph_active;
89955-static struct notifier_block ftrace_suspend_notifier;
89956-
89957 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89958 {
89959 return 0;
89960@@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
89961 ftrace_graph_entry = ftrace_graph_entry_test;
89962 }
89963
89964+static struct notifier_block ftrace_suspend_notifier = {
89965+ .notifier_call = ftrace_suspend_notifier_call
89966+};
89967+
89968 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89969 trace_func_graph_ent_t entryfunc)
89970 {
89971@@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89972 goto out;
89973 }
89974
89975- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89976 register_pm_notifier(&ftrace_suspend_notifier);
89977
89978 ftrace_graph_active++;
89979diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89980index 0e337ee..3370631 100644
89981--- a/kernel/trace/ring_buffer.c
89982+++ b/kernel/trace/ring_buffer.c
89983@@ -352,9 +352,9 @@ struct buffer_data_page {
89984 */
89985 struct buffer_page {
89986 struct list_head list; /* list of buffer pages */
89987- local_t write; /* index for next write */
89988+ local_unchecked_t write; /* index for next write */
89989 unsigned read; /* index for next read */
89990- local_t entries; /* entries on this page */
89991+ local_unchecked_t entries; /* entries on this page */
89992 unsigned long real_end; /* real end of data */
89993 struct buffer_data_page *page; /* Actual data page */
89994 };
89995@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
89996 unsigned long last_overrun;
89997 local_t entries_bytes;
89998 local_t entries;
89999- local_t overrun;
90000- local_t commit_overrun;
90001+ local_unchecked_t overrun;
90002+ local_unchecked_t commit_overrun;
90003 local_t dropped_events;
90004 local_t committing;
90005 local_t commits;
90006@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90007 *
90008 * We add a counter to the write field to denote this.
90009 */
90010- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
90011- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
90012+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
90013+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
90014
90015 /*
90016 * Just make sure we have seen our old_write and synchronize
90017@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90018 * cmpxchg to only update if an interrupt did not already
90019 * do it for us. If the cmpxchg fails, we don't care.
90020 */
90021- (void)local_cmpxchg(&next_page->write, old_write, val);
90022- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90023+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90024+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90025
90026 /*
90027 * No need to worry about races with clearing out the commit.
90028@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90029
90030 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90031 {
90032- return local_read(&bpage->entries) & RB_WRITE_MASK;
90033+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90034 }
90035
90036 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90037 {
90038- return local_read(&bpage->write) & RB_WRITE_MASK;
90039+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90040 }
90041
90042 static int
90043@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90044 * bytes consumed in ring buffer from here.
90045 * Increment overrun to account for the lost events.
90046 */
90047- local_add(page_entries, &cpu_buffer->overrun);
90048+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90049 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90050 }
90051
90052@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90053 * it is our responsibility to update
90054 * the counters.
90055 */
90056- local_add(entries, &cpu_buffer->overrun);
90057+ local_add_unchecked(entries, &cpu_buffer->overrun);
90058 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90059
90060 /*
90061@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90062 if (tail == BUF_PAGE_SIZE)
90063 tail_page->real_end = 0;
90064
90065- local_sub(length, &tail_page->write);
90066+ local_sub_unchecked(length, &tail_page->write);
90067 return;
90068 }
90069
90070@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90071 rb_event_set_padding(event);
90072
90073 /* Set the write back to the previous setting */
90074- local_sub(length, &tail_page->write);
90075+ local_sub_unchecked(length, &tail_page->write);
90076 return;
90077 }
90078
90079@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90080
90081 /* Set write to end of buffer */
90082 length = (tail + length) - BUF_PAGE_SIZE;
90083- local_sub(length, &tail_page->write);
90084+ local_sub_unchecked(length, &tail_page->write);
90085 }
90086
90087 /*
90088@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90089 * about it.
90090 */
90091 if (unlikely(next_page == commit_page)) {
90092- local_inc(&cpu_buffer->commit_overrun);
90093+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90094 goto out_reset;
90095 }
90096
90097@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90098 cpu_buffer->tail_page) &&
90099 (cpu_buffer->commit_page ==
90100 cpu_buffer->reader_page))) {
90101- local_inc(&cpu_buffer->commit_overrun);
90102+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90103 goto out_reset;
90104 }
90105 }
90106@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90107 length += RB_LEN_TIME_EXTEND;
90108
90109 tail_page = cpu_buffer->tail_page;
90110- write = local_add_return(length, &tail_page->write);
90111+ write = local_add_return_unchecked(length, &tail_page->write);
90112
90113 /* set write to only the index of the write */
90114 write &= RB_WRITE_MASK;
90115@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90116 kmemcheck_annotate_bitfield(event, bitfield);
90117 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90118
90119- local_inc(&tail_page->entries);
90120+ local_inc_unchecked(&tail_page->entries);
90121
90122 /*
90123 * If this is the first commit on the page, then update
90124@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90125
90126 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90127 unsigned long write_mask =
90128- local_read(&bpage->write) & ~RB_WRITE_MASK;
90129+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90130 unsigned long event_length = rb_event_length(event);
90131 /*
90132 * This is on the tail page. It is possible that
90133@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90134 */
90135 old_index += write_mask;
90136 new_index += write_mask;
90137- index = local_cmpxchg(&bpage->write, old_index, new_index);
90138+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90139 if (index == old_index) {
90140 /* update counters */
90141 local_sub(event_length, &cpu_buffer->entries_bytes);
90142@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90143
90144 /* Do the likely case first */
90145 if (likely(bpage->page == (void *)addr)) {
90146- local_dec(&bpage->entries);
90147+ local_dec_unchecked(&bpage->entries);
90148 return;
90149 }
90150
90151@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90152 start = bpage;
90153 do {
90154 if (bpage->page == (void *)addr) {
90155- local_dec(&bpage->entries);
90156+ local_dec_unchecked(&bpage->entries);
90157 return;
90158 }
90159 rb_inc_page(cpu_buffer, &bpage);
90160@@ -3146,7 +3146,7 @@ static inline unsigned long
90161 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90162 {
90163 return local_read(&cpu_buffer->entries) -
90164- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90165+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90166 }
90167
90168 /**
90169@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90170 return 0;
90171
90172 cpu_buffer = buffer->buffers[cpu];
90173- ret = local_read(&cpu_buffer->overrun);
90174+ ret = local_read_unchecked(&cpu_buffer->overrun);
90175
90176 return ret;
90177 }
90178@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90179 return 0;
90180
90181 cpu_buffer = buffer->buffers[cpu];
90182- ret = local_read(&cpu_buffer->commit_overrun);
90183+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90184
90185 return ret;
90186 }
90187@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90188 /* if you care about this being correct, lock the buffer */
90189 for_each_buffer_cpu(buffer, cpu) {
90190 cpu_buffer = buffer->buffers[cpu];
90191- overruns += local_read(&cpu_buffer->overrun);
90192+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90193 }
90194
90195 return overruns;
90196@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90197 /*
90198 * Reset the reader page to size zero.
90199 */
90200- local_set(&cpu_buffer->reader_page->write, 0);
90201- local_set(&cpu_buffer->reader_page->entries, 0);
90202+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90203+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90204 local_set(&cpu_buffer->reader_page->page->commit, 0);
90205 cpu_buffer->reader_page->real_end = 0;
90206
90207@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90208 * want to compare with the last_overrun.
90209 */
90210 smp_mb();
90211- overwrite = local_read(&(cpu_buffer->overrun));
90212+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90213
90214 /*
90215 * Here's the tricky part.
90216@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90217
90218 cpu_buffer->head_page
90219 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90220- local_set(&cpu_buffer->head_page->write, 0);
90221- local_set(&cpu_buffer->head_page->entries, 0);
90222+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90223+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90224 local_set(&cpu_buffer->head_page->page->commit, 0);
90225
90226 cpu_buffer->head_page->read = 0;
90227@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90228
90229 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90230 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90231- local_set(&cpu_buffer->reader_page->write, 0);
90232- local_set(&cpu_buffer->reader_page->entries, 0);
90233+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90234+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90235 local_set(&cpu_buffer->reader_page->page->commit, 0);
90236 cpu_buffer->reader_page->read = 0;
90237
90238 local_set(&cpu_buffer->entries_bytes, 0);
90239- local_set(&cpu_buffer->overrun, 0);
90240- local_set(&cpu_buffer->commit_overrun, 0);
90241+ local_set_unchecked(&cpu_buffer->overrun, 0);
90242+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90243 local_set(&cpu_buffer->dropped_events, 0);
90244 local_set(&cpu_buffer->entries, 0);
90245 local_set(&cpu_buffer->committing, 0);
90246@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90247 rb_init_page(bpage);
90248 bpage = reader->page;
90249 reader->page = *data_page;
90250- local_set(&reader->write, 0);
90251- local_set(&reader->entries, 0);
90252+ local_set_unchecked(&reader->write, 0);
90253+ local_set_unchecked(&reader->entries, 0);
90254 reader->read = 0;
90255 *data_page = bpage;
90256
90257diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90258index 0a360ce..7bd800e 100644
90259--- a/kernel/trace/trace.c
90260+++ b/kernel/trace/trace.c
90261@@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90262 return 0;
90263 }
90264
90265-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90266+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90267 {
90268 /* do nothing if flag is already set */
90269 if (!!(trace_flags & mask) == !!enabled)
90270diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90271index ea189e0..a5b48c4 100644
90272--- a/kernel/trace/trace.h
90273+++ b/kernel/trace/trace.h
90274@@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90275 void trace_printk_init_buffers(void);
90276 void trace_printk_start_comm(void);
90277 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90278-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90279+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90280
90281 /*
90282 * Normal trace_printk() and friends allocates special buffers
90283diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90284index 26dc348..8708ca7 100644
90285--- a/kernel/trace/trace_clock.c
90286+++ b/kernel/trace/trace_clock.c
90287@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90288 return now;
90289 }
90290
90291-static atomic64_t trace_counter;
90292+static atomic64_unchecked_t trace_counter;
90293
90294 /*
90295 * trace_clock_counter(): simply an atomic counter.
90296@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90297 */
90298 u64 notrace trace_clock_counter(void)
90299 {
90300- return atomic64_add_return(1, &trace_counter);
90301+ return atomic64_inc_return_unchecked(&trace_counter);
90302 }
90303diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90304index ba983dc..911aaf9 100644
90305--- a/kernel/trace/trace_events.c
90306+++ b/kernel/trace/trace_events.c
90307@@ -1675,7 +1675,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90308 return 0;
90309 }
90310
90311-struct ftrace_module_file_ops;
90312 static void __add_event_to_tracers(struct ftrace_event_call *call);
90313
90314 /* Add an additional event_call dynamically */
90315diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90316index 0abd9b8..6a663a2 100644
90317--- a/kernel/trace/trace_mmiotrace.c
90318+++ b/kernel/trace/trace_mmiotrace.c
90319@@ -24,7 +24,7 @@ struct header_iter {
90320 static struct trace_array *mmio_trace_array;
90321 static bool overrun_detected;
90322 static unsigned long prev_overruns;
90323-static atomic_t dropped_count;
90324+static atomic_unchecked_t dropped_count;
90325
90326 static void mmio_reset_data(struct trace_array *tr)
90327 {
90328@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90329
90330 static unsigned long count_overruns(struct trace_iterator *iter)
90331 {
90332- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90333+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90334 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90335
90336 if (over > prev_overruns)
90337@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90338 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90339 sizeof(*entry), 0, pc);
90340 if (!event) {
90341- atomic_inc(&dropped_count);
90342+ atomic_inc_unchecked(&dropped_count);
90343 return;
90344 }
90345 entry = ring_buffer_event_data(event);
90346@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90347 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90348 sizeof(*entry), 0, pc);
90349 if (!event) {
90350- atomic_inc(&dropped_count);
90351+ atomic_inc_unchecked(&dropped_count);
90352 return;
90353 }
90354 entry = ring_buffer_event_data(event);
90355diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90356index ed32284..884d6c3 100644
90357--- a/kernel/trace/trace_output.c
90358+++ b/kernel/trace/trace_output.c
90359@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90360
90361 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90362 if (!IS_ERR(p)) {
90363- p = mangle_path(s->buffer + s->len, p, "\n");
90364+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90365 if (p) {
90366 s->len = p - s->buffer;
90367 return 1;
90368@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90369 goto out;
90370 }
90371
90372+ pax_open_kernel();
90373 if (event->funcs->trace == NULL)
90374- event->funcs->trace = trace_nop_print;
90375+ *(void **)&event->funcs->trace = trace_nop_print;
90376 if (event->funcs->raw == NULL)
90377- event->funcs->raw = trace_nop_print;
90378+ *(void **)&event->funcs->raw = trace_nop_print;
90379 if (event->funcs->hex == NULL)
90380- event->funcs->hex = trace_nop_print;
90381+ *(void **)&event->funcs->hex = trace_nop_print;
90382 if (event->funcs->binary == NULL)
90383- event->funcs->binary = trace_nop_print;
90384+ *(void **)&event->funcs->binary = trace_nop_print;
90385+ pax_close_kernel();
90386
90387 key = event->type & (EVENT_HASHSIZE - 1);
90388
90389diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90390index b20428c..4845a10 100644
90391--- a/kernel/trace/trace_stack.c
90392+++ b/kernel/trace/trace_stack.c
90393@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90394 return;
90395
90396 /* we do not handle interrupt stacks yet */
90397- if (!object_is_on_stack(stack))
90398+ if (!object_starts_on_stack(stack))
90399 return;
90400
90401 local_irq_save(flags);
90402diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90403index 240fb62..583473e 100644
90404--- a/kernel/user_namespace.c
90405+++ b/kernel/user_namespace.c
90406@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90407 !kgid_has_mapping(parent_ns, group))
90408 return -EPERM;
90409
90410+#ifdef CONFIG_GRKERNSEC
90411+ /*
90412+ * This doesn't really inspire confidence:
90413+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90414+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90415+ * Increases kernel attack surface in areas developers
90416+ * previously cared little about ("low importance due
90417+ * to requiring "root" capability")
90418+ * To be removed when this code receives *proper* review
90419+ */
90420+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90421+ !capable(CAP_SETGID))
90422+ return -EPERM;
90423+#endif
90424+
90425 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90426 if (!ns)
90427 return -ENOMEM;
90428@@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90429 if (atomic_read(&current->mm->mm_users) > 1)
90430 return -EINVAL;
90431
90432- if (current->fs->users != 1)
90433+ if (atomic_read(&current->fs->users) != 1)
90434 return -EINVAL;
90435
90436 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90437diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90438index 4f69f9a..7c6f8f8 100644
90439--- a/kernel/utsname_sysctl.c
90440+++ b/kernel/utsname_sysctl.c
90441@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90442 static int proc_do_uts_string(ctl_table *table, int write,
90443 void __user *buffer, size_t *lenp, loff_t *ppos)
90444 {
90445- struct ctl_table uts_table;
90446+ ctl_table_no_const uts_table;
90447 int r;
90448 memcpy(&uts_table, table, sizeof(uts_table));
90449 uts_table.data = get_uts(table, write);
90450diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90451index 4431610..4265616 100644
90452--- a/kernel/watchdog.c
90453+++ b/kernel/watchdog.c
90454@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90455 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90456 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90457
90458-static struct smp_hotplug_thread watchdog_threads = {
90459+static struct smp_hotplug_thread watchdog_threads __read_only = {
90460 .store = &softlockup_watchdog,
90461 .thread_should_run = watchdog_should_run,
90462 .thread_fn = watchdog,
90463diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90464index a8381cf..1ce1331 100644
90465--- a/kernel/workqueue.c
90466+++ b/kernel/workqueue.c
90467@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90468 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90469 worker_flags |= WORKER_REBOUND;
90470 worker_flags &= ~WORKER_UNBOUND;
90471- ACCESS_ONCE(worker->flags) = worker_flags;
90472+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
90473 }
90474
90475 spin_unlock_irq(&pool->lock);
90476diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90477index db25707..8b16430 100644
90478--- a/lib/Kconfig.debug
90479+++ b/lib/Kconfig.debug
90480@@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90481
90482 config DEBUG_WW_MUTEX_SLOWPATH
90483 bool "Wait/wound mutex debugging: Slowpath testing"
90484- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90485+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90486 select DEBUG_LOCK_ALLOC
90487 select DEBUG_SPINLOCK
90488 select DEBUG_MUTEXES
90489@@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90490
90491 config DEBUG_LOCK_ALLOC
90492 bool "Lock debugging: detect incorrect freeing of live locks"
90493- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90494+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90495 select DEBUG_SPINLOCK
90496 select DEBUG_MUTEXES
90497 select LOCKDEP
90498@@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90499
90500 config PROVE_LOCKING
90501 bool "Lock debugging: prove locking correctness"
90502- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90503+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90504 select LOCKDEP
90505 select DEBUG_SPINLOCK
90506 select DEBUG_MUTEXES
90507@@ -923,7 +923,7 @@ config LOCKDEP
90508
90509 config LOCK_STAT
90510 bool "Lock usage statistics"
90511- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90512+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90513 select LOCKDEP
90514 select DEBUG_SPINLOCK
90515 select DEBUG_MUTEXES
90516@@ -1385,6 +1385,7 @@ config LATENCYTOP
90517 depends on DEBUG_KERNEL
90518 depends on STACKTRACE_SUPPORT
90519 depends on PROC_FS
90520+ depends on !GRKERNSEC_HIDESYM
90521 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90522 select KALLSYMS
90523 select KALLSYMS_ALL
90524@@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90525 config DEBUG_STRICT_USER_COPY_CHECKS
90526 bool "Strict user copy size checks"
90527 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90528- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90529+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90530 help
90531 Enabling this option turns a certain set of sanity checks for user
90532 copy operations into compile time failures.
90533@@ -1520,7 +1521,7 @@ endmenu # runtime tests
90534
90535 config PROVIDE_OHCI1394_DMA_INIT
90536 bool "Remote debugging over FireWire early on boot"
90537- depends on PCI && X86
90538+ depends on PCI && X86 && !GRKERNSEC
90539 help
90540 If you want to debug problems which hang or crash the kernel early
90541 on boot and the crashing machine has a FireWire port, you can use
90542@@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90543
90544 config FIREWIRE_OHCI_REMOTE_DMA
90545 bool "Remote debugging over FireWire with firewire-ohci"
90546- depends on FIREWIRE_OHCI
90547+ depends on FIREWIRE_OHCI && !GRKERNSEC
90548 help
90549 This option lets you use the FireWire bus for remote debugging
90550 with help of the firewire-ohci driver. It enables unfiltered
90551diff --git a/lib/Makefile b/lib/Makefile
90552index 04944e9..f43eabe 100644
90553--- a/lib/Makefile
90554+++ b/lib/Makefile
90555@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90556 obj-$(CONFIG_BTREE) += btree.o
90557 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90558 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90559-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90560+obj-y += list_debug.o
90561 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90562
90563 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90564diff --git a/lib/bitmap.c b/lib/bitmap.c
90565index 06f7e4f..f3cf2b0 100644
90566--- a/lib/bitmap.c
90567+++ b/lib/bitmap.c
90568@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90569 {
90570 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90571 u32 chunk;
90572- const char __user __force *ubuf = (const char __user __force *)buf;
90573+ const char __user *ubuf = (const char __force_user *)buf;
90574
90575 bitmap_zero(maskp, nmaskbits);
90576
90577@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90578 {
90579 if (!access_ok(VERIFY_READ, ubuf, ulen))
90580 return -EFAULT;
90581- return __bitmap_parse((const char __force *)ubuf,
90582+ return __bitmap_parse((const char __force_kernel *)ubuf,
90583 ulen, 1, maskp, nmaskbits);
90584
90585 }
90586@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90587 {
90588 unsigned a, b;
90589 int c, old_c, totaldigits;
90590- const char __user __force *ubuf = (const char __user __force *)buf;
90591+ const char __user *ubuf = (const char __force_user *)buf;
90592 int exp_digit, in_range;
90593
90594 totaldigits = c = 0;
90595@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90596 {
90597 if (!access_ok(VERIFY_READ, ubuf, ulen))
90598 return -EFAULT;
90599- return __bitmap_parselist((const char __force *)ubuf,
90600+ return __bitmap_parselist((const char __force_kernel *)ubuf,
90601 ulen, 1, maskp, nmaskbits);
90602 }
90603 EXPORT_SYMBOL(bitmap_parselist_user);
90604diff --git a/lib/bug.c b/lib/bug.c
90605index 1686034..a9c00c8 100644
90606--- a/lib/bug.c
90607+++ b/lib/bug.c
90608@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90609 return BUG_TRAP_TYPE_NONE;
90610
90611 bug = find_bug(bugaddr);
90612+ if (!bug)
90613+ return BUG_TRAP_TYPE_NONE;
90614
90615 file = NULL;
90616 line = 0;
90617diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90618index e0731c3..ad66444 100644
90619--- a/lib/debugobjects.c
90620+++ b/lib/debugobjects.c
90621@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90622 if (limit > 4)
90623 return;
90624
90625- is_on_stack = object_is_on_stack(addr);
90626+ is_on_stack = object_starts_on_stack(addr);
90627 if (is_on_stack == onstack)
90628 return;
90629
90630diff --git a/lib/devres.c b/lib/devres.c
90631index 8235331..5881053 100644
90632--- a/lib/devres.c
90633+++ b/lib/devres.c
90634@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90635 void devm_iounmap(struct device *dev, void __iomem *addr)
90636 {
90637 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90638- (void *)addr));
90639+ (void __force *)addr));
90640 iounmap(addr);
90641 }
90642 EXPORT_SYMBOL(devm_iounmap);
90643@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90644 {
90645 ioport_unmap(addr);
90646 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90647- devm_ioport_map_match, (void *)addr));
90648+ devm_ioport_map_match, (void __force *)addr));
90649 }
90650 EXPORT_SYMBOL(devm_ioport_unmap);
90651 #endif /* CONFIG_HAS_IOPORT */
90652diff --git a/lib/div64.c b/lib/div64.c
90653index 4382ad7..08aa558 100644
90654--- a/lib/div64.c
90655+++ b/lib/div64.c
90656@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90657 EXPORT_SYMBOL(__div64_32);
90658
90659 #ifndef div_s64_rem
90660-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90661+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90662 {
90663 u64 quotient;
90664
90665@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90666 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90667 */
90668 #ifndef div64_u64
90669-u64 div64_u64(u64 dividend, u64 divisor)
90670+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90671 {
90672 u32 high = divisor >> 32;
90673 u64 quot;
90674diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90675index d87a17a..ac0d79a 100644
90676--- a/lib/dma-debug.c
90677+++ b/lib/dma-debug.c
90678@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90679
90680 void dma_debug_add_bus(struct bus_type *bus)
90681 {
90682- struct notifier_block *nb;
90683+ notifier_block_no_const *nb;
90684
90685 if (global_disable)
90686 return;
90687@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90688
90689 static void check_for_stack(struct device *dev, void *addr)
90690 {
90691- if (object_is_on_stack(addr))
90692+ if (object_starts_on_stack(addr))
90693 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90694 "stack [addr=%p]\n", addr);
90695 }
90696diff --git a/lib/inflate.c b/lib/inflate.c
90697index 013a761..c28f3fc 100644
90698--- a/lib/inflate.c
90699+++ b/lib/inflate.c
90700@@ -269,7 +269,7 @@ static void free(void *where)
90701 malloc_ptr = free_mem_ptr;
90702 }
90703 #else
90704-#define malloc(a) kmalloc(a, GFP_KERNEL)
90705+#define malloc(a) kmalloc((a), GFP_KERNEL)
90706 #define free(a) kfree(a)
90707 #endif
90708
90709diff --git a/lib/ioremap.c b/lib/ioremap.c
90710index 0c9216c..863bd89 100644
90711--- a/lib/ioremap.c
90712+++ b/lib/ioremap.c
90713@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90714 unsigned long next;
90715
90716 phys_addr -= addr;
90717- pmd = pmd_alloc(&init_mm, pud, addr);
90718+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90719 if (!pmd)
90720 return -ENOMEM;
90721 do {
90722@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90723 unsigned long next;
90724
90725 phys_addr -= addr;
90726- pud = pud_alloc(&init_mm, pgd, addr);
90727+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90728 if (!pud)
90729 return -ENOMEM;
90730 do {
90731diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90732index bd2bea9..6b3c95e 100644
90733--- a/lib/is_single_threaded.c
90734+++ b/lib/is_single_threaded.c
90735@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90736 struct task_struct *p, *t;
90737 bool ret;
90738
90739+ if (!mm)
90740+ return true;
90741+
90742 if (atomic_read(&task->signal->live) != 1)
90743 return false;
90744
90745diff --git a/lib/kobject.c b/lib/kobject.c
90746index 5b4b888..c2950f7 100644
90747--- a/lib/kobject.c
90748+++ b/lib/kobject.c
90749@@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90750
90751
90752 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90753-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90754+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90755
90756-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90757+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90758 {
90759 enum kobj_ns_type type = ops->type;
90760 int error;
90761diff --git a/lib/list_debug.c b/lib/list_debug.c
90762index c24c2f7..f0296f4 100644
90763--- a/lib/list_debug.c
90764+++ b/lib/list_debug.c
90765@@ -11,7 +11,9 @@
90766 #include <linux/bug.h>
90767 #include <linux/kernel.h>
90768 #include <linux/rculist.h>
90769+#include <linux/mm.h>
90770
90771+#ifdef CONFIG_DEBUG_LIST
90772 /*
90773 * Insert a new entry between two known consecutive entries.
90774 *
90775@@ -19,21 +21,40 @@
90776 * the prev/next entries already!
90777 */
90778
90779+static bool __list_add_debug(struct list_head *new,
90780+ struct list_head *prev,
90781+ struct list_head *next)
90782+{
90783+ if (unlikely(next->prev != prev)) {
90784+ printk(KERN_ERR "list_add corruption. next->prev should be "
90785+ "prev (%p), but was %p. (next=%p).\n",
90786+ prev, next->prev, next);
90787+ BUG();
90788+ return false;
90789+ }
90790+ if (unlikely(prev->next != next)) {
90791+ printk(KERN_ERR "list_add corruption. prev->next should be "
90792+ "next (%p), but was %p. (prev=%p).\n",
90793+ next, prev->next, prev);
90794+ BUG();
90795+ return false;
90796+ }
90797+ if (unlikely(new == prev || new == next)) {
90798+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90799+ new, prev, next);
90800+ BUG();
90801+ return false;
90802+ }
90803+ return true;
90804+}
90805+
90806 void __list_add(struct list_head *new,
90807- struct list_head *prev,
90808- struct list_head *next)
90809+ struct list_head *prev,
90810+ struct list_head *next)
90811 {
90812- WARN(next->prev != prev,
90813- "list_add corruption. next->prev should be "
90814- "prev (%p), but was %p. (next=%p).\n",
90815- prev, next->prev, next);
90816- WARN(prev->next != next,
90817- "list_add corruption. prev->next should be "
90818- "next (%p), but was %p. (prev=%p).\n",
90819- next, prev->next, prev);
90820- WARN(new == prev || new == next,
90821- "list_add double add: new=%p, prev=%p, next=%p.\n",
90822- new, prev, next);
90823+ if (!__list_add_debug(new, prev, next))
90824+ return;
90825+
90826 next->prev = new;
90827 new->next = next;
90828 new->prev = prev;
90829@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90830 }
90831 EXPORT_SYMBOL(__list_add);
90832
90833-void __list_del_entry(struct list_head *entry)
90834+static bool __list_del_entry_debug(struct list_head *entry)
90835 {
90836 struct list_head *prev, *next;
90837
90838 prev = entry->prev;
90839 next = entry->next;
90840
90841- if (WARN(next == LIST_POISON1,
90842- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90843- entry, LIST_POISON1) ||
90844- WARN(prev == LIST_POISON2,
90845- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90846- entry, LIST_POISON2) ||
90847- WARN(prev->next != entry,
90848- "list_del corruption. prev->next should be %p, "
90849- "but was %p\n", entry, prev->next) ||
90850- WARN(next->prev != entry,
90851- "list_del corruption. next->prev should be %p, "
90852- "but was %p\n", entry, next->prev))
90853+ if (unlikely(next == LIST_POISON1)) {
90854+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90855+ entry, LIST_POISON1);
90856+ BUG();
90857+ return false;
90858+ }
90859+ if (unlikely(prev == LIST_POISON2)) {
90860+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90861+ entry, LIST_POISON2);
90862+ BUG();
90863+ return false;
90864+ }
90865+ if (unlikely(entry->prev->next != entry)) {
90866+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90867+ "but was %p\n", entry, prev->next);
90868+ BUG();
90869+ return false;
90870+ }
90871+ if (unlikely(entry->next->prev != entry)) {
90872+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90873+ "but was %p\n", entry, next->prev);
90874+ BUG();
90875+ return false;
90876+ }
90877+ return true;
90878+}
90879+
90880+void __list_del_entry(struct list_head *entry)
90881+{
90882+ if (!__list_del_entry_debug(entry))
90883 return;
90884
90885- __list_del(prev, next);
90886+ __list_del(entry->prev, entry->next);
90887 }
90888 EXPORT_SYMBOL(__list_del_entry);
90889
90890@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90891 void __list_add_rcu(struct list_head *new,
90892 struct list_head *prev, struct list_head *next)
90893 {
90894- WARN(next->prev != prev,
90895- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90896- prev, next->prev, next);
90897- WARN(prev->next != next,
90898- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90899- next, prev->next, prev);
90900+ if (!__list_add_debug(new, prev, next))
90901+ return;
90902+
90903 new->next = next;
90904 new->prev = prev;
90905 rcu_assign_pointer(list_next_rcu(prev), new);
90906 next->prev = new;
90907 }
90908 EXPORT_SYMBOL(__list_add_rcu);
90909+#endif
90910+
90911+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90912+{
90913+#ifdef CONFIG_DEBUG_LIST
90914+ if (!__list_add_debug(new, prev, next))
90915+ return;
90916+#endif
90917+
90918+ pax_open_kernel();
90919+ next->prev = new;
90920+ new->next = next;
90921+ new->prev = prev;
90922+ prev->next = new;
90923+ pax_close_kernel();
90924+}
90925+EXPORT_SYMBOL(__pax_list_add);
90926+
90927+void pax_list_del(struct list_head *entry)
90928+{
90929+#ifdef CONFIG_DEBUG_LIST
90930+ if (!__list_del_entry_debug(entry))
90931+ return;
90932+#endif
90933+
90934+ pax_open_kernel();
90935+ __list_del(entry->prev, entry->next);
90936+ entry->next = LIST_POISON1;
90937+ entry->prev = LIST_POISON2;
90938+ pax_close_kernel();
90939+}
90940+EXPORT_SYMBOL(pax_list_del);
90941+
90942+void pax_list_del_init(struct list_head *entry)
90943+{
90944+ pax_open_kernel();
90945+ __list_del(entry->prev, entry->next);
90946+ INIT_LIST_HEAD(entry);
90947+ pax_close_kernel();
90948+}
90949+EXPORT_SYMBOL(pax_list_del_init);
90950+
90951+void __pax_list_add_rcu(struct list_head *new,
90952+ struct list_head *prev, struct list_head *next)
90953+{
90954+#ifdef CONFIG_DEBUG_LIST
90955+ if (!__list_add_debug(new, prev, next))
90956+ return;
90957+#endif
90958+
90959+ pax_open_kernel();
90960+ new->next = next;
90961+ new->prev = prev;
90962+ rcu_assign_pointer(list_next_rcu(prev), new);
90963+ next->prev = new;
90964+ pax_close_kernel();
90965+}
90966+EXPORT_SYMBOL(__pax_list_add_rcu);
90967+
90968+void pax_list_del_rcu(struct list_head *entry)
90969+{
90970+#ifdef CONFIG_DEBUG_LIST
90971+ if (!__list_del_entry_debug(entry))
90972+ return;
90973+#endif
90974+
90975+ pax_open_kernel();
90976+ __list_del(entry->prev, entry->next);
90977+ entry->next = LIST_POISON1;
90978+ entry->prev = LIST_POISON2;
90979+ pax_close_kernel();
90980+}
90981+EXPORT_SYMBOL(pax_list_del_rcu);
90982diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90983index 1a53d49..ace934c 100644
90984--- a/lib/percpu-refcount.c
90985+++ b/lib/percpu-refcount.c
90986@@ -29,7 +29,7 @@
90987 * can't hit 0 before we've added up all the percpu refs.
90988 */
90989
90990-#define PCPU_COUNT_BIAS (1U << 31)
90991+#define PCPU_COUNT_BIAS (1U << 30)
90992
90993 /**
90994 * percpu_ref_init - initialize a percpu refcount
90995diff --git a/lib/radix-tree.c b/lib/radix-tree.c
90996index 7811ed3..f80ca19 100644
90997--- a/lib/radix-tree.c
90998+++ b/lib/radix-tree.c
90999@@ -93,7 +93,7 @@ struct radix_tree_preload {
91000 int nr;
91001 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
91002 };
91003-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
91004+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
91005
91006 static inline void *ptr_to_indirect(void *ptr)
91007 {
91008diff --git a/lib/random32.c b/lib/random32.c
91009index 1e5b2df..009bfe8 100644
91010--- a/lib/random32.c
91011+++ b/lib/random32.c
91012@@ -44,7 +44,7 @@
91013 static void __init prandom_state_selftest(void);
91014 #endif
91015
91016-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91017+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91018
91019 /**
91020 * prandom_u32_state - seeded pseudo-random number generator.
91021@@ -244,8 +244,19 @@ static void __prandom_reseed(bool late)
91022 static bool latch = false;
91023 static DEFINE_SPINLOCK(lock);
91024
91025+ /* Asking for random bytes might result in bytes getting
91026+ * moved into the nonblocking pool and thus marking it
91027+ * as initialized. In this case we would double back into
91028+ * this function and attempt to do a late reseed.
91029+ * Ignore the pointless attempt to reseed again if we're
91030+ * already waiting for bytes when the nonblocking pool
91031+ * got initialized.
91032+ */
91033+
91034 /* only allow initial seeding (late == false) once */
91035- spin_lock_irqsave(&lock, flags);
91036+ if (!spin_trylock_irqsave(&lock, flags))
91037+ return;
91038+
91039 if (latch && !late)
91040 goto out;
91041 latch = true;
91042diff --git a/lib/rbtree.c b/lib/rbtree.c
91043index 65f4eff..2cfa167 100644
91044--- a/lib/rbtree.c
91045+++ b/lib/rbtree.c
91046@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91047 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91048
91049 static const struct rb_augment_callbacks dummy_callbacks = {
91050- dummy_propagate, dummy_copy, dummy_rotate
91051+ .propagate = dummy_propagate,
91052+ .copy = dummy_copy,
91053+ .rotate = dummy_rotate
91054 };
91055
91056 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91057diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91058index bb2b201..46abaf9 100644
91059--- a/lib/strncpy_from_user.c
91060+++ b/lib/strncpy_from_user.c
91061@@ -21,7 +21,7 @@
91062 */
91063 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91064 {
91065- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91066+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91067 long res = 0;
91068
91069 /*
91070diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91071index a28df52..3d55877 100644
91072--- a/lib/strnlen_user.c
91073+++ b/lib/strnlen_user.c
91074@@ -26,7 +26,7 @@
91075 */
91076 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91077 {
91078- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91079+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91080 long align, res = 0;
91081 unsigned long c;
91082
91083diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91084index e4399fa..5e8b214 100644
91085--- a/lib/swiotlb.c
91086+++ b/lib/swiotlb.c
91087@@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91088
91089 void
91090 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91091- dma_addr_t dev_addr)
91092+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91093 {
91094 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91095
91096diff --git a/lib/usercopy.c b/lib/usercopy.c
91097index 4f5b1dd..7cab418 100644
91098--- a/lib/usercopy.c
91099+++ b/lib/usercopy.c
91100@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91101 WARN(1, "Buffer overflow detected!\n");
91102 }
91103 EXPORT_SYMBOL(copy_from_user_overflow);
91104+
91105+void copy_to_user_overflow(void)
91106+{
91107+ WARN(1, "Buffer overflow detected!\n");
91108+}
91109+EXPORT_SYMBOL(copy_to_user_overflow);
91110diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91111index 10909c5..653e1b8 100644
91112--- a/lib/vsprintf.c
91113+++ b/lib/vsprintf.c
91114@@ -16,6 +16,9 @@
91115 * - scnprintf and vscnprintf
91116 */
91117
91118+#ifdef CONFIG_GRKERNSEC_HIDESYM
91119+#define __INCLUDED_BY_HIDESYM 1
91120+#endif
91121 #include <stdarg.h>
91122 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91123 #include <linux/types.h>
91124@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
91125 return number(buf, end, *(const netdev_features_t *)addr, spec);
91126 }
91127
91128+#ifdef CONFIG_GRKERNSEC_HIDESYM
91129+int kptr_restrict __read_mostly = 2;
91130+#else
91131 int kptr_restrict __read_mostly;
91132+#endif
91133
91134 /*
91135 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91136@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
91137 * - 'f' For simple symbolic function names without offset
91138 * - 'S' For symbolic direct pointers with offset
91139 * - 's' For symbolic direct pointers without offset
91140+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91141 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91142 * - 'B' For backtraced symbolic direct pointers with offset
91143 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91144@@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91145
91146 if (!ptr && *fmt != 'K') {
91147 /*
91148- * Print (null) with the same width as a pointer so it makes
91149+ * Print (nil) with the same width as a pointer so it makes
91150 * tabular output look nice.
91151 */
91152 if (spec.field_width == -1)
91153 spec.field_width = default_width;
91154- return string(buf, end, "(null)", spec);
91155+ return string(buf, end, "(nil)", spec);
91156 }
91157
91158 switch (*fmt) {
91159@@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91160 /* Fallthrough */
91161 case 'S':
91162 case 's':
91163+#ifdef CONFIG_GRKERNSEC_HIDESYM
91164+ break;
91165+#else
91166+ return symbol_string(buf, end, ptr, spec, fmt);
91167+#endif
91168+ case 'A':
91169 case 'B':
91170 return symbol_string(buf, end, ptr, spec, fmt);
91171 case 'R':
91172@@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91173 va_end(va);
91174 return buf;
91175 }
91176+ case 'P':
91177+ break;
91178 case 'K':
91179 /*
91180 * %pK cannot be used in IRQ context because its test
91181@@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91182 ((const struct file *)ptr)->f_path.dentry,
91183 spec, fmt);
91184 }
91185+
91186+#ifdef CONFIG_GRKERNSEC_HIDESYM
91187+ /* 'P' = approved pointers to copy to userland,
91188+ as in the /proc/kallsyms case, as we make it display nothing
91189+ for non-root users, and the real contents for root users
91190+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91191+ above
91192+ */
91193+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91194+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91195+ dump_stack();
91196+ ptr = NULL;
91197+ }
91198+#endif
91199+
91200 spec.flags |= SMALL;
91201 if (spec.field_width == -1) {
91202 spec.field_width = default_width;
91203@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91204 typeof(type) value; \
91205 if (sizeof(type) == 8) { \
91206 args = PTR_ALIGN(args, sizeof(u32)); \
91207- *(u32 *)&value = *(u32 *)args; \
91208- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91209+ *(u32 *)&value = *(const u32 *)args; \
91210+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91211 } else { \
91212 args = PTR_ALIGN(args, sizeof(type)); \
91213- value = *(typeof(type) *)args; \
91214+ value = *(const typeof(type) *)args; \
91215 } \
91216 args += sizeof(type); \
91217 value; \
91218@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91219 case FORMAT_TYPE_STR: {
91220 const char *str_arg = args;
91221 args += strlen(str_arg) + 1;
91222- str = string(str, end, (char *)str_arg, spec);
91223+ str = string(str, end, str_arg, spec);
91224 break;
91225 }
91226
91227diff --git a/localversion-grsec b/localversion-grsec
91228new file mode 100644
91229index 0000000..7cd6065
91230--- /dev/null
91231+++ b/localversion-grsec
91232@@ -0,0 +1 @@
91233+-grsec
91234diff --git a/mm/Kconfig b/mm/Kconfig
91235index 723bbe0..ea624b1 100644
91236--- a/mm/Kconfig
91237+++ b/mm/Kconfig
91238@@ -326,10 +326,11 @@ config KSM
91239 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91240
91241 config DEFAULT_MMAP_MIN_ADDR
91242- int "Low address space to protect from user allocation"
91243+ int "Low address space to protect from user allocation"
91244 depends on MMU
91245- default 4096
91246- help
91247+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91248+ default 65536
91249+ help
91250 This is the portion of low virtual memory which should be protected
91251 from userspace allocation. Keeping a user from writing to low pages
91252 can help reduce the impact of kernel NULL pointer bugs.
91253@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91254
91255 config HWPOISON_INJECT
91256 tristate "HWPoison pages injector"
91257- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91258+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91259 select PROC_PAGE_MONITOR
91260
91261 config NOMMU_INITIAL_TRIM_EXCESS
91262diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91263index ce682f7..1fb54f9 100644
91264--- a/mm/backing-dev.c
91265+++ b/mm/backing-dev.c
91266@@ -12,7 +12,7 @@
91267 #include <linux/device.h>
91268 #include <trace/events/writeback.h>
91269
91270-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91271+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91272
91273 struct backing_dev_info default_backing_dev_info = {
91274 .name = "default",
91275@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91276 return err;
91277
91278 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91279- atomic_long_inc_return(&bdi_seq));
91280+ atomic_long_inc_return_unchecked(&bdi_seq));
91281 if (err) {
91282 bdi_destroy(bdi);
91283 return err;
91284diff --git a/mm/filemap.c b/mm/filemap.c
91285index b7749a9..50d1123 100644
91286--- a/mm/filemap.c
91287+++ b/mm/filemap.c
91288@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91289 struct address_space *mapping = file->f_mapping;
91290
91291 if (!mapping->a_ops->readpage)
91292- return -ENOEXEC;
91293+ return -ENODEV;
91294 file_accessed(file);
91295 vma->vm_ops = &generic_file_vm_ops;
91296 return 0;
91297@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91298
91299 while (bytes) {
91300 char __user *buf = iov->iov_base + base;
91301- int copy = min(bytes, iov->iov_len - base);
91302+ size_t copy = min(bytes, iov->iov_len - base);
91303
91304 base = 0;
91305 left = __copy_from_user_inatomic(vaddr, buf, copy);
91306@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91307 BUG_ON(!in_atomic());
91308 kaddr = kmap_atomic(page);
91309 if (likely(i->nr_segs == 1)) {
91310- int left;
91311+ size_t left;
91312 char __user *buf = i->iov->iov_base + i->iov_offset;
91313 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91314 copied = bytes - left;
91315@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91316
91317 kaddr = kmap(page);
91318 if (likely(i->nr_segs == 1)) {
91319- int left;
91320+ size_t left;
91321 char __user *buf = i->iov->iov_base + i->iov_offset;
91322 left = __copy_from_user(kaddr + offset, buf, bytes);
91323 copied = bytes - left;
91324@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91325 * zero-length segments (without overruning the iovec).
91326 */
91327 while (bytes || unlikely(i->count && !iov->iov_len)) {
91328- int copy;
91329+ size_t copy;
91330
91331 copy = min(bytes, iov->iov_len - base);
91332 BUG_ON(!i->count || i->count < copy);
91333@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91334 *pos = i_size_read(inode);
91335
91336 if (limit != RLIM_INFINITY) {
91337+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91338 if (*pos >= limit) {
91339 send_sig(SIGXFSZ, current, 0);
91340 return -EFBIG;
91341diff --git a/mm/fremap.c b/mm/fremap.c
91342index bbc4d66..117b798 100644
91343--- a/mm/fremap.c
91344+++ b/mm/fremap.c
91345@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91346 retry:
91347 vma = find_vma(mm, start);
91348
91349+#ifdef CONFIG_PAX_SEGMEXEC
91350+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91351+ goto out;
91352+#endif
91353+
91354 /*
91355 * Make sure the vma is shared, that it supports prefaulting,
91356 * and that the remapped range is valid and fully within
91357diff --git a/mm/highmem.c b/mm/highmem.c
91358index b32b70c..e512eb0 100644
91359--- a/mm/highmem.c
91360+++ b/mm/highmem.c
91361@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91362 * So no dangers, even with speculative execution.
91363 */
91364 page = pte_page(pkmap_page_table[i]);
91365+ pax_open_kernel();
91366 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91367-
91368+ pax_close_kernel();
91369 set_page_address(page, NULL);
91370 need_flush = 1;
91371 }
91372@@ -198,9 +199,11 @@ start:
91373 }
91374 }
91375 vaddr = PKMAP_ADDR(last_pkmap_nr);
91376+
91377+ pax_open_kernel();
91378 set_pte_at(&init_mm, vaddr,
91379 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91380-
91381+ pax_close_kernel();
91382 pkmap_count[last_pkmap_nr] = 1;
91383 set_page_address(page, (void *)vaddr);
91384
91385diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91386index dee6cf4..52b94f7 100644
91387--- a/mm/hugetlb.c
91388+++ b/mm/hugetlb.c
91389@@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91390 struct hstate *h = &default_hstate;
91391 unsigned long tmp;
91392 int ret;
91393+ ctl_table_no_const hugetlb_table;
91394
91395 tmp = h->max_huge_pages;
91396
91397 if (write && h->order >= MAX_ORDER)
91398 return -EINVAL;
91399
91400- table->data = &tmp;
91401- table->maxlen = sizeof(unsigned long);
91402- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91403+ hugetlb_table = *table;
91404+ hugetlb_table.data = &tmp;
91405+ hugetlb_table.maxlen = sizeof(unsigned long);
91406+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91407 if (ret)
91408 goto out;
91409
91410@@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91411 struct hstate *h = &default_hstate;
91412 unsigned long tmp;
91413 int ret;
91414+ ctl_table_no_const hugetlb_table;
91415
91416 tmp = h->nr_overcommit_huge_pages;
91417
91418 if (write && h->order >= MAX_ORDER)
91419 return -EINVAL;
91420
91421- table->data = &tmp;
91422- table->maxlen = sizeof(unsigned long);
91423- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91424+ hugetlb_table = *table;
91425+ hugetlb_table.data = &tmp;
91426+ hugetlb_table.maxlen = sizeof(unsigned long);
91427+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91428 if (ret)
91429 goto out;
91430
91431@@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91432 return 1;
91433 }
91434
91435+#ifdef CONFIG_PAX_SEGMEXEC
91436+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91437+{
91438+ struct mm_struct *mm = vma->vm_mm;
91439+ struct vm_area_struct *vma_m;
91440+ unsigned long address_m;
91441+ pte_t *ptep_m;
91442+
91443+ vma_m = pax_find_mirror_vma(vma);
91444+ if (!vma_m)
91445+ return;
91446+
91447+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91448+ address_m = address + SEGMEXEC_TASK_SIZE;
91449+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91450+ get_page(page_m);
91451+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
91452+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91453+}
91454+#endif
91455+
91456 /*
91457 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91458 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91459@@ -2712,6 +2737,11 @@ retry_avoidcopy:
91460 make_huge_pte(vma, new_page, 1));
91461 page_remove_rmap(old_page);
91462 hugepage_add_new_anon_rmap(new_page, vma, address);
91463+
91464+#ifdef CONFIG_PAX_SEGMEXEC
91465+ pax_mirror_huge_pte(vma, address, new_page);
91466+#endif
91467+
91468 /* Make the old page be freed below */
91469 new_page = old_page;
91470 }
91471@@ -2876,6 +2906,10 @@ retry:
91472 && (vma->vm_flags & VM_SHARED)));
91473 set_huge_pte_at(mm, address, ptep, new_pte);
91474
91475+#ifdef CONFIG_PAX_SEGMEXEC
91476+ pax_mirror_huge_pte(vma, address, page);
91477+#endif
91478+
91479 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91480 /* Optimization, do the COW without a second fault */
91481 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91482@@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91483 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91484 struct hstate *h = hstate_vma(vma);
91485
91486+#ifdef CONFIG_PAX_SEGMEXEC
91487+ struct vm_area_struct *vma_m;
91488+#endif
91489+
91490 address &= huge_page_mask(h);
91491
91492 ptep = huge_pte_offset(mm, address);
91493@@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91494 VM_FAULT_SET_HINDEX(hstate_index(h));
91495 }
91496
91497+#ifdef CONFIG_PAX_SEGMEXEC
91498+ vma_m = pax_find_mirror_vma(vma);
91499+ if (vma_m) {
91500+ unsigned long address_m;
91501+
91502+ if (vma->vm_start > vma_m->vm_start) {
91503+ address_m = address;
91504+ address -= SEGMEXEC_TASK_SIZE;
91505+ vma = vma_m;
91506+ h = hstate_vma(vma);
91507+ } else
91508+ address_m = address + SEGMEXEC_TASK_SIZE;
91509+
91510+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91511+ return VM_FAULT_OOM;
91512+ address_m &= HPAGE_MASK;
91513+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91514+ }
91515+#endif
91516+
91517 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91518 if (!ptep)
91519 return VM_FAULT_OOM;
91520diff --git a/mm/internal.h b/mm/internal.h
91521index 8b6cfd6..ec809a6 100644
91522--- a/mm/internal.h
91523+++ b/mm/internal.h
91524@@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91525 * in mm/page_alloc.c
91526 */
91527 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91528+extern void free_compound_page(struct page *page);
91529 extern void prep_compound_page(struct page *page, unsigned long order);
91530 #ifdef CONFIG_MEMORY_FAILURE
91531 extern bool is_free_buddy_page(struct page *page);
91532@@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91533
91534 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91535 unsigned long, unsigned long,
91536- unsigned long, unsigned long);
91537+ unsigned long, unsigned long) __intentional_overflow(-1);
91538
91539 extern void set_pageblock_order(void);
91540 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91541diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91542index 31f01c5..7015178 100644
91543--- a/mm/kmemleak.c
91544+++ b/mm/kmemleak.c
91545@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91546
91547 for (i = 0; i < object->trace_len; i++) {
91548 void *ptr = (void *)object->trace[i];
91549- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91550+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91551 }
91552 }
91553
91554@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91555 return -ENOMEM;
91556 }
91557
91558- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91559+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91560 &kmemleak_fops);
91561 if (!dentry)
91562 pr_warning("Failed to create the debugfs kmemleak file\n");
91563diff --git a/mm/maccess.c b/mm/maccess.c
91564index d53adf9..03a24bf 100644
91565--- a/mm/maccess.c
91566+++ b/mm/maccess.c
91567@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91568 set_fs(KERNEL_DS);
91569 pagefault_disable();
91570 ret = __copy_from_user_inatomic(dst,
91571- (__force const void __user *)src, size);
91572+ (const void __force_user *)src, size);
91573 pagefault_enable();
91574 set_fs(old_fs);
91575
91576@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91577
91578 set_fs(KERNEL_DS);
91579 pagefault_disable();
91580- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91581+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91582 pagefault_enable();
91583 set_fs(old_fs);
91584
91585diff --git a/mm/madvise.c b/mm/madvise.c
91586index 539eeb9..e24a987 100644
91587--- a/mm/madvise.c
91588+++ b/mm/madvise.c
91589@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91590 pgoff_t pgoff;
91591 unsigned long new_flags = vma->vm_flags;
91592
91593+#ifdef CONFIG_PAX_SEGMEXEC
91594+ struct vm_area_struct *vma_m;
91595+#endif
91596+
91597 switch (behavior) {
91598 case MADV_NORMAL:
91599 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91600@@ -126,6 +130,13 @@ success:
91601 /*
91602 * vm_flags is protected by the mmap_sem held in write mode.
91603 */
91604+
91605+#ifdef CONFIG_PAX_SEGMEXEC
91606+ vma_m = pax_find_mirror_vma(vma);
91607+ if (vma_m)
91608+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91609+#endif
91610+
91611 vma->vm_flags = new_flags;
91612
91613 out:
91614@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91615 struct vm_area_struct **prev,
91616 unsigned long start, unsigned long end)
91617 {
91618+
91619+#ifdef CONFIG_PAX_SEGMEXEC
91620+ struct vm_area_struct *vma_m;
91621+#endif
91622+
91623 *prev = vma;
91624 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91625 return -EINVAL;
91626@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91627 zap_page_range(vma, start, end - start, &details);
91628 } else
91629 zap_page_range(vma, start, end - start, NULL);
91630+
91631+#ifdef CONFIG_PAX_SEGMEXEC
91632+ vma_m = pax_find_mirror_vma(vma);
91633+ if (vma_m) {
91634+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91635+ struct zap_details details = {
91636+ .nonlinear_vma = vma_m,
91637+ .last_index = ULONG_MAX,
91638+ };
91639+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91640+ } else
91641+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91642+ }
91643+#endif
91644+
91645 return 0;
91646 }
91647
91648@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91649 if (end < start)
91650 return error;
91651
91652+#ifdef CONFIG_PAX_SEGMEXEC
91653+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91654+ if (end > SEGMEXEC_TASK_SIZE)
91655+ return error;
91656+ } else
91657+#endif
91658+
91659+ if (end > TASK_SIZE)
91660+ return error;
91661+
91662 error = 0;
91663 if (end == start)
91664 return error;
91665diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91666index 90977ac..487ab84 100644
91667--- a/mm/memory-failure.c
91668+++ b/mm/memory-failure.c
91669@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91670
91671 int sysctl_memory_failure_recovery __read_mostly = 1;
91672
91673-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91674+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91675
91676 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91677
91678@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91679 pfn, t->comm, t->pid);
91680 si.si_signo = SIGBUS;
91681 si.si_errno = 0;
91682- si.si_addr = (void *)addr;
91683+ si.si_addr = (void __user *)addr;
91684 #ifdef __ARCH_SI_TRAPNO
91685 si.si_trapno = trapno;
91686 #endif
91687@@ -762,7 +762,7 @@ static struct page_state {
91688 unsigned long res;
91689 char *msg;
91690 int (*action)(struct page *p, unsigned long pfn);
91691-} error_states[] = {
91692+} __do_const error_states[] = {
91693 { reserved, reserved, "reserved kernel", me_kernel },
91694 /*
91695 * free pages are specially detected outside this table:
91696@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91697 nr_pages = 1 << compound_order(hpage);
91698 else /* normal page or thp */
91699 nr_pages = 1;
91700- atomic_long_add(nr_pages, &num_poisoned_pages);
91701+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91702
91703 /*
91704 * We need/can do nothing about count=0 pages.
91705@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91706 if (!PageHWPoison(hpage)
91707 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91708 || (p != hpage && TestSetPageHWPoison(hpage))) {
91709- atomic_long_sub(nr_pages, &num_poisoned_pages);
91710+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91711 return 0;
91712 }
91713 set_page_hwpoison_huge_page(hpage);
91714@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91715 }
91716 if (hwpoison_filter(p)) {
91717 if (TestClearPageHWPoison(p))
91718- atomic_long_sub(nr_pages, &num_poisoned_pages);
91719+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91720 unlock_page(hpage);
91721 put_page(hpage);
91722 return 0;
91723@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91724 return 0;
91725 }
91726 if (TestClearPageHWPoison(p))
91727- atomic_long_dec(&num_poisoned_pages);
91728+ atomic_long_dec_unchecked(&num_poisoned_pages);
91729 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91730 return 0;
91731 }
91732@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91733 */
91734 if (TestClearPageHWPoison(page)) {
91735 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91736- atomic_long_sub(nr_pages, &num_poisoned_pages);
91737+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91738 freeit = 1;
91739 if (PageHuge(page))
91740 clear_page_hwpoison_huge_page(page);
91741@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91742 if (PageHuge(page)) {
91743 set_page_hwpoison_huge_page(hpage);
91744 dequeue_hwpoisoned_huge_page(hpage);
91745- atomic_long_add(1 << compound_order(hpage),
91746+ atomic_long_add_unchecked(1 << compound_order(hpage),
91747 &num_poisoned_pages);
91748 } else {
91749 SetPageHWPoison(page);
91750- atomic_long_inc(&num_poisoned_pages);
91751+ atomic_long_inc_unchecked(&num_poisoned_pages);
91752 }
91753 }
91754 return ret;
91755@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91756 put_page(page);
91757 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91758 SetPageHWPoison(page);
91759- atomic_long_inc(&num_poisoned_pages);
91760+ atomic_long_inc_unchecked(&num_poisoned_pages);
91761 return 0;
91762 }
91763
91764@@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91765 if (!is_free_buddy_page(page))
91766 pr_info("soft offline: %#lx: page leaked\n",
91767 pfn);
91768- atomic_long_inc(&num_poisoned_pages);
91769+ atomic_long_inc_unchecked(&num_poisoned_pages);
91770 }
91771 } else {
91772 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91773@@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91774 if (PageHuge(page)) {
91775 set_page_hwpoison_huge_page(hpage);
91776 dequeue_hwpoisoned_huge_page(hpage);
91777- atomic_long_add(1 << compound_order(hpage),
91778+ atomic_long_add_unchecked(1 << compound_order(hpage),
91779 &num_poisoned_pages);
91780 } else {
91781 SetPageHWPoison(page);
91782- atomic_long_inc(&num_poisoned_pages);
91783+ atomic_long_inc_unchecked(&num_poisoned_pages);
91784 }
91785 }
91786 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91787diff --git a/mm/memory.c b/mm/memory.c
91788index dda27b9..c56b9d6 100644
91789--- a/mm/memory.c
91790+++ b/mm/memory.c
91791@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91792 free_pte_range(tlb, pmd, addr);
91793 } while (pmd++, addr = next, addr != end);
91794
91795+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91796 start &= PUD_MASK;
91797 if (start < floor)
91798 return;
91799@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91800 pmd = pmd_offset(pud, start);
91801 pud_clear(pud);
91802 pmd_free_tlb(tlb, pmd, start);
91803+#endif
91804+
91805 }
91806
91807 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91808@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91809 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91810 } while (pud++, addr = next, addr != end);
91811
91812+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91813 start &= PGDIR_MASK;
91814 if (start < floor)
91815 return;
91816@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91817 pud = pud_offset(pgd, start);
91818 pgd_clear(pgd);
91819 pud_free_tlb(tlb, pud, start);
91820+#endif
91821+
91822 }
91823
91824 /*
91825@@ -1635,12 +1641,6 @@ no_page_table:
91826 return page;
91827 }
91828
91829-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91830-{
91831- return stack_guard_page_start(vma, addr) ||
91832- stack_guard_page_end(vma, addr+PAGE_SIZE);
91833-}
91834-
91835 /**
91836 * __get_user_pages() - pin user pages in memory
91837 * @tsk: task_struct of target task
91838@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91839
91840 i = 0;
91841
91842- do {
91843+ while (nr_pages) {
91844 struct vm_area_struct *vma;
91845
91846- vma = find_extend_vma(mm, start);
91847+ vma = find_vma(mm, start);
91848 if (!vma && in_gate_area(mm, start)) {
91849 unsigned long pg = start & PAGE_MASK;
91850 pgd_t *pgd;
91851@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91852 goto next_page;
91853 }
91854
91855- if (!vma ||
91856+ if (!vma || start < vma->vm_start ||
91857 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91858 !(vm_flags & vma->vm_flags))
91859 return i ? : -EFAULT;
91860@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91861 int ret;
91862 unsigned int fault_flags = 0;
91863
91864- /* For mlock, just skip the stack guard page. */
91865- if (foll_flags & FOLL_MLOCK) {
91866- if (stack_guard_page(vma, start))
91867- goto next_page;
91868- }
91869 if (foll_flags & FOLL_WRITE)
91870 fault_flags |= FAULT_FLAG_WRITE;
91871 if (nonblocking)
91872@@ -1892,7 +1887,7 @@ next_page:
91873 start += page_increm * PAGE_SIZE;
91874 nr_pages -= page_increm;
91875 } while (nr_pages && start < vma->vm_end);
91876- } while (nr_pages);
91877+ }
91878 return i;
91879 }
91880 EXPORT_SYMBOL(__get_user_pages);
91881@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91882 page_add_file_rmap(page);
91883 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91884
91885+#ifdef CONFIG_PAX_SEGMEXEC
91886+ pax_mirror_file_pte(vma, addr, page, ptl);
91887+#endif
91888+
91889 retval = 0;
91890 pte_unmap_unlock(pte, ptl);
91891 return retval;
91892@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91893 if (!page_count(page))
91894 return -EINVAL;
91895 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91896+
91897+#ifdef CONFIG_PAX_SEGMEXEC
91898+ struct vm_area_struct *vma_m;
91899+#endif
91900+
91901 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91902 BUG_ON(vma->vm_flags & VM_PFNMAP);
91903 vma->vm_flags |= VM_MIXEDMAP;
91904+
91905+#ifdef CONFIG_PAX_SEGMEXEC
91906+ vma_m = pax_find_mirror_vma(vma);
91907+ if (vma_m)
91908+ vma_m->vm_flags |= VM_MIXEDMAP;
91909+#endif
91910+
91911 }
91912 return insert_page(vma, addr, page, vma->vm_page_prot);
91913 }
91914@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91915 unsigned long pfn)
91916 {
91917 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91918+ BUG_ON(vma->vm_mirror);
91919
91920 if (addr < vma->vm_start || addr >= vma->vm_end)
91921 return -EFAULT;
91922@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91923
91924 BUG_ON(pud_huge(*pud));
91925
91926- pmd = pmd_alloc(mm, pud, addr);
91927+ pmd = (mm == &init_mm) ?
91928+ pmd_alloc_kernel(mm, pud, addr) :
91929+ pmd_alloc(mm, pud, addr);
91930 if (!pmd)
91931 return -ENOMEM;
91932 do {
91933@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91934 unsigned long next;
91935 int err;
91936
91937- pud = pud_alloc(mm, pgd, addr);
91938+ pud = (mm == &init_mm) ?
91939+ pud_alloc_kernel(mm, pgd, addr) :
91940+ pud_alloc(mm, pgd, addr);
91941 if (!pud)
91942 return -ENOMEM;
91943 do {
91944@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91945 copy_user_highpage(dst, src, va, vma);
91946 }
91947
91948+#ifdef CONFIG_PAX_SEGMEXEC
91949+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91950+{
91951+ struct mm_struct *mm = vma->vm_mm;
91952+ spinlock_t *ptl;
91953+ pte_t *pte, entry;
91954+
91955+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91956+ entry = *pte;
91957+ if (!pte_present(entry)) {
91958+ if (!pte_none(entry)) {
91959+ BUG_ON(pte_file(entry));
91960+ free_swap_and_cache(pte_to_swp_entry(entry));
91961+ pte_clear_not_present_full(mm, address, pte, 0);
91962+ }
91963+ } else {
91964+ struct page *page;
91965+
91966+ flush_cache_page(vma, address, pte_pfn(entry));
91967+ entry = ptep_clear_flush(vma, address, pte);
91968+ BUG_ON(pte_dirty(entry));
91969+ page = vm_normal_page(vma, address, entry);
91970+ if (page) {
91971+ update_hiwater_rss(mm);
91972+ if (PageAnon(page))
91973+ dec_mm_counter_fast(mm, MM_ANONPAGES);
91974+ else
91975+ dec_mm_counter_fast(mm, MM_FILEPAGES);
91976+ page_remove_rmap(page);
91977+ page_cache_release(page);
91978+ }
91979+ }
91980+ pte_unmap_unlock(pte, ptl);
91981+}
91982+
91983+/* PaX: if vma is mirrored, synchronize the mirror's PTE
91984+ *
91985+ * the ptl of the lower mapped page is held on entry and is not released on exit
91986+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91987+ */
91988+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91989+{
91990+ struct mm_struct *mm = vma->vm_mm;
91991+ unsigned long address_m;
91992+ spinlock_t *ptl_m;
91993+ struct vm_area_struct *vma_m;
91994+ pmd_t *pmd_m;
91995+ pte_t *pte_m, entry_m;
91996+
91997+ BUG_ON(!page_m || !PageAnon(page_m));
91998+
91999+ vma_m = pax_find_mirror_vma(vma);
92000+ if (!vma_m)
92001+ return;
92002+
92003+ BUG_ON(!PageLocked(page_m));
92004+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92005+ address_m = address + SEGMEXEC_TASK_SIZE;
92006+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92007+ pte_m = pte_offset_map(pmd_m, address_m);
92008+ ptl_m = pte_lockptr(mm, pmd_m);
92009+ if (ptl != ptl_m) {
92010+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92011+ if (!pte_none(*pte_m))
92012+ goto out;
92013+ }
92014+
92015+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92016+ page_cache_get(page_m);
92017+ page_add_anon_rmap(page_m, vma_m, address_m);
92018+ inc_mm_counter_fast(mm, MM_ANONPAGES);
92019+ set_pte_at(mm, address_m, pte_m, entry_m);
92020+ update_mmu_cache(vma_m, address_m, pte_m);
92021+out:
92022+ if (ptl != ptl_m)
92023+ spin_unlock(ptl_m);
92024+ pte_unmap(pte_m);
92025+ unlock_page(page_m);
92026+}
92027+
92028+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
92029+{
92030+ struct mm_struct *mm = vma->vm_mm;
92031+ unsigned long address_m;
92032+ spinlock_t *ptl_m;
92033+ struct vm_area_struct *vma_m;
92034+ pmd_t *pmd_m;
92035+ pte_t *pte_m, entry_m;
92036+
92037+ BUG_ON(!page_m || PageAnon(page_m));
92038+
92039+ vma_m = pax_find_mirror_vma(vma);
92040+ if (!vma_m)
92041+ return;
92042+
92043+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92044+ address_m = address + SEGMEXEC_TASK_SIZE;
92045+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92046+ pte_m = pte_offset_map(pmd_m, address_m);
92047+ ptl_m = pte_lockptr(mm, pmd_m);
92048+ if (ptl != ptl_m) {
92049+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92050+ if (!pte_none(*pte_m))
92051+ goto out;
92052+ }
92053+
92054+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92055+ page_cache_get(page_m);
92056+ page_add_file_rmap(page_m);
92057+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92058+ set_pte_at(mm, address_m, pte_m, entry_m);
92059+ update_mmu_cache(vma_m, address_m, pte_m);
92060+out:
92061+ if (ptl != ptl_m)
92062+ spin_unlock(ptl_m);
92063+ pte_unmap(pte_m);
92064+}
92065+
92066+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92067+{
92068+ struct mm_struct *mm = vma->vm_mm;
92069+ unsigned long address_m;
92070+ spinlock_t *ptl_m;
92071+ struct vm_area_struct *vma_m;
92072+ pmd_t *pmd_m;
92073+ pte_t *pte_m, entry_m;
92074+
92075+ vma_m = pax_find_mirror_vma(vma);
92076+ if (!vma_m)
92077+ return;
92078+
92079+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92080+ address_m = address + SEGMEXEC_TASK_SIZE;
92081+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92082+ pte_m = pte_offset_map(pmd_m, address_m);
92083+ ptl_m = pte_lockptr(mm, pmd_m);
92084+ if (ptl != ptl_m) {
92085+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92086+ if (!pte_none(*pte_m))
92087+ goto out;
92088+ }
92089+
92090+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92091+ set_pte_at(mm, address_m, pte_m, entry_m);
92092+out:
92093+ if (ptl != ptl_m)
92094+ spin_unlock(ptl_m);
92095+ pte_unmap(pte_m);
92096+}
92097+
92098+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92099+{
92100+ struct page *page_m;
92101+ pte_t entry;
92102+
92103+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92104+ goto out;
92105+
92106+ entry = *pte;
92107+ page_m = vm_normal_page(vma, address, entry);
92108+ if (!page_m)
92109+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92110+ else if (PageAnon(page_m)) {
92111+ if (pax_find_mirror_vma(vma)) {
92112+ pte_unmap_unlock(pte, ptl);
92113+ lock_page(page_m);
92114+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92115+ if (pte_same(entry, *pte))
92116+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92117+ else
92118+ unlock_page(page_m);
92119+ }
92120+ } else
92121+ pax_mirror_file_pte(vma, address, page_m, ptl);
92122+
92123+out:
92124+ pte_unmap_unlock(pte, ptl);
92125+}
92126+#endif
92127+
92128 /*
92129 * This routine handles present pages, when users try to write
92130 * to a shared page. It is done by copying the page to a new address
92131@@ -2807,6 +3003,12 @@ gotten:
92132 */
92133 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92134 if (likely(pte_same(*page_table, orig_pte))) {
92135+
92136+#ifdef CONFIG_PAX_SEGMEXEC
92137+ if (pax_find_mirror_vma(vma))
92138+ BUG_ON(!trylock_page(new_page));
92139+#endif
92140+
92141 if (old_page) {
92142 if (!PageAnon(old_page)) {
92143 dec_mm_counter_fast(mm, MM_FILEPAGES);
92144@@ -2858,6 +3060,10 @@ gotten:
92145 page_remove_rmap(old_page);
92146 }
92147
92148+#ifdef CONFIG_PAX_SEGMEXEC
92149+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92150+#endif
92151+
92152 /* Free the old page.. */
92153 new_page = old_page;
92154 ret |= VM_FAULT_WRITE;
92155@@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92156 swap_free(entry);
92157 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92158 try_to_free_swap(page);
92159+
92160+#ifdef CONFIG_PAX_SEGMEXEC
92161+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92162+#endif
92163+
92164 unlock_page(page);
92165 if (page != swapcache) {
92166 /*
92167@@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92168
92169 /* No need to invalidate - it was non-present before */
92170 update_mmu_cache(vma, address, page_table);
92171+
92172+#ifdef CONFIG_PAX_SEGMEXEC
92173+ pax_mirror_anon_pte(vma, address, page, ptl);
92174+#endif
92175+
92176 unlock:
92177 pte_unmap_unlock(page_table, ptl);
92178 out:
92179@@ -3177,40 +3393,6 @@ out_release:
92180 }
92181
92182 /*
92183- * This is like a special single-page "expand_{down|up}wards()",
92184- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92185- * doesn't hit another vma.
92186- */
92187-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92188-{
92189- address &= PAGE_MASK;
92190- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92191- struct vm_area_struct *prev = vma->vm_prev;
92192-
92193- /*
92194- * Is there a mapping abutting this one below?
92195- *
92196- * That's only ok if it's the same stack mapping
92197- * that has gotten split..
92198- */
92199- if (prev && prev->vm_end == address)
92200- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92201-
92202- expand_downwards(vma, address - PAGE_SIZE);
92203- }
92204- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92205- struct vm_area_struct *next = vma->vm_next;
92206-
92207- /* As VM_GROWSDOWN but s/below/above/ */
92208- if (next && next->vm_start == address + PAGE_SIZE)
92209- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92210-
92211- expand_upwards(vma, address + PAGE_SIZE);
92212- }
92213- return 0;
92214-}
92215-
92216-/*
92217 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92218 * but allow concurrent faults), and pte mapped but not yet locked.
92219 * We return with mmap_sem still held, but pte unmapped and unlocked.
92220@@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92221 unsigned long address, pte_t *page_table, pmd_t *pmd,
92222 unsigned int flags)
92223 {
92224- struct page *page;
92225+ struct page *page = NULL;
92226 spinlock_t *ptl;
92227 pte_t entry;
92228
92229- pte_unmap(page_table);
92230-
92231- /* Check if we need to add a guard page to the stack */
92232- if (check_stack_guard_page(vma, address) < 0)
92233- return VM_FAULT_SIGBUS;
92234-
92235- /* Use the zero-page for reads */
92236 if (!(flags & FAULT_FLAG_WRITE)) {
92237 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92238 vma->vm_page_prot));
92239- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92240+ ptl = pte_lockptr(mm, pmd);
92241+ spin_lock(ptl);
92242 if (!pte_none(*page_table))
92243 goto unlock;
92244 goto setpte;
92245 }
92246
92247 /* Allocate our own private page. */
92248+ pte_unmap(page_table);
92249+
92250 if (unlikely(anon_vma_prepare(vma)))
92251 goto oom;
92252 page = alloc_zeroed_user_highpage_movable(vma, address);
92253@@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92254 if (!pte_none(*page_table))
92255 goto release;
92256
92257+#ifdef CONFIG_PAX_SEGMEXEC
92258+ if (pax_find_mirror_vma(vma))
92259+ BUG_ON(!trylock_page(page));
92260+#endif
92261+
92262 inc_mm_counter_fast(mm, MM_ANONPAGES);
92263 page_add_new_anon_rmap(page, vma, address);
92264 setpte:
92265@@ -3270,6 +3453,12 @@ setpte:
92266
92267 /* No need to invalidate - it was non-present before */
92268 update_mmu_cache(vma, address, page_table);
92269+
92270+#ifdef CONFIG_PAX_SEGMEXEC
92271+ if (page)
92272+ pax_mirror_anon_pte(vma, address, page, ptl);
92273+#endif
92274+
92275 unlock:
92276 pte_unmap_unlock(page_table, ptl);
92277 return 0;
92278@@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92279 */
92280 /* Only go through if we didn't race with anybody else... */
92281 if (likely(pte_same(*page_table, orig_pte))) {
92282+
92283+#ifdef CONFIG_PAX_SEGMEXEC
92284+ if (anon && pax_find_mirror_vma(vma))
92285+ BUG_ON(!trylock_page(page));
92286+#endif
92287+
92288 flush_icache_page(vma, page);
92289 entry = mk_pte(page, vma->vm_page_prot);
92290 if (flags & FAULT_FLAG_WRITE)
92291@@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92292
92293 /* no need to invalidate: a not-present page won't be cached */
92294 update_mmu_cache(vma, address, page_table);
92295+
92296+#ifdef CONFIG_PAX_SEGMEXEC
92297+ if (anon)
92298+ pax_mirror_anon_pte(vma, address, page, ptl);
92299+ else
92300+ pax_mirror_file_pte(vma, address, page, ptl);
92301+#endif
92302+
92303 } else {
92304 if (cow_page)
92305 mem_cgroup_uncharge_page(cow_page);
92306@@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92307 if (flags & FAULT_FLAG_WRITE)
92308 flush_tlb_fix_spurious_fault(vma, address);
92309 }
92310+
92311+#ifdef CONFIG_PAX_SEGMEXEC
92312+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92313+ return 0;
92314+#endif
92315+
92316 unlock:
92317 pte_unmap_unlock(pte, ptl);
92318 return 0;
92319@@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92320 pmd_t *pmd;
92321 pte_t *pte;
92322
92323+#ifdef CONFIG_PAX_SEGMEXEC
92324+ struct vm_area_struct *vma_m;
92325+#endif
92326+
92327 if (unlikely(is_vm_hugetlb_page(vma)))
92328 return hugetlb_fault(mm, vma, address, flags);
92329
92330+#ifdef CONFIG_PAX_SEGMEXEC
92331+ vma_m = pax_find_mirror_vma(vma);
92332+ if (vma_m) {
92333+ unsigned long address_m;
92334+ pgd_t *pgd_m;
92335+ pud_t *pud_m;
92336+ pmd_t *pmd_m;
92337+
92338+ if (vma->vm_start > vma_m->vm_start) {
92339+ address_m = address;
92340+ address -= SEGMEXEC_TASK_SIZE;
92341+ vma = vma_m;
92342+ } else
92343+ address_m = address + SEGMEXEC_TASK_SIZE;
92344+
92345+ pgd_m = pgd_offset(mm, address_m);
92346+ pud_m = pud_alloc(mm, pgd_m, address_m);
92347+ if (!pud_m)
92348+ return VM_FAULT_OOM;
92349+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92350+ if (!pmd_m)
92351+ return VM_FAULT_OOM;
92352+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92353+ return VM_FAULT_OOM;
92354+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92355+ }
92356+#endif
92357+
92358 pgd = pgd_offset(mm, address);
92359 pud = pud_alloc(mm, pgd, address);
92360 if (!pud)
92361@@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92362 spin_unlock(&mm->page_table_lock);
92363 return 0;
92364 }
92365+
92366+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92367+{
92368+ pud_t *new = pud_alloc_one(mm, address);
92369+ if (!new)
92370+ return -ENOMEM;
92371+
92372+ smp_wmb(); /* See comment in __pte_alloc */
92373+
92374+ spin_lock(&mm->page_table_lock);
92375+ if (pgd_present(*pgd)) /* Another has populated it */
92376+ pud_free(mm, new);
92377+ else
92378+ pgd_populate_kernel(mm, pgd, new);
92379+ spin_unlock(&mm->page_table_lock);
92380+ return 0;
92381+}
92382 #endif /* __PAGETABLE_PUD_FOLDED */
92383
92384 #ifndef __PAGETABLE_PMD_FOLDED
92385@@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92386 spin_unlock(&mm->page_table_lock);
92387 return 0;
92388 }
92389+
92390+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92391+{
92392+ pmd_t *new = pmd_alloc_one(mm, address);
92393+ if (!new)
92394+ return -ENOMEM;
92395+
92396+ smp_wmb(); /* See comment in __pte_alloc */
92397+
92398+ spin_lock(&mm->page_table_lock);
92399+#ifndef __ARCH_HAS_4LEVEL_HACK
92400+ if (pud_present(*pud)) /* Another has populated it */
92401+ pmd_free(mm, new);
92402+ else
92403+ pud_populate_kernel(mm, pud, new);
92404+#else
92405+ if (pgd_present(*pud)) /* Another has populated it */
92406+ pmd_free(mm, new);
92407+ else
92408+ pgd_populate_kernel(mm, pud, new);
92409+#endif /* __ARCH_HAS_4LEVEL_HACK */
92410+ spin_unlock(&mm->page_table_lock);
92411+ return 0;
92412+}
92413 #endif /* __PAGETABLE_PMD_FOLDED */
92414
92415 #if !defined(__HAVE_ARCH_GATE_AREA)
92416@@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92417 gate_vma.vm_start = FIXADDR_USER_START;
92418 gate_vma.vm_end = FIXADDR_USER_END;
92419 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92420- gate_vma.vm_page_prot = __P101;
92421+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92422
92423 return 0;
92424 }
92425@@ -4007,8 +4289,8 @@ out:
92426 return ret;
92427 }
92428
92429-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92430- void *buf, int len, int write)
92431+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92432+ void *buf, size_t len, int write)
92433 {
92434 resource_size_t phys_addr;
92435 unsigned long prot = 0;
92436@@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92437 * Access another process' address space as given in mm. If non-NULL, use the
92438 * given task for page fault accounting.
92439 */
92440-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92441- unsigned long addr, void *buf, int len, int write)
92442+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92443+ unsigned long addr, void *buf, size_t len, int write)
92444 {
92445 struct vm_area_struct *vma;
92446 void *old_buf = buf;
92447@@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92448 down_read(&mm->mmap_sem);
92449 /* ignore errors, just check how much was successfully transferred */
92450 while (len) {
92451- int bytes, ret, offset;
92452+ ssize_t bytes, ret, offset;
92453 void *maddr;
92454 struct page *page = NULL;
92455
92456@@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92457 *
92458 * The caller must hold a reference on @mm.
92459 */
92460-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92461- void *buf, int len, int write)
92462+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92463+ void *buf, size_t len, int write)
92464 {
92465 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92466 }
92467@@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92468 * Source/target buffer must be kernel space,
92469 * Do not walk the page table directly, use get_user_pages
92470 */
92471-int access_process_vm(struct task_struct *tsk, unsigned long addr,
92472- void *buf, int len, int write)
92473+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92474+ void *buf, size_t len, int write)
92475 {
92476 struct mm_struct *mm;
92477- int ret;
92478+ ssize_t ret;
92479
92480 mm = get_task_mm(tsk);
92481 if (!mm)
92482diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92483index cb2f3dd..fb80468 100644
92484--- a/mm/mempolicy.c
92485+++ b/mm/mempolicy.c
92486@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92487 unsigned long vmstart;
92488 unsigned long vmend;
92489
92490+#ifdef CONFIG_PAX_SEGMEXEC
92491+ struct vm_area_struct *vma_m;
92492+#endif
92493+
92494 vma = find_vma(mm, start);
92495 if (!vma || vma->vm_start > start)
92496 return -EFAULT;
92497@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92498 err = vma_replace_policy(vma, new_pol);
92499 if (err)
92500 goto out;
92501+
92502+#ifdef CONFIG_PAX_SEGMEXEC
92503+ vma_m = pax_find_mirror_vma(vma);
92504+ if (vma_m) {
92505+ err = vma_replace_policy(vma_m, new_pol);
92506+ if (err)
92507+ goto out;
92508+ }
92509+#endif
92510+
92511 }
92512
92513 out:
92514@@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92515
92516 if (end < start)
92517 return -EINVAL;
92518+
92519+#ifdef CONFIG_PAX_SEGMEXEC
92520+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92521+ if (end > SEGMEXEC_TASK_SIZE)
92522+ return -EINVAL;
92523+ } else
92524+#endif
92525+
92526+ if (end > TASK_SIZE)
92527+ return -EINVAL;
92528+
92529 if (end == start)
92530 return 0;
92531
92532@@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92533 */
92534 tcred = __task_cred(task);
92535 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92536- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92537- !capable(CAP_SYS_NICE)) {
92538+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92539 rcu_read_unlock();
92540 err = -EPERM;
92541 goto out_put;
92542@@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92543 goto out;
92544 }
92545
92546+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92547+ if (mm != current->mm &&
92548+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92549+ mmput(mm);
92550+ err = -EPERM;
92551+ goto out;
92552+ }
92553+#endif
92554+
92555 err = do_migrate_pages(mm, old, new,
92556 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92557
92558diff --git a/mm/migrate.c b/mm/migrate.c
92559index 9194375..75c81e2 100644
92560--- a/mm/migrate.c
92561+++ b/mm/migrate.c
92562@@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92563 */
92564 tcred = __task_cred(task);
92565 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92566- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92567- !capable(CAP_SYS_NICE)) {
92568+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92569 rcu_read_unlock();
92570 err = -EPERM;
92571 goto out;
92572diff --git a/mm/mlock.c b/mm/mlock.c
92573index 192e6ee..b044449 100644
92574--- a/mm/mlock.c
92575+++ b/mm/mlock.c
92576@@ -14,6 +14,7 @@
92577 #include <linux/pagevec.h>
92578 #include <linux/mempolicy.h>
92579 #include <linux/syscalls.h>
92580+#include <linux/security.h>
92581 #include <linux/sched.h>
92582 #include <linux/export.h>
92583 #include <linux/rmap.h>
92584@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92585 {
92586 unsigned long nstart, end, tmp;
92587 struct vm_area_struct * vma, * prev;
92588- int error;
92589+ int error = 0;
92590
92591 VM_BUG_ON(start & ~PAGE_MASK);
92592 VM_BUG_ON(len != PAGE_ALIGN(len));
92593@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92594 return -EINVAL;
92595 if (end == start)
92596 return 0;
92597+ if (end > TASK_SIZE)
92598+ return -EINVAL;
92599+
92600 vma = find_vma(current->mm, start);
92601 if (!vma || vma->vm_start > start)
92602 return -ENOMEM;
92603@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92604 for (nstart = start ; ; ) {
92605 vm_flags_t newflags;
92606
92607+#ifdef CONFIG_PAX_SEGMEXEC
92608+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92609+ break;
92610+#endif
92611+
92612 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92613
92614 newflags = vma->vm_flags & ~VM_LOCKED;
92615@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92616 lock_limit >>= PAGE_SHIFT;
92617
92618 /* check against resource limits */
92619+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92620 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92621 error = do_mlock(start, len, 1);
92622 up_write(&current->mm->mmap_sem);
92623@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92624 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92625 vm_flags_t newflags;
92626
92627+#ifdef CONFIG_PAX_SEGMEXEC
92628+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92629+ break;
92630+#endif
92631+
92632 newflags = vma->vm_flags & ~VM_LOCKED;
92633 if (flags & MCL_CURRENT)
92634 newflags |= VM_LOCKED;
92635@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92636 lock_limit >>= PAGE_SHIFT;
92637
92638 ret = -ENOMEM;
92639+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92640 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92641 capable(CAP_IPC_LOCK))
92642 ret = do_mlockall(flags);
92643diff --git a/mm/mmap.c b/mm/mmap.c
92644index 546db74..650d1b9 100644
92645--- a/mm/mmap.c
92646+++ b/mm/mmap.c
92647@@ -36,6 +36,7 @@
92648 #include <linux/sched/sysctl.h>
92649 #include <linux/notifier.h>
92650 #include <linux/memory.h>
92651+#include <linux/random.h>
92652
92653 #include <asm/uaccess.h>
92654 #include <asm/cacheflush.h>
92655@@ -52,6 +53,16 @@
92656 #define arch_rebalance_pgtables(addr, len) (addr)
92657 #endif
92658
92659+static inline void verify_mm_writelocked(struct mm_struct *mm)
92660+{
92661+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92662+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92663+ up_read(&mm->mmap_sem);
92664+ BUG();
92665+ }
92666+#endif
92667+}
92668+
92669 static void unmap_region(struct mm_struct *mm,
92670 struct vm_area_struct *vma, struct vm_area_struct *prev,
92671 unsigned long start, unsigned long end);
92672@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92673 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92674 *
92675 */
92676-pgprot_t protection_map[16] = {
92677+pgprot_t protection_map[16] __read_only = {
92678 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92679 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92680 };
92681
92682-pgprot_t vm_get_page_prot(unsigned long vm_flags)
92683+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92684 {
92685- return __pgprot(pgprot_val(protection_map[vm_flags &
92686+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92687 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92688 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92689+
92690+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92691+ if (!(__supported_pte_mask & _PAGE_NX) &&
92692+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92693+ (vm_flags & (VM_READ | VM_WRITE)))
92694+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92695+#endif
92696+
92697+ return prot;
92698 }
92699 EXPORT_SYMBOL(vm_get_page_prot);
92700
92701@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92702 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92703 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92704 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92705+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92706 /*
92707 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92708 * other variables. It can be updated by several CPUs frequently.
92709@@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92710 struct vm_area_struct *next = vma->vm_next;
92711
92712 might_sleep();
92713+ BUG_ON(vma->vm_mirror);
92714 if (vma->vm_ops && vma->vm_ops->close)
92715 vma->vm_ops->close(vma);
92716 if (vma->vm_file)
92717@@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92718 * not page aligned -Ram Gupta
92719 */
92720 rlim = rlimit(RLIMIT_DATA);
92721+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92722 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92723 (mm->end_data - mm->start_data) > rlim)
92724 goto out;
92725@@ -939,6 +962,12 @@ static int
92726 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92727 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92728 {
92729+
92730+#ifdef CONFIG_PAX_SEGMEXEC
92731+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92732+ return 0;
92733+#endif
92734+
92735 if (is_mergeable_vma(vma, file, vm_flags) &&
92736 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92737 if (vma->vm_pgoff == vm_pgoff)
92738@@ -958,6 +987,12 @@ static int
92739 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92740 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92741 {
92742+
92743+#ifdef CONFIG_PAX_SEGMEXEC
92744+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92745+ return 0;
92746+#endif
92747+
92748 if (is_mergeable_vma(vma, file, vm_flags) &&
92749 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92750 pgoff_t vm_pglen;
92751@@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92752 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92753 struct vm_area_struct *prev, unsigned long addr,
92754 unsigned long end, unsigned long vm_flags,
92755- struct anon_vma *anon_vma, struct file *file,
92756+ struct anon_vma *anon_vma, struct file *file,
92757 pgoff_t pgoff, struct mempolicy *policy)
92758 {
92759 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92760 struct vm_area_struct *area, *next;
92761 int err;
92762
92763+#ifdef CONFIG_PAX_SEGMEXEC
92764+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92765+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92766+
92767+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92768+#endif
92769+
92770 /*
92771 * We later require that vma->vm_flags == vm_flags,
92772 * so this tests vma->vm_flags & VM_SPECIAL, too.
92773@@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92774 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92775 next = next->vm_next;
92776
92777+#ifdef CONFIG_PAX_SEGMEXEC
92778+ if (prev)
92779+ prev_m = pax_find_mirror_vma(prev);
92780+ if (area)
92781+ area_m = pax_find_mirror_vma(area);
92782+ if (next)
92783+ next_m = pax_find_mirror_vma(next);
92784+#endif
92785+
92786 /*
92787 * Can it merge with the predecessor?
92788 */
92789@@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92790 /* cases 1, 6 */
92791 err = vma_adjust(prev, prev->vm_start,
92792 next->vm_end, prev->vm_pgoff, NULL);
92793- } else /* cases 2, 5, 7 */
92794+
92795+#ifdef CONFIG_PAX_SEGMEXEC
92796+ if (!err && prev_m)
92797+ err = vma_adjust(prev_m, prev_m->vm_start,
92798+ next_m->vm_end, prev_m->vm_pgoff, NULL);
92799+#endif
92800+
92801+ } else { /* cases 2, 5, 7 */
92802 err = vma_adjust(prev, prev->vm_start,
92803 end, prev->vm_pgoff, NULL);
92804+
92805+#ifdef CONFIG_PAX_SEGMEXEC
92806+ if (!err && prev_m)
92807+ err = vma_adjust(prev_m, prev_m->vm_start,
92808+ end_m, prev_m->vm_pgoff, NULL);
92809+#endif
92810+
92811+ }
92812 if (err)
92813 return NULL;
92814 khugepaged_enter_vma_merge(prev);
92815@@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92816 mpol_equal(policy, vma_policy(next)) &&
92817 can_vma_merge_before(next, vm_flags,
92818 anon_vma, file, pgoff+pglen)) {
92819- if (prev && addr < prev->vm_end) /* case 4 */
92820+ if (prev && addr < prev->vm_end) { /* case 4 */
92821 err = vma_adjust(prev, prev->vm_start,
92822 addr, prev->vm_pgoff, NULL);
92823- else /* cases 3, 8 */
92824+
92825+#ifdef CONFIG_PAX_SEGMEXEC
92826+ if (!err && prev_m)
92827+ err = vma_adjust(prev_m, prev_m->vm_start,
92828+ addr_m, prev_m->vm_pgoff, NULL);
92829+#endif
92830+
92831+ } else { /* cases 3, 8 */
92832 err = vma_adjust(area, addr, next->vm_end,
92833 next->vm_pgoff - pglen, NULL);
92834+
92835+#ifdef CONFIG_PAX_SEGMEXEC
92836+ if (!err && area_m)
92837+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
92838+ next_m->vm_pgoff - pglen, NULL);
92839+#endif
92840+
92841+ }
92842 if (err)
92843 return NULL;
92844 khugepaged_enter_vma_merge(area);
92845@@ -1171,8 +1252,10 @@ none:
92846 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92847 struct file *file, long pages)
92848 {
92849- const unsigned long stack_flags
92850- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92851+
92852+#ifdef CONFIG_PAX_RANDMMAP
92853+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92854+#endif
92855
92856 mm->total_vm += pages;
92857
92858@@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92859 mm->shared_vm += pages;
92860 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92861 mm->exec_vm += pages;
92862- } else if (flags & stack_flags)
92863+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92864 mm->stack_vm += pages;
92865 }
92866 #endif /* CONFIG_PROC_FS */
92867@@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92868 * (the exception is when the underlying filesystem is noexec
92869 * mounted, in which case we dont add PROT_EXEC.)
92870 */
92871- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92872+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92873 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92874 prot |= PROT_EXEC;
92875
92876@@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92877 /* Obtain the address to map to. we verify (or select) it and ensure
92878 * that it represents a valid section of the address space.
92879 */
92880- addr = get_unmapped_area(file, addr, len, pgoff, flags);
92881+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92882 if (addr & ~PAGE_MASK)
92883 return addr;
92884
92885@@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92886 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92887 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92888
92889+#ifdef CONFIG_PAX_MPROTECT
92890+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92891+
92892+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92893+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92894+ mm->binfmt->handle_mmap)
92895+ mm->binfmt->handle_mmap(file);
92896+#endif
92897+
92898+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92899+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92900+ gr_log_rwxmmap(file);
92901+
92902+#ifdef CONFIG_PAX_EMUPLT
92903+ vm_flags &= ~VM_EXEC;
92904+#else
92905+ return -EPERM;
92906+#endif
92907+
92908+ }
92909+
92910+ if (!(vm_flags & VM_EXEC))
92911+ vm_flags &= ~VM_MAYEXEC;
92912+#else
92913+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92914+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92915+#endif
92916+ else
92917+ vm_flags &= ~VM_MAYWRITE;
92918+ }
92919+#endif
92920+
92921+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92922+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92923+ vm_flags &= ~VM_PAGEEXEC;
92924+#endif
92925+
92926 if (flags & MAP_LOCKED)
92927 if (!can_do_mlock())
92928 return -EPERM;
92929@@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92930 locked += mm->locked_vm;
92931 lock_limit = rlimit(RLIMIT_MEMLOCK);
92932 lock_limit >>= PAGE_SHIFT;
92933+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92934 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92935 return -EAGAIN;
92936 }
92937@@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92938 vm_flags |= VM_NORESERVE;
92939 }
92940
92941+ if (!gr_acl_handle_mmap(file, prot))
92942+ return -EACCES;
92943+
92944 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92945 if (!IS_ERR_VALUE(addr) &&
92946 ((vm_flags & VM_LOCKED) ||
92947@@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92948 vm_flags_t vm_flags = vma->vm_flags;
92949
92950 /* If it was private or non-writable, the write bit is already clear */
92951- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92952+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92953 return 0;
92954
92955 /* The backer wishes to know when pages are first written to? */
92956@@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92957 struct rb_node **rb_link, *rb_parent;
92958 unsigned long charged = 0;
92959
92960+#ifdef CONFIG_PAX_SEGMEXEC
92961+ struct vm_area_struct *vma_m = NULL;
92962+#endif
92963+
92964+ /*
92965+ * mm->mmap_sem is required to protect against another thread
92966+ * changing the mappings in case we sleep.
92967+ */
92968+ verify_mm_writelocked(mm);
92969+
92970 /* Check against address space limit. */
92971+
92972+#ifdef CONFIG_PAX_RANDMMAP
92973+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92974+#endif
92975+
92976 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92977 unsigned long nr_pages;
92978
92979@@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92980
92981 /* Clear old maps */
92982 error = -ENOMEM;
92983-munmap_back:
92984 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92985 if (do_munmap(mm, addr, len))
92986 return -ENOMEM;
92987- goto munmap_back;
92988+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92989 }
92990
92991 /*
92992@@ -1543,6 +1681,16 @@ munmap_back:
92993 goto unacct_error;
92994 }
92995
92996+#ifdef CONFIG_PAX_SEGMEXEC
92997+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92998+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92999+ if (!vma_m) {
93000+ error = -ENOMEM;
93001+ goto free_vma;
93002+ }
93003+ }
93004+#endif
93005+
93006 vma->vm_mm = mm;
93007 vma->vm_start = addr;
93008 vma->vm_end = addr + len;
93009@@ -1562,6 +1710,13 @@ munmap_back:
93010 if (error)
93011 goto unmap_and_free_vma;
93012
93013+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93014+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
93015+ vma->vm_flags |= VM_PAGEEXEC;
93016+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93017+ }
93018+#endif
93019+
93020 /* Can addr have changed??
93021 *
93022 * Answer: Yes, several device drivers can do it in their
93023@@ -1595,6 +1750,12 @@ munmap_back:
93024 }
93025
93026 vma_link(mm, vma, prev, rb_link, rb_parent);
93027+
93028+#ifdef CONFIG_PAX_SEGMEXEC
93029+ if (vma_m)
93030+ BUG_ON(pax_mirror_vma(vma_m, vma));
93031+#endif
93032+
93033 /* Once vma denies write, undo our temporary denial count */
93034 if (vm_flags & VM_DENYWRITE)
93035 allow_write_access(file);
93036@@ -1603,6 +1764,7 @@ out:
93037 perf_event_mmap(vma);
93038
93039 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93040+ track_exec_limit(mm, addr, addr + len, vm_flags);
93041 if (vm_flags & VM_LOCKED) {
93042 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93043 vma == get_gate_vma(current->mm)))
93044@@ -1635,6 +1797,12 @@ unmap_and_free_vma:
93045 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93046 charged = 0;
93047 free_vma:
93048+
93049+#ifdef CONFIG_PAX_SEGMEXEC
93050+ if (vma_m)
93051+ kmem_cache_free(vm_area_cachep, vma_m);
93052+#endif
93053+
93054 kmem_cache_free(vm_area_cachep, vma);
93055 unacct_error:
93056 if (charged)
93057@@ -1642,7 +1810,63 @@ unacct_error:
93058 return error;
93059 }
93060
93061-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93062+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93063+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93064+{
93065+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93066+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93067+
93068+ return 0;
93069+}
93070+#endif
93071+
93072+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93073+{
93074+ if (!vma) {
93075+#ifdef CONFIG_STACK_GROWSUP
93076+ if (addr > sysctl_heap_stack_gap)
93077+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93078+ else
93079+ vma = find_vma(current->mm, 0);
93080+ if (vma && (vma->vm_flags & VM_GROWSUP))
93081+ return false;
93082+#endif
93083+ return true;
93084+ }
93085+
93086+ if (addr + len > vma->vm_start)
93087+ return false;
93088+
93089+ if (vma->vm_flags & VM_GROWSDOWN)
93090+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93091+#ifdef CONFIG_STACK_GROWSUP
93092+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93093+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93094+#endif
93095+ else if (offset)
93096+ return offset <= vma->vm_start - addr - len;
93097+
93098+ return true;
93099+}
93100+
93101+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93102+{
93103+ if (vma->vm_start < len)
93104+ return -ENOMEM;
93105+
93106+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93107+ if (offset <= vma->vm_start - len)
93108+ return vma->vm_start - len - offset;
93109+ else
93110+ return -ENOMEM;
93111+ }
93112+
93113+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93114+ return vma->vm_start - len - sysctl_heap_stack_gap;
93115+ return -ENOMEM;
93116+}
93117+
93118+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93119 {
93120 /*
93121 * We implement the search by looking for an rbtree node that
93122@@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93123 }
93124 }
93125
93126- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93127+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93128 check_current:
93129 /* Check if current node has a suitable gap */
93130 if (gap_start > high_limit)
93131 return -ENOMEM;
93132+
93133+ if (gap_end - gap_start > info->threadstack_offset)
93134+ gap_start += info->threadstack_offset;
93135+ else
93136+ gap_start = gap_end;
93137+
93138+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93139+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93140+ gap_start += sysctl_heap_stack_gap;
93141+ else
93142+ gap_start = gap_end;
93143+ }
93144+ if (vma->vm_flags & VM_GROWSDOWN) {
93145+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93146+ gap_end -= sysctl_heap_stack_gap;
93147+ else
93148+ gap_end = gap_start;
93149+ }
93150 if (gap_end >= low_limit && gap_end - gap_start >= length)
93151 goto found;
93152
93153@@ -1744,7 +1986,7 @@ found:
93154 return gap_start;
93155 }
93156
93157-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93158+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93159 {
93160 struct mm_struct *mm = current->mm;
93161 struct vm_area_struct *vma;
93162@@ -1798,6 +2040,24 @@ check_current:
93163 gap_end = vma->vm_start;
93164 if (gap_end < low_limit)
93165 return -ENOMEM;
93166+
93167+ if (gap_end - gap_start > info->threadstack_offset)
93168+ gap_end -= info->threadstack_offset;
93169+ else
93170+ gap_end = gap_start;
93171+
93172+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93173+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93174+ gap_start += sysctl_heap_stack_gap;
93175+ else
93176+ gap_start = gap_end;
93177+ }
93178+ if (vma->vm_flags & VM_GROWSDOWN) {
93179+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93180+ gap_end -= sysctl_heap_stack_gap;
93181+ else
93182+ gap_end = gap_start;
93183+ }
93184 if (gap_start <= high_limit && gap_end - gap_start >= length)
93185 goto found;
93186
93187@@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93188 struct mm_struct *mm = current->mm;
93189 struct vm_area_struct *vma;
93190 struct vm_unmapped_area_info info;
93191+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93192
93193 if (len > TASK_SIZE - mmap_min_addr)
93194 return -ENOMEM;
93195@@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93196 if (flags & MAP_FIXED)
93197 return addr;
93198
93199+#ifdef CONFIG_PAX_RANDMMAP
93200+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93201+#endif
93202+
93203 if (addr) {
93204 addr = PAGE_ALIGN(addr);
93205 vma = find_vma(mm, addr);
93206 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93207- (!vma || addr + len <= vma->vm_start))
93208+ check_heap_stack_gap(vma, addr, len, offset))
93209 return addr;
93210 }
93211
93212@@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93213 info.low_limit = mm->mmap_base;
93214 info.high_limit = TASK_SIZE;
93215 info.align_mask = 0;
93216+ info.threadstack_offset = offset;
93217 return vm_unmapped_area(&info);
93218 }
93219 #endif
93220@@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93221 struct mm_struct *mm = current->mm;
93222 unsigned long addr = addr0;
93223 struct vm_unmapped_area_info info;
93224+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93225
93226 /* requested length too big for entire address space */
93227 if (len > TASK_SIZE - mmap_min_addr)
93228@@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93229 if (flags & MAP_FIXED)
93230 return addr;
93231
93232+#ifdef CONFIG_PAX_RANDMMAP
93233+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93234+#endif
93235+
93236 /* requesting a specific address */
93237 if (addr) {
93238 addr = PAGE_ALIGN(addr);
93239 vma = find_vma(mm, addr);
93240 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93241- (!vma || addr + len <= vma->vm_start))
93242+ check_heap_stack_gap(vma, addr, len, offset))
93243 return addr;
93244 }
93245
93246@@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93247 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93248 info.high_limit = mm->mmap_base;
93249 info.align_mask = 0;
93250+ info.threadstack_offset = offset;
93251 addr = vm_unmapped_area(&info);
93252
93253 /*
93254@@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93255 VM_BUG_ON(addr != -ENOMEM);
93256 info.flags = 0;
93257 info.low_limit = TASK_UNMAPPED_BASE;
93258+
93259+#ifdef CONFIG_PAX_RANDMMAP
93260+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93261+ info.low_limit += mm->delta_mmap;
93262+#endif
93263+
93264 info.high_limit = TASK_SIZE;
93265 addr = vm_unmapped_area(&info);
93266 }
93267@@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93268 return vma;
93269 }
93270
93271+#ifdef CONFIG_PAX_SEGMEXEC
93272+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93273+{
93274+ struct vm_area_struct *vma_m;
93275+
93276+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93277+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93278+ BUG_ON(vma->vm_mirror);
93279+ return NULL;
93280+ }
93281+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93282+ vma_m = vma->vm_mirror;
93283+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93284+ BUG_ON(vma->vm_file != vma_m->vm_file);
93285+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93286+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93287+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93288+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93289+ return vma_m;
93290+}
93291+#endif
93292+
93293 /*
93294 * Verify that the stack growth is acceptable and
93295 * update accounting. This is shared with both the
93296@@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93297 return -ENOMEM;
93298
93299 /* Stack limit test */
93300+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93301 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93302 return -ENOMEM;
93303
93304@@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93305 locked = mm->locked_vm + grow;
93306 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93307 limit >>= PAGE_SHIFT;
93308+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93309 if (locked > limit && !capable(CAP_IPC_LOCK))
93310 return -ENOMEM;
93311 }
93312@@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93313 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93314 * vma is the last one with address > vma->vm_end. Have to extend vma.
93315 */
93316+#ifndef CONFIG_IA64
93317+static
93318+#endif
93319 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93320 {
93321 int error;
93322+ bool locknext;
93323
93324 if (!(vma->vm_flags & VM_GROWSUP))
93325 return -EFAULT;
93326
93327+ /* Also guard against wrapping around to address 0. */
93328+ if (address < PAGE_ALIGN(address+1))
93329+ address = PAGE_ALIGN(address+1);
93330+ else
93331+ return -ENOMEM;
93332+
93333 /*
93334 * We must make sure the anon_vma is allocated
93335 * so that the anon_vma locking is not a noop.
93336 */
93337 if (unlikely(anon_vma_prepare(vma)))
93338 return -ENOMEM;
93339+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93340+ if (locknext && anon_vma_prepare(vma->vm_next))
93341+ return -ENOMEM;
93342 vma_lock_anon_vma(vma);
93343+ if (locknext)
93344+ vma_lock_anon_vma(vma->vm_next);
93345
93346 /*
93347 * vma->vm_start/vm_end cannot change under us because the caller
93348 * is required to hold the mmap_sem in read mode. We need the
93349- * anon_vma lock to serialize against concurrent expand_stacks.
93350- * Also guard against wrapping around to address 0.
93351+ * anon_vma locks to serialize against concurrent expand_stacks
93352+ * and expand_upwards.
93353 */
93354- if (address < PAGE_ALIGN(address+4))
93355- address = PAGE_ALIGN(address+4);
93356- else {
93357- vma_unlock_anon_vma(vma);
93358- return -ENOMEM;
93359- }
93360 error = 0;
93361
93362 /* Somebody else might have raced and expanded it already */
93363- if (address > vma->vm_end) {
93364+ 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)
93365+ error = -ENOMEM;
93366+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93367 unsigned long size, grow;
93368
93369 size = address - vma->vm_start;
93370@@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93371 }
93372 }
93373 }
93374+ if (locknext)
93375+ vma_unlock_anon_vma(vma->vm_next);
93376 vma_unlock_anon_vma(vma);
93377 khugepaged_enter_vma_merge(vma);
93378 validate_mm(vma->vm_mm);
93379@@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93380 unsigned long address)
93381 {
93382 int error;
93383+ bool lockprev = false;
93384+ struct vm_area_struct *prev;
93385
93386 /*
93387 * We must make sure the anon_vma is allocated
93388@@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93389 if (error)
93390 return error;
93391
93392+ prev = vma->vm_prev;
93393+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93394+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93395+#endif
93396+ if (lockprev && anon_vma_prepare(prev))
93397+ return -ENOMEM;
93398+ if (lockprev)
93399+ vma_lock_anon_vma(prev);
93400+
93401 vma_lock_anon_vma(vma);
93402
93403 /*
93404@@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93405 */
93406
93407 /* Somebody else might have raced and expanded it already */
93408- if (address < vma->vm_start) {
93409+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93410+ error = -ENOMEM;
93411+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93412 unsigned long size, grow;
93413
93414+#ifdef CONFIG_PAX_SEGMEXEC
93415+ struct vm_area_struct *vma_m;
93416+
93417+ vma_m = pax_find_mirror_vma(vma);
93418+#endif
93419+
93420 size = vma->vm_end - address;
93421 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93422
93423@@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93424 vma->vm_pgoff -= grow;
93425 anon_vma_interval_tree_post_update_vma(vma);
93426 vma_gap_update(vma);
93427+
93428+#ifdef CONFIG_PAX_SEGMEXEC
93429+ if (vma_m) {
93430+ anon_vma_interval_tree_pre_update_vma(vma_m);
93431+ vma_m->vm_start -= grow << PAGE_SHIFT;
93432+ vma_m->vm_pgoff -= grow;
93433+ anon_vma_interval_tree_post_update_vma(vma_m);
93434+ vma_gap_update(vma_m);
93435+ }
93436+#endif
93437+
93438 spin_unlock(&vma->vm_mm->page_table_lock);
93439
93440+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93441 perf_event_mmap(vma);
93442 }
93443 }
93444 }
93445 vma_unlock_anon_vma(vma);
93446+ if (lockprev)
93447+ vma_unlock_anon_vma(prev);
93448 khugepaged_enter_vma_merge(vma);
93449 validate_mm(vma->vm_mm);
93450 return error;
93451@@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93452 do {
93453 long nrpages = vma_pages(vma);
93454
93455+#ifdef CONFIG_PAX_SEGMEXEC
93456+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93457+ vma = remove_vma(vma);
93458+ continue;
93459+ }
93460+#endif
93461+
93462 if (vma->vm_flags & VM_ACCOUNT)
93463 nr_accounted += nrpages;
93464 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93465@@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93466 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93467 vma->vm_prev = NULL;
93468 do {
93469+
93470+#ifdef CONFIG_PAX_SEGMEXEC
93471+ if (vma->vm_mirror) {
93472+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93473+ vma->vm_mirror->vm_mirror = NULL;
93474+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
93475+ vma->vm_mirror = NULL;
93476+ }
93477+#endif
93478+
93479 vma_rb_erase(vma, &mm->mm_rb);
93480 mm->map_count--;
93481 tail_vma = vma;
93482@@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93483 struct vm_area_struct *new;
93484 int err = -ENOMEM;
93485
93486+#ifdef CONFIG_PAX_SEGMEXEC
93487+ struct vm_area_struct *vma_m, *new_m = NULL;
93488+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93489+#endif
93490+
93491 if (is_vm_hugetlb_page(vma) && (addr &
93492 ~(huge_page_mask(hstate_vma(vma)))))
93493 return -EINVAL;
93494
93495+#ifdef CONFIG_PAX_SEGMEXEC
93496+ vma_m = pax_find_mirror_vma(vma);
93497+#endif
93498+
93499 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93500 if (!new)
93501 goto out_err;
93502
93503+#ifdef CONFIG_PAX_SEGMEXEC
93504+ if (vma_m) {
93505+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93506+ if (!new_m) {
93507+ kmem_cache_free(vm_area_cachep, new);
93508+ goto out_err;
93509+ }
93510+ }
93511+#endif
93512+
93513 /* most fields are the same, copy all, and then fixup */
93514 *new = *vma;
93515
93516@@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93517 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93518 }
93519
93520+#ifdef CONFIG_PAX_SEGMEXEC
93521+ if (vma_m) {
93522+ *new_m = *vma_m;
93523+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
93524+ new_m->vm_mirror = new;
93525+ new->vm_mirror = new_m;
93526+
93527+ if (new_below)
93528+ new_m->vm_end = addr_m;
93529+ else {
93530+ new_m->vm_start = addr_m;
93531+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93532+ }
93533+ }
93534+#endif
93535+
93536 err = vma_dup_policy(vma, new);
93537 if (err)
93538 goto out_free_vma;
93539@@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93540 else
93541 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93542
93543+#ifdef CONFIG_PAX_SEGMEXEC
93544+ if (!err && vma_m) {
93545+ struct mempolicy *pol = vma_policy(new);
93546+
93547+ if (anon_vma_clone(new_m, vma_m))
93548+ goto out_free_mpol;
93549+
93550+ mpol_get(pol);
93551+ set_vma_policy(new_m, pol);
93552+
93553+ if (new_m->vm_file)
93554+ get_file(new_m->vm_file);
93555+
93556+ if (new_m->vm_ops && new_m->vm_ops->open)
93557+ new_m->vm_ops->open(new_m);
93558+
93559+ if (new_below)
93560+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93561+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93562+ else
93563+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93564+
93565+ if (err) {
93566+ if (new_m->vm_ops && new_m->vm_ops->close)
93567+ new_m->vm_ops->close(new_m);
93568+ if (new_m->vm_file)
93569+ fput(new_m->vm_file);
93570+ mpol_put(pol);
93571+ }
93572+ }
93573+#endif
93574+
93575 /* Success. */
93576 if (!err)
93577 return 0;
93578@@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93579 new->vm_ops->close(new);
93580 if (new->vm_file)
93581 fput(new->vm_file);
93582- unlink_anon_vmas(new);
93583 out_free_mpol:
93584 mpol_put(vma_policy(new));
93585 out_free_vma:
93586+
93587+#ifdef CONFIG_PAX_SEGMEXEC
93588+ if (new_m) {
93589+ unlink_anon_vmas(new_m);
93590+ kmem_cache_free(vm_area_cachep, new_m);
93591+ }
93592+#endif
93593+
93594+ unlink_anon_vmas(new);
93595 kmem_cache_free(vm_area_cachep, new);
93596 out_err:
93597 return err;
93598@@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93599 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93600 unsigned long addr, int new_below)
93601 {
93602+
93603+#ifdef CONFIG_PAX_SEGMEXEC
93604+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93605+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93606+ if (mm->map_count >= sysctl_max_map_count-1)
93607+ return -ENOMEM;
93608+ } else
93609+#endif
93610+
93611 if (mm->map_count >= sysctl_max_map_count)
93612 return -ENOMEM;
93613
93614@@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93615 * work. This now handles partial unmappings.
93616 * Jeremy Fitzhardinge <jeremy@goop.org>
93617 */
93618+#ifdef CONFIG_PAX_SEGMEXEC
93619 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93620 {
93621+ int ret = __do_munmap(mm, start, len);
93622+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93623+ return ret;
93624+
93625+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93626+}
93627+
93628+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93629+#else
93630+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93631+#endif
93632+{
93633 unsigned long end;
93634 struct vm_area_struct *vma, *prev, *last;
93635
93636+ /*
93637+ * mm->mmap_sem is required to protect against another thread
93638+ * changing the mappings in case we sleep.
93639+ */
93640+ verify_mm_writelocked(mm);
93641+
93642 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93643 return -EINVAL;
93644
93645@@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93646 /* Fix up all other VM information */
93647 remove_vma_list(mm, vma);
93648
93649+ track_exec_limit(mm, start, end, 0UL);
93650+
93651 return 0;
93652 }
93653
93654@@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93655 int ret;
93656 struct mm_struct *mm = current->mm;
93657
93658+
93659+#ifdef CONFIG_PAX_SEGMEXEC
93660+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93661+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93662+ return -EINVAL;
93663+#endif
93664+
93665 down_write(&mm->mmap_sem);
93666 ret = do_munmap(mm, start, len);
93667 up_write(&mm->mmap_sem);
93668@@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93669 return vm_munmap(addr, len);
93670 }
93671
93672-static inline void verify_mm_writelocked(struct mm_struct *mm)
93673-{
93674-#ifdef CONFIG_DEBUG_VM
93675- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93676- WARN_ON(1);
93677- up_read(&mm->mmap_sem);
93678- }
93679-#endif
93680-}
93681-
93682 /*
93683 * this is really a simplified "do_mmap". it only handles
93684 * anonymous maps. eventually we may be able to do some
93685@@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93686 struct rb_node ** rb_link, * rb_parent;
93687 pgoff_t pgoff = addr >> PAGE_SHIFT;
93688 int error;
93689+ unsigned long charged;
93690
93691 len = PAGE_ALIGN(len);
93692 if (!len)
93693@@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93694
93695 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93696
93697+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93698+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93699+ flags &= ~VM_EXEC;
93700+
93701+#ifdef CONFIG_PAX_MPROTECT
93702+ if (mm->pax_flags & MF_PAX_MPROTECT)
93703+ flags &= ~VM_MAYEXEC;
93704+#endif
93705+
93706+ }
93707+#endif
93708+
93709 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93710 if (error & ~PAGE_MASK)
93711 return error;
93712
93713+ charged = len >> PAGE_SHIFT;
93714+
93715 /*
93716 * mlock MCL_FUTURE?
93717 */
93718 if (mm->def_flags & VM_LOCKED) {
93719 unsigned long locked, lock_limit;
93720- locked = len >> PAGE_SHIFT;
93721+ locked = charged;
93722 locked += mm->locked_vm;
93723 lock_limit = rlimit(RLIMIT_MEMLOCK);
93724 lock_limit >>= PAGE_SHIFT;
93725@@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93726 /*
93727 * Clear old maps. this also does some error checking for us
93728 */
93729- munmap_back:
93730 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93731 if (do_munmap(mm, addr, len))
93732 return -ENOMEM;
93733- goto munmap_back;
93734+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93735 }
93736
93737 /* Check against address space limits *after* clearing old maps... */
93738- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93739+ if (!may_expand_vm(mm, charged))
93740 return -ENOMEM;
93741
93742 if (mm->map_count > sysctl_max_map_count)
93743 return -ENOMEM;
93744
93745- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93746+ if (security_vm_enough_memory_mm(mm, charged))
93747 return -ENOMEM;
93748
93749 /* Can we just expand an old private anonymous mapping? */
93750@@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93751 */
93752 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93753 if (!vma) {
93754- vm_unacct_memory(len >> PAGE_SHIFT);
93755+ vm_unacct_memory(charged);
93756 return -ENOMEM;
93757 }
93758
93759@@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93760 vma_link(mm, vma, prev, rb_link, rb_parent);
93761 out:
93762 perf_event_mmap(vma);
93763- mm->total_vm += len >> PAGE_SHIFT;
93764+ mm->total_vm += charged;
93765 if (flags & VM_LOCKED)
93766- mm->locked_vm += (len >> PAGE_SHIFT);
93767+ mm->locked_vm += charged;
93768 vma->vm_flags |= VM_SOFTDIRTY;
93769+ track_exec_limit(mm, addr, addr + len, flags);
93770 return addr;
93771 }
93772
93773@@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93774 while (vma) {
93775 if (vma->vm_flags & VM_ACCOUNT)
93776 nr_accounted += vma_pages(vma);
93777+ vma->vm_mirror = NULL;
93778 vma = remove_vma(vma);
93779 }
93780 vm_unacct_memory(nr_accounted);
93781@@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93782 struct vm_area_struct *prev;
93783 struct rb_node **rb_link, *rb_parent;
93784
93785+#ifdef CONFIG_PAX_SEGMEXEC
93786+ struct vm_area_struct *vma_m = NULL;
93787+#endif
93788+
93789+ if (security_mmap_addr(vma->vm_start))
93790+ return -EPERM;
93791+
93792 /*
93793 * The vm_pgoff of a purely anonymous vma should be irrelevant
93794 * until its first write fault, when page's anon_vma and index
93795@@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93796 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93797 return -ENOMEM;
93798
93799+#ifdef CONFIG_PAX_SEGMEXEC
93800+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93801+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93802+ if (!vma_m)
93803+ return -ENOMEM;
93804+ }
93805+#endif
93806+
93807 vma_link(mm, vma, prev, rb_link, rb_parent);
93808+
93809+#ifdef CONFIG_PAX_SEGMEXEC
93810+ if (vma_m)
93811+ BUG_ON(pax_mirror_vma(vma_m, vma));
93812+#endif
93813+
93814 return 0;
93815 }
93816
93817@@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93818 struct rb_node **rb_link, *rb_parent;
93819 bool faulted_in_anon_vma = true;
93820
93821+ BUG_ON(vma->vm_mirror);
93822+
93823 /*
93824 * If anonymous vma has not yet been faulted, update new pgoff
93825 * to match new location, to increase its chance of merging.
93826@@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93827 return NULL;
93828 }
93829
93830+#ifdef CONFIG_PAX_SEGMEXEC
93831+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93832+{
93833+ struct vm_area_struct *prev_m;
93834+ struct rb_node **rb_link_m, *rb_parent_m;
93835+ struct mempolicy *pol_m;
93836+
93837+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93838+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93839+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93840+ *vma_m = *vma;
93841+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93842+ if (anon_vma_clone(vma_m, vma))
93843+ return -ENOMEM;
93844+ pol_m = vma_policy(vma_m);
93845+ mpol_get(pol_m);
93846+ set_vma_policy(vma_m, pol_m);
93847+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93848+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93849+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93850+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93851+ if (vma_m->vm_file)
93852+ get_file(vma_m->vm_file);
93853+ if (vma_m->vm_ops && vma_m->vm_ops->open)
93854+ vma_m->vm_ops->open(vma_m);
93855+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93856+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93857+ vma_m->vm_mirror = vma;
93858+ vma->vm_mirror = vma_m;
93859+ return 0;
93860+}
93861+#endif
93862+
93863 /*
93864 * Return true if the calling process may expand its vm space by the passed
93865 * number of pages
93866@@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93867
93868 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93869
93870+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93871 if (cur + npages > lim)
93872 return 0;
93873 return 1;
93874@@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
93875 vma->vm_start = addr;
93876 vma->vm_end = addr + len;
93877
93878+#ifdef CONFIG_PAX_MPROTECT
93879+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93880+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93881+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93882+ return -EPERM;
93883+ if (!(vm_flags & VM_EXEC))
93884+ vm_flags &= ~VM_MAYEXEC;
93885+#else
93886+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93887+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93888+#endif
93889+ else
93890+ vm_flags &= ~VM_MAYWRITE;
93891+ }
93892+#endif
93893+
93894 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93895 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93896
93897diff --git a/mm/mprotect.c b/mm/mprotect.c
93898index bb53a65..249c052 100644
93899--- a/mm/mprotect.c
93900+++ b/mm/mprotect.c
93901@@ -23,10 +23,18 @@
93902 #include <linux/mmu_notifier.h>
93903 #include <linux/migrate.h>
93904 #include <linux/perf_event.h>
93905+#include <linux/sched/sysctl.h>
93906+
93907+#ifdef CONFIG_PAX_MPROTECT
93908+#include <linux/elf.h>
93909+#include <linux/binfmts.h>
93910+#endif
93911+
93912 #include <asm/uaccess.h>
93913 #include <asm/pgtable.h>
93914 #include <asm/cacheflush.h>
93915 #include <asm/tlbflush.h>
93916+#include <asm/mmu_context.h>
93917
93918 #ifndef pgprot_modify
93919 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93920@@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93921 return pages;
93922 }
93923
93924+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93925+/* called while holding the mmap semaphor for writing except stack expansion */
93926+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93927+{
93928+ unsigned long oldlimit, newlimit = 0UL;
93929+
93930+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93931+ return;
93932+
93933+ spin_lock(&mm->page_table_lock);
93934+ oldlimit = mm->context.user_cs_limit;
93935+ if ((prot & VM_EXEC) && oldlimit < end)
93936+ /* USER_CS limit moved up */
93937+ newlimit = end;
93938+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93939+ /* USER_CS limit moved down */
93940+ newlimit = start;
93941+
93942+ if (newlimit) {
93943+ mm->context.user_cs_limit = newlimit;
93944+
93945+#ifdef CONFIG_SMP
93946+ wmb();
93947+ cpus_clear(mm->context.cpu_user_cs_mask);
93948+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93949+#endif
93950+
93951+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93952+ }
93953+ spin_unlock(&mm->page_table_lock);
93954+ if (newlimit == end) {
93955+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
93956+
93957+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
93958+ if (is_vm_hugetlb_page(vma))
93959+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93960+ else
93961+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93962+ }
93963+}
93964+#endif
93965+
93966 int
93967 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93968 unsigned long start, unsigned long end, unsigned long newflags)
93969@@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93970 int error;
93971 int dirty_accountable = 0;
93972
93973+#ifdef CONFIG_PAX_SEGMEXEC
93974+ struct vm_area_struct *vma_m = NULL;
93975+ unsigned long start_m, end_m;
93976+
93977+ start_m = start + SEGMEXEC_TASK_SIZE;
93978+ end_m = end + SEGMEXEC_TASK_SIZE;
93979+#endif
93980+
93981 if (newflags == oldflags) {
93982 *pprev = vma;
93983 return 0;
93984 }
93985
93986+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93987+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93988+
93989+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93990+ return -ENOMEM;
93991+
93992+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93993+ return -ENOMEM;
93994+ }
93995+
93996 /*
93997 * If we make a private mapping writable we increase our commit;
93998 * but (without finer accounting) cannot reduce our commit if we
93999@@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
94000 }
94001 }
94002
94003+#ifdef CONFIG_PAX_SEGMEXEC
94004+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
94005+ if (start != vma->vm_start) {
94006+ error = split_vma(mm, vma, start, 1);
94007+ if (error)
94008+ goto fail;
94009+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
94010+ *pprev = (*pprev)->vm_next;
94011+ }
94012+
94013+ if (end != vma->vm_end) {
94014+ error = split_vma(mm, vma, end, 0);
94015+ if (error)
94016+ goto fail;
94017+ }
94018+
94019+ if (pax_find_mirror_vma(vma)) {
94020+ error = __do_munmap(mm, start_m, end_m - start_m);
94021+ if (error)
94022+ goto fail;
94023+ } else {
94024+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94025+ if (!vma_m) {
94026+ error = -ENOMEM;
94027+ goto fail;
94028+ }
94029+ vma->vm_flags = newflags;
94030+ error = pax_mirror_vma(vma_m, vma);
94031+ if (error) {
94032+ vma->vm_flags = oldflags;
94033+ goto fail;
94034+ }
94035+ }
94036+ }
94037+#endif
94038+
94039 /*
94040 * First try to merge with previous and/or next vma.
94041 */
94042@@ -285,9 +389,21 @@ success:
94043 * vm_flags and vm_page_prot are protected by the mmap_sem
94044 * held in write mode.
94045 */
94046+
94047+#ifdef CONFIG_PAX_SEGMEXEC
94048+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94049+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94050+#endif
94051+
94052 vma->vm_flags = newflags;
94053+
94054+#ifdef CONFIG_PAX_MPROTECT
94055+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94056+ mm->binfmt->handle_mprotect(vma, newflags);
94057+#endif
94058+
94059 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94060- vm_get_page_prot(newflags));
94061+ vm_get_page_prot(vma->vm_flags));
94062
94063 if (vma_wants_writenotify(vma)) {
94064 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94065@@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94066 end = start + len;
94067 if (end <= start)
94068 return -ENOMEM;
94069+
94070+#ifdef CONFIG_PAX_SEGMEXEC
94071+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94072+ if (end > SEGMEXEC_TASK_SIZE)
94073+ return -EINVAL;
94074+ } else
94075+#endif
94076+
94077+ if (end > TASK_SIZE)
94078+ return -EINVAL;
94079+
94080 if (!arch_validate_prot(prot))
94081 return -EINVAL;
94082
94083@@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94084 /*
94085 * Does the application expect PROT_READ to imply PROT_EXEC:
94086 */
94087- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94088+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94089 prot |= PROT_EXEC;
94090
94091 vm_flags = calc_vm_prot_bits(prot);
94092@@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94093 if (start > vma->vm_start)
94094 prev = vma;
94095
94096+#ifdef CONFIG_PAX_MPROTECT
94097+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94098+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94099+#endif
94100+
94101 for (nstart = start ; ; ) {
94102 unsigned long newflags;
94103
94104@@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94105
94106 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94107 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94108+ if (prot & (PROT_WRITE | PROT_EXEC))
94109+ gr_log_rwxmprotect(vma);
94110+
94111+ error = -EACCES;
94112+ goto out;
94113+ }
94114+
94115+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94116 error = -EACCES;
94117 goto out;
94118 }
94119@@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94120 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94121 if (error)
94122 goto out;
94123+
94124+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94125+
94126 nstart = tmp;
94127
94128 if (nstart < prev->vm_end)
94129diff --git a/mm/mremap.c b/mm/mremap.c
94130index 0843feb..4f5b2e6 100644
94131--- a/mm/mremap.c
94132+++ b/mm/mremap.c
94133@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94134 continue;
94135 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94136 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94137+
94138+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94139+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94140+ pte = pte_exprotect(pte);
94141+#endif
94142+
94143 pte = move_soft_dirty_pte(pte);
94144 set_pte_at(mm, new_addr, new_pte, pte);
94145 }
94146@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94147 if (is_vm_hugetlb_page(vma))
94148 goto Einval;
94149
94150+#ifdef CONFIG_PAX_SEGMEXEC
94151+ if (pax_find_mirror_vma(vma))
94152+ goto Einval;
94153+#endif
94154+
94155 /* We can't remap across vm area boundaries */
94156 if (old_len > vma->vm_end - addr)
94157 goto Efault;
94158@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94159 unsigned long ret = -EINVAL;
94160 unsigned long charged = 0;
94161 unsigned long map_flags;
94162+ unsigned long pax_task_size = TASK_SIZE;
94163
94164 if (new_addr & ~PAGE_MASK)
94165 goto out;
94166
94167- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94168+#ifdef CONFIG_PAX_SEGMEXEC
94169+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94170+ pax_task_size = SEGMEXEC_TASK_SIZE;
94171+#endif
94172+
94173+ pax_task_size -= PAGE_SIZE;
94174+
94175+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94176 goto out;
94177
94178 /* Check if the location we're moving into overlaps the
94179 * old location at all, and fail if it does.
94180 */
94181- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94182- goto out;
94183-
94184- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94185+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94186 goto out;
94187
94188 ret = do_munmap(mm, new_addr, new_len);
94189@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94190 unsigned long ret = -EINVAL;
94191 unsigned long charged = 0;
94192 bool locked = false;
94193+ unsigned long pax_task_size = TASK_SIZE;
94194
94195 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94196 return ret;
94197@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94198 if (!new_len)
94199 return ret;
94200
94201+#ifdef CONFIG_PAX_SEGMEXEC
94202+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94203+ pax_task_size = SEGMEXEC_TASK_SIZE;
94204+#endif
94205+
94206+ pax_task_size -= PAGE_SIZE;
94207+
94208+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94209+ old_len > pax_task_size || addr > pax_task_size-old_len)
94210+ return ret;
94211+
94212 down_write(&current->mm->mmap_sem);
94213
94214 if (flags & MREMAP_FIXED) {
94215@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94216 new_addr = addr;
94217 }
94218 ret = addr;
94219+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94220 goto out;
94221 }
94222 }
94223@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94224 goto out;
94225 }
94226
94227+ map_flags = vma->vm_flags;
94228 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94229+ if (!(ret & ~PAGE_MASK)) {
94230+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94231+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94232+ }
94233 }
94234 out:
94235 if (ret & ~PAGE_MASK)
94236diff --git a/mm/nommu.c b/mm/nommu.c
94237index fec093a..8162f74 100644
94238--- a/mm/nommu.c
94239+++ b/mm/nommu.c
94240@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94241 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94242 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94243 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94244-int heap_stack_gap = 0;
94245
94246 atomic_long_t mmap_pages_allocated;
94247
94248@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94249 EXPORT_SYMBOL(find_vma);
94250
94251 /*
94252- * find a VMA
94253- * - we don't extend stack VMAs under NOMMU conditions
94254- */
94255-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94256-{
94257- return find_vma(mm, addr);
94258-}
94259-
94260-/*
94261 * expand a stack to a given address
94262 * - not supported under NOMMU conditions
94263 */
94264@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94265
94266 /* most fields are the same, copy all, and then fixup */
94267 *new = *vma;
94268+ INIT_LIST_HEAD(&new->anon_vma_chain);
94269 *region = *vma->vm_region;
94270 new->vm_region = region;
94271
94272@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94273 }
94274 EXPORT_SYMBOL(generic_file_remap_pages);
94275
94276-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94277- unsigned long addr, void *buf, int len, int write)
94278+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94279+ unsigned long addr, void *buf, size_t len, int write)
94280 {
94281 struct vm_area_struct *vma;
94282
94283@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94284 *
94285 * The caller must hold a reference on @mm.
94286 */
94287-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94288- void *buf, int len, int write)
94289+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94290+ void *buf, size_t len, int write)
94291 {
94292 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94293 }
94294@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94295 * Access another process' address space.
94296 * - source/target buffer must be kernel space
94297 */
94298-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94299+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94300 {
94301 struct mm_struct *mm;
94302
94303diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94304index 7106cb1..0805f48 100644
94305--- a/mm/page-writeback.c
94306+++ b/mm/page-writeback.c
94307@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94308 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94309 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94310 */
94311-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94312+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94313 unsigned long thresh,
94314 unsigned long bg_thresh,
94315 unsigned long dirty,
94316diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94317index 56f268d..4d35ec4 100644
94318--- a/mm/page_alloc.c
94319+++ b/mm/page_alloc.c
94320@@ -61,6 +61,7 @@
94321 #include <linux/page-debug-flags.h>
94322 #include <linux/hugetlb.h>
94323 #include <linux/sched/rt.h>
94324+#include <linux/random.h>
94325
94326 #include <asm/sections.h>
94327 #include <asm/tlbflush.h>
94328@@ -354,7 +355,7 @@ out:
94329 * This usage means that zero-order pages may not be compound.
94330 */
94331
94332-static void free_compound_page(struct page *page)
94333+void free_compound_page(struct page *page)
94334 {
94335 __free_pages_ok(page, compound_order(page));
94336 }
94337@@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94338 int i;
94339 int bad = 0;
94340
94341+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94342+ unsigned long index = 1UL << order;
94343+#endif
94344+
94345 trace_mm_page_free(page, order);
94346 kmemcheck_free_shadow(page, order);
94347
94348@@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94349 debug_check_no_obj_freed(page_address(page),
94350 PAGE_SIZE << order);
94351 }
94352+
94353+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94354+ for (; index; --index)
94355+ sanitize_highpage(page + index - 1);
94356+#endif
94357+
94358 arch_free_page(page, order);
94359 kernel_map_pages(page, 1 << order, 0);
94360
94361@@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94362 local_irq_restore(flags);
94363 }
94364
94365+#ifdef CONFIG_PAX_LATENT_ENTROPY
94366+bool __meminitdata extra_latent_entropy;
94367+
94368+static int __init setup_pax_extra_latent_entropy(char *str)
94369+{
94370+ extra_latent_entropy = true;
94371+ return 0;
94372+}
94373+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94374+
94375+volatile u64 latent_entropy __latent_entropy;
94376+EXPORT_SYMBOL(latent_entropy);
94377+#endif
94378+
94379 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94380 {
94381 unsigned int nr_pages = 1 << order;
94382@@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94383 __ClearPageReserved(p);
94384 set_page_count(p, 0);
94385
94386+#ifdef CONFIG_PAX_LATENT_ENTROPY
94387+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94388+ u64 hash = 0;
94389+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94390+ const u64 *data = lowmem_page_address(page);
94391+
94392+ for (index = 0; index < end; index++)
94393+ hash ^= hash + data[index];
94394+ latent_entropy ^= hash;
94395+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94396+ }
94397+#endif
94398+
94399 page_zone(page)->managed_pages += nr_pages;
94400 set_page_refcounted(page);
94401 __free_pages(page, order);
94402@@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94403 arch_alloc_page(page, order);
94404 kernel_map_pages(page, 1 << order, 1);
94405
94406+#ifndef CONFIG_PAX_MEMORY_SANITIZE
94407 if (gfp_flags & __GFP_ZERO)
94408 prep_zero_page(page, order, gfp_flags);
94409+#endif
94410
94411 if (order && (gfp_flags & __GFP_COMP))
94412 prep_compound_page(page, order);
94413diff --git a/mm/page_io.c b/mm/page_io.c
94414index 8c79a47..a689e0d 100644
94415--- a/mm/page_io.c
94416+++ b/mm/page_io.c
94417@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94418 struct file *swap_file = sis->swap_file;
94419 struct address_space *mapping = swap_file->f_mapping;
94420 struct iovec iov = {
94421- .iov_base = kmap(page),
94422+ .iov_base = (void __force_user *)kmap(page),
94423 .iov_len = PAGE_SIZE,
94424 };
94425
94426diff --git a/mm/percpu.c b/mm/percpu.c
94427index 0d10def..6dc822d 100644
94428--- a/mm/percpu.c
94429+++ b/mm/percpu.c
94430@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94431 static unsigned int pcpu_high_unit_cpu __read_mostly;
94432
94433 /* the address of the first chunk which starts with the kernel static area */
94434-void *pcpu_base_addr __read_mostly;
94435+void *pcpu_base_addr __read_only;
94436 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94437
94438 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94439diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94440index fd26d04..0cea1b0 100644
94441--- a/mm/process_vm_access.c
94442+++ b/mm/process_vm_access.c
94443@@ -13,6 +13,7 @@
94444 #include <linux/uio.h>
94445 #include <linux/sched.h>
94446 #include <linux/highmem.h>
94447+#include <linux/security.h>
94448 #include <linux/ptrace.h>
94449 #include <linux/slab.h>
94450 #include <linux/syscalls.h>
94451@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94452 size_t iov_l_curr_offset = 0;
94453 ssize_t iov_len;
94454
94455+ return -ENOSYS; // PaX: until properly audited
94456+
94457 /*
94458 * Work out how many pages of struct pages we're going to need
94459 * when eventually calling get_user_pages
94460 */
94461 for (i = 0; i < riovcnt; i++) {
94462 iov_len = rvec[i].iov_len;
94463- if (iov_len > 0) {
94464- nr_pages_iov = ((unsigned long)rvec[i].iov_base
94465- + iov_len)
94466- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94467- / PAGE_SIZE + 1;
94468- nr_pages = max(nr_pages, nr_pages_iov);
94469- }
94470+ if (iov_len <= 0)
94471+ continue;
94472+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94473+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94474+ nr_pages = max(nr_pages, nr_pages_iov);
94475 }
94476
94477 if (nr_pages == 0)
94478@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94479 goto free_proc_pages;
94480 }
94481
94482+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94483+ rc = -EPERM;
94484+ goto put_task_struct;
94485+ }
94486+
94487 mm = mm_access(task, PTRACE_MODE_ATTACH);
94488 if (!mm || IS_ERR(mm)) {
94489 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94490diff --git a/mm/rmap.c b/mm/rmap.c
94491index 068522d..f539f21 100644
94492--- a/mm/rmap.c
94493+++ b/mm/rmap.c
94494@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94495 struct anon_vma *anon_vma = vma->anon_vma;
94496 struct anon_vma_chain *avc;
94497
94498+#ifdef CONFIG_PAX_SEGMEXEC
94499+ struct anon_vma_chain *avc_m = NULL;
94500+#endif
94501+
94502 might_sleep();
94503 if (unlikely(!anon_vma)) {
94504 struct mm_struct *mm = vma->vm_mm;
94505@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94506 if (!avc)
94507 goto out_enomem;
94508
94509+#ifdef CONFIG_PAX_SEGMEXEC
94510+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94511+ if (!avc_m)
94512+ goto out_enomem_free_avc;
94513+#endif
94514+
94515 anon_vma = find_mergeable_anon_vma(vma);
94516 allocated = NULL;
94517 if (!anon_vma) {
94518@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94519 /* page_table_lock to protect against threads */
94520 spin_lock(&mm->page_table_lock);
94521 if (likely(!vma->anon_vma)) {
94522+
94523+#ifdef CONFIG_PAX_SEGMEXEC
94524+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94525+
94526+ if (vma_m) {
94527+ BUG_ON(vma_m->anon_vma);
94528+ vma_m->anon_vma = anon_vma;
94529+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
94530+ avc_m = NULL;
94531+ }
94532+#endif
94533+
94534 vma->anon_vma = anon_vma;
94535 anon_vma_chain_link(vma, avc, anon_vma);
94536 allocated = NULL;
94537@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94538
94539 if (unlikely(allocated))
94540 put_anon_vma(allocated);
94541+
94542+#ifdef CONFIG_PAX_SEGMEXEC
94543+ if (unlikely(avc_m))
94544+ anon_vma_chain_free(avc_m);
94545+#endif
94546+
94547 if (unlikely(avc))
94548 anon_vma_chain_free(avc);
94549 }
94550 return 0;
94551
94552 out_enomem_free_avc:
94553+
94554+#ifdef CONFIG_PAX_SEGMEXEC
94555+ if (avc_m)
94556+ anon_vma_chain_free(avc_m);
94557+#endif
94558+
94559 anon_vma_chain_free(avc);
94560 out_enomem:
94561 return -ENOMEM;
94562@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94563 * Attach the anon_vmas from src to dst.
94564 * Returns 0 on success, -ENOMEM on failure.
94565 */
94566-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94567+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94568 {
94569 struct anon_vma_chain *avc, *pavc;
94570 struct anon_vma *root = NULL;
94571@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94572 * the corresponding VMA in the parent process is attached to.
94573 * Returns 0 on success, non-zero on failure.
94574 */
94575-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94576+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94577 {
94578 struct anon_vma_chain *avc;
94579 struct anon_vma *anon_vma;
94580@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94581 void __init anon_vma_init(void)
94582 {
94583 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94584- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94585- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94586+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94587+ anon_vma_ctor);
94588+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94589+ SLAB_PANIC|SLAB_NO_SANITIZE);
94590 }
94591
94592 /*
94593diff --git a/mm/shmem.c b/mm/shmem.c
94594index 902a148..58f9d59 100644
94595--- a/mm/shmem.c
94596+++ b/mm/shmem.c
94597@@ -33,7 +33,7 @@
94598 #include <linux/swap.h>
94599 #include <linux/aio.h>
94600
94601-static struct vfsmount *shm_mnt;
94602+struct vfsmount *shm_mnt;
94603
94604 #ifdef CONFIG_SHMEM
94605 /*
94606@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94607 #define BOGO_DIRENT_SIZE 20
94608
94609 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94610-#define SHORT_SYMLINK_LEN 128
94611+#define SHORT_SYMLINK_LEN 64
94612
94613 /*
94614 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94615@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94616 static int shmem_xattr_validate(const char *name)
94617 {
94618 struct { const char *prefix; size_t len; } arr[] = {
94619+
94620+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94621+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94622+#endif
94623+
94624 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94625 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94626 };
94627@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94628 if (err)
94629 return err;
94630
94631+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94632+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94633+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94634+ return -EOPNOTSUPP;
94635+ if (size > 8)
94636+ return -EINVAL;
94637+ }
94638+#endif
94639+
94640 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94641 }
94642
94643@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94644 int err = -ENOMEM;
94645
94646 /* Round up to L1_CACHE_BYTES to resist false sharing */
94647- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94648- L1_CACHE_BYTES), GFP_KERNEL);
94649+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94650 if (!sbinfo)
94651 return -ENOMEM;
94652
94653diff --git a/mm/slab.c b/mm/slab.c
94654index eb043bf..d82f5a8 100644
94655--- a/mm/slab.c
94656+++ b/mm/slab.c
94657@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94658 if ((x)->max_freeable < i) \
94659 (x)->max_freeable = i; \
94660 } while (0)
94661-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94662-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94663-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94664-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94665+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94666+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94667+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94668+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94669+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94670+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94671 #else
94672 #define STATS_INC_ACTIVE(x) do { } while (0)
94673 #define STATS_DEC_ACTIVE(x) do { } while (0)
94674@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94675 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94676 #define STATS_INC_FREEHIT(x) do { } while (0)
94677 #define STATS_INC_FREEMISS(x) do { } while (0)
94678+#define STATS_INC_SANITIZED(x) do { } while (0)
94679+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94680 #endif
94681
94682 #if DEBUG
94683@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94684 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94685 */
94686 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94687- const struct page *page, void *obj)
94688+ const struct page *page, const void *obj)
94689 {
94690 u32 offset = (obj - page->s_mem);
94691 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94692@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94693 */
94694
94695 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94696- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94697+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94698
94699 if (INDEX_AC != INDEX_NODE)
94700 kmalloc_caches[INDEX_NODE] =
94701 create_kmalloc_cache("kmalloc-node",
94702- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94703+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94704
94705 slab_early_init = 0;
94706
94707@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94708 struct array_cache *ac = cpu_cache_get(cachep);
94709
94710 check_irq_off();
94711+
94712+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94713+ if (pax_sanitize_slab) {
94714+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94715+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94716+
94717+ if (cachep->ctor)
94718+ cachep->ctor(objp);
94719+
94720+ STATS_INC_SANITIZED(cachep);
94721+ } else
94722+ STATS_INC_NOT_SANITIZED(cachep);
94723+ }
94724+#endif
94725+
94726 kmemleak_free_recursive(objp, cachep->flags);
94727 objp = cache_free_debugcheck(cachep, objp, caller);
94728
94729@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94730
94731 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94732 return;
94733+ VM_BUG_ON(!virt_addr_valid(objp));
94734 local_irq_save(flags);
94735 kfree_debugcheck(objp);
94736 c = virt_to_cache(objp);
94737@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94738 }
94739 /* cpu stats */
94740 {
94741- unsigned long allochit = atomic_read(&cachep->allochit);
94742- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94743- unsigned long freehit = atomic_read(&cachep->freehit);
94744- unsigned long freemiss = atomic_read(&cachep->freemiss);
94745+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94746+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94747+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94748+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94749
94750 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94751 allochit, allocmiss, freehit, freemiss);
94752 }
94753+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94754+ {
94755+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94756+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94757+
94758+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94759+ }
94760+#endif
94761 #endif
94762 }
94763
94764@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94765 static int __init slab_proc_init(void)
94766 {
94767 #ifdef CONFIG_DEBUG_SLAB_LEAK
94768- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94769+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94770 #endif
94771 return 0;
94772 }
94773 module_init(slab_proc_init);
94774 #endif
94775
94776+bool is_usercopy_object(const void *ptr)
94777+{
94778+ struct page *page;
94779+ struct kmem_cache *cachep;
94780+
94781+ if (ZERO_OR_NULL_PTR(ptr))
94782+ return false;
94783+
94784+ if (!slab_is_available())
94785+ return false;
94786+
94787+ if (!virt_addr_valid(ptr))
94788+ return false;
94789+
94790+ page = virt_to_head_page(ptr);
94791+
94792+ if (!PageSlab(page))
94793+ return false;
94794+
94795+ cachep = page->slab_cache;
94796+ return cachep->flags & SLAB_USERCOPY;
94797+}
94798+
94799+#ifdef CONFIG_PAX_USERCOPY
94800+const char *check_heap_object(const void *ptr, unsigned long n)
94801+{
94802+ struct page *page;
94803+ struct kmem_cache *cachep;
94804+ unsigned int objnr;
94805+ unsigned long offset;
94806+
94807+ if (ZERO_OR_NULL_PTR(ptr))
94808+ return "<null>";
94809+
94810+ if (!virt_addr_valid(ptr))
94811+ return NULL;
94812+
94813+ page = virt_to_head_page(ptr);
94814+
94815+ if (!PageSlab(page))
94816+ return NULL;
94817+
94818+ cachep = page->slab_cache;
94819+ if (!(cachep->flags & SLAB_USERCOPY))
94820+ return cachep->name;
94821+
94822+ objnr = obj_to_index(cachep, page, ptr);
94823+ BUG_ON(objnr >= cachep->num);
94824+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94825+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94826+ return NULL;
94827+
94828+ return cachep->name;
94829+}
94830+#endif
94831+
94832 /**
94833 * ksize - get the actual amount of memory allocated for a given object
94834 * @objp: Pointer to the object
94835diff --git a/mm/slab.h b/mm/slab.h
94836index 0859c42..2f7b737 100644
94837--- a/mm/slab.h
94838+++ b/mm/slab.h
94839@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94840 /* The slab cache that manages slab cache information */
94841 extern struct kmem_cache *kmem_cache;
94842
94843+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94844+#ifdef CONFIG_X86_64
94845+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94846+#else
94847+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94848+#endif
94849+extern bool pax_sanitize_slab;
94850+#endif
94851+
94852 unsigned long calculate_alignment(unsigned long flags,
94853 unsigned long align, unsigned long size);
94854
94855@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94856
94857 /* Legal flag mask for kmem_cache_create(), for various configurations */
94858 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94859- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94860+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94861+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
94862
94863 #if defined(CONFIG_DEBUG_SLAB)
94864 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94865@@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94866 return s;
94867
94868 page = virt_to_head_page(x);
94869+
94870+ BUG_ON(!PageSlab(page));
94871+
94872 cachep = page->slab_cache;
94873 if (slab_equal_or_root(cachep, s))
94874 return cachep;
94875diff --git a/mm/slab_common.c b/mm/slab_common.c
94876index 0b7bb39..334c328 100644
94877--- a/mm/slab_common.c
94878+++ b/mm/slab_common.c
94879@@ -23,11 +23,22 @@
94880
94881 #include "slab.h"
94882
94883-enum slab_state slab_state;
94884+enum slab_state slab_state __read_only;
94885 LIST_HEAD(slab_caches);
94886 DEFINE_MUTEX(slab_mutex);
94887 struct kmem_cache *kmem_cache;
94888
94889+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94890+bool pax_sanitize_slab __read_only = true;
94891+static int __init pax_sanitize_slab_setup(char *str)
94892+{
94893+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94894+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94895+ return 1;
94896+}
94897+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94898+#endif
94899+
94900 #ifdef CONFIG_DEBUG_VM
94901 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94902 size_t size)
94903@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94904
94905 err = __kmem_cache_create(s, flags);
94906 if (!err) {
94907- s->refcount = 1;
94908+ atomic_set(&s->refcount, 1);
94909 list_add(&s->list, &slab_caches);
94910 memcg_cache_list_add(memcg, s);
94911 } else {
94912@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94913
94914 get_online_cpus();
94915 mutex_lock(&slab_mutex);
94916- s->refcount--;
94917- if (!s->refcount) {
94918+ if (atomic_dec_and_test(&s->refcount)) {
94919 list_del(&s->list);
94920
94921 if (!__kmem_cache_shutdown(s)) {
94922@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94923 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94924 name, size, err);
94925
94926- s->refcount = -1; /* Exempt from merging for now */
94927+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94928 }
94929
94930 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94931@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94932
94933 create_boot_cache(s, name, size, flags);
94934 list_add(&s->list, &slab_caches);
94935- s->refcount = 1;
94936+ atomic_set(&s->refcount, 1);
94937 return s;
94938 }
94939
94940@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94941 EXPORT_SYMBOL(kmalloc_dma_caches);
94942 #endif
94943
94944+#ifdef CONFIG_PAX_USERCOPY_SLABS
94945+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94946+EXPORT_SYMBOL(kmalloc_usercopy_caches);
94947+#endif
94948+
94949 /*
94950 * Conversion table for small slabs sizes / 8 to the index in the
94951 * kmalloc array. This is necessary for slabs < 192 since we have non power
94952@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94953 return kmalloc_dma_caches[index];
94954
94955 #endif
94956+
94957+#ifdef CONFIG_PAX_USERCOPY_SLABS
94958+ if (unlikely((flags & GFP_USERCOPY)))
94959+ return kmalloc_usercopy_caches[index];
94960+
94961+#endif
94962+
94963 return kmalloc_caches[index];
94964 }
94965
94966@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94967 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94968 if (!kmalloc_caches[i]) {
94969 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94970- 1 << i, flags);
94971+ 1 << i, SLAB_USERCOPY | flags);
94972 }
94973
94974 /*
94975@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94976 * earlier power of two caches
94977 */
94978 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94979- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94980+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94981
94982 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94983- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94984+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94985 }
94986
94987 /* Kmalloc array is now usable */
94988@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94989 }
94990 }
94991 #endif
94992+
94993+#ifdef CONFIG_PAX_USERCOPY_SLABS
94994+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94995+ struct kmem_cache *s = kmalloc_caches[i];
94996+
94997+ if (s) {
94998+ int size = kmalloc_size(i);
94999+ char *n = kasprintf(GFP_NOWAIT,
95000+ "usercopy-kmalloc-%d", size);
95001+
95002+ BUG_ON(!n);
95003+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
95004+ size, SLAB_USERCOPY | flags);
95005+ }
95006+ }
95007+#endif
95008+
95009 }
95010 #endif /* !CONFIG_SLOB */
95011
95012@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
95013 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
95014 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
95015 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
95016+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95017+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
95018+#endif
95019 #endif
95020 seq_putc(m, '\n');
95021 }
95022diff --git a/mm/slob.c b/mm/slob.c
95023index 4bf8809..98a6914 100644
95024--- a/mm/slob.c
95025+++ b/mm/slob.c
95026@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
95027 /*
95028 * Return the size of a slob block.
95029 */
95030-static slobidx_t slob_units(slob_t *s)
95031+static slobidx_t slob_units(const slob_t *s)
95032 {
95033 if (s->units > 0)
95034 return s->units;
95035@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
95036 /*
95037 * Return the next free slob block pointer after this one.
95038 */
95039-static slob_t *slob_next(slob_t *s)
95040+static slob_t *slob_next(const slob_t *s)
95041 {
95042 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95043 slobidx_t next;
95044@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95045 /*
95046 * Returns true if s is the last free block in its page.
95047 */
95048-static int slob_last(slob_t *s)
95049+static int slob_last(const slob_t *s)
95050 {
95051 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95052 }
95053
95054-static void *slob_new_pages(gfp_t gfp, int order, int node)
95055+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95056 {
95057- void *page;
95058+ struct page *page;
95059
95060 #ifdef CONFIG_NUMA
95061 if (node != NUMA_NO_NODE)
95062@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95063 if (!page)
95064 return NULL;
95065
95066- return page_address(page);
95067+ __SetPageSlab(page);
95068+ return page;
95069 }
95070
95071-static void slob_free_pages(void *b, int order)
95072+static void slob_free_pages(struct page *sp, int order)
95073 {
95074 if (current->reclaim_state)
95075 current->reclaim_state->reclaimed_slab += 1 << order;
95076- free_pages((unsigned long)b, order);
95077+ __ClearPageSlab(sp);
95078+ page_mapcount_reset(sp);
95079+ sp->private = 0;
95080+ __free_pages(sp, order);
95081 }
95082
95083 /*
95084@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95085
95086 /* Not enough space: must allocate a new page */
95087 if (!b) {
95088- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95089- if (!b)
95090+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95091+ if (!sp)
95092 return NULL;
95093- sp = virt_to_page(b);
95094- __SetPageSlab(sp);
95095+ b = page_address(sp);
95096
95097 spin_lock_irqsave(&slob_lock, flags);
95098 sp->units = SLOB_UNITS(PAGE_SIZE);
95099 sp->freelist = b;
95100+ sp->private = 0;
95101 INIT_LIST_HEAD(&sp->list);
95102 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95103 set_slob_page_free(sp, slob_list);
95104@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95105 if (slob_page_free(sp))
95106 clear_slob_page_free(sp);
95107 spin_unlock_irqrestore(&slob_lock, flags);
95108- __ClearPageSlab(sp);
95109- page_mapcount_reset(sp);
95110- slob_free_pages(b, 0);
95111+ slob_free_pages(sp, 0);
95112 return;
95113 }
95114
95115+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95116+ if (pax_sanitize_slab)
95117+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95118+#endif
95119+
95120 if (!slob_page_free(sp)) {
95121 /* This slob page is about to become partially free. Easy! */
95122 sp->units = units;
95123@@ -424,11 +431,10 @@ out:
95124 */
95125
95126 static __always_inline void *
95127-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95128+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95129 {
95130- unsigned int *m;
95131- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95132- void *ret;
95133+ slob_t *m;
95134+ void *ret = NULL;
95135
95136 gfp &= gfp_allowed_mask;
95137
95138@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95139
95140 if (!m)
95141 return NULL;
95142- *m = size;
95143+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95144+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95145+ m[0].units = size;
95146+ m[1].units = align;
95147 ret = (void *)m + align;
95148
95149 trace_kmalloc_node(caller, ret,
95150 size, size + align, gfp, node);
95151 } else {
95152 unsigned int order = get_order(size);
95153+ struct page *page;
95154
95155 if (likely(order))
95156 gfp |= __GFP_COMP;
95157- ret = slob_new_pages(gfp, order, node);
95158+ page = slob_new_pages(gfp, order, node);
95159+ if (page) {
95160+ ret = page_address(page);
95161+ page->private = size;
95162+ }
95163
95164 trace_kmalloc_node(caller, ret,
95165 size, PAGE_SIZE << order, gfp, node);
95166 }
95167
95168- kmemleak_alloc(ret, size, 1, gfp);
95169+ return ret;
95170+}
95171+
95172+static __always_inline void *
95173+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95174+{
95175+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95176+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95177+
95178+ if (!ZERO_OR_NULL_PTR(ret))
95179+ kmemleak_alloc(ret, size, 1, gfp);
95180 return ret;
95181 }
95182
95183@@ -493,34 +517,112 @@ void kfree(const void *block)
95184 return;
95185 kmemleak_free(block);
95186
95187+ VM_BUG_ON(!virt_addr_valid(block));
95188 sp = virt_to_page(block);
95189- if (PageSlab(sp)) {
95190+ VM_BUG_ON(!PageSlab(sp));
95191+ if (!sp->private) {
95192 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95193- unsigned int *m = (unsigned int *)(block - align);
95194- slob_free(m, *m + align);
95195- } else
95196+ slob_t *m = (slob_t *)(block - align);
95197+ slob_free(m, m[0].units + align);
95198+ } else {
95199+ __ClearPageSlab(sp);
95200+ page_mapcount_reset(sp);
95201+ sp->private = 0;
95202 __free_pages(sp, compound_order(sp));
95203+ }
95204 }
95205 EXPORT_SYMBOL(kfree);
95206
95207+bool is_usercopy_object(const void *ptr)
95208+{
95209+ if (!slab_is_available())
95210+ return false;
95211+
95212+ // PAX: TODO
95213+
95214+ return false;
95215+}
95216+
95217+#ifdef CONFIG_PAX_USERCOPY
95218+const char *check_heap_object(const void *ptr, unsigned long n)
95219+{
95220+ struct page *page;
95221+ const slob_t *free;
95222+ const void *base;
95223+ unsigned long flags;
95224+
95225+ if (ZERO_OR_NULL_PTR(ptr))
95226+ return "<null>";
95227+
95228+ if (!virt_addr_valid(ptr))
95229+ return NULL;
95230+
95231+ page = virt_to_head_page(ptr);
95232+ if (!PageSlab(page))
95233+ return NULL;
95234+
95235+ if (page->private) {
95236+ base = page;
95237+ if (base <= ptr && n <= page->private - (ptr - base))
95238+ return NULL;
95239+ return "<slob>";
95240+ }
95241+
95242+ /* some tricky double walking to find the chunk */
95243+ spin_lock_irqsave(&slob_lock, flags);
95244+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95245+ free = page->freelist;
95246+
95247+ while (!slob_last(free) && (void *)free <= ptr) {
95248+ base = free + slob_units(free);
95249+ free = slob_next(free);
95250+ }
95251+
95252+ while (base < (void *)free) {
95253+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95254+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95255+ int offset;
95256+
95257+ if (ptr < base + align)
95258+ break;
95259+
95260+ offset = ptr - base - align;
95261+ if (offset >= m) {
95262+ base += size;
95263+ continue;
95264+ }
95265+
95266+ if (n > m - offset)
95267+ break;
95268+
95269+ spin_unlock_irqrestore(&slob_lock, flags);
95270+ return NULL;
95271+ }
95272+
95273+ spin_unlock_irqrestore(&slob_lock, flags);
95274+ return "<slob>";
95275+}
95276+#endif
95277+
95278 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95279 size_t ksize(const void *block)
95280 {
95281 struct page *sp;
95282 int align;
95283- unsigned int *m;
95284+ slob_t *m;
95285
95286 BUG_ON(!block);
95287 if (unlikely(block == ZERO_SIZE_PTR))
95288 return 0;
95289
95290 sp = virt_to_page(block);
95291- if (unlikely(!PageSlab(sp)))
95292- return PAGE_SIZE << compound_order(sp);
95293+ VM_BUG_ON(!PageSlab(sp));
95294+ if (sp->private)
95295+ return sp->private;
95296
95297 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95298- m = (unsigned int *)(block - align);
95299- return SLOB_UNITS(*m) * SLOB_UNIT;
95300+ m = (slob_t *)(block - align);
95301+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95302 }
95303 EXPORT_SYMBOL(ksize);
95304
95305@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95306
95307 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95308 {
95309- void *b;
95310+ void *b = NULL;
95311
95312 flags &= gfp_allowed_mask;
95313
95314 lockdep_trace_alloc(flags);
95315
95316+#ifdef CONFIG_PAX_USERCOPY_SLABS
95317+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95318+#else
95319 if (c->size < PAGE_SIZE) {
95320 b = slob_alloc(c->size, flags, c->align, node);
95321 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95322 SLOB_UNITS(c->size) * SLOB_UNIT,
95323 flags, node);
95324 } else {
95325- b = slob_new_pages(flags, get_order(c->size), node);
95326+ struct page *sp;
95327+
95328+ sp = slob_new_pages(flags, get_order(c->size), node);
95329+ if (sp) {
95330+ b = page_address(sp);
95331+ sp->private = c->size;
95332+ }
95333 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95334 PAGE_SIZE << get_order(c->size),
95335 flags, node);
95336 }
95337+#endif
95338
95339 if (b && c->ctor)
95340 c->ctor(b);
95341@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95342
95343 static void __kmem_cache_free(void *b, int size)
95344 {
95345- if (size < PAGE_SIZE)
95346+ struct page *sp;
95347+
95348+ sp = virt_to_page(b);
95349+ BUG_ON(!PageSlab(sp));
95350+ if (!sp->private)
95351 slob_free(b, size);
95352 else
95353- slob_free_pages(b, get_order(size));
95354+ slob_free_pages(sp, get_order(size));
95355 }
95356
95357 static void kmem_rcu_free(struct rcu_head *head)
95358@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95359
95360 void kmem_cache_free(struct kmem_cache *c, void *b)
95361 {
95362+ int size = c->size;
95363+
95364+#ifdef CONFIG_PAX_USERCOPY_SLABS
95365+ if (size + c->align < PAGE_SIZE) {
95366+ size += c->align;
95367+ b -= c->align;
95368+ }
95369+#endif
95370+
95371 kmemleak_free_recursive(b, c->flags);
95372 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95373 struct slob_rcu *slob_rcu;
95374- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95375- slob_rcu->size = c->size;
95376+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95377+ slob_rcu->size = size;
95378 call_rcu(&slob_rcu->head, kmem_rcu_free);
95379 } else {
95380- __kmem_cache_free(b, c->size);
95381+ __kmem_cache_free(b, size);
95382 }
95383
95384+#ifdef CONFIG_PAX_USERCOPY_SLABS
95385+ trace_kfree(_RET_IP_, b);
95386+#else
95387 trace_kmem_cache_free(_RET_IP_, b);
95388+#endif
95389+
95390 }
95391 EXPORT_SYMBOL(kmem_cache_free);
95392
95393diff --git a/mm/slub.c b/mm/slub.c
95394index 89490d9..c7b226a 100644
95395--- a/mm/slub.c
95396+++ b/mm/slub.c
95397@@ -207,7 +207,7 @@ struct track {
95398
95399 enum track_item { TRACK_ALLOC, TRACK_FREE };
95400
95401-#ifdef CONFIG_SYSFS
95402+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95403 static int sysfs_slab_add(struct kmem_cache *);
95404 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95405 static void sysfs_slab_remove(struct kmem_cache *);
95406@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95407 if (!t->addr)
95408 return;
95409
95410- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95411+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95412 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95413 #ifdef CONFIG_STACKTRACE
95414 {
95415@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95416
95417 slab_free_hook(s, x);
95418
95419+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95420+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95421+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95422+ if (s->ctor)
95423+ s->ctor(x);
95424+ }
95425+#endif
95426+
95427 redo:
95428 /*
95429 * Determine the currently cpus per cpu slab.
95430@@ -2710,7 +2718,7 @@ static int slub_min_objects;
95431 * Merge control. If this is set then no merging of slab caches will occur.
95432 * (Could be removed. This was introduced to pacify the merge skeptics.)
95433 */
95434-static int slub_nomerge;
95435+static int slub_nomerge = 1;
95436
95437 /*
95438 * Calculate the order of allocation given an slab object size.
95439@@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95440 s->inuse = size;
95441
95442 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95443+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95444+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95445+#endif
95446 s->ctor)) {
95447 /*
95448 * Relocate free pointer after the object if it is not
95449@@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95450 EXPORT_SYMBOL(__kmalloc_node);
95451 #endif
95452
95453+bool is_usercopy_object(const void *ptr)
95454+{
95455+ struct page *page;
95456+ struct kmem_cache *s;
95457+
95458+ if (ZERO_OR_NULL_PTR(ptr))
95459+ return false;
95460+
95461+ if (!slab_is_available())
95462+ return false;
95463+
95464+ if (!virt_addr_valid(ptr))
95465+ return false;
95466+
95467+ page = virt_to_head_page(ptr);
95468+
95469+ if (!PageSlab(page))
95470+ return false;
95471+
95472+ s = page->slab_cache;
95473+ return s->flags & SLAB_USERCOPY;
95474+}
95475+
95476+#ifdef CONFIG_PAX_USERCOPY
95477+const char *check_heap_object(const void *ptr, unsigned long n)
95478+{
95479+ struct page *page;
95480+ struct kmem_cache *s;
95481+ unsigned long offset;
95482+
95483+ if (ZERO_OR_NULL_PTR(ptr))
95484+ return "<null>";
95485+
95486+ if (!virt_addr_valid(ptr))
95487+ return NULL;
95488+
95489+ page = virt_to_head_page(ptr);
95490+
95491+ if (!PageSlab(page))
95492+ return NULL;
95493+
95494+ s = page->slab_cache;
95495+ if (!(s->flags & SLAB_USERCOPY))
95496+ return s->name;
95497+
95498+ offset = (ptr - page_address(page)) % s->size;
95499+ if (offset <= s->object_size && n <= s->object_size - offset)
95500+ return NULL;
95501+
95502+ return s->name;
95503+}
95504+#endif
95505+
95506 size_t ksize(const void *object)
95507 {
95508 struct page *page;
95509@@ -3360,6 +3424,7 @@ void kfree(const void *x)
95510 if (unlikely(ZERO_OR_NULL_PTR(x)))
95511 return;
95512
95513+ VM_BUG_ON(!virt_addr_valid(x));
95514 page = virt_to_head_page(x);
95515 if (unlikely(!PageSlab(page))) {
95516 BUG_ON(!PageCompound(page));
95517@@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95518 /*
95519 * We may have set a slab to be unmergeable during bootstrap.
95520 */
95521- if (s->refcount < 0)
95522+ if (atomic_read(&s->refcount) < 0)
95523 return 1;
95524
95525 return 0;
95526@@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95527
95528 s = find_mergeable(memcg, size, align, flags, name, ctor);
95529 if (s) {
95530- s->refcount++;
95531+ atomic_inc(&s->refcount);
95532 /*
95533 * Adjust the object sizes so that we clear
95534 * the complete object on kzalloc.
95535@@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95536 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95537
95538 if (sysfs_slab_alias(s, name)) {
95539- s->refcount--;
95540+ atomic_dec(&s->refcount);
95541 s = NULL;
95542 }
95543 }
95544@@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95545 }
95546 #endif
95547
95548-#ifdef CONFIG_SYSFS
95549+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95550 static int count_inuse(struct page *page)
95551 {
95552 return page->inuse;
95553@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95554 validate_slab_cache(kmalloc_caches[9]);
95555 }
95556 #else
95557-#ifdef CONFIG_SYSFS
95558+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95559 static void resiliency_test(void) {};
95560 #endif
95561 #endif
95562
95563-#ifdef CONFIG_SYSFS
95564+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95565 enum slab_stat_type {
95566 SL_ALL, /* All slabs */
95567 SL_PARTIAL, /* Only partially allocated slabs */
95568@@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95569
95570 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95571 {
95572- return sprintf(buf, "%d\n", s->refcount - 1);
95573+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95574 }
95575 SLAB_ATTR_RO(aliases);
95576
95577@@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95578 SLAB_ATTR_RO(cache_dma);
95579 #endif
95580
95581+#ifdef CONFIG_PAX_USERCOPY_SLABS
95582+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95583+{
95584+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95585+}
95586+SLAB_ATTR_RO(usercopy);
95587+#endif
95588+
95589 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95590 {
95591 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95592@@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95593 #ifdef CONFIG_ZONE_DMA
95594 &cache_dma_attr.attr,
95595 #endif
95596+#ifdef CONFIG_PAX_USERCOPY_SLABS
95597+ &usercopy_attr.attr,
95598+#endif
95599 #ifdef CONFIG_NUMA
95600 &remote_node_defrag_ratio_attr.attr,
95601 #endif
95602@@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95603 return name;
95604 }
95605
95606+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95607 static int sysfs_slab_add(struct kmem_cache *s)
95608 {
95609 int err;
95610@@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95611 }
95612
95613 s->kobj.kset = slab_kset;
95614- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95615+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95616 if (err) {
95617 kobject_put(&s->kobj);
95618 return err;
95619@@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95620 kobject_del(&s->kobj);
95621 kobject_put(&s->kobj);
95622 }
95623+#endif
95624
95625 /*
95626 * Need to buffer aliases during bootup until sysfs becomes
95627@@ -5216,6 +5294,7 @@ struct saved_alias {
95628
95629 static struct saved_alias *alias_list;
95630
95631+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95632 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95633 {
95634 struct saved_alias *al;
95635@@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95636 alias_list = al;
95637 return 0;
95638 }
95639+#endif
95640
95641 static int __init slab_sysfs_init(void)
95642 {
95643diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95644index 27eeab3..7c3f7f2 100644
95645--- a/mm/sparse-vmemmap.c
95646+++ b/mm/sparse-vmemmap.c
95647@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95648 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95649 if (!p)
95650 return NULL;
95651- pud_populate(&init_mm, pud, p);
95652+ pud_populate_kernel(&init_mm, pud, p);
95653 }
95654 return pud;
95655 }
95656@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95657 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95658 if (!p)
95659 return NULL;
95660- pgd_populate(&init_mm, pgd, p);
95661+ pgd_populate_kernel(&init_mm, pgd, p);
95662 }
95663 return pgd;
95664 }
95665diff --git a/mm/sparse.c b/mm/sparse.c
95666index 8cc7be0..d0f7d7a 100644
95667--- a/mm/sparse.c
95668+++ b/mm/sparse.c
95669@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95670
95671 for (i = 0; i < PAGES_PER_SECTION; i++) {
95672 if (PageHWPoison(&memmap[i])) {
95673- atomic_long_sub(1, &num_poisoned_pages);
95674+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
95675 ClearPageHWPoison(&memmap[i]);
95676 }
95677 }
95678diff --git a/mm/swap.c b/mm/swap.c
95679index 84b26aa..ce39899 100644
95680--- a/mm/swap.c
95681+++ b/mm/swap.c
95682@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95683
95684 __page_cache_release(page);
95685 dtor = get_compound_page_dtor(page);
95686+ if (!PageHuge(page))
95687+ BUG_ON(dtor != free_compound_page);
95688 (*dtor)(page);
95689 }
95690
95691diff --git a/mm/swapfile.c b/mm/swapfile.c
95692index 461fce2..363ae44 100644
95693--- a/mm/swapfile.c
95694+++ b/mm/swapfile.c
95695@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95696
95697 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95698 /* Activity counter to indicate that a swapon or swapoff has occurred */
95699-static atomic_t proc_poll_event = ATOMIC_INIT(0);
95700+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95701
95702 static inline unsigned char swap_count(unsigned char ent)
95703 {
95704@@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95705 spin_unlock(&swap_lock);
95706
95707 err = 0;
95708- atomic_inc(&proc_poll_event);
95709+ atomic_inc_unchecked(&proc_poll_event);
95710 wake_up_interruptible(&proc_poll_wait);
95711
95712 out_dput:
95713@@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95714
95715 poll_wait(file, &proc_poll_wait, wait);
95716
95717- if (seq->poll_event != atomic_read(&proc_poll_event)) {
95718- seq->poll_event = atomic_read(&proc_poll_event);
95719+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95720+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95721 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95722 }
95723
95724@@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95725 return ret;
95726
95727 seq = file->private_data;
95728- seq->poll_event = atomic_read(&proc_poll_event);
95729+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95730 return 0;
95731 }
95732
95733@@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95734 (frontswap_map) ? "FS" : "");
95735
95736 mutex_unlock(&swapon_mutex);
95737- atomic_inc(&proc_poll_event);
95738+ atomic_inc_unchecked(&proc_poll_event);
95739 wake_up_interruptible(&proc_poll_wait);
95740
95741 if (S_ISREG(inode->i_mode))
95742diff --git a/mm/util.c b/mm/util.c
95743index 808f375..e4764b5 100644
95744--- a/mm/util.c
95745+++ b/mm/util.c
95746@@ -297,6 +297,12 @@ done:
95747 void arch_pick_mmap_layout(struct mm_struct *mm)
95748 {
95749 mm->mmap_base = TASK_UNMAPPED_BASE;
95750+
95751+#ifdef CONFIG_PAX_RANDMMAP
95752+ if (mm->pax_flags & MF_PAX_RANDMMAP)
95753+ mm->mmap_base += mm->delta_mmap;
95754+#endif
95755+
95756 mm->get_unmapped_area = arch_get_unmapped_area;
95757 }
95758 #endif
95759diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95760index 0fdf968..d6686e8 100644
95761--- a/mm/vmalloc.c
95762+++ b/mm/vmalloc.c
95763@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95764
95765 pte = pte_offset_kernel(pmd, addr);
95766 do {
95767- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95768- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95769+
95770+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95771+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95772+ BUG_ON(!pte_exec(*pte));
95773+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95774+ continue;
95775+ }
95776+#endif
95777+
95778+ {
95779+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95780+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95781+ }
95782 } while (pte++, addr += PAGE_SIZE, addr != end);
95783 }
95784
95785@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95786 pte = pte_alloc_kernel(pmd, addr);
95787 if (!pte)
95788 return -ENOMEM;
95789+
95790+ pax_open_kernel();
95791 do {
95792 struct page *page = pages[*nr];
95793
95794- if (WARN_ON(!pte_none(*pte)))
95795+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95796+ if (pgprot_val(prot) & _PAGE_NX)
95797+#endif
95798+
95799+ if (!pte_none(*pte)) {
95800+ pax_close_kernel();
95801+ WARN_ON(1);
95802 return -EBUSY;
95803- if (WARN_ON(!page))
95804+ }
95805+ if (!page) {
95806+ pax_close_kernel();
95807+ WARN_ON(1);
95808 return -ENOMEM;
95809+ }
95810 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95811 (*nr)++;
95812 } while (pte++, addr += PAGE_SIZE, addr != end);
95813+ pax_close_kernel();
95814 return 0;
95815 }
95816
95817@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95818 pmd_t *pmd;
95819 unsigned long next;
95820
95821- pmd = pmd_alloc(&init_mm, pud, addr);
95822+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95823 if (!pmd)
95824 return -ENOMEM;
95825 do {
95826@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95827 pud_t *pud;
95828 unsigned long next;
95829
95830- pud = pud_alloc(&init_mm, pgd, addr);
95831+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
95832 if (!pud)
95833 return -ENOMEM;
95834 do {
95835@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95836 if (addr >= MODULES_VADDR && addr < MODULES_END)
95837 return 1;
95838 #endif
95839+
95840+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95841+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95842+ return 1;
95843+#endif
95844+
95845 return is_vmalloc_addr(x);
95846 }
95847
95848@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95849
95850 if (!pgd_none(*pgd)) {
95851 pud_t *pud = pud_offset(pgd, addr);
95852+#ifdef CONFIG_X86
95853+ if (!pud_large(*pud))
95854+#endif
95855 if (!pud_none(*pud)) {
95856 pmd_t *pmd = pmd_offset(pud, addr);
95857+#ifdef CONFIG_X86
95858+ if (!pmd_large(*pmd))
95859+#endif
95860 if (!pmd_none(*pmd)) {
95861 pte_t *ptep, pte;
95862
95863@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95864 struct vm_struct *area;
95865
95866 BUG_ON(in_interrupt());
95867+
95868+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95869+ if (flags & VM_KERNEXEC) {
95870+ if (start != VMALLOC_START || end != VMALLOC_END)
95871+ return NULL;
95872+ start = (unsigned long)MODULES_EXEC_VADDR;
95873+ end = (unsigned long)MODULES_EXEC_END;
95874+ }
95875+#endif
95876+
95877 if (flags & VM_IOREMAP)
95878 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95879
95880@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95881 if (count > totalram_pages)
95882 return NULL;
95883
95884+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95885+ if (!(pgprot_val(prot) & _PAGE_NX))
95886+ flags |= VM_KERNEXEC;
95887+#endif
95888+
95889 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95890 __builtin_return_address(0));
95891 if (!area)
95892@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95893 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95894 goto fail;
95895
95896+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95897+ if (!(pgprot_val(prot) & _PAGE_NX))
95898+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95899+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95900+ else
95901+#endif
95902+
95903 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95904 start, end, node, gfp_mask, caller);
95905 if (!area)
95906@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95907 * For tight control over page level allocator and protection flags
95908 * use __vmalloc() instead.
95909 */
95910-
95911 void *vmalloc_exec(unsigned long size)
95912 {
95913- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95914+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95915 NUMA_NO_NODE, __builtin_return_address(0));
95916 }
95917
95918@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95919 {
95920 struct vm_struct *area;
95921
95922+ BUG_ON(vma->vm_mirror);
95923+
95924 size = PAGE_ALIGN(size);
95925
95926 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95927@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95928 v->addr, v->addr + v->size, v->size);
95929
95930 if (v->caller)
95931+#ifdef CONFIG_GRKERNSEC_HIDESYM
95932+ seq_printf(m, " %pK", v->caller);
95933+#else
95934 seq_printf(m, " %pS", v->caller);
95935+#endif
95936
95937 if (v->nr_pages)
95938 seq_printf(m, " pages=%d", v->nr_pages);
95939diff --git a/mm/vmstat.c b/mm/vmstat.c
95940index 7249614..2639fc7 100644
95941--- a/mm/vmstat.c
95942+++ b/mm/vmstat.c
95943@@ -20,6 +20,7 @@
95944 #include <linux/writeback.h>
95945 #include <linux/compaction.h>
95946 #include <linux/mm_inline.h>
95947+#include <linux/grsecurity.h>
95948
95949 #include "internal.h"
95950
95951@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95952 *
95953 * vm_stat contains the global counters
95954 */
95955-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95956+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95957 EXPORT_SYMBOL(vm_stat);
95958
95959 #ifdef CONFIG_SMP
95960@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95961
95962 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95963 if (diff[i])
95964- atomic_long_add(diff[i], &vm_stat[i]);
95965+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95966 }
95967
95968 /*
95969@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95970 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95971 if (v) {
95972
95973- atomic_long_add(v, &zone->vm_stat[i]);
95974+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95975 global_diff[i] += v;
95976 #ifdef CONFIG_NUMA
95977 /* 3 seconds idle till flush */
95978@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95979
95980 v = p->vm_stat_diff[i];
95981 p->vm_stat_diff[i] = 0;
95982- atomic_long_add(v, &zone->vm_stat[i]);
95983+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95984 global_diff[i] += v;
95985 }
95986 }
95987@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95988 if (pset->vm_stat_diff[i]) {
95989 int v = pset->vm_stat_diff[i];
95990 pset->vm_stat_diff[i] = 0;
95991- atomic_long_add(v, &zone->vm_stat[i]);
95992- atomic_long_add(v, &vm_stat[i]);
95993+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95994+ atomic_long_add_unchecked(v, &vm_stat[i]);
95995 }
95996 }
95997 #endif
95998@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95999 stat_items_size += sizeof(struct vm_event_state);
96000 #endif
96001
96002- v = kmalloc(stat_items_size, GFP_KERNEL);
96003+ v = kzalloc(stat_items_size, GFP_KERNEL);
96004 m->private = v;
96005 if (!v)
96006 return ERR_PTR(-ENOMEM);
96007+
96008+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96009+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
96010+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
96011+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
96012+ && !in_group_p(grsec_proc_gid)
96013+#endif
96014+ )
96015+ return (unsigned long *)m->private + *pos;
96016+#endif
96017+#endif
96018+
96019 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
96020 v[i] = global_page_state(i);
96021 v += NR_VM_ZONE_STAT_ITEMS;
96022@@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
96023 put_online_cpus();
96024 #endif
96025 #ifdef CONFIG_PROC_FS
96026- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
96027- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
96028- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96029- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
96030+ {
96031+ mode_t gr_mode = S_IRUGO;
96032+#ifdef CONFIG_GRKERNSEC_PROC_ADD
96033+ gr_mode = S_IRUSR;
96034+#endif
96035+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
96036+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96037+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96038+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96039+ }
96040 #endif
96041 return 0;
96042 }
96043diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96044index b3d17d1..e8e4cdd 100644
96045--- a/net/8021q/vlan.c
96046+++ b/net/8021q/vlan.c
96047@@ -472,7 +472,7 @@ out:
96048 return NOTIFY_DONE;
96049 }
96050
96051-static struct notifier_block vlan_notifier_block __read_mostly = {
96052+static struct notifier_block vlan_notifier_block = {
96053 .notifier_call = vlan_device_event,
96054 };
96055
96056@@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96057 err = -EPERM;
96058 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96059 break;
96060- if ((args.u.name_type >= 0) &&
96061- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96062+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96063 struct vlan_net *vn;
96064
96065 vn = net_generic(net, vlan_net_id);
96066diff --git a/net/9p/client.c b/net/9p/client.c
96067index ee8fd6b..0469d50 100644
96068--- a/net/9p/client.c
96069+++ b/net/9p/client.c
96070@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96071 len - inline_len);
96072 } else {
96073 err = copy_from_user(ename + inline_len,
96074- uidata, len - inline_len);
96075+ (char __force_user *)uidata, len - inline_len);
96076 if (err) {
96077 err = -EFAULT;
96078 goto out_err;
96079@@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96080 kernel_buf = 1;
96081 indata = data;
96082 } else
96083- indata = (__force char *)udata;
96084+ indata = (__force_kernel char *)udata;
96085 /*
96086 * response header len is 11
96087 * PDU Header(7) + IO Size (4)
96088@@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96089 kernel_buf = 1;
96090 odata = data;
96091 } else
96092- odata = (char *)udata;
96093+ odata = (char __force_kernel *)udata;
96094 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96095 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96096 fid->fid, offset, rsize);
96097diff --git a/net/9p/mod.c b/net/9p/mod.c
96098index 6ab36ae..6f1841b 100644
96099--- a/net/9p/mod.c
96100+++ b/net/9p/mod.c
96101@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96102 void v9fs_register_trans(struct p9_trans_module *m)
96103 {
96104 spin_lock(&v9fs_trans_lock);
96105- list_add_tail(&m->list, &v9fs_trans_list);
96106+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96107 spin_unlock(&v9fs_trans_lock);
96108 }
96109 EXPORT_SYMBOL(v9fs_register_trans);
96110@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96111 void v9fs_unregister_trans(struct p9_trans_module *m)
96112 {
96113 spin_lock(&v9fs_trans_lock);
96114- list_del_init(&m->list);
96115+ pax_list_del_init((struct list_head *)&m->list);
96116 spin_unlock(&v9fs_trans_lock);
96117 }
96118 EXPORT_SYMBOL(v9fs_unregister_trans);
96119diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96120index 9321a77..ed2f256 100644
96121--- a/net/9p/trans_fd.c
96122+++ b/net/9p/trans_fd.c
96123@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96124 oldfs = get_fs();
96125 set_fs(get_ds());
96126 /* The cast to a user pointer is valid due to the set_fs() */
96127- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96128+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96129 set_fs(oldfs);
96130
96131 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96132diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96133index 876fbe8..8bbea9f 100644
96134--- a/net/atm/atm_misc.c
96135+++ b/net/atm/atm_misc.c
96136@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96137 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96138 return 1;
96139 atm_return(vcc, truesize);
96140- atomic_inc(&vcc->stats->rx_drop);
96141+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96142 return 0;
96143 }
96144 EXPORT_SYMBOL(atm_charge);
96145@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96146 }
96147 }
96148 atm_return(vcc, guess);
96149- atomic_inc(&vcc->stats->rx_drop);
96150+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96151 return NULL;
96152 }
96153 EXPORT_SYMBOL(atm_alloc_charge);
96154@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96155
96156 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96157 {
96158-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96159+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96160 __SONET_ITEMS
96161 #undef __HANDLE_ITEM
96162 }
96163@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96164
96165 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96166 {
96167-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96168+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96169 __SONET_ITEMS
96170 #undef __HANDLE_ITEM
96171 }
96172diff --git a/net/atm/lec.c b/net/atm/lec.c
96173index f23916b..dd4d26b 100644
96174--- a/net/atm/lec.c
96175+++ b/net/atm/lec.c
96176@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96177 }
96178
96179 static struct lane2_ops lane2_ops = {
96180- lane2_resolve, /* resolve, spec 3.1.3 */
96181- lane2_associate_req, /* associate_req, spec 3.1.4 */
96182- NULL /* associate indicator, spec 3.1.5 */
96183+ .resolve = lane2_resolve,
96184+ .associate_req = lane2_associate_req,
96185+ .associate_indicator = NULL
96186 };
96187
96188 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96189diff --git a/net/atm/lec.h b/net/atm/lec.h
96190index 4149db1..f2ab682 100644
96191--- a/net/atm/lec.h
96192+++ b/net/atm/lec.h
96193@@ -48,7 +48,7 @@ struct lane2_ops {
96194 const u8 *tlvs, u32 sizeoftlvs);
96195 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96196 const u8 *tlvs, u32 sizeoftlvs);
96197-};
96198+} __no_const;
96199
96200 /*
96201 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96202diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96203index d1b2d9a..d549f7f 100644
96204--- a/net/atm/mpoa_caches.c
96205+++ b/net/atm/mpoa_caches.c
96206@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96207
96208
96209 static struct in_cache_ops ingress_ops = {
96210- in_cache_add_entry, /* add_entry */
96211- in_cache_get, /* get */
96212- in_cache_get_with_mask, /* get_with_mask */
96213- in_cache_get_by_vcc, /* get_by_vcc */
96214- in_cache_put, /* put */
96215- in_cache_remove_entry, /* remove_entry */
96216- cache_hit, /* cache_hit */
96217- clear_count_and_expired, /* clear_count */
96218- check_resolving_entries, /* check_resolving */
96219- refresh_entries, /* refresh */
96220- in_destroy_cache /* destroy_cache */
96221+ .add_entry = in_cache_add_entry,
96222+ .get = in_cache_get,
96223+ .get_with_mask = in_cache_get_with_mask,
96224+ .get_by_vcc = in_cache_get_by_vcc,
96225+ .put = in_cache_put,
96226+ .remove_entry = in_cache_remove_entry,
96227+ .cache_hit = cache_hit,
96228+ .clear_count = clear_count_and_expired,
96229+ .check_resolving = check_resolving_entries,
96230+ .refresh = refresh_entries,
96231+ .destroy_cache = in_destroy_cache
96232 };
96233
96234 static struct eg_cache_ops egress_ops = {
96235- eg_cache_add_entry, /* add_entry */
96236- eg_cache_get_by_cache_id, /* get_by_cache_id */
96237- eg_cache_get_by_tag, /* get_by_tag */
96238- eg_cache_get_by_vcc, /* get_by_vcc */
96239- eg_cache_get_by_src_ip, /* get_by_src_ip */
96240- eg_cache_put, /* put */
96241- eg_cache_remove_entry, /* remove_entry */
96242- update_eg_cache_entry, /* update */
96243- clear_expired, /* clear_expired */
96244- eg_destroy_cache /* destroy_cache */
96245+ .add_entry = eg_cache_add_entry,
96246+ .get_by_cache_id = eg_cache_get_by_cache_id,
96247+ .get_by_tag = eg_cache_get_by_tag,
96248+ .get_by_vcc = eg_cache_get_by_vcc,
96249+ .get_by_src_ip = eg_cache_get_by_src_ip,
96250+ .put = eg_cache_put,
96251+ .remove_entry = eg_cache_remove_entry,
96252+ .update = update_eg_cache_entry,
96253+ .clear_expired = clear_expired,
96254+ .destroy_cache = eg_destroy_cache
96255 };
96256
96257
96258diff --git a/net/atm/proc.c b/net/atm/proc.c
96259index bbb6461..cf04016 100644
96260--- a/net/atm/proc.c
96261+++ b/net/atm/proc.c
96262@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96263 const struct k_atm_aal_stats *stats)
96264 {
96265 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96266- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96267- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96268- atomic_read(&stats->rx_drop));
96269+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96270+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96271+ atomic_read_unchecked(&stats->rx_drop));
96272 }
96273
96274 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96275diff --git a/net/atm/resources.c b/net/atm/resources.c
96276index 0447d5d..3cf4728 100644
96277--- a/net/atm/resources.c
96278+++ b/net/atm/resources.c
96279@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96280 static void copy_aal_stats(struct k_atm_aal_stats *from,
96281 struct atm_aal_stats *to)
96282 {
96283-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96284+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96285 __AAL_STAT_ITEMS
96286 #undef __HANDLE_ITEM
96287 }
96288@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96289 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96290 struct atm_aal_stats *to)
96291 {
96292-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96293+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96294 __AAL_STAT_ITEMS
96295 #undef __HANDLE_ITEM
96296 }
96297diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96298index 919a5ce..cc6b444 100644
96299--- a/net/ax25/sysctl_net_ax25.c
96300+++ b/net/ax25/sysctl_net_ax25.c
96301@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96302 {
96303 char path[sizeof("net/ax25/") + IFNAMSIZ];
96304 int k;
96305- struct ctl_table *table;
96306+ ctl_table_no_const *table;
96307
96308 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96309 if (!table)
96310diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96311index f7270b9..cd0d879 100644
96312--- a/net/batman-adv/bat_iv_ogm.c
96313+++ b/net/batman-adv/bat_iv_ogm.c
96314@@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96315
96316 /* randomize initial seqno to avoid collision */
96317 get_random_bytes(&random_seqno, sizeof(random_seqno));
96318- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96319+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96320
96321 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96322 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96323@@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96324 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96325
96326 /* change sequence number to network order */
96327- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96328+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96329 batadv_ogm_packet->seqno = htonl(seqno);
96330- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96331+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96332
96333 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96334 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96335@@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96336 return;
96337
96338 /* could be changed by schedule_own_packet() */
96339- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96340+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96341
96342 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96343 has_directlink_flag = 1;
96344diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96345index 6ddb614..ca7e886 100644
96346--- a/net/batman-adv/fragmentation.c
96347+++ b/net/batman-adv/fragmentation.c
96348@@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96349 frag_header.packet_type = BATADV_UNICAST_FRAG;
96350 frag_header.version = BATADV_COMPAT_VERSION;
96351 frag_header.ttl = BATADV_TTL;
96352- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96353+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96354 frag_header.reserved = 0;
96355 frag_header.no = 0;
96356 frag_header.total_size = htons(skb->len);
96357diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96358index a8f99d1..11797ef 100644
96359--- a/net/batman-adv/soft-interface.c
96360+++ b/net/batman-adv/soft-interface.c
96361@@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96362 primary_if->net_dev->dev_addr, ETH_ALEN);
96363
96364 /* set broadcast sequence number */
96365- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96366+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96367 bcast_packet->seqno = htonl(seqno);
96368
96369 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96370@@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96371 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96372
96373 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96374- atomic_set(&bat_priv->bcast_seqno, 1);
96375+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96376 atomic_set(&bat_priv->tt.vn, 0);
96377 atomic_set(&bat_priv->tt.local_changes, 0);
96378 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96379@@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96380
96381 /* randomize initial seqno to avoid collision */
96382 get_random_bytes(&random_seqno, sizeof(random_seqno));
96383- atomic_set(&bat_priv->frag_seqno, random_seqno);
96384+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96385
96386 bat_priv->primary_if = NULL;
96387 bat_priv->num_ifaces = 0;
96388diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96389index 91dd369..9c25750 100644
96390--- a/net/batman-adv/types.h
96391+++ b/net/batman-adv/types.h
96392@@ -56,7 +56,7 @@
96393 struct batadv_hard_iface_bat_iv {
96394 unsigned char *ogm_buff;
96395 int ogm_buff_len;
96396- atomic_t ogm_seqno;
96397+ atomic_unchecked_t ogm_seqno;
96398 };
96399
96400 /**
96401@@ -673,7 +673,7 @@ struct batadv_priv {
96402 atomic_t bonding;
96403 atomic_t fragmentation;
96404 atomic_t packet_size_max;
96405- atomic_t frag_seqno;
96406+ atomic_unchecked_t frag_seqno;
96407 #ifdef CONFIG_BATMAN_ADV_BLA
96408 atomic_t bridge_loop_avoidance;
96409 #endif
96410@@ -687,7 +687,7 @@ struct batadv_priv {
96411 #ifdef CONFIG_BATMAN_ADV_DEBUG
96412 atomic_t log_level;
96413 #endif
96414- atomic_t bcast_seqno;
96415+ atomic_unchecked_t bcast_seqno;
96416 atomic_t bcast_queue_left;
96417 atomic_t batman_queue_left;
96418 char num_ifaces;
96419diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96420index 7552f9e..074ce29 100644
96421--- a/net/bluetooth/hci_sock.c
96422+++ b/net/bluetooth/hci_sock.c
96423@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96424 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96425 }
96426
96427- len = min_t(unsigned int, len, sizeof(uf));
96428+ len = min((size_t)len, sizeof(uf));
96429 if (copy_from_user(&uf, optval, len)) {
96430 err = -EFAULT;
96431 break;
96432diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96433index 4af3821..f2ba46c 100644
96434--- a/net/bluetooth/l2cap_core.c
96435+++ b/net/bluetooth/l2cap_core.c
96436@@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96437 break;
96438
96439 case L2CAP_CONF_RFC:
96440- if (olen == sizeof(rfc))
96441- memcpy(&rfc, (void *)val, olen);
96442+ if (olen != sizeof(rfc))
96443+ break;
96444+
96445+ memcpy(&rfc, (void *)val, olen);
96446
96447 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96448 rfc.mode != chan->mode)
96449diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96450index 7cc24d2..e83f531 100644
96451--- a/net/bluetooth/l2cap_sock.c
96452+++ b/net/bluetooth/l2cap_sock.c
96453@@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96454 struct sock *sk = sock->sk;
96455 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96456 struct l2cap_options opts;
96457- int len, err = 0;
96458+ int err = 0;
96459+ size_t len = optlen;
96460 u32 opt;
96461
96462 BT_DBG("sk %p", sk);
96463@@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96464 opts.max_tx = chan->max_tx;
96465 opts.txwin_size = chan->tx_win;
96466
96467- len = min_t(unsigned int, sizeof(opts), optlen);
96468+ len = min(sizeof(opts), len);
96469 if (copy_from_user((char *) &opts, optval, len)) {
96470 err = -EFAULT;
96471 break;
96472@@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96473 struct bt_security sec;
96474 struct bt_power pwr;
96475 struct l2cap_conn *conn;
96476- int len, err = 0;
96477+ int err = 0;
96478+ size_t len = optlen;
96479 u32 opt;
96480
96481 BT_DBG("sk %p", sk);
96482@@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96483
96484 sec.level = BT_SECURITY_LOW;
96485
96486- len = min_t(unsigned int, sizeof(sec), optlen);
96487+ len = min(sizeof(sec), len);
96488 if (copy_from_user((char *) &sec, optval, len)) {
96489 err = -EFAULT;
96490 break;
96491@@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96492
96493 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96494
96495- len = min_t(unsigned int, sizeof(pwr), optlen);
96496+ len = min(sizeof(pwr), len);
96497 if (copy_from_user((char *) &pwr, optval, len)) {
96498 err = -EFAULT;
96499 break;
96500diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96501index 3c2d3e4..884855a 100644
96502--- a/net/bluetooth/rfcomm/sock.c
96503+++ b/net/bluetooth/rfcomm/sock.c
96504@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96505 struct sock *sk = sock->sk;
96506 struct bt_security sec;
96507 int err = 0;
96508- size_t len;
96509+ size_t len = optlen;
96510 u32 opt;
96511
96512 BT_DBG("sk %p", sk);
96513@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96514
96515 sec.level = BT_SECURITY_LOW;
96516
96517- len = min_t(unsigned int, sizeof(sec), optlen);
96518+ len = min(sizeof(sec), len);
96519 if (copy_from_user((char *) &sec, optval, len)) {
96520 err = -EFAULT;
96521 break;
96522diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96523index 84fcf9f..e389b27 100644
96524--- a/net/bluetooth/rfcomm/tty.c
96525+++ b/net/bluetooth/rfcomm/tty.c
96526@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96527 BT_DBG("tty %p id %d", tty, tty->index);
96528
96529 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96530- dev->channel, dev->port.count);
96531+ dev->channel, atomic_read(&dev->port.count));
96532
96533 err = tty_port_open(&dev->port, tty, filp);
96534 if (err)
96535@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96536 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96537
96538 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96539- dev->port.count);
96540+ atomic_read(&dev->port.count));
96541
96542 tty_port_close(&dev->port, tty, filp);
96543 }
96544diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96545index ac78024..161a80c 100644
96546--- a/net/bridge/netfilter/ebtables.c
96547+++ b/net/bridge/netfilter/ebtables.c
96548@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96549 tmp.valid_hooks = t->table->valid_hooks;
96550 }
96551 mutex_unlock(&ebt_mutex);
96552- if (copy_to_user(user, &tmp, *len) != 0){
96553+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96554 BUGPRINT("c2u Didn't work\n");
96555 ret = -EFAULT;
96556 break;
96557@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96558 goto out;
96559 tmp.valid_hooks = t->valid_hooks;
96560
96561- if (copy_to_user(user, &tmp, *len) != 0) {
96562+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96563 ret = -EFAULT;
96564 break;
96565 }
96566@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96567 tmp.entries_size = t->table->entries_size;
96568 tmp.valid_hooks = t->table->valid_hooks;
96569
96570- if (copy_to_user(user, &tmp, *len) != 0) {
96571+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96572 ret = -EFAULT;
96573 break;
96574 }
96575diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96576index 0f45522..dab651f 100644
96577--- a/net/caif/cfctrl.c
96578+++ b/net/caif/cfctrl.c
96579@@ -10,6 +10,7 @@
96580 #include <linux/spinlock.h>
96581 #include <linux/slab.h>
96582 #include <linux/pkt_sched.h>
96583+#include <linux/sched.h>
96584 #include <net/caif/caif_layer.h>
96585 #include <net/caif/cfpkt.h>
96586 #include <net/caif/cfctrl.h>
96587@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96588 memset(&dev_info, 0, sizeof(dev_info));
96589 dev_info.id = 0xff;
96590 cfsrvl_init(&this->serv, 0, &dev_info, false);
96591- atomic_set(&this->req_seq_no, 1);
96592- atomic_set(&this->rsp_seq_no, 1);
96593+ atomic_set_unchecked(&this->req_seq_no, 1);
96594+ atomic_set_unchecked(&this->rsp_seq_no, 1);
96595 this->serv.layer.receive = cfctrl_recv;
96596 sprintf(this->serv.layer.name, "ctrl");
96597 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96598@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96599 struct cfctrl_request_info *req)
96600 {
96601 spin_lock_bh(&ctrl->info_list_lock);
96602- atomic_inc(&ctrl->req_seq_no);
96603- req->sequence_no = atomic_read(&ctrl->req_seq_no);
96604+ atomic_inc_unchecked(&ctrl->req_seq_no);
96605+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96606 list_add_tail(&req->list, &ctrl->list);
96607 spin_unlock_bh(&ctrl->info_list_lock);
96608 }
96609@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96610 if (p != first)
96611 pr_warn("Requests are not received in order\n");
96612
96613- atomic_set(&ctrl->rsp_seq_no,
96614+ atomic_set_unchecked(&ctrl->rsp_seq_no,
96615 p->sequence_no);
96616 list_del(&p->list);
96617 goto out;
96618diff --git a/net/can/af_can.c b/net/can/af_can.c
96619index a27f8aa..67174a3 100644
96620--- a/net/can/af_can.c
96621+++ b/net/can/af_can.c
96622@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96623 };
96624
96625 /* notifier block for netdevice event */
96626-static struct notifier_block can_netdev_notifier __read_mostly = {
96627+static struct notifier_block can_netdev_notifier = {
96628 .notifier_call = can_notifier,
96629 };
96630
96631diff --git a/net/can/gw.c b/net/can/gw.c
96632index 3f9b0f3..fc6d4fa 100644
96633--- a/net/can/gw.c
96634+++ b/net/can/gw.c
96635@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96636 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96637
96638 static HLIST_HEAD(cgw_list);
96639-static struct notifier_block notifier;
96640
96641 static struct kmem_cache *cgw_cache __read_mostly;
96642
96643@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96644 return err;
96645 }
96646
96647+static struct notifier_block notifier = {
96648+ .notifier_call = cgw_notifier
96649+};
96650+
96651 static __init int cgw_module_init(void)
96652 {
96653 /* sanitize given module parameter */
96654@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96655 return -ENOMEM;
96656
96657 /* set notifier */
96658- notifier.notifier_call = cgw_notifier;
96659 register_netdevice_notifier(&notifier);
96660
96661 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96662diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96663index 464303f..9c30218 100644
96664--- a/net/ceph/messenger.c
96665+++ b/net/ceph/messenger.c
96666@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96667 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96668
96669 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96670-static atomic_t addr_str_seq = ATOMIC_INIT(0);
96671+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96672
96673 static struct page *zero_page; /* used in certain error cases */
96674
96675@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96676 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96677 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96678
96679- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96680+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96681 s = addr_str[i];
96682
96683 switch (ss->ss_family) {
96684diff --git a/net/compat.c b/net/compat.c
96685index f50161f..94fa415 100644
96686--- a/net/compat.c
96687+++ b/net/compat.c
96688@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96689 return -EFAULT;
96690 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96691 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96692- kmsg->msg_name = compat_ptr(tmp1);
96693- kmsg->msg_iov = compat_ptr(tmp2);
96694- kmsg->msg_control = compat_ptr(tmp3);
96695+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96696+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96697+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96698 return 0;
96699 }
96700
96701@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96702
96703 if (kern_msg->msg_namelen) {
96704 if (mode == VERIFY_READ) {
96705- int err = move_addr_to_kernel(kern_msg->msg_name,
96706+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96707 kern_msg->msg_namelen,
96708 kern_address);
96709 if (err < 0)
96710@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96711 kern_msg->msg_name = NULL;
96712
96713 tot_len = iov_from_user_compat_to_kern(kern_iov,
96714- (struct compat_iovec __user *)kern_msg->msg_iov,
96715+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
96716 kern_msg->msg_iovlen);
96717 if (tot_len >= 0)
96718 kern_msg->msg_iov = kern_iov;
96719@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96720
96721 #define CMSG_COMPAT_FIRSTHDR(msg) \
96722 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96723- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96724+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96725 (struct compat_cmsghdr __user *)NULL)
96726
96727 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96728 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96729 (ucmlen) <= (unsigned long) \
96730 ((mhdr)->msg_controllen - \
96731- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96732+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96733
96734 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96735 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96736 {
96737 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96738- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96739+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96740 msg->msg_controllen)
96741 return NULL;
96742 return (struct compat_cmsghdr __user *)ptr;
96743@@ -222,7 +222,7 @@ Efault:
96744
96745 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96746 {
96747- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96748+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96749 struct compat_cmsghdr cmhdr;
96750 struct compat_timeval ctv;
96751 struct compat_timespec cts[3];
96752@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96753
96754 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96755 {
96756- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96757+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96758 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96759 int fdnum = scm->fp->count;
96760 struct file **fp = scm->fp->fp;
96761@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96762 return -EFAULT;
96763 old_fs = get_fs();
96764 set_fs(KERNEL_DS);
96765- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96766+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96767 set_fs(old_fs);
96768
96769 return err;
96770@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96771 len = sizeof(ktime);
96772 old_fs = get_fs();
96773 set_fs(KERNEL_DS);
96774- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96775+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96776 set_fs(old_fs);
96777
96778 if (!err) {
96779@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96780 case MCAST_JOIN_GROUP:
96781 case MCAST_LEAVE_GROUP:
96782 {
96783- struct compat_group_req __user *gr32 = (void *)optval;
96784+ struct compat_group_req __user *gr32 = (void __user *)optval;
96785 struct group_req __user *kgr =
96786 compat_alloc_user_space(sizeof(struct group_req));
96787 u32 interface;
96788@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96789 case MCAST_BLOCK_SOURCE:
96790 case MCAST_UNBLOCK_SOURCE:
96791 {
96792- struct compat_group_source_req __user *gsr32 = (void *)optval;
96793+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96794 struct group_source_req __user *kgsr = compat_alloc_user_space(
96795 sizeof(struct group_source_req));
96796 u32 interface;
96797@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96798 }
96799 case MCAST_MSFILTER:
96800 {
96801- struct compat_group_filter __user *gf32 = (void *)optval;
96802+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96803 struct group_filter __user *kgf;
96804 u32 interface, fmode, numsrc;
96805
96806@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96807 char __user *optval, int __user *optlen,
96808 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96809 {
96810- struct compat_group_filter __user *gf32 = (void *)optval;
96811+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96812 struct group_filter __user *kgf;
96813 int __user *koptlen;
96814 u32 interface, fmode, numsrc;
96815@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96816
96817 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96818 return -EINVAL;
96819- if (copy_from_user(a, args, nas[call]))
96820+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96821 return -EFAULT;
96822 a0 = a[0];
96823 a1 = a[1];
96824diff --git a/net/core/datagram.c b/net/core/datagram.c
96825index a16ed7b..eb44d17 100644
96826--- a/net/core/datagram.c
96827+++ b/net/core/datagram.c
96828@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96829 }
96830
96831 kfree_skb(skb);
96832- atomic_inc(&sk->sk_drops);
96833+ atomic_inc_unchecked(&sk->sk_drops);
96834 sk_mem_reclaim_partial(sk);
96835
96836 return err;
96837diff --git a/net/core/dev.c b/net/core/dev.c
96838index 616eccf..31832d38 100644
96839--- a/net/core/dev.c
96840+++ b/net/core/dev.c
96841@@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96842 {
96843 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96844 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96845- atomic_long_inc(&dev->rx_dropped);
96846+ atomic_long_inc_unchecked(&dev->rx_dropped);
96847 kfree_skb(skb);
96848 return NET_RX_DROP;
96849 }
96850 }
96851
96852 if (unlikely(!is_skb_forwardable(dev, skb))) {
96853- atomic_long_inc(&dev->rx_dropped);
96854+ atomic_long_inc_unchecked(&dev->rx_dropped);
96855 kfree_skb(skb);
96856 return NET_RX_DROP;
96857 }
96858@@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96859
96860 struct dev_gso_cb {
96861 void (*destructor)(struct sk_buff *skb);
96862-};
96863+} __no_const;
96864
96865 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96866
96867@@ -3224,7 +3224,7 @@ enqueue:
96868
96869 local_irq_restore(flags);
96870
96871- atomic_long_inc(&skb->dev->rx_dropped);
96872+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96873 kfree_skb(skb);
96874 return NET_RX_DROP;
96875 }
96876@@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
96877 }
96878 EXPORT_SYMBOL(netif_rx_ni);
96879
96880-static void net_tx_action(struct softirq_action *h)
96881+static __latent_entropy void net_tx_action(void)
96882 {
96883 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96884
96885@@ -3630,7 +3630,7 @@ ncls:
96886 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96887 } else {
96888 drop:
96889- atomic_long_inc(&skb->dev->rx_dropped);
96890+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96891 kfree_skb(skb);
96892 /* Jamal, now you will not able to escape explaining
96893 * me how you were going to use this. :-)
96894@@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
96895 }
96896 EXPORT_SYMBOL(netif_napi_del);
96897
96898-static void net_rx_action(struct softirq_action *h)
96899+static __latent_entropy void net_rx_action(void)
96900 {
96901 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96902 unsigned long time_limit = jiffies + 2;
96903@@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96904 } else {
96905 netdev_stats_to_stats64(storage, &dev->stats);
96906 }
96907- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96908+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96909 return storage;
96910 }
96911 EXPORT_SYMBOL(dev_get_stats);
96912diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96913index 5b7d0e1..cb960fc 100644
96914--- a/net/core/dev_ioctl.c
96915+++ b/net/core/dev_ioctl.c
96916@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
96917 if (no_module && capable(CAP_NET_ADMIN))
96918 no_module = request_module("netdev-%s", name);
96919 if (no_module && capable(CAP_SYS_MODULE)) {
96920+#ifdef CONFIG_GRKERNSEC_MODHARDEN
96921+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
96922+#else
96923 if (!request_module("%s", name))
96924 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96925 name);
96926+#endif
96927 }
96928 }
96929 EXPORT_SYMBOL(dev_load);
96930diff --git a/net/core/filter.c b/net/core/filter.c
96931index ad30d62..821081f 100644
96932--- a/net/core/filter.c
96933+++ b/net/core/filter.c
96934@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
96935 void *ptr;
96936 u32 A = 0; /* Accumulator */
96937 u32 X = 0; /* Index Register */
96938- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
96939+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
96940 u32 tmp;
96941 int k;
96942
96943@@ -292,10 +292,10 @@ load_b:
96944 X = K;
96945 continue;
96946 case BPF_S_LD_MEM:
96947- A = mem[K];
96948+ A = mem[K&15];
96949 continue;
96950 case BPF_S_LDX_MEM:
96951- X = mem[K];
96952+ X = mem[K&15];
96953 continue;
96954 case BPF_S_MISC_TAX:
96955 X = A;
96956@@ -308,10 +308,10 @@ load_b:
96957 case BPF_S_RET_A:
96958 return A;
96959 case BPF_S_ST:
96960- mem[K] = A;
96961+ mem[K&15] = A;
96962 continue;
96963 case BPF_S_STX:
96964- mem[K] = X;
96965+ mem[K&15] = X;
96966 continue;
96967 case BPF_S_ANC_PROTOCOL:
96968 A = ntohs(skb->protocol);
96969@@ -391,9 +391,10 @@ load_b:
96970 continue;
96971 #endif
96972 default:
96973- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
96974+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
96975 fentry->code, fentry->jt,
96976 fentry->jf, fentry->k);
96977+ BUG();
96978 return 0;
96979 }
96980 }
96981@@ -416,7 +417,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
96982 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
96983 int pc, ret = 0;
96984
96985- BUILD_BUG_ON(BPF_MEMWORDS > 16);
96986+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
96987 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
96988 if (!masks)
96989 return -ENOMEM;
96990@@ -679,7 +680,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
96991 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
96992 if (!fp)
96993 return -ENOMEM;
96994- memcpy(fp->insns, fprog->filter, fsize);
96995+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
96996
96997 atomic_set(&fp->refcnt, 1);
96998 fp->len = fprog->len;
96999diff --git a/net/core/flow.c b/net/core/flow.c
97000index dfa602c..3103d88 100644
97001--- a/net/core/flow.c
97002+++ b/net/core/flow.c
97003@@ -61,7 +61,7 @@ struct flow_cache {
97004 struct timer_list rnd_timer;
97005 };
97006
97007-atomic_t flow_cache_genid = ATOMIC_INIT(0);
97008+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97009 EXPORT_SYMBOL(flow_cache_genid);
97010 static struct flow_cache flow_cache_global;
97011 static struct kmem_cache *flow_cachep __read_mostly;
97012@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97013
97014 static int flow_entry_valid(struct flow_cache_entry *fle)
97015 {
97016- if (atomic_read(&flow_cache_genid) != fle->genid)
97017+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97018 return 0;
97019 if (fle->object && !fle->object->ops->check(fle->object))
97020 return 0;
97021@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97022 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97023 fcp->hash_count++;
97024 }
97025- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97026+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97027 flo = fle->object;
97028 if (!flo)
97029 goto ret_object;
97030@@ -279,7 +279,7 @@ nocache:
97031 }
97032 flo = resolver(net, key, family, dir, flo, ctx);
97033 if (fle) {
97034- fle->genid = atomic_read(&flow_cache_genid);
97035+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97036 if (!IS_ERR(flo))
97037 fle->object = flo;
97038 else
97039diff --git a/net/core/iovec.c b/net/core/iovec.c
97040index b618694..192bbba 100644
97041--- a/net/core/iovec.c
97042+++ b/net/core/iovec.c
97043@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97044 if (m->msg_namelen) {
97045 if (mode == VERIFY_READ) {
97046 void __user *namep;
97047- namep = (void __user __force *) m->msg_name;
97048+ namep = (void __force_user *) m->msg_name;
97049 err = move_addr_to_kernel(namep, m->msg_namelen,
97050 address);
97051 if (err < 0)
97052@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97053 }
97054
97055 size = m->msg_iovlen * sizeof(struct iovec);
97056- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97057+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97058 return -EFAULT;
97059
97060 m->msg_iov = iov;
97061diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97062index 43128dd..e4d4311 100644
97063--- a/net/core/neighbour.c
97064+++ b/net/core/neighbour.c
97065@@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97066 void __user *buffer, size_t *lenp, loff_t *ppos)
97067 {
97068 int size, ret;
97069- struct ctl_table tmp = *ctl;
97070+ ctl_table_no_const tmp = *ctl;
97071
97072 tmp.extra1 = &zero;
97073 tmp.extra2 = &unres_qlen_max;
97074@@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97075 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97076 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97077 } else {
97078+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97079 dev_name_source = "default";
97080- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97081- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97082- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97083- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97084+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97085+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97086+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97087+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97088 }
97089
97090
97091diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97092index 2bf8329..7960607 100644
97093--- a/net/core/net-procfs.c
97094+++ b/net/core/net-procfs.c
97095@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97096 else
97097 seq_printf(seq, "%04x", ntohs(pt->type));
97098
97099+#ifdef CONFIG_GRKERNSEC_HIDESYM
97100+ seq_printf(seq, " %-8s %pf\n",
97101+ pt->dev ? pt->dev->name : "", NULL);
97102+#else
97103 seq_printf(seq, " %-8s %pf\n",
97104 pt->dev ? pt->dev->name : "", pt->func);
97105+#endif
97106 }
97107
97108 return 0;
97109diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
97110index f3edf96..3cd8b40 100644
97111--- a/net/core/net-sysfs.c
97112+++ b/net/core/net-sysfs.c
97113@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
97114 }
97115 EXPORT_SYMBOL(netdev_class_remove_file_ns);
97116
97117-int netdev_kobject_init(void)
97118+int __init netdev_kobject_init(void)
97119 {
97120 kobj_ns_type_register(&net_ns_type_operations);
97121 return class_register(&net_class);
97122diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97123index 81d3a9a..a0bd7a8 100644
97124--- a/net/core/net_namespace.c
97125+++ b/net/core/net_namespace.c
97126@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97127 int error;
97128 LIST_HEAD(net_exit_list);
97129
97130- list_add_tail(&ops->list, list);
97131+ pax_list_add_tail((struct list_head *)&ops->list, list);
97132 if (ops->init || (ops->id && ops->size)) {
97133 for_each_net(net) {
97134 error = ops_init(ops, net);
97135@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97136
97137 out_undo:
97138 /* If I have an error cleanup all namespaces I initialized */
97139- list_del(&ops->list);
97140+ pax_list_del((struct list_head *)&ops->list);
97141 ops_exit_list(ops, &net_exit_list);
97142 ops_free_list(ops, &net_exit_list);
97143 return error;
97144@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97145 struct net *net;
97146 LIST_HEAD(net_exit_list);
97147
97148- list_del(&ops->list);
97149+ pax_list_del((struct list_head *)&ops->list);
97150 for_each_net(net)
97151 list_add_tail(&net->exit_list, &net_exit_list);
97152 ops_exit_list(ops, &net_exit_list);
97153@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97154 mutex_lock(&net_mutex);
97155 error = register_pernet_operations(&pernet_list, ops);
97156 if (!error && (first_device == &pernet_list))
97157- first_device = &ops->list;
97158+ first_device = (struct list_head *)&ops->list;
97159 mutex_unlock(&net_mutex);
97160 return error;
97161 }
97162diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97163index 81975f2..9ef3531 100644
97164--- a/net/core/netpoll.c
97165+++ b/net/core/netpoll.c
97166@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97167 struct udphdr *udph;
97168 struct iphdr *iph;
97169 struct ethhdr *eth;
97170- static atomic_t ip_ident;
97171+ static atomic_unchecked_t ip_ident;
97172 struct ipv6hdr *ip6h;
97173
97174 udp_len = len + sizeof(*udph);
97175@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97176 put_unaligned(0x45, (unsigned char *)iph);
97177 iph->tos = 0;
97178 put_unaligned(htons(ip_len), &(iph->tot_len));
97179- iph->id = htons(atomic_inc_return(&ip_ident));
97180+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97181 iph->frag_off = 0;
97182 iph->ttl = 64;
97183 iph->protocol = IPPROTO_UDP;
97184diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97185index cf67144..12bf94c 100644
97186--- a/net/core/rtnetlink.c
97187+++ b/net/core/rtnetlink.c
97188@@ -58,7 +58,7 @@ struct rtnl_link {
97189 rtnl_doit_func doit;
97190 rtnl_dumpit_func dumpit;
97191 rtnl_calcit_func calcit;
97192-};
97193+} __no_const;
97194
97195 static DEFINE_MUTEX(rtnl_mutex);
97196
97197@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97198 if (rtnl_link_ops_get(ops->kind))
97199 return -EEXIST;
97200
97201- if (!ops->dellink)
97202- ops->dellink = unregister_netdevice_queue;
97203+ if (!ops->dellink) {
97204+ pax_open_kernel();
97205+ *(void **)&ops->dellink = unregister_netdevice_queue;
97206+ pax_close_kernel();
97207+ }
97208
97209- list_add_tail(&ops->list, &link_ops);
97210+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97211 return 0;
97212 }
97213 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97214@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97215 for_each_net(net) {
97216 __rtnl_kill_links(net, ops);
97217 }
97218- list_del(&ops->list);
97219+ pax_list_del((struct list_head *)&ops->list);
97220 }
97221 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97222
97223diff --git a/net/core/scm.c b/net/core/scm.c
97224index b442e7e..6f5b5a2 100644
97225--- a/net/core/scm.c
97226+++ b/net/core/scm.c
97227@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97228 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97229 {
97230 struct cmsghdr __user *cm
97231- = (__force struct cmsghdr __user *)msg->msg_control;
97232+ = (struct cmsghdr __force_user *)msg->msg_control;
97233 struct cmsghdr cmhdr;
97234 int cmlen = CMSG_LEN(len);
97235 int err;
97236@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97237 err = -EFAULT;
97238 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97239 goto out;
97240- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97241+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97242 goto out;
97243 cmlen = CMSG_SPACE(len);
97244 if (msg->msg_controllen < cmlen)
97245@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97246 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97247 {
97248 struct cmsghdr __user *cm
97249- = (__force struct cmsghdr __user*)msg->msg_control;
97250+ = (struct cmsghdr __force_user *)msg->msg_control;
97251
97252 int fdmax = 0;
97253 int fdnum = scm->fp->count;
97254@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97255 if (fdnum < fdmax)
97256 fdmax = fdnum;
97257
97258- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97259+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97260 i++, cmfptr++)
97261 {
97262 struct socket *sock;
97263diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97264index deffb37..213db0a 100644
97265--- a/net/core/skbuff.c
97266+++ b/net/core/skbuff.c
97267@@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97268 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97269 int len, __wsum csum)
97270 {
97271- const struct skb_checksum_ops ops = {
97272+ static const struct skb_checksum_ops ops = {
97273 .update = csum_partial_ext,
97274 .combine = csum_block_add_ext,
97275 };
97276@@ -3119,13 +3119,15 @@ void __init skb_init(void)
97277 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97278 sizeof(struct sk_buff),
97279 0,
97280- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97281+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97282+ SLAB_NO_SANITIZE,
97283 NULL);
97284 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97285 (2*sizeof(struct sk_buff)) +
97286 sizeof(atomic_t),
97287 0,
97288- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97289+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97290+ SLAB_NO_SANITIZE,
97291 NULL);
97292 }
97293
97294diff --git a/net/core/sock.c b/net/core/sock.c
97295index fbc5cfb..6d7e8c3 100644
97296--- a/net/core/sock.c
97297+++ b/net/core/sock.c
97298@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97299 struct sk_buff_head *list = &sk->sk_receive_queue;
97300
97301 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97302- atomic_inc(&sk->sk_drops);
97303+ atomic_inc_unchecked(&sk->sk_drops);
97304 trace_sock_rcvqueue_full(sk, skb);
97305 return -ENOMEM;
97306 }
97307@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97308 return err;
97309
97310 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97311- atomic_inc(&sk->sk_drops);
97312+ atomic_inc_unchecked(&sk->sk_drops);
97313 return -ENOBUFS;
97314 }
97315
97316@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97317 skb_dst_force(skb);
97318
97319 spin_lock_irqsave(&list->lock, flags);
97320- skb->dropcount = atomic_read(&sk->sk_drops);
97321+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97322 __skb_queue_tail(list, skb);
97323 spin_unlock_irqrestore(&list->lock, flags);
97324
97325@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97326 skb->dev = NULL;
97327
97328 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97329- atomic_inc(&sk->sk_drops);
97330+ atomic_inc_unchecked(&sk->sk_drops);
97331 goto discard_and_relse;
97332 }
97333 if (nested)
97334@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97335 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97336 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97337 bh_unlock_sock(sk);
97338- atomic_inc(&sk->sk_drops);
97339+ atomic_inc_unchecked(&sk->sk_drops);
97340 goto discard_and_relse;
97341 }
97342
97343@@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97344 struct timeval tm;
97345 } v;
97346
97347- int lv = sizeof(int);
97348- int len;
97349+ unsigned int lv = sizeof(int);
97350+ unsigned int len;
97351
97352 if (get_user(len, optlen))
97353 return -EFAULT;
97354- if (len < 0)
97355+ if (len > INT_MAX)
97356 return -EINVAL;
97357
97358 memset(&v, 0, sizeof(v));
97359@@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97360
97361 case SO_PEERNAME:
97362 {
97363- char address[128];
97364+ char address[_K_SS_MAXSIZE];
97365
97366 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97367 return -ENOTCONN;
97368- if (lv < len)
97369+ if (lv < len || sizeof address < len)
97370 return -EINVAL;
97371 if (copy_to_user(optval, address, len))
97372 return -EFAULT;
97373@@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97374
97375 if (len > lv)
97376 len = lv;
97377- if (copy_to_user(optval, &v, len))
97378+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
97379 return -EFAULT;
97380 lenout:
97381 if (put_user(len, optlen))
97382@@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97383 */
97384 smp_wmb();
97385 atomic_set(&sk->sk_refcnt, 1);
97386- atomic_set(&sk->sk_drops, 0);
97387+ atomic_set_unchecked(&sk->sk_drops, 0);
97388 }
97389 EXPORT_SYMBOL(sock_init_data);
97390
97391@@ -2478,6 +2478,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97392 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97393 int level, int type)
97394 {
97395+ struct sock_extended_err ee;
97396 struct sock_exterr_skb *serr;
97397 struct sk_buff *skb, *skb2;
97398 int copied, err;
97399@@ -2499,7 +2500,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97400 sock_recv_timestamp(msg, sk, skb);
97401
97402 serr = SKB_EXT_ERR(skb);
97403- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97404+ ee = serr->ee;
97405+ put_cmsg(msg, level, type, sizeof ee, &ee);
97406
97407 msg->msg_flags |= MSG_ERRQUEUE;
97408 err = copied;
97409diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97410index a0e9cf6..ef7f9ed 100644
97411--- a/net/core/sock_diag.c
97412+++ b/net/core/sock_diag.c
97413@@ -9,26 +9,33 @@
97414 #include <linux/inet_diag.h>
97415 #include <linux/sock_diag.h>
97416
97417-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97418+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97419 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97420 static DEFINE_MUTEX(sock_diag_table_mutex);
97421
97422 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97423 {
97424+#ifndef CONFIG_GRKERNSEC_HIDESYM
97425 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97426 cookie[1] != INET_DIAG_NOCOOKIE) &&
97427 ((u32)(unsigned long)sk != cookie[0] ||
97428 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97429 return -ESTALE;
97430 else
97431+#endif
97432 return 0;
97433 }
97434 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97435
97436 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97437 {
97438+#ifdef CONFIG_GRKERNSEC_HIDESYM
97439+ cookie[0] = 0;
97440+ cookie[1] = 0;
97441+#else
97442 cookie[0] = (u32)(unsigned long)sk;
97443 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97444+#endif
97445 }
97446 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97447
97448@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97449 mutex_lock(&sock_diag_table_mutex);
97450 if (sock_diag_handlers[hndl->family])
97451 err = -EBUSY;
97452- else
97453+ else {
97454+ pax_open_kernel();
97455 sock_diag_handlers[hndl->family] = hndl;
97456+ pax_close_kernel();
97457+ }
97458 mutex_unlock(&sock_diag_table_mutex);
97459
97460 return err;
97461@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97462
97463 mutex_lock(&sock_diag_table_mutex);
97464 BUG_ON(sock_diag_handlers[family] != hnld);
97465+ pax_open_kernel();
97466 sock_diag_handlers[family] = NULL;
97467+ pax_close_kernel();
97468 mutex_unlock(&sock_diag_table_mutex);
97469 }
97470 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97471diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97472index cca4441..5e616de 100644
97473--- a/net/core/sysctl_net_core.c
97474+++ b/net/core/sysctl_net_core.c
97475@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97476 {
97477 unsigned int orig_size, size;
97478 int ret, i;
97479- struct ctl_table tmp = {
97480+ ctl_table_no_const tmp = {
97481 .data = &size,
97482 .maxlen = sizeof(size),
97483 .mode = table->mode
97484@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97485 void __user *buffer, size_t *lenp, loff_t *ppos)
97486 {
97487 char id[IFNAMSIZ];
97488- struct ctl_table tbl = {
97489+ ctl_table_no_const tbl = {
97490 .data = id,
97491 .maxlen = IFNAMSIZ,
97492 };
97493@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97494
97495 static __net_init int sysctl_core_net_init(struct net *net)
97496 {
97497- struct ctl_table *tbl;
97498+ ctl_table_no_const *tbl = NULL;
97499
97500 net->core.sysctl_somaxconn = SOMAXCONN;
97501
97502- tbl = netns_core_table;
97503 if (!net_eq(net, &init_net)) {
97504- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97505+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97506 if (tbl == NULL)
97507 goto err_dup;
97508
97509@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97510 if (net->user_ns != &init_user_ns) {
97511 tbl[0].procname = NULL;
97512 }
97513- }
97514-
97515- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97516+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97517+ } else
97518+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97519 if (net->core.sysctl_hdr == NULL)
97520 goto err_reg;
97521
97522 return 0;
97523
97524 err_reg:
97525- if (tbl != netns_core_table)
97526- kfree(tbl);
97527+ kfree(tbl);
97528 err_dup:
97529 return -ENOMEM;
97530 }
97531@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97532 kfree(tbl);
97533 }
97534
97535-static __net_initdata struct pernet_operations sysctl_core_ops = {
97536+static __net_initconst struct pernet_operations sysctl_core_ops = {
97537 .init = sysctl_core_net_init,
97538 .exit = sysctl_core_net_exit,
97539 };
97540diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97541index dd4d506..fb2fb87 100644
97542--- a/net/decnet/af_decnet.c
97543+++ b/net/decnet/af_decnet.c
97544@@ -465,6 +465,7 @@ static struct proto dn_proto = {
97545 .sysctl_rmem = sysctl_decnet_rmem,
97546 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97547 .obj_size = sizeof(struct dn_sock),
97548+ .slab_flags = SLAB_USERCOPY,
97549 };
97550
97551 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97552diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97553index dd0dfb2..fdbc764 100644
97554--- a/net/decnet/dn_dev.c
97555+++ b/net/decnet/dn_dev.c
97556@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97557 .extra1 = &min_t3,
97558 .extra2 = &max_t3
97559 },
97560- {0}
97561+ { }
97562 },
97563 };
97564
97565diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97566index 5325b54..a0d4d69 100644
97567--- a/net/decnet/sysctl_net_decnet.c
97568+++ b/net/decnet/sysctl_net_decnet.c
97569@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97570
97571 if (len > *lenp) len = *lenp;
97572
97573- if (copy_to_user(buffer, addr, len))
97574+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
97575 return -EFAULT;
97576
97577 *lenp = len;
97578@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97579
97580 if (len > *lenp) len = *lenp;
97581
97582- if (copy_to_user(buffer, devname, len))
97583+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
97584 return -EFAULT;
97585
97586 *lenp = len;
97587diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97588index 1865fdf..581a595 100644
97589--- a/net/ieee802154/dgram.c
97590+++ b/net/ieee802154/dgram.c
97591@@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97592 if (saddr) {
97593 saddr->family = AF_IEEE802154;
97594 saddr->addr = mac_cb(skb)->sa;
97595+ }
97596+ if (addr_len)
97597 *addr_len = sizeof(*saddr);
97598- }
97599
97600 if (flags & MSG_TRUNC)
97601 copied = skb->len;
97602diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97603index e4d96d4..e1651da 100644
97604--- a/net/ipv4/af_inet.c
97605+++ b/net/ipv4/af_inet.c
97606@@ -1686,13 +1686,9 @@ static int __init inet_init(void)
97607
97608 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97609
97610- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97611- if (!sysctl_local_reserved_ports)
97612- goto out;
97613-
97614 rc = proto_register(&tcp_prot, 1);
97615 if (rc)
97616- goto out_free_reserved_ports;
97617+ goto out;
97618
97619 rc = proto_register(&udp_prot, 1);
97620 if (rc)
97621@@ -1799,8 +1795,6 @@ out_unregister_udp_proto:
97622 proto_unregister(&udp_prot);
97623 out_unregister_tcp_proto:
97624 proto_unregister(&tcp_prot);
97625-out_free_reserved_ports:
97626- kfree(sysctl_local_reserved_ports);
97627 goto out;
97628 }
97629
97630diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97631index f4b34d8..c54a163 100644
97632--- a/net/ipv4/devinet.c
97633+++ b/net/ipv4/devinet.c
97634@@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97635 idx = 0;
97636 head = &net->dev_index_head[h];
97637 rcu_read_lock();
97638- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97639+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97640 net->dev_base_seq;
97641 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97642 if (idx < s_idx)
97643@@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
97644 idx = 0;
97645 head = &net->dev_index_head[h];
97646 rcu_read_lock();
97647- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97648+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97649 net->dev_base_seq;
97650 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97651 if (idx < s_idx)
97652@@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97653 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97654 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97655
97656-static struct devinet_sysctl_table {
97657+static const struct devinet_sysctl_table {
97658 struct ctl_table_header *sysctl_header;
97659 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97660 } devinet_sysctl = {
97661@@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97662 int err;
97663 struct ipv4_devconf *all, *dflt;
97664 #ifdef CONFIG_SYSCTL
97665- struct ctl_table *tbl = ctl_forward_entry;
97666+ ctl_table_no_const *tbl = NULL;
97667 struct ctl_table_header *forw_hdr;
97668 #endif
97669
97670@@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97671 goto err_alloc_dflt;
97672
97673 #ifdef CONFIG_SYSCTL
97674- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97675+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97676 if (tbl == NULL)
97677 goto err_alloc_ctl;
97678
97679@@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97680 goto err_reg_dflt;
97681
97682 err = -ENOMEM;
97683- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97684+ if (!net_eq(net, &init_net))
97685+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97686+ else
97687+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97688 if (forw_hdr == NULL)
97689 goto err_reg_ctl;
97690 net->ipv4.forw_hdr = forw_hdr;
97691@@ -2246,8 +2249,7 @@ err_reg_ctl:
97692 err_reg_dflt:
97693 __devinet_sysctl_unregister(all);
97694 err_reg_all:
97695- if (tbl != ctl_forward_entry)
97696- kfree(tbl);
97697+ kfree(tbl);
97698 err_alloc_ctl:
97699 #endif
97700 if (dflt != &ipv4_devconf_dflt)
97701diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97702index c7539e2..b455e51 100644
97703--- a/net/ipv4/fib_frontend.c
97704+++ b/net/ipv4/fib_frontend.c
97705@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97706 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97707 fib_sync_up(dev);
97708 #endif
97709- atomic_inc(&net->ipv4.dev_addr_genid);
97710+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97711 rt_cache_flush(dev_net(dev));
97712 break;
97713 case NETDEV_DOWN:
97714 fib_del_ifaddr(ifa, NULL);
97715- atomic_inc(&net->ipv4.dev_addr_genid);
97716+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97717 if (ifa->ifa_dev->ifa_list == NULL) {
97718 /* Last address was deleted from this interface.
97719 * Disable IP.
97720@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97721 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97722 fib_sync_up(dev);
97723 #endif
97724- atomic_inc(&net->ipv4.dev_addr_genid);
97725+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97726 rt_cache_flush(net);
97727 break;
97728 case NETDEV_DOWN:
97729diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97730index e63f47a..e5c531d 100644
97731--- a/net/ipv4/fib_semantics.c
97732+++ b/net/ipv4/fib_semantics.c
97733@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97734 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97735 nh->nh_gw,
97736 nh->nh_parent->fib_scope);
97737- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97738+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97739
97740 return nh->nh_saddr;
97741 }
97742diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97743index fc0e649..febfa65 100644
97744--- a/net/ipv4/inet_connection_sock.c
97745+++ b/net/ipv4/inet_connection_sock.c
97746@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97747 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97748 #endif
97749
97750-unsigned long *sysctl_local_reserved_ports;
97751+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97752 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97753
97754 void inet_get_local_port_range(struct net *net, int *low, int *high)
97755diff --git a/net/ipv4/inet_fragment.c b/net/ipv4/inet_fragment.c
97756index bb075fc..322dceb 100644
97757--- a/net/ipv4/inet_fragment.c
97758+++ b/net/ipv4/inet_fragment.c
97759@@ -278,9 +278,10 @@ static struct inet_frag_queue *inet_frag_intern(struct netns_frags *nf,
97760
97761 atomic_inc(&qp->refcnt);
97762 hlist_add_head(&qp->list, &hb->chain);
97763- spin_unlock(&hb->chain_lock);
97764- read_unlock(&f->lock);
97765 inet_frag_lru_add(nf, qp);
97766+ spin_unlock(&hb->chain_lock);
97767+ read_unlock(&f->lock);
97768+
97769 return qp;
97770 }
97771
97772diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97773index 8b9cf27..0d8d592 100644
97774--- a/net/ipv4/inet_hashtables.c
97775+++ b/net/ipv4/inet_hashtables.c
97776@@ -18,6 +18,7 @@
97777 #include <linux/sched.h>
97778 #include <linux/slab.h>
97779 #include <linux/wait.h>
97780+#include <linux/security.h>
97781
97782 #include <net/inet_connection_sock.h>
97783 #include <net/inet_hashtables.h>
97784@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97785 return inet_ehashfn(net, laddr, lport, faddr, fport);
97786 }
97787
97788+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97789+
97790 /*
97791 * Allocate and initialize a new local port bind bucket.
97792 * The bindhash mutex for snum's hash chain must be held here.
97793@@ -554,6 +557,8 @@ ok:
97794 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97795 spin_unlock(&head->lock);
97796
97797+ gr_update_task_in_ip_table(current, inet_sk(sk));
97798+
97799 if (tw) {
97800 inet_twsk_deschedule(tw, death_row);
97801 while (twrefcnt) {
97802diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97803index 33d5537..da337a4 100644
97804--- a/net/ipv4/inetpeer.c
97805+++ b/net/ipv4/inetpeer.c
97806@@ -503,8 +503,8 @@ relookup:
97807 if (p) {
97808 p->daddr = *daddr;
97809 atomic_set(&p->refcnt, 1);
97810- atomic_set(&p->rid, 0);
97811- atomic_set(&p->ip_id_count,
97812+ atomic_set_unchecked(&p->rid, 0);
97813+ atomic_set_unchecked(&p->ip_id_count,
97814 (daddr->family == AF_INET) ?
97815 secure_ip_id(daddr->addr.a4) :
97816 secure_ipv6_id(daddr->addr.a6));
97817diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97818index 2481993..2d9a7a7 100644
97819--- a/net/ipv4/ip_fragment.c
97820+++ b/net/ipv4/ip_fragment.c
97821@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97822 return 0;
97823
97824 start = qp->rid;
97825- end = atomic_inc_return(&peer->rid);
97826+ end = atomic_inc_return_unchecked(&peer->rid);
97827 qp->rid = end;
97828
97829 rc = qp->q.fragments && (end - start) > max;
97830@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97831
97832 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97833 {
97834- struct ctl_table *table;
97835+ ctl_table_no_const *table = NULL;
97836 struct ctl_table_header *hdr;
97837
97838- table = ip4_frags_ns_ctl_table;
97839 if (!net_eq(net, &init_net)) {
97840- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97841+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97842 if (table == NULL)
97843 goto err_alloc;
97844
97845@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97846 /* Don't export sysctls to unprivileged users */
97847 if (net->user_ns != &init_user_ns)
97848 table[0].procname = NULL;
97849- }
97850+ hdr = register_net_sysctl(net, "net/ipv4", table);
97851+ } else
97852+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97853
97854- hdr = register_net_sysctl(net, "net/ipv4", table);
97855 if (hdr == NULL)
97856 goto err_reg;
97857
97858@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97859 return 0;
97860
97861 err_reg:
97862- if (!net_eq(net, &init_net))
97863- kfree(table);
97864+ kfree(table);
97865 err_alloc:
97866 return -ENOMEM;
97867 }
97868diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97869index d306360..1c1a1f1 100644
97870--- a/net/ipv4/ip_gre.c
97871+++ b/net/ipv4/ip_gre.c
97872@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97873 module_param(log_ecn_error, bool, 0644);
97874 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97875
97876-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97877+static struct rtnl_link_ops ipgre_link_ops;
97878 static int ipgre_tunnel_init(struct net_device *dev);
97879
97880 static int ipgre_net_id __read_mostly;
97881@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97882 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97883 };
97884
97885-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97886+static struct rtnl_link_ops ipgre_link_ops = {
97887 .kind = "gre",
97888 .maxtype = IFLA_GRE_MAX,
97889 .policy = ipgre_policy,
97890@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97891 .fill_info = ipgre_fill_info,
97892 };
97893
97894-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97895+static struct rtnl_link_ops ipgre_tap_ops = {
97896 .kind = "gretap",
97897 .maxtype = IFLA_GRE_MAX,
97898 .policy = ipgre_policy,
97899diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97900index ddf32a6..3fdeea9 100644
97901--- a/net/ipv4/ip_sockglue.c
97902+++ b/net/ipv4/ip_sockglue.c
97903@@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97904 len = min_t(unsigned int, len, opt->optlen);
97905 if (put_user(len, optlen))
97906 return -EFAULT;
97907- if (copy_to_user(optval, opt->__data, len))
97908+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97909+ copy_to_user(optval, opt->__data, len))
97910 return -EFAULT;
97911 return 0;
97912 }
97913@@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97914 if (sk->sk_type != SOCK_STREAM)
97915 return -ENOPROTOOPT;
97916
97917- msg.msg_control = optval;
97918+ msg.msg_control = (void __force_kernel *)optval;
97919 msg.msg_controllen = len;
97920 msg.msg_flags = flags;
97921
97922diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97923index 52b802a..b725179 100644
97924--- a/net/ipv4/ip_vti.c
97925+++ b/net/ipv4/ip_vti.c
97926@@ -44,7 +44,7 @@
97927 #include <net/net_namespace.h>
97928 #include <net/netns/generic.h>
97929
97930-static struct rtnl_link_ops vti_link_ops __read_mostly;
97931+static struct rtnl_link_ops vti_link_ops;
97932
97933 static int vti_net_id __read_mostly;
97934 static int vti_tunnel_init(struct net_device *dev);
97935@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97936 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97937 };
97938
97939-static struct rtnl_link_ops vti_link_ops __read_mostly = {
97940+static struct rtnl_link_ops vti_link_ops = {
97941 .kind = "vti",
97942 .maxtype = IFLA_VTI_MAX,
97943 .policy = vti_policy,
97944diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97945index efa1138..20dbba0 100644
97946--- a/net/ipv4/ipconfig.c
97947+++ b/net/ipv4/ipconfig.c
97948@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97949
97950 mm_segment_t oldfs = get_fs();
97951 set_fs(get_ds());
97952- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97953+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97954 set_fs(oldfs);
97955 return res;
97956 }
97957@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97958
97959 mm_segment_t oldfs = get_fs();
97960 set_fs(get_ds());
97961- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97962+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97963 set_fs(oldfs);
97964 return res;
97965 }
97966@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97967
97968 mm_segment_t oldfs = get_fs();
97969 set_fs(get_ds());
97970- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97971+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97972 set_fs(oldfs);
97973 return res;
97974 }
97975diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97976index fe3e9f7..4956990 100644
97977--- a/net/ipv4/ipip.c
97978+++ b/net/ipv4/ipip.c
97979@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97980 static int ipip_net_id __read_mostly;
97981
97982 static int ipip_tunnel_init(struct net_device *dev);
97983-static struct rtnl_link_ops ipip_link_ops __read_mostly;
97984+static struct rtnl_link_ops ipip_link_ops;
97985
97986 static int ipip_err(struct sk_buff *skb, u32 info)
97987 {
97988@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97989 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97990 };
97991
97992-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97993+static struct rtnl_link_ops ipip_link_ops = {
97994 .kind = "ipip",
97995 .maxtype = IFLA_IPTUN_MAX,
97996 .policy = ipip_policy,
97997diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97998index 59da7cd..e318de1 100644
97999--- a/net/ipv4/netfilter/arp_tables.c
98000+++ b/net/ipv4/netfilter/arp_tables.c
98001@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
98002 #endif
98003
98004 static int get_info(struct net *net, void __user *user,
98005- const int *len, int compat)
98006+ int len, int compat)
98007 {
98008 char name[XT_TABLE_MAXNAMELEN];
98009 struct xt_table *t;
98010 int ret;
98011
98012- if (*len != sizeof(struct arpt_getinfo)) {
98013- duprintf("length %u != %Zu\n", *len,
98014+ if (len != sizeof(struct arpt_getinfo)) {
98015+ duprintf("length %u != %Zu\n", len,
98016 sizeof(struct arpt_getinfo));
98017 return -EINVAL;
98018 }
98019@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
98020 info.size = private->size;
98021 strcpy(info.name, name);
98022
98023- if (copy_to_user(user, &info, *len) != 0)
98024+ if (copy_to_user(user, &info, len) != 0)
98025 ret = -EFAULT;
98026 else
98027 ret = 0;
98028@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98029
98030 switch (cmd) {
98031 case ARPT_SO_GET_INFO:
98032- ret = get_info(sock_net(sk), user, len, 1);
98033+ ret = get_info(sock_net(sk), user, *len, 1);
98034 break;
98035 case ARPT_SO_GET_ENTRIES:
98036 ret = compat_get_entries(sock_net(sk), user, len);
98037@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98038
98039 switch (cmd) {
98040 case ARPT_SO_GET_INFO:
98041- ret = get_info(sock_net(sk), user, len, 0);
98042+ ret = get_info(sock_net(sk), user, *len, 0);
98043 break;
98044
98045 case ARPT_SO_GET_ENTRIES:
98046diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98047index 718dfbd..cef4152 100644
98048--- a/net/ipv4/netfilter/ip_tables.c
98049+++ b/net/ipv4/netfilter/ip_tables.c
98050@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98051 #endif
98052
98053 static int get_info(struct net *net, void __user *user,
98054- const int *len, int compat)
98055+ int len, int compat)
98056 {
98057 char name[XT_TABLE_MAXNAMELEN];
98058 struct xt_table *t;
98059 int ret;
98060
98061- if (*len != sizeof(struct ipt_getinfo)) {
98062- duprintf("length %u != %zu\n", *len,
98063+ if (len != sizeof(struct ipt_getinfo)) {
98064+ duprintf("length %u != %zu\n", len,
98065 sizeof(struct ipt_getinfo));
98066 return -EINVAL;
98067 }
98068@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98069 info.size = private->size;
98070 strcpy(info.name, name);
98071
98072- if (copy_to_user(user, &info, *len) != 0)
98073+ if (copy_to_user(user, &info, len) != 0)
98074 ret = -EFAULT;
98075 else
98076 ret = 0;
98077@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98078
98079 switch (cmd) {
98080 case IPT_SO_GET_INFO:
98081- ret = get_info(sock_net(sk), user, len, 1);
98082+ ret = get_info(sock_net(sk), user, *len, 1);
98083 break;
98084 case IPT_SO_GET_ENTRIES:
98085 ret = compat_get_entries(sock_net(sk), user, len);
98086@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98087
98088 switch (cmd) {
98089 case IPT_SO_GET_INFO:
98090- ret = get_info(sock_net(sk), user, len, 0);
98091+ ret = get_info(sock_net(sk), user, *len, 0);
98092 break;
98093
98094 case IPT_SO_GET_ENTRIES:
98095diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98096index 242e7f4..a084e95 100644
98097--- a/net/ipv4/ping.c
98098+++ b/net/ipv4/ping.c
98099@@ -55,7 +55,7 @@
98100
98101
98102 struct ping_table ping_table;
98103-struct pingv6_ops pingv6_ops;
98104+struct pingv6_ops *pingv6_ops;
98105 EXPORT_SYMBOL_GPL(pingv6_ops);
98106
98107 static u16 ping_port_rover;
98108@@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98109 return -ENODEV;
98110 }
98111 }
98112- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98113+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98114 scoped);
98115 rcu_read_unlock();
98116
98117@@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98118 }
98119 #if IS_ENABLED(CONFIG_IPV6)
98120 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98121- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98122+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98123 #endif
98124 }
98125
98126@@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98127 info, (u8 *)icmph);
98128 #if IS_ENABLED(CONFIG_IPV6)
98129 } else if (family == AF_INET6) {
98130- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98131+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98132 info, (u8 *)icmph);
98133 #endif
98134 }
98135@@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98136 {
98137 struct inet_sock *isk = inet_sk(sk);
98138 int family = sk->sk_family;
98139+ struct sockaddr_in *sin;
98140+ struct sockaddr_in6 *sin6;
98141 struct sk_buff *skb;
98142 int copied, err;
98143
98144@@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98145 if (flags & MSG_OOB)
98146 goto out;
98147
98148+ if (addr_len) {
98149+ if (family == AF_INET)
98150+ *addr_len = sizeof(*sin);
98151+ else if (family == AF_INET6 && addr_len)
98152+ *addr_len = sizeof(*sin6);
98153+ }
98154+
98155 if (flags & MSG_ERRQUEUE) {
98156 if (family == AF_INET) {
98157 return ip_recv_error(sk, msg, len, addr_len);
98158 #if IS_ENABLED(CONFIG_IPV6)
98159 } else if (family == AF_INET6) {
98160- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98161+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98162 addr_len);
98163 #endif
98164 }
98165@@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98166 sin->sin_port = 0 /* skb->h.uh->source */;
98167 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98168 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98169- *addr_len = sizeof(*sin);
98170 }
98171
98172 if (isk->cmsg_flags)
98173@@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98174 sin6->sin6_scope_id =
98175 ipv6_iface_scope_id(&sin6->sin6_addr,
98176 IP6CB(skb)->iif);
98177- *addr_len = sizeof(*sin6);
98178 }
98179
98180 if (inet6_sk(sk)->rxopt.all)
98181- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
98182+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
98183 #endif
98184 } else {
98185 BUG();
98186@@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98187 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98188 0, sock_i_ino(sp),
98189 atomic_read(&sp->sk_refcnt), sp,
98190- atomic_read(&sp->sk_drops));
98191+ atomic_read_unchecked(&sp->sk_drops));
98192 }
98193
98194 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98195diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98196index 23c3e5b..cdb8b36 100644
98197--- a/net/ipv4/raw.c
98198+++ b/net/ipv4/raw.c
98199@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98200 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98201 {
98202 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98203- atomic_inc(&sk->sk_drops);
98204+ atomic_inc_unchecked(&sk->sk_drops);
98205 kfree_skb(skb);
98206 return NET_RX_DROP;
98207 }
98208@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98209 if (flags & MSG_OOB)
98210 goto out;
98211
98212+ if (addr_len)
98213+ *addr_len = sizeof(*sin);
98214+
98215 if (flags & MSG_ERRQUEUE) {
98216 err = ip_recv_error(sk, msg, len, addr_len);
98217 goto out;
98218@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98219 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98220 sin->sin_port = 0;
98221 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98222- *addr_len = sizeof(*sin);
98223 }
98224 if (inet->cmsg_flags)
98225 ip_cmsg_recv(msg, skb);
98226@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98227
98228 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98229 {
98230+ struct icmp_filter filter;
98231+
98232 if (optlen > sizeof(struct icmp_filter))
98233 optlen = sizeof(struct icmp_filter);
98234- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98235+ if (copy_from_user(&filter, optval, optlen))
98236 return -EFAULT;
98237+ raw_sk(sk)->filter = filter;
98238 return 0;
98239 }
98240
98241 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98242 {
98243 int len, ret = -EFAULT;
98244+ struct icmp_filter filter;
98245
98246 if (get_user(len, optlen))
98247 goto out;
98248@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98249 if (len > sizeof(struct icmp_filter))
98250 len = sizeof(struct icmp_filter);
98251 ret = -EFAULT;
98252- if (put_user(len, optlen) ||
98253- copy_to_user(optval, &raw_sk(sk)->filter, len))
98254+ filter = raw_sk(sk)->filter;
98255+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98256 goto out;
98257 ret = 0;
98258 out: return ret;
98259@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98260 0, 0L, 0,
98261 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98262 0, sock_i_ino(sp),
98263- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98264+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98265 }
98266
98267 static int raw_seq_show(struct seq_file *seq, void *v)
98268diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98269index e611651f..0c17263 100644
98270--- a/net/ipv4/route.c
98271+++ b/net/ipv4/route.c
98272@@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98273 .maxlen = sizeof(int),
98274 .mode = 0200,
98275 .proc_handler = ipv4_sysctl_rtcache_flush,
98276+ .extra1 = &init_net,
98277 },
98278 { },
98279 };
98280
98281 static __net_init int sysctl_route_net_init(struct net *net)
98282 {
98283- struct ctl_table *tbl;
98284+ ctl_table_no_const *tbl = NULL;
98285
98286- tbl = ipv4_route_flush_table;
98287 if (!net_eq(net, &init_net)) {
98288- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98289+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98290 if (tbl == NULL)
98291 goto err_dup;
98292
98293 /* Don't export sysctls to unprivileged users */
98294 if (net->user_ns != &init_user_ns)
98295 tbl[0].procname = NULL;
98296- }
98297- tbl[0].extra1 = net;
98298+ tbl[0].extra1 = net;
98299+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98300+ } else
98301+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98302
98303- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98304 if (net->ipv4.route_hdr == NULL)
98305 goto err_reg;
98306 return 0;
98307
98308 err_reg:
98309- if (tbl != ipv4_route_flush_table)
98310- kfree(tbl);
98311+ kfree(tbl);
98312 err_dup:
98313 return -ENOMEM;
98314 }
98315@@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98316
98317 static __net_init int rt_genid_init(struct net *net)
98318 {
98319- atomic_set(&net->ipv4.rt_genid, 0);
98320- atomic_set(&net->fnhe_genid, 0);
98321+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98322+ atomic_set_unchecked(&net->fnhe_genid, 0);
98323 get_random_bytes(&net->ipv4.dev_addr_genid,
98324 sizeof(net->ipv4.dev_addr_genid));
98325 return 0;
98326diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98327index 3d69ec8..57207b4 100644
98328--- a/net/ipv4/sysctl_net_ipv4.c
98329+++ b/net/ipv4/sysctl_net_ipv4.c
98330@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98331 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98332 int ret;
98333 int range[2];
98334- struct ctl_table tmp = {
98335+ ctl_table_no_const tmp = {
98336 .data = &range,
98337 .maxlen = sizeof(range),
98338 .mode = table->mode,
98339@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98340 int ret;
98341 gid_t urange[2];
98342 kgid_t low, high;
98343- struct ctl_table tmp = {
98344+ ctl_table_no_const tmp = {
98345 .data = &urange,
98346 .maxlen = sizeof(urange),
98347 .mode = table->mode,
98348@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98349 void __user *buffer, size_t *lenp, loff_t *ppos)
98350 {
98351 char val[TCP_CA_NAME_MAX];
98352- struct ctl_table tbl = {
98353+ ctl_table_no_const tbl = {
98354 .data = val,
98355 .maxlen = TCP_CA_NAME_MAX,
98356 };
98357@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98358 void __user *buffer, size_t *lenp,
98359 loff_t *ppos)
98360 {
98361- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98362+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98363 int ret;
98364
98365 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98366@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98367 void __user *buffer, size_t *lenp,
98368 loff_t *ppos)
98369 {
98370- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98371+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98372 int ret;
98373
98374 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98375@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98376 void __user *buffer, size_t *lenp,
98377 loff_t *ppos)
98378 {
98379- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98380+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98381 struct tcp_fastopen_context *ctxt;
98382 int ret;
98383 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98384@@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98385 },
98386 {
98387 .procname = "ip_local_reserved_ports",
98388- .data = NULL, /* initialized in sysctl_ipv4_init */
98389+ .data = sysctl_local_reserved_ports,
98390 .maxlen = 65536,
98391 .mode = 0644,
98392 .proc_handler = proc_do_large_bitmap,
98393@@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98394
98395 static __net_init int ipv4_sysctl_init_net(struct net *net)
98396 {
98397- struct ctl_table *table;
98398+ ctl_table_no_const *table = NULL;
98399
98400- table = ipv4_net_table;
98401 if (!net_eq(net, &init_net)) {
98402 int i;
98403
98404- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98405+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98406 if (table == NULL)
98407 goto err_alloc;
98408
98409@@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98410 net->ipv4.sysctl_local_ports.range[0] = 32768;
98411 net->ipv4.sysctl_local_ports.range[1] = 61000;
98412
98413- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98414+ if (!net_eq(net, &init_net))
98415+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98416+ else
98417+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98418 if (net->ipv4.ipv4_hdr == NULL)
98419 goto err_reg;
98420
98421 return 0;
98422
98423 err_reg:
98424- if (!net_eq(net, &init_net))
98425- kfree(table);
98426+ kfree(table);
98427 err_alloc:
98428 return -ENOMEM;
98429 }
98430@@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98431 static __init int sysctl_ipv4_init(void)
98432 {
98433 struct ctl_table_header *hdr;
98434- struct ctl_table *i;
98435-
98436- for (i = ipv4_table; i->procname; i++) {
98437- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98438- i->data = sysctl_local_reserved_ports;
98439- break;
98440- }
98441- }
98442- if (!i->procname)
98443- return -EINVAL;
98444
98445 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98446 if (hdr == NULL)
98447diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98448index c53b7f3..a89aadd 100644
98449--- a/net/ipv4/tcp_input.c
98450+++ b/net/ipv4/tcp_input.c
98451@@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98452 * without any lock. We want to make sure compiler wont store
98453 * intermediate values in this location.
98454 */
98455- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98456+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98457 sk->sk_max_pacing_rate);
98458 }
98459
98460@@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98461 * simplifies code)
98462 */
98463 static void
98464-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98465+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98466 struct sk_buff *head, struct sk_buff *tail,
98467 u32 start, u32 end)
98468 {
98469@@ -5559,6 +5559,7 @@ discard:
98470 tcp_paws_reject(&tp->rx_opt, 0))
98471 goto discard_and_undo;
98472
98473+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98474 if (th->syn) {
98475 /* We see SYN without ACK. It is attempt of
98476 * simultaneous connect with crossed SYNs.
98477@@ -5609,6 +5610,7 @@ discard:
98478 goto discard;
98479 #endif
98480 }
98481+#endif
98482 /* "fifth, if neither of the SYN or RST bits is set then
98483 * drop the segment and return."
98484 */
98485@@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98486 goto discard;
98487
98488 if (th->syn) {
98489- if (th->fin)
98490+ if (th->fin || th->urg || th->psh)
98491 goto discard;
98492 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98493 return 1;
98494diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98495index 0672139..cacc17d 100644
98496--- a/net/ipv4/tcp_ipv4.c
98497+++ b/net/ipv4/tcp_ipv4.c
98498@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98499 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98500
98501
98502+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98503+extern int grsec_enable_blackhole;
98504+#endif
98505+
98506 #ifdef CONFIG_TCP_MD5SIG
98507 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98508 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98509@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98510 return 0;
98511
98512 reset:
98513+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98514+ if (!grsec_enable_blackhole)
98515+#endif
98516 tcp_v4_send_reset(rsk, skb);
98517 discard:
98518 kfree_skb(skb);
98519@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98520 TCP_SKB_CB(skb)->sacked = 0;
98521
98522 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98523- if (!sk)
98524+ if (!sk) {
98525+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98526+ ret = 1;
98527+#endif
98528 goto no_tcp_socket;
98529-
98530+ }
98531 process:
98532- if (sk->sk_state == TCP_TIME_WAIT)
98533+ if (sk->sk_state == TCP_TIME_WAIT) {
98534+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98535+ ret = 2;
98536+#endif
98537 goto do_time_wait;
98538+ }
98539
98540 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98541 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98542@@ -2034,6 +2048,10 @@ csum_error:
98543 bad_packet:
98544 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98545 } else {
98546+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98547+ if (!grsec_enable_blackhole || (ret == 1 &&
98548+ (skb->dev->flags & IFF_LOOPBACK)))
98549+#endif
98550 tcp_v4_send_reset(NULL, skb);
98551 }
98552
98553diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98554index 97b6841..0893357 100644
98555--- a/net/ipv4/tcp_minisocks.c
98556+++ b/net/ipv4/tcp_minisocks.c
98557@@ -27,6 +27,10 @@
98558 #include <net/inet_common.h>
98559 #include <net/xfrm.h>
98560
98561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98562+extern int grsec_enable_blackhole;
98563+#endif
98564+
98565 int sysctl_tcp_syncookies __read_mostly = 1;
98566 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98567
98568@@ -708,7 +712,10 @@ embryonic_reset:
98569 * avoid becoming vulnerable to outside attack aiming at
98570 * resetting legit local connections.
98571 */
98572- req->rsk_ops->send_reset(sk, skb);
98573+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98574+ if (!grsec_enable_blackhole)
98575+#endif
98576+ req->rsk_ops->send_reset(sk, skb);
98577 } else if (fastopen) { /* received a valid RST pkt */
98578 reqsk_fastopen_remove(sk, req, true);
98579 tcp_reset(sk);
98580diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98581index 8b97d71..9d7ccf5 100644
98582--- a/net/ipv4/tcp_probe.c
98583+++ b/net/ipv4/tcp_probe.c
98584@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98585 if (cnt + width >= len)
98586 break;
98587
98588- if (copy_to_user(buf + cnt, tbuf, width))
98589+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98590 return -EFAULT;
98591 cnt += width;
98592 }
98593diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98594index 64f0354..a81b39d 100644
98595--- a/net/ipv4/tcp_timer.c
98596+++ b/net/ipv4/tcp_timer.c
98597@@ -22,6 +22,10 @@
98598 #include <linux/gfp.h>
98599 #include <net/tcp.h>
98600
98601+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98602+extern int grsec_lastack_retries;
98603+#endif
98604+
98605 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98606 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98607 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98608@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98609 }
98610 }
98611
98612+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98613+ if ((sk->sk_state == TCP_LAST_ACK) &&
98614+ (grsec_lastack_retries > 0) &&
98615+ (grsec_lastack_retries < retry_until))
98616+ retry_until = grsec_lastack_retries;
98617+#endif
98618+
98619 if (retransmits_timed_out(sk, retry_until,
98620 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98621 /* Has it gone just too far? */
98622diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98623index a7e4729..2758946 100644
98624--- a/net/ipv4/udp.c
98625+++ b/net/ipv4/udp.c
98626@@ -87,6 +87,7 @@
98627 #include <linux/types.h>
98628 #include <linux/fcntl.h>
98629 #include <linux/module.h>
98630+#include <linux/security.h>
98631 #include <linux/socket.h>
98632 #include <linux/sockios.h>
98633 #include <linux/igmp.h>
98634@@ -113,6 +114,10 @@
98635 #include <net/busy_poll.h>
98636 #include "udp_impl.h"
98637
98638+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98639+extern int grsec_enable_blackhole;
98640+#endif
98641+
98642 struct udp_table udp_table __read_mostly;
98643 EXPORT_SYMBOL(udp_table);
98644
98645@@ -615,6 +620,9 @@ found:
98646 return s;
98647 }
98648
98649+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98650+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98651+
98652 /*
98653 * This routine is called by the ICMP module when it gets some
98654 * sort of error condition. If err < 0 then the socket should
98655@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98656 dport = usin->sin_port;
98657 if (dport == 0)
98658 return -EINVAL;
98659+
98660+ err = gr_search_udp_sendmsg(sk, usin);
98661+ if (err)
98662+ return err;
98663 } else {
98664 if (sk->sk_state != TCP_ESTABLISHED)
98665 return -EDESTADDRREQ;
98666+
98667+ err = gr_search_udp_sendmsg(sk, NULL);
98668+ if (err)
98669+ return err;
98670+
98671 daddr = inet->inet_daddr;
98672 dport = inet->inet_dport;
98673 /* Open fast path for connected socket.
98674@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98675 IS_UDPLITE(sk));
98676 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98677 IS_UDPLITE(sk));
98678- atomic_inc(&sk->sk_drops);
98679+ atomic_inc_unchecked(&sk->sk_drops);
98680 __skb_unlink(skb, rcvq);
98681 __skb_queue_tail(&list_kill, skb);
98682 }
98683@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98684 int is_udplite = IS_UDPLITE(sk);
98685 bool slow;
98686
98687+ /*
98688+ * Check any passed addresses
98689+ */
98690+ if (addr_len)
98691+ *addr_len = sizeof(*sin);
98692+
98693 if (flags & MSG_ERRQUEUE)
98694 return ip_recv_error(sk, msg, len, addr_len);
98695
98696@@ -1243,6 +1266,10 @@ try_again:
98697 if (!skb)
98698 goto out;
98699
98700+ err = gr_search_udp_recvmsg(sk, skb);
98701+ if (err)
98702+ goto out_free;
98703+
98704 ulen = skb->len - sizeof(struct udphdr);
98705 copied = len;
98706 if (copied > ulen)
98707@@ -1276,7 +1303,7 @@ try_again:
98708 if (unlikely(err)) {
98709 trace_kfree_skb(skb, udp_recvmsg);
98710 if (!peeked) {
98711- atomic_inc(&sk->sk_drops);
98712+ atomic_inc_unchecked(&sk->sk_drops);
98713 UDP_INC_STATS_USER(sock_net(sk),
98714 UDP_MIB_INERRORS, is_udplite);
98715 }
98716@@ -1295,7 +1322,6 @@ try_again:
98717 sin->sin_port = udp_hdr(skb)->source;
98718 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98719 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98720- *addr_len = sizeof(*sin);
98721 }
98722 if (inet->cmsg_flags)
98723 ip_cmsg_recv(msg, skb);
98724@@ -1566,7 +1592,7 @@ csum_error:
98725 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98726 drop:
98727 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98728- atomic_inc(&sk->sk_drops);
98729+ atomic_inc_unchecked(&sk->sk_drops);
98730 kfree_skb(skb);
98731 return -1;
98732 }
98733@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98734 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98735
98736 if (!skb1) {
98737- atomic_inc(&sk->sk_drops);
98738+ atomic_inc_unchecked(&sk->sk_drops);
98739 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98740 IS_UDPLITE(sk));
98741 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98742@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98743 goto csum_error;
98744
98745 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98746+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98747+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98748+#endif
98749 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98750
98751 /*
98752@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98753 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98754 0, sock_i_ino(sp),
98755 atomic_read(&sp->sk_refcnt), sp,
98756- atomic_read(&sp->sk_drops));
98757+ atomic_read_unchecked(&sp->sk_drops));
98758 }
98759
98760 int udp4_seq_show(struct seq_file *seq, void *v)
98761diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98762index e1a6393..f634ce5 100644
98763--- a/net/ipv4/xfrm4_policy.c
98764+++ b/net/ipv4/xfrm4_policy.c
98765@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98766 fl4->flowi4_tos = iph->tos;
98767 }
98768
98769-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98770+static int xfrm4_garbage_collect(struct dst_ops *ops)
98771 {
98772 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98773
98774- xfrm4_policy_afinfo.garbage_collect(net);
98775+ xfrm_garbage_collect_deferred(net);
98776 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98777 }
98778
98779@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98780
98781 static int __net_init xfrm4_net_init(struct net *net)
98782 {
98783- struct ctl_table *table;
98784+ ctl_table_no_const *table = NULL;
98785 struct ctl_table_header *hdr;
98786
98787- table = xfrm4_policy_table;
98788 if (!net_eq(net, &init_net)) {
98789- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98790+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98791 if (!table)
98792 goto err_alloc;
98793
98794 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98795- }
98796-
98797- hdr = register_net_sysctl(net, "net/ipv4", table);
98798+ hdr = register_net_sysctl(net, "net/ipv4", table);
98799+ } else
98800+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98801 if (!hdr)
98802 goto err_reg;
98803
98804@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98805 return 0;
98806
98807 err_reg:
98808- if (!net_eq(net, &init_net))
98809- kfree(table);
98810+ kfree(table);
98811 err_alloc:
98812 return -ENOMEM;
98813 }
98814diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98815index 9c05d77..9cfa714 100644
98816--- a/net/ipv6/addrconf.c
98817+++ b/net/ipv6/addrconf.c
98818@@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98819 idx = 0;
98820 head = &net->dev_index_head[h];
98821 rcu_read_lock();
98822- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98823+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98824 net->dev_base_seq;
98825 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98826 if (idx < s_idx)
98827@@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98828 p.iph.ihl = 5;
98829 p.iph.protocol = IPPROTO_IPV6;
98830 p.iph.ttl = 64;
98831- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98832+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98833
98834 if (ops->ndo_do_ioctl) {
98835 mm_segment_t oldfs = get_fs();
98836@@ -3964,7 +3964,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98837 s_ip_idx = ip_idx = cb->args[2];
98838
98839 rcu_read_lock();
98840- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98841+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98842 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98843 idx = 0;
98844 head = &net->dev_index_head[h];
98845@@ -4571,7 +4571,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98846 dst_free(&ifp->rt->dst);
98847 break;
98848 }
98849- atomic_inc(&net->ipv6.dev_addr_genid);
98850+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98851 rt_genid_bump_ipv6(net);
98852 }
98853
98854@@ -4592,7 +4592,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98855 int *valp = ctl->data;
98856 int val = *valp;
98857 loff_t pos = *ppos;
98858- struct ctl_table lctl;
98859+ ctl_table_no_const lctl;
98860 int ret;
98861
98862 /*
98863@@ -4677,7 +4677,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98864 int *valp = ctl->data;
98865 int val = *valp;
98866 loff_t pos = *ppos;
98867- struct ctl_table lctl;
98868+ ctl_table_no_const lctl;
98869 int ret;
98870
98871 /*
98872diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98873index 4fbdb70..f6411f2 100644
98874--- a/net/ipv6/af_inet6.c
98875+++ b/net/ipv6/af_inet6.c
98876@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98877
98878 net->ipv6.sysctl.bindv6only = 0;
98879 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98880- atomic_set(&net->ipv6.rt_genid, 0);
98881+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98882
98883 err = ipv6_init_mibs(net);
98884 if (err)
98885diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98886index 93b1aa3..e902855 100644
98887--- a/net/ipv6/datagram.c
98888+++ b/net/ipv6/datagram.c
98889@@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98890 0,
98891 sock_i_ino(sp),
98892 atomic_read(&sp->sk_refcnt), sp,
98893- atomic_read(&sp->sk_drops));
98894+ atomic_read_unchecked(&sp->sk_drops));
98895 }
98896diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98897index eef8d94..cfa1852 100644
98898--- a/net/ipv6/icmp.c
98899+++ b/net/ipv6/icmp.c
98900@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
98901
98902 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98903 {
98904- struct ctl_table *table;
98905+ ctl_table_no_const *table;
98906
98907 table = kmemdup(ipv6_icmp_table_template,
98908 sizeof(ipv6_icmp_table_template),
98909diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98910index 8acb286..840dd06 100644
98911--- a/net/ipv6/ip6_gre.c
98912+++ b/net/ipv6/ip6_gre.c
98913@@ -74,7 +74,7 @@ struct ip6gre_net {
98914 struct net_device *fb_tunnel_dev;
98915 };
98916
98917-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98918+static struct rtnl_link_ops ip6gre_link_ops;
98919 static int ip6gre_tunnel_init(struct net_device *dev);
98920 static void ip6gre_tunnel_setup(struct net_device *dev);
98921 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98922@@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98923 }
98924
98925
98926-static struct inet6_protocol ip6gre_protocol __read_mostly = {
98927+static struct inet6_protocol ip6gre_protocol = {
98928 .handler = ip6gre_rcv,
98929 .err_handler = ip6gre_err,
98930 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98931@@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98932 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98933 };
98934
98935-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98936+static struct rtnl_link_ops ip6gre_link_ops = {
98937 .kind = "ip6gre",
98938 .maxtype = IFLA_GRE_MAX,
98939 .policy = ip6gre_policy,
98940@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98941 .fill_info = ip6gre_fill_info,
98942 };
98943
98944-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98945+static struct rtnl_link_ops ip6gre_tap_ops = {
98946 .kind = "ip6gretap",
98947 .maxtype = IFLA_GRE_MAX,
98948 .policy = ip6gre_policy,
98949diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98950index 7881965..9cf62c4 100644
98951--- a/net/ipv6/ip6_tunnel.c
98952+++ b/net/ipv6/ip6_tunnel.c
98953@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98954
98955 static int ip6_tnl_dev_init(struct net_device *dev);
98956 static void ip6_tnl_dev_setup(struct net_device *dev);
98957-static struct rtnl_link_ops ip6_link_ops __read_mostly;
98958+static struct rtnl_link_ops ip6_link_ops;
98959
98960 static int ip6_tnl_net_id __read_mostly;
98961 struct ip6_tnl_net {
98962@@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98963 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98964 };
98965
98966-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98967+static struct rtnl_link_ops ip6_link_ops = {
98968 .kind = "ip6tnl",
98969 .maxtype = IFLA_IPTUN_MAX,
98970 .policy = ip6_tnl_policy,
98971diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
98972index 7b42d5e..1eff693 100644
98973--- a/net/ipv6/ip6_vti.c
98974+++ b/net/ipv6/ip6_vti.c
98975@@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98976
98977 static int vti6_dev_init(struct net_device *dev);
98978 static void vti6_dev_setup(struct net_device *dev);
98979-static struct rtnl_link_ops vti6_link_ops __read_mostly;
98980+static struct rtnl_link_ops vti6_link_ops;
98981
98982 static int vti6_net_id __read_mostly;
98983 struct vti6_net {
98984@@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
98985 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
98986 };
98987
98988-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
98989+static struct rtnl_link_ops vti6_link_ops = {
98990 .kind = "vti6",
98991 .maxtype = IFLA_VTI_MAX,
98992 .policy = vti6_policy,
98993diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
98994index 1c6ce31..299e566 100644
98995--- a/net/ipv6/ipv6_sockglue.c
98996+++ b/net/ipv6/ipv6_sockglue.c
98997@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
98998 if (sk->sk_type != SOCK_STREAM)
98999 return -ENOPROTOOPT;
99000
99001- msg.msg_control = optval;
99002+ msg.msg_control = (void __force_kernel *)optval;
99003 msg.msg_controllen = len;
99004 msg.msg_flags = flags;
99005
99006diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99007index 710238f..0fd1816 100644
99008--- a/net/ipv6/netfilter/ip6_tables.c
99009+++ b/net/ipv6/netfilter/ip6_tables.c
99010@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99011 #endif
99012
99013 static int get_info(struct net *net, void __user *user,
99014- const int *len, int compat)
99015+ int len, int compat)
99016 {
99017 char name[XT_TABLE_MAXNAMELEN];
99018 struct xt_table *t;
99019 int ret;
99020
99021- if (*len != sizeof(struct ip6t_getinfo)) {
99022- duprintf("length %u != %zu\n", *len,
99023+ if (len != sizeof(struct ip6t_getinfo)) {
99024+ duprintf("length %u != %zu\n", len,
99025 sizeof(struct ip6t_getinfo));
99026 return -EINVAL;
99027 }
99028@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99029 info.size = private->size;
99030 strcpy(info.name, name);
99031
99032- if (copy_to_user(user, &info, *len) != 0)
99033+ if (copy_to_user(user, &info, len) != 0)
99034 ret = -EFAULT;
99035 else
99036 ret = 0;
99037@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99038
99039 switch (cmd) {
99040 case IP6T_SO_GET_INFO:
99041- ret = get_info(sock_net(sk), user, len, 1);
99042+ ret = get_info(sock_net(sk), user, *len, 1);
99043 break;
99044 case IP6T_SO_GET_ENTRIES:
99045 ret = compat_get_entries(sock_net(sk), user, len);
99046@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99047
99048 switch (cmd) {
99049 case IP6T_SO_GET_INFO:
99050- ret = get_info(sock_net(sk), user, len, 0);
99051+ ret = get_info(sock_net(sk), user, *len, 0);
99052 break;
99053
99054 case IP6T_SO_GET_ENTRIES:
99055diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99056index 767ab8d..c5ec70a 100644
99057--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99058+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99059@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99060
99061 static int nf_ct_frag6_sysctl_register(struct net *net)
99062 {
99063- struct ctl_table *table;
99064+ ctl_table_no_const *table = NULL;
99065 struct ctl_table_header *hdr;
99066
99067- table = nf_ct_frag6_sysctl_table;
99068 if (!net_eq(net, &init_net)) {
99069- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99070+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99071 GFP_KERNEL);
99072 if (table == NULL)
99073 goto err_alloc;
99074@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99075 table[0].data = &net->nf_frag.frags.timeout;
99076 table[1].data = &net->nf_frag.frags.low_thresh;
99077 table[2].data = &net->nf_frag.frags.high_thresh;
99078- }
99079-
99080- hdr = register_net_sysctl(net, "net/netfilter", table);
99081+ hdr = register_net_sysctl(net, "net/netfilter", table);
99082+ } else
99083+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99084 if (hdr == NULL)
99085 goto err_reg;
99086
99087@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99088 return 0;
99089
99090 err_reg:
99091- if (!net_eq(net, &init_net))
99092- kfree(table);
99093+ kfree(table);
99094 err_alloc:
99095 return -ENOMEM;
99096 }
99097diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99098index 827f795..7e28e82 100644
99099--- a/net/ipv6/output_core.c
99100+++ b/net/ipv6/output_core.c
99101@@ -9,8 +9,8 @@
99102
99103 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99104 {
99105- static atomic_t ipv6_fragmentation_id;
99106- int old, new;
99107+ static atomic_unchecked_t ipv6_fragmentation_id;
99108+ int id;
99109
99110 #if IS_ENABLED(CONFIG_IPV6)
99111 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99112@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99113 }
99114 }
99115 #endif
99116- do {
99117- old = atomic_read(&ipv6_fragmentation_id);
99118- new = old + 1;
99119- if (!new)
99120- new = 1;
99121- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99122- fhdr->identification = htonl(new);
99123+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99124+ if (!id)
99125+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99126+ fhdr->identification = htonl(id);
99127 }
99128 EXPORT_SYMBOL(ipv6_select_ident);
99129
99130diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99131index a83243c..a1ca589 100644
99132--- a/net/ipv6/ping.c
99133+++ b/net/ipv6/ping.c
99134@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
99135 };
99136 #endif
99137
99138+static struct pingv6_ops real_pingv6_ops = {
99139+ .ipv6_recv_error = ipv6_recv_error,
99140+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
99141+ .icmpv6_err_convert = icmpv6_err_convert,
99142+ .ipv6_icmp_error = ipv6_icmp_error,
99143+ .ipv6_chk_addr = ipv6_chk_addr,
99144+};
99145+
99146+static struct pingv6_ops dummy_pingv6_ops = {
99147+ .ipv6_recv_error = dummy_ipv6_recv_error,
99148+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
99149+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99150+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99151+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99152+};
99153+
99154 int __init pingv6_init(void)
99155 {
99156 #ifdef CONFIG_PROC_FS
99157@@ -253,11 +269,7 @@ int __init pingv6_init(void)
99158 if (ret)
99159 return ret;
99160 #endif
99161- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99162- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
99163- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99164- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99165- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99166+ pingv6_ops = &real_pingv6_ops;
99167 return inet6_register_protosw(&pingv6_protosw);
99168 }
99169
99170@@ -266,11 +278,7 @@ int __init pingv6_init(void)
99171 */
99172 void pingv6_exit(void)
99173 {
99174- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99175- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
99176- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99177- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99178- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99179+ pingv6_ops = &dummy_pingv6_ops;
99180 #ifdef CONFIG_PROC_FS
99181 unregister_pernet_subsys(&ping_v6_net_ops);
99182 #endif
99183diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99184index b6bb87e..06cc9ed 100644
99185--- a/net/ipv6/raw.c
99186+++ b/net/ipv6/raw.c
99187@@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99188 {
99189 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99190 skb_checksum_complete(skb)) {
99191- atomic_inc(&sk->sk_drops);
99192+ atomic_inc_unchecked(&sk->sk_drops);
99193 kfree_skb(skb);
99194 return NET_RX_DROP;
99195 }
99196@@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99197 struct raw6_sock *rp = raw6_sk(sk);
99198
99199 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99200- atomic_inc(&sk->sk_drops);
99201+ atomic_inc_unchecked(&sk->sk_drops);
99202 kfree_skb(skb);
99203 return NET_RX_DROP;
99204 }
99205@@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99206
99207 if (inet->hdrincl) {
99208 if (skb_checksum_complete(skb)) {
99209- atomic_inc(&sk->sk_drops);
99210+ atomic_inc_unchecked(&sk->sk_drops);
99211 kfree_skb(skb);
99212 return NET_RX_DROP;
99213 }
99214@@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99215 if (flags & MSG_OOB)
99216 return -EOPNOTSUPP;
99217
99218+ if (addr_len)
99219+ *addr_len=sizeof(*sin6);
99220+
99221 if (flags & MSG_ERRQUEUE)
99222 return ipv6_recv_error(sk, msg, len, addr_len);
99223
99224@@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99225 sin6->sin6_flowinfo = 0;
99226 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99227 IP6CB(skb)->iif);
99228- *addr_len = sizeof(*sin6);
99229 }
99230
99231 sock_recv_ts_and_drops(msg, sk, skb);
99232@@ -606,7 +608,7 @@ out:
99233 return err;
99234 }
99235
99236-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99237+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99238 struct flowi6 *fl6, struct dst_entry **dstp,
99239 unsigned int flags)
99240 {
99241@@ -918,12 +920,15 @@ do_confirm:
99242 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99243 char __user *optval, int optlen)
99244 {
99245+ struct icmp6_filter filter;
99246+
99247 switch (optname) {
99248 case ICMPV6_FILTER:
99249 if (optlen > sizeof(struct icmp6_filter))
99250 optlen = sizeof(struct icmp6_filter);
99251- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99252+ if (copy_from_user(&filter, optval, optlen))
99253 return -EFAULT;
99254+ raw6_sk(sk)->filter = filter;
99255 return 0;
99256 default:
99257 return -ENOPROTOOPT;
99258@@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99259 char __user *optval, int __user *optlen)
99260 {
99261 int len;
99262+ struct icmp6_filter filter;
99263
99264 switch (optname) {
99265 case ICMPV6_FILTER:
99266@@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99267 len = sizeof(struct icmp6_filter);
99268 if (put_user(len, optlen))
99269 return -EFAULT;
99270- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99271+ filter = raw6_sk(sk)->filter;
99272+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
99273 return -EFAULT;
99274 return 0;
99275 default:
99276diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99277index cc85a9b..526a133 100644
99278--- a/net/ipv6/reassembly.c
99279+++ b/net/ipv6/reassembly.c
99280@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99281
99282 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99283 {
99284- struct ctl_table *table;
99285+ ctl_table_no_const *table = NULL;
99286 struct ctl_table_header *hdr;
99287
99288- table = ip6_frags_ns_ctl_table;
99289 if (!net_eq(net, &init_net)) {
99290- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99291+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99292 if (table == NULL)
99293 goto err_alloc;
99294
99295@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99296 /* Don't export sysctls to unprivileged users */
99297 if (net->user_ns != &init_user_ns)
99298 table[0].procname = NULL;
99299- }
99300+ hdr = register_net_sysctl(net, "net/ipv6", table);
99301+ } else
99302+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99303
99304- hdr = register_net_sysctl(net, "net/ipv6", table);
99305 if (hdr == NULL)
99306 goto err_reg;
99307
99308@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99309 return 0;
99310
99311 err_reg:
99312- if (!net_eq(net, &init_net))
99313- kfree(table);
99314+ kfree(table);
99315 err_alloc:
99316 return -ENOMEM;
99317 }
99318diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99319index 4b4944c..d346b14 100644
99320--- a/net/ipv6/route.c
99321+++ b/net/ipv6/route.c
99322@@ -1495,7 +1495,7 @@ int ip6_route_add(struct fib6_config *cfg)
99323 if (!table)
99324 goto out;
99325
99326- rt = ip6_dst_alloc(net, NULL, DST_NOCOUNT, table);
99327+ rt = ip6_dst_alloc(net, NULL, (cfg->fc_flags & RTF_ADDRCONF) ? 0 : DST_NOCOUNT, table);
99328
99329 if (!rt) {
99330 err = -ENOMEM;
99331@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99332
99333 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99334 {
99335- struct ctl_table *table;
99336+ ctl_table_no_const *table;
99337
99338 table = kmemdup(ipv6_route_table_template,
99339 sizeof(ipv6_route_table_template),
99340diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99341index d3005b3..b36df4a 100644
99342--- a/net/ipv6/sit.c
99343+++ b/net/ipv6/sit.c
99344@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99345 static void ipip6_dev_free(struct net_device *dev);
99346 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99347 __be32 *v4dst);
99348-static struct rtnl_link_ops sit_link_ops __read_mostly;
99349+static struct rtnl_link_ops sit_link_ops;
99350
99351 static int sit_net_id __read_mostly;
99352 struct sit_net {
99353@@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99354 unregister_netdevice_queue(dev, head);
99355 }
99356
99357-static struct rtnl_link_ops sit_link_ops __read_mostly = {
99358+static struct rtnl_link_ops sit_link_ops = {
99359 .kind = "sit",
99360 .maxtype = IFLA_IPTUN_MAX,
99361 .policy = ipip6_policy,
99362diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99363index 107b2f1..72741a9 100644
99364--- a/net/ipv6/sysctl_net_ipv6.c
99365+++ b/net/ipv6/sysctl_net_ipv6.c
99366@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99367
99368 static int __net_init ipv6_sysctl_net_init(struct net *net)
99369 {
99370- struct ctl_table *ipv6_table;
99371+ ctl_table_no_const *ipv6_table;
99372 struct ctl_table *ipv6_route_table;
99373 struct ctl_table *ipv6_icmp_table;
99374 int err;
99375diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99376index f67033b..6f974fc 100644
99377--- a/net/ipv6/tcp_ipv6.c
99378+++ b/net/ipv6/tcp_ipv6.c
99379@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99380 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99381 }
99382
99383+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99384+extern int grsec_enable_blackhole;
99385+#endif
99386+
99387 static void tcp_v6_hash(struct sock *sk)
99388 {
99389 if (sk->sk_state != TCP_CLOSE) {
99390@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99391 return 0;
99392
99393 reset:
99394+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99395+ if (!grsec_enable_blackhole)
99396+#endif
99397 tcp_v6_send_reset(sk, skb);
99398 discard:
99399 if (opt_skb)
99400@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99401 TCP_SKB_CB(skb)->sacked = 0;
99402
99403 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99404- if (!sk)
99405+ if (!sk) {
99406+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99407+ ret = 1;
99408+#endif
99409 goto no_tcp_socket;
99410+ }
99411
99412 process:
99413- if (sk->sk_state == TCP_TIME_WAIT)
99414+ if (sk->sk_state == TCP_TIME_WAIT) {
99415+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99416+ ret = 2;
99417+#endif
99418 goto do_time_wait;
99419+ }
99420
99421 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99422 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99423@@ -1536,6 +1551,10 @@ csum_error:
99424 bad_packet:
99425 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99426 } else {
99427+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99428+ if (!grsec_enable_blackhole || (ret == 1 &&
99429+ (skb->dev->flags & IFF_LOOPBACK)))
99430+#endif
99431 tcp_v6_send_reset(NULL, skb);
99432 }
99433
99434diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99435index 089c741..cfee117 100644
99436--- a/net/ipv6/udp.c
99437+++ b/net/ipv6/udp.c
99438@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99439 udp_ipv6_hash_secret + net_hash_mix(net));
99440 }
99441
99442+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99443+extern int grsec_enable_blackhole;
99444+#endif
99445+
99446 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99447 {
99448 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99449@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99450 int is_udp4;
99451 bool slow;
99452
99453+ if (addr_len)
99454+ *addr_len = sizeof(struct sockaddr_in6);
99455+
99456 if (flags & MSG_ERRQUEUE)
99457 return ipv6_recv_error(sk, msg, len, addr_len);
99458
99459@@ -435,7 +442,7 @@ try_again:
99460 if (unlikely(err)) {
99461 trace_kfree_skb(skb, udpv6_recvmsg);
99462 if (!peeked) {
99463- atomic_inc(&sk->sk_drops);
99464+ atomic_inc_unchecked(&sk->sk_drops);
99465 if (is_udp4)
99466 UDP_INC_STATS_USER(sock_net(sk),
99467 UDP_MIB_INERRORS,
99468@@ -477,7 +484,7 @@ try_again:
99469 ipv6_iface_scope_id(&sin6->sin6_addr,
99470 IP6CB(skb)->iif);
99471 }
99472- *addr_len = sizeof(*sin6);
99473+
99474 }
99475 if (is_udp4) {
99476 if (inet->cmsg_flags)
99477@@ -685,7 +692,7 @@ csum_error:
99478 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99479 drop:
99480 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99481- atomic_inc(&sk->sk_drops);
99482+ atomic_inc_unchecked(&sk->sk_drops);
99483 kfree_skb(skb);
99484 return -1;
99485 }
99486@@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99487 if (likely(skb1 == NULL))
99488 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99489 if (!skb1) {
99490- atomic_inc(&sk->sk_drops);
99491+ atomic_inc_unchecked(&sk->sk_drops);
99492 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99493 IS_UDPLITE(sk));
99494 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99495@@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99496 goto csum_error;
99497
99498 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99499+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99500+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99501+#endif
99502 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99503
99504 kfree_skb(skb);
99505diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99506index 5f8e128..865d38e 100644
99507--- a/net/ipv6/xfrm6_policy.c
99508+++ b/net/ipv6/xfrm6_policy.c
99509@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99510 }
99511 }
99512
99513-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99514+static int xfrm6_garbage_collect(struct dst_ops *ops)
99515 {
99516 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99517
99518- xfrm6_policy_afinfo.garbage_collect(net);
99519+ xfrm_garbage_collect_deferred(net);
99520 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99521 }
99522
99523@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99524
99525 static int __net_init xfrm6_net_init(struct net *net)
99526 {
99527- struct ctl_table *table;
99528+ ctl_table_no_const *table = NULL;
99529 struct ctl_table_header *hdr;
99530
99531- table = xfrm6_policy_table;
99532 if (!net_eq(net, &init_net)) {
99533- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99534+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99535 if (!table)
99536 goto err_alloc;
99537
99538 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99539- }
99540+ hdr = register_net_sysctl(net, "net/ipv6", table);
99541+ } else
99542+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99543
99544- hdr = register_net_sysctl(net, "net/ipv6", table);
99545 if (!hdr)
99546 goto err_reg;
99547
99548@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99549 return 0;
99550
99551 err_reg:
99552- if (!net_eq(net, &init_net))
99553- kfree(table);
99554+ kfree(table);
99555 err_alloc:
99556 return -ENOMEM;
99557 }
99558diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99559index 41ac7938..75e3bb1 100644
99560--- a/net/irda/ircomm/ircomm_tty.c
99561+++ b/net/irda/ircomm/ircomm_tty.c
99562@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99563 add_wait_queue(&port->open_wait, &wait);
99564
99565 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99566- __FILE__, __LINE__, tty->driver->name, port->count);
99567+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99568
99569 spin_lock_irqsave(&port->lock, flags);
99570 if (!tty_hung_up_p(filp))
99571- port->count--;
99572+ atomic_dec(&port->count);
99573 port->blocked_open++;
99574 spin_unlock_irqrestore(&port->lock, flags);
99575
99576@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99577 }
99578
99579 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99580- __FILE__, __LINE__, tty->driver->name, port->count);
99581+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99582
99583 schedule();
99584 }
99585@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99586
99587 spin_lock_irqsave(&port->lock, flags);
99588 if (!tty_hung_up_p(filp))
99589- port->count++;
99590+ atomic_inc(&port->count);
99591 port->blocked_open--;
99592 spin_unlock_irqrestore(&port->lock, flags);
99593
99594 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99595- __FILE__, __LINE__, tty->driver->name, port->count);
99596+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99597
99598 if (!retval)
99599 port->flags |= ASYNC_NORMAL_ACTIVE;
99600@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99601
99602 /* ++ is not atomic, so this should be protected - Jean II */
99603 spin_lock_irqsave(&self->port.lock, flags);
99604- self->port.count++;
99605+ atomic_inc(&self->port.count);
99606 spin_unlock_irqrestore(&self->port.lock, flags);
99607 tty_port_tty_set(&self->port, tty);
99608
99609 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99610- self->line, self->port.count);
99611+ self->line, atomic_read(&self->port.count));
99612
99613 /* Not really used by us, but lets do it anyway */
99614 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99615@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99616 tty_kref_put(port->tty);
99617 }
99618 port->tty = NULL;
99619- port->count = 0;
99620+ atomic_set(&port->count, 0);
99621 spin_unlock_irqrestore(&port->lock, flags);
99622
99623 wake_up_interruptible(&port->open_wait);
99624@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99625 seq_putc(m, '\n');
99626
99627 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99628- seq_printf(m, "Open count: %d\n", self->port.count);
99629+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99630 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99631 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99632
99633diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99634index c4b7218..3e83259 100644
99635--- a/net/iucv/af_iucv.c
99636+++ b/net/iucv/af_iucv.c
99637@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99638
99639 write_lock_bh(&iucv_sk_list.lock);
99640
99641- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99642+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99643 while (__iucv_get_sock_by_name(name)) {
99644 sprintf(name, "%08x",
99645- atomic_inc_return(&iucv_sk_list.autobind_name));
99646+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99647 }
99648
99649 write_unlock_bh(&iucv_sk_list.lock);
99650diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99651index cd5b8ec..f205e6b 100644
99652--- a/net/iucv/iucv.c
99653+++ b/net/iucv/iucv.c
99654@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99655 return NOTIFY_OK;
99656 }
99657
99658-static struct notifier_block __refdata iucv_cpu_notifier = {
99659+static struct notifier_block iucv_cpu_notifier = {
99660 .notifier_call = iucv_cpu_notify,
99661 };
99662
99663diff --git a/net/key/af_key.c b/net/key/af_key.c
99664index 545f047..9757a9d 100644
99665--- a/net/key/af_key.c
99666+++ b/net/key/af_key.c
99667@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99668 static u32 get_acqseq(void)
99669 {
99670 u32 res;
99671- static atomic_t acqseq;
99672+ static atomic_unchecked_t acqseq;
99673
99674 do {
99675- res = atomic_inc_return(&acqseq);
99676+ res = atomic_inc_return_unchecked(&acqseq);
99677 } while (!res);
99678 return res;
99679 }
99680diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99681index da1a1ce..571db8d 100644
99682--- a/net/l2tp/l2tp_ip.c
99683+++ b/net/l2tp/l2tp_ip.c
99684@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99685 if (flags & MSG_OOB)
99686 goto out;
99687
99688+ if (addr_len)
99689+ *addr_len = sizeof(*sin);
99690+
99691 skb = skb_recv_datagram(sk, flags, noblock, &err);
99692 if (!skb)
99693 goto out;
99694@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99695 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99696 sin->sin_port = 0;
99697 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99698- *addr_len = sizeof(*sin);
99699 }
99700 if (inet->cmsg_flags)
99701 ip_cmsg_recv(msg, skb);
99702diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99703index b4b61b2..ac84a257 100644
99704--- a/net/mac80211/cfg.c
99705+++ b/net/mac80211/cfg.c
99706@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99707 ret = ieee80211_vif_use_channel(sdata, chandef,
99708 IEEE80211_CHANCTX_EXCLUSIVE);
99709 }
99710- } else if (local->open_count == local->monitors) {
99711+ } else if (local_read(&local->open_count) == local->monitors) {
99712 local->_oper_chandef = *chandef;
99713 ieee80211_hw_config(local, 0);
99714 }
99715@@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99716 else
99717 local->probe_req_reg--;
99718
99719- if (!local->open_count)
99720+ if (!local_read(&local->open_count))
99721 break;
99722
99723 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99724@@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99725 if (chanctx_conf) {
99726 *chandef = chanctx_conf->def;
99727 ret = 0;
99728- } else if (local->open_count > 0 &&
99729- local->open_count == local->monitors &&
99730+ } else if (local_read(&local->open_count) > 0 &&
99731+ local_read(&local->open_count) == local->monitors &&
99732 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99733 if (local->use_chanctx)
99734 *chandef = local->monitor_chandef;
99735diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99736index 4aea4e7..9e698d1 100644
99737--- a/net/mac80211/ieee80211_i.h
99738+++ b/net/mac80211/ieee80211_i.h
99739@@ -28,6 +28,7 @@
99740 #include <net/ieee80211_radiotap.h>
99741 #include <net/cfg80211.h>
99742 #include <net/mac80211.h>
99743+#include <asm/local.h>
99744 #include "key.h"
99745 #include "sta_info.h"
99746 #include "debug.h"
99747@@ -961,7 +962,7 @@ struct ieee80211_local {
99748 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99749 spinlock_t queue_stop_reason_lock;
99750
99751- int open_count;
99752+ local_t open_count;
99753 int monitors, cooked_mntrs;
99754 /* number of interfaces with corresponding FIF_ flags */
99755 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99756diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99757index a075791..1d0027f 100644
99758--- a/net/mac80211/iface.c
99759+++ b/net/mac80211/iface.c
99760@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99761 break;
99762 }
99763
99764- if (local->open_count == 0) {
99765+ if (local_read(&local->open_count) == 0) {
99766 res = drv_start(local);
99767 if (res)
99768 goto err_del_bss;
99769@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99770 res = drv_add_interface(local, sdata);
99771 if (res)
99772 goto err_stop;
99773- } else if (local->monitors == 0 && local->open_count == 0) {
99774+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99775 res = ieee80211_add_virtual_monitor(local);
99776 if (res)
99777 goto err_stop;
99778@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99779 atomic_inc(&local->iff_promiscs);
99780
99781 if (coming_up)
99782- local->open_count++;
99783+ local_inc(&local->open_count);
99784
99785 if (hw_reconf_flags)
99786 ieee80211_hw_config(local, hw_reconf_flags);
99787@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99788 err_del_interface:
99789 drv_remove_interface(local, sdata);
99790 err_stop:
99791- if (!local->open_count)
99792+ if (!local_read(&local->open_count))
99793 drv_stop(local);
99794 err_del_bss:
99795 sdata->bss = NULL;
99796@@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99797 }
99798
99799 if (going_down)
99800- local->open_count--;
99801+ local_dec(&local->open_count);
99802
99803 switch (sdata->vif.type) {
99804 case NL80211_IFTYPE_AP_VLAN:
99805@@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99806 }
99807 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99808
99809- if (local->open_count == 0)
99810+ if (local_read(&local->open_count) == 0)
99811 ieee80211_clear_tx_pending(local);
99812
99813 /*
99814@@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99815
99816 ieee80211_recalc_ps(local, -1);
99817
99818- if (local->open_count == 0) {
99819+ if (local_read(&local->open_count) == 0) {
99820 ieee80211_stop_device(local);
99821
99822 /* no reconfiguring after stop! */
99823@@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99824 ieee80211_configure_filter(local);
99825 ieee80211_hw_config(local, hw_reconf_flags);
99826
99827- if (local->monitors == local->open_count)
99828+ if (local->monitors == local_read(&local->open_count))
99829 ieee80211_add_virtual_monitor(local);
99830 }
99831
99832diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99833index 7d1c3ac..b62dd29 100644
99834--- a/net/mac80211/main.c
99835+++ b/net/mac80211/main.c
99836@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99837 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99838 IEEE80211_CONF_CHANGE_POWER);
99839
99840- if (changed && local->open_count) {
99841+ if (changed && local_read(&local->open_count)) {
99842 ret = drv_config(local, changed);
99843 /*
99844 * Goal:
99845diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99846index 3401262..d5cd68d 100644
99847--- a/net/mac80211/pm.c
99848+++ b/net/mac80211/pm.c
99849@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99850 struct ieee80211_sub_if_data *sdata;
99851 struct sta_info *sta;
99852
99853- if (!local->open_count)
99854+ if (!local_read(&local->open_count))
99855 goto suspend;
99856
99857 ieee80211_scan_cancel(local);
99858@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99859 cancel_work_sync(&local->dynamic_ps_enable_work);
99860 del_timer_sync(&local->dynamic_ps_timer);
99861
99862- local->wowlan = wowlan && local->open_count;
99863+ local->wowlan = wowlan && local_read(&local->open_count);
99864 if (local->wowlan) {
99865 int err = drv_suspend(local, wowlan);
99866 if (err < 0) {
99867@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99868 WARN_ON(!list_empty(&local->chanctx_list));
99869
99870 /* stop hardware - this must stop RX */
99871- if (local->open_count)
99872+ if (local_read(&local->open_count))
99873 ieee80211_stop_device(local);
99874
99875 suspend:
99876diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99877index 22b223f..ab70070 100644
99878--- a/net/mac80211/rate.c
99879+++ b/net/mac80211/rate.c
99880@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99881
99882 ASSERT_RTNL();
99883
99884- if (local->open_count)
99885+ if (local_read(&local->open_count))
99886 return -EBUSY;
99887
99888 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99889diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99890index 6ff1346..936ca9a 100644
99891--- a/net/mac80211/rc80211_pid_debugfs.c
99892+++ b/net/mac80211/rc80211_pid_debugfs.c
99893@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99894
99895 spin_unlock_irqrestore(&events->lock, status);
99896
99897- if (copy_to_user(buf, pb, p))
99898+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99899 return -EFAULT;
99900
99901 return p;
99902diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99903index 9f9b9bd..d6fcf59 100644
99904--- a/net/mac80211/util.c
99905+++ b/net/mac80211/util.c
99906@@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99907 }
99908 #endif
99909 /* everything else happens only if HW was up & running */
99910- if (!local->open_count)
99911+ if (!local_read(&local->open_count))
99912 goto wake_up;
99913
99914 /*
99915@@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99916 local->in_reconfig = false;
99917 barrier();
99918
99919- if (local->monitors == local->open_count && local->monitors > 0)
99920+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99921 ieee80211_add_virtual_monitor(local);
99922
99923 /*
99924diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99925index c3398cd..98ad3b4 100644
99926--- a/net/netfilter/Kconfig
99927+++ b/net/netfilter/Kconfig
99928@@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
99929
99930 To compile it as a module, choose M here. If unsure, say N.
99931
99932+config NETFILTER_XT_MATCH_GRADM
99933+ tristate '"gradm" match support'
99934+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99935+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99936+ ---help---
99937+ The gradm match allows to match on grsecurity RBAC being enabled.
99938+ It is useful when iptables rules are applied early on bootup to
99939+ prevent connections to the machine (except from a trusted host)
99940+ while the RBAC system is disabled.
99941+
99942 config NETFILTER_XT_MATCH_HASHLIMIT
99943 tristate '"hashlimit" match support'
99944 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99945diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99946index 394483b..ed51f2d 100644
99947--- a/net/netfilter/Makefile
99948+++ b/net/netfilter/Makefile
99949@@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99950 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99951 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99952 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99953+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99954 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99955 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99956 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99957diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99958index bac7e01..1d7a31a 100644
99959--- a/net/netfilter/ipset/ip_set_core.c
99960+++ b/net/netfilter/ipset/ip_set_core.c
99961@@ -1950,7 +1950,7 @@ done:
99962 return ret;
99963 }
99964
99965-static struct nf_sockopt_ops so_set __read_mostly = {
99966+static struct nf_sockopt_ops so_set = {
99967 .pf = PF_INET,
99968 .get_optmin = SO_IP_SET,
99969 .get_optmax = SO_IP_SET + 1,
99970diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99971index 4c8e5c0..5a79b4d 100644
99972--- a/net/netfilter/ipvs/ip_vs_conn.c
99973+++ b/net/netfilter/ipvs/ip_vs_conn.c
99974@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99975 /* Increase the refcnt counter of the dest */
99976 ip_vs_dest_hold(dest);
99977
99978- conn_flags = atomic_read(&dest->conn_flags);
99979+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
99980 if (cp->protocol != IPPROTO_UDP)
99981 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
99982 flags = cp->flags;
99983@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
99984
99985 cp->control = NULL;
99986 atomic_set(&cp->n_control, 0);
99987- atomic_set(&cp->in_pkts, 0);
99988+ atomic_set_unchecked(&cp->in_pkts, 0);
99989
99990 cp->packet_xmit = NULL;
99991 cp->app = NULL;
99992@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
99993
99994 /* Don't drop the entry if its number of incoming packets is not
99995 located in [0, 8] */
99996- i = atomic_read(&cp->in_pkts);
99997+ i = atomic_read_unchecked(&cp->in_pkts);
99998 if (i > 8 || i < 0) return 0;
99999
100000 if (!todrop_rate[i]) return 0;
100001diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
100002index 4f26ee4..6a9d7c3 100644
100003--- a/net/netfilter/ipvs/ip_vs_core.c
100004+++ b/net/netfilter/ipvs/ip_vs_core.c
100005@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100006 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100007 /* do not touch skb anymore */
100008
100009- atomic_inc(&cp->in_pkts);
100010+ atomic_inc_unchecked(&cp->in_pkts);
100011 ip_vs_conn_put(cp);
100012 return ret;
100013 }
100014@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100015 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100016 pkts = sysctl_sync_threshold(ipvs);
100017 else
100018- pkts = atomic_add_return(1, &cp->in_pkts);
100019+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100020
100021 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100022 ip_vs_sync_conn(net, cp, pkts);
100023diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100024index 35be035..50f8834 100644
100025--- a/net/netfilter/ipvs/ip_vs_ctl.c
100026+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100027@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100028 */
100029 ip_vs_rs_hash(ipvs, dest);
100030 }
100031- atomic_set(&dest->conn_flags, conn_flags);
100032+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100033
100034 /* bind the service */
100035 old_svc = rcu_dereference_protected(dest->svc, 1);
100036@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100037 * align with netns init in ip_vs_control_net_init()
100038 */
100039
100040-static struct ctl_table vs_vars[] = {
100041+static ctl_table_no_const vs_vars[] __read_only = {
100042 {
100043 .procname = "amemthresh",
100044 .maxlen = sizeof(int),
100045@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100046 " %-7s %-6d %-10d %-10d\n",
100047 &dest->addr.in6,
100048 ntohs(dest->port),
100049- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100050+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100051 atomic_read(&dest->weight),
100052 atomic_read(&dest->activeconns),
100053 atomic_read(&dest->inactconns));
100054@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100055 "%-7s %-6d %-10d %-10d\n",
100056 ntohl(dest->addr.ip),
100057 ntohs(dest->port),
100058- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100059+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100060 atomic_read(&dest->weight),
100061 atomic_read(&dest->activeconns),
100062 atomic_read(&dest->inactconns));
100063@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100064
100065 entry.addr = dest->addr.ip;
100066 entry.port = dest->port;
100067- entry.conn_flags = atomic_read(&dest->conn_flags);
100068+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100069 entry.weight = atomic_read(&dest->weight);
100070 entry.u_threshold = dest->u_threshold;
100071 entry.l_threshold = dest->l_threshold;
100072@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100073 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100074 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100075 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100076- (atomic_read(&dest->conn_flags) &
100077+ (atomic_read_unchecked(&dest->conn_flags) &
100078 IP_VS_CONN_F_FWD_MASK)) ||
100079 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100080 atomic_read(&dest->weight)) ||
100081@@ -3580,7 +3580,7 @@ out:
100082 }
100083
100084
100085-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100086+static const struct genl_ops ip_vs_genl_ops[] = {
100087 {
100088 .cmd = IPVS_CMD_NEW_SERVICE,
100089 .flags = GENL_ADMIN_PERM,
100090@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100091 {
100092 int idx;
100093 struct netns_ipvs *ipvs = net_ipvs(net);
100094- struct ctl_table *tbl;
100095+ ctl_table_no_const *tbl;
100096
100097 atomic_set(&ipvs->dropentry, 0);
100098 spin_lock_init(&ipvs->dropentry_lock);
100099diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100100index ca056a3..9cf01ef 100644
100101--- a/net/netfilter/ipvs/ip_vs_lblc.c
100102+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100103@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100104 * IPVS LBLC sysctl table
100105 */
100106 #ifdef CONFIG_SYSCTL
100107-static struct ctl_table vs_vars_table[] = {
100108+static ctl_table_no_const vs_vars_table[] __read_only = {
100109 {
100110 .procname = "lblc_expiration",
100111 .data = NULL,
100112diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100113index 3f21a2f..a112e85 100644
100114--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100115+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100116@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100117 * IPVS LBLCR sysctl table
100118 */
100119
100120-static struct ctl_table vs_vars_table[] = {
100121+static ctl_table_no_const vs_vars_table[] __read_only = {
100122 {
100123 .procname = "lblcr_expiration",
100124 .data = NULL,
100125diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100126index f63c238..1b87f8a 100644
100127--- a/net/netfilter/ipvs/ip_vs_sync.c
100128+++ b/net/netfilter/ipvs/ip_vs_sync.c
100129@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100130 cp = cp->control;
100131 if (cp) {
100132 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100133- pkts = atomic_add_return(1, &cp->in_pkts);
100134+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100135 else
100136 pkts = sysctl_sync_threshold(ipvs);
100137 ip_vs_sync_conn(net, cp->control, pkts);
100138@@ -771,7 +771,7 @@ control:
100139 if (!cp)
100140 return;
100141 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100142- pkts = atomic_add_return(1, &cp->in_pkts);
100143+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100144 else
100145 pkts = sysctl_sync_threshold(ipvs);
100146 goto sloop;
100147@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100148
100149 if (opt)
100150 memcpy(&cp->in_seq, opt, sizeof(*opt));
100151- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100152+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100153 cp->state = state;
100154 cp->old_state = cp->state;
100155 /*
100156diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100157index c47444e..b0961c6 100644
100158--- a/net/netfilter/ipvs/ip_vs_xmit.c
100159+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100160@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100161 else
100162 rc = NF_ACCEPT;
100163 /* do not touch skb anymore */
100164- atomic_inc(&cp->in_pkts);
100165+ atomic_inc_unchecked(&cp->in_pkts);
100166 goto out;
100167 }
100168
100169@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100170 else
100171 rc = NF_ACCEPT;
100172 /* do not touch skb anymore */
100173- atomic_inc(&cp->in_pkts);
100174+ atomic_inc_unchecked(&cp->in_pkts);
100175 goto out;
100176 }
100177
100178diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100179index a4b5e2a..13b1de3 100644
100180--- a/net/netfilter/nf_conntrack_acct.c
100181+++ b/net/netfilter/nf_conntrack_acct.c
100182@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100183 #ifdef CONFIG_SYSCTL
100184 static int nf_conntrack_acct_init_sysctl(struct net *net)
100185 {
100186- struct ctl_table *table;
100187+ ctl_table_no_const *table;
100188
100189 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100190 GFP_KERNEL);
100191diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100192index 43549eb..0bbeace 100644
100193--- a/net/netfilter/nf_conntrack_core.c
100194+++ b/net/netfilter/nf_conntrack_core.c
100195@@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
100196 #define DYING_NULLS_VAL ((1<<30)+1)
100197 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100198
100199+#ifdef CONFIG_GRKERNSEC_HIDESYM
100200+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100201+#endif
100202+
100203 int nf_conntrack_init_net(struct net *net)
100204 {
100205 int ret;
100206@@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
100207 goto err_stat;
100208 }
100209
100210+#ifdef CONFIG_GRKERNSEC_HIDESYM
100211+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100212+#else
100213 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100214+#endif
100215 if (!net->ct.slabname) {
100216 ret = -ENOMEM;
100217 goto err_slabname;
100218diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100219index 1df1761..ce8b88a 100644
100220--- a/net/netfilter/nf_conntrack_ecache.c
100221+++ b/net/netfilter/nf_conntrack_ecache.c
100222@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100223 #ifdef CONFIG_SYSCTL
100224 static int nf_conntrack_event_init_sysctl(struct net *net)
100225 {
100226- struct ctl_table *table;
100227+ ctl_table_no_const *table;
100228
100229 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100230 GFP_KERNEL);
100231diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100232index 974a2a4..52cc6ff 100644
100233--- a/net/netfilter/nf_conntrack_helper.c
100234+++ b/net/netfilter/nf_conntrack_helper.c
100235@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100236
100237 static int nf_conntrack_helper_init_sysctl(struct net *net)
100238 {
100239- struct ctl_table *table;
100240+ ctl_table_no_const *table;
100241
100242 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100243 GFP_KERNEL);
100244diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100245index ce30041..3861b5d 100644
100246--- a/net/netfilter/nf_conntrack_proto.c
100247+++ b/net/netfilter/nf_conntrack_proto.c
100248@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100249
100250 static void
100251 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100252- struct ctl_table **table,
100253+ ctl_table_no_const **table,
100254 unsigned int users)
100255 {
100256 if (users > 0)
100257diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100258index a99b6c3..cb372f9 100644
100259--- a/net/netfilter/nf_conntrack_proto_dccp.c
100260+++ b/net/netfilter/nf_conntrack_proto_dccp.c
100261@@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100262 const char *msg;
100263 u_int8_t state;
100264
100265- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100266+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100267 BUG_ON(dh == NULL);
100268
100269 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
100270@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100271 out_invalid:
100272 if (LOG_INVALID(net, IPPROTO_DCCP))
100273 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100274- NULL, msg);
100275+ NULL, "%s", msg);
100276 return false;
100277 }
100278
100279@@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
100280 u_int8_t type, old_state, new_state;
100281 enum ct_dccp_roles role;
100282
100283- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100284+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100285 BUG_ON(dh == NULL);
100286 type = dh->dccph_type;
100287
100288@@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100289 unsigned int cscov;
100290 const char *msg;
100291
100292- dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
100293+ dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
100294 if (dh == NULL) {
100295 msg = "nf_ct_dccp: short packet ";
100296 goto out_invalid;
100297@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100298
100299 out_invalid:
100300 if (LOG_INVALID(net, IPPROTO_DCCP))
100301- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100302+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100303 return -NF_ACCEPT;
100304 }
100305
100306diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100307index f641751..d3c5b51 100644
100308--- a/net/netfilter/nf_conntrack_standalone.c
100309+++ b/net/netfilter/nf_conntrack_standalone.c
100310@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100311
100312 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100313 {
100314- struct ctl_table *table;
100315+ ctl_table_no_const *table;
100316
100317 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100318 GFP_KERNEL);
100319diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100320index 7a394df..bd91a8a 100644
100321--- a/net/netfilter/nf_conntrack_timestamp.c
100322+++ b/net/netfilter/nf_conntrack_timestamp.c
100323@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100324 #ifdef CONFIG_SYSCTL
100325 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100326 {
100327- struct ctl_table *table;
100328+ ctl_table_no_const *table;
100329
100330 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100331 GFP_KERNEL);
100332diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100333index 85296d4..8becdec 100644
100334--- a/net/netfilter/nf_log.c
100335+++ b/net/netfilter/nf_log.c
100336@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100337
100338 #ifdef CONFIG_SYSCTL
100339 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100340-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100341+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100342
100343 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100344 void __user *buffer, size_t *lenp, loff_t *ppos)
100345@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100346 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100347 mutex_unlock(&nf_log_mutex);
100348 } else {
100349+ ctl_table_no_const nf_log_table = *table;
100350+
100351 mutex_lock(&nf_log_mutex);
100352 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100353 lockdep_is_held(&nf_log_mutex));
100354 if (!logger)
100355- table->data = "NONE";
100356+ nf_log_table.data = "NONE";
100357 else
100358- table->data = logger->name;
100359- r = proc_dostring(table, write, buffer, lenp, ppos);
100360+ nf_log_table.data = logger->name;
100361+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100362 mutex_unlock(&nf_log_mutex);
100363 }
100364
100365diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100366index f042ae5..30ea486 100644
100367--- a/net/netfilter/nf_sockopt.c
100368+++ b/net/netfilter/nf_sockopt.c
100369@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100370 }
100371 }
100372
100373- list_add(&reg->list, &nf_sockopts);
100374+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100375 out:
100376 mutex_unlock(&nf_sockopt_mutex);
100377 return ret;
100378@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100379 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100380 {
100381 mutex_lock(&nf_sockopt_mutex);
100382- list_del(&reg->list);
100383+ pax_list_del((struct list_head *)&reg->list);
100384 mutex_unlock(&nf_sockopt_mutex);
100385 }
100386 EXPORT_SYMBOL(nf_unregister_sockopt);
100387diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100388index a155d19..726b0f2 100644
100389--- a/net/netfilter/nfnetlink_log.c
100390+++ b/net/netfilter/nfnetlink_log.c
100391@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100392 struct nfnl_log_net {
100393 spinlock_t instances_lock;
100394 struct hlist_head instance_table[INSTANCE_BUCKETS];
100395- atomic_t global_seq;
100396+ atomic_unchecked_t global_seq;
100397 };
100398
100399 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100400@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100401 /* global sequence number */
100402 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100403 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100404- htonl(atomic_inc_return(&log->global_seq))))
100405+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
100406 goto nla_put_failure;
100407
100408 if (data_len) {
100409diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100410index da0c1f4..f79737a 100644
100411--- a/net/netfilter/nft_compat.c
100412+++ b/net/netfilter/nft_compat.c
100413@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100414 /* We want to reuse existing compat_to_user */
100415 old_fs = get_fs();
100416 set_fs(KERNEL_DS);
100417- t->compat_to_user(out, in);
100418+ t->compat_to_user((void __force_user *)out, in);
100419 set_fs(old_fs);
100420 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100421 kfree(out);
100422@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100423 /* We want to reuse existing compat_to_user */
100424 old_fs = get_fs();
100425 set_fs(KERNEL_DS);
100426- m->compat_to_user(out, in);
100427+ m->compat_to_user((void __force_user *)out, in);
100428 set_fs(old_fs);
100429 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100430 kfree(out);
100431diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100432new file mode 100644
100433index 0000000..c566332
100434--- /dev/null
100435+++ b/net/netfilter/xt_gradm.c
100436@@ -0,0 +1,51 @@
100437+/*
100438+ * gradm match for netfilter
100439