]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-3.0-3.13.10-201404141717.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.10-201404141717.patch
CommitLineData
9de2bd41
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 982ade0..f9cdd67 100644
291--- a/Makefile
292+++ b/Makefile
293@@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297-HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298-HOSTCXXFLAGS = -O2
299+HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300+HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301+HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305@@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309+ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310+ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311+ quiet=silent_
312+endif
313+else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317+endif
318
319 export quiet Q KBUILD_VERBOSE
320
321@@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325-PHONY += scripts_basic
326-scripts_basic:
327+PHONY += scripts_basic gcc-plugins
328+scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332@@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336+ifndef DISABLE_PAX_PLUGINS
337+ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339+else
340+PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341+endif
342+ifneq ($(PLUGINCC),)
343+ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344+CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345+endif
346+ifdef CONFIG_PAX_MEMORY_STACKLEAK
347+STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348+STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349+endif
350+ifdef CONFIG_KALLOCSTAT_PLUGIN
351+KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352+endif
353+ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354+KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355+KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356+KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357+endif
358+ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359+RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360+ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361+RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362+endif
363+endif
364+ifdef CONFIG_CHECKER_PLUGIN
365+ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366+CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367+endif
368+endif
369+COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370+ifdef CONFIG_PAX_SIZE_OVERFLOW
371+SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372+endif
373+ifdef CONFIG_PAX_LATENT_ENTROPY
374+LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375+endif
376+ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377+STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378+endif
379+GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380+GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381+GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382+GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383+GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384+export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
385+ifeq ($(KBUILD_EXTMOD),)
386+gcc-plugins:
387+ $(Q)$(MAKE) $(build)=tools/gcc
388+else
389+gcc-plugins: ;
390+endif
391+else
392+gcc-plugins:
393+ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394+ $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
395+else
396+ $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397+endif
398+ $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399+endif
400+endif
401+
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405@@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409-KBUILD_AFLAGS += -gdwarf-2
410+KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414@@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418-core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419+core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423@@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428+$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432@@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436-$(vmlinux-dirs): prepare scripts
437+$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441@@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445+prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446+prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451+prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455@@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464@@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468-modules_prepare: prepare scripts
469+modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473@@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477- signing_key.x509.signer
478+ signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479+ tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483@@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487+ -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491@@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495+modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496+modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500@@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504-%.s: %.c prepare scripts FORCE
505+%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506+%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507+%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511-%.o: %.c prepare scripts FORCE
512+%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513+%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514+%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518-%.s: %.S prepare scripts FORCE
519+%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521-%.o: %.S prepare scripts FORCE
522+%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526@@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530-%/: prepare scripts FORCE
531+%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532+%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533+%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537-%.ko: prepare scripts FORCE
538+%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539+%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540+%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545index 78b03ef..da28a51 100644
546--- a/arch/alpha/include/asm/atomic.h
547+++ b/arch/alpha/include/asm/atomic.h
548@@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552+#define atomic64_read_unchecked(v) atomic64_read(v)
553+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557+#define atomic64_inc_unchecked(v) atomic64_inc(v)
558+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559+#define atomic64_dec_unchecked(v) atomic64_dec(v)
560+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561+
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566index ad368a9..fbe0f25 100644
567--- a/arch/alpha/include/asm/cache.h
568+++ b/arch/alpha/include/asm/cache.h
569@@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573+#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577-# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583-# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592index 968d999..d36b2df 100644
593--- a/arch/alpha/include/asm/elf.h
594+++ b/arch/alpha/include/asm/elf.h
595@@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599+#ifdef CONFIG_PAX_ASLR
600+#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601+
602+#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603+#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604+#endif
605+
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610index aab14a0..b4fa3e7 100644
611--- a/arch/alpha/include/asm/pgalloc.h
612+++ b/arch/alpha/include/asm/pgalloc.h
613@@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617+static inline void
618+pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619+{
620+ pgd_populate(mm, pgd, pmd);
621+}
622+
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627index d8f9b7e..f6222fa 100644
628--- a/arch/alpha/include/asm/pgtable.h
629+++ b/arch/alpha/include/asm/pgtable.h
630@@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634+
635+#ifdef CONFIG_PAX_PAGEEXEC
636+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639+#else
640+# define PAGE_SHARED_NOEXEC PAGE_SHARED
641+# define PAGE_COPY_NOEXEC PAGE_COPY
642+# define PAGE_READONLY_NOEXEC PAGE_READONLY
643+#endif
644+
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649index 2fd00b7..cfd5069 100644
650--- a/arch/alpha/kernel/module.c
651+++ b/arch/alpha/kernel/module.c
652@@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656- gp = (u64)me->module_core + me->core_size - 0x8000;
657+ gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662index 1402fcc..0b1abd2 100644
663--- a/arch/alpha/kernel/osf_sys.c
664+++ b/arch/alpha/kernel/osf_sys.c
665@@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669-arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670- unsigned long limit)
671+arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672+ unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679@@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683+ info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687@@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691+#ifdef CONFIG_PAX_RANDMMAP
692+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693+#endif
694+
695 if (addr) {
696- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703- addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704- len, limit);
705+ addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706+
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711- addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712+ addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717index 98838a0..b304fb4 100644
718--- a/arch/alpha/mm/fault.c
719+++ b/arch/alpha/mm/fault.c
720@@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724+#ifdef CONFIG_PAX_PAGEEXEC
725+/*
726+ * PaX: decide what to do with offenders (regs->pc = fault address)
727+ *
728+ * returns 1 when task should be killed
729+ * 2 when patched PLT trampoline was detected
730+ * 3 when unpatched PLT trampoline was detected
731+ */
732+static int pax_handle_fetch_fault(struct pt_regs *regs)
733+{
734+
735+#ifdef CONFIG_PAX_EMUPLT
736+ int err;
737+
738+ do { /* PaX: patched PLT emulation #1 */
739+ unsigned int ldah, ldq, jmp;
740+
741+ err = get_user(ldah, (unsigned int *)regs->pc);
742+ err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743+ err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744+
745+ if (err)
746+ break;
747+
748+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749+ (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750+ jmp == 0x6BFB0000U)
751+ {
752+ unsigned long r27, addr;
753+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754+ unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755+
756+ addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757+ err = get_user(r27, (unsigned long *)addr);
758+ if (err)
759+ break;
760+
761+ regs->r27 = r27;
762+ regs->pc = r27;
763+ return 2;
764+ }
765+ } while (0);
766+
767+ do { /* PaX: patched PLT emulation #2 */
768+ unsigned int ldah, lda, br;
769+
770+ err = get_user(ldah, (unsigned int *)regs->pc);
771+ err |= get_user(lda, (unsigned int *)(regs->pc+4));
772+ err |= get_user(br, (unsigned int *)(regs->pc+8));
773+
774+ if (err)
775+ break;
776+
777+ if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778+ (lda & 0xFFFF0000U) == 0xA77B0000U &&
779+ (br & 0xFFE00000U) == 0xC3E00000U)
780+ {
781+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782+ unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783+ unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784+
785+ regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786+ regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787+ return 2;
788+ }
789+ } while (0);
790+
791+ do { /* PaX: unpatched PLT emulation */
792+ unsigned int br;
793+
794+ err = get_user(br, (unsigned int *)regs->pc);
795+
796+ if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797+ unsigned int br2, ldq, nop, jmp;
798+ unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799+
800+ addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801+ err = get_user(br2, (unsigned int *)addr);
802+ err |= get_user(ldq, (unsigned int *)(addr+4));
803+ err |= get_user(nop, (unsigned int *)(addr+8));
804+ err |= get_user(jmp, (unsigned int *)(addr+12));
805+ err |= get_user(resolver, (unsigned long *)(addr+16));
806+
807+ if (err)
808+ break;
809+
810+ if (br2 == 0xC3600000U &&
811+ ldq == 0xA77B000CU &&
812+ nop == 0x47FF041FU &&
813+ jmp == 0x6B7B0000U)
814+ {
815+ regs->r28 = regs->pc+4;
816+ regs->r27 = addr+16;
817+ regs->pc = resolver;
818+ return 3;
819+ }
820+ }
821+ } while (0);
822+#endif
823+
824+ return 1;
825+}
826+
827+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828+{
829+ unsigned long i;
830+
831+ printk(KERN_ERR "PAX: bytes at PC: ");
832+ for (i = 0; i < 5; i++) {
833+ unsigned int c;
834+ if (get_user(c, (unsigned int *)pc+i))
835+ printk(KERN_CONT "???????? ");
836+ else
837+ printk(KERN_CONT "%08x ", c);
838+ }
839+ printk("\n");
840+}
841+#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845@@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849- if (!(vma->vm_flags & VM_EXEC))
850+ if (!(vma->vm_flags & VM_EXEC)) {
851+
852+#ifdef CONFIG_PAX_PAGEEXEC
853+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854+ goto bad_area;
855+
856+ up_read(&mm->mmap_sem);
857+ switch (pax_handle_fetch_fault(regs)) {
858+
859+#ifdef CONFIG_PAX_EMUPLT
860+ case 2:
861+ case 3:
862+ return;
863+#endif
864+
865+ }
866+ pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867+ do_group_exit(SIGKILL);
868+#else
869 goto bad_area;
870+#endif
871+
872+ }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877index 47085a0..f975a53 100644
878--- a/arch/arm/Kconfig
879+++ b/arch/arm/Kconfig
880@@ -1830,7 +1830,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884- depends on MMU
885+ depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889@@ -2102,6 +2102,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893+ depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898index 62d2cb5..09d45e3 100644
899--- a/arch/arm/include/asm/atomic.h
900+++ b/arch/arm/include/asm/atomic.h
901@@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905+#ifdef CONFIG_GENERIC_ATOMIC64
906+#include <asm-generic/atomic64.h>
907+#endif
908+
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913+#define _ASM_EXTABLE(from, to) \
914+" .pushsection __ex_table,\"a\"\n"\
915+" .align 3\n" \
916+" .long " #from ", " #to"\n" \
917+" .popsection"
918+
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926+{
927+ return v->counter;
928+}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931+{
932+ v->counter = i;
933+}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937@@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941+"1: ldrex %1, [%3]\n"
942+" adds %0, %1, %4\n"
943+
944+#ifdef CONFIG_PAX_REFCOUNT
945+" bvc 3f\n"
946+"2: bkpt 0xf103\n"
947+"3:\n"
948+#endif
949+
950+" strex %1, %0, [%3]\n"
951+" teq %1, #0\n"
952+" bne 1b"
953+
954+#ifdef CONFIG_PAX_REFCOUNT
955+"\n4:\n"
956+ _ASM_EXTABLE(2b, 4b)
957+#endif
958+
959+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960+ : "r" (&v->counter), "Ir" (i)
961+ : "cc");
962+}
963+
964+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965+{
966+ unsigned long tmp;
967+ int result;
968+
969+ prefetchw(&v->counter);
970+ __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974@@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978+"1: ldrex %1, [%3]\n"
979+" adds %0, %1, %4\n"
980+
981+#ifdef CONFIG_PAX_REFCOUNT
982+" bvc 3f\n"
983+" mov %0, %1\n"
984+"2: bkpt 0xf103\n"
985+"3:\n"
986+#endif
987+
988+" strex %1, %0, [%3]\n"
989+" teq %1, #0\n"
990+" bne 1b"
991+
992+#ifdef CONFIG_PAX_REFCOUNT
993+"\n4:\n"
994+ _ASM_EXTABLE(2b, 4b)
995+#endif
996+
997+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998+ : "r" (&v->counter), "Ir" (i)
999+ : "cc");
1000+
1001+ smp_mb();
1002+
1003+ return result;
1004+}
1005+
1006+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007+{
1008+ unsigned long tmp;
1009+ int result;
1010+
1011+ smp_mb();
1012+
1013+ __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017@@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021+"1: ldrex %1, [%3]\n"
1022+" subs %0, %1, %4\n"
1023+
1024+#ifdef CONFIG_PAX_REFCOUNT
1025+" bvc 3f\n"
1026+"2: bkpt 0xf103\n"
1027+"3:\n"
1028+#endif
1029+
1030+" strex %1, %0, [%3]\n"
1031+" teq %1, #0\n"
1032+" bne 1b"
1033+
1034+#ifdef CONFIG_PAX_REFCOUNT
1035+"\n4:\n"
1036+ _ASM_EXTABLE(2b, 4b)
1037+#endif
1038+
1039+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040+ : "r" (&v->counter), "Ir" (i)
1041+ : "cc");
1042+}
1043+
1044+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045+{
1046+ unsigned long tmp;
1047+ int result;
1048+
1049+ prefetchw(&v->counter);
1050+ __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054@@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058-"1: ldrex %0, [%3]\n"
1059-" sub %0, %0, %4\n"
1060+"1: ldrex %1, [%3]\n"
1061+" subs %0, %1, %4\n"
1062+
1063+#ifdef CONFIG_PAX_REFCOUNT
1064+" bvc 3f\n"
1065+" mov %0, %1\n"
1066+"2: bkpt 0xf103\n"
1067+"3:\n"
1068+#endif
1069+
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073+
1074+#ifdef CONFIG_PAX_REFCOUNT
1075+"\n4:\n"
1076+ _ASM_EXTABLE(2b, 4b)
1077+#endif
1078+
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082@@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087+{
1088+ unsigned long oldval, res;
1089+
1090+ smp_mb();
1091+
1092+ do {
1093+ __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094+ "ldrex %1, [%3]\n"
1095+ "mov %0, #0\n"
1096+ "teq %1, %4\n"
1097+ "strexeq %0, %5, [%3]\n"
1098+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099+ : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100+ : "cc");
1101+ } while (res);
1102+
1103+ smp_mb();
1104+
1105+ return oldval;
1106+}
1107+
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111@@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115+
1116+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117+{
1118+ return atomic_add_return(i, v);
1119+}
1120+
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123+{
1124+ (void) atomic_add_return(i, v);
1125+}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129@@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134+{
1135+ (void) atomic_sub_return(i, v);
1136+}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140@@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145+{
1146+ return atomic_cmpxchg(v, old, new);
1147+}
1148+
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153+{
1154+ return xchg(&v->counter, new);
1155+}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159@@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164+{
1165+ atomic_add_unchecked(1, v);
1166+}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169+{
1170+ atomic_sub_unchecked(1, v);
1171+}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175+{
1176+ return atomic_add_return_unchecked(1, v) == 0;
1177+}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181+{
1182+ return atomic_add_return_unchecked(1, v);
1183+}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187@@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191+#ifdef CONFIG_PAX_REFCOUNT
1192+typedef struct {
1193+ long long counter;
1194+} atomic64_unchecked_t;
1195+#else
1196+typedef atomic64_t atomic64_unchecked_t;
1197+#endif
1198+
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202@@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207+{
1208+ long long result;
1209+
1210+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211+" ldrd %0, %H0, [%1]"
1212+ : "=&r" (result)
1213+ : "r" (&v->counter), "Qo" (v->counter)
1214+ );
1215+
1216+ return result;
1217+}
1218+
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222@@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226+
1227+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228+{
1229+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230+" strd %2, %H2, [%1]"
1231+ : "=Qo" (v->counter)
1232+ : "r" (&v->counter), "r" (i)
1233+ );
1234+}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238@@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242+static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243+{
1244+ long long result;
1245+
1246+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247+" ldrexd %0, %H0, [%1]"
1248+ : "=&r" (result)
1249+ : "r" (&v->counter), "Qo" (v->counter)
1250+ );
1251+
1252+ return result;
1253+}
1254+
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258@@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262+
1263+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264+{
1265+ long long tmp;
1266+
1267+ prefetchw(&v->counter);
1268+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269+"1: ldrexd %0, %H0, [%2]\n"
1270+" strexd %0, %3, %H3, [%2]\n"
1271+" teq %0, #0\n"
1272+" bne 1b"
1273+ : "=&r" (tmp), "=Qo" (v->counter)
1274+ : "r" (&v->counter), "r" (i)
1275+ : "cc");
1276+}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280@@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284+" adcs %R0, %R0, %R4\n"
1285+
1286+#ifdef CONFIG_PAX_REFCOUNT
1287+" bvc 3f\n"
1288+"2: bkpt 0xf103\n"
1289+"3:\n"
1290+#endif
1291+
1292+" strexd %1, %0, %H0, [%3]\n"
1293+" teq %1, #0\n"
1294+" bne 1b"
1295+
1296+#ifdef CONFIG_PAX_REFCOUNT
1297+"\n4:\n"
1298+ _ASM_EXTABLE(2b, 4b)
1299+#endif
1300+
1301+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302+ : "r" (&v->counter), "r" (i)
1303+ : "cc");
1304+}
1305+
1306+static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307+{
1308+ long long result;
1309+ unsigned long tmp;
1310+
1311+ prefetchw(&v->counter);
1312+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313+"1: ldrexd %0, %H0, [%3]\n"
1314+" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318@@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322+" adcs %R0, %R0, %R4\n"
1323+
1324+#ifdef CONFIG_PAX_REFCOUNT
1325+" bvc 3f\n"
1326+" mov %0, %1\n"
1327+" mov %H0, %H1\n"
1328+"2: bkpt 0xf103\n"
1329+"3:\n"
1330+#endif
1331+
1332+" strexd %1, %0, %H0, [%3]\n"
1333+" teq %1, #0\n"
1334+" bne 1b"
1335+
1336+#ifdef CONFIG_PAX_REFCOUNT
1337+"\n4:\n"
1338+ _ASM_EXTABLE(2b, 4b)
1339+#endif
1340+
1341+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342+ : "r" (&v->counter), "r" (i)
1343+ : "cc");
1344+
1345+ smp_mb();
1346+
1347+ return result;
1348+}
1349+
1350+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351+{
1352+ long long result;
1353+ unsigned long tmp;
1354+
1355+ smp_mb();
1356+
1357+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358+"1: ldrexd %0, %H0, [%3]\n"
1359+" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363@@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367+" sbcs %R0, %R0, %R4\n"
1368+
1369+#ifdef CONFIG_PAX_REFCOUNT
1370+" bvc 3f\n"
1371+"2: bkpt 0xf103\n"
1372+"3:\n"
1373+#endif
1374+
1375+" strexd %1, %0, %H0, [%3]\n"
1376+" teq %1, #0\n"
1377+" bne 1b"
1378+
1379+#ifdef CONFIG_PAX_REFCOUNT
1380+"\n4:\n"
1381+ _ASM_EXTABLE(2b, 4b)
1382+#endif
1383+
1384+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385+ : "r" (&v->counter), "r" (i)
1386+ : "cc");
1387+}
1388+
1389+static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390+{
1391+ long long result;
1392+ unsigned long tmp;
1393+
1394+ prefetchw(&v->counter);
1395+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396+"1: ldrexd %0, %H0, [%3]\n"
1397+" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401@@ -344,16 +691,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405-" sbc %R0, %R0, %R4\n"
1406+" sbcs %R0, %R0, %R4\n"
1407+
1408+#ifdef CONFIG_PAX_REFCOUNT
1409+" bvc 3f\n"
1410+" mov %0, %1\n"
1411+" mov %H0, %H1\n"
1412+"2: bkpt 0xf103\n"
1413+"3:\n"
1414+#endif
1415+
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419+
1420+#ifdef CONFIG_PAX_REFCOUNT
1421+"\n4:\n"
1422+ _ASM_EXTABLE(2b, 4b)
1423+#endif
1424+
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428
1429- smp_mb();
1430-
1431 return result;
1432 }
1433
1434@@ -382,6 +742,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 return oldval;
1436 }
1437
1438+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1439+ long long new)
1440+{
1441+ long long oldval;
1442+ unsigned long res;
1443+
1444+ smp_mb();
1445+
1446+ do {
1447+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1448+ "ldrexd %1, %H1, [%3]\n"
1449+ "mov %0, #0\n"
1450+ "teq %1, %4\n"
1451+ "teqeq %H1, %H4\n"
1452+ "strexdeq %0, %5, %H5, [%3]"
1453+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1454+ : "r" (&ptr->counter), "r" (old), "r" (new)
1455+ : "cc");
1456+ } while (res);
1457+
1458+ smp_mb();
1459+
1460+ return oldval;
1461+}
1462+
1463 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1464 {
1465 long long result;
1466@@ -406,20 +791,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1467 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1468 {
1469 long long result;
1470- unsigned long tmp;
1471+ u64 tmp;
1472
1473 smp_mb();
1474
1475 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1476-"1: ldrexd %0, %H0, [%3]\n"
1477-" subs %Q0, %Q0, #1\n"
1478-" sbc %R0, %R0, #0\n"
1479+"1: ldrexd %1, %H1, [%3]\n"
1480+" subs %Q0, %Q1, #1\n"
1481+" sbcs %R0, %R1, #0\n"
1482+
1483+#ifdef CONFIG_PAX_REFCOUNT
1484+" bvc 3f\n"
1485+" mov %Q0, %Q1\n"
1486+" mov %R0, %R1\n"
1487+"2: bkpt 0xf103\n"
1488+"3:\n"
1489+#endif
1490+
1491 " teq %R0, #0\n"
1492-" bmi 2f\n"
1493+" bmi 4f\n"
1494 " strexd %1, %0, %H0, [%3]\n"
1495 " teq %1, #0\n"
1496 " bne 1b\n"
1497-"2:"
1498+"4:\n"
1499+
1500+#ifdef CONFIG_PAX_REFCOUNT
1501+ _ASM_EXTABLE(2b, 4b)
1502+#endif
1503+
1504 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1505 : "r" (&v->counter)
1506 : "cc");
1507@@ -442,13 +841,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1508 " teq %0, %5\n"
1509 " teqeq %H0, %H5\n"
1510 " moveq %1, #0\n"
1511-" beq 2f\n"
1512+" beq 4f\n"
1513 " adds %Q0, %Q0, %Q6\n"
1514-" adc %R0, %R0, %R6\n"
1515+" adcs %R0, %R0, %R6\n"
1516+
1517+#ifdef CONFIG_PAX_REFCOUNT
1518+" bvc 3f\n"
1519+"2: bkpt 0xf103\n"
1520+"3:\n"
1521+#endif
1522+
1523 " strexd %2, %0, %H0, [%4]\n"
1524 " teq %2, #0\n"
1525 " bne 1b\n"
1526-"2:"
1527+"4:\n"
1528+
1529+#ifdef CONFIG_PAX_REFCOUNT
1530+ _ASM_EXTABLE(2b, 4b)
1531+#endif
1532+
1533 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1534 : "r" (&v->counter), "r" (u), "r" (a)
1535 : "cc");
1536@@ -461,10 +872,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1537
1538 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1539 #define atomic64_inc(v) atomic64_add(1LL, (v))
1540+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1541 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1542+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1544 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1545 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1546+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1547 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1548 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1549 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1550diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1551index 75fe66b..ba3dee4 100644
1552--- a/arch/arm/include/asm/cache.h
1553+++ b/arch/arm/include/asm/cache.h
1554@@ -4,8 +4,10 @@
1555 #ifndef __ASMARM_CACHE_H
1556 #define __ASMARM_CACHE_H
1557
1558+#include <linux/const.h>
1559+
1560 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1561-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1563
1564 /*
1565 * Memory returned by kmalloc() may be used for DMA, so we must make
1566@@ -24,5 +26,6 @@
1567 #endif
1568
1569 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1570+#define __read_only __attribute__ ((__section__(".data..read_only")))
1571
1572 #endif
1573diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1574index ab91ebb..2c2afeb 100644
1575--- a/arch/arm/include/asm/cacheflush.h
1576+++ b/arch/arm/include/asm/cacheflush.h
1577@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1578 void (*dma_unmap_area)(const void *, size_t, int);
1579
1580 void (*dma_flush_range)(const void *, const void *);
1581-};
1582+} __no_const;
1583
1584 /*
1585 * Select the calling method
1586diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1587index 6dcc164..b14d917 100644
1588--- a/arch/arm/include/asm/checksum.h
1589+++ b/arch/arm/include/asm/checksum.h
1590@@ -37,7 +37,19 @@ __wsum
1591 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1592
1593 __wsum
1594-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1595+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596+
1597+static inline __wsum
1598+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1599+{
1600+ __wsum ret;
1601+ pax_open_userland();
1602+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1603+ pax_close_userland();
1604+ return ret;
1605+}
1606+
1607+
1608
1609 /*
1610 * Fold a partial checksum without adding pseudo headers
1611diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1612index df2fbba..63fe3e1 100644
1613--- a/arch/arm/include/asm/cmpxchg.h
1614+++ b/arch/arm/include/asm/cmpxchg.h
1615@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1616
1617 #define xchg(ptr,x) \
1618 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1619+#define xchg_unchecked(ptr,x) \
1620+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1621
1622 #include <asm-generic/cmpxchg-local.h>
1623
1624diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1625index 6ddbe44..b5e38b1 100644
1626--- a/arch/arm/include/asm/domain.h
1627+++ b/arch/arm/include/asm/domain.h
1628@@ -48,18 +48,37 @@
1629 * Domain types
1630 */
1631 #define DOMAIN_NOACCESS 0
1632-#define DOMAIN_CLIENT 1
1633 #ifdef CONFIG_CPU_USE_DOMAINS
1634+#define DOMAIN_USERCLIENT 1
1635+#define DOMAIN_KERNELCLIENT 1
1636 #define DOMAIN_MANAGER 3
1637+#define DOMAIN_VECTORS DOMAIN_USER
1638 #else
1639+
1640+#ifdef CONFIG_PAX_KERNEXEC
1641 #define DOMAIN_MANAGER 1
1642+#define DOMAIN_KERNEXEC 3
1643+#else
1644+#define DOMAIN_MANAGER 1
1645+#endif
1646+
1647+#ifdef CONFIG_PAX_MEMORY_UDEREF
1648+#define DOMAIN_USERCLIENT 0
1649+#define DOMAIN_UDEREF 1
1650+#define DOMAIN_VECTORS DOMAIN_KERNEL
1651+#else
1652+#define DOMAIN_USERCLIENT 1
1653+#define DOMAIN_VECTORS DOMAIN_USER
1654+#endif
1655+#define DOMAIN_KERNELCLIENT 1
1656+
1657 #endif
1658
1659 #define domain_val(dom,type) ((type) << (2*(dom)))
1660
1661 #ifndef __ASSEMBLY__
1662
1663-#ifdef CONFIG_CPU_USE_DOMAINS
1664+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1665 static inline void set_domain(unsigned val)
1666 {
1667 asm volatile(
1668@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1669 isb();
1670 }
1671
1672-#define modify_domain(dom,type) \
1673- do { \
1674- struct thread_info *thread = current_thread_info(); \
1675- unsigned int domain = thread->cpu_domain; \
1676- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1677- thread->cpu_domain = domain | domain_val(dom, type); \
1678- set_domain(thread->cpu_domain); \
1679- } while (0)
1680-
1681+extern void modify_domain(unsigned int dom, unsigned int type);
1682 #else
1683 static inline void set_domain(unsigned val) { }
1684 static inline void modify_domain(unsigned dom, unsigned type) { }
1685diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1686index f4b46d3..abc9b2b 100644
1687--- a/arch/arm/include/asm/elf.h
1688+++ b/arch/arm/include/asm/elf.h
1689@@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1690 the loader. We need to make sure that it is out of the way of the program
1691 that it will "exec", and that there is sufficient room for the brk. */
1692
1693-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1694+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1695+
1696+#ifdef CONFIG_PAX_ASLR
1697+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1698+
1699+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1700+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701+#endif
1702
1703 /* When the program starts, a1 contains a pointer to a function to be
1704 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1705@@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1706 extern void elf_set_personality(const struct elf32_hdr *);
1707 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1708
1709-struct mm_struct;
1710-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1711-#define arch_randomize_brk arch_randomize_brk
1712-
1713 #ifdef CONFIG_MMU
1714 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1715 struct linux_binprm;
1716diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1717index de53547..52b9a28 100644
1718--- a/arch/arm/include/asm/fncpy.h
1719+++ b/arch/arm/include/asm/fncpy.h
1720@@ -81,7 +81,9 @@
1721 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1722 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1723 \
1724+ pax_open_kernel(); \
1725 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1726+ pax_close_kernel(); \
1727 flush_icache_range((unsigned long)(dest_buf), \
1728 (unsigned long)(dest_buf) + (size)); \
1729 \
1730diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1731index e42cf59..7b94b8f 100644
1732--- a/arch/arm/include/asm/futex.h
1733+++ b/arch/arm/include/asm/futex.h
1734@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1735 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1736 return -EFAULT;
1737
1738+ pax_open_userland();
1739+
1740 smp_mb();
1741 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1742 "1: ldrex %1, [%4]\n"
1743@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1744 : "cc", "memory");
1745 smp_mb();
1746
1747+ pax_close_userland();
1748+
1749 *uval = val;
1750 return ret;
1751 }
1752@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1753 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1754 return -EFAULT;
1755
1756+ pax_open_userland();
1757+
1758 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1759 "1: " TUSER(ldr) " %1, [%4]\n"
1760 " teq %1, %2\n"
1761@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1762 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1763 : "cc", "memory");
1764
1765+ pax_close_userland();
1766+
1767 *uval = val;
1768 return ret;
1769 }
1770@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1771 return -EFAULT;
1772
1773 pagefault_disable(); /* implies preempt_disable() */
1774+ pax_open_userland();
1775
1776 switch (op) {
1777 case FUTEX_OP_SET:
1778@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1779 ret = -ENOSYS;
1780 }
1781
1782+ pax_close_userland();
1783 pagefault_enable(); /* subsumes preempt_enable() */
1784
1785 if (!ret) {
1786diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1787index 83eb2f7..ed77159 100644
1788--- a/arch/arm/include/asm/kmap_types.h
1789+++ b/arch/arm/include/asm/kmap_types.h
1790@@ -4,6 +4,6 @@
1791 /*
1792 * This is the "bare minimum". AIO seems to require this.
1793 */
1794-#define KM_TYPE_NR 16
1795+#define KM_TYPE_NR 17
1796
1797 #endif
1798diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1799index 9e614a1..3302cca 100644
1800--- a/arch/arm/include/asm/mach/dma.h
1801+++ b/arch/arm/include/asm/mach/dma.h
1802@@ -22,7 +22,7 @@ struct dma_ops {
1803 int (*residue)(unsigned int, dma_t *); /* optional */
1804 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1805 const char *type;
1806-};
1807+} __do_const;
1808
1809 struct dma_struct {
1810 void *addr; /* single DMA address */
1811diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1812index 2fe141f..192dc01 100644
1813--- a/arch/arm/include/asm/mach/map.h
1814+++ b/arch/arm/include/asm/mach/map.h
1815@@ -27,13 +27,16 @@ struct map_desc {
1816 #define MT_MINICLEAN 6
1817 #define MT_LOW_VECTORS 7
1818 #define MT_HIGH_VECTORS 8
1819-#define MT_MEMORY 9
1820+#define MT_MEMORY_RWX 9
1821 #define MT_ROM 10
1822-#define MT_MEMORY_NONCACHED 11
1823+#define MT_MEMORY_NONCACHED_RX 11
1824 #define MT_MEMORY_DTCM 12
1825 #define MT_MEMORY_ITCM 13
1826 #define MT_MEMORY_SO 14
1827 #define MT_MEMORY_DMA_READY 15
1828+#define MT_MEMORY_RW 16
1829+#define MT_MEMORY_RX 17
1830+#define MT_MEMORY_NONCACHED_RW 18
1831
1832 #ifdef CONFIG_MMU
1833 extern void iotable_init(struct map_desc *, int);
1834diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1835index f94784f..9a09a4a 100644
1836--- a/arch/arm/include/asm/outercache.h
1837+++ b/arch/arm/include/asm/outercache.h
1838@@ -35,7 +35,7 @@ struct outer_cache_fns {
1839 #endif
1840 void (*set_debug)(unsigned long);
1841 void (*resume)(void);
1842-};
1843+} __no_const;
1844
1845 extern struct outer_cache_fns outer_cache;
1846
1847diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1848index 4355f0e..cd9168e 100644
1849--- a/arch/arm/include/asm/page.h
1850+++ b/arch/arm/include/asm/page.h
1851@@ -23,6 +23,7 @@
1852
1853 #else
1854
1855+#include <linux/compiler.h>
1856 #include <asm/glue.h>
1857
1858 /*
1859@@ -114,7 +115,7 @@ struct cpu_user_fns {
1860 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1861 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1862 unsigned long vaddr, struct vm_area_struct *vma);
1863-};
1864+} __no_const;
1865
1866 #ifdef MULTI_USER
1867 extern struct cpu_user_fns cpu_user;
1868diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1869index 78a7793..e3dc06c 100644
1870--- a/arch/arm/include/asm/pgalloc.h
1871+++ b/arch/arm/include/asm/pgalloc.h
1872@@ -17,6 +17,7 @@
1873 #include <asm/processor.h>
1874 #include <asm/cacheflush.h>
1875 #include <asm/tlbflush.h>
1876+#include <asm/system_info.h>
1877
1878 #define check_pgt_cache() do { } while (0)
1879
1880@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1881 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1882 }
1883
1884+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1885+{
1886+ pud_populate(mm, pud, pmd);
1887+}
1888+
1889 #else /* !CONFIG_ARM_LPAE */
1890
1891 /*
1892@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1893 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1894 #define pmd_free(mm, pmd) do { } while (0)
1895 #define pud_populate(mm,pmd,pte) BUG()
1896+#define pud_populate_kernel(mm,pmd,pte) BUG()
1897
1898 #endif /* CONFIG_ARM_LPAE */
1899
1900@@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1901 __free_page(pte);
1902 }
1903
1904+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1905+{
1906+#ifdef CONFIG_ARM_LPAE
1907+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1908+#else
1909+ if (addr & SECTION_SIZE)
1910+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1911+ else
1912+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1913+#endif
1914+ flush_pmd_entry(pmdp);
1915+}
1916+
1917 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1918 pmdval_t prot)
1919 {
1920@@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1921 static inline void
1922 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1923 {
1924- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1925+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1926 }
1927 #define pmd_pgtable(pmd) pmd_page(pmd)
1928
1929diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1930index 5cfba15..f415e1a 100644
1931--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1932+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1933@@ -20,12 +20,15 @@
1934 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1935 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1936 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1937+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1938 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1939 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1940 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1941+
1942 /*
1943 * - section
1944 */
1945+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1946 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1947 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1948 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1949@@ -37,6 +40,7 @@
1950 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1951 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1952 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1953+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1954
1955 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1956 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1957@@ -66,6 +70,7 @@
1958 * - extended small page/tiny page
1959 */
1960 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1961+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1962 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1963 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1964 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1965diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1966index 86a659a..70e0120 100644
1967--- a/arch/arm/include/asm/pgtable-2level.h
1968+++ b/arch/arm/include/asm/pgtable-2level.h
1969@@ -126,6 +126,9 @@
1970 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1971 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1972
1973+/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1974+#define L_PTE_PXN (_AT(pteval_t, 0))
1975+
1976 /*
1977 * These are the memory types, defined to be compatible with
1978 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1979diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1980index 626989f..9d67a33 100644
1981--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1982+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1983@@ -75,6 +75,7 @@
1984 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1985 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1986 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1987+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1988 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1989
1990 /*
1991diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1992index 1d15673..04d626a 100644
1993--- a/arch/arm/include/asm/pgtable-3level.h
1994+++ b/arch/arm/include/asm/pgtable-3level.h
1995@@ -82,6 +82,7 @@
1996 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1997 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1998 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1999+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2000 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2001 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2002 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2003@@ -95,6 +96,7 @@
2004 /*
2005 * To be used in assembly code with the upper page attributes.
2006 */
2007+#define L_PTE_PXN_HIGH (1 << (53 - 32))
2008 #define L_PTE_XN_HIGH (1 << (54 - 32))
2009 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2010
2011diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2012index 1571d12..b8a9b43 100644
2013--- a/arch/arm/include/asm/pgtable.h
2014+++ b/arch/arm/include/asm/pgtable.h
2015@@ -33,6 +33,9 @@
2016 #include <asm/pgtable-2level.h>
2017 #endif
2018
2019+#define ktla_ktva(addr) (addr)
2020+#define ktva_ktla(addr) (addr)
2021+
2022 /*
2023 * Just any arbitrary offset to the start of the vmalloc VM area: the
2024 * current 8MB value just means that there will be a 8MB "hole" after the
2025@@ -48,6 +51,9 @@
2026 #define LIBRARY_TEXT_START 0x0c000000
2027
2028 #ifndef __ASSEMBLY__
2029+extern pteval_t __supported_pte_mask;
2030+extern pmdval_t __supported_pmd_mask;
2031+
2032 extern void __pte_error(const char *file, int line, pte_t);
2033 extern void __pmd_error(const char *file, int line, pmd_t);
2034 extern void __pgd_error(const char *file, int line, pgd_t);
2035@@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2036 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2037 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2038
2039+#define __HAVE_ARCH_PAX_OPEN_KERNEL
2040+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2041+
2042+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2043+#include <asm/domain.h>
2044+#include <linux/thread_info.h>
2045+#include <linux/preempt.h>
2046+
2047+static inline int test_domain(int domain, int domaintype)
2048+{
2049+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2050+}
2051+#endif
2052+
2053+#ifdef CONFIG_PAX_KERNEXEC
2054+static inline unsigned long pax_open_kernel(void) {
2055+#ifdef CONFIG_ARM_LPAE
2056+ /* TODO */
2057+#else
2058+ preempt_disable();
2059+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2060+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2061+#endif
2062+ return 0;
2063+}
2064+
2065+static inline unsigned long pax_close_kernel(void) {
2066+#ifdef CONFIG_ARM_LPAE
2067+ /* TODO */
2068+#else
2069+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2070+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
2071+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2072+ preempt_enable_no_resched();
2073+#endif
2074+ return 0;
2075+}
2076+#else
2077+static inline unsigned long pax_open_kernel(void) { return 0; }
2078+static inline unsigned long pax_close_kernel(void) { return 0; }
2079+#endif
2080+
2081 /*
2082 * This is the lowest virtual address we can permit any user space
2083 * mapping to be mapped at. This is particularly important for
2084@@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2085 /*
2086 * The pgprot_* and protection_map entries will be fixed up in runtime
2087 * to include the cachable and bufferable bits based on memory policy,
2088- * as well as any architecture dependent bits like global/ASID and SMP
2089- * shared mapping bits.
2090+ * as well as any architecture dependent bits like global/ASID, PXN,
2091+ * and SMP shared mapping bits.
2092 */
2093 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2094
2095@@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2096 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2097 {
2098 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2099- L_PTE_NONE | L_PTE_VALID;
2100+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2101 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2102 return pte;
2103 }
2104diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2105index c4ae171..ea0c0c2 100644
2106--- a/arch/arm/include/asm/psci.h
2107+++ b/arch/arm/include/asm/psci.h
2108@@ -29,7 +29,7 @@ struct psci_operations {
2109 int (*cpu_off)(struct psci_power_state state);
2110 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2111 int (*migrate)(unsigned long cpuid);
2112-};
2113+} __no_const;
2114
2115 extern struct psci_operations psci_ops;
2116 extern struct smp_operations psci_smp_ops;
2117diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2118index 22a3b9b..7f214ee 100644
2119--- a/arch/arm/include/asm/smp.h
2120+++ b/arch/arm/include/asm/smp.h
2121@@ -112,7 +112,7 @@ struct smp_operations {
2122 int (*cpu_disable)(unsigned int cpu);
2123 #endif
2124 #endif
2125-};
2126+} __no_const;
2127
2128 /*
2129 * set platform specific SMP operations
2130diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2131index 71a06b2..8bb9ae1 100644
2132--- a/arch/arm/include/asm/thread_info.h
2133+++ b/arch/arm/include/asm/thread_info.h
2134@@ -88,9 +88,9 @@ struct thread_info {
2135 .flags = 0, \
2136 .preempt_count = INIT_PREEMPT_COUNT, \
2137 .addr_limit = KERNEL_DS, \
2138- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2139- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2140- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2141+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2142+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2143+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2144 .restart_block = { \
2145 .fn = do_no_restart_syscall, \
2146 }, \
2147@@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2148 #define TIF_SYSCALL_AUDIT 9
2149 #define TIF_SYSCALL_TRACEPOINT 10
2150 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2151-#define TIF_NOHZ 12 /* in adaptive nohz mode */
2152+/* within 8 bits of TIF_SYSCALL_TRACE
2153+ * to meet flexible second operand requirements
2154+ */
2155+#define TIF_GRSEC_SETXID 12
2156+#define TIF_NOHZ 13 /* in adaptive nohz mode */
2157 #define TIF_USING_IWMMXT 17
2158 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2159 #define TIF_RESTORE_SIGMASK 20
2160@@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2161 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2162 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2163 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2164+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2165
2166 /* Checks for any syscall work in entry-common.S */
2167 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2168- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2169+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2170
2171 /*
2172 * Change these and you break ASM code in entry-common.S
2173diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2174index 72abdc5..35acac1 100644
2175--- a/arch/arm/include/asm/uaccess.h
2176+++ b/arch/arm/include/asm/uaccess.h
2177@@ -18,6 +18,7 @@
2178 #include <asm/domain.h>
2179 #include <asm/unified.h>
2180 #include <asm/compiler.h>
2181+#include <asm/pgtable.h>
2182
2183 #if __LINUX_ARM_ARCH__ < 6
2184 #include <asm-generic/uaccess-unaligned.h>
2185@@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2186 static inline void set_fs(mm_segment_t fs)
2187 {
2188 current_thread_info()->addr_limit = fs;
2189- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2190+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2191 }
2192
2193 #define segment_eq(a,b) ((a) == (b))
2194
2195+#define __HAVE_ARCH_PAX_OPEN_USERLAND
2196+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2197+
2198+static inline void pax_open_userland(void)
2199+{
2200+
2201+#ifdef CONFIG_PAX_MEMORY_UDEREF
2202+ if (segment_eq(get_fs(), USER_DS)) {
2203+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2204+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2205+ }
2206+#endif
2207+
2208+}
2209+
2210+static inline void pax_close_userland(void)
2211+{
2212+
2213+#ifdef CONFIG_PAX_MEMORY_UDEREF
2214+ if (segment_eq(get_fs(), USER_DS)) {
2215+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2216+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2217+ }
2218+#endif
2219+
2220+}
2221+
2222 #define __addr_ok(addr) ({ \
2223 unsigned long flag; \
2224 __asm__("cmp %2, %0; movlo %0, #0" \
2225@@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2226
2227 #define get_user(x,p) \
2228 ({ \
2229+ int __e; \
2230 might_fault(); \
2231- __get_user_check(x,p); \
2232+ pax_open_userland(); \
2233+ __e = __get_user_check(x,p); \
2234+ pax_close_userland(); \
2235+ __e; \
2236 })
2237
2238 extern int __put_user_1(void *, unsigned int);
2239@@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2240
2241 #define put_user(x,p) \
2242 ({ \
2243+ int __e; \
2244 might_fault(); \
2245- __put_user_check(x,p); \
2246+ pax_open_userland(); \
2247+ __e = __put_user_check(x,p); \
2248+ pax_close_userland(); \
2249+ __e; \
2250 })
2251
2252 #else /* CONFIG_MMU */
2253@@ -220,6 +256,7 @@ static inline void set_fs(mm_segment_t fs)
2254
2255 #endif /* CONFIG_MMU */
2256
2257+#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2258 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2259
2260 #define user_addr_max() \
2261@@ -237,13 +274,17 @@ static inline void set_fs(mm_segment_t fs)
2262 #define __get_user(x,ptr) \
2263 ({ \
2264 long __gu_err = 0; \
2265+ pax_open_userland(); \
2266 __get_user_err((x),(ptr),__gu_err); \
2267+ pax_close_userland(); \
2268 __gu_err; \
2269 })
2270
2271 #define __get_user_error(x,ptr,err) \
2272 ({ \
2273+ pax_open_userland(); \
2274 __get_user_err((x),(ptr),err); \
2275+ pax_close_userland(); \
2276 (void) 0; \
2277 })
2278
2279@@ -319,13 +360,17 @@ do { \
2280 #define __put_user(x,ptr) \
2281 ({ \
2282 long __pu_err = 0; \
2283+ pax_open_userland(); \
2284 __put_user_err((x),(ptr),__pu_err); \
2285+ pax_close_userland(); \
2286 __pu_err; \
2287 })
2288
2289 #define __put_user_error(x,ptr,err) \
2290 ({ \
2291+ pax_open_userland(); \
2292 __put_user_err((x),(ptr),err); \
2293+ pax_close_userland(); \
2294 (void) 0; \
2295 })
2296
2297@@ -425,11 +470,44 @@ do { \
2298
2299
2300 #ifdef CONFIG_MMU
2301-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2302-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2303+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2304+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2305+
2306+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2307+{
2308+ unsigned long ret;
2309+
2310+ check_object_size(to, n, false);
2311+ pax_open_userland();
2312+ ret = ___copy_from_user(to, from, n);
2313+ pax_close_userland();
2314+ return ret;
2315+}
2316+
2317+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2318+{
2319+ unsigned long ret;
2320+
2321+ check_object_size(from, n, true);
2322+ pax_open_userland();
2323+ ret = ___copy_to_user(to, from, n);
2324+ pax_close_userland();
2325+ return ret;
2326+}
2327+
2328 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2329-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2330+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2331 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2332+
2333+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2334+{
2335+ unsigned long ret;
2336+ pax_open_userland();
2337+ ret = ___clear_user(addr, n);
2338+ pax_close_userland();
2339+ return ret;
2340+}
2341+
2342 #else
2343 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2344 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2345@@ -438,6 +516,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2346
2347 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2348 {
2349+ if ((long)n < 0)
2350+ return n;
2351+
2352 if (access_ok(VERIFY_READ, from, n))
2353 n = __copy_from_user(to, from, n);
2354 else /* security hole - plug it */
2355@@ -447,6 +528,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2356
2357 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2358 {
2359+ if ((long)n < 0)
2360+ return n;
2361+
2362 if (access_ok(VERIFY_WRITE, to, n))
2363 n = __copy_to_user(to, from, n);
2364 return n;
2365diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2366index 5af0ed1..cea83883 100644
2367--- a/arch/arm/include/uapi/asm/ptrace.h
2368+++ b/arch/arm/include/uapi/asm/ptrace.h
2369@@ -92,7 +92,7 @@
2370 * ARMv7 groups of PSR bits
2371 */
2372 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2373-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2374+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2375 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2376 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2377
2378diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2379index 1f031dd..d9b5e4a 100644
2380--- a/arch/arm/kernel/armksyms.c
2381+++ b/arch/arm/kernel/armksyms.c
2382@@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2383
2384 /* networking */
2385 EXPORT_SYMBOL(csum_partial);
2386-EXPORT_SYMBOL(csum_partial_copy_from_user);
2387+EXPORT_SYMBOL(__csum_partial_copy_from_user);
2388 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2389 EXPORT_SYMBOL(__csum_ipv6_magic);
2390
2391@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2392 #ifdef CONFIG_MMU
2393 EXPORT_SYMBOL(copy_page);
2394
2395-EXPORT_SYMBOL(__copy_from_user);
2396-EXPORT_SYMBOL(__copy_to_user);
2397-EXPORT_SYMBOL(__clear_user);
2398+EXPORT_SYMBOL(___copy_from_user);
2399+EXPORT_SYMBOL(___copy_to_user);
2400+EXPORT_SYMBOL(___clear_user);
2401
2402 EXPORT_SYMBOL(__get_user_1);
2403 EXPORT_SYMBOL(__get_user_2);
2404diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2405index b3fb8c9..59cfab2 100644
2406--- a/arch/arm/kernel/entry-armv.S
2407+++ b/arch/arm/kernel/entry-armv.S
2408@@ -47,6 +47,87 @@
2409 9997:
2410 .endm
2411
2412+ .macro pax_enter_kernel
2413+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2414+ @ make aligned space for saved DACR
2415+ sub sp, sp, #8
2416+ @ save regs
2417+ stmdb sp!, {r1, r2}
2418+ @ read DACR from cpu_domain into r1
2419+ mov r2, sp
2420+ @ assume 8K pages, since we have to split the immediate in two
2421+ bic r2, r2, #(0x1fc0)
2422+ bic r2, r2, #(0x3f)
2423+ ldr r1, [r2, #TI_CPU_DOMAIN]
2424+ @ store old DACR on stack
2425+ str r1, [sp, #8]
2426+#ifdef CONFIG_PAX_KERNEXEC
2427+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2428+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2429+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2430+#endif
2431+#ifdef CONFIG_PAX_MEMORY_UDEREF
2432+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2433+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2434+#endif
2435+ @ write r1 to current_thread_info()->cpu_domain
2436+ str r1, [r2, #TI_CPU_DOMAIN]
2437+ @ write r1 to DACR
2438+ mcr p15, 0, r1, c3, c0, 0
2439+ @ instruction sync
2440+ instr_sync
2441+ @ restore regs
2442+ ldmia sp!, {r1, r2}
2443+#endif
2444+ .endm
2445+
2446+ .macro pax_open_userland
2447+#ifdef CONFIG_PAX_MEMORY_UDEREF
2448+ @ save regs
2449+ stmdb sp!, {r0, r1}
2450+ @ read DACR from cpu_domain into r1
2451+ mov r0, sp
2452+ @ assume 8K pages, since we have to split the immediate in two
2453+ bic r0, r0, #(0x1fc0)
2454+ bic r0, r0, #(0x3f)
2455+ ldr r1, [r0, #TI_CPU_DOMAIN]
2456+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2457+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2458+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2459+ @ write r1 to current_thread_info()->cpu_domain
2460+ str r1, [r0, #TI_CPU_DOMAIN]
2461+ @ write r1 to DACR
2462+ mcr p15, 0, r1, c3, c0, 0
2463+ @ instruction sync
2464+ instr_sync
2465+ @ restore regs
2466+ ldmia sp!, {r0, r1}
2467+#endif
2468+ .endm
2469+
2470+ .macro pax_close_userland
2471+#ifdef CONFIG_PAX_MEMORY_UDEREF
2472+ @ save regs
2473+ stmdb sp!, {r0, r1}
2474+ @ read DACR from cpu_domain into r1
2475+ mov r0, sp
2476+ @ assume 8K pages, since we have to split the immediate in two
2477+ bic r0, r0, #(0x1fc0)
2478+ bic r0, r0, #(0x3f)
2479+ ldr r1, [r0, #TI_CPU_DOMAIN]
2480+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2481+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2482+ @ write r1 to current_thread_info()->cpu_domain
2483+ str r1, [r0, #TI_CPU_DOMAIN]
2484+ @ write r1 to DACR
2485+ mcr p15, 0, r1, c3, c0, 0
2486+ @ instruction sync
2487+ instr_sync
2488+ @ restore regs
2489+ ldmia sp!, {r0, r1}
2490+#endif
2491+ .endm
2492+
2493 .macro pabt_helper
2494 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2495 #ifdef MULTI_PABORT
2496@@ -89,11 +170,15 @@
2497 * Invalid mode handlers
2498 */
2499 .macro inv_entry, reason
2500+
2501+ pax_enter_kernel
2502+
2503 sub sp, sp, #S_FRAME_SIZE
2504 ARM( stmib sp, {r1 - lr} )
2505 THUMB( stmia sp, {r0 - r12} )
2506 THUMB( str sp, [sp, #S_SP] )
2507 THUMB( str lr, [sp, #S_LR] )
2508+
2509 mov r1, #\reason
2510 .endm
2511
2512@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2513 .macro svc_entry, stack_hole=0
2514 UNWIND(.fnstart )
2515 UNWIND(.save {r0 - pc} )
2516+
2517+ pax_enter_kernel
2518+
2519 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2520+
2521 #ifdef CONFIG_THUMB2_KERNEL
2522 SPFIX( str r0, [sp] ) @ temporarily saved
2523 SPFIX( mov r0, sp )
2524@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2525 ldmia r0, {r3 - r5}
2526 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2527 mov r6, #-1 @ "" "" "" ""
2528+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2529+ @ offset sp by 8 as done in pax_enter_kernel
2530+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2531+#else
2532 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2533+#endif
2534 SPFIX( addeq r2, r2, #4 )
2535 str r3, [sp, #-4]! @ save the "real" r0 copied
2536 @ from the exception stack
2537@@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2538 .macro usr_entry
2539 UNWIND(.fnstart )
2540 UNWIND(.cantunwind ) @ don't unwind the user space
2541+
2542+ pax_enter_kernel_user
2543+
2544 sub sp, sp, #S_FRAME_SIZE
2545 ARM( stmib sp, {r1 - r12} )
2546 THUMB( stmia sp, {r0 - r12} )
2547@@ -416,7 +513,9 @@ __und_usr:
2548 tst r3, #PSR_T_BIT @ Thumb mode?
2549 bne __und_usr_thumb
2550 sub r4, r2, #4 @ ARM instr at LR - 4
2551+ pax_open_userland
2552 1: ldrt r0, [r4]
2553+ pax_close_userland
2554 ARM_BE8(rev r0, r0) @ little endian instruction
2555
2556 @ r0 = 32-bit ARM instruction which caused the exception
2557@@ -450,10 +549,14 @@ __und_usr_thumb:
2558 */
2559 .arch armv6t2
2560 #endif
2561+ pax_open_userland
2562 2: ldrht r5, [r4]
2563+ pax_close_userland
2564 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2565 blo __und_usr_fault_16 @ 16bit undefined instruction
2566+ pax_open_userland
2567 3: ldrht r0, [r2]
2568+ pax_close_userland
2569 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2570 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2571 orr r0, r0, r5, lsl #16
2572@@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2573 */
2574 .pushsection .fixup, "ax"
2575 .align 2
2576-4: mov pc, r9
2577+4: pax_close_userland
2578+ mov pc, r9
2579 .popsection
2580 .pushsection __ex_table,"a"
2581 .long 1b, 4b
2582@@ -692,7 +796,7 @@ ENTRY(__switch_to)
2583 THUMB( str lr, [ip], #4 )
2584 ldr r4, [r2, #TI_TP_VALUE]
2585 ldr r5, [r2, #TI_TP_VALUE + 4]
2586-#ifdef CONFIG_CPU_USE_DOMAINS
2587+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2588 ldr r6, [r2, #TI_CPU_DOMAIN]
2589 #endif
2590 switch_tls r1, r4, r5, r3, r7
2591@@ -701,7 +805,7 @@ ENTRY(__switch_to)
2592 ldr r8, =__stack_chk_guard
2593 ldr r7, [r7, #TSK_STACK_CANARY]
2594 #endif
2595-#ifdef CONFIG_CPU_USE_DOMAINS
2596+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2597 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2598 #endif
2599 mov r5, r0
2600diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2601index a2dcafd..1048b5a 100644
2602--- a/arch/arm/kernel/entry-common.S
2603+++ b/arch/arm/kernel/entry-common.S
2604@@ -10,18 +10,46 @@
2605
2606 #include <asm/unistd.h>
2607 #include <asm/ftrace.h>
2608+#include <asm/domain.h>
2609 #include <asm/unwind.h>
2610
2611+#include "entry-header.S"
2612+
2613 #ifdef CONFIG_NEED_RET_TO_USER
2614 #include <mach/entry-macro.S>
2615 #else
2616 .macro arch_ret_to_user, tmp1, tmp2
2617+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2618+ @ save regs
2619+ stmdb sp!, {r1, r2}
2620+ @ read DACR from cpu_domain into r1
2621+ mov r2, sp
2622+ @ assume 8K pages, since we have to split the immediate in two
2623+ bic r2, r2, #(0x1fc0)
2624+ bic r2, r2, #(0x3f)
2625+ ldr r1, [r2, #TI_CPU_DOMAIN]
2626+#ifdef CONFIG_PAX_KERNEXEC
2627+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2628+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2629+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2630+#endif
2631+#ifdef CONFIG_PAX_MEMORY_UDEREF
2632+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2633+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2634+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2635+#endif
2636+ @ write r1 to current_thread_info()->cpu_domain
2637+ str r1, [r2, #TI_CPU_DOMAIN]
2638+ @ write r1 to DACR
2639+ mcr p15, 0, r1, c3, c0, 0
2640+ @ instruction sync
2641+ instr_sync
2642+ @ restore regs
2643+ ldmia sp!, {r1, r2}
2644+#endif
2645 .endm
2646 #endif
2647
2648-#include "entry-header.S"
2649-
2650-
2651 .align 5
2652 /*
2653 * This is the fast syscall return path. We do as little as
2654@@ -411,6 +439,12 @@ ENTRY(vector_swi)
2655 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2656 #endif
2657
2658+ /*
2659+ * do this here to avoid a performance hit of wrapping the code above
2660+ * that directly dereferences userland to parse the SWI instruction
2661+ */
2662+ pax_enter_kernel_user
2663+
2664 adr tbl, sys_call_table @ load syscall table pointer
2665
2666 #if defined(CONFIG_OABI_COMPAT)
2667diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2668index 39f89fb..d612bd9 100644
2669--- a/arch/arm/kernel/entry-header.S
2670+++ b/arch/arm/kernel/entry-header.S
2671@@ -184,6 +184,60 @@
2672 msr cpsr_c, \rtemp @ switch back to the SVC mode
2673 .endm
2674
2675+ .macro pax_enter_kernel_user
2676+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2677+ @ save regs
2678+ stmdb sp!, {r0, r1}
2679+ @ read DACR from cpu_domain into r1
2680+ mov r0, sp
2681+ @ assume 8K pages, since we have to split the immediate in two
2682+ bic r0, r0, #(0x1fc0)
2683+ bic r0, r0, #(0x3f)
2684+ ldr r1, [r0, #TI_CPU_DOMAIN]
2685+#ifdef CONFIG_PAX_MEMORY_UDEREF
2686+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2687+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2688+#endif
2689+#ifdef CONFIG_PAX_KERNEXEC
2690+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2691+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2692+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2693+#endif
2694+ @ write r1 to current_thread_info()->cpu_domain
2695+ str r1, [r0, #TI_CPU_DOMAIN]
2696+ @ write r1 to DACR
2697+ mcr p15, 0, r1, c3, c0, 0
2698+ @ instruction sync
2699+ instr_sync
2700+ @ restore regs
2701+ ldmia sp!, {r0, r1}
2702+#endif
2703+ .endm
2704+
2705+ .macro pax_exit_kernel
2706+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2707+ @ save regs
2708+ stmdb sp!, {r0, r1}
2709+ @ read old DACR from stack into r1
2710+ ldr r1, [sp, #(8 + S_SP)]
2711+ sub r1, r1, #8
2712+ ldr r1, [r1]
2713+
2714+ @ write r1 to current_thread_info()->cpu_domain
2715+ mov r0, sp
2716+ @ assume 8K pages, since we have to split the immediate in two
2717+ bic r0, r0, #(0x1fc0)
2718+ bic r0, r0, #(0x3f)
2719+ str r1, [r0, #TI_CPU_DOMAIN]
2720+ @ write r1 to DACR
2721+ mcr p15, 0, r1, c3, c0, 0
2722+ @ instruction sync
2723+ instr_sync
2724+ @ restore regs
2725+ ldmia sp!, {r0, r1}
2726+#endif
2727+ .endm
2728+
2729 #ifndef CONFIG_THUMB2_KERNEL
2730 .macro svc_exit, rpsr, irq = 0
2731 .if \irq != 0
2732@@ -203,6 +257,9 @@
2733 blne trace_hardirqs_off
2734 #endif
2735 .endif
2736+
2737+ pax_exit_kernel
2738+
2739 msr spsr_cxsf, \rpsr
2740 #if defined(CONFIG_CPU_V6)
2741 ldr r0, [sp]
2742@@ -266,6 +323,9 @@
2743 blne trace_hardirqs_off
2744 #endif
2745 .endif
2746+
2747+ pax_exit_kernel
2748+
2749 ldr lr, [sp, #S_SP] @ top of the stack
2750 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2751 clrex @ clear the exclusive monitor
2752diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2753index 918875d..cd5fa27 100644
2754--- a/arch/arm/kernel/fiq.c
2755+++ b/arch/arm/kernel/fiq.c
2756@@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2757 void *base = vectors_page;
2758 unsigned offset = FIQ_OFFSET;
2759
2760+ pax_open_kernel();
2761 memcpy(base + offset, start, length);
2762+ pax_close_kernel();
2763+
2764 if (!cache_is_vipt_nonaliasing())
2765 flush_icache_range((unsigned long)base + offset, offset +
2766 length);
2767diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2768index 32f317e..710ae07 100644
2769--- a/arch/arm/kernel/head.S
2770+++ b/arch/arm/kernel/head.S
2771@@ -52,7 +52,9 @@
2772 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2773
2774 .macro pgtbl, rd, phys
2775- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2776+ mov \rd, #TEXT_OFFSET
2777+ sub \rd, #PG_DIR_SIZE
2778+ add \rd, \rd, \phys
2779 .endm
2780
2781 /*
2782@@ -436,7 +438,7 @@ __enable_mmu:
2783 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2784 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2785 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2786- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2787+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2788 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2789 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2790 #endif
2791diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2792index 45e4781..8eac93d 100644
2793--- a/arch/arm/kernel/module.c
2794+++ b/arch/arm/kernel/module.c
2795@@ -38,12 +38,39 @@
2796 #endif
2797
2798 #ifdef CONFIG_MMU
2799-void *module_alloc(unsigned long size)
2800+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2801 {
2802+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2803+ return NULL;
2804 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2805- GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2806+ GFP_KERNEL, prot, NUMA_NO_NODE,
2807 __builtin_return_address(0));
2808 }
2809+
2810+void *module_alloc(unsigned long size)
2811+{
2812+
2813+#ifdef CONFIG_PAX_KERNEXEC
2814+ return __module_alloc(size, PAGE_KERNEL);
2815+#else
2816+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2817+#endif
2818+
2819+}
2820+
2821+#ifdef CONFIG_PAX_KERNEXEC
2822+void module_free_exec(struct module *mod, void *module_region)
2823+{
2824+ module_free(mod, module_region);
2825+}
2826+EXPORT_SYMBOL(module_free_exec);
2827+
2828+void *module_alloc_exec(unsigned long size)
2829+{
2830+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2831+}
2832+EXPORT_SYMBOL(module_alloc_exec);
2833+#endif
2834 #endif
2835
2836 int
2837diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2838index 07314af..c46655c 100644
2839--- a/arch/arm/kernel/patch.c
2840+++ b/arch/arm/kernel/patch.c
2841@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2842 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2843 int size;
2844
2845+ pax_open_kernel();
2846 if (thumb2 && __opcode_is_thumb16(insn)) {
2847 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2848 size = sizeof(u16);
2849@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2850 *(u32 *)addr = insn;
2851 size = sizeof(u32);
2852 }
2853+ pax_close_kernel();
2854
2855 flush_icache_range((uintptr_t)(addr),
2856 (uintptr_t)(addr) + size);
2857diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2858index 92f7b15..7048500 100644
2859--- a/arch/arm/kernel/process.c
2860+++ b/arch/arm/kernel/process.c
2861@@ -217,6 +217,7 @@ void machine_power_off(void)
2862
2863 if (pm_power_off)
2864 pm_power_off();
2865+ BUG();
2866 }
2867
2868 /*
2869@@ -230,7 +231,7 @@ void machine_power_off(void)
2870 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2871 * to use. Implementing such co-ordination would be essentially impossible.
2872 */
2873-void machine_restart(char *cmd)
2874+__noreturn void machine_restart(char *cmd)
2875 {
2876 local_irq_disable();
2877 smp_send_stop();
2878@@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2879
2880 show_regs_print_info(KERN_DEFAULT);
2881
2882- print_symbol("PC is at %s\n", instruction_pointer(regs));
2883- print_symbol("LR is at %s\n", regs->ARM_lr);
2884+ printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2885+ printk("LR is at %pA\n", (void *)regs->ARM_lr);
2886 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2887 "sp : %08lx ip : %08lx fp : %08lx\n",
2888 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2889@@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2890 return 0;
2891 }
2892
2893-unsigned long arch_randomize_brk(struct mm_struct *mm)
2894-{
2895- unsigned long range_end = mm->brk + 0x02000000;
2896- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2897-}
2898-
2899 #ifdef CONFIG_MMU
2900 #ifdef CONFIG_KUSER_HELPERS
2901 /*
2902@@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2903
2904 static int __init gate_vma_init(void)
2905 {
2906- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2907+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2908 return 0;
2909 }
2910 arch_initcall(gate_vma_init);
2911@@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2912
2913 const char *arch_vma_name(struct vm_area_struct *vma)
2914 {
2915- return is_gate_vma(vma) ? "[vectors]" :
2916- (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2917- "[sigpage]" : NULL;
2918+ return is_gate_vma(vma) ? "[vectors]" : NULL;
2919 }
2920
2921-static struct page *signal_page;
2922-extern struct page *get_signal_page(void);
2923-
2924 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2925 {
2926 struct mm_struct *mm = current->mm;
2927- unsigned long addr;
2928- int ret;
2929-
2930- if (!signal_page)
2931- signal_page = get_signal_page();
2932- if (!signal_page)
2933- return -ENOMEM;
2934
2935 down_write(&mm->mmap_sem);
2936- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2937- if (IS_ERR_VALUE(addr)) {
2938- ret = addr;
2939- goto up_fail;
2940- }
2941-
2942- ret = install_special_mapping(mm, addr, PAGE_SIZE,
2943- VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2944- &signal_page);
2945-
2946- if (ret == 0)
2947- mm->context.sigpage = addr;
2948-
2949- up_fail:
2950+ mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2951 up_write(&mm->mmap_sem);
2952- return ret;
2953+ return 0;
2954 }
2955 #endif
2956diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2957index 4693188..4596c5e 100644
2958--- a/arch/arm/kernel/psci.c
2959+++ b/arch/arm/kernel/psci.c
2960@@ -24,7 +24,7 @@
2961 #include <asm/opcodes-virt.h>
2962 #include <asm/psci.h>
2963
2964-struct psci_operations psci_ops;
2965+struct psci_operations psci_ops __read_only;
2966
2967 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2968
2969diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2970index 0dd3b79..e018f64 100644
2971--- a/arch/arm/kernel/ptrace.c
2972+++ b/arch/arm/kernel/ptrace.c
2973@@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2974 return current_thread_info()->syscall;
2975 }
2976
2977+#ifdef CONFIG_GRKERNSEC_SETXID
2978+extern void gr_delayed_cred_worker(void);
2979+#endif
2980+
2981 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2982 {
2983 current_thread_info()->syscall = scno;
2984
2985+#ifdef CONFIG_GRKERNSEC_SETXID
2986+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2987+ gr_delayed_cred_worker();
2988+#endif
2989+
2990 /* Do the secure computing check first; failures should be fast. */
2991 if (secure_computing(scno) == -1)
2992 return -1;
2993diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2994index 987a7f5..ab0c397 100644
2995--- a/arch/arm/kernel/setup.c
2996+++ b/arch/arm/kernel/setup.c
2997@@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2998 unsigned int elf_hwcap __read_mostly;
2999 EXPORT_SYMBOL(elf_hwcap);
3000
3001+pteval_t __supported_pte_mask __read_only;
3002+pmdval_t __supported_pmd_mask __read_only;
3003
3004 #ifdef MULTI_CPU
3005-struct processor processor __read_mostly;
3006+struct processor processor __read_only;
3007 #endif
3008 #ifdef MULTI_TLB
3009-struct cpu_tlb_fns cpu_tlb __read_mostly;
3010+struct cpu_tlb_fns cpu_tlb __read_only;
3011 #endif
3012 #ifdef MULTI_USER
3013-struct cpu_user_fns cpu_user __read_mostly;
3014+struct cpu_user_fns cpu_user __read_only;
3015 #endif
3016 #ifdef MULTI_CACHE
3017-struct cpu_cache_fns cpu_cache __read_mostly;
3018+struct cpu_cache_fns cpu_cache __read_only;
3019 #endif
3020 #ifdef CONFIG_OUTER_CACHE
3021-struct outer_cache_fns outer_cache __read_mostly;
3022+struct outer_cache_fns outer_cache __read_only;
3023 EXPORT_SYMBOL(outer_cache);
3024 #endif
3025
3026@@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3027 asm("mrc p15, 0, %0, c0, c1, 4"
3028 : "=r" (mmfr0));
3029 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3030- (mmfr0 & 0x000000f0) >= 0x00000030)
3031+ (mmfr0 & 0x000000f0) >= 0x00000030) {
3032 cpu_arch = CPU_ARCH_ARMv7;
3033- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3034+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3035+ __supported_pte_mask |= L_PTE_PXN;
3036+ __supported_pmd_mask |= PMD_PXNTABLE;
3037+ }
3038+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3039 (mmfr0 & 0x000000f0) == 0x00000020)
3040 cpu_arch = CPU_ARCH_ARMv6;
3041 else
3042diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3043index 04d6388..5115238 100644
3044--- a/arch/arm/kernel/signal.c
3045+++ b/arch/arm/kernel/signal.c
3046@@ -23,8 +23,6 @@
3047
3048 extern const unsigned long sigreturn_codes[7];
3049
3050-static unsigned long signal_return_offset;
3051-
3052 #ifdef CONFIG_CRUNCH
3053 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3054 {
3055@@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3056 * except when the MPU has protected the vectors
3057 * page from PL0
3058 */
3059- retcode = mm->context.sigpage + signal_return_offset +
3060- (idx << 2) + thumb;
3061+ retcode = mm->context.sigpage + (idx << 2) + thumb;
3062 } else
3063 #endif
3064 {
3065@@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3066 } while (thread_flags & _TIF_WORK_MASK);
3067 return 0;
3068 }
3069-
3070-struct page *get_signal_page(void)
3071-{
3072- unsigned long ptr;
3073- unsigned offset;
3074- struct page *page;
3075- void *addr;
3076-
3077- page = alloc_pages(GFP_KERNEL, 0);
3078-
3079- if (!page)
3080- return NULL;
3081-
3082- addr = page_address(page);
3083-
3084- /* Give the signal return code some randomness */
3085- offset = 0x200 + (get_random_int() & 0x7fc);
3086- signal_return_offset = offset;
3087-
3088- /*
3089- * Copy signal return handlers into the vector page, and
3090- * set sigreturn to be a pointer to these.
3091- */
3092- memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3093-
3094- ptr = (unsigned long)addr + offset;
3095- flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3096-
3097- return page;
3098-}
3099diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3100index dc894ab..f929a0d 100644
3101--- a/arch/arm/kernel/smp.c
3102+++ b/arch/arm/kernel/smp.c
3103@@ -73,7 +73,7 @@ enum ipi_msg_type {
3104
3105 static DECLARE_COMPLETION(cpu_running);
3106
3107-static struct smp_operations smp_ops;
3108+static struct smp_operations smp_ops __read_only;
3109
3110 void __init smp_set_ops(struct smp_operations *ops)
3111 {
3112diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3113index 4636d56..ce4ec3d 100644
3114--- a/arch/arm/kernel/traps.c
3115+++ b/arch/arm/kernel/traps.c
3116@@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3117 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3118 {
3119 #ifdef CONFIG_KALLSYMS
3120- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3121+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3122 #else
3123 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3124 #endif
3125@@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3126 static int die_owner = -1;
3127 static unsigned int die_nest_count;
3128
3129+extern void gr_handle_kernel_exploit(void);
3130+
3131 static unsigned long oops_begin(void)
3132 {
3133 int cpu;
3134@@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3135 panic("Fatal exception in interrupt");
3136 if (panic_on_oops)
3137 panic("Fatal exception");
3138+
3139+ gr_handle_kernel_exploit();
3140+
3141 if (signr)
3142 do_exit(signr);
3143 }
3144@@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3145 * The user helper at 0xffff0fe0 must be used instead.
3146 * (see entry-armv.S for details)
3147 */
3148+ pax_open_kernel();
3149 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3150+ pax_close_kernel();
3151 }
3152 return 0;
3153
3154@@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3155 kuser_init(vectors_base);
3156
3157 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3158- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3159+
3160+#ifndef CONFIG_PAX_MEMORY_UDEREF
3161+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3162+#endif
3163+
3164 #else /* ifndef CONFIG_CPU_V7M */
3165 /*
3166 * on V7-M there is no need to copy the vector table to a dedicated
3167diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3168index 7bcee5c..e2f3249 100644
3169--- a/arch/arm/kernel/vmlinux.lds.S
3170+++ b/arch/arm/kernel/vmlinux.lds.S
3171@@ -8,7 +8,11 @@
3172 #include <asm/thread_info.h>
3173 #include <asm/memory.h>
3174 #include <asm/page.h>
3175-
3176+
3177+#ifdef CONFIG_PAX_KERNEXEC
3178+#include <asm/pgtable.h>
3179+#endif
3180+
3181 #define PROC_INFO \
3182 . = ALIGN(4); \
3183 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3184@@ -34,7 +38,7 @@
3185 #endif
3186
3187 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3188- defined(CONFIG_GENERIC_BUG)
3189+ defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3190 #define ARM_EXIT_KEEP(x) x
3191 #define ARM_EXIT_DISCARD(x)
3192 #else
3193@@ -90,6 +94,11 @@ SECTIONS
3194 _text = .;
3195 HEAD_TEXT
3196 }
3197+
3198+#ifdef CONFIG_PAX_KERNEXEC
3199+ . = ALIGN(1<<SECTION_SHIFT);
3200+#endif
3201+
3202 .text : { /* Real text segment */
3203 _stext = .; /* Text and read-only data */
3204 __exception_text_start = .;
3205@@ -112,6 +121,8 @@ SECTIONS
3206 ARM_CPU_KEEP(PROC_INFO)
3207 }
3208
3209+ _etext = .; /* End of text section */
3210+
3211 RO_DATA(PAGE_SIZE)
3212
3213 . = ALIGN(4);
3214@@ -142,7 +153,9 @@ SECTIONS
3215
3216 NOTES
3217
3218- _etext = .; /* End of text and rodata section */
3219+#ifdef CONFIG_PAX_KERNEXEC
3220+ . = ALIGN(1<<SECTION_SHIFT);
3221+#endif
3222
3223 #ifndef CONFIG_XIP_KERNEL
3224 . = ALIGN(PAGE_SIZE);
3225@@ -220,6 +233,11 @@ SECTIONS
3226 . = PAGE_OFFSET + TEXT_OFFSET;
3227 #else
3228 __init_end = .;
3229+
3230+#ifdef CONFIG_PAX_KERNEXEC
3231+ . = ALIGN(1<<SECTION_SHIFT);
3232+#endif
3233+
3234 . = ALIGN(THREAD_SIZE);
3235 __data_loc = .;
3236 #endif
3237diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3238index 2a700e0..745b980 100644
3239--- a/arch/arm/kvm/arm.c
3240+++ b/arch/arm/kvm/arm.c
3241@@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3242 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3243
3244 /* The VMID used in the VTTBR */
3245-static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3246+static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3247 static u8 kvm_next_vmid;
3248 static DEFINE_SPINLOCK(kvm_vmid_lock);
3249
3250@@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3251 */
3252 static bool need_new_vmid_gen(struct kvm *kvm)
3253 {
3254- return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3255+ return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3256 }
3257
3258 /**
3259@@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3260
3261 /* First user of a new VMID generation? */
3262 if (unlikely(kvm_next_vmid == 0)) {
3263- atomic64_inc(&kvm_vmid_gen);
3264+ atomic64_inc_unchecked(&kvm_vmid_gen);
3265 kvm_next_vmid = 1;
3266
3267 /*
3268@@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3269 kvm_call_hyp(__kvm_flush_vm_context);
3270 }
3271
3272- kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3273+ kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3274 kvm->arch.vmid = kvm_next_vmid;
3275 kvm_next_vmid++;
3276
3277diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3278index 14a0d98..7771a7d 100644
3279--- a/arch/arm/lib/clear_user.S
3280+++ b/arch/arm/lib/clear_user.S
3281@@ -12,14 +12,14 @@
3282
3283 .text
3284
3285-/* Prototype: int __clear_user(void *addr, size_t sz)
3286+/* Prototype: int ___clear_user(void *addr, size_t sz)
3287 * Purpose : clear some user memory
3288 * Params : addr - user memory address to clear
3289 * : sz - number of bytes to clear
3290 * Returns : number of bytes NOT cleared
3291 */
3292 ENTRY(__clear_user_std)
3293-WEAK(__clear_user)
3294+WEAK(___clear_user)
3295 stmfd sp!, {r1, lr}
3296 mov r2, #0
3297 cmp r1, #4
3298@@ -44,7 +44,7 @@ WEAK(__clear_user)
3299 USER( strnebt r2, [r0])
3300 mov r0, #0
3301 ldmfd sp!, {r1, pc}
3302-ENDPROC(__clear_user)
3303+ENDPROC(___clear_user)
3304 ENDPROC(__clear_user_std)
3305
3306 .pushsection .fixup,"ax"
3307diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3308index 66a477a..bee61d3 100644
3309--- a/arch/arm/lib/copy_from_user.S
3310+++ b/arch/arm/lib/copy_from_user.S
3311@@ -16,7 +16,7 @@
3312 /*
3313 * Prototype:
3314 *
3315- * size_t __copy_from_user(void *to, const void *from, size_t n)
3316+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3317 *
3318 * Purpose:
3319 *
3320@@ -84,11 +84,11 @@
3321
3322 .text
3323
3324-ENTRY(__copy_from_user)
3325+ENTRY(___copy_from_user)
3326
3327 #include "copy_template.S"
3328
3329-ENDPROC(__copy_from_user)
3330+ENDPROC(___copy_from_user)
3331
3332 .pushsection .fixup,"ax"
3333 .align 0
3334diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3335index 6ee2f67..d1cce76 100644
3336--- a/arch/arm/lib/copy_page.S
3337+++ b/arch/arm/lib/copy_page.S
3338@@ -10,6 +10,7 @@
3339 * ASM optimised string functions
3340 */
3341 #include <linux/linkage.h>
3342+#include <linux/const.h>
3343 #include <asm/assembler.h>
3344 #include <asm/asm-offsets.h>
3345 #include <asm/cache.h>
3346diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3347index d066df6..df28194 100644
3348--- a/arch/arm/lib/copy_to_user.S
3349+++ b/arch/arm/lib/copy_to_user.S
3350@@ -16,7 +16,7 @@
3351 /*
3352 * Prototype:
3353 *
3354- * size_t __copy_to_user(void *to, const void *from, size_t n)
3355+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3356 *
3357 * Purpose:
3358 *
3359@@ -88,11 +88,11 @@
3360 .text
3361
3362 ENTRY(__copy_to_user_std)
3363-WEAK(__copy_to_user)
3364+WEAK(___copy_to_user)
3365
3366 #include "copy_template.S"
3367
3368-ENDPROC(__copy_to_user)
3369+ENDPROC(___copy_to_user)
3370 ENDPROC(__copy_to_user_std)
3371
3372 .pushsection .fixup,"ax"
3373diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3374index 7d08b43..f7ca7ea 100644
3375--- a/arch/arm/lib/csumpartialcopyuser.S
3376+++ b/arch/arm/lib/csumpartialcopyuser.S
3377@@ -57,8 +57,8 @@
3378 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3379 */
3380
3381-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3382-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3383+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3384+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3385
3386 #include "csumpartialcopygeneric.S"
3387
3388diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3389index 5306de3..aed6d03 100644
3390--- a/arch/arm/lib/delay.c
3391+++ b/arch/arm/lib/delay.c
3392@@ -28,7 +28,7 @@
3393 /*
3394 * Default to the loop-based delay implementation.
3395 */
3396-struct arm_delay_ops arm_delay_ops = {
3397+struct arm_delay_ops arm_delay_ops __read_only = {
3398 .delay = __loop_delay,
3399 .const_udelay = __loop_const_udelay,
3400 .udelay = __loop_udelay,
3401diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3402index 3e58d71..029817c 100644
3403--- a/arch/arm/lib/uaccess_with_memcpy.c
3404+++ b/arch/arm/lib/uaccess_with_memcpy.c
3405@@ -136,7 +136,7 @@ out:
3406 }
3407
3408 unsigned long
3409-__copy_to_user(void __user *to, const void *from, unsigned long n)
3410+___copy_to_user(void __user *to, const void *from, unsigned long n)
3411 {
3412 /*
3413 * This test is stubbed out of the main function above to keep
3414@@ -190,7 +190,7 @@ out:
3415 return n;
3416 }
3417
3418-unsigned long __clear_user(void __user *addr, unsigned long n)
3419+unsigned long ___clear_user(void __user *addr, unsigned long n)
3420 {
3421 /* See rational for this in __copy_to_user() above. */
3422 if (n < 64)
3423diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3424index f3407a5..bd4256f 100644
3425--- a/arch/arm/mach-kirkwood/common.c
3426+++ b/arch/arm/mach-kirkwood/common.c
3427@@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3428 clk_gate_ops.disable(hw);
3429 }
3430
3431-static struct clk_ops clk_gate_fn_ops;
3432+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3433+{
3434+ return clk_gate_ops.is_enabled(hw);
3435+}
3436+
3437+static struct clk_ops clk_gate_fn_ops = {
3438+ .enable = clk_gate_fn_enable,
3439+ .disable = clk_gate_fn_disable,
3440+ .is_enabled = clk_gate_fn_is_enabled,
3441+};
3442
3443 static struct clk __init *clk_register_gate_fn(struct device *dev,
3444 const char *name,
3445@@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3446 gate_fn->fn_en = fn_en;
3447 gate_fn->fn_dis = fn_dis;
3448
3449- /* ops is the gate ops, but with our enable/disable functions */
3450- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3451- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3452- clk_gate_fn_ops = clk_gate_ops;
3453- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3454- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3455- }
3456-
3457 clk = clk_register(dev, &gate_fn->gate.hw);
3458
3459 if (IS_ERR(clk))
3460diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3461index 827d1500..2885dc6 100644
3462--- a/arch/arm/mach-omap2/board-n8x0.c
3463+++ b/arch/arm/mach-omap2/board-n8x0.c
3464@@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3465 }
3466 #endif
3467
3468-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3469+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3470 .late_init = n8x0_menelaus_late_init,
3471 };
3472
3473diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3474index ab43755..ccfa231 100644
3475--- a/arch/arm/mach-omap2/gpmc.c
3476+++ b/arch/arm/mach-omap2/gpmc.c
3477@@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3478 };
3479
3480 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3481-static struct irq_chip gpmc_irq_chip;
3482 static int gpmc_irq_start;
3483
3484 static struct resource gpmc_mem_root;
3485@@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3486
3487 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3488
3489+static struct irq_chip gpmc_irq_chip = {
3490+ .name = "gpmc",
3491+ .irq_startup = gpmc_irq_noop_ret,
3492+ .irq_enable = gpmc_irq_enable,
3493+ .irq_disable = gpmc_irq_disable,
3494+ .irq_shutdown = gpmc_irq_noop,
3495+ .irq_ack = gpmc_irq_noop,
3496+ .irq_mask = gpmc_irq_noop,
3497+ .irq_unmask = gpmc_irq_noop,
3498+
3499+};
3500+
3501 static int gpmc_setup_irq(void)
3502 {
3503 int i;
3504@@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3505 return gpmc_irq_start;
3506 }
3507
3508- gpmc_irq_chip.name = "gpmc";
3509- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3510- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3511- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3512- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3513- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3514- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3515- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3516-
3517 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3518 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3519
3520diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3521index f991016..145ebeb 100644
3522--- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3523+++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3524@@ -84,7 +84,7 @@ struct cpu_pm_ops {
3525 int (*finish_suspend)(unsigned long cpu_state);
3526 void (*resume)(void);
3527 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3528-};
3529+} __no_const;
3530
3531 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3532 static struct powerdomain *mpuss_pd;
3533@@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3534 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3535 {}
3536
3537-struct cpu_pm_ops omap_pm_ops = {
3538+static struct cpu_pm_ops omap_pm_ops __read_only = {
3539 .finish_suspend = default_finish_suspend,
3540 .resume = dummy_cpu_resume,
3541 .scu_prepare = dummy_scu_prepare,
3542diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3543index 3664562..72f85c6 100644
3544--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3545+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3546@@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3547 return NOTIFY_OK;
3548 }
3549
3550-static struct notifier_block __refdata irq_hotplug_notifier = {
3551+static struct notifier_block irq_hotplug_notifier = {
3552 .notifier_call = irq_cpu_hotplug_notify,
3553 };
3554
3555diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3556index e0a398c..a470fa5 100644
3557--- a/arch/arm/mach-omap2/omap_device.c
3558+++ b/arch/arm/mach-omap2/omap_device.c
3559@@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3560 struct platform_device __init *omap_device_build(const char *pdev_name,
3561 int pdev_id,
3562 struct omap_hwmod *oh,
3563- void *pdata, int pdata_len)
3564+ const void *pdata, int pdata_len)
3565 {
3566 struct omap_hwmod *ohs[] = { oh };
3567
3568@@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3569 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3570 int pdev_id,
3571 struct omap_hwmod **ohs,
3572- int oh_cnt, void *pdata,
3573+ int oh_cnt, const void *pdata,
3574 int pdata_len)
3575 {
3576 int ret = -ENOMEM;
3577diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3578index 78c02b3..c94109a 100644
3579--- a/arch/arm/mach-omap2/omap_device.h
3580+++ b/arch/arm/mach-omap2/omap_device.h
3581@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3582 /* Core code interface */
3583
3584 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3585- struct omap_hwmod *oh, void *pdata,
3586+ struct omap_hwmod *oh, const void *pdata,
3587 int pdata_len);
3588
3589 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3590 struct omap_hwmod **oh, int oh_cnt,
3591- void *pdata, int pdata_len);
3592+ const void *pdata, int pdata_len);
3593
3594 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3595 struct omap_hwmod **ohs, int oh_cnt);
3596diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3597index 8a1b5e0..5f30074 100644
3598--- a/arch/arm/mach-omap2/omap_hwmod.c
3599+++ b/arch/arm/mach-omap2/omap_hwmod.c
3600@@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3601 int (*init_clkdm)(struct omap_hwmod *oh);
3602 void (*update_context_lost)(struct omap_hwmod *oh);
3603 int (*get_context_lost)(struct omap_hwmod *oh);
3604-};
3605+} __no_const;
3606
3607 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3608-static struct omap_hwmod_soc_ops soc_ops;
3609+static struct omap_hwmod_soc_ops soc_ops __read_only;
3610
3611 /* omap_hwmod_list contains all registered struct omap_hwmods */
3612 static LIST_HEAD(omap_hwmod_list);
3613diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3614index 95fee54..cfa9cf1 100644
3615--- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3616+++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3617@@ -10,6 +10,7 @@
3618
3619 #include <linux/kernel.h>
3620 #include <linux/init.h>
3621+#include <asm/pgtable.h>
3622
3623 #include "powerdomain.h"
3624
3625@@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3626
3627 void __init am43xx_powerdomains_init(void)
3628 {
3629- omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3630+ pax_open_kernel();
3631+ *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3632+ pax_close_kernel();
3633 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3634 pwrdm_register_pwrdms(powerdomains_am43xx);
3635 pwrdm_complete_init();
3636diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3637index d15c7bb..b2d1f0c 100644
3638--- a/arch/arm/mach-omap2/wd_timer.c
3639+++ b/arch/arm/mach-omap2/wd_timer.c
3640@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3641 struct omap_hwmod *oh;
3642 char *oh_name = "wd_timer2";
3643 char *dev_name = "omap_wdt";
3644- struct omap_wd_timer_platform_data pdata;
3645+ static struct omap_wd_timer_platform_data pdata = {
3646+ .read_reset_sources = prm_read_reset_sources
3647+ };
3648
3649 if (!cpu_class_is_omap2() || of_have_populated_dt())
3650 return 0;
3651@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3652 return -EINVAL;
3653 }
3654
3655- pdata.read_reset_sources = prm_read_reset_sources;
3656-
3657 pdev = omap_device_build(dev_name, id, oh, &pdata,
3658 sizeof(struct omap_wd_timer_platform_data));
3659 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3660diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3661index b82dcae..44ee5b6 100644
3662--- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3663+++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3664@@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3665 bool entered_lp2 = false;
3666
3667 if (tegra_pending_sgi())
3668- ACCESS_ONCE(abort_flag) = true;
3669+ ACCESS_ONCE_RW(abort_flag) = true;
3670
3671 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3672
3673diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3674index bdb3564..cebb96f 100644
3675--- a/arch/arm/mach-ux500/setup.h
3676+++ b/arch/arm/mach-ux500/setup.h
3677@@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3678 .type = MT_DEVICE, \
3679 }
3680
3681-#define __MEM_DEV_DESC(x, sz) { \
3682- .virtual = IO_ADDRESS(x), \
3683- .pfn = __phys_to_pfn(x), \
3684- .length = sz, \
3685- .type = MT_MEMORY, \
3686-}
3687-
3688 extern struct smp_operations ux500_smp_ops;
3689 extern void ux500_cpu_die(unsigned int cpu);
3690
3691diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3692index 1f8fed9..14d7823 100644
3693--- a/arch/arm/mm/Kconfig
3694+++ b/arch/arm/mm/Kconfig
3695@@ -446,7 +446,7 @@ config CPU_32v5
3696
3697 config CPU_32v6
3698 bool
3699- select CPU_USE_DOMAINS if CPU_V6 && MMU
3700+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3701 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3702
3703 config CPU_32v6K
3704@@ -601,6 +601,7 @@ config CPU_CP15_MPU
3705
3706 config CPU_USE_DOMAINS
3707 bool
3708+ depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3709 help
3710 This option enables or disables the use of domain switching
3711 via the set_fs() function.
3712@@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3713 config KUSER_HELPERS
3714 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3715 default y
3716+ depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3717 help
3718 Warning: disabling this option may break user programs.
3719
3720@@ -812,7 +814,7 @@ config KUSER_HELPERS
3721 See Documentation/arm/kernel_user_helpers.txt for details.
3722
3723 However, the fixed address nature of these helpers can be used
3724- by ROP (return orientated programming) authors when creating
3725+ by ROP (Return Oriented Programming) authors when creating
3726 exploits.
3727
3728 If all of the binaries and libraries which run on your platform
3729diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3730index 9240364..a2b8cf3 100644
3731--- a/arch/arm/mm/alignment.c
3732+++ b/arch/arm/mm/alignment.c
3733@@ -212,10 +212,12 @@ union offset_union {
3734 #define __get16_unaligned_check(ins,val,addr) \
3735 do { \
3736 unsigned int err = 0, v, a = addr; \
3737+ pax_open_userland(); \
3738 __get8_unaligned_check(ins,v,a,err); \
3739 val = v << ((BE) ? 8 : 0); \
3740 __get8_unaligned_check(ins,v,a,err); \
3741 val |= v << ((BE) ? 0 : 8); \
3742+ pax_close_userland(); \
3743 if (err) \
3744 goto fault; \
3745 } while (0)
3746@@ -229,6 +231,7 @@ union offset_union {
3747 #define __get32_unaligned_check(ins,val,addr) \
3748 do { \
3749 unsigned int err = 0, v, a = addr; \
3750+ pax_open_userland(); \
3751 __get8_unaligned_check(ins,v,a,err); \
3752 val = v << ((BE) ? 24 : 0); \
3753 __get8_unaligned_check(ins,v,a,err); \
3754@@ -237,6 +240,7 @@ union offset_union {
3755 val |= v << ((BE) ? 8 : 16); \
3756 __get8_unaligned_check(ins,v,a,err); \
3757 val |= v << ((BE) ? 0 : 24); \
3758+ pax_close_userland(); \
3759 if (err) \
3760 goto fault; \
3761 } while (0)
3762@@ -250,6 +254,7 @@ union offset_union {
3763 #define __put16_unaligned_check(ins,val,addr) \
3764 do { \
3765 unsigned int err = 0, v = val, a = addr; \
3766+ pax_open_userland(); \
3767 __asm__( FIRST_BYTE_16 \
3768 ARM( "1: "ins" %1, [%2], #1\n" ) \
3769 THUMB( "1: "ins" %1, [%2]\n" ) \
3770@@ -269,6 +274,7 @@ union offset_union {
3771 " .popsection\n" \
3772 : "=r" (err), "=&r" (v), "=&r" (a) \
3773 : "0" (err), "1" (v), "2" (a)); \
3774+ pax_close_userland(); \
3775 if (err) \
3776 goto fault; \
3777 } while (0)
3778@@ -282,6 +288,7 @@ union offset_union {
3779 #define __put32_unaligned_check(ins,val,addr) \
3780 do { \
3781 unsigned int err = 0, v = val, a = addr; \
3782+ pax_open_userland(); \
3783 __asm__( FIRST_BYTE_32 \
3784 ARM( "1: "ins" %1, [%2], #1\n" ) \
3785 THUMB( "1: "ins" %1, [%2]\n" ) \
3786@@ -311,6 +318,7 @@ union offset_union {
3787 " .popsection\n" \
3788 : "=r" (err), "=&r" (v), "=&r" (a) \
3789 : "0" (err), "1" (v), "2" (a)); \
3790+ pax_close_userland(); \
3791 if (err) \
3792 goto fault; \
3793 } while (0)
3794diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3795index 447da6f..77a5057 100644
3796--- a/arch/arm/mm/cache-l2x0.c
3797+++ b/arch/arm/mm/cache-l2x0.c
3798@@ -45,7 +45,7 @@ struct l2x0_of_data {
3799 void (*setup)(const struct device_node *, u32 *, u32 *);
3800 void (*save)(void);
3801 struct outer_cache_fns outer_cache;
3802-};
3803+} __do_const;
3804
3805 static bool of_init = false;
3806
3807diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3808index 84e6f77..0b52f31 100644
3809--- a/arch/arm/mm/context.c
3810+++ b/arch/arm/mm/context.c
3811@@ -43,7 +43,7 @@
3812 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3813
3814 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3815-static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3816+static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3817 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3818
3819 static DEFINE_PER_CPU(atomic64_t, active_asids);
3820@@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3821 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3822 {
3823 u64 asid = atomic64_read(&mm->context.id);
3824- u64 generation = atomic64_read(&asid_generation);
3825+ u64 generation = atomic64_read_unchecked(&asid_generation);
3826
3827 if (asid != 0 && is_reserved_asid(asid)) {
3828 /*
3829@@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3830 */
3831 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3832 if (asid == NUM_USER_ASIDS) {
3833- generation = atomic64_add_return(ASID_FIRST_VERSION,
3834+ generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3835 &asid_generation);
3836 flush_context(cpu);
3837 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3838@@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3839 cpu_set_reserved_ttbr0();
3840
3841 asid = atomic64_read(&mm->context.id);
3842- if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3843+ if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3844 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3845 goto switch_mm_fastpath;
3846
3847 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3848 /* Check that our ASID belongs to the current generation. */
3849 asid = atomic64_read(&mm->context.id);
3850- if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3851+ if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3852 asid = new_context(mm, cpu);
3853 atomic64_set(&mm->context.id, asid);
3854 }
3855diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3856index eb8830a..5360ce7 100644
3857--- a/arch/arm/mm/fault.c
3858+++ b/arch/arm/mm/fault.c
3859@@ -25,6 +25,7 @@
3860 #include <asm/system_misc.h>
3861 #include <asm/system_info.h>
3862 #include <asm/tlbflush.h>
3863+#include <asm/sections.h>
3864
3865 #include "fault.h"
3866
3867@@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3868 if (fixup_exception(regs))
3869 return;
3870
3871+#ifdef CONFIG_PAX_MEMORY_UDEREF
3872+ if (addr < TASK_SIZE) {
3873+ if (current->signal->curr_ip)
3874+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3875+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3876+ else
3877+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3878+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3879+ }
3880+#endif
3881+
3882+#ifdef CONFIG_PAX_KERNEXEC
3883+ if ((fsr & FSR_WRITE) &&
3884+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3885+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3886+ {
3887+ if (current->signal->curr_ip)
3888+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3889+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3890+ else
3891+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3892+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3893+ }
3894+#endif
3895+
3896 /*
3897 * No handler, we'll have to terminate things with extreme prejudice.
3898 */
3899@@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3900 }
3901 #endif
3902
3903+#ifdef CONFIG_PAX_PAGEEXEC
3904+ if (fsr & FSR_LNX_PF) {
3905+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3906+ do_group_exit(SIGKILL);
3907+ }
3908+#endif
3909+
3910 tsk->thread.address = addr;
3911 tsk->thread.error_code = fsr;
3912 tsk->thread.trap_no = 14;
3913@@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3914 }
3915 #endif /* CONFIG_MMU */
3916
3917+#ifdef CONFIG_PAX_PAGEEXEC
3918+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3919+{
3920+ long i;
3921+
3922+ printk(KERN_ERR "PAX: bytes at PC: ");
3923+ for (i = 0; i < 20; i++) {
3924+ unsigned char c;
3925+ if (get_user(c, (__force unsigned char __user *)pc+i))
3926+ printk(KERN_CONT "?? ");
3927+ else
3928+ printk(KERN_CONT "%02x ", c);
3929+ }
3930+ printk("\n");
3931+
3932+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3933+ for (i = -1; i < 20; i++) {
3934+ unsigned long c;
3935+ if (get_user(c, (__force unsigned long __user *)sp+i))
3936+ printk(KERN_CONT "???????? ");
3937+ else
3938+ printk(KERN_CONT "%08lx ", c);
3939+ }
3940+ printk("\n");
3941+}
3942+#endif
3943+
3944 /*
3945 * First Level Translation Fault Handler
3946 *
3947@@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3948 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3949 struct siginfo info;
3950
3951+#ifdef CONFIG_PAX_MEMORY_UDEREF
3952+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3953+ if (current->signal->curr_ip)
3954+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3955+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3956+ else
3957+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3958+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3959+ goto die;
3960+ }
3961+#endif
3962+
3963 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3964 return;
3965
3966+die:
3967 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3968 inf->name, fsr, addr);
3969
3970@@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3971 ifsr_info[nr].name = name;
3972 }
3973
3974+asmlinkage int sys_sigreturn(struct pt_regs *regs);
3975+asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3976+
3977 asmlinkage void __exception
3978 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3979 {
3980 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3981 struct siginfo info;
3982+ unsigned long pc = instruction_pointer(regs);
3983+
3984+ if (user_mode(regs)) {
3985+ unsigned long sigpage = current->mm->context.sigpage;
3986+
3987+ if (sigpage <= pc && pc < sigpage + 7*4) {
3988+ if (pc < sigpage + 3*4)
3989+ sys_sigreturn(regs);
3990+ else
3991+ sys_rt_sigreturn(regs);
3992+ return;
3993+ }
3994+ if (pc == 0xffff0f60UL) {
3995+ /*
3996+ * PaX: __kuser_cmpxchg64 emulation
3997+ */
3998+ // TODO
3999+ //regs->ARM_pc = regs->ARM_lr;
4000+ //return;
4001+ }
4002+ if (pc == 0xffff0fa0UL) {
4003+ /*
4004+ * PaX: __kuser_memory_barrier emulation
4005+ */
4006+ // dmb(); implied by the exception
4007+ regs->ARM_pc = regs->ARM_lr;
4008+ return;
4009+ }
4010+ if (pc == 0xffff0fc0UL) {
4011+ /*
4012+ * PaX: __kuser_cmpxchg emulation
4013+ */
4014+ // TODO
4015+ //long new;
4016+ //int op;
4017+
4018+ //op = FUTEX_OP_SET << 28;
4019+ //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4020+ //regs->ARM_r0 = old != new;
4021+ //regs->ARM_pc = regs->ARM_lr;
4022+ //return;
4023+ }
4024+ if (pc == 0xffff0fe0UL) {
4025+ /*
4026+ * PaX: __kuser_get_tls emulation
4027+ */
4028+ regs->ARM_r0 = current_thread_info()->tp_value[0];
4029+ regs->ARM_pc = regs->ARM_lr;
4030+ return;
4031+ }
4032+ }
4033+
4034+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4035+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4036+ if (current->signal->curr_ip)
4037+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4038+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4039+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4040+ else
4041+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4042+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4043+ pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4044+ goto die;
4045+ }
4046+#endif
4047+
4048+#ifdef CONFIG_PAX_REFCOUNT
4049+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4050+ unsigned int bkpt;
4051+
4052+ if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4053+ current->thread.error_code = ifsr;
4054+ current->thread.trap_no = 0;
4055+ pax_report_refcount_overflow(regs);
4056+ fixup_exception(regs);
4057+ return;
4058+ }
4059+ }
4060+#endif
4061
4062 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4063 return;
4064
4065+die:
4066 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4067 inf->name, ifsr, addr);
4068
4069diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4070index cf08bdf..772656c 100644
4071--- a/arch/arm/mm/fault.h
4072+++ b/arch/arm/mm/fault.h
4073@@ -3,6 +3,7 @@
4074
4075 /*
4076 * Fault status register encodings. We steal bit 31 for our own purposes.
4077+ * Set when the FSR value is from an instruction fault.
4078 */
4079 #define FSR_LNX_PF (1 << 31)
4080 #define FSR_WRITE (1 << 11)
4081@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4082 }
4083 #endif
4084
4085+/* valid for LPAE and !LPAE */
4086+static inline int is_xn_fault(unsigned int fsr)
4087+{
4088+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
4089+}
4090+
4091+static inline int is_domain_fault(unsigned int fsr)
4092+{
4093+ return ((fsr_fs(fsr) & 0xD) == 0x9);
4094+}
4095+
4096 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4097 unsigned long search_exception_table(unsigned long addr);
4098
4099diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4100index ac1d883..5a7bb91 100644
4101--- a/arch/arm/mm/init.c
4102+++ b/arch/arm/mm/init.c
4103@@ -30,6 +30,8 @@
4104 #include <asm/setup.h>
4105 #include <asm/tlb.h>
4106 #include <asm/fixmap.h>
4107+#include <asm/system_info.h>
4108+#include <asm/cp15.h>
4109
4110 #include <asm/mach/arch.h>
4111 #include <asm/mach/map.h>
4112@@ -682,7 +684,46 @@ void free_initmem(void)
4113 {
4114 #ifdef CONFIG_HAVE_TCM
4115 extern char __tcm_start, __tcm_end;
4116+#endif
4117
4118+#ifdef CONFIG_PAX_KERNEXEC
4119+ unsigned long addr;
4120+ pgd_t *pgd;
4121+ pud_t *pud;
4122+ pmd_t *pmd;
4123+ int cpu_arch = cpu_architecture();
4124+ unsigned int cr = get_cr();
4125+
4126+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4127+ /* make pages tables, etc before .text NX */
4128+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4129+ pgd = pgd_offset_k(addr);
4130+ pud = pud_offset(pgd, addr);
4131+ pmd = pmd_offset(pud, addr);
4132+ __section_update(pmd, addr, PMD_SECT_XN);
4133+ }
4134+ /* make init NX */
4135+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4136+ pgd = pgd_offset_k(addr);
4137+ pud = pud_offset(pgd, addr);
4138+ pmd = pmd_offset(pud, addr);
4139+ __section_update(pmd, addr, PMD_SECT_XN);
4140+ }
4141+ /* make kernel code/rodata RX */
4142+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4143+ pgd = pgd_offset_k(addr);
4144+ pud = pud_offset(pgd, addr);
4145+ pmd = pmd_offset(pud, addr);
4146+#ifdef CONFIG_ARM_LPAE
4147+ __section_update(pmd, addr, PMD_SECT_RDONLY);
4148+#else
4149+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4150+#endif
4151+ }
4152+ }
4153+#endif
4154+
4155+#ifdef CONFIG_HAVE_TCM
4156 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4157 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4158 #endif
4159diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4160index f123d6e..04bf569 100644
4161--- a/arch/arm/mm/ioremap.c
4162+++ b/arch/arm/mm/ioremap.c
4163@@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4164 unsigned int mtype;
4165
4166 if (cached)
4167- mtype = MT_MEMORY;
4168+ mtype = MT_MEMORY_RX;
4169 else
4170- mtype = MT_MEMORY_NONCACHED;
4171+ mtype = MT_MEMORY_NONCACHED_RX;
4172
4173 return __arm_ioremap_caller(phys_addr, size, mtype,
4174 __builtin_return_address(0));
4175diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4176index 5e85ed3..b10a7ed 100644
4177--- a/arch/arm/mm/mmap.c
4178+++ b/arch/arm/mm/mmap.c
4179@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4180 struct vm_area_struct *vma;
4181 int do_align = 0;
4182 int aliasing = cache_is_vipt_aliasing();
4183+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4184 struct vm_unmapped_area_info info;
4185
4186 /*
4187@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4188 if (len > TASK_SIZE)
4189 return -ENOMEM;
4190
4191+#ifdef CONFIG_PAX_RANDMMAP
4192+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4193+#endif
4194+
4195 if (addr) {
4196 if (do_align)
4197 addr = COLOUR_ALIGN(addr, pgoff);
4198@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4199 addr = PAGE_ALIGN(addr);
4200
4201 vma = find_vma(mm, addr);
4202- if (TASK_SIZE - len >= addr &&
4203- (!vma || addr + len <= vma->vm_start))
4204+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4205 return addr;
4206 }
4207
4208@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4209 info.high_limit = TASK_SIZE;
4210 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4211 info.align_offset = pgoff << PAGE_SHIFT;
4212+ info.threadstack_offset = offset;
4213 return vm_unmapped_area(&info);
4214 }
4215
4216@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4217 unsigned long addr = addr0;
4218 int do_align = 0;
4219 int aliasing = cache_is_vipt_aliasing();
4220+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4221 struct vm_unmapped_area_info info;
4222
4223 /*
4224@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4225 return addr;
4226 }
4227
4228+#ifdef CONFIG_PAX_RANDMMAP
4229+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4230+#endif
4231+
4232 /* requesting a specific address */
4233 if (addr) {
4234 if (do_align)
4235@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4236 else
4237 addr = PAGE_ALIGN(addr);
4238 vma = find_vma(mm, addr);
4239- if (TASK_SIZE - len >= addr &&
4240- (!vma || addr + len <= vma->vm_start))
4241+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4242 return addr;
4243 }
4244
4245@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4246 info.high_limit = mm->mmap_base;
4247 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4248 info.align_offset = pgoff << PAGE_SHIFT;
4249+ info.threadstack_offset = offset;
4250 addr = vm_unmapped_area(&info);
4251
4252 /*
4253@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4254 {
4255 unsigned long random_factor = 0UL;
4256
4257+#ifdef CONFIG_PAX_RANDMMAP
4258+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4259+#endif
4260+
4261 /* 8 bits of randomness in 20 address space bits */
4262 if ((current->flags & PF_RANDOMIZE) &&
4263 !(current->personality & ADDR_NO_RANDOMIZE))
4264@@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4265
4266 if (mmap_is_legacy()) {
4267 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4268+
4269+#ifdef CONFIG_PAX_RANDMMAP
4270+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4271+ mm->mmap_base += mm->delta_mmap;
4272+#endif
4273+
4274 mm->get_unmapped_area = arch_get_unmapped_area;
4275 } else {
4276 mm->mmap_base = mmap_base(random_factor);
4277+
4278+#ifdef CONFIG_PAX_RANDMMAP
4279+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4280+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4281+#endif
4282+
4283 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4284 }
4285 }
4286diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4287index 911d433..8580952 100644
4288--- a/arch/arm/mm/mmu.c
4289+++ b/arch/arm/mm/mmu.c
4290@@ -38,6 +38,22 @@
4291 #include "mm.h"
4292 #include "tcm.h"
4293
4294+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4295+void modify_domain(unsigned int dom, unsigned int type)
4296+{
4297+ struct thread_info *thread = current_thread_info();
4298+ unsigned int domain = thread->cpu_domain;
4299+ /*
4300+ * DOMAIN_MANAGER might be defined to some other value,
4301+ * use the arch-defined constant
4302+ */
4303+ domain &= ~domain_val(dom, 3);
4304+ thread->cpu_domain = domain | domain_val(dom, type);
4305+ set_domain(thread->cpu_domain);
4306+}
4307+EXPORT_SYMBOL(modify_domain);
4308+#endif
4309+
4310 /*
4311 * empty_zero_page is a special page that is used for
4312 * zero-initialized data and COW.
4313@@ -230,11 +246,19 @@ __setup("noalign", noalign_setup);
4314
4315 #endif /* ifdef CONFIG_CPU_CP15 / else */
4316
4317-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4318+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4319 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4320 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4321
4322-static struct mem_type mem_types[] = {
4323+#ifdef CONFIG_PAX_KERNEXEC
4324+#define L_PTE_KERNEXEC L_PTE_RDONLY
4325+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4326+#else
4327+#define L_PTE_KERNEXEC L_PTE_DIRTY
4328+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4329+#endif
4330+
4331+static struct mem_type mem_types[] __read_only = {
4332 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4333 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4334 L_PTE_SHARED,
4335@@ -266,16 +290,16 @@ static struct mem_type mem_types[] = {
4336 [MT_UNCACHED] = {
4337 .prot_pte = PROT_PTE_DEVICE,
4338 .prot_l1 = PMD_TYPE_TABLE,
4339- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4340+ .prot_sect = PROT_SECT_DEVICE,
4341 .domain = DOMAIN_IO,
4342 },
4343 [MT_CACHECLEAN] = {
4344- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4345+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4346 .domain = DOMAIN_KERNEL,
4347 },
4348 #ifndef CONFIG_ARM_LPAE
4349 [MT_MINICLEAN] = {
4350- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4351+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #endif
4355@@ -283,36 +307,54 @@ static struct mem_type mem_types[] = {
4356 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4357 L_PTE_RDONLY,
4358 .prot_l1 = PMD_TYPE_TABLE,
4359- .domain = DOMAIN_USER,
4360+ .domain = DOMAIN_VECTORS,
4361 },
4362 [MT_HIGH_VECTORS] = {
4363 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4364 L_PTE_USER | L_PTE_RDONLY,
4365 .prot_l1 = PMD_TYPE_TABLE,
4366- .domain = DOMAIN_USER,
4367+ .domain = DOMAIN_VECTORS,
4368 },
4369- [MT_MEMORY] = {
4370+ [MT_MEMORY_RWX] = {
4371 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4372 .prot_l1 = PMD_TYPE_TABLE,
4373 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4374 .domain = DOMAIN_KERNEL,
4375 },
4376+ [MT_MEMORY_RW] = {
4377+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378+ .prot_l1 = PMD_TYPE_TABLE,
4379+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380+ .domain = DOMAIN_KERNEL,
4381+ },
4382+ [MT_MEMORY_RX] = {
4383+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4384+ .prot_l1 = PMD_TYPE_TABLE,
4385+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4386+ .domain = DOMAIN_KERNEL,
4387+ },
4388 [MT_ROM] = {
4389- .prot_sect = PMD_TYPE_SECT,
4390+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4391 .domain = DOMAIN_KERNEL,
4392 },
4393- [MT_MEMORY_NONCACHED] = {
4394+ [MT_MEMORY_NONCACHED_RW] = {
4395 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4396 L_PTE_MT_BUFFERABLE,
4397 .prot_l1 = PMD_TYPE_TABLE,
4398 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4399 .domain = DOMAIN_KERNEL,
4400 },
4401+ [MT_MEMORY_NONCACHED_RX] = {
4402+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4403+ L_PTE_MT_BUFFERABLE,
4404+ .prot_l1 = PMD_TYPE_TABLE,
4405+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4406+ .domain = DOMAIN_KERNEL,
4407+ },
4408 [MT_MEMORY_DTCM] = {
4409- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4410- L_PTE_XN,
4411+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4412 .prot_l1 = PMD_TYPE_TABLE,
4413- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4414+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4415 .domain = DOMAIN_KERNEL,
4416 },
4417 [MT_MEMORY_ITCM] = {
4418@@ -322,10 +364,10 @@ static struct mem_type mem_types[] = {
4419 },
4420 [MT_MEMORY_SO] = {
4421 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4422- L_PTE_MT_UNCACHED | L_PTE_XN,
4423+ L_PTE_MT_UNCACHED,
4424 .prot_l1 = PMD_TYPE_TABLE,
4425 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4426- PMD_SECT_UNCACHED | PMD_SECT_XN,
4427+ PMD_SECT_UNCACHED,
4428 .domain = DOMAIN_KERNEL,
4429 },
4430 [MT_MEMORY_DMA_READY] = {
4431@@ -411,9 +453,35 @@ static void __init build_mem_type_table(void)
4432 * to prevent speculative instruction fetches.
4433 */
4434 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4435+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4436 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4437+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4438 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4439+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4440 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4441+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4442+
4443+ /* Mark other regions on ARMv6+ as execute-never */
4444+
4445+#ifdef CONFIG_PAX_KERNEXEC
4446+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4447+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4448+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4449+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4450+#ifndef CONFIG_ARM_LPAE
4451+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4452+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4453+#endif
4454+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4455+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4456+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4457+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4458+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4459+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4460+#endif
4461+
4462+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4463+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4464 }
4465 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4466 /*
4467@@ -475,6 +543,9 @@ static void __init build_mem_type_table(void)
4468 * from SVC mode and no access from userspace.
4469 */
4470 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4471+#ifdef CONFIG_PAX_KERNEXEC
4472+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4473+#endif
4474 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4475 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4476 #endif
4477@@ -492,11 +563,17 @@ static void __init build_mem_type_table(void)
4478 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4479 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4480 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4481- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4482- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4483+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4484+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4485+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4486+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4487+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4488+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4489 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4490- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4491- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4492+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4493+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4494+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4495+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4496 }
4497 }
4498
4499@@ -507,15 +584,20 @@ static void __init build_mem_type_table(void)
4500 if (cpu_arch >= CPU_ARCH_ARMv6) {
4501 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4502 /* Non-cacheable Normal is XCB = 001 */
4503- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4504+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4505+ PMD_SECT_BUFFERED;
4506+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4507 PMD_SECT_BUFFERED;
4508 } else {
4509 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4510- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4511+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4512+ PMD_SECT_TEX(1);
4513+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4514 PMD_SECT_TEX(1);
4515 }
4516 } else {
4517- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4518+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4519+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4520 }
4521
4522 #ifdef CONFIG_ARM_LPAE
4523@@ -531,6 +613,8 @@ static void __init build_mem_type_table(void)
4524 vecs_pgprot |= PTE_EXT_AF;
4525 #endif
4526
4527+ user_pgprot |= __supported_pte_mask;
4528+
4529 for (i = 0; i < 16; i++) {
4530 pteval_t v = pgprot_val(protection_map[i]);
4531 protection_map[i] = __pgprot(v | user_pgprot);
4532@@ -548,10 +632,15 @@ static void __init build_mem_type_table(void)
4533
4534 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4535 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4536- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4537- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4538+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4539+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4540+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4541+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4542+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4543+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4544 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4545- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4546+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4547+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4548 mem_types[MT_ROM].prot_sect |= cp->pmd;
4549
4550 switch (cp->pmd) {
4551@@ -1193,18 +1282,15 @@ void __init arm_mm_memblock_reserve(void)
4552 * called function. This means you can't use any function or debugging
4553 * method which may touch any device, otherwise the kernel _will_ crash.
4554 */
4555+
4556+static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4557+
4558 static void __init devicemaps_init(const struct machine_desc *mdesc)
4559 {
4560 struct map_desc map;
4561 unsigned long addr;
4562- void *vectors;
4563
4564- /*
4565- * Allocate the vector page early.
4566- */
4567- vectors = early_alloc(PAGE_SIZE * 2);
4568-
4569- early_trap_init(vectors);
4570+ early_trap_init(&vectors);
4571
4572 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4573 pmd_clear(pmd_off_k(addr));
4574@@ -1244,7 +1330,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4575 * location (0xffff0000). If we aren't using high-vectors, also
4576 * create a mapping at the low-vectors virtual address.
4577 */
4578- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4579+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4580 map.virtual = 0xffff0000;
4581 map.length = PAGE_SIZE;
4582 #ifdef CONFIG_KUSER_HELPERS
4583@@ -1316,8 +1402,39 @@ static void __init map_lowmem(void)
4584 map.pfn = __phys_to_pfn(start);
4585 map.virtual = __phys_to_virt(start);
4586 map.length = end - start;
4587- map.type = MT_MEMORY;
4588
4589+#ifdef CONFIG_PAX_KERNEXEC
4590+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4591+ struct map_desc kernel;
4592+ struct map_desc initmap;
4593+
4594+ /* when freeing initmem we will make this RW */
4595+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4596+ initmap.virtual = (unsigned long)__init_begin;
4597+ initmap.length = _sdata - __init_begin;
4598+ initmap.type = MT_MEMORY_RWX;
4599+ create_mapping(&initmap);
4600+
4601+ /* when freeing initmem we will make this RX */
4602+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4603+ kernel.virtual = (unsigned long)_stext;
4604+ kernel.length = __init_begin - _stext;
4605+ kernel.type = MT_MEMORY_RWX;
4606+ create_mapping(&kernel);
4607+
4608+ if (map.virtual < (unsigned long)_stext) {
4609+ map.length = (unsigned long)_stext - map.virtual;
4610+ map.type = MT_MEMORY_RWX;
4611+ create_mapping(&map);
4612+ }
4613+
4614+ map.pfn = __phys_to_pfn(__pa(_sdata));
4615+ map.virtual = (unsigned long)_sdata;
4616+ map.length = end - __pa(_sdata);
4617+ }
4618+#endif
4619+
4620+ map.type = MT_MEMORY_RW;
4621 create_mapping(&map);
4622 }
4623 }
4624diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4625index a5bc92d..0bb4730 100644
4626--- a/arch/arm/plat-omap/sram.c
4627+++ b/arch/arm/plat-omap/sram.c
4628@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4629 * Looks like we need to preserve some bootloader code at the
4630 * beginning of SRAM for jumping to flash for reboot to work...
4631 */
4632+ pax_open_kernel();
4633 memset_io(omap_sram_base + omap_sram_skip, 0,
4634 omap_sram_size - omap_sram_skip);
4635+ pax_close_kernel();
4636 }
4637diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4638index ce6d763..cfea917 100644
4639--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4640+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4641@@ -47,7 +47,7 @@ struct samsung_dma_ops {
4642 int (*started)(unsigned ch);
4643 int (*flush)(unsigned ch);
4644 int (*stop)(unsigned ch);
4645-};
4646+} __no_const;
4647
4648 extern void *samsung_dmadev_get_ops(void);
4649 extern void *s3c_dma_get_ops(void);
4650diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4651index 7ecc2b2..5e56c66 100644
4652--- a/arch/arm64/include/asm/uaccess.h
4653+++ b/arch/arm64/include/asm/uaccess.h
4654@@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4655 flag; \
4656 })
4657
4658+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4659 #define access_ok(type, addr, size) __range_ok(addr, size)
4660
4661 /*
4662diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4663index c3a58a1..78fbf54 100644
4664--- a/arch/avr32/include/asm/cache.h
4665+++ b/arch/avr32/include/asm/cache.h
4666@@ -1,8 +1,10 @@
4667 #ifndef __ASM_AVR32_CACHE_H
4668 #define __ASM_AVR32_CACHE_H
4669
4670+#include <linux/const.h>
4671+
4672 #define L1_CACHE_SHIFT 5
4673-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4674+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4675
4676 /*
4677 * Memory returned by kmalloc() may be used for DMA, so we must make
4678diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4679index d232888..87c8df1 100644
4680--- a/arch/avr32/include/asm/elf.h
4681+++ b/arch/avr32/include/asm/elf.h
4682@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4683 the loader. We need to make sure that it is out of the way of the program
4684 that it will "exec", and that there is sufficient room for the brk. */
4685
4686-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4687+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4688
4689+#ifdef CONFIG_PAX_ASLR
4690+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4691+
4692+#define PAX_DELTA_MMAP_LEN 15
4693+#define PAX_DELTA_STACK_LEN 15
4694+#endif
4695
4696 /* This yields a mask that user programs can use to figure out what
4697 instruction set this CPU supports. This could be done in user space,
4698diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4699index 479330b..53717a8 100644
4700--- a/arch/avr32/include/asm/kmap_types.h
4701+++ b/arch/avr32/include/asm/kmap_types.h
4702@@ -2,9 +2,9 @@
4703 #define __ASM_AVR32_KMAP_TYPES_H
4704
4705 #ifdef CONFIG_DEBUG_HIGHMEM
4706-# define KM_TYPE_NR 29
4707+# define KM_TYPE_NR 30
4708 #else
4709-# define KM_TYPE_NR 14
4710+# define KM_TYPE_NR 15
4711 #endif
4712
4713 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4714diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4715index 0eca933..eb78c7b 100644
4716--- a/arch/avr32/mm/fault.c
4717+++ b/arch/avr32/mm/fault.c
4718@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4719
4720 int exception_trace = 1;
4721
4722+#ifdef CONFIG_PAX_PAGEEXEC
4723+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4724+{
4725+ unsigned long i;
4726+
4727+ printk(KERN_ERR "PAX: bytes at PC: ");
4728+ for (i = 0; i < 20; i++) {
4729+ unsigned char c;
4730+ if (get_user(c, (unsigned char *)pc+i))
4731+ printk(KERN_CONT "???????? ");
4732+ else
4733+ printk(KERN_CONT "%02x ", c);
4734+ }
4735+ printk("\n");
4736+}
4737+#endif
4738+
4739 /*
4740 * This routine handles page faults. It determines the address and the
4741 * problem, and then passes it off to one of the appropriate routines.
4742@@ -176,6 +193,16 @@ bad_area:
4743 up_read(&mm->mmap_sem);
4744
4745 if (user_mode(regs)) {
4746+
4747+#ifdef CONFIG_PAX_PAGEEXEC
4748+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4749+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4750+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4751+ do_group_exit(SIGKILL);
4752+ }
4753+ }
4754+#endif
4755+
4756 if (exception_trace && printk_ratelimit())
4757 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4758 "sp %08lx ecr %lu\n",
4759diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4760index 568885a..f8008df 100644
4761--- a/arch/blackfin/include/asm/cache.h
4762+++ b/arch/blackfin/include/asm/cache.h
4763@@ -7,6 +7,7 @@
4764 #ifndef __ARCH_BLACKFIN_CACHE_H
4765 #define __ARCH_BLACKFIN_CACHE_H
4766
4767+#include <linux/const.h>
4768 #include <linux/linkage.h> /* for asmlinkage */
4769
4770 /*
4771@@ -14,7 +15,7 @@
4772 * Blackfin loads 32 bytes for cache
4773 */
4774 #define L1_CACHE_SHIFT 5
4775-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4776+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4777 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4778
4779 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4780diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4781index aea2718..3639a60 100644
4782--- a/arch/cris/include/arch-v10/arch/cache.h
4783+++ b/arch/cris/include/arch-v10/arch/cache.h
4784@@ -1,8 +1,9 @@
4785 #ifndef _ASM_ARCH_CACHE_H
4786 #define _ASM_ARCH_CACHE_H
4787
4788+#include <linux/const.h>
4789 /* Etrax 100LX have 32-byte cache-lines. */
4790-#define L1_CACHE_BYTES 32
4791 #define L1_CACHE_SHIFT 5
4792+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4793
4794 #endif /* _ASM_ARCH_CACHE_H */
4795diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4796index 7caf25d..ee65ac5 100644
4797--- a/arch/cris/include/arch-v32/arch/cache.h
4798+++ b/arch/cris/include/arch-v32/arch/cache.h
4799@@ -1,11 +1,12 @@
4800 #ifndef _ASM_CRIS_ARCH_CACHE_H
4801 #define _ASM_CRIS_ARCH_CACHE_H
4802
4803+#include <linux/const.h>
4804 #include <arch/hwregs/dma.h>
4805
4806 /* A cache-line is 32 bytes. */
4807-#define L1_CACHE_BYTES 32
4808 #define L1_CACHE_SHIFT 5
4809+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4810
4811 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4812
4813diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4814index b86329d..6709906 100644
4815--- a/arch/frv/include/asm/atomic.h
4816+++ b/arch/frv/include/asm/atomic.h
4817@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4818 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4819 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4820
4821+#define atomic64_read_unchecked(v) atomic64_read(v)
4822+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4823+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4824+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4825+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4826+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4827+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4828+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4829+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4830+
4831 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4832 {
4833 int c, old;
4834diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4835index 2797163..c2a401d 100644
4836--- a/arch/frv/include/asm/cache.h
4837+++ b/arch/frv/include/asm/cache.h
4838@@ -12,10 +12,11 @@
4839 #ifndef __ASM_CACHE_H
4840 #define __ASM_CACHE_H
4841
4842+#include <linux/const.h>
4843
4844 /* bytes per L1 cache line */
4845 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4846-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4847+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4848
4849 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4850 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4851diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4852index 43901f2..0d8b865 100644
4853--- a/arch/frv/include/asm/kmap_types.h
4854+++ b/arch/frv/include/asm/kmap_types.h
4855@@ -2,6 +2,6 @@
4856 #ifndef _ASM_KMAP_TYPES_H
4857 #define _ASM_KMAP_TYPES_H
4858
4859-#define KM_TYPE_NR 17
4860+#define KM_TYPE_NR 18
4861
4862 #endif
4863diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4864index 836f147..4cf23f5 100644
4865--- a/arch/frv/mm/elf-fdpic.c
4866+++ b/arch/frv/mm/elf-fdpic.c
4867@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4868 {
4869 struct vm_area_struct *vma;
4870 struct vm_unmapped_area_info info;
4871+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4872
4873 if (len > TASK_SIZE)
4874 return -ENOMEM;
4875@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4876 if (addr) {
4877 addr = PAGE_ALIGN(addr);
4878 vma = find_vma(current->mm, addr);
4879- if (TASK_SIZE - len >= addr &&
4880- (!vma || addr + len <= vma->vm_start))
4881+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4882 goto success;
4883 }
4884
4885@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4886 info.high_limit = (current->mm->start_stack - 0x00200000);
4887 info.align_mask = 0;
4888 info.align_offset = 0;
4889+ info.threadstack_offset = offset;
4890 addr = vm_unmapped_area(&info);
4891 if (!(addr & ~PAGE_MASK))
4892 goto success;
4893diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4894index f4ca594..adc72fd6 100644
4895--- a/arch/hexagon/include/asm/cache.h
4896+++ b/arch/hexagon/include/asm/cache.h
4897@@ -21,9 +21,11 @@
4898 #ifndef __ASM_CACHE_H
4899 #define __ASM_CACHE_H
4900
4901+#include <linux/const.h>
4902+
4903 /* Bytes per L1 cache line */
4904-#define L1_CACHE_SHIFT (5)
4905-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4906+#define L1_CACHE_SHIFT 5
4907+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4908
4909 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4910 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4911diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4912index 4e4119b..dd7de0a 100644
4913--- a/arch/ia64/Kconfig
4914+++ b/arch/ia64/Kconfig
4915@@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4916 config KEXEC
4917 bool "kexec system call"
4918 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4919+ depends on !GRKERNSEC_KMEM
4920 help
4921 kexec is a system call that implements the ability to shutdown your
4922 current kernel, and to start another kernel. It is like a reboot
4923diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4924index 6e6fe18..a6ae668 100644
4925--- a/arch/ia64/include/asm/atomic.h
4926+++ b/arch/ia64/include/asm/atomic.h
4927@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4928 #define atomic64_inc(v) atomic64_add(1, (v))
4929 #define atomic64_dec(v) atomic64_sub(1, (v))
4930
4931+#define atomic64_read_unchecked(v) atomic64_read(v)
4932+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4933+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4934+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4935+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4936+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4937+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4938+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4939+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4940+
4941 /* Atomic operations are already serializing */
4942 #define smp_mb__before_atomic_dec() barrier()
4943 #define smp_mb__after_atomic_dec() barrier()
4944diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4945index 988254a..e1ee885 100644
4946--- a/arch/ia64/include/asm/cache.h
4947+++ b/arch/ia64/include/asm/cache.h
4948@@ -1,6 +1,7 @@
4949 #ifndef _ASM_IA64_CACHE_H
4950 #define _ASM_IA64_CACHE_H
4951
4952+#include <linux/const.h>
4953
4954 /*
4955 * Copyright (C) 1998-2000 Hewlett-Packard Co
4956@@ -9,7 +10,7 @@
4957
4958 /* Bytes per L1 (data) cache line. */
4959 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4960-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4961+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4962
4963 #ifdef CONFIG_SMP
4964 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4965diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4966index 5a83c5c..4d7f553 100644
4967--- a/arch/ia64/include/asm/elf.h
4968+++ b/arch/ia64/include/asm/elf.h
4969@@ -42,6 +42,13 @@
4970 */
4971 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4972
4973+#ifdef CONFIG_PAX_ASLR
4974+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4975+
4976+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4977+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4978+#endif
4979+
4980 #define PT_IA_64_UNWIND 0x70000001
4981
4982 /* IA-64 relocations: */
4983diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4984index 5767cdf..7462574 100644
4985--- a/arch/ia64/include/asm/pgalloc.h
4986+++ b/arch/ia64/include/asm/pgalloc.h
4987@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4988 pgd_val(*pgd_entry) = __pa(pud);
4989 }
4990
4991+static inline void
4992+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4993+{
4994+ pgd_populate(mm, pgd_entry, pud);
4995+}
4996+
4997 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4998 {
4999 return quicklist_alloc(0, GFP_KERNEL, NULL);
5000@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5001 pud_val(*pud_entry) = __pa(pmd);
5002 }
5003
5004+static inline void
5005+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5006+{
5007+ pud_populate(mm, pud_entry, pmd);
5008+}
5009+
5010 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5011 {
5012 return quicklist_alloc(0, GFP_KERNEL, NULL);
5013diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5014index 7935115..c0eca6a 100644
5015--- a/arch/ia64/include/asm/pgtable.h
5016+++ b/arch/ia64/include/asm/pgtable.h
5017@@ -12,7 +12,7 @@
5018 * David Mosberger-Tang <davidm@hpl.hp.com>
5019 */
5020
5021-
5022+#include <linux/const.h>
5023 #include <asm/mman.h>
5024 #include <asm/page.h>
5025 #include <asm/processor.h>
5026@@ -142,6 +142,17 @@
5027 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5030+
5031+#ifdef CONFIG_PAX_PAGEEXEC
5032+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5033+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5034+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5035+#else
5036+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5037+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5038+# define PAGE_COPY_NOEXEC PAGE_COPY
5039+#endif
5040+
5041 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5042 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5043 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5044diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5045index 45698cd..e8e2dbc 100644
5046--- a/arch/ia64/include/asm/spinlock.h
5047+++ b/arch/ia64/include/asm/spinlock.h
5048@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5049 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5050
5051 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5052- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5053+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5054 }
5055
5056 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5057diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5058index 449c8c0..3d4b1e9 100644
5059--- a/arch/ia64/include/asm/uaccess.h
5060+++ b/arch/ia64/include/asm/uaccess.h
5061@@ -70,6 +70,7 @@
5062 && ((segment).seg == KERNEL_DS.seg \
5063 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5064 })
5065+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5066 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5067
5068 /*
5069@@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5070 static inline unsigned long
5071 __copy_to_user (void __user *to, const void *from, unsigned long count)
5072 {
5073+ if (count > INT_MAX)
5074+ return count;
5075+
5076+ if (!__builtin_constant_p(count))
5077+ check_object_size(from, count, true);
5078+
5079 return __copy_user(to, (__force void __user *) from, count);
5080 }
5081
5082 static inline unsigned long
5083 __copy_from_user (void *to, const void __user *from, unsigned long count)
5084 {
5085+ if (count > INT_MAX)
5086+ return count;
5087+
5088+ if (!__builtin_constant_p(count))
5089+ check_object_size(to, count, false);
5090+
5091 return __copy_user((__force void __user *) to, from, count);
5092 }
5093
5094@@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5095 ({ \
5096 void __user *__cu_to = (to); \
5097 const void *__cu_from = (from); \
5098- long __cu_len = (n); \
5099+ unsigned long __cu_len = (n); \
5100 \
5101- if (__access_ok(__cu_to, __cu_len, get_fs())) \
5102+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5103+ if (!__builtin_constant_p(n)) \
5104+ check_object_size(__cu_from, __cu_len, true); \
5105 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5106+ } \
5107 __cu_len; \
5108 })
5109
5110@@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5111 ({ \
5112 void *__cu_to = (to); \
5113 const void __user *__cu_from = (from); \
5114- long __cu_len = (n); \
5115+ unsigned long __cu_len = (n); \
5116 \
5117 __chk_user_ptr(__cu_from); \
5118- if (__access_ok(__cu_from, __cu_len, get_fs())) \
5119+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5120+ if (!__builtin_constant_p(n)) \
5121+ check_object_size(__cu_to, __cu_len, false); \
5122 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5123+ } \
5124 __cu_len; \
5125 })
5126
5127diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5128index 24603be..948052d 100644
5129--- a/arch/ia64/kernel/module.c
5130+++ b/arch/ia64/kernel/module.c
5131@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5132 void
5133 module_free (struct module *mod, void *module_region)
5134 {
5135- if (mod && mod->arch.init_unw_table &&
5136- module_region == mod->module_init) {
5137+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5138 unw_remove_unwind_table(mod->arch.init_unw_table);
5139 mod->arch.init_unw_table = NULL;
5140 }
5141@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5142 }
5143
5144 static inline int
5145+in_init_rx (const struct module *mod, uint64_t addr)
5146+{
5147+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5148+}
5149+
5150+static inline int
5151+in_init_rw (const struct module *mod, uint64_t addr)
5152+{
5153+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5154+}
5155+
5156+static inline int
5157 in_init (const struct module *mod, uint64_t addr)
5158 {
5159- return addr - (uint64_t) mod->module_init < mod->init_size;
5160+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5161+}
5162+
5163+static inline int
5164+in_core_rx (const struct module *mod, uint64_t addr)
5165+{
5166+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5167+}
5168+
5169+static inline int
5170+in_core_rw (const struct module *mod, uint64_t addr)
5171+{
5172+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5173 }
5174
5175 static inline int
5176 in_core (const struct module *mod, uint64_t addr)
5177 {
5178- return addr - (uint64_t) mod->module_core < mod->core_size;
5179+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5180 }
5181
5182 static inline int
5183@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5184 break;
5185
5186 case RV_BDREL:
5187- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5188+ if (in_init_rx(mod, val))
5189+ val -= (uint64_t) mod->module_init_rx;
5190+ else if (in_init_rw(mod, val))
5191+ val -= (uint64_t) mod->module_init_rw;
5192+ else if (in_core_rx(mod, val))
5193+ val -= (uint64_t) mod->module_core_rx;
5194+ else if (in_core_rw(mod, val))
5195+ val -= (uint64_t) mod->module_core_rw;
5196 break;
5197
5198 case RV_LTV:
5199@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5200 * addresses have been selected...
5201 */
5202 uint64_t gp;
5203- if (mod->core_size > MAX_LTOFF)
5204+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5205 /*
5206 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5207 * at the end of the module.
5208 */
5209- gp = mod->core_size - MAX_LTOFF / 2;
5210+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5211 else
5212- gp = mod->core_size / 2;
5213- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5214+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5215+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5216 mod->arch.gp = gp;
5217 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5218 }
5219diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5220index ab33328..f39506c 100644
5221--- a/arch/ia64/kernel/palinfo.c
5222+++ b/arch/ia64/kernel/palinfo.c
5223@@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5224 return NOTIFY_OK;
5225 }
5226
5227-static struct notifier_block __refdata palinfo_cpu_notifier =
5228+static struct notifier_block palinfo_cpu_notifier =
5229 {
5230 .notifier_call = palinfo_cpu_callback,
5231 .priority = 0,
5232diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5233index 41e33f8..65180b2a 100644
5234--- a/arch/ia64/kernel/sys_ia64.c
5235+++ b/arch/ia64/kernel/sys_ia64.c
5236@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5237 unsigned long align_mask = 0;
5238 struct mm_struct *mm = current->mm;
5239 struct vm_unmapped_area_info info;
5240+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5241
5242 if (len > RGN_MAP_LIMIT)
5243 return -ENOMEM;
5244@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 if (REGION_NUMBER(addr) == RGN_HPAGE)
5246 addr = 0;
5247 #endif
5248+
5249+#ifdef CONFIG_PAX_RANDMMAP
5250+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5251+ addr = mm->free_area_cache;
5252+ else
5253+#endif
5254+
5255 if (!addr)
5256 addr = TASK_UNMAPPED_BASE;
5257
5258@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5259 info.high_limit = TASK_SIZE;
5260 info.align_mask = align_mask;
5261 info.align_offset = 0;
5262+ info.threadstack_offset = offset;
5263 return vm_unmapped_area(&info);
5264 }
5265
5266diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5267index 0ccb28f..8992469 100644
5268--- a/arch/ia64/kernel/vmlinux.lds.S
5269+++ b/arch/ia64/kernel/vmlinux.lds.S
5270@@ -198,7 +198,7 @@ SECTIONS {
5271 /* Per-cpu data: */
5272 . = ALIGN(PERCPU_PAGE_SIZE);
5273 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5274- __phys_per_cpu_start = __per_cpu_load;
5275+ __phys_per_cpu_start = per_cpu_load;
5276 /*
5277 * ensure percpu data fits
5278 * into percpu page size
5279diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5280index 7225dad..2a7c8256 100644
5281--- a/arch/ia64/mm/fault.c
5282+++ b/arch/ia64/mm/fault.c
5283@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5284 return pte_present(pte);
5285 }
5286
5287+#ifdef CONFIG_PAX_PAGEEXEC
5288+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5289+{
5290+ unsigned long i;
5291+
5292+ printk(KERN_ERR "PAX: bytes at PC: ");
5293+ for (i = 0; i < 8; i++) {
5294+ unsigned int c;
5295+ if (get_user(c, (unsigned int *)pc+i))
5296+ printk(KERN_CONT "???????? ");
5297+ else
5298+ printk(KERN_CONT "%08x ", c);
5299+ }
5300+ printk("\n");
5301+}
5302+#endif
5303+
5304 # define VM_READ_BIT 0
5305 # define VM_WRITE_BIT 1
5306 # define VM_EXEC_BIT 2
5307@@ -151,8 +168,21 @@ retry:
5308 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5309 goto bad_area;
5310
5311- if ((vma->vm_flags & mask) != mask)
5312+ if ((vma->vm_flags & mask) != mask) {
5313+
5314+#ifdef CONFIG_PAX_PAGEEXEC
5315+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5316+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5317+ goto bad_area;
5318+
5319+ up_read(&mm->mmap_sem);
5320+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5321+ do_group_exit(SIGKILL);
5322+ }
5323+#endif
5324+
5325 goto bad_area;
5326+ }
5327
5328 /*
5329 * If for any reason at all we couldn't handle the fault, make
5330diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5331index 68232db..6ca80af 100644
5332--- a/arch/ia64/mm/hugetlbpage.c
5333+++ b/arch/ia64/mm/hugetlbpage.c
5334@@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5335 unsigned long pgoff, unsigned long flags)
5336 {
5337 struct vm_unmapped_area_info info;
5338+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5339
5340 if (len > RGN_MAP_LIMIT)
5341 return -ENOMEM;
5342@@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5343 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5344 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5345 info.align_offset = 0;
5346+ info.threadstack_offset = offset;
5347 return vm_unmapped_area(&info);
5348 }
5349
5350diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5351index 88504ab..cbb6c9f 100644
5352--- a/arch/ia64/mm/init.c
5353+++ b/arch/ia64/mm/init.c
5354@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5355 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5356 vma->vm_end = vma->vm_start + PAGE_SIZE;
5357 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5358+
5359+#ifdef CONFIG_PAX_PAGEEXEC
5360+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5361+ vma->vm_flags &= ~VM_EXEC;
5362+
5363+#ifdef CONFIG_PAX_MPROTECT
5364+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5365+ vma->vm_flags &= ~VM_MAYEXEC;
5366+#endif
5367+
5368+ }
5369+#endif
5370+
5371 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5372 down_write(&current->mm->mmap_sem);
5373 if (insert_vm_struct(current->mm, vma)) {
5374diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5375index 40b3ee9..8c2c112 100644
5376--- a/arch/m32r/include/asm/cache.h
5377+++ b/arch/m32r/include/asm/cache.h
5378@@ -1,8 +1,10 @@
5379 #ifndef _ASM_M32R_CACHE_H
5380 #define _ASM_M32R_CACHE_H
5381
5382+#include <linux/const.h>
5383+
5384 /* L1 cache line size */
5385 #define L1_CACHE_SHIFT 4
5386-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5387+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5388
5389 #endif /* _ASM_M32R_CACHE_H */
5390diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5391index 82abd15..d95ae5d 100644
5392--- a/arch/m32r/lib/usercopy.c
5393+++ b/arch/m32r/lib/usercopy.c
5394@@ -14,6 +14,9 @@
5395 unsigned long
5396 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5397 {
5398+ if ((long)n < 0)
5399+ return n;
5400+
5401 prefetch(from);
5402 if (access_ok(VERIFY_WRITE, to, n))
5403 __copy_user(to,from,n);
5404@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5405 unsigned long
5406 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5407 {
5408+ if ((long)n < 0)
5409+ return n;
5410+
5411 prefetchw(to);
5412 if (access_ok(VERIFY_READ, from, n))
5413 __copy_user_zeroing(to,from,n);
5414diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5415index 0395c51..5f26031 100644
5416--- a/arch/m68k/include/asm/cache.h
5417+++ b/arch/m68k/include/asm/cache.h
5418@@ -4,9 +4,11 @@
5419 #ifndef __ARCH_M68K_CACHE_H
5420 #define __ARCH_M68K_CACHE_H
5421
5422+#include <linux/const.h>
5423+
5424 /* bytes per L1 cache line */
5425 #define L1_CACHE_SHIFT 4
5426-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5427+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5428
5429 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5430
5431diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5432index 0424315..defcca9 100644
5433--- a/arch/metag/mm/hugetlbpage.c
5434+++ b/arch/metag/mm/hugetlbpage.c
5435@@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5436 info.high_limit = TASK_SIZE;
5437 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5438 info.align_offset = 0;
5439+ info.threadstack_offset = 0;
5440 return vm_unmapped_area(&info);
5441 }
5442
5443diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5444index 4efe96a..60e8699 100644
5445--- a/arch/microblaze/include/asm/cache.h
5446+++ b/arch/microblaze/include/asm/cache.h
5447@@ -13,11 +13,12 @@
5448 #ifndef _ASM_MICROBLAZE_CACHE_H
5449 #define _ASM_MICROBLAZE_CACHE_H
5450
5451+#include <linux/const.h>
5452 #include <asm/registers.h>
5453
5454 #define L1_CACHE_SHIFT 5
5455 /* word-granular cache in microblaze */
5456-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5457+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5458
5459 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5460
5461diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5462index 650de39..6982b02 100644
5463--- a/arch/mips/Kconfig
5464+++ b/arch/mips/Kconfig
5465@@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5466
5467 config KEXEC
5468 bool "Kexec system call"
5469+ depends on !GRKERNSEC_KMEM
5470 help
5471 kexec is a system call that implements the ability to shutdown your
5472 current kernel, and to start another kernel. It is like a reboot
5473diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5474index 02f2444..506969c 100644
5475--- a/arch/mips/cavium-octeon/dma-octeon.c
5476+++ b/arch/mips/cavium-octeon/dma-octeon.c
5477@@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5478 if (dma_release_from_coherent(dev, order, vaddr))
5479 return;
5480
5481- swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5482+ swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5483 }
5484
5485 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5486diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5487index 7eed2f2..c4e385d 100644
5488--- a/arch/mips/include/asm/atomic.h
5489+++ b/arch/mips/include/asm/atomic.h
5490@@ -21,15 +21,39 @@
5491 #include <asm/cmpxchg.h>
5492 #include <asm/war.h>
5493
5494+#ifdef CONFIG_GENERIC_ATOMIC64
5495+#include <asm-generic/atomic64.h>
5496+#endif
5497+
5498 #define ATOMIC_INIT(i) { (i) }
5499
5500+#ifdef CONFIG_64BIT
5501+#define _ASM_EXTABLE(from, to) \
5502+" .section __ex_table,\"a\"\n" \
5503+" .dword " #from ", " #to"\n" \
5504+" .previous\n"
5505+#else
5506+#define _ASM_EXTABLE(from, to) \
5507+" .section __ex_table,\"a\"\n" \
5508+" .word " #from ", " #to"\n" \
5509+" .previous\n"
5510+#endif
5511+
5512 /*
5513 * atomic_read - read atomic variable
5514 * @v: pointer of type atomic_t
5515 *
5516 * Atomically reads the value of @v.
5517 */
5518-#define atomic_read(v) (*(volatile int *)&(v)->counter)
5519+static inline int atomic_read(const atomic_t *v)
5520+{
5521+ return (*(volatile const int *) &v->counter);
5522+}
5523+
5524+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5525+{
5526+ return (*(volatile const int *) &v->counter);
5527+}
5528
5529 /*
5530 * atomic_set - set atomic variable
5531@@ -38,7 +62,15 @@
5532 *
5533 * Atomically sets the value of @v to @i.
5534 */
5535-#define atomic_set(v, i) ((v)->counter = (i))
5536+static inline void atomic_set(atomic_t *v, int i)
5537+{
5538+ v->counter = i;
5539+}
5540+
5541+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5542+{
5543+ v->counter = i;
5544+}
5545
5546 /*
5547 * atomic_add - add integer to atomic variable
5548@@ -47,7 +79,67 @@
5549 *
5550 * Atomically adds @i to @v.
5551 */
5552-static __inline__ void atomic_add(int i, atomic_t * v)
5553+static __inline__ void atomic_add(int i, atomic_t *v)
5554+{
5555+ int temp;
5556+
5557+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5558+ __asm__ __volatile__(
5559+ " .set mips3 \n"
5560+ "1: ll %0, %1 # atomic_add \n"
5561+#ifdef CONFIG_PAX_REFCOUNT
5562+ /* Exception on overflow. */
5563+ "2: add %0, %2 \n"
5564+#else
5565+ " addu %0, %2 \n"
5566+#endif
5567+ " sc %0, %1 \n"
5568+ " beqzl %0, 1b \n"
5569+#ifdef CONFIG_PAX_REFCOUNT
5570+ "3: \n"
5571+ _ASM_EXTABLE(2b, 3b)
5572+#endif
5573+ " .set mips0 \n"
5574+ : "=&r" (temp), "+m" (v->counter)
5575+ : "Ir" (i));
5576+ } else if (kernel_uses_llsc) {
5577+ __asm__ __volatile__(
5578+ " .set mips3 \n"
5579+ "1: ll %0, %1 # atomic_add \n"
5580+#ifdef CONFIG_PAX_REFCOUNT
5581+ /* Exception on overflow. */
5582+ "2: add %0, %2 \n"
5583+#else
5584+ " addu %0, %2 \n"
5585+#endif
5586+ " sc %0, %1 \n"
5587+ " beqz %0, 1b \n"
5588+#ifdef CONFIG_PAX_REFCOUNT
5589+ "3: \n"
5590+ _ASM_EXTABLE(2b, 3b)
5591+#endif
5592+ " .set mips0 \n"
5593+ : "=&r" (temp), "+m" (v->counter)
5594+ : "Ir" (i));
5595+ } else {
5596+ unsigned long flags;
5597+
5598+ raw_local_irq_save(flags);
5599+ __asm__ __volatile__(
5600+#ifdef CONFIG_PAX_REFCOUNT
5601+ /* Exception on overflow. */
5602+ "1: add %0, %1 \n"
5603+ "2: \n"
5604+ _ASM_EXTABLE(1b, 2b)
5605+#else
5606+ " addu %0, %1 \n"
5607+#endif
5608+ : "+r" (v->counter) : "Ir" (i));
5609+ raw_local_irq_restore(flags);
5610+ }
5611+}
5612+
5613+static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5614 {
5615 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5616 int temp;
5617@@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5618 *
5619 * Atomically subtracts @i from @v.
5620 */
5621-static __inline__ void atomic_sub(int i, atomic_t * v)
5622+static __inline__ void atomic_sub(int i, atomic_t *v)
5623+{
5624+ int temp;
5625+
5626+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5627+ __asm__ __volatile__(
5628+ " .set mips3 \n"
5629+ "1: ll %0, %1 # atomic64_sub \n"
5630+#ifdef CONFIG_PAX_REFCOUNT
5631+ /* Exception on overflow. */
5632+ "2: sub %0, %2 \n"
5633+#else
5634+ " subu %0, %2 \n"
5635+#endif
5636+ " sc %0, %1 \n"
5637+ " beqzl %0, 1b \n"
5638+#ifdef CONFIG_PAX_REFCOUNT
5639+ "3: \n"
5640+ _ASM_EXTABLE(2b, 3b)
5641+#endif
5642+ " .set mips0 \n"
5643+ : "=&r" (temp), "+m" (v->counter)
5644+ : "Ir" (i));
5645+ } else if (kernel_uses_llsc) {
5646+ __asm__ __volatile__(
5647+ " .set mips3 \n"
5648+ "1: ll %0, %1 # atomic64_sub \n"
5649+#ifdef CONFIG_PAX_REFCOUNT
5650+ /* Exception on overflow. */
5651+ "2: sub %0, %2 \n"
5652+#else
5653+ " subu %0, %2 \n"
5654+#endif
5655+ " sc %0, %1 \n"
5656+ " beqz %0, 1b \n"
5657+#ifdef CONFIG_PAX_REFCOUNT
5658+ "3: \n"
5659+ _ASM_EXTABLE(2b, 3b)
5660+#endif
5661+ " .set mips0 \n"
5662+ : "=&r" (temp), "+m" (v->counter)
5663+ : "Ir" (i));
5664+ } else {
5665+ unsigned long flags;
5666+
5667+ raw_local_irq_save(flags);
5668+ __asm__ __volatile__(
5669+#ifdef CONFIG_PAX_REFCOUNT
5670+ /* Exception on overflow. */
5671+ "1: sub %0, %1 \n"
5672+ "2: \n"
5673+ _ASM_EXTABLE(1b, 2b)
5674+#else
5675+ " subu %0, %1 \n"
5676+#endif
5677+ : "+r" (v->counter) : "Ir" (i));
5678+ raw_local_irq_restore(flags);
5679+ }
5680+}
5681+
5682+static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5683 {
5684 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5685 int temp;
5686@@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5687 /*
5688 * Same as above, but return the result value
5689 */
5690-static __inline__ int atomic_add_return(int i, atomic_t * v)
5691+static __inline__ int atomic_add_return(int i, atomic_t *v)
5692+{
5693+ int result;
5694+ int temp;
5695+
5696+ smp_mb__before_llsc();
5697+
5698+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5699+ __asm__ __volatile__(
5700+ " .set mips3 \n"
5701+ "1: ll %1, %2 # atomic_add_return \n"
5702+#ifdef CONFIG_PAX_REFCOUNT
5703+ "2: add %0, %1, %3 \n"
5704+#else
5705+ " addu %0, %1, %3 \n"
5706+#endif
5707+ " sc %0, %2 \n"
5708+ " beqzl %0, 1b \n"
5709+#ifdef CONFIG_PAX_REFCOUNT
5710+ " b 4f \n"
5711+ " .set noreorder \n"
5712+ "3: b 5f \n"
5713+ " move %0, %1 \n"
5714+ " .set reorder \n"
5715+ _ASM_EXTABLE(2b, 3b)
5716+#endif
5717+ "4: addu %0, %1, %3 \n"
5718+#ifdef CONFIG_PAX_REFCOUNT
5719+ "5: \n"
5720+#endif
5721+ " .set mips0 \n"
5722+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5723+ : "Ir" (i));
5724+ } else if (kernel_uses_llsc) {
5725+ __asm__ __volatile__(
5726+ " .set mips3 \n"
5727+ "1: ll %1, %2 # atomic_add_return \n"
5728+#ifdef CONFIG_PAX_REFCOUNT
5729+ "2: add %0, %1, %3 \n"
5730+#else
5731+ " addu %0, %1, %3 \n"
5732+#endif
5733+ " sc %0, %2 \n"
5734+ " bnez %0, 4f \n"
5735+ " b 1b \n"
5736+#ifdef CONFIG_PAX_REFCOUNT
5737+ " .set noreorder \n"
5738+ "3: b 5f \n"
5739+ " move %0, %1 \n"
5740+ " .set reorder \n"
5741+ _ASM_EXTABLE(2b, 3b)
5742+#endif
5743+ "4: addu %0, %1, %3 \n"
5744+#ifdef CONFIG_PAX_REFCOUNT
5745+ "5: \n"
5746+#endif
5747+ " .set mips0 \n"
5748+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5749+ : "Ir" (i));
5750+ } else {
5751+ unsigned long flags;
5752+
5753+ raw_local_irq_save(flags);
5754+ __asm__ __volatile__(
5755+ " lw %0, %1 \n"
5756+#ifdef CONFIG_PAX_REFCOUNT
5757+ /* Exception on overflow. */
5758+ "1: add %0, %2 \n"
5759+#else
5760+ " addu %0, %2 \n"
5761+#endif
5762+ " sw %0, %1 \n"
5763+#ifdef CONFIG_PAX_REFCOUNT
5764+ /* Note: Dest reg is not modified on overflow */
5765+ "2: \n"
5766+ _ASM_EXTABLE(1b, 2b)
5767+#endif
5768+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5769+ raw_local_irq_restore(flags);
5770+ }
5771+
5772+ smp_llsc_mb();
5773+
5774+ return result;
5775+}
5776+
5777+static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5778 {
5779 int result;
5780
5781@@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5782 return result;
5783 }
5784
5785-static __inline__ int atomic_sub_return(int i, atomic_t * v)
5786+static __inline__ int atomic_sub_return(int i, atomic_t *v)
5787+{
5788+ int result;
5789+ int temp;
5790+
5791+ smp_mb__before_llsc();
5792+
5793+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
5794+ __asm__ __volatile__(
5795+ " .set mips3 \n"
5796+ "1: ll %1, %2 # atomic_sub_return \n"
5797+#ifdef CONFIG_PAX_REFCOUNT
5798+ "2: sub %0, %1, %3 \n"
5799+#else
5800+ " subu %0, %1, %3 \n"
5801+#endif
5802+ " sc %0, %2 \n"
5803+ " beqzl %0, 1b \n"
5804+#ifdef CONFIG_PAX_REFCOUNT
5805+ " b 4f \n"
5806+ " .set noreorder \n"
5807+ "3: b 5f \n"
5808+ " move %0, %1 \n"
5809+ " .set reorder \n"
5810+ _ASM_EXTABLE(2b, 3b)
5811+#endif
5812+ "4: subu %0, %1, %3 \n"
5813+#ifdef CONFIG_PAX_REFCOUNT
5814+ "5: \n"
5815+#endif
5816+ " .set mips0 \n"
5817+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5818+ : "Ir" (i), "m" (v->counter)
5819+ : "memory");
5820+ } else if (kernel_uses_llsc) {
5821+ __asm__ __volatile__(
5822+ " .set mips3 \n"
5823+ "1: ll %1, %2 # atomic_sub_return \n"
5824+#ifdef CONFIG_PAX_REFCOUNT
5825+ "2: sub %0, %1, %3 \n"
5826+#else
5827+ " subu %0, %1, %3 \n"
5828+#endif
5829+ " sc %0, %2 \n"
5830+ " bnez %0, 4f \n"
5831+ " b 1b \n"
5832+#ifdef CONFIG_PAX_REFCOUNT
5833+ " .set noreorder \n"
5834+ "3: b 5f \n"
5835+ " move %0, %1 \n"
5836+ " .set reorder \n"
5837+ _ASM_EXTABLE(2b, 3b)
5838+#endif
5839+ "4: subu %0, %1, %3 \n"
5840+#ifdef CONFIG_PAX_REFCOUNT
5841+ "5: \n"
5842+#endif
5843+ " .set mips0 \n"
5844+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5845+ : "Ir" (i));
5846+ } else {
5847+ unsigned long flags;
5848+
5849+ raw_local_irq_save(flags);
5850+ __asm__ __volatile__(
5851+ " lw %0, %1 \n"
5852+#ifdef CONFIG_PAX_REFCOUNT
5853+ /* Exception on overflow. */
5854+ "1: sub %0, %2 \n"
5855+#else
5856+ " subu %0, %2 \n"
5857+#endif
5858+ " sw %0, %1 \n"
5859+#ifdef CONFIG_PAX_REFCOUNT
5860+ /* Note: Dest reg is not modified on overflow */
5861+ "2: \n"
5862+ _ASM_EXTABLE(1b, 2b)
5863+#endif
5864+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5865+ raw_local_irq_restore(flags);
5866+ }
5867+
5868+ smp_llsc_mb();
5869+
5870+ return result;
5871+}
5872+static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5873 {
5874 int result;
5875
5876@@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5877 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5878 * The function returns the old value of @v minus @i.
5879 */
5880-static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5881+static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5882 {
5883 int result;
5884
5885@@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5886 return result;
5887 }
5888
5889-#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5890-#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5891+static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5892+{
5893+ return cmpxchg(&v->counter, old, new);
5894+}
5895+
5896+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5897+ int new)
5898+{
5899+ return cmpxchg(&(v->counter), old, new);
5900+}
5901+
5902+static inline int atomic_xchg(atomic_t *v, int new)
5903+{
5904+ return xchg(&v->counter, new);
5905+}
5906+
5907+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5908+{
5909+ return xchg(&(v->counter), new);
5910+}
5911
5912 /**
5913 * __atomic_add_unless - add unless the number is a given value
5914@@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5915
5916 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5917 #define atomic_inc_return(v) atomic_add_return(1, (v))
5918+static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5919+{
5920+ return atomic_add_return_unchecked(1, v);
5921+}
5922
5923 /*
5924 * atomic_sub_and_test - subtract value from variable and test result
5925@@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5926 * other cases.
5927 */
5928 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5929+static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5930+{
5931+ return atomic_add_return_unchecked(1, v) == 0;
5932+}
5933
5934 /*
5935 * atomic_dec_and_test - decrement by 1 and test
5936@@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5937 * Atomically increments @v by 1.
5938 */
5939 #define atomic_inc(v) atomic_add(1, (v))
5940+static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5941+{
5942+ atomic_add_unchecked(1, v);
5943+}
5944
5945 /*
5946 * atomic_dec - decrement and test
5947@@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5948 * Atomically decrements @v by 1.
5949 */
5950 #define atomic_dec(v) atomic_sub(1, (v))
5951+static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5952+{
5953+ atomic_sub_unchecked(1, v);
5954+}
5955
5956 /*
5957 * atomic_add_negative - add and test if negative
5958@@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5959 * @v: pointer of type atomic64_t
5960 *
5961 */
5962-#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5963+static inline long atomic64_read(const atomic64_t *v)
5964+{
5965+ return (*(volatile const long *) &v->counter);
5966+}
5967+
5968+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5969+{
5970+ return (*(volatile const long *) &v->counter);
5971+}
5972
5973 /*
5974 * atomic64_set - set atomic variable
5975 * @v: pointer of type atomic64_t
5976 * @i: required value
5977 */
5978-#define atomic64_set(v, i) ((v)->counter = (i))
5979+static inline void atomic64_set(atomic64_t *v, long i)
5980+{
5981+ v->counter = i;
5982+}
5983+
5984+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5985+{
5986+ v->counter = i;
5987+}
5988
5989 /*
5990 * atomic64_add - add integer to atomic variable
5991@@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5992 *
5993 * Atomically adds @i to @v.
5994 */
5995-static __inline__ void atomic64_add(long i, atomic64_t * v)
5996+static __inline__ void atomic64_add(long i, atomic64_t *v)
5997+{
5998+ long temp;
5999+
6000+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6001+ __asm__ __volatile__(
6002+ " .set mips3 \n"
6003+ "1: lld %0, %1 # atomic64_add \n"
6004+#ifdef CONFIG_PAX_REFCOUNT
6005+ /* Exception on overflow. */
6006+ "2: dadd %0, %2 \n"
6007+#else
6008+ " daddu %0, %2 \n"
6009+#endif
6010+ " scd %0, %1 \n"
6011+ " beqzl %0, 1b \n"
6012+#ifdef CONFIG_PAX_REFCOUNT
6013+ "3: \n"
6014+ _ASM_EXTABLE(2b, 3b)
6015+#endif
6016+ " .set mips0 \n"
6017+ : "=&r" (temp), "+m" (v->counter)
6018+ : "Ir" (i));
6019+ } else if (kernel_uses_llsc) {
6020+ __asm__ __volatile__(
6021+ " .set mips3 \n"
6022+ "1: lld %0, %1 # atomic64_add \n"
6023+#ifdef CONFIG_PAX_REFCOUNT
6024+ /* Exception on overflow. */
6025+ "2: dadd %0, %2 \n"
6026+#else
6027+ " daddu %0, %2 \n"
6028+#endif
6029+ " scd %0, %1 \n"
6030+ " beqz %0, 1b \n"
6031+#ifdef CONFIG_PAX_REFCOUNT
6032+ "3: \n"
6033+ _ASM_EXTABLE(2b, 3b)
6034+#endif
6035+ " .set mips0 \n"
6036+ : "=&r" (temp), "+m" (v->counter)
6037+ : "Ir" (i));
6038+ } else {
6039+ unsigned long flags;
6040+
6041+ raw_local_irq_save(flags);
6042+ __asm__ __volatile__(
6043+#ifdef CONFIG_PAX_REFCOUNT
6044+ /* Exception on overflow. */
6045+ "1: dadd %0, %1 \n"
6046+ "2: \n"
6047+ _ASM_EXTABLE(1b, 2b)
6048+#else
6049+ " daddu %0, %1 \n"
6050+#endif
6051+ : "+r" (v->counter) : "Ir" (i));
6052+ raw_local_irq_restore(flags);
6053+ }
6054+}
6055+static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6056 {
6057 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6058 long temp;
6059@@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6060 *
6061 * Atomically subtracts @i from @v.
6062 */
6063-static __inline__ void atomic64_sub(long i, atomic64_t * v)
6064+static __inline__ void atomic64_sub(long i, atomic64_t *v)
6065+{
6066+ long temp;
6067+
6068+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6069+ __asm__ __volatile__(
6070+ " .set mips3 \n"
6071+ "1: lld %0, %1 # atomic64_sub \n"
6072+#ifdef CONFIG_PAX_REFCOUNT
6073+ /* Exception on overflow. */
6074+ "2: dsub %0, %2 \n"
6075+#else
6076+ " dsubu %0, %2 \n"
6077+#endif
6078+ " scd %0, %1 \n"
6079+ " beqzl %0, 1b \n"
6080+#ifdef CONFIG_PAX_REFCOUNT
6081+ "3: \n"
6082+ _ASM_EXTABLE(2b, 3b)
6083+#endif
6084+ " .set mips0 \n"
6085+ : "=&r" (temp), "+m" (v->counter)
6086+ : "Ir" (i));
6087+ } else if (kernel_uses_llsc) {
6088+ __asm__ __volatile__(
6089+ " .set mips3 \n"
6090+ "1: lld %0, %1 # atomic64_sub \n"
6091+#ifdef CONFIG_PAX_REFCOUNT
6092+ /* Exception on overflow. */
6093+ "2: dsub %0, %2 \n"
6094+#else
6095+ " dsubu %0, %2 \n"
6096+#endif
6097+ " scd %0, %1 \n"
6098+ " beqz %0, 1b \n"
6099+#ifdef CONFIG_PAX_REFCOUNT
6100+ "3: \n"
6101+ _ASM_EXTABLE(2b, 3b)
6102+#endif
6103+ " .set mips0 \n"
6104+ : "=&r" (temp), "+m" (v->counter)
6105+ : "Ir" (i));
6106+ } else {
6107+ unsigned long flags;
6108+
6109+ raw_local_irq_save(flags);
6110+ __asm__ __volatile__(
6111+#ifdef CONFIG_PAX_REFCOUNT
6112+ /* Exception on overflow. */
6113+ "1: dsub %0, %1 \n"
6114+ "2: \n"
6115+ _ASM_EXTABLE(1b, 2b)
6116+#else
6117+ " dsubu %0, %1 \n"
6118+#endif
6119+ : "+r" (v->counter) : "Ir" (i));
6120+ raw_local_irq_restore(flags);
6121+ }
6122+}
6123+
6124+static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6125 {
6126 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6127 long temp;
6128@@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6129 /*
6130 * Same as above, but return the result value
6131 */
6132-static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6133+static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6134+{
6135+ long result;
6136+ long temp;
6137+
6138+ smp_mb__before_llsc();
6139+
6140+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6141+ __asm__ __volatile__(
6142+ " .set mips3 \n"
6143+ "1: lld %1, %2 # atomic64_add_return \n"
6144+#ifdef CONFIG_PAX_REFCOUNT
6145+ "2: dadd %0, %1, %3 \n"
6146+#else
6147+ " daddu %0, %1, %3 \n"
6148+#endif
6149+ " scd %0, %2 \n"
6150+ " beqzl %0, 1b \n"
6151+#ifdef CONFIG_PAX_REFCOUNT
6152+ " b 4f \n"
6153+ " .set noreorder \n"
6154+ "3: b 5f \n"
6155+ " move %0, %1 \n"
6156+ " .set reorder \n"
6157+ _ASM_EXTABLE(2b, 3b)
6158+#endif
6159+ "4: daddu %0, %1, %3 \n"
6160+#ifdef CONFIG_PAX_REFCOUNT
6161+ "5: \n"
6162+#endif
6163+ " .set mips0 \n"
6164+ : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6165+ : "Ir" (i));
6166+ } else if (kernel_uses_llsc) {
6167+ __asm__ __volatile__(
6168+ " .set mips3 \n"
6169+ "1: lld %1, %2 # atomic64_add_return \n"
6170+#ifdef CONFIG_PAX_REFCOUNT
6171+ "2: dadd %0, %1, %3 \n"
6172+#else
6173+ " daddu %0, %1, %3 \n"
6174+#endif
6175+ " scd %0, %2 \n"
6176+ " bnez %0, 4f \n"
6177+ " b 1b \n"
6178+#ifdef CONFIG_PAX_REFCOUNT
6179+ " .set noreorder \n"
6180+ "3: b 5f \n"
6181+ " move %0, %1 \n"
6182+ " .set reorder \n"
6183+ _ASM_EXTABLE(2b, 3b)
6184+#endif
6185+ "4: daddu %0, %1, %3 \n"
6186+#ifdef CONFIG_PAX_REFCOUNT
6187+ "5: \n"
6188+#endif
6189+ " .set mips0 \n"
6190+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6191+ : "Ir" (i), "m" (v->counter)
6192+ : "memory");
6193+ } else {
6194+ unsigned long flags;
6195+
6196+ raw_local_irq_save(flags);
6197+ __asm__ __volatile__(
6198+ " ld %0, %1 \n"
6199+#ifdef CONFIG_PAX_REFCOUNT
6200+ /* Exception on overflow. */
6201+ "1: dadd %0, %2 \n"
6202+#else
6203+ " daddu %0, %2 \n"
6204+#endif
6205+ " sd %0, %1 \n"
6206+#ifdef CONFIG_PAX_REFCOUNT
6207+ /* Note: Dest reg is not modified on overflow */
6208+ "2: \n"
6209+ _ASM_EXTABLE(1b, 2b)
6210+#endif
6211+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6212+ raw_local_irq_restore(flags);
6213+ }
6214+
6215+ smp_llsc_mb();
6216+
6217+ return result;
6218+}
6219+static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6220 {
6221 long result;
6222
6223@@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6224 return result;
6225 }
6226
6227-static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6228+static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6229+{
6230+ long result;
6231+ long temp;
6232+
6233+ smp_mb__before_llsc();
6234+
6235+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6236+ long temp;
6237+
6238+ __asm__ __volatile__(
6239+ " .set mips3 \n"
6240+ "1: lld %1, %2 # atomic64_sub_return \n"
6241+#ifdef CONFIG_PAX_REFCOUNT
6242+ "2: dsub %0, %1, %3 \n"
6243+#else
6244+ " dsubu %0, %1, %3 \n"
6245+#endif
6246+ " scd %0, %2 \n"
6247+ " beqzl %0, 1b \n"
6248+#ifdef CONFIG_PAX_REFCOUNT
6249+ " b 4f \n"
6250+ " .set noreorder \n"
6251+ "3: b 5f \n"
6252+ " move %0, %1 \n"
6253+ " .set reorder \n"
6254+ _ASM_EXTABLE(2b, 3b)
6255+#endif
6256+ "4: dsubu %0, %1, %3 \n"
6257+#ifdef CONFIG_PAX_REFCOUNT
6258+ "5: \n"
6259+#endif
6260+ " .set mips0 \n"
6261+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262+ : "Ir" (i), "m" (v->counter)
6263+ : "memory");
6264+ } else if (kernel_uses_llsc) {
6265+ __asm__ __volatile__(
6266+ " .set mips3 \n"
6267+ "1: lld %1, %2 # atomic64_sub_return \n"
6268+#ifdef CONFIG_PAX_REFCOUNT
6269+ "2: dsub %0, %1, %3 \n"
6270+#else
6271+ " dsubu %0, %1, %3 \n"
6272+#endif
6273+ " scd %0, %2 \n"
6274+ " bnez %0, 4f \n"
6275+ " b 1b \n"
6276+#ifdef CONFIG_PAX_REFCOUNT
6277+ " .set noreorder \n"
6278+ "3: b 5f \n"
6279+ " move %0, %1 \n"
6280+ " .set reorder \n"
6281+ _ASM_EXTABLE(2b, 3b)
6282+#endif
6283+ "4: dsubu %0, %1, %3 \n"
6284+#ifdef CONFIG_PAX_REFCOUNT
6285+ "5: \n"
6286+#endif
6287+ " .set mips0 \n"
6288+ : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6289+ : "Ir" (i), "m" (v->counter)
6290+ : "memory");
6291+ } else {
6292+ unsigned long flags;
6293+
6294+ raw_local_irq_save(flags);
6295+ __asm__ __volatile__(
6296+ " ld %0, %1 \n"
6297+#ifdef CONFIG_PAX_REFCOUNT
6298+ /* Exception on overflow. */
6299+ "1: dsub %0, %2 \n"
6300+#else
6301+ " dsubu %0, %2 \n"
6302+#endif
6303+ " sd %0, %1 \n"
6304+#ifdef CONFIG_PAX_REFCOUNT
6305+ /* Note: Dest reg is not modified on overflow */
6306+ "2: \n"
6307+ _ASM_EXTABLE(1b, 2b)
6308+#endif
6309+ : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6310+ raw_local_irq_restore(flags);
6311+ }
6312+
6313+ smp_llsc_mb();
6314+
6315+ return result;
6316+}
6317+
6318+static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6319 {
6320 long result;
6321
6322@@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6323 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6324 * The function returns the old value of @v minus @i.
6325 */
6326-static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6327+static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6328 {
6329 long result;
6330
6331@@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6332 return result;
6333 }
6334
6335-#define atomic64_cmpxchg(v, o, n) \
6336- ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6337-#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6338+static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6339+{
6340+ return cmpxchg(&v->counter, old, new);
6341+}
6342+
6343+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6344+ long new)
6345+{
6346+ return cmpxchg(&(v->counter), old, new);
6347+}
6348+
6349+static inline long atomic64_xchg(atomic64_t *v, long new)
6350+{
6351+ return xchg(&v->counter, new);
6352+}
6353+
6354+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6355+{
6356+ return xchg(&(v->counter), new);
6357+}
6358
6359 /**
6360 * atomic64_add_unless - add unless the number is a given value
6361@@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6362
6363 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6364 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6365+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6366
6367 /*
6368 * atomic64_sub_and_test - subtract value from variable and test result
6369@@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6370 * other cases.
6371 */
6372 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6373+#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6374
6375 /*
6376 * atomic64_dec_and_test - decrement by 1 and test
6377@@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6378 * Atomically increments @v by 1.
6379 */
6380 #define atomic64_inc(v) atomic64_add(1, (v))
6381+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6382
6383 /*
6384 * atomic64_dec - decrement and test
6385@@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6386 * Atomically decrements @v by 1.
6387 */
6388 #define atomic64_dec(v) atomic64_sub(1, (v))
6389+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6390
6391 /*
6392 * atomic64_add_negative - add and test if negative
6393diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6394index b4db69f..8f3b093 100644
6395--- a/arch/mips/include/asm/cache.h
6396+++ b/arch/mips/include/asm/cache.h
6397@@ -9,10 +9,11 @@
6398 #ifndef _ASM_CACHE_H
6399 #define _ASM_CACHE_H
6400
6401+#include <linux/const.h>
6402 #include <kmalloc.h>
6403
6404 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6405-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6406+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6407
6408 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6409 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6410diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6411index a66359e..d3d474a 100644
6412--- a/arch/mips/include/asm/elf.h
6413+++ b/arch/mips/include/asm/elf.h
6414@@ -373,13 +373,16 @@ extern const char *__elf_platform;
6415 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6416 #endif
6417
6418+#ifdef CONFIG_PAX_ASLR
6419+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6420+
6421+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6422+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6423+#endif
6424+
6425 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6426 struct linux_binprm;
6427 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6428 int uses_interp);
6429
6430-struct mm_struct;
6431-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6432-#define arch_randomize_brk arch_randomize_brk
6433-
6434 #endif /* _ASM_ELF_H */
6435diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6436index c1f6afa..38cc6e9 100644
6437--- a/arch/mips/include/asm/exec.h
6438+++ b/arch/mips/include/asm/exec.h
6439@@ -12,6 +12,6 @@
6440 #ifndef _ASM_EXEC_H
6441 #define _ASM_EXEC_H
6442
6443-extern unsigned long arch_align_stack(unsigned long sp);
6444+#define arch_align_stack(x) ((x) & ~0xfUL)
6445
6446 #endif /* _ASM_EXEC_H */
6447diff --git a/arch/mips/include/asm/ftrace.h b/arch/mips/include/asm/ftrace.h
6448index ce35c9a..434321c 100644
6449--- a/arch/mips/include/asm/ftrace.h
6450+++ b/arch/mips/include/asm/ftrace.h
6451@@ -22,12 +22,12 @@ extern void _mcount(void);
6452 #define safe_load(load, src, dst, error) \
6453 do { \
6454 asm volatile ( \
6455- "1: " load " %[" STR(dst) "], 0(%[" STR(src) "])\n"\
6456- " li %[" STR(error) "], 0\n" \
6457+ "1: " load " %[dest], 0(%[source])\n" \
6458+ " li %[err], 0\n" \
6459 "2:\n" \
6460 \
6461 ".section .fixup, \"ax\"\n" \
6462- "3: li %[" STR(error) "], 1\n" \
6463+ "3: li %[err], 1\n" \
6464 " j 2b\n" \
6465 ".previous\n" \
6466 \
6467@@ -35,8 +35,8 @@ do { \
6468 STR(PTR) "\t1b, 3b\n\t" \
6469 ".previous\n" \
6470 \
6471- : [dst] "=&r" (dst), [error] "=r" (error)\
6472- : [src] "r" (src) \
6473+ : [dest] "=&r" (dst), [err] "=r" (error)\
6474+ : [source] "r" (src) \
6475 : "memory" \
6476 ); \
6477 } while (0)
6478@@ -44,12 +44,12 @@ do { \
6479 #define safe_store(store, src, dst, error) \
6480 do { \
6481 asm volatile ( \
6482- "1: " store " %[" STR(src) "], 0(%[" STR(dst) "])\n"\
6483- " li %[" STR(error) "], 0\n" \
6484+ "1: " store " %[source], 0(%[dest])\n"\
6485+ " li %[err], 0\n" \
6486 "2:\n" \
6487 \
6488 ".section .fixup, \"ax\"\n" \
6489- "3: li %[" STR(error) "], 1\n" \
6490+ "3: li %[err], 1\n" \
6491 " j 2b\n" \
6492 ".previous\n" \
6493 \
6494@@ -57,8 +57,8 @@ do { \
6495 STR(PTR) "\t1b, 3b\n\t" \
6496 ".previous\n" \
6497 \
6498- : [error] "=r" (error) \
6499- : [dst] "r" (dst), [src] "r" (src)\
6500+ : [err] "=r" (error) \
6501+ : [dest] "r" (dst), [source] "r" (src)\
6502 : "memory" \
6503 ); \
6504 } while (0)
6505diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6506index 9e8ef59..1139d6b 100644
6507--- a/arch/mips/include/asm/hw_irq.h
6508+++ b/arch/mips/include/asm/hw_irq.h
6509@@ -10,7 +10,7 @@
6510
6511 #include <linux/atomic.h>
6512
6513-extern atomic_t irq_err_count;
6514+extern atomic_unchecked_t irq_err_count;
6515
6516 /*
6517 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6518diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6519index d44622c..64990d2 100644
6520--- a/arch/mips/include/asm/local.h
6521+++ b/arch/mips/include/asm/local.h
6522@@ -12,15 +12,25 @@ typedef struct
6523 atomic_long_t a;
6524 } local_t;
6525
6526+typedef struct {
6527+ atomic_long_unchecked_t a;
6528+} local_unchecked_t;
6529+
6530 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6531
6532 #define local_read(l) atomic_long_read(&(l)->a)
6533+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6534 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6535+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6536
6537 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6538+#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6539 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6540+#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6541 #define local_inc(l) atomic_long_inc(&(l)->a)
6542+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6543 #define local_dec(l) atomic_long_dec(&(l)->a)
6544+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6545
6546 /*
6547 * Same as above, but return the result value
6548@@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6549 return result;
6550 }
6551
6552+static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6553+{
6554+ unsigned long result;
6555+
6556+ if (kernel_uses_llsc && R10000_LLSC_WAR) {
6557+ unsigned long temp;
6558+
6559+ __asm__ __volatile__(
6560+ " .set mips3 \n"
6561+ "1:" __LL "%1, %2 # local_add_return \n"
6562+ " addu %0, %1, %3 \n"
6563+ __SC "%0, %2 \n"
6564+ " beqzl %0, 1b \n"
6565+ " addu %0, %1, %3 \n"
6566+ " .set mips0 \n"
6567+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6568+ : "Ir" (i), "m" (l->a.counter)
6569+ : "memory");
6570+ } else if (kernel_uses_llsc) {
6571+ unsigned long temp;
6572+
6573+ __asm__ __volatile__(
6574+ " .set mips3 \n"
6575+ "1:" __LL "%1, %2 # local_add_return \n"
6576+ " addu %0, %1, %3 \n"
6577+ __SC "%0, %2 \n"
6578+ " beqz %0, 1b \n"
6579+ " addu %0, %1, %3 \n"
6580+ " .set mips0 \n"
6581+ : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6582+ : "Ir" (i), "m" (l->a.counter)
6583+ : "memory");
6584+ } else {
6585+ unsigned long flags;
6586+
6587+ local_irq_save(flags);
6588+ result = l->a.counter;
6589+ result += i;
6590+ l->a.counter = result;
6591+ local_irq_restore(flags);
6592+ }
6593+
6594+ return result;
6595+}
6596+
6597 static __inline__ long local_sub_return(long i, local_t * l)
6598 {
6599 unsigned long result;
6600@@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6601
6602 #define local_cmpxchg(l, o, n) \
6603 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6604+#define local_cmpxchg_unchecked(l, o, n) \
6605+ ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6606 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6607
6608 /**
6609diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6610index f6be474..12ad554 100644
6611--- a/arch/mips/include/asm/page.h
6612+++ b/arch/mips/include/asm/page.h
6613@@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6614 #ifdef CONFIG_CPU_MIPS32
6615 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6616 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6617- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6618+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6619 #else
6620 typedef struct { unsigned long long pte; } pte_t;
6621 #define pte_val(x) ((x).pte)
6622diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6623index b336037..5b874cc 100644
6624--- a/arch/mips/include/asm/pgalloc.h
6625+++ b/arch/mips/include/asm/pgalloc.h
6626@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6627 {
6628 set_pud(pud, __pud((unsigned long)pmd));
6629 }
6630+
6631+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6632+{
6633+ pud_populate(mm, pud, pmd);
6634+}
6635 #endif
6636
6637 /*
6638diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6639index 008324d..f67c239 100644
6640--- a/arch/mips/include/asm/pgtable.h
6641+++ b/arch/mips/include/asm/pgtable.h
6642@@ -20,6 +20,9 @@
6643 #include <asm/io.h>
6644 #include <asm/pgtable-bits.h>
6645
6646+#define ktla_ktva(addr) (addr)
6647+#define ktva_ktla(addr) (addr)
6648+
6649 struct mm_struct;
6650 struct vm_area_struct;
6651
6652diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6653index 25da651..ae2a259 100644
6654--- a/arch/mips/include/asm/smtc_proc.h
6655+++ b/arch/mips/include/asm/smtc_proc.h
6656@@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6657
6658 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6659
6660-extern atomic_t smtc_fpu_recoveries;
6661+extern atomic_unchecked_t smtc_fpu_recoveries;
6662
6663 #endif /* __ASM_SMTC_PROC_H */
6664diff --git a/arch/mips/include/asm/syscall.h b/arch/mips/include/asm/syscall.h
6665index 33e8dbf..81d8432 100644
6666--- a/arch/mips/include/asm/syscall.h
6667+++ b/arch/mips/include/asm/syscall.h
6668@@ -39,14 +39,14 @@ static inline unsigned long mips_get_syscall_arg(unsigned long *arg,
6669
6670 #ifdef CONFIG_32BIT
6671 case 4: case 5: case 6: case 7:
6672- return get_user(*arg, (int *)usp + 4 * n);
6673+ return get_user(*arg, (int *)usp + n);
6674 #endif
6675
6676 #ifdef CONFIG_64BIT
6677 case 4: case 5: case 6: case 7:
6678 #ifdef CONFIG_MIPS32_O32
6679 if (test_thread_flag(TIF_32BIT_REGS))
6680- return get_user(*arg, (int *)usp + 4 * n);
6681+ return get_user(*arg, (int *)usp + n);
6682 else
6683 #endif
6684 *arg = regs->regs[4 + n];
6685@@ -83,11 +83,10 @@ static inline void syscall_get_arguments(struct task_struct *task,
6686 unsigned int i, unsigned int n,
6687 unsigned long *args)
6688 {
6689- unsigned long arg;
6690 int ret;
6691
6692 while (n--)
6693- ret |= mips_get_syscall_arg(&arg, task, regs, i++);
6694+ ret |= mips_get_syscall_arg(args++, task, regs, i++);
6695
6696 /*
6697 * No way to communicate an error because this is a void function.
6698diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6699index 4f58ef6..5e7081b 100644
6700--- a/arch/mips/include/asm/thread_info.h
6701+++ b/arch/mips/include/asm/thread_info.h
6702@@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6703 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6704 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6705 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6706+/* li takes a 32bit immediate */
6707+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6708 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6709
6710 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6711@@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6712 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6713 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6714 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6715+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6716
6717 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6718- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6719+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6720
6721 /* work to do in syscall_trace_leave() */
6722 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6723- _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6724+ _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6725
6726 /* work to do on interrupt/exception return */
6727 #define _TIF_WORK_MASK \
6728@@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6729 /* work to do on any return to u-space */
6730 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6731 _TIF_WORK_SYSCALL_EXIT | \
6732- _TIF_SYSCALL_TRACEPOINT)
6733+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6734
6735 /*
6736 * We stash processor id into a COP0 register to retrieve it fast
6737diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6738index f3fa375..3af6637 100644
6739--- a/arch/mips/include/asm/uaccess.h
6740+++ b/arch/mips/include/asm/uaccess.h
6741@@ -128,6 +128,7 @@ extern u64 __ua_limit;
6742 __ok == 0; \
6743 })
6744
6745+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6746 #define access_ok(type, addr, size) \
6747 likely(__access_ok((addr), (size), __access_mask))
6748
6749diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6750index 1188e00..41cf144 100644
6751--- a/arch/mips/kernel/binfmt_elfn32.c
6752+++ b/arch/mips/kernel/binfmt_elfn32.c
6753@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6754 #undef ELF_ET_DYN_BASE
6755 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6756
6757+#ifdef CONFIG_PAX_ASLR
6758+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6759+
6760+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6761+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6762+#endif
6763+
6764 #include <asm/processor.h>
6765 #include <linux/module.h>
6766 #include <linux/elfcore.h>
6767diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6768index 202e581..689ca79 100644
6769--- a/arch/mips/kernel/binfmt_elfo32.c
6770+++ b/arch/mips/kernel/binfmt_elfo32.c
6771@@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6772 #undef ELF_ET_DYN_BASE
6773 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6774
6775+#ifdef CONFIG_PAX_ASLR
6776+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6777+
6778+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6779+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6780+#endif
6781+
6782 #include <asm/processor.h>
6783
6784 /*
6785diff --git a/arch/mips/kernel/ftrace.c b/arch/mips/kernel/ftrace.c
6786index 185ba25..374ed74 100644
6787--- a/arch/mips/kernel/ftrace.c
6788+++ b/arch/mips/kernel/ftrace.c
6789@@ -111,11 +111,10 @@ static int ftrace_modify_code_2(unsigned long ip, unsigned int new_code1,
6790 safe_store_code(new_code1, ip, faulted);
6791 if (unlikely(faulted))
6792 return -EFAULT;
6793- ip += 4;
6794- safe_store_code(new_code2, ip, faulted);
6795+ safe_store_code(new_code2, ip + 4, faulted);
6796 if (unlikely(faulted))
6797 return -EFAULT;
6798- flush_icache_range(ip, ip + 8); /* original ip + 12 */
6799+ flush_icache_range(ip, ip + 8);
6800 return 0;
6801 }
6802 #endif
6803diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6804index 2b91fe8..fe4f6b4 100644
6805--- a/arch/mips/kernel/i8259.c
6806+++ b/arch/mips/kernel/i8259.c
6807@@ -205,7 +205,7 @@ spurious_8259A_irq:
6808 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6809 spurious_irq_mask |= irqmask;
6810 }
6811- atomic_inc(&irq_err_count);
6812+ atomic_inc_unchecked(&irq_err_count);
6813 /*
6814 * Theoretically we do not have to handle this IRQ,
6815 * but in Linux this does not cause problems and is
6816diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6817index 44a1f79..2bd6aa3 100644
6818--- a/arch/mips/kernel/irq-gt641xx.c
6819+++ b/arch/mips/kernel/irq-gt641xx.c
6820@@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6821 }
6822 }
6823
6824- atomic_inc(&irq_err_count);
6825+ atomic_inc_unchecked(&irq_err_count);
6826 }
6827
6828 void __init gt641xx_irq_init(void)
6829diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6830index d1fea7a..45602ea 100644
6831--- a/arch/mips/kernel/irq.c
6832+++ b/arch/mips/kernel/irq.c
6833@@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6834 printk("unexpected IRQ # %d\n", irq);
6835 }
6836
6837-atomic_t irq_err_count;
6838+atomic_unchecked_t irq_err_count;
6839
6840 int arch_show_interrupts(struct seq_file *p, int prec)
6841 {
6842- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6843+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6844 return 0;
6845 }
6846
6847 asmlinkage void spurious_interrupt(void)
6848 {
6849- atomic_inc(&irq_err_count);
6850+ atomic_inc_unchecked(&irq_err_count);
6851 }
6852
6853 void __init init_IRQ(void)
6854diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6855index ddc7610..8c58f17 100644
6856--- a/arch/mips/kernel/process.c
6857+++ b/arch/mips/kernel/process.c
6858@@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6859 out:
6860 return pc;
6861 }
6862-
6863-/*
6864- * Don't forget that the stack pointer must be aligned on a 8 bytes
6865- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6866- */
6867-unsigned long arch_align_stack(unsigned long sp)
6868-{
6869- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6870- sp -= get_random_int() & ~PAGE_MASK;
6871-
6872- return sp & ALMASK;
6873-}
6874diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6875index b52e1d2..1a3ca09 100644
6876--- a/arch/mips/kernel/ptrace.c
6877+++ b/arch/mips/kernel/ptrace.c
6878@@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6879 return ret;
6880 }
6881
6882+#ifdef CONFIG_GRKERNSEC_SETXID
6883+extern void gr_delayed_cred_worker(void);
6884+#endif
6885+
6886 /*
6887 * Notification of system call entry/exit
6888 * - triggered by current->work.syscall_trace
6889@@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6890 tracehook_report_syscall_entry(regs))
6891 ret = -1;
6892
6893+#ifdef CONFIG_GRKERNSEC_SETXID
6894+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6895+ gr_delayed_cred_worker();
6896+#endif
6897+
6898 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6899 trace_sys_enter(regs, regs->regs[2]);
6900
6901diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6902index 07fc524..b9d7f28 100644
6903--- a/arch/mips/kernel/reset.c
6904+++ b/arch/mips/kernel/reset.c
6905@@ -13,6 +13,7 @@
6906 #include <linux/reboot.h>
6907
6908 #include <asm/reboot.h>
6909+#include <asm/bug.h>
6910
6911 /*
6912 * Urgs ... Too many MIPS machines to handle this in a generic way.
6913@@ -29,16 +30,19 @@ void machine_restart(char *command)
6914 {
6915 if (_machine_restart)
6916 _machine_restart(command);
6917+ BUG();
6918 }
6919
6920 void machine_halt(void)
6921 {
6922 if (_machine_halt)
6923 _machine_halt();
6924+ BUG();
6925 }
6926
6927 void machine_power_off(void)
6928 {
6929 if (pm_power_off)
6930 pm_power_off();
6931+ BUG();
6932 }
6933diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6934index c10aa84..9ec2e60 100644
6935--- a/arch/mips/kernel/smtc-proc.c
6936+++ b/arch/mips/kernel/smtc-proc.c
6937@@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6938
6939 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6940
6941-atomic_t smtc_fpu_recoveries;
6942+atomic_unchecked_t smtc_fpu_recoveries;
6943
6944 static int smtc_proc_show(struct seq_file *m, void *v)
6945 {
6946@@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6947 for(i = 0; i < NR_CPUS; i++)
6948 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6949 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6950- atomic_read(&smtc_fpu_recoveries));
6951+ atomic_read_unchecked(&smtc_fpu_recoveries));
6952 return 0;
6953 }
6954
6955@@ -73,7 +73,7 @@ void init_smtc_stats(void)
6956 smtc_cpu_stats[i].selfipis = 0;
6957 }
6958
6959- atomic_set(&smtc_fpu_recoveries, 0);
6960+ atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6961
6962 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6963 }
6964diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6965index dfc1b91..11a2c07 100644
6966--- a/arch/mips/kernel/smtc.c
6967+++ b/arch/mips/kernel/smtc.c
6968@@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6969 }
6970 smtc_ipi_qdump();
6971 printk("%d Recoveries of \"stolen\" FPU\n",
6972- atomic_read(&smtc_fpu_recoveries));
6973+ atomic_read_unchecked(&smtc_fpu_recoveries));
6974 }
6975
6976
6977diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6978index 84536bf..79caa4d 100644
6979--- a/arch/mips/kernel/sync-r4k.c
6980+++ b/arch/mips/kernel/sync-r4k.c
6981@@ -21,8 +21,8 @@
6982 #include <asm/mipsregs.h>
6983
6984 static atomic_t count_start_flag = ATOMIC_INIT(0);
6985-static atomic_t count_count_start = ATOMIC_INIT(0);
6986-static atomic_t count_count_stop = ATOMIC_INIT(0);
6987+static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6988+static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6989 static atomic_t count_reference = ATOMIC_INIT(0);
6990
6991 #define COUNTON 100
6992@@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6993
6994 for (i = 0; i < NR_LOOPS; i++) {
6995 /* slaves loop on '!= 2' */
6996- while (atomic_read(&count_count_start) != 1)
6997+ while (atomic_read_unchecked(&count_count_start) != 1)
6998 mb();
6999- atomic_set(&count_count_stop, 0);
7000+ atomic_set_unchecked(&count_count_stop, 0);
7001 smp_wmb();
7002
7003 /* this lets the slaves write their count register */
7004- atomic_inc(&count_count_start);
7005+ atomic_inc_unchecked(&count_count_start);
7006
7007 /*
7008 * Everyone initialises count in the last loop:
7009@@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
7010 /*
7011 * Wait for all slaves to leave the synchronization point:
7012 */
7013- while (atomic_read(&count_count_stop) != 1)
7014+ while (atomic_read_unchecked(&count_count_stop) != 1)
7015 mb();
7016- atomic_set(&count_count_start, 0);
7017+ atomic_set_unchecked(&count_count_start, 0);
7018 smp_wmb();
7019- atomic_inc(&count_count_stop);
7020+ atomic_inc_unchecked(&count_count_stop);
7021 }
7022 /* Arrange for an interrupt in a short while */
7023 write_c0_compare(read_c0_count() + COUNTON);
7024@@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
7025 initcount = atomic_read(&count_reference);
7026
7027 for (i = 0; i < NR_LOOPS; i++) {
7028- atomic_inc(&count_count_start);
7029- while (atomic_read(&count_count_start) != 2)
7030+ atomic_inc_unchecked(&count_count_start);
7031+ while (atomic_read_unchecked(&count_count_start) != 2)
7032 mb();
7033
7034 /*
7035@@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
7036 if (i == NR_LOOPS-1)
7037 write_c0_count(initcount);
7038
7039- atomic_inc(&count_count_stop);
7040- while (atomic_read(&count_count_stop) != 2)
7041+ atomic_inc_unchecked(&count_count_stop);
7042+ while (atomic_read_unchecked(&count_count_stop) != 2)
7043 mb();
7044 }
7045 /* Arrange for an interrupt in a short while */
7046diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7047index f9c8746..78b64e3 100644
7048--- a/arch/mips/kernel/traps.c
7049+++ b/arch/mips/kernel/traps.c
7050@@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7051 siginfo_t info;
7052
7053 prev_state = exception_enter();
7054- die_if_kernel("Integer overflow", regs);
7055+ if (unlikely(!user_mode(regs))) {
7056+
7057+#ifdef CONFIG_PAX_REFCOUNT
7058+ if (fixup_exception(regs)) {
7059+ pax_report_refcount_overflow(regs);
7060+ exception_exit(prev_state);
7061+ return;
7062+ }
7063+#endif
7064+
7065+ die("Integer overflow", regs);
7066+ }
7067
7068 info.si_code = FPE_INTOVF;
7069 info.si_signo = SIGFPE;
7070diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7071index becc42b..9e43d4b 100644
7072--- a/arch/mips/mm/fault.c
7073+++ b/arch/mips/mm/fault.c
7074@@ -28,6 +28,23 @@
7075 #include <asm/highmem.h> /* For VMALLOC_END */
7076 #include <linux/kdebug.h>
7077
7078+#ifdef CONFIG_PAX_PAGEEXEC
7079+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7080+{
7081+ unsigned long i;
7082+
7083+ printk(KERN_ERR "PAX: bytes at PC: ");
7084+ for (i = 0; i < 5; i++) {
7085+ unsigned int c;
7086+ if (get_user(c, (unsigned int *)pc+i))
7087+ printk(KERN_CONT "???????? ");
7088+ else
7089+ printk(KERN_CONT "%08x ", c);
7090+ }
7091+ printk("\n");
7092+}
7093+#endif
7094+
7095 /*
7096 * This routine handles page faults. It determines the address,
7097 * and the problem, and then passes it off to one of the appropriate
7098@@ -199,6 +216,14 @@ bad_area:
7099 bad_area_nosemaphore:
7100 /* User mode accesses just cause a SIGSEGV */
7101 if (user_mode(regs)) {
7102+
7103+#ifdef CONFIG_PAX_PAGEEXEC
7104+ if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7105+ pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7106+ do_group_exit(SIGKILL);
7107+ }
7108+#endif
7109+
7110 tsk->thread.cp0_badvaddr = address;
7111 tsk->thread.error_code = write;
7112 #if 0
7113diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7114index f1baadd..5472dca 100644
7115--- a/arch/mips/mm/mmap.c
7116+++ b/arch/mips/mm/mmap.c
7117@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7118 struct vm_area_struct *vma;
7119 unsigned long addr = addr0;
7120 int do_color_align;
7121+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7122 struct vm_unmapped_area_info info;
7123
7124 if (unlikely(len > TASK_SIZE))
7125@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7126 do_color_align = 1;
7127
7128 /* requesting a specific address */
7129+
7130+#ifdef CONFIG_PAX_RANDMMAP
7131+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7132+#endif
7133+
7134 if (addr) {
7135 if (do_color_align)
7136 addr = COLOUR_ALIGN(addr, pgoff);
7137@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7138 addr = PAGE_ALIGN(addr);
7139
7140 vma = find_vma(mm, addr);
7141- if (TASK_SIZE - len >= addr &&
7142- (!vma || addr + len <= vma->vm_start))
7143+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7144 return addr;
7145 }
7146
7147 info.length = len;
7148 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7149 info.align_offset = pgoff << PAGE_SHIFT;
7150+ info.threadstack_offset = offset;
7151
7152 if (dir == DOWN) {
7153 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7154@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7155 {
7156 unsigned long random_factor = 0UL;
7157
7158+#ifdef CONFIG_PAX_RANDMMAP
7159+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7160+#endif
7161+
7162 if (current->flags & PF_RANDOMIZE) {
7163 random_factor = get_random_int();
7164 random_factor = random_factor << PAGE_SHIFT;
7165@@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7166
7167 if (mmap_is_legacy()) {
7168 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7169+
7170+#ifdef CONFIG_PAX_RANDMMAP
7171+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7172+ mm->mmap_base += mm->delta_mmap;
7173+#endif
7174+
7175 mm->get_unmapped_area = arch_get_unmapped_area;
7176 } else {
7177 mm->mmap_base = mmap_base(random_factor);
7178+
7179+#ifdef CONFIG_PAX_RANDMMAP
7180+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7181+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7182+#endif
7183+
7184 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7185 }
7186 }
7187
7188-static inline unsigned long brk_rnd(void)
7189-{
7190- unsigned long rnd = get_random_int();
7191-
7192- rnd = rnd << PAGE_SHIFT;
7193- /* 8MB for 32bit, 256MB for 64bit */
7194- if (TASK_IS_32BIT_ADDR)
7195- rnd = rnd & 0x7ffffful;
7196- else
7197- rnd = rnd & 0xffffffful;
7198-
7199- return rnd;
7200-}
7201-
7202-unsigned long arch_randomize_brk(struct mm_struct *mm)
7203-{
7204- unsigned long base = mm->brk;
7205- unsigned long ret;
7206-
7207- ret = PAGE_ALIGN(base + brk_rnd());
7208-
7209- if (ret < mm->brk)
7210- return mm->brk;
7211-
7212- return ret;
7213-}
7214-
7215 int __virt_addr_valid(const volatile void *kaddr)
7216 {
7217 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7218diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7219index 59cccd9..f39ac2f 100644
7220--- a/arch/mips/pci/pci-octeon.c
7221+++ b/arch/mips/pci/pci-octeon.c
7222@@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7223
7224
7225 static struct pci_ops octeon_pci_ops = {
7226- octeon_read_config,
7227- octeon_write_config,
7228+ .read = octeon_read_config,
7229+ .write = octeon_write_config,
7230 };
7231
7232 static struct resource octeon_pci_mem_resource = {
7233diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7234index 5e36c33..eb4a17b 100644
7235--- a/arch/mips/pci/pcie-octeon.c
7236+++ b/arch/mips/pci/pcie-octeon.c
7237@@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7238 }
7239
7240 static struct pci_ops octeon_pcie0_ops = {
7241- octeon_pcie0_read_config,
7242- octeon_pcie0_write_config,
7243+ .read = octeon_pcie0_read_config,
7244+ .write = octeon_pcie0_write_config,
7245 };
7246
7247 static struct resource octeon_pcie0_mem_resource = {
7248@@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7249 };
7250
7251 static struct pci_ops octeon_pcie1_ops = {
7252- octeon_pcie1_read_config,
7253- octeon_pcie1_write_config,
7254+ .read = octeon_pcie1_read_config,
7255+ .write = octeon_pcie1_write_config,
7256 };
7257
7258 static struct resource octeon_pcie1_mem_resource = {
7259@@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7260 };
7261
7262 static struct pci_ops octeon_dummy_ops = {
7263- octeon_dummy_read_config,
7264- octeon_dummy_write_config,
7265+ .read = octeon_dummy_read_config,
7266+ .write = octeon_dummy_write_config,
7267 };
7268
7269 static struct resource octeon_dummy_mem_resource = {
7270diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7271index a2358b4..7cead4f 100644
7272--- a/arch/mips/sgi-ip27/ip27-nmi.c
7273+++ b/arch/mips/sgi-ip27/ip27-nmi.c
7274@@ -187,9 +187,9 @@ void
7275 cont_nmi_dump(void)
7276 {
7277 #ifndef REAL_NMI_SIGNAL
7278- static atomic_t nmied_cpus = ATOMIC_INIT(0);
7279+ static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7280
7281- atomic_inc(&nmied_cpus);
7282+ atomic_inc_unchecked(&nmied_cpus);
7283 #endif
7284 /*
7285 * Only allow 1 cpu to proceed
7286@@ -233,7 +233,7 @@ cont_nmi_dump(void)
7287 udelay(10000);
7288 }
7289 #else
7290- while (atomic_read(&nmied_cpus) != num_online_cpus());
7291+ while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7292 #endif
7293
7294 /*
7295diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7296index a046b30..6799527 100644
7297--- a/arch/mips/sni/rm200.c
7298+++ b/arch/mips/sni/rm200.c
7299@@ -270,7 +270,7 @@ spurious_8259A_irq:
7300 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7301 spurious_irq_mask |= irqmask;
7302 }
7303- atomic_inc(&irq_err_count);
7304+ atomic_inc_unchecked(&irq_err_count);
7305 /*
7306 * Theoretically we do not have to handle this IRQ,
7307 * but in Linux this does not cause problems and is
7308diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7309index 41e873b..34d33a7 100644
7310--- a/arch/mips/vr41xx/common/icu.c
7311+++ b/arch/mips/vr41xx/common/icu.c
7312@@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7313
7314 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7315
7316- atomic_inc(&irq_err_count);
7317+ atomic_inc_unchecked(&irq_err_count);
7318
7319 return -1;
7320 }
7321diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7322index ae0e4ee..e8f0692 100644
7323--- a/arch/mips/vr41xx/common/irq.c
7324+++ b/arch/mips/vr41xx/common/irq.c
7325@@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7326 irq_cascade_t *cascade;
7327
7328 if (irq >= NR_IRQS) {
7329- atomic_inc(&irq_err_count);
7330+ atomic_inc_unchecked(&irq_err_count);
7331 return;
7332 }
7333
7334@@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7335 ret = cascade->get_irq(irq);
7336 irq = ret;
7337 if (ret < 0)
7338- atomic_inc(&irq_err_count);
7339+ atomic_inc_unchecked(&irq_err_count);
7340 else
7341 irq_dispatch(irq);
7342 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7343diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7344index 967d144..db12197 100644
7345--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7346+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7347@@ -11,12 +11,14 @@
7348 #ifndef _ASM_PROC_CACHE_H
7349 #define _ASM_PROC_CACHE_H
7350
7351+#include <linux/const.h>
7352+
7353 /* L1 cache */
7354
7355 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7356 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7357-#define L1_CACHE_BYTES 16 /* bytes per entry */
7358 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7360 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7361
7362 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7363diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7364index bcb5df2..84fabd2 100644
7365--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7366+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7367@@ -16,13 +16,15 @@
7368 #ifndef _ASM_PROC_CACHE_H
7369 #define _ASM_PROC_CACHE_H
7370
7371+#include <linux/const.h>
7372+
7373 /*
7374 * L1 cache
7375 */
7376 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7377 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7378-#define L1_CACHE_BYTES 32 /* bytes per entry */
7379 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7380+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7381 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7382
7383 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7384diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7385index 4ce7a01..449202a 100644
7386--- a/arch/openrisc/include/asm/cache.h
7387+++ b/arch/openrisc/include/asm/cache.h
7388@@ -19,11 +19,13 @@
7389 #ifndef __ASM_OPENRISC_CACHE_H
7390 #define __ASM_OPENRISC_CACHE_H
7391
7392+#include <linux/const.h>
7393+
7394 /* FIXME: How can we replace these with values from the CPU...
7395 * they shouldn't be hard-coded!
7396 */
7397
7398-#define L1_CACHE_BYTES 16
7399 #define L1_CACHE_SHIFT 4
7400+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7401
7402 #endif /* __ASM_OPENRISC_CACHE_H */
7403diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7404index 472886c..00e7df9 100644
7405--- a/arch/parisc/include/asm/atomic.h
7406+++ b/arch/parisc/include/asm/atomic.h
7407@@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7408 return dec;
7409 }
7410
7411+#define atomic64_read_unchecked(v) atomic64_read(v)
7412+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7413+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7414+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7415+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7416+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7417+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7418+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7419+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7420+
7421 #endif /* !CONFIG_64BIT */
7422
7423
7424diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7425index 47f11c7..3420df2 100644
7426--- a/arch/parisc/include/asm/cache.h
7427+++ b/arch/parisc/include/asm/cache.h
7428@@ -5,6 +5,7 @@
7429 #ifndef __ARCH_PARISC_CACHE_H
7430 #define __ARCH_PARISC_CACHE_H
7431
7432+#include <linux/const.h>
7433
7434 /*
7435 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7436@@ -15,13 +16,13 @@
7437 * just ruin performance.
7438 */
7439 #ifdef CONFIG_PA20
7440-#define L1_CACHE_BYTES 64
7441 #define L1_CACHE_SHIFT 6
7442 #else
7443-#define L1_CACHE_BYTES 32
7444 #define L1_CACHE_SHIFT 5
7445 #endif
7446
7447+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7448+
7449 #ifndef __ASSEMBLY__
7450
7451 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7452diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7453index ad2b503..bdf1651 100644
7454--- a/arch/parisc/include/asm/elf.h
7455+++ b/arch/parisc/include/asm/elf.h
7456@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7457
7458 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7459
7460+#ifdef CONFIG_PAX_ASLR
7461+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7462+
7463+#define PAX_DELTA_MMAP_LEN 16
7464+#define PAX_DELTA_STACK_LEN 16
7465+#endif
7466+
7467 /* This yields a mask that user programs can use to figure out what
7468 instruction set this CPU supports. This could be done in user space,
7469 but it's not easy, and we've already done it here. */
7470diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7471index f213f5b..0af3e8e 100644
7472--- a/arch/parisc/include/asm/pgalloc.h
7473+++ b/arch/parisc/include/asm/pgalloc.h
7474@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7475 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7476 }
7477
7478+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7479+{
7480+ pgd_populate(mm, pgd, pmd);
7481+}
7482+
7483 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7484 {
7485 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7486@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7487 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7488 #define pmd_free(mm, x) do { } while (0)
7489 #define pgd_populate(mm, pmd, pte) BUG()
7490+#define pgd_populate_kernel(mm, pmd, pte) BUG()
7491
7492 #endif
7493
7494diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7495index 34899b5..02dd060 100644
7496--- a/arch/parisc/include/asm/pgtable.h
7497+++ b/arch/parisc/include/asm/pgtable.h
7498@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7499 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7500 #define PAGE_COPY PAGE_EXECREAD
7501 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7502+
7503+#ifdef CONFIG_PAX_PAGEEXEC
7504+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7505+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7506+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7507+#else
7508+# define PAGE_SHARED_NOEXEC PAGE_SHARED
7509+# define PAGE_COPY_NOEXEC PAGE_COPY
7510+# define PAGE_READONLY_NOEXEC PAGE_READONLY
7511+#endif
7512+
7513 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7514 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7515 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7516diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7517index 4006964..fcb3cc2 100644
7518--- a/arch/parisc/include/asm/uaccess.h
7519+++ b/arch/parisc/include/asm/uaccess.h
7520@@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7521 const void __user *from,
7522 unsigned long n)
7523 {
7524- int sz = __compiletime_object_size(to);
7525+ size_t sz = __compiletime_object_size(to);
7526 int ret = -EFAULT;
7527
7528- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7529+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7530 ret = __copy_from_user(to, from, n);
7531 else
7532 copy_from_user_overflow();
7533diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7534index 50dfafc..b9fc230 100644
7535--- a/arch/parisc/kernel/module.c
7536+++ b/arch/parisc/kernel/module.c
7537@@ -98,16 +98,38 @@
7538
7539 /* three functions to determine where in the module core
7540 * or init pieces the location is */
7541+static inline int in_init_rx(struct module *me, void *loc)
7542+{
7543+ return (loc >= me->module_init_rx &&
7544+ loc < (me->module_init_rx + me->init_size_rx));
7545+}
7546+
7547+static inline int in_init_rw(struct module *me, void *loc)
7548+{
7549+ return (loc >= me->module_init_rw &&
7550+ loc < (me->module_init_rw + me->init_size_rw));
7551+}
7552+
7553 static inline int in_init(struct module *me, void *loc)
7554 {
7555- return (loc >= me->module_init &&
7556- loc <= (me->module_init + me->init_size));
7557+ return in_init_rx(me, loc) || in_init_rw(me, loc);
7558+}
7559+
7560+static inline int in_core_rx(struct module *me, void *loc)
7561+{
7562+ return (loc >= me->module_core_rx &&
7563+ loc < (me->module_core_rx + me->core_size_rx));
7564+}
7565+
7566+static inline int in_core_rw(struct module *me, void *loc)
7567+{
7568+ return (loc >= me->module_core_rw &&
7569+ loc < (me->module_core_rw + me->core_size_rw));
7570 }
7571
7572 static inline int in_core(struct module *me, void *loc)
7573 {
7574- return (loc >= me->module_core &&
7575- loc <= (me->module_core + me->core_size));
7576+ return in_core_rx(me, loc) || in_core_rw(me, loc);
7577 }
7578
7579 static inline int in_local(struct module *me, void *loc)
7580@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7581 }
7582
7583 /* align things a bit */
7584- me->core_size = ALIGN(me->core_size, 16);
7585- me->arch.got_offset = me->core_size;
7586- me->core_size += gots * sizeof(struct got_entry);
7587+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7588+ me->arch.got_offset = me->core_size_rw;
7589+ me->core_size_rw += gots * sizeof(struct got_entry);
7590
7591- me->core_size = ALIGN(me->core_size, 16);
7592- me->arch.fdesc_offset = me->core_size;
7593- me->core_size += fdescs * sizeof(Elf_Fdesc);
7594+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
7595+ me->arch.fdesc_offset = me->core_size_rw;
7596+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7597
7598 me->arch.got_max = gots;
7599 me->arch.fdesc_max = fdescs;
7600@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7601
7602 BUG_ON(value == 0);
7603
7604- got = me->module_core + me->arch.got_offset;
7605+ got = me->module_core_rw + me->arch.got_offset;
7606 for (i = 0; got[i].addr; i++)
7607 if (got[i].addr == value)
7608 goto out;
7609@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7610 #ifdef CONFIG_64BIT
7611 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7612 {
7613- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7614+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7615
7616 if (!value) {
7617 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7618@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7619
7620 /* Create new one */
7621 fdesc->addr = value;
7622- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7623+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7624 return (Elf_Addr)fdesc;
7625 }
7626 #endif /* CONFIG_64BIT */
7627@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7628
7629 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7630 end = table + sechdrs[me->arch.unwind_section].sh_size;
7631- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7632+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7633
7634 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7635 me->arch.unwind_section, table, end, gp);
7636diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7637index 0d3a9d4..20a99b0 100644
7638--- a/arch/parisc/kernel/sys_parisc.c
7639+++ b/arch/parisc/kernel/sys_parisc.c
7640@@ -33,9 +33,11 @@
7641 #include <linux/utsname.h>
7642 #include <linux/personality.h>
7643
7644-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7645+static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7646+ unsigned long flags)
7647 {
7648 struct vm_unmapped_area_info info;
7649+ unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7650
7651 info.flags = 0;
7652 info.length = len;
7653@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7654 info.high_limit = TASK_SIZE;
7655 info.align_mask = 0;
7656 info.align_offset = 0;
7657+ info.threadstack_offset = offset;
7658 return vm_unmapped_area(&info);
7659 }
7660
7661@@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7662 }
7663
7664 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7665- unsigned long len, unsigned long pgoff)
7666+ unsigned long len, unsigned long pgoff, unsigned long flags)
7667 {
7668 struct vm_unmapped_area_info info;
7669+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7670
7671 info.flags = 0;
7672 info.length = len;
7673@@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7674 info.high_limit = TASK_SIZE;
7675 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7676 info.align_offset = shared_align_offset(filp, pgoff);
7677+ info.threadstack_offset = offset;
7678 return vm_unmapped_area(&info);
7679 }
7680
7681@@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7682 return -EINVAL;
7683 return addr;
7684 }
7685- if (!addr)
7686+ if (!addr) {
7687 addr = TASK_UNMAPPED_BASE;
7688
7689+#ifdef CONFIG_PAX_RANDMMAP
7690+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7691+ addr += current->mm->delta_mmap;
7692+#endif
7693+
7694+ }
7695+
7696 if (filp || (flags & MAP_SHARED))
7697- addr = get_shared_area(filp, addr, len, pgoff);
7698+ addr = get_shared_area(filp, addr, len, pgoff, flags);
7699 else
7700- addr = get_unshared_area(addr, len);
7701+ addr = get_unshared_area(addr, len, flags);
7702
7703 return addr;
7704 }
7705diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7706index 1cd1d0c..44ec918 100644
7707--- a/arch/parisc/kernel/traps.c
7708+++ b/arch/parisc/kernel/traps.c
7709@@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7710
7711 down_read(&current->mm->mmap_sem);
7712 vma = find_vma(current->mm,regs->iaoq[0]);
7713- if (vma && (regs->iaoq[0] >= vma->vm_start)
7714- && (vma->vm_flags & VM_EXEC)) {
7715-
7716+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7717 fault_address = regs->iaoq[0];
7718 fault_space = regs->iasq[0];
7719
7720diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7721index 9d08c71..e2b4d20 100644
7722--- a/arch/parisc/mm/fault.c
7723+++ b/arch/parisc/mm/fault.c
7724@@ -15,6 +15,7 @@
7725 #include <linux/sched.h>
7726 #include <linux/interrupt.h>
7727 #include <linux/module.h>
7728+#include <linux/unistd.h>
7729
7730 #include <asm/uaccess.h>
7731 #include <asm/traps.h>
7732@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7733 static unsigned long
7734 parisc_acctyp(unsigned long code, unsigned int inst)
7735 {
7736- if (code == 6 || code == 16)
7737+ if (code == 6 || code == 7 || code == 16)
7738 return VM_EXEC;
7739
7740 switch (inst & 0xf0000000) {
7741@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7742 }
7743 #endif
7744
7745+#ifdef CONFIG_PAX_PAGEEXEC
7746+/*
7747+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7748+ *
7749+ * returns 1 when task should be killed
7750+ * 2 when rt_sigreturn trampoline was detected
7751+ * 3 when unpatched PLT trampoline was detected
7752+ */
7753+static int pax_handle_fetch_fault(struct pt_regs *regs)
7754+{
7755+
7756+#ifdef CONFIG_PAX_EMUPLT
7757+ int err;
7758+
7759+ do { /* PaX: unpatched PLT emulation */
7760+ unsigned int bl, depwi;
7761+
7762+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7763+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7764+
7765+ if (err)
7766+ break;
7767+
7768+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7769+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7770+
7771+ err = get_user(ldw, (unsigned int *)addr);
7772+ err |= get_user(bv, (unsigned int *)(addr+4));
7773+ err |= get_user(ldw2, (unsigned int *)(addr+8));
7774+
7775+ if (err)
7776+ break;
7777+
7778+ if (ldw == 0x0E801096U &&
7779+ bv == 0xEAC0C000U &&
7780+ ldw2 == 0x0E881095U)
7781+ {
7782+ unsigned int resolver, map;
7783+
7784+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7785+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7786+ if (err)
7787+ break;
7788+
7789+ regs->gr[20] = instruction_pointer(regs)+8;
7790+ regs->gr[21] = map;
7791+ regs->gr[22] = resolver;
7792+ regs->iaoq[0] = resolver | 3UL;
7793+ regs->iaoq[1] = regs->iaoq[0] + 4;
7794+ return 3;
7795+ }
7796+ }
7797+ } while (0);
7798+#endif
7799+
7800+#ifdef CONFIG_PAX_EMUTRAMP
7801+
7802+#ifndef CONFIG_PAX_EMUSIGRT
7803+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7804+ return 1;
7805+#endif
7806+
7807+ do { /* PaX: rt_sigreturn emulation */
7808+ unsigned int ldi1, ldi2, bel, nop;
7809+
7810+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7811+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7812+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7813+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7814+
7815+ if (err)
7816+ break;
7817+
7818+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7819+ ldi2 == 0x3414015AU &&
7820+ bel == 0xE4008200U &&
7821+ nop == 0x08000240U)
7822+ {
7823+ regs->gr[25] = (ldi1 & 2) >> 1;
7824+ regs->gr[20] = __NR_rt_sigreturn;
7825+ regs->gr[31] = regs->iaoq[1] + 16;
7826+ regs->sr[0] = regs->iasq[1];
7827+ regs->iaoq[0] = 0x100UL;
7828+ regs->iaoq[1] = regs->iaoq[0] + 4;
7829+ regs->iasq[0] = regs->sr[2];
7830+ regs->iasq[1] = regs->sr[2];
7831+ return 2;
7832+ }
7833+ } while (0);
7834+#endif
7835+
7836+ return 1;
7837+}
7838+
7839+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7840+{
7841+ unsigned long i;
7842+
7843+ printk(KERN_ERR "PAX: bytes at PC: ");
7844+ for (i = 0; i < 5; i++) {
7845+ unsigned int c;
7846+ if (get_user(c, (unsigned int *)pc+i))
7847+ printk(KERN_CONT "???????? ");
7848+ else
7849+ printk(KERN_CONT "%08x ", c);
7850+ }
7851+ printk("\n");
7852+}
7853+#endif
7854+
7855 int fixup_exception(struct pt_regs *regs)
7856 {
7857 const struct exception_table_entry *fix;
7858@@ -210,8 +321,33 @@ retry:
7859
7860 good_area:
7861
7862- if ((vma->vm_flags & acc_type) != acc_type)
7863+ if ((vma->vm_flags & acc_type) != acc_type) {
7864+
7865+#ifdef CONFIG_PAX_PAGEEXEC
7866+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7867+ (address & ~3UL) == instruction_pointer(regs))
7868+ {
7869+ up_read(&mm->mmap_sem);
7870+ switch (pax_handle_fetch_fault(regs)) {
7871+
7872+#ifdef CONFIG_PAX_EMUPLT
7873+ case 3:
7874+ return;
7875+#endif
7876+
7877+#ifdef CONFIG_PAX_EMUTRAMP
7878+ case 2:
7879+ return;
7880+#endif
7881+
7882+ }
7883+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7884+ do_group_exit(SIGKILL);
7885+ }
7886+#endif
7887+
7888 goto bad_area;
7889+ }
7890
7891 /*
7892 * If for any reason at all we couldn't handle the fault, make
7893diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7894index b44b52c..4cd253c 100644
7895--- a/arch/powerpc/Kconfig
7896+++ b/arch/powerpc/Kconfig
7897@@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7898 config KEXEC
7899 bool "kexec system call"
7900 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7901+ depends on !GRKERNSEC_KMEM
7902 help
7903 kexec is a system call that implements the ability to shutdown your
7904 current kernel, and to start another kernel. It is like a reboot
7905diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7906index e3b1d41..8e81edf 100644
7907--- a/arch/powerpc/include/asm/atomic.h
7908+++ b/arch/powerpc/include/asm/atomic.h
7909@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7910 return t1;
7911 }
7912
7913+#define atomic64_read_unchecked(v) atomic64_read(v)
7914+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7915+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7916+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7917+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7918+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7919+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7920+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7921+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7922+
7923 #endif /* __powerpc64__ */
7924
7925 #endif /* __KERNEL__ */
7926diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7927index 9e495c9..b6878e5 100644
7928--- a/arch/powerpc/include/asm/cache.h
7929+++ b/arch/powerpc/include/asm/cache.h
7930@@ -3,6 +3,7 @@
7931
7932 #ifdef __KERNEL__
7933
7934+#include <linux/const.h>
7935
7936 /* bytes per L1 cache line */
7937 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7938@@ -22,7 +23,7 @@
7939 #define L1_CACHE_SHIFT 7
7940 #endif
7941
7942-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7943+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7944
7945 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7946
7947diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7948index 935b5e7..7001d2d 100644
7949--- a/arch/powerpc/include/asm/elf.h
7950+++ b/arch/powerpc/include/asm/elf.h
7951@@ -28,8 +28,19 @@
7952 the loader. We need to make sure that it is out of the way of the program
7953 that it will "exec", and that there is sufficient room for the brk. */
7954
7955-extern unsigned long randomize_et_dyn(unsigned long base);
7956-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7957+#define ELF_ET_DYN_BASE (0x20000000)
7958+
7959+#ifdef CONFIG_PAX_ASLR
7960+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7961+
7962+#ifdef __powerpc64__
7963+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7964+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7965+#else
7966+#define PAX_DELTA_MMAP_LEN 15
7967+#define PAX_DELTA_STACK_LEN 15
7968+#endif
7969+#endif
7970
7971 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7972
7973@@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7974 (0x7ff >> (PAGE_SHIFT - 12)) : \
7975 (0x3ffff >> (PAGE_SHIFT - 12)))
7976
7977-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7978-#define arch_randomize_brk arch_randomize_brk
7979-
7980-
7981 #ifdef CONFIG_SPU_BASE
7982 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7983 #define NT_SPU 1
7984diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7985index 8196e9c..d83a9f3 100644
7986--- a/arch/powerpc/include/asm/exec.h
7987+++ b/arch/powerpc/include/asm/exec.h
7988@@ -4,6 +4,6 @@
7989 #ifndef _ASM_POWERPC_EXEC_H
7990 #define _ASM_POWERPC_EXEC_H
7991
7992-extern unsigned long arch_align_stack(unsigned long sp);
7993+#define arch_align_stack(x) ((x) & ~0xfUL)
7994
7995 #endif /* _ASM_POWERPC_EXEC_H */
7996diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7997index 5acabbd..7ea14fa 100644
7998--- a/arch/powerpc/include/asm/kmap_types.h
7999+++ b/arch/powerpc/include/asm/kmap_types.h
8000@@ -10,7 +10,7 @@
8001 * 2 of the License, or (at your option) any later version.
8002 */
8003
8004-#define KM_TYPE_NR 16
8005+#define KM_TYPE_NR 17
8006
8007 #endif /* __KERNEL__ */
8008 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8009diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8010index b8da913..60b608a 100644
8011--- a/arch/powerpc/include/asm/local.h
8012+++ b/arch/powerpc/include/asm/local.h
8013@@ -9,15 +9,26 @@ typedef struct
8014 atomic_long_t a;
8015 } local_t;
8016
8017+typedef struct
8018+{
8019+ atomic_long_unchecked_t a;
8020+} local_unchecked_t;
8021+
8022 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8023
8024 #define local_read(l) atomic_long_read(&(l)->a)
8025+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8026 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8027+#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8028
8029 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8030+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8031 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8032+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8033 #define local_inc(l) atomic_long_inc(&(l)->a)
8034+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8035 #define local_dec(l) atomic_long_dec(&(l)->a)
8036+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8037
8038 static __inline__ long local_add_return(long a, local_t *l)
8039 {
8040@@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8041
8042 return t;
8043 }
8044+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8045
8046 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8047
8048@@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8049
8050 return t;
8051 }
8052+#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8053
8054 static __inline__ long local_inc_return(local_t *l)
8055 {
8056@@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8057
8058 #define local_cmpxchg(l, o, n) \
8059 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8060+#define local_cmpxchg_unchecked(l, o, n) \
8061+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
8062 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8063
8064 /**
8065diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8066index 8565c25..2865190 100644
8067--- a/arch/powerpc/include/asm/mman.h
8068+++ b/arch/powerpc/include/asm/mman.h
8069@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8070 }
8071 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8072
8073-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8074+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8075 {
8076 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8077 }
8078diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8079index 32e4e21..62afb12 100644
8080--- a/arch/powerpc/include/asm/page.h
8081+++ b/arch/powerpc/include/asm/page.h
8082@@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8083 * and needs to be executable. This means the whole heap ends
8084 * up being executable.
8085 */
8086-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8087- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8088+#define VM_DATA_DEFAULT_FLAGS32 \
8089+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8090+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8091
8092 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8093 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8094@@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8095 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8096 #endif
8097
8098+#define ktla_ktva(addr) (addr)
8099+#define ktva_ktla(addr) (addr)
8100+
8101 #ifndef CONFIG_PPC_BOOK3S_64
8102 /*
8103 * Use the top bit of the higher-level page table entries to indicate whether
8104diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8105index 88693ce..ac6f9ab 100644
8106--- a/arch/powerpc/include/asm/page_64.h
8107+++ b/arch/powerpc/include/asm/page_64.h
8108@@ -153,15 +153,18 @@ do { \
8109 * stack by default, so in the absence of a PT_GNU_STACK program header
8110 * we turn execute permission off.
8111 */
8112-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8113- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8114+#define VM_STACK_DEFAULT_FLAGS32 \
8115+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8116+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8117
8118 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8119 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8120
8121+#ifndef CONFIG_PAX_PAGEEXEC
8122 #define VM_STACK_DEFAULT_FLAGS \
8123 (is_32bit_task() ? \
8124 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8125+#endif
8126
8127 #include <asm-generic/getorder.h>
8128
8129diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8130index 4b0be20..c15a27d 100644
8131--- a/arch/powerpc/include/asm/pgalloc-64.h
8132+++ b/arch/powerpc/include/asm/pgalloc-64.h
8133@@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8134 #ifndef CONFIG_PPC_64K_PAGES
8135
8136 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8137+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8138
8139 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8140 {
8141@@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8142 pud_set(pud, (unsigned long)pmd);
8143 }
8144
8145+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8146+{
8147+ pud_populate(mm, pud, pmd);
8148+}
8149+
8150 #define pmd_populate(mm, pmd, pte_page) \
8151 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8152 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8153@@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8154 #endif
8155
8156 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8157+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8158
8159 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8160 pte_t *pte)
8161diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8162index 7d6eacf..14c0240 100644
8163--- a/arch/powerpc/include/asm/pgtable.h
8164+++ b/arch/powerpc/include/asm/pgtable.h
8165@@ -2,6 +2,7 @@
8166 #define _ASM_POWERPC_PGTABLE_H
8167 #ifdef __KERNEL__
8168
8169+#include <linux/const.h>
8170 #ifndef __ASSEMBLY__
8171 #include <asm/processor.h> /* For TASK_SIZE */
8172 #include <asm/mmu.h>
8173diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8174index 4aad413..85d86bf 100644
8175--- a/arch/powerpc/include/asm/pte-hash32.h
8176+++ b/arch/powerpc/include/asm/pte-hash32.h
8177@@ -21,6 +21,7 @@
8178 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8179 #define _PAGE_USER 0x004 /* usermode access allowed */
8180 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8181+#define _PAGE_EXEC _PAGE_GUARDED
8182 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8183 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8184 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8185diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8186index fa8388e..f985549 100644
8187--- a/arch/powerpc/include/asm/reg.h
8188+++ b/arch/powerpc/include/asm/reg.h
8189@@ -239,6 +239,7 @@
8190 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8191 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8192 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8193+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8194 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8195 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8196 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8197diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8198index 084e080..9415a3d 100644
8199--- a/arch/powerpc/include/asm/smp.h
8200+++ b/arch/powerpc/include/asm/smp.h
8201@@ -51,7 +51,7 @@ struct smp_ops_t {
8202 int (*cpu_disable)(void);
8203 void (*cpu_die)(unsigned int nr);
8204 int (*cpu_bootable)(unsigned int nr);
8205-};
8206+} __no_const;
8207
8208 extern void smp_send_debugger_break(void);
8209 extern void start_secondary_resume(void);
8210diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8211index 9854c56..7517190 100644
8212--- a/arch/powerpc/include/asm/thread_info.h
8213+++ b/arch/powerpc/include/asm/thread_info.h
8214@@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
8215 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
8216 TIF_NEED_RESCHED */
8217 #define TIF_32BIT 4 /* 32 bit binary */
8218-#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
8219 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
8220 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
8221 #define TIF_SINGLESTEP 8 /* singlestepping active */
8222@@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
8223 #if defined(CONFIG_PPC64)
8224 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8225 #endif
8226+#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
8227+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8228+#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
8229
8230 /* as above, but as bit values */
8231 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8232@@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
8233 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8234 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8235 #define _TIF_NOHZ (1<<TIF_NOHZ)
8236+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8237 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8238 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8239- _TIF_NOHZ)
8240+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
8241
8242 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8243 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
8244diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8245index 9485b43..3bd3c16 100644
8246--- a/arch/powerpc/include/asm/uaccess.h
8247+++ b/arch/powerpc/include/asm/uaccess.h
8248@@ -58,6 +58,7 @@
8249
8250 #endif
8251
8252+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8253 #define access_ok(type, addr, size) \
8254 (__chk_user_ptr(addr), \
8255 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8256@@ -318,52 +319,6 @@ do { \
8257 extern unsigned long __copy_tofrom_user(void __user *to,
8258 const void __user *from, unsigned long size);
8259
8260-#ifndef __powerpc64__
8261-
8262-static inline unsigned long copy_from_user(void *to,
8263- const void __user *from, unsigned long n)
8264-{
8265- unsigned long over;
8266-
8267- if (access_ok(VERIFY_READ, from, n))
8268- return __copy_tofrom_user((__force void __user *)to, from, n);
8269- if ((unsigned long)from < TASK_SIZE) {
8270- over = (unsigned long)from + n - TASK_SIZE;
8271- return __copy_tofrom_user((__force void __user *)to, from,
8272- n - over) + over;
8273- }
8274- return n;
8275-}
8276-
8277-static inline unsigned long copy_to_user(void __user *to,
8278- const void *from, unsigned long n)
8279-{
8280- unsigned long over;
8281-
8282- if (access_ok(VERIFY_WRITE, to, n))
8283- return __copy_tofrom_user(to, (__force void __user *)from, n);
8284- if ((unsigned long)to < TASK_SIZE) {
8285- over = (unsigned long)to + n - TASK_SIZE;
8286- return __copy_tofrom_user(to, (__force void __user *)from,
8287- n - over) + over;
8288- }
8289- return n;
8290-}
8291-
8292-#else /* __powerpc64__ */
8293-
8294-#define __copy_in_user(to, from, size) \
8295- __copy_tofrom_user((to), (from), (size))
8296-
8297-extern unsigned long copy_from_user(void *to, const void __user *from,
8298- unsigned long n);
8299-extern unsigned long copy_to_user(void __user *to, const void *from,
8300- unsigned long n);
8301-extern unsigned long copy_in_user(void __user *to, const void __user *from,
8302- unsigned long n);
8303-
8304-#endif /* __powerpc64__ */
8305-
8306 static inline unsigned long __copy_from_user_inatomic(void *to,
8307 const void __user *from, unsigned long n)
8308 {
8309@@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8310 if (ret == 0)
8311 return 0;
8312 }
8313+
8314+ if (!__builtin_constant_p(n))
8315+ check_object_size(to, n, false);
8316+
8317 return __copy_tofrom_user((__force void __user *)to, from, n);
8318 }
8319
8320@@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8321 if (ret == 0)
8322 return 0;
8323 }
8324+
8325+ if (!__builtin_constant_p(n))
8326+ check_object_size(from, n, true);
8327+
8328 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8329 }
8330
8331@@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8332 return __copy_to_user_inatomic(to, from, size);
8333 }
8334
8335+#ifndef __powerpc64__
8336+
8337+static inline unsigned long __must_check copy_from_user(void *to,
8338+ const void __user *from, unsigned long n)
8339+{
8340+ unsigned long over;
8341+
8342+ if ((long)n < 0)
8343+ return n;
8344+
8345+ if (access_ok(VERIFY_READ, from, n)) {
8346+ if (!__builtin_constant_p(n))
8347+ check_object_size(to, n, false);
8348+ return __copy_tofrom_user((__force void __user *)to, from, n);
8349+ }
8350+ if ((unsigned long)from < TASK_SIZE) {
8351+ over = (unsigned long)from + n - TASK_SIZE;
8352+ if (!__builtin_constant_p(n - over))
8353+ check_object_size(to, n - over, false);
8354+ return __copy_tofrom_user((__force void __user *)to, from,
8355+ n - over) + over;
8356+ }
8357+ return n;
8358+}
8359+
8360+static inline unsigned long __must_check copy_to_user(void __user *to,
8361+ const void *from, unsigned long n)
8362+{
8363+ unsigned long over;
8364+
8365+ if ((long)n < 0)
8366+ return n;
8367+
8368+ if (access_ok(VERIFY_WRITE, to, n)) {
8369+ if (!__builtin_constant_p(n))
8370+ check_object_size(from, n, true);
8371+ return __copy_tofrom_user(to, (__force void __user *)from, n);
8372+ }
8373+ if ((unsigned long)to < TASK_SIZE) {
8374+ over = (unsigned long)to + n - TASK_SIZE;
8375+ if (!__builtin_constant_p(n))
8376+ check_object_size(from, n - over, true);
8377+ return __copy_tofrom_user(to, (__force void __user *)from,
8378+ n - over) + over;
8379+ }
8380+ return n;
8381+}
8382+
8383+#else /* __powerpc64__ */
8384+
8385+#define __copy_in_user(to, from, size) \
8386+ __copy_tofrom_user((to), (from), (size))
8387+
8388+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8389+{
8390+ if ((long)n < 0 || n > INT_MAX)
8391+ return n;
8392+
8393+ if (!__builtin_constant_p(n))
8394+ check_object_size(to, n, false);
8395+
8396+ if (likely(access_ok(VERIFY_READ, from, n)))
8397+ n = __copy_from_user(to, from, n);
8398+ else
8399+ memset(to, 0, n);
8400+ return n;
8401+}
8402+
8403+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8404+{
8405+ if ((long)n < 0 || n > INT_MAX)
8406+ return n;
8407+
8408+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
8409+ if (!__builtin_constant_p(n))
8410+ check_object_size(from, n, true);
8411+ n = __copy_to_user(to, from, n);
8412+ }
8413+ return n;
8414+}
8415+
8416+extern unsigned long copy_in_user(void __user *to, const void __user *from,
8417+ unsigned long n);
8418+
8419+#endif /* __powerpc64__ */
8420+
8421 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8422
8423 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8424diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8425index 445cb6e..4f80c5d 100644
8426--- a/arch/powerpc/kernel/Makefile
8427+++ b/arch/powerpc/kernel/Makefile
8428@@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8429 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8430 endif
8431
8432+CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8433+
8434 obj-y := cputable.o ptrace.o syscalls.o \
8435 irq.o align.o signal_32.o pmc.o vdso.o \
8436 process.o systbl.o idle.o \
8437diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8438index e775156..af2d1c0 100644
8439--- a/arch/powerpc/kernel/exceptions-64e.S
8440+++ b/arch/powerpc/kernel/exceptions-64e.S
8441@@ -759,6 +759,7 @@ storage_fault_common:
8442 std r14,_DAR(r1)
8443 std r15,_DSISR(r1)
8444 addi r3,r1,STACK_FRAME_OVERHEAD
8445+ bl .save_nvgprs
8446 mr r4,r14
8447 mr r5,r15
8448 ld r14,PACA_EXGEN+EX_R14(r13)
8449@@ -767,8 +768,7 @@ storage_fault_common:
8450 cmpdi r3,0
8451 bne- 1f
8452 b .ret_from_except_lite
8453-1: bl .save_nvgprs
8454- mr r5,r3
8455+1: mr r5,r3
8456 addi r3,r1,STACK_FRAME_OVERHEAD
8457 ld r4,_DAR(r1)
8458 bl .bad_page_fault
8459diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8460index 9f905e4..1d6b3d2 100644
8461--- a/arch/powerpc/kernel/exceptions-64s.S
8462+++ b/arch/powerpc/kernel/exceptions-64s.S
8463@@ -1390,10 +1390,10 @@ handle_page_fault:
8464 11: ld r4,_DAR(r1)
8465 ld r5,_DSISR(r1)
8466 addi r3,r1,STACK_FRAME_OVERHEAD
8467+ bl .save_nvgprs
8468 bl .do_page_fault
8469 cmpdi r3,0
8470 beq+ 12f
8471- bl .save_nvgprs
8472 mr r5,r3
8473 addi r3,r1,STACK_FRAME_OVERHEAD
8474 lwz r4,_DAR(r1)
8475diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8476index 6cff040..74ac5d1 100644
8477--- a/arch/powerpc/kernel/module_32.c
8478+++ b/arch/powerpc/kernel/module_32.c
8479@@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8480 me->arch.core_plt_section = i;
8481 }
8482 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8483- printk("Module doesn't contain .plt or .init.plt sections.\n");
8484+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8485 return -ENOEXEC;
8486 }
8487
8488@@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8489
8490 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8491 /* Init, or core PLT? */
8492- if (location >= mod->module_core
8493- && location < mod->module_core + mod->core_size)
8494+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8495+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8496 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8497- else
8498+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8499+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8500 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8501+ else {
8502+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8503+ return ~0UL;
8504+ }
8505
8506 /* Find this entry, or if that fails, the next avail. entry */
8507 while (entry->jump[0]) {
8508@@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8509 }
8510 #ifdef CONFIG_DYNAMIC_FTRACE
8511 module->arch.tramp =
8512- do_plt_call(module->module_core,
8513+ do_plt_call(module->module_core_rx,
8514 (unsigned long)ftrace_caller,
8515 sechdrs, module);
8516 #endif
8517diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8518index ea2f6a3..dbb2be3 100644
8519--- a/arch/powerpc/kernel/process.c
8520+++ b/arch/powerpc/kernel/process.c
8521@@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8522 * Lookup NIP late so we have the best change of getting the
8523 * above info out without failing
8524 */
8525- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8526- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8527+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8528+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8529 #endif
8530 show_stack(current, (unsigned long *) regs->gpr[1]);
8531 if (!user_mode(regs))
8532@@ -1385,10 +1385,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8533 newsp = stack[0];
8534 ip = stack[STACK_FRAME_LR_SAVE];
8535 if (!firstframe || ip != lr) {
8536- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8537+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8538 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8539 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8540- printk(" (%pS)",
8541+ printk(" (%pA)",
8542 (void *)current->ret_stack[curr_frame].ret);
8543 curr_frame--;
8544 }
8545@@ -1408,7 +1408,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8546 struct pt_regs *regs = (struct pt_regs *)
8547 (sp + STACK_FRAME_OVERHEAD);
8548 lr = regs->link;
8549- printk("--- Exception: %lx at %pS\n LR = %pS\n",
8550+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
8551 regs->trap, (void *)regs->nip, (void *)lr);
8552 firstframe = 1;
8553 }
8554@@ -1444,58 +1444,3 @@ void notrace __ppc64_runlatch_off(void)
8555 mtspr(SPRN_CTRLT, ctrl);
8556 }
8557 #endif /* CONFIG_PPC64 */
8558-
8559-unsigned long arch_align_stack(unsigned long sp)
8560-{
8561- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8562- sp -= get_random_int() & ~PAGE_MASK;
8563- return sp & ~0xf;
8564-}
8565-
8566-static inline unsigned long brk_rnd(void)
8567-{
8568- unsigned long rnd = 0;
8569-
8570- /* 8MB for 32bit, 1GB for 64bit */
8571- if (is_32bit_task())
8572- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8573- else
8574- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8575-
8576- return rnd << PAGE_SHIFT;
8577-}
8578-
8579-unsigned long arch_randomize_brk(struct mm_struct *mm)
8580-{
8581- unsigned long base = mm->brk;
8582- unsigned long ret;
8583-
8584-#ifdef CONFIG_PPC_STD_MMU_64
8585- /*
8586- * If we are using 1TB segments and we are allowed to randomise
8587- * the heap, we can put it above 1TB so it is backed by a 1TB
8588- * segment. Otherwise the heap will be in the bottom 1TB
8589- * which always uses 256MB segments and this may result in a
8590- * performance penalty.
8591- */
8592- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8593- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8594-#endif
8595-
8596- ret = PAGE_ALIGN(base + brk_rnd());
8597-
8598- if (ret < mm->brk)
8599- return mm->brk;
8600-
8601- return ret;
8602-}
8603-
8604-unsigned long randomize_et_dyn(unsigned long base)
8605-{
8606- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8607-
8608- if (ret < base)
8609- return base;
8610-
8611- return ret;
8612-}
8613diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8614index 2e3d2bf..35df241 100644
8615--- a/arch/powerpc/kernel/ptrace.c
8616+++ b/arch/powerpc/kernel/ptrace.c
8617@@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8618 return ret;
8619 }
8620
8621+#ifdef CONFIG_GRKERNSEC_SETXID
8622+extern void gr_delayed_cred_worker(void);
8623+#endif
8624+
8625 /*
8626 * We must return the syscall number to actually look up in the table.
8627 * This can be -1L to skip running any syscall at all.
8628@@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8629
8630 secure_computing_strict(regs->gpr[0]);
8631
8632+#ifdef CONFIG_GRKERNSEC_SETXID
8633+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8634+ gr_delayed_cred_worker();
8635+#endif
8636+
8637 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8638 tracehook_report_syscall_entry(regs))
8639 /*
8640@@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8641 {
8642 int step;
8643
8644+#ifdef CONFIG_GRKERNSEC_SETXID
8645+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8646+ gr_delayed_cred_worker();
8647+#endif
8648+
8649 audit_syscall_exit(regs);
8650
8651 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8652diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8653index 68027bf..b26fd31 100644
8654--- a/arch/powerpc/kernel/signal_32.c
8655+++ b/arch/powerpc/kernel/signal_32.c
8656@@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8657 /* Save user registers on the stack */
8658 frame = &rt_sf->uc.uc_mcontext;
8659 addr = frame;
8660- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8661+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8662 sigret = 0;
8663 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8664 } else {
8665diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8666index 448245f..b9bae83 100644
8667--- a/arch/powerpc/kernel/signal_64.c
8668+++ b/arch/powerpc/kernel/signal_64.c
8669@@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8670 #endif
8671
8672 /* Set up to return from userspace. */
8673- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8674+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8675 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8676 } else {
8677 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8678diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8679index 907a472..4ba206f 100644
8680--- a/arch/powerpc/kernel/traps.c
8681+++ b/arch/powerpc/kernel/traps.c
8682@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8683 return flags;
8684 }
8685
8686+extern void gr_handle_kernel_exploit(void);
8687+
8688 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8689 int signr)
8690 {
8691@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8692 panic("Fatal exception in interrupt");
8693 if (panic_on_oops)
8694 panic("Fatal exception");
8695+
8696+ gr_handle_kernel_exploit();
8697+
8698 do_exit(signr);
8699 }
8700
8701diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8702index 094e45c..d82b848 100644
8703--- a/arch/powerpc/kernel/vdso.c
8704+++ b/arch/powerpc/kernel/vdso.c
8705@@ -35,6 +35,7 @@
8706 #include <asm/vdso.h>
8707 #include <asm/vdso_datapage.h>
8708 #include <asm/setup.h>
8709+#include <asm/mman.h>
8710
8711 #undef DEBUG
8712
8713@@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8714 vdso_base = VDSO32_MBASE;
8715 #endif
8716
8717- current->mm->context.vdso_base = 0;
8718+ current->mm->context.vdso_base = ~0UL;
8719
8720 /* vDSO has a problem and was disabled, just don't "enable" it for the
8721 * process
8722@@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8723 vdso_base = get_unmapped_area(NULL, vdso_base,
8724 (vdso_pages << PAGE_SHIFT) +
8725 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8726- 0, 0);
8727+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
8728 if (IS_ERR_VALUE(vdso_base)) {
8729 rc = vdso_base;
8730 goto fail_mmapsem;
8731diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8732index 9ae9768..87c3448 100644
8733--- a/arch/powerpc/kvm/powerpc.c
8734+++ b/arch/powerpc/kvm/powerpc.c
8735@@ -1141,7 +1141,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8736 }
8737 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8738
8739-int kvm_arch_init(void *opaque)
8740+int kvm_arch_init(const void *opaque)
8741 {
8742 return 0;
8743 }
8744diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8745index 5eea6f3..5d10396 100644
8746--- a/arch/powerpc/lib/usercopy_64.c
8747+++ b/arch/powerpc/lib/usercopy_64.c
8748@@ -9,22 +9,6 @@
8749 #include <linux/module.h>
8750 #include <asm/uaccess.h>
8751
8752-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8753-{
8754- if (likely(access_ok(VERIFY_READ, from, n)))
8755- n = __copy_from_user(to, from, n);
8756- else
8757- memset(to, 0, n);
8758- return n;
8759-}
8760-
8761-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8762-{
8763- if (likely(access_ok(VERIFY_WRITE, to, n)))
8764- n = __copy_to_user(to, from, n);
8765- return n;
8766-}
8767-
8768 unsigned long copy_in_user(void __user *to, const void __user *from,
8769 unsigned long n)
8770 {
8771@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8772 return n;
8773 }
8774
8775-EXPORT_SYMBOL(copy_from_user);
8776-EXPORT_SYMBOL(copy_to_user);
8777 EXPORT_SYMBOL(copy_in_user);
8778
8779diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8780index 51ab9e7..7d3c78b 100644
8781--- a/arch/powerpc/mm/fault.c
8782+++ b/arch/powerpc/mm/fault.c
8783@@ -33,6 +33,10 @@
8784 #include <linux/magic.h>
8785 #include <linux/ratelimit.h>
8786 #include <linux/context_tracking.h>
8787+#include <linux/slab.h>
8788+#include <linux/pagemap.h>
8789+#include <linux/compiler.h>
8790+#include <linux/unistd.h>
8791
8792 #include <asm/firmware.h>
8793 #include <asm/page.h>
8794@@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8795 }
8796 #endif
8797
8798+#ifdef CONFIG_PAX_PAGEEXEC
8799+/*
8800+ * PaX: decide what to do with offenders (regs->nip = fault address)
8801+ *
8802+ * returns 1 when task should be killed
8803+ */
8804+static int pax_handle_fetch_fault(struct pt_regs *regs)
8805+{
8806+ return 1;
8807+}
8808+
8809+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8810+{
8811+ unsigned long i;
8812+
8813+ printk(KERN_ERR "PAX: bytes at PC: ");
8814+ for (i = 0; i < 5; i++) {
8815+ unsigned int c;
8816+ if (get_user(c, (unsigned int __user *)pc+i))
8817+ printk(KERN_CONT "???????? ");
8818+ else
8819+ printk(KERN_CONT "%08x ", c);
8820+ }
8821+ printk("\n");
8822+}
8823+#endif
8824+
8825 /*
8826 * Check whether the instruction at regs->nip is a store using
8827 * an update addressing form which will update r1.
8828@@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8829 * indicate errors in DSISR but can validly be set in SRR1.
8830 */
8831 if (trap == 0x400)
8832- error_code &= 0x48200000;
8833+ error_code &= 0x58200000;
8834 else
8835 is_write = error_code & DSISR_ISSTORE;
8836 #else
8837@@ -378,7 +409,7 @@ good_area:
8838 * "undefined". Of those that can be set, this is the only
8839 * one which seems bad.
8840 */
8841- if (error_code & 0x10000000)
8842+ if (error_code & DSISR_GUARDED)
8843 /* Guarded storage error. */
8844 goto bad_area;
8845 #endif /* CONFIG_8xx */
8846@@ -393,7 +424,7 @@ good_area:
8847 * processors use the same I/D cache coherency mechanism
8848 * as embedded.
8849 */
8850- if (error_code & DSISR_PROTFAULT)
8851+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8852 goto bad_area;
8853 #endif /* CONFIG_PPC_STD_MMU */
8854
8855@@ -483,6 +514,23 @@ bad_area:
8856 bad_area_nosemaphore:
8857 /* User mode accesses cause a SIGSEGV */
8858 if (user_mode(regs)) {
8859+
8860+#ifdef CONFIG_PAX_PAGEEXEC
8861+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8862+#ifdef CONFIG_PPC_STD_MMU
8863+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8864+#else
8865+ if (is_exec && regs->nip == address) {
8866+#endif
8867+ switch (pax_handle_fetch_fault(regs)) {
8868+ }
8869+
8870+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8871+ do_group_exit(SIGKILL);
8872+ }
8873+ }
8874+#endif
8875+
8876 _exception(SIGSEGV, regs, code, address);
8877 goto bail;
8878 }
8879diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8880index cb8bdbe..cde4bc7 100644
8881--- a/arch/powerpc/mm/mmap.c
8882+++ b/arch/powerpc/mm/mmap.c
8883@@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
8884 return sysctl_legacy_va_layout;
8885 }
8886
8887-static unsigned long mmap_rnd(void)
8888+static unsigned long mmap_rnd(struct mm_struct *mm)
8889 {
8890 unsigned long rnd = 0;
8891
8892+#ifdef CONFIG_PAX_RANDMMAP
8893+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8894+#endif
8895+
8896 if (current->flags & PF_RANDOMIZE) {
8897 /* 8MB for 32bit, 1GB for 64bit */
8898 if (is_32bit_task())
8899@@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
8900 return rnd << PAGE_SHIFT;
8901 }
8902
8903-static inline unsigned long mmap_base(void)
8904+static inline unsigned long mmap_base(struct mm_struct *mm)
8905 {
8906 unsigned long gap = rlimit(RLIMIT_STACK);
8907
8908@@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
8909 else if (gap > MAX_GAP)
8910 gap = MAX_GAP;
8911
8912- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
8913+ return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
8914 }
8915
8916 /*
8917@@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8918 */
8919 if (mmap_is_legacy()) {
8920 mm->mmap_base = TASK_UNMAPPED_BASE;
8921+
8922+#ifdef CONFIG_PAX_RANDMMAP
8923+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8924+ mm->mmap_base += mm->delta_mmap;
8925+#endif
8926+
8927 mm->get_unmapped_area = arch_get_unmapped_area;
8928 } else {
8929- mm->mmap_base = mmap_base();
8930+ mm->mmap_base = mmap_base(mm);
8931+
8932+#ifdef CONFIG_PAX_RANDMMAP
8933+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8934+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8935+#endif
8936+
8937 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8938 }
8939 }
8940diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8941index 7ce9cf3..a964087 100644
8942--- a/arch/powerpc/mm/slice.c
8943+++ b/arch/powerpc/mm/slice.c
8944@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8945 if ((mm->task_size - len) < addr)
8946 return 0;
8947 vma = find_vma(mm, addr);
8948- return (!vma || (addr + len) <= vma->vm_start);
8949+ return check_heap_stack_gap(vma, addr, len, 0);
8950 }
8951
8952 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8953@@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8954 info.align_offset = 0;
8955
8956 addr = TASK_UNMAPPED_BASE;
8957+
8958+#ifdef CONFIG_PAX_RANDMMAP
8959+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8960+ addr += mm->delta_mmap;
8961+#endif
8962+
8963 while (addr < TASK_SIZE) {
8964 info.low_limit = addr;
8965 if (!slice_scan_available(addr, available, 1, &addr))
8966@@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8967 if (fixed && addr > (mm->task_size - len))
8968 return -EINVAL;
8969
8970+#ifdef CONFIG_PAX_RANDMMAP
8971+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8972+ addr = 0;
8973+#endif
8974+
8975 /* If hint, make sure it matches our alignment restrictions */
8976 if (!fixed && addr) {
8977 addr = _ALIGN_UP(addr, 1ul << pshift);
8978diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8979index 4278acf..67fd0e6 100644
8980--- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8981+++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
8982@@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
8983 }
8984
8985 static struct pci_ops scc_pciex_pci_ops = {
8986- scc_pciex_read_config,
8987- scc_pciex_write_config,
8988+ .read = scc_pciex_read_config,
8989+ .write = scc_pciex_write_config,
8990 };
8991
8992 static void pciex_clear_intr_all(unsigned int __iomem *base)
8993diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8994index 9098692..3d54cd1 100644
8995--- a/arch/powerpc/platforms/cell/spufs/file.c
8996+++ b/arch/powerpc/platforms/cell/spufs/file.c
8997@@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8998 return VM_FAULT_NOPAGE;
8999 }
9000
9001-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9002+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9003 unsigned long address,
9004- void *buf, int len, int write)
9005+ void *buf, size_t len, int write)
9006 {
9007 struct spu_context *ctx = vma->vm_file->private_data;
9008 unsigned long offset = address - vma->vm_start;
9009diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9010index fa9aaf7..3f5d836 100644
9011--- a/arch/s390/include/asm/atomic.h
9012+++ b/arch/s390/include/asm/atomic.h
9013@@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9014 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9015 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9016
9017+#define atomic64_read_unchecked(v) atomic64_read(v)
9018+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9019+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9020+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9021+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9022+#define atomic64_inc_unchecked(v) atomic64_inc(v)
9023+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9024+#define atomic64_dec_unchecked(v) atomic64_dec(v)
9025+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9026+
9027 #define smp_mb__before_atomic_dec() smp_mb()
9028 #define smp_mb__after_atomic_dec() smp_mb()
9029 #define smp_mb__before_atomic_inc() smp_mb()
9030diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9031index 4d7ccac..d03d0ad 100644
9032--- a/arch/s390/include/asm/cache.h
9033+++ b/arch/s390/include/asm/cache.h
9034@@ -9,8 +9,10 @@
9035 #ifndef __ARCH_S390_CACHE_H
9036 #define __ARCH_S390_CACHE_H
9037
9038-#define L1_CACHE_BYTES 256
9039+#include <linux/const.h>
9040+
9041 #define L1_CACHE_SHIFT 8
9042+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9043 #define NET_SKB_PAD 32
9044
9045 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9046diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9047index 78f4f87..598ce39 100644
9048--- a/arch/s390/include/asm/elf.h
9049+++ b/arch/s390/include/asm/elf.h
9050@@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9051 the loader. We need to make sure that it is out of the way of the program
9052 that it will "exec", and that there is sufficient room for the brk. */
9053
9054-extern unsigned long randomize_et_dyn(unsigned long base);
9055-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9056+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9057+
9058+#ifdef CONFIG_PAX_ASLR
9059+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9060+
9061+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9062+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9063+#endif
9064
9065 /* This yields a mask that user programs can use to figure out what
9066 instruction set this CPU supports. */
9067@@ -222,9 +228,6 @@ struct linux_binprm;
9068 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9069 int arch_setup_additional_pages(struct linux_binprm *, int);
9070
9071-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9072-#define arch_randomize_brk arch_randomize_brk
9073-
9074 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9075
9076 #endif
9077diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9078index c4a93d6..4d2a9b4 100644
9079--- a/arch/s390/include/asm/exec.h
9080+++ b/arch/s390/include/asm/exec.h
9081@@ -7,6 +7,6 @@
9082 #ifndef __ASM_EXEC_H
9083 #define __ASM_EXEC_H
9084
9085-extern unsigned long arch_align_stack(unsigned long sp);
9086+#define arch_align_stack(x) ((x) & ~0xfUL)
9087
9088 #endif /* __ASM_EXEC_H */
9089diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9090index 79330af..254cf37 100644
9091--- a/arch/s390/include/asm/uaccess.h
9092+++ b/arch/s390/include/asm/uaccess.h
9093@@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9094 __range_ok((unsigned long)(addr), (size)); \
9095 })
9096
9097+#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9098 #define access_ok(type, addr, size) __access_ok(addr, size)
9099
9100 /*
9101@@ -245,6 +246,10 @@ static inline unsigned long __must_check
9102 copy_to_user(void __user *to, const void *from, unsigned long n)
9103 {
9104 might_fault();
9105+
9106+ if ((long)n < 0)
9107+ return n;
9108+
9109 return __copy_to_user(to, from, n);
9110 }
9111
9112@@ -268,6 +273,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
9113 static inline unsigned long __must_check
9114 __copy_from_user(void *to, const void __user *from, unsigned long n)
9115 {
9116+ if ((long)n < 0)
9117+ return n;
9118+
9119 return uaccess.copy_from_user(n, from, to);
9120 }
9121
9122@@ -296,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9123 static inline unsigned long __must_check
9124 copy_from_user(void *to, const void __user *from, unsigned long n)
9125 {
9126- unsigned int sz = __compiletime_object_size(to);
9127+ size_t sz = __compiletime_object_size(to);
9128
9129 might_fault();
9130- if (unlikely(sz != -1 && sz < n)) {
9131+
9132+ if ((long)n < 0)
9133+ return n;
9134+
9135+ if (unlikely(sz != (size_t)-1 && sz < n)) {
9136 copy_from_user_overflow();
9137 return n;
9138 }
9139diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9140index b89b591..fd9609d 100644
9141--- a/arch/s390/kernel/module.c
9142+++ b/arch/s390/kernel/module.c
9143@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9144
9145 /* Increase core size by size of got & plt and set start
9146 offsets for got and plt. */
9147- me->core_size = ALIGN(me->core_size, 4);
9148- me->arch.got_offset = me->core_size;
9149- me->core_size += me->arch.got_size;
9150- me->arch.plt_offset = me->core_size;
9151- me->core_size += me->arch.plt_size;
9152+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
9153+ me->arch.got_offset = me->core_size_rw;
9154+ me->core_size_rw += me->arch.got_size;
9155+ me->arch.plt_offset = me->core_size_rx;
9156+ me->core_size_rx += me->arch.plt_size;
9157 return 0;
9158 }
9159
9160@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9161 if (info->got_initialized == 0) {
9162 Elf_Addr *gotent;
9163
9164- gotent = me->module_core + me->arch.got_offset +
9165+ gotent = me->module_core_rw + me->arch.got_offset +
9166 info->got_offset;
9167 *gotent = val;
9168 info->got_initialized = 1;
9169@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9170 rc = apply_rela_bits(loc, val, 0, 64, 0);
9171 else if (r_type == R_390_GOTENT ||
9172 r_type == R_390_GOTPLTENT) {
9173- val += (Elf_Addr) me->module_core - loc;
9174+ val += (Elf_Addr) me->module_core_rw - loc;
9175 rc = apply_rela_bits(loc, val, 1, 32, 1);
9176 }
9177 break;
9178@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9179 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9180 if (info->plt_initialized == 0) {
9181 unsigned int *ip;
9182- ip = me->module_core + me->arch.plt_offset +
9183+ ip = me->module_core_rx + me->arch.plt_offset +
9184 info->plt_offset;
9185 #ifndef CONFIG_64BIT
9186 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9187@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9188 val - loc + 0xffffUL < 0x1ffffeUL) ||
9189 (r_type == R_390_PLT32DBL &&
9190 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9191- val = (Elf_Addr) me->module_core +
9192+ val = (Elf_Addr) me->module_core_rx +
9193 me->arch.plt_offset +
9194 info->plt_offset;
9195 val += rela->r_addend - loc;
9196@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9197 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9198 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9199 val = val + rela->r_addend -
9200- ((Elf_Addr) me->module_core + me->arch.got_offset);
9201+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9202 if (r_type == R_390_GOTOFF16)
9203 rc = apply_rela_bits(loc, val, 0, 16, 0);
9204 else if (r_type == R_390_GOTOFF32)
9205@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9206 break;
9207 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9208 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9209- val = (Elf_Addr) me->module_core + me->arch.got_offset +
9210+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9211 rela->r_addend - loc;
9212 if (r_type == R_390_GOTPC)
9213 rc = apply_rela_bits(loc, val, 1, 32, 0);
9214diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9215index 7ed0d4e..1dfc145 100644
9216--- a/arch/s390/kernel/process.c
9217+++ b/arch/s390/kernel/process.c
9218@@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9219 }
9220 return 0;
9221 }
9222-
9223-unsigned long arch_align_stack(unsigned long sp)
9224-{
9225- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9226- sp -= get_random_int() & ~PAGE_MASK;
9227- return sp & ~0xf;
9228-}
9229-
9230-static inline unsigned long brk_rnd(void)
9231-{
9232- /* 8MB for 32bit, 1GB for 64bit */
9233- if (is_32bit_task())
9234- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9235- else
9236- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9237-}
9238-
9239-unsigned long arch_randomize_brk(struct mm_struct *mm)
9240-{
9241- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
9242-
9243- if (ret < mm->brk)
9244- return mm->brk;
9245- return ret;
9246-}
9247-
9248-unsigned long randomize_et_dyn(unsigned long base)
9249-{
9250- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
9251-
9252- if (!(current->flags & PF_RANDOMIZE))
9253- return base;
9254- if (ret < base)
9255- return base;
9256- return ret;
9257-}
9258diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9259index 9b436c2..54fbf0a 100644
9260--- a/arch/s390/mm/mmap.c
9261+++ b/arch/s390/mm/mmap.c
9262@@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9263 */
9264 if (mmap_is_legacy()) {
9265 mm->mmap_base = mmap_base_legacy();
9266+
9267+#ifdef CONFIG_PAX_RANDMMAP
9268+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9269+ mm->mmap_base += mm->delta_mmap;
9270+#endif
9271+
9272 mm->get_unmapped_area = arch_get_unmapped_area;
9273 } else {
9274 mm->mmap_base = mmap_base();
9275+
9276+#ifdef CONFIG_PAX_RANDMMAP
9277+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9278+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9279+#endif
9280+
9281 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9282 }
9283 }
9284@@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9285 */
9286 if (mmap_is_legacy()) {
9287 mm->mmap_base = mmap_base_legacy();
9288+
9289+#ifdef CONFIG_PAX_RANDMMAP
9290+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9291+ mm->mmap_base += mm->delta_mmap;
9292+#endif
9293+
9294 mm->get_unmapped_area = s390_get_unmapped_area;
9295 } else {
9296 mm->mmap_base = mmap_base();
9297+
9298+#ifdef CONFIG_PAX_RANDMMAP
9299+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9300+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9301+#endif
9302+
9303 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9304 }
9305 }
9306diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9307index ae3d59f..f65f075 100644
9308--- a/arch/score/include/asm/cache.h
9309+++ b/arch/score/include/asm/cache.h
9310@@ -1,7 +1,9 @@
9311 #ifndef _ASM_SCORE_CACHE_H
9312 #define _ASM_SCORE_CACHE_H
9313
9314+#include <linux/const.h>
9315+
9316 #define L1_CACHE_SHIFT 4
9317-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9318+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9319
9320 #endif /* _ASM_SCORE_CACHE_H */
9321diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9322index f9f3cd5..58ff438 100644
9323--- a/arch/score/include/asm/exec.h
9324+++ b/arch/score/include/asm/exec.h
9325@@ -1,6 +1,6 @@
9326 #ifndef _ASM_SCORE_EXEC_H
9327 #define _ASM_SCORE_EXEC_H
9328
9329-extern unsigned long arch_align_stack(unsigned long sp);
9330+#define arch_align_stack(x) (x)
9331
9332 #endif /* _ASM_SCORE_EXEC_H */
9333diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9334index a1519ad3..e8ac1ff 100644
9335--- a/arch/score/kernel/process.c
9336+++ b/arch/score/kernel/process.c
9337@@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9338
9339 return task_pt_regs(task)->cp0_epc;
9340 }
9341-
9342-unsigned long arch_align_stack(unsigned long sp)
9343-{
9344- return sp;
9345-}
9346diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9347index ef9e555..331bd29 100644
9348--- a/arch/sh/include/asm/cache.h
9349+++ b/arch/sh/include/asm/cache.h
9350@@ -9,10 +9,11 @@
9351 #define __ASM_SH_CACHE_H
9352 #ifdef __KERNEL__
9353
9354+#include <linux/const.h>
9355 #include <linux/init.h>
9356 #include <cpu/cache.h>
9357
9358-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9359+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9360
9361 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9362
9363diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9364index 6777177..cb5e44f 100644
9365--- a/arch/sh/mm/mmap.c
9366+++ b/arch/sh/mm/mmap.c
9367@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9368 struct mm_struct *mm = current->mm;
9369 struct vm_area_struct *vma;
9370 int do_colour_align;
9371+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9372 struct vm_unmapped_area_info info;
9373
9374 if (flags & MAP_FIXED) {
9375@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9376 if (filp || (flags & MAP_SHARED))
9377 do_colour_align = 1;
9378
9379+#ifdef CONFIG_PAX_RANDMMAP
9380+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9381+#endif
9382+
9383 if (addr) {
9384 if (do_colour_align)
9385 addr = COLOUR_ALIGN(addr, pgoff);
9386@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9387 addr = PAGE_ALIGN(addr);
9388
9389 vma = find_vma(mm, addr);
9390- if (TASK_SIZE - len >= addr &&
9391- (!vma || addr + len <= vma->vm_start))
9392+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9393 return addr;
9394 }
9395
9396 info.flags = 0;
9397 info.length = len;
9398- info.low_limit = TASK_UNMAPPED_BASE;
9399+ info.low_limit = mm->mmap_base;
9400 info.high_limit = TASK_SIZE;
9401 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9402 info.align_offset = pgoff << PAGE_SHIFT;
9403@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9404 struct mm_struct *mm = current->mm;
9405 unsigned long addr = addr0;
9406 int do_colour_align;
9407+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9408 struct vm_unmapped_area_info info;
9409
9410 if (flags & MAP_FIXED) {
9411@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9412 if (filp || (flags & MAP_SHARED))
9413 do_colour_align = 1;
9414
9415+#ifdef CONFIG_PAX_RANDMMAP
9416+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9417+#endif
9418+
9419 /* requesting a specific address */
9420 if (addr) {
9421 if (do_colour_align)
9422@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9423 addr = PAGE_ALIGN(addr);
9424
9425 vma = find_vma(mm, addr);
9426- if (TASK_SIZE - len >= addr &&
9427- (!vma || addr + len <= vma->vm_start))
9428+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9429 return addr;
9430 }
9431
9432@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9433 VM_BUG_ON(addr != -ENOMEM);
9434 info.flags = 0;
9435 info.low_limit = TASK_UNMAPPED_BASE;
9436+
9437+#ifdef CONFIG_PAX_RANDMMAP
9438+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9439+ info.low_limit += mm->delta_mmap;
9440+#endif
9441+
9442 info.high_limit = TASK_SIZE;
9443 addr = vm_unmapped_area(&info);
9444 }
9445diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9446index be56a24..443328f 100644
9447--- a/arch/sparc/include/asm/atomic_64.h
9448+++ b/arch/sparc/include/asm/atomic_64.h
9449@@ -14,18 +14,40 @@
9450 #define ATOMIC64_INIT(i) { (i) }
9451
9452 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9453+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9454+{
9455+ return v->counter;
9456+}
9457 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9458+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9459+{
9460+ return v->counter;
9461+}
9462
9463 #define atomic_set(v, i) (((v)->counter) = i)
9464+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9465+{
9466+ v->counter = i;
9467+}
9468 #define atomic64_set(v, i) (((v)->counter) = i)
9469+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9470+{
9471+ v->counter = i;
9472+}
9473
9474 extern void atomic_add(int, atomic_t *);
9475+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9476 extern void atomic64_add(long, atomic64_t *);
9477+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9478 extern void atomic_sub(int, atomic_t *);
9479+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9480 extern void atomic64_sub(long, atomic64_t *);
9481+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9482
9483 extern int atomic_add_ret(int, atomic_t *);
9484+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9485 extern long atomic64_add_ret(long, atomic64_t *);
9486+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9487 extern int atomic_sub_ret(int, atomic_t *);
9488 extern long atomic64_sub_ret(long, atomic64_t *);
9489
9490@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9491 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9492
9493 #define atomic_inc_return(v) atomic_add_ret(1, v)
9494+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9495+{
9496+ return atomic_add_ret_unchecked(1, v);
9497+}
9498 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9499+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9500+{
9501+ return atomic64_add_ret_unchecked(1, v);
9502+}
9503
9504 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9505 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9506
9507 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9508+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9509+{
9510+ return atomic_add_ret_unchecked(i, v);
9511+}
9512 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9513+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9514+{
9515+ return atomic64_add_ret_unchecked(i, v);
9516+}
9517
9518 /*
9519 * atomic_inc_and_test - increment and test
9520@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9521 * other cases.
9522 */
9523 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9524+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9525+{
9526+ return atomic_inc_return_unchecked(v) == 0;
9527+}
9528 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9529
9530 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9531@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9532 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9533
9534 #define atomic_inc(v) atomic_add(1, v)
9535+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9536+{
9537+ atomic_add_unchecked(1, v);
9538+}
9539 #define atomic64_inc(v) atomic64_add(1, v)
9540+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9541+{
9542+ atomic64_add_unchecked(1, v);
9543+}
9544
9545 #define atomic_dec(v) atomic_sub(1, v)
9546+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9547+{
9548+ atomic_sub_unchecked(1, v);
9549+}
9550 #define atomic64_dec(v) atomic64_sub(1, v)
9551+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9552+{
9553+ atomic64_sub_unchecked(1, v);
9554+}
9555
9556 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9557 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9558
9559 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9560+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9561+{
9562+ return cmpxchg(&v->counter, old, new);
9563+}
9564 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9565+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9566+{
9567+ return xchg(&v->counter, new);
9568+}
9569
9570 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9571 {
9572- int c, old;
9573+ int c, old, new;
9574 c = atomic_read(v);
9575 for (;;) {
9576- if (unlikely(c == (u)))
9577+ if (unlikely(c == u))
9578 break;
9579- old = atomic_cmpxchg((v), c, c + (a));
9580+
9581+ asm volatile("addcc %2, %0, %0\n"
9582+
9583+#ifdef CONFIG_PAX_REFCOUNT
9584+ "tvs %%icc, 6\n"
9585+#endif
9586+
9587+ : "=r" (new)
9588+ : "0" (c), "ir" (a)
9589+ : "cc");
9590+
9591+ old = atomic_cmpxchg(v, c, new);
9592 if (likely(old == c))
9593 break;
9594 c = old;
9595@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9596 #define atomic64_cmpxchg(v, o, n) \
9597 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9598 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9599+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9600+{
9601+ return xchg(&v->counter, new);
9602+}
9603
9604 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9605 {
9606- long c, old;
9607+ long c, old, new;
9608 c = atomic64_read(v);
9609 for (;;) {
9610- if (unlikely(c == (u)))
9611+ if (unlikely(c == u))
9612 break;
9613- old = atomic64_cmpxchg((v), c, c + (a));
9614+
9615+ asm volatile("addcc %2, %0, %0\n"
9616+
9617+#ifdef CONFIG_PAX_REFCOUNT
9618+ "tvs %%xcc, 6\n"
9619+#endif
9620+
9621+ : "=r" (new)
9622+ : "0" (c), "ir" (a)
9623+ : "cc");
9624+
9625+ old = atomic64_cmpxchg(v, c, new);
9626 if (likely(old == c))
9627 break;
9628 c = old;
9629 }
9630- return c != (u);
9631+ return c != u;
9632 }
9633
9634 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9635diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9636index 5bb6991..5c2132e 100644
9637--- a/arch/sparc/include/asm/cache.h
9638+++ b/arch/sparc/include/asm/cache.h
9639@@ -7,10 +7,12 @@
9640 #ifndef _SPARC_CACHE_H
9641 #define _SPARC_CACHE_H
9642
9643+#include <linux/const.h>
9644+
9645 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9646
9647 #define L1_CACHE_SHIFT 5
9648-#define L1_CACHE_BYTES 32
9649+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9650
9651 #ifdef CONFIG_SPARC32
9652 #define SMP_CACHE_BYTES_SHIFT 5
9653diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9654index a24e41f..47677ff 100644
9655--- a/arch/sparc/include/asm/elf_32.h
9656+++ b/arch/sparc/include/asm/elf_32.h
9657@@ -114,6 +114,13 @@ typedef struct {
9658
9659 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9660
9661+#ifdef CONFIG_PAX_ASLR
9662+#define PAX_ELF_ET_DYN_BASE 0x10000UL
9663+
9664+#define PAX_DELTA_MMAP_LEN 16
9665+#define PAX_DELTA_STACK_LEN 16
9666+#endif
9667+
9668 /* This yields a mask that user programs can use to figure out what
9669 instruction set this cpu supports. This can NOT be done in userspace
9670 on Sparc. */
9671diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9672index 370ca1e..d4f4a98 100644
9673--- a/arch/sparc/include/asm/elf_64.h
9674+++ b/arch/sparc/include/asm/elf_64.h
9675@@ -189,6 +189,13 @@ typedef struct {
9676 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9677 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9678
9679+#ifdef CONFIG_PAX_ASLR
9680+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9681+
9682+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9683+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9684+#endif
9685+
9686 extern unsigned long sparc64_elf_hwcap;
9687 #define ELF_HWCAP sparc64_elf_hwcap
9688
9689diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9690index 9b1c36d..209298b 100644
9691--- a/arch/sparc/include/asm/pgalloc_32.h
9692+++ b/arch/sparc/include/asm/pgalloc_32.h
9693@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9694 }
9695
9696 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9697+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9698
9699 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9700 unsigned long address)
9701diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9702index bcfe063..b333142 100644
9703--- a/arch/sparc/include/asm/pgalloc_64.h
9704+++ b/arch/sparc/include/asm/pgalloc_64.h
9705@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9706 }
9707
9708 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9709+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9710
9711 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9712 {
9713diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9714index 59ba6f6..4518128 100644
9715--- a/arch/sparc/include/asm/pgtable.h
9716+++ b/arch/sparc/include/asm/pgtable.h
9717@@ -5,4 +5,8 @@
9718 #else
9719 #include <asm/pgtable_32.h>
9720 #endif
9721+
9722+#define ktla_ktva(addr) (addr)
9723+#define ktva_ktla(addr) (addr)
9724+
9725 #endif
9726diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9727index 502f632..da1917f 100644
9728--- a/arch/sparc/include/asm/pgtable_32.h
9729+++ b/arch/sparc/include/asm/pgtable_32.h
9730@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9731 #define PAGE_SHARED SRMMU_PAGE_SHARED
9732 #define PAGE_COPY SRMMU_PAGE_COPY
9733 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9734+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9735+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9736+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9737 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9738
9739 /* Top-level page directory - dummy used by init-mm.
9740@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9741
9742 /* xwr */
9743 #define __P000 PAGE_NONE
9744-#define __P001 PAGE_READONLY
9745-#define __P010 PAGE_COPY
9746-#define __P011 PAGE_COPY
9747+#define __P001 PAGE_READONLY_NOEXEC
9748+#define __P010 PAGE_COPY_NOEXEC
9749+#define __P011 PAGE_COPY_NOEXEC
9750 #define __P100 PAGE_READONLY
9751 #define __P101 PAGE_READONLY
9752 #define __P110 PAGE_COPY
9753 #define __P111 PAGE_COPY
9754
9755 #define __S000 PAGE_NONE
9756-#define __S001 PAGE_READONLY
9757-#define __S010 PAGE_SHARED
9758-#define __S011 PAGE_SHARED
9759+#define __S001 PAGE_READONLY_NOEXEC
9760+#define __S010 PAGE_SHARED_NOEXEC
9761+#define __S011 PAGE_SHARED_NOEXEC
9762 #define __S100 PAGE_READONLY
9763 #define __S101 PAGE_READONLY
9764 #define __S110 PAGE_SHARED
9765diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9766index 79da178..c2eede8 100644
9767--- a/arch/sparc/include/asm/pgtsrmmu.h
9768+++ b/arch/sparc/include/asm/pgtsrmmu.h
9769@@ -115,6 +115,11 @@
9770 SRMMU_EXEC | SRMMU_REF)
9771 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9772 SRMMU_EXEC | SRMMU_REF)
9773+
9774+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9775+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9776+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9777+
9778 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9779 SRMMU_DIRTY | SRMMU_REF)
9780
9781diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9782index 9689176..63c18ea 100644
9783--- a/arch/sparc/include/asm/spinlock_64.h
9784+++ b/arch/sparc/include/asm/spinlock_64.h
9785@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9786
9787 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9788
9789-static void inline arch_read_lock(arch_rwlock_t *lock)
9790+static inline void arch_read_lock(arch_rwlock_t *lock)
9791 {
9792 unsigned long tmp1, tmp2;
9793
9794 __asm__ __volatile__ (
9795 "1: ldsw [%2], %0\n"
9796 " brlz,pn %0, 2f\n"
9797-"4: add %0, 1, %1\n"
9798+"4: addcc %0, 1, %1\n"
9799+
9800+#ifdef CONFIG_PAX_REFCOUNT
9801+" tvs %%icc, 6\n"
9802+#endif
9803+
9804 " cas [%2], %0, %1\n"
9805 " cmp %0, %1\n"
9806 " bne,pn %%icc, 1b\n"
9807@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9808 " .previous"
9809 : "=&r" (tmp1), "=&r" (tmp2)
9810 : "r" (lock)
9811- : "memory");
9812+ : "memory", "cc");
9813 }
9814
9815-static int inline arch_read_trylock(arch_rwlock_t *lock)
9816+static inline int arch_read_trylock(arch_rwlock_t *lock)
9817 {
9818 int tmp1, tmp2;
9819
9820@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9821 "1: ldsw [%2], %0\n"
9822 " brlz,a,pn %0, 2f\n"
9823 " mov 0, %0\n"
9824-" add %0, 1, %1\n"
9825+" addcc %0, 1, %1\n"
9826+
9827+#ifdef CONFIG_PAX_REFCOUNT
9828+" tvs %%icc, 6\n"
9829+#endif
9830+
9831 " cas [%2], %0, %1\n"
9832 " cmp %0, %1\n"
9833 " bne,pn %%icc, 1b\n"
9834@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9835 return tmp1;
9836 }
9837
9838-static void inline arch_read_unlock(arch_rwlock_t *lock)
9839+static inline void arch_read_unlock(arch_rwlock_t *lock)
9840 {
9841 unsigned long tmp1, tmp2;
9842
9843 __asm__ __volatile__(
9844 "1: lduw [%2], %0\n"
9845-" sub %0, 1, %1\n"
9846+" subcc %0, 1, %1\n"
9847+
9848+#ifdef CONFIG_PAX_REFCOUNT
9849+" tvs %%icc, 6\n"
9850+#endif
9851+
9852 " cas [%2], %0, %1\n"
9853 " cmp %0, %1\n"
9854 " bne,pn %%xcc, 1b\n"
9855@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9856 : "memory");
9857 }
9858
9859-static void inline arch_write_lock(arch_rwlock_t *lock)
9860+static inline void arch_write_lock(arch_rwlock_t *lock)
9861 {
9862 unsigned long mask, tmp1, tmp2;
9863
9864@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9865 : "memory");
9866 }
9867
9868-static void inline arch_write_unlock(arch_rwlock_t *lock)
9869+static inline void arch_write_unlock(arch_rwlock_t *lock)
9870 {
9871 __asm__ __volatile__(
9872 " stw %%g0, [%0]"
9873@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9874 : "memory");
9875 }
9876
9877-static int inline arch_write_trylock(arch_rwlock_t *lock)
9878+static inline int arch_write_trylock(arch_rwlock_t *lock)
9879 {
9880 unsigned long mask, tmp1, tmp2, result;
9881
9882diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9883index 96efa7a..16858bf 100644
9884--- a/arch/sparc/include/asm/thread_info_32.h
9885+++ b/arch/sparc/include/asm/thread_info_32.h
9886@@ -49,6 +49,8 @@ struct thread_info {
9887 unsigned long w_saved;
9888
9889 struct restart_block restart_block;
9890+
9891+ unsigned long lowest_stack;
9892 };
9893
9894 /*
9895diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9896index a5f01ac..703b554 100644
9897--- a/arch/sparc/include/asm/thread_info_64.h
9898+++ b/arch/sparc/include/asm/thread_info_64.h
9899@@ -63,6 +63,8 @@ struct thread_info {
9900 struct pt_regs *kern_una_regs;
9901 unsigned int kern_una_insn;
9902
9903+ unsigned long lowest_stack;
9904+
9905 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9906 };
9907
9908@@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9909 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9910 /* flag bit 4 is available */
9911 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9912-/* flag bit 6 is available */
9913+#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9914 #define TIF_32BIT 7 /* 32-bit binary */
9915 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9916 #define TIF_SECCOMP 9 /* secure computing */
9917 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9918 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9919+
9920 /* NOTE: Thread flags >= 12 should be ones we have no interest
9921 * in using in assembly, else we can't use the mask as
9922 * an immediate value in instructions such as andcc.
9923@@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9924 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9925 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9926 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9927+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9928
9929 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9930 _TIF_DO_NOTIFY_RESUME_MASK | \
9931 _TIF_NEED_RESCHED)
9932 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9933
9934+#define _TIF_WORK_SYSCALL \
9935+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9936+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9937+
9938+
9939 /*
9940 * Thread-synchronous status.
9941 *
9942diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9943index 0167d26..767bb0c 100644
9944--- a/arch/sparc/include/asm/uaccess.h
9945+++ b/arch/sparc/include/asm/uaccess.h
9946@@ -1,5 +1,6 @@
9947 #ifndef ___ASM_SPARC_UACCESS_H
9948 #define ___ASM_SPARC_UACCESS_H
9949+
9950 #if defined(__sparc__) && defined(__arch64__)
9951 #include <asm/uaccess_64.h>
9952 #else
9953diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9954index 53a28dd..50c38c3 100644
9955--- a/arch/sparc/include/asm/uaccess_32.h
9956+++ b/arch/sparc/include/asm/uaccess_32.h
9957@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9958
9959 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9960 {
9961- if (n && __access_ok((unsigned long) to, n))
9962+ if ((long)n < 0)
9963+ return n;
9964+
9965+ if (n && __access_ok((unsigned long) to, n)) {
9966+ if (!__builtin_constant_p(n))
9967+ check_object_size(from, n, true);
9968 return __copy_user(to, (__force void __user *) from, n);
9969- else
9970+ } else
9971 return n;
9972 }
9973
9974 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9975 {
9976+ if ((long)n < 0)
9977+ return n;
9978+
9979+ if (!__builtin_constant_p(n))
9980+ check_object_size(from, n, true);
9981+
9982 return __copy_user(to, (__force void __user *) from, n);
9983 }
9984
9985 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9986 {
9987- if (n && __access_ok((unsigned long) from, n))
9988+ if ((long)n < 0)
9989+ return n;
9990+
9991+ if (n && __access_ok((unsigned long) from, n)) {
9992+ if (!__builtin_constant_p(n))
9993+ check_object_size(to, n, false);
9994 return __copy_user((__force void __user *) to, from, n);
9995- else
9996+ } else
9997 return n;
9998 }
9999
10000 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10001 {
10002+ if ((long)n < 0)
10003+ return n;
10004+
10005 return __copy_user((__force void __user *) to, from, n);
10006 }
10007
10008diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10009index ad7e178..c9e7423 100644
10010--- a/arch/sparc/include/asm/uaccess_64.h
10011+++ b/arch/sparc/include/asm/uaccess_64.h
10012@@ -10,6 +10,7 @@
10013 #include <linux/compiler.h>
10014 #include <linux/string.h>
10015 #include <linux/thread_info.h>
10016+#include <linux/kernel.h>
10017 #include <asm/asi.h>
10018 #include <asm/spitfire.h>
10019 #include <asm-generic/uaccess-unaligned.h>
10020@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10021 static inline unsigned long __must_check
10022 copy_from_user(void *to, const void __user *from, unsigned long size)
10023 {
10024- unsigned long ret = ___copy_from_user(to, from, size);
10025+ unsigned long ret;
10026
10027+ if ((long)size < 0 || size > INT_MAX)
10028+ return size;
10029+
10030+ if (!__builtin_constant_p(size))
10031+ check_object_size(to, size, false);
10032+
10033+ ret = ___copy_from_user(to, from, size);
10034 if (unlikely(ret))
10035 ret = copy_from_user_fixup(to, from, size);
10036
10037@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10038 static inline unsigned long __must_check
10039 copy_to_user(void __user *to, const void *from, unsigned long size)
10040 {
10041- unsigned long ret = ___copy_to_user(to, from, size);
10042+ unsigned long ret;
10043
10044+ if ((long)size < 0 || size > INT_MAX)
10045+ return size;
10046+
10047+ if (!__builtin_constant_p(size))
10048+ check_object_size(from, size, true);
10049+
10050+ ret = ___copy_to_user(to, from, size);
10051 if (unlikely(ret))
10052 ret = copy_to_user_fixup(to, from, size);
10053 return ret;
10054diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10055index d15cc17..d0ae796 100644
10056--- a/arch/sparc/kernel/Makefile
10057+++ b/arch/sparc/kernel/Makefile
10058@@ -4,7 +4,7 @@
10059 #
10060
10061 asflags-y := -ansi
10062-ccflags-y := -Werror
10063+#ccflags-y := -Werror
10064
10065 extra-y := head_$(BITS).o
10066
10067diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10068index fdd819d..5af08c8 100644
10069--- a/arch/sparc/kernel/process_32.c
10070+++ b/arch/sparc/kernel/process_32.c
10071@@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
10072
10073 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10074 r->psr, r->pc, r->npc, r->y, print_tainted());
10075- printk("PC: <%pS>\n", (void *) r->pc);
10076+ printk("PC: <%pA>\n", (void *) r->pc);
10077 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10078 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10079 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10080 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10081 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10082 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10083- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10084+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10085
10086 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10087 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10088@@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10089 rw = (struct reg_window32 *) fp;
10090 pc = rw->ins[7];
10091 printk("[%08lx : ", pc);
10092- printk("%pS ] ", (void *) pc);
10093+ printk("%pA ] ", (void *) pc);
10094 fp = rw->ins[6];
10095 } while (++count < 16);
10096 printk("\n");
10097diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10098index 32a280e..84fc6a9 100644
10099--- a/arch/sparc/kernel/process_64.c
10100+++ b/arch/sparc/kernel/process_64.c
10101@@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
10102 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10103 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10104 if (regs->tstate & TSTATE_PRIV)
10105- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10106+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10107 }
10108
10109 void show_regs(struct pt_regs *regs)
10110@@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
10111
10112 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10113 regs->tpc, regs->tnpc, regs->y, print_tainted());
10114- printk("TPC: <%pS>\n", (void *) regs->tpc);
10115+ printk("TPC: <%pA>\n", (void *) regs->tpc);
10116 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10117 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10118 regs->u_regs[3]);
10119@@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
10120 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10121 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10122 regs->u_regs[15]);
10123- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10124+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10125 show_regwindow(regs);
10126 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10127 }
10128@@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
10129 ((tp && tp->task) ? tp->task->pid : -1));
10130
10131 if (gp->tstate & TSTATE_PRIV) {
10132- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10133+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10134 (void *) gp->tpc,
10135 (void *) gp->o7,
10136 (void *) gp->i7,
10137diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10138index 79cc0d1..ec62734 100644
10139--- a/arch/sparc/kernel/prom_common.c
10140+++ b/arch/sparc/kernel/prom_common.c
10141@@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10142
10143 unsigned int prom_early_allocated __initdata;
10144
10145-static struct of_pdt_ops prom_sparc_ops __initdata = {
10146+static struct of_pdt_ops prom_sparc_ops __initconst = {
10147 .nextprop = prom_common_nextprop,
10148 .getproplen = prom_getproplen,
10149 .getproperty = prom_getproperty,
10150diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10151index c13c9f2..d572c34 100644
10152--- a/arch/sparc/kernel/ptrace_64.c
10153+++ b/arch/sparc/kernel/ptrace_64.c
10154@@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10155 return ret;
10156 }
10157
10158+#ifdef CONFIG_GRKERNSEC_SETXID
10159+extern void gr_delayed_cred_worker(void);
10160+#endif
10161+
10162 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10163 {
10164 int ret = 0;
10165@@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10166 if (test_thread_flag(TIF_NOHZ))
10167 user_exit();
10168
10169+#ifdef CONFIG_GRKERNSEC_SETXID
10170+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10171+ gr_delayed_cred_worker();
10172+#endif
10173+
10174 if (test_thread_flag(TIF_SYSCALL_TRACE))
10175 ret = tracehook_report_syscall_entry(regs);
10176
10177@@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10178 if (test_thread_flag(TIF_NOHZ))
10179 user_exit();
10180
10181+#ifdef CONFIG_GRKERNSEC_SETXID
10182+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10183+ gr_delayed_cred_worker();
10184+#endif
10185+
10186 audit_syscall_exit(regs);
10187
10188 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10189diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10190index b085311..6f885f7 100644
10191--- a/arch/sparc/kernel/smp_64.c
10192+++ b/arch/sparc/kernel/smp_64.c
10193@@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10194 extern unsigned long xcall_flush_dcache_page_spitfire;
10195
10196 #ifdef CONFIG_DEBUG_DCFLUSH
10197-extern atomic_t dcpage_flushes;
10198-extern atomic_t dcpage_flushes_xcall;
10199+extern atomic_unchecked_t dcpage_flushes;
10200+extern atomic_unchecked_t dcpage_flushes_xcall;
10201 #endif
10202
10203 static inline void __local_flush_dcache_page(struct page *page)
10204@@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10205 return;
10206
10207 #ifdef CONFIG_DEBUG_DCFLUSH
10208- atomic_inc(&dcpage_flushes);
10209+ atomic_inc_unchecked(&dcpage_flushes);
10210 #endif
10211
10212 this_cpu = get_cpu();
10213@@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10214 xcall_deliver(data0, __pa(pg_addr),
10215 (u64) pg_addr, cpumask_of(cpu));
10216 #ifdef CONFIG_DEBUG_DCFLUSH
10217- atomic_inc(&dcpage_flushes_xcall);
10218+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10219 #endif
10220 }
10221 }
10222@@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10223 preempt_disable();
10224
10225 #ifdef CONFIG_DEBUG_DCFLUSH
10226- atomic_inc(&dcpage_flushes);
10227+ atomic_inc_unchecked(&dcpage_flushes);
10228 #endif
10229 data0 = 0;
10230 pg_addr = page_address(page);
10231@@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10232 xcall_deliver(data0, __pa(pg_addr),
10233 (u64) pg_addr, cpu_online_mask);
10234 #ifdef CONFIG_DEBUG_DCFLUSH
10235- atomic_inc(&dcpage_flushes_xcall);
10236+ atomic_inc_unchecked(&dcpage_flushes_xcall);
10237 #endif
10238 }
10239 __local_flush_dcache_page(page);
10240diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10241index 3a8d184..49498a8 100644
10242--- a/arch/sparc/kernel/sys_sparc_32.c
10243+++ b/arch/sparc/kernel/sys_sparc_32.c
10244@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10245 if (len > TASK_SIZE - PAGE_SIZE)
10246 return -ENOMEM;
10247 if (!addr)
10248- addr = TASK_UNMAPPED_BASE;
10249+ addr = current->mm->mmap_base;
10250
10251 info.flags = 0;
10252 info.length = len;
10253diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10254index beb0b5a..5a153f7 100644
10255--- a/arch/sparc/kernel/sys_sparc_64.c
10256+++ b/arch/sparc/kernel/sys_sparc_64.c
10257@@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10258 struct vm_area_struct * vma;
10259 unsigned long task_size = TASK_SIZE;
10260 int do_color_align;
10261+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10262 struct vm_unmapped_area_info info;
10263
10264 if (flags & MAP_FIXED) {
10265 /* We do not accept a shared mapping if it would violate
10266 * cache aliasing constraints.
10267 */
10268- if ((flags & MAP_SHARED) &&
10269+ if ((filp || (flags & MAP_SHARED)) &&
10270 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10271 return -EINVAL;
10272 return addr;
10273@@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10274 if (filp || (flags & MAP_SHARED))
10275 do_color_align = 1;
10276
10277+#ifdef CONFIG_PAX_RANDMMAP
10278+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10279+#endif
10280+
10281 if (addr) {
10282 if (do_color_align)
10283 addr = COLOR_ALIGN(addr, pgoff);
10284@@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10285 addr = PAGE_ALIGN(addr);
10286
10287 vma = find_vma(mm, addr);
10288- if (task_size - len >= addr &&
10289- (!vma || addr + len <= vma->vm_start))
10290+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10291 return addr;
10292 }
10293
10294 info.flags = 0;
10295 info.length = len;
10296- info.low_limit = TASK_UNMAPPED_BASE;
10297+ info.low_limit = mm->mmap_base;
10298 info.high_limit = min(task_size, VA_EXCLUDE_START);
10299 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10300 info.align_offset = pgoff << PAGE_SHIFT;
10301+ info.threadstack_offset = offset;
10302 addr = vm_unmapped_area(&info);
10303
10304 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10305 VM_BUG_ON(addr != -ENOMEM);
10306 info.low_limit = VA_EXCLUDE_END;
10307+
10308+#ifdef CONFIG_PAX_RANDMMAP
10309+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10310+ info.low_limit += mm->delta_mmap;
10311+#endif
10312+
10313 info.high_limit = task_size;
10314 addr = vm_unmapped_area(&info);
10315 }
10316@@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10317 unsigned long task_size = STACK_TOP32;
10318 unsigned long addr = addr0;
10319 int do_color_align;
10320+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10321 struct vm_unmapped_area_info info;
10322
10323 /* This should only ever run for 32-bit processes. */
10324@@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10325 /* We do not accept a shared mapping if it would violate
10326 * cache aliasing constraints.
10327 */
10328- if ((flags & MAP_SHARED) &&
10329+ if ((filp || (flags & MAP_SHARED)) &&
10330 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10331 return -EINVAL;
10332 return addr;
10333@@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10334 if (filp || (flags & MAP_SHARED))
10335 do_color_align = 1;
10336
10337+#ifdef CONFIG_PAX_RANDMMAP
10338+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10339+#endif
10340+
10341 /* requesting a specific address */
10342 if (addr) {
10343 if (do_color_align)
10344@@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10345 addr = PAGE_ALIGN(addr);
10346
10347 vma = find_vma(mm, addr);
10348- if (task_size - len >= addr &&
10349- (!vma || addr + len <= vma->vm_start))
10350+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10351 return addr;
10352 }
10353
10354@@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10355 info.high_limit = mm->mmap_base;
10356 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10357 info.align_offset = pgoff << PAGE_SHIFT;
10358+ info.threadstack_offset = offset;
10359 addr = vm_unmapped_area(&info);
10360
10361 /*
10362@@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10363 VM_BUG_ON(addr != -ENOMEM);
10364 info.flags = 0;
10365 info.low_limit = TASK_UNMAPPED_BASE;
10366+
10367+#ifdef CONFIG_PAX_RANDMMAP
10368+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10369+ info.low_limit += mm->delta_mmap;
10370+#endif
10371+
10372 info.high_limit = STACK_TOP32;
10373 addr = vm_unmapped_area(&info);
10374 }
10375@@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10376 EXPORT_SYMBOL(get_fb_unmapped_area);
10377
10378 /* Essentially the same as PowerPC. */
10379-static unsigned long mmap_rnd(void)
10380+static unsigned long mmap_rnd(struct mm_struct *mm)
10381 {
10382 unsigned long rnd = 0UL;
10383
10384+#ifdef CONFIG_PAX_RANDMMAP
10385+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10386+#endif
10387+
10388 if (current->flags & PF_RANDOMIZE) {
10389 unsigned long val = get_random_int();
10390 if (test_thread_flag(TIF_32BIT))
10391@@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10392
10393 void arch_pick_mmap_layout(struct mm_struct *mm)
10394 {
10395- unsigned long random_factor = mmap_rnd();
10396+ unsigned long random_factor = mmap_rnd(mm);
10397 unsigned long gap;
10398
10399 /*
10400@@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10401 gap == RLIM_INFINITY ||
10402 sysctl_legacy_va_layout) {
10403 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10404+
10405+#ifdef CONFIG_PAX_RANDMMAP
10406+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10407+ mm->mmap_base += mm->delta_mmap;
10408+#endif
10409+
10410 mm->get_unmapped_area = arch_get_unmapped_area;
10411 } else {
10412 /* We know it's 32-bit */
10413@@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10414 gap = (task_size / 6 * 5);
10415
10416 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10417+
10418+#ifdef CONFIG_PAX_RANDMMAP
10419+ if (mm->pax_flags & MF_PAX_RANDMMAP)
10420+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10421+#endif
10422+
10423 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10424 }
10425 }
10426diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10427index 87729ff..d87fb1f 100644
10428--- a/arch/sparc/kernel/syscalls.S
10429+++ b/arch/sparc/kernel/syscalls.S
10430@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10431 #endif
10432 .align 32
10433 1: ldx [%g6 + TI_FLAGS], %l5
10434- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10435+ andcc %l5, _TIF_WORK_SYSCALL, %g0
10436 be,pt %icc, rtrap
10437 nop
10438 call syscall_trace_leave
10439@@ -184,12 +184,13 @@ linux_sparc_syscall32:
10440
10441 srl %i3, 0, %o3 ! IEU0
10442 srl %i2, 0, %o2 ! IEU0 Group
10443- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10444+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10445 bne,pn %icc, linux_syscall_trace32 ! CTI
10446 mov %i0, %l5 ! IEU1
10447 5: call %l7 ! CTI Group brk forced
10448 srl %i5, 0, %o5 ! IEU1
10449- ba,a,pt %xcc, 3f
10450+ ba,pt %xcc, 3f
10451+ sra %o0, 0, %o0
10452
10453 /* Linux native system calls enter here... */
10454 .align 32
10455@@ -207,7 +208,7 @@ linux_sparc_syscall:
10456
10457 mov %i3, %o3 ! IEU1
10458 mov %i4, %o4 ! IEU0 Group
10459- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10460+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10461 bne,pn %icc, linux_syscall_trace ! CTI Group
10462 mov %i0, %l5 ! IEU0
10463 2: call %l7 ! CTI Group brk forced
10464@@ -217,13 +218,12 @@ linux_sparc_syscall:
10465 3: stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
10466 ret_sys_call:
10467 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %g3
10468- sra %o0, 0, %o0
10469 mov %ulo(TSTATE_XCARRY | TSTATE_ICARRY), %g2
10470 sllx %g2, 32, %g2
10471
10472 cmp %o0, -ERESTART_RESTARTBLOCK
10473 bgeu,pn %xcc, 1f
10474- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10475+ andcc %l0, _TIF_WORK_SYSCALL, %g0
10476 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10477
10478 2:
10479diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10480index 6629829..036032d 100644
10481--- a/arch/sparc/kernel/traps_32.c
10482+++ b/arch/sparc/kernel/traps_32.c
10483@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10484 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10485 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10486
10487+extern void gr_handle_kernel_exploit(void);
10488+
10489 void die_if_kernel(char *str, struct pt_regs *regs)
10490 {
10491 static int die_counter;
10492@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10493 count++ < 30 &&
10494 (((unsigned long) rw) >= PAGE_OFFSET) &&
10495 !(((unsigned long) rw) & 0x7)) {
10496- printk("Caller[%08lx]: %pS\n", rw->ins[7],
10497+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
10498 (void *) rw->ins[7]);
10499 rw = (struct reg_window32 *)rw->ins[6];
10500 }
10501 }
10502 printk("Instruction DUMP:");
10503 instruction_dump ((unsigned long *) regs->pc);
10504- if(regs->psr & PSR_PS)
10505+ if(regs->psr & PSR_PS) {
10506+ gr_handle_kernel_exploit();
10507 do_exit(SIGKILL);
10508+ }
10509 do_exit(SIGSEGV);
10510 }
10511
10512diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10513index 4ced92f..965eeed 100644
10514--- a/arch/sparc/kernel/traps_64.c
10515+++ b/arch/sparc/kernel/traps_64.c
10516@@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10517 i + 1,
10518 p->trapstack[i].tstate, p->trapstack[i].tpc,
10519 p->trapstack[i].tnpc, p->trapstack[i].tt);
10520- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10521+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10522 }
10523 }
10524
10525@@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10526
10527 lvl -= 0x100;
10528 if (regs->tstate & TSTATE_PRIV) {
10529+
10530+#ifdef CONFIG_PAX_REFCOUNT
10531+ if (lvl == 6)
10532+ pax_report_refcount_overflow(regs);
10533+#endif
10534+
10535 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10536 die_if_kernel(buffer, regs);
10537 }
10538@@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10539 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10540 {
10541 char buffer[32];
10542-
10543+
10544 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10545 0, lvl, SIGTRAP) == NOTIFY_STOP)
10546 return;
10547
10548+#ifdef CONFIG_PAX_REFCOUNT
10549+ if (lvl == 6)
10550+ pax_report_refcount_overflow(regs);
10551+#endif
10552+
10553 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10554
10555 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10556@@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10557 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10558 printk("%s" "ERROR(%d): ",
10559 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10560- printk("TPC<%pS>\n", (void *) regs->tpc);
10561+ printk("TPC<%pA>\n", (void *) regs->tpc);
10562 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10563 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10564 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10565@@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10566 smp_processor_id(),
10567 (type & 0x1) ? 'I' : 'D',
10568 regs->tpc);
10569- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10570+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10571 panic("Irrecoverable Cheetah+ parity error.");
10572 }
10573
10574@@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10575 smp_processor_id(),
10576 (type & 0x1) ? 'I' : 'D',
10577 regs->tpc);
10578- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10579+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10580 }
10581
10582 struct sun4v_error_entry {
10583@@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10584 /*0x38*/u64 reserved_5;
10585 };
10586
10587-static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10588-static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10589+static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10590+static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10591
10592 static const char *sun4v_err_type_to_str(u8 type)
10593 {
10594@@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10595 }
10596
10597 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10598- int cpu, const char *pfx, atomic_t *ocnt)
10599+ int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10600 {
10601 u64 *raw_ptr = (u64 *) ent;
10602 u32 attrs;
10603@@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10604
10605 show_regs(regs);
10606
10607- if ((cnt = atomic_read(ocnt)) != 0) {
10608- atomic_set(ocnt, 0);
10609+ if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10610+ atomic_set_unchecked(ocnt, 0);
10611 wmb();
10612 printk("%s: Queue overflowed %d times.\n",
10613 pfx, cnt);
10614@@ -2046,7 +2057,7 @@ out:
10615 */
10616 void sun4v_resum_overflow(struct pt_regs *regs)
10617 {
10618- atomic_inc(&sun4v_resum_oflow_cnt);
10619+ atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10620 }
10621
10622 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10623@@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10624 /* XXX Actually even this can make not that much sense. Perhaps
10625 * XXX we should just pull the plug and panic directly from here?
10626 */
10627- atomic_inc(&sun4v_nonresum_oflow_cnt);
10628+ atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10629 }
10630
10631 unsigned long sun4v_err_itlb_vaddr;
10632@@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10633
10634 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10635 regs->tpc, tl);
10636- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10637+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10638 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10639- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10640+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10641 (void *) regs->u_regs[UREG_I7]);
10642 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10643 "pte[%lx] error[%lx]\n",
10644@@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10645
10646 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10647 regs->tpc, tl);
10648- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10649+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10650 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10651- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10652+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10653 (void *) regs->u_regs[UREG_I7]);
10654 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10655 "pte[%lx] error[%lx]\n",
10656@@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10657 fp = (unsigned long)sf->fp + STACK_BIAS;
10658 }
10659
10660- printk(" [%016lx] %pS\n", pc, (void *) pc);
10661+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10663 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10664 int index = tsk->curr_ret_stack;
10665 if (tsk->ret_stack && index >= graph) {
10666 pc = tsk->ret_stack[index - graph].ret;
10667- printk(" [%016lx] %pS\n", pc, (void *) pc);
10668+ printk(" [%016lx] %pA\n", pc, (void *) pc);
10669 graph++;
10670 }
10671 }
10672@@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10673 return (struct reg_window *) (fp + STACK_BIAS);
10674 }
10675
10676+extern void gr_handle_kernel_exploit(void);
10677+
10678 void die_if_kernel(char *str, struct pt_regs *regs)
10679 {
10680 static int die_counter;
10681@@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10682 while (rw &&
10683 count++ < 30 &&
10684 kstack_valid(tp, (unsigned long) rw)) {
10685- printk("Caller[%016lx]: %pS\n", rw->ins[7],
10686+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
10687 (void *) rw->ins[7]);
10688
10689 rw = kernel_stack_up(rw);
10690@@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10691 }
10692 user_instruction_dump ((unsigned int __user *) regs->tpc);
10693 }
10694- if (regs->tstate & TSTATE_PRIV)
10695+ if (regs->tstate & TSTATE_PRIV) {
10696+ gr_handle_kernel_exploit();
10697 do_exit(SIGKILL);
10698+ }
10699 do_exit(SIGSEGV);
10700 }
10701 EXPORT_SYMBOL(die_if_kernel);
10702diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10703index 3c1a7cb..73e1923 100644
10704--- a/arch/sparc/kernel/unaligned_64.c
10705+++ b/arch/sparc/kernel/unaligned_64.c
10706@@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10707 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10708
10709 if (__ratelimit(&ratelimit)) {
10710- printk("Kernel unaligned access at TPC[%lx] %pS\n",
10711+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
10712 regs->tpc, (void *) regs->tpc);
10713 }
10714 }
10715diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10716index dbe119b..089c7c1 100644
10717--- a/arch/sparc/lib/Makefile
10718+++ b/arch/sparc/lib/Makefile
10719@@ -2,7 +2,7 @@
10720 #
10721
10722 asflags-y := -ansi -DST_DIV0=0x02
10723-ccflags-y := -Werror
10724+#ccflags-y := -Werror
10725
10726 lib-$(CONFIG_SPARC32) += ashrdi3.o
10727 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10728diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10729index 85c233d..68500e0 100644
10730--- a/arch/sparc/lib/atomic_64.S
10731+++ b/arch/sparc/lib/atomic_64.S
10732@@ -17,7 +17,12 @@
10733 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10734 BACKOFF_SETUP(%o2)
10735 1: lduw [%o1], %g1
10736- add %g1, %o0, %g7
10737+ addcc %g1, %o0, %g7
10738+
10739+#ifdef CONFIG_PAX_REFCOUNT
10740+ tvs %icc, 6
10741+#endif
10742+
10743 cas [%o1], %g1, %g7
10744 cmp %g1, %g7
10745 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10746@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10747 2: BACKOFF_SPIN(%o2, %o3, 1b)
10748 ENDPROC(atomic_add)
10749
10750+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10751+ BACKOFF_SETUP(%o2)
10752+1: lduw [%o1], %g1
10753+ add %g1, %o0, %g7
10754+ cas [%o1], %g1, %g7
10755+ cmp %g1, %g7
10756+ bne,pn %icc, 2f
10757+ nop
10758+ retl
10759+ nop
10760+2: BACKOFF_SPIN(%o2, %o3, 1b)
10761+ENDPROC(atomic_add_unchecked)
10762+
10763 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10764 BACKOFF_SETUP(%o2)
10765 1: lduw [%o1], %g1
10766- sub %g1, %o0, %g7
10767+ subcc %g1, %o0, %g7
10768+
10769+#ifdef CONFIG_PAX_REFCOUNT
10770+ tvs %icc, 6
10771+#endif
10772+
10773 cas [%o1], %g1, %g7
10774 cmp %g1, %g7
10775 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10776@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10777 2: BACKOFF_SPIN(%o2, %o3, 1b)
10778 ENDPROC(atomic_sub)
10779
10780+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10781+ BACKOFF_SETUP(%o2)
10782+1: lduw [%o1], %g1
10783+ sub %g1, %o0, %g7
10784+ cas [%o1], %g1, %g7
10785+ cmp %g1, %g7
10786+ bne,pn %icc, 2f
10787+ nop
10788+ retl
10789+ nop
10790+2: BACKOFF_SPIN(%o2, %o3, 1b)
10791+ENDPROC(atomic_sub_unchecked)
10792+
10793 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10794 BACKOFF_SETUP(%o2)
10795 1: lduw [%o1], %g1
10796- add %g1, %o0, %g7
10797+ addcc %g1, %o0, %g7
10798+
10799+#ifdef CONFIG_PAX_REFCOUNT
10800+ tvs %icc, 6
10801+#endif
10802+
10803 cas [%o1], %g1, %g7
10804 cmp %g1, %g7
10805 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10806@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10807 2: BACKOFF_SPIN(%o2, %o3, 1b)
10808 ENDPROC(atomic_add_ret)
10809
10810+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10811+ BACKOFF_SETUP(%o2)
10812+1: lduw [%o1], %g1
10813+ addcc %g1, %o0, %g7
10814+ cas [%o1], %g1, %g7
10815+ cmp %g1, %g7
10816+ bne,pn %icc, 2f
10817+ add %g7, %o0, %g7
10818+ sra %g7, 0, %o0
10819+ retl
10820+ nop
10821+2: BACKOFF_SPIN(%o2, %o3, 1b)
10822+ENDPROC(atomic_add_ret_unchecked)
10823+
10824 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10825 BACKOFF_SETUP(%o2)
10826 1: lduw [%o1], %g1
10827- sub %g1, %o0, %g7
10828+ subcc %g1, %o0, %g7
10829+
10830+#ifdef CONFIG_PAX_REFCOUNT
10831+ tvs %icc, 6
10832+#endif
10833+
10834 cas [%o1], %g1, %g7
10835 cmp %g1, %g7
10836 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10837@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10838 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10839 BACKOFF_SETUP(%o2)
10840 1: ldx [%o1], %g1
10841- add %g1, %o0, %g7
10842+ addcc %g1, %o0, %g7
10843+
10844+#ifdef CONFIG_PAX_REFCOUNT
10845+ tvs %xcc, 6
10846+#endif
10847+
10848 casx [%o1], %g1, %g7
10849 cmp %g1, %g7
10850 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10851@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10852 2: BACKOFF_SPIN(%o2, %o3, 1b)
10853 ENDPROC(atomic64_add)
10854
10855+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10856+ BACKOFF_SETUP(%o2)
10857+1: ldx [%o1], %g1
10858+ addcc %g1, %o0, %g7
10859+ casx [%o1], %g1, %g7
10860+ cmp %g1, %g7
10861+ bne,pn %xcc, 2f
10862+ nop
10863+ retl
10864+ nop
10865+2: BACKOFF_SPIN(%o2, %o3, 1b)
10866+ENDPROC(atomic64_add_unchecked)
10867+
10868 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10869 BACKOFF_SETUP(%o2)
10870 1: ldx [%o1], %g1
10871- sub %g1, %o0, %g7
10872+ subcc %g1, %o0, %g7
10873+
10874+#ifdef CONFIG_PAX_REFCOUNT
10875+ tvs %xcc, 6
10876+#endif
10877+
10878 casx [%o1], %g1, %g7
10879 cmp %g1, %g7
10880 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10881@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10882 2: BACKOFF_SPIN(%o2, %o3, 1b)
10883 ENDPROC(atomic64_sub)
10884
10885+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10886+ BACKOFF_SETUP(%o2)
10887+1: ldx [%o1], %g1
10888+ subcc %g1, %o0, %g7
10889+ casx [%o1], %g1, %g7
10890+ cmp %g1, %g7
10891+ bne,pn %xcc, 2f
10892+ nop
10893+ retl
10894+ nop
10895+2: BACKOFF_SPIN(%o2, %o3, 1b)
10896+ENDPROC(atomic64_sub_unchecked)
10897+
10898 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10899 BACKOFF_SETUP(%o2)
10900 1: ldx [%o1], %g1
10901- add %g1, %o0, %g7
10902+ addcc %g1, %o0, %g7
10903+
10904+#ifdef CONFIG_PAX_REFCOUNT
10905+ tvs %xcc, 6
10906+#endif
10907+
10908 casx [%o1], %g1, %g7
10909 cmp %g1, %g7
10910 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10911@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10912 2: BACKOFF_SPIN(%o2, %o3, 1b)
10913 ENDPROC(atomic64_add_ret)
10914
10915+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10916+ BACKOFF_SETUP(%o2)
10917+1: ldx [%o1], %g1
10918+ addcc %g1, %o0, %g7
10919+ casx [%o1], %g1, %g7
10920+ cmp %g1, %g7
10921+ bne,pn %xcc, 2f
10922+ add %g7, %o0, %g7
10923+ mov %g7, %o0
10924+ retl
10925+ nop
10926+2: BACKOFF_SPIN(%o2, %o3, 1b)
10927+ENDPROC(atomic64_add_ret_unchecked)
10928+
10929 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10930 BACKOFF_SETUP(%o2)
10931 1: ldx [%o1], %g1
10932- sub %g1, %o0, %g7
10933+ subcc %g1, %o0, %g7
10934+
10935+#ifdef CONFIG_PAX_REFCOUNT
10936+ tvs %xcc, 6
10937+#endif
10938+
10939 casx [%o1], %g1, %g7
10940 cmp %g1, %g7
10941 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10942diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10943index 323335b..ed85ea2 100644
10944--- a/arch/sparc/lib/ksyms.c
10945+++ b/arch/sparc/lib/ksyms.c
10946@@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10947
10948 /* Atomic counter implementation. */
10949 EXPORT_SYMBOL(atomic_add);
10950+EXPORT_SYMBOL(atomic_add_unchecked);
10951 EXPORT_SYMBOL(atomic_add_ret);
10952+EXPORT_SYMBOL(atomic_add_ret_unchecked);
10953 EXPORT_SYMBOL(atomic_sub);
10954+EXPORT_SYMBOL(atomic_sub_unchecked);
10955 EXPORT_SYMBOL(atomic_sub_ret);
10956 EXPORT_SYMBOL(atomic64_add);
10957+EXPORT_SYMBOL(atomic64_add_unchecked);
10958 EXPORT_SYMBOL(atomic64_add_ret);
10959+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10960 EXPORT_SYMBOL(atomic64_sub);
10961+EXPORT_SYMBOL(atomic64_sub_unchecked);
10962 EXPORT_SYMBOL(atomic64_sub_ret);
10963 EXPORT_SYMBOL(atomic64_dec_if_positive);
10964
10965diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10966index 30c3ecc..736f015 100644
10967--- a/arch/sparc/mm/Makefile
10968+++ b/arch/sparc/mm/Makefile
10969@@ -2,7 +2,7 @@
10970 #
10971
10972 asflags-y := -ansi
10973-ccflags-y := -Werror
10974+#ccflags-y := -Werror
10975
10976 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10977 obj-y += fault_$(BITS).o
10978diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10979index 59dbd46..1dd7f5e 100644
10980--- a/arch/sparc/mm/fault_32.c
10981+++ b/arch/sparc/mm/fault_32.c
10982@@ -21,6 +21,9 @@
10983 #include <linux/perf_event.h>
10984 #include <linux/interrupt.h>
10985 #include <linux/kdebug.h>
10986+#include <linux/slab.h>
10987+#include <linux/pagemap.h>
10988+#include <linux/compiler.h>
10989
10990 #include <asm/page.h>
10991 #include <asm/pgtable.h>
10992@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10993 return safe_compute_effective_address(regs, insn);
10994 }
10995
10996+#ifdef CONFIG_PAX_PAGEEXEC
10997+#ifdef CONFIG_PAX_DLRESOLVE
10998+static void pax_emuplt_close(struct vm_area_struct *vma)
10999+{
11000+ vma->vm_mm->call_dl_resolve = 0UL;
11001+}
11002+
11003+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11004+{
11005+ unsigned int *kaddr;
11006+
11007+ vmf->page = alloc_page(GFP_HIGHUSER);
11008+ if (!vmf->page)
11009+ return VM_FAULT_OOM;
11010+
11011+ kaddr = kmap(vmf->page);
11012+ memset(kaddr, 0, PAGE_SIZE);
11013+ kaddr[0] = 0x9DE3BFA8U; /* save */
11014+ flush_dcache_page(vmf->page);
11015+ kunmap(vmf->page);
11016+ return VM_FAULT_MAJOR;
11017+}
11018+
11019+static const struct vm_operations_struct pax_vm_ops = {
11020+ .close = pax_emuplt_close,
11021+ .fault = pax_emuplt_fault
11022+};
11023+
11024+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11025+{
11026+ int ret;
11027+
11028+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11029+ vma->vm_mm = current->mm;
11030+ vma->vm_start = addr;
11031+ vma->vm_end = addr + PAGE_SIZE;
11032+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11033+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11034+ vma->vm_ops = &pax_vm_ops;
11035+
11036+ ret = insert_vm_struct(current->mm, vma);
11037+ if (ret)
11038+ return ret;
11039+
11040+ ++current->mm->total_vm;
11041+ return 0;
11042+}
11043+#endif
11044+
11045+/*
11046+ * PaX: decide what to do with offenders (regs->pc = fault address)
11047+ *
11048+ * returns 1 when task should be killed
11049+ * 2 when patched PLT trampoline was detected
11050+ * 3 when unpatched PLT trampoline was detected
11051+ */
11052+static int pax_handle_fetch_fault(struct pt_regs *regs)
11053+{
11054+
11055+#ifdef CONFIG_PAX_EMUPLT
11056+ int err;
11057+
11058+ do { /* PaX: patched PLT emulation #1 */
11059+ unsigned int sethi1, sethi2, jmpl;
11060+
11061+ err = get_user(sethi1, (unsigned int *)regs->pc);
11062+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11063+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11064+
11065+ if (err)
11066+ break;
11067+
11068+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11069+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11070+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11071+ {
11072+ unsigned int addr;
11073+
11074+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11075+ addr = regs->u_regs[UREG_G1];
11076+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11077+ regs->pc = addr;
11078+ regs->npc = addr+4;
11079+ return 2;
11080+ }
11081+ } while (0);
11082+
11083+ do { /* PaX: patched PLT emulation #2 */
11084+ unsigned int ba;
11085+
11086+ err = get_user(ba, (unsigned int *)regs->pc);
11087+
11088+ if (err)
11089+ break;
11090+
11091+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11092+ unsigned int addr;
11093+
11094+ if ((ba & 0xFFC00000U) == 0x30800000U)
11095+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11096+ else
11097+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11098+ regs->pc = addr;
11099+ regs->npc = addr+4;
11100+ return 2;
11101+ }
11102+ } while (0);
11103+
11104+ do { /* PaX: patched PLT emulation #3 */
11105+ unsigned int sethi, bajmpl, nop;
11106+
11107+ err = get_user(sethi, (unsigned int *)regs->pc);
11108+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11109+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11110+
11111+ if (err)
11112+ break;
11113+
11114+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11115+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11116+ nop == 0x01000000U)
11117+ {
11118+ unsigned int addr;
11119+
11120+ addr = (sethi & 0x003FFFFFU) << 10;
11121+ regs->u_regs[UREG_G1] = addr;
11122+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11123+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11124+ else
11125+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11126+ regs->pc = addr;
11127+ regs->npc = addr+4;
11128+ return 2;
11129+ }
11130+ } while (0);
11131+
11132+ do { /* PaX: unpatched PLT emulation step 1 */
11133+ unsigned int sethi, ba, nop;
11134+
11135+ err = get_user(sethi, (unsigned int *)regs->pc);
11136+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
11137+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
11138+
11139+ if (err)
11140+ break;
11141+
11142+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11143+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11144+ nop == 0x01000000U)
11145+ {
11146+ unsigned int addr, save, call;
11147+
11148+ if ((ba & 0xFFC00000U) == 0x30800000U)
11149+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11150+ else
11151+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11152+
11153+ err = get_user(save, (unsigned int *)addr);
11154+ err |= get_user(call, (unsigned int *)(addr+4));
11155+ err |= get_user(nop, (unsigned int *)(addr+8));
11156+ if (err)
11157+ break;
11158+
11159+#ifdef CONFIG_PAX_DLRESOLVE
11160+ if (save == 0x9DE3BFA8U &&
11161+ (call & 0xC0000000U) == 0x40000000U &&
11162+ nop == 0x01000000U)
11163+ {
11164+ struct vm_area_struct *vma;
11165+ unsigned long call_dl_resolve;
11166+
11167+ down_read(&current->mm->mmap_sem);
11168+ call_dl_resolve = current->mm->call_dl_resolve;
11169+ up_read(&current->mm->mmap_sem);
11170+ if (likely(call_dl_resolve))
11171+ goto emulate;
11172+
11173+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11174+
11175+ down_write(&current->mm->mmap_sem);
11176+ if (current->mm->call_dl_resolve) {
11177+ call_dl_resolve = current->mm->call_dl_resolve;
11178+ up_write(&current->mm->mmap_sem);
11179+ if (vma)
11180+ kmem_cache_free(vm_area_cachep, vma);
11181+ goto emulate;
11182+ }
11183+
11184+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11185+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11186+ up_write(&current->mm->mmap_sem);
11187+ if (vma)
11188+ kmem_cache_free(vm_area_cachep, vma);
11189+ return 1;
11190+ }
11191+
11192+ if (pax_insert_vma(vma, call_dl_resolve)) {
11193+ up_write(&current->mm->mmap_sem);
11194+ kmem_cache_free(vm_area_cachep, vma);
11195+ return 1;
11196+ }
11197+
11198+ current->mm->call_dl_resolve = call_dl_resolve;
11199+ up_write(&current->mm->mmap_sem);
11200+
11201+emulate:
11202+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11203+ regs->pc = call_dl_resolve;
11204+ regs->npc = addr+4;
11205+ return 3;
11206+ }
11207+#endif
11208+
11209+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11210+ if ((save & 0xFFC00000U) == 0x05000000U &&
11211+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11212+ nop == 0x01000000U)
11213+ {
11214+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11215+ regs->u_regs[UREG_G2] = addr + 4;
11216+ addr = (save & 0x003FFFFFU) << 10;
11217+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11218+ regs->pc = addr;
11219+ regs->npc = addr+4;
11220+ return 3;
11221+ }
11222+ }
11223+ } while (0);
11224+
11225+ do { /* PaX: unpatched PLT emulation step 2 */
11226+ unsigned int save, call, nop;
11227+
11228+ err = get_user(save, (unsigned int *)(regs->pc-4));
11229+ err |= get_user(call, (unsigned int *)regs->pc);
11230+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
11231+ if (err)
11232+ break;
11233+
11234+ if (save == 0x9DE3BFA8U &&
11235+ (call & 0xC0000000U) == 0x40000000U &&
11236+ nop == 0x01000000U)
11237+ {
11238+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11239+
11240+ regs->u_regs[UREG_RETPC] = regs->pc;
11241+ regs->pc = dl_resolve;
11242+ regs->npc = dl_resolve+4;
11243+ return 3;
11244+ }
11245+ } while (0);
11246+#endif
11247+
11248+ return 1;
11249+}
11250+
11251+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11252+{
11253+ unsigned long i;
11254+
11255+ printk(KERN_ERR "PAX: bytes at PC: ");
11256+ for (i = 0; i < 8; i++) {
11257+ unsigned int c;
11258+ if (get_user(c, (unsigned int *)pc+i))
11259+ printk(KERN_CONT "???????? ");
11260+ else
11261+ printk(KERN_CONT "%08x ", c);
11262+ }
11263+ printk("\n");
11264+}
11265+#endif
11266+
11267 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11268 int text_fault)
11269 {
11270@@ -229,6 +503,24 @@ good_area:
11271 if (!(vma->vm_flags & VM_WRITE))
11272 goto bad_area;
11273 } else {
11274+
11275+#ifdef CONFIG_PAX_PAGEEXEC
11276+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11277+ up_read(&mm->mmap_sem);
11278+ switch (pax_handle_fetch_fault(regs)) {
11279+
11280+#ifdef CONFIG_PAX_EMUPLT
11281+ case 2:
11282+ case 3:
11283+ return;
11284+#endif
11285+
11286+ }
11287+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11288+ do_group_exit(SIGKILL);
11289+ }
11290+#endif
11291+
11292 /* Allow reads even for write-only mappings */
11293 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11294 goto bad_area;
11295diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11296index 69bb818..6ca35c8 100644
11297--- a/arch/sparc/mm/fault_64.c
11298+++ b/arch/sparc/mm/fault_64.c
11299@@ -22,6 +22,9 @@
11300 #include <linux/kdebug.h>
11301 #include <linux/percpu.h>
11302 #include <linux/context_tracking.h>
11303+#include <linux/slab.h>
11304+#include <linux/pagemap.h>
11305+#include <linux/compiler.h>
11306
11307 #include <asm/page.h>
11308 #include <asm/pgtable.h>
11309@@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11310 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11311 regs->tpc);
11312 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11313- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11314+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11315 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11316 dump_stack();
11317 unhandled_fault(regs->tpc, current, regs);
11318@@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
11319 show_regs(regs);
11320 }
11321
11322+#ifdef CONFIG_PAX_PAGEEXEC
11323+#ifdef CONFIG_PAX_DLRESOLVE
11324+static void pax_emuplt_close(struct vm_area_struct *vma)
11325+{
11326+ vma->vm_mm->call_dl_resolve = 0UL;
11327+}
11328+
11329+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11330+{
11331+ unsigned int *kaddr;
11332+
11333+ vmf->page = alloc_page(GFP_HIGHUSER);
11334+ if (!vmf->page)
11335+ return VM_FAULT_OOM;
11336+
11337+ kaddr = kmap(vmf->page);
11338+ memset(kaddr, 0, PAGE_SIZE);
11339+ kaddr[0] = 0x9DE3BFA8U; /* save */
11340+ flush_dcache_page(vmf->page);
11341+ kunmap(vmf->page);
11342+ return VM_FAULT_MAJOR;
11343+}
11344+
11345+static const struct vm_operations_struct pax_vm_ops = {
11346+ .close = pax_emuplt_close,
11347+ .fault = pax_emuplt_fault
11348+};
11349+
11350+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11351+{
11352+ int ret;
11353+
11354+ INIT_LIST_HEAD(&vma->anon_vma_chain);
11355+ vma->vm_mm = current->mm;
11356+ vma->vm_start = addr;
11357+ vma->vm_end = addr + PAGE_SIZE;
11358+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11359+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11360+ vma->vm_ops = &pax_vm_ops;
11361+
11362+ ret = insert_vm_struct(current->mm, vma);
11363+ if (ret)
11364+ return ret;
11365+
11366+ ++current->mm->total_vm;
11367+ return 0;
11368+}
11369+#endif
11370+
11371+/*
11372+ * PaX: decide what to do with offenders (regs->tpc = fault address)
11373+ *
11374+ * returns 1 when task should be killed
11375+ * 2 when patched PLT trampoline was detected
11376+ * 3 when unpatched PLT trampoline was detected
11377+ */
11378+static int pax_handle_fetch_fault(struct pt_regs *regs)
11379+{
11380+
11381+#ifdef CONFIG_PAX_EMUPLT
11382+ int err;
11383+
11384+ do { /* PaX: patched PLT emulation #1 */
11385+ unsigned int sethi1, sethi2, jmpl;
11386+
11387+ err = get_user(sethi1, (unsigned int *)regs->tpc);
11388+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11389+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11390+
11391+ if (err)
11392+ break;
11393+
11394+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11395+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
11396+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
11397+ {
11398+ unsigned long addr;
11399+
11400+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11401+ addr = regs->u_regs[UREG_G1];
11402+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11403+
11404+ if (test_thread_flag(TIF_32BIT))
11405+ addr &= 0xFFFFFFFFUL;
11406+
11407+ regs->tpc = addr;
11408+ regs->tnpc = addr+4;
11409+ return 2;
11410+ }
11411+ } while (0);
11412+
11413+ do { /* PaX: patched PLT emulation #2 */
11414+ unsigned int ba;
11415+
11416+ err = get_user(ba, (unsigned int *)regs->tpc);
11417+
11418+ if (err)
11419+ break;
11420+
11421+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11422+ unsigned long addr;
11423+
11424+ if ((ba & 0xFFC00000U) == 0x30800000U)
11425+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11426+ else
11427+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11428+
11429+ if (test_thread_flag(TIF_32BIT))
11430+ addr &= 0xFFFFFFFFUL;
11431+
11432+ regs->tpc = addr;
11433+ regs->tnpc = addr+4;
11434+ return 2;
11435+ }
11436+ } while (0);
11437+
11438+ do { /* PaX: patched PLT emulation #3 */
11439+ unsigned int sethi, bajmpl, nop;
11440+
11441+ err = get_user(sethi, (unsigned int *)regs->tpc);
11442+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11443+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11444+
11445+ if (err)
11446+ break;
11447+
11448+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11449+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11450+ nop == 0x01000000U)
11451+ {
11452+ unsigned long addr;
11453+
11454+ addr = (sethi & 0x003FFFFFU) << 10;
11455+ regs->u_regs[UREG_G1] = addr;
11456+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11457+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11458+ else
11459+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11460+
11461+ if (test_thread_flag(TIF_32BIT))
11462+ addr &= 0xFFFFFFFFUL;
11463+
11464+ regs->tpc = addr;
11465+ regs->tnpc = addr+4;
11466+ return 2;
11467+ }
11468+ } while (0);
11469+
11470+ do { /* PaX: patched PLT emulation #4 */
11471+ unsigned int sethi, mov1, call, mov2;
11472+
11473+ err = get_user(sethi, (unsigned int *)regs->tpc);
11474+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11475+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
11476+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11477+
11478+ if (err)
11479+ break;
11480+
11481+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11482+ mov1 == 0x8210000FU &&
11483+ (call & 0xC0000000U) == 0x40000000U &&
11484+ mov2 == 0x9E100001U)
11485+ {
11486+ unsigned long addr;
11487+
11488+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11489+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11490+
11491+ if (test_thread_flag(TIF_32BIT))
11492+ addr &= 0xFFFFFFFFUL;
11493+
11494+ regs->tpc = addr;
11495+ regs->tnpc = addr+4;
11496+ return 2;
11497+ }
11498+ } while (0);
11499+
11500+ do { /* PaX: patched PLT emulation #5 */
11501+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11502+
11503+ err = get_user(sethi, (unsigned int *)regs->tpc);
11504+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11505+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11506+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11507+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11508+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11509+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11510+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11511+
11512+ if (err)
11513+ break;
11514+
11515+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11516+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11517+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11518+ (or1 & 0xFFFFE000U) == 0x82106000U &&
11519+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11520+ sllx == 0x83287020U &&
11521+ jmpl == 0x81C04005U &&
11522+ nop == 0x01000000U)
11523+ {
11524+ unsigned long addr;
11525+
11526+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11527+ regs->u_regs[UREG_G1] <<= 32;
11528+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11529+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11530+ regs->tpc = addr;
11531+ regs->tnpc = addr+4;
11532+ return 2;
11533+ }
11534+ } while (0);
11535+
11536+ do { /* PaX: patched PLT emulation #6 */
11537+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11538+
11539+ err = get_user(sethi, (unsigned int *)regs->tpc);
11540+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11541+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11542+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11543+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
11544+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11545+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11546+
11547+ if (err)
11548+ break;
11549+
11550+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11551+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
11552+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11553+ sllx == 0x83287020U &&
11554+ (or & 0xFFFFE000U) == 0x8A116000U &&
11555+ jmpl == 0x81C04005U &&
11556+ nop == 0x01000000U)
11557+ {
11558+ unsigned long addr;
11559+
11560+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11561+ regs->u_regs[UREG_G1] <<= 32;
11562+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11563+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11564+ regs->tpc = addr;
11565+ regs->tnpc = addr+4;
11566+ return 2;
11567+ }
11568+ } while (0);
11569+
11570+ do { /* PaX: unpatched PLT emulation step 1 */
11571+ unsigned int sethi, ba, nop;
11572+
11573+ err = get_user(sethi, (unsigned int *)regs->tpc);
11574+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11575+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11576+
11577+ if (err)
11578+ break;
11579+
11580+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11581+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11582+ nop == 0x01000000U)
11583+ {
11584+ unsigned long addr;
11585+ unsigned int save, call;
11586+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11587+
11588+ if ((ba & 0xFFC00000U) == 0x30800000U)
11589+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11590+ else
11591+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11592+
11593+ if (test_thread_flag(TIF_32BIT))
11594+ addr &= 0xFFFFFFFFUL;
11595+
11596+ err = get_user(save, (unsigned int *)addr);
11597+ err |= get_user(call, (unsigned int *)(addr+4));
11598+ err |= get_user(nop, (unsigned int *)(addr+8));
11599+ if (err)
11600+ break;
11601+
11602+#ifdef CONFIG_PAX_DLRESOLVE
11603+ if (save == 0x9DE3BFA8U &&
11604+ (call & 0xC0000000U) == 0x40000000U &&
11605+ nop == 0x01000000U)
11606+ {
11607+ struct vm_area_struct *vma;
11608+ unsigned long call_dl_resolve;
11609+
11610+ down_read(&current->mm->mmap_sem);
11611+ call_dl_resolve = current->mm->call_dl_resolve;
11612+ up_read(&current->mm->mmap_sem);
11613+ if (likely(call_dl_resolve))
11614+ goto emulate;
11615+
11616+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11617+
11618+ down_write(&current->mm->mmap_sem);
11619+ if (current->mm->call_dl_resolve) {
11620+ call_dl_resolve = current->mm->call_dl_resolve;
11621+ up_write(&current->mm->mmap_sem);
11622+ if (vma)
11623+ kmem_cache_free(vm_area_cachep, vma);
11624+ goto emulate;
11625+ }
11626+
11627+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11628+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11629+ up_write(&current->mm->mmap_sem);
11630+ if (vma)
11631+ kmem_cache_free(vm_area_cachep, vma);
11632+ return 1;
11633+ }
11634+
11635+ if (pax_insert_vma(vma, call_dl_resolve)) {
11636+ up_write(&current->mm->mmap_sem);
11637+ kmem_cache_free(vm_area_cachep, vma);
11638+ return 1;
11639+ }
11640+
11641+ current->mm->call_dl_resolve = call_dl_resolve;
11642+ up_write(&current->mm->mmap_sem);
11643+
11644+emulate:
11645+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11646+ regs->tpc = call_dl_resolve;
11647+ regs->tnpc = addr+4;
11648+ return 3;
11649+ }
11650+#endif
11651+
11652+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11653+ if ((save & 0xFFC00000U) == 0x05000000U &&
11654+ (call & 0xFFFFE000U) == 0x85C0A000U &&
11655+ nop == 0x01000000U)
11656+ {
11657+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11658+ regs->u_regs[UREG_G2] = addr + 4;
11659+ addr = (save & 0x003FFFFFU) << 10;
11660+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11661+
11662+ if (test_thread_flag(TIF_32BIT))
11663+ addr &= 0xFFFFFFFFUL;
11664+
11665+ regs->tpc = addr;
11666+ regs->tnpc = addr+4;
11667+ return 3;
11668+ }
11669+
11670+ /* PaX: 64-bit PLT stub */
11671+ err = get_user(sethi1, (unsigned int *)addr);
11672+ err |= get_user(sethi2, (unsigned int *)(addr+4));
11673+ err |= get_user(or1, (unsigned int *)(addr+8));
11674+ err |= get_user(or2, (unsigned int *)(addr+12));
11675+ err |= get_user(sllx, (unsigned int *)(addr+16));
11676+ err |= get_user(add, (unsigned int *)(addr+20));
11677+ err |= get_user(jmpl, (unsigned int *)(addr+24));
11678+ err |= get_user(nop, (unsigned int *)(addr+28));
11679+ if (err)
11680+ break;
11681+
11682+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11683+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11684+ (or1 & 0xFFFFE000U) == 0x88112000U &&
11685+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
11686+ sllx == 0x89293020U &&
11687+ add == 0x8A010005U &&
11688+ jmpl == 0x89C14000U &&
11689+ nop == 0x01000000U)
11690+ {
11691+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11692+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11693+ regs->u_regs[UREG_G4] <<= 32;
11694+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11695+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11696+ regs->u_regs[UREG_G4] = addr + 24;
11697+ addr = regs->u_regs[UREG_G5];
11698+ regs->tpc = addr;
11699+ regs->tnpc = addr+4;
11700+ return 3;
11701+ }
11702+ }
11703+ } while (0);
11704+
11705+#ifdef CONFIG_PAX_DLRESOLVE
11706+ do { /* PaX: unpatched PLT emulation step 2 */
11707+ unsigned int save, call, nop;
11708+
11709+ err = get_user(save, (unsigned int *)(regs->tpc-4));
11710+ err |= get_user(call, (unsigned int *)regs->tpc);
11711+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11712+ if (err)
11713+ break;
11714+
11715+ if (save == 0x9DE3BFA8U &&
11716+ (call & 0xC0000000U) == 0x40000000U &&
11717+ nop == 0x01000000U)
11718+ {
11719+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11720+
11721+ if (test_thread_flag(TIF_32BIT))
11722+ dl_resolve &= 0xFFFFFFFFUL;
11723+
11724+ regs->u_regs[UREG_RETPC] = regs->tpc;
11725+ regs->tpc = dl_resolve;
11726+ regs->tnpc = dl_resolve+4;
11727+ return 3;
11728+ }
11729+ } while (0);
11730+#endif
11731+
11732+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11733+ unsigned int sethi, ba, nop;
11734+
11735+ err = get_user(sethi, (unsigned int *)regs->tpc);
11736+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11737+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11738+
11739+ if (err)
11740+ break;
11741+
11742+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
11743+ (ba & 0xFFF00000U) == 0x30600000U &&
11744+ nop == 0x01000000U)
11745+ {
11746+ unsigned long addr;
11747+
11748+ addr = (sethi & 0x003FFFFFU) << 10;
11749+ regs->u_regs[UREG_G1] = addr;
11750+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11751+
11752+ if (test_thread_flag(TIF_32BIT))
11753+ addr &= 0xFFFFFFFFUL;
11754+
11755+ regs->tpc = addr;
11756+ regs->tnpc = addr+4;
11757+ return 2;
11758+ }
11759+ } while (0);
11760+
11761+#endif
11762+
11763+ return 1;
11764+}
11765+
11766+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11767+{
11768+ unsigned long i;
11769+
11770+ printk(KERN_ERR "PAX: bytes at PC: ");
11771+ for (i = 0; i < 8; i++) {
11772+ unsigned int c;
11773+ if (get_user(c, (unsigned int *)pc+i))
11774+ printk(KERN_CONT "???????? ");
11775+ else
11776+ printk(KERN_CONT "%08x ", c);
11777+ }
11778+ printk("\n");
11779+}
11780+#endif
11781+
11782 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11783 {
11784 enum ctx_state prev_state = exception_enter();
11785@@ -344,6 +807,29 @@ retry:
11786 if (!vma)
11787 goto bad_area;
11788
11789+#ifdef CONFIG_PAX_PAGEEXEC
11790+ /* PaX: detect ITLB misses on non-exec pages */
11791+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11792+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11793+ {
11794+ if (address != regs->tpc)
11795+ goto good_area;
11796+
11797+ up_read(&mm->mmap_sem);
11798+ switch (pax_handle_fetch_fault(regs)) {
11799+
11800+#ifdef CONFIG_PAX_EMUPLT
11801+ case 2:
11802+ case 3:
11803+ return;
11804+#endif
11805+
11806+ }
11807+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11808+ do_group_exit(SIGKILL);
11809+ }
11810+#endif
11811+
11812 /* Pure DTLB misses do not tell us whether the fault causing
11813 * load/store/atomic was a write or not, it only says that there
11814 * was no match. So in such a case we (carefully) read the
11815diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11816index 3096317..a7b7654 100644
11817--- a/arch/sparc/mm/hugetlbpage.c
11818+++ b/arch/sparc/mm/hugetlbpage.c
11819@@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11820 unsigned long addr,
11821 unsigned long len,
11822 unsigned long pgoff,
11823- unsigned long flags)
11824+ unsigned long flags,
11825+ unsigned long offset)
11826 {
11827 unsigned long task_size = TASK_SIZE;
11828 struct vm_unmapped_area_info info;
11829@@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11830
11831 info.flags = 0;
11832 info.length = len;
11833- info.low_limit = TASK_UNMAPPED_BASE;
11834+ info.low_limit = mm->mmap_base;
11835 info.high_limit = min(task_size, VA_EXCLUDE_START);
11836 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11837 info.align_offset = 0;
11838+ info.threadstack_offset = offset;
11839 addr = vm_unmapped_area(&info);
11840
11841 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11842 VM_BUG_ON(addr != -ENOMEM);
11843 info.low_limit = VA_EXCLUDE_END;
11844+
11845+#ifdef CONFIG_PAX_RANDMMAP
11846+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11847+ info.low_limit += mm->delta_mmap;
11848+#endif
11849+
11850 info.high_limit = task_size;
11851 addr = vm_unmapped_area(&info);
11852 }
11853@@ -56,7 +64,8 @@ static unsigned long
11854 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11855 const unsigned long len,
11856 const unsigned long pgoff,
11857- const unsigned long flags)
11858+ const unsigned long flags,
11859+ const unsigned long offset)
11860 {
11861 struct mm_struct *mm = current->mm;
11862 unsigned long addr = addr0;
11863@@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11864 info.high_limit = mm->mmap_base;
11865 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11866 info.align_offset = 0;
11867+ info.threadstack_offset = offset;
11868 addr = vm_unmapped_area(&info);
11869
11870 /*
11871@@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11872 VM_BUG_ON(addr != -ENOMEM);
11873 info.flags = 0;
11874 info.low_limit = TASK_UNMAPPED_BASE;
11875+
11876+#ifdef CONFIG_PAX_RANDMMAP
11877+ if (mm->pax_flags & MF_PAX_RANDMMAP)
11878+ info.low_limit += mm->delta_mmap;
11879+#endif
11880+
11881 info.high_limit = STACK_TOP32;
11882 addr = vm_unmapped_area(&info);
11883 }
11884@@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11885 struct mm_struct *mm = current->mm;
11886 struct vm_area_struct *vma;
11887 unsigned long task_size = TASK_SIZE;
11888+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11889
11890 if (test_thread_flag(TIF_32BIT))
11891 task_size = STACK_TOP32;
11892@@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11893 return addr;
11894 }
11895
11896+#ifdef CONFIG_PAX_RANDMMAP
11897+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11898+#endif
11899+
11900 if (addr) {
11901 addr = ALIGN(addr, HPAGE_SIZE);
11902 vma = find_vma(mm, addr);
11903- if (task_size - len >= addr &&
11904- (!vma || addr + len <= vma->vm_start))
11905+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11906 return addr;
11907 }
11908 if (mm->get_unmapped_area == arch_get_unmapped_area)
11909 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11910- pgoff, flags);
11911+ pgoff, flags, offset);
11912 else
11913 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11914- pgoff, flags);
11915+ pgoff, flags, offset);
11916 }
11917
11918 pte_t *huge_pte_alloc(struct mm_struct *mm,
11919diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11920index 5322e53..f820c5e 100644
11921--- a/arch/sparc/mm/init_64.c
11922+++ b/arch/sparc/mm/init_64.c
11923@@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11924 int num_kernel_image_mappings;
11925
11926 #ifdef CONFIG_DEBUG_DCFLUSH
11927-atomic_t dcpage_flushes = ATOMIC_INIT(0);
11928+atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11929 #ifdef CONFIG_SMP
11930-atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11931+atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11932 #endif
11933 #endif
11934
11935@@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11936 {
11937 BUG_ON(tlb_type == hypervisor);
11938 #ifdef CONFIG_DEBUG_DCFLUSH
11939- atomic_inc(&dcpage_flushes);
11940+ atomic_inc_unchecked(&dcpage_flushes);
11941 #endif
11942
11943 #ifdef DCACHE_ALIASING_POSSIBLE
11944@@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11945
11946 #ifdef CONFIG_DEBUG_DCFLUSH
11947 seq_printf(m, "DCPageFlushes\t: %d\n",
11948- atomic_read(&dcpage_flushes));
11949+ atomic_read_unchecked(&dcpage_flushes));
11950 #ifdef CONFIG_SMP
11951 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11952- atomic_read(&dcpage_flushes_xcall));
11953+ atomic_read_unchecked(&dcpage_flushes_xcall));
11954 #endif /* CONFIG_SMP */
11955 #endif /* CONFIG_DEBUG_DCFLUSH */
11956 }
11957diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11958index b3692ce..e4517c9 100644
11959--- a/arch/tile/Kconfig
11960+++ b/arch/tile/Kconfig
11961@@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11962
11963 config KEXEC
11964 bool "kexec system call"
11965+ depends on !GRKERNSEC_KMEM
11966 ---help---
11967 kexec is a system call that implements the ability to shutdown your
11968 current kernel, and to start another kernel. It is like a reboot
11969diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11970index ad220ee..2f537b3 100644
11971--- a/arch/tile/include/asm/atomic_64.h
11972+++ b/arch/tile/include/asm/atomic_64.h
11973@@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11974
11975 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11976
11977+#define atomic64_read_unchecked(v) atomic64_read(v)
11978+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11979+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11980+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11981+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11982+#define atomic64_inc_unchecked(v) atomic64_inc(v)
11983+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11984+#define atomic64_dec_unchecked(v) atomic64_dec(v)
11985+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11986+
11987 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11988 #define smp_mb__before_atomic_dec() smp_mb()
11989 #define smp_mb__after_atomic_dec() smp_mb()
11990diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11991index 6160761..00cac88 100644
11992--- a/arch/tile/include/asm/cache.h
11993+++ b/arch/tile/include/asm/cache.h
11994@@ -15,11 +15,12 @@
11995 #ifndef _ASM_TILE_CACHE_H
11996 #define _ASM_TILE_CACHE_H
11997
11998+#include <linux/const.h>
11999 #include <arch/chip.h>
12000
12001 /* bytes per L1 data cache line */
12002 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12003-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12004+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12005
12006 /* bytes per L2 cache line */
12007 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12008diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12009index b6cde32..c0cb736 100644
12010--- a/arch/tile/include/asm/uaccess.h
12011+++ b/arch/tile/include/asm/uaccess.h
12012@@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12013 const void __user *from,
12014 unsigned long n)
12015 {
12016- int sz = __compiletime_object_size(to);
12017+ size_t sz = __compiletime_object_size(to);
12018
12019- if (likely(sz == -1 || sz >= n))
12020+ if (likely(sz == (size_t)-1 || sz >= n))
12021 n = _copy_from_user(to, from, n);
12022 else
12023 copy_from_user_overflow();
12024diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12025index 0cb3bba..7338b2d 100644
12026--- a/arch/tile/mm/hugetlbpage.c
12027+++ b/arch/tile/mm/hugetlbpage.c
12028@@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12029 info.high_limit = TASK_SIZE;
12030 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12031 info.align_offset = 0;
12032+ info.threadstack_offset = 0;
12033 return vm_unmapped_area(&info);
12034 }
12035
12036@@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12037 info.high_limit = current->mm->mmap_base;
12038 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12039 info.align_offset = 0;
12040+ info.threadstack_offset = 0;
12041 addr = vm_unmapped_area(&info);
12042
12043 /*
12044diff --git a/arch/um/Makefile b/arch/um/Makefile
12045index 36e658a..71a5c5a 100644
12046--- a/arch/um/Makefile
12047+++ b/arch/um/Makefile
12048@@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12049 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12050 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12051
12052+ifdef CONSTIFY_PLUGIN
12053+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12054+endif
12055+
12056 #This will adjust *FLAGS accordingly to the platform.
12057 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12058
12059diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12060index 19e1bdd..3665b77 100644
12061--- a/arch/um/include/asm/cache.h
12062+++ b/arch/um/include/asm/cache.h
12063@@ -1,6 +1,7 @@
12064 #ifndef __UM_CACHE_H
12065 #define __UM_CACHE_H
12066
12067+#include <linux/const.h>
12068
12069 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12070 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12071@@ -12,6 +13,6 @@
12072 # define L1_CACHE_SHIFT 5
12073 #endif
12074
12075-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12076+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12077
12078 #endif
12079diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12080index 2e0a6b1..a64d0f5 100644
12081--- a/arch/um/include/asm/kmap_types.h
12082+++ b/arch/um/include/asm/kmap_types.h
12083@@ -8,6 +8,6 @@
12084
12085 /* No more #include "asm/arch/kmap_types.h" ! */
12086
12087-#define KM_TYPE_NR 14
12088+#define KM_TYPE_NR 15
12089
12090 #endif
12091diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12092index 5ff53d9..5850cdf 100644
12093--- a/arch/um/include/asm/page.h
12094+++ b/arch/um/include/asm/page.h
12095@@ -14,6 +14,9 @@
12096 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12097 #define PAGE_MASK (~(PAGE_SIZE-1))
12098
12099+#define ktla_ktva(addr) (addr)
12100+#define ktva_ktla(addr) (addr)
12101+
12102 #ifndef __ASSEMBLY__
12103
12104 struct page;
12105diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12106index 0032f92..cd151e0 100644
12107--- a/arch/um/include/asm/pgtable-3level.h
12108+++ b/arch/um/include/asm/pgtable-3level.h
12109@@ -58,6 +58,7 @@
12110 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12111 #define pud_populate(mm, pud, pmd) \
12112 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12113+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12114
12115 #ifdef CONFIG_64BIT
12116 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12117diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12118index eecc414..48adb87 100644
12119--- a/arch/um/kernel/process.c
12120+++ b/arch/um/kernel/process.c
12121@@ -356,22 +356,6 @@ int singlestepping(void * t)
12122 return 2;
12123 }
12124
12125-/*
12126- * Only x86 and x86_64 have an arch_align_stack().
12127- * All other arches have "#define arch_align_stack(x) (x)"
12128- * in their asm/system.h
12129- * As this is included in UML from asm-um/system-generic.h,
12130- * we can use it to behave as the subarch does.
12131- */
12132-#ifndef arch_align_stack
12133-unsigned long arch_align_stack(unsigned long sp)
12134-{
12135- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12136- sp -= get_random_int() % 8192;
12137- return sp & ~0xf;
12138-}
12139-#endif
12140-
12141 unsigned long get_wchan(struct task_struct *p)
12142 {
12143 unsigned long stack_page, sp, ip;
12144diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12145index ad8f795..2c7eec6 100644
12146--- a/arch/unicore32/include/asm/cache.h
12147+++ b/arch/unicore32/include/asm/cache.h
12148@@ -12,8 +12,10 @@
12149 #ifndef __UNICORE_CACHE_H__
12150 #define __UNICORE_CACHE_H__
12151
12152-#define L1_CACHE_SHIFT (5)
12153-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12154+#include <linux/const.h>
12155+
12156+#define L1_CACHE_SHIFT 5
12157+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12158
12159 /*
12160 * Memory returned by kmalloc() may be used for DMA, so we must make
12161diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12162index 0952ecd..9cf578c 100644
12163--- a/arch/x86/Kconfig
12164+++ b/arch/x86/Kconfig
12165@@ -249,7 +249,7 @@ config X86_HT
12166
12167 config X86_32_LAZY_GS
12168 def_bool y
12169- depends on X86_32 && !CC_STACKPROTECTOR
12170+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12171
12172 config ARCH_HWEIGHT_CFLAGS
12173 string
12174@@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
12175
12176 menuconfig HYPERVISOR_GUEST
12177 bool "Linux guest support"
12178+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12179 ---help---
12180 Say Y here to enable options for running Linux under various hyper-
12181 visors. This option enables basic hypervisor detection and platform
12182@@ -1127,7 +1128,7 @@ choice
12183
12184 config NOHIGHMEM
12185 bool "off"
12186- depends on !X86_NUMAQ
12187+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12188 ---help---
12189 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12190 However, the address space of 32-bit x86 processors is only 4
12191@@ -1164,7 +1165,7 @@ config NOHIGHMEM
12192
12193 config HIGHMEM4G
12194 bool "4GB"
12195- depends on !X86_NUMAQ
12196+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12197 ---help---
12198 Select this if you have a 32-bit processor and between 1 and 4
12199 gigabytes of physical RAM.
12200@@ -1217,7 +1218,7 @@ config PAGE_OFFSET
12201 hex
12202 default 0xB0000000 if VMSPLIT_3G_OPT
12203 default 0x80000000 if VMSPLIT_2G
12204- default 0x78000000 if VMSPLIT_2G_OPT
12205+ default 0x70000000 if VMSPLIT_2G_OPT
12206 default 0x40000000 if VMSPLIT_1G
12207 default 0xC0000000
12208 depends on X86_32
12209@@ -1619,6 +1620,7 @@ config SECCOMP
12210
12211 config CC_STACKPROTECTOR
12212 bool "Enable -fstack-protector buffer overflow detection"
12213+ depends on X86_64 || !PAX_MEMORY_UDEREF
12214 ---help---
12215 This option turns on the -fstack-protector GCC feature. This
12216 feature puts, at the beginning of functions, a canary value on
12217@@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
12218
12219 config KEXEC
12220 bool "kexec system call"
12221+ depends on !GRKERNSEC_KMEM
12222 ---help---
12223 kexec is a system call that implements the ability to shutdown your
12224 current kernel, and to start another kernel. It is like a reboot
12225@@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
12226 config PHYSICAL_ALIGN
12227 hex "Alignment value to which kernel should be aligned"
12228 default "0x1000000"
12229+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12230+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12231 range 0x2000 0x1000000 if X86_32
12232 range 0x200000 0x1000000 if X86_64
12233 ---help---
12234@@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
12235 If unsure, say N.
12236
12237 config COMPAT_VDSO
12238- def_bool y
12239+ def_bool n
12240 prompt "Compat VDSO support"
12241 depends on X86_32 || IA32_EMULATION
12242+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12243 ---help---
12244 Map the 32-bit VDSO to the predictable old-style address too.
12245
12246diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12247index c026cca..14657ae 100644
12248--- a/arch/x86/Kconfig.cpu
12249+++ b/arch/x86/Kconfig.cpu
12250@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12251
12252 config X86_F00F_BUG
12253 def_bool y
12254- depends on M586MMX || M586TSC || M586 || M486
12255+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12256
12257 config X86_INVD_BUG
12258 def_bool y
12259@@ -327,7 +327,7 @@ config X86_INVD_BUG
12260
12261 config X86_ALIGNMENT_16
12262 def_bool y
12263- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12264+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12265
12266 config X86_INTEL_USERCOPY
12267 def_bool y
12268@@ -373,7 +373,7 @@ config X86_CMPXCHG64
12269 # generates cmov.
12270 config X86_CMOV
12271 def_bool y
12272- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12273+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12274
12275 config X86_MINIMUM_CPU_FAMILY
12276 int
12277diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12278index 0f3621e..282f24b 100644
12279--- a/arch/x86/Kconfig.debug
12280+++ b/arch/x86/Kconfig.debug
12281@@ -84,7 +84,7 @@ config X86_PTDUMP
12282 config DEBUG_RODATA
12283 bool "Write protect kernel read-only data structures"
12284 default y
12285- depends on DEBUG_KERNEL
12286+ depends on DEBUG_KERNEL && BROKEN
12287 ---help---
12288 Mark the kernel read-only data as write-protected in the pagetables,
12289 in order to catch accidental (and incorrect) writes to such const
12290@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
12291
12292 config DEBUG_SET_MODULE_RONX
12293 bool "Set loadable kernel module data as NX and text as RO"
12294- depends on MODULES
12295+ depends on MODULES && BROKEN
12296 ---help---
12297 This option helps catch unintended modifications to loadable
12298 kernel module's text and read-only data. It also prevents execution
12299diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12300index 57d0215..b4373fb 100644
12301--- a/arch/x86/Makefile
12302+++ b/arch/x86/Makefile
12303@@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
12304 # CPU-specific tuning. Anything which can be shared with UML should go here.
12305 include $(srctree)/arch/x86/Makefile_32.cpu
12306 KBUILD_CFLAGS += $(cflags-y)
12307-
12308- # temporary until string.h is fixed
12309- KBUILD_CFLAGS += -ffreestanding
12310 else
12311 BITS := 64
12312 UTS_MACHINE := x86_64
12313 CHECKFLAGS += -D__x86_64__ -m64
12314
12315+ biarch := $(call cc-option,-m64)
12316 KBUILD_AFLAGS += -m64
12317 KBUILD_CFLAGS += -m64
12318
12319@@ -89,6 +87,9 @@ else
12320 KBUILD_CFLAGS += -maccumulate-outgoing-args
12321 endif
12322
12323+# temporary until string.h is fixed
12324+KBUILD_CFLAGS += -ffreestanding
12325+
12326 ifdef CONFIG_CC_STACKPROTECTOR
12327 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12328 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
12329@@ -247,3 +248,12 @@ define archhelp
12330 echo ' FDINITRD=file initrd for the booted kernel'
12331 echo ' kvmconfig - Enable additional options for guest kernel support'
12332 endef
12333+
12334+define OLD_LD
12335+
12336+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12337+*** Please upgrade your binutils to 2.18 or newer
12338+endef
12339+
12340+archprepare:
12341+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12342diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12343index d9c1195..a26ca0d 100644
12344--- a/arch/x86/boot/Makefile
12345+++ b/arch/x86/boot/Makefile
12346@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
12347 $(call cc-option, -fno-unit-at-a-time)) \
12348 $(call cc-option, -fno-stack-protector) \
12349 $(call cc-option, -mpreferred-stack-boundary=2)
12350+ifdef CONSTIFY_PLUGIN
12351+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12352+endif
12353 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12354 GCOV_PROFILE := n
12355
12356diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12357index 878e4b9..20537ab 100644
12358--- a/arch/x86/boot/bitops.h
12359+++ b/arch/x86/boot/bitops.h
12360@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12361 u8 v;
12362 const u32 *p = (const u32 *)addr;
12363
12364- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12365+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12366 return v;
12367 }
12368
12369@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12370
12371 static inline void set_bit(int nr, void *addr)
12372 {
12373- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12374+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12375 }
12376
12377 #endif /* BOOT_BITOPS_H */
12378diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12379index ef72bae..353a184 100644
12380--- a/arch/x86/boot/boot.h
12381+++ b/arch/x86/boot/boot.h
12382@@ -85,7 +85,7 @@ static inline void io_delay(void)
12383 static inline u16 ds(void)
12384 {
12385 u16 seg;
12386- asm("movw %%ds,%0" : "=rm" (seg));
12387+ asm volatile("movw %%ds,%0" : "=rm" (seg));
12388 return seg;
12389 }
12390
12391@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
12392 static inline int memcmp(const void *s1, const void *s2, size_t len)
12393 {
12394 u8 diff;
12395- asm("repe; cmpsb; setnz %0"
12396+ asm volatile("repe; cmpsb; setnz %0"
12397 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
12398 return diff;
12399 }
12400diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12401index c8a6792..2402765 100644
12402--- a/arch/x86/boot/compressed/Makefile
12403+++ b/arch/x86/boot/compressed/Makefile
12404@@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12405 KBUILD_CFLAGS += -mno-mmx -mno-sse
12406 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12407 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12408+ifdef CONSTIFY_PLUGIN
12409+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12410+endif
12411
12412 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12413 GCOV_PROFILE := n
12414diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12415index a53440e..c3dbf1e 100644
12416--- a/arch/x86/boot/compressed/efi_stub_32.S
12417+++ b/arch/x86/boot/compressed/efi_stub_32.S
12418@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12419 * parameter 2, ..., param n. To make things easy, we save the return
12420 * address of efi_call_phys in a global variable.
12421 */
12422- popl %ecx
12423- movl %ecx, saved_return_addr(%edx)
12424- /* get the function pointer into ECX*/
12425- popl %ecx
12426- movl %ecx, efi_rt_function_ptr(%edx)
12427+ popl saved_return_addr(%edx)
12428+ popl efi_rt_function_ptr(%edx)
12429
12430 /*
12431 * 3. Call the physical function.
12432 */
12433- call *%ecx
12434+ call *efi_rt_function_ptr(%edx)
12435
12436 /*
12437 * 4. Balance the stack. And because EAX contain the return value,
12438@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12439 1: popl %edx
12440 subl $1b, %edx
12441
12442- movl efi_rt_function_ptr(%edx), %ecx
12443- pushl %ecx
12444+ pushl efi_rt_function_ptr(%edx)
12445
12446 /*
12447 * 10. Push the saved return address onto the stack and return.
12448 */
12449- movl saved_return_addr(%edx), %ecx
12450- pushl %ecx
12451- ret
12452+ jmpl *saved_return_addr(%edx)
12453 ENDPROC(efi_call_phys)
12454 .previous
12455
12456diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12457index 5d6f689..9d06730 100644
12458--- a/arch/x86/boot/compressed/head_32.S
12459+++ b/arch/x86/boot/compressed/head_32.S
12460@@ -118,7 +118,7 @@ preferred_addr:
12461 notl %eax
12462 andl %eax, %ebx
12463 #else
12464- movl $LOAD_PHYSICAL_ADDR, %ebx
12465+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12466 #endif
12467
12468 /* Target address to relocate to for decompression */
12469diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12470index c337422..2c5be72 100644
12471--- a/arch/x86/boot/compressed/head_64.S
12472+++ b/arch/x86/boot/compressed/head_64.S
12473@@ -95,7 +95,7 @@ ENTRY(startup_32)
12474 notl %eax
12475 andl %eax, %ebx
12476 #else
12477- movl $LOAD_PHYSICAL_ADDR, %ebx
12478+ movl $____LOAD_PHYSICAL_ADDR, %ebx
12479 #endif
12480
12481 /* Target address to relocate to for decompression */
12482@@ -270,7 +270,7 @@ preferred_addr:
12483 notq %rax
12484 andq %rax, %rbp
12485 #else
12486- movq $LOAD_PHYSICAL_ADDR, %rbp
12487+ movq $____LOAD_PHYSICAL_ADDR, %rbp
12488 #endif
12489
12490 /* Target address to relocate to for decompression */
12491@@ -362,8 +362,8 @@ gdt:
12492 .long gdt
12493 .word 0
12494 .quad 0x0000000000000000 /* NULL descriptor */
12495- .quad 0x00af9a000000ffff /* __KERNEL_CS */
12496- .quad 0x00cf92000000ffff /* __KERNEL_DS */
12497+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
12498+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
12499 .quad 0x0080890000000000 /* TS descriptor */
12500 .quad 0x0000000000000000 /* TS continued */
12501 gdt_end:
12502diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12503index 434f077..f20f3ff 100644
12504--- a/arch/x86/boot/compressed/misc.c
12505+++ b/arch/x86/boot/compressed/misc.c
12506@@ -224,7 +224,7 @@ void __putstr(const char *s)
12507
12508 void *memset(void *s, int c, size_t n)
12509 {
12510- int i;
12511+ size_t i;
12512 char *ss = s;
12513
12514 for (i = 0; i < n; i++)
12515@@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12516 * Calculate the delta between where vmlinux was linked to load
12517 * and where it was actually loaded.
12518 */
12519- delta = min_addr - LOAD_PHYSICAL_ADDR;
12520+ delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12521 if (!delta) {
12522 debug_putstr("No relocation needed... ");
12523 return;
12524@@ -353,7 +353,7 @@ static void parse_elf(void *output)
12525 Elf32_Ehdr ehdr;
12526 Elf32_Phdr *phdrs, *phdr;
12527 #endif
12528- void *dest;
12529+ void *dest, *prev;
12530 int i;
12531
12532 memcpy(&ehdr, output, sizeof(ehdr));
12533@@ -380,13 +380,16 @@ static void parse_elf(void *output)
12534 case PT_LOAD:
12535 #ifdef CONFIG_RELOCATABLE
12536 dest = output;
12537- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12538+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12539 #else
12540 dest = (void *)(phdr->p_paddr);
12541 #endif
12542 memcpy(dest,
12543 output + phdr->p_offset,
12544 phdr->p_filesz);
12545+ if (i)
12546+ memset(prev, 0xff, dest - prev);
12547+ prev = dest + phdr->p_filesz;
12548 break;
12549 default: /* Ignore other PT_* */ break;
12550 }
12551@@ -432,7 +435,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12552 error("Destination address too large");
12553 #endif
12554 #ifndef CONFIG_RELOCATABLE
12555- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12556+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12557 error("Wrong destination address");
12558 #endif
12559
12560diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12561index 4d3ff03..e4972ff 100644
12562--- a/arch/x86/boot/cpucheck.c
12563+++ b/arch/x86/boot/cpucheck.c
12564@@ -74,7 +74,7 @@ static int has_fpu(void)
12565 u16 fcw = -1, fsw = -1;
12566 u32 cr0;
12567
12568- asm("movl %%cr0,%0" : "=r" (cr0));
12569+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
12570 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12571 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12572 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12573@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12574 {
12575 u32 f0, f1;
12576
12577- asm("pushfl ; "
12578+ asm volatile("pushfl ; "
12579 "pushfl ; "
12580 "popl %0 ; "
12581 "movl %0,%1 ; "
12582@@ -115,7 +115,7 @@ static void get_flags(void)
12583 set_bit(X86_FEATURE_FPU, cpu.flags);
12584
12585 if (has_eflag(X86_EFLAGS_ID)) {
12586- asm("cpuid"
12587+ asm volatile("cpuid"
12588 : "=a" (max_intel_level),
12589 "=b" (cpu_vendor[0]),
12590 "=d" (cpu_vendor[1]),
12591@@ -124,7 +124,7 @@ static void get_flags(void)
12592
12593 if (max_intel_level >= 0x00000001 &&
12594 max_intel_level <= 0x0000ffff) {
12595- asm("cpuid"
12596+ asm volatile("cpuid"
12597 : "=a" (tfms),
12598 "=c" (cpu.flags[4]),
12599 "=d" (cpu.flags[0])
12600@@ -136,7 +136,7 @@ static void get_flags(void)
12601 cpu.model += ((tfms >> 16) & 0xf) << 4;
12602 }
12603
12604- asm("cpuid"
12605+ asm volatile("cpuid"
12606 : "=a" (max_amd_level)
12607 : "a" (0x80000000)
12608 : "ebx", "ecx", "edx");
12609@@ -144,7 +144,7 @@ static void get_flags(void)
12610 if (max_amd_level >= 0x80000001 &&
12611 max_amd_level <= 0x8000ffff) {
12612 u32 eax = 0x80000001;
12613- asm("cpuid"
12614+ asm volatile("cpuid"
12615 : "+a" (eax),
12616 "=c" (cpu.flags[6]),
12617 "=d" (cpu.flags[1])
12618@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12619 u32 ecx = MSR_K7_HWCR;
12620 u32 eax, edx;
12621
12622- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12623+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12624 eax &= ~(1 << 15);
12625- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12626+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12627
12628 get_flags(); /* Make sure it really did something */
12629 err = check_flags();
12630@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12631 u32 ecx = MSR_VIA_FCR;
12632 u32 eax, edx;
12633
12634- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12635+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12636 eax |= (1<<1)|(1<<7);
12637- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12638+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12639
12640 set_bit(X86_FEATURE_CX8, cpu.flags);
12641 err = check_flags();
12642@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12643 u32 eax, edx;
12644 u32 level = 1;
12645
12646- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12647- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12648- asm("cpuid"
12649+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12650+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12651+ asm volatile("cpuid"
12652 : "+a" (level), "=d" (cpu.flags[0])
12653 : : "ecx", "ebx");
12654- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12655+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12656
12657 err = check_flags();
12658 }
12659diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12660index 9ec06a1..2c25e79 100644
12661--- a/arch/x86/boot/header.S
12662+++ b/arch/x86/boot/header.S
12663@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12664 # single linked list of
12665 # struct setup_data
12666
12667-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12668+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12669
12670 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12671+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12672+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12673+#else
12674 #define VO_INIT_SIZE (VO__end - VO__text)
12675+#endif
12676 #if ZO_INIT_SIZE > VO_INIT_SIZE
12677 #define INIT_SIZE ZO_INIT_SIZE
12678 #else
12679diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12680index db75d07..8e6d0af 100644
12681--- a/arch/x86/boot/memory.c
12682+++ b/arch/x86/boot/memory.c
12683@@ -19,7 +19,7 @@
12684
12685 static int detect_memory_e820(void)
12686 {
12687- int count = 0;
12688+ unsigned int count = 0;
12689 struct biosregs ireg, oreg;
12690 struct e820entry *desc = boot_params.e820_map;
12691 static struct e820entry buf; /* static so it is zeroed */
12692diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12693index 11e8c6e..fdbb1ed 100644
12694--- a/arch/x86/boot/video-vesa.c
12695+++ b/arch/x86/boot/video-vesa.c
12696@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12697
12698 boot_params.screen_info.vesapm_seg = oreg.es;
12699 boot_params.screen_info.vesapm_off = oreg.di;
12700+ boot_params.screen_info.vesapm_size = oreg.cx;
12701 }
12702
12703 /*
12704diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12705index 43eda28..5ab5fdb 100644
12706--- a/arch/x86/boot/video.c
12707+++ b/arch/x86/boot/video.c
12708@@ -96,7 +96,7 @@ static void store_mode_params(void)
12709 static unsigned int get_entry(void)
12710 {
12711 char entry_buf[4];
12712- int i, len = 0;
12713+ unsigned int i, len = 0;
12714 int key;
12715 unsigned int v;
12716
12717diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12718index 9105655..41779c1 100644
12719--- a/arch/x86/crypto/aes-x86_64-asm_64.S
12720+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12721@@ -8,6 +8,8 @@
12722 * including this sentence is retained in full.
12723 */
12724
12725+#include <asm/alternative-asm.h>
12726+
12727 .extern crypto_ft_tab
12728 .extern crypto_it_tab
12729 .extern crypto_fl_tab
12730@@ -70,6 +72,8 @@
12731 je B192; \
12732 leaq 32(r9),r9;
12733
12734+#define ret pax_force_retaddr; ret
12735+
12736 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12737 movq r1,r2; \
12738 movq r3,r4; \
12739diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12740index 477e9d7..c92c7d8 100644
12741--- a/arch/x86/crypto/aesni-intel_asm.S
12742+++ b/arch/x86/crypto/aesni-intel_asm.S
12743@@ -31,6 +31,7 @@
12744
12745 #include <linux/linkage.h>
12746 #include <asm/inst.h>
12747+#include <asm/alternative-asm.h>
12748
12749 #ifdef __x86_64__
12750 .data
12751@@ -205,7 +206,7 @@ enc: .octa 0x2
12752 * num_initial_blocks = b mod 4
12753 * encrypt the initial num_initial_blocks blocks and apply ghash on
12754 * the ciphertext
12755-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12756+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12757 * are clobbered
12758 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12759 */
12760@@ -214,8 +215,8 @@ enc: .octa 0x2
12761 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12762 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12763 mov arg7, %r10 # %r10 = AAD
12764- mov arg8, %r12 # %r12 = aadLen
12765- mov %r12, %r11
12766+ mov arg8, %r15 # %r15 = aadLen
12767+ mov %r15, %r11
12768 pxor %xmm\i, %xmm\i
12769 _get_AAD_loop\num_initial_blocks\operation:
12770 movd (%r10), \TMP1
12771@@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12772 psrldq $4, %xmm\i
12773 pxor \TMP1, %xmm\i
12774 add $4, %r10
12775- sub $4, %r12
12776+ sub $4, %r15
12777 jne _get_AAD_loop\num_initial_blocks\operation
12778 cmp $16, %r11
12779 je _get_AAD_loop2_done\num_initial_blocks\operation
12780- mov $16, %r12
12781+ mov $16, %r15
12782 _get_AAD_loop2\num_initial_blocks\operation:
12783 psrldq $4, %xmm\i
12784- sub $4, %r12
12785- cmp %r11, %r12
12786+ sub $4, %r15
12787+ cmp %r11, %r15
12788 jne _get_AAD_loop2\num_initial_blocks\operation
12789 _get_AAD_loop2_done\num_initial_blocks\operation:
12790 movdqa SHUF_MASK(%rip), %xmm14
12791@@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12792 * num_initial_blocks = b mod 4
12793 * encrypt the initial num_initial_blocks blocks and apply ghash on
12794 * the ciphertext
12795-* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12796+* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12797 * are clobbered
12798 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12799 */
12800@@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12801 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12802 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12803 mov arg7, %r10 # %r10 = AAD
12804- mov arg8, %r12 # %r12 = aadLen
12805- mov %r12, %r11
12806+ mov arg8, %r15 # %r15 = aadLen
12807+ mov %r15, %r11
12808 pxor %xmm\i, %xmm\i
12809 _get_AAD_loop\num_initial_blocks\operation:
12810 movd (%r10), \TMP1
12811@@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12812 psrldq $4, %xmm\i
12813 pxor \TMP1, %xmm\i
12814 add $4, %r10
12815- sub $4, %r12
12816+ sub $4, %r15
12817 jne _get_AAD_loop\num_initial_blocks\operation
12818 cmp $16, %r11
12819 je _get_AAD_loop2_done\num_initial_blocks\operation
12820- mov $16, %r12
12821+ mov $16, %r15
12822 _get_AAD_loop2\num_initial_blocks\operation:
12823 psrldq $4, %xmm\i
12824- sub $4, %r12
12825- cmp %r11, %r12
12826+ sub $4, %r15
12827+ cmp %r11, %r15
12828 jne _get_AAD_loop2\num_initial_blocks\operation
12829 _get_AAD_loop2_done\num_initial_blocks\operation:
12830 movdqa SHUF_MASK(%rip), %xmm14
12831@@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12832 *
12833 *****************************************************************************/
12834 ENTRY(aesni_gcm_dec)
12835- push %r12
12836+ push %r15
12837 push %r13
12838 push %r14
12839 mov %rsp, %r14
12840@@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12841 */
12842 sub $VARIABLE_OFFSET, %rsp
12843 and $~63, %rsp # align rsp to 64 bytes
12844- mov %arg6, %r12
12845- movdqu (%r12), %xmm13 # %xmm13 = HashKey
12846+ mov %arg6, %r15
12847+ movdqu (%r15), %xmm13 # %xmm13 = HashKey
12848 movdqa SHUF_MASK(%rip), %xmm2
12849 PSHUFB_XMM %xmm2, %xmm13
12850
12851@@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12852 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12853 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12854 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12855- mov %r13, %r12
12856- and $(3<<4), %r12
12857+ mov %r13, %r15
12858+ and $(3<<4), %r15
12859 jz _initial_num_blocks_is_0_decrypt
12860- cmp $(2<<4), %r12
12861+ cmp $(2<<4), %r15
12862 jb _initial_num_blocks_is_1_decrypt
12863 je _initial_num_blocks_is_2_decrypt
12864 _initial_num_blocks_is_3_decrypt:
12865@@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12866 sub $16, %r11
12867 add %r13, %r11
12868 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12869- lea SHIFT_MASK+16(%rip), %r12
12870- sub %r13, %r12
12871+ lea SHIFT_MASK+16(%rip), %r15
12872+ sub %r13, %r15
12873 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12874 # (%r13 is the number of bytes in plaintext mod 16)
12875- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12876+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12877 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12878
12879 movdqa %xmm1, %xmm2
12880 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12881- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12882+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12883 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12884 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12885 pand %xmm1, %xmm2
12886@@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12887 sub $1, %r13
12888 jne _less_than_8_bytes_left_decrypt
12889 _multiple_of_16_bytes_decrypt:
12890- mov arg8, %r12 # %r13 = aadLen (number of bytes)
12891- shl $3, %r12 # convert into number of bits
12892- movd %r12d, %xmm15 # len(A) in %xmm15
12893+ mov arg8, %r15 # %r13 = aadLen (number of bytes)
12894+ shl $3, %r15 # convert into number of bits
12895+ movd %r15d, %xmm15 # len(A) in %xmm15
12896 shl $3, %arg4 # len(C) in bits (*128)
12897 MOVQ_R64_XMM %arg4, %xmm1
12898 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12899@@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12900 mov %r14, %rsp
12901 pop %r14
12902 pop %r13
12903- pop %r12
12904+ pop %r15
12905+ pax_force_retaddr
12906 ret
12907 ENDPROC(aesni_gcm_dec)
12908
12909@@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12910 * poly = x^128 + x^127 + x^126 + x^121 + 1
12911 ***************************************************************************/
12912 ENTRY(aesni_gcm_enc)
12913- push %r12
12914+ push %r15
12915 push %r13
12916 push %r14
12917 mov %rsp, %r14
12918@@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12919 #
12920 sub $VARIABLE_OFFSET, %rsp
12921 and $~63, %rsp
12922- mov %arg6, %r12
12923- movdqu (%r12), %xmm13
12924+ mov %arg6, %r15
12925+ movdqu (%r15), %xmm13
12926 movdqa SHUF_MASK(%rip), %xmm2
12927 PSHUFB_XMM %xmm2, %xmm13
12928
12929@@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12930 movdqa %xmm13, HashKey(%rsp)
12931 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12932 and $-16, %r13
12933- mov %r13, %r12
12934+ mov %r13, %r15
12935
12936 # Encrypt first few blocks
12937
12938- and $(3<<4), %r12
12939+ and $(3<<4), %r15
12940 jz _initial_num_blocks_is_0_encrypt
12941- cmp $(2<<4), %r12
12942+ cmp $(2<<4), %r15
12943 jb _initial_num_blocks_is_1_encrypt
12944 je _initial_num_blocks_is_2_encrypt
12945 _initial_num_blocks_is_3_encrypt:
12946@@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12947 sub $16, %r11
12948 add %r13, %r11
12949 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12950- lea SHIFT_MASK+16(%rip), %r12
12951- sub %r13, %r12
12952+ lea SHIFT_MASK+16(%rip), %r15
12953+ sub %r13, %r15
12954 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12955 # (%r13 is the number of bytes in plaintext mod 16)
12956- movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12957+ movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12958 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12959 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12960- movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12961+ movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12962 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12963 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12964 movdqa SHUF_MASK(%rip), %xmm10
12965@@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12966 sub $1, %r13
12967 jne _less_than_8_bytes_left_encrypt
12968 _multiple_of_16_bytes_encrypt:
12969- mov arg8, %r12 # %r12 = addLen (number of bytes)
12970- shl $3, %r12
12971- movd %r12d, %xmm15 # len(A) in %xmm15
12972+ mov arg8, %r15 # %r15 = addLen (number of bytes)
12973+ shl $3, %r15
12974+ movd %r15d, %xmm15 # len(A) in %xmm15
12975 shl $3, %arg4 # len(C) in bits (*128)
12976 MOVQ_R64_XMM %arg4, %xmm1
12977 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12978@@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12979 mov %r14, %rsp
12980 pop %r14
12981 pop %r13
12982- pop %r12
12983+ pop %r15
12984+ pax_force_retaddr
12985 ret
12986 ENDPROC(aesni_gcm_enc)
12987
12988@@ -1722,6 +1725,7 @@ _key_expansion_256a:
12989 pxor %xmm1, %xmm0
12990 movaps %xmm0, (TKEYP)
12991 add $0x10, TKEYP
12992+ pax_force_retaddr
12993 ret
12994 ENDPROC(_key_expansion_128)
12995 ENDPROC(_key_expansion_256a)
12996@@ -1748,6 +1752,7 @@ _key_expansion_192a:
12997 shufps $0b01001110, %xmm2, %xmm1
12998 movaps %xmm1, 0x10(TKEYP)
12999 add $0x20, TKEYP
13000+ pax_force_retaddr
13001 ret
13002 ENDPROC(_key_expansion_192a)
13003
13004@@ -1768,6 +1773,7 @@ _key_expansion_192b:
13005
13006 movaps %xmm0, (TKEYP)
13007 add $0x10, TKEYP
13008+ pax_force_retaddr
13009 ret
13010 ENDPROC(_key_expansion_192b)
13011
13012@@ -1781,6 +1787,7 @@ _key_expansion_256b:
13013 pxor %xmm1, %xmm2
13014 movaps %xmm2, (TKEYP)
13015 add $0x10, TKEYP
13016+ pax_force_retaddr
13017 ret
13018 ENDPROC(_key_expansion_256b)
13019
13020@@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13021 #ifndef __x86_64__
13022 popl KEYP
13023 #endif
13024+ pax_force_retaddr
13025 ret
13026 ENDPROC(aesni_set_key)
13027
13028@@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13029 popl KLEN
13030 popl KEYP
13031 #endif
13032+ pax_force_retaddr
13033 ret
13034 ENDPROC(aesni_enc)
13035
13036@@ -1974,6 +1983,7 @@ _aesni_enc1:
13037 AESENC KEY STATE
13038 movaps 0x70(TKEYP), KEY
13039 AESENCLAST KEY STATE
13040+ pax_force_retaddr
13041 ret
13042 ENDPROC(_aesni_enc1)
13043
13044@@ -2083,6 +2093,7 @@ _aesni_enc4:
13045 AESENCLAST KEY STATE2
13046 AESENCLAST KEY STATE3
13047 AESENCLAST KEY STATE4
13048+ pax_force_retaddr
13049 ret
13050 ENDPROC(_aesni_enc4)
13051
13052@@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13053 popl KLEN
13054 popl KEYP
13055 #endif
13056+ pax_force_retaddr
13057 ret
13058 ENDPROC(aesni_dec)
13059
13060@@ -2164,6 +2176,7 @@ _aesni_dec1:
13061 AESDEC KEY STATE
13062 movaps 0x70(TKEYP), KEY
13063 AESDECLAST KEY STATE
13064+ pax_force_retaddr
13065 ret
13066 ENDPROC(_aesni_dec1)
13067
13068@@ -2273,6 +2286,7 @@ _aesni_dec4:
13069 AESDECLAST KEY STATE2
13070 AESDECLAST KEY STATE3
13071 AESDECLAST KEY STATE4
13072+ pax_force_retaddr
13073 ret
13074 ENDPROC(_aesni_dec4)
13075
13076@@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13077 popl KEYP
13078 popl LEN
13079 #endif
13080+ pax_force_retaddr
13081 ret
13082 ENDPROC(aesni_ecb_enc)
13083
13084@@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13085 popl KEYP
13086 popl LEN
13087 #endif
13088+ pax_force_retaddr
13089 ret
13090 ENDPROC(aesni_ecb_dec)
13091
13092@@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13093 popl LEN
13094 popl IVP
13095 #endif
13096+ pax_force_retaddr
13097 ret
13098 ENDPROC(aesni_cbc_enc)
13099
13100@@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13101 popl LEN
13102 popl IVP
13103 #endif
13104+ pax_force_retaddr
13105 ret
13106 ENDPROC(aesni_cbc_dec)
13107
13108@@ -2550,6 +2568,7 @@ _aesni_inc_init:
13109 mov $1, TCTR_LOW
13110 MOVQ_R64_XMM TCTR_LOW INC
13111 MOVQ_R64_XMM CTR TCTR_LOW
13112+ pax_force_retaddr
13113 ret
13114 ENDPROC(_aesni_inc_init)
13115
13116@@ -2579,6 +2598,7 @@ _aesni_inc:
13117 .Linc_low:
13118 movaps CTR, IV
13119 PSHUFB_XMM BSWAP_MASK IV
13120+ pax_force_retaddr
13121 ret
13122 ENDPROC(_aesni_inc)
13123
13124@@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13125 .Lctr_enc_ret:
13126 movups IV, (IVP)
13127 .Lctr_enc_just_ret:
13128+ pax_force_retaddr
13129 ret
13130 ENDPROC(aesni_ctr_enc)
13131
13132@@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13133 pxor INC, STATE4
13134 movdqu STATE4, 0x70(OUTP)
13135
13136+ pax_force_retaddr
13137 ret
13138 ENDPROC(aesni_xts_crypt8)
13139
13140diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13141index 246c670..466e2d6 100644
13142--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13143+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13144@@ -21,6 +21,7 @@
13145 */
13146
13147 #include <linux/linkage.h>
13148+#include <asm/alternative-asm.h>
13149
13150 .file "blowfish-x86_64-asm.S"
13151 .text
13152@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13153 jnz .L__enc_xor;
13154
13155 write_block();
13156+ pax_force_retaddr
13157 ret;
13158 .L__enc_xor:
13159 xor_block();
13160+ pax_force_retaddr
13161 ret;
13162 ENDPROC(__blowfish_enc_blk)
13163
13164@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13165
13166 movq %r11, %rbp;
13167
13168+ pax_force_retaddr
13169 ret;
13170 ENDPROC(blowfish_dec_blk)
13171
13172@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13173
13174 popq %rbx;
13175 popq %rbp;
13176+ pax_force_retaddr
13177 ret;
13178
13179 .L__enc_xor4:
13180@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13181
13182 popq %rbx;
13183 popq %rbp;
13184+ pax_force_retaddr
13185 ret;
13186 ENDPROC(__blowfish_enc_blk_4way)
13187
13188@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13189 popq %rbx;
13190 popq %rbp;
13191
13192+ pax_force_retaddr
13193 ret;
13194 ENDPROC(blowfish_dec_blk_4way)
13195diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13196index ce71f92..1dce7ec 100644
13197--- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13198+++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13199@@ -16,6 +16,7 @@
13200 */
13201
13202 #include <linux/linkage.h>
13203+#include <asm/alternative-asm.h>
13204
13205 #define CAMELLIA_TABLE_BYTE_LEN 272
13206
13207@@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13208 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13209 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13210 %rcx, (%r9));
13211+ pax_force_retaddr
13212 ret;
13213 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13214
13215@@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13216 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13217 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13218 %rax, (%r9));
13219+ pax_force_retaddr
13220 ret;
13221 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13222
13223@@ -780,6 +783,7 @@ __camellia_enc_blk16:
13224 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13225 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13226
13227+ pax_force_retaddr
13228 ret;
13229
13230 .align 8
13231@@ -865,6 +869,7 @@ __camellia_dec_blk16:
13232 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13233 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13234
13235+ pax_force_retaddr
13236 ret;
13237
13238 .align 8
13239@@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13240 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13241 %xmm8, %rsi);
13242
13243+ pax_force_retaddr
13244 ret;
13245 ENDPROC(camellia_ecb_enc_16way)
13246
13247@@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13248 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13249 %xmm8, %rsi);
13250
13251+ pax_force_retaddr
13252 ret;
13253 ENDPROC(camellia_ecb_dec_16way)
13254
13255@@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13256 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13257 %xmm8, %rsi);
13258
13259+ pax_force_retaddr
13260 ret;
13261 ENDPROC(camellia_cbc_dec_16way)
13262
13263@@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13264 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13265 %xmm8, %rsi);
13266
13267+ pax_force_retaddr
13268 ret;
13269 ENDPROC(camellia_ctr_16way)
13270
13271@@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13272 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13273 %xmm8, %rsi);
13274
13275+ pax_force_retaddr
13276 ret;
13277 ENDPROC(camellia_xts_crypt_16way)
13278
13279diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13280index 0e0b886..5a3123c 100644
13281--- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13282+++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13283@@ -11,6 +11,7 @@
13284 */
13285
13286 #include <linux/linkage.h>
13287+#include <asm/alternative-asm.h>
13288
13289 #define CAMELLIA_TABLE_BYTE_LEN 272
13290
13291@@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13292 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13293 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13294 %rcx, (%r9));
13295+ pax_force_retaddr
13296 ret;
13297 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13298
13299@@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13300 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13301 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13302 %rax, (%r9));
13303+ pax_force_retaddr
13304 ret;
13305 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13306
13307@@ -820,6 +823,7 @@ __camellia_enc_blk32:
13308 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13309 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13310
13311+ pax_force_retaddr
13312 ret;
13313
13314 .align 8
13315@@ -905,6 +909,7 @@ __camellia_dec_blk32:
13316 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13317 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13318
13319+ pax_force_retaddr
13320 ret;
13321
13322 .align 8
13323@@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13324
13325 vzeroupper;
13326
13327+ pax_force_retaddr
13328 ret;
13329 ENDPROC(camellia_ecb_enc_32way)
13330
13331@@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13332
13333 vzeroupper;
13334
13335+ pax_force_retaddr
13336 ret;
13337 ENDPROC(camellia_ecb_dec_32way)
13338
13339@@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13340
13341 vzeroupper;
13342
13343+ pax_force_retaddr
13344 ret;
13345 ENDPROC(camellia_cbc_dec_32way)
13346
13347@@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13348
13349 vzeroupper;
13350
13351+ pax_force_retaddr
13352 ret;
13353 ENDPROC(camellia_ctr_32way)
13354
13355@@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13356
13357 vzeroupper;
13358
13359+ pax_force_retaddr
13360 ret;
13361 ENDPROC(camellia_xts_crypt_32way)
13362
13363diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13364index 310319c..db3d7b5 100644
13365--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13366+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13367@@ -21,6 +21,7 @@
13368 */
13369
13370 #include <linux/linkage.h>
13371+#include <asm/alternative-asm.h>
13372
13373 .file "camellia-x86_64-asm_64.S"
13374 .text
13375@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13376 enc_outunpack(mov, RT1);
13377
13378 movq RRBP, %rbp;
13379+ pax_force_retaddr
13380 ret;
13381
13382 .L__enc_xor:
13383 enc_outunpack(xor, RT1);
13384
13385 movq RRBP, %rbp;
13386+ pax_force_retaddr
13387 ret;
13388 ENDPROC(__camellia_enc_blk)
13389
13390@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13391 dec_outunpack();
13392
13393 movq RRBP, %rbp;
13394+ pax_force_retaddr
13395 ret;
13396 ENDPROC(camellia_dec_blk)
13397
13398@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13399
13400 movq RRBP, %rbp;
13401 popq %rbx;
13402+ pax_force_retaddr
13403 ret;
13404
13405 .L__enc2_xor:
13406@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13407
13408 movq RRBP, %rbp;
13409 popq %rbx;
13410+ pax_force_retaddr
13411 ret;
13412 ENDPROC(__camellia_enc_blk_2way)
13413
13414@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13415
13416 movq RRBP, %rbp;
13417 movq RXOR, %rbx;
13418+ pax_force_retaddr
13419 ret;
13420 ENDPROC(camellia_dec_blk_2way)
13421diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13422index c35fd5d..2d8c7db 100644
13423--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13424+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13425@@ -24,6 +24,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429+#include <asm/alternative-asm.h>
13430
13431 .file "cast5-avx-x86_64-asm_64.S"
13432
13433@@ -281,6 +282,7 @@ __cast5_enc_blk16:
13434 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13435 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13436
13437+ pax_force_retaddr
13438 ret;
13439 ENDPROC(__cast5_enc_blk16)
13440
13441@@ -352,6 +354,7 @@ __cast5_dec_blk16:
13442 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13443 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13444
13445+ pax_force_retaddr
13446 ret;
13447
13448 .L__skip_dec:
13449@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13450 vmovdqu RR4, (6*4*4)(%r11);
13451 vmovdqu RL4, (7*4*4)(%r11);
13452
13453+ pax_force_retaddr
13454 ret;
13455 ENDPROC(cast5_ecb_enc_16way)
13456
13457@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13458 vmovdqu RR4, (6*4*4)(%r11);
13459 vmovdqu RL4, (7*4*4)(%r11);
13460
13461+ pax_force_retaddr
13462 ret;
13463 ENDPROC(cast5_ecb_dec_16way)
13464
13465@@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13466 * %rdx: src
13467 */
13468
13469- pushq %r12;
13470+ pushq %r14;
13471
13472 movq %rsi, %r11;
13473- movq %rdx, %r12;
13474+ movq %rdx, %r14;
13475
13476 vmovdqu (0*16)(%rdx), RL1;
13477 vmovdqu (1*16)(%rdx), RR1;
13478@@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13479 call __cast5_dec_blk16;
13480
13481 /* xor with src */
13482- vmovq (%r12), RX;
13483+ vmovq (%r14), RX;
13484 vpshufd $0x4f, RX, RX;
13485 vpxor RX, RR1, RR1;
13486- vpxor 0*16+8(%r12), RL1, RL1;
13487- vpxor 1*16+8(%r12), RR2, RR2;
13488- vpxor 2*16+8(%r12), RL2, RL2;
13489- vpxor 3*16+8(%r12), RR3, RR3;
13490- vpxor 4*16+8(%r12), RL3, RL3;
13491- vpxor 5*16+8(%r12), RR4, RR4;
13492- vpxor 6*16+8(%r12), RL4, RL4;
13493+ vpxor 0*16+8(%r14), RL1, RL1;
13494+ vpxor 1*16+8(%r14), RR2, RR2;
13495+ vpxor 2*16+8(%r14), RL2, RL2;
13496+ vpxor 3*16+8(%r14), RR3, RR3;
13497+ vpxor 4*16+8(%r14), RL3, RL3;
13498+ vpxor 5*16+8(%r14), RR4, RR4;
13499+ vpxor 6*16+8(%r14), RL4, RL4;
13500
13501 vmovdqu RR1, (0*16)(%r11);
13502 vmovdqu RL1, (1*16)(%r11);
13503@@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13504 vmovdqu RR4, (6*16)(%r11);
13505 vmovdqu RL4, (7*16)(%r11);
13506
13507- popq %r12;
13508+ popq %r14;
13509
13510+ pax_force_retaddr
13511 ret;
13512 ENDPROC(cast5_cbc_dec_16way)
13513
13514@@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13515 * %rcx: iv (big endian, 64bit)
13516 */
13517
13518- pushq %r12;
13519+ pushq %r14;
13520
13521 movq %rsi, %r11;
13522- movq %rdx, %r12;
13523+ movq %rdx, %r14;
13524
13525 vpcmpeqd RTMP, RTMP, RTMP;
13526 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13527@@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13528 call __cast5_enc_blk16;
13529
13530 /* dst = src ^ iv */
13531- vpxor (0*16)(%r12), RR1, RR1;
13532- vpxor (1*16)(%r12), RL1, RL1;
13533- vpxor (2*16)(%r12), RR2, RR2;
13534- vpxor (3*16)(%r12), RL2, RL2;
13535- vpxor (4*16)(%r12), RR3, RR3;
13536- vpxor (5*16)(%r12), RL3, RL3;
13537- vpxor (6*16)(%r12), RR4, RR4;
13538- vpxor (7*16)(%r12), RL4, RL4;
13539+ vpxor (0*16)(%r14), RR1, RR1;
13540+ vpxor (1*16)(%r14), RL1, RL1;
13541+ vpxor (2*16)(%r14), RR2, RR2;
13542+ vpxor (3*16)(%r14), RL2, RL2;
13543+ vpxor (4*16)(%r14), RR3, RR3;
13544+ vpxor (5*16)(%r14), RL3, RL3;
13545+ vpxor (6*16)(%r14), RR4, RR4;
13546+ vpxor (7*16)(%r14), RL4, RL4;
13547 vmovdqu RR1, (0*16)(%r11);
13548 vmovdqu RL1, (1*16)(%r11);
13549 vmovdqu RR2, (2*16)(%r11);
13550@@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13551 vmovdqu RR4, (6*16)(%r11);
13552 vmovdqu RL4, (7*16)(%r11);
13553
13554- popq %r12;
13555+ popq %r14;
13556
13557+ pax_force_retaddr
13558 ret;
13559 ENDPROC(cast5_ctr_16way)
13560diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13561index e3531f8..e123f35 100644
13562--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13563+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13564@@ -24,6 +24,7 @@
13565 */
13566
13567 #include <linux/linkage.h>
13568+#include <asm/alternative-asm.h>
13569 #include "glue_helper-asm-avx.S"
13570
13571 .file "cast6-avx-x86_64-asm_64.S"
13572@@ -295,6 +296,7 @@ __cast6_enc_blk8:
13573 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13574 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13575
13576+ pax_force_retaddr
13577 ret;
13578 ENDPROC(__cast6_enc_blk8)
13579
13580@@ -340,6 +342,7 @@ __cast6_dec_blk8:
13581 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13582 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13583
13584+ pax_force_retaddr
13585 ret;
13586 ENDPROC(__cast6_dec_blk8)
13587
13588@@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13589
13590 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13591
13592+ pax_force_retaddr
13593 ret;
13594 ENDPROC(cast6_ecb_enc_8way)
13595
13596@@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13597
13598 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13599
13600+ pax_force_retaddr
13601 ret;
13602 ENDPROC(cast6_ecb_dec_8way)
13603
13604@@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13605 * %rdx: src
13606 */
13607
13608- pushq %r12;
13609+ pushq %r14;
13610
13611 movq %rsi, %r11;
13612- movq %rdx, %r12;
13613+ movq %rdx, %r14;
13614
13615 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13616
13617 call __cast6_dec_blk8;
13618
13619- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13620+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13621
13622- popq %r12;
13623+ popq %r14;
13624
13625+ pax_force_retaddr
13626 ret;
13627 ENDPROC(cast6_cbc_dec_8way)
13628
13629@@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13630 * %rcx: iv (little endian, 128bit)
13631 */
13632
13633- pushq %r12;
13634+ pushq %r14;
13635
13636 movq %rsi, %r11;
13637- movq %rdx, %r12;
13638+ movq %rdx, %r14;
13639
13640 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13641 RD2, RX, RKR, RKM);
13642
13643 call __cast6_enc_blk8;
13644
13645- store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646+ store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13647
13648- popq %r12;
13649+ popq %r14;
13650
13651+ pax_force_retaddr
13652 ret;
13653 ENDPROC(cast6_ctr_8way)
13654
13655@@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13656 /* dst <= regs xor IVs(in dst) */
13657 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13658
13659+ pax_force_retaddr
13660 ret;
13661 ENDPROC(cast6_xts_enc_8way)
13662
13663@@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13664 /* dst <= regs xor IVs(in dst) */
13665 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13666
13667+ pax_force_retaddr
13668 ret;
13669 ENDPROC(cast6_xts_dec_8way)
13670diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13671index dbc4339..de6e120 100644
13672--- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13673+++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13674@@ -45,6 +45,7 @@
13675
13676 #include <asm/inst.h>
13677 #include <linux/linkage.h>
13678+#include <asm/alternative-asm.h>
13679
13680 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13681
13682@@ -312,6 +313,7 @@ do_return:
13683 popq %rsi
13684 popq %rdi
13685 popq %rbx
13686+ pax_force_retaddr
13687 ret
13688
13689 ################################################################
13690diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13691index 185fad4..ff4cd36 100644
13692--- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13693+++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13694@@ -18,6 +18,7 @@
13695
13696 #include <linux/linkage.h>
13697 #include <asm/inst.h>
13698+#include <asm/alternative-asm.h>
13699
13700 .data
13701
13702@@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13703 psrlq $1, T2
13704 pxor T2, T1
13705 pxor T1, DATA
13706+ pax_force_retaddr
13707 ret
13708 ENDPROC(__clmul_gf128mul_ble)
13709
13710@@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13711 call __clmul_gf128mul_ble
13712 PSHUFB_XMM BSWAP DATA
13713 movups DATA, (%rdi)
13714+ pax_force_retaddr
13715 ret
13716 ENDPROC(clmul_ghash_mul)
13717
13718@@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13719 PSHUFB_XMM BSWAP DATA
13720 movups DATA, (%rdi)
13721 .Lupdate_just_ret:
13722+ pax_force_retaddr
13723 ret
13724 ENDPROC(clmul_ghash_update)
13725diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13726index 9279e0b..c4b3d2c 100644
13727--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13728+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13729@@ -1,4 +1,5 @@
13730 #include <linux/linkage.h>
13731+#include <asm/alternative-asm.h>
13732
13733 # enter salsa20_encrypt_bytes
13734 ENTRY(salsa20_encrypt_bytes)
13735@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13736 add %r11,%rsp
13737 mov %rdi,%rax
13738 mov %rsi,%rdx
13739+ pax_force_retaddr
13740 ret
13741 # bytesatleast65:
13742 ._bytesatleast65:
13743@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13744 add %r11,%rsp
13745 mov %rdi,%rax
13746 mov %rsi,%rdx
13747+ pax_force_retaddr
13748 ret
13749 ENDPROC(salsa20_keysetup)
13750
13751@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13752 add %r11,%rsp
13753 mov %rdi,%rax
13754 mov %rsi,%rdx
13755+ pax_force_retaddr
13756 ret
13757 ENDPROC(salsa20_ivsetup)
13758diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13759index 2f202f4..d9164d6 100644
13760--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13761+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13762@@ -24,6 +24,7 @@
13763 */
13764
13765 #include <linux/linkage.h>
13766+#include <asm/alternative-asm.h>
13767 #include "glue_helper-asm-avx.S"
13768
13769 .file "serpent-avx-x86_64-asm_64.S"
13770@@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13771 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13772 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13773
13774+ pax_force_retaddr
13775 ret;
13776 ENDPROC(__serpent_enc_blk8_avx)
13777
13778@@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13779 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13780 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13781
13782+ pax_force_retaddr
13783 ret;
13784 ENDPROC(__serpent_dec_blk8_avx)
13785
13786@@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13787
13788 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13789
13790+ pax_force_retaddr
13791 ret;
13792 ENDPROC(serpent_ecb_enc_8way_avx)
13793
13794@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13795
13796 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13797
13798+ pax_force_retaddr
13799 ret;
13800 ENDPROC(serpent_ecb_dec_8way_avx)
13801
13802@@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13803
13804 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13805
13806+ pax_force_retaddr
13807 ret;
13808 ENDPROC(serpent_cbc_dec_8way_avx)
13809
13810@@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13811
13812 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13813
13814+ pax_force_retaddr
13815 ret;
13816 ENDPROC(serpent_ctr_8way_avx)
13817
13818@@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13819 /* dst <= regs xor IVs(in dst) */
13820 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13821
13822+ pax_force_retaddr
13823 ret;
13824 ENDPROC(serpent_xts_enc_8way_avx)
13825
13826@@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13827 /* dst <= regs xor IVs(in dst) */
13828 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13829
13830+ pax_force_retaddr
13831 ret;
13832 ENDPROC(serpent_xts_dec_8way_avx)
13833diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13834index b222085..abd483c 100644
13835--- a/arch/x86/crypto/serpent-avx2-asm_64.S
13836+++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13837@@ -15,6 +15,7 @@
13838 */
13839
13840 #include <linux/linkage.h>
13841+#include <asm/alternative-asm.h>
13842 #include "glue_helper-asm-avx2.S"
13843
13844 .file "serpent-avx2-asm_64.S"
13845@@ -610,6 +611,7 @@ __serpent_enc_blk16:
13846 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13847 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13848
13849+ pax_force_retaddr
13850 ret;
13851 ENDPROC(__serpent_enc_blk16)
13852
13853@@ -664,6 +666,7 @@ __serpent_dec_blk16:
13854 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13855 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13856
13857+ pax_force_retaddr
13858 ret;
13859 ENDPROC(__serpent_dec_blk16)
13860
13861@@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13862
13863 vzeroupper;
13864
13865+ pax_force_retaddr
13866 ret;
13867 ENDPROC(serpent_ecb_enc_16way)
13868
13869@@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13870
13871 vzeroupper;
13872
13873+ pax_force_retaddr
13874 ret;
13875 ENDPROC(serpent_ecb_dec_16way)
13876
13877@@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13878
13879 vzeroupper;
13880
13881+ pax_force_retaddr
13882 ret;
13883 ENDPROC(serpent_cbc_dec_16way)
13884
13885@@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13886
13887 vzeroupper;
13888
13889+ pax_force_retaddr
13890 ret;
13891 ENDPROC(serpent_ctr_16way)
13892
13893@@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13894
13895 vzeroupper;
13896
13897+ pax_force_retaddr
13898 ret;
13899 ENDPROC(serpent_xts_enc_16way)
13900
13901@@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13902
13903 vzeroupper;
13904
13905+ pax_force_retaddr
13906 ret;
13907 ENDPROC(serpent_xts_dec_16way)
13908diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13909index acc066c..1559cc4 100644
13910--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13911+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13912@@ -25,6 +25,7 @@
13913 */
13914
13915 #include <linux/linkage.h>
13916+#include <asm/alternative-asm.h>
13917
13918 .file "serpent-sse2-x86_64-asm_64.S"
13919 .text
13920@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13921 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13922 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13923
13924+ pax_force_retaddr
13925 ret;
13926
13927 .L__enc_xor8:
13928 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13929 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13930
13931+ pax_force_retaddr
13932 ret;
13933 ENDPROC(__serpent_enc_blk_8way)
13934
13935@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13936 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13937 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13938
13939+ pax_force_retaddr
13940 ret;
13941 ENDPROC(serpent_dec_blk_8way)
13942diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13943index a410950..9dfe7ad 100644
13944--- a/arch/x86/crypto/sha1_ssse3_asm.S
13945+++ b/arch/x86/crypto/sha1_ssse3_asm.S
13946@@ -29,6 +29,7 @@
13947 */
13948
13949 #include <linux/linkage.h>
13950+#include <asm/alternative-asm.h>
13951
13952 #define CTX %rdi // arg1
13953 #define BUF %rsi // arg2
13954@@ -75,9 +76,9 @@
13955
13956 push %rbx
13957 push %rbp
13958- push %r12
13959+ push %r14
13960
13961- mov %rsp, %r12
13962+ mov %rsp, %r14
13963 sub $64, %rsp # allocate workspace
13964 and $~15, %rsp # align stack
13965
13966@@ -99,11 +100,12 @@
13967 xor %rax, %rax
13968 rep stosq
13969
13970- mov %r12, %rsp # deallocate workspace
13971+ mov %r14, %rsp # deallocate workspace
13972
13973- pop %r12
13974+ pop %r14
13975 pop %rbp
13976 pop %rbx
13977+ pax_force_retaddr
13978 ret
13979
13980 ENDPROC(\name)
13981diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13982index 642f156..51a513c 100644
13983--- a/arch/x86/crypto/sha256-avx-asm.S
13984+++ b/arch/x86/crypto/sha256-avx-asm.S
13985@@ -49,6 +49,7 @@
13986
13987 #ifdef CONFIG_AS_AVX
13988 #include <linux/linkage.h>
13989+#include <asm/alternative-asm.h>
13990
13991 ## assume buffers not aligned
13992 #define VMOVDQ vmovdqu
13993@@ -460,6 +461,7 @@ done_hash:
13994 popq %r13
13995 popq %rbp
13996 popq %rbx
13997+ pax_force_retaddr
13998 ret
13999 ENDPROC(sha256_transform_avx)
14000
14001diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14002index 9e86944..3795e6a 100644
14003--- a/arch/x86/crypto/sha256-avx2-asm.S
14004+++ b/arch/x86/crypto/sha256-avx2-asm.S
14005@@ -50,6 +50,7 @@
14006
14007 #ifdef CONFIG_AS_AVX2
14008 #include <linux/linkage.h>
14009+#include <asm/alternative-asm.h>
14010
14011 ## assume buffers not aligned
14012 #define VMOVDQ vmovdqu
14013@@ -720,6 +721,7 @@ done_hash:
14014 popq %r12
14015 popq %rbp
14016 popq %rbx
14017+ pax_force_retaddr
14018 ret
14019 ENDPROC(sha256_transform_rorx)
14020
14021diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14022index f833b74..8c62a9e 100644
14023--- a/arch/x86/crypto/sha256-ssse3-asm.S
14024+++ b/arch/x86/crypto/sha256-ssse3-asm.S
14025@@ -47,6 +47,7 @@
14026 ########################################################################
14027
14028 #include <linux/linkage.h>
14029+#include <asm/alternative-asm.h>
14030
14031 ## assume buffers not aligned
14032 #define MOVDQ movdqu
14033@@ -471,6 +472,7 @@ done_hash:
14034 popq %rbp
14035 popq %rbx
14036
14037+ pax_force_retaddr
14038 ret
14039 ENDPROC(sha256_transform_ssse3)
14040
14041diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14042index 974dde9..a823ff9 100644
14043--- a/arch/x86/crypto/sha512-avx-asm.S
14044+++ b/arch/x86/crypto/sha512-avx-asm.S
14045@@ -49,6 +49,7 @@
14046
14047 #ifdef CONFIG_AS_AVX
14048 #include <linux/linkage.h>
14049+#include <asm/alternative-asm.h>
14050
14051 .text
14052
14053@@ -364,6 +365,7 @@ updateblock:
14054 mov frame_RSPSAVE(%rsp), %rsp
14055
14056 nowork:
14057+ pax_force_retaddr
14058 ret
14059 ENDPROC(sha512_transform_avx)
14060
14061diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14062index 568b961..ed20c37 100644
14063--- a/arch/x86/crypto/sha512-avx2-asm.S
14064+++ b/arch/x86/crypto/sha512-avx2-asm.S
14065@@ -51,6 +51,7 @@
14066
14067 #ifdef CONFIG_AS_AVX2
14068 #include <linux/linkage.h>
14069+#include <asm/alternative-asm.h>
14070
14071 .text
14072
14073@@ -678,6 +679,7 @@ done_hash:
14074
14075 # Restore Stack Pointer
14076 mov frame_RSPSAVE(%rsp), %rsp
14077+ pax_force_retaddr
14078 ret
14079 ENDPROC(sha512_transform_rorx)
14080
14081diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14082index fb56855..6edd768 100644
14083--- a/arch/x86/crypto/sha512-ssse3-asm.S
14084+++ b/arch/x86/crypto/sha512-ssse3-asm.S
14085@@ -48,6 +48,7 @@
14086 ########################################################################
14087
14088 #include <linux/linkage.h>
14089+#include <asm/alternative-asm.h>
14090
14091 .text
14092
14093@@ -363,6 +364,7 @@ updateblock:
14094 mov frame_RSPSAVE(%rsp), %rsp
14095
14096 nowork:
14097+ pax_force_retaddr
14098 ret
14099 ENDPROC(sha512_transform_ssse3)
14100
14101diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14102index 0505813..b067311 100644
14103--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14104+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14105@@ -24,6 +24,7 @@
14106 */
14107
14108 #include <linux/linkage.h>
14109+#include <asm/alternative-asm.h>
14110 #include "glue_helper-asm-avx.S"
14111
14112 .file "twofish-avx-x86_64-asm_64.S"
14113@@ -284,6 +285,7 @@ __twofish_enc_blk8:
14114 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14115 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14116
14117+ pax_force_retaddr
14118 ret;
14119 ENDPROC(__twofish_enc_blk8)
14120
14121@@ -324,6 +326,7 @@ __twofish_dec_blk8:
14122 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14123 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14124
14125+ pax_force_retaddr
14126 ret;
14127 ENDPROC(__twofish_dec_blk8)
14128
14129@@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14130
14131 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14132
14133+ pax_force_retaddr
14134 ret;
14135 ENDPROC(twofish_ecb_enc_8way)
14136
14137@@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14138
14139 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14140
14141+ pax_force_retaddr
14142 ret;
14143 ENDPROC(twofish_ecb_dec_8way)
14144
14145@@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14146 * %rdx: src
14147 */
14148
14149- pushq %r12;
14150+ pushq %r14;
14151
14152 movq %rsi, %r11;
14153- movq %rdx, %r12;
14154+ movq %rdx, %r14;
14155
14156 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14157
14158 call __twofish_dec_blk8;
14159
14160- store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14161+ store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14162
14163- popq %r12;
14164+ popq %r14;
14165
14166+ pax_force_retaddr
14167 ret;
14168 ENDPROC(twofish_cbc_dec_8way)
14169
14170@@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14171 * %rcx: iv (little endian, 128bit)
14172 */
14173
14174- pushq %r12;
14175+ pushq %r14;
14176
14177 movq %rsi, %r11;
14178- movq %rdx, %r12;
14179+ movq %rdx, %r14;
14180
14181 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14182 RD2, RX0, RX1, RY0);
14183
14184 call __twofish_enc_blk8;
14185
14186- store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14187+ store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14188
14189- popq %r12;
14190+ popq %r14;
14191
14192+ pax_force_retaddr
14193 ret;
14194 ENDPROC(twofish_ctr_8way)
14195
14196@@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14197 /* dst <= regs xor IVs(in dst) */
14198 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14199
14200+ pax_force_retaddr
14201 ret;
14202 ENDPROC(twofish_xts_enc_8way)
14203
14204@@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14205 /* dst <= regs xor IVs(in dst) */
14206 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14207
14208+ pax_force_retaddr
14209 ret;
14210 ENDPROC(twofish_xts_dec_8way)
14211diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14212index 1c3b7ce..02f578d 100644
14213--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14214+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14215@@ -21,6 +21,7 @@
14216 */
14217
14218 #include <linux/linkage.h>
14219+#include <asm/alternative-asm.h>
14220
14221 .file "twofish-x86_64-asm-3way.S"
14222 .text
14223@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14224 popq %r13;
14225 popq %r14;
14226 popq %r15;
14227+ pax_force_retaddr
14228 ret;
14229
14230 .L__enc_xor3:
14231@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14232 popq %r13;
14233 popq %r14;
14234 popq %r15;
14235+ pax_force_retaddr
14236 ret;
14237 ENDPROC(__twofish_enc_blk_3way)
14238
14239@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14240 popq %r13;
14241 popq %r14;
14242 popq %r15;
14243+ pax_force_retaddr
14244 ret;
14245 ENDPROC(twofish_dec_blk_3way)
14246diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14247index a039d21..524b8b2 100644
14248--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14249+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14250@@ -22,6 +22,7 @@
14251
14252 #include <linux/linkage.h>
14253 #include <asm/asm-offsets.h>
14254+#include <asm/alternative-asm.h>
14255
14256 #define a_offset 0
14257 #define b_offset 4
14258@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14259
14260 popq R1
14261 movq $1,%rax
14262+ pax_force_retaddr
14263 ret
14264 ENDPROC(twofish_enc_blk)
14265
14266@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14267
14268 popq R1
14269 movq $1,%rax
14270+ pax_force_retaddr
14271 ret
14272 ENDPROC(twofish_dec_blk)
14273diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14274index d21ff89..6da8e6e 100644
14275--- a/arch/x86/ia32/ia32_aout.c
14276+++ b/arch/x86/ia32/ia32_aout.c
14277@@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14278 unsigned long dump_start, dump_size;
14279 struct user32 dump;
14280
14281+ memset(&dump, 0, sizeof(dump));
14282+
14283 fs = get_fs();
14284 set_fs(KERNEL_DS);
14285 has_dumped = 1;
14286diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14287index 2206757..85cbcfa 100644
14288--- a/arch/x86/ia32/ia32_signal.c
14289+++ b/arch/x86/ia32/ia32_signal.c
14290@@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14291 if (__get_user(set.sig[0], &frame->sc.oldmask)
14292 || (_COMPAT_NSIG_WORDS > 1
14293 && __copy_from_user((((char *) &set.sig) + 4),
14294- &frame->extramask,
14295+ frame->extramask,
14296 sizeof(frame->extramask))))
14297 goto badframe;
14298
14299@@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14300 sp -= frame_size;
14301 /* Align the stack pointer according to the i386 ABI,
14302 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14303- sp = ((sp + 4) & -16ul) - 4;
14304+ sp = ((sp - 12) & -16ul) - 4;
14305 return (void __user *) sp;
14306 }
14307
14308@@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14309 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14310 sigreturn);
14311 else
14312- restorer = &frame->retcode;
14313+ restorer = frame->retcode;
14314 }
14315
14316 put_user_try {
14317@@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14318 * These are actually not used anymore, but left because some
14319 * gdb versions depend on them as a marker.
14320 */
14321- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14322+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14323 } put_user_catch(err);
14324
14325 if (err)
14326@@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14327 0xb8,
14328 __NR_ia32_rt_sigreturn,
14329 0x80cd,
14330- 0,
14331+ 0
14332 };
14333
14334 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14335@@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14336
14337 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14338 restorer = ksig->ka.sa.sa_restorer;
14339+ else if (current->mm->context.vdso)
14340+ /* Return stub is in 32bit vsyscall page */
14341+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14342 else
14343- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14344- rt_sigreturn);
14345+ restorer = frame->retcode;
14346 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14347
14348 /*
14349 * Not actually used anymore, but left because some gdb
14350 * versions need it.
14351 */
14352- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14353+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14354 } put_user_catch(err);
14355
14356 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14357diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14358index 4299eb0..c0687a7 100644
14359--- a/arch/x86/ia32/ia32entry.S
14360+++ b/arch/x86/ia32/ia32entry.S
14361@@ -15,8 +15,10 @@
14362 #include <asm/irqflags.h>
14363 #include <asm/asm.h>
14364 #include <asm/smap.h>
14365+#include <asm/pgtable.h>
14366 #include <linux/linkage.h>
14367 #include <linux/err.h>
14368+#include <asm/alternative-asm.h>
14369
14370 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14371 #include <linux/elf-em.h>
14372@@ -62,12 +64,12 @@
14373 */
14374 .macro LOAD_ARGS32 offset, _r9=0
14375 .if \_r9
14376- movl \offset+16(%rsp),%r9d
14377+ movl \offset+R9(%rsp),%r9d
14378 .endif
14379- movl \offset+40(%rsp),%ecx
14380- movl \offset+48(%rsp),%edx
14381- movl \offset+56(%rsp),%esi
14382- movl \offset+64(%rsp),%edi
14383+ movl \offset+RCX(%rsp),%ecx
14384+ movl \offset+RDX(%rsp),%edx
14385+ movl \offset+RSI(%rsp),%esi
14386+ movl \offset+RDI(%rsp),%edi
14387 movl %eax,%eax /* zero extension */
14388 .endm
14389
14390@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14391 ENDPROC(native_irq_enable_sysexit)
14392 #endif
14393
14394+ .macro pax_enter_kernel_user
14395+ pax_set_fptr_mask
14396+#ifdef CONFIG_PAX_MEMORY_UDEREF
14397+ call pax_enter_kernel_user
14398+#endif
14399+ .endm
14400+
14401+ .macro pax_exit_kernel_user
14402+#ifdef CONFIG_PAX_MEMORY_UDEREF
14403+ call pax_exit_kernel_user
14404+#endif
14405+#ifdef CONFIG_PAX_RANDKSTACK
14406+ pushq %rax
14407+ pushq %r11
14408+ call pax_randomize_kstack
14409+ popq %r11
14410+ popq %rax
14411+#endif
14412+ .endm
14413+
14414+ .macro pax_erase_kstack
14415+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14416+ call pax_erase_kstack
14417+#endif
14418+ .endm
14419+
14420 /*
14421 * 32bit SYSENTER instruction entry.
14422 *
14423@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14424 CFI_REGISTER rsp,rbp
14425 SWAPGS_UNSAFE_STACK
14426 movq PER_CPU_VAR(kernel_stack), %rsp
14427- addq $(KERNEL_STACK_OFFSET),%rsp
14428- /*
14429- * No need to follow this irqs on/off section: the syscall
14430- * disabled irqs, here we enable it straight after entry:
14431- */
14432- ENABLE_INTERRUPTS(CLBR_NONE)
14433 movl %ebp,%ebp /* zero extension */
14434 pushq_cfi $__USER32_DS
14435 /*CFI_REL_OFFSET ss,0*/
14436@@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14437 CFI_REL_OFFSET rsp,0
14438 pushfq_cfi
14439 /*CFI_REL_OFFSET rflags,0*/
14440- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14441- CFI_REGISTER rip,r10
14442+ orl $X86_EFLAGS_IF,(%rsp)
14443+ GET_THREAD_INFO(%r11)
14444+ movl TI_sysenter_return(%r11), %r11d
14445+ CFI_REGISTER rip,r11
14446 pushq_cfi $__USER32_CS
14447 /*CFI_REL_OFFSET cs,0*/
14448 movl %eax, %eax
14449- pushq_cfi %r10
14450+ pushq_cfi %r11
14451 CFI_REL_OFFSET rip,0
14452 pushq_cfi %rax
14453 cld
14454 SAVE_ARGS 0,1,0
14455+ pax_enter_kernel_user
14456+
14457+#ifdef CONFIG_PAX_RANDKSTACK
14458+ pax_erase_kstack
14459+#endif
14460+
14461+ /*
14462+ * No need to follow this irqs on/off section: the syscall
14463+ * disabled irqs, here we enable it straight after entry:
14464+ */
14465+ ENABLE_INTERRUPTS(CLBR_NONE)
14466 /* no need to do an access_ok check here because rbp has been
14467 32bit zero extended */
14468+
14469+#ifdef CONFIG_PAX_MEMORY_UDEREF
14470+ addq pax_user_shadow_base,%rbp
14471+ ASM_PAX_OPEN_USERLAND
14472+#endif
14473+
14474 ASM_STAC
14475 1: movl (%rbp),%ebp
14476 _ASM_EXTABLE(1b,ia32_badarg)
14477 ASM_CLAC
14478- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14479- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14480+
14481+#ifdef CONFIG_PAX_MEMORY_UDEREF
14482+ ASM_PAX_CLOSE_USERLAND
14483+#endif
14484+
14485+ GET_THREAD_INFO(%r11)
14486+ orl $TS_COMPAT,TI_status(%r11)
14487+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14488 CFI_REMEMBER_STATE
14489 jnz sysenter_tracesys
14490 cmpq $(IA32_NR_syscalls-1),%rax
14491@@ -162,15 +209,18 @@ sysenter_do_call:
14492 sysenter_dispatch:
14493 call *ia32_sys_call_table(,%rax,8)
14494 movq %rax,RAX-ARGOFFSET(%rsp)
14495+ GET_THREAD_INFO(%r11)
14496 DISABLE_INTERRUPTS(CLBR_NONE)
14497 TRACE_IRQS_OFF
14498- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14499+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14500 jnz sysexit_audit
14501 sysexit_from_sys_call:
14502- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14503+ pax_exit_kernel_user
14504+ pax_erase_kstack
14505+ andl $~TS_COMPAT,TI_status(%r11)
14506 /* clear IF, that popfq doesn't enable interrupts early */
14507- andl $~0x200,EFLAGS-R11(%rsp)
14508- movl RIP-R11(%rsp),%edx /* User %eip */
14509+ andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14510+ movl RIP(%rsp),%edx /* User %eip */
14511 CFI_REGISTER rip,rdx
14512 RESTORE_ARGS 0,24,0,0,0,0
14513 xorq %r8,%r8
14514@@ -193,6 +243,9 @@ sysexit_from_sys_call:
14515 movl %eax,%esi /* 2nd arg: syscall number */
14516 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14517 call __audit_syscall_entry
14518+
14519+ pax_erase_kstack
14520+
14521 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14522 cmpq $(IA32_NR_syscalls-1),%rax
14523 ja ia32_badsys
14524@@ -204,7 +257,7 @@ sysexit_from_sys_call:
14525 .endm
14526
14527 .macro auditsys_exit exit
14528- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14529+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14530 jnz ia32_ret_from_sys_call
14531 TRACE_IRQS_ON
14532 ENABLE_INTERRUPTS(CLBR_NONE)
14533@@ -215,11 +268,12 @@ sysexit_from_sys_call:
14534 1: setbe %al /* 1 if error, 0 if not */
14535 movzbl %al,%edi /* zero-extend that into %edi */
14536 call __audit_syscall_exit
14537+ GET_THREAD_INFO(%r11)
14538 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14539 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14540 DISABLE_INTERRUPTS(CLBR_NONE)
14541 TRACE_IRQS_OFF
14542- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14543+ testl %edi,TI_flags(%r11)
14544 jz \exit
14545 CLEAR_RREGS -ARGOFFSET
14546 jmp int_with_check
14547@@ -237,7 +291,7 @@ sysexit_audit:
14548
14549 sysenter_tracesys:
14550 #ifdef CONFIG_AUDITSYSCALL
14551- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14552+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14553 jz sysenter_auditsys
14554 #endif
14555 SAVE_REST
14556@@ -249,6 +303,9 @@ sysenter_tracesys:
14557 RESTORE_REST
14558 cmpq $(IA32_NR_syscalls-1),%rax
14559 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14560+
14561+ pax_erase_kstack
14562+
14563 jmp sysenter_do_call
14564 CFI_ENDPROC
14565 ENDPROC(ia32_sysenter_target)
14566@@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14567 ENTRY(ia32_cstar_target)
14568 CFI_STARTPROC32 simple
14569 CFI_SIGNAL_FRAME
14570- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14571+ CFI_DEF_CFA rsp,0
14572 CFI_REGISTER rip,rcx
14573 /*CFI_REGISTER rflags,r11*/
14574 SWAPGS_UNSAFE_STACK
14575 movl %esp,%r8d
14576 CFI_REGISTER rsp,r8
14577 movq PER_CPU_VAR(kernel_stack),%rsp
14578+ SAVE_ARGS 8*6,0,0
14579+ pax_enter_kernel_user
14580+
14581+#ifdef CONFIG_PAX_RANDKSTACK
14582+ pax_erase_kstack
14583+#endif
14584+
14585 /*
14586 * No need to follow this irqs on/off section: the syscall
14587 * disabled irqs and here we enable it straight after entry:
14588 */
14589 ENABLE_INTERRUPTS(CLBR_NONE)
14590- SAVE_ARGS 8,0,0
14591 movl %eax,%eax /* zero extension */
14592 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14593 movq %rcx,RIP-ARGOFFSET(%rsp)
14594@@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14595 /* no need to do an access_ok check here because r8 has been
14596 32bit zero extended */
14597 /* hardware stack frame is complete now */
14598+
14599+#ifdef CONFIG_PAX_MEMORY_UDEREF
14600+ ASM_PAX_OPEN_USERLAND
14601+ movq pax_user_shadow_base,%r8
14602+ addq RSP-ARGOFFSET(%rsp),%r8
14603+#endif
14604+
14605 ASM_STAC
14606 1: movl (%r8),%r9d
14607 _ASM_EXTABLE(1b,ia32_badarg)
14608 ASM_CLAC
14609- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14610- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14611+
14612+#ifdef CONFIG_PAX_MEMORY_UDEREF
14613+ ASM_PAX_CLOSE_USERLAND
14614+#endif
14615+
14616+ GET_THREAD_INFO(%r11)
14617+ orl $TS_COMPAT,TI_status(%r11)
14618+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14619 CFI_REMEMBER_STATE
14620 jnz cstar_tracesys
14621 cmpq $IA32_NR_syscalls-1,%rax
14622@@ -319,13 +395,16 @@ cstar_do_call:
14623 cstar_dispatch:
14624 call *ia32_sys_call_table(,%rax,8)
14625 movq %rax,RAX-ARGOFFSET(%rsp)
14626+ GET_THREAD_INFO(%r11)
14627 DISABLE_INTERRUPTS(CLBR_NONE)
14628 TRACE_IRQS_OFF
14629- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14630+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14631 jnz sysretl_audit
14632 sysretl_from_sys_call:
14633- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14634- RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14635+ pax_exit_kernel_user
14636+ pax_erase_kstack
14637+ andl $~TS_COMPAT,TI_status(%r11)
14638+ RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14639 movl RIP-ARGOFFSET(%rsp),%ecx
14640 CFI_REGISTER rip,rcx
14641 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14642@@ -352,7 +431,7 @@ sysretl_audit:
14643
14644 cstar_tracesys:
14645 #ifdef CONFIG_AUDITSYSCALL
14646- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14647+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14648 jz cstar_auditsys
14649 #endif
14650 xchgl %r9d,%ebp
14651@@ -366,11 +445,19 @@ cstar_tracesys:
14652 xchgl %ebp,%r9d
14653 cmpq $(IA32_NR_syscalls-1),%rax
14654 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14655+
14656+ pax_erase_kstack
14657+
14658 jmp cstar_do_call
14659 END(ia32_cstar_target)
14660
14661 ia32_badarg:
14662 ASM_CLAC
14663+
14664+#ifdef CONFIG_PAX_MEMORY_UDEREF
14665+ ASM_PAX_CLOSE_USERLAND
14666+#endif
14667+
14668 movq $-EFAULT,%rax
14669 jmp ia32_sysret
14670 CFI_ENDPROC
14671@@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14672 CFI_REL_OFFSET rip,RIP-RIP
14673 PARAVIRT_ADJUST_EXCEPTION_FRAME
14674 SWAPGS
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 movl %eax,%eax
14681 pushq_cfi %rax
14682 cld
14683 /* note the registers are not zero extended to the sf.
14684 this could be a problem. */
14685 SAVE_ARGS 0,1,0
14686- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14687- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14688+ pax_enter_kernel_user
14689+
14690+#ifdef CONFIG_PAX_RANDKSTACK
14691+ pax_erase_kstack
14692+#endif
14693+
14694+ /*
14695+ * No need to follow this irqs on/off section: the syscall
14696+ * disabled irqs and here we enable it straight after entry:
14697+ */
14698+ ENABLE_INTERRUPTS(CLBR_NONE)
14699+ GET_THREAD_INFO(%r11)
14700+ orl $TS_COMPAT,TI_status(%r11)
14701+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14702 jnz ia32_tracesys
14703 cmpq $(IA32_NR_syscalls-1),%rax
14704 ja ia32_badsys
14705@@ -442,6 +536,9 @@ ia32_tracesys:
14706 RESTORE_REST
14707 cmpq $(IA32_NR_syscalls-1),%rax
14708 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14709+
14710+ pax_erase_kstack
14711+
14712 jmp ia32_do_call
14713 END(ia32_syscall)
14714
14715diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14716index 8e0ceec..af13504 100644
14717--- a/arch/x86/ia32/sys_ia32.c
14718+++ b/arch/x86/ia32/sys_ia32.c
14719@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14720 */
14721 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14722 {
14723- typeof(ubuf->st_uid) uid = 0;
14724- typeof(ubuf->st_gid) gid = 0;
14725+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
14726+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
14727 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14728 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14729 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14730diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14731index 372231c..51b537d 100644
14732--- a/arch/x86/include/asm/alternative-asm.h
14733+++ b/arch/x86/include/asm/alternative-asm.h
14734@@ -18,6 +18,45 @@
14735 .endm
14736 #endif
14737
14738+#ifdef KERNEXEC_PLUGIN
14739+ .macro pax_force_retaddr_bts rip=0
14740+ btsq $63,\rip(%rsp)
14741+ .endm
14742+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14743+ .macro pax_force_retaddr rip=0, reload=0
14744+ btsq $63,\rip(%rsp)
14745+ .endm
14746+ .macro pax_force_fptr ptr
14747+ btsq $63,\ptr
14748+ .endm
14749+ .macro pax_set_fptr_mask
14750+ .endm
14751+#endif
14752+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14753+ .macro pax_force_retaddr rip=0, reload=0
14754+ .if \reload
14755+ pax_set_fptr_mask
14756+ .endif
14757+ orq %r12,\rip(%rsp)
14758+ .endm
14759+ .macro pax_force_fptr ptr
14760+ orq %r12,\ptr
14761+ .endm
14762+ .macro pax_set_fptr_mask
14763+ movabs $0x8000000000000000,%r12
14764+ .endm
14765+#endif
14766+#else
14767+ .macro pax_force_retaddr rip=0, reload=0
14768+ .endm
14769+ .macro pax_force_fptr ptr
14770+ .endm
14771+ .macro pax_force_retaddr_bts rip=0
14772+ .endm
14773+ .macro pax_set_fptr_mask
14774+ .endm
14775+#endif
14776+
14777 .macro altinstruction_entry orig alt feature orig_len alt_len
14778 .long \orig - .
14779 .long \alt - .
14780diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14781index 0a3f9c9..c9d081d 100644
14782--- a/arch/x86/include/asm/alternative.h
14783+++ b/arch/x86/include/asm/alternative.h
14784@@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14785 ".pushsection .discard,\"aw\",@progbits\n" \
14786 DISCARD_ENTRY(1) \
14787 ".popsection\n" \
14788- ".pushsection .altinstr_replacement, \"ax\"\n" \
14789+ ".pushsection .altinstr_replacement, \"a\"\n" \
14790 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14791 ".popsection"
14792
14793@@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14794 DISCARD_ENTRY(1) \
14795 DISCARD_ENTRY(2) \
14796 ".popsection\n" \
14797- ".pushsection .altinstr_replacement, \"ax\"\n" \
14798+ ".pushsection .altinstr_replacement, \"a\"\n" \
14799 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14800 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14801 ".popsection"
14802diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14803index 1d2091a..f5074c1 100644
14804--- a/arch/x86/include/asm/apic.h
14805+++ b/arch/x86/include/asm/apic.h
14806@@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14807
14808 #ifdef CONFIG_X86_LOCAL_APIC
14809
14810-extern unsigned int apic_verbosity;
14811+extern int apic_verbosity;
14812 extern int local_apic_timer_c2_ok;
14813
14814 extern int disable_apic;
14815diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14816index 20370c6..a2eb9b0 100644
14817--- a/arch/x86/include/asm/apm.h
14818+++ b/arch/x86/include/asm/apm.h
14819@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14820 __asm__ __volatile__(APM_DO_ZERO_SEGS
14821 "pushl %%edi\n\t"
14822 "pushl %%ebp\n\t"
14823- "lcall *%%cs:apm_bios_entry\n\t"
14824+ "lcall *%%ss:apm_bios_entry\n\t"
14825 "setc %%al\n\t"
14826 "popl %%ebp\n\t"
14827 "popl %%edi\n\t"
14828@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14829 __asm__ __volatile__(APM_DO_ZERO_SEGS
14830 "pushl %%edi\n\t"
14831 "pushl %%ebp\n\t"
14832- "lcall *%%cs:apm_bios_entry\n\t"
14833+ "lcall *%%ss:apm_bios_entry\n\t"
14834 "setc %%bl\n\t"
14835 "popl %%ebp\n\t"
14836 "popl %%edi\n\t"
14837diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14838index b17f4f4..9620151 100644
14839--- a/arch/x86/include/asm/atomic.h
14840+++ b/arch/x86/include/asm/atomic.h
14841@@ -23,7 +23,18 @@
14842 */
14843 static inline int atomic_read(const atomic_t *v)
14844 {
14845- return (*(volatile int *)&(v)->counter);
14846+ return (*(volatile const int *)&(v)->counter);
14847+}
14848+
14849+/**
14850+ * atomic_read_unchecked - read atomic variable
14851+ * @v: pointer of type atomic_unchecked_t
14852+ *
14853+ * Atomically reads the value of @v.
14854+ */
14855+static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14856+{
14857+ return (*(volatile const int *)&(v)->counter);
14858 }
14859
14860 /**
14861@@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14862 }
14863
14864 /**
14865+ * atomic_set_unchecked - set atomic variable
14866+ * @v: pointer of type atomic_unchecked_t
14867+ * @i: required value
14868+ *
14869+ * Atomically sets the value of @v to @i.
14870+ */
14871+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14872+{
14873+ v->counter = i;
14874+}
14875+
14876+/**
14877 * atomic_add - add integer to atomic variable
14878 * @i: integer value to add
14879 * @v: pointer of type atomic_t
14880@@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14881 */
14882 static inline void atomic_add(int i, atomic_t *v)
14883 {
14884- asm volatile(LOCK_PREFIX "addl %1,%0"
14885+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14886+
14887+#ifdef CONFIG_PAX_REFCOUNT
14888+ "jno 0f\n"
14889+ LOCK_PREFIX "subl %1,%0\n"
14890+ "int $4\n0:\n"
14891+ _ASM_EXTABLE(0b, 0b)
14892+#endif
14893+
14894+ : "+m" (v->counter)
14895+ : "ir" (i));
14896+}
14897+
14898+/**
14899+ * atomic_add_unchecked - add integer to atomic variable
14900+ * @i: integer value to add
14901+ * @v: pointer of type atomic_unchecked_t
14902+ *
14903+ * Atomically adds @i to @v.
14904+ */
14905+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14906+{
14907+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
14908 : "+m" (v->counter)
14909 : "ir" (i));
14910 }
14911@@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14912 */
14913 static inline void atomic_sub(int i, atomic_t *v)
14914 {
14915- asm volatile(LOCK_PREFIX "subl %1,%0"
14916+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14917+
14918+#ifdef CONFIG_PAX_REFCOUNT
14919+ "jno 0f\n"
14920+ LOCK_PREFIX "addl %1,%0\n"
14921+ "int $4\n0:\n"
14922+ _ASM_EXTABLE(0b, 0b)
14923+#endif
14924+
14925+ : "+m" (v->counter)
14926+ : "ir" (i));
14927+}
14928+
14929+/**
14930+ * atomic_sub_unchecked - subtract integer from atomic variable
14931+ * @i: integer value to subtract
14932+ * @v: pointer of type atomic_unchecked_t
14933+ *
14934+ * Atomically subtracts @i from @v.
14935+ */
14936+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14937+{
14938+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
14939 : "+m" (v->counter)
14940 : "ir" (i));
14941 }
14942@@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14943 */
14944 static inline int atomic_sub_and_test(int i, atomic_t *v)
14945 {
14946- GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14947+ GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14948 }
14949
14950 /**
14951@@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14952 */
14953 static inline void atomic_inc(atomic_t *v)
14954 {
14955- asm volatile(LOCK_PREFIX "incl %0"
14956+ asm volatile(LOCK_PREFIX "incl %0\n"
14957+
14958+#ifdef CONFIG_PAX_REFCOUNT
14959+ "jno 0f\n"
14960+ LOCK_PREFIX "decl %0\n"
14961+ "int $4\n0:\n"
14962+ _ASM_EXTABLE(0b, 0b)
14963+#endif
14964+
14965+ : "+m" (v->counter));
14966+}
14967+
14968+/**
14969+ * atomic_inc_unchecked - increment atomic variable
14970+ * @v: pointer of type atomic_unchecked_t
14971+ *
14972+ * Atomically increments @v by 1.
14973+ */
14974+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14975+{
14976+ asm volatile(LOCK_PREFIX "incl %0\n"
14977 : "+m" (v->counter));
14978 }
14979
14980@@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14981 */
14982 static inline void atomic_dec(atomic_t *v)
14983 {
14984- asm volatile(LOCK_PREFIX "decl %0"
14985+ asm volatile(LOCK_PREFIX "decl %0\n"
14986+
14987+#ifdef CONFIG_PAX_REFCOUNT
14988+ "jno 0f\n"
14989+ LOCK_PREFIX "incl %0\n"
14990+ "int $4\n0:\n"
14991+ _ASM_EXTABLE(0b, 0b)
14992+#endif
14993+
14994+ : "+m" (v->counter));
14995+}
14996+
14997+/**
14998+ * atomic_dec_unchecked - decrement atomic variable
14999+ * @v: pointer of type atomic_unchecked_t
15000+ *
15001+ * Atomically decrements @v by 1.
15002+ */
15003+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15004+{
15005+ asm volatile(LOCK_PREFIX "decl %0\n"
15006 : "+m" (v->counter));
15007 }
15008
15009@@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15010 */
15011 static inline int atomic_dec_and_test(atomic_t *v)
15012 {
15013- GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15014+ GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15015 }
15016
15017 /**
15018@@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15019 */
15020 static inline int atomic_inc_and_test(atomic_t *v)
15021 {
15022- GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15023+ GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15024+}
15025+
15026+/**
15027+ * atomic_inc_and_test_unchecked - increment and test
15028+ * @v: pointer of type atomic_unchecked_t
15029+ *
15030+ * Atomically increments @v by 1
15031+ * and returns true if the result is zero, or false for all
15032+ * other cases.
15033+ */
15034+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15035+{
15036+ GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15037 }
15038
15039 /**
15040@@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15041 */
15042 static inline int atomic_add_negative(int i, atomic_t *v)
15043 {
15044- GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15045+ GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15046 }
15047
15048 /**
15049@@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15050 */
15051 static inline int atomic_add_return(int i, atomic_t *v)
15052 {
15053+ return i + xadd_check_overflow(&v->counter, i);
15054+}
15055+
15056+/**
15057+ * atomic_add_return_unchecked - add integer and return
15058+ * @i: integer value to add
15059+ * @v: pointer of type atomic_unchecked_t
15060+ *
15061+ * Atomically adds @i to @v and returns @i + @v
15062+ */
15063+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15064+{
15065 return i + xadd(&v->counter, i);
15066 }
15067
15068@@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15069 }
15070
15071 #define atomic_inc_return(v) (atomic_add_return(1, v))
15072+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15073+{
15074+ return atomic_add_return_unchecked(1, v);
15075+}
15076 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15077
15078-static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15079+static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15080+{
15081+ return cmpxchg(&v->counter, old, new);
15082+}
15083+
15084+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15085 {
15086 return cmpxchg(&v->counter, old, new);
15087 }
15088@@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15089 return xchg(&v->counter, new);
15090 }
15091
15092+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15093+{
15094+ return xchg(&v->counter, new);
15095+}
15096+
15097 /**
15098 * __atomic_add_unless - add unless the number is already a given value
15099 * @v: pointer of type atomic_t
15100@@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15101 * Atomically adds @a to @v, so long as @v was not already @u.
15102 * Returns the old value of @v.
15103 */
15104-static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15105+static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15106 {
15107- int c, old;
15108+ int c, old, new;
15109 c = atomic_read(v);
15110 for (;;) {
15111- if (unlikely(c == (u)))
15112+ if (unlikely(c == u))
15113 break;
15114- old = atomic_cmpxchg((v), c, c + (a));
15115+
15116+ asm volatile("addl %2,%0\n"
15117+
15118+#ifdef CONFIG_PAX_REFCOUNT
15119+ "jno 0f\n"
15120+ "subl %2,%0\n"
15121+ "int $4\n0:\n"
15122+ _ASM_EXTABLE(0b, 0b)
15123+#endif
15124+
15125+ : "=r" (new)
15126+ : "0" (c), "ir" (a));
15127+
15128+ old = atomic_cmpxchg(v, c, new);
15129 if (likely(old == c))
15130 break;
15131 c = old;
15132@@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15133 }
15134
15135 /**
15136+ * atomic_inc_not_zero_hint - increment if not null
15137+ * @v: pointer of type atomic_t
15138+ * @hint: probable value of the atomic before the increment
15139+ *
15140+ * This version of atomic_inc_not_zero() gives a hint of probable
15141+ * value of the atomic. This helps processor to not read the memory
15142+ * before doing the atomic read/modify/write cycle, lowering
15143+ * number of bus transactions on some arches.
15144+ *
15145+ * Returns: 0 if increment was not done, 1 otherwise.
15146+ */
15147+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15148+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15149+{
15150+ int val, c = hint, new;
15151+
15152+ /* sanity test, should be removed by compiler if hint is a constant */
15153+ if (!hint)
15154+ return __atomic_add_unless(v, 1, 0);
15155+
15156+ do {
15157+ asm volatile("incl %0\n"
15158+
15159+#ifdef CONFIG_PAX_REFCOUNT
15160+ "jno 0f\n"
15161+ "decl %0\n"
15162+ "int $4\n0:\n"
15163+ _ASM_EXTABLE(0b, 0b)
15164+#endif
15165+
15166+ : "=r" (new)
15167+ : "0" (c));
15168+
15169+ val = atomic_cmpxchg(v, c, new);
15170+ if (val == c)
15171+ return 1;
15172+ c = val;
15173+ } while (c);
15174+
15175+ return 0;
15176+}
15177+
15178+/**
15179 * atomic_inc_short - increment of a short integer
15180 * @v: pointer to type int
15181 *
15182@@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15183 #endif
15184
15185 /* These are x86-specific, used by some header files */
15186-#define atomic_clear_mask(mask, addr) \
15187- asm volatile(LOCK_PREFIX "andl %0,%1" \
15188- : : "r" (~(mask)), "m" (*(addr)) : "memory")
15189+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15190+{
15191+ asm volatile(LOCK_PREFIX "andl %1,%0"
15192+ : "+m" (v->counter)
15193+ : "r" (~(mask))
15194+ : "memory");
15195+}
15196
15197-#define atomic_set_mask(mask, addr) \
15198- asm volatile(LOCK_PREFIX "orl %0,%1" \
15199- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15200- : "memory")
15201+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15202+{
15203+ asm volatile(LOCK_PREFIX "andl %1,%0"
15204+ : "+m" (v->counter)
15205+ : "r" (~(mask))
15206+ : "memory");
15207+}
15208+
15209+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15210+{
15211+ asm volatile(LOCK_PREFIX "orl %1,%0"
15212+ : "+m" (v->counter)
15213+ : "r" (mask)
15214+ : "memory");
15215+}
15216+
15217+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15218+{
15219+ asm volatile(LOCK_PREFIX "orl %1,%0"
15220+ : "+m" (v->counter)
15221+ : "r" (mask)
15222+ : "memory");
15223+}
15224
15225 /* Atomic operations are already serializing on x86 */
15226 #define smp_mb__before_atomic_dec() barrier()
15227diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15228index b154de7..bf18a5a 100644
15229--- a/arch/x86/include/asm/atomic64_32.h
15230+++ b/arch/x86/include/asm/atomic64_32.h
15231@@ -12,6 +12,14 @@ typedef struct {
15232 u64 __aligned(8) counter;
15233 } atomic64_t;
15234
15235+#ifdef CONFIG_PAX_REFCOUNT
15236+typedef struct {
15237+ u64 __aligned(8) counter;
15238+} atomic64_unchecked_t;
15239+#else
15240+typedef atomic64_t atomic64_unchecked_t;
15241+#endif
15242+
15243 #define ATOMIC64_INIT(val) { (val) }
15244
15245 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15246@@ -37,21 +45,31 @@ typedef struct {
15247 ATOMIC64_DECL_ONE(sym##_386)
15248
15249 ATOMIC64_DECL_ONE(add_386);
15250+ATOMIC64_DECL_ONE(add_unchecked_386);
15251 ATOMIC64_DECL_ONE(sub_386);
15252+ATOMIC64_DECL_ONE(sub_unchecked_386);
15253 ATOMIC64_DECL_ONE(inc_386);
15254+ATOMIC64_DECL_ONE(inc_unchecked_386);
15255 ATOMIC64_DECL_ONE(dec_386);
15256+ATOMIC64_DECL_ONE(dec_unchecked_386);
15257 #endif
15258
15259 #define alternative_atomic64(f, out, in...) \
15260 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15261
15262 ATOMIC64_DECL(read);
15263+ATOMIC64_DECL(read_unchecked);
15264 ATOMIC64_DECL(set);
15265+ATOMIC64_DECL(set_unchecked);
15266 ATOMIC64_DECL(xchg);
15267 ATOMIC64_DECL(add_return);
15268+ATOMIC64_DECL(add_return_unchecked);
15269 ATOMIC64_DECL(sub_return);
15270+ATOMIC64_DECL(sub_return_unchecked);
15271 ATOMIC64_DECL(inc_return);
15272+ATOMIC64_DECL(inc_return_unchecked);
15273 ATOMIC64_DECL(dec_return);
15274+ATOMIC64_DECL(dec_return_unchecked);
15275 ATOMIC64_DECL(dec_if_positive);
15276 ATOMIC64_DECL(inc_not_zero);
15277 ATOMIC64_DECL(add_unless);
15278@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15279 }
15280
15281 /**
15282+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15283+ * @p: pointer to type atomic64_unchecked_t
15284+ * @o: expected value
15285+ * @n: new value
15286+ *
15287+ * Atomically sets @v to @n if it was equal to @o and returns
15288+ * the old value.
15289+ */
15290+
15291+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15292+{
15293+ return cmpxchg64(&v->counter, o, n);
15294+}
15295+
15296+/**
15297 * atomic64_xchg - xchg atomic64 variable
15298 * @v: pointer to type atomic64_t
15299 * @n: value to assign
15300@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15301 }
15302
15303 /**
15304+ * atomic64_set_unchecked - set atomic64 variable
15305+ * @v: pointer to type atomic64_unchecked_t
15306+ * @n: value to assign
15307+ *
15308+ * Atomically sets the value of @v to @n.
15309+ */
15310+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15311+{
15312+ unsigned high = (unsigned)(i >> 32);
15313+ unsigned low = (unsigned)i;
15314+ alternative_atomic64(set, /* no output */,
15315+ "S" (v), "b" (low), "c" (high)
15316+ : "eax", "edx", "memory");
15317+}
15318+
15319+/**
15320 * atomic64_read - read atomic64 variable
15321 * @v: pointer to type atomic64_t
15322 *
15323@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15324 }
15325
15326 /**
15327+ * atomic64_read_unchecked - read atomic64 variable
15328+ * @v: pointer to type atomic64_unchecked_t
15329+ *
15330+ * Atomically reads the value of @v and returns it.
15331+ */
15332+static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15333+{
15334+ long long r;
15335+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15336+ return r;
15337+ }
15338+
15339+/**
15340 * atomic64_add_return - add and return
15341 * @i: integer value to add
15342 * @v: pointer to type atomic64_t
15343@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15344 return i;
15345 }
15346
15347+/**
15348+ * atomic64_add_return_unchecked - add and return
15349+ * @i: integer value to add
15350+ * @v: pointer to type atomic64_unchecked_t
15351+ *
15352+ * Atomically adds @i to @v and returns @i + *@v
15353+ */
15354+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15355+{
15356+ alternative_atomic64(add_return_unchecked,
15357+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15358+ ASM_NO_INPUT_CLOBBER("memory"));
15359+ return i;
15360+}
15361+
15362 /*
15363 * Other variants with different arithmetic operators:
15364 */
15365@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15366 return a;
15367 }
15368
15369+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15370+{
15371+ long long a;
15372+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
15373+ "S" (v) : "memory", "ecx");
15374+ return a;
15375+}
15376+
15377 static inline long long atomic64_dec_return(atomic64_t *v)
15378 {
15379 long long a;
15380@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15381 }
15382
15383 /**
15384+ * atomic64_add_unchecked - add integer to atomic64 variable
15385+ * @i: integer value to add
15386+ * @v: pointer to type atomic64_unchecked_t
15387+ *
15388+ * Atomically adds @i to @v.
15389+ */
15390+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15391+{
15392+ __alternative_atomic64(add_unchecked, add_return_unchecked,
15393+ ASM_OUTPUT2("+A" (i), "+c" (v)),
15394+ ASM_NO_INPUT_CLOBBER("memory"));
15395+ return i;
15396+}
15397+
15398+/**
15399 * atomic64_sub - subtract the atomic64 variable
15400 * @i: integer value to subtract
15401 * @v: pointer to type atomic64_t
15402diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15403index 46e9052..ae45136 100644
15404--- a/arch/x86/include/asm/atomic64_64.h
15405+++ b/arch/x86/include/asm/atomic64_64.h
15406@@ -18,7 +18,19 @@
15407 */
15408 static inline long atomic64_read(const atomic64_t *v)
15409 {
15410- return (*(volatile long *)&(v)->counter);
15411+ return (*(volatile const long *)&(v)->counter);
15412+}
15413+
15414+/**
15415+ * atomic64_read_unchecked - read atomic64 variable
15416+ * @v: pointer of type atomic64_unchecked_t
15417+ *
15418+ * Atomically reads the value of @v.
15419+ * Doesn't imply a read memory barrier.
15420+ */
15421+static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15422+{
15423+ return (*(volatile const long *)&(v)->counter);
15424 }
15425
15426 /**
15427@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15428 }
15429
15430 /**
15431+ * atomic64_set_unchecked - set atomic64 variable
15432+ * @v: pointer to type atomic64_unchecked_t
15433+ * @i: required value
15434+ *
15435+ * Atomically sets the value of @v to @i.
15436+ */
15437+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15438+{
15439+ v->counter = i;
15440+}
15441+
15442+/**
15443 * atomic64_add - add integer to atomic64 variable
15444 * @i: integer value to add
15445 * @v: pointer to type atomic64_t
15446@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15447 */
15448 static inline void atomic64_add(long i, atomic64_t *v)
15449 {
15450+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
15451+
15452+#ifdef CONFIG_PAX_REFCOUNT
15453+ "jno 0f\n"
15454+ LOCK_PREFIX "subq %1,%0\n"
15455+ "int $4\n0:\n"
15456+ _ASM_EXTABLE(0b, 0b)
15457+#endif
15458+
15459+ : "=m" (v->counter)
15460+ : "er" (i), "m" (v->counter));
15461+}
15462+
15463+/**
15464+ * atomic64_add_unchecked - add integer to atomic64 variable
15465+ * @i: integer value to add
15466+ * @v: pointer to type atomic64_unchecked_t
15467+ *
15468+ * Atomically adds @i to @v.
15469+ */
15470+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15471+{
15472 asm volatile(LOCK_PREFIX "addq %1,%0"
15473 : "=m" (v->counter)
15474 : "er" (i), "m" (v->counter));
15475@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15476 */
15477 static inline void atomic64_sub(long i, atomic64_t *v)
15478 {
15479- asm volatile(LOCK_PREFIX "subq %1,%0"
15480+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15481+
15482+#ifdef CONFIG_PAX_REFCOUNT
15483+ "jno 0f\n"
15484+ LOCK_PREFIX "addq %1,%0\n"
15485+ "int $4\n0:\n"
15486+ _ASM_EXTABLE(0b, 0b)
15487+#endif
15488+
15489+ : "=m" (v->counter)
15490+ : "er" (i), "m" (v->counter));
15491+}
15492+
15493+/**
15494+ * atomic64_sub_unchecked - subtract the atomic64 variable
15495+ * @i: integer value to subtract
15496+ * @v: pointer to type atomic64_unchecked_t
15497+ *
15498+ * Atomically subtracts @i from @v.
15499+ */
15500+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15501+{
15502+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
15503 : "=m" (v->counter)
15504 : "er" (i), "m" (v->counter));
15505 }
15506@@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15507 */
15508 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15509 {
15510- GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15511+ GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15512 }
15513
15514 /**
15515@@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15516 */
15517 static inline void atomic64_inc(atomic64_t *v)
15518 {
15519+ asm volatile(LOCK_PREFIX "incq %0\n"
15520+
15521+#ifdef CONFIG_PAX_REFCOUNT
15522+ "jno 0f\n"
15523+ LOCK_PREFIX "decq %0\n"
15524+ "int $4\n0:\n"
15525+ _ASM_EXTABLE(0b, 0b)
15526+#endif
15527+
15528+ : "=m" (v->counter)
15529+ : "m" (v->counter));
15530+}
15531+
15532+/**
15533+ * atomic64_inc_unchecked - increment atomic64 variable
15534+ * @v: pointer to type atomic64_unchecked_t
15535+ *
15536+ * Atomically increments @v by 1.
15537+ */
15538+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15539+{
15540 asm volatile(LOCK_PREFIX "incq %0"
15541 : "=m" (v->counter)
15542 : "m" (v->counter));
15543@@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15544 */
15545 static inline void atomic64_dec(atomic64_t *v)
15546 {
15547- asm volatile(LOCK_PREFIX "decq %0"
15548+ asm volatile(LOCK_PREFIX "decq %0\n"
15549+
15550+#ifdef CONFIG_PAX_REFCOUNT
15551+ "jno 0f\n"
15552+ LOCK_PREFIX "incq %0\n"
15553+ "int $4\n0:\n"
15554+ _ASM_EXTABLE(0b, 0b)
15555+#endif
15556+
15557+ : "=m" (v->counter)
15558+ : "m" (v->counter));
15559+}
15560+
15561+/**
15562+ * atomic64_dec_unchecked - decrement atomic64 variable
15563+ * @v: pointer to type atomic64_t
15564+ *
15565+ * Atomically decrements @v by 1.
15566+ */
15567+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15568+{
15569+ asm volatile(LOCK_PREFIX "decq %0\n"
15570 : "=m" (v->counter)
15571 : "m" (v->counter));
15572 }
15573@@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15574 */
15575 static inline int atomic64_dec_and_test(atomic64_t *v)
15576 {
15577- GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15578+ GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15579 }
15580
15581 /**
15582@@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15583 */
15584 static inline int atomic64_inc_and_test(atomic64_t *v)
15585 {
15586- GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15587+ GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15588 }
15589
15590 /**
15591@@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15592 */
15593 static inline int atomic64_add_negative(long i, atomic64_t *v)
15594 {
15595- GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15596+ GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15597 }
15598
15599 /**
15600@@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15601 */
15602 static inline long atomic64_add_return(long i, atomic64_t *v)
15603 {
15604+ return i + xadd_check_overflow(&v->counter, i);
15605+}
15606+
15607+/**
15608+ * atomic64_add_return_unchecked - add and return
15609+ * @i: integer value to add
15610+ * @v: pointer to type atomic64_unchecked_t
15611+ *
15612+ * Atomically adds @i to @v and returns @i + @v
15613+ */
15614+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15615+{
15616 return i + xadd(&v->counter, i);
15617 }
15618
15619@@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15620 }
15621
15622 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15623+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15624+{
15625+ return atomic64_add_return_unchecked(1, v);
15626+}
15627 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15628
15629 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15630@@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15631 return cmpxchg(&v->counter, old, new);
15632 }
15633
15634+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15635+{
15636+ return cmpxchg(&v->counter, old, new);
15637+}
15638+
15639 static inline long atomic64_xchg(atomic64_t *v, long new)
15640 {
15641 return xchg(&v->counter, new);
15642@@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15643 */
15644 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15645 {
15646- long c, old;
15647+ long c, old, new;
15648 c = atomic64_read(v);
15649 for (;;) {
15650- if (unlikely(c == (u)))
15651+ if (unlikely(c == u))
15652 break;
15653- old = atomic64_cmpxchg((v), c, c + (a));
15654+
15655+ asm volatile("add %2,%0\n"
15656+
15657+#ifdef CONFIG_PAX_REFCOUNT
15658+ "jno 0f\n"
15659+ "sub %2,%0\n"
15660+ "int $4\n0:\n"
15661+ _ASM_EXTABLE(0b, 0b)
15662+#endif
15663+
15664+ : "=r" (new)
15665+ : "0" (c), "ir" (a));
15666+
15667+ old = atomic64_cmpxchg(v, c, new);
15668 if (likely(old == c))
15669 break;
15670 c = old;
15671 }
15672- return c != (u);
15673+ return c != u;
15674 }
15675
15676 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15677diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15678index 9fc1af7..fc71228 100644
15679--- a/arch/x86/include/asm/bitops.h
15680+++ b/arch/x86/include/asm/bitops.h
15681@@ -49,7 +49,7 @@
15682 * a mask operation on a byte.
15683 */
15684 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15685-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15686+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15687 #define CONST_MASK(nr) (1 << ((nr) & 7))
15688
15689 /**
15690@@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15691 */
15692 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15693 {
15694- GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15695+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15696 }
15697
15698 /**
15699@@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15700 */
15701 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15702 {
15703- GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15704+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15705 }
15706
15707 /**
15708@@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15709 */
15710 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15711 {
15712- GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15713+ GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15714 }
15715
15716 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15717@@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15718 *
15719 * Undefined if no bit exists, so code should check against 0 first.
15720 */
15721-static inline unsigned long __ffs(unsigned long word)
15722+static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15723 {
15724 asm("rep; bsf %1,%0"
15725 : "=r" (word)
15726@@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15727 *
15728 * Undefined if no zero exists, so code should check against ~0UL first.
15729 */
15730-static inline unsigned long ffz(unsigned long word)
15731+static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15732 {
15733 asm("rep; bsf %1,%0"
15734 : "=r" (word)
15735@@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15736 *
15737 * Undefined if no set bit exists, so code should check against 0 first.
15738 */
15739-static inline unsigned long __fls(unsigned long word)
15740+static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15741 {
15742 asm("bsr %1,%0"
15743 : "=r" (word)
15744@@ -436,7 +436,7 @@ static inline int ffs(int x)
15745 * set bit if value is nonzero. The last (most significant) bit is
15746 * at position 32.
15747 */
15748-static inline int fls(int x)
15749+static inline int __intentional_overflow(-1) fls(int x)
15750 {
15751 int r;
15752
15753@@ -478,7 +478,7 @@ static inline int fls(int x)
15754 * at position 64.
15755 */
15756 #ifdef CONFIG_X86_64
15757-static __always_inline int fls64(__u64 x)
15758+static __always_inline long fls64(__u64 x)
15759 {
15760 int bitpos = -1;
15761 /*
15762diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15763index 4fa687a..60f2d39 100644
15764--- a/arch/x86/include/asm/boot.h
15765+++ b/arch/x86/include/asm/boot.h
15766@@ -6,10 +6,15 @@
15767 #include <uapi/asm/boot.h>
15768
15769 /* Physical address where kernel should be loaded. */
15770-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15771+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15772 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15773 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15774
15775+#ifndef __ASSEMBLY__
15776+extern unsigned char __LOAD_PHYSICAL_ADDR[];
15777+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15778+#endif
15779+
15780 /* Minimum kernel alignment, as a power of two */
15781 #ifdef CONFIG_X86_64
15782 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15783diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15784index 48f99f1..d78ebf9 100644
15785--- a/arch/x86/include/asm/cache.h
15786+++ b/arch/x86/include/asm/cache.h
15787@@ -5,12 +5,13 @@
15788
15789 /* L1 cache line size */
15790 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15791-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15792+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15793
15794 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15795+#define __read_only __attribute__((__section__(".data..read_only")))
15796
15797 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15798-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15799+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15800
15801 #ifdef CONFIG_X86_VSMP
15802 #ifdef CONFIG_SMP
15803diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15804index 9863ee3..4a1f8e1 100644
15805--- a/arch/x86/include/asm/cacheflush.h
15806+++ b/arch/x86/include/asm/cacheflush.h
15807@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15808 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15809
15810 if (pg_flags == _PGMT_DEFAULT)
15811- return -1;
15812+ return ~0UL;
15813 else if (pg_flags == _PGMT_WC)
15814 return _PAGE_CACHE_WC;
15815 else if (pg_flags == _PGMT_UC_MINUS)
15816diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15817index cb4c73b..c473c29 100644
15818--- a/arch/x86/include/asm/calling.h
15819+++ b/arch/x86/include/asm/calling.h
15820@@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15821 #define RSP 152
15822 #define SS 160
15823
15824-#define ARGOFFSET R11
15825-#define SWFRAME ORIG_RAX
15826+#define ARGOFFSET R15
15827
15828 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15829- subq $9*8+\addskip, %rsp
15830- CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15831- movq_cfi rdi, 8*8
15832- movq_cfi rsi, 7*8
15833- movq_cfi rdx, 6*8
15834+ subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15835+ CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15836+ movq_cfi rdi, RDI
15837+ movq_cfi rsi, RSI
15838+ movq_cfi rdx, RDX
15839
15840 .if \save_rcx
15841- movq_cfi rcx, 5*8
15842+ movq_cfi rcx, RCX
15843 .endif
15844
15845- movq_cfi rax, 4*8
15846+ movq_cfi rax, RAX
15847
15848 .if \save_r891011
15849- movq_cfi r8, 3*8
15850- movq_cfi r9, 2*8
15851- movq_cfi r10, 1*8
15852- movq_cfi r11, 0*8
15853+ movq_cfi r8, R8
15854+ movq_cfi r9, R9
15855+ movq_cfi r10, R10
15856+ movq_cfi r11, R11
15857 .endif
15858
15859+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15860+ movq_cfi r12, R12
15861+#endif
15862+
15863 .endm
15864
15865-#define ARG_SKIP (9*8)
15866+#define ARG_SKIP ORIG_RAX
15867
15868 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15869 rstor_r8910=1, rstor_rdx=1
15870+
15871+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15872+ movq_cfi_restore R12, r12
15873+#endif
15874+
15875 .if \rstor_r11
15876- movq_cfi_restore 0*8, r11
15877+ movq_cfi_restore R11, r11
15878 .endif
15879
15880 .if \rstor_r8910
15881- movq_cfi_restore 1*8, r10
15882- movq_cfi_restore 2*8, r9
15883- movq_cfi_restore 3*8, r8
15884+ movq_cfi_restore R10, r10
15885+ movq_cfi_restore R9, r9
15886+ movq_cfi_restore R8, r8
15887 .endif
15888
15889 .if \rstor_rax
15890- movq_cfi_restore 4*8, rax
15891+ movq_cfi_restore RAX, rax
15892 .endif
15893
15894 .if \rstor_rcx
15895- movq_cfi_restore 5*8, rcx
15896+ movq_cfi_restore RCX, rcx
15897 .endif
15898
15899 .if \rstor_rdx
15900- movq_cfi_restore 6*8, rdx
15901+ movq_cfi_restore RDX, rdx
15902 .endif
15903
15904- movq_cfi_restore 7*8, rsi
15905- movq_cfi_restore 8*8, rdi
15906+ movq_cfi_restore RSI, rsi
15907+ movq_cfi_restore RDI, rdi
15908
15909- .if ARG_SKIP+\addskip > 0
15910- addq $ARG_SKIP+\addskip, %rsp
15911- CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15912+ .if ORIG_RAX+\addskip > 0
15913+ addq $ORIG_RAX+\addskip, %rsp
15914+ CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15915 .endif
15916 .endm
15917
15918- .macro LOAD_ARGS offset, skiprax=0
15919- movq \offset(%rsp), %r11
15920- movq \offset+8(%rsp), %r10
15921- movq \offset+16(%rsp), %r9
15922- movq \offset+24(%rsp), %r8
15923- movq \offset+40(%rsp), %rcx
15924- movq \offset+48(%rsp), %rdx
15925- movq \offset+56(%rsp), %rsi
15926- movq \offset+64(%rsp), %rdi
15927+ .macro LOAD_ARGS skiprax=0
15928+ movq R11(%rsp), %r11
15929+ movq R10(%rsp), %r10
15930+ movq R9(%rsp), %r9
15931+ movq R8(%rsp), %r8
15932+ movq RCX(%rsp), %rcx
15933+ movq RDX(%rsp), %rdx
15934+ movq RSI(%rsp), %rsi
15935+ movq RDI(%rsp), %rdi
15936 .if \skiprax
15937 .else
15938- movq \offset+72(%rsp), %rax
15939+ movq RAX(%rsp), %rax
15940 .endif
15941 .endm
15942
15943-#define REST_SKIP (6*8)
15944-
15945 .macro SAVE_REST
15946- subq $REST_SKIP, %rsp
15947- CFI_ADJUST_CFA_OFFSET REST_SKIP
15948- movq_cfi rbx, 5*8
15949- movq_cfi rbp, 4*8
15950- movq_cfi r12, 3*8
15951- movq_cfi r13, 2*8
15952- movq_cfi r14, 1*8
15953- movq_cfi r15, 0*8
15954+ movq_cfi rbx, RBX
15955+ movq_cfi rbp, RBP
15956+
15957+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15958+ movq_cfi r12, R12
15959+#endif
15960+
15961+ movq_cfi r13, R13
15962+ movq_cfi r14, R14
15963+ movq_cfi r15, R15
15964 .endm
15965
15966 .macro RESTORE_REST
15967- movq_cfi_restore 0*8, r15
15968- movq_cfi_restore 1*8, r14
15969- movq_cfi_restore 2*8, r13
15970- movq_cfi_restore 3*8, r12
15971- movq_cfi_restore 4*8, rbp
15972- movq_cfi_restore 5*8, rbx
15973- addq $REST_SKIP, %rsp
15974- CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15975+ movq_cfi_restore R15, r15
15976+ movq_cfi_restore R14, r14
15977+ movq_cfi_restore R13, r13
15978+
15979+#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15980+ movq_cfi_restore R12, r12
15981+#endif
15982+
15983+ movq_cfi_restore RBP, rbp
15984+ movq_cfi_restore RBX, rbx
15985 .endm
15986
15987 .macro SAVE_ALL
15988diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15989index f50de69..2b0a458 100644
15990--- a/arch/x86/include/asm/checksum_32.h
15991+++ b/arch/x86/include/asm/checksum_32.h
15992@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15993 int len, __wsum sum,
15994 int *src_err_ptr, int *dst_err_ptr);
15995
15996+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15997+ int len, __wsum sum,
15998+ int *src_err_ptr, int *dst_err_ptr);
15999+
16000+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16001+ int len, __wsum sum,
16002+ int *src_err_ptr, int *dst_err_ptr);
16003+
16004 /*
16005 * Note: when you get a NULL pointer exception here this means someone
16006 * passed in an incorrect kernel address to one of these functions.
16007@@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16008
16009 might_sleep();
16010 stac();
16011- ret = csum_partial_copy_generic((__force void *)src, dst,
16012+ ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16013 len, sum, err_ptr, NULL);
16014 clac();
16015
16016@@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16017 might_sleep();
16018 if (access_ok(VERIFY_WRITE, dst, len)) {
16019 stac();
16020- ret = csum_partial_copy_generic(src, (__force void *)dst,
16021+ ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16022 len, sum, NULL, err_ptr);
16023 clac();
16024 return ret;
16025diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16026index d47786a..ce1b05d 100644
16027--- a/arch/x86/include/asm/cmpxchg.h
16028+++ b/arch/x86/include/asm/cmpxchg.h
16029@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16030 __compiletime_error("Bad argument size for cmpxchg");
16031 extern void __xadd_wrong_size(void)
16032 __compiletime_error("Bad argument size for xadd");
16033+extern void __xadd_check_overflow_wrong_size(void)
16034+ __compiletime_error("Bad argument size for xadd_check_overflow");
16035 extern void __add_wrong_size(void)
16036 __compiletime_error("Bad argument size for add");
16037+extern void __add_check_overflow_wrong_size(void)
16038+ __compiletime_error("Bad argument size for add_check_overflow");
16039
16040 /*
16041 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16042@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
16043 __ret; \
16044 })
16045
16046+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16047+ ({ \
16048+ __typeof__ (*(ptr)) __ret = (arg); \
16049+ switch (sizeof(*(ptr))) { \
16050+ case __X86_CASE_L: \
16051+ asm volatile (lock #op "l %0, %1\n" \
16052+ "jno 0f\n" \
16053+ "mov %0,%1\n" \
16054+ "int $4\n0:\n" \
16055+ _ASM_EXTABLE(0b, 0b) \
16056+ : "+r" (__ret), "+m" (*(ptr)) \
16057+ : : "memory", "cc"); \
16058+ break; \
16059+ case __X86_CASE_Q: \
16060+ asm volatile (lock #op "q %q0, %1\n" \
16061+ "jno 0f\n" \
16062+ "mov %0,%1\n" \
16063+ "int $4\n0:\n" \
16064+ _ASM_EXTABLE(0b, 0b) \
16065+ : "+r" (__ret), "+m" (*(ptr)) \
16066+ : : "memory", "cc"); \
16067+ break; \
16068+ default: \
16069+ __ ## op ## _check_overflow_wrong_size(); \
16070+ } \
16071+ __ret; \
16072+ })
16073+
16074 /*
16075 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16076 * Since this is generally used to protect other memory information, we
16077@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
16078 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16079 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16080
16081+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16082+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16083+
16084 #define __add(ptr, inc, lock) \
16085 ({ \
16086 __typeof__ (*(ptr)) __ret = (inc); \
16087diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16088index 59c6c40..5e0b22c 100644
16089--- a/arch/x86/include/asm/compat.h
16090+++ b/arch/x86/include/asm/compat.h
16091@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16092 typedef u32 compat_uint_t;
16093 typedef u32 compat_ulong_t;
16094 typedef u64 __attribute__((aligned(4))) compat_u64;
16095-typedef u32 compat_uptr_t;
16096+typedef u32 __user compat_uptr_t;
16097
16098 struct compat_timespec {
16099 compat_time_t tv_sec;
16100diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16101index 89270b4..f0abf8e 100644
16102--- a/arch/x86/include/asm/cpufeature.h
16103+++ b/arch/x86/include/asm/cpufeature.h
16104@@ -203,7 +203,7 @@
16105 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16106 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16107 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16108-
16109+#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16110
16111 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16112 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16113@@ -211,7 +211,7 @@
16114 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16115 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16116 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16117-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16118+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16119 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16120 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16121 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16122@@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
16123 #undef cpu_has_centaur_mcr
16124 #define cpu_has_centaur_mcr 0
16125
16126+#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16127 #endif /* CONFIG_X86_64 */
16128
16129 #if __GNUC__ >= 4
16130@@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16131
16132 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16133 t_warn:
16134- warn_pre_alternatives();
16135+ if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16136+ warn_pre_alternatives();
16137 return false;
16138 #endif
16139
16140@@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16141 ".section .discard,\"aw\",@progbits\n"
16142 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16143 ".previous\n"
16144- ".section .altinstr_replacement,\"ax\"\n"
16145+ ".section .altinstr_replacement,\"a\"\n"
16146 "3: movb $1,%0\n"
16147 "4:\n"
16148 ".previous\n"
16149@@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16150 " .byte 2b - 1b\n" /* src len */
16151 " .byte 4f - 3f\n" /* repl len */
16152 ".previous\n"
16153- ".section .altinstr_replacement,\"ax\"\n"
16154+ ".section .altinstr_replacement,\"a\"\n"
16155 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16156 "4:\n"
16157 ".previous\n"
16158@@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16159 ".section .discard,\"aw\",@progbits\n"
16160 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16161 ".previous\n"
16162- ".section .altinstr_replacement,\"ax\"\n"
16163+ ".section .altinstr_replacement,\"a\"\n"
16164 "3: movb $0,%0\n"
16165 "4:\n"
16166 ".previous\n"
16167@@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16168 ".section .discard,\"aw\",@progbits\n"
16169 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16170 ".previous\n"
16171- ".section .altinstr_replacement,\"ax\"\n"
16172+ ".section .altinstr_replacement,\"a\"\n"
16173 "5: movb $1,%0\n"
16174 "6:\n"
16175 ".previous\n"
16176diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16177index 50d033a..37deb26 100644
16178--- a/arch/x86/include/asm/desc.h
16179+++ b/arch/x86/include/asm/desc.h
16180@@ -4,6 +4,7 @@
16181 #include <asm/desc_defs.h>
16182 #include <asm/ldt.h>
16183 #include <asm/mmu.h>
16184+#include <asm/pgtable.h>
16185
16186 #include <linux/smp.h>
16187 #include <linux/percpu.h>
16188@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16189
16190 desc->type = (info->read_exec_only ^ 1) << 1;
16191 desc->type |= info->contents << 2;
16192+ desc->type |= info->seg_not_present ^ 1;
16193
16194 desc->s = 1;
16195 desc->dpl = 0x3;
16196@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16197 }
16198
16199 extern struct desc_ptr idt_descr;
16200-extern gate_desc idt_table[];
16201-extern struct desc_ptr debug_idt_descr;
16202-extern gate_desc debug_idt_table[];
16203-
16204-struct gdt_page {
16205- struct desc_struct gdt[GDT_ENTRIES];
16206-} __attribute__((aligned(PAGE_SIZE)));
16207-
16208-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16209+extern gate_desc idt_table[IDT_ENTRIES];
16210+extern const struct desc_ptr debug_idt_descr;
16211+extern gate_desc debug_idt_table[IDT_ENTRIES];
16212
16213+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16214 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16215 {
16216- return per_cpu(gdt_page, cpu).gdt;
16217+ return cpu_gdt_table[cpu];
16218 }
16219
16220 #ifdef CONFIG_X86_64
16221@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16222 unsigned long base, unsigned dpl, unsigned flags,
16223 unsigned short seg)
16224 {
16225- gate->a = (seg << 16) | (base & 0xffff);
16226- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16227+ gate->gate.offset_low = base;
16228+ gate->gate.seg = seg;
16229+ gate->gate.reserved = 0;
16230+ gate->gate.type = type;
16231+ gate->gate.s = 0;
16232+ gate->gate.dpl = dpl;
16233+ gate->gate.p = 1;
16234+ gate->gate.offset_high = base >> 16;
16235 }
16236
16237 #endif
16238@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16239
16240 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16241 {
16242+ pax_open_kernel();
16243 memcpy(&idt[entry], gate, sizeof(*gate));
16244+ pax_close_kernel();
16245 }
16246
16247 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16248 {
16249+ pax_open_kernel();
16250 memcpy(&ldt[entry], desc, 8);
16251+ pax_close_kernel();
16252 }
16253
16254 static inline void
16255@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16256 default: size = sizeof(*gdt); break;
16257 }
16258
16259+ pax_open_kernel();
16260 memcpy(&gdt[entry], desc, size);
16261+ pax_close_kernel();
16262 }
16263
16264 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16265@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16266
16267 static inline void native_load_tr_desc(void)
16268 {
16269+ pax_open_kernel();
16270 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16271+ pax_close_kernel();
16272 }
16273
16274 static inline void native_load_gdt(const struct desc_ptr *dtr)
16275@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16276 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16277 unsigned int i;
16278
16279+ pax_open_kernel();
16280 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16281 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16282+ pax_close_kernel();
16283 }
16284
16285 #define _LDT_empty(info) \
16286@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16287 preempt_enable();
16288 }
16289
16290-static inline unsigned long get_desc_base(const struct desc_struct *desc)
16291+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16292 {
16293 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16294 }
16295@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16296 }
16297
16298 #ifdef CONFIG_X86_64
16299-static inline void set_nmi_gate(int gate, void *addr)
16300+static inline void set_nmi_gate(int gate, const void *addr)
16301 {
16302 gate_desc s;
16303
16304@@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16305 #endif
16306
16307 #ifdef CONFIG_TRACING
16308-extern struct desc_ptr trace_idt_descr;
16309-extern gate_desc trace_idt_table[];
16310+extern const struct desc_ptr trace_idt_descr;
16311+extern gate_desc trace_idt_table[IDT_ENTRIES];
16312 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16313 {
16314 write_idt_entry(trace_idt_table, entry, gate);
16315 }
16316
16317-static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16318+static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16319 unsigned dpl, unsigned ist, unsigned seg)
16320 {
16321 gate_desc s;
16322@@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16323 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16324 #endif
16325
16326-static inline void _set_gate(int gate, unsigned type, void *addr,
16327+static inline void _set_gate(int gate, unsigned type, const void *addr,
16328 unsigned dpl, unsigned ist, unsigned seg)
16329 {
16330 gate_desc s;
16331@@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16332 #define set_intr_gate(n, addr) \
16333 do { \
16334 BUG_ON((unsigned)n > 0xFF); \
16335- _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16336+ _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16337 __KERNEL_CS); \
16338- _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16339+ _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16340 0, 0, __KERNEL_CS); \
16341 } while (0)
16342
16343@@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16344 /*
16345 * This routine sets up an interrupt gate at directory privilege level 3.
16346 */
16347-static inline void set_system_intr_gate(unsigned int n, void *addr)
16348+static inline void set_system_intr_gate(unsigned int n, const void *addr)
16349 {
16350 BUG_ON((unsigned)n > 0xFF);
16351 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16352 }
16353
16354-static inline void set_system_trap_gate(unsigned int n, void *addr)
16355+static inline void set_system_trap_gate(unsigned int n, const void *addr)
16356 {
16357 BUG_ON((unsigned)n > 0xFF);
16358 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16359 }
16360
16361-static inline void set_trap_gate(unsigned int n, void *addr)
16362+static inline void set_trap_gate(unsigned int n, const void *addr)
16363 {
16364 BUG_ON((unsigned)n > 0xFF);
16365 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16366@@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16367 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16368 {
16369 BUG_ON((unsigned)n > 0xFF);
16370- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16371+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16372 }
16373
16374-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16375+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16376 {
16377 BUG_ON((unsigned)n > 0xFF);
16378 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16379 }
16380
16381-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16382+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16383 {
16384 BUG_ON((unsigned)n > 0xFF);
16385 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16386@@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16387 else
16388 load_idt((const struct desc_ptr *)&idt_descr);
16389 }
16390+
16391+#ifdef CONFIG_X86_32
16392+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16393+{
16394+ struct desc_struct d;
16395+
16396+ if (likely(limit))
16397+ limit = (limit - 1UL) >> PAGE_SHIFT;
16398+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
16399+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16400+}
16401+#endif
16402+
16403 #endif /* _ASM_X86_DESC_H */
16404diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16405index 278441f..b95a174 100644
16406--- a/arch/x86/include/asm/desc_defs.h
16407+++ b/arch/x86/include/asm/desc_defs.h
16408@@ -31,6 +31,12 @@ struct desc_struct {
16409 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16410 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16411 };
16412+ struct {
16413+ u16 offset_low;
16414+ u16 seg;
16415+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16416+ unsigned offset_high: 16;
16417+ } gate;
16418 };
16419 } __attribute__((packed));
16420
16421diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16422index ced283a..ffe04cc 100644
16423--- a/arch/x86/include/asm/div64.h
16424+++ b/arch/x86/include/asm/div64.h
16425@@ -39,7 +39,7 @@
16426 __mod; \
16427 })
16428
16429-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16430+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16431 {
16432 union {
16433 u64 v64;
16434diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16435index 9c999c1..3860cb8 100644
16436--- a/arch/x86/include/asm/elf.h
16437+++ b/arch/x86/include/asm/elf.h
16438@@ -243,7 +243,25 @@ extern int force_personality32;
16439 the loader. We need to make sure that it is out of the way of the program
16440 that it will "exec", and that there is sufficient room for the brk. */
16441
16442+#ifdef CONFIG_PAX_SEGMEXEC
16443+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16444+#else
16445 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16446+#endif
16447+
16448+#ifdef CONFIG_PAX_ASLR
16449+#ifdef CONFIG_X86_32
16450+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16451+
16452+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16453+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16454+#else
16455+#define PAX_ELF_ET_DYN_BASE 0x400000UL
16456+
16457+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16458+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16459+#endif
16460+#endif
16461
16462 /* This yields a mask that user programs can use to figure out what
16463 instruction set this CPU supports. This could be done in user space,
16464@@ -296,16 +314,12 @@ do { \
16465
16466 #define ARCH_DLINFO \
16467 do { \
16468- if (vdso_enabled) \
16469- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16470- (unsigned long)current->mm->context.vdso); \
16471+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16472 } while (0)
16473
16474 #define ARCH_DLINFO_X32 \
16475 do { \
16476- if (vdso_enabled) \
16477- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16478- (unsigned long)current->mm->context.vdso); \
16479+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16480 } while (0)
16481
16482 #define AT_SYSINFO 32
16483@@ -320,7 +334,7 @@ else \
16484
16485 #endif /* !CONFIG_X86_32 */
16486
16487-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16488+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16489
16490 #define VDSO_ENTRY \
16491 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16492@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16493 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16494 #define compat_arch_setup_additional_pages syscall32_setup_pages
16495
16496-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16497-#define arch_randomize_brk arch_randomize_brk
16498-
16499 /*
16500 * True on X86_32 or when emulating IA32 on X86_64
16501 */
16502diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16503index 77a99ac..39ff7f5 100644
16504--- a/arch/x86/include/asm/emergency-restart.h
16505+++ b/arch/x86/include/asm/emergency-restart.h
16506@@ -1,6 +1,6 @@
16507 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16508 #define _ASM_X86_EMERGENCY_RESTART_H
16509
16510-extern void machine_emergency_restart(void);
16511+extern void machine_emergency_restart(void) __noreturn;
16512
16513 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16514diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16515index d3d7469..677ef72 100644
16516--- a/arch/x86/include/asm/floppy.h
16517+++ b/arch/x86/include/asm/floppy.h
16518@@ -229,18 +229,18 @@ static struct fd_routine_l {
16519 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16520 } fd_routine[] = {
16521 {
16522- request_dma,
16523- free_dma,
16524- get_dma_residue,
16525- dma_mem_alloc,
16526- hard_dma_setup
16527+ ._request_dma = request_dma,
16528+ ._free_dma = free_dma,
16529+ ._get_dma_residue = get_dma_residue,
16530+ ._dma_mem_alloc = dma_mem_alloc,
16531+ ._dma_setup = hard_dma_setup
16532 },
16533 {
16534- vdma_request_dma,
16535- vdma_nop,
16536- vdma_get_dma_residue,
16537- vdma_mem_alloc,
16538- vdma_dma_setup
16539+ ._request_dma = vdma_request_dma,
16540+ ._free_dma = vdma_nop,
16541+ ._get_dma_residue = vdma_get_dma_residue,
16542+ ._dma_mem_alloc = vdma_mem_alloc,
16543+ ._dma_setup = vdma_dma_setup
16544 }
16545 };
16546
16547diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16548index cea1c76..6c0d79b 100644
16549--- a/arch/x86/include/asm/fpu-internal.h
16550+++ b/arch/x86/include/asm/fpu-internal.h
16551@@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16552 #define user_insn(insn, output, input...) \
16553 ({ \
16554 int err; \
16555+ pax_open_userland(); \
16556 asm volatile(ASM_STAC "\n" \
16557- "1:" #insn "\n\t" \
16558+ "1:" \
16559+ __copyuser_seg \
16560+ #insn "\n\t" \
16561 "2: " ASM_CLAC "\n" \
16562 ".section .fixup,\"ax\"\n" \
16563 "3: movl $-1,%[err]\n" \
16564@@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16565 _ASM_EXTABLE(1b, 3b) \
16566 : [err] "=r" (err), output \
16567 : "0"(0), input); \
16568+ pax_close_userland(); \
16569 err; \
16570 })
16571
16572@@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16573 "fnclex\n\t"
16574 "emms\n\t"
16575 "fildl %P[addr]" /* set F?P to defined value */
16576- : : [addr] "m" (tsk->thread.fpu.has_fpu));
16577+ : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16578 }
16579
16580 return fpu_restore_checking(&tsk->thread.fpu);
16581diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16582index be27ba1..04a8801 100644
16583--- a/arch/x86/include/asm/futex.h
16584+++ b/arch/x86/include/asm/futex.h
16585@@ -12,6 +12,7 @@
16586 #include <asm/smap.h>
16587
16588 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16589+ typecheck(u32 __user *, uaddr); \
16590 asm volatile("\t" ASM_STAC "\n" \
16591 "1:\t" insn "\n" \
16592 "2:\t" ASM_CLAC "\n" \
16593@@ -20,15 +21,16 @@
16594 "\tjmp\t2b\n" \
16595 "\t.previous\n" \
16596 _ASM_EXTABLE(1b, 3b) \
16597- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16598+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16599 : "i" (-EFAULT), "0" (oparg), "1" (0))
16600
16601 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16602+ typecheck(u32 __user *, uaddr); \
16603 asm volatile("\t" ASM_STAC "\n" \
16604 "1:\tmovl %2, %0\n" \
16605 "\tmovl\t%0, %3\n" \
16606 "\t" insn "\n" \
16607- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16608+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16609 "\tjnz\t1b\n" \
16610 "3:\t" ASM_CLAC "\n" \
16611 "\t.section .fixup,\"ax\"\n" \
16612@@ -38,7 +40,7 @@
16613 _ASM_EXTABLE(1b, 4b) \
16614 _ASM_EXTABLE(2b, 4b) \
16615 : "=&a" (oldval), "=&r" (ret), \
16616- "+m" (*uaddr), "=&r" (tem) \
16617+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16618 : "r" (oparg), "i" (-EFAULT), "1" (0))
16619
16620 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16621@@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16622
16623 pagefault_disable();
16624
16625+ pax_open_userland();
16626 switch (op) {
16627 case FUTEX_OP_SET:
16628- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16629+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16630 break;
16631 case FUTEX_OP_ADD:
16632- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16633+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16634 uaddr, oparg);
16635 break;
16636 case FUTEX_OP_OR:
16637@@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16638 default:
16639 ret = -ENOSYS;
16640 }
16641+ pax_close_userland();
16642
16643 pagefault_enable();
16644
16645@@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16646 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16647 return -EFAULT;
16648
16649+ pax_open_userland();
16650 asm volatile("\t" ASM_STAC "\n"
16651- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16652+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16653 "2:\t" ASM_CLAC "\n"
16654 "\t.section .fixup, \"ax\"\n"
16655 "3:\tmov %3, %0\n"
16656 "\tjmp 2b\n"
16657 "\t.previous\n"
16658 _ASM_EXTABLE(1b, 3b)
16659- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16660+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16661 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16662 : "memory"
16663 );
16664+ pax_close_userland();
16665
16666 *uval = oldval;
16667 return ret;
16668diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16669index cba45d9..86344ba 100644
16670--- a/arch/x86/include/asm/hw_irq.h
16671+++ b/arch/x86/include/asm/hw_irq.h
16672@@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16673 extern void enable_IO_APIC(void);
16674
16675 /* Statistics */
16676-extern atomic_t irq_err_count;
16677-extern atomic_t irq_mis_count;
16678+extern atomic_unchecked_t irq_err_count;
16679+extern atomic_unchecked_t irq_mis_count;
16680
16681 /* EISA */
16682 extern void eisa_set_level_irq(unsigned int irq);
16683diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16684index a203659..9889f1c 100644
16685--- a/arch/x86/include/asm/i8259.h
16686+++ b/arch/x86/include/asm/i8259.h
16687@@ -62,7 +62,7 @@ struct legacy_pic {
16688 void (*init)(int auto_eoi);
16689 int (*irq_pending)(unsigned int irq);
16690 void (*make_irq)(unsigned int irq);
16691-};
16692+} __do_const;
16693
16694 extern struct legacy_pic *legacy_pic;
16695 extern struct legacy_pic null_legacy_pic;
16696diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16697index 34f69cb..6d95446 100644
16698--- a/arch/x86/include/asm/io.h
16699+++ b/arch/x86/include/asm/io.h
16700@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16701 "m" (*(volatile type __force *)addr) barrier); }
16702
16703 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16704-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16705-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16706+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16707+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16708
16709 build_mmio_read(__readb, "b", unsigned char, "=q", )
16710-build_mmio_read(__readw, "w", unsigned short, "=r", )
16711-build_mmio_read(__readl, "l", unsigned int, "=r", )
16712+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16713+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16714
16715 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16716 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16717@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16718 return ioremap_nocache(offset, size);
16719 }
16720
16721-extern void iounmap(volatile void __iomem *addr);
16722+extern void iounmap(const volatile void __iomem *addr);
16723
16724 extern void set_iounmap_nonlazy(void);
16725
16726@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16727
16728 #include <linux/vmalloc.h>
16729
16730+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16731+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16732+{
16733+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16734+}
16735+
16736+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16737+{
16738+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16739+}
16740+
16741 /*
16742 * Convert a virtual cached pointer to an uncached pointer
16743 */
16744diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16745index bba3cf8..06bc8da 100644
16746--- a/arch/x86/include/asm/irqflags.h
16747+++ b/arch/x86/include/asm/irqflags.h
16748@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16749 sti; \
16750 sysexit
16751
16752+#define GET_CR0_INTO_RDI mov %cr0, %rdi
16753+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16754+#define GET_CR3_INTO_RDI mov %cr3, %rdi
16755+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16756+
16757 #else
16758 #define INTERRUPT_RETURN iret
16759 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16760diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16761index 9454c16..e4100e3 100644
16762--- a/arch/x86/include/asm/kprobes.h
16763+++ b/arch/x86/include/asm/kprobes.h
16764@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16765 #define RELATIVEJUMP_SIZE 5
16766 #define RELATIVECALL_OPCODE 0xe8
16767 #define RELATIVE_ADDR_SIZE 4
16768-#define MAX_STACK_SIZE 64
16769-#define MIN_STACK_SIZE(ADDR) \
16770- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16771- THREAD_SIZE - (unsigned long)(ADDR))) \
16772- ? (MAX_STACK_SIZE) \
16773- : (((unsigned long)current_thread_info()) + \
16774- THREAD_SIZE - (unsigned long)(ADDR)))
16775+#define MAX_STACK_SIZE 64UL
16776+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16777
16778 #define flush_insn_slot(p) do { } while (0)
16779
16780diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16781index 4ad6560..75c7bdd 100644
16782--- a/arch/x86/include/asm/local.h
16783+++ b/arch/x86/include/asm/local.h
16784@@ -10,33 +10,97 @@ typedef struct {
16785 atomic_long_t a;
16786 } local_t;
16787
16788+typedef struct {
16789+ atomic_long_unchecked_t a;
16790+} local_unchecked_t;
16791+
16792 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16793
16794 #define local_read(l) atomic_long_read(&(l)->a)
16795+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16796 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16797+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16798
16799 static inline void local_inc(local_t *l)
16800 {
16801- asm volatile(_ASM_INC "%0"
16802+ asm volatile(_ASM_INC "%0\n"
16803+
16804+#ifdef CONFIG_PAX_REFCOUNT
16805+ "jno 0f\n"
16806+ _ASM_DEC "%0\n"
16807+ "int $4\n0:\n"
16808+ _ASM_EXTABLE(0b, 0b)
16809+#endif
16810+
16811+ : "+m" (l->a.counter));
16812+}
16813+
16814+static inline void local_inc_unchecked(local_unchecked_t *l)
16815+{
16816+ asm volatile(_ASM_INC "%0\n"
16817 : "+m" (l->a.counter));
16818 }
16819
16820 static inline void local_dec(local_t *l)
16821 {
16822- asm volatile(_ASM_DEC "%0"
16823+ asm volatile(_ASM_DEC "%0\n"
16824+
16825+#ifdef CONFIG_PAX_REFCOUNT
16826+ "jno 0f\n"
16827+ _ASM_INC "%0\n"
16828+ "int $4\n0:\n"
16829+ _ASM_EXTABLE(0b, 0b)
16830+#endif
16831+
16832+ : "+m" (l->a.counter));
16833+}
16834+
16835+static inline void local_dec_unchecked(local_unchecked_t *l)
16836+{
16837+ asm volatile(_ASM_DEC "%0\n"
16838 : "+m" (l->a.counter));
16839 }
16840
16841 static inline void local_add(long i, local_t *l)
16842 {
16843- asm volatile(_ASM_ADD "%1,%0"
16844+ asm volatile(_ASM_ADD "%1,%0\n"
16845+
16846+#ifdef CONFIG_PAX_REFCOUNT
16847+ "jno 0f\n"
16848+ _ASM_SUB "%1,%0\n"
16849+ "int $4\n0:\n"
16850+ _ASM_EXTABLE(0b, 0b)
16851+#endif
16852+
16853+ : "+m" (l->a.counter)
16854+ : "ir" (i));
16855+}
16856+
16857+static inline void local_add_unchecked(long i, local_unchecked_t *l)
16858+{
16859+ asm volatile(_ASM_ADD "%1,%0\n"
16860 : "+m" (l->a.counter)
16861 : "ir" (i));
16862 }
16863
16864 static inline void local_sub(long i, local_t *l)
16865 {
16866- asm volatile(_ASM_SUB "%1,%0"
16867+ asm volatile(_ASM_SUB "%1,%0\n"
16868+
16869+#ifdef CONFIG_PAX_REFCOUNT
16870+ "jno 0f\n"
16871+ _ASM_ADD "%1,%0\n"
16872+ "int $4\n0:\n"
16873+ _ASM_EXTABLE(0b, 0b)
16874+#endif
16875+
16876+ : "+m" (l->a.counter)
16877+ : "ir" (i));
16878+}
16879+
16880+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16881+{
16882+ asm volatile(_ASM_SUB "%1,%0\n"
16883 : "+m" (l->a.counter)
16884 : "ir" (i));
16885 }
16886@@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16887 */
16888 static inline int local_sub_and_test(long i, local_t *l)
16889 {
16890- GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16891+ GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16892 }
16893
16894 /**
16895@@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16896 */
16897 static inline int local_dec_and_test(local_t *l)
16898 {
16899- GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16900+ GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16901 }
16902
16903 /**
16904@@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16905 */
16906 static inline int local_inc_and_test(local_t *l)
16907 {
16908- GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16909+ GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16910 }
16911
16912 /**
16913@@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16914 */
16915 static inline int local_add_negative(long i, local_t *l)
16916 {
16917- GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16918+ GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16919 }
16920
16921 /**
16922@@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16923 static inline long local_add_return(long i, local_t *l)
16924 {
16925 long __i = i;
16926+ asm volatile(_ASM_XADD "%0, %1\n"
16927+
16928+#ifdef CONFIG_PAX_REFCOUNT
16929+ "jno 0f\n"
16930+ _ASM_MOV "%0,%1\n"
16931+ "int $4\n0:\n"
16932+ _ASM_EXTABLE(0b, 0b)
16933+#endif
16934+
16935+ : "+r" (i), "+m" (l->a.counter)
16936+ : : "memory");
16937+ return i + __i;
16938+}
16939+
16940+/**
16941+ * local_add_return_unchecked - add and return
16942+ * @i: integer value to add
16943+ * @l: pointer to type local_unchecked_t
16944+ *
16945+ * Atomically adds @i to @l and returns @i + @l
16946+ */
16947+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16948+{
16949+ long __i = i;
16950 asm volatile(_ASM_XADD "%0, %1;"
16951 : "+r" (i), "+m" (l->a.counter)
16952 : : "memory");
16953@@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16954
16955 #define local_cmpxchg(l, o, n) \
16956 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16957+#define local_cmpxchg_unchecked(l, o, n) \
16958+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
16959 /* Always has a lock prefix */
16960 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16961
16962diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16963new file mode 100644
16964index 0000000..2bfd3ba
16965--- /dev/null
16966+++ b/arch/x86/include/asm/mman.h
16967@@ -0,0 +1,15 @@
16968+#ifndef _X86_MMAN_H
16969+#define _X86_MMAN_H
16970+
16971+#include <uapi/asm/mman.h>
16972+
16973+#ifdef __KERNEL__
16974+#ifndef __ASSEMBLY__
16975+#ifdef CONFIG_X86_32
16976+#define arch_mmap_check i386_mmap_check
16977+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16978+#endif
16979+#endif
16980+#endif
16981+
16982+#endif /* X86_MMAN_H */
16983diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16984index 5f55e69..e20bfb1 100644
16985--- a/arch/x86/include/asm/mmu.h
16986+++ b/arch/x86/include/asm/mmu.h
16987@@ -9,7 +9,7 @@
16988 * we put the segment information here.
16989 */
16990 typedef struct {
16991- void *ldt;
16992+ struct desc_struct *ldt;
16993 int size;
16994
16995 #ifdef CONFIG_X86_64
16996@@ -18,7 +18,19 @@ typedef struct {
16997 #endif
16998
16999 struct mutex lock;
17000- void *vdso;
17001+ unsigned long vdso;
17002+
17003+#ifdef CONFIG_X86_32
17004+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17005+ unsigned long user_cs_base;
17006+ unsigned long user_cs_limit;
17007+
17008+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17009+ cpumask_t cpu_user_cs_mask;
17010+#endif
17011+
17012+#endif
17013+#endif
17014 } mm_context_t;
17015
17016 #ifdef CONFIG_SMP
17017diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17018index be12c53..4d24039 100644
17019--- a/arch/x86/include/asm/mmu_context.h
17020+++ b/arch/x86/include/asm/mmu_context.h
17021@@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17022
17023 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17024 {
17025+
17026+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17027+ if (!(static_cpu_has(X86_FEATURE_PCID))) {
17028+ unsigned int i;
17029+ pgd_t *pgd;
17030+
17031+ pax_open_kernel();
17032+ pgd = get_cpu_pgd(smp_processor_id(), kernel);
17033+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17034+ set_pgd_batched(pgd+i, native_make_pgd(0));
17035+ pax_close_kernel();
17036+ }
17037+#endif
17038+
17039 #ifdef CONFIG_SMP
17040 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17041 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17042@@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17043 struct task_struct *tsk)
17044 {
17045 unsigned cpu = smp_processor_id();
17046+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17047+ int tlbstate = TLBSTATE_OK;
17048+#endif
17049
17050 if (likely(prev != next)) {
17051 #ifdef CONFIG_SMP
17052+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17053+ tlbstate = this_cpu_read(cpu_tlbstate.state);
17054+#endif
17055 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17056 this_cpu_write(cpu_tlbstate.active_mm, next);
17057 #endif
17058 cpumask_set_cpu(cpu, mm_cpumask(next));
17059
17060 /* Re-load page tables */
17061+#ifdef CONFIG_PAX_PER_CPU_PGD
17062+ pax_open_kernel();
17063+
17064+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17065+ if (static_cpu_has(X86_FEATURE_PCID))
17066+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17067+ else
17068+#endif
17069+
17070+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17071+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17072+ pax_close_kernel();
17073+ BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17074+
17075+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17076+ if (static_cpu_has(X86_FEATURE_PCID)) {
17077+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17078+ u64 descriptor[2];
17079+ descriptor[0] = PCID_USER;
17080+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17081+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17082+ descriptor[0] = PCID_KERNEL;
17083+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17084+ }
17085+ } else {
17086+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17087+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17088+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17089+ else
17090+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17091+ }
17092+ } else
17093+#endif
17094+
17095+ load_cr3(get_cpu_pgd(cpu, kernel));
17096+#else
17097 load_cr3(next->pgd);
17098+#endif
17099
17100 /* Stop flush ipis for the previous mm */
17101 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17102@@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17103 /* Load the LDT, if the LDT is different: */
17104 if (unlikely(prev->context.ldt != next->context.ldt))
17105 load_LDT_nolock(&next->context);
17106+
17107+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17108+ if (!(__supported_pte_mask & _PAGE_NX)) {
17109+ smp_mb__before_clear_bit();
17110+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17111+ smp_mb__after_clear_bit();
17112+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17113+ }
17114+#endif
17115+
17116+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17117+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17118+ prev->context.user_cs_limit != next->context.user_cs_limit))
17119+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17120+#ifdef CONFIG_SMP
17121+ else if (unlikely(tlbstate != TLBSTATE_OK))
17122+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17123+#endif
17124+#endif
17125+
17126 }
17127+ else {
17128+
17129+#ifdef CONFIG_PAX_PER_CPU_PGD
17130+ pax_open_kernel();
17131+
17132+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17133+ if (static_cpu_has(X86_FEATURE_PCID))
17134+ __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17135+ else
17136+#endif
17137+
17138+ __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17139+ __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17140+ pax_close_kernel();
17141+ 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));
17142+
17143+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17144+ if (static_cpu_has(X86_FEATURE_PCID)) {
17145+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
17146+ u64 descriptor[2];
17147+ descriptor[0] = PCID_USER;
17148+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17149+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17150+ descriptor[0] = PCID_KERNEL;
17151+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17152+ }
17153+ } else {
17154+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17155+ if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17156+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17157+ else
17158+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17159+ }
17160+ } else
17161+#endif
17162+
17163+ load_cr3(get_cpu_pgd(cpu, kernel));
17164+#endif
17165+
17166 #ifdef CONFIG_SMP
17167- else {
17168 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17169 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17170
17171@@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17172 * tlb flush IPI delivery. We must reload CR3
17173 * to make sure to use no freed page tables.
17174 */
17175+
17176+#ifndef CONFIG_PAX_PER_CPU_PGD
17177 load_cr3(next->pgd);
17178+#endif
17179+
17180 load_LDT_nolock(&next->context);
17181+
17182+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17183+ if (!(__supported_pte_mask & _PAGE_NX))
17184+ cpu_set(cpu, next->context.cpu_user_cs_mask);
17185+#endif
17186+
17187+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17188+#ifdef CONFIG_PAX_PAGEEXEC
17189+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17190+#endif
17191+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17192+#endif
17193+
17194 }
17195+#endif
17196 }
17197-#endif
17198 }
17199
17200 #define activate_mm(prev, next) \
17201diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17202index e3b7819..b257c64 100644
17203--- a/arch/x86/include/asm/module.h
17204+++ b/arch/x86/include/asm/module.h
17205@@ -5,6 +5,7 @@
17206
17207 #ifdef CONFIG_X86_64
17208 /* X86_64 does not define MODULE_PROC_FAMILY */
17209+#define MODULE_PROC_FAMILY ""
17210 #elif defined CONFIG_M486
17211 #define MODULE_PROC_FAMILY "486 "
17212 #elif defined CONFIG_M586
17213@@ -57,8 +58,20 @@
17214 #error unknown processor family
17215 #endif
17216
17217-#ifdef CONFIG_X86_32
17218-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17219+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17220+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17221+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17222+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17223+#else
17224+#define MODULE_PAX_KERNEXEC ""
17225 #endif
17226
17227+#ifdef CONFIG_PAX_MEMORY_UDEREF
17228+#define MODULE_PAX_UDEREF "UDEREF "
17229+#else
17230+#define MODULE_PAX_UDEREF ""
17231+#endif
17232+
17233+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17234+
17235 #endif /* _ASM_X86_MODULE_H */
17236diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17237index 86f9301..b365cda 100644
17238--- a/arch/x86/include/asm/nmi.h
17239+++ b/arch/x86/include/asm/nmi.h
17240@@ -40,11 +40,11 @@ struct nmiaction {
17241 nmi_handler_t handler;
17242 unsigned long flags;
17243 const char *name;
17244-};
17245+} __do_const;
17246
17247 #define register_nmi_handler(t, fn, fg, n, init...) \
17248 ({ \
17249- static struct nmiaction init fn##_na = { \
17250+ static const struct nmiaction init fn##_na = { \
17251 .handler = (fn), \
17252 .name = (n), \
17253 .flags = (fg), \
17254@@ -52,7 +52,7 @@ struct nmiaction {
17255 __register_nmi_handler((t), &fn##_na); \
17256 })
17257
17258-int __register_nmi_handler(unsigned int, struct nmiaction *);
17259+int __register_nmi_handler(unsigned int, const struct nmiaction *);
17260
17261 void unregister_nmi_handler(unsigned int, const char *);
17262
17263diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17264index c878924..21f4889 100644
17265--- a/arch/x86/include/asm/page.h
17266+++ b/arch/x86/include/asm/page.h
17267@@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17268 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17269
17270 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17271+#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17272
17273 #define __boot_va(x) __va(x)
17274 #define __boot_pa(x) __pa(x)
17275diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17276index 0f1ddee..e2fc3d1 100644
17277--- a/arch/x86/include/asm/page_64.h
17278+++ b/arch/x86/include/asm/page_64.h
17279@@ -7,9 +7,9 @@
17280
17281 /* duplicated to the one in bootmem.h */
17282 extern unsigned long max_pfn;
17283-extern unsigned long phys_base;
17284+extern const unsigned long phys_base;
17285
17286-static inline unsigned long __phys_addr_nodebug(unsigned long x)
17287+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17288 {
17289 unsigned long y = x - __START_KERNEL_map;
17290
17291diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17292index 401f350..dee5d13 100644
17293--- a/arch/x86/include/asm/paravirt.h
17294+++ b/arch/x86/include/asm/paravirt.h
17295@@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17296 return (pmd_t) { ret };
17297 }
17298
17299-static inline pmdval_t pmd_val(pmd_t pmd)
17300+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17301 {
17302 pmdval_t ret;
17303
17304@@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17305 val);
17306 }
17307
17308+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17309+{
17310+ pgdval_t val = native_pgd_val(pgd);
17311+
17312+ if (sizeof(pgdval_t) > sizeof(long))
17313+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17314+ val, (u64)val >> 32);
17315+ else
17316+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17317+ val);
17318+}
17319+
17320 static inline void pgd_clear(pgd_t *pgdp)
17321 {
17322 set_pgd(pgdp, __pgd(0));
17323@@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17324 pv_mmu_ops.set_fixmap(idx, phys, flags);
17325 }
17326
17327+#ifdef CONFIG_PAX_KERNEXEC
17328+static inline unsigned long pax_open_kernel(void)
17329+{
17330+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17331+}
17332+
17333+static inline unsigned long pax_close_kernel(void)
17334+{
17335+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17336+}
17337+#else
17338+static inline unsigned long pax_open_kernel(void) { return 0; }
17339+static inline unsigned long pax_close_kernel(void) { return 0; }
17340+#endif
17341+
17342 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17343
17344 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17345@@ -906,7 +933,7 @@ extern void default_banner(void);
17346
17347 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17348 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17349-#define PARA_INDIRECT(addr) *%cs:addr
17350+#define PARA_INDIRECT(addr) *%ss:addr
17351 #endif
17352
17353 #define INTERRUPT_RETURN \
17354@@ -981,6 +1008,21 @@ extern void default_banner(void);
17355 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17356 CLBR_NONE, \
17357 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17358+
17359+#define GET_CR0_INTO_RDI \
17360+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17361+ mov %rax,%rdi
17362+
17363+#define SET_RDI_INTO_CR0 \
17364+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17365+
17366+#define GET_CR3_INTO_RDI \
17367+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17368+ mov %rax,%rdi
17369+
17370+#define SET_RDI_INTO_CR3 \
17371+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17372+
17373 #endif /* CONFIG_X86_32 */
17374
17375 #endif /* __ASSEMBLY__ */
17376diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17377index aab8f67..0fb0ee4 100644
17378--- a/arch/x86/include/asm/paravirt_types.h
17379+++ b/arch/x86/include/asm/paravirt_types.h
17380@@ -84,7 +84,7 @@ struct pv_init_ops {
17381 */
17382 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17383 unsigned long addr, unsigned len);
17384-};
17385+} __no_const __no_randomize_layout;
17386
17387
17388 struct pv_lazy_ops {
17389@@ -92,13 +92,13 @@ struct pv_lazy_ops {
17390 void (*enter)(void);
17391 void (*leave)(void);
17392 void (*flush)(void);
17393-};
17394+} __no_randomize_layout;
17395
17396 struct pv_time_ops {
17397 unsigned long long (*sched_clock)(void);
17398 unsigned long long (*steal_clock)(int cpu);
17399 unsigned long (*get_tsc_khz)(void);
17400-};
17401+} __no_const __no_randomize_layout;
17402
17403 struct pv_cpu_ops {
17404 /* hooks for various privileged instructions */
17405@@ -192,7 +192,7 @@ struct pv_cpu_ops {
17406
17407 void (*start_context_switch)(struct task_struct *prev);
17408 void (*end_context_switch)(struct task_struct *next);
17409-};
17410+} __no_const __no_randomize_layout;
17411
17412 struct pv_irq_ops {
17413 /*
17414@@ -215,7 +215,7 @@ struct pv_irq_ops {
17415 #ifdef CONFIG_X86_64
17416 void (*adjust_exception_frame)(void);
17417 #endif
17418-};
17419+} __no_randomize_layout;
17420
17421 struct pv_apic_ops {
17422 #ifdef CONFIG_X86_LOCAL_APIC
17423@@ -223,7 +223,7 @@ struct pv_apic_ops {
17424 unsigned long start_eip,
17425 unsigned long start_esp);
17426 #endif
17427-};
17428+} __no_const __no_randomize_layout;
17429
17430 struct pv_mmu_ops {
17431 unsigned long (*read_cr2)(void);
17432@@ -313,6 +313,7 @@ struct pv_mmu_ops {
17433 struct paravirt_callee_save make_pud;
17434
17435 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17436+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17437 #endif /* PAGETABLE_LEVELS == 4 */
17438 #endif /* PAGETABLE_LEVELS >= 3 */
17439
17440@@ -324,7 +325,13 @@ struct pv_mmu_ops {
17441 an mfn. We can tell which is which from the index. */
17442 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17443 phys_addr_t phys, pgprot_t flags);
17444-};
17445+
17446+#ifdef CONFIG_PAX_KERNEXEC
17447+ unsigned long (*pax_open_kernel)(void);
17448+ unsigned long (*pax_close_kernel)(void);
17449+#endif
17450+
17451+} __no_randomize_layout;
17452
17453 struct arch_spinlock;
17454 #ifdef CONFIG_SMP
17455@@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17456 struct pv_lock_ops {
17457 struct paravirt_callee_save lock_spinning;
17458 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17459-};
17460+} __no_randomize_layout;
17461
17462 /* This contains all the paravirt structures: we get a convenient
17463 * number for each function using the offset which we use to indicate
17464- * what to patch. */
17465+ * what to patch.
17466+ * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17467+ */
17468+
17469 struct paravirt_patch_template {
17470 struct pv_init_ops pv_init_ops;
17471 struct pv_time_ops pv_time_ops;
17472@@ -349,7 +359,7 @@ struct paravirt_patch_template {
17473 struct pv_apic_ops pv_apic_ops;
17474 struct pv_mmu_ops pv_mmu_ops;
17475 struct pv_lock_ops pv_lock_ops;
17476-};
17477+} __no_randomize_layout;
17478
17479 extern struct pv_info pv_info;
17480 extern struct pv_init_ops pv_init_ops;
17481diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17482index c4412e9..90e88c5 100644
17483--- a/arch/x86/include/asm/pgalloc.h
17484+++ b/arch/x86/include/asm/pgalloc.h
17485@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17486 pmd_t *pmd, pte_t *pte)
17487 {
17488 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17489+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17490+}
17491+
17492+static inline void pmd_populate_user(struct mm_struct *mm,
17493+ pmd_t *pmd, pte_t *pte)
17494+{
17495+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17496 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17497 }
17498
17499@@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17500
17501 #ifdef CONFIG_X86_PAE
17502 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17503+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17504+{
17505+ pud_populate(mm, pudp, pmd);
17506+}
17507 #else /* !CONFIG_X86_PAE */
17508 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17509 {
17510 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17511 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17512 }
17513+
17514+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17515+{
17516+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17517+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17518+}
17519 #endif /* CONFIG_X86_PAE */
17520
17521 #if PAGETABLE_LEVELS > 3
17522@@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17523 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17524 }
17525
17526+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17527+{
17528+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17529+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17530+}
17531+
17532 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17533 {
17534 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17535diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17536index 3bf2dd0..23d2a9f 100644
17537--- a/arch/x86/include/asm/pgtable-2level.h
17538+++ b/arch/x86/include/asm/pgtable-2level.h
17539@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17540
17541 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17542 {
17543+ pax_open_kernel();
17544 *pmdp = pmd;
17545+ pax_close_kernel();
17546 }
17547
17548 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17549diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17550index 81bb91b..9392125 100644
17551--- a/arch/x86/include/asm/pgtable-3level.h
17552+++ b/arch/x86/include/asm/pgtable-3level.h
17553@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17554
17555 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17556 {
17557+ pax_open_kernel();
17558 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17559+ pax_close_kernel();
17560 }
17561
17562 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17563 {
17564+ pax_open_kernel();
17565 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17566+ pax_close_kernel();
17567 }
17568
17569 /*
17570diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17571index bbc8b12..f228861 100644
17572--- a/arch/x86/include/asm/pgtable.h
17573+++ b/arch/x86/include/asm/pgtable.h
17574@@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17575
17576 #ifndef __PAGETABLE_PUD_FOLDED
17577 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17578+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17579 #define pgd_clear(pgd) native_pgd_clear(pgd)
17580 #endif
17581
17582@@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17583
17584 #define arch_end_context_switch(prev) do {} while(0)
17585
17586+#define pax_open_kernel() native_pax_open_kernel()
17587+#define pax_close_kernel() native_pax_close_kernel()
17588 #endif /* CONFIG_PARAVIRT */
17589
17590+#define __HAVE_ARCH_PAX_OPEN_KERNEL
17591+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17592+
17593+#ifdef CONFIG_PAX_KERNEXEC
17594+static inline unsigned long native_pax_open_kernel(void)
17595+{
17596+ unsigned long cr0;
17597+
17598+ preempt_disable();
17599+ barrier();
17600+ cr0 = read_cr0() ^ X86_CR0_WP;
17601+ BUG_ON(cr0 & X86_CR0_WP);
17602+ write_cr0(cr0);
17603+ return cr0 ^ X86_CR0_WP;
17604+}
17605+
17606+static inline unsigned long native_pax_close_kernel(void)
17607+{
17608+ unsigned long cr0;
17609+
17610+ cr0 = read_cr0() ^ X86_CR0_WP;
17611+ BUG_ON(!(cr0 & X86_CR0_WP));
17612+ write_cr0(cr0);
17613+ barrier();
17614+ preempt_enable_no_resched();
17615+ return cr0 ^ X86_CR0_WP;
17616+}
17617+#else
17618+static inline unsigned long native_pax_open_kernel(void) { return 0; }
17619+static inline unsigned long native_pax_close_kernel(void) { return 0; }
17620+#endif
17621+
17622 /*
17623 * The following only work if pte_present() is true.
17624 * Undefined behaviour if not..
17625 */
17626+static inline int pte_user(pte_t pte)
17627+{
17628+ return pte_val(pte) & _PAGE_USER;
17629+}
17630+
17631 static inline int pte_dirty(pte_t pte)
17632 {
17633 return pte_flags(pte) & _PAGE_DIRTY;
17634@@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17635 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17636 }
17637
17638+static inline unsigned long pgd_pfn(pgd_t pgd)
17639+{
17640+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17641+}
17642+
17643 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17644
17645 static inline int pmd_large(pmd_t pte)
17646@@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17647 return pte_clear_flags(pte, _PAGE_RW);
17648 }
17649
17650+static inline pte_t pte_mkread(pte_t pte)
17651+{
17652+ return __pte(pte_val(pte) | _PAGE_USER);
17653+}
17654+
17655 static inline pte_t pte_mkexec(pte_t pte)
17656 {
17657- return pte_clear_flags(pte, _PAGE_NX);
17658+#ifdef CONFIG_X86_PAE
17659+ if (__supported_pte_mask & _PAGE_NX)
17660+ return pte_clear_flags(pte, _PAGE_NX);
17661+ else
17662+#endif
17663+ return pte_set_flags(pte, _PAGE_USER);
17664+}
17665+
17666+static inline pte_t pte_exprotect(pte_t pte)
17667+{
17668+#ifdef CONFIG_X86_PAE
17669+ if (__supported_pte_mask & _PAGE_NX)
17670+ return pte_set_flags(pte, _PAGE_NX);
17671+ else
17672+#endif
17673+ return pte_clear_flags(pte, _PAGE_USER);
17674 }
17675
17676 static inline pte_t pte_mkdirty(pte_t pte)
17677@@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17678 #endif
17679
17680 #ifndef __ASSEMBLY__
17681+
17682+#ifdef CONFIG_PAX_PER_CPU_PGD
17683+extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17684+enum cpu_pgd_type {kernel = 0, user = 1};
17685+static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17686+{
17687+ return cpu_pgd[cpu][type];
17688+}
17689+#endif
17690+
17691 #include <linux/mm_types.h>
17692 #include <linux/mmdebug.h>
17693 #include <linux/log2.h>
17694@@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17695 * Currently stuck as a macro due to indirect forward reference to
17696 * linux/mmzone.h's __section_mem_map_addr() definition:
17697 */
17698-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17699+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17700
17701 /* Find an entry in the second-level page table.. */
17702 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17703@@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17704 * Currently stuck as a macro due to indirect forward reference to
17705 * linux/mmzone.h's __section_mem_map_addr() definition:
17706 */
17707-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17708+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17709
17710 /* to find an entry in a page-table-directory. */
17711 static inline unsigned long pud_index(unsigned long address)
17712@@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17713
17714 static inline int pgd_bad(pgd_t pgd)
17715 {
17716- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17717+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17718 }
17719
17720 static inline int pgd_none(pgd_t pgd)
17721@@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17722 * pgd_offset() returns a (pgd_t *)
17723 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17724 */
17725-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17726+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17727+
17728+#ifdef CONFIG_PAX_PER_CPU_PGD
17729+#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17730+#endif
17731+
17732 /*
17733 * a shortcut which implies the use of the kernel's pgd, instead
17734 * of a process's
17735@@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17736 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17737 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17738
17739+#ifdef CONFIG_X86_32
17740+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17741+#else
17742+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17743+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17744+
17745+#ifdef CONFIG_PAX_MEMORY_UDEREF
17746+#ifdef __ASSEMBLY__
17747+#define pax_user_shadow_base pax_user_shadow_base(%rip)
17748+#else
17749+extern unsigned long pax_user_shadow_base;
17750+extern pgdval_t clone_pgd_mask;
17751+#endif
17752+#endif
17753+
17754+#endif
17755+
17756 #ifndef __ASSEMBLY__
17757
17758 extern int direct_gbpages;
17759@@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17760 * dst and src can be on the same page, but the range must not overlap,
17761 * and must not cross a page boundary.
17762 */
17763-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17764+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17765 {
17766- memcpy(dst, src, count * sizeof(pgd_t));
17767+ pax_open_kernel();
17768+ while (count--)
17769+ *dst++ = *src++;
17770+ pax_close_kernel();
17771 }
17772
17773+#ifdef CONFIG_PAX_PER_CPU_PGD
17774+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17775+#endif
17776+
17777+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17778+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17779+#else
17780+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17781+#endif
17782+
17783 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17784 static inline int page_level_shift(enum pg_level level)
17785 {
17786diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17787index 9ee3221..b979c6b 100644
17788--- a/arch/x86/include/asm/pgtable_32.h
17789+++ b/arch/x86/include/asm/pgtable_32.h
17790@@ -25,9 +25,6 @@
17791 struct mm_struct;
17792 struct vm_area_struct;
17793
17794-extern pgd_t swapper_pg_dir[1024];
17795-extern pgd_t initial_page_table[1024];
17796-
17797 static inline void pgtable_cache_init(void) { }
17798 static inline void check_pgt_cache(void) { }
17799 void paging_init(void);
17800@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17801 # include <asm/pgtable-2level.h>
17802 #endif
17803
17804+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17805+extern pgd_t initial_page_table[PTRS_PER_PGD];
17806+#ifdef CONFIG_X86_PAE
17807+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17808+#endif
17809+
17810 #if defined(CONFIG_HIGHPTE)
17811 #define pte_offset_map(dir, address) \
17812 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17813@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17814 /* Clear a kernel PTE and flush it from the TLB */
17815 #define kpte_clear_flush(ptep, vaddr) \
17816 do { \
17817+ pax_open_kernel(); \
17818 pte_clear(&init_mm, (vaddr), (ptep)); \
17819+ pax_close_kernel(); \
17820 __flush_tlb_one((vaddr)); \
17821 } while (0)
17822
17823 #endif /* !__ASSEMBLY__ */
17824
17825+#define HAVE_ARCH_UNMAPPED_AREA
17826+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17827+
17828 /*
17829 * kern_addr_valid() is (1) for FLATMEM and (0) for
17830 * SPARSEMEM and DISCONTIGMEM
17831diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17832index ed5903b..c7fe163 100644
17833--- a/arch/x86/include/asm/pgtable_32_types.h
17834+++ b/arch/x86/include/asm/pgtable_32_types.h
17835@@ -8,7 +8,7 @@
17836 */
17837 #ifdef CONFIG_X86_PAE
17838 # include <asm/pgtable-3level_types.h>
17839-# define PMD_SIZE (1UL << PMD_SHIFT)
17840+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17841 # define PMD_MASK (~(PMD_SIZE - 1))
17842 #else
17843 # include <asm/pgtable-2level_types.h>
17844@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17845 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17846 #endif
17847
17848+#ifdef CONFIG_PAX_KERNEXEC
17849+#ifndef __ASSEMBLY__
17850+extern unsigned char MODULES_EXEC_VADDR[];
17851+extern unsigned char MODULES_EXEC_END[];
17852+#endif
17853+#include <asm/boot.h>
17854+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17855+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17856+#else
17857+#define ktla_ktva(addr) (addr)
17858+#define ktva_ktla(addr) (addr)
17859+#endif
17860+
17861 #define MODULES_VADDR VMALLOC_START
17862 #define MODULES_END VMALLOC_END
17863 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17864diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17865index e22c1db..23a625a 100644
17866--- a/arch/x86/include/asm/pgtable_64.h
17867+++ b/arch/x86/include/asm/pgtable_64.h
17868@@ -16,10 +16,14 @@
17869
17870 extern pud_t level3_kernel_pgt[512];
17871 extern pud_t level3_ident_pgt[512];
17872+extern pud_t level3_vmalloc_start_pgt[512];
17873+extern pud_t level3_vmalloc_end_pgt[512];
17874+extern pud_t level3_vmemmap_pgt[512];
17875+extern pud_t level2_vmemmap_pgt[512];
17876 extern pmd_t level2_kernel_pgt[512];
17877 extern pmd_t level2_fixmap_pgt[512];
17878-extern pmd_t level2_ident_pgt[512];
17879-extern pgd_t init_level4_pgt[];
17880+extern pmd_t level2_ident_pgt[512*2];
17881+extern pgd_t init_level4_pgt[512];
17882
17883 #define swapper_pg_dir init_level4_pgt
17884
17885@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17886
17887 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17888 {
17889+ pax_open_kernel();
17890 *pmdp = pmd;
17891+ pax_close_kernel();
17892 }
17893
17894 static inline void native_pmd_clear(pmd_t *pmd)
17895@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17896
17897 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17898 {
17899+ pax_open_kernel();
17900 *pudp = pud;
17901+ pax_close_kernel();
17902 }
17903
17904 static inline void native_pud_clear(pud_t *pud)
17905@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17906
17907 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17908 {
17909+ pax_open_kernel();
17910+ *pgdp = pgd;
17911+ pax_close_kernel();
17912+}
17913+
17914+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17915+{
17916 *pgdp = pgd;
17917 }
17918
17919diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17920index 2d88344..4679fc3 100644
17921--- a/arch/x86/include/asm/pgtable_64_types.h
17922+++ b/arch/x86/include/asm/pgtable_64_types.h
17923@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17924 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17925 #define MODULES_END _AC(0xffffffffff000000, UL)
17926 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17927+#define MODULES_EXEC_VADDR MODULES_VADDR
17928+#define MODULES_EXEC_END MODULES_END
17929+
17930+#define ktla_ktva(addr) (addr)
17931+#define ktva_ktla(addr) (addr)
17932
17933 #define EARLY_DYNAMIC_PAGE_TABLES 64
17934
17935diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17936index 840c127..a8f297b 100644
17937--- a/arch/x86/include/asm/pgtable_types.h
17938+++ b/arch/x86/include/asm/pgtable_types.h
17939@@ -16,13 +16,12 @@
17940 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17941 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17942 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17943-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17944+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17945 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17946 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17947 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17948-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17949-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17950-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17951+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17952+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17953 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17954
17955 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17956@@ -40,7 +39,6 @@
17957 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17958 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17959 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17960-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17961 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17962 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17963 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17964@@ -87,8 +85,10 @@
17965
17966 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17967 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17968-#else
17969+#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17970 #define _PAGE_NX (_AT(pteval_t, 0))
17971+#else
17972+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17973 #endif
17974
17975 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17976@@ -147,6 +147,9 @@
17977 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17978 _PAGE_ACCESSED)
17979
17980+#define PAGE_READONLY_NOEXEC PAGE_READONLY
17981+#define PAGE_SHARED_NOEXEC PAGE_SHARED
17982+
17983 #define __PAGE_KERNEL_EXEC \
17984 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17985 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17986@@ -157,7 +160,7 @@
17987 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17988 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17989 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17990-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17991+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17992 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17993 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17994 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17995@@ -219,8 +222,8 @@
17996 * bits are combined, this will alow user to access the high address mapped
17997 * VDSO in the presence of CONFIG_COMPAT_VDSO
17998 */
17999-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18000-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
18001+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18002+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18003 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18004 #endif
18005
18006@@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18007 {
18008 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18009 }
18010+#endif
18011
18012+#if PAGETABLE_LEVELS == 3
18013+#include <asm-generic/pgtable-nopud.h>
18014+#endif
18015+
18016+#if PAGETABLE_LEVELS == 2
18017+#include <asm-generic/pgtable-nopmd.h>
18018+#endif
18019+
18020+#ifndef __ASSEMBLY__
18021 #if PAGETABLE_LEVELS > 3
18022 typedef struct { pudval_t pud; } pud_t;
18023
18024@@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18025 return pud.pud;
18026 }
18027 #else
18028-#include <asm-generic/pgtable-nopud.h>
18029-
18030 static inline pudval_t native_pud_val(pud_t pud)
18031 {
18032 return native_pgd_val(pud.pgd);
18033@@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18034 return pmd.pmd;
18035 }
18036 #else
18037-#include <asm-generic/pgtable-nopmd.h>
18038-
18039 static inline pmdval_t native_pmd_val(pmd_t pmd)
18040 {
18041 return native_pgd_val(pmd.pud.pgd);
18042@@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
18043
18044 extern pteval_t __supported_pte_mask;
18045 extern void set_nx(void);
18046-extern int nx_enabled;
18047
18048 #define pgprot_writecombine pgprot_writecombine
18049 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18050diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18051index c8b0519..fd29e73 100644
18052--- a/arch/x86/include/asm/preempt.h
18053+++ b/arch/x86/include/asm/preempt.h
18054@@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18055 */
18056 static __always_inline bool __preempt_count_dec_and_test(void)
18057 {
18058- GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18059+ GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18060 }
18061
18062 /*
18063diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18064index 7b034a4..4fe3e3f 100644
18065--- a/arch/x86/include/asm/processor.h
18066+++ b/arch/x86/include/asm/processor.h
18067@@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18068 /* Index into per_cpu list: */
18069 u16 cpu_index;
18070 u32 microcode;
18071-} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18072+} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18073
18074 #define X86_VENDOR_INTEL 0
18075 #define X86_VENDOR_CYRIX 1
18076@@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18077 : "memory");
18078 }
18079
18080+/* invpcid (%rdx),%rax */
18081+#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18082+
18083+#define INVPCID_SINGLE_ADDRESS 0UL
18084+#define INVPCID_SINGLE_CONTEXT 1UL
18085+#define INVPCID_ALL_GLOBAL 2UL
18086+#define INVPCID_ALL_MONGLOBAL 3UL
18087+
18088+#define PCID_KERNEL 0UL
18089+#define PCID_USER 1UL
18090+#define PCID_NOFLUSH (1UL << 63)
18091+
18092 static inline void load_cr3(pgd_t *pgdir)
18093 {
18094- write_cr3(__pa(pgdir));
18095+ write_cr3(__pa(pgdir) | PCID_KERNEL);
18096 }
18097
18098 #ifdef CONFIG_X86_32
18099@@ -283,7 +295,7 @@ struct tss_struct {
18100
18101 } ____cacheline_aligned;
18102
18103-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18104+extern struct tss_struct init_tss[NR_CPUS];
18105
18106 /*
18107 * Save the original ist values for checking stack pointers during debugging
18108@@ -453,6 +465,7 @@ struct thread_struct {
18109 unsigned short ds;
18110 unsigned short fsindex;
18111 unsigned short gsindex;
18112+ unsigned short ss;
18113 #endif
18114 #ifdef CONFIG_X86_32
18115 unsigned long ip;
18116@@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
18117 extern unsigned long mmu_cr4_features;
18118 extern u32 *trampoline_cr4_features;
18119
18120-static inline void set_in_cr4(unsigned long mask)
18121-{
18122- unsigned long cr4;
18123-
18124- mmu_cr4_features |= mask;
18125- if (trampoline_cr4_features)
18126- *trampoline_cr4_features = mmu_cr4_features;
18127- cr4 = read_cr4();
18128- cr4 |= mask;
18129- write_cr4(cr4);
18130-}
18131-
18132-static inline void clear_in_cr4(unsigned long mask)
18133-{
18134- unsigned long cr4;
18135-
18136- mmu_cr4_features &= ~mask;
18137- if (trampoline_cr4_features)
18138- *trampoline_cr4_features = mmu_cr4_features;
18139- cr4 = read_cr4();
18140- cr4 &= ~mask;
18141- write_cr4(cr4);
18142-}
18143+extern void set_in_cr4(unsigned long mask);
18144+extern void clear_in_cr4(unsigned long mask);
18145
18146 typedef struct {
18147 unsigned long seg;
18148@@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
18149 */
18150 #define TASK_SIZE PAGE_OFFSET
18151 #define TASK_SIZE_MAX TASK_SIZE
18152+
18153+#ifdef CONFIG_PAX_SEGMEXEC
18154+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18155+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18156+#else
18157 #define STACK_TOP TASK_SIZE
18158-#define STACK_TOP_MAX STACK_TOP
18159+#endif
18160+
18161+#define STACK_TOP_MAX TASK_SIZE
18162
18163 #define INIT_THREAD { \
18164- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18165+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18166 .vm86_info = NULL, \
18167 .sysenter_cs = __KERNEL_CS, \
18168 .io_bitmap_ptr = NULL, \
18169@@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
18170 */
18171 #define INIT_TSS { \
18172 .x86_tss = { \
18173- .sp0 = sizeof(init_stack) + (long)&init_stack, \
18174+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18175 .ss0 = __KERNEL_DS, \
18176 .ss1 = __KERNEL_CS, \
18177 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18178@@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
18179 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18180
18181 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18182-#define KSTK_TOP(info) \
18183-({ \
18184- unsigned long *__ptr = (unsigned long *)(info); \
18185- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18186-})
18187+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18188
18189 /*
18190 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18191@@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18192 #define task_pt_regs(task) \
18193 ({ \
18194 struct pt_regs *__regs__; \
18195- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18196+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18197 __regs__ - 1; \
18198 })
18199
18200@@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18201 /*
18202 * User space process size. 47bits minus one guard page.
18203 */
18204-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18205+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18206
18207 /* This decides where the kernel will search for a free chunk of vm
18208 * space during mmap's.
18209 */
18210 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18211- 0xc0000000 : 0xFFFFe000)
18212+ 0xc0000000 : 0xFFFFf000)
18213
18214 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18215 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18216@@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18217 #define STACK_TOP_MAX TASK_SIZE_MAX
18218
18219 #define INIT_THREAD { \
18220- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18221+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18222 }
18223
18224 #define INIT_TSS { \
18225- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18226+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18227 }
18228
18229 /*
18230@@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18231 */
18232 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18233
18234+#ifdef CONFIG_PAX_SEGMEXEC
18235+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18236+#endif
18237+
18238 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18239
18240 /* Get/set a process' ability to use the timestamp counter instruction */
18241@@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18242 return 0;
18243 }
18244
18245-extern unsigned long arch_align_stack(unsigned long sp);
18246+#define arch_align_stack(x) ((x) & ~0xfUL)
18247 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18248
18249 void default_idle(void);
18250@@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
18251 #define xen_set_default_idle 0
18252 #endif
18253
18254-void stop_this_cpu(void *dummy);
18255+void stop_this_cpu(void *dummy) __noreturn;
18256 void df_debug(struct pt_regs *regs, long error_code);
18257 #endif /* _ASM_X86_PROCESSOR_H */
18258diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18259index 942a086..6c26446 100644
18260--- a/arch/x86/include/asm/ptrace.h
18261+++ b/arch/x86/include/asm/ptrace.h
18262@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18263 }
18264
18265 /*
18266- * user_mode_vm(regs) determines whether a register set came from user mode.
18267+ * user_mode(regs) determines whether a register set came from user mode.
18268 * This is true if V8086 mode was enabled OR if the register set was from
18269 * protected mode with RPL-3 CS value. This tricky test checks that with
18270 * one comparison. Many places in the kernel can bypass this full check
18271- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18272+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18273+ * be used.
18274 */
18275-static inline int user_mode(struct pt_regs *regs)
18276+static inline int user_mode_novm(struct pt_regs *regs)
18277 {
18278 #ifdef CONFIG_X86_32
18279 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18280 #else
18281- return !!(regs->cs & 3);
18282+ return !!(regs->cs & SEGMENT_RPL_MASK);
18283 #endif
18284 }
18285
18286-static inline int user_mode_vm(struct pt_regs *regs)
18287+static inline int user_mode(struct pt_regs *regs)
18288 {
18289 #ifdef CONFIG_X86_32
18290 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18291 USER_RPL;
18292 #else
18293- return user_mode(regs);
18294+ return user_mode_novm(regs);
18295 #endif
18296 }
18297
18298@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18299 #ifdef CONFIG_X86_64
18300 static inline bool user_64bit_mode(struct pt_regs *regs)
18301 {
18302+ unsigned long cs = regs->cs & 0xffff;
18303 #ifndef CONFIG_PARAVIRT
18304 /*
18305 * On non-paravirt systems, this is the only long mode CPL 3
18306 * selector. We do not allow long mode selectors in the LDT.
18307 */
18308- return regs->cs == __USER_CS;
18309+ return cs == __USER_CS;
18310 #else
18311 /* Headers are too twisted for this to go in paravirt.h. */
18312- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18313+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18314 #endif
18315 }
18316
18317@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18318 * Traps from the kernel do not save sp and ss.
18319 * Use the helper function to retrieve sp.
18320 */
18321- if (offset == offsetof(struct pt_regs, sp) &&
18322- regs->cs == __KERNEL_CS)
18323- return kernel_stack_pointer(regs);
18324+ if (offset == offsetof(struct pt_regs, sp)) {
18325+ unsigned long cs = regs->cs & 0xffff;
18326+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18327+ return kernel_stack_pointer(regs);
18328+ }
18329 #endif
18330 return *(unsigned long *)((unsigned long)regs + offset);
18331 }
18332diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18333index 9c6b890..5305f53 100644
18334--- a/arch/x86/include/asm/realmode.h
18335+++ b/arch/x86/include/asm/realmode.h
18336@@ -22,16 +22,14 @@ struct real_mode_header {
18337 #endif
18338 /* APM/BIOS reboot */
18339 u32 machine_real_restart_asm;
18340-#ifdef CONFIG_X86_64
18341 u32 machine_real_restart_seg;
18342-#endif
18343 };
18344
18345 /* This must match data at trampoline_32/64.S */
18346 struct trampoline_header {
18347 #ifdef CONFIG_X86_32
18348 u32 start;
18349- u16 gdt_pad;
18350+ u16 boot_cs;
18351 u16 gdt_limit;
18352 u32 gdt_base;
18353 #else
18354diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18355index a82c4f1..ac45053 100644
18356--- a/arch/x86/include/asm/reboot.h
18357+++ b/arch/x86/include/asm/reboot.h
18358@@ -6,13 +6,13 @@
18359 struct pt_regs;
18360
18361 struct machine_ops {
18362- void (*restart)(char *cmd);
18363- void (*halt)(void);
18364- void (*power_off)(void);
18365+ void (* __noreturn restart)(char *cmd);
18366+ void (* __noreturn halt)(void);
18367+ void (* __noreturn power_off)(void);
18368 void (*shutdown)(void);
18369 void (*crash_shutdown)(struct pt_regs *);
18370- void (*emergency_restart)(void);
18371-};
18372+ void (* __noreturn emergency_restart)(void);
18373+} __no_const;
18374
18375 extern struct machine_ops machine_ops;
18376
18377diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18378index 8f7866a..e442f20 100644
18379--- a/arch/x86/include/asm/rmwcc.h
18380+++ b/arch/x86/include/asm/rmwcc.h
18381@@ -3,7 +3,34 @@
18382
18383 #ifdef CC_HAVE_ASM_GOTO
18384
18385-#define __GEN_RMWcc(fullop, var, cc, ...) \
18386+#ifdef CONFIG_PAX_REFCOUNT
18387+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18388+do { \
18389+ asm_volatile_goto (fullop \
18390+ ";jno 0f\n" \
18391+ fullantiop \
18392+ ";int $4\n0:\n" \
18393+ _ASM_EXTABLE(0b, 0b) \
18394+ ";j" cc " %l[cc_label]" \
18395+ : : "m" (var), ## __VA_ARGS__ \
18396+ : "memory" : cc_label); \
18397+ return 0; \
18398+cc_label: \
18399+ return 1; \
18400+} while (0)
18401+#else
18402+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18403+do { \
18404+ asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18405+ : : "m" (var), ## __VA_ARGS__ \
18406+ : "memory" : cc_label); \
18407+ return 0; \
18408+cc_label: \
18409+ return 1; \
18410+} while (0)
18411+#endif
18412+
18413+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18414 do { \
18415 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18416 : : "m" (var), ## __VA_ARGS__ \
18417@@ -13,15 +40,46 @@ cc_label: \
18418 return 1; \
18419 } while (0)
18420
18421-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18422- __GEN_RMWcc(op " " arg0, var, cc)
18423+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18424+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18425
18426-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18427- __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18428+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18429+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18430+
18431+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18432+ __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18433+
18434+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18435+ __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18436
18437 #else /* !CC_HAVE_ASM_GOTO */
18438
18439-#define __GEN_RMWcc(fullop, var, cc, ...) \
18440+#ifdef CONFIG_PAX_REFCOUNT
18441+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18442+do { \
18443+ char c; \
18444+ asm volatile (fullop \
18445+ ";jno 0f\n" \
18446+ fullantiop \
18447+ ";int $4\n0:\n" \
18448+ _ASM_EXTABLE(0b, 0b) \
18449+ "; set" cc " %1" \
18450+ : "+m" (var), "=qm" (c) \
18451+ : __VA_ARGS__ : "memory"); \
18452+ return c != 0; \
18453+} while (0)
18454+#else
18455+#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18456+do { \
18457+ char c; \
18458+ asm volatile (fullop "; set" cc " %1" \
18459+ : "+m" (var), "=qm" (c) \
18460+ : __VA_ARGS__ : "memory"); \
18461+ return c != 0; \
18462+} while (0)
18463+#endif
18464+
18465+#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18466 do { \
18467 char c; \
18468 asm volatile (fullop "; set" cc " %1" \
18469@@ -30,11 +88,17 @@ do { \
18470 return c != 0; \
18471 } while (0)
18472
18473-#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18474- __GEN_RMWcc(op " " arg0, var, cc)
18475+#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18476+ __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18477+
18478+#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18479+ __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18480+
18481+#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18482+ __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18483
18484-#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18485- __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18486+#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18487+ __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18488
18489 #endif /* CC_HAVE_ASM_GOTO */
18490
18491diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18492index cad82c9..2e5c5c1 100644
18493--- a/arch/x86/include/asm/rwsem.h
18494+++ b/arch/x86/include/asm/rwsem.h
18495@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18496 {
18497 asm volatile("# beginning down_read\n\t"
18498 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18499+
18500+#ifdef CONFIG_PAX_REFCOUNT
18501+ "jno 0f\n"
18502+ LOCK_PREFIX _ASM_DEC "(%1)\n"
18503+ "int $4\n0:\n"
18504+ _ASM_EXTABLE(0b, 0b)
18505+#endif
18506+
18507 /* adds 0x00000001 */
18508 " jns 1f\n"
18509 " call call_rwsem_down_read_failed\n"
18510@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18511 "1:\n\t"
18512 " mov %1,%2\n\t"
18513 " add %3,%2\n\t"
18514+
18515+#ifdef CONFIG_PAX_REFCOUNT
18516+ "jno 0f\n"
18517+ "sub %3,%2\n"
18518+ "int $4\n0:\n"
18519+ _ASM_EXTABLE(0b, 0b)
18520+#endif
18521+
18522 " jle 2f\n\t"
18523 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18524 " jnz 1b\n\t"
18525@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18526 long tmp;
18527 asm volatile("# beginning down_write\n\t"
18528 LOCK_PREFIX " xadd %1,(%2)\n\t"
18529+
18530+#ifdef CONFIG_PAX_REFCOUNT
18531+ "jno 0f\n"
18532+ "mov %1,(%2)\n"
18533+ "int $4\n0:\n"
18534+ _ASM_EXTABLE(0b, 0b)
18535+#endif
18536+
18537 /* adds 0xffff0001, returns the old value */
18538 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18539 /* was the active mask 0 before? */
18540@@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18541 long tmp;
18542 asm volatile("# beginning __up_read\n\t"
18543 LOCK_PREFIX " xadd %1,(%2)\n\t"
18544+
18545+#ifdef CONFIG_PAX_REFCOUNT
18546+ "jno 0f\n"
18547+ "mov %1,(%2)\n"
18548+ "int $4\n0:\n"
18549+ _ASM_EXTABLE(0b, 0b)
18550+#endif
18551+
18552 /* subtracts 1, returns the old value */
18553 " jns 1f\n\t"
18554 " call call_rwsem_wake\n" /* expects old value in %edx */
18555@@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18556 long tmp;
18557 asm volatile("# beginning __up_write\n\t"
18558 LOCK_PREFIX " xadd %1,(%2)\n\t"
18559+
18560+#ifdef CONFIG_PAX_REFCOUNT
18561+ "jno 0f\n"
18562+ "mov %1,(%2)\n"
18563+ "int $4\n0:\n"
18564+ _ASM_EXTABLE(0b, 0b)
18565+#endif
18566+
18567 /* subtracts 0xffff0001, returns the old value */
18568 " jns 1f\n\t"
18569 " call call_rwsem_wake\n" /* expects old value in %edx */
18570@@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18571 {
18572 asm volatile("# beginning __downgrade_write\n\t"
18573 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18574+
18575+#ifdef CONFIG_PAX_REFCOUNT
18576+ "jno 0f\n"
18577+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18578+ "int $4\n0:\n"
18579+ _ASM_EXTABLE(0b, 0b)
18580+#endif
18581+
18582 /*
18583 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18584 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18585@@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18586 */
18587 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18588 {
18589- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18590+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18591+
18592+#ifdef CONFIG_PAX_REFCOUNT
18593+ "jno 0f\n"
18594+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
18595+ "int $4\n0:\n"
18596+ _ASM_EXTABLE(0b, 0b)
18597+#endif
18598+
18599 : "+m" (sem->count)
18600 : "er" (delta));
18601 }
18602@@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18603 */
18604 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18605 {
18606- return delta + xadd(&sem->count, delta);
18607+ return delta + xadd_check_overflow(&sem->count, delta);
18608 }
18609
18610 #endif /* __KERNEL__ */
18611diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18612index 6f1c3a8..7744f19 100644
18613--- a/arch/x86/include/asm/segment.h
18614+++ b/arch/x86/include/asm/segment.h
18615@@ -64,10 +64,15 @@
18616 * 26 - ESPFIX small SS
18617 * 27 - per-cpu [ offset to per-cpu data area ]
18618 * 28 - stack_canary-20 [ for stack protector ]
18619- * 29 - unused
18620- * 30 - unused
18621+ * 29 - PCI BIOS CS
18622+ * 30 - PCI BIOS DS
18623 * 31 - TSS for double fault handler
18624 */
18625+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18626+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18627+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18628+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18629+
18630 #define GDT_ENTRY_TLS_MIN 6
18631 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18632
18633@@ -79,6 +84,8 @@
18634
18635 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18636
18637+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18638+
18639 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18640
18641 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18642@@ -104,6 +111,12 @@
18643 #define __KERNEL_STACK_CANARY 0
18644 #endif
18645
18646+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18647+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18648+
18649+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18650+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18651+
18652 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18653
18654 /*
18655@@ -141,7 +154,7 @@
18656 */
18657
18658 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18659-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18660+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18661
18662
18663 #else
18664@@ -165,6 +178,8 @@
18665 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18666 #define __USER32_DS __USER_DS
18667
18668+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18669+
18670 #define GDT_ENTRY_TSS 8 /* needs two entries */
18671 #define GDT_ENTRY_LDT 10 /* needs two entries */
18672 #define GDT_ENTRY_TLS_MIN 12
18673@@ -173,6 +188,8 @@
18674 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18675 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18676
18677+#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18678+
18679 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18680 #define FS_TLS 0
18681 #define GS_TLS 1
18682@@ -180,12 +197,14 @@
18683 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18684 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18685
18686-#define GDT_ENTRIES 16
18687+#define GDT_ENTRIES 17
18688
18689 #endif
18690
18691 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18692+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18693 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18694+#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18695 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18696 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18697 #ifndef CONFIG_PARAVIRT
18698@@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18699 {
18700 unsigned long __limit;
18701 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18702- return __limit + 1;
18703+ return __limit;
18704 }
18705
18706 #endif /* !__ASSEMBLY__ */
18707diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18708index 8d3120f..352b440 100644
18709--- a/arch/x86/include/asm/smap.h
18710+++ b/arch/x86/include/asm/smap.h
18711@@ -25,11 +25,40 @@
18712
18713 #include <asm/alternative-asm.h>
18714
18715+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18716+#define ASM_PAX_OPEN_USERLAND \
18717+ 661: jmp 663f; \
18718+ .pushsection .altinstr_replacement, "a" ; \
18719+ 662: pushq %rax; nop; \
18720+ .popsection ; \
18721+ .pushsection .altinstructions, "a" ; \
18722+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18723+ .popsection ; \
18724+ call __pax_open_userland; \
18725+ popq %rax; \
18726+ 663:
18727+
18728+#define ASM_PAX_CLOSE_USERLAND \
18729+ 661: jmp 663f; \
18730+ .pushsection .altinstr_replacement, "a" ; \
18731+ 662: pushq %rax; nop; \
18732+ .popsection; \
18733+ .pushsection .altinstructions, "a" ; \
18734+ altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18735+ .popsection; \
18736+ call __pax_close_userland; \
18737+ popq %rax; \
18738+ 663:
18739+#else
18740+#define ASM_PAX_OPEN_USERLAND
18741+#define ASM_PAX_CLOSE_USERLAND
18742+#endif
18743+
18744 #ifdef CONFIG_X86_SMAP
18745
18746 #define ASM_CLAC \
18747 661: ASM_NOP3 ; \
18748- .pushsection .altinstr_replacement, "ax" ; \
18749+ .pushsection .altinstr_replacement, "a" ; \
18750 662: __ASM_CLAC ; \
18751 .popsection ; \
18752 .pushsection .altinstructions, "a" ; \
18753@@ -38,7 +67,7 @@
18754
18755 #define ASM_STAC \
18756 661: ASM_NOP3 ; \
18757- .pushsection .altinstr_replacement, "ax" ; \
18758+ .pushsection .altinstr_replacement, "a" ; \
18759 662: __ASM_STAC ; \
18760 .popsection ; \
18761 .pushsection .altinstructions, "a" ; \
18762@@ -56,6 +85,37 @@
18763
18764 #include <asm/alternative.h>
18765
18766+#define __HAVE_ARCH_PAX_OPEN_USERLAND
18767+#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18768+
18769+extern void __pax_open_userland(void);
18770+static __always_inline unsigned long pax_open_userland(void)
18771+{
18772+
18773+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18774+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18775+ :
18776+ : [open] "i" (__pax_open_userland)
18777+ : "memory", "rax");
18778+#endif
18779+
18780+ return 0;
18781+}
18782+
18783+extern void __pax_close_userland(void);
18784+static __always_inline unsigned long pax_close_userland(void)
18785+{
18786+
18787+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18788+ asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18789+ :
18790+ : [close] "i" (__pax_close_userland)
18791+ : "memory", "rax");
18792+#endif
18793+
18794+ return 0;
18795+}
18796+
18797 #ifdef CONFIG_X86_SMAP
18798
18799 static __always_inline void clac(void)
18800diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18801index 4137890..03fa172 100644
18802--- a/arch/x86/include/asm/smp.h
18803+++ b/arch/x86/include/asm/smp.h
18804@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18805 /* cpus sharing the last level cache: */
18806 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18807 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18808-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18809+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18810
18811 static inline struct cpumask *cpu_sibling_mask(int cpu)
18812 {
18813@@ -79,7 +79,7 @@ struct smp_ops {
18814
18815 void (*send_call_func_ipi)(const struct cpumask *mask);
18816 void (*send_call_func_single_ipi)(int cpu);
18817-};
18818+} __no_const;
18819
18820 /* Globals due to paravirt */
18821 extern void set_cpu_sibling_map(int cpu);
18822@@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18823 extern int safe_smp_processor_id(void);
18824
18825 #elif defined(CONFIG_X86_64_SMP)
18826-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18827-
18828-#define stack_smp_processor_id() \
18829-({ \
18830- struct thread_info *ti; \
18831- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18832- ti->cpu; \
18833-})
18834+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18835+#define stack_smp_processor_id() raw_smp_processor_id()
18836 #define safe_smp_processor_id() smp_processor_id()
18837
18838 #endif
18839diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18840index bf156de..1a782ab 100644
18841--- a/arch/x86/include/asm/spinlock.h
18842+++ b/arch/x86/include/asm/spinlock.h
18843@@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18844 static inline void arch_read_lock(arch_rwlock_t *rw)
18845 {
18846 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18847+
18848+#ifdef CONFIG_PAX_REFCOUNT
18849+ "jno 0f\n"
18850+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18851+ "int $4\n0:\n"
18852+ _ASM_EXTABLE(0b, 0b)
18853+#endif
18854+
18855 "jns 1f\n"
18856 "call __read_lock_failed\n\t"
18857 "1:\n"
18858@@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18859 static inline void arch_write_lock(arch_rwlock_t *rw)
18860 {
18861 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18862+
18863+#ifdef CONFIG_PAX_REFCOUNT
18864+ "jno 0f\n"
18865+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18866+ "int $4\n0:\n"
18867+ _ASM_EXTABLE(0b, 0b)
18868+#endif
18869+
18870 "jz 1f\n"
18871 "call __write_lock_failed\n\t"
18872 "1:\n"
18873@@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18874
18875 static inline void arch_read_unlock(arch_rwlock_t *rw)
18876 {
18877- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18878+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18879+
18880+#ifdef CONFIG_PAX_REFCOUNT
18881+ "jno 0f\n"
18882+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18883+ "int $4\n0:\n"
18884+ _ASM_EXTABLE(0b, 0b)
18885+#endif
18886+
18887 :"+m" (rw->lock) : : "memory");
18888 }
18889
18890 static inline void arch_write_unlock(arch_rwlock_t *rw)
18891 {
18892- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18893+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18894+
18895+#ifdef CONFIG_PAX_REFCOUNT
18896+ "jno 0f\n"
18897+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18898+ "int $4\n0:\n"
18899+ _ASM_EXTABLE(0b, 0b)
18900+#endif
18901+
18902 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18903 }
18904
18905diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18906index 6a99859..03cb807 100644
18907--- a/arch/x86/include/asm/stackprotector.h
18908+++ b/arch/x86/include/asm/stackprotector.h
18909@@ -47,7 +47,7 @@
18910 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18911 */
18912 #define GDT_STACK_CANARY_INIT \
18913- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18914+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18915
18916 /*
18917 * Initialize the stackprotector canary value.
18918@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18919
18920 static inline void load_stack_canary_segment(void)
18921 {
18922-#ifdef CONFIG_X86_32
18923+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18924 asm volatile ("mov %0, %%gs" : : "r" (0));
18925 #endif
18926 }
18927diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18928index 70bbe39..4ae2bd4 100644
18929--- a/arch/x86/include/asm/stacktrace.h
18930+++ b/arch/x86/include/asm/stacktrace.h
18931@@ -11,28 +11,20 @@
18932
18933 extern int kstack_depth_to_print;
18934
18935-struct thread_info;
18936+struct task_struct;
18937 struct stacktrace_ops;
18938
18939-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18940- unsigned long *stack,
18941- unsigned long bp,
18942- const struct stacktrace_ops *ops,
18943- void *data,
18944- unsigned long *end,
18945- int *graph);
18946+typedef unsigned long walk_stack_t(struct task_struct *task,
18947+ void *stack_start,
18948+ unsigned long *stack,
18949+ unsigned long bp,
18950+ const struct stacktrace_ops *ops,
18951+ void *data,
18952+ unsigned long *end,
18953+ int *graph);
18954
18955-extern unsigned long
18956-print_context_stack(struct thread_info *tinfo,
18957- unsigned long *stack, unsigned long bp,
18958- const struct stacktrace_ops *ops, void *data,
18959- unsigned long *end, int *graph);
18960-
18961-extern unsigned long
18962-print_context_stack_bp(struct thread_info *tinfo,
18963- unsigned long *stack, unsigned long bp,
18964- const struct stacktrace_ops *ops, void *data,
18965- unsigned long *end, int *graph);
18966+extern walk_stack_t print_context_stack;
18967+extern walk_stack_t print_context_stack_bp;
18968
18969 /* Generic stack tracer with callbacks */
18970
18971@@ -40,7 +32,7 @@ struct stacktrace_ops {
18972 void (*address)(void *data, unsigned long address, int reliable);
18973 /* On negative return stop dumping */
18974 int (*stack)(void *data, char *name);
18975- walk_stack_t walk_stack;
18976+ walk_stack_t *walk_stack;
18977 };
18978
18979 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18980diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18981index d7f3b3b..3cc39f1 100644
18982--- a/arch/x86/include/asm/switch_to.h
18983+++ b/arch/x86/include/asm/switch_to.h
18984@@ -108,7 +108,7 @@ do { \
18985 "call __switch_to\n\t" \
18986 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18987 __switch_canary \
18988- "movq %P[thread_info](%%rsi),%%r8\n\t" \
18989+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18990 "movq %%rax,%%rdi\n\t" \
18991 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18992 "jnz ret_from_fork\n\t" \
18993@@ -119,7 +119,7 @@ do { \
18994 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18995 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18996 [_tif_fork] "i" (_TIF_FORK), \
18997- [thread_info] "i" (offsetof(struct task_struct, stack)), \
18998+ [thread_info] "m" (current_tinfo), \
18999 [current_task] "m" (current_task) \
19000 __switch_canary_iparam \
19001 : "memory", "cc" __EXTRA_CLOBBER)
19002diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19003index 3ba3de4..6c113b2 100644
19004--- a/arch/x86/include/asm/thread_info.h
19005+++ b/arch/x86/include/asm/thread_info.h
19006@@ -10,6 +10,7 @@
19007 #include <linux/compiler.h>
19008 #include <asm/page.h>
19009 #include <asm/types.h>
19010+#include <asm/percpu.h>
19011
19012 /*
19013 * low level task data that entry.S needs immediate access to
19014@@ -23,7 +24,6 @@ struct exec_domain;
19015 #include <linux/atomic.h>
19016
19017 struct thread_info {
19018- struct task_struct *task; /* main task structure */
19019 struct exec_domain *exec_domain; /* execution domain */
19020 __u32 flags; /* low level flags */
19021 __u32 status; /* thread synchronous flags */
19022@@ -32,19 +32,13 @@ struct thread_info {
19023 mm_segment_t addr_limit;
19024 struct restart_block restart_block;
19025 void __user *sysenter_return;
19026-#ifdef CONFIG_X86_32
19027- unsigned long previous_esp; /* ESP of the previous stack in
19028- case of nested (IRQ) stacks
19029- */
19030- __u8 supervisor_stack[0];
19031-#endif
19032+ unsigned long lowest_stack;
19033 unsigned int sig_on_uaccess_error:1;
19034 unsigned int uaccess_err:1; /* uaccess failed */
19035 };
19036
19037-#define INIT_THREAD_INFO(tsk) \
19038+#define INIT_THREAD_INFO \
19039 { \
19040- .task = &tsk, \
19041 .exec_domain = &default_exec_domain, \
19042 .flags = 0, \
19043 .cpu = 0, \
19044@@ -55,7 +49,7 @@ struct thread_info {
19045 }, \
19046 }
19047
19048-#define init_thread_info (init_thread_union.thread_info)
19049+#define init_thread_info (init_thread_union.stack)
19050 #define init_stack (init_thread_union.stack)
19051
19052 #else /* !__ASSEMBLY__ */
19053@@ -95,6 +89,7 @@ struct thread_info {
19054 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19055 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19056 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19057+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19058
19059 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19060 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19061@@ -118,17 +113,18 @@ struct thread_info {
19062 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19063 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19064 #define _TIF_X32 (1 << TIF_X32)
19065+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19066
19067 /* work to do in syscall_trace_enter() */
19068 #define _TIF_WORK_SYSCALL_ENTRY \
19069 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19070 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19071- _TIF_NOHZ)
19072+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19073
19074 /* work to do in syscall_trace_leave() */
19075 #define _TIF_WORK_SYSCALL_EXIT \
19076 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19077- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19078+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19079
19080 /* work to do on interrupt/exception return */
19081 #define _TIF_WORK_MASK \
19082@@ -139,7 +135,7 @@ struct thread_info {
19083 /* work to do on any return to user space */
19084 #define _TIF_ALLWORK_MASK \
19085 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19086- _TIF_NOHZ)
19087+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
19088
19089 /* Only used for 64 bit */
19090 #define _TIF_DO_NOTIFY_MASK \
19091@@ -153,45 +149,40 @@ struct thread_info {
19092 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
19093 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19094
19095-#ifdef CONFIG_X86_32
19096-
19097-#define STACK_WARN (THREAD_SIZE/8)
19098-/*
19099- * macros/functions for gaining access to the thread information structure
19100- *
19101- * preempt_count needs to be 1 initially, until the scheduler is functional.
19102- */
19103-#ifndef __ASSEMBLY__
19104-
19105-
19106-/* how to get the current stack pointer from C */
19107-register unsigned long current_stack_pointer asm("esp") __used;
19108-
19109-/* how to get the thread information struct from C */
19110-static inline struct thread_info *current_thread_info(void)
19111-{
19112- return (struct thread_info *)
19113- (current_stack_pointer & ~(THREAD_SIZE - 1));
19114-}
19115-
19116-#else /* !__ASSEMBLY__ */
19117-
19118+#ifdef __ASSEMBLY__
19119 /* how to get the thread information struct from ASM */
19120 #define GET_THREAD_INFO(reg) \
19121- movl $-THREAD_SIZE, reg; \
19122- andl %esp, reg
19123+ mov PER_CPU_VAR(current_tinfo), reg
19124
19125 /* use this one if reg already contains %esp */
19126-#define GET_THREAD_INFO_WITH_ESP(reg) \
19127- andl $-THREAD_SIZE, reg
19128+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
19129+#else
19130+/* how to get the thread information struct from C */
19131+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19132+
19133+static __always_inline struct thread_info *current_thread_info(void)
19134+{
19135+ return this_cpu_read_stable(current_tinfo);
19136+}
19137+#endif
19138+
19139+#ifdef CONFIG_X86_32
19140+
19141+#define STACK_WARN (THREAD_SIZE/8)
19142+/*
19143+ * macros/functions for gaining access to the thread information structure
19144+ *
19145+ * preempt_count needs to be 1 initially, until the scheduler is functional.
19146+ */
19147+#ifndef __ASSEMBLY__
19148+
19149+/* how to get the current stack pointer from C */
19150+register unsigned long current_stack_pointer asm("esp") __used;
19151
19152 #endif
19153
19154 #else /* X86_32 */
19155
19156-#include <asm/percpu.h>
19157-#define KERNEL_STACK_OFFSET (5*8)
19158-
19159 /*
19160 * macros/functions for gaining access to the thread information structure
19161 * preempt_count needs to be 1 initially, until the scheduler is functional.
19162@@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
19163 #ifndef __ASSEMBLY__
19164 DECLARE_PER_CPU(unsigned long, kernel_stack);
19165
19166-static inline struct thread_info *current_thread_info(void)
19167-{
19168- struct thread_info *ti;
19169- ti = (void *)(this_cpu_read_stable(kernel_stack) +
19170- KERNEL_STACK_OFFSET - THREAD_SIZE);
19171- return ti;
19172-}
19173-
19174-#else /* !__ASSEMBLY__ */
19175-
19176-/* how to get the thread information struct from ASM */
19177-#define GET_THREAD_INFO(reg) \
19178- movq PER_CPU_VAR(kernel_stack),reg ; \
19179- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
19180-
19181-/*
19182- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19183- * a certain register (to be used in assembler memory operands).
19184- */
19185-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19186-
19187+/* how to get the current stack pointer from C */
19188+register unsigned long current_stack_pointer asm("rsp") __used;
19189 #endif
19190
19191 #endif /* !X86_32 */
19192@@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
19193 extern void arch_task_cache_init(void);
19194 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19195 extern void arch_release_task_struct(struct task_struct *tsk);
19196+
19197+#define __HAVE_THREAD_FUNCTIONS
19198+#define task_thread_info(task) (&(task)->tinfo)
19199+#define task_stack_page(task) ((task)->stack)
19200+#define setup_thread_stack(p, org) do {} while (0)
19201+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19202+
19203 #endif
19204 #endif /* _ASM_X86_THREAD_INFO_H */
19205diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19206index e6d90ba..f81f114 100644
19207--- a/arch/x86/include/asm/tlbflush.h
19208+++ b/arch/x86/include/asm/tlbflush.h
19209@@ -17,18 +17,44 @@
19210
19211 static inline void __native_flush_tlb(void)
19212 {
19213+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19214+ u64 descriptor[2];
19215+
19216+ descriptor[0] = PCID_KERNEL;
19217+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19218+ return;
19219+ }
19220+
19221+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19222+ if (static_cpu_has(X86_FEATURE_PCID)) {
19223+ unsigned int cpu = raw_get_cpu();
19224+
19225+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19226+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19227+ raw_put_cpu_no_resched();
19228+ return;
19229+ }
19230+#endif
19231+
19232 native_write_cr3(native_read_cr3());
19233 }
19234
19235 static inline void __native_flush_tlb_global_irq_disabled(void)
19236 {
19237- unsigned long cr4;
19238+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19239+ u64 descriptor[2];
19240
19241- cr4 = native_read_cr4();
19242- /* clear PGE */
19243- native_write_cr4(cr4 & ~X86_CR4_PGE);
19244- /* write old PGE again and flush TLBs */
19245- native_write_cr4(cr4);
19246+ descriptor[0] = PCID_KERNEL;
19247+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19248+ } else {
19249+ unsigned long cr4;
19250+
19251+ cr4 = native_read_cr4();
19252+ /* clear PGE */
19253+ native_write_cr4(cr4 & ~X86_CR4_PGE);
19254+ /* write old PGE again and flush TLBs */
19255+ native_write_cr4(cr4);
19256+ }
19257 }
19258
19259 static inline void __native_flush_tlb_global(void)
19260@@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19261
19262 static inline void __native_flush_tlb_single(unsigned long addr)
19263 {
19264+ if (static_cpu_has(X86_FEATURE_INVPCID)) {
19265+ u64 descriptor[2];
19266+
19267+ descriptor[0] = PCID_KERNEL;
19268+ descriptor[1] = addr;
19269+
19270+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19271+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19272+ if (addr < TASK_SIZE_MAX)
19273+ descriptor[1] += pax_user_shadow_base;
19274+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19275+ }
19276+
19277+ descriptor[0] = PCID_USER;
19278+ descriptor[1] = addr;
19279+#endif
19280+
19281+ asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19282+ return;
19283+ }
19284+
19285+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19286+ if (static_cpu_has(X86_FEATURE_PCID)) {
19287+ unsigned int cpu = raw_get_cpu();
19288+
19289+ native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19290+ asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19291+ native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19292+ raw_put_cpu_no_resched();
19293+
19294+ if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19295+ addr += pax_user_shadow_base;
19296+ }
19297+#endif
19298+
19299 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19300 }
19301
19302diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19303index 8ec57c0..451bcfc 100644
19304--- a/arch/x86/include/asm/uaccess.h
19305+++ b/arch/x86/include/asm/uaccess.h
19306@@ -7,6 +7,7 @@
19307 #include <linux/compiler.h>
19308 #include <linux/thread_info.h>
19309 #include <linux/string.h>
19310+#include <linux/spinlock.h>
19311 #include <asm/asm.h>
19312 #include <asm/page.h>
19313 #include <asm/smap.h>
19314@@ -29,7 +30,12 @@
19315
19316 #define get_ds() (KERNEL_DS)
19317 #define get_fs() (current_thread_info()->addr_limit)
19318+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19319+void __set_fs(mm_segment_t x);
19320+void set_fs(mm_segment_t x);
19321+#else
19322 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19323+#endif
19324
19325 #define segment_eq(a, b) ((a).seg == (b).seg)
19326
19327@@ -77,8 +83,34 @@
19328 * checks that the pointer is in the user space range - after calling
19329 * this function, memory access functions may still return -EFAULT.
19330 */
19331-#define access_ok(type, addr, size) \
19332- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19333+extern int _cond_resched(void);
19334+#define access_ok_noprefault(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
19335+#define access_ok(type, addr, size) \
19336+({ \
19337+ long __size = size; \
19338+ unsigned long __addr = (unsigned long)addr; \
19339+ unsigned long __addr_ao = __addr & PAGE_MASK; \
19340+ unsigned long __end_ao = __addr + __size - 1; \
19341+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19342+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19343+ while(__addr_ao <= __end_ao) { \
19344+ char __c_ao; \
19345+ __addr_ao += PAGE_SIZE; \
19346+ if (__size > PAGE_SIZE) \
19347+ _cond_resched(); \
19348+ if (__get_user(__c_ao, (char __user *)__addr)) \
19349+ break; \
19350+ if (type != VERIFY_WRITE) { \
19351+ __addr = __addr_ao; \
19352+ continue; \
19353+ } \
19354+ if (__put_user(__c_ao, (char __user *)__addr)) \
19355+ break; \
19356+ __addr = __addr_ao; \
19357+ } \
19358+ } \
19359+ __ret_ao; \
19360+})
19361
19362 /*
19363 * The exception table consists of pairs of addresses relative to the
19364@@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19365 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19366 __chk_user_ptr(ptr); \
19367 might_fault(); \
19368+ pax_open_userland(); \
19369 asm volatile("call __get_user_%P3" \
19370 : "=a" (__ret_gu), "=r" (__val_gu) \
19371 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19372 (x) = (__typeof__(*(ptr))) __val_gu; \
19373+ pax_close_userland(); \
19374 __ret_gu; \
19375 })
19376
19377@@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19378 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19379 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19380
19381-
19382+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19383+#define __copyuser_seg "gs;"
19384+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19385+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19386+#else
19387+#define __copyuser_seg
19388+#define __COPYUSER_SET_ES
19389+#define __COPYUSER_RESTORE_ES
19390+#endif
19391
19392 #ifdef CONFIG_X86_32
19393 #define __put_user_asm_u64(x, addr, err, errret) \
19394 asm volatile(ASM_STAC "\n" \
19395- "1: movl %%eax,0(%2)\n" \
19396- "2: movl %%edx,4(%2)\n" \
19397+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19398+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19399 "3: " ASM_CLAC "\n" \
19400 ".section .fixup,\"ax\"\n" \
19401 "4: movl %3,%0\n" \
19402@@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19403
19404 #define __put_user_asm_ex_u64(x, addr) \
19405 asm volatile(ASM_STAC "\n" \
19406- "1: movl %%eax,0(%1)\n" \
19407- "2: movl %%edx,4(%1)\n" \
19408+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19409+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19410 "3: " ASM_CLAC "\n" \
19411 _ASM_EXTABLE_EX(1b, 2b) \
19412 _ASM_EXTABLE_EX(2b, 3b) \
19413@@ -249,7 +291,8 @@ extern void __put_user_8(void);
19414 __typeof__(*(ptr)) __pu_val; \
19415 __chk_user_ptr(ptr); \
19416 might_fault(); \
19417- __pu_val = x; \
19418+ __pu_val = (x); \
19419+ pax_open_userland(); \
19420 switch (sizeof(*(ptr))) { \
19421 case 1: \
19422 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19423@@ -267,6 +310,7 @@ extern void __put_user_8(void);
19424 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19425 break; \
19426 } \
19427+ pax_close_userland(); \
19428 __ret_pu; \
19429 })
19430
19431@@ -347,8 +391,10 @@ do { \
19432 } while (0)
19433
19434 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19435+do { \
19436+ pax_open_userland(); \
19437 asm volatile(ASM_STAC "\n" \
19438- "1: mov"itype" %2,%"rtype"1\n" \
19439+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19440 "2: " ASM_CLAC "\n" \
19441 ".section .fixup,\"ax\"\n" \
19442 "3: mov %3,%0\n" \
19443@@ -356,8 +402,10 @@ do { \
19444 " jmp 2b\n" \
19445 ".previous\n" \
19446 _ASM_EXTABLE(1b, 3b) \
19447- : "=r" (err), ltype(x) \
19448- : "m" (__m(addr)), "i" (errret), "0" (err))
19449+ : "=r" (err), ltype (x) \
19450+ : "m" (__m(addr)), "i" (errret), "0" (err)); \
19451+ pax_close_userland(); \
19452+} while (0)
19453
19454 #define __get_user_size_ex(x, ptr, size) \
19455 do { \
19456@@ -381,7 +429,7 @@ do { \
19457 } while (0)
19458
19459 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19460- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19461+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19462 "2:\n" \
19463 _ASM_EXTABLE_EX(1b, 2b) \
19464 : ltype(x) : "m" (__m(addr)))
19465@@ -398,13 +446,24 @@ do { \
19466 int __gu_err; \
19467 unsigned long __gu_val; \
19468 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19469- (x) = (__force __typeof__(*(ptr)))__gu_val; \
19470+ (x) = (__typeof__(*(ptr)))__gu_val; \
19471 __gu_err; \
19472 })
19473
19474 /* FIXME: this hack is definitely wrong -AK */
19475 struct __large_struct { unsigned long buf[100]; };
19476-#define __m(x) (*(struct __large_struct __user *)(x))
19477+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19478+#define ____m(x) \
19479+({ \
19480+ unsigned long ____x = (unsigned long)(x); \
19481+ if (____x < pax_user_shadow_base) \
19482+ ____x += pax_user_shadow_base; \
19483+ (typeof(x))____x; \
19484+})
19485+#else
19486+#define ____m(x) (x)
19487+#endif
19488+#define __m(x) (*(struct __large_struct __user *)____m(x))
19489
19490 /*
19491 * Tell gcc we read from memory instead of writing: this is because
19492@@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
19493 * aliasing issues.
19494 */
19495 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19496+do { \
19497+ pax_open_userland(); \
19498 asm volatile(ASM_STAC "\n" \
19499- "1: mov"itype" %"rtype"1,%2\n" \
19500+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19501 "2: " ASM_CLAC "\n" \
19502 ".section .fixup,\"ax\"\n" \
19503 "3: mov %3,%0\n" \
19504@@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
19505 ".previous\n" \
19506 _ASM_EXTABLE(1b, 3b) \
19507 : "=r"(err) \
19508- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19509+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19510+ pax_close_userland(); \
19511+} while (0)
19512
19513 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19514- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19515+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19516 "2:\n" \
19517 _ASM_EXTABLE_EX(1b, 2b) \
19518 : : ltype(x), "m" (__m(addr)))
19519@@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19520 */
19521 #define uaccess_try do { \
19522 current_thread_info()->uaccess_err = 0; \
19523+ pax_open_userland(); \
19524 stac(); \
19525 barrier();
19526
19527 #define uaccess_catch(err) \
19528 clac(); \
19529+ pax_close_userland(); \
19530 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19531 } while (0)
19532
19533@@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19534 * On error, the variable @x is set to zero.
19535 */
19536
19537+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19538+#define __get_user(x, ptr) get_user((x), (ptr))
19539+#else
19540 #define __get_user(x, ptr) \
19541 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19542+#endif
19543
19544 /**
19545 * __put_user: - Write a simple value into user space, with less checking.
19546@@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19547 * Returns zero on success, or -EFAULT on error.
19548 */
19549
19550+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19551+#define __put_user(x, ptr) put_user((x), (ptr))
19552+#else
19553 #define __put_user(x, ptr) \
19554 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19555+#endif
19556
19557 #define __get_user_unaligned __get_user
19558 #define __put_user_unaligned __put_user
19559@@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19560 #define get_user_ex(x, ptr) do { \
19561 unsigned long __gue_val; \
19562 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19563- (x) = (__force __typeof__(*(ptr)))__gue_val; \
19564+ (x) = (__typeof__(*(ptr)))__gue_val; \
19565 } while (0)
19566
19567 #define put_user_try uaccess_try
19568@@ -536,17 +609,6 @@ extern struct movsl_mask {
19569
19570 #define ARCH_HAS_NOCACHE_UACCESS 1
19571
19572-#ifdef CONFIG_X86_32
19573-# include <asm/uaccess_32.h>
19574-#else
19575-# include <asm/uaccess_64.h>
19576-#endif
19577-
19578-unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19579- unsigned n);
19580-unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19581- unsigned n);
19582-
19583 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19584 # define copy_user_diag __compiletime_error
19585 #else
19586@@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19587 extern void copy_user_diag("copy_from_user() buffer size is too small")
19588 copy_from_user_overflow(void);
19589 extern void copy_user_diag("copy_to_user() buffer size is too small")
19590-copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19591+copy_to_user_overflow(void);
19592
19593 #undef copy_user_diag
19594
19595@@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19596
19597 extern void
19598 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19599-__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19600+__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19601 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19602
19603 #else
19604@@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19605
19606 #endif
19607
19608+#ifdef CONFIG_X86_32
19609+# include <asm/uaccess_32.h>
19610+#else
19611+# include <asm/uaccess_64.h>
19612+#endif
19613+
19614 static inline unsigned long __must_check
19615 copy_from_user(void *to, const void __user *from, unsigned long n)
19616 {
19617- int sz = __compiletime_object_size(to);
19618+ size_t sz = __compiletime_object_size(to);
19619
19620 might_fault();
19621
19622@@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19623 * case, and do only runtime checking for non-constant sizes.
19624 */
19625
19626- if (likely(sz < 0 || sz >= n))
19627- n = _copy_from_user(to, from, n);
19628- else if(__builtin_constant_p(n))
19629- copy_from_user_overflow();
19630- else
19631- __copy_from_user_overflow(sz, n);
19632+ if (likely(sz != (size_t)-1 && sz < n)) {
19633+ if(__builtin_constant_p(n))
19634+ copy_from_user_overflow();
19635+ else
19636+ __copy_from_user_overflow(sz, n);
19637+ } if (access_ok(VERIFY_READ, from, n))
19638+ n = __copy_from_user(to, from, n);
19639+ else if ((long)n > 0)
19640+ memset(to, 0, n);
19641
19642 return n;
19643 }
19644@@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19645 static inline unsigned long __must_check
19646 copy_to_user(void __user *to, const void *from, unsigned long n)
19647 {
19648- int sz = __compiletime_object_size(from);
19649+ size_t sz = __compiletime_object_size(from);
19650
19651 might_fault();
19652
19653 /* See the comment in copy_from_user() above. */
19654- if (likely(sz < 0 || sz >= n))
19655- n = _copy_to_user(to, from, n);
19656- else if(__builtin_constant_p(n))
19657- copy_to_user_overflow();
19658- else
19659- __copy_to_user_overflow(sz, n);
19660+ if (likely(sz != (size_t)-1 && sz < n)) {
19661+ if(__builtin_constant_p(n))
19662+ copy_to_user_overflow();
19663+ else
19664+ __copy_to_user_overflow(sz, n);
19665+ } else if (access_ok(VERIFY_WRITE, to, n))
19666+ n = __copy_to_user(to, from, n);
19667
19668 return n;
19669 }
19670diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19671index 3c03a5d..1071638 100644
19672--- a/arch/x86/include/asm/uaccess_32.h
19673+++ b/arch/x86/include/asm/uaccess_32.h
19674@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19675 static __always_inline unsigned long __must_check
19676 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19677 {
19678+ if ((long)n < 0)
19679+ return n;
19680+
19681+ check_object_size(from, n, true);
19682+
19683 if (__builtin_constant_p(n)) {
19684 unsigned long ret;
19685
19686@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19687 __copy_to_user(void __user *to, const void *from, unsigned long n)
19688 {
19689 might_fault();
19690+
19691 return __copy_to_user_inatomic(to, from, n);
19692 }
19693
19694 static __always_inline unsigned long
19695 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19696 {
19697+ if ((long)n < 0)
19698+ return n;
19699+
19700 /* Avoid zeroing the tail if the copy fails..
19701 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19702 * but as the zeroing behaviour is only significant when n is not
19703@@ -137,6 +146,12 @@ static __always_inline unsigned long
19704 __copy_from_user(void *to, const void __user *from, unsigned long n)
19705 {
19706 might_fault();
19707+
19708+ if ((long)n < 0)
19709+ return n;
19710+
19711+ check_object_size(to, n, false);
19712+
19713 if (__builtin_constant_p(n)) {
19714 unsigned long ret;
19715
19716@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19717 const void __user *from, unsigned long n)
19718 {
19719 might_fault();
19720+
19721+ if ((long)n < 0)
19722+ return n;
19723+
19724 if (__builtin_constant_p(n)) {
19725 unsigned long ret;
19726
19727@@ -181,7 +200,10 @@ static __always_inline unsigned long
19728 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19729 unsigned long n)
19730 {
19731- return __copy_from_user_ll_nocache_nozero(to, from, n);
19732+ if ((long)n < 0)
19733+ return n;
19734+
19735+ return __copy_from_user_ll_nocache_nozero(to, from, n);
19736 }
19737
19738 #endif /* _ASM_X86_UACCESS_32_H */
19739diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19740index 190413d..206c200 100644
19741--- a/arch/x86/include/asm/uaccess_64.h
19742+++ b/arch/x86/include/asm/uaccess_64.h
19743@@ -10,6 +10,9 @@
19744 #include <asm/alternative.h>
19745 #include <asm/cpufeature.h>
19746 #include <asm/page.h>
19747+#include <asm/pgtable.h>
19748+
19749+#define set_fs(x) (current_thread_info()->addr_limit = (x))
19750
19751 /*
19752 * Copy To/From Userspace
19753@@ -17,14 +20,14 @@
19754
19755 /* Handles exceptions in both to and from, but doesn't do access_ok */
19756 __must_check unsigned long
19757-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19758+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19759 __must_check unsigned long
19760-copy_user_generic_string(void *to, const void *from, unsigned len);
19761+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19762 __must_check unsigned long
19763-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19764+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19765
19766 static __always_inline __must_check unsigned long
19767-copy_user_generic(void *to, const void *from, unsigned len)
19768+copy_user_generic(void *to, const void *from, unsigned long len)
19769 {
19770 unsigned ret;
19771
19772@@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19773 }
19774
19775 __must_check unsigned long
19776-copy_in_user(void __user *to, const void __user *from, unsigned len);
19777+copy_in_user(void __user *to, const void __user *from, unsigned long len);
19778
19779 static __always_inline __must_check
19780-int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19781+unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19782 {
19783- int ret = 0;
19784+ size_t sz = __compiletime_object_size(dst);
19785+ unsigned ret = 0;
19786+
19787+ if (size > INT_MAX)
19788+ return size;
19789+
19790+ check_object_size(dst, size, false);
19791+
19792+#ifdef CONFIG_PAX_MEMORY_UDEREF
19793+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19794+ return size;
19795+#endif
19796+
19797+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19798+ if(__builtin_constant_p(size))
19799+ copy_from_user_overflow();
19800+ else
19801+ __copy_from_user_overflow(sz, size);
19802+ return size;
19803+ }
19804
19805 if (!__builtin_constant_p(size))
19806- return copy_user_generic(dst, (__force void *)src, size);
19807+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19808 switch (size) {
19809- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19810+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19811 ret, "b", "b", "=q", 1);
19812 return ret;
19813- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19814+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19815 ret, "w", "w", "=r", 2);
19816 return ret;
19817- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19818+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19819 ret, "l", "k", "=r", 4);
19820 return ret;
19821- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19822+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19823 ret, "q", "", "=r", 8);
19824 return ret;
19825 case 10:
19826- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19827+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19828 ret, "q", "", "=r", 10);
19829 if (unlikely(ret))
19830 return ret;
19831 __get_user_asm(*(u16 *)(8 + (char *)dst),
19832- (u16 __user *)(8 + (char __user *)src),
19833+ (const u16 __user *)(8 + (const char __user *)src),
19834 ret, "w", "w", "=r", 2);
19835 return ret;
19836 case 16:
19837- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19838+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19839 ret, "q", "", "=r", 16);
19840 if (unlikely(ret))
19841 return ret;
19842 __get_user_asm(*(u64 *)(8 + (char *)dst),
19843- (u64 __user *)(8 + (char __user *)src),
19844+ (const u64 __user *)(8 + (const char __user *)src),
19845 ret, "q", "", "=r", 8);
19846 return ret;
19847 default:
19848- return copy_user_generic(dst, (__force void *)src, size);
19849+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19850 }
19851 }
19852
19853 static __always_inline __must_check
19854-int __copy_from_user(void *dst, const void __user *src, unsigned size)
19855+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19856 {
19857 might_fault();
19858 return __copy_from_user_nocheck(dst, src, size);
19859 }
19860
19861 static __always_inline __must_check
19862-int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19863+unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19864 {
19865- int ret = 0;
19866+ size_t sz = __compiletime_object_size(src);
19867+ unsigned ret = 0;
19868+
19869+ if (size > INT_MAX)
19870+ return size;
19871+
19872+ check_object_size(src, size, true);
19873+
19874+#ifdef CONFIG_PAX_MEMORY_UDEREF
19875+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19876+ return size;
19877+#endif
19878+
19879+ if (unlikely(sz != (size_t)-1 && sz < size)) {
19880+ if(__builtin_constant_p(size))
19881+ copy_to_user_overflow();
19882+ else
19883+ __copy_to_user_overflow(sz, size);
19884+ return size;
19885+ }
19886
19887 if (!__builtin_constant_p(size))
19888- return copy_user_generic((__force void *)dst, src, size);
19889+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19890 switch (size) {
19891- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19892+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19893 ret, "b", "b", "iq", 1);
19894 return ret;
19895- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19896+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19897 ret, "w", "w", "ir", 2);
19898 return ret;
19899- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19900+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19901 ret, "l", "k", "ir", 4);
19902 return ret;
19903- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19904+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19905 ret, "q", "", "er", 8);
19906 return ret;
19907 case 10:
19908- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19909+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19910 ret, "q", "", "er", 10);
19911 if (unlikely(ret))
19912 return ret;
19913 asm("":::"memory");
19914- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19915+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19916 ret, "w", "w", "ir", 2);
19917 return ret;
19918 case 16:
19919- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19920+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19921 ret, "q", "", "er", 16);
19922 if (unlikely(ret))
19923 return ret;
19924 asm("":::"memory");
19925- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19926+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19927 ret, "q", "", "er", 8);
19928 return ret;
19929 default:
19930- return copy_user_generic((__force void *)dst, src, size);
19931+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19932 }
19933 }
19934
19935 static __always_inline __must_check
19936-int __copy_to_user(void __user *dst, const void *src, unsigned size)
19937+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19938 {
19939 might_fault();
19940 return __copy_to_user_nocheck(dst, src, size);
19941 }
19942
19943 static __always_inline __must_check
19944-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19945+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19946 {
19947- int ret = 0;
19948+ unsigned ret = 0;
19949
19950 might_fault();
19951+
19952+ if (size > INT_MAX)
19953+ return size;
19954+
19955+#ifdef CONFIG_PAX_MEMORY_UDEREF
19956+ if (!access_ok_noprefault(VERIFY_READ, src, size))
19957+ return size;
19958+ if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19959+ return size;
19960+#endif
19961+
19962 if (!__builtin_constant_p(size))
19963- return copy_user_generic((__force void *)dst,
19964- (__force void *)src, size);
19965+ return copy_user_generic((__force_kernel void *)____m(dst),
19966+ (__force_kernel const void *)____m(src), size);
19967 switch (size) {
19968 case 1: {
19969 u8 tmp;
19970- __get_user_asm(tmp, (u8 __user *)src,
19971+ __get_user_asm(tmp, (const u8 __user *)src,
19972 ret, "b", "b", "=q", 1);
19973 if (likely(!ret))
19974 __put_user_asm(tmp, (u8 __user *)dst,
19975@@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19976 }
19977 case 2: {
19978 u16 tmp;
19979- __get_user_asm(tmp, (u16 __user *)src,
19980+ __get_user_asm(tmp, (const u16 __user *)src,
19981 ret, "w", "w", "=r", 2);
19982 if (likely(!ret))
19983 __put_user_asm(tmp, (u16 __user *)dst,
19984@@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19985
19986 case 4: {
19987 u32 tmp;
19988- __get_user_asm(tmp, (u32 __user *)src,
19989+ __get_user_asm(tmp, (const u32 __user *)src,
19990 ret, "l", "k", "=r", 4);
19991 if (likely(!ret))
19992 __put_user_asm(tmp, (u32 __user *)dst,
19993@@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19994 }
19995 case 8: {
19996 u64 tmp;
19997- __get_user_asm(tmp, (u64 __user *)src,
19998+ __get_user_asm(tmp, (const u64 __user *)src,
19999 ret, "q", "", "=r", 8);
20000 if (likely(!ret))
20001 __put_user_asm(tmp, (u64 __user *)dst,
20002@@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20003 return ret;
20004 }
20005 default:
20006- return copy_user_generic((__force void *)dst,
20007- (__force void *)src, size);
20008+ return copy_user_generic((__force_kernel void *)____m(dst),
20009+ (__force_kernel const void *)____m(src), size);
20010 }
20011 }
20012
20013-static __must_check __always_inline int
20014-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20015+static __must_check __always_inline unsigned long
20016+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20017 {
20018- return __copy_from_user_nocheck(dst, (__force const void *)src, size);
20019+ return __copy_from_user_nocheck(dst, src, size);
20020 }
20021
20022-static __must_check __always_inline int
20023-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20024+static __must_check __always_inline unsigned long
20025+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20026 {
20027- return __copy_to_user_nocheck((__force void *)dst, src, size);
20028+ return __copy_to_user_nocheck(dst, src, size);
20029 }
20030
20031-extern long __copy_user_nocache(void *dst, const void __user *src,
20032- unsigned size, int zerorest);
20033+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20034+ unsigned long size, int zerorest);
20035
20036-static inline int
20037-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20038+static inline unsigned long
20039+__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20040 {
20041 might_fault();
20042+
20043+ if (size > INT_MAX)
20044+ return size;
20045+
20046+#ifdef CONFIG_PAX_MEMORY_UDEREF
20047+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20048+ return size;
20049+#endif
20050+
20051 return __copy_user_nocache(dst, src, size, 1);
20052 }
20053
20054-static inline int
20055+static inline unsigned long
20056 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20057- unsigned size)
20058+ unsigned long size)
20059 {
20060+ if (size > INT_MAX)
20061+ return size;
20062+
20063+#ifdef CONFIG_PAX_MEMORY_UDEREF
20064+ if (!access_ok_noprefault(VERIFY_READ, src, size))
20065+ return size;
20066+#endif
20067+
20068 return __copy_user_nocache(dst, src, size, 0);
20069 }
20070
20071 unsigned long
20072-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20073+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20074
20075 #endif /* _ASM_X86_UACCESS_64_H */
20076diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20077index 5b238981..77fdd78 100644
20078--- a/arch/x86/include/asm/word-at-a-time.h
20079+++ b/arch/x86/include/asm/word-at-a-time.h
20080@@ -11,7 +11,7 @@
20081 * and shift, for example.
20082 */
20083 struct word_at_a_time {
20084- const unsigned long one_bits, high_bits;
20085+ unsigned long one_bits, high_bits;
20086 };
20087
20088 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20089diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20090index 0f1be11..f7542bf 100644
20091--- a/arch/x86/include/asm/x86_init.h
20092+++ b/arch/x86/include/asm/x86_init.h
20093@@ -129,7 +129,7 @@ struct x86_init_ops {
20094 struct x86_init_timers timers;
20095 struct x86_init_iommu iommu;
20096 struct x86_init_pci pci;
20097-};
20098+} __no_const;
20099
20100 /**
20101 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20102@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20103 void (*setup_percpu_clockev)(void);
20104 void (*early_percpu_clock_init)(void);
20105 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20106-};
20107+} __no_const;
20108
20109 struct timespec;
20110
20111@@ -168,7 +168,7 @@ struct x86_platform_ops {
20112 void (*save_sched_clock_state)(void);
20113 void (*restore_sched_clock_state)(void);
20114 void (*apic_post_init)(void);
20115-};
20116+} __no_const;
20117
20118 struct pci_dev;
20119 struct msi_msg;
20120@@ -185,7 +185,7 @@ struct x86_msi_ops {
20121 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20122 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20123 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20124-};
20125+} __no_const;
20126
20127 struct IO_APIC_route_entry;
20128 struct io_apic_irq_attr;
20129@@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20130 unsigned int destination, int vector,
20131 struct io_apic_irq_attr *attr);
20132 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20133-};
20134+} __no_const;
20135
20136 extern struct x86_init_ops x86_init;
20137 extern struct x86_cpuinit_ops x86_cpuinit;
20138diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20139index b913915..4f5a581 100644
20140--- a/arch/x86/include/asm/xen/page.h
20141+++ b/arch/x86/include/asm/xen/page.h
20142@@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
20143 extern struct page *m2p_find_override(unsigned long mfn);
20144 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20145
20146-static inline unsigned long pfn_to_mfn(unsigned long pfn)
20147+static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20148 {
20149 unsigned long mfn;
20150
20151diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20152index 0415cda..3b22adc 100644
20153--- a/arch/x86/include/asm/xsave.h
20154+++ b/arch/x86/include/asm/xsave.h
20155@@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20156 if (unlikely(err))
20157 return -EFAULT;
20158
20159+ pax_open_userland();
20160 __asm__ __volatile__(ASM_STAC "\n"
20161- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20162+ "1:"
20163+ __copyuser_seg
20164+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20165 "2: " ASM_CLAC "\n"
20166 ".section .fixup,\"ax\"\n"
20167 "3: movl $-1,%[err]\n"
20168@@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20169 : [err] "=r" (err)
20170 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20171 : "memory");
20172+ pax_close_userland();
20173 return err;
20174 }
20175
20176 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20177 {
20178 int err;
20179- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20180+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20181 u32 lmask = mask;
20182 u32 hmask = mask >> 32;
20183
20184+ pax_open_userland();
20185 __asm__ __volatile__(ASM_STAC "\n"
20186- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20187+ "1:"
20188+ __copyuser_seg
20189+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20190 "2: " ASM_CLAC "\n"
20191 ".section .fixup,\"ax\"\n"
20192 "3: movl $-1,%[err]\n"
20193@@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20194 : [err] "=r" (err)
20195 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20196 : "memory"); /* memory required? */
20197+ pax_close_userland();
20198 return err;
20199 }
20200
20201diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20202index bbae024..e1528f9 100644
20203--- a/arch/x86/include/uapi/asm/e820.h
20204+++ b/arch/x86/include/uapi/asm/e820.h
20205@@ -63,7 +63,7 @@ struct e820map {
20206 #define ISA_START_ADDRESS 0xa0000
20207 #define ISA_END_ADDRESS 0x100000
20208
20209-#define BIOS_BEGIN 0x000a0000
20210+#define BIOS_BEGIN 0x000c0000
20211 #define BIOS_END 0x00100000
20212
20213 #define BIOS_ROM_BASE 0xffe00000
20214diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20215index 7b0a55a..ad115bf 100644
20216--- a/arch/x86/include/uapi/asm/ptrace-abi.h
20217+++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20218@@ -49,7 +49,6 @@
20219 #define EFLAGS 144
20220 #define RSP 152
20221 #define SS 160
20222-#define ARGOFFSET R11
20223 #endif /* __ASSEMBLY__ */
20224
20225 /* top of stack page */
20226diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20227index 9b0a34e..fc7e553 100644
20228--- a/arch/x86/kernel/Makefile
20229+++ b/arch/x86/kernel/Makefile
20230@@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20231 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20232 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20233 obj-y += probe_roms.o
20234-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20235+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20236 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20237 obj-y += syscall_$(BITS).o
20238 obj-$(CONFIG_X86_64) += vsyscall_64.o
20239diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20240index 6c0b43b..e67bb31 100644
20241--- a/arch/x86/kernel/acpi/boot.c
20242+++ b/arch/x86/kernel/acpi/boot.c
20243@@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20244 * If your system is blacklisted here, but you find that acpi=force
20245 * works for you, please contact linux-acpi@vger.kernel.org
20246 */
20247-static struct dmi_system_id __initdata acpi_dmi_table[] = {
20248+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20249 /*
20250 * Boxes that need ACPI disabled
20251 */
20252@@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20253 };
20254
20255 /* second table for DMI checks that should run after early-quirks */
20256-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20257+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20258 /*
20259 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20260 * which includes some code which overrides all temperature
20261diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20262index 3a2ae4c..9db31d6 100644
20263--- a/arch/x86/kernel/acpi/sleep.c
20264+++ b/arch/x86/kernel/acpi/sleep.c
20265@@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20266 #else /* CONFIG_64BIT */
20267 #ifdef CONFIG_SMP
20268 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20269+
20270+ pax_open_kernel();
20271 early_gdt_descr.address =
20272 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20273+ pax_close_kernel();
20274+
20275 initial_gs = per_cpu_offset(smp_processor_id());
20276 #endif
20277 initial_code = (unsigned long)wakeup_long64;
20278diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20279index 665c6b7..eae4d56 100644
20280--- a/arch/x86/kernel/acpi/wakeup_32.S
20281+++ b/arch/x86/kernel/acpi/wakeup_32.S
20282@@ -29,13 +29,11 @@ wakeup_pmode_return:
20283 # and restore the stack ... but you need gdt for this to work
20284 movl saved_context_esp, %esp
20285
20286- movl %cs:saved_magic, %eax
20287- cmpl $0x12345678, %eax
20288+ cmpl $0x12345678, saved_magic
20289 jne bogus_magic
20290
20291 # jump to place where we left off
20292- movl saved_eip, %eax
20293- jmp *%eax
20294+ jmp *(saved_eip)
20295
20296 bogus_magic:
20297 jmp bogus_magic
20298diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20299index df94598..f3b29bf 100644
20300--- a/arch/x86/kernel/alternative.c
20301+++ b/arch/x86/kernel/alternative.c
20302@@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20303 */
20304 for (a = start; a < end; a++) {
20305 instr = (u8 *)&a->instr_offset + a->instr_offset;
20306+
20307+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20308+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20309+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20310+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20311+#endif
20312+
20313 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20314 BUG_ON(a->replacementlen > a->instrlen);
20315 BUG_ON(a->instrlen > sizeof(insnbuf));
20316@@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20317 for (poff = start; poff < end; poff++) {
20318 u8 *ptr = (u8 *)poff + *poff;
20319
20320+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20321+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20322+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20323+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20324+#endif
20325+
20326 if (!*poff || ptr < text || ptr >= text_end)
20327 continue;
20328 /* turn DS segment override prefix into lock prefix */
20329- if (*ptr == 0x3e)
20330+ if (*ktla_ktva(ptr) == 0x3e)
20331 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20332 }
20333 mutex_unlock(&text_mutex);
20334@@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20335 for (poff = start; poff < end; poff++) {
20336 u8 *ptr = (u8 *)poff + *poff;
20337
20338+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20339+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20340+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20341+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20342+#endif
20343+
20344 if (!*poff || ptr < text || ptr >= text_end)
20345 continue;
20346 /* turn lock prefix into DS segment override prefix */
20347- if (*ptr == 0xf0)
20348+ if (*ktla_ktva(ptr) == 0xf0)
20349 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20350 }
20351 mutex_unlock(&text_mutex);
20352@@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20353
20354 BUG_ON(p->len > MAX_PATCH_LEN);
20355 /* prep the buffer with the original instructions */
20356- memcpy(insnbuf, p->instr, p->len);
20357+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20358 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20359 (unsigned long)p->instr, p->len);
20360
20361@@ -505,7 +524,7 @@ void __init alternative_instructions(void)
20362 if (!uniproc_patched || num_possible_cpus() == 1)
20363 free_init_pages("SMP alternatives",
20364 (unsigned long)__smp_locks,
20365- (unsigned long)__smp_locks_end);
20366+ PAGE_ALIGN((unsigned long)__smp_locks_end));
20367 #endif
20368
20369 apply_paravirt(__parainstructions, __parainstructions_end);
20370@@ -525,13 +544,17 @@ void __init alternative_instructions(void)
20371 * instructions. And on the local CPU you need to be protected again NMI or MCE
20372 * handlers seeing an inconsistent instruction while you patch.
20373 */
20374-void *__init_or_module text_poke_early(void *addr, const void *opcode,
20375+void *__kprobes text_poke_early(void *addr, const void *opcode,
20376 size_t len)
20377 {
20378 unsigned long flags;
20379 local_irq_save(flags);
20380- memcpy(addr, opcode, len);
20381+
20382+ pax_open_kernel();
20383+ memcpy(ktla_ktva(addr), opcode, len);
20384 sync_core();
20385+ pax_close_kernel();
20386+
20387 local_irq_restore(flags);
20388 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20389 that causes hangs on some VIA CPUs. */
20390@@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20391 */
20392 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20393 {
20394- unsigned long flags;
20395- char *vaddr;
20396+ unsigned char *vaddr = ktla_ktva(addr);
20397 struct page *pages[2];
20398- int i;
20399+ size_t i;
20400
20401 if (!core_kernel_text((unsigned long)addr)) {
20402- pages[0] = vmalloc_to_page(addr);
20403- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20404+ pages[0] = vmalloc_to_page(vaddr);
20405+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20406 } else {
20407- pages[0] = virt_to_page(addr);
20408+ pages[0] = virt_to_page(vaddr);
20409 WARN_ON(!PageReserved(pages[0]));
20410- pages[1] = virt_to_page(addr + PAGE_SIZE);
20411+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20412 }
20413 BUG_ON(!pages[0]);
20414- local_irq_save(flags);
20415- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20416- if (pages[1])
20417- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20418- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20419- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20420- clear_fixmap(FIX_TEXT_POKE0);
20421- if (pages[1])
20422- clear_fixmap(FIX_TEXT_POKE1);
20423- local_flush_tlb();
20424- sync_core();
20425- /* Could also do a CLFLUSH here to speed up CPU recovery; but
20426- that causes hangs on some VIA CPUs. */
20427+ text_poke_early(addr, opcode, len);
20428 for (i = 0; i < len; i++)
20429- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20430- local_irq_restore(flags);
20431+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20432 return addr;
20433 }
20434
20435@@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
20436 if (likely(!bp_patching_in_progress))
20437 return 0;
20438
20439- if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20440+ if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20441 return 0;
20442
20443 /* set up the specified breakpoint handler */
20444@@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
20445 */
20446 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20447 {
20448- unsigned char int3 = 0xcc;
20449+ const unsigned char int3 = 0xcc;
20450
20451 bp_int3_handler = handler;
20452 bp_int3_addr = (u8 *)addr + sizeof(int3);
20453diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20454index d278736..0b4af9a8 100644
20455--- a/arch/x86/kernel/apic/apic.c
20456+++ b/arch/x86/kernel/apic/apic.c
20457@@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
20458 /*
20459 * Debug level, exported for io_apic.c
20460 */
20461-unsigned int apic_verbosity;
20462+int apic_verbosity;
20463
20464 int pic_mode;
20465
20466@@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20467 apic_write(APIC_ESR, 0);
20468 v1 = apic_read(APIC_ESR);
20469 ack_APIC_irq();
20470- atomic_inc(&irq_err_count);
20471+ atomic_inc_unchecked(&irq_err_count);
20472
20473 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
20474 smp_processor_id(), v0 , v1);
20475diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20476index 00c77cf..2dc6a2d 100644
20477--- a/arch/x86/kernel/apic/apic_flat_64.c
20478+++ b/arch/x86/kernel/apic/apic_flat_64.c
20479@@ -157,7 +157,7 @@ static int flat_probe(void)
20480 return 1;
20481 }
20482
20483-static struct apic apic_flat = {
20484+static struct apic apic_flat __read_only = {
20485 .name = "flat",
20486 .probe = flat_probe,
20487 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20488@@ -271,7 +271,7 @@ static int physflat_probe(void)
20489 return 0;
20490 }
20491
20492-static struct apic apic_physflat = {
20493+static struct apic apic_physflat __read_only = {
20494
20495 .name = "physical flat",
20496 .probe = physflat_probe,
20497diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20498index e145f28..2752888 100644
20499--- a/arch/x86/kernel/apic/apic_noop.c
20500+++ b/arch/x86/kernel/apic/apic_noop.c
20501@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
20502 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20503 }
20504
20505-struct apic apic_noop = {
20506+struct apic apic_noop __read_only = {
20507 .name = "noop",
20508 .probe = noop_probe,
20509 .acpi_madt_oem_check = NULL,
20510diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20511index d50e364..543bee3 100644
20512--- a/arch/x86/kernel/apic/bigsmp_32.c
20513+++ b/arch/x86/kernel/apic/bigsmp_32.c
20514@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20515 return dmi_bigsmp;
20516 }
20517
20518-static struct apic apic_bigsmp = {
20519+static struct apic apic_bigsmp __read_only = {
20520
20521 .name = "bigsmp",
20522 .probe = probe_bigsmp,
20523diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20524index c552247..587a316 100644
20525--- a/arch/x86/kernel/apic/es7000_32.c
20526+++ b/arch/x86/kernel/apic/es7000_32.c
20527@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20528 return ret && es7000_apic_is_cluster();
20529 }
20530
20531-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20532-static struct apic __refdata apic_es7000_cluster = {
20533+static struct apic apic_es7000_cluster __read_only = {
20534
20535 .name = "es7000",
20536 .probe = probe_es7000,
20537@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20538 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20539 };
20540
20541-static struct apic __refdata apic_es7000 = {
20542+static struct apic apic_es7000 __read_only = {
20543
20544 .name = "es7000",
20545 .probe = probe_es7000,
20546diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20547index e63a5bd..c0babf8 100644
20548--- a/arch/x86/kernel/apic/io_apic.c
20549+++ b/arch/x86/kernel/apic/io_apic.c
20550@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20551 }
20552 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20553
20554-void lock_vector_lock(void)
20555+void lock_vector_lock(void) __acquires(vector_lock)
20556 {
20557 /* Used to the online set of cpus does not change
20558 * during assign_irq_vector.
20559@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20560 raw_spin_lock(&vector_lock);
20561 }
20562
20563-void unlock_vector_lock(void)
20564+void unlock_vector_lock(void) __releases(vector_lock)
20565 {
20566 raw_spin_unlock(&vector_lock);
20567 }
20568@@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20569 ack_APIC_irq();
20570 }
20571
20572-atomic_t irq_mis_count;
20573+atomic_unchecked_t irq_mis_count;
20574
20575 #ifdef CONFIG_GENERIC_PENDING_IRQ
20576 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20577@@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20578 * at the cpu.
20579 */
20580 if (!(v & (1 << (i & 0x1f)))) {
20581- atomic_inc(&irq_mis_count);
20582+ atomic_inc_unchecked(&irq_mis_count);
20583
20584 eoi_ioapic_irq(irq, cfg);
20585 }
20586diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20587index 1e42e8f..daacf44 100644
20588--- a/arch/x86/kernel/apic/numaq_32.c
20589+++ b/arch/x86/kernel/apic/numaq_32.c
20590@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20591 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20592 }
20593
20594-/* Use __refdata to keep false positive warning calm. */
20595-static struct apic __refdata apic_numaq = {
20596+static struct apic apic_numaq __read_only = {
20597
20598 .name = "NUMAQ",
20599 .probe = probe_numaq,
20600diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20601index eb35ef9..f184a21 100644
20602--- a/arch/x86/kernel/apic/probe_32.c
20603+++ b/arch/x86/kernel/apic/probe_32.c
20604@@ -72,7 +72,7 @@ static int probe_default(void)
20605 return 1;
20606 }
20607
20608-static struct apic apic_default = {
20609+static struct apic apic_default __read_only = {
20610
20611 .name = "default",
20612 .probe = probe_default,
20613diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20614index 77c95c0..434f8a4 100644
20615--- a/arch/x86/kernel/apic/summit_32.c
20616+++ b/arch/x86/kernel/apic/summit_32.c
20617@@ -486,7 +486,7 @@ void setup_summit(void)
20618 }
20619 #endif
20620
20621-static struct apic apic_summit = {
20622+static struct apic apic_summit __read_only = {
20623
20624 .name = "summit",
20625 .probe = probe_summit,
20626diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20627index 140e29d..d88bc95 100644
20628--- a/arch/x86/kernel/apic/x2apic_cluster.c
20629+++ b/arch/x86/kernel/apic/x2apic_cluster.c
20630@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20631 return notifier_from_errno(err);
20632 }
20633
20634-static struct notifier_block __refdata x2apic_cpu_notifier = {
20635+static struct notifier_block x2apic_cpu_notifier = {
20636 .notifier_call = update_clusterinfo,
20637 };
20638
20639@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20640 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20641 }
20642
20643-static struct apic apic_x2apic_cluster = {
20644+static struct apic apic_x2apic_cluster __read_only = {
20645
20646 .name = "cluster x2apic",
20647 .probe = x2apic_cluster_probe,
20648diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20649index 562a76d..a003c0f 100644
20650--- a/arch/x86/kernel/apic/x2apic_phys.c
20651+++ b/arch/x86/kernel/apic/x2apic_phys.c
20652@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20653 return apic == &apic_x2apic_phys;
20654 }
20655
20656-static struct apic apic_x2apic_phys = {
20657+static struct apic apic_x2apic_phys __read_only = {
20658
20659 .name = "physical x2apic",
20660 .probe = x2apic_phys_probe,
20661diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20662index ad0dc04..0d9cc56 100644
20663--- a/arch/x86/kernel/apic/x2apic_uv_x.c
20664+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20665@@ -350,7 +350,7 @@ static int uv_probe(void)
20666 return apic == &apic_x2apic_uv_x;
20667 }
20668
20669-static struct apic __refdata apic_x2apic_uv_x = {
20670+static struct apic apic_x2apic_uv_x __read_only = {
20671
20672 .name = "UV large system",
20673 .probe = uv_probe,
20674diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20675index 3ab0343..814c4787 100644
20676--- a/arch/x86/kernel/apm_32.c
20677+++ b/arch/x86/kernel/apm_32.c
20678@@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20679 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20680 * even though they are called in protected mode.
20681 */
20682-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20683+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20684 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20685
20686 static const char driver_version[] = "1.16ac"; /* no spaces */
20687@@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20688 BUG_ON(cpu != 0);
20689 gdt = get_cpu_gdt_table(cpu);
20690 save_desc_40 = gdt[0x40 / 8];
20691+
20692+ pax_open_kernel();
20693 gdt[0x40 / 8] = bad_bios_desc;
20694+ pax_close_kernel();
20695
20696 apm_irq_save(flags);
20697 APM_DO_SAVE_SEGS;
20698@@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20699 &call->esi);
20700 APM_DO_RESTORE_SEGS;
20701 apm_irq_restore(flags);
20702+
20703+ pax_open_kernel();
20704 gdt[0x40 / 8] = save_desc_40;
20705+ pax_close_kernel();
20706+
20707 put_cpu();
20708
20709 return call->eax & 0xff;
20710@@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20711 BUG_ON(cpu != 0);
20712 gdt = get_cpu_gdt_table(cpu);
20713 save_desc_40 = gdt[0x40 / 8];
20714+
20715+ pax_open_kernel();
20716 gdt[0x40 / 8] = bad_bios_desc;
20717+ pax_close_kernel();
20718
20719 apm_irq_save(flags);
20720 APM_DO_SAVE_SEGS;
20721@@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20722 &call->eax);
20723 APM_DO_RESTORE_SEGS;
20724 apm_irq_restore(flags);
20725+
20726+ pax_open_kernel();
20727 gdt[0x40 / 8] = save_desc_40;
20728+ pax_close_kernel();
20729+
20730 put_cpu();
20731 return error;
20732 }
20733@@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20734 * code to that CPU.
20735 */
20736 gdt = get_cpu_gdt_table(0);
20737+
20738+ pax_open_kernel();
20739 set_desc_base(&gdt[APM_CS >> 3],
20740 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20741 set_desc_base(&gdt[APM_CS_16 >> 3],
20742 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20743 set_desc_base(&gdt[APM_DS >> 3],
20744 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20745+ pax_close_kernel();
20746
20747 proc_create("apm", 0, NULL, &apm_file_ops);
20748
20749diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20750index 9f6b934..cf5ffb3 100644
20751--- a/arch/x86/kernel/asm-offsets.c
20752+++ b/arch/x86/kernel/asm-offsets.c
20753@@ -32,6 +32,8 @@ void common(void) {
20754 OFFSET(TI_flags, thread_info, flags);
20755 OFFSET(TI_status, thread_info, status);
20756 OFFSET(TI_addr_limit, thread_info, addr_limit);
20757+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20758+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20759
20760 BLANK();
20761 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20762@@ -52,8 +54,26 @@ void common(void) {
20763 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20764 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20765 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20766+
20767+#ifdef CONFIG_PAX_KERNEXEC
20768+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20769 #endif
20770
20771+#ifdef CONFIG_PAX_MEMORY_UDEREF
20772+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20773+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20774+#ifdef CONFIG_X86_64
20775+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20776+#endif
20777+#endif
20778+
20779+#endif
20780+
20781+ BLANK();
20782+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20783+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20784+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20785+
20786 #ifdef CONFIG_XEN
20787 BLANK();
20788 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20789diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20790index e7c798b..2b2019b 100644
20791--- a/arch/x86/kernel/asm-offsets_64.c
20792+++ b/arch/x86/kernel/asm-offsets_64.c
20793@@ -77,6 +77,7 @@ int main(void)
20794 BLANK();
20795 #undef ENTRY
20796
20797+ DEFINE(TSS_size, sizeof(struct tss_struct));
20798 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20799 BLANK();
20800
20801diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20802index 47b56a7..efc2bc6 100644
20803--- a/arch/x86/kernel/cpu/Makefile
20804+++ b/arch/x86/kernel/cpu/Makefile
20805@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20806 CFLAGS_REMOVE_perf_event.o = -pg
20807 endif
20808
20809-# Make sure load_percpu_segment has no stackprotector
20810-nostackp := $(call cc-option, -fno-stack-protector)
20811-CFLAGS_common.o := $(nostackp)
20812-
20813 obj-y := intel_cacheinfo.o scattered.o topology.o
20814 obj-y += proc.o capflags.o powerflags.o common.o
20815 obj-y += rdrand.o
20816diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20817index 59bfebc..d8f27bd 100644
20818--- a/arch/x86/kernel/cpu/amd.c
20819+++ b/arch/x86/kernel/cpu/amd.c
20820@@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20821 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20822 {
20823 /* AMD errata T13 (order #21922) */
20824- if ((c->x86 == 6)) {
20825+ if (c->x86 == 6) {
20826 /* Duron Rev A0 */
20827 if (c->x86_model == 3 && c->x86_mask == 0)
20828 size = 64;
20829diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20830index fe2bdd0..77b0d1b 100644
20831--- a/arch/x86/kernel/cpu/common.c
20832+++ b/arch/x86/kernel/cpu/common.c
20833@@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20834
20835 static const struct cpu_dev *this_cpu = &default_cpu;
20836
20837-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20838-#ifdef CONFIG_X86_64
20839- /*
20840- * We need valid kernel segments for data and code in long mode too
20841- * IRET will check the segment types kkeil 2000/10/28
20842- * Also sysret mandates a special GDT layout
20843- *
20844- * TLS descriptors are currently at a different place compared to i386.
20845- * Hopefully nobody expects them at a fixed place (Wine?)
20846- */
20847- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20848- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20849- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20850- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20851- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20852- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20853-#else
20854- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20855- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20856- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20857- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20858- /*
20859- * Segments used for calling PnP BIOS have byte granularity.
20860- * They code segments and data segments have fixed 64k limits,
20861- * the transfer segment sizes are set at run time.
20862- */
20863- /* 32-bit code */
20864- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20865- /* 16-bit code */
20866- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20867- /* 16-bit data */
20868- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20869- /* 16-bit data */
20870- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20871- /* 16-bit data */
20872- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20873- /*
20874- * The APM segments have byte granularity and their bases
20875- * are set at run time. All have 64k limits.
20876- */
20877- /* 32-bit code */
20878- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20879- /* 16-bit code */
20880- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20881- /* data */
20882- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20883-
20884- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20885- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20886- GDT_STACK_CANARY_INIT
20887-#endif
20888-} };
20889-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20890-
20891 static int __init x86_xsave_setup(char *s)
20892 {
20893 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20894@@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20895 }
20896 }
20897
20898+#ifdef CONFIG_X86_64
20899+static __init int setup_disable_pcid(char *arg)
20900+{
20901+ setup_clear_cpu_cap(X86_FEATURE_PCID);
20902+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20903+
20904+#ifdef CONFIG_PAX_MEMORY_UDEREF
20905+ if (clone_pgd_mask != ~(pgdval_t)0UL)
20906+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20907+#endif
20908+
20909+ return 1;
20910+}
20911+__setup("nopcid", setup_disable_pcid);
20912+
20913+static void setup_pcid(struct cpuinfo_x86 *c)
20914+{
20915+ if (!cpu_has(c, X86_FEATURE_PCID)) {
20916+ clear_cpu_cap(c, X86_FEATURE_INVPCID);
20917+
20918+#ifdef CONFIG_PAX_MEMORY_UDEREF
20919+ if (clone_pgd_mask != ~(pgdval_t)0UL) {
20920+ pax_open_kernel();
20921+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20922+ pax_close_kernel();
20923+ printk("PAX: slow and weak UDEREF enabled\n");
20924+ } else
20925+ printk("PAX: UDEREF disabled\n");
20926+#endif
20927+
20928+ return;
20929+ }
20930+
20931+ printk("PAX: PCID detected\n");
20932+ set_in_cr4(X86_CR4_PCIDE);
20933+
20934+#ifdef CONFIG_PAX_MEMORY_UDEREF
20935+ pax_open_kernel();
20936+ clone_pgd_mask = ~(pgdval_t)0UL;
20937+ pax_close_kernel();
20938+ if (pax_user_shadow_base)
20939+ printk("PAX: weak UDEREF enabled\n");
20940+ else {
20941+ set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20942+ printk("PAX: strong UDEREF enabled\n");
20943+ }
20944+#endif
20945+
20946+ if (cpu_has(c, X86_FEATURE_INVPCID))
20947+ printk("PAX: INVPCID detected\n");
20948+}
20949+#endif
20950+
20951 /*
20952 * Some CPU features depend on higher CPUID levels, which may not always
20953 * be available due to CPUID level capping or broken virtualization
20954@@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
20955 {
20956 struct desc_ptr gdt_descr;
20957
20958- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20959+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20960 gdt_descr.size = GDT_SIZE - 1;
20961 load_gdt(&gdt_descr);
20962 /* Reload the per-cpu base */
20963@@ -882,6 +881,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20964 setup_smep(c);
20965 setup_smap(c);
20966
20967+#ifdef CONFIG_X86_64
20968+ setup_pcid(c);
20969+#endif
20970+
20971 /*
20972 * The vendor-specific functions might have changed features.
20973 * Now we do "generic changes."
20974@@ -890,6 +893,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20975 /* Filter out anything that depends on CPUID levels we don't have */
20976 filter_cpuid_features(c, true);
20977
20978+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20979+ setup_clear_cpu_cap(X86_FEATURE_SEP);
20980+#endif
20981+
20982 /* If the model name is still unset, do table lookup. */
20983 if (!c->x86_model_id[0]) {
20984 const char *p;
20985@@ -1077,10 +1084,12 @@ static __init int setup_disablecpuid(char *arg)
20986 }
20987 __setup("clearcpuid=", setup_disablecpuid);
20988
20989+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20990+EXPORT_PER_CPU_SYMBOL(current_tinfo);
20991+
20992 #ifdef CONFIG_X86_64
20993-struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20994-struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20995- (unsigned long) debug_idt_table };
20996+struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20997+const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20998
20999 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21000 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21001@@ -1094,7 +1103,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
21002 EXPORT_PER_CPU_SYMBOL(current_task);
21003
21004 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21005- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21006+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21007 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21008
21009 DEFINE_PER_CPU(char *, irq_stack_ptr) =
21010@@ -1244,7 +1253,7 @@ void cpu_init(void)
21011 load_ucode_ap();
21012
21013 cpu = stack_smp_processor_id();
21014- t = &per_cpu(init_tss, cpu);
21015+ t = init_tss + cpu;
21016 oist = &per_cpu(orig_ist, cpu);
21017
21018 #ifdef CONFIG_NUMA
21019@@ -1279,7 +1288,6 @@ void cpu_init(void)
21020 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21021 barrier();
21022
21023- x86_configure_nx();
21024 enable_x2apic();
21025
21026 /*
21027@@ -1331,7 +1339,7 @@ void cpu_init(void)
21028 {
21029 int cpu = smp_processor_id();
21030 struct task_struct *curr = current;
21031- struct tss_struct *t = &per_cpu(init_tss, cpu);
21032+ struct tss_struct *t = init_tss + cpu;
21033 struct thread_struct *thread = &curr->thread;
21034
21035 show_ucode_info_early();
21036diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21037index 0641113..06f5ba4 100644
21038--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21039+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21040@@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21041 };
21042
21043 #ifdef CONFIG_AMD_NB
21044+static struct attribute *default_attrs_amd_nb[] = {
21045+ &type.attr,
21046+ &level.attr,
21047+ &coherency_line_size.attr,
21048+ &physical_line_partition.attr,
21049+ &ways_of_associativity.attr,
21050+ &number_of_sets.attr,
21051+ &size.attr,
21052+ &shared_cpu_map.attr,
21053+ &shared_cpu_list.attr,
21054+ NULL,
21055+ NULL,
21056+ NULL,
21057+ NULL
21058+};
21059+
21060 static struct attribute **amd_l3_attrs(void)
21061 {
21062 static struct attribute **attrs;
21063@@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21064
21065 n = ARRAY_SIZE(default_attrs);
21066
21067- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21068- n += 2;
21069-
21070- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21071- n += 1;
21072-
21073- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21074- if (attrs == NULL)
21075- return attrs = default_attrs;
21076-
21077- for (n = 0; default_attrs[n]; n++)
21078- attrs[n] = default_attrs[n];
21079+ attrs = default_attrs_amd_nb;
21080
21081 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21082 attrs[n++] = &cache_disable_0.attr;
21083@@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21084 .default_attrs = default_attrs,
21085 };
21086
21087+#ifdef CONFIG_AMD_NB
21088+static struct kobj_type ktype_cache_amd_nb = {
21089+ .sysfs_ops = &sysfs_ops,
21090+ .default_attrs = default_attrs_amd_nb,
21091+};
21092+#endif
21093+
21094 static struct kobj_type ktype_percpu_entry = {
21095 .sysfs_ops = &sysfs_ops,
21096 };
21097@@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21098 return retval;
21099 }
21100
21101+#ifdef CONFIG_AMD_NB
21102+ amd_l3_attrs();
21103+#endif
21104+
21105 for (i = 0; i < num_cache_leaves; i++) {
21106+ struct kobj_type *ktype;
21107+
21108 this_object = INDEX_KOBJECT_PTR(cpu, i);
21109 this_object->cpu = cpu;
21110 this_object->index = i;
21111
21112 this_leaf = CPUID4_INFO_IDX(cpu, i);
21113
21114- ktype_cache.default_attrs = default_attrs;
21115+ ktype = &ktype_cache;
21116 #ifdef CONFIG_AMD_NB
21117 if (this_leaf->base.nb)
21118- ktype_cache.default_attrs = amd_l3_attrs();
21119+ ktype = &ktype_cache_amd_nb;
21120 #endif
21121 retval = kobject_init_and_add(&(this_object->kobj),
21122- &ktype_cache,
21123+ ktype,
21124 per_cpu(ici_cache_kobject, cpu),
21125 "index%1lu", i);
21126 if (unlikely(retval)) {
21127diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21128index b3218cd..99a75de 100644
21129--- a/arch/x86/kernel/cpu/mcheck/mce.c
21130+++ b/arch/x86/kernel/cpu/mcheck/mce.c
21131@@ -45,6 +45,7 @@
21132 #include <asm/processor.h>
21133 #include <asm/mce.h>
21134 #include <asm/msr.h>
21135+#include <asm/local.h>
21136
21137 #include "mce-internal.h"
21138
21139@@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
21140 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21141 m->cs, m->ip);
21142
21143- if (m->cs == __KERNEL_CS)
21144+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21145 print_symbol("{%s}", m->ip);
21146 pr_cont("\n");
21147 }
21148@@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
21149
21150 #define PANIC_TIMEOUT 5 /* 5 seconds */
21151
21152-static atomic_t mce_paniced;
21153+static atomic_unchecked_t mce_paniced;
21154
21155 static int fake_panic;
21156-static atomic_t mce_fake_paniced;
21157+static atomic_unchecked_t mce_fake_paniced;
21158
21159 /* Panic in progress. Enable interrupts and wait for final IPI */
21160 static void wait_for_panic(void)
21161@@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21162 /*
21163 * Make sure only one CPU runs in machine check panic
21164 */
21165- if (atomic_inc_return(&mce_paniced) > 1)
21166+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21167 wait_for_panic();
21168 barrier();
21169
21170@@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21171 console_verbose();
21172 } else {
21173 /* Don't log too much for fake panic */
21174- if (atomic_inc_return(&mce_fake_paniced) > 1)
21175+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21176 return;
21177 }
21178 /* First print corrected ones that are still unlogged */
21179@@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21180 if (!fake_panic) {
21181 if (panic_timeout == 0)
21182 panic_timeout = mca_cfg.panic_timeout;
21183- panic(msg);
21184+ panic("%s", msg);
21185 } else
21186 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21187 }
21188@@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
21189 * might have been modified by someone else.
21190 */
21191 rmb();
21192- if (atomic_read(&mce_paniced))
21193+ if (atomic_read_unchecked(&mce_paniced))
21194 wait_for_panic();
21195 if (!mca_cfg.monarch_timeout)
21196 goto out;
21197@@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21198 }
21199
21200 /* Call the installed machine check handler for this CPU setup. */
21201-void (*machine_check_vector)(struct pt_regs *, long error_code) =
21202+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21203 unexpected_machine_check;
21204
21205 /*
21206@@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21207 return;
21208 }
21209
21210+ pax_open_kernel();
21211 machine_check_vector = do_machine_check;
21212+ pax_close_kernel();
21213
21214 __mcheck_cpu_init_generic();
21215 __mcheck_cpu_init_vendor(c);
21216@@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21217 */
21218
21219 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21220-static int mce_chrdev_open_count; /* #times opened */
21221+static local_t mce_chrdev_open_count; /* #times opened */
21222 static int mce_chrdev_open_exclu; /* already open exclusive? */
21223
21224 static int mce_chrdev_open(struct inode *inode, struct file *file)
21225@@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21226 spin_lock(&mce_chrdev_state_lock);
21227
21228 if (mce_chrdev_open_exclu ||
21229- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21230+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21231 spin_unlock(&mce_chrdev_state_lock);
21232
21233 return -EBUSY;
21234@@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21235
21236 if (file->f_flags & O_EXCL)
21237 mce_chrdev_open_exclu = 1;
21238- mce_chrdev_open_count++;
21239+ local_inc(&mce_chrdev_open_count);
21240
21241 spin_unlock(&mce_chrdev_state_lock);
21242
21243@@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21244 {
21245 spin_lock(&mce_chrdev_state_lock);
21246
21247- mce_chrdev_open_count--;
21248+ local_dec(&mce_chrdev_open_count);
21249 mce_chrdev_open_exclu = 0;
21250
21251 spin_unlock(&mce_chrdev_state_lock);
21252@@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
21253
21254 for (i = 0; i < mca_cfg.banks; i++) {
21255 struct mce_bank *b = &mce_banks[i];
21256- struct device_attribute *a = &b->attr;
21257+ device_attribute_no_const *a = &b->attr;
21258
21259 sysfs_attr_init(&a->attr);
21260 a->attr.name = b->attrname;
21261@@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
21262 static void mce_reset(void)
21263 {
21264 cpu_missing = 0;
21265- atomic_set(&mce_fake_paniced, 0);
21266+ atomic_set_unchecked(&mce_fake_paniced, 0);
21267 atomic_set(&mce_executing, 0);
21268 atomic_set(&mce_callin, 0);
21269 atomic_set(&global_nwo, 0);
21270diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21271index 1c044b1..37a2a43 100644
21272--- a/arch/x86/kernel/cpu/mcheck/p5.c
21273+++ b/arch/x86/kernel/cpu/mcheck/p5.c
21274@@ -11,6 +11,7 @@
21275 #include <asm/processor.h>
21276 #include <asm/mce.h>
21277 #include <asm/msr.h>
21278+#include <asm/pgtable.h>
21279
21280 /* By default disabled */
21281 int mce_p5_enabled __read_mostly;
21282@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21283 if (!cpu_has(c, X86_FEATURE_MCE))
21284 return;
21285
21286+ pax_open_kernel();
21287 machine_check_vector = pentium_machine_check;
21288+ pax_close_kernel();
21289 /* Make sure the vector pointer is visible before we enable MCEs: */
21290 wmb();
21291
21292diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21293index e9a701a..35317d6 100644
21294--- a/arch/x86/kernel/cpu/mcheck/winchip.c
21295+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21296@@ -10,6 +10,7 @@
21297 #include <asm/processor.h>
21298 #include <asm/mce.h>
21299 #include <asm/msr.h>
21300+#include <asm/pgtable.h>
21301
21302 /* Machine check handler for WinChip C6: */
21303 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21304@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21305 {
21306 u32 lo, hi;
21307
21308+ pax_open_kernel();
21309 machine_check_vector = winchip_machine_check;
21310+ pax_close_kernel();
21311 /* Make sure the vector pointer is visible before we enable MCEs: */
21312 wmb();
21313
21314diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21315index f961de9..8a9d332 100644
21316--- a/arch/x86/kernel/cpu/mtrr/main.c
21317+++ b/arch/x86/kernel/cpu/mtrr/main.c
21318@@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21319 u64 size_or_mask, size_and_mask;
21320 static bool mtrr_aps_delayed_init;
21321
21322-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21323+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21324
21325 const struct mtrr_ops *mtrr_if;
21326
21327diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21328index df5e41f..816c719 100644
21329--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21330+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21331@@ -25,7 +25,7 @@ struct mtrr_ops {
21332 int (*validate_add_page)(unsigned long base, unsigned long size,
21333 unsigned int type);
21334 int (*have_wrcomb)(void);
21335-};
21336+} __do_const;
21337
21338 extern int generic_get_free_region(unsigned long base, unsigned long size,
21339 int replace_reg);
21340diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21341index db6cdbe..faaf834 100644
21342--- a/arch/x86/kernel/cpu/perf_event.c
21343+++ b/arch/x86/kernel/cpu/perf_event.c
21344@@ -1351,7 +1351,7 @@ static void __init pmu_check_apic(void)
21345 pr_info("no hardware sampling interrupt available.\n");
21346 }
21347
21348-static struct attribute_group x86_pmu_format_group = {
21349+static attribute_group_no_const x86_pmu_format_group = {
21350 .name = "format",
21351 .attrs = NULL,
21352 };
21353@@ -1450,7 +1450,7 @@ static struct attribute *events_attr[] = {
21354 NULL,
21355 };
21356
21357-static struct attribute_group x86_pmu_events_group = {
21358+static attribute_group_no_const x86_pmu_events_group = {
21359 .name = "events",
21360 .attrs = events_attr,
21361 };
21362@@ -1961,7 +1961,7 @@ static unsigned long get_segment_base(unsigned int segment)
21363 if (idx > GDT_ENTRIES)
21364 return 0;
21365
21366- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21367+ desc = get_cpu_gdt_table(smp_processor_id());
21368 }
21369
21370 return get_desc_base(desc + idx);
21371@@ -2051,7 +2051,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21372 break;
21373
21374 perf_callchain_store(entry, frame.return_address);
21375- fp = frame.next_frame;
21376+ fp = (const void __force_user *)frame.next_frame;
21377 }
21378 }
21379
21380diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21381index 639d128..e92d7e5 100644
21382--- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21383+++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21384@@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21385 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21386 {
21387 struct attribute **attrs;
21388- struct attribute_group *attr_group;
21389+ attribute_group_no_const *attr_group;
21390 int i = 0, j;
21391
21392 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21393diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21394index 0fa4f24..17990ed 100644
21395--- a/arch/x86/kernel/cpu/perf_event_intel.c
21396+++ b/arch/x86/kernel/cpu/perf_event_intel.c
21397@@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
21398 * v2 and above have a perf capabilities MSR
21399 */
21400 if (version > 1) {
21401- u64 capabilities;
21402+ u64 capabilities = x86_pmu.intel_cap.capabilities;
21403
21404- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21405- x86_pmu.intel_cap.capabilities = capabilities;
21406+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21407+ x86_pmu.intel_cap.capabilities = capabilities;
21408 }
21409
21410 intel_ds_init();
21411diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21412index 29c2487..a5606fa 100644
21413--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21414+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21415@@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21416 static int __init uncore_type_init(struct intel_uncore_type *type)
21417 {
21418 struct intel_uncore_pmu *pmus;
21419- struct attribute_group *attr_group;
21420+ attribute_group_no_const *attr_group;
21421 struct attribute **attrs;
21422 int i, j;
21423
21424diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21425index a80ab71..4089da5 100644
21426--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21427+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21428@@ -498,7 +498,7 @@ struct intel_uncore_box {
21429 struct uncore_event_desc {
21430 struct kobj_attribute attr;
21431 const char *config;
21432-};
21433+} __do_const;
21434
21435 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21436 { \
21437diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21438index 7d9481c..99c7e4b 100644
21439--- a/arch/x86/kernel/cpuid.c
21440+++ b/arch/x86/kernel/cpuid.c
21441@@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21442 return notifier_from_errno(err);
21443 }
21444
21445-static struct notifier_block __refdata cpuid_class_cpu_notifier =
21446+static struct notifier_block cpuid_class_cpu_notifier =
21447 {
21448 .notifier_call = cpuid_class_cpu_callback,
21449 };
21450diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21451index 18677a9..f67c45b 100644
21452--- a/arch/x86/kernel/crash.c
21453+++ b/arch/x86/kernel/crash.c
21454@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21455 {
21456 #ifdef CONFIG_X86_32
21457 struct pt_regs fixed_regs;
21458-#endif
21459
21460-#ifdef CONFIG_X86_32
21461- if (!user_mode_vm(regs)) {
21462+ if (!user_mode(regs)) {
21463 crash_fixup_ss_esp(&fixed_regs, regs);
21464 regs = &fixed_regs;
21465 }
21466diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21467index afa64ad..dce67dd 100644
21468--- a/arch/x86/kernel/crash_dump_64.c
21469+++ b/arch/x86/kernel/crash_dump_64.c
21470@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21471 return -ENOMEM;
21472
21473 if (userbuf) {
21474- if (copy_to_user(buf, vaddr + offset, csize)) {
21475+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21476 iounmap(vaddr);
21477 return -EFAULT;
21478 }
21479diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21480index 5d3fe8d..02e1429 100644
21481--- a/arch/x86/kernel/doublefault.c
21482+++ b/arch/x86/kernel/doublefault.c
21483@@ -13,7 +13,7 @@
21484
21485 #define DOUBLEFAULT_STACKSIZE (1024)
21486 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21487-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21488+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21489
21490 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21491
21492@@ -23,7 +23,7 @@ static void doublefault_fn(void)
21493 unsigned long gdt, tss;
21494
21495 native_store_gdt(&gdt_desc);
21496- gdt = gdt_desc.address;
21497+ gdt = (unsigned long)gdt_desc.address;
21498
21499 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21500
21501@@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21502 /* 0x2 bit is always set */
21503 .flags = X86_EFLAGS_SF | 0x2,
21504 .sp = STACK_START,
21505- .es = __USER_DS,
21506+ .es = __KERNEL_DS,
21507 .cs = __KERNEL_CS,
21508 .ss = __KERNEL_DS,
21509- .ds = __USER_DS,
21510+ .ds = __KERNEL_DS,
21511 .fs = __KERNEL_PERCPU,
21512
21513 .__cr3 = __pa_nodebug(swapper_pg_dir),
21514diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21515index d9c12d3..7858b62 100644
21516--- a/arch/x86/kernel/dumpstack.c
21517+++ b/arch/x86/kernel/dumpstack.c
21518@@ -2,6 +2,9 @@
21519 * Copyright (C) 1991, 1992 Linus Torvalds
21520 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21521 */
21522+#ifdef CONFIG_GRKERNSEC_HIDESYM
21523+#define __INCLUDED_BY_HIDESYM 1
21524+#endif
21525 #include <linux/kallsyms.h>
21526 #include <linux/kprobes.h>
21527 #include <linux/uaccess.h>
21528@@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21529 static void
21530 print_ftrace_graph_addr(unsigned long addr, void *data,
21531 const struct stacktrace_ops *ops,
21532- struct thread_info *tinfo, int *graph)
21533+ struct task_struct *task, int *graph)
21534 {
21535- struct task_struct *task;
21536 unsigned long ret_addr;
21537 int index;
21538
21539 if (addr != (unsigned long)return_to_handler)
21540 return;
21541
21542- task = tinfo->task;
21543 index = task->curr_ret_stack;
21544
21545 if (!task->ret_stack || index < *graph)
21546@@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21547 static inline void
21548 print_ftrace_graph_addr(unsigned long addr, void *data,
21549 const struct stacktrace_ops *ops,
21550- struct thread_info *tinfo, int *graph)
21551+ struct task_struct *task, int *graph)
21552 { }
21553 #endif
21554
21555@@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21556 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21557 */
21558
21559-static inline int valid_stack_ptr(struct thread_info *tinfo,
21560- void *p, unsigned int size, void *end)
21561+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21562 {
21563- void *t = tinfo;
21564 if (end) {
21565 if (p < end && p >= (end-THREAD_SIZE))
21566 return 1;
21567@@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21568 }
21569
21570 unsigned long
21571-print_context_stack(struct thread_info *tinfo,
21572+print_context_stack(struct task_struct *task, void *stack_start,
21573 unsigned long *stack, unsigned long bp,
21574 const struct stacktrace_ops *ops, void *data,
21575 unsigned long *end, int *graph)
21576 {
21577 struct stack_frame *frame = (struct stack_frame *)bp;
21578
21579- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21580+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21581 unsigned long addr;
21582
21583 addr = *stack;
21584@@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21585 } else {
21586 ops->address(data, addr, 0);
21587 }
21588- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21589+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21590 }
21591 stack++;
21592 }
21593@@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21594 EXPORT_SYMBOL_GPL(print_context_stack);
21595
21596 unsigned long
21597-print_context_stack_bp(struct thread_info *tinfo,
21598+print_context_stack_bp(struct task_struct *task, void *stack_start,
21599 unsigned long *stack, unsigned long bp,
21600 const struct stacktrace_ops *ops, void *data,
21601 unsigned long *end, int *graph)
21602@@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21603 struct stack_frame *frame = (struct stack_frame *)bp;
21604 unsigned long *ret_addr = &frame->return_address;
21605
21606- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21607+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21608 unsigned long addr = *ret_addr;
21609
21610 if (!__kernel_text_address(addr))
21611@@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21612 ops->address(data, addr, 1);
21613 frame = frame->next_frame;
21614 ret_addr = &frame->return_address;
21615- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21616+ print_ftrace_graph_addr(addr, data, ops, task, graph);
21617 }
21618
21619 return (unsigned long)frame;
21620@@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21621 static void print_trace_address(void *data, unsigned long addr, int reliable)
21622 {
21623 touch_nmi_watchdog();
21624- printk(data);
21625+ printk("%s", (char *)data);
21626 printk_stack_address(addr, reliable);
21627 }
21628
21629@@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21630 }
21631 EXPORT_SYMBOL_GPL(oops_begin);
21632
21633+extern void gr_handle_kernel_exploit(void);
21634+
21635 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21636 {
21637 if (regs && kexec_should_crash(current))
21638@@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21639 panic("Fatal exception in interrupt");
21640 if (panic_on_oops)
21641 panic("Fatal exception");
21642- do_exit(signr);
21643+
21644+ gr_handle_kernel_exploit();
21645+
21646+ do_group_exit(signr);
21647 }
21648
21649 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21650@@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21651 print_modules();
21652 show_regs(regs);
21653 #ifdef CONFIG_X86_32
21654- if (user_mode_vm(regs)) {
21655+ if (user_mode(regs)) {
21656 sp = regs->sp;
21657 ss = regs->ss & 0xffff;
21658 } else {
21659@@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21660 unsigned long flags = oops_begin();
21661 int sig = SIGSEGV;
21662
21663- if (!user_mode_vm(regs))
21664+ if (!user_mode(regs))
21665 report_bug(regs->ip, regs);
21666
21667 if (__die(str, regs, err))
21668diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21669index f2a1770..540657f 100644
21670--- a/arch/x86/kernel/dumpstack_32.c
21671+++ b/arch/x86/kernel/dumpstack_32.c
21672@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21673 bp = stack_frame(task, regs);
21674
21675 for (;;) {
21676- struct thread_info *context;
21677+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21678
21679- context = (struct thread_info *)
21680- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21681- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21682+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21683
21684- stack = (unsigned long *)context->previous_esp;
21685- if (!stack)
21686+ if (stack_start == task_stack_page(task))
21687 break;
21688+ stack = *(unsigned long **)stack_start;
21689 if (ops->stack(data, "IRQ") < 0)
21690 break;
21691 touch_nmi_watchdog();
21692@@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21693 int i;
21694
21695 show_regs_print_info(KERN_EMERG);
21696- __show_regs(regs, !user_mode_vm(regs));
21697+ __show_regs(regs, !user_mode(regs));
21698
21699 /*
21700 * When in-kernel, we also print out the stack and code at the
21701 * time of the fault..
21702 */
21703- if (!user_mode_vm(regs)) {
21704+ if (!user_mode(regs)) {
21705 unsigned int code_prologue = code_bytes * 43 / 64;
21706 unsigned int code_len = code_bytes;
21707 unsigned char c;
21708 u8 *ip;
21709+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21710
21711 pr_emerg("Stack:\n");
21712 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21713
21714 pr_emerg("Code:");
21715
21716- ip = (u8 *)regs->ip - code_prologue;
21717+ ip = (u8 *)regs->ip - code_prologue + cs_base;
21718 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21719 /* try starting at IP */
21720- ip = (u8 *)regs->ip;
21721+ ip = (u8 *)regs->ip + cs_base;
21722 code_len = code_len - code_prologue + 1;
21723 }
21724 for (i = 0; i < code_len; i++, ip++) {
21725@@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21726 pr_cont(" Bad EIP value.");
21727 break;
21728 }
21729- if (ip == (u8 *)regs->ip)
21730+ if (ip == (u8 *)regs->ip + cs_base)
21731 pr_cont(" <%02x>", c);
21732 else
21733 pr_cont(" %02x", c);
21734@@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21735 {
21736 unsigned short ud2;
21737
21738+ ip = ktla_ktva(ip);
21739 if (ip < PAGE_OFFSET)
21740 return 0;
21741 if (probe_kernel_address((unsigned short *)ip, ud2))
21742@@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21743
21744 return ud2 == 0x0b0f;
21745 }
21746+
21747+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21748+void pax_check_alloca(unsigned long size)
21749+{
21750+ unsigned long sp = (unsigned long)&sp, stack_left;
21751+
21752+ /* all kernel stacks are of the same size */
21753+ stack_left = sp & (THREAD_SIZE - 1);
21754+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21755+}
21756+EXPORT_SYMBOL(pax_check_alloca);
21757+#endif
21758diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21759index addb207..99635fa 100644
21760--- a/arch/x86/kernel/dumpstack_64.c
21761+++ b/arch/x86/kernel/dumpstack_64.c
21762@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21763 unsigned long *irq_stack_end =
21764 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21765 unsigned used = 0;
21766- struct thread_info *tinfo;
21767 int graph = 0;
21768 unsigned long dummy;
21769+ void *stack_start;
21770
21771 if (!task)
21772 task = current;
21773@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21774 * current stack address. If the stacks consist of nested
21775 * exceptions
21776 */
21777- tinfo = task_thread_info(task);
21778 for (;;) {
21779 char *id;
21780 unsigned long *estack_end;
21781+
21782 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21783 &used, &id);
21784
21785@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21786 if (ops->stack(data, id) < 0)
21787 break;
21788
21789- bp = ops->walk_stack(tinfo, stack, bp, ops,
21790+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21791 data, estack_end, &graph);
21792 ops->stack(data, "<EOE>");
21793 /*
21794@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21795 * second-to-last pointer (index -2 to end) in the
21796 * exception stack:
21797 */
21798+ if ((u16)estack_end[-1] != __KERNEL_DS)
21799+ goto out;
21800 stack = (unsigned long *) estack_end[-2];
21801 continue;
21802 }
21803@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21804 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21805 if (ops->stack(data, "IRQ") < 0)
21806 break;
21807- bp = ops->walk_stack(tinfo, stack, bp,
21808+ bp = ops->walk_stack(task, irq_stack, stack, bp,
21809 ops, data, irq_stack_end, &graph);
21810 /*
21811 * We link to the next stack (which would be
21812@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21813 /*
21814 * This handles the process stack:
21815 */
21816- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21817+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21818+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21819+out:
21820 put_cpu();
21821 }
21822 EXPORT_SYMBOL(dump_trace);
21823@@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21824
21825 return ud2 == 0x0b0f;
21826 }
21827+
21828+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21829+void pax_check_alloca(unsigned long size)
21830+{
21831+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21832+ unsigned cpu, used;
21833+ char *id;
21834+
21835+ /* check the process stack first */
21836+ stack_start = (unsigned long)task_stack_page(current);
21837+ stack_end = stack_start + THREAD_SIZE;
21838+ if (likely(stack_start <= sp && sp < stack_end)) {
21839+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
21840+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21841+ return;
21842+ }
21843+
21844+ cpu = get_cpu();
21845+
21846+ /* check the irq stacks */
21847+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21848+ stack_start = stack_end - IRQ_STACK_SIZE;
21849+ if (stack_start <= sp && sp < stack_end) {
21850+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21851+ put_cpu();
21852+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21853+ return;
21854+ }
21855+
21856+ /* check the exception stacks */
21857+ used = 0;
21858+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21859+ stack_start = stack_end - EXCEPTION_STKSZ;
21860+ if (stack_end && stack_start <= sp && sp < stack_end) {
21861+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21862+ put_cpu();
21863+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
21864+ return;
21865+ }
21866+
21867+ put_cpu();
21868+
21869+ /* unknown stack */
21870+ BUG();
21871+}
21872+EXPORT_SYMBOL(pax_check_alloca);
21873+#endif
21874diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21875index 174da5f..5e55606 100644
21876--- a/arch/x86/kernel/e820.c
21877+++ b/arch/x86/kernel/e820.c
21878@@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21879
21880 static void early_panic(char *msg)
21881 {
21882- early_printk(msg);
21883- panic(msg);
21884+ early_printk("%s", msg);
21885+ panic("%s", msg);
21886 }
21887
21888 static int userdef __initdata;
21889diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21890index 01d1c18..8073693 100644
21891--- a/arch/x86/kernel/early_printk.c
21892+++ b/arch/x86/kernel/early_printk.c
21893@@ -7,6 +7,7 @@
21894 #include <linux/pci_regs.h>
21895 #include <linux/pci_ids.h>
21896 #include <linux/errno.h>
21897+#include <linux/sched.h>
21898 #include <asm/io.h>
21899 #include <asm/processor.h>
21900 #include <asm/fcntl.h>
21901diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21902index a2a4f46..6cab058 100644
21903--- a/arch/x86/kernel/entry_32.S
21904+++ b/arch/x86/kernel/entry_32.S
21905@@ -177,13 +177,153 @@
21906 /*CFI_REL_OFFSET gs, PT_GS*/
21907 .endm
21908 .macro SET_KERNEL_GS reg
21909+
21910+#ifdef CONFIG_CC_STACKPROTECTOR
21911 movl $(__KERNEL_STACK_CANARY), \reg
21912+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21913+ movl $(__USER_DS), \reg
21914+#else
21915+ xorl \reg, \reg
21916+#endif
21917+
21918 movl \reg, %gs
21919 .endm
21920
21921 #endif /* CONFIG_X86_32_LAZY_GS */
21922
21923-.macro SAVE_ALL
21924+.macro pax_enter_kernel
21925+#ifdef CONFIG_PAX_KERNEXEC
21926+ call pax_enter_kernel
21927+#endif
21928+.endm
21929+
21930+.macro pax_exit_kernel
21931+#ifdef CONFIG_PAX_KERNEXEC
21932+ call pax_exit_kernel
21933+#endif
21934+.endm
21935+
21936+#ifdef CONFIG_PAX_KERNEXEC
21937+ENTRY(pax_enter_kernel)
21938+#ifdef CONFIG_PARAVIRT
21939+ pushl %eax
21940+ pushl %ecx
21941+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21942+ mov %eax, %esi
21943+#else
21944+ mov %cr0, %esi
21945+#endif
21946+ bts $16, %esi
21947+ jnc 1f
21948+ mov %cs, %esi
21949+ cmp $__KERNEL_CS, %esi
21950+ jz 3f
21951+ ljmp $__KERNEL_CS, $3f
21952+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21953+2:
21954+#ifdef CONFIG_PARAVIRT
21955+ mov %esi, %eax
21956+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21957+#else
21958+ mov %esi, %cr0
21959+#endif
21960+3:
21961+#ifdef CONFIG_PARAVIRT
21962+ popl %ecx
21963+ popl %eax
21964+#endif
21965+ ret
21966+ENDPROC(pax_enter_kernel)
21967+
21968+ENTRY(pax_exit_kernel)
21969+#ifdef CONFIG_PARAVIRT
21970+ pushl %eax
21971+ pushl %ecx
21972+#endif
21973+ mov %cs, %esi
21974+ cmp $__KERNEXEC_KERNEL_CS, %esi
21975+ jnz 2f
21976+#ifdef CONFIG_PARAVIRT
21977+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21978+ mov %eax, %esi
21979+#else
21980+ mov %cr0, %esi
21981+#endif
21982+ btr $16, %esi
21983+ ljmp $__KERNEL_CS, $1f
21984+1:
21985+#ifdef CONFIG_PARAVIRT
21986+ mov %esi, %eax
21987+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21988+#else
21989+ mov %esi, %cr0
21990+#endif
21991+2:
21992+#ifdef CONFIG_PARAVIRT
21993+ popl %ecx
21994+ popl %eax
21995+#endif
21996+ ret
21997+ENDPROC(pax_exit_kernel)
21998+#endif
21999+
22000+ .macro pax_erase_kstack
22001+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22002+ call pax_erase_kstack
22003+#endif
22004+ .endm
22005+
22006+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22007+/*
22008+ * ebp: thread_info
22009+ */
22010+ENTRY(pax_erase_kstack)
22011+ pushl %edi
22012+ pushl %ecx
22013+ pushl %eax
22014+
22015+ mov TI_lowest_stack(%ebp), %edi
22016+ mov $-0xBEEF, %eax
22017+ std
22018+
22019+1: mov %edi, %ecx
22020+ and $THREAD_SIZE_asm - 1, %ecx
22021+ shr $2, %ecx
22022+ repne scasl
22023+ jecxz 2f
22024+
22025+ cmp $2*16, %ecx
22026+ jc 2f
22027+
22028+ mov $2*16, %ecx
22029+ repe scasl
22030+ jecxz 2f
22031+ jne 1b
22032+
22033+2: cld
22034+ mov %esp, %ecx
22035+ sub %edi, %ecx
22036+
22037+ cmp $THREAD_SIZE_asm, %ecx
22038+ jb 3f
22039+ ud2
22040+3:
22041+
22042+ shr $2, %ecx
22043+ rep stosl
22044+
22045+ mov TI_task_thread_sp0(%ebp), %edi
22046+ sub $128, %edi
22047+ mov %edi, TI_lowest_stack(%ebp)
22048+
22049+ popl %eax
22050+ popl %ecx
22051+ popl %edi
22052+ ret
22053+ENDPROC(pax_erase_kstack)
22054+#endif
22055+
22056+.macro __SAVE_ALL _DS
22057 cld
22058 PUSH_GS
22059 pushl_cfi %fs
22060@@ -206,7 +346,7 @@
22061 CFI_REL_OFFSET ecx, 0
22062 pushl_cfi %ebx
22063 CFI_REL_OFFSET ebx, 0
22064- movl $(__USER_DS), %edx
22065+ movl $\_DS, %edx
22066 movl %edx, %ds
22067 movl %edx, %es
22068 movl $(__KERNEL_PERCPU), %edx
22069@@ -214,6 +354,15 @@
22070 SET_KERNEL_GS %edx
22071 .endm
22072
22073+.macro SAVE_ALL
22074+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22075+ __SAVE_ALL __KERNEL_DS
22076+ pax_enter_kernel
22077+#else
22078+ __SAVE_ALL __USER_DS
22079+#endif
22080+.endm
22081+
22082 .macro RESTORE_INT_REGS
22083 popl_cfi %ebx
22084 CFI_RESTORE ebx
22085@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22086 popfl_cfi
22087 jmp syscall_exit
22088 CFI_ENDPROC
22089-END(ret_from_fork)
22090+ENDPROC(ret_from_fork)
22091
22092 ENTRY(ret_from_kernel_thread)
22093 CFI_STARTPROC
22094@@ -344,7 +493,15 @@ ret_from_intr:
22095 andl $SEGMENT_RPL_MASK, %eax
22096 #endif
22097 cmpl $USER_RPL, %eax
22098+
22099+#ifdef CONFIG_PAX_KERNEXEC
22100+ jae resume_userspace
22101+
22102+ pax_exit_kernel
22103+ jmp resume_kernel
22104+#else
22105 jb resume_kernel # not returning to v8086 or userspace
22106+#endif
22107
22108 ENTRY(resume_userspace)
22109 LOCKDEP_SYS_EXIT
22110@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22111 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22112 # int/exception return?
22113 jne work_pending
22114- jmp restore_all
22115-END(ret_from_exception)
22116+ jmp restore_all_pax
22117+ENDPROC(ret_from_exception)
22118
22119 #ifdef CONFIG_PREEMPT
22120 ENTRY(resume_kernel)
22121@@ -369,7 +526,7 @@ need_resched:
22122 jz restore_all
22123 call preempt_schedule_irq
22124 jmp need_resched
22125-END(resume_kernel)
22126+ENDPROC(resume_kernel)
22127 #endif
22128 CFI_ENDPROC
22129 /*
22130@@ -403,30 +560,45 @@ sysenter_past_esp:
22131 /*CFI_REL_OFFSET cs, 0*/
22132 /*
22133 * Push current_thread_info()->sysenter_return to the stack.
22134- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22135- * pushed above; +8 corresponds to copy_thread's esp0 setting.
22136 */
22137- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22138+ pushl_cfi $0
22139 CFI_REL_OFFSET eip, 0
22140
22141 pushl_cfi %eax
22142 SAVE_ALL
22143+ GET_THREAD_INFO(%ebp)
22144+ movl TI_sysenter_return(%ebp),%ebp
22145+ movl %ebp,PT_EIP(%esp)
22146 ENABLE_INTERRUPTS(CLBR_NONE)
22147
22148 /*
22149 * Load the potential sixth argument from user stack.
22150 * Careful about security.
22151 */
22152+ movl PT_OLDESP(%esp),%ebp
22153+
22154+#ifdef CONFIG_PAX_MEMORY_UDEREF
22155+ mov PT_OLDSS(%esp),%ds
22156+1: movl %ds:(%ebp),%ebp
22157+ push %ss
22158+ pop %ds
22159+#else
22160 cmpl $__PAGE_OFFSET-3,%ebp
22161 jae syscall_fault
22162 ASM_STAC
22163 1: movl (%ebp),%ebp
22164 ASM_CLAC
22165+#endif
22166+
22167 movl %ebp,PT_EBP(%esp)
22168 _ASM_EXTABLE(1b,syscall_fault)
22169
22170 GET_THREAD_INFO(%ebp)
22171
22172+#ifdef CONFIG_PAX_RANDKSTACK
22173+ pax_erase_kstack
22174+#endif
22175+
22176 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22177 jnz sysenter_audit
22178 sysenter_do_call:
22179@@ -441,12 +613,24 @@ sysenter_do_call:
22180 testl $_TIF_ALLWORK_MASK, %ecx
22181 jne sysexit_audit
22182 sysenter_exit:
22183+
22184+#ifdef CONFIG_PAX_RANDKSTACK
22185+ pushl_cfi %eax
22186+ movl %esp, %eax
22187+ call pax_randomize_kstack
22188+ popl_cfi %eax
22189+#endif
22190+
22191+ pax_erase_kstack
22192+
22193 /* if something modifies registers it must also disable sysexit */
22194 movl PT_EIP(%esp), %edx
22195 movl PT_OLDESP(%esp), %ecx
22196 xorl %ebp,%ebp
22197 TRACE_IRQS_ON
22198 1: mov PT_FS(%esp), %fs
22199+2: mov PT_DS(%esp), %ds
22200+3: mov PT_ES(%esp), %es
22201 PTGS_TO_GS
22202 ENABLE_INTERRUPTS_SYSEXIT
22203
22204@@ -463,6 +647,9 @@ sysenter_audit:
22205 movl %eax,%edx /* 2nd arg: syscall number */
22206 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22207 call __audit_syscall_entry
22208+
22209+ pax_erase_kstack
22210+
22211 pushl_cfi %ebx
22212 movl PT_EAX(%esp),%eax /* reload syscall number */
22213 jmp sysenter_do_call
22214@@ -488,10 +675,16 @@ sysexit_audit:
22215
22216 CFI_ENDPROC
22217 .pushsection .fixup,"ax"
22218-2: movl $0,PT_FS(%esp)
22219+4: movl $0,PT_FS(%esp)
22220+ jmp 1b
22221+5: movl $0,PT_DS(%esp)
22222+ jmp 1b
22223+6: movl $0,PT_ES(%esp)
22224 jmp 1b
22225 .popsection
22226- _ASM_EXTABLE(1b,2b)
22227+ _ASM_EXTABLE(1b,4b)
22228+ _ASM_EXTABLE(2b,5b)
22229+ _ASM_EXTABLE(3b,6b)
22230 PTGS_TO_GS_EX
22231 ENDPROC(ia32_sysenter_target)
22232
22233@@ -506,6 +699,11 @@ ENTRY(system_call)
22234 pushl_cfi %eax # save orig_eax
22235 SAVE_ALL
22236 GET_THREAD_INFO(%ebp)
22237+
22238+#ifdef CONFIG_PAX_RANDKSTACK
22239+ pax_erase_kstack
22240+#endif
22241+
22242 # system call tracing in operation / emulation
22243 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22244 jnz syscall_trace_entry
22245@@ -524,6 +722,15 @@ syscall_exit:
22246 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22247 jne syscall_exit_work
22248
22249+restore_all_pax:
22250+
22251+#ifdef CONFIG_PAX_RANDKSTACK
22252+ movl %esp, %eax
22253+ call pax_randomize_kstack
22254+#endif
22255+
22256+ pax_erase_kstack
22257+
22258 restore_all:
22259 TRACE_IRQS_IRET
22260 restore_all_notrace:
22261@@ -580,14 +787,34 @@ ldt_ss:
22262 * compensating for the offset by changing to the ESPFIX segment with
22263 * a base address that matches for the difference.
22264 */
22265-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22266+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22267 mov %esp, %edx /* load kernel esp */
22268 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22269 mov %dx, %ax /* eax: new kernel esp */
22270 sub %eax, %edx /* offset (low word is 0) */
22271+#ifdef CONFIG_SMP
22272+ movl PER_CPU_VAR(cpu_number), %ebx
22273+ shll $PAGE_SHIFT_asm, %ebx
22274+ addl $cpu_gdt_table, %ebx
22275+#else
22276+ movl $cpu_gdt_table, %ebx
22277+#endif
22278 shr $16, %edx
22279- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22280- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22281+
22282+#ifdef CONFIG_PAX_KERNEXEC
22283+ mov %cr0, %esi
22284+ btr $16, %esi
22285+ mov %esi, %cr0
22286+#endif
22287+
22288+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22289+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22290+
22291+#ifdef CONFIG_PAX_KERNEXEC
22292+ bts $16, %esi
22293+ mov %esi, %cr0
22294+#endif
22295+
22296 pushl_cfi $__ESPFIX_SS
22297 pushl_cfi %eax /* new kernel esp */
22298 /* Disable interrupts, but do not irqtrace this section: we
22299@@ -616,20 +843,18 @@ work_resched:
22300 movl TI_flags(%ebp), %ecx
22301 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22302 # than syscall tracing?
22303- jz restore_all
22304+ jz restore_all_pax
22305 testb $_TIF_NEED_RESCHED, %cl
22306 jnz work_resched
22307
22308 work_notifysig: # deal with pending signals and
22309 # notify-resume requests
22310+ movl %esp, %eax
22311 #ifdef CONFIG_VM86
22312 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22313- movl %esp, %eax
22314 jne work_notifysig_v86 # returning to kernel-space or
22315 # vm86-space
22316 1:
22317-#else
22318- movl %esp, %eax
22319 #endif
22320 TRACE_IRQS_ON
22321 ENABLE_INTERRUPTS(CLBR_NONE)
22322@@ -650,7 +875,7 @@ work_notifysig_v86:
22323 movl %eax, %esp
22324 jmp 1b
22325 #endif
22326-END(work_pending)
22327+ENDPROC(work_pending)
22328
22329 # perform syscall exit tracing
22330 ALIGN
22331@@ -658,11 +883,14 @@ syscall_trace_entry:
22332 movl $-ENOSYS,PT_EAX(%esp)
22333 movl %esp, %eax
22334 call syscall_trace_enter
22335+
22336+ pax_erase_kstack
22337+
22338 /* What it returned is what we'll actually use. */
22339 cmpl $(NR_syscalls), %eax
22340 jnae syscall_call
22341 jmp syscall_exit
22342-END(syscall_trace_entry)
22343+ENDPROC(syscall_trace_entry)
22344
22345 # perform syscall exit tracing
22346 ALIGN
22347@@ -675,21 +903,25 @@ syscall_exit_work:
22348 movl %esp, %eax
22349 call syscall_trace_leave
22350 jmp resume_userspace
22351-END(syscall_exit_work)
22352+ENDPROC(syscall_exit_work)
22353 CFI_ENDPROC
22354
22355 RING0_INT_FRAME # can't unwind into user space anyway
22356 syscall_fault:
22357+#ifdef CONFIG_PAX_MEMORY_UDEREF
22358+ push %ss
22359+ pop %ds
22360+#endif
22361 ASM_CLAC
22362 GET_THREAD_INFO(%ebp)
22363 movl $-EFAULT,PT_EAX(%esp)
22364 jmp resume_userspace
22365-END(syscall_fault)
22366+ENDPROC(syscall_fault)
22367
22368 syscall_badsys:
22369 movl $-ENOSYS,PT_EAX(%esp)
22370 jmp resume_userspace
22371-END(syscall_badsys)
22372+ENDPROC(syscall_badsys)
22373 CFI_ENDPROC
22374 /*
22375 * End of kprobes section
22376@@ -705,8 +937,15 @@ END(syscall_badsys)
22377 * normal stack and adjusts ESP with the matching offset.
22378 */
22379 /* fixup the stack */
22380- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22381- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22382+#ifdef CONFIG_SMP
22383+ movl PER_CPU_VAR(cpu_number), %ebx
22384+ shll $PAGE_SHIFT_asm, %ebx
22385+ addl $cpu_gdt_table, %ebx
22386+#else
22387+ movl $cpu_gdt_table, %ebx
22388+#endif
22389+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22390+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22391 shl $16, %eax
22392 addl %esp, %eax /* the adjusted stack pointer */
22393 pushl_cfi $__KERNEL_DS
22394@@ -759,7 +998,7 @@ vector=vector+1
22395 .endr
22396 2: jmp common_interrupt
22397 .endr
22398-END(irq_entries_start)
22399+ENDPROC(irq_entries_start)
22400
22401 .previous
22402 END(interrupt)
22403@@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
22404 pushl_cfi $do_coprocessor_error
22405 jmp error_code
22406 CFI_ENDPROC
22407-END(coprocessor_error)
22408+ENDPROC(coprocessor_error)
22409
22410 ENTRY(simd_coprocessor_error)
22411 RING0_INT_FRAME
22412@@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
22413 .section .altinstructions,"a"
22414 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22415 .previous
22416-.section .altinstr_replacement,"ax"
22417+.section .altinstr_replacement,"a"
22418 663: pushl $do_simd_coprocessor_error
22419 664:
22420 .previous
22421@@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
22422 #endif
22423 jmp error_code
22424 CFI_ENDPROC
22425-END(simd_coprocessor_error)
22426+ENDPROC(simd_coprocessor_error)
22427
22428 ENTRY(device_not_available)
22429 RING0_INT_FRAME
22430@@ -851,18 +1090,18 @@ ENTRY(device_not_available)
22431 pushl_cfi $do_device_not_available
22432 jmp error_code
22433 CFI_ENDPROC
22434-END(device_not_available)
22435+ENDPROC(device_not_available)
22436
22437 #ifdef CONFIG_PARAVIRT
22438 ENTRY(native_iret)
22439 iret
22440 _ASM_EXTABLE(native_iret, iret_exc)
22441-END(native_iret)
22442+ENDPROC(native_iret)
22443
22444 ENTRY(native_irq_enable_sysexit)
22445 sti
22446 sysexit
22447-END(native_irq_enable_sysexit)
22448+ENDPROC(native_irq_enable_sysexit)
22449 #endif
22450
22451 ENTRY(overflow)
22452@@ -872,7 +1111,7 @@ ENTRY(overflow)
22453 pushl_cfi $do_overflow
22454 jmp error_code
22455 CFI_ENDPROC
22456-END(overflow)
22457+ENDPROC(overflow)
22458
22459 ENTRY(bounds)
22460 RING0_INT_FRAME
22461@@ -881,7 +1120,7 @@ ENTRY(bounds)
22462 pushl_cfi $do_bounds
22463 jmp error_code
22464 CFI_ENDPROC
22465-END(bounds)
22466+ENDPROC(bounds)
22467
22468 ENTRY(invalid_op)
22469 RING0_INT_FRAME
22470@@ -890,7 +1129,7 @@ ENTRY(invalid_op)
22471 pushl_cfi $do_invalid_op
22472 jmp error_code
22473 CFI_ENDPROC
22474-END(invalid_op)
22475+ENDPROC(invalid_op)
22476
22477 ENTRY(coprocessor_segment_overrun)
22478 RING0_INT_FRAME
22479@@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
22480 pushl_cfi $do_coprocessor_segment_overrun
22481 jmp error_code
22482 CFI_ENDPROC
22483-END(coprocessor_segment_overrun)
22484+ENDPROC(coprocessor_segment_overrun)
22485
22486 ENTRY(invalid_TSS)
22487 RING0_EC_FRAME
22488@@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
22489 pushl_cfi $do_invalid_TSS
22490 jmp error_code
22491 CFI_ENDPROC
22492-END(invalid_TSS)
22493+ENDPROC(invalid_TSS)
22494
22495 ENTRY(segment_not_present)
22496 RING0_EC_FRAME
22497@@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
22498 pushl_cfi $do_segment_not_present
22499 jmp error_code
22500 CFI_ENDPROC
22501-END(segment_not_present)
22502+ENDPROC(segment_not_present)
22503
22504 ENTRY(stack_segment)
22505 RING0_EC_FRAME
22506@@ -923,7 +1162,7 @@ ENTRY(stack_segment)
22507 pushl_cfi $do_stack_segment
22508 jmp error_code
22509 CFI_ENDPROC
22510-END(stack_segment)
22511+ENDPROC(stack_segment)
22512
22513 ENTRY(alignment_check)
22514 RING0_EC_FRAME
22515@@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22516 pushl_cfi $do_alignment_check
22517 jmp error_code
22518 CFI_ENDPROC
22519-END(alignment_check)
22520+ENDPROC(alignment_check)
22521
22522 ENTRY(divide_error)
22523 RING0_INT_FRAME
22524@@ -940,7 +1179,7 @@ ENTRY(divide_error)
22525 pushl_cfi $do_divide_error
22526 jmp error_code
22527 CFI_ENDPROC
22528-END(divide_error)
22529+ENDPROC(divide_error)
22530
22531 #ifdef CONFIG_X86_MCE
22532 ENTRY(machine_check)
22533@@ -950,7 +1189,7 @@ ENTRY(machine_check)
22534 pushl_cfi machine_check_vector
22535 jmp error_code
22536 CFI_ENDPROC
22537-END(machine_check)
22538+ENDPROC(machine_check)
22539 #endif
22540
22541 ENTRY(spurious_interrupt_bug)
22542@@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22543 pushl_cfi $do_spurious_interrupt_bug
22544 jmp error_code
22545 CFI_ENDPROC
22546-END(spurious_interrupt_bug)
22547+ENDPROC(spurious_interrupt_bug)
22548 /*
22549 * End of kprobes section
22550 */
22551@@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22552
22553 ENTRY(mcount)
22554 ret
22555-END(mcount)
22556+ENDPROC(mcount)
22557
22558 ENTRY(ftrace_caller)
22559 cmpl $0, function_trace_stop
22560@@ -1103,7 +1342,7 @@ ftrace_graph_call:
22561 .globl ftrace_stub
22562 ftrace_stub:
22563 ret
22564-END(ftrace_caller)
22565+ENDPROC(ftrace_caller)
22566
22567 ENTRY(ftrace_regs_caller)
22568 pushf /* push flags before compare (in cs location) */
22569@@ -1207,7 +1446,7 @@ trace:
22570 popl %ecx
22571 popl %eax
22572 jmp ftrace_stub
22573-END(mcount)
22574+ENDPROC(mcount)
22575 #endif /* CONFIG_DYNAMIC_FTRACE */
22576 #endif /* CONFIG_FUNCTION_TRACER */
22577
22578@@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22579 popl %ecx
22580 popl %eax
22581 ret
22582-END(ftrace_graph_caller)
22583+ENDPROC(ftrace_graph_caller)
22584
22585 .globl return_to_handler
22586 return_to_handler:
22587@@ -1291,15 +1530,18 @@ error_code:
22588 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22589 REG_TO_PTGS %ecx
22590 SET_KERNEL_GS %ecx
22591- movl $(__USER_DS), %ecx
22592+ movl $(__KERNEL_DS), %ecx
22593 movl %ecx, %ds
22594 movl %ecx, %es
22595+
22596+ pax_enter_kernel
22597+
22598 TRACE_IRQS_OFF
22599 movl %esp,%eax # pt_regs pointer
22600 call *%edi
22601 jmp ret_from_exception
22602 CFI_ENDPROC
22603-END(page_fault)
22604+ENDPROC(page_fault)
22605
22606 /*
22607 * Debug traps and NMI can happen at the one SYSENTER instruction
22608@@ -1342,7 +1584,7 @@ debug_stack_correct:
22609 call do_debug
22610 jmp ret_from_exception
22611 CFI_ENDPROC
22612-END(debug)
22613+ENDPROC(debug)
22614
22615 /*
22616 * NMI is doubly nasty. It can happen _while_ we're handling
22617@@ -1380,6 +1622,9 @@ nmi_stack_correct:
22618 xorl %edx,%edx # zero error code
22619 movl %esp,%eax # pt_regs pointer
22620 call do_nmi
22621+
22622+ pax_exit_kernel
22623+
22624 jmp restore_all_notrace
22625 CFI_ENDPROC
22626
22627@@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22628 FIXUP_ESPFIX_STACK # %eax == %esp
22629 xorl %edx,%edx # zero error code
22630 call do_nmi
22631+
22632+ pax_exit_kernel
22633+
22634 RESTORE_REGS
22635 lss 12+4(%esp), %esp # back to espfix stack
22636 CFI_ADJUST_CFA_OFFSET -24
22637 jmp irq_return
22638 CFI_ENDPROC
22639-END(nmi)
22640+ENDPROC(nmi)
22641
22642 ENTRY(int3)
22643 RING0_INT_FRAME
22644@@ -1434,14 +1682,14 @@ ENTRY(int3)
22645 call do_int3
22646 jmp ret_from_exception
22647 CFI_ENDPROC
22648-END(int3)
22649+ENDPROC(int3)
22650
22651 ENTRY(general_protection)
22652 RING0_EC_FRAME
22653 pushl_cfi $do_general_protection
22654 jmp error_code
22655 CFI_ENDPROC
22656-END(general_protection)
22657+ENDPROC(general_protection)
22658
22659 #ifdef CONFIG_KVM_GUEST
22660 ENTRY(async_page_fault)
22661@@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22662 pushl_cfi $do_async_page_fault
22663 jmp error_code
22664 CFI_ENDPROC
22665-END(async_page_fault)
22666+ENDPROC(async_page_fault)
22667 #endif
22668
22669 /*
22670diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22671index 1e96c36..3ff710a 100644
22672--- a/arch/x86/kernel/entry_64.S
22673+++ b/arch/x86/kernel/entry_64.S
22674@@ -59,6 +59,8 @@
22675 #include <asm/context_tracking.h>
22676 #include <asm/smap.h>
22677 #include <linux/err.h>
22678+#include <asm/pgtable.h>
22679+#include <asm/alternative-asm.h>
22680
22681 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22682 #include <linux/elf-em.h>
22683@@ -80,8 +82,9 @@
22684 #ifdef CONFIG_DYNAMIC_FTRACE
22685
22686 ENTRY(function_hook)
22687+ pax_force_retaddr
22688 retq
22689-END(function_hook)
22690+ENDPROC(function_hook)
22691
22692 /* skip is set if stack has been adjusted */
22693 .macro ftrace_caller_setup skip=0
22694@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22695 #endif
22696
22697 GLOBAL(ftrace_stub)
22698+ pax_force_retaddr
22699 retq
22700-END(ftrace_caller)
22701+ENDPROC(ftrace_caller)
22702
22703 ENTRY(ftrace_regs_caller)
22704 /* Save the current flags before compare (in SS location)*/
22705@@ -191,7 +195,7 @@ ftrace_restore_flags:
22706 popfq
22707 jmp ftrace_stub
22708
22709-END(ftrace_regs_caller)
22710+ENDPROC(ftrace_regs_caller)
22711
22712
22713 #else /* ! CONFIG_DYNAMIC_FTRACE */
22714@@ -212,6 +216,7 @@ ENTRY(function_hook)
22715 #endif
22716
22717 GLOBAL(ftrace_stub)
22718+ pax_force_retaddr
22719 retq
22720
22721 trace:
22722@@ -225,12 +230,13 @@ trace:
22723 #endif
22724 subq $MCOUNT_INSN_SIZE, %rdi
22725
22726+ pax_force_fptr ftrace_trace_function
22727 call *ftrace_trace_function
22728
22729 MCOUNT_RESTORE_FRAME
22730
22731 jmp ftrace_stub
22732-END(function_hook)
22733+ENDPROC(function_hook)
22734 #endif /* CONFIG_DYNAMIC_FTRACE */
22735 #endif /* CONFIG_FUNCTION_TRACER */
22736
22737@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22738
22739 MCOUNT_RESTORE_FRAME
22740
22741+ pax_force_retaddr
22742 retq
22743-END(ftrace_graph_caller)
22744+ENDPROC(ftrace_graph_caller)
22745
22746 GLOBAL(return_to_handler)
22747 subq $24, %rsp
22748@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22749 movq 8(%rsp), %rdx
22750 movq (%rsp), %rax
22751 addq $24, %rsp
22752+ pax_force_fptr %rdi
22753 jmp *%rdi
22754+ENDPROC(return_to_handler)
22755 #endif
22756
22757
22758@@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22759 ENDPROC(native_usergs_sysret64)
22760 #endif /* CONFIG_PARAVIRT */
22761
22762+ .macro ljmpq sel, off
22763+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22764+ .byte 0x48; ljmp *1234f(%rip)
22765+ .pushsection .rodata
22766+ .align 16
22767+ 1234: .quad \off; .word \sel
22768+ .popsection
22769+#else
22770+ pushq $\sel
22771+ pushq $\off
22772+ lretq
22773+#endif
22774+ .endm
22775+
22776+ .macro pax_enter_kernel
22777+ pax_set_fptr_mask
22778+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22779+ call pax_enter_kernel
22780+#endif
22781+ .endm
22782+
22783+ .macro pax_exit_kernel
22784+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22785+ call pax_exit_kernel
22786+#endif
22787+
22788+ .endm
22789+
22790+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22791+ENTRY(pax_enter_kernel)
22792+ pushq %rdi
22793+
22794+#ifdef CONFIG_PARAVIRT
22795+ PV_SAVE_REGS(CLBR_RDI)
22796+#endif
22797+
22798+#ifdef CONFIG_PAX_KERNEXEC
22799+ GET_CR0_INTO_RDI
22800+ bts $16,%rdi
22801+ jnc 3f
22802+ mov %cs,%edi
22803+ cmp $__KERNEL_CS,%edi
22804+ jnz 2f
22805+1:
22806+#endif
22807+
22808+#ifdef CONFIG_PAX_MEMORY_UDEREF
22809+ 661: jmp 111f
22810+ .pushsection .altinstr_replacement, "a"
22811+ 662: ASM_NOP2
22812+ .popsection
22813+ .pushsection .altinstructions, "a"
22814+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22815+ .popsection
22816+ GET_CR3_INTO_RDI
22817+ cmp $0,%dil
22818+ jnz 112f
22819+ mov $__KERNEL_DS,%edi
22820+ mov %edi,%ss
22821+ jmp 111f
22822+112: cmp $1,%dil
22823+ jz 113f
22824+ ud2
22825+113: sub $4097,%rdi
22826+ bts $63,%rdi
22827+ SET_RDI_INTO_CR3
22828+ mov $__UDEREF_KERNEL_DS,%edi
22829+ mov %edi,%ss
22830+111:
22831+#endif
22832+
22833+#ifdef CONFIG_PARAVIRT
22834+ PV_RESTORE_REGS(CLBR_RDI)
22835+#endif
22836+
22837+ popq %rdi
22838+ pax_force_retaddr
22839+ retq
22840+
22841+#ifdef CONFIG_PAX_KERNEXEC
22842+2: ljmpq __KERNEL_CS,1b
22843+3: ljmpq __KERNEXEC_KERNEL_CS,4f
22844+4: SET_RDI_INTO_CR0
22845+ jmp 1b
22846+#endif
22847+ENDPROC(pax_enter_kernel)
22848+
22849+ENTRY(pax_exit_kernel)
22850+ pushq %rdi
22851+
22852+#ifdef CONFIG_PARAVIRT
22853+ PV_SAVE_REGS(CLBR_RDI)
22854+#endif
22855+
22856+#ifdef CONFIG_PAX_KERNEXEC
22857+ mov %cs,%rdi
22858+ cmp $__KERNEXEC_KERNEL_CS,%edi
22859+ jz 2f
22860+ GET_CR0_INTO_RDI
22861+ bts $16,%rdi
22862+ jnc 4f
22863+1:
22864+#endif
22865+
22866+#ifdef CONFIG_PAX_MEMORY_UDEREF
22867+ 661: jmp 111f
22868+ .pushsection .altinstr_replacement, "a"
22869+ 662: ASM_NOP2
22870+ .popsection
22871+ .pushsection .altinstructions, "a"
22872+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22873+ .popsection
22874+ mov %ss,%edi
22875+ cmp $__UDEREF_KERNEL_DS,%edi
22876+ jnz 111f
22877+ GET_CR3_INTO_RDI
22878+ cmp $0,%dil
22879+ jz 112f
22880+ ud2
22881+112: add $4097,%rdi
22882+ bts $63,%rdi
22883+ SET_RDI_INTO_CR3
22884+ mov $__KERNEL_DS,%edi
22885+ mov %edi,%ss
22886+111:
22887+#endif
22888+
22889+#ifdef CONFIG_PARAVIRT
22890+ PV_RESTORE_REGS(CLBR_RDI);
22891+#endif
22892+
22893+ popq %rdi
22894+ pax_force_retaddr
22895+ retq
22896+
22897+#ifdef CONFIG_PAX_KERNEXEC
22898+2: GET_CR0_INTO_RDI
22899+ btr $16,%rdi
22900+ jnc 4f
22901+ ljmpq __KERNEL_CS,3f
22902+3: SET_RDI_INTO_CR0
22903+ jmp 1b
22904+4: ud2
22905+ jmp 4b
22906+#endif
22907+ENDPROC(pax_exit_kernel)
22908+#endif
22909+
22910+ .macro pax_enter_kernel_user
22911+ pax_set_fptr_mask
22912+#ifdef CONFIG_PAX_MEMORY_UDEREF
22913+ call pax_enter_kernel_user
22914+#endif
22915+ .endm
22916+
22917+ .macro pax_exit_kernel_user
22918+#ifdef CONFIG_PAX_MEMORY_UDEREF
22919+ call pax_exit_kernel_user
22920+#endif
22921+#ifdef CONFIG_PAX_RANDKSTACK
22922+ pushq %rax
22923+ pushq %r11
22924+ call pax_randomize_kstack
22925+ popq %r11
22926+ popq %rax
22927+#endif
22928+ .endm
22929+
22930+#ifdef CONFIG_PAX_MEMORY_UDEREF
22931+ENTRY(pax_enter_kernel_user)
22932+ pushq %rdi
22933+ pushq %rbx
22934+
22935+#ifdef CONFIG_PARAVIRT
22936+ PV_SAVE_REGS(CLBR_RDI)
22937+#endif
22938+
22939+ 661: jmp 111f
22940+ .pushsection .altinstr_replacement, "a"
22941+ 662: ASM_NOP2
22942+ .popsection
22943+ .pushsection .altinstructions, "a"
22944+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22945+ .popsection
22946+ GET_CR3_INTO_RDI
22947+ cmp $1,%dil
22948+ jnz 4f
22949+ sub $4097,%rdi
22950+ bts $63,%rdi
22951+ SET_RDI_INTO_CR3
22952+ jmp 3f
22953+111:
22954+
22955+ GET_CR3_INTO_RDI
22956+ mov %rdi,%rbx
22957+ add $__START_KERNEL_map,%rbx
22958+ sub phys_base(%rip),%rbx
22959+
22960+#ifdef CONFIG_PARAVIRT
22961+ cmpl $0, pv_info+PARAVIRT_enabled
22962+ jz 1f
22963+ pushq %rdi
22964+ i = 0
22965+ .rept USER_PGD_PTRS
22966+ mov i*8(%rbx),%rsi
22967+ mov $0,%sil
22968+ lea i*8(%rbx),%rdi
22969+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22970+ i = i + 1
22971+ .endr
22972+ popq %rdi
22973+ jmp 2f
22974+1:
22975+#endif
22976+
22977+ i = 0
22978+ .rept USER_PGD_PTRS
22979+ movb $0,i*8(%rbx)
22980+ i = i + 1
22981+ .endr
22982+
22983+2: SET_RDI_INTO_CR3
22984+
22985+#ifdef CONFIG_PAX_KERNEXEC
22986+ GET_CR0_INTO_RDI
22987+ bts $16,%rdi
22988+ SET_RDI_INTO_CR0
22989+#endif
22990+
22991+3:
22992+
22993+#ifdef CONFIG_PARAVIRT
22994+ PV_RESTORE_REGS(CLBR_RDI)
22995+#endif
22996+
22997+ popq %rbx
22998+ popq %rdi
22999+ pax_force_retaddr
23000+ retq
23001+4: ud2
23002+ENDPROC(pax_enter_kernel_user)
23003+
23004+ENTRY(pax_exit_kernel_user)
23005+ pushq %rdi
23006+ pushq %rbx
23007+
23008+#ifdef CONFIG_PARAVIRT
23009+ PV_SAVE_REGS(CLBR_RDI)
23010+#endif
23011+
23012+ GET_CR3_INTO_RDI
23013+ 661: jmp 1f
23014+ .pushsection .altinstr_replacement, "a"
23015+ 662: ASM_NOP2
23016+ .popsection
23017+ .pushsection .altinstructions, "a"
23018+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23019+ .popsection
23020+ cmp $0,%dil
23021+ jnz 3f
23022+ add $4097,%rdi
23023+ bts $63,%rdi
23024+ SET_RDI_INTO_CR3
23025+ jmp 2f
23026+1:
23027+
23028+ mov %rdi,%rbx
23029+
23030+#ifdef CONFIG_PAX_KERNEXEC
23031+ GET_CR0_INTO_RDI
23032+ btr $16,%rdi
23033+ jnc 3f
23034+ SET_RDI_INTO_CR0
23035+#endif
23036+
23037+ add $__START_KERNEL_map,%rbx
23038+ sub phys_base(%rip),%rbx
23039+
23040+#ifdef CONFIG_PARAVIRT
23041+ cmpl $0, pv_info+PARAVIRT_enabled
23042+ jz 1f
23043+ i = 0
23044+ .rept USER_PGD_PTRS
23045+ mov i*8(%rbx),%rsi
23046+ mov $0x67,%sil
23047+ lea i*8(%rbx),%rdi
23048+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23049+ i = i + 1
23050+ .endr
23051+ jmp 2f
23052+1:
23053+#endif
23054+
23055+ i = 0
23056+ .rept USER_PGD_PTRS
23057+ movb $0x67,i*8(%rbx)
23058+ i = i + 1
23059+ .endr
23060+2:
23061+
23062+#ifdef CONFIG_PARAVIRT
23063+ PV_RESTORE_REGS(CLBR_RDI)
23064+#endif
23065+
23066+ popq %rbx
23067+ popq %rdi
23068+ pax_force_retaddr
23069+ retq
23070+3: ud2
23071+ENDPROC(pax_exit_kernel_user)
23072+#endif
23073+
23074+ .macro pax_enter_kernel_nmi
23075+ pax_set_fptr_mask
23076+
23077+#ifdef CONFIG_PAX_KERNEXEC
23078+ GET_CR0_INTO_RDI
23079+ bts $16,%rdi
23080+ jc 110f
23081+ SET_RDI_INTO_CR0
23082+ or $2,%ebx
23083+110:
23084+#endif
23085+
23086+#ifdef CONFIG_PAX_MEMORY_UDEREF
23087+ 661: jmp 111f
23088+ .pushsection .altinstr_replacement, "a"
23089+ 662: ASM_NOP2
23090+ .popsection
23091+ .pushsection .altinstructions, "a"
23092+ altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23093+ .popsection
23094+ GET_CR3_INTO_RDI
23095+ cmp $0,%dil
23096+ jz 111f
23097+ sub $4097,%rdi
23098+ or $4,%ebx
23099+ bts $63,%rdi
23100+ SET_RDI_INTO_CR3
23101+ mov $__UDEREF_KERNEL_DS,%edi
23102+ mov %edi,%ss
23103+111:
23104+#endif
23105+ .endm
23106+
23107+ .macro pax_exit_kernel_nmi
23108+#ifdef CONFIG_PAX_KERNEXEC
23109+ btr $1,%ebx
23110+ jnc 110f
23111+ GET_CR0_INTO_RDI
23112+ btr $16,%rdi
23113+ SET_RDI_INTO_CR0
23114+110:
23115+#endif
23116+
23117+#ifdef CONFIG_PAX_MEMORY_UDEREF
23118+ btr $2,%ebx
23119+ jnc 111f
23120+ GET_CR3_INTO_RDI
23121+ add $4097,%rdi
23122+ bts $63,%rdi
23123+ SET_RDI_INTO_CR3
23124+ mov $__KERNEL_DS,%edi
23125+ mov %edi,%ss
23126+111:
23127+#endif
23128+ .endm
23129+
23130+ .macro pax_erase_kstack
23131+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23132+ call pax_erase_kstack
23133+#endif
23134+ .endm
23135+
23136+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23137+ENTRY(pax_erase_kstack)
23138+ pushq %rdi
23139+ pushq %rcx
23140+ pushq %rax
23141+ pushq %r11
23142+
23143+ GET_THREAD_INFO(%r11)
23144+ mov TI_lowest_stack(%r11), %rdi
23145+ mov $-0xBEEF, %rax
23146+ std
23147+
23148+1: mov %edi, %ecx
23149+ and $THREAD_SIZE_asm - 1, %ecx
23150+ shr $3, %ecx
23151+ repne scasq
23152+ jecxz 2f
23153+
23154+ cmp $2*8, %ecx
23155+ jc 2f
23156+
23157+ mov $2*8, %ecx
23158+ repe scasq
23159+ jecxz 2f
23160+ jne 1b
23161+
23162+2: cld
23163+ mov %esp, %ecx
23164+ sub %edi, %ecx
23165+
23166+ cmp $THREAD_SIZE_asm, %rcx
23167+ jb 3f
23168+ ud2
23169+3:
23170+
23171+ shr $3, %ecx
23172+ rep stosq
23173+
23174+ mov TI_task_thread_sp0(%r11), %rdi
23175+ sub $256, %rdi
23176+ mov %rdi, TI_lowest_stack(%r11)
23177+
23178+ popq %r11
23179+ popq %rax
23180+ popq %rcx
23181+ popq %rdi
23182+ pax_force_retaddr
23183+ ret
23184+ENDPROC(pax_erase_kstack)
23185+#endif
23186
23187 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23188 #ifdef CONFIG_TRACE_IRQFLAGS
23189@@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23190 .endm
23191
23192 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23193- bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23194+ bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23195 jnc 1f
23196 TRACE_IRQS_ON_DEBUG
23197 1:
23198@@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23199 movq \tmp,R11+\offset(%rsp)
23200 .endm
23201
23202- .macro FAKE_STACK_FRAME child_rip
23203- /* push in order ss, rsp, eflags, cs, rip */
23204- xorl %eax, %eax
23205- pushq_cfi $__KERNEL_DS /* ss */
23206- /*CFI_REL_OFFSET ss,0*/
23207- pushq_cfi %rax /* rsp */
23208- CFI_REL_OFFSET rsp,0
23209- pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23210- /*CFI_REL_OFFSET rflags,0*/
23211- pushq_cfi $__KERNEL_CS /* cs */
23212- /*CFI_REL_OFFSET cs,0*/
23213- pushq_cfi \child_rip /* rip */
23214- CFI_REL_OFFSET rip,0
23215- pushq_cfi %rax /* orig rax */
23216- .endm
23217-
23218- .macro UNFAKE_STACK_FRAME
23219- addq $8*6, %rsp
23220- CFI_ADJUST_CFA_OFFSET -(6*8)
23221- .endm
23222-
23223 /*
23224 * initial frame state for interrupts (and exceptions without error code)
23225 */
23226@@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23227 /* save partial stack frame */
23228 .macro SAVE_ARGS_IRQ
23229 cld
23230- /* start from rbp in pt_regs and jump over */
23231- movq_cfi rdi, (RDI-RBP)
23232- movq_cfi rsi, (RSI-RBP)
23233- movq_cfi rdx, (RDX-RBP)
23234- movq_cfi rcx, (RCX-RBP)
23235- movq_cfi rax, (RAX-RBP)
23236- movq_cfi r8, (R8-RBP)
23237- movq_cfi r9, (R9-RBP)
23238- movq_cfi r10, (R10-RBP)
23239- movq_cfi r11, (R11-RBP)
23240+ /* start from r15 in pt_regs and jump over */
23241+ movq_cfi rdi, RDI
23242+ movq_cfi rsi, RSI
23243+ movq_cfi rdx, RDX
23244+ movq_cfi rcx, RCX
23245+ movq_cfi rax, RAX
23246+ movq_cfi r8, R8
23247+ movq_cfi r9, R9
23248+ movq_cfi r10, R10
23249+ movq_cfi r11, R11
23250+ movq_cfi r12, R12
23251
23252 /* Save rbp so that we can unwind from get_irq_regs() */
23253- movq_cfi rbp, 0
23254+ movq_cfi rbp, RBP
23255
23256 /* Save previous stack value */
23257 movq %rsp, %rsi
23258
23259- leaq -RBP(%rsp),%rdi /* arg1 for handler */
23260- testl $3, CS-RBP(%rsi)
23261+ movq %rsp,%rdi /* arg1 for handler */
23262+ testb $3, CS(%rsi)
23263 je 1f
23264 SWAPGS
23265 /*
23266@@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23267 0x06 /* DW_OP_deref */, \
23268 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23269 0x22 /* DW_OP_plus */
23270+
23271+#ifdef CONFIG_PAX_MEMORY_UDEREF
23272+ testb $3, CS(%rdi)
23273+ jnz 1f
23274+ pax_enter_kernel
23275+ jmp 2f
23276+1: pax_enter_kernel_user
23277+2:
23278+#else
23279+ pax_enter_kernel
23280+#endif
23281+
23282 /* We entered an interrupt context - irqs are off: */
23283 TRACE_IRQS_OFF
23284 .endm
23285@@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23286 js 1f /* negative -> in kernel */
23287 SWAPGS
23288 xorl %ebx,%ebx
23289-1: ret
23290+1:
23291+#ifdef CONFIG_PAX_MEMORY_UDEREF
23292+ testb $3, CS+8(%rsp)
23293+ jnz 1f
23294+ pax_enter_kernel
23295+ jmp 2f
23296+1: pax_enter_kernel_user
23297+2:
23298+#else
23299+ pax_enter_kernel
23300+#endif
23301+ pax_force_retaddr
23302+ ret
23303 CFI_ENDPROC
23304-END(save_paranoid)
23305+ENDPROC(save_paranoid)
23306+
23307+ENTRY(save_paranoid_nmi)
23308+ XCPT_FRAME 1 RDI+8
23309+ cld
23310+ movq_cfi rdi, RDI+8
23311+ movq_cfi rsi, RSI+8
23312+ movq_cfi rdx, RDX+8
23313+ movq_cfi rcx, RCX+8
23314+ movq_cfi rax, RAX+8
23315+ movq_cfi r8, R8+8
23316+ movq_cfi r9, R9+8
23317+ movq_cfi r10, R10+8
23318+ movq_cfi r11, R11+8
23319+ movq_cfi rbx, RBX+8
23320+ movq_cfi rbp, RBP+8
23321+ movq_cfi r12, R12+8
23322+ movq_cfi r13, R13+8
23323+ movq_cfi r14, R14+8
23324+ movq_cfi r15, R15+8
23325+ movl $1,%ebx
23326+ movl $MSR_GS_BASE,%ecx
23327+ rdmsr
23328+ testl %edx,%edx
23329+ js 1f /* negative -> in kernel */
23330+ SWAPGS
23331+ xorl %ebx,%ebx
23332+1: pax_enter_kernel_nmi
23333+ pax_force_retaddr
23334+ ret
23335+ CFI_ENDPROC
23336+ENDPROC(save_paranoid_nmi)
23337 .popsection
23338
23339 /*
23340@@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23341
23342 RESTORE_REST
23343
23344- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23345+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23346 jz 1f
23347
23348 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23349@@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23350 jmp ret_from_sys_call # go to the SYSRET fastpath
23351
23352 1:
23353- subq $REST_SKIP, %rsp # leave space for volatiles
23354- CFI_ADJUST_CFA_OFFSET REST_SKIP
23355 movq %rbp, %rdi
23356 call *%rbx
23357 movl $0, RAX(%rsp)
23358 RESTORE_REST
23359 jmp int_ret_from_sys_call
23360 CFI_ENDPROC
23361-END(ret_from_fork)
23362+ENDPROC(ret_from_fork)
23363
23364 /*
23365 * System call entry. Up to 6 arguments in registers are supported.
23366@@ -593,7 +1059,7 @@ END(ret_from_fork)
23367 ENTRY(system_call)
23368 CFI_STARTPROC simple
23369 CFI_SIGNAL_FRAME
23370- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23371+ CFI_DEF_CFA rsp,0
23372 CFI_REGISTER rip,rcx
23373 /*CFI_REGISTER rflags,r11*/
23374 SWAPGS_UNSAFE_STACK
23375@@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23376
23377 movq %rsp,PER_CPU_VAR(old_rsp)
23378 movq PER_CPU_VAR(kernel_stack),%rsp
23379+ SAVE_ARGS 8*6,0
23380+ pax_enter_kernel_user
23381+
23382+#ifdef CONFIG_PAX_RANDKSTACK
23383+ pax_erase_kstack
23384+#endif
23385+
23386 /*
23387 * No need to follow this irqs off/on section - it's straight
23388 * and short:
23389 */
23390 ENABLE_INTERRUPTS(CLBR_NONE)
23391- SAVE_ARGS 8,0
23392 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23393 movq %rcx,RIP-ARGOFFSET(%rsp)
23394 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23395- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23396+ GET_THREAD_INFO(%rcx)
23397+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23398 jnz tracesys
23399 system_call_fastpath:
23400 #if __SYSCALL_MASK == ~0
23401@@ -639,10 +1112,13 @@ sysret_check:
23402 LOCKDEP_SYS_EXIT
23403 DISABLE_INTERRUPTS(CLBR_NONE)
23404 TRACE_IRQS_OFF
23405- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23406+ GET_THREAD_INFO(%rcx)
23407+ movl TI_flags(%rcx),%edx
23408 andl %edi,%edx
23409 jnz sysret_careful
23410 CFI_REMEMBER_STATE
23411+ pax_exit_kernel_user
23412+ pax_erase_kstack
23413 /*
23414 * sysretq will re-enable interrupts:
23415 */
23416@@ -701,6 +1177,9 @@ auditsys:
23417 movq %rax,%rsi /* 2nd arg: syscall number */
23418 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23419 call __audit_syscall_entry
23420+
23421+ pax_erase_kstack
23422+
23423 LOAD_ARGS 0 /* reload call-clobbered registers */
23424 jmp system_call_fastpath
23425
23426@@ -722,7 +1201,7 @@ sysret_audit:
23427 /* Do syscall tracing */
23428 tracesys:
23429 #ifdef CONFIG_AUDITSYSCALL
23430- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23431+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23432 jz auditsys
23433 #endif
23434 SAVE_REST
23435@@ -730,12 +1209,15 @@ tracesys:
23436 FIXUP_TOP_OF_STACK %rdi
23437 movq %rsp,%rdi
23438 call syscall_trace_enter
23439+
23440+ pax_erase_kstack
23441+
23442 /*
23443 * Reload arg registers from stack in case ptrace changed them.
23444 * We don't reload %rax because syscall_trace_enter() returned
23445 * the value it wants us to use in the table lookup.
23446 */
23447- LOAD_ARGS ARGOFFSET, 1
23448+ LOAD_ARGS 1
23449 RESTORE_REST
23450 #if __SYSCALL_MASK == ~0
23451 cmpq $__NR_syscall_max,%rax
23452@@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23453 andl %edi,%edx
23454 jnz int_careful
23455 andl $~TS_COMPAT,TI_status(%rcx)
23456- jmp retint_swapgs
23457+ pax_exit_kernel_user
23458+ pax_erase_kstack
23459+ jmp retint_swapgs_pax
23460
23461 /* Either reschedule or signal or syscall exit tracking needed. */
23462 /* First do a reschedule test. */
23463@@ -811,7 +1295,7 @@ int_restore_rest:
23464 TRACE_IRQS_OFF
23465 jmp int_with_check
23466 CFI_ENDPROC
23467-END(system_call)
23468+ENDPROC(system_call)
23469
23470 .macro FORK_LIKE func
23471 ENTRY(stub_\func)
23472@@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23473 DEFAULT_FRAME 0 8 /* offset 8: return address */
23474 call sys_\func
23475 RESTORE_TOP_OF_STACK %r11, 8
23476- ret $REST_SKIP /* pop extended registers */
23477+ pax_force_retaddr
23478+ ret
23479 CFI_ENDPROC
23480-END(stub_\func)
23481+ENDPROC(stub_\func)
23482 .endm
23483
23484 .macro FIXED_FRAME label,func
23485@@ -836,9 +1321,10 @@ ENTRY(\label)
23486 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23487 call \func
23488 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23489+ pax_force_retaddr
23490 ret
23491 CFI_ENDPROC
23492-END(\label)
23493+ENDPROC(\label)
23494 .endm
23495
23496 FORK_LIKE clone
23497@@ -846,19 +1332,6 @@ END(\label)
23498 FORK_LIKE vfork
23499 FIXED_FRAME stub_iopl, sys_iopl
23500
23501-ENTRY(ptregscall_common)
23502- DEFAULT_FRAME 1 8 /* offset 8: return address */
23503- RESTORE_TOP_OF_STACK %r11, 8
23504- movq_cfi_restore R15+8, r15
23505- movq_cfi_restore R14+8, r14
23506- movq_cfi_restore R13+8, r13
23507- movq_cfi_restore R12+8, r12
23508- movq_cfi_restore RBP+8, rbp
23509- movq_cfi_restore RBX+8, rbx
23510- ret $REST_SKIP /* pop extended registers */
23511- CFI_ENDPROC
23512-END(ptregscall_common)
23513-
23514 ENTRY(stub_execve)
23515 CFI_STARTPROC
23516 addq $8, %rsp
23517@@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23518 RESTORE_REST
23519 jmp int_ret_from_sys_call
23520 CFI_ENDPROC
23521-END(stub_execve)
23522+ENDPROC(stub_execve)
23523
23524 /*
23525 * sigreturn is special because it needs to restore all registers on return.
23526@@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23527 RESTORE_REST
23528 jmp int_ret_from_sys_call
23529 CFI_ENDPROC
23530-END(stub_rt_sigreturn)
23531+ENDPROC(stub_rt_sigreturn)
23532
23533 #ifdef CONFIG_X86_X32_ABI
23534 ENTRY(stub_x32_rt_sigreturn)
23535@@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23536 RESTORE_REST
23537 jmp int_ret_from_sys_call
23538 CFI_ENDPROC
23539-END(stub_x32_rt_sigreturn)
23540+ENDPROC(stub_x32_rt_sigreturn)
23541
23542 ENTRY(stub_x32_execve)
23543 CFI_STARTPROC
23544@@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23545 RESTORE_REST
23546 jmp int_ret_from_sys_call
23547 CFI_ENDPROC
23548-END(stub_x32_execve)
23549+ENDPROC(stub_x32_execve)
23550
23551 #endif
23552
23553@@ -952,7 +1425,7 @@ vector=vector+1
23554 2: jmp common_interrupt
23555 .endr
23556 CFI_ENDPROC
23557-END(irq_entries_start)
23558+ENDPROC(irq_entries_start)
23559
23560 .previous
23561 END(interrupt)
23562@@ -969,8 +1442,8 @@ END(interrupt)
23563 /* 0(%rsp): ~(interrupt number) */
23564 .macro interrupt func
23565 /* reserve pt_regs for scratch regs and rbp */
23566- subq $ORIG_RAX-RBP, %rsp
23567- CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23568+ subq $ORIG_RAX, %rsp
23569+ CFI_ADJUST_CFA_OFFSET ORIG_RAX
23570 SAVE_ARGS_IRQ
23571 call \func
23572 .endm
23573@@ -997,14 +1470,14 @@ ret_from_intr:
23574
23575 /* Restore saved previous stack */
23576 popq %rsi
23577- CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23578- leaq ARGOFFSET-RBP(%rsi), %rsp
23579+ CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23580+ movq %rsi, %rsp
23581 CFI_DEF_CFA_REGISTER rsp
23582- CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23583+ CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23584
23585 exit_intr:
23586 GET_THREAD_INFO(%rcx)
23587- testl $3,CS-ARGOFFSET(%rsp)
23588+ testb $3,CS-ARGOFFSET(%rsp)
23589 je retint_kernel
23590
23591 /* Interrupt came from user space */
23592@@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23593 * The iretq could re-enable interrupts:
23594 */
23595 DISABLE_INTERRUPTS(CLBR_ANY)
23596+ pax_exit_kernel_user
23597+retint_swapgs_pax:
23598 TRACE_IRQS_IRETQ
23599 SWAPGS
23600 jmp restore_args
23601
23602 retint_restore_args: /* return to kernel space */
23603 DISABLE_INTERRUPTS(CLBR_ANY)
23604+ pax_exit_kernel
23605+ pax_force_retaddr (RIP-ARGOFFSET)
23606 /*
23607 * The iretq could re-enable interrupts:
23608 */
23609@@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23610 #endif
23611
23612 CFI_ENDPROC
23613-END(common_interrupt)
23614+ENDPROC(common_interrupt)
23615 /*
23616 * End of kprobes section
23617 */
23618@@ -1130,7 +1607,7 @@ ENTRY(\sym)
23619 interrupt \do_sym
23620 jmp ret_from_intr
23621 CFI_ENDPROC
23622-END(\sym)
23623+ENDPROC(\sym)
23624 .endm
23625
23626 #ifdef CONFIG_TRACING
23627@@ -1218,7 +1695,7 @@ ENTRY(\sym)
23628 call \do_sym
23629 jmp error_exit /* %ebx: no swapgs flag */
23630 CFI_ENDPROC
23631-END(\sym)
23632+ENDPROC(\sym)
23633 .endm
23634
23635 .macro paranoidzeroentry sym do_sym
23636@@ -1236,10 +1713,10 @@ ENTRY(\sym)
23637 call \do_sym
23638 jmp paranoid_exit /* %ebx: no swapgs flag */
23639 CFI_ENDPROC
23640-END(\sym)
23641+ENDPROC(\sym)
23642 .endm
23643
23644-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23645+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23646 .macro paranoidzeroentry_ist sym do_sym ist
23647 ENTRY(\sym)
23648 INTR_FRAME
23649@@ -1252,12 +1729,18 @@ ENTRY(\sym)
23650 TRACE_IRQS_OFF_DEBUG
23651 movq %rsp,%rdi /* pt_regs pointer */
23652 xorl %esi,%esi /* no error code */
23653+#ifdef CONFIG_SMP
23654+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23655+ lea init_tss(%r13), %r13
23656+#else
23657+ lea init_tss(%rip), %r13
23658+#endif
23659 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23660 call \do_sym
23661 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23662 jmp paranoid_exit /* %ebx: no swapgs flag */
23663 CFI_ENDPROC
23664-END(\sym)
23665+ENDPROC(\sym)
23666 .endm
23667
23668 .macro errorentry sym do_sym
23669@@ -1275,7 +1758,7 @@ ENTRY(\sym)
23670 call \do_sym
23671 jmp error_exit /* %ebx: no swapgs flag */
23672 CFI_ENDPROC
23673-END(\sym)
23674+ENDPROC(\sym)
23675 .endm
23676
23677 #ifdef CONFIG_TRACING
23678@@ -1306,7 +1789,7 @@ ENTRY(\sym)
23679 call \do_sym
23680 jmp paranoid_exit /* %ebx: no swapgs flag */
23681 CFI_ENDPROC
23682-END(\sym)
23683+ENDPROC(\sym)
23684 .endm
23685
23686 zeroentry divide_error do_divide_error
23687@@ -1336,9 +1819,10 @@ gs_change:
23688 2: mfence /* workaround */
23689 SWAPGS
23690 popfq_cfi
23691+ pax_force_retaddr
23692 ret
23693 CFI_ENDPROC
23694-END(native_load_gs_index)
23695+ENDPROC(native_load_gs_index)
23696
23697 _ASM_EXTABLE(gs_change,bad_gs)
23698 .section .fixup,"ax"
23699@@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23700 CFI_DEF_CFA_REGISTER rsp
23701 CFI_ADJUST_CFA_OFFSET -8
23702 decl PER_CPU_VAR(irq_count)
23703+ pax_force_retaddr
23704 ret
23705 CFI_ENDPROC
23706-END(do_softirq_own_stack)
23707+ENDPROC(do_softirq_own_stack)
23708
23709 #ifdef CONFIG_XEN
23710 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23711@@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23712 decl PER_CPU_VAR(irq_count)
23713 jmp error_exit
23714 CFI_ENDPROC
23715-END(xen_do_hypervisor_callback)
23716+ENDPROC(xen_do_hypervisor_callback)
23717
23718 /*
23719 * Hypervisor uses this for application faults while it executes.
23720@@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23721 SAVE_ALL
23722 jmp error_exit
23723 CFI_ENDPROC
23724-END(xen_failsafe_callback)
23725+ENDPROC(xen_failsafe_callback)
23726
23727 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23728 xen_hvm_callback_vector xen_evtchn_do_upcall
23729@@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23730 DEFAULT_FRAME
23731 DISABLE_INTERRUPTS(CLBR_NONE)
23732 TRACE_IRQS_OFF_DEBUG
23733- testl %ebx,%ebx /* swapgs needed? */
23734+ testl $1,%ebx /* swapgs needed? */
23735 jnz paranoid_restore
23736- testl $3,CS(%rsp)
23737+ testb $3,CS(%rsp)
23738 jnz paranoid_userspace
23739+#ifdef CONFIG_PAX_MEMORY_UDEREF
23740+ pax_exit_kernel
23741+ TRACE_IRQS_IRETQ 0
23742+ SWAPGS_UNSAFE_STACK
23743+ RESTORE_ALL 8
23744+ pax_force_retaddr_bts
23745+ jmp irq_return
23746+#endif
23747 paranoid_swapgs:
23748+#ifdef CONFIG_PAX_MEMORY_UDEREF
23749+ pax_exit_kernel_user
23750+#else
23751+ pax_exit_kernel
23752+#endif
23753 TRACE_IRQS_IRETQ 0
23754 SWAPGS_UNSAFE_STACK
23755 RESTORE_ALL 8
23756 jmp irq_return
23757 paranoid_restore:
23758+ pax_exit_kernel
23759 TRACE_IRQS_IRETQ_DEBUG 0
23760 RESTORE_ALL 8
23761+ pax_force_retaddr_bts
23762 jmp irq_return
23763 paranoid_userspace:
23764 GET_THREAD_INFO(%rcx)
23765@@ -1557,7 +2057,7 @@ paranoid_schedule:
23766 TRACE_IRQS_OFF
23767 jmp paranoid_userspace
23768 CFI_ENDPROC
23769-END(paranoid_exit)
23770+ENDPROC(paranoid_exit)
23771
23772 /*
23773 * Exception entry point. This expects an error code/orig_rax on the stack.
23774@@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23775 movq_cfi r14, R14+8
23776 movq_cfi r15, R15+8
23777 xorl %ebx,%ebx
23778- testl $3,CS+8(%rsp)
23779+ testb $3,CS+8(%rsp)
23780 je error_kernelspace
23781 error_swapgs:
23782 SWAPGS
23783 error_sti:
23784+#ifdef CONFIG_PAX_MEMORY_UDEREF
23785+ testb $3, CS+8(%rsp)
23786+ jnz 1f
23787+ pax_enter_kernel
23788+ jmp 2f
23789+1: pax_enter_kernel_user
23790+2:
23791+#else
23792+ pax_enter_kernel
23793+#endif
23794 TRACE_IRQS_OFF
23795+ pax_force_retaddr
23796 ret
23797
23798 /*
23799@@ -1616,7 +2127,7 @@ bstep_iret:
23800 movq %rcx,RIP+8(%rsp)
23801 jmp error_swapgs
23802 CFI_ENDPROC
23803-END(error_entry)
23804+ENDPROC(error_entry)
23805
23806
23807 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23808@@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23809 DISABLE_INTERRUPTS(CLBR_NONE)
23810 TRACE_IRQS_OFF
23811 GET_THREAD_INFO(%rcx)
23812- testl %eax,%eax
23813+ testl $1,%eax
23814 jne retint_kernel
23815 LOCKDEP_SYS_EXIT_IRQ
23816 movl TI_flags(%rcx),%edx
23817@@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23818 jnz retint_careful
23819 jmp retint_swapgs
23820 CFI_ENDPROC
23821-END(error_exit)
23822+ENDPROC(error_exit)
23823
23824 /*
23825 * Test if a given stack is an NMI stack or not.
23826@@ -1694,9 +2205,11 @@ ENTRY(nmi)
23827 * If %cs was not the kernel segment, then the NMI triggered in user
23828 * space, which means it is definitely not nested.
23829 */
23830+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23831+ je 1f
23832 cmpl $__KERNEL_CS, 16(%rsp)
23833 jne first_nmi
23834-
23835+1:
23836 /*
23837 * Check the special variable on the stack to see if NMIs are
23838 * executing.
23839@@ -1730,8 +2243,7 @@ nested_nmi:
23840
23841 1:
23842 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23843- leaq -1*8(%rsp), %rdx
23844- movq %rdx, %rsp
23845+ subq $8, %rsp
23846 CFI_ADJUST_CFA_OFFSET 1*8
23847 leaq -10*8(%rsp), %rdx
23848 pushq_cfi $__KERNEL_DS
23849@@ -1749,6 +2261,7 @@ nested_nmi_out:
23850 CFI_RESTORE rdx
23851
23852 /* No need to check faults here */
23853+# pax_force_retaddr_bts
23854 INTERRUPT_RETURN
23855
23856 CFI_RESTORE_STATE
23857@@ -1845,13 +2358,13 @@ end_repeat_nmi:
23858 subq $ORIG_RAX-R15, %rsp
23859 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23860 /*
23861- * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23862+ * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23863 * as we should not be calling schedule in NMI context.
23864 * Even with normal interrupts enabled. An NMI should not be
23865 * setting NEED_RESCHED or anything that normal interrupts and
23866 * exceptions might do.
23867 */
23868- call save_paranoid
23869+ call save_paranoid_nmi
23870 DEFAULT_FRAME 0
23871
23872 /*
23873@@ -1861,9 +2374,9 @@ end_repeat_nmi:
23874 * NMI itself takes a page fault, the page fault that was preempted
23875 * will read the information from the NMI page fault and not the
23876 * origin fault. Save it off and restore it if it changes.
23877- * Use the r12 callee-saved register.
23878+ * Use the r13 callee-saved register.
23879 */
23880- movq %cr2, %r12
23881+ movq %cr2, %r13
23882
23883 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23884 movq %rsp,%rdi
23885@@ -1872,31 +2385,36 @@ end_repeat_nmi:
23886
23887 /* Did the NMI take a page fault? Restore cr2 if it did */
23888 movq %cr2, %rcx
23889- cmpq %rcx, %r12
23890+ cmpq %rcx, %r13
23891 je 1f
23892- movq %r12, %cr2
23893+ movq %r13, %cr2
23894 1:
23895
23896- testl %ebx,%ebx /* swapgs needed? */
23897+ testl $1,%ebx /* swapgs needed? */
23898 jnz nmi_restore
23899 nmi_swapgs:
23900 SWAPGS_UNSAFE_STACK
23901 nmi_restore:
23902+ pax_exit_kernel_nmi
23903 /* Pop the extra iret frame at once */
23904 RESTORE_ALL 6*8
23905+ testb $3, 8(%rsp)
23906+ jnz 1f
23907+ pax_force_retaddr_bts
23908+1:
23909
23910 /* Clear the NMI executing stack variable */
23911 movq $0, 5*8(%rsp)
23912 jmp irq_return
23913 CFI_ENDPROC
23914-END(nmi)
23915+ENDPROC(nmi)
23916
23917 ENTRY(ignore_sysret)
23918 CFI_STARTPROC
23919 mov $-ENOSYS,%eax
23920 sysret
23921 CFI_ENDPROC
23922-END(ignore_sysret)
23923+ENDPROC(ignore_sysret)
23924
23925 /*
23926 * End of kprobes section
23927diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23928index e625319..b9abb9d 100644
23929--- a/arch/x86/kernel/ftrace.c
23930+++ b/arch/x86/kernel/ftrace.c
23931@@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23932 {
23933 unsigned char replaced[MCOUNT_INSN_SIZE];
23934
23935+ ip = ktla_ktva(ip);
23936+
23937 /*
23938 * Note: Due to modules and __init, code can
23939 * disappear and change, we need to protect against faulting
23940@@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
23941 unsigned char old[MCOUNT_INSN_SIZE];
23942 int ret;
23943
23944- memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
23945+ memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
23946
23947 ftrace_update_func = ip;
23948 /* Make sure the breakpoints see the ftrace_update_func update */
23949@@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23950 * kernel identity mapping to modify code.
23951 */
23952 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23953- ip = (unsigned long)__va(__pa_symbol(ip));
23954+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23955
23956 return probe_kernel_write((void *)ip, val, size);
23957 }
23958@@ -316,7 +318,7 @@ static int add_break(unsigned long ip, const char *old)
23959 unsigned char replaced[MCOUNT_INSN_SIZE];
23960 unsigned char brk = BREAKPOINT_INSTRUCTION;
23961
23962- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23963+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23964 return -EFAULT;
23965
23966 /* Make sure it is what we expect it to be */
23967@@ -664,7 +666,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23968 return ret;
23969
23970 fail_update:
23971- probe_kernel_write((void *)ip, &old_code[0], 1);
23972+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23973 goto out;
23974 }
23975
23976diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23977index 85126cc..1bbce17 100644
23978--- a/arch/x86/kernel/head64.c
23979+++ b/arch/x86/kernel/head64.c
23980@@ -67,12 +67,12 @@ again:
23981 pgd = *pgd_p;
23982
23983 /*
23984- * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23985- * critical -- __PAGE_OFFSET would point us back into the dynamic
23986+ * The use of __early_va rather than __va here is critical:
23987+ * __va would point us back into the dynamic
23988 * range and we might end up looping forever...
23989 */
23990 if (pgd)
23991- pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23992+ pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23993 else {
23994 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23995 reset_early_page_tables();
23996@@ -82,13 +82,13 @@ again:
23997 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23998 for (i = 0; i < PTRS_PER_PUD; i++)
23999 pud_p[i] = 0;
24000- *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24001+ *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24002 }
24003 pud_p += pud_index(address);
24004 pud = *pud_p;
24005
24006 if (pud)
24007- pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24008+ pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24009 else {
24010 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24011 reset_early_page_tables();
24012@@ -98,7 +98,7 @@ again:
24013 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24014 for (i = 0; i < PTRS_PER_PMD; i++)
24015 pmd_p[i] = 0;
24016- *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24017+ *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24018 }
24019 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24020 pmd_p[pmd_index(address)] = pmd;
24021@@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
24022 if (console_loglevel == 10)
24023 early_printk("Kernel alive\n");
24024
24025- clear_page(init_level4_pgt);
24026 /* set init_level4_pgt kernel high mapping*/
24027 init_level4_pgt[511] = early_level4_pgt[511];
24028
24029diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24030index f36bd42..56ee1534 100644
24031--- a/arch/x86/kernel/head_32.S
24032+++ b/arch/x86/kernel/head_32.S
24033@@ -26,6 +26,12 @@
24034 /* Physical address */
24035 #define pa(X) ((X) - __PAGE_OFFSET)
24036
24037+#ifdef CONFIG_PAX_KERNEXEC
24038+#define ta(X) (X)
24039+#else
24040+#define ta(X) ((X) - __PAGE_OFFSET)
24041+#endif
24042+
24043 /*
24044 * References to members of the new_cpu_data structure.
24045 */
24046@@ -55,11 +61,7 @@
24047 * and small than max_low_pfn, otherwise will waste some page table entries
24048 */
24049
24050-#if PTRS_PER_PMD > 1
24051-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24052-#else
24053-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24054-#endif
24055+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24056
24057 /* Number of possible pages in the lowmem region */
24058 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24059@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24060 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24061
24062 /*
24063+ * Real beginning of normal "text" segment
24064+ */
24065+ENTRY(stext)
24066+ENTRY(_stext)
24067+
24068+/*
24069 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24070 * %esi points to the real-mode code as a 32-bit pointer.
24071 * CS and DS must be 4 GB flat segments, but we don't depend on
24072@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24073 * can.
24074 */
24075 __HEAD
24076+
24077+#ifdef CONFIG_PAX_KERNEXEC
24078+ jmp startup_32
24079+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24080+.fill PAGE_SIZE-5,1,0xcc
24081+#endif
24082+
24083 ENTRY(startup_32)
24084 movl pa(stack_start),%ecx
24085
24086@@ -106,6 +121,59 @@ ENTRY(startup_32)
24087 2:
24088 leal -__PAGE_OFFSET(%ecx),%esp
24089
24090+#ifdef CONFIG_SMP
24091+ movl $pa(cpu_gdt_table),%edi
24092+ movl $__per_cpu_load,%eax
24093+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24094+ rorl $16,%eax
24095+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24096+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24097+ movl $__per_cpu_end - 1,%eax
24098+ subl $__per_cpu_start,%eax
24099+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24100+#endif
24101+
24102+#ifdef CONFIG_PAX_MEMORY_UDEREF
24103+ movl $NR_CPUS,%ecx
24104+ movl $pa(cpu_gdt_table),%edi
24105+1:
24106+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24107+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24108+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24109+ addl $PAGE_SIZE_asm,%edi
24110+ loop 1b
24111+#endif
24112+
24113+#ifdef CONFIG_PAX_KERNEXEC
24114+ movl $pa(boot_gdt),%edi
24115+ movl $__LOAD_PHYSICAL_ADDR,%eax
24116+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24117+ rorl $16,%eax
24118+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24119+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24120+ rorl $16,%eax
24121+
24122+ ljmp $(__BOOT_CS),$1f
24123+1:
24124+
24125+ movl $NR_CPUS,%ecx
24126+ movl $pa(cpu_gdt_table),%edi
24127+ addl $__PAGE_OFFSET,%eax
24128+1:
24129+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24130+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24131+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24132+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24133+ rorl $16,%eax
24134+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24135+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24136+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24137+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24138+ rorl $16,%eax
24139+ addl $PAGE_SIZE_asm,%edi
24140+ loop 1b
24141+#endif
24142+
24143 /*
24144 * Clear BSS first so that there are no surprises...
24145 */
24146@@ -201,8 +269,11 @@ ENTRY(startup_32)
24147 movl %eax, pa(max_pfn_mapped)
24148
24149 /* Do early initialization of the fixmap area */
24150- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24151- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24152+#ifdef CONFIG_COMPAT_VDSO
24153+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24154+#else
24155+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24156+#endif
24157 #else /* Not PAE */
24158
24159 page_pde_offset = (__PAGE_OFFSET >> 20);
24160@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24161 movl %eax, pa(max_pfn_mapped)
24162
24163 /* Do early initialization of the fixmap area */
24164- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24165- movl %eax,pa(initial_page_table+0xffc)
24166+#ifdef CONFIG_COMPAT_VDSO
24167+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24168+#else
24169+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24170+#endif
24171 #endif
24172
24173 #ifdef CONFIG_PARAVIRT
24174@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24175 cmpl $num_subarch_entries, %eax
24176 jae bad_subarch
24177
24178- movl pa(subarch_entries)(,%eax,4), %eax
24179- subl $__PAGE_OFFSET, %eax
24180- jmp *%eax
24181+ jmp *pa(subarch_entries)(,%eax,4)
24182
24183 bad_subarch:
24184 WEAK(lguest_entry)
24185@@ -261,10 +333,10 @@ WEAK(xen_entry)
24186 __INITDATA
24187
24188 subarch_entries:
24189- .long default_entry /* normal x86/PC */
24190- .long lguest_entry /* lguest hypervisor */
24191- .long xen_entry /* Xen hypervisor */
24192- .long default_entry /* Moorestown MID */
24193+ .long ta(default_entry) /* normal x86/PC */
24194+ .long ta(lguest_entry) /* lguest hypervisor */
24195+ .long ta(xen_entry) /* Xen hypervisor */
24196+ .long ta(default_entry) /* Moorestown MID */
24197 num_subarch_entries = (. - subarch_entries) / 4
24198 .previous
24199 #else
24200@@ -354,6 +426,7 @@ default_entry:
24201 movl pa(mmu_cr4_features),%eax
24202 movl %eax,%cr4
24203
24204+#ifdef CONFIG_X86_PAE
24205 testb $X86_CR4_PAE, %al # check if PAE is enabled
24206 jz enable_paging
24207
24208@@ -382,6 +455,9 @@ default_entry:
24209 /* Make changes effective */
24210 wrmsr
24211
24212+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24213+#endif
24214+
24215 enable_paging:
24216
24217 /*
24218@@ -449,14 +525,20 @@ is486:
24219 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24220 movl %eax,%ss # after changing gdt.
24221
24222- movl $(__USER_DS),%eax # DS/ES contains default USER segment
24223+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24224 movl %eax,%ds
24225 movl %eax,%es
24226
24227 movl $(__KERNEL_PERCPU), %eax
24228 movl %eax,%fs # set this cpu's percpu
24229
24230+#ifdef CONFIG_CC_STACKPROTECTOR
24231 movl $(__KERNEL_STACK_CANARY),%eax
24232+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24233+ movl $(__USER_DS),%eax
24234+#else
24235+ xorl %eax,%eax
24236+#endif
24237 movl %eax,%gs
24238
24239 xorl %eax,%eax # Clear LDT
24240@@ -512,8 +594,11 @@ setup_once:
24241 * relocation. Manually set base address in stack canary
24242 * segment descriptor.
24243 */
24244- movl $gdt_page,%eax
24245+ movl $cpu_gdt_table,%eax
24246 movl $stack_canary,%ecx
24247+#ifdef CONFIG_SMP
24248+ addl $__per_cpu_load,%ecx
24249+#endif
24250 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24251 shrl $16, %ecx
24252 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24253@@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24254 cmpl $2,(%esp) # X86_TRAP_NMI
24255 je is_nmi # Ignore NMI
24256
24257- cmpl $2,%ss:early_recursion_flag
24258+ cmpl $1,%ss:early_recursion_flag
24259 je hlt_loop
24260 incl %ss:early_recursion_flag
24261
24262@@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24263 pushl (20+6*4)(%esp) /* trapno */
24264 pushl $fault_msg
24265 call printk
24266-#endif
24267 call dump_stack
24268+#endif
24269 hlt_loop:
24270 hlt
24271 jmp hlt_loop
24272@@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24273 /* This is the default interrupt "handler" :-) */
24274 ALIGN
24275 ignore_int:
24276- cld
24277 #ifdef CONFIG_PRINTK
24278+ cmpl $2,%ss:early_recursion_flag
24279+ je hlt_loop
24280+ incl %ss:early_recursion_flag
24281+ cld
24282 pushl %eax
24283 pushl %ecx
24284 pushl %edx
24285@@ -617,9 +705,6 @@ ignore_int:
24286 movl $(__KERNEL_DS),%eax
24287 movl %eax,%ds
24288 movl %eax,%es
24289- cmpl $2,early_recursion_flag
24290- je hlt_loop
24291- incl early_recursion_flag
24292 pushl 16(%esp)
24293 pushl 24(%esp)
24294 pushl 32(%esp)
24295@@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24296 /*
24297 * BSS section
24298 */
24299-__PAGE_ALIGNED_BSS
24300- .align PAGE_SIZE
24301 #ifdef CONFIG_X86_PAE
24302+.section .initial_pg_pmd,"a",@progbits
24303 initial_pg_pmd:
24304 .fill 1024*KPMDS,4,0
24305 #else
24306+.section .initial_page_table,"a",@progbits
24307 ENTRY(initial_page_table)
24308 .fill 1024,4,0
24309 #endif
24310+.section .initial_pg_fixmap,"a",@progbits
24311 initial_pg_fixmap:
24312 .fill 1024,4,0
24313+.section .empty_zero_page,"a",@progbits
24314 ENTRY(empty_zero_page)
24315 .fill 4096,1,0
24316+.section .swapper_pg_dir,"a",@progbits
24317 ENTRY(swapper_pg_dir)
24318+#ifdef CONFIG_X86_PAE
24319+ .fill 4,8,0
24320+#else
24321 .fill 1024,4,0
24322+#endif
24323
24324 /*
24325 * This starts the data section.
24326 */
24327 #ifdef CONFIG_X86_PAE
24328-__PAGE_ALIGNED_DATA
24329- /* Page-aligned for the benefit of paravirt? */
24330- .align PAGE_SIZE
24331+.section .initial_page_table,"a",@progbits
24332 ENTRY(initial_page_table)
24333 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24334 # if KPMDS == 3
24335@@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24336 # error "Kernel PMDs should be 1, 2 or 3"
24337 # endif
24338 .align PAGE_SIZE /* needs to be page-sized too */
24339+
24340+#ifdef CONFIG_PAX_PER_CPU_PGD
24341+ENTRY(cpu_pgd)
24342+ .rept 2*NR_CPUS
24343+ .fill 4,8,0
24344+ .endr
24345+#endif
24346+
24347 #endif
24348
24349 .data
24350 .balign 4
24351 ENTRY(stack_start)
24352- .long init_thread_union+THREAD_SIZE
24353+ .long init_thread_union+THREAD_SIZE-8
24354
24355 __INITRODATA
24356 int_msg:
24357@@ -727,7 +825,7 @@ fault_msg:
24358 * segment size, and 32-bit linear address value:
24359 */
24360
24361- .data
24362+.section .rodata,"a",@progbits
24363 .globl boot_gdt_descr
24364 .globl idt_descr
24365
24366@@ -736,7 +834,7 @@ fault_msg:
24367 .word 0 # 32 bit align gdt_desc.address
24368 boot_gdt_descr:
24369 .word __BOOT_DS+7
24370- .long boot_gdt - __PAGE_OFFSET
24371+ .long pa(boot_gdt)
24372
24373 .word 0 # 32-bit align idt_desc.address
24374 idt_descr:
24375@@ -747,7 +845,7 @@ idt_descr:
24376 .word 0 # 32 bit align gdt_desc.address
24377 ENTRY(early_gdt_descr)
24378 .word GDT_ENTRIES*8-1
24379- .long gdt_page /* Overwritten for secondary CPUs */
24380+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
24381
24382 /*
24383 * The boot_gdt must mirror the equivalent in setup.S and is
24384@@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24385 .align L1_CACHE_BYTES
24386 ENTRY(boot_gdt)
24387 .fill GDT_ENTRY_BOOT_CS,8,0
24388- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24389- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24390+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24391+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24392+
24393+ .align PAGE_SIZE_asm
24394+ENTRY(cpu_gdt_table)
24395+ .rept NR_CPUS
24396+ .quad 0x0000000000000000 /* NULL descriptor */
24397+ .quad 0x0000000000000000 /* 0x0b reserved */
24398+ .quad 0x0000000000000000 /* 0x13 reserved */
24399+ .quad 0x0000000000000000 /* 0x1b reserved */
24400+
24401+#ifdef CONFIG_PAX_KERNEXEC
24402+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24403+#else
24404+ .quad 0x0000000000000000 /* 0x20 unused */
24405+#endif
24406+
24407+ .quad 0x0000000000000000 /* 0x28 unused */
24408+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24409+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24410+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24411+ .quad 0x0000000000000000 /* 0x4b reserved */
24412+ .quad 0x0000000000000000 /* 0x53 reserved */
24413+ .quad 0x0000000000000000 /* 0x5b reserved */
24414+
24415+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24416+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24417+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24418+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24419+
24420+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24421+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24422+
24423+ /*
24424+ * Segments used for calling PnP BIOS have byte granularity.
24425+ * The code segments and data segments have fixed 64k limits,
24426+ * the transfer segment sizes are set at run time.
24427+ */
24428+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
24429+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
24430+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
24431+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
24432+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
24433+
24434+ /*
24435+ * The APM segments have byte granularity and their bases
24436+ * are set at run time. All have 64k limits.
24437+ */
24438+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24439+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24440+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
24441+
24442+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24443+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24444+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24445+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24446+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24447+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24448+
24449+ /* Be sure this is zeroed to avoid false validations in Xen */
24450+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24451+ .endr
24452diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24453index a468c0a..c7dec74 100644
24454--- a/arch/x86/kernel/head_64.S
24455+++ b/arch/x86/kernel/head_64.S
24456@@ -20,6 +20,8 @@
24457 #include <asm/processor-flags.h>
24458 #include <asm/percpu.h>
24459 #include <asm/nops.h>
24460+#include <asm/cpufeature.h>
24461+#include <asm/alternative-asm.h>
24462
24463 #ifdef CONFIG_PARAVIRT
24464 #include <asm/asm-offsets.h>
24465@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24466 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24467 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24468 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24469+L4_VMALLOC_START = pgd_index(VMALLOC_START)
24470+L3_VMALLOC_START = pud_index(VMALLOC_START)
24471+L4_VMALLOC_END = pgd_index(VMALLOC_END)
24472+L3_VMALLOC_END = pud_index(VMALLOC_END)
24473+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24474+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24475
24476 .text
24477 __HEAD
24478@@ -89,11 +97,24 @@ startup_64:
24479 * Fixup the physical addresses in the page table
24480 */
24481 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24482+ addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24483+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24484+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24485+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24486+ addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24487
24488- addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24489- addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24490+ addq %rbp, level3_ident_pgt + (0*8)(%rip)
24491+#ifndef CONFIG_XEN
24492+ addq %rbp, level3_ident_pgt + (1*8)(%rip)
24493+#endif
24494+
24495+ addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24496+
24497+ addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24498+ addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24499
24500 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24501+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24502
24503 /*
24504 * Set up the identity mapping for the switchover. These
24505@@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24506 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24507 1:
24508
24509- /* Enable PAE mode and PGE */
24510- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24511+ /* Enable PAE mode and PSE/PGE */
24512+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24513 movq %rcx, %cr4
24514
24515 /* Setup early boot stage 4 level pagetables. */
24516@@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24517 movl $MSR_EFER, %ecx
24518 rdmsr
24519 btsl $_EFER_SCE, %eax /* Enable System Call */
24520- btl $20,%edi /* No Execute supported? */
24521+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24522 jnc 1f
24523 btsl $_EFER_NX, %eax
24524 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24525+#ifndef CONFIG_EFI
24526+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24527+#endif
24528+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24529+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24530+ btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24531+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24532+ btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24533+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24534 1: wrmsr /* Make changes effective */
24535
24536 /* Setup cr0 */
24537@@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24538 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24539 * address given in m16:64.
24540 */
24541+ pax_set_fptr_mask
24542 movq initial_code(%rip),%rax
24543 pushq $0 # fake return address to stop unwinder
24544 pushq $__KERNEL_CS # set correct cs
24545@@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24546 .quad INIT_PER_CPU_VAR(irq_stack_union)
24547
24548 GLOBAL(stack_start)
24549- .quad init_thread_union+THREAD_SIZE-8
24550+ .quad init_thread_union+THREAD_SIZE-16
24551 .word 0
24552 __FINITDATA
24553
24554@@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24555 call dump_stack
24556 #ifdef CONFIG_KALLSYMS
24557 leaq early_idt_ripmsg(%rip),%rdi
24558- movq 40(%rsp),%rsi # %rip again
24559+ movq 88(%rsp),%rsi # %rip again
24560 call __print_symbol
24561 #endif
24562 #endif /* EARLY_PRINTK */
24563@@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24564 early_recursion_flag:
24565 .long 0
24566
24567+ .section .rodata,"a",@progbits
24568 #ifdef CONFIG_EARLY_PRINTK
24569 early_idt_msg:
24570 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24571@@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24572 NEXT_PAGE(early_dynamic_pgts)
24573 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24574
24575- .data
24576+ .section .rodata,"a",@progbits
24577
24578-#ifndef CONFIG_XEN
24579 NEXT_PAGE(init_level4_pgt)
24580- .fill 512,8,0
24581-#else
24582-NEXT_PAGE(init_level4_pgt)
24583- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24584 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24585 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24586+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
24587+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24588+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
24589+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24590+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24591+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24592 .org init_level4_pgt + L4_START_KERNEL*8, 0
24593 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24594 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24595
24596+#ifdef CONFIG_PAX_PER_CPU_PGD
24597+NEXT_PAGE(cpu_pgd)
24598+ .rept 2*NR_CPUS
24599+ .fill 512,8,0
24600+ .endr
24601+#endif
24602+
24603 NEXT_PAGE(level3_ident_pgt)
24604 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24605+#ifdef CONFIG_XEN
24606 .fill 511, 8, 0
24607+#else
24608+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24609+ .fill 510,8,0
24610+#endif
24611+
24612+NEXT_PAGE(level3_vmalloc_start_pgt)
24613+ .fill 512,8,0
24614+
24615+NEXT_PAGE(level3_vmalloc_end_pgt)
24616+ .fill 512,8,0
24617+
24618+NEXT_PAGE(level3_vmemmap_pgt)
24619+ .fill L3_VMEMMAP_START,8,0
24620+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24621+
24622 NEXT_PAGE(level2_ident_pgt)
24623- /* Since I easily can, map the first 1G.
24624+ /* Since I easily can, map the first 2G.
24625 * Don't set NX because code runs from these pages.
24626 */
24627- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24628-#endif
24629+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24630
24631 NEXT_PAGE(level3_kernel_pgt)
24632 .fill L3_START_KERNEL,8,0
24633@@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24634 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24635 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24636
24637+NEXT_PAGE(level2_vmemmap_pgt)
24638+ .fill 512,8,0
24639+
24640 NEXT_PAGE(level2_kernel_pgt)
24641 /*
24642 * 512 MB kernel mapping. We spend a full page on this pagetable
24643@@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24644 NEXT_PAGE(level2_fixmap_pgt)
24645 .fill 506,8,0
24646 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24647- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24648- .fill 5,8,0
24649+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24650+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24651+ .fill 4,8,0
24652
24653 NEXT_PAGE(level1_fixmap_pgt)
24654 .fill 512,8,0
24655
24656+NEXT_PAGE(level1_vsyscall_pgt)
24657+ .fill 512,8,0
24658+
24659 #undef PMDS
24660
24661- .data
24662+ .align PAGE_SIZE
24663+ENTRY(cpu_gdt_table)
24664+ .rept NR_CPUS
24665+ .quad 0x0000000000000000 /* NULL descriptor */
24666+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24667+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
24668+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
24669+ .quad 0x00cffb000000ffff /* __USER32_CS */
24670+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24671+ .quad 0x00affb000000ffff /* __USER_CS */
24672+
24673+#ifdef CONFIG_PAX_KERNEXEC
24674+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24675+#else
24676+ .quad 0x0 /* unused */
24677+#endif
24678+
24679+ .quad 0,0 /* TSS */
24680+ .quad 0,0 /* LDT */
24681+ .quad 0,0,0 /* three TLS descriptors */
24682+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
24683+ /* asm/segment.h:GDT_ENTRIES must match this */
24684+
24685+#ifdef CONFIG_PAX_MEMORY_UDEREF
24686+ .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24687+#else
24688+ .quad 0x0 /* unused */
24689+#endif
24690+
24691+ /* zero the remaining page */
24692+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24693+ .endr
24694+
24695 .align 16
24696 .globl early_gdt_descr
24697 early_gdt_descr:
24698 .word GDT_ENTRIES*8-1
24699 early_gdt_descr_base:
24700- .quad INIT_PER_CPU_VAR(gdt_page)
24701+ .quad cpu_gdt_table
24702
24703 ENTRY(phys_base)
24704 /* This must match the first entry in level2_kernel_pgt */
24705 .quad 0x0000000000000000
24706
24707 #include "../../x86/xen/xen-head.S"
24708-
24709- __PAGE_ALIGNED_BSS
24710+
24711+ .section .rodata,"a",@progbits
24712 NEXT_PAGE(empty_zero_page)
24713 .skip PAGE_SIZE
24714diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24715index 05fd74f..c3548b1 100644
24716--- a/arch/x86/kernel/i386_ksyms_32.c
24717+++ b/arch/x86/kernel/i386_ksyms_32.c
24718@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24719 EXPORT_SYMBOL(cmpxchg8b_emu);
24720 #endif
24721
24722+EXPORT_SYMBOL_GPL(cpu_gdt_table);
24723+
24724 /* Networking helper routines. */
24725 EXPORT_SYMBOL(csum_partial_copy_generic);
24726+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24727+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24728
24729 EXPORT_SYMBOL(__get_user_1);
24730 EXPORT_SYMBOL(__get_user_2);
24731@@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24732 EXPORT_SYMBOL(___preempt_schedule_context);
24733 #endif
24734 #endif
24735+
24736+#ifdef CONFIG_PAX_KERNEXEC
24737+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24738+#endif
24739+
24740+#ifdef CONFIG_PAX_PER_CPU_PGD
24741+EXPORT_SYMBOL(cpu_pgd);
24742+#endif
24743diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24744index d5dd808..b6432cf 100644
24745--- a/arch/x86/kernel/i387.c
24746+++ b/arch/x86/kernel/i387.c
24747@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24748 static inline bool interrupted_user_mode(void)
24749 {
24750 struct pt_regs *regs = get_irq_regs();
24751- return regs && user_mode_vm(regs);
24752+ return regs && user_mode(regs);
24753 }
24754
24755 /*
24756diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24757index 2e977b5..5f2c273 100644
24758--- a/arch/x86/kernel/i8259.c
24759+++ b/arch/x86/kernel/i8259.c
24760@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24761 static void make_8259A_irq(unsigned int irq)
24762 {
24763 disable_irq_nosync(irq);
24764- io_apic_irqs &= ~(1<<irq);
24765+ io_apic_irqs &= ~(1UL<<irq);
24766 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24767 i8259A_chip.name);
24768 enable_irq(irq);
24769@@ -209,7 +209,7 @@ spurious_8259A_irq:
24770 "spurious 8259A interrupt: IRQ%d.\n", irq);
24771 spurious_irq_mask |= irqmask;
24772 }
24773- atomic_inc(&irq_err_count);
24774+ atomic_inc_unchecked(&irq_err_count);
24775 /*
24776 * Theoretically we do not have to handle this IRQ,
24777 * but in Linux this does not cause problems and is
24778@@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24779 /* (slave's support for AEOI in flat mode is to be investigated) */
24780 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24781
24782+ pax_open_kernel();
24783 if (auto_eoi)
24784 /*
24785 * In AEOI mode we just have to mask the interrupt
24786 * when acking.
24787 */
24788- i8259A_chip.irq_mask_ack = disable_8259A_irq;
24789+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24790 else
24791- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24792+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24793+ pax_close_kernel();
24794
24795 udelay(100); /* wait for 8259A to initialize */
24796
24797diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24798index a979b5b..1d6db75 100644
24799--- a/arch/x86/kernel/io_delay.c
24800+++ b/arch/x86/kernel/io_delay.c
24801@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24802 * Quirk table for systems that misbehave (lock up, etc.) if port
24803 * 0x80 is used:
24804 */
24805-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24806+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24807 {
24808 .callback = dmi_io_delay_0xed_port,
24809 .ident = "Compaq Presario V6000",
24810diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24811index 4ddaf66..49d5c18 100644
24812--- a/arch/x86/kernel/ioport.c
24813+++ b/arch/x86/kernel/ioport.c
24814@@ -6,6 +6,7 @@
24815 #include <linux/sched.h>
24816 #include <linux/kernel.h>
24817 #include <linux/capability.h>
24818+#include <linux/security.h>
24819 #include <linux/errno.h>
24820 #include <linux/types.h>
24821 #include <linux/ioport.h>
24822@@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24823 return -EINVAL;
24824 if (turn_on && !capable(CAP_SYS_RAWIO))
24825 return -EPERM;
24826+#ifdef CONFIG_GRKERNSEC_IO
24827+ if (turn_on && grsec_disable_privio) {
24828+ gr_handle_ioperm();
24829+ return -ENODEV;
24830+ }
24831+#endif
24832
24833 /*
24834 * If it's the first ioperm() call in this thread's lifetime, set the
24835@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24836 * because the ->io_bitmap_max value must match the bitmap
24837 * contents:
24838 */
24839- tss = &per_cpu(init_tss, get_cpu());
24840+ tss = init_tss + get_cpu();
24841
24842 if (turn_on)
24843 bitmap_clear(t->io_bitmap_ptr, from, num);
24844@@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24845 if (level > old) {
24846 if (!capable(CAP_SYS_RAWIO))
24847 return -EPERM;
24848+#ifdef CONFIG_GRKERNSEC_IO
24849+ if (grsec_disable_privio) {
24850+ gr_handle_iopl();
24851+ return -ENODEV;
24852+ }
24853+#endif
24854 }
24855 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24856 t->iopl = level << 12;
24857diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24858index 22d0687..e07b2a5 100644
24859--- a/arch/x86/kernel/irq.c
24860+++ b/arch/x86/kernel/irq.c
24861@@ -21,7 +21,7 @@
24862 #define CREATE_TRACE_POINTS
24863 #include <asm/trace/irq_vectors.h>
24864
24865-atomic_t irq_err_count;
24866+atomic_unchecked_t irq_err_count;
24867
24868 /* Function pointer for generic interrupt vector handling */
24869 void (*x86_platform_ipi_callback)(void) = NULL;
24870@@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24871 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24872 seq_printf(p, " Machine check polls\n");
24873 #endif
24874- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24875+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24876 #if defined(CONFIG_X86_IO_APIC)
24877- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24878+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24879 #endif
24880 return 0;
24881 }
24882@@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24883
24884 u64 arch_irq_stat(void)
24885 {
24886- u64 sum = atomic_read(&irq_err_count);
24887+ u64 sum = atomic_read_unchecked(&irq_err_count);
24888 return sum;
24889 }
24890
24891diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24892index d7fcbed..1f747f7 100644
24893--- a/arch/x86/kernel/irq_32.c
24894+++ b/arch/x86/kernel/irq_32.c
24895@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24896 __asm__ __volatile__("andl %%esp,%0" :
24897 "=r" (sp) : "0" (THREAD_SIZE - 1));
24898
24899- return sp < (sizeof(struct thread_info) + STACK_WARN);
24900+ return sp < STACK_WARN;
24901 }
24902
24903 static void print_stack_overflow(void)
24904@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24905 * per-CPU IRQ handling contexts (thread information and stack)
24906 */
24907 union irq_ctx {
24908- struct thread_info tinfo;
24909- u32 stack[THREAD_SIZE/sizeof(u32)];
24910+ unsigned long previous_esp;
24911+ u32 stack[THREAD_SIZE/sizeof(u32)];
24912 } __attribute__((aligned(THREAD_SIZE)));
24913
24914 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24915@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24916 static inline int
24917 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24918 {
24919- union irq_ctx *curctx, *irqctx;
24920+ union irq_ctx *irqctx;
24921 u32 *isp, arg1, arg2;
24922
24923- curctx = (union irq_ctx *) current_thread_info();
24924 irqctx = __this_cpu_read(hardirq_ctx);
24925
24926 /*
24927@@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24928 * handler) we can't do that and just have to keep using the
24929 * current stack (which is the irq stack already after all)
24930 */
24931- if (unlikely(curctx == irqctx))
24932+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24933 return 0;
24934
24935 /* build the stack frame on the IRQ stack */
24936- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24937- irqctx->tinfo.task = curctx->tinfo.task;
24938- irqctx->tinfo.previous_esp = current_stack_pointer;
24939+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24940+ irqctx->previous_esp = current_stack_pointer;
24941+
24942+#ifdef CONFIG_PAX_MEMORY_UDEREF
24943+ __set_fs(MAKE_MM_SEG(0));
24944+#endif
24945
24946 if (unlikely(overflow))
24947 call_on_stack(print_stack_overflow, isp);
24948@@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24949 : "0" (irq), "1" (desc), "2" (isp),
24950 "D" (desc->handle_irq)
24951 : "memory", "cc", "ecx");
24952+
24953+#ifdef CONFIG_PAX_MEMORY_UDEREF
24954+ __set_fs(current_thread_info()->addr_limit);
24955+#endif
24956+
24957 return 1;
24958 }
24959
24960@@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24961 */
24962 void irq_ctx_init(int cpu)
24963 {
24964- union irq_ctx *irqctx;
24965-
24966 if (per_cpu(hardirq_ctx, cpu))
24967 return;
24968
24969- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24970- THREADINFO_GFP,
24971- THREAD_SIZE_ORDER));
24972- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24973- irqctx->tinfo.cpu = cpu;
24974- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24975-
24976- per_cpu(hardirq_ctx, cpu) = irqctx;
24977-
24978- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24979- THREADINFO_GFP,
24980- THREAD_SIZE_ORDER));
24981- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24982- irqctx->tinfo.cpu = cpu;
24983- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24984-
24985- per_cpu(softirq_ctx, cpu) = irqctx;
24986-
24987- printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24988- cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24989+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24990+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24991 }
24992
24993 void do_softirq_own_stack(void)
24994 {
24995- struct thread_info *curctx;
24996 union irq_ctx *irqctx;
24997 u32 *isp;
24998
24999- curctx = current_thread_info();
25000 irqctx = __this_cpu_read(softirq_ctx);
25001- irqctx->tinfo.task = curctx->task;
25002- irqctx->tinfo.previous_esp = current_stack_pointer;
25003+ irqctx->previous_esp = current_stack_pointer;
25004
25005 /* build the stack frame on the softirq stack */
25006- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
25007+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
25008+
25009+#ifdef CONFIG_PAX_MEMORY_UDEREF
25010+ __set_fs(MAKE_MM_SEG(0));
25011+#endif
25012
25013 call_on_stack(__do_softirq, isp);
25014+
25015+#ifdef CONFIG_PAX_MEMORY_UDEREF
25016+ __set_fs(current_thread_info()->addr_limit);
25017+#endif
25018+
25019 }
25020
25021 bool handle_irq(unsigned irq, struct pt_regs *regs)
25022@@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25023 if (unlikely(!desc))
25024 return false;
25025
25026- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25027+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25028 if (unlikely(overflow))
25029 print_stack_overflow();
25030 desc->handle_irq(irq, desc);
25031diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25032index 4d1c746..232961d 100644
25033--- a/arch/x86/kernel/irq_64.c
25034+++ b/arch/x86/kernel/irq_64.c
25035@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25036 u64 estack_top, estack_bottom;
25037 u64 curbase = (u64)task_stack_page(current);
25038
25039- if (user_mode_vm(regs))
25040+ if (user_mode(regs))
25041 return;
25042
25043 if (regs->sp >= curbase + sizeof(struct thread_info) +
25044diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25045index 26d5a55..a01160a 100644
25046--- a/arch/x86/kernel/jump_label.c
25047+++ b/arch/x86/kernel/jump_label.c
25048@@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25049 * Jump label is enabled for the first time.
25050 * So we expect a default_nop...
25051 */
25052- if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25053+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25054 != 0))
25055 bug_at((void *)entry->code, __LINE__);
25056 } else {
25057@@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25058 * ...otherwise expect an ideal_nop. Otherwise
25059 * something went horribly wrong.
25060 */
25061- if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25062+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25063 != 0))
25064 bug_at((void *)entry->code, __LINE__);
25065 }
25066@@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25067 * are converting the default nop to the ideal nop.
25068 */
25069 if (init) {
25070- if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25071+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25072 bug_at((void *)entry->code, __LINE__);
25073 } else {
25074 code.jump = 0xe9;
25075 code.offset = entry->target -
25076 (entry->code + JUMP_LABEL_NOP_SIZE);
25077- if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25078+ if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25079 bug_at((void *)entry->code, __LINE__);
25080 }
25081 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25082diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25083index 836f832..a8bda67 100644
25084--- a/arch/x86/kernel/kgdb.c
25085+++ b/arch/x86/kernel/kgdb.c
25086@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25087 #ifdef CONFIG_X86_32
25088 switch (regno) {
25089 case GDB_SS:
25090- if (!user_mode_vm(regs))
25091+ if (!user_mode(regs))
25092 *(unsigned long *)mem = __KERNEL_DS;
25093 break;
25094 case GDB_SP:
25095- if (!user_mode_vm(regs))
25096+ if (!user_mode(regs))
25097 *(unsigned long *)mem = kernel_stack_pointer(regs);
25098 break;
25099 case GDB_GS:
25100@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
25101 bp->attr.bp_addr = breakinfo[breakno].addr;
25102 bp->attr.bp_len = breakinfo[breakno].len;
25103 bp->attr.bp_type = breakinfo[breakno].type;
25104- info->address = breakinfo[breakno].addr;
25105+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25106+ info->address = ktla_ktva(breakinfo[breakno].addr);
25107+ else
25108+ info->address = breakinfo[breakno].addr;
25109 info->len = breakinfo[breakno].len;
25110 info->type = breakinfo[breakno].type;
25111 val = arch_install_hw_breakpoint(bp);
25112@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25113 case 'k':
25114 /* clear the trace bit */
25115 linux_regs->flags &= ~X86_EFLAGS_TF;
25116- atomic_set(&kgdb_cpu_doing_single_step, -1);
25117+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25118
25119 /* set the trace bit if we're stepping */
25120 if (remcomInBuffer[0] == 's') {
25121 linux_regs->flags |= X86_EFLAGS_TF;
25122- atomic_set(&kgdb_cpu_doing_single_step,
25123+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25124 raw_smp_processor_id());
25125 }
25126
25127@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25128
25129 switch (cmd) {
25130 case DIE_DEBUG:
25131- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25132+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25133 if (user_mode(regs))
25134 return single_step_cont(regs, args);
25135 break;
25136@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25137 #endif /* CONFIG_DEBUG_RODATA */
25138
25139 bpt->type = BP_BREAKPOINT;
25140- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25141+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25142 BREAK_INSTR_SIZE);
25143 if (err)
25144 return err;
25145- err = probe_kernel_write((char *)bpt->bpt_addr,
25146+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25147 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25148 #ifdef CONFIG_DEBUG_RODATA
25149 if (!err)
25150@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25151 return -EBUSY;
25152 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25153 BREAK_INSTR_SIZE);
25154- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25155+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25156 if (err)
25157 return err;
25158 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25159@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25160 if (mutex_is_locked(&text_mutex))
25161 goto knl_write;
25162 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25163- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25164+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25165 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25166 goto knl_write;
25167 return err;
25168 knl_write:
25169 #endif /* CONFIG_DEBUG_RODATA */
25170- return probe_kernel_write((char *)bpt->bpt_addr,
25171+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25172 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25173 }
25174
25175diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25176index 79a3f96..6ba030a 100644
25177--- a/arch/x86/kernel/kprobes/core.c
25178+++ b/arch/x86/kernel/kprobes/core.c
25179@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25180 s32 raddr;
25181 } __packed *insn;
25182
25183- insn = (struct __arch_relative_insn *)from;
25184+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
25185+
25186+ pax_open_kernel();
25187 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25188 insn->op = op;
25189+ pax_close_kernel();
25190 }
25191
25192 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25193@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25194 kprobe_opcode_t opcode;
25195 kprobe_opcode_t *orig_opcodes = opcodes;
25196
25197- if (search_exception_tables((unsigned long)opcodes))
25198+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25199 return 0; /* Page fault may occur on this address. */
25200
25201 retry:
25202@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25203 * for the first byte, we can recover the original instruction
25204 * from it and kp->opcode.
25205 */
25206- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25207+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25208 buf[0] = kp->opcode;
25209- return (unsigned long)buf;
25210+ return ktva_ktla((unsigned long)buf);
25211 }
25212
25213 /*
25214@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25215 /* Another subsystem puts a breakpoint, failed to recover */
25216 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25217 return 0;
25218+ pax_open_kernel();
25219 memcpy(dest, insn.kaddr, insn.length);
25220+ pax_close_kernel();
25221
25222 #ifdef CONFIG_X86_64
25223 if (insn_rip_relative(&insn)) {
25224@@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25225 return 0;
25226 }
25227 disp = (u8 *) dest + insn_offset_displacement(&insn);
25228+ pax_open_kernel();
25229 *(s32 *) disp = (s32) newdisp;
25230+ pax_close_kernel();
25231 }
25232 #endif
25233 return insn.length;
25234@@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25235 * nor set current_kprobe, because it doesn't use single
25236 * stepping.
25237 */
25238- regs->ip = (unsigned long)p->ainsn.insn;
25239+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25240 preempt_enable_no_resched();
25241 return;
25242 }
25243@@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25244 regs->flags &= ~X86_EFLAGS_IF;
25245 /* single step inline if the instruction is an int3 */
25246 if (p->opcode == BREAKPOINT_INSTRUCTION)
25247- regs->ip = (unsigned long)p->addr;
25248+ regs->ip = ktla_ktva((unsigned long)p->addr);
25249 else
25250- regs->ip = (unsigned long)p->ainsn.insn;
25251+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25252 }
25253
25254 /*
25255@@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25256 setup_singlestep(p, regs, kcb, 0);
25257 return 1;
25258 }
25259- } else if (*addr != BREAKPOINT_INSTRUCTION) {
25260+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25261 /*
25262 * The breakpoint instruction was removed right
25263 * after we hit it. Another cpu has removed
25264@@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25265 " movq %rax, 152(%rsp)\n"
25266 RESTORE_REGS_STRING
25267 " popfq\n"
25268+#ifdef KERNEXEC_PLUGIN
25269+ " btsq $63,(%rsp)\n"
25270+#endif
25271 #else
25272 " pushf\n"
25273 SAVE_REGS_STRING
25274@@ -779,7 +789,7 @@ static void __kprobes
25275 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25276 {
25277 unsigned long *tos = stack_addr(regs);
25278- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25279+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25280 unsigned long orig_ip = (unsigned long)p->addr;
25281 kprobe_opcode_t *insn = p->ainsn.insn;
25282
25283@@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25284 struct die_args *args = data;
25285 int ret = NOTIFY_DONE;
25286
25287- if (args->regs && user_mode_vm(args->regs))
25288+ if (args->regs && user_mode(args->regs))
25289 return ret;
25290
25291 switch (val) {
25292diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25293index 898160b..758cde8 100644
25294--- a/arch/x86/kernel/kprobes/opt.c
25295+++ b/arch/x86/kernel/kprobes/opt.c
25296@@ -79,6 +79,7 @@ found:
25297 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25298 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25299 {
25300+ pax_open_kernel();
25301 #ifdef CONFIG_X86_64
25302 *addr++ = 0x48;
25303 *addr++ = 0xbf;
25304@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25305 *addr++ = 0xb8;
25306 #endif
25307 *(unsigned long *)addr = val;
25308+ pax_close_kernel();
25309 }
25310
25311 asm (
25312@@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25313 * Verify if the address gap is in 2GB range, because this uses
25314 * a relative jump.
25315 */
25316- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25317+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25318 if (abs(rel) > 0x7fffffff)
25319 return -ERANGE;
25320
25321@@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25322 op->optinsn.size = ret;
25323
25324 /* Copy arch-dep-instance from template */
25325- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25326+ pax_open_kernel();
25327+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25328+ pax_close_kernel();
25329
25330 /* Set probe information */
25331 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25332
25333 /* Set probe function call */
25334- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25335+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25336
25337 /* Set returning jmp instruction at the tail of out-of-line buffer */
25338- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25339+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25340 (u8 *)op->kp.addr + op->optinsn.size);
25341
25342 flush_icache_range((unsigned long) buf,
25343@@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25344 WARN_ON(kprobe_disabled(&op->kp));
25345
25346 /* Backup instructions which will be replaced by jump address */
25347- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25348+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25349 RELATIVE_ADDR_SIZE);
25350
25351 insn_buf[0] = RELATIVEJUMP_OPCODE;
25352@@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25353 /* This kprobe is really able to run optimized path. */
25354 op = container_of(p, struct optimized_kprobe, kp);
25355 /* Detour through copied instructions */
25356- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25357+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25358 if (!reenter)
25359 reset_current_kprobe();
25360 preempt_enable_no_resched();
25361diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25362index ebc9873..37b8776 100644
25363--- a/arch/x86/kernel/ldt.c
25364+++ b/arch/x86/kernel/ldt.c
25365@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25366 if (reload) {
25367 #ifdef CONFIG_SMP
25368 preempt_disable();
25369- load_LDT(pc);
25370+ load_LDT_nolock(pc);
25371 if (!cpumask_equal(mm_cpumask(current->mm),
25372 cpumask_of(smp_processor_id())))
25373 smp_call_function(flush_ldt, current->mm, 1);
25374 preempt_enable();
25375 #else
25376- load_LDT(pc);
25377+ load_LDT_nolock(pc);
25378 #endif
25379 }
25380 if (oldsize) {
25381@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25382 return err;
25383
25384 for (i = 0; i < old->size; i++)
25385- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25386+ write_ldt_entry(new->ldt, i, old->ldt + i);
25387 return 0;
25388 }
25389
25390@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25391 retval = copy_ldt(&mm->context, &old_mm->context);
25392 mutex_unlock(&old_mm->context.lock);
25393 }
25394+
25395+ if (tsk == current) {
25396+ mm->context.vdso = 0;
25397+
25398+#ifdef CONFIG_X86_32
25399+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25400+ mm->context.user_cs_base = 0UL;
25401+ mm->context.user_cs_limit = ~0UL;
25402+
25403+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25404+ cpus_clear(mm->context.cpu_user_cs_mask);
25405+#endif
25406+
25407+#endif
25408+#endif
25409+
25410+ }
25411+
25412 return retval;
25413 }
25414
25415@@ -229,6 +247,24 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25416 }
25417 }
25418
25419+#ifdef CONFIG_PAX_SEGMEXEC
25420+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25421+ error = -EINVAL;
25422+ goto out_unlock;
25423+ }
25424+#endif
25425+
25426+ /*
25427+ * On x86-64 we do not support 16-bit segments due to
25428+ * IRET leaking the high bits of the kernel stack address.
25429+ */
25430+#ifdef CONFIG_X86_64
25431+ if (!ldt_info.seg_32bit) {
25432+ error = -EINVAL;
25433+ goto out_unlock;
25434+ }
25435+#endif
25436+
25437 fill_ldt(&ldt, &ldt_info);
25438 if (oldmode)
25439 ldt.avl = 0;
25440diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25441index 5b19e4d..6476a76 100644
25442--- a/arch/x86/kernel/machine_kexec_32.c
25443+++ b/arch/x86/kernel/machine_kexec_32.c
25444@@ -26,7 +26,7 @@
25445 #include <asm/cacheflush.h>
25446 #include <asm/debugreg.h>
25447
25448-static void set_idt(void *newidt, __u16 limit)
25449+static void set_idt(struct desc_struct *newidt, __u16 limit)
25450 {
25451 struct desc_ptr curidt;
25452
25453@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
25454 }
25455
25456
25457-static void set_gdt(void *newgdt, __u16 limit)
25458+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25459 {
25460 struct desc_ptr curgdt;
25461
25462@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
25463 }
25464
25465 control_page = page_address(image->control_code_page);
25466- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25467+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25468
25469 relocate_kernel_ptr = control_page;
25470 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25471diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
25472index 15c9876..0a43909 100644
25473--- a/arch/x86/kernel/microcode_core.c
25474+++ b/arch/x86/kernel/microcode_core.c
25475@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
25476 return NOTIFY_OK;
25477 }
25478
25479-static struct notifier_block __refdata mc_cpu_notifier = {
25480+static struct notifier_block mc_cpu_notifier = {
25481 .notifier_call = mc_cpu_callback,
25482 };
25483
25484diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
25485index 5fb2ceb..3ae90bb 100644
25486--- a/arch/x86/kernel/microcode_intel.c
25487+++ b/arch/x86/kernel/microcode_intel.c
25488@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
25489
25490 static int get_ucode_user(void *to, const void *from, size_t n)
25491 {
25492- return copy_from_user(to, from, n);
25493+ return copy_from_user(to, (const void __force_user *)from, n);
25494 }
25495
25496 static enum ucode_state
25497 request_microcode_user(int cpu, const void __user *buf, size_t size)
25498 {
25499- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
25500+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
25501 }
25502
25503 static void microcode_fini_cpu(int cpu)
25504diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25505index 18be189..4a9fe40 100644
25506--- a/arch/x86/kernel/module.c
25507+++ b/arch/x86/kernel/module.c
25508@@ -43,15 +43,60 @@ do { \
25509 } while (0)
25510 #endif
25511
25512-void *module_alloc(unsigned long size)
25513+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25514 {
25515- if (PAGE_ALIGN(size) > MODULES_LEN)
25516+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25517 return NULL;
25518 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25519- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25520+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25521 NUMA_NO_NODE, __builtin_return_address(0));
25522 }
25523
25524+void *module_alloc(unsigned long size)
25525+{
25526+
25527+#ifdef CONFIG_PAX_KERNEXEC
25528+ return __module_alloc(size, PAGE_KERNEL);
25529+#else
25530+ return __module_alloc(size, PAGE_KERNEL_EXEC);
25531+#endif
25532+
25533+}
25534+
25535+#ifdef CONFIG_PAX_KERNEXEC
25536+#ifdef CONFIG_X86_32
25537+void *module_alloc_exec(unsigned long size)
25538+{
25539+ struct vm_struct *area;
25540+
25541+ if (size == 0)
25542+ return NULL;
25543+
25544+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25545+ return area ? area->addr : NULL;
25546+}
25547+EXPORT_SYMBOL(module_alloc_exec);
25548+
25549+void module_free_exec(struct module *mod, void *module_region)
25550+{
25551+ vunmap(module_region);
25552+}
25553+EXPORT_SYMBOL(module_free_exec);
25554+#else
25555+void module_free_exec(struct module *mod, void *module_region)
25556+{
25557+ module_free(mod, module_region);
25558+}
25559+EXPORT_SYMBOL(module_free_exec);
25560+
25561+void *module_alloc_exec(unsigned long size)
25562+{
25563+ return __module_alloc(size, PAGE_KERNEL_RX);
25564+}
25565+EXPORT_SYMBOL(module_alloc_exec);
25566+#endif
25567+#endif
25568+
25569 #ifdef CONFIG_X86_32
25570 int apply_relocate(Elf32_Shdr *sechdrs,
25571 const char *strtab,
25572@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25573 unsigned int i;
25574 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25575 Elf32_Sym *sym;
25576- uint32_t *location;
25577+ uint32_t *plocation, location;
25578
25579 DEBUGP("Applying relocate section %u to %u\n",
25580 relsec, sechdrs[relsec].sh_info);
25581 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25582 /* This is where to make the change */
25583- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25584- + rel[i].r_offset;
25585+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25586+ location = (uint32_t)plocation;
25587+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25588+ plocation = ktla_ktva((void *)plocation);
25589 /* This is the symbol it is referring to. Note that all
25590 undefined symbols have been resolved. */
25591 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25592@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25593 switch (ELF32_R_TYPE(rel[i].r_info)) {
25594 case R_386_32:
25595 /* We add the value into the location given */
25596- *location += sym->st_value;
25597+ pax_open_kernel();
25598+ *plocation += sym->st_value;
25599+ pax_close_kernel();
25600 break;
25601 case R_386_PC32:
25602 /* Add the value, subtract its position */
25603- *location += sym->st_value - (uint32_t)location;
25604+ pax_open_kernel();
25605+ *plocation += sym->st_value - location;
25606+ pax_close_kernel();
25607 break;
25608 default:
25609 pr_err("%s: Unknown relocation: %u\n",
25610@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25611 case R_X86_64_NONE:
25612 break;
25613 case R_X86_64_64:
25614+ pax_open_kernel();
25615 *(u64 *)loc = val;
25616+ pax_close_kernel();
25617 break;
25618 case R_X86_64_32:
25619+ pax_open_kernel();
25620 *(u32 *)loc = val;
25621+ pax_close_kernel();
25622 if (val != *(u32 *)loc)
25623 goto overflow;
25624 break;
25625 case R_X86_64_32S:
25626+ pax_open_kernel();
25627 *(s32 *)loc = val;
25628+ pax_close_kernel();
25629 if ((s64)val != *(s32 *)loc)
25630 goto overflow;
25631 break;
25632 case R_X86_64_PC32:
25633 val -= (u64)loc;
25634+ pax_open_kernel();
25635 *(u32 *)loc = val;
25636+ pax_close_kernel();
25637+
25638 #if 0
25639 if ((s64)val != *(s32 *)loc)
25640 goto overflow;
25641diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25642index 05266b5..3432443 100644
25643--- a/arch/x86/kernel/msr.c
25644+++ b/arch/x86/kernel/msr.c
25645@@ -37,6 +37,7 @@
25646 #include <linux/notifier.h>
25647 #include <linux/uaccess.h>
25648 #include <linux/gfp.h>
25649+#include <linux/grsecurity.h>
25650
25651 #include <asm/processor.h>
25652 #include <asm/msr.h>
25653@@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25654 int err = 0;
25655 ssize_t bytes = 0;
25656
25657+#ifdef CONFIG_GRKERNSEC_KMEM
25658+ gr_handle_msr_write();
25659+ return -EPERM;
25660+#endif
25661+
25662 if (count % 8)
25663 return -EINVAL; /* Invalid chunk size */
25664
25665@@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25666 err = -EBADF;
25667 break;
25668 }
25669+#ifdef CONFIG_GRKERNSEC_KMEM
25670+ gr_handle_msr_write();
25671+ return -EPERM;
25672+#endif
25673 if (copy_from_user(&regs, uregs, sizeof regs)) {
25674 err = -EFAULT;
25675 break;
25676@@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25677 return notifier_from_errno(err);
25678 }
25679
25680-static struct notifier_block __refdata msr_class_cpu_notifier = {
25681+static struct notifier_block msr_class_cpu_notifier = {
25682 .notifier_call = msr_class_cpu_callback,
25683 };
25684
25685diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25686index 6fcb49c..5b3f4ff 100644
25687--- a/arch/x86/kernel/nmi.c
25688+++ b/arch/x86/kernel/nmi.c
25689@@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25690 return handled;
25691 }
25692
25693-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25694+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25695 {
25696 struct nmi_desc *desc = nmi_to_desc(type);
25697 unsigned long flags;
25698@@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25699 * event confuses some handlers (kdump uses this flag)
25700 */
25701 if (action->flags & NMI_FLAG_FIRST)
25702- list_add_rcu(&action->list, &desc->head);
25703+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25704 else
25705- list_add_tail_rcu(&action->list, &desc->head);
25706+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25707
25708 spin_unlock_irqrestore(&desc->lock, flags);
25709 return 0;
25710@@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25711 if (!strcmp(n->name, name)) {
25712 WARN(in_nmi(),
25713 "Trying to free NMI (%s) from NMI context!\n", n->name);
25714- list_del_rcu(&n->list);
25715+ pax_list_del_rcu((struct list_head *)&n->list);
25716 break;
25717 }
25718 }
25719@@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25720 dotraplinkage notrace __kprobes void
25721 do_nmi(struct pt_regs *regs, long error_code)
25722 {
25723+
25724+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25725+ if (!user_mode(regs)) {
25726+ unsigned long cs = regs->cs & 0xFFFF;
25727+ unsigned long ip = ktva_ktla(regs->ip);
25728+
25729+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25730+ regs->ip = ip;
25731+ }
25732+#endif
25733+
25734 nmi_nesting_preprocess(regs);
25735
25736 nmi_enter();
25737diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25738index 6d9582e..f746287 100644
25739--- a/arch/x86/kernel/nmi_selftest.c
25740+++ b/arch/x86/kernel/nmi_selftest.c
25741@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25742 {
25743 /* trap all the unknown NMIs we may generate */
25744 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25745- __initdata);
25746+ __initconst);
25747 }
25748
25749 static void __init cleanup_nmi_testsuite(void)
25750@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25751 unsigned long timeout;
25752
25753 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25754- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25755+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25756 nmi_fail = FAILURE;
25757 return;
25758 }
25759diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25760index bbb6c73..24a58ef 100644
25761--- a/arch/x86/kernel/paravirt-spinlocks.c
25762+++ b/arch/x86/kernel/paravirt-spinlocks.c
25763@@ -8,7 +8,7 @@
25764
25765 #include <asm/paravirt.h>
25766
25767-struct pv_lock_ops pv_lock_ops = {
25768+struct pv_lock_ops pv_lock_ops __read_only = {
25769 #ifdef CONFIG_SMP
25770 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25771 .unlock_kick = paravirt_nop,
25772diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25773index 1b10af8..0b58cbc 100644
25774--- a/arch/x86/kernel/paravirt.c
25775+++ b/arch/x86/kernel/paravirt.c
25776@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25777 {
25778 return x;
25779 }
25780+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25781+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25782+#endif
25783
25784 void __init default_banner(void)
25785 {
25786@@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25787 if (opfunc == NULL)
25788 /* If there's no function, patch it with a ud2a (BUG) */
25789 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25790- else if (opfunc == _paravirt_nop)
25791+ else if (opfunc == (void *)_paravirt_nop)
25792 /* If the operation is a nop, then nop the callsite */
25793 ret = paravirt_patch_nop();
25794
25795 /* identity functions just return their single argument */
25796- else if (opfunc == _paravirt_ident_32)
25797+ else if (opfunc == (void *)_paravirt_ident_32)
25798 ret = paravirt_patch_ident_32(insnbuf, len);
25799- else if (opfunc == _paravirt_ident_64)
25800+ else if (opfunc == (void *)_paravirt_ident_64)
25801 ret = paravirt_patch_ident_64(insnbuf, len);
25802+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25803+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25804+ ret = paravirt_patch_ident_64(insnbuf, len);
25805+#endif
25806
25807 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25808 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25809@@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25810 if (insn_len > len || start == NULL)
25811 insn_len = len;
25812 else
25813- memcpy(insnbuf, start, insn_len);
25814+ memcpy(insnbuf, ktla_ktva(start), insn_len);
25815
25816 return insn_len;
25817 }
25818@@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25819 return this_cpu_read(paravirt_lazy_mode);
25820 }
25821
25822-struct pv_info pv_info = {
25823+struct pv_info pv_info __read_only = {
25824 .name = "bare hardware",
25825 .paravirt_enabled = 0,
25826 .kernel_rpl = 0,
25827@@ -310,16 +317,16 @@ struct pv_info pv_info = {
25828 #endif
25829 };
25830
25831-struct pv_init_ops pv_init_ops = {
25832+struct pv_init_ops pv_init_ops __read_only = {
25833 .patch = native_patch,
25834 };
25835
25836-struct pv_time_ops pv_time_ops = {
25837+struct pv_time_ops pv_time_ops __read_only = {
25838 .sched_clock = native_sched_clock,
25839 .steal_clock = native_steal_clock,
25840 };
25841
25842-__visible struct pv_irq_ops pv_irq_ops = {
25843+__visible struct pv_irq_ops pv_irq_ops __read_only = {
25844 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25845 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25846 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25847@@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25848 #endif
25849 };
25850
25851-__visible struct pv_cpu_ops pv_cpu_ops = {
25852+__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25853 .cpuid = native_cpuid,
25854 .get_debugreg = native_get_debugreg,
25855 .set_debugreg = native_set_debugreg,
25856@@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25857 .end_context_switch = paravirt_nop,
25858 };
25859
25860-struct pv_apic_ops pv_apic_ops = {
25861+struct pv_apic_ops pv_apic_ops __read_only= {
25862 #ifdef CONFIG_X86_LOCAL_APIC
25863 .startup_ipi_hook = paravirt_nop,
25864 #endif
25865 };
25866
25867-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25868+#ifdef CONFIG_X86_32
25869+#ifdef CONFIG_X86_PAE
25870+/* 64-bit pagetable entries */
25871+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25872+#else
25873 /* 32-bit pagetable entries */
25874 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25875+#endif
25876 #else
25877 /* 64-bit pagetable entries */
25878 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25879 #endif
25880
25881-struct pv_mmu_ops pv_mmu_ops = {
25882+struct pv_mmu_ops pv_mmu_ops __read_only = {
25883
25884 .read_cr2 = native_read_cr2,
25885 .write_cr2 = native_write_cr2,
25886@@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25887 .make_pud = PTE_IDENT,
25888
25889 .set_pgd = native_set_pgd,
25890+ .set_pgd_batched = native_set_pgd_batched,
25891 #endif
25892 #endif /* PAGETABLE_LEVELS >= 3 */
25893
25894@@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25895 },
25896
25897 .set_fixmap = native_set_fixmap,
25898+
25899+#ifdef CONFIG_PAX_KERNEXEC
25900+ .pax_open_kernel = native_pax_open_kernel,
25901+ .pax_close_kernel = native_pax_close_kernel,
25902+#endif
25903+
25904 };
25905
25906 EXPORT_SYMBOL_GPL(pv_time_ops);
25907diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25908index 299d493..2ccb0ee 100644
25909--- a/arch/x86/kernel/pci-calgary_64.c
25910+++ b/arch/x86/kernel/pci-calgary_64.c
25911@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25912 tce_space = be64_to_cpu(readq(target));
25913 tce_space = tce_space & TAR_SW_BITS;
25914
25915- tce_space = tce_space & (~specified_table_size);
25916+ tce_space = tce_space & (~(unsigned long)specified_table_size);
25917 info->tce_space = (u64 *)__va(tce_space);
25918 }
25919 }
25920diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25921index 35ccf75..7a15747 100644
25922--- a/arch/x86/kernel/pci-iommu_table.c
25923+++ b/arch/x86/kernel/pci-iommu_table.c
25924@@ -2,7 +2,7 @@
25925 #include <asm/iommu_table.h>
25926 #include <linux/string.h>
25927 #include <linux/kallsyms.h>
25928-
25929+#include <linux/sched.h>
25930
25931 #define DEBUG 1
25932
25933diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25934index 6c483ba..d10ce2f 100644
25935--- a/arch/x86/kernel/pci-swiotlb.c
25936+++ b/arch/x86/kernel/pci-swiotlb.c
25937@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25938 void *vaddr, dma_addr_t dma_addr,
25939 struct dma_attrs *attrs)
25940 {
25941- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25942+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25943 }
25944
25945 static struct dma_map_ops swiotlb_dma_ops = {
25946diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25947index ca7f0d5..8996469 100644
25948--- a/arch/x86/kernel/preempt.S
25949+++ b/arch/x86/kernel/preempt.S
25950@@ -3,12 +3,14 @@
25951 #include <asm/dwarf2.h>
25952 #include <asm/asm.h>
25953 #include <asm/calling.h>
25954+#include <asm/alternative-asm.h>
25955
25956 ENTRY(___preempt_schedule)
25957 CFI_STARTPROC
25958 SAVE_ALL
25959 call preempt_schedule
25960 RESTORE_ALL
25961+ pax_force_retaddr
25962 ret
25963 CFI_ENDPROC
25964
25965@@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25966 SAVE_ALL
25967 call preempt_schedule_context
25968 RESTORE_ALL
25969+ pax_force_retaddr
25970 ret
25971 CFI_ENDPROC
25972
25973diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25974index 3fb8d95..254dc51 100644
25975--- a/arch/x86/kernel/process.c
25976+++ b/arch/x86/kernel/process.c
25977@@ -36,7 +36,8 @@
25978 * section. Since TSS's are completely CPU-local, we want them
25979 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25980 */
25981-__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25982+struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25983+EXPORT_SYMBOL(init_tss);
25984
25985 #ifdef CONFIG_X86_64
25986 static DEFINE_PER_CPU(unsigned char, is_idle);
25987@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25988 task_xstate_cachep =
25989 kmem_cache_create("task_xstate", xstate_size,
25990 __alignof__(union thread_xstate),
25991- SLAB_PANIC | SLAB_NOTRACK, NULL);
25992+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25993 }
25994
25995 /*
25996@@ -105,7 +106,7 @@ void exit_thread(void)
25997 unsigned long *bp = t->io_bitmap_ptr;
25998
25999 if (bp) {
26000- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26001+ struct tss_struct *tss = init_tss + get_cpu();
26002
26003 t->io_bitmap_ptr = NULL;
26004 clear_thread_flag(TIF_IO_BITMAP);
26005@@ -125,6 +126,9 @@ void flush_thread(void)
26006 {
26007 struct task_struct *tsk = current;
26008
26009+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26010+ loadsegment(gs, 0);
26011+#endif
26012 flush_ptrace_hw_breakpoint(tsk);
26013 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26014 drop_init_fpu(tsk);
26015@@ -271,7 +275,7 @@ static void __exit_idle(void)
26016 void exit_idle(void)
26017 {
26018 /* idle loop has pid 0 */
26019- if (current->pid)
26020+ if (task_pid_nr(current))
26021 return;
26022 __exit_idle();
26023 }
26024@@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
26025 return ret;
26026 }
26027 #endif
26028-void stop_this_cpu(void *dummy)
26029+__noreturn void stop_this_cpu(void *dummy)
26030 {
26031 local_irq_disable();
26032 /*
26033@@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
26034 }
26035 early_param("idle", idle_setup);
26036
26037-unsigned long arch_align_stack(unsigned long sp)
26038+#ifdef CONFIG_PAX_RANDKSTACK
26039+void pax_randomize_kstack(struct pt_regs *regs)
26040 {
26041- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26042- sp -= get_random_int() % 8192;
26043- return sp & ~0xf;
26044-}
26045+ struct thread_struct *thread = &current->thread;
26046+ unsigned long time;
26047
26048-unsigned long arch_randomize_brk(struct mm_struct *mm)
26049-{
26050- unsigned long range_end = mm->brk + 0x02000000;
26051- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26052-}
26053+ if (!randomize_va_space)
26054+ return;
26055+
26056+ if (v8086_mode(regs))
26057+ return;
26058
26059+ rdtscl(time);
26060+
26061+ /* P4 seems to return a 0 LSB, ignore it */
26062+#ifdef CONFIG_MPENTIUM4
26063+ time &= 0x3EUL;
26064+ time <<= 2;
26065+#elif defined(CONFIG_X86_64)
26066+ time &= 0xFUL;
26067+ time <<= 4;
26068+#else
26069+ time &= 0x1FUL;
26070+ time <<= 3;
26071+#endif
26072+
26073+ thread->sp0 ^= time;
26074+ load_sp0(init_tss + smp_processor_id(), thread);
26075+
26076+#ifdef CONFIG_X86_64
26077+ this_cpu_write(kernel_stack, thread->sp0);
26078+#endif
26079+}
26080+#endif
26081diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26082index 6f1236c..fd448d4 100644
26083--- a/arch/x86/kernel/process_32.c
26084+++ b/arch/x86/kernel/process_32.c
26085@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26086 unsigned long thread_saved_pc(struct task_struct *tsk)
26087 {
26088 return ((unsigned long *)tsk->thread.sp)[3];
26089+//XXX return tsk->thread.eip;
26090 }
26091
26092 void __show_regs(struct pt_regs *regs, int all)
26093@@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
26094 unsigned long sp;
26095 unsigned short ss, gs;
26096
26097- if (user_mode_vm(regs)) {
26098+ if (user_mode(regs)) {
26099 sp = regs->sp;
26100 ss = regs->ss & 0xffff;
26101- gs = get_user_gs(regs);
26102 } else {
26103 sp = kernel_stack_pointer(regs);
26104 savesegment(ss, ss);
26105- savesegment(gs, gs);
26106 }
26107+ gs = get_user_gs(regs);
26108
26109 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26110 (u16)regs->cs, regs->ip, regs->flags,
26111- smp_processor_id());
26112+ raw_smp_processor_id());
26113 print_symbol("EIP is at %s\n", regs->ip);
26114
26115 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26116@@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
26117 int copy_thread(unsigned long clone_flags, unsigned long sp,
26118 unsigned long arg, struct task_struct *p)
26119 {
26120- struct pt_regs *childregs = task_pt_regs(p);
26121+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26122 struct task_struct *tsk;
26123 int err;
26124
26125 p->thread.sp = (unsigned long) childregs;
26126 p->thread.sp0 = (unsigned long) (childregs+1);
26127+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26128
26129 if (unlikely(p->flags & PF_KTHREAD)) {
26130 /* kernel thread */
26131 memset(childregs, 0, sizeof(struct pt_regs));
26132 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26133- task_user_gs(p) = __KERNEL_STACK_CANARY;
26134- childregs->ds = __USER_DS;
26135- childregs->es = __USER_DS;
26136+ savesegment(gs, childregs->gs);
26137+ childregs->ds = __KERNEL_DS;
26138+ childregs->es = __KERNEL_DS;
26139 childregs->fs = __KERNEL_PERCPU;
26140 childregs->bx = sp; /* function */
26141 childregs->bp = arg;
26142@@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26143 struct thread_struct *prev = &prev_p->thread,
26144 *next = &next_p->thread;
26145 int cpu = smp_processor_id();
26146- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26147+ struct tss_struct *tss = init_tss + cpu;
26148 fpu_switch_t fpu;
26149
26150 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26151@@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26152 */
26153 lazy_save_gs(prev->gs);
26154
26155+#ifdef CONFIG_PAX_MEMORY_UDEREF
26156+ __set_fs(task_thread_info(next_p)->addr_limit);
26157+#endif
26158+
26159 /*
26160 * Load the per-thread Thread-Local Storage descriptor.
26161 */
26162@@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26163 */
26164 arch_end_context_switch(next_p);
26165
26166+ this_cpu_write(current_task, next_p);
26167+ this_cpu_write(current_tinfo, &next_p->tinfo);
26168+
26169 /*
26170 * Restore %gs if needed (which is common)
26171 */
26172@@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26173
26174 switch_fpu_finish(next_p, fpu);
26175
26176- this_cpu_write(current_task, next_p);
26177-
26178 return prev_p;
26179 }
26180
26181@@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26182 } while (count++ < 16);
26183 return 0;
26184 }
26185-
26186diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26187index 9c0280f..5bbb1c0 100644
26188--- a/arch/x86/kernel/process_64.c
26189+++ b/arch/x86/kernel/process_64.c
26190@@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26191 struct pt_regs *childregs;
26192 struct task_struct *me = current;
26193
26194- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26195+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26196 childregs = task_pt_regs(p);
26197 p->thread.sp = (unsigned long) childregs;
26198 p->thread.usersp = me->thread.usersp;
26199+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26200 set_tsk_thread_flag(p, TIF_FORK);
26201 p->thread.fpu_counter = 0;
26202 p->thread.io_bitmap_ptr = NULL;
26203@@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26204 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26205 savesegment(es, p->thread.es);
26206 savesegment(ds, p->thread.ds);
26207+ savesegment(ss, p->thread.ss);
26208+ BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26209 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26210
26211 if (unlikely(p->flags & PF_KTHREAD)) {
26212@@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26213 struct thread_struct *prev = &prev_p->thread;
26214 struct thread_struct *next = &next_p->thread;
26215 int cpu = smp_processor_id();
26216- struct tss_struct *tss = &per_cpu(init_tss, cpu);
26217+ struct tss_struct *tss = init_tss + cpu;
26218 unsigned fsindex, gsindex;
26219 fpu_switch_t fpu;
26220
26221@@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26222 if (unlikely(next->ds | prev->ds))
26223 loadsegment(ds, next->ds);
26224
26225+ savesegment(ss, prev->ss);
26226+ if (unlikely(next->ss != prev->ss))
26227+ loadsegment(ss, next->ss);
26228
26229 /* We must save %fs and %gs before load_TLS() because
26230 * %fs and %gs may be cleared by load_TLS().
26231@@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26232 prev->usersp = this_cpu_read(old_rsp);
26233 this_cpu_write(old_rsp, next->usersp);
26234 this_cpu_write(current_task, next_p);
26235+ this_cpu_write(current_tinfo, &next_p->tinfo);
26236
26237 /*
26238 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26239@@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26240 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26241 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26242
26243- this_cpu_write(kernel_stack,
26244- (unsigned long)task_stack_page(next_p) +
26245- THREAD_SIZE - KERNEL_STACK_OFFSET);
26246+ this_cpu_write(kernel_stack, next->sp0);
26247
26248 /*
26249 * Now maybe reload the debug registers and handle I/O bitmaps
26250@@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26251 if (!p || p == current || p->state == TASK_RUNNING)
26252 return 0;
26253 stack = (unsigned long)task_stack_page(p);
26254- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26255+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26256 return 0;
26257 fp = *(u64 *)(p->thread.sp);
26258 do {
26259- if (fp < (unsigned long)stack ||
26260- fp >= (unsigned long)stack+THREAD_SIZE)
26261+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26262 return 0;
26263 ip = *(u64 *)(fp+8);
26264 if (!in_sched_functions(ip))
26265diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26266index 7461f50..1334029 100644
26267--- a/arch/x86/kernel/ptrace.c
26268+++ b/arch/x86/kernel/ptrace.c
26269@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26270 {
26271 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
26272 unsigned long sp = (unsigned long)&regs->sp;
26273- struct thread_info *tinfo;
26274
26275- if (context == (sp & ~(THREAD_SIZE - 1)))
26276+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26277 return sp;
26278
26279- tinfo = (struct thread_info *)context;
26280- if (tinfo->previous_esp)
26281- return tinfo->previous_esp;
26282+ sp = *(unsigned long *)context;
26283+ if (sp)
26284+ return sp;
26285
26286 return (unsigned long)regs;
26287 }
26288@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
26289 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26290 {
26291 int i;
26292- int dr7 = 0;
26293+ unsigned long dr7 = 0;
26294 struct arch_hw_breakpoint *info;
26295
26296 for (i = 0; i < HBP_NUM; i++) {
26297@@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
26298 unsigned long addr, unsigned long data)
26299 {
26300 int ret;
26301- unsigned long __user *datap = (unsigned long __user *)data;
26302+ unsigned long __user *datap = (__force unsigned long __user *)data;
26303
26304 switch (request) {
26305 /* read the word at location addr in the USER area. */
26306@@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
26307 if ((int) addr < 0)
26308 return -EIO;
26309 ret = do_get_thread_area(child, addr,
26310- (struct user_desc __user *)data);
26311+ (__force struct user_desc __user *) data);
26312 break;
26313
26314 case PTRACE_SET_THREAD_AREA:
26315 if ((int) addr < 0)
26316 return -EIO;
26317 ret = do_set_thread_area(child, addr,
26318- (struct user_desc __user *)data, 0);
26319+ (__force struct user_desc __user *) data, 0);
26320 break;
26321 #endif
26322
26323@@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26324
26325 #ifdef CONFIG_X86_64
26326
26327-static struct user_regset x86_64_regsets[] __read_mostly = {
26328+static user_regset_no_const x86_64_regsets[] __read_only = {
26329 [REGSET_GENERAL] = {
26330 .core_note_type = NT_PRSTATUS,
26331 .n = sizeof(struct user_regs_struct) / sizeof(long),
26332@@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
26333 #endif /* CONFIG_X86_64 */
26334
26335 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26336-static struct user_regset x86_32_regsets[] __read_mostly = {
26337+static user_regset_no_const x86_32_regsets[] __read_only = {
26338 [REGSET_GENERAL] = {
26339 .core_note_type = NT_PRSTATUS,
26340 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26341@@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
26342 */
26343 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26344
26345-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26346+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26347 {
26348 #ifdef CONFIG_X86_64
26349 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26350@@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26351 memset(info, 0, sizeof(*info));
26352 info->si_signo = SIGTRAP;
26353 info->si_code = si_code;
26354- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26355+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26356 }
26357
26358 void user_single_step_siginfo(struct task_struct *tsk,
26359@@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26360 # define IS_IA32 0
26361 #endif
26362
26363+#ifdef CONFIG_GRKERNSEC_SETXID
26364+extern void gr_delayed_cred_worker(void);
26365+#endif
26366+
26367 /*
26368 * We must return the syscall number to actually look up in the table.
26369 * This can be -1L to skip running any syscall at all.
26370@@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26371
26372 user_exit();
26373
26374+#ifdef CONFIG_GRKERNSEC_SETXID
26375+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26376+ gr_delayed_cred_worker();
26377+#endif
26378+
26379 /*
26380 * If we stepped into a sysenter/syscall insn, it trapped in
26381 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26382@@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26383 */
26384 user_exit();
26385
26386+#ifdef CONFIG_GRKERNSEC_SETXID
26387+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26388+ gr_delayed_cred_worker();
26389+#endif
26390+
26391 audit_syscall_exit(regs);
26392
26393 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26394diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26395index 2f355d2..e75ed0a 100644
26396--- a/arch/x86/kernel/pvclock.c
26397+++ b/arch/x86/kernel/pvclock.c
26398@@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26399 reset_hung_task_detector();
26400 }
26401
26402-static atomic64_t last_value = ATOMIC64_INIT(0);
26403+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26404
26405 void pvclock_resume(void)
26406 {
26407- atomic64_set(&last_value, 0);
26408+ atomic64_set_unchecked(&last_value, 0);
26409 }
26410
26411 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26412@@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26413 * updating at the same time, and one of them could be slightly behind,
26414 * making the assumption that last_value always go forward fail to hold.
26415 */
26416- last = atomic64_read(&last_value);
26417+ last = atomic64_read_unchecked(&last_value);
26418 do {
26419 if (ret < last)
26420 return last;
26421- last = atomic64_cmpxchg(&last_value, last, ret);
26422+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26423 } while (unlikely(last != ret));
26424
26425 return ret;
26426diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26427index c752cb4..866c432 100644
26428--- a/arch/x86/kernel/reboot.c
26429+++ b/arch/x86/kernel/reboot.c
26430@@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26431
26432 void __noreturn machine_real_restart(unsigned int type)
26433 {
26434+
26435+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26436+ struct desc_struct *gdt;
26437+#endif
26438+
26439 local_irq_disable();
26440
26441 /*
26442@@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26443
26444 /* Jump to the identity-mapped low memory code */
26445 #ifdef CONFIG_X86_32
26446- asm volatile("jmpl *%0" : :
26447+
26448+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26449+ gdt = get_cpu_gdt_table(smp_processor_id());
26450+ pax_open_kernel();
26451+#ifdef CONFIG_PAX_MEMORY_UDEREF
26452+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26453+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26454+ loadsegment(ds, __KERNEL_DS);
26455+ loadsegment(es, __KERNEL_DS);
26456+ loadsegment(ss, __KERNEL_DS);
26457+#endif
26458+#ifdef CONFIG_PAX_KERNEXEC
26459+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26460+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26461+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26462+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26463+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26464+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26465+#endif
26466+ pax_close_kernel();
26467+#endif
26468+
26469+ asm volatile("ljmpl *%0" : :
26470 "rm" (real_mode_header->machine_real_restart_asm),
26471 "a" (type));
26472 #else
26473@@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26474 * try to force a triple fault and then cycle between hitting the keyboard
26475 * controller and doing that
26476 */
26477-static void native_machine_emergency_restart(void)
26478+static void __noreturn native_machine_emergency_restart(void)
26479 {
26480 int i;
26481 int attempt = 0;
26482@@ -593,13 +620,13 @@ void native_machine_shutdown(void)
26483 #endif
26484 }
26485
26486-static void __machine_emergency_restart(int emergency)
26487+static void __noreturn __machine_emergency_restart(int emergency)
26488 {
26489 reboot_emergency = emergency;
26490 machine_ops.emergency_restart();
26491 }
26492
26493-static void native_machine_restart(char *__unused)
26494+static void __noreturn native_machine_restart(char *__unused)
26495 {
26496 pr_notice("machine restart\n");
26497
26498@@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
26499 __machine_emergency_restart(0);
26500 }
26501
26502-static void native_machine_halt(void)
26503+static void __noreturn native_machine_halt(void)
26504 {
26505 /* Stop other cpus and apics */
26506 machine_shutdown();
26507@@ -618,7 +645,7 @@ static void native_machine_halt(void)
26508 stop_this_cpu(NULL);
26509 }
26510
26511-static void native_machine_power_off(void)
26512+static void __noreturn native_machine_power_off(void)
26513 {
26514 if (pm_power_off) {
26515 if (!reboot_force)
26516@@ -627,9 +654,10 @@ static void native_machine_power_off(void)
26517 }
26518 /* A fallback in case there is no PM info available */
26519 tboot_shutdown(TB_SHUTDOWN_HALT);
26520+ unreachable();
26521 }
26522
26523-struct machine_ops machine_ops = {
26524+struct machine_ops machine_ops __read_only = {
26525 .power_off = native_machine_power_off,
26526 .shutdown = native_machine_shutdown,
26527 .emergency_restart = native_machine_emergency_restart,
26528diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26529index c8e41e9..64049ef 100644
26530--- a/arch/x86/kernel/reboot_fixups_32.c
26531+++ b/arch/x86/kernel/reboot_fixups_32.c
26532@@ -57,7 +57,7 @@ struct device_fixup {
26533 unsigned int vendor;
26534 unsigned int device;
26535 void (*reboot_fixup)(struct pci_dev *);
26536-};
26537+} __do_const;
26538
26539 /*
26540 * PCI ids solely used for fixups_table go here
26541diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26542index 3fd2c69..a444264 100644
26543--- a/arch/x86/kernel/relocate_kernel_64.S
26544+++ b/arch/x86/kernel/relocate_kernel_64.S
26545@@ -96,8 +96,7 @@ relocate_kernel:
26546
26547 /* jump to identity mapped page */
26548 addq $(identity_mapped - relocate_kernel), %r8
26549- pushq %r8
26550- ret
26551+ jmp *%r8
26552
26553 identity_mapped:
26554 /* set return address to 0 if not preserving context */
26555diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26556index cb233bc..23b4879 100644
26557--- a/arch/x86/kernel/setup.c
26558+++ b/arch/x86/kernel/setup.c
26559@@ -110,6 +110,7 @@
26560 #include <asm/mce.h>
26561 #include <asm/alternative.h>
26562 #include <asm/prom.h>
26563+#include <asm/boot.h>
26564
26565 /*
26566 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26567@@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26568 #endif
26569
26570
26571-#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26572-__visible unsigned long mmu_cr4_features;
26573+#ifdef CONFIG_X86_64
26574+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26575+#elif defined(CONFIG_X86_PAE)
26576+__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26577 #else
26578-__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26579+__visible unsigned long mmu_cr4_features __read_only;
26580 #endif
26581
26582+void set_in_cr4(unsigned long mask)
26583+{
26584+ unsigned long cr4 = read_cr4();
26585+
26586+ if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26587+ return;
26588+
26589+ pax_open_kernel();
26590+ mmu_cr4_features |= mask;
26591+ pax_close_kernel();
26592+
26593+ if (trampoline_cr4_features)
26594+ *trampoline_cr4_features = mmu_cr4_features;
26595+ cr4 |= mask;
26596+ write_cr4(cr4);
26597+}
26598+EXPORT_SYMBOL(set_in_cr4);
26599+
26600+void clear_in_cr4(unsigned long mask)
26601+{
26602+ unsigned long cr4 = read_cr4();
26603+
26604+ if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26605+ return;
26606+
26607+ pax_open_kernel();
26608+ mmu_cr4_features &= ~mask;
26609+ pax_close_kernel();
26610+
26611+ if (trampoline_cr4_features)
26612+ *trampoline_cr4_features = mmu_cr4_features;
26613+ cr4 &= ~mask;
26614+ write_cr4(cr4);
26615+}
26616+EXPORT_SYMBOL(clear_in_cr4);
26617+
26618 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26619 int bootloader_type, bootloader_version;
26620
26621@@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26622 * area (640->1Mb) as ram even though it is not.
26623 * take them out.
26624 */
26625- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26626+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26627
26628 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26629 }
26630@@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26631 /* called before trim_bios_range() to spare extra sanitize */
26632 static void __init e820_add_kernel_range(void)
26633 {
26634- u64 start = __pa_symbol(_text);
26635+ u64 start = __pa_symbol(ktla_ktva(_text));
26636 u64 size = __pa_symbol(_end) - start;
26637
26638 /*
26639@@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26640
26641 void __init setup_arch(char **cmdline_p)
26642 {
26643+#ifdef CONFIG_X86_32
26644+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26645+#else
26646 memblock_reserve(__pa_symbol(_text),
26647 (unsigned long)__bss_stop - (unsigned long)_text);
26648+#endif
26649
26650 early_reserve_initrd();
26651
26652@@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26653
26654 if (!boot_params.hdr.root_flags)
26655 root_mountflags &= ~MS_RDONLY;
26656- init_mm.start_code = (unsigned long) _text;
26657- init_mm.end_code = (unsigned long) _etext;
26658+ init_mm.start_code = ktla_ktva((unsigned long) _text);
26659+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
26660 init_mm.end_data = (unsigned long) _edata;
26661 init_mm.brk = _brk_end;
26662
26663- code_resource.start = __pa_symbol(_text);
26664- code_resource.end = __pa_symbol(_etext)-1;
26665- data_resource.start = __pa_symbol(_etext);
26666+ code_resource.start = __pa_symbol(ktla_ktva(_text));
26667+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26668+ data_resource.start = __pa_symbol(_sdata);
26669 data_resource.end = __pa_symbol(_edata)-1;
26670 bss_resource.start = __pa_symbol(__bss_start);
26671 bss_resource.end = __pa_symbol(__bss_stop)-1;
26672diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26673index 5cdff03..80fa283 100644
26674--- a/arch/x86/kernel/setup_percpu.c
26675+++ b/arch/x86/kernel/setup_percpu.c
26676@@ -21,19 +21,17 @@
26677 #include <asm/cpu.h>
26678 #include <asm/stackprotector.h>
26679
26680-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26681+#ifdef CONFIG_SMP
26682+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26683 EXPORT_PER_CPU_SYMBOL(cpu_number);
26684+#endif
26685
26686-#ifdef CONFIG_X86_64
26687 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26688-#else
26689-#define BOOT_PERCPU_OFFSET 0
26690-#endif
26691
26692 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26693 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26694
26695-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26696+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26697 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26698 };
26699 EXPORT_SYMBOL(__per_cpu_offset);
26700@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26701 {
26702 #ifdef CONFIG_NEED_MULTIPLE_NODES
26703 pg_data_t *last = NULL;
26704- unsigned int cpu;
26705+ int cpu;
26706
26707 for_each_possible_cpu(cpu) {
26708 int node = early_cpu_to_node(cpu);
26709@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26710 {
26711 #ifdef CONFIG_X86_32
26712 struct desc_struct gdt;
26713+ unsigned long base = per_cpu_offset(cpu);
26714
26715- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26716- 0x2 | DESCTYPE_S, 0x8);
26717- gdt.s = 1;
26718+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26719+ 0x83 | DESCTYPE_S, 0xC);
26720 write_gdt_entry(get_cpu_gdt_table(cpu),
26721 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26722 #endif
26723@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26724 /* alrighty, percpu areas up and running */
26725 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26726 for_each_possible_cpu(cpu) {
26727+#ifdef CONFIG_CC_STACKPROTECTOR
26728+#ifdef CONFIG_X86_32
26729+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
26730+#endif
26731+#endif
26732 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26733 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26734 per_cpu(cpu_number, cpu) = cpu;
26735@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26736 */
26737 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26738 #endif
26739+#ifdef CONFIG_CC_STACKPROTECTOR
26740+#ifdef CONFIG_X86_32
26741+ if (!cpu)
26742+ per_cpu(stack_canary.canary, cpu) = canary;
26743+#endif
26744+#endif
26745 /*
26746 * Up to this point, the boot CPU has been using .init.data
26747 * area. Reload any changed state for the boot CPU.
26748diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26749index 9e5de68..16c53cb 100644
26750--- a/arch/x86/kernel/signal.c
26751+++ b/arch/x86/kernel/signal.c
26752@@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26753 * Align the stack pointer according to the i386 ABI,
26754 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26755 */
26756- sp = ((sp + 4) & -16ul) - 4;
26757+ sp = ((sp - 12) & -16ul) - 4;
26758 #else /* !CONFIG_X86_32 */
26759 sp = round_down(sp, 16) - 8;
26760 #endif
26761@@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26762 }
26763
26764 if (current->mm->context.vdso)
26765- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26766+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26767 else
26768- restorer = &frame->retcode;
26769+ restorer = (void __user *)&frame->retcode;
26770 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26771 restorer = ksig->ka.sa.sa_restorer;
26772
26773@@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26774 * reasons and because gdb uses it as a signature to notice
26775 * signal handler stack frames.
26776 */
26777- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26778+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26779
26780 if (err)
26781 return -EFAULT;
26782@@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26783 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26784
26785 /* Set up to return from userspace. */
26786- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26787+ if (current->mm->context.vdso)
26788+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26789+ else
26790+ restorer = (void __user *)&frame->retcode;
26791 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26792 restorer = ksig->ka.sa.sa_restorer;
26793 put_user_ex(restorer, &frame->pretcode);
26794@@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26795 * reasons and because gdb uses it as a signature to notice
26796 * signal handler stack frames.
26797 */
26798- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26799+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26800 } put_user_catch(err);
26801
26802 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26803@@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26804 {
26805 int usig = signr_convert(ksig->sig);
26806 sigset_t *set = sigmask_to_save();
26807- compat_sigset_t *cset = (compat_sigset_t *) set;
26808+ sigset_t sigcopy;
26809+ compat_sigset_t *cset;
26810+
26811+ sigcopy = *set;
26812+
26813+ cset = (compat_sigset_t *) &sigcopy;
26814
26815 /* Set up the stack frame */
26816 if (is_ia32_frame()) {
26817@@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26818 } else if (is_x32_frame()) {
26819 return x32_setup_rt_frame(ksig, cset, regs);
26820 } else {
26821- return __setup_rt_frame(ksig->sig, ksig, set, regs);
26822+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26823 }
26824 }
26825
26826diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26827index 7c3a5a6..f0a8961 100644
26828--- a/arch/x86/kernel/smp.c
26829+++ b/arch/x86/kernel/smp.c
26830@@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26831
26832 __setup("nonmi_ipi", nonmi_ipi_setup);
26833
26834-struct smp_ops smp_ops = {
26835+struct smp_ops smp_ops __read_only = {
26836 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26837 .smp_prepare_cpus = native_smp_prepare_cpus,
26838 .smp_cpus_done = native_smp_cpus_done,
26839diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26840index 85dc05a..f8c96f6 100644
26841--- a/arch/x86/kernel/smpboot.c
26842+++ b/arch/x86/kernel/smpboot.c
26843@@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26844
26845 enable_start_cpu0 = 0;
26846
26847-#ifdef CONFIG_X86_32
26848- /* switch away from the initial page table */
26849- load_cr3(swapper_pg_dir);
26850- __flush_tlb_all();
26851-#endif
26852-
26853 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26854 barrier();
26855+
26856+ /* switch away from the initial page table */
26857+#ifdef CONFIG_PAX_PER_CPU_PGD
26858+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26859+ __flush_tlb_all();
26860+#elif defined(CONFIG_X86_32)
26861+ load_cr3(swapper_pg_dir);
26862+ __flush_tlb_all();
26863+#endif
26864+
26865 /*
26866 * Check TSC synchronization with the BP:
26867 */
26868@@ -749,8 +753,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26869 alternatives_enable_smp();
26870
26871 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26872- (THREAD_SIZE + task_stack_page(idle))) - 1);
26873+ (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
26874 per_cpu(current_task, cpu) = idle;
26875+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
26876
26877 #ifdef CONFIG_X86_32
26878 /* Stack for startup_32 can be just as for start_secondary onwards */
26879@@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26880 #else
26881 clear_tsk_thread_flag(idle, TIF_FORK);
26882 initial_gs = per_cpu_offset(cpu);
26883- per_cpu(kernel_stack, cpu) =
26884- (unsigned long)task_stack_page(idle) -
26885- KERNEL_STACK_OFFSET + THREAD_SIZE;
26886+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26887 #endif
26888+
26889+ pax_open_kernel();
26890 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26891+ pax_close_kernel();
26892+
26893 initial_code = (unsigned long)start_secondary;
26894 stack_start = idle->thread.sp;
26895
26896@@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26897 /* the FPU context is blank, nobody can own it */
26898 __cpu_disable_lazy_restore(cpu);
26899
26900+#ifdef CONFIG_PAX_PER_CPU_PGD
26901+ clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26902+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26903+ KERNEL_PGD_PTRS);
26904+ clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26905+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26906+ KERNEL_PGD_PTRS);
26907+#endif
26908+
26909 err = do_boot_cpu(apicid, cpu, tidle);
26910 if (err) {
26911 pr_debug("do_boot_cpu failed %d\n", err);
26912diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26913index 9b4d51d..5d28b58 100644
26914--- a/arch/x86/kernel/step.c
26915+++ b/arch/x86/kernel/step.c
26916@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26917 struct desc_struct *desc;
26918 unsigned long base;
26919
26920- seg &= ~7UL;
26921+ seg >>= 3;
26922
26923 mutex_lock(&child->mm->context.lock);
26924- if (unlikely((seg >> 3) >= child->mm->context.size))
26925+ if (unlikely(seg >= child->mm->context.size))
26926 addr = -1L; /* bogus selector, access would fault */
26927 else {
26928 desc = child->mm->context.ldt + seg;
26929@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26930 addr += base;
26931 }
26932 mutex_unlock(&child->mm->context.lock);
26933- }
26934+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26935+ addr = ktla_ktva(addr);
26936
26937 return addr;
26938 }
26939@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26940 unsigned char opcode[15];
26941 unsigned long addr = convert_ip_to_linear(child, regs);
26942
26943+ if (addr == -EINVAL)
26944+ return 0;
26945+
26946 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26947 for (i = 0; i < copied; i++) {
26948 switch (opcode[i]) {
26949diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26950new file mode 100644
26951index 0000000..5877189
26952--- /dev/null
26953+++ b/arch/x86/kernel/sys_i386_32.c
26954@@ -0,0 +1,189 @@
26955+/*
26956+ * This file contains various random system calls that
26957+ * have a non-standard calling sequence on the Linux/i386
26958+ * platform.
26959+ */
26960+
26961+#include <linux/errno.h>
26962+#include <linux/sched.h>
26963+#include <linux/mm.h>
26964+#include <linux/fs.h>
26965+#include <linux/smp.h>
26966+#include <linux/sem.h>
26967+#include <linux/msg.h>
26968+#include <linux/shm.h>
26969+#include <linux/stat.h>
26970+#include <linux/syscalls.h>
26971+#include <linux/mman.h>
26972+#include <linux/file.h>
26973+#include <linux/utsname.h>
26974+#include <linux/ipc.h>
26975+#include <linux/elf.h>
26976+
26977+#include <linux/uaccess.h>
26978+#include <linux/unistd.h>
26979+
26980+#include <asm/syscalls.h>
26981+
26982+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26983+{
26984+ unsigned long pax_task_size = TASK_SIZE;
26985+
26986+#ifdef CONFIG_PAX_SEGMEXEC
26987+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26988+ pax_task_size = SEGMEXEC_TASK_SIZE;
26989+#endif
26990+
26991+ if (flags & MAP_FIXED)
26992+ if (len > pax_task_size || addr > pax_task_size - len)
26993+ return -EINVAL;
26994+
26995+ return 0;
26996+}
26997+
26998+/*
26999+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27000+ */
27001+static unsigned long get_align_mask(void)
27002+{
27003+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27004+ return 0;
27005+
27006+ if (!(current->flags & PF_RANDOMIZE))
27007+ return 0;
27008+
27009+ return va_align.mask;
27010+}
27011+
27012+unsigned long
27013+arch_get_unmapped_area(struct file *filp, unsigned long addr,
27014+ unsigned long len, unsigned long pgoff, unsigned long flags)
27015+{
27016+ struct mm_struct *mm = current->mm;
27017+ struct vm_area_struct *vma;
27018+ unsigned long pax_task_size = TASK_SIZE;
27019+ struct vm_unmapped_area_info info;
27020+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27021+
27022+#ifdef CONFIG_PAX_SEGMEXEC
27023+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27024+ pax_task_size = SEGMEXEC_TASK_SIZE;
27025+#endif
27026+
27027+ pax_task_size -= PAGE_SIZE;
27028+
27029+ if (len > pax_task_size)
27030+ return -ENOMEM;
27031+
27032+ if (flags & MAP_FIXED)
27033+ return addr;
27034+
27035+#ifdef CONFIG_PAX_RANDMMAP
27036+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27037+#endif
27038+
27039+ if (addr) {
27040+ addr = PAGE_ALIGN(addr);
27041+ if (pax_task_size - len >= addr) {
27042+ vma = find_vma(mm, addr);
27043+ if (check_heap_stack_gap(vma, addr, len, offset))
27044+ return addr;
27045+ }
27046+ }
27047+
27048+ info.flags = 0;
27049+ info.length = len;
27050+ info.align_mask = filp ? get_align_mask() : 0;
27051+ info.align_offset = pgoff << PAGE_SHIFT;
27052+ info.threadstack_offset = offset;
27053+
27054+#ifdef CONFIG_PAX_PAGEEXEC
27055+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27056+ info.low_limit = 0x00110000UL;
27057+ info.high_limit = mm->start_code;
27058+
27059+#ifdef CONFIG_PAX_RANDMMAP
27060+ if (mm->pax_flags & MF_PAX_RANDMMAP)
27061+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27062+#endif
27063+
27064+ if (info.low_limit < info.high_limit) {
27065+ addr = vm_unmapped_area(&info);
27066+ if (!IS_ERR_VALUE(addr))
27067+ return addr;
27068+ }
27069+ } else
27070+#endif
27071+
27072+ info.low_limit = mm->mmap_base;
27073+ info.high_limit = pax_task_size;
27074+
27075+ return vm_unmapped_area(&info);
27076+}
27077+
27078+unsigned long
27079+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27080+ const unsigned long len, const unsigned long pgoff,
27081+ const unsigned long flags)
27082+{
27083+ struct vm_area_struct *vma;
27084+ struct mm_struct *mm = current->mm;
27085+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27086+ struct vm_unmapped_area_info info;
27087+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27088+
27089+#ifdef CONFIG_PAX_SEGMEXEC
27090+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
27091+ pax_task_size = SEGMEXEC_TASK_SIZE;
27092+#endif
27093+
27094+ pax_task_size -= PAGE_SIZE;
27095+
27096+ /* requested length too big for entire address space */
27097+ if (len > pax_task_size)
27098+ return -ENOMEM;
27099+
27100+ if (flags & MAP_FIXED)
27101+ return addr;
27102+
27103+#ifdef CONFIG_PAX_PAGEEXEC
27104+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27105+ goto bottomup;
27106+#endif
27107+
27108+#ifdef CONFIG_PAX_RANDMMAP
27109+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27110+#endif
27111+
27112+ /* requesting a specific address */
27113+ if (addr) {
27114+ addr = PAGE_ALIGN(addr);
27115+ if (pax_task_size - len >= addr) {
27116+ vma = find_vma(mm, addr);
27117+ if (check_heap_stack_gap(vma, addr, len, offset))
27118+ return addr;
27119+ }
27120+ }
27121+
27122+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27123+ info.length = len;
27124+ info.low_limit = PAGE_SIZE;
27125+ info.high_limit = mm->mmap_base;
27126+ info.align_mask = filp ? get_align_mask() : 0;
27127+ info.align_offset = pgoff << PAGE_SHIFT;
27128+ info.threadstack_offset = offset;
27129+
27130+ addr = vm_unmapped_area(&info);
27131+ if (!(addr & ~PAGE_MASK))
27132+ return addr;
27133+ VM_BUG_ON(addr != -ENOMEM);
27134+
27135+bottomup:
27136+ /*
27137+ * A failed mmap() very likely causes application failure,
27138+ * so fall back to the bottom-up function here. This scenario
27139+ * can happen with large stack limits and large mmap()
27140+ * allocations.
27141+ */
27142+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27143+}
27144diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27145index 30277e2..5664a29 100644
27146--- a/arch/x86/kernel/sys_x86_64.c
27147+++ b/arch/x86/kernel/sys_x86_64.c
27148@@ -81,8 +81,8 @@ out:
27149 return error;
27150 }
27151
27152-static void find_start_end(unsigned long flags, unsigned long *begin,
27153- unsigned long *end)
27154+static void find_start_end(struct mm_struct *mm, unsigned long flags,
27155+ unsigned long *begin, unsigned long *end)
27156 {
27157 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27158 unsigned long new_begin;
27159@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27160 *begin = new_begin;
27161 }
27162 } else {
27163- *begin = current->mm->mmap_legacy_base;
27164+ *begin = mm->mmap_legacy_base;
27165 *end = TASK_SIZE;
27166 }
27167 }
27168@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27169 struct vm_area_struct *vma;
27170 struct vm_unmapped_area_info info;
27171 unsigned long begin, end;
27172+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27173
27174 if (flags & MAP_FIXED)
27175 return addr;
27176
27177- find_start_end(flags, &begin, &end);
27178+ find_start_end(mm, flags, &begin, &end);
27179
27180 if (len > end)
27181 return -ENOMEM;
27182
27183+#ifdef CONFIG_PAX_RANDMMAP
27184+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27185+#endif
27186+
27187 if (addr) {
27188 addr = PAGE_ALIGN(addr);
27189 vma = find_vma(mm, addr);
27190- if (end - len >= addr &&
27191- (!vma || addr + len <= vma->vm_start))
27192+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27193 return addr;
27194 }
27195
27196@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27197 info.high_limit = end;
27198 info.align_mask = filp ? get_align_mask() : 0;
27199 info.align_offset = pgoff << PAGE_SHIFT;
27200+ info.threadstack_offset = offset;
27201 return vm_unmapped_area(&info);
27202 }
27203
27204@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27205 struct mm_struct *mm = current->mm;
27206 unsigned long addr = addr0;
27207 struct vm_unmapped_area_info info;
27208+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27209
27210 /* requested length too big for entire address space */
27211 if (len > TASK_SIZE)
27212@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27213 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27214 goto bottomup;
27215
27216+#ifdef CONFIG_PAX_RANDMMAP
27217+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27218+#endif
27219+
27220 /* requesting a specific address */
27221 if (addr) {
27222 addr = PAGE_ALIGN(addr);
27223 vma = find_vma(mm, addr);
27224- if (TASK_SIZE - len >= addr &&
27225- (!vma || addr + len <= vma->vm_start))
27226+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27227 return addr;
27228 }
27229
27230@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27231 info.high_limit = mm->mmap_base;
27232 info.align_mask = filp ? get_align_mask() : 0;
27233 info.align_offset = pgoff << PAGE_SHIFT;
27234+ info.threadstack_offset = offset;
27235 addr = vm_unmapped_area(&info);
27236 if (!(addr & ~PAGE_MASK))
27237 return addr;
27238diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27239index 91a4496..bb87552 100644
27240--- a/arch/x86/kernel/tboot.c
27241+++ b/arch/x86/kernel/tboot.c
27242@@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27243
27244 void tboot_shutdown(u32 shutdown_type)
27245 {
27246- void (*shutdown)(void);
27247+ void (* __noreturn shutdown)(void);
27248
27249 if (!tboot_enabled())
27250 return;
27251@@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27252
27253 switch_to_tboot_pt();
27254
27255- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27256+ shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27257 shutdown();
27258
27259 /* should not reach here */
27260@@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27261 return -ENODEV;
27262 }
27263
27264-static atomic_t ap_wfs_count;
27265+static atomic_unchecked_t ap_wfs_count;
27266
27267 static int tboot_wait_for_aps(int num_aps)
27268 {
27269@@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27270 {
27271 switch (action) {
27272 case CPU_DYING:
27273- atomic_inc(&ap_wfs_count);
27274+ atomic_inc_unchecked(&ap_wfs_count);
27275 if (num_online_cpus() == 1)
27276- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27277+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27278 return NOTIFY_BAD;
27279 break;
27280 }
27281@@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27282
27283 tboot_create_trampoline();
27284
27285- atomic_set(&ap_wfs_count, 0);
27286+ atomic_set_unchecked(&ap_wfs_count, 0);
27287 register_hotcpu_notifier(&tboot_cpu_notifier);
27288
27289 #ifdef CONFIG_DEBUG_FS
27290diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27291index 24d3c91..d06b473 100644
27292--- a/arch/x86/kernel/time.c
27293+++ b/arch/x86/kernel/time.c
27294@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27295 {
27296 unsigned long pc = instruction_pointer(regs);
27297
27298- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27299+ if (!user_mode(regs) && in_lock_functions(pc)) {
27300 #ifdef CONFIG_FRAME_POINTER
27301- return *(unsigned long *)(regs->bp + sizeof(long));
27302+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27303 #else
27304 unsigned long *sp =
27305 (unsigned long *)kernel_stack_pointer(regs);
27306@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27307 * or above a saved flags. Eflags has bits 22-31 zero,
27308 * kernel addresses don't.
27309 */
27310+
27311+#ifdef CONFIG_PAX_KERNEXEC
27312+ return ktla_ktva(sp[0]);
27313+#else
27314 if (sp[0] >> 22)
27315 return sp[0];
27316 if (sp[1] >> 22)
27317 return sp[1];
27318 #endif
27319+
27320+#endif
27321 }
27322 return pc;
27323 }
27324diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27325index f7fec09..9991981 100644
27326--- a/arch/x86/kernel/tls.c
27327+++ b/arch/x86/kernel/tls.c
27328@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27329 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27330 return -EINVAL;
27331
27332+#ifdef CONFIG_PAX_SEGMEXEC
27333+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27334+ return -EINVAL;
27335+#endif
27336+
27337 set_tls_desc(p, idx, &info, 1);
27338
27339 return 0;
27340@@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27341
27342 if (kbuf)
27343 info = kbuf;
27344- else if (__copy_from_user(infobuf, ubuf, count))
27345+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27346 return -EFAULT;
27347 else
27348 info = infobuf;
27349diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27350index 1c113db..287b42e 100644
27351--- a/arch/x86/kernel/tracepoint.c
27352+++ b/arch/x86/kernel/tracepoint.c
27353@@ -9,11 +9,11 @@
27354 #include <linux/atomic.h>
27355
27356 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27357-struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27358+const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27359 (unsigned long) trace_idt_table };
27360
27361 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27362-gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27363+gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27364
27365 static int trace_irq_vector_refcount;
27366 static DEFINE_MUTEX(irq_vector_mutex);
27367diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27368index b857ed8..51ae4cb 100644
27369--- a/arch/x86/kernel/traps.c
27370+++ b/arch/x86/kernel/traps.c
27371@@ -66,7 +66,7 @@
27372 #include <asm/proto.h>
27373
27374 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27375-gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27376+gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27377 #else
27378 #include <asm/processor-flags.h>
27379 #include <asm/setup.h>
27380@@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27381 #endif
27382
27383 /* Must be page-aligned because the real IDT is used in a fixmap. */
27384-gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27385+gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27386
27387 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27388 EXPORT_SYMBOL_GPL(used_vectors);
27389@@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27390 }
27391
27392 static int __kprobes
27393-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27394+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27395 struct pt_regs *regs, long error_code)
27396 {
27397 #ifdef CONFIG_X86_32
27398- if (regs->flags & X86_VM_MASK) {
27399+ if (v8086_mode(regs)) {
27400 /*
27401 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27402 * On nmi (interrupt 2), do_trap should not be called.
27403@@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27404 return -1;
27405 }
27406 #endif
27407- if (!user_mode(regs)) {
27408+ if (!user_mode_novm(regs)) {
27409 if (!fixup_exception(regs)) {
27410 tsk->thread.error_code = error_code;
27411 tsk->thread.trap_nr = trapnr;
27412+
27413+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27414+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27415+ str = "PAX: suspicious stack segment fault";
27416+#endif
27417+
27418 die(str, regs, error_code);
27419 }
27420+
27421+#ifdef CONFIG_PAX_REFCOUNT
27422+ if (trapnr == 4)
27423+ pax_report_refcount_overflow(regs);
27424+#endif
27425+
27426 return 0;
27427 }
27428
27429@@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27430 }
27431
27432 static void __kprobes
27433-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27434+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27435 long error_code, siginfo_t *info)
27436 {
27437 struct task_struct *tsk = current;
27438@@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27439 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27440 printk_ratelimit()) {
27441 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27442- tsk->comm, tsk->pid, str,
27443+ tsk->comm, task_pid_nr(tsk), str,
27444 regs->ip, regs->sp, error_code);
27445 print_vma_addr(" in ", regs->ip);
27446 pr_cont("\n");
27447@@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27448 conditional_sti(regs);
27449
27450 #ifdef CONFIG_X86_32
27451- if (regs->flags & X86_VM_MASK) {
27452+ if (v8086_mode(regs)) {
27453 local_irq_enable();
27454 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27455 goto exit;
27456@@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27457 #endif
27458
27459 tsk = current;
27460- if (!user_mode(regs)) {
27461+ if (!user_mode_novm(regs)) {
27462 if (fixup_exception(regs))
27463 goto exit;
27464
27465 tsk->thread.error_code = error_code;
27466 tsk->thread.trap_nr = X86_TRAP_GP;
27467 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27468- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27469+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27470+
27471+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27472+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27473+ die("PAX: suspicious general protection fault", regs, error_code);
27474+ else
27475+#endif
27476+
27477 die("general protection fault", regs, error_code);
27478+ }
27479 goto exit;
27480 }
27481
27482+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27483+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27484+ struct mm_struct *mm = tsk->mm;
27485+ unsigned long limit;
27486+
27487+ down_write(&mm->mmap_sem);
27488+ limit = mm->context.user_cs_limit;
27489+ if (limit < TASK_SIZE) {
27490+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27491+ up_write(&mm->mmap_sem);
27492+ return;
27493+ }
27494+ up_write(&mm->mmap_sem);
27495+ }
27496+#endif
27497+
27498 tsk->thread.error_code = error_code;
27499 tsk->thread.trap_nr = X86_TRAP_GP;
27500
27501@@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27502 /* It's safe to allow irq's after DR6 has been saved */
27503 preempt_conditional_sti(regs);
27504
27505- if (regs->flags & X86_VM_MASK) {
27506+ if (v8086_mode(regs)) {
27507 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27508 X86_TRAP_DB);
27509 preempt_conditional_cli(regs);
27510@@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27511 * We already checked v86 mode above, so we can check for kernel mode
27512 * by just checking the CPL of CS.
27513 */
27514- if ((dr6 & DR_STEP) && !user_mode(regs)) {
27515+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27516 tsk->thread.debugreg6 &= ~DR_STEP;
27517 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27518 regs->flags &= ~X86_EFLAGS_TF;
27519@@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27520 return;
27521 conditional_sti(regs);
27522
27523- if (!user_mode_vm(regs))
27524+ if (!user_mode(regs))
27525 {
27526 if (!fixup_exception(regs)) {
27527 task->thread.error_code = error_code;
27528diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27529index 2ed8459..7cf329f 100644
27530--- a/arch/x86/kernel/uprobes.c
27531+++ b/arch/x86/kernel/uprobes.c
27532@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27533 int ret = NOTIFY_DONE;
27534
27535 /* We are only interested in userspace traps */
27536- if (regs && !user_mode_vm(regs))
27537+ if (regs && !user_mode(regs))
27538 return NOTIFY_DONE;
27539
27540 switch (val) {
27541@@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27542
27543 if (ncopied != rasize) {
27544 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27545- "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27546+ "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27547
27548 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27549 }
27550diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27551index b9242ba..50c5edd 100644
27552--- a/arch/x86/kernel/verify_cpu.S
27553+++ b/arch/x86/kernel/verify_cpu.S
27554@@ -20,6 +20,7 @@
27555 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27556 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27557 * arch/x86/kernel/head_32.S: processor startup
27558+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27559 *
27560 * verify_cpu, returns the status of longmode and SSE in register %eax.
27561 * 0: Success 1: Failure
27562diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27563index e8edcf5..27f9344 100644
27564--- a/arch/x86/kernel/vm86_32.c
27565+++ b/arch/x86/kernel/vm86_32.c
27566@@ -44,6 +44,7 @@
27567 #include <linux/ptrace.h>
27568 #include <linux/audit.h>
27569 #include <linux/stddef.h>
27570+#include <linux/grsecurity.h>
27571
27572 #include <asm/uaccess.h>
27573 #include <asm/io.h>
27574@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27575 do_exit(SIGSEGV);
27576 }
27577
27578- tss = &per_cpu(init_tss, get_cpu());
27579+ tss = init_tss + get_cpu();
27580 current->thread.sp0 = current->thread.saved_sp0;
27581 current->thread.sysenter_cs = __KERNEL_CS;
27582 load_sp0(tss, &current->thread);
27583@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27584
27585 if (tsk->thread.saved_sp0)
27586 return -EPERM;
27587+
27588+#ifdef CONFIG_GRKERNSEC_VM86
27589+ if (!capable(CAP_SYS_RAWIO)) {
27590+ gr_handle_vm86();
27591+ return -EPERM;
27592+ }
27593+#endif
27594+
27595 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27596 offsetof(struct kernel_vm86_struct, vm86plus) -
27597 sizeof(info.regs));
27598@@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27599 int tmp;
27600 struct vm86plus_struct __user *v86;
27601
27602+#ifdef CONFIG_GRKERNSEC_VM86
27603+ if (!capable(CAP_SYS_RAWIO)) {
27604+ gr_handle_vm86();
27605+ return -EPERM;
27606+ }
27607+#endif
27608+
27609 tsk = current;
27610 switch (cmd) {
27611 case VM86_REQUEST_IRQ:
27612@@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27613 tsk->thread.saved_fs = info->regs32->fs;
27614 tsk->thread.saved_gs = get_user_gs(info->regs32);
27615
27616- tss = &per_cpu(init_tss, get_cpu());
27617+ tss = init_tss + get_cpu();
27618 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27619 if (cpu_has_sep)
27620 tsk->thread.sysenter_cs = 0;
27621@@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27622 goto cannot_handle;
27623 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27624 goto cannot_handle;
27625- intr_ptr = (unsigned long __user *) (i << 2);
27626+ intr_ptr = (__force unsigned long __user *) (i << 2);
27627 if (get_user(segoffs, intr_ptr))
27628 goto cannot_handle;
27629 if ((segoffs >> 16) == BIOSSEG)
27630diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27631index da6b35a..977e9cf 100644
27632--- a/arch/x86/kernel/vmlinux.lds.S
27633+++ b/arch/x86/kernel/vmlinux.lds.S
27634@@ -26,6 +26,13 @@
27635 #include <asm/page_types.h>
27636 #include <asm/cache.h>
27637 #include <asm/boot.h>
27638+#include <asm/segment.h>
27639+
27640+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27641+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27642+#else
27643+#define __KERNEL_TEXT_OFFSET 0
27644+#endif
27645
27646 #undef i386 /* in case the preprocessor is a 32bit one */
27647
27648@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27649
27650 PHDRS {
27651 text PT_LOAD FLAGS(5); /* R_E */
27652+#ifdef CONFIG_X86_32
27653+ module PT_LOAD FLAGS(5); /* R_E */
27654+#endif
27655+#ifdef CONFIG_XEN
27656+ rodata PT_LOAD FLAGS(5); /* R_E */
27657+#else
27658+ rodata PT_LOAD FLAGS(4); /* R__ */
27659+#endif
27660 data PT_LOAD FLAGS(6); /* RW_ */
27661-#ifdef CONFIG_X86_64
27662+ init.begin PT_LOAD FLAGS(6); /* RW_ */
27663 #ifdef CONFIG_SMP
27664 percpu PT_LOAD FLAGS(6); /* RW_ */
27665 #endif
27666+ text.init PT_LOAD FLAGS(5); /* R_E */
27667+ text.exit PT_LOAD FLAGS(5); /* R_E */
27668 init PT_LOAD FLAGS(7); /* RWE */
27669-#endif
27670 note PT_NOTE FLAGS(0); /* ___ */
27671 }
27672
27673 SECTIONS
27674 {
27675 #ifdef CONFIG_X86_32
27676- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27677- phys_startup_32 = startup_32 - LOAD_OFFSET;
27678+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27679 #else
27680- . = __START_KERNEL;
27681- phys_startup_64 = startup_64 - LOAD_OFFSET;
27682+ . = __START_KERNEL;
27683 #endif
27684
27685 /* Text and read-only data */
27686- .text : AT(ADDR(.text) - LOAD_OFFSET) {
27687- _text = .;
27688+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27689 /* bootstrapping code */
27690+#ifdef CONFIG_X86_32
27691+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27692+#else
27693+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27694+#endif
27695+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27696+ _text = .;
27697 HEAD_TEXT
27698 . = ALIGN(8);
27699 _stext = .;
27700@@ -104,13 +124,47 @@ SECTIONS
27701 IRQENTRY_TEXT
27702 *(.fixup)
27703 *(.gnu.warning)
27704- /* End of text section */
27705- _etext = .;
27706 } :text = 0x9090
27707
27708- NOTES :text :note
27709+ . += __KERNEL_TEXT_OFFSET;
27710
27711- EXCEPTION_TABLE(16) :text = 0x9090
27712+#ifdef CONFIG_X86_32
27713+ . = ALIGN(PAGE_SIZE);
27714+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27715+
27716+#ifdef CONFIG_PAX_KERNEXEC
27717+ MODULES_EXEC_VADDR = .;
27718+ BYTE(0)
27719+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27720+ . = ALIGN(HPAGE_SIZE) - 1;
27721+ MODULES_EXEC_END = .;
27722+#endif
27723+
27724+ } :module
27725+#endif
27726+
27727+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27728+ /* End of text section */
27729+ BYTE(0)
27730+ _etext = . - __KERNEL_TEXT_OFFSET;
27731+ }
27732+
27733+#ifdef CONFIG_X86_32
27734+ . = ALIGN(PAGE_SIZE);
27735+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27736+ . = ALIGN(PAGE_SIZE);
27737+ *(.empty_zero_page)
27738+ *(.initial_pg_fixmap)
27739+ *(.initial_pg_pmd)
27740+ *(.initial_page_table)
27741+ *(.swapper_pg_dir)
27742+ } :rodata
27743+#endif
27744+
27745+ . = ALIGN(PAGE_SIZE);
27746+ NOTES :rodata :note
27747+
27748+ EXCEPTION_TABLE(16) :rodata
27749
27750 #if defined(CONFIG_DEBUG_RODATA)
27751 /* .text should occupy whole number of pages */
27752@@ -122,16 +176,20 @@ SECTIONS
27753
27754 /* Data */
27755 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27756+
27757+#ifdef CONFIG_PAX_KERNEXEC
27758+ . = ALIGN(HPAGE_SIZE);
27759+#else
27760+ . = ALIGN(PAGE_SIZE);
27761+#endif
27762+
27763 /* Start of data section */
27764 _sdata = .;
27765
27766 /* init_task */
27767 INIT_TASK_DATA(THREAD_SIZE)
27768
27769-#ifdef CONFIG_X86_32
27770- /* 32 bit has nosave before _edata */
27771 NOSAVE_DATA
27772-#endif
27773
27774 PAGE_ALIGNED_DATA(PAGE_SIZE)
27775
27776@@ -172,12 +230,19 @@ SECTIONS
27777 #endif /* CONFIG_X86_64 */
27778
27779 /* Init code and data - will be freed after init */
27780- . = ALIGN(PAGE_SIZE);
27781 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27782+ BYTE(0)
27783+
27784+#ifdef CONFIG_PAX_KERNEXEC
27785+ . = ALIGN(HPAGE_SIZE);
27786+#else
27787+ . = ALIGN(PAGE_SIZE);
27788+#endif
27789+
27790 __init_begin = .; /* paired with __init_end */
27791- }
27792+ } :init.begin
27793
27794-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27795+#ifdef CONFIG_SMP
27796 /*
27797 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27798 * output PHDR, so the next output section - .init.text - should
27799@@ -186,12 +251,27 @@ SECTIONS
27800 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27801 #endif
27802
27803- INIT_TEXT_SECTION(PAGE_SIZE)
27804-#ifdef CONFIG_X86_64
27805- :init
27806-#endif
27807+ . = ALIGN(PAGE_SIZE);
27808+ init_begin = .;
27809+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27810+ VMLINUX_SYMBOL(_sinittext) = .;
27811+ INIT_TEXT
27812+ VMLINUX_SYMBOL(_einittext) = .;
27813+ . = ALIGN(PAGE_SIZE);
27814+ } :text.init
27815
27816- INIT_DATA_SECTION(16)
27817+ /*
27818+ * .exit.text is discard at runtime, not link time, to deal with
27819+ * references from .altinstructions and .eh_frame
27820+ */
27821+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27822+ EXIT_TEXT
27823+ . = ALIGN(16);
27824+ } :text.exit
27825+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27826+
27827+ . = ALIGN(PAGE_SIZE);
27828+ INIT_DATA_SECTION(16) :init
27829
27830 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27831 __x86_cpu_dev_start = .;
27832@@ -262,19 +342,12 @@ SECTIONS
27833 }
27834
27835 . = ALIGN(8);
27836- /*
27837- * .exit.text is discard at runtime, not link time, to deal with
27838- * references from .altinstructions and .eh_frame
27839- */
27840- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27841- EXIT_TEXT
27842- }
27843
27844 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27845 EXIT_DATA
27846 }
27847
27848-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27849+#ifndef CONFIG_SMP
27850 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27851 #endif
27852
27853@@ -293,16 +366,10 @@ SECTIONS
27854 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27855 __smp_locks = .;
27856 *(.smp_locks)
27857- . = ALIGN(PAGE_SIZE);
27858 __smp_locks_end = .;
27859+ . = ALIGN(PAGE_SIZE);
27860 }
27861
27862-#ifdef CONFIG_X86_64
27863- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27864- NOSAVE_DATA
27865- }
27866-#endif
27867-
27868 /* BSS */
27869 . = ALIGN(PAGE_SIZE);
27870 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27871@@ -318,6 +385,7 @@ SECTIONS
27872 __brk_base = .;
27873 . += 64 * 1024; /* 64k alignment slop space */
27874 *(.brk_reservation) /* areas brk users have reserved */
27875+ . = ALIGN(HPAGE_SIZE);
27876 __brk_limit = .;
27877 }
27878
27879@@ -344,13 +412,12 @@ SECTIONS
27880 * for the boot processor.
27881 */
27882 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27883-INIT_PER_CPU(gdt_page);
27884 INIT_PER_CPU(irq_stack_union);
27885
27886 /*
27887 * Build-time check on the image size:
27888 */
27889-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27890+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27891 "kernel image bigger than KERNEL_IMAGE_SIZE");
27892
27893 #ifdef CONFIG_SMP
27894diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27895index 1f96f93..d5c8f7a 100644
27896--- a/arch/x86/kernel/vsyscall_64.c
27897+++ b/arch/x86/kernel/vsyscall_64.c
27898@@ -56,15 +56,13 @@
27899 DEFINE_VVAR(int, vgetcpu_mode);
27900 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27901
27902-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27903+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27904
27905 static int __init vsyscall_setup(char *str)
27906 {
27907 if (str) {
27908 if (!strcmp("emulate", str))
27909 vsyscall_mode = EMULATE;
27910- else if (!strcmp("native", str))
27911- vsyscall_mode = NATIVE;
27912 else if (!strcmp("none", str))
27913 vsyscall_mode = NONE;
27914 else
27915@@ -323,8 +321,7 @@ do_ret:
27916 return true;
27917
27918 sigsegv:
27919- force_sig(SIGSEGV, current);
27920- return true;
27921+ do_group_exit(SIGKILL);
27922 }
27923
27924 /*
27925@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27926 extern char __vvar_page;
27927 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27928
27929- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27930- vsyscall_mode == NATIVE
27931- ? PAGE_KERNEL_VSYSCALL
27932- : PAGE_KERNEL_VVAR);
27933+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27934 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27935 (unsigned long)VSYSCALL_START);
27936
27937diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27938index 04068192..4d75aa6 100644
27939--- a/arch/x86/kernel/x8664_ksyms_64.c
27940+++ b/arch/x86/kernel/x8664_ksyms_64.c
27941@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27942 EXPORT_SYMBOL(copy_user_generic_unrolled);
27943 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27944 EXPORT_SYMBOL(__copy_user_nocache);
27945-EXPORT_SYMBOL(_copy_from_user);
27946-EXPORT_SYMBOL(_copy_to_user);
27947
27948 EXPORT_SYMBOL(copy_page);
27949 EXPORT_SYMBOL(clear_page);
27950@@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27951 EXPORT_SYMBOL(___preempt_schedule_context);
27952 #endif
27953 #endif
27954+
27955+#ifdef CONFIG_PAX_PER_CPU_PGD
27956+EXPORT_SYMBOL(cpu_pgd);
27957+#endif
27958diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27959index 021783b..6511282 100644
27960--- a/arch/x86/kernel/x86_init.c
27961+++ b/arch/x86/kernel/x86_init.c
27962@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27963 static void default_nmi_init(void) { };
27964 static int default_i8042_detect(void) { return 1; };
27965
27966-struct x86_platform_ops x86_platform = {
27967+struct x86_platform_ops x86_platform __read_only = {
27968 .calibrate_tsc = native_calibrate_tsc,
27969 .get_wallclock = mach_get_cmos_time,
27970 .set_wallclock = mach_set_rtc_mmss,
27971@@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27972 EXPORT_SYMBOL_GPL(x86_platform);
27973
27974 #if defined(CONFIG_PCI_MSI)
27975-struct x86_msi_ops x86_msi = {
27976+struct x86_msi_ops x86_msi __read_only = {
27977 .setup_msi_irqs = native_setup_msi_irqs,
27978 .compose_msi_msg = native_compose_msi_msg,
27979 .teardown_msi_irq = native_teardown_msi_irq,
27980@@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27981 }
27982 #endif
27983
27984-struct x86_io_apic_ops x86_io_apic_ops = {
27985+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27986 .init = native_io_apic_init_mappings,
27987 .read = native_io_apic_read,
27988 .write = native_io_apic_write,
27989diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27990index 422fd82..b2d262e 100644
27991--- a/arch/x86/kernel/xsave.c
27992+++ b/arch/x86/kernel/xsave.c
27993@@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27994
27995 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27996 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27997- err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27998+ err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27999
28000 if (!use_xsave())
28001 return err;
28002
28003- err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28004+ err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28005
28006 /*
28007 * Read the xstate_bv which we copied (directly from the cpu or
28008 * from the state in task struct) to the user buffers.
28009 */
28010- err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28011+ err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28012
28013 /*
28014 * For legacy compatible, we always set FP/SSE bits in the bit
28015@@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28016 */
28017 xstate_bv |= XSTATE_FPSSE;
28018
28019- err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28020+ err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28021
28022 return err;
28023 }
28024@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28025 {
28026 int err;
28027
28028+ buf = (struct xsave_struct __user *)____m(buf);
28029 if (use_xsave())
28030 err = xsave_user(buf);
28031 else if (use_fxsr())
28032@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28033 */
28034 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28035 {
28036+ buf = (void __user *)____m(buf);
28037 if (use_xsave()) {
28038 if ((unsigned long)buf % 64 || fx_only) {
28039 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28040diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28041index c697625..a032162 100644
28042--- a/arch/x86/kvm/cpuid.c
28043+++ b/arch/x86/kvm/cpuid.c
28044@@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28045 struct kvm_cpuid2 *cpuid,
28046 struct kvm_cpuid_entry2 __user *entries)
28047 {
28048- int r;
28049+ int r, i;
28050
28051 r = -E2BIG;
28052 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28053 goto out;
28054 r = -EFAULT;
28055- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28056- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28057+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28058 goto out;
28059+ for (i = 0; i < cpuid->nent; ++i) {
28060+ struct kvm_cpuid_entry2 cpuid_entry;
28061+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28062+ goto out;
28063+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
28064+ }
28065 vcpu->arch.cpuid_nent = cpuid->nent;
28066 kvm_apic_set_version(vcpu);
28067 kvm_x86_ops->cpuid_update(vcpu);
28068@@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28069 struct kvm_cpuid2 *cpuid,
28070 struct kvm_cpuid_entry2 __user *entries)
28071 {
28072- int r;
28073+ int r, i;
28074
28075 r = -E2BIG;
28076 if (cpuid->nent < vcpu->arch.cpuid_nent)
28077 goto out;
28078 r = -EFAULT;
28079- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28080- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28081+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28082 goto out;
28083+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28084+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28085+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28086+ goto out;
28087+ }
28088 return 0;
28089
28090 out:
28091diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28092index d86ff15..e77b023 100644
28093--- a/arch/x86/kvm/lapic.c
28094+++ b/arch/x86/kvm/lapic.c
28095@@ -55,7 +55,7 @@
28096 #define APIC_BUS_CYCLE_NS 1
28097
28098 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28099-#define apic_debug(fmt, arg...)
28100+#define apic_debug(fmt, arg...) do {} while (0)
28101
28102 #define APIC_LVT_NUM 6
28103 /* 14 is the version for Xeon and Pentium 8.4.8*/
28104diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28105index cba218a..1cc1bed 100644
28106--- a/arch/x86/kvm/paging_tmpl.h
28107+++ b/arch/x86/kvm/paging_tmpl.h
28108@@ -331,7 +331,7 @@ retry_walk:
28109 if (unlikely(kvm_is_error_hva(host_addr)))
28110 goto error;
28111
28112- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28113+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28114 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28115 goto error;
28116 walker->ptep_user[walker->level - 1] = ptep_user;
28117diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28118index 532add1..59eb241 100644
28119--- a/arch/x86/kvm/svm.c
28120+++ b/arch/x86/kvm/svm.c
28121@@ -3495,7 +3495,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28122 int cpu = raw_smp_processor_id();
28123
28124 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28125+
28126+ pax_open_kernel();
28127 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28128+ pax_close_kernel();
28129+
28130 load_TR_desc();
28131 }
28132
28133@@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28134 #endif
28135 #endif
28136
28137+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28138+ __set_fs(current_thread_info()->addr_limit);
28139+#endif
28140+
28141 reload_tss(vcpu);
28142
28143 local_irq_disable();
28144diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28145index 31c3e8b..ca3acc6 100644
28146--- a/arch/x86/kvm/vmx.c
28147+++ b/arch/x86/kvm/vmx.c
28148@@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28149 #endif
28150 }
28151
28152-static void vmcs_clear_bits(unsigned long field, u32 mask)
28153+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28154 {
28155 vmcs_writel(field, vmcs_readl(field) & ~mask);
28156 }
28157
28158-static void vmcs_set_bits(unsigned long field, u32 mask)
28159+static void vmcs_set_bits(unsigned long field, unsigned long mask)
28160 {
28161 vmcs_writel(field, vmcs_readl(field) | mask);
28162 }
28163@@ -1522,7 +1522,11 @@ static void reload_tss(void)
28164 struct desc_struct *descs;
28165
28166 descs = (void *)gdt->address;
28167+
28168+ pax_open_kernel();
28169 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28170+ pax_close_kernel();
28171+
28172 load_TR_desc();
28173 }
28174
28175@@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28176 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28177 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28178
28179+#ifdef CONFIG_PAX_PER_CPU_PGD
28180+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28181+#endif
28182+
28183 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28184 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28185 vmx->loaded_vmcs->cpu = cpu;
28186@@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28187 * reads and returns guest's timestamp counter "register"
28188 * guest_tsc = host_tsc + tsc_offset -- 21.3
28189 */
28190-static u64 guest_read_tsc(void)
28191+static u64 __intentional_overflow(-1) guest_read_tsc(void)
28192 {
28193 u64 host_tsc, tsc_offset;
28194
28195@@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
28196 if (!cpu_has_vmx_flexpriority())
28197 flexpriority_enabled = 0;
28198
28199- if (!cpu_has_vmx_tpr_shadow())
28200- kvm_x86_ops->update_cr8_intercept = NULL;
28201+ if (!cpu_has_vmx_tpr_shadow()) {
28202+ pax_open_kernel();
28203+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28204+ pax_close_kernel();
28205+ }
28206
28207 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28208 kvm_disable_largepages();
28209@@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
28210 if (!cpu_has_vmx_apicv())
28211 enable_apicv = 0;
28212
28213+ pax_open_kernel();
28214 if (enable_apicv)
28215- kvm_x86_ops->update_cr8_intercept = NULL;
28216+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28217 else {
28218- kvm_x86_ops->hwapic_irr_update = NULL;
28219- kvm_x86_ops->deliver_posted_interrupt = NULL;
28220- kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28221+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28222+ *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28223+ *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28224 }
28225+ pax_close_kernel();
28226
28227 if (nested)
28228 nested_vmx_setup_ctls_msrs();
28229@@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28230
28231 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28232 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28233+
28234+#ifndef CONFIG_PAX_PER_CPU_PGD
28235 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28236+#endif
28237
28238 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28239 #ifdef CONFIG_X86_64
28240@@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28241 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28242 vmx->host_idt_base = dt.address;
28243
28244- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28245+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28246
28247 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28248 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28249@@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28250 "jmp 2f \n\t"
28251 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28252 "2: "
28253+
28254+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28255+ "ljmp %[cs],$3f\n\t"
28256+ "3: "
28257+#endif
28258+
28259 /* Save guest registers, load host registers, keep flags */
28260 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28261 "pop %0 \n\t"
28262@@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28263 #endif
28264 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28265 [wordsize]"i"(sizeof(ulong))
28266+
28267+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28268+ ,[cs]"i"(__KERNEL_CS)
28269+#endif
28270+
28271 : "cc", "memory"
28272 #ifdef CONFIG_X86_64
28273 , "rax", "rbx", "rdi", "rsi"
28274@@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28275 if (debugctlmsr)
28276 update_debugctlmsr(debugctlmsr);
28277
28278-#ifndef CONFIG_X86_64
28279+#ifdef CONFIG_X86_32
28280 /*
28281 * The sysexit path does not restore ds/es, so we must set them to
28282 * a reasonable value ourselves.
28283@@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28284 * may be executed in interrupt context, which saves and restore segments
28285 * around it, nullifying its effect.
28286 */
28287- loadsegment(ds, __USER_DS);
28288- loadsegment(es, __USER_DS);
28289+ loadsegment(ds, __KERNEL_DS);
28290+ loadsegment(es, __KERNEL_DS);
28291+ loadsegment(ss, __KERNEL_DS);
28292+
28293+#ifdef CONFIG_PAX_KERNEXEC
28294+ loadsegment(fs, __KERNEL_PERCPU);
28295+#endif
28296+
28297+#ifdef CONFIG_PAX_MEMORY_UDEREF
28298+ __set_fs(current_thread_info()->addr_limit);
28299+#endif
28300+
28301 #endif
28302
28303 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28304diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28305index 4e33b85..fa94855 100644
28306--- a/arch/x86/kvm/x86.c
28307+++ b/arch/x86/kvm/x86.c
28308@@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28309 {
28310 struct kvm *kvm = vcpu->kvm;
28311 int lm = is_long_mode(vcpu);
28312- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28313- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28314+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28315+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28316 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28317 : kvm->arch.xen_hvm_config.blob_size_32;
28318 u32 page_num = data & ~PAGE_MASK;
28319@@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28320 if (n < msr_list.nmsrs)
28321 goto out;
28322 r = -EFAULT;
28323+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28324+ goto out;
28325 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28326 num_msrs_to_save * sizeof(u32)))
28327 goto out;
28328@@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28329 };
28330 #endif
28331
28332-int kvm_arch_init(void *opaque)
28333+int kvm_arch_init(const void *opaque)
28334 {
28335 int r;
28336 struct kvm_x86_ops *ops = opaque;
28337diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28338index bdf8532..f63c587 100644
28339--- a/arch/x86/lguest/boot.c
28340+++ b/arch/x86/lguest/boot.c
28341@@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28342 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28343 * Launcher to reboot us.
28344 */
28345-static void lguest_restart(char *reason)
28346+static __noreturn void lguest_restart(char *reason)
28347 {
28348 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28349+ BUG();
28350 }
28351
28352 /*G:050
28353diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28354index 00933d5..3a64af9 100644
28355--- a/arch/x86/lib/atomic64_386_32.S
28356+++ b/arch/x86/lib/atomic64_386_32.S
28357@@ -48,6 +48,10 @@ BEGIN(read)
28358 movl (v), %eax
28359 movl 4(v), %edx
28360 RET_ENDP
28361+BEGIN(read_unchecked)
28362+ movl (v), %eax
28363+ movl 4(v), %edx
28364+RET_ENDP
28365 #undef v
28366
28367 #define v %esi
28368@@ -55,6 +59,10 @@ BEGIN(set)
28369 movl %ebx, (v)
28370 movl %ecx, 4(v)
28371 RET_ENDP
28372+BEGIN(set_unchecked)
28373+ movl %ebx, (v)
28374+ movl %ecx, 4(v)
28375+RET_ENDP
28376 #undef v
28377
28378 #define v %esi
28379@@ -70,6 +78,20 @@ RET_ENDP
28380 BEGIN(add)
28381 addl %eax, (v)
28382 adcl %edx, 4(v)
28383+
28384+#ifdef CONFIG_PAX_REFCOUNT
28385+ jno 0f
28386+ subl %eax, (v)
28387+ sbbl %edx, 4(v)
28388+ int $4
28389+0:
28390+ _ASM_EXTABLE(0b, 0b)
28391+#endif
28392+
28393+RET_ENDP
28394+BEGIN(add_unchecked)
28395+ addl %eax, (v)
28396+ adcl %edx, 4(v)
28397 RET_ENDP
28398 #undef v
28399
28400@@ -77,6 +99,24 @@ RET_ENDP
28401 BEGIN(add_return)
28402 addl (v), %eax
28403 adcl 4(v), %edx
28404+
28405+#ifdef CONFIG_PAX_REFCOUNT
28406+ into
28407+1234:
28408+ _ASM_EXTABLE(1234b, 2f)
28409+#endif
28410+
28411+ movl %eax, (v)
28412+ movl %edx, 4(v)
28413+
28414+#ifdef CONFIG_PAX_REFCOUNT
28415+2:
28416+#endif
28417+
28418+RET_ENDP
28419+BEGIN(add_return_unchecked)
28420+ addl (v), %eax
28421+ adcl 4(v), %edx
28422 movl %eax, (v)
28423 movl %edx, 4(v)
28424 RET_ENDP
28425@@ -86,6 +126,20 @@ RET_ENDP
28426 BEGIN(sub)
28427 subl %eax, (v)
28428 sbbl %edx, 4(v)
28429+
28430+#ifdef CONFIG_PAX_REFCOUNT
28431+ jno 0f
28432+ addl %eax, (v)
28433+ adcl %edx, 4(v)
28434+ int $4
28435+0:
28436+ _ASM_EXTABLE(0b, 0b)
28437+#endif
28438+
28439+RET_ENDP
28440+BEGIN(sub_unchecked)
28441+ subl %eax, (v)
28442+ sbbl %edx, 4(v)
28443 RET_ENDP
28444 #undef v
28445
28446@@ -96,6 +150,27 @@ BEGIN(sub_return)
28447 sbbl $0, %edx
28448 addl (v), %eax
28449 adcl 4(v), %edx
28450+
28451+#ifdef CONFIG_PAX_REFCOUNT
28452+ into
28453+1234:
28454+ _ASM_EXTABLE(1234b, 2f)
28455+#endif
28456+
28457+ movl %eax, (v)
28458+ movl %edx, 4(v)
28459+
28460+#ifdef CONFIG_PAX_REFCOUNT
28461+2:
28462+#endif
28463+
28464+RET_ENDP
28465+BEGIN(sub_return_unchecked)
28466+ negl %edx
28467+ negl %eax
28468+ sbbl $0, %edx
28469+ addl (v), %eax
28470+ adcl 4(v), %edx
28471 movl %eax, (v)
28472 movl %edx, 4(v)
28473 RET_ENDP
28474@@ -105,6 +180,20 @@ RET_ENDP
28475 BEGIN(inc)
28476 addl $1, (v)
28477 adcl $0, 4(v)
28478+
28479+#ifdef CONFIG_PAX_REFCOUNT
28480+ jno 0f
28481+ subl $1, (v)
28482+ sbbl $0, 4(v)
28483+ int $4
28484+0:
28485+ _ASM_EXTABLE(0b, 0b)
28486+#endif
28487+
28488+RET_ENDP
28489+BEGIN(inc_unchecked)
28490+ addl $1, (v)
28491+ adcl $0, 4(v)
28492 RET_ENDP
28493 #undef v
28494
28495@@ -114,6 +203,26 @@ BEGIN(inc_return)
28496 movl 4(v), %edx
28497 addl $1, %eax
28498 adcl $0, %edx
28499+
28500+#ifdef CONFIG_PAX_REFCOUNT
28501+ into
28502+1234:
28503+ _ASM_EXTABLE(1234b, 2f)
28504+#endif
28505+
28506+ movl %eax, (v)
28507+ movl %edx, 4(v)
28508+
28509+#ifdef CONFIG_PAX_REFCOUNT
28510+2:
28511+#endif
28512+
28513+RET_ENDP
28514+BEGIN(inc_return_unchecked)
28515+ movl (v), %eax
28516+ movl 4(v), %edx
28517+ addl $1, %eax
28518+ adcl $0, %edx
28519 movl %eax, (v)
28520 movl %edx, 4(v)
28521 RET_ENDP
28522@@ -123,6 +232,20 @@ RET_ENDP
28523 BEGIN(dec)
28524 subl $1, (v)
28525 sbbl $0, 4(v)
28526+
28527+#ifdef CONFIG_PAX_REFCOUNT
28528+ jno 0f
28529+ addl $1, (v)
28530+ adcl $0, 4(v)
28531+ int $4
28532+0:
28533+ _ASM_EXTABLE(0b, 0b)
28534+#endif
28535+
28536+RET_ENDP
28537+BEGIN(dec_unchecked)
28538+ subl $1, (v)
28539+ sbbl $0, 4(v)
28540 RET_ENDP
28541 #undef v
28542
28543@@ -132,6 +255,26 @@ BEGIN(dec_return)
28544 movl 4(v), %edx
28545 subl $1, %eax
28546 sbbl $0, %edx
28547+
28548+#ifdef CONFIG_PAX_REFCOUNT
28549+ into
28550+1234:
28551+ _ASM_EXTABLE(1234b, 2f)
28552+#endif
28553+
28554+ movl %eax, (v)
28555+ movl %edx, 4(v)
28556+
28557+#ifdef CONFIG_PAX_REFCOUNT
28558+2:
28559+#endif
28560+
28561+RET_ENDP
28562+BEGIN(dec_return_unchecked)
28563+ movl (v), %eax
28564+ movl 4(v), %edx
28565+ subl $1, %eax
28566+ sbbl $0, %edx
28567 movl %eax, (v)
28568 movl %edx, 4(v)
28569 RET_ENDP
28570@@ -143,6 +286,13 @@ BEGIN(add_unless)
28571 adcl %edx, %edi
28572 addl (v), %eax
28573 adcl 4(v), %edx
28574+
28575+#ifdef CONFIG_PAX_REFCOUNT
28576+ into
28577+1234:
28578+ _ASM_EXTABLE(1234b, 2f)
28579+#endif
28580+
28581 cmpl %eax, %ecx
28582 je 3f
28583 1:
28584@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28585 1:
28586 addl $1, %eax
28587 adcl $0, %edx
28588+
28589+#ifdef CONFIG_PAX_REFCOUNT
28590+ into
28591+1234:
28592+ _ASM_EXTABLE(1234b, 2f)
28593+#endif
28594+
28595 movl %eax, (v)
28596 movl %edx, 4(v)
28597 movl $1, %eax
28598@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28599 movl 4(v), %edx
28600 subl $1, %eax
28601 sbbl $0, %edx
28602+
28603+#ifdef CONFIG_PAX_REFCOUNT
28604+ into
28605+1234:
28606+ _ASM_EXTABLE(1234b, 1f)
28607+#endif
28608+
28609 js 1f
28610 movl %eax, (v)
28611 movl %edx, 4(v)
28612diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28613index f5cc9eb..51fa319 100644
28614--- a/arch/x86/lib/atomic64_cx8_32.S
28615+++ b/arch/x86/lib/atomic64_cx8_32.S
28616@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28617 CFI_STARTPROC
28618
28619 read64 %ecx
28620+ pax_force_retaddr
28621 ret
28622 CFI_ENDPROC
28623 ENDPROC(atomic64_read_cx8)
28624
28625+ENTRY(atomic64_read_unchecked_cx8)
28626+ CFI_STARTPROC
28627+
28628+ read64 %ecx
28629+ pax_force_retaddr
28630+ ret
28631+ CFI_ENDPROC
28632+ENDPROC(atomic64_read_unchecked_cx8)
28633+
28634 ENTRY(atomic64_set_cx8)
28635 CFI_STARTPROC
28636
28637@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28638 cmpxchg8b (%esi)
28639 jne 1b
28640
28641+ pax_force_retaddr
28642 ret
28643 CFI_ENDPROC
28644 ENDPROC(atomic64_set_cx8)
28645
28646+ENTRY(atomic64_set_unchecked_cx8)
28647+ CFI_STARTPROC
28648+
28649+1:
28650+/* we don't need LOCK_PREFIX since aligned 64-bit writes
28651+ * are atomic on 586 and newer */
28652+ cmpxchg8b (%esi)
28653+ jne 1b
28654+
28655+ pax_force_retaddr
28656+ ret
28657+ CFI_ENDPROC
28658+ENDPROC(atomic64_set_unchecked_cx8)
28659+
28660 ENTRY(atomic64_xchg_cx8)
28661 CFI_STARTPROC
28662
28663@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28664 cmpxchg8b (%esi)
28665 jne 1b
28666
28667+ pax_force_retaddr
28668 ret
28669 CFI_ENDPROC
28670 ENDPROC(atomic64_xchg_cx8)
28671
28672-.macro addsub_return func ins insc
28673-ENTRY(atomic64_\func\()_return_cx8)
28674+.macro addsub_return func ins insc unchecked=""
28675+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28676 CFI_STARTPROC
28677 SAVE ebp
28678 SAVE ebx
28679@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28680 movl %edx, %ecx
28681 \ins\()l %esi, %ebx
28682 \insc\()l %edi, %ecx
28683+
28684+.ifb \unchecked
28685+#ifdef CONFIG_PAX_REFCOUNT
28686+ into
28687+2:
28688+ _ASM_EXTABLE(2b, 3f)
28689+#endif
28690+.endif
28691+
28692 LOCK_PREFIX
28693 cmpxchg8b (%ebp)
28694 jne 1b
28695-
28696-10:
28697 movl %ebx, %eax
28698 movl %ecx, %edx
28699+
28700+.ifb \unchecked
28701+#ifdef CONFIG_PAX_REFCOUNT
28702+3:
28703+#endif
28704+.endif
28705+
28706 RESTORE edi
28707 RESTORE esi
28708 RESTORE ebx
28709 RESTORE ebp
28710+ pax_force_retaddr
28711 ret
28712 CFI_ENDPROC
28713-ENDPROC(atomic64_\func\()_return_cx8)
28714+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28715 .endm
28716
28717 addsub_return add add adc
28718 addsub_return sub sub sbb
28719+addsub_return add add adc _unchecked
28720+addsub_return sub sub sbb _unchecked
28721
28722-.macro incdec_return func ins insc
28723-ENTRY(atomic64_\func\()_return_cx8)
28724+.macro incdec_return func ins insc unchecked=""
28725+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28726 CFI_STARTPROC
28727 SAVE ebx
28728
28729@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28730 movl %edx, %ecx
28731 \ins\()l $1, %ebx
28732 \insc\()l $0, %ecx
28733+
28734+.ifb \unchecked
28735+#ifdef CONFIG_PAX_REFCOUNT
28736+ into
28737+2:
28738+ _ASM_EXTABLE(2b, 3f)
28739+#endif
28740+.endif
28741+
28742 LOCK_PREFIX
28743 cmpxchg8b (%esi)
28744 jne 1b
28745
28746-10:
28747 movl %ebx, %eax
28748 movl %ecx, %edx
28749+
28750+.ifb \unchecked
28751+#ifdef CONFIG_PAX_REFCOUNT
28752+3:
28753+#endif
28754+.endif
28755+
28756 RESTORE ebx
28757+ pax_force_retaddr
28758 ret
28759 CFI_ENDPROC
28760-ENDPROC(atomic64_\func\()_return_cx8)
28761+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28762 .endm
28763
28764 incdec_return inc add adc
28765 incdec_return dec sub sbb
28766+incdec_return inc add adc _unchecked
28767+incdec_return dec sub sbb _unchecked
28768
28769 ENTRY(atomic64_dec_if_positive_cx8)
28770 CFI_STARTPROC
28771@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28772 movl %edx, %ecx
28773 subl $1, %ebx
28774 sbb $0, %ecx
28775+
28776+#ifdef CONFIG_PAX_REFCOUNT
28777+ into
28778+1234:
28779+ _ASM_EXTABLE(1234b, 2f)
28780+#endif
28781+
28782 js 2f
28783 LOCK_PREFIX
28784 cmpxchg8b (%esi)
28785@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28786 movl %ebx, %eax
28787 movl %ecx, %edx
28788 RESTORE ebx
28789+ pax_force_retaddr
28790 ret
28791 CFI_ENDPROC
28792 ENDPROC(atomic64_dec_if_positive_cx8)
28793@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28794 movl %edx, %ecx
28795 addl %ebp, %ebx
28796 adcl %edi, %ecx
28797+
28798+#ifdef CONFIG_PAX_REFCOUNT
28799+ into
28800+1234:
28801+ _ASM_EXTABLE(1234b, 3f)
28802+#endif
28803+
28804 LOCK_PREFIX
28805 cmpxchg8b (%esi)
28806 jne 1b
28807@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28808 CFI_ADJUST_CFA_OFFSET -8
28809 RESTORE ebx
28810 RESTORE ebp
28811+ pax_force_retaddr
28812 ret
28813 4:
28814 cmpl %edx, 4(%esp)
28815@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28816 xorl %ecx, %ecx
28817 addl $1, %ebx
28818 adcl %edx, %ecx
28819+
28820+#ifdef CONFIG_PAX_REFCOUNT
28821+ into
28822+1234:
28823+ _ASM_EXTABLE(1234b, 3f)
28824+#endif
28825+
28826 LOCK_PREFIX
28827 cmpxchg8b (%esi)
28828 jne 1b
28829@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28830 movl $1, %eax
28831 3:
28832 RESTORE ebx
28833+ pax_force_retaddr
28834 ret
28835 CFI_ENDPROC
28836 ENDPROC(atomic64_inc_not_zero_cx8)
28837diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28838index e78b8ee..7e173a8 100644
28839--- a/arch/x86/lib/checksum_32.S
28840+++ b/arch/x86/lib/checksum_32.S
28841@@ -29,7 +29,8 @@
28842 #include <asm/dwarf2.h>
28843 #include <asm/errno.h>
28844 #include <asm/asm.h>
28845-
28846+#include <asm/segment.h>
28847+
28848 /*
28849 * computes a partial checksum, e.g. for TCP/UDP fragments
28850 */
28851@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28852
28853 #define ARGBASE 16
28854 #define FP 12
28855-
28856-ENTRY(csum_partial_copy_generic)
28857+
28858+ENTRY(csum_partial_copy_generic_to_user)
28859 CFI_STARTPROC
28860+
28861+#ifdef CONFIG_PAX_MEMORY_UDEREF
28862+ pushl_cfi %gs
28863+ popl_cfi %es
28864+ jmp csum_partial_copy_generic
28865+#endif
28866+
28867+ENTRY(csum_partial_copy_generic_from_user)
28868+
28869+#ifdef CONFIG_PAX_MEMORY_UDEREF
28870+ pushl_cfi %gs
28871+ popl_cfi %ds
28872+#endif
28873+
28874+ENTRY(csum_partial_copy_generic)
28875 subl $4,%esp
28876 CFI_ADJUST_CFA_OFFSET 4
28877 pushl_cfi %edi
28878@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28879 jmp 4f
28880 SRC(1: movw (%esi), %bx )
28881 addl $2, %esi
28882-DST( movw %bx, (%edi) )
28883+DST( movw %bx, %es:(%edi) )
28884 addl $2, %edi
28885 addw %bx, %ax
28886 adcl $0, %eax
28887@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28888 SRC(1: movl (%esi), %ebx )
28889 SRC( movl 4(%esi), %edx )
28890 adcl %ebx, %eax
28891-DST( movl %ebx, (%edi) )
28892+DST( movl %ebx, %es:(%edi) )
28893 adcl %edx, %eax
28894-DST( movl %edx, 4(%edi) )
28895+DST( movl %edx, %es:4(%edi) )
28896
28897 SRC( movl 8(%esi), %ebx )
28898 SRC( movl 12(%esi), %edx )
28899 adcl %ebx, %eax
28900-DST( movl %ebx, 8(%edi) )
28901+DST( movl %ebx, %es:8(%edi) )
28902 adcl %edx, %eax
28903-DST( movl %edx, 12(%edi) )
28904+DST( movl %edx, %es:12(%edi) )
28905
28906 SRC( movl 16(%esi), %ebx )
28907 SRC( movl 20(%esi), %edx )
28908 adcl %ebx, %eax
28909-DST( movl %ebx, 16(%edi) )
28910+DST( movl %ebx, %es:16(%edi) )
28911 adcl %edx, %eax
28912-DST( movl %edx, 20(%edi) )
28913+DST( movl %edx, %es:20(%edi) )
28914
28915 SRC( movl 24(%esi), %ebx )
28916 SRC( movl 28(%esi), %edx )
28917 adcl %ebx, %eax
28918-DST( movl %ebx, 24(%edi) )
28919+DST( movl %ebx, %es:24(%edi) )
28920 adcl %edx, %eax
28921-DST( movl %edx, 28(%edi) )
28922+DST( movl %edx, %es:28(%edi) )
28923
28924 lea 32(%esi), %esi
28925 lea 32(%edi), %edi
28926@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28927 shrl $2, %edx # This clears CF
28928 SRC(3: movl (%esi), %ebx )
28929 adcl %ebx, %eax
28930-DST( movl %ebx, (%edi) )
28931+DST( movl %ebx, %es:(%edi) )
28932 lea 4(%esi), %esi
28933 lea 4(%edi), %edi
28934 dec %edx
28935@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28936 jb 5f
28937 SRC( movw (%esi), %cx )
28938 leal 2(%esi), %esi
28939-DST( movw %cx, (%edi) )
28940+DST( movw %cx, %es:(%edi) )
28941 leal 2(%edi), %edi
28942 je 6f
28943 shll $16,%ecx
28944 SRC(5: movb (%esi), %cl )
28945-DST( movb %cl, (%edi) )
28946+DST( movb %cl, %es:(%edi) )
28947 6: addl %ecx, %eax
28948 adcl $0, %eax
28949 7:
28950@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28951
28952 6001:
28953 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28954- movl $-EFAULT, (%ebx)
28955+ movl $-EFAULT, %ss:(%ebx)
28956
28957 # zero the complete destination - computing the rest
28958 # is too much work
28959@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28960
28961 6002:
28962 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28963- movl $-EFAULT,(%ebx)
28964+ movl $-EFAULT,%ss:(%ebx)
28965 jmp 5000b
28966
28967 .previous
28968
28969+ pushl_cfi %ss
28970+ popl_cfi %ds
28971+ pushl_cfi %ss
28972+ popl_cfi %es
28973 popl_cfi %ebx
28974 CFI_RESTORE ebx
28975 popl_cfi %esi
28976@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28977 popl_cfi %ecx # equivalent to addl $4,%esp
28978 ret
28979 CFI_ENDPROC
28980-ENDPROC(csum_partial_copy_generic)
28981+ENDPROC(csum_partial_copy_generic_to_user)
28982
28983 #else
28984
28985 /* Version for PentiumII/PPro */
28986
28987 #define ROUND1(x) \
28988+ nop; nop; nop; \
28989 SRC(movl x(%esi), %ebx ) ; \
28990 addl %ebx, %eax ; \
28991- DST(movl %ebx, x(%edi) ) ;
28992+ DST(movl %ebx, %es:x(%edi)) ;
28993
28994 #define ROUND(x) \
28995+ nop; nop; nop; \
28996 SRC(movl x(%esi), %ebx ) ; \
28997 adcl %ebx, %eax ; \
28998- DST(movl %ebx, x(%edi) ) ;
28999+ DST(movl %ebx, %es:x(%edi)) ;
29000
29001 #define ARGBASE 12
29002-
29003-ENTRY(csum_partial_copy_generic)
29004+
29005+ENTRY(csum_partial_copy_generic_to_user)
29006 CFI_STARTPROC
29007+
29008+#ifdef CONFIG_PAX_MEMORY_UDEREF
29009+ pushl_cfi %gs
29010+ popl_cfi %es
29011+ jmp csum_partial_copy_generic
29012+#endif
29013+
29014+ENTRY(csum_partial_copy_generic_from_user)
29015+
29016+#ifdef CONFIG_PAX_MEMORY_UDEREF
29017+ pushl_cfi %gs
29018+ popl_cfi %ds
29019+#endif
29020+
29021+ENTRY(csum_partial_copy_generic)
29022 pushl_cfi %ebx
29023 CFI_REL_OFFSET ebx, 0
29024 pushl_cfi %edi
29025@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29026 subl %ebx, %edi
29027 lea -1(%esi),%edx
29028 andl $-32,%edx
29029- lea 3f(%ebx,%ebx), %ebx
29030+ lea 3f(%ebx,%ebx,2), %ebx
29031 testl %esi, %esi
29032 jmp *%ebx
29033 1: addl $64,%esi
29034@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29035 jb 5f
29036 SRC( movw (%esi), %dx )
29037 leal 2(%esi), %esi
29038-DST( movw %dx, (%edi) )
29039+DST( movw %dx, %es:(%edi) )
29040 leal 2(%edi), %edi
29041 je 6f
29042 shll $16,%edx
29043 5:
29044 SRC( movb (%esi), %dl )
29045-DST( movb %dl, (%edi) )
29046+DST( movb %dl, %es:(%edi) )
29047 6: addl %edx, %eax
29048 adcl $0, %eax
29049 7:
29050 .section .fixup, "ax"
29051 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29052- movl $-EFAULT, (%ebx)
29053+ movl $-EFAULT, %ss:(%ebx)
29054 # zero the complete destination (computing the rest is too much work)
29055 movl ARGBASE+8(%esp),%edi # dst
29056 movl ARGBASE+12(%esp),%ecx # len
29057@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29058 rep; stosb
29059 jmp 7b
29060 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29061- movl $-EFAULT, (%ebx)
29062+ movl $-EFAULT, %ss:(%ebx)
29063 jmp 7b
29064 .previous
29065
29066+#ifdef CONFIG_PAX_MEMORY_UDEREF
29067+ pushl_cfi %ss
29068+ popl_cfi %ds
29069+ pushl_cfi %ss
29070+ popl_cfi %es
29071+#endif
29072+
29073 popl_cfi %esi
29074 CFI_RESTORE esi
29075 popl_cfi %edi
29076@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29077 CFI_RESTORE ebx
29078 ret
29079 CFI_ENDPROC
29080-ENDPROC(csum_partial_copy_generic)
29081+ENDPROC(csum_partial_copy_generic_to_user)
29082
29083 #undef ROUND
29084 #undef ROUND1
29085diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29086index f2145cf..cea889d 100644
29087--- a/arch/x86/lib/clear_page_64.S
29088+++ b/arch/x86/lib/clear_page_64.S
29089@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29090 movl $4096/8,%ecx
29091 xorl %eax,%eax
29092 rep stosq
29093+ pax_force_retaddr
29094 ret
29095 CFI_ENDPROC
29096 ENDPROC(clear_page_c)
29097@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29098 movl $4096,%ecx
29099 xorl %eax,%eax
29100 rep stosb
29101+ pax_force_retaddr
29102 ret
29103 CFI_ENDPROC
29104 ENDPROC(clear_page_c_e)
29105@@ -43,6 +45,7 @@ ENTRY(clear_page)
29106 leaq 64(%rdi),%rdi
29107 jnz .Lloop
29108 nop
29109+ pax_force_retaddr
29110 ret
29111 CFI_ENDPROC
29112 .Lclear_page_end:
29113@@ -58,7 +61,7 @@ ENDPROC(clear_page)
29114
29115 #include <asm/cpufeature.h>
29116
29117- .section .altinstr_replacement,"ax"
29118+ .section .altinstr_replacement,"a"
29119 1: .byte 0xeb /* jmp <disp8> */
29120 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29121 2: .byte 0xeb /* jmp <disp8> */
29122diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29123index 1e572c5..2a162cd 100644
29124--- a/arch/x86/lib/cmpxchg16b_emu.S
29125+++ b/arch/x86/lib/cmpxchg16b_emu.S
29126@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29127
29128 popf
29129 mov $1, %al
29130+ pax_force_retaddr
29131 ret
29132
29133 not_same:
29134 popf
29135 xor %al,%al
29136+ pax_force_retaddr
29137 ret
29138
29139 CFI_ENDPROC
29140diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29141index 176cca6..e0d658e 100644
29142--- a/arch/x86/lib/copy_page_64.S
29143+++ b/arch/x86/lib/copy_page_64.S
29144@@ -9,6 +9,7 @@ copy_page_rep:
29145 CFI_STARTPROC
29146 movl $4096/8, %ecx
29147 rep movsq
29148+ pax_force_retaddr
29149 ret
29150 CFI_ENDPROC
29151 ENDPROC(copy_page_rep)
29152@@ -24,8 +25,8 @@ ENTRY(copy_page)
29153 CFI_ADJUST_CFA_OFFSET 2*8
29154 movq %rbx, (%rsp)
29155 CFI_REL_OFFSET rbx, 0
29156- movq %r12, 1*8(%rsp)
29157- CFI_REL_OFFSET r12, 1*8
29158+ movq %r13, 1*8(%rsp)
29159+ CFI_REL_OFFSET r13, 1*8
29160
29161 movl $(4096/64)-5, %ecx
29162 .p2align 4
29163@@ -38,7 +39,7 @@ ENTRY(copy_page)
29164 movq 0x8*4(%rsi), %r9
29165 movq 0x8*5(%rsi), %r10
29166 movq 0x8*6(%rsi), %r11
29167- movq 0x8*7(%rsi), %r12
29168+ movq 0x8*7(%rsi), %r13
29169
29170 prefetcht0 5*64(%rsi)
29171
29172@@ -49,7 +50,7 @@ ENTRY(copy_page)
29173 movq %r9, 0x8*4(%rdi)
29174 movq %r10, 0x8*5(%rdi)
29175 movq %r11, 0x8*6(%rdi)
29176- movq %r12, 0x8*7(%rdi)
29177+ movq %r13, 0x8*7(%rdi)
29178
29179 leaq 64 (%rsi), %rsi
29180 leaq 64 (%rdi), %rdi
29181@@ -68,7 +69,7 @@ ENTRY(copy_page)
29182 movq 0x8*4(%rsi), %r9
29183 movq 0x8*5(%rsi), %r10
29184 movq 0x8*6(%rsi), %r11
29185- movq 0x8*7(%rsi), %r12
29186+ movq 0x8*7(%rsi), %r13
29187
29188 movq %rax, 0x8*0(%rdi)
29189 movq %rbx, 0x8*1(%rdi)
29190@@ -77,7 +78,7 @@ ENTRY(copy_page)
29191 movq %r9, 0x8*4(%rdi)
29192 movq %r10, 0x8*5(%rdi)
29193 movq %r11, 0x8*6(%rdi)
29194- movq %r12, 0x8*7(%rdi)
29195+ movq %r13, 0x8*7(%rdi)
29196
29197 leaq 64(%rdi), %rdi
29198 leaq 64(%rsi), %rsi
29199@@ -85,10 +86,11 @@ ENTRY(copy_page)
29200
29201 movq (%rsp), %rbx
29202 CFI_RESTORE rbx
29203- movq 1*8(%rsp), %r12
29204- CFI_RESTORE r12
29205+ movq 1*8(%rsp), %r13
29206+ CFI_RESTORE r13
29207 addq $2*8, %rsp
29208 CFI_ADJUST_CFA_OFFSET -2*8
29209+ pax_force_retaddr
29210 ret
29211 .Lcopy_page_end:
29212 CFI_ENDPROC
29213@@ -99,7 +101,7 @@ ENDPROC(copy_page)
29214
29215 #include <asm/cpufeature.h>
29216
29217- .section .altinstr_replacement,"ax"
29218+ .section .altinstr_replacement,"a"
29219 1: .byte 0xeb /* jmp <disp8> */
29220 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29221 2:
29222diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29223index a30ca15..407412b 100644
29224--- a/arch/x86/lib/copy_user_64.S
29225+++ b/arch/x86/lib/copy_user_64.S
29226@@ -18,31 +18,7 @@
29227 #include <asm/alternative-asm.h>
29228 #include <asm/asm.h>
29229 #include <asm/smap.h>
29230-
29231-/*
29232- * By placing feature2 after feature1 in altinstructions section, we logically
29233- * implement:
29234- * If CPU has feature2, jmp to alt2 is used
29235- * else if CPU has feature1, jmp to alt1 is used
29236- * else jmp to orig is used.
29237- */
29238- .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29239-0:
29240- .byte 0xe9 /* 32bit jump */
29241- .long \orig-1f /* by default jump to orig */
29242-1:
29243- .section .altinstr_replacement,"ax"
29244-2: .byte 0xe9 /* near jump with 32bit immediate */
29245- .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29246-3: .byte 0xe9 /* near jump with 32bit immediate */
29247- .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29248- .previous
29249-
29250- .section .altinstructions,"a"
29251- altinstruction_entry 0b,2b,\feature1,5,5
29252- altinstruction_entry 0b,3b,\feature2,5,5
29253- .previous
29254- .endm
29255+#include <asm/pgtable.h>
29256
29257 .macro ALIGN_DESTINATION
29258 #ifdef FIX_ALIGNMENT
29259@@ -70,52 +46,6 @@
29260 #endif
29261 .endm
29262
29263-/* Standard copy_to_user with segment limit checking */
29264-ENTRY(_copy_to_user)
29265- CFI_STARTPROC
29266- GET_THREAD_INFO(%rax)
29267- movq %rdi,%rcx
29268- addq %rdx,%rcx
29269- jc bad_to_user
29270- cmpq TI_addr_limit(%rax),%rcx
29271- ja bad_to_user
29272- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29273- copy_user_generic_unrolled,copy_user_generic_string, \
29274- copy_user_enhanced_fast_string
29275- CFI_ENDPROC
29276-ENDPROC(_copy_to_user)
29277-
29278-/* Standard copy_from_user with segment limit checking */
29279-ENTRY(_copy_from_user)
29280- CFI_STARTPROC
29281- GET_THREAD_INFO(%rax)
29282- movq %rsi,%rcx
29283- addq %rdx,%rcx
29284- jc bad_from_user
29285- cmpq TI_addr_limit(%rax),%rcx
29286- ja bad_from_user
29287- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29288- copy_user_generic_unrolled,copy_user_generic_string, \
29289- copy_user_enhanced_fast_string
29290- CFI_ENDPROC
29291-ENDPROC(_copy_from_user)
29292-
29293- .section .fixup,"ax"
29294- /* must zero dest */
29295-ENTRY(bad_from_user)
29296-bad_from_user:
29297- CFI_STARTPROC
29298- movl %edx,%ecx
29299- xorl %eax,%eax
29300- rep
29301- stosb
29302-bad_to_user:
29303- movl %edx,%eax
29304- ret
29305- CFI_ENDPROC
29306-ENDPROC(bad_from_user)
29307- .previous
29308-
29309 /*
29310 * copy_user_generic_unrolled - memory copy with exception handling.
29311 * This version is for CPUs like P4 that don't have efficient micro
29312@@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29313 */
29314 ENTRY(copy_user_generic_unrolled)
29315 CFI_STARTPROC
29316+ ASM_PAX_OPEN_USERLAND
29317 ASM_STAC
29318 cmpl $8,%edx
29319 jb 20f /* less then 8 bytes, go to byte copy loop */
29320@@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29321 jnz 21b
29322 23: xor %eax,%eax
29323 ASM_CLAC
29324+ ASM_PAX_CLOSE_USERLAND
29325+ pax_force_retaddr
29326 ret
29327
29328 .section .fixup,"ax"
29329@@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29330 */
29331 ENTRY(copy_user_generic_string)
29332 CFI_STARTPROC
29333+ ASM_PAX_OPEN_USERLAND
29334 ASM_STAC
29335 andl %edx,%edx
29336 jz 4f
29337@@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
29338 movsb
29339 4: xorl %eax,%eax
29340 ASM_CLAC
29341+ ASM_PAX_CLOSE_USERLAND
29342+ pax_force_retaddr
29343 ret
29344
29345 .section .fixup,"ax"
29346@@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
29347 */
29348 ENTRY(copy_user_enhanced_fast_string)
29349 CFI_STARTPROC
29350+ ASM_PAX_OPEN_USERLAND
29351 ASM_STAC
29352 andl %edx,%edx
29353 jz 2f
29354@@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
29355 movsb
29356 2: xorl %eax,%eax
29357 ASM_CLAC
29358+ ASM_PAX_CLOSE_USERLAND
29359+ pax_force_retaddr
29360 ret
29361
29362 .section .fixup,"ax"
29363diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29364index 6a4f43c..c70fb52 100644
29365--- a/arch/x86/lib/copy_user_nocache_64.S
29366+++ b/arch/x86/lib/copy_user_nocache_64.S
29367@@ -8,6 +8,7 @@
29368
29369 #include <linux/linkage.h>
29370 #include <asm/dwarf2.h>
29371+#include <asm/alternative-asm.h>
29372
29373 #define FIX_ALIGNMENT 1
29374
29375@@ -16,6 +17,7 @@
29376 #include <asm/thread_info.h>
29377 #include <asm/asm.h>
29378 #include <asm/smap.h>
29379+#include <asm/pgtable.h>
29380
29381 .macro ALIGN_DESTINATION
29382 #ifdef FIX_ALIGNMENT
29383@@ -49,6 +51,16 @@
29384 */
29385 ENTRY(__copy_user_nocache)
29386 CFI_STARTPROC
29387+
29388+#ifdef CONFIG_PAX_MEMORY_UDEREF
29389+ mov pax_user_shadow_base,%rcx
29390+ cmp %rcx,%rsi
29391+ jae 1f
29392+ add %rcx,%rsi
29393+1:
29394+#endif
29395+
29396+ ASM_PAX_OPEN_USERLAND
29397 ASM_STAC
29398 cmpl $8,%edx
29399 jb 20f /* less then 8 bytes, go to byte copy loop */
29400@@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29401 jnz 21b
29402 23: xorl %eax,%eax
29403 ASM_CLAC
29404+ ASM_PAX_CLOSE_USERLAND
29405 sfence
29406+ pax_force_retaddr
29407 ret
29408
29409 .section .fixup,"ax"
29410diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29411index 2419d5f..fe52d0e 100644
29412--- a/arch/x86/lib/csum-copy_64.S
29413+++ b/arch/x86/lib/csum-copy_64.S
29414@@ -9,6 +9,7 @@
29415 #include <asm/dwarf2.h>
29416 #include <asm/errno.h>
29417 #include <asm/asm.h>
29418+#include <asm/alternative-asm.h>
29419
29420 /*
29421 * Checksum copy with exception handling.
29422@@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29423 CFI_ADJUST_CFA_OFFSET 7*8
29424 movq %rbx, 2*8(%rsp)
29425 CFI_REL_OFFSET rbx, 2*8
29426- movq %r12, 3*8(%rsp)
29427- CFI_REL_OFFSET r12, 3*8
29428+ movq %r15, 3*8(%rsp)
29429+ CFI_REL_OFFSET r15, 3*8
29430 movq %r14, 4*8(%rsp)
29431 CFI_REL_OFFSET r14, 4*8
29432 movq %r13, 5*8(%rsp)
29433@@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29434 movl %edx, %ecx
29435
29436 xorl %r9d, %r9d
29437- movq %rcx, %r12
29438+ movq %rcx, %r15
29439
29440- shrq $6, %r12
29441+ shrq $6, %r15
29442 jz .Lhandle_tail /* < 64 */
29443
29444 clc
29445
29446 /* main loop. clear in 64 byte blocks */
29447 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29448- /* r11: temp3, rdx: temp4, r12 loopcnt */
29449+ /* r11: temp3, rdx: temp4, r15 loopcnt */
29450 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29451 .p2align 4
29452 .Lloop:
29453@@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29454 adcq %r14, %rax
29455 adcq %r13, %rax
29456
29457- decl %r12d
29458+ decl %r15d
29459
29460 dest
29461 movq %rbx, (%rsi)
29462@@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29463 .Lende:
29464 movq 2*8(%rsp), %rbx
29465 CFI_RESTORE rbx
29466- movq 3*8(%rsp), %r12
29467- CFI_RESTORE r12
29468+ movq 3*8(%rsp), %r15
29469+ CFI_RESTORE r15
29470 movq 4*8(%rsp), %r14
29471 CFI_RESTORE r14
29472 movq 5*8(%rsp), %r13
29473@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29474 CFI_RESTORE rbp
29475 addq $7*8, %rsp
29476 CFI_ADJUST_CFA_OFFSET -7*8
29477+ pax_force_retaddr
29478 ret
29479 CFI_RESTORE_STATE
29480
29481diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29482index 7609e0e..b449b98 100644
29483--- a/arch/x86/lib/csum-wrappers_64.c
29484+++ b/arch/x86/lib/csum-wrappers_64.c
29485@@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29486 len -= 2;
29487 }
29488 }
29489+ pax_open_userland();
29490 stac();
29491- isum = csum_partial_copy_generic((__force const void *)src,
29492+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29493 dst, len, isum, errp, NULL);
29494 clac();
29495+ pax_close_userland();
29496 if (unlikely(*errp))
29497 goto out_err;
29498
29499@@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29500 }
29501
29502 *errp = 0;
29503+ pax_open_userland();
29504 stac();
29505- ret = csum_partial_copy_generic(src, (void __force *)dst,
29506+ ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29507 len, isum, NULL, errp);
29508 clac();
29509+ pax_close_userland();
29510 return ret;
29511 }
29512 EXPORT_SYMBOL(csum_partial_copy_to_user);
29513diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29514index a451235..1daa956 100644
29515--- a/arch/x86/lib/getuser.S
29516+++ b/arch/x86/lib/getuser.S
29517@@ -33,17 +33,40 @@
29518 #include <asm/thread_info.h>
29519 #include <asm/asm.h>
29520 #include <asm/smap.h>
29521+#include <asm/segment.h>
29522+#include <asm/pgtable.h>
29523+#include <asm/alternative-asm.h>
29524+
29525+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29526+#define __copyuser_seg gs;
29527+#else
29528+#define __copyuser_seg
29529+#endif
29530
29531 .text
29532 ENTRY(__get_user_1)
29533 CFI_STARTPROC
29534+
29535+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29536 GET_THREAD_INFO(%_ASM_DX)
29537 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29538 jae bad_get_user
29539 ASM_STAC
29540-1: movzbl (%_ASM_AX),%edx
29541+
29542+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29543+ mov pax_user_shadow_base,%_ASM_DX
29544+ cmp %_ASM_DX,%_ASM_AX
29545+ jae 1234f
29546+ add %_ASM_DX,%_ASM_AX
29547+1234:
29548+#endif
29549+
29550+#endif
29551+
29552+1: __copyuser_seg movzbl (%_ASM_AX),%edx
29553 xor %eax,%eax
29554 ASM_CLAC
29555+ pax_force_retaddr
29556 ret
29557 CFI_ENDPROC
29558 ENDPROC(__get_user_1)
29559@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29560 ENTRY(__get_user_2)
29561 CFI_STARTPROC
29562 add $1,%_ASM_AX
29563+
29564+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29565 jc bad_get_user
29566 GET_THREAD_INFO(%_ASM_DX)
29567 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29568 jae bad_get_user
29569 ASM_STAC
29570-2: movzwl -1(%_ASM_AX),%edx
29571+
29572+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29573+ mov pax_user_shadow_base,%_ASM_DX
29574+ cmp %_ASM_DX,%_ASM_AX
29575+ jae 1234f
29576+ add %_ASM_DX,%_ASM_AX
29577+1234:
29578+#endif
29579+
29580+#endif
29581+
29582+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29583 xor %eax,%eax
29584 ASM_CLAC
29585+ pax_force_retaddr
29586 ret
29587 CFI_ENDPROC
29588 ENDPROC(__get_user_2)
29589@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29590 ENTRY(__get_user_4)
29591 CFI_STARTPROC
29592 add $3,%_ASM_AX
29593+
29594+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29595 jc bad_get_user
29596 GET_THREAD_INFO(%_ASM_DX)
29597 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29598 jae bad_get_user
29599 ASM_STAC
29600-3: movl -3(%_ASM_AX),%edx
29601+
29602+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29603+ mov pax_user_shadow_base,%_ASM_DX
29604+ cmp %_ASM_DX,%_ASM_AX
29605+ jae 1234f
29606+ add %_ASM_DX,%_ASM_AX
29607+1234:
29608+#endif
29609+
29610+#endif
29611+
29612+3: __copyuser_seg movl -3(%_ASM_AX),%edx
29613 xor %eax,%eax
29614 ASM_CLAC
29615+ pax_force_retaddr
29616 ret
29617 CFI_ENDPROC
29618 ENDPROC(__get_user_4)
29619@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29620 GET_THREAD_INFO(%_ASM_DX)
29621 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29622 jae bad_get_user
29623+
29624+#ifdef CONFIG_PAX_MEMORY_UDEREF
29625+ mov pax_user_shadow_base,%_ASM_DX
29626+ cmp %_ASM_DX,%_ASM_AX
29627+ jae 1234f
29628+ add %_ASM_DX,%_ASM_AX
29629+1234:
29630+#endif
29631+
29632 ASM_STAC
29633 4: movq -7(%_ASM_AX),%rdx
29634 xor %eax,%eax
29635 ASM_CLAC
29636+ pax_force_retaddr
29637 ret
29638 #else
29639 add $7,%_ASM_AX
29640@@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29641 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29642 jae bad_get_user_8
29643 ASM_STAC
29644-4: movl -7(%_ASM_AX),%edx
29645-5: movl -3(%_ASM_AX),%ecx
29646+4: __copyuser_seg movl -7(%_ASM_AX),%edx
29647+5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29648 xor %eax,%eax
29649 ASM_CLAC
29650+ pax_force_retaddr
29651 ret
29652 #endif
29653 CFI_ENDPROC
29654@@ -113,6 +175,7 @@ bad_get_user:
29655 xor %edx,%edx
29656 mov $(-EFAULT),%_ASM_AX
29657 ASM_CLAC
29658+ pax_force_retaddr
29659 ret
29660 CFI_ENDPROC
29661 END(bad_get_user)
29662@@ -124,6 +187,7 @@ bad_get_user_8:
29663 xor %ecx,%ecx
29664 mov $(-EFAULT),%_ASM_AX
29665 ASM_CLAC
29666+ pax_force_retaddr
29667 ret
29668 CFI_ENDPROC
29669 END(bad_get_user_8)
29670diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29671index 54fcffe..7be149e 100644
29672--- a/arch/x86/lib/insn.c
29673+++ b/arch/x86/lib/insn.c
29674@@ -20,8 +20,10 @@
29675
29676 #ifdef __KERNEL__
29677 #include <linux/string.h>
29678+#include <asm/pgtable_types.h>
29679 #else
29680 #include <string.h>
29681+#define ktla_ktva(addr) addr
29682 #endif
29683 #include <asm/inat.h>
29684 #include <asm/insn.h>
29685@@ -53,8 +55,8 @@
29686 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29687 {
29688 memset(insn, 0, sizeof(*insn));
29689- insn->kaddr = kaddr;
29690- insn->next_byte = kaddr;
29691+ insn->kaddr = ktla_ktva(kaddr);
29692+ insn->next_byte = ktla_ktva(kaddr);
29693 insn->x86_64 = x86_64 ? 1 : 0;
29694 insn->opnd_bytes = 4;
29695 if (x86_64)
29696diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29697index 05a95e7..326f2fa 100644
29698--- a/arch/x86/lib/iomap_copy_64.S
29699+++ b/arch/x86/lib/iomap_copy_64.S
29700@@ -17,6 +17,7 @@
29701
29702 #include <linux/linkage.h>
29703 #include <asm/dwarf2.h>
29704+#include <asm/alternative-asm.h>
29705
29706 /*
29707 * override generic version in lib/iomap_copy.c
29708@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29709 CFI_STARTPROC
29710 movl %edx,%ecx
29711 rep movsd
29712+ pax_force_retaddr
29713 ret
29714 CFI_ENDPROC
29715 ENDPROC(__iowrite32_copy)
29716diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29717index 56313a3..0db417e 100644
29718--- a/arch/x86/lib/memcpy_64.S
29719+++ b/arch/x86/lib/memcpy_64.S
29720@@ -24,7 +24,7 @@
29721 * This gets patched over the unrolled variant (below) via the
29722 * alternative instructions framework:
29723 */
29724- .section .altinstr_replacement, "ax", @progbits
29725+ .section .altinstr_replacement, "a", @progbits
29726 .Lmemcpy_c:
29727 movq %rdi, %rax
29728 movq %rdx, %rcx
29729@@ -33,6 +33,7 @@
29730 rep movsq
29731 movl %edx, %ecx
29732 rep movsb
29733+ pax_force_retaddr
29734 ret
29735 .Lmemcpy_e:
29736 .previous
29737@@ -44,11 +45,12 @@
29738 * This gets patched over the unrolled variant (below) via the
29739 * alternative instructions framework:
29740 */
29741- .section .altinstr_replacement, "ax", @progbits
29742+ .section .altinstr_replacement, "a", @progbits
29743 .Lmemcpy_c_e:
29744 movq %rdi, %rax
29745 movq %rdx, %rcx
29746 rep movsb
29747+ pax_force_retaddr
29748 ret
29749 .Lmemcpy_e_e:
29750 .previous
29751@@ -136,6 +138,7 @@ ENTRY(memcpy)
29752 movq %r9, 1*8(%rdi)
29753 movq %r10, -2*8(%rdi, %rdx)
29754 movq %r11, -1*8(%rdi, %rdx)
29755+ pax_force_retaddr
29756 retq
29757 .p2align 4
29758 .Lless_16bytes:
29759@@ -148,6 +151,7 @@ ENTRY(memcpy)
29760 movq -1*8(%rsi, %rdx), %r9
29761 movq %r8, 0*8(%rdi)
29762 movq %r9, -1*8(%rdi, %rdx)
29763+ pax_force_retaddr
29764 retq
29765 .p2align 4
29766 .Lless_8bytes:
29767@@ -161,6 +165,7 @@ ENTRY(memcpy)
29768 movl -4(%rsi, %rdx), %r8d
29769 movl %ecx, (%rdi)
29770 movl %r8d, -4(%rdi, %rdx)
29771+ pax_force_retaddr
29772 retq
29773 .p2align 4
29774 .Lless_3bytes:
29775@@ -179,6 +184,7 @@ ENTRY(memcpy)
29776 movb %cl, (%rdi)
29777
29778 .Lend:
29779+ pax_force_retaddr
29780 retq
29781 CFI_ENDPROC
29782 ENDPROC(memcpy)
29783diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29784index 65268a6..dd1de11 100644
29785--- a/arch/x86/lib/memmove_64.S
29786+++ b/arch/x86/lib/memmove_64.S
29787@@ -202,14 +202,16 @@ ENTRY(memmove)
29788 movb (%rsi), %r11b
29789 movb %r11b, (%rdi)
29790 13:
29791+ pax_force_retaddr
29792 retq
29793 CFI_ENDPROC
29794
29795- .section .altinstr_replacement,"ax"
29796+ .section .altinstr_replacement,"a"
29797 .Lmemmove_begin_forward_efs:
29798 /* Forward moving data. */
29799 movq %rdx, %rcx
29800 rep movsb
29801+ pax_force_retaddr
29802 retq
29803 .Lmemmove_end_forward_efs:
29804 .previous
29805diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29806index 2dcb380..2eb79fe 100644
29807--- a/arch/x86/lib/memset_64.S
29808+++ b/arch/x86/lib/memset_64.S
29809@@ -16,7 +16,7 @@
29810 *
29811 * rax original destination
29812 */
29813- .section .altinstr_replacement, "ax", @progbits
29814+ .section .altinstr_replacement, "a", @progbits
29815 .Lmemset_c:
29816 movq %rdi,%r9
29817 movq %rdx,%rcx
29818@@ -30,6 +30,7 @@
29819 movl %edx,%ecx
29820 rep stosb
29821 movq %r9,%rax
29822+ pax_force_retaddr
29823 ret
29824 .Lmemset_e:
29825 .previous
29826@@ -45,13 +46,14 @@
29827 *
29828 * rax original destination
29829 */
29830- .section .altinstr_replacement, "ax", @progbits
29831+ .section .altinstr_replacement, "a", @progbits
29832 .Lmemset_c_e:
29833 movq %rdi,%r9
29834 movb %sil,%al
29835 movq %rdx,%rcx
29836 rep stosb
29837 movq %r9,%rax
29838+ pax_force_retaddr
29839 ret
29840 .Lmemset_e_e:
29841 .previous
29842@@ -118,6 +120,7 @@ ENTRY(__memset)
29843
29844 .Lende:
29845 movq %r10,%rax
29846+ pax_force_retaddr
29847 ret
29848
29849 CFI_RESTORE_STATE
29850diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29851index c9f2d9b..e7fd2c0 100644
29852--- a/arch/x86/lib/mmx_32.c
29853+++ b/arch/x86/lib/mmx_32.c
29854@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29855 {
29856 void *p;
29857 int i;
29858+ unsigned long cr0;
29859
29860 if (unlikely(in_interrupt()))
29861 return __memcpy(to, from, len);
29862@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29863 kernel_fpu_begin();
29864
29865 __asm__ __volatile__ (
29866- "1: prefetch (%0)\n" /* This set is 28 bytes */
29867- " prefetch 64(%0)\n"
29868- " prefetch 128(%0)\n"
29869- " prefetch 192(%0)\n"
29870- " prefetch 256(%0)\n"
29871+ "1: prefetch (%1)\n" /* This set is 28 bytes */
29872+ " prefetch 64(%1)\n"
29873+ " prefetch 128(%1)\n"
29874+ " prefetch 192(%1)\n"
29875+ " prefetch 256(%1)\n"
29876 "2: \n"
29877 ".section .fixup, \"ax\"\n"
29878- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29879+ "3: \n"
29880+
29881+#ifdef CONFIG_PAX_KERNEXEC
29882+ " movl %%cr0, %0\n"
29883+ " movl %0, %%eax\n"
29884+ " andl $0xFFFEFFFF, %%eax\n"
29885+ " movl %%eax, %%cr0\n"
29886+#endif
29887+
29888+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29889+
29890+#ifdef CONFIG_PAX_KERNEXEC
29891+ " movl %0, %%cr0\n"
29892+#endif
29893+
29894 " jmp 2b\n"
29895 ".previous\n"
29896 _ASM_EXTABLE(1b, 3b)
29897- : : "r" (from));
29898+ : "=&r" (cr0) : "r" (from) : "ax");
29899
29900 for ( ; i > 5; i--) {
29901 __asm__ __volatile__ (
29902- "1: prefetch 320(%0)\n"
29903- "2: movq (%0), %%mm0\n"
29904- " movq 8(%0), %%mm1\n"
29905- " movq 16(%0), %%mm2\n"
29906- " movq 24(%0), %%mm3\n"
29907- " movq %%mm0, (%1)\n"
29908- " movq %%mm1, 8(%1)\n"
29909- " movq %%mm2, 16(%1)\n"
29910- " movq %%mm3, 24(%1)\n"
29911- " movq 32(%0), %%mm0\n"
29912- " movq 40(%0), %%mm1\n"
29913- " movq 48(%0), %%mm2\n"
29914- " movq 56(%0), %%mm3\n"
29915- " movq %%mm0, 32(%1)\n"
29916- " movq %%mm1, 40(%1)\n"
29917- " movq %%mm2, 48(%1)\n"
29918- " movq %%mm3, 56(%1)\n"
29919+ "1: prefetch 320(%1)\n"
29920+ "2: movq (%1), %%mm0\n"
29921+ " movq 8(%1), %%mm1\n"
29922+ " movq 16(%1), %%mm2\n"
29923+ " movq 24(%1), %%mm3\n"
29924+ " movq %%mm0, (%2)\n"
29925+ " movq %%mm1, 8(%2)\n"
29926+ " movq %%mm2, 16(%2)\n"
29927+ " movq %%mm3, 24(%2)\n"
29928+ " movq 32(%1), %%mm0\n"
29929+ " movq 40(%1), %%mm1\n"
29930+ " movq 48(%1), %%mm2\n"
29931+ " movq 56(%1), %%mm3\n"
29932+ " movq %%mm0, 32(%2)\n"
29933+ " movq %%mm1, 40(%2)\n"
29934+ " movq %%mm2, 48(%2)\n"
29935+ " movq %%mm3, 56(%2)\n"
29936 ".section .fixup, \"ax\"\n"
29937- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29938+ "3:\n"
29939+
29940+#ifdef CONFIG_PAX_KERNEXEC
29941+ " movl %%cr0, %0\n"
29942+ " movl %0, %%eax\n"
29943+ " andl $0xFFFEFFFF, %%eax\n"
29944+ " movl %%eax, %%cr0\n"
29945+#endif
29946+
29947+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29948+
29949+#ifdef CONFIG_PAX_KERNEXEC
29950+ " movl %0, %%cr0\n"
29951+#endif
29952+
29953 " jmp 2b\n"
29954 ".previous\n"
29955 _ASM_EXTABLE(1b, 3b)
29956- : : "r" (from), "r" (to) : "memory");
29957+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29958
29959 from += 64;
29960 to += 64;
29961@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29962 static void fast_copy_page(void *to, void *from)
29963 {
29964 int i;
29965+ unsigned long cr0;
29966
29967 kernel_fpu_begin();
29968
29969@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29970 * but that is for later. -AV
29971 */
29972 __asm__ __volatile__(
29973- "1: prefetch (%0)\n"
29974- " prefetch 64(%0)\n"
29975- " prefetch 128(%0)\n"
29976- " prefetch 192(%0)\n"
29977- " prefetch 256(%0)\n"
29978+ "1: prefetch (%1)\n"
29979+ " prefetch 64(%1)\n"
29980+ " prefetch 128(%1)\n"
29981+ " prefetch 192(%1)\n"
29982+ " prefetch 256(%1)\n"
29983 "2: \n"
29984 ".section .fixup, \"ax\"\n"
29985- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29986+ "3: \n"
29987+
29988+#ifdef CONFIG_PAX_KERNEXEC
29989+ " movl %%cr0, %0\n"
29990+ " movl %0, %%eax\n"
29991+ " andl $0xFFFEFFFF, %%eax\n"
29992+ " movl %%eax, %%cr0\n"
29993+#endif
29994+
29995+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29996+
29997+#ifdef CONFIG_PAX_KERNEXEC
29998+ " movl %0, %%cr0\n"
29999+#endif
30000+
30001 " jmp 2b\n"
30002 ".previous\n"
30003- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30004+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30005
30006 for (i = 0; i < (4096-320)/64; i++) {
30007 __asm__ __volatile__ (
30008- "1: prefetch 320(%0)\n"
30009- "2: movq (%0), %%mm0\n"
30010- " movntq %%mm0, (%1)\n"
30011- " movq 8(%0), %%mm1\n"
30012- " movntq %%mm1, 8(%1)\n"
30013- " movq 16(%0), %%mm2\n"
30014- " movntq %%mm2, 16(%1)\n"
30015- " movq 24(%0), %%mm3\n"
30016- " movntq %%mm3, 24(%1)\n"
30017- " movq 32(%0), %%mm4\n"
30018- " movntq %%mm4, 32(%1)\n"
30019- " movq 40(%0), %%mm5\n"
30020- " movntq %%mm5, 40(%1)\n"
30021- " movq 48(%0), %%mm6\n"
30022- " movntq %%mm6, 48(%1)\n"
30023- " movq 56(%0), %%mm7\n"
30024- " movntq %%mm7, 56(%1)\n"
30025+ "1: prefetch 320(%1)\n"
30026+ "2: movq (%1), %%mm0\n"
30027+ " movntq %%mm0, (%2)\n"
30028+ " movq 8(%1), %%mm1\n"
30029+ " movntq %%mm1, 8(%2)\n"
30030+ " movq 16(%1), %%mm2\n"
30031+ " movntq %%mm2, 16(%2)\n"
30032+ " movq 24(%1), %%mm3\n"
30033+ " movntq %%mm3, 24(%2)\n"
30034+ " movq 32(%1), %%mm4\n"
30035+ " movntq %%mm4, 32(%2)\n"
30036+ " movq 40(%1), %%mm5\n"
30037+ " movntq %%mm5, 40(%2)\n"
30038+ " movq 48(%1), %%mm6\n"
30039+ " movntq %%mm6, 48(%2)\n"
30040+ " movq 56(%1), %%mm7\n"
30041+ " movntq %%mm7, 56(%2)\n"
30042 ".section .fixup, \"ax\"\n"
30043- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30044+ "3:\n"
30045+
30046+#ifdef CONFIG_PAX_KERNEXEC
30047+ " movl %%cr0, %0\n"
30048+ " movl %0, %%eax\n"
30049+ " andl $0xFFFEFFFF, %%eax\n"
30050+ " movl %%eax, %%cr0\n"
30051+#endif
30052+
30053+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30054+
30055+#ifdef CONFIG_PAX_KERNEXEC
30056+ " movl %0, %%cr0\n"
30057+#endif
30058+
30059 " jmp 2b\n"
30060 ".previous\n"
30061- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30062+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30063
30064 from += 64;
30065 to += 64;
30066@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30067 static void fast_copy_page(void *to, void *from)
30068 {
30069 int i;
30070+ unsigned long cr0;
30071
30072 kernel_fpu_begin();
30073
30074 __asm__ __volatile__ (
30075- "1: prefetch (%0)\n"
30076- " prefetch 64(%0)\n"
30077- " prefetch 128(%0)\n"
30078- " prefetch 192(%0)\n"
30079- " prefetch 256(%0)\n"
30080+ "1: prefetch (%1)\n"
30081+ " prefetch 64(%1)\n"
30082+ " prefetch 128(%1)\n"
30083+ " prefetch 192(%1)\n"
30084+ " prefetch 256(%1)\n"
30085 "2: \n"
30086 ".section .fixup, \"ax\"\n"
30087- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30088+ "3: \n"
30089+
30090+#ifdef CONFIG_PAX_KERNEXEC
30091+ " movl %%cr0, %0\n"
30092+ " movl %0, %%eax\n"
30093+ " andl $0xFFFEFFFF, %%eax\n"
30094+ " movl %%eax, %%cr0\n"
30095+#endif
30096+
30097+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30098+
30099+#ifdef CONFIG_PAX_KERNEXEC
30100+ " movl %0, %%cr0\n"
30101+#endif
30102+
30103 " jmp 2b\n"
30104 ".previous\n"
30105- _ASM_EXTABLE(1b, 3b) : : "r" (from));
30106+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30107
30108 for (i = 0; i < 4096/64; i++) {
30109 __asm__ __volatile__ (
30110- "1: prefetch 320(%0)\n"
30111- "2: movq (%0), %%mm0\n"
30112- " movq 8(%0), %%mm1\n"
30113- " movq 16(%0), %%mm2\n"
30114- " movq 24(%0), %%mm3\n"
30115- " movq %%mm0, (%1)\n"
30116- " movq %%mm1, 8(%1)\n"
30117- " movq %%mm2, 16(%1)\n"
30118- " movq %%mm3, 24(%1)\n"
30119- " movq 32(%0), %%mm0\n"
30120- " movq 40(%0), %%mm1\n"
30121- " movq 48(%0), %%mm2\n"
30122- " movq 56(%0), %%mm3\n"
30123- " movq %%mm0, 32(%1)\n"
30124- " movq %%mm1, 40(%1)\n"
30125- " movq %%mm2, 48(%1)\n"
30126- " movq %%mm3, 56(%1)\n"
30127+ "1: prefetch 320(%1)\n"
30128+ "2: movq (%1), %%mm0\n"
30129+ " movq 8(%1), %%mm1\n"
30130+ " movq 16(%1), %%mm2\n"
30131+ " movq 24(%1), %%mm3\n"
30132+ " movq %%mm0, (%2)\n"
30133+ " movq %%mm1, 8(%2)\n"
30134+ " movq %%mm2, 16(%2)\n"
30135+ " movq %%mm3, 24(%2)\n"
30136+ " movq 32(%1), %%mm0\n"
30137+ " movq 40(%1), %%mm1\n"
30138+ " movq 48(%1), %%mm2\n"
30139+ " movq 56(%1), %%mm3\n"
30140+ " movq %%mm0, 32(%2)\n"
30141+ " movq %%mm1, 40(%2)\n"
30142+ " movq %%mm2, 48(%2)\n"
30143+ " movq %%mm3, 56(%2)\n"
30144 ".section .fixup, \"ax\"\n"
30145- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30146+ "3:\n"
30147+
30148+#ifdef CONFIG_PAX_KERNEXEC
30149+ " movl %%cr0, %0\n"
30150+ " movl %0, %%eax\n"
30151+ " andl $0xFFFEFFFF, %%eax\n"
30152+ " movl %%eax, %%cr0\n"
30153+#endif
30154+
30155+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30156+
30157+#ifdef CONFIG_PAX_KERNEXEC
30158+ " movl %0, %%cr0\n"
30159+#endif
30160+
30161 " jmp 2b\n"
30162 ".previous\n"
30163 _ASM_EXTABLE(1b, 3b)
30164- : : "r" (from), "r" (to) : "memory");
30165+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30166
30167 from += 64;
30168 to += 64;
30169diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30170index f6d13ee..d789440 100644
30171--- a/arch/x86/lib/msr-reg.S
30172+++ b/arch/x86/lib/msr-reg.S
30173@@ -3,6 +3,7 @@
30174 #include <asm/dwarf2.h>
30175 #include <asm/asm.h>
30176 #include <asm/msr.h>
30177+#include <asm/alternative-asm.h>
30178
30179 #ifdef CONFIG_X86_64
30180 /*
30181@@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30182 movl %edi, 28(%r10)
30183 popq_cfi %rbp
30184 popq_cfi %rbx
30185+ pax_force_retaddr
30186 ret
30187 3:
30188 CFI_RESTORE_STATE
30189diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30190index fc6ba17..d4d989d 100644
30191--- a/arch/x86/lib/putuser.S
30192+++ b/arch/x86/lib/putuser.S
30193@@ -16,7 +16,9 @@
30194 #include <asm/errno.h>
30195 #include <asm/asm.h>
30196 #include <asm/smap.h>
30197-
30198+#include <asm/segment.h>
30199+#include <asm/pgtable.h>
30200+#include <asm/alternative-asm.h>
30201
30202 /*
30203 * __put_user_X
30204@@ -30,57 +32,125 @@
30205 * as they get called from within inline assembly.
30206 */
30207
30208-#define ENTER CFI_STARTPROC ; \
30209- GET_THREAD_INFO(%_ASM_BX)
30210-#define EXIT ASM_CLAC ; \
30211- ret ; \
30212+#define ENTER CFI_STARTPROC
30213+#define EXIT ASM_CLAC ; \
30214+ pax_force_retaddr ; \
30215+ ret ; \
30216 CFI_ENDPROC
30217
30218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30219+#define _DEST %_ASM_CX,%_ASM_BX
30220+#else
30221+#define _DEST %_ASM_CX
30222+#endif
30223+
30224+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30225+#define __copyuser_seg gs;
30226+#else
30227+#define __copyuser_seg
30228+#endif
30229+
30230 .text
30231 ENTRY(__put_user_1)
30232 ENTER
30233+
30234+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30235+ GET_THREAD_INFO(%_ASM_BX)
30236 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30237 jae bad_put_user
30238 ASM_STAC
30239-1: movb %al,(%_ASM_CX)
30240+
30241+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30242+ mov pax_user_shadow_base,%_ASM_BX
30243+ cmp %_ASM_BX,%_ASM_CX
30244+ jb 1234f
30245+ xor %ebx,%ebx
30246+1234:
30247+#endif
30248+
30249+#endif
30250+
30251+1: __copyuser_seg movb %al,(_DEST)
30252 xor %eax,%eax
30253 EXIT
30254 ENDPROC(__put_user_1)
30255
30256 ENTRY(__put_user_2)
30257 ENTER
30258+
30259+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30260+ GET_THREAD_INFO(%_ASM_BX)
30261 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30262 sub $1,%_ASM_BX
30263 cmp %_ASM_BX,%_ASM_CX
30264 jae bad_put_user
30265 ASM_STAC
30266-2: movw %ax,(%_ASM_CX)
30267+
30268+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30269+ mov pax_user_shadow_base,%_ASM_BX
30270+ cmp %_ASM_BX,%_ASM_CX
30271+ jb 1234f
30272+ xor %ebx,%ebx
30273+1234:
30274+#endif
30275+
30276+#endif
30277+
30278+2: __copyuser_seg movw %ax,(_DEST)
30279 xor %eax,%eax
30280 EXIT
30281 ENDPROC(__put_user_2)
30282
30283 ENTRY(__put_user_4)
30284 ENTER
30285+
30286+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30287+ GET_THREAD_INFO(%_ASM_BX)
30288 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30289 sub $3,%_ASM_BX
30290 cmp %_ASM_BX,%_ASM_CX
30291 jae bad_put_user
30292 ASM_STAC
30293-3: movl %eax,(%_ASM_CX)
30294+
30295+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30296+ mov pax_user_shadow_base,%_ASM_BX
30297+ cmp %_ASM_BX,%_ASM_CX
30298+ jb 1234f
30299+ xor %ebx,%ebx
30300+1234:
30301+#endif
30302+
30303+#endif
30304+
30305+3: __copyuser_seg movl %eax,(_DEST)
30306 xor %eax,%eax
30307 EXIT
30308 ENDPROC(__put_user_4)
30309
30310 ENTRY(__put_user_8)
30311 ENTER
30312+
30313+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30314+ GET_THREAD_INFO(%_ASM_BX)
30315 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30316 sub $7,%_ASM_BX
30317 cmp %_ASM_BX,%_ASM_CX
30318 jae bad_put_user
30319 ASM_STAC
30320-4: mov %_ASM_AX,(%_ASM_CX)
30321+
30322+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30323+ mov pax_user_shadow_base,%_ASM_BX
30324+ cmp %_ASM_BX,%_ASM_CX
30325+ jb 1234f
30326+ xor %ebx,%ebx
30327+1234:
30328+#endif
30329+
30330+#endif
30331+
30332+4: __copyuser_seg mov %_ASM_AX,(_DEST)
30333 #ifdef CONFIG_X86_32
30334-5: movl %edx,4(%_ASM_CX)
30335+5: __copyuser_seg movl %edx,4(_DEST)
30336 #endif
30337 xor %eax,%eax
30338 EXIT
30339diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30340index 1cad221..de671ee 100644
30341--- a/arch/x86/lib/rwlock.S
30342+++ b/arch/x86/lib/rwlock.S
30343@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30344 FRAME
30345 0: LOCK_PREFIX
30346 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30347+
30348+#ifdef CONFIG_PAX_REFCOUNT
30349+ jno 1234f
30350+ LOCK_PREFIX
30351+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30352+ int $4
30353+1234:
30354+ _ASM_EXTABLE(1234b, 1234b)
30355+#endif
30356+
30357 1: rep; nop
30358 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30359 jne 1b
30360 LOCK_PREFIX
30361 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30362+
30363+#ifdef CONFIG_PAX_REFCOUNT
30364+ jno 1234f
30365+ LOCK_PREFIX
30366+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30367+ int $4
30368+1234:
30369+ _ASM_EXTABLE(1234b, 1234b)
30370+#endif
30371+
30372 jnz 0b
30373 ENDFRAME
30374+ pax_force_retaddr
30375 ret
30376 CFI_ENDPROC
30377 END(__write_lock_failed)
30378@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30379 FRAME
30380 0: LOCK_PREFIX
30381 READ_LOCK_SIZE(inc) (%__lock_ptr)
30382+
30383+#ifdef CONFIG_PAX_REFCOUNT
30384+ jno 1234f
30385+ LOCK_PREFIX
30386+ READ_LOCK_SIZE(dec) (%__lock_ptr)
30387+ int $4
30388+1234:
30389+ _ASM_EXTABLE(1234b, 1234b)
30390+#endif
30391+
30392 1: rep; nop
30393 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30394 js 1b
30395 LOCK_PREFIX
30396 READ_LOCK_SIZE(dec) (%__lock_ptr)
30397+
30398+#ifdef CONFIG_PAX_REFCOUNT
30399+ jno 1234f
30400+ LOCK_PREFIX
30401+ READ_LOCK_SIZE(inc) (%__lock_ptr)
30402+ int $4
30403+1234:
30404+ _ASM_EXTABLE(1234b, 1234b)
30405+#endif
30406+
30407 js 0b
30408 ENDFRAME
30409+ pax_force_retaddr
30410 ret
30411 CFI_ENDPROC
30412 END(__read_lock_failed)
30413diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30414index 5dff5f0..cadebf4 100644
30415--- a/arch/x86/lib/rwsem.S
30416+++ b/arch/x86/lib/rwsem.S
30417@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30418 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30419 CFI_RESTORE __ASM_REG(dx)
30420 restore_common_regs
30421+ pax_force_retaddr
30422 ret
30423 CFI_ENDPROC
30424 ENDPROC(call_rwsem_down_read_failed)
30425@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30426 movq %rax,%rdi
30427 call rwsem_down_write_failed
30428 restore_common_regs
30429+ pax_force_retaddr
30430 ret
30431 CFI_ENDPROC
30432 ENDPROC(call_rwsem_down_write_failed)
30433@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30434 movq %rax,%rdi
30435 call rwsem_wake
30436 restore_common_regs
30437-1: ret
30438+1: pax_force_retaddr
30439+ ret
30440 CFI_ENDPROC
30441 ENDPROC(call_rwsem_wake)
30442
30443@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30444 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30445 CFI_RESTORE __ASM_REG(dx)
30446 restore_common_regs
30447+ pax_force_retaddr
30448 ret
30449 CFI_ENDPROC
30450 ENDPROC(call_rwsem_downgrade_wake)
30451diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30452index a63efd6..8149fbe 100644
30453--- a/arch/x86/lib/thunk_64.S
30454+++ b/arch/x86/lib/thunk_64.S
30455@@ -8,6 +8,7 @@
30456 #include <linux/linkage.h>
30457 #include <asm/dwarf2.h>
30458 #include <asm/calling.h>
30459+#include <asm/alternative-asm.h>
30460
30461 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30462 .macro THUNK name, func, put_ret_addr_in_rdi=0
30463@@ -15,11 +16,11 @@
30464 \name:
30465 CFI_STARTPROC
30466
30467- /* this one pushes 9 elems, the next one would be %rIP */
30468- SAVE_ARGS
30469+ /* this one pushes 15+1 elems, the next one would be %rIP */
30470+ SAVE_ARGS 8
30471
30472 .if \put_ret_addr_in_rdi
30473- movq_cfi_restore 9*8, rdi
30474+ movq_cfi_restore RIP, rdi
30475 .endif
30476
30477 call \func
30478@@ -38,8 +39,9 @@
30479
30480 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30481 CFI_STARTPROC
30482- SAVE_ARGS
30483+ SAVE_ARGS 8
30484 restore:
30485- RESTORE_ARGS
30486+ RESTORE_ARGS 1,8
30487+ pax_force_retaddr
30488 ret
30489 CFI_ENDPROC
30490diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30491index e2f5e21..4b22130 100644
30492--- a/arch/x86/lib/usercopy_32.c
30493+++ b/arch/x86/lib/usercopy_32.c
30494@@ -42,11 +42,13 @@ do { \
30495 int __d0; \
30496 might_fault(); \
30497 __asm__ __volatile__( \
30498+ __COPYUSER_SET_ES \
30499 ASM_STAC "\n" \
30500 "0: rep; stosl\n" \
30501 " movl %2,%0\n" \
30502 "1: rep; stosb\n" \
30503 "2: " ASM_CLAC "\n" \
30504+ __COPYUSER_RESTORE_ES \
30505 ".section .fixup,\"ax\"\n" \
30506 "3: lea 0(%2,%0,4),%0\n" \
30507 " jmp 2b\n" \
30508@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30509
30510 #ifdef CONFIG_X86_INTEL_USERCOPY
30511 static unsigned long
30512-__copy_user_intel(void __user *to, const void *from, unsigned long size)
30513+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30514 {
30515 int d0, d1;
30516 __asm__ __volatile__(
30517@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30518 " .align 2,0x90\n"
30519 "3: movl 0(%4), %%eax\n"
30520 "4: movl 4(%4), %%edx\n"
30521- "5: movl %%eax, 0(%3)\n"
30522- "6: movl %%edx, 4(%3)\n"
30523+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30524+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30525 "7: movl 8(%4), %%eax\n"
30526 "8: movl 12(%4),%%edx\n"
30527- "9: movl %%eax, 8(%3)\n"
30528- "10: movl %%edx, 12(%3)\n"
30529+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30530+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30531 "11: movl 16(%4), %%eax\n"
30532 "12: movl 20(%4), %%edx\n"
30533- "13: movl %%eax, 16(%3)\n"
30534- "14: movl %%edx, 20(%3)\n"
30535+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30536+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30537 "15: movl 24(%4), %%eax\n"
30538 "16: movl 28(%4), %%edx\n"
30539- "17: movl %%eax, 24(%3)\n"
30540- "18: movl %%edx, 28(%3)\n"
30541+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30542+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30543 "19: movl 32(%4), %%eax\n"
30544 "20: movl 36(%4), %%edx\n"
30545- "21: movl %%eax, 32(%3)\n"
30546- "22: movl %%edx, 36(%3)\n"
30547+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30548+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30549 "23: movl 40(%4), %%eax\n"
30550 "24: movl 44(%4), %%edx\n"
30551- "25: movl %%eax, 40(%3)\n"
30552- "26: movl %%edx, 44(%3)\n"
30553+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30554+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30555 "27: movl 48(%4), %%eax\n"
30556 "28: movl 52(%4), %%edx\n"
30557- "29: movl %%eax, 48(%3)\n"
30558- "30: movl %%edx, 52(%3)\n"
30559+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30560+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30561 "31: movl 56(%4), %%eax\n"
30562 "32: movl 60(%4), %%edx\n"
30563- "33: movl %%eax, 56(%3)\n"
30564- "34: movl %%edx, 60(%3)\n"
30565+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30566+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30567 " addl $-64, %0\n"
30568 " addl $64, %4\n"
30569 " addl $64, %3\n"
30570@@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30571 " shrl $2, %0\n"
30572 " andl $3, %%eax\n"
30573 " cld\n"
30574+ __COPYUSER_SET_ES
30575 "99: rep; movsl\n"
30576 "36: movl %%eax, %0\n"
30577 "37: rep; movsb\n"
30578 "100:\n"
30579+ __COPYUSER_RESTORE_ES
30580+ ".section .fixup,\"ax\"\n"
30581+ "101: lea 0(%%eax,%0,4),%0\n"
30582+ " jmp 100b\n"
30583+ ".previous\n"
30584+ _ASM_EXTABLE(1b,100b)
30585+ _ASM_EXTABLE(2b,100b)
30586+ _ASM_EXTABLE(3b,100b)
30587+ _ASM_EXTABLE(4b,100b)
30588+ _ASM_EXTABLE(5b,100b)
30589+ _ASM_EXTABLE(6b,100b)
30590+ _ASM_EXTABLE(7b,100b)
30591+ _ASM_EXTABLE(8b,100b)
30592+ _ASM_EXTABLE(9b,100b)
30593+ _ASM_EXTABLE(10b,100b)
30594+ _ASM_EXTABLE(11b,100b)
30595+ _ASM_EXTABLE(12b,100b)
30596+ _ASM_EXTABLE(13b,100b)
30597+ _ASM_EXTABLE(14b,100b)
30598+ _ASM_EXTABLE(15b,100b)
30599+ _ASM_EXTABLE(16b,100b)
30600+ _ASM_EXTABLE(17b,100b)
30601+ _ASM_EXTABLE(18b,100b)
30602+ _ASM_EXTABLE(19b,100b)
30603+ _ASM_EXTABLE(20b,100b)
30604+ _ASM_EXTABLE(21b,100b)
30605+ _ASM_EXTABLE(22b,100b)
30606+ _ASM_EXTABLE(23b,100b)
30607+ _ASM_EXTABLE(24b,100b)
30608+ _ASM_EXTABLE(25b,100b)
30609+ _ASM_EXTABLE(26b,100b)
30610+ _ASM_EXTABLE(27b,100b)
30611+ _ASM_EXTABLE(28b,100b)
30612+ _ASM_EXTABLE(29b,100b)
30613+ _ASM_EXTABLE(30b,100b)
30614+ _ASM_EXTABLE(31b,100b)
30615+ _ASM_EXTABLE(32b,100b)
30616+ _ASM_EXTABLE(33b,100b)
30617+ _ASM_EXTABLE(34b,100b)
30618+ _ASM_EXTABLE(35b,100b)
30619+ _ASM_EXTABLE(36b,100b)
30620+ _ASM_EXTABLE(37b,100b)
30621+ _ASM_EXTABLE(99b,101b)
30622+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
30623+ : "1"(to), "2"(from), "0"(size)
30624+ : "eax", "edx", "memory");
30625+ return size;
30626+}
30627+
30628+static unsigned long
30629+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30630+{
30631+ int d0, d1;
30632+ __asm__ __volatile__(
30633+ " .align 2,0x90\n"
30634+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30635+ " cmpl $67, %0\n"
30636+ " jbe 3f\n"
30637+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30638+ " .align 2,0x90\n"
30639+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30640+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30641+ "5: movl %%eax, 0(%3)\n"
30642+ "6: movl %%edx, 4(%3)\n"
30643+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30644+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30645+ "9: movl %%eax, 8(%3)\n"
30646+ "10: movl %%edx, 12(%3)\n"
30647+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30648+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30649+ "13: movl %%eax, 16(%3)\n"
30650+ "14: movl %%edx, 20(%3)\n"
30651+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30652+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30653+ "17: movl %%eax, 24(%3)\n"
30654+ "18: movl %%edx, 28(%3)\n"
30655+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30656+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30657+ "21: movl %%eax, 32(%3)\n"
30658+ "22: movl %%edx, 36(%3)\n"
30659+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30660+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30661+ "25: movl %%eax, 40(%3)\n"
30662+ "26: movl %%edx, 44(%3)\n"
30663+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30664+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30665+ "29: movl %%eax, 48(%3)\n"
30666+ "30: movl %%edx, 52(%3)\n"
30667+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30668+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30669+ "33: movl %%eax, 56(%3)\n"
30670+ "34: movl %%edx, 60(%3)\n"
30671+ " addl $-64, %0\n"
30672+ " addl $64, %4\n"
30673+ " addl $64, %3\n"
30674+ " cmpl $63, %0\n"
30675+ " ja 1b\n"
30676+ "35: movl %0, %%eax\n"
30677+ " shrl $2, %0\n"
30678+ " andl $3, %%eax\n"
30679+ " cld\n"
30680+ "99: rep; "__copyuser_seg" movsl\n"
30681+ "36: movl %%eax, %0\n"
30682+ "37: rep; "__copyuser_seg" movsb\n"
30683+ "100:\n"
30684 ".section .fixup,\"ax\"\n"
30685 "101: lea 0(%%eax,%0,4),%0\n"
30686 " jmp 100b\n"
30687@@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30688 int d0, d1;
30689 __asm__ __volatile__(
30690 " .align 2,0x90\n"
30691- "0: movl 32(%4), %%eax\n"
30692+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30693 " cmpl $67, %0\n"
30694 " jbe 2f\n"
30695- "1: movl 64(%4), %%eax\n"
30696+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30697 " .align 2,0x90\n"
30698- "2: movl 0(%4), %%eax\n"
30699- "21: movl 4(%4), %%edx\n"
30700+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30701+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30702 " movl %%eax, 0(%3)\n"
30703 " movl %%edx, 4(%3)\n"
30704- "3: movl 8(%4), %%eax\n"
30705- "31: movl 12(%4),%%edx\n"
30706+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30707+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30708 " movl %%eax, 8(%3)\n"
30709 " movl %%edx, 12(%3)\n"
30710- "4: movl 16(%4), %%eax\n"
30711- "41: movl 20(%4), %%edx\n"
30712+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30713+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30714 " movl %%eax, 16(%3)\n"
30715 " movl %%edx, 20(%3)\n"
30716- "10: movl 24(%4), %%eax\n"
30717- "51: movl 28(%4), %%edx\n"
30718+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30719+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30720 " movl %%eax, 24(%3)\n"
30721 " movl %%edx, 28(%3)\n"
30722- "11: movl 32(%4), %%eax\n"
30723- "61: movl 36(%4), %%edx\n"
30724+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30725+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30726 " movl %%eax, 32(%3)\n"
30727 " movl %%edx, 36(%3)\n"
30728- "12: movl 40(%4), %%eax\n"
30729- "71: movl 44(%4), %%edx\n"
30730+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30731+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30732 " movl %%eax, 40(%3)\n"
30733 " movl %%edx, 44(%3)\n"
30734- "13: movl 48(%4), %%eax\n"
30735- "81: movl 52(%4), %%edx\n"
30736+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30737+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30738 " movl %%eax, 48(%3)\n"
30739 " movl %%edx, 52(%3)\n"
30740- "14: movl 56(%4), %%eax\n"
30741- "91: movl 60(%4), %%edx\n"
30742+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30743+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30744 " movl %%eax, 56(%3)\n"
30745 " movl %%edx, 60(%3)\n"
30746 " addl $-64, %0\n"
30747@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30748 " shrl $2, %0\n"
30749 " andl $3, %%eax\n"
30750 " cld\n"
30751- "6: rep; movsl\n"
30752+ "6: rep; "__copyuser_seg" movsl\n"
30753 " movl %%eax,%0\n"
30754- "7: rep; movsb\n"
30755+ "7: rep; "__copyuser_seg" movsb\n"
30756 "8:\n"
30757 ".section .fixup,\"ax\"\n"
30758 "9: lea 0(%%eax,%0,4),%0\n"
30759@@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30760
30761 __asm__ __volatile__(
30762 " .align 2,0x90\n"
30763- "0: movl 32(%4), %%eax\n"
30764+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30765 " cmpl $67, %0\n"
30766 " jbe 2f\n"
30767- "1: movl 64(%4), %%eax\n"
30768+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30769 " .align 2,0x90\n"
30770- "2: movl 0(%4), %%eax\n"
30771- "21: movl 4(%4), %%edx\n"
30772+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30773+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30774 " movnti %%eax, 0(%3)\n"
30775 " movnti %%edx, 4(%3)\n"
30776- "3: movl 8(%4), %%eax\n"
30777- "31: movl 12(%4),%%edx\n"
30778+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30779+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30780 " movnti %%eax, 8(%3)\n"
30781 " movnti %%edx, 12(%3)\n"
30782- "4: movl 16(%4), %%eax\n"
30783- "41: movl 20(%4), %%edx\n"
30784+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30785+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30786 " movnti %%eax, 16(%3)\n"
30787 " movnti %%edx, 20(%3)\n"
30788- "10: movl 24(%4), %%eax\n"
30789- "51: movl 28(%4), %%edx\n"
30790+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30791+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30792 " movnti %%eax, 24(%3)\n"
30793 " movnti %%edx, 28(%3)\n"
30794- "11: movl 32(%4), %%eax\n"
30795- "61: movl 36(%4), %%edx\n"
30796+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30797+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30798 " movnti %%eax, 32(%3)\n"
30799 " movnti %%edx, 36(%3)\n"
30800- "12: movl 40(%4), %%eax\n"
30801- "71: movl 44(%4), %%edx\n"
30802+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30803+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30804 " movnti %%eax, 40(%3)\n"
30805 " movnti %%edx, 44(%3)\n"
30806- "13: movl 48(%4), %%eax\n"
30807- "81: movl 52(%4), %%edx\n"
30808+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30809+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30810 " movnti %%eax, 48(%3)\n"
30811 " movnti %%edx, 52(%3)\n"
30812- "14: movl 56(%4), %%eax\n"
30813- "91: movl 60(%4), %%edx\n"
30814+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30815+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30816 " movnti %%eax, 56(%3)\n"
30817 " movnti %%edx, 60(%3)\n"
30818 " addl $-64, %0\n"
30819@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30820 " shrl $2, %0\n"
30821 " andl $3, %%eax\n"
30822 " cld\n"
30823- "6: rep; movsl\n"
30824+ "6: rep; "__copyuser_seg" movsl\n"
30825 " movl %%eax,%0\n"
30826- "7: rep; movsb\n"
30827+ "7: rep; "__copyuser_seg" movsb\n"
30828 "8:\n"
30829 ".section .fixup,\"ax\"\n"
30830 "9: lea 0(%%eax,%0,4),%0\n"
30831@@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30832
30833 __asm__ __volatile__(
30834 " .align 2,0x90\n"
30835- "0: movl 32(%4), %%eax\n"
30836+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30837 " cmpl $67, %0\n"
30838 " jbe 2f\n"
30839- "1: movl 64(%4), %%eax\n"
30840+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30841 " .align 2,0x90\n"
30842- "2: movl 0(%4), %%eax\n"
30843- "21: movl 4(%4), %%edx\n"
30844+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30845+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30846 " movnti %%eax, 0(%3)\n"
30847 " movnti %%edx, 4(%3)\n"
30848- "3: movl 8(%4), %%eax\n"
30849- "31: movl 12(%4),%%edx\n"
30850+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30851+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30852 " movnti %%eax, 8(%3)\n"
30853 " movnti %%edx, 12(%3)\n"
30854- "4: movl 16(%4), %%eax\n"
30855- "41: movl 20(%4), %%edx\n"
30856+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30857+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30858 " movnti %%eax, 16(%3)\n"
30859 " movnti %%edx, 20(%3)\n"
30860- "10: movl 24(%4), %%eax\n"
30861- "51: movl 28(%4), %%edx\n"
30862+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30863+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30864 " movnti %%eax, 24(%3)\n"
30865 " movnti %%edx, 28(%3)\n"
30866- "11: movl 32(%4), %%eax\n"
30867- "61: movl 36(%4), %%edx\n"
30868+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30869+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30870 " movnti %%eax, 32(%3)\n"
30871 " movnti %%edx, 36(%3)\n"
30872- "12: movl 40(%4), %%eax\n"
30873- "71: movl 44(%4), %%edx\n"
30874+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30875+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30876 " movnti %%eax, 40(%3)\n"
30877 " movnti %%edx, 44(%3)\n"
30878- "13: movl 48(%4), %%eax\n"
30879- "81: movl 52(%4), %%edx\n"
30880+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30881+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30882 " movnti %%eax, 48(%3)\n"
30883 " movnti %%edx, 52(%3)\n"
30884- "14: movl 56(%4), %%eax\n"
30885- "91: movl 60(%4), %%edx\n"
30886+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30887+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30888 " movnti %%eax, 56(%3)\n"
30889 " movnti %%edx, 60(%3)\n"
30890 " addl $-64, %0\n"
30891@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30892 " shrl $2, %0\n"
30893 " andl $3, %%eax\n"
30894 " cld\n"
30895- "6: rep; movsl\n"
30896+ "6: rep; "__copyuser_seg" movsl\n"
30897 " movl %%eax,%0\n"
30898- "7: rep; movsb\n"
30899+ "7: rep; "__copyuser_seg" movsb\n"
30900 "8:\n"
30901 ".section .fixup,\"ax\"\n"
30902 "9: lea 0(%%eax,%0,4),%0\n"
30903@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30904 */
30905 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30906 unsigned long size);
30907-unsigned long __copy_user_intel(void __user *to, const void *from,
30908+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30909+ unsigned long size);
30910+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30911 unsigned long size);
30912 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30913 const void __user *from, unsigned long size);
30914 #endif /* CONFIG_X86_INTEL_USERCOPY */
30915
30916 /* Generic arbitrary sized copy. */
30917-#define __copy_user(to, from, size) \
30918+#define __copy_user(to, from, size, prefix, set, restore) \
30919 do { \
30920 int __d0, __d1, __d2; \
30921 __asm__ __volatile__( \
30922+ set \
30923 " cmp $7,%0\n" \
30924 " jbe 1f\n" \
30925 " movl %1,%0\n" \
30926 " negl %0\n" \
30927 " andl $7,%0\n" \
30928 " subl %0,%3\n" \
30929- "4: rep; movsb\n" \
30930+ "4: rep; "prefix"movsb\n" \
30931 " movl %3,%0\n" \
30932 " shrl $2,%0\n" \
30933 " andl $3,%3\n" \
30934 " .align 2,0x90\n" \
30935- "0: rep; movsl\n" \
30936+ "0: rep; "prefix"movsl\n" \
30937 " movl %3,%0\n" \
30938- "1: rep; movsb\n" \
30939+ "1: rep; "prefix"movsb\n" \
30940 "2:\n" \
30941+ restore \
30942 ".section .fixup,\"ax\"\n" \
30943 "5: addl %3,%0\n" \
30944 " jmp 2b\n" \
30945@@ -538,14 +650,14 @@ do { \
30946 " negl %0\n" \
30947 " andl $7,%0\n" \
30948 " subl %0,%3\n" \
30949- "4: rep; movsb\n" \
30950+ "4: rep; "__copyuser_seg"movsb\n" \
30951 " movl %3,%0\n" \
30952 " shrl $2,%0\n" \
30953 " andl $3,%3\n" \
30954 " .align 2,0x90\n" \
30955- "0: rep; movsl\n" \
30956+ "0: rep; "__copyuser_seg"movsl\n" \
30957 " movl %3,%0\n" \
30958- "1: rep; movsb\n" \
30959+ "1: rep; "__copyuser_seg"movsb\n" \
30960 "2:\n" \
30961 ".section .fixup,\"ax\"\n" \
30962 "5: addl %3,%0\n" \
30963@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30964 {
30965 stac();
30966 if (movsl_is_ok(to, from, n))
30967- __copy_user(to, from, n);
30968+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30969 else
30970- n = __copy_user_intel(to, from, n);
30971+ n = __generic_copy_to_user_intel(to, from, n);
30972 clac();
30973 return n;
30974 }
30975@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30976 {
30977 stac();
30978 if (movsl_is_ok(to, from, n))
30979- __copy_user(to, from, n);
30980+ __copy_user(to, from, n, __copyuser_seg, "", "");
30981 else
30982- n = __copy_user_intel((void __user *)to,
30983- (const void *)from, n);
30984+ n = __generic_copy_from_user_intel(to, from, n);
30985 clac();
30986 return n;
30987 }
30988@@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30989 if (n > 64 && cpu_has_xmm2)
30990 n = __copy_user_intel_nocache(to, from, n);
30991 else
30992- __copy_user(to, from, n);
30993+ __copy_user(to, from, n, __copyuser_seg, "", "");
30994 #else
30995- __copy_user(to, from, n);
30996+ __copy_user(to, from, n, __copyuser_seg, "", "");
30997 #endif
30998 clac();
30999 return n;
31000 }
31001 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31002
31003-/**
31004- * copy_to_user: - Copy a block of data into user space.
31005- * @to: Destination address, in user space.
31006- * @from: Source address, in kernel space.
31007- * @n: Number of bytes to copy.
31008- *
31009- * Context: User context only. This function may sleep.
31010- *
31011- * Copy data from kernel space to user space.
31012- *
31013- * Returns number of bytes that could not be copied.
31014- * On success, this will be zero.
31015- */
31016-unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31017+#ifdef CONFIG_PAX_MEMORY_UDEREF
31018+void __set_fs(mm_segment_t x)
31019 {
31020- if (access_ok(VERIFY_WRITE, to, n))
31021- n = __copy_to_user(to, from, n);
31022- return n;
31023+ switch (x.seg) {
31024+ case 0:
31025+ loadsegment(gs, 0);
31026+ break;
31027+ case TASK_SIZE_MAX:
31028+ loadsegment(gs, __USER_DS);
31029+ break;
31030+ case -1UL:
31031+ loadsegment(gs, __KERNEL_DS);
31032+ break;
31033+ default:
31034+ BUG();
31035+ }
31036 }
31037-EXPORT_SYMBOL(_copy_to_user);
31038+EXPORT_SYMBOL(__set_fs);
31039
31040-/**
31041- * copy_from_user: - Copy a block of data from user space.
31042- * @to: Destination address, in kernel space.
31043- * @from: Source address, in user space.
31044- * @n: Number of bytes to copy.
31045- *
31046- * Context: User context only. This function may sleep.
31047- *
31048- * Copy data from user space to kernel space.
31049- *
31050- * Returns number of bytes that could not be copied.
31051- * On success, this will be zero.
31052- *
31053- * If some data could not be copied, this function will pad the copied
31054- * data to the requested size using zero bytes.
31055- */
31056-unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31057+void set_fs(mm_segment_t x)
31058 {
31059- if (access_ok(VERIFY_READ, from, n))
31060- n = __copy_from_user(to, from, n);
31061- else
31062- memset(to, 0, n);
31063- return n;
31064+ current_thread_info()->addr_limit = x;
31065+ __set_fs(x);
31066 }
31067-EXPORT_SYMBOL(_copy_from_user);
31068+EXPORT_SYMBOL(set_fs);
31069+#endif
31070diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31071index c905e89..01ab928 100644
31072--- a/arch/x86/lib/usercopy_64.c
31073+++ b/arch/x86/lib/usercopy_64.c
31074@@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31075 might_fault();
31076 /* no memory constraint because it doesn't change any memory gcc knows
31077 about */
31078+ pax_open_userland();
31079 stac();
31080 asm volatile(
31081 " testq %[size8],%[size8]\n"
31082@@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31083 _ASM_EXTABLE(0b,3b)
31084 _ASM_EXTABLE(1b,2b)
31085 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31086- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31087+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31088 [zero] "r" (0UL), [eight] "r" (8UL));
31089 clac();
31090+ pax_close_userland();
31091 return size;
31092 }
31093 EXPORT_SYMBOL(__clear_user);
31094@@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31095 }
31096 EXPORT_SYMBOL(clear_user);
31097
31098-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31099+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31100 {
31101- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31102- return copy_user_generic((__force void *)to, (__force void *)from, len);
31103- }
31104- return len;
31105+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31106+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31107+ return len;
31108 }
31109 EXPORT_SYMBOL(copy_in_user);
31110
31111@@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31112 * it is not necessary to optimize tail handling.
31113 */
31114 __visible unsigned long
31115-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31116+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31117 {
31118 char c;
31119 unsigned zero_len;
31120
31121+ clac();
31122+ pax_close_userland();
31123 for (; len; --len, to++) {
31124 if (__get_user_nocheck(c, from++, sizeof(char)))
31125 break;
31126@@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31127 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31128 if (__put_user_nocheck(c, to++, sizeof(char)))
31129 break;
31130- clac();
31131 return len;
31132 }
31133diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31134index 6a19ad9..1c48f9a 100644
31135--- a/arch/x86/mm/Makefile
31136+++ b/arch/x86/mm/Makefile
31137@@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31138 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31139
31140 obj-$(CONFIG_MEMTEST) += memtest.o
31141+
31142+quote:="
31143+obj-$(CONFIG_X86_64) += uderef_64.o
31144+CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31145diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31146index 903ec1e..c4166b2 100644
31147--- a/arch/x86/mm/extable.c
31148+++ b/arch/x86/mm/extable.c
31149@@ -6,12 +6,24 @@
31150 static inline unsigned long
31151 ex_insn_addr(const struct exception_table_entry *x)
31152 {
31153- return (unsigned long)&x->insn + x->insn;
31154+ unsigned long reloc = 0;
31155+
31156+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31157+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31158+#endif
31159+
31160+ return (unsigned long)&x->insn + x->insn + reloc;
31161 }
31162 static inline unsigned long
31163 ex_fixup_addr(const struct exception_table_entry *x)
31164 {
31165- return (unsigned long)&x->fixup + x->fixup;
31166+ unsigned long reloc = 0;
31167+
31168+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31169+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31170+#endif
31171+
31172+ return (unsigned long)&x->fixup + x->fixup + reloc;
31173 }
31174
31175 int fixup_exception(struct pt_regs *regs)
31176@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31177 unsigned long new_ip;
31178
31179 #ifdef CONFIG_PNPBIOS
31180- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31181+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31182 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31183 extern u32 pnp_bios_is_utter_crap;
31184 pnp_bios_is_utter_crap = 1;
31185@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31186 i += 4;
31187 p->fixup -= i;
31188 i += 4;
31189+
31190+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31191+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31192+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31193+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31194+#endif
31195+
31196 }
31197 }
31198
31199diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31200index 6dea040..31e52ff 100644
31201--- a/arch/x86/mm/fault.c
31202+++ b/arch/x86/mm/fault.c
31203@@ -14,11 +14,18 @@
31204 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31205 #include <linux/prefetch.h> /* prefetchw */
31206 #include <linux/context_tracking.h> /* exception_enter(), ... */
31207+#include <linux/unistd.h>
31208+#include <linux/compiler.h>
31209
31210 #include <asm/traps.h> /* dotraplinkage, ... */
31211 #include <asm/pgalloc.h> /* pgd_*(), ... */
31212 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31213 #include <asm/fixmap.h> /* VSYSCALL_START */
31214+#include <asm/tlbflush.h>
31215+
31216+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31217+#include <asm/stacktrace.h>
31218+#endif
31219
31220 #define CREATE_TRACE_POINTS
31221 #include <asm/trace/exceptions.h>
31222@@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31223 int ret = 0;
31224
31225 /* kprobe_running() needs smp_processor_id() */
31226- if (kprobes_built_in() && !user_mode_vm(regs)) {
31227+ if (kprobes_built_in() && !user_mode(regs)) {
31228 preempt_disable();
31229 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31230 ret = 1;
31231@@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31232 return !instr_lo || (instr_lo>>1) == 1;
31233 case 0x00:
31234 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31235- if (probe_kernel_address(instr, opcode))
31236+ if (user_mode(regs)) {
31237+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31238+ return 0;
31239+ } else if (probe_kernel_address(instr, opcode))
31240 return 0;
31241
31242 *prefetch = (instr_lo == 0xF) &&
31243@@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31244 while (instr < max_instr) {
31245 unsigned char opcode;
31246
31247- if (probe_kernel_address(instr, opcode))
31248+ if (user_mode(regs)) {
31249+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31250+ break;
31251+ } else if (probe_kernel_address(instr, opcode))
31252 break;
31253
31254 instr++;
31255@@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31256 force_sig_info(si_signo, &info, tsk);
31257 }
31258
31259+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31260+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31261+#endif
31262+
31263+#ifdef CONFIG_PAX_EMUTRAMP
31264+static int pax_handle_fetch_fault(struct pt_regs *regs);
31265+#endif
31266+
31267+#ifdef CONFIG_PAX_PAGEEXEC
31268+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31269+{
31270+ pgd_t *pgd;
31271+ pud_t *pud;
31272+ pmd_t *pmd;
31273+
31274+ pgd = pgd_offset(mm, address);
31275+ if (!pgd_present(*pgd))
31276+ return NULL;
31277+ pud = pud_offset(pgd, address);
31278+ if (!pud_present(*pud))
31279+ return NULL;
31280+ pmd = pmd_offset(pud, address);
31281+ if (!pmd_present(*pmd))
31282+ return NULL;
31283+ return pmd;
31284+}
31285+#endif
31286+
31287 DEFINE_SPINLOCK(pgd_lock);
31288 LIST_HEAD(pgd_list);
31289
31290@@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31291 for (address = VMALLOC_START & PMD_MASK;
31292 address >= TASK_SIZE && address < FIXADDR_TOP;
31293 address += PMD_SIZE) {
31294+
31295+#ifdef CONFIG_PAX_PER_CPU_PGD
31296+ unsigned long cpu;
31297+#else
31298 struct page *page;
31299+#endif
31300
31301 spin_lock(&pgd_lock);
31302+
31303+#ifdef CONFIG_PAX_PER_CPU_PGD
31304+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31305+ pgd_t *pgd = get_cpu_pgd(cpu, user);
31306+ pmd_t *ret;
31307+
31308+ ret = vmalloc_sync_one(pgd, address);
31309+ if (!ret)
31310+ break;
31311+ pgd = get_cpu_pgd(cpu, kernel);
31312+#else
31313 list_for_each_entry(page, &pgd_list, lru) {
31314+ pgd_t *pgd;
31315 spinlock_t *pgt_lock;
31316 pmd_t *ret;
31317
31318@@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31319 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31320
31321 spin_lock(pgt_lock);
31322- ret = vmalloc_sync_one(page_address(page), address);
31323+ pgd = page_address(page);
31324+#endif
31325+
31326+ ret = vmalloc_sync_one(pgd, address);
31327+
31328+#ifndef CONFIG_PAX_PER_CPU_PGD
31329 spin_unlock(pgt_lock);
31330+#endif
31331
31332 if (!ret)
31333 break;
31334@@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31335 * an interrupt in the middle of a task switch..
31336 */
31337 pgd_paddr = read_cr3();
31338+
31339+#ifdef CONFIG_PAX_PER_CPU_PGD
31340+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31341+ vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31342+#endif
31343+
31344 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31345 if (!pmd_k)
31346 return -1;
31347@@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31348 * happen within a race in page table update. In the later
31349 * case just flush:
31350 */
31351- pgd = pgd_offset(current->active_mm, address);
31352+
31353 pgd_ref = pgd_offset_k(address);
31354 if (pgd_none(*pgd_ref))
31355 return -1;
31356
31357+#ifdef CONFIG_PAX_PER_CPU_PGD
31358+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31359+ pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31360+ if (pgd_none(*pgd)) {
31361+ set_pgd(pgd, *pgd_ref);
31362+ arch_flush_lazy_mmu_mode();
31363+ } else {
31364+ BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31365+ }
31366+ pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31367+#else
31368+ pgd = pgd_offset(current->active_mm, address);
31369+#endif
31370+
31371 if (pgd_none(*pgd)) {
31372 set_pgd(pgd, *pgd_ref);
31373 arch_flush_lazy_mmu_mode();
31374@@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31375 static int is_errata100(struct pt_regs *regs, unsigned long address)
31376 {
31377 #ifdef CONFIG_X86_64
31378- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31379+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31380 return 1;
31381 #endif
31382 return 0;
31383@@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31384 }
31385
31386 static const char nx_warning[] = KERN_CRIT
31387-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31388+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31389
31390 static void
31391 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31392@@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31393 if (!oops_may_print())
31394 return;
31395
31396- if (error_code & PF_INSTR) {
31397+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31398 unsigned int level;
31399
31400 pte_t *pte = lookup_address(address, &level);
31401
31402 if (pte && pte_present(*pte) && !pte_exec(*pte))
31403- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31404+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31405 }
31406
31407+#ifdef CONFIG_PAX_KERNEXEC
31408+ if (init_mm.start_code <= address && address < init_mm.end_code) {
31409+ if (current->signal->curr_ip)
31410+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31411+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
31412+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31413+ else
31414+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31415+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31416+ }
31417+#endif
31418+
31419 printk(KERN_ALERT "BUG: unable to handle kernel ");
31420 if (address < PAGE_SIZE)
31421 printk(KERN_CONT "NULL pointer dereference");
31422@@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31423 return;
31424 }
31425 #endif
31426+
31427+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31428+ if (pax_is_fetch_fault(regs, error_code, address)) {
31429+
31430+#ifdef CONFIG_PAX_EMUTRAMP
31431+ switch (pax_handle_fetch_fault(regs)) {
31432+ case 2:
31433+ return;
31434+ }
31435+#endif
31436+
31437+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31438+ do_group_exit(SIGKILL);
31439+ }
31440+#endif
31441+
31442 /* Kernel addresses are always protection faults: */
31443 if (address >= TASK_SIZE)
31444 error_code |= PF_PROT;
31445@@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31446 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31447 printk(KERN_ERR
31448 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31449- tsk->comm, tsk->pid, address);
31450+ tsk->comm, task_pid_nr(tsk), address);
31451 code = BUS_MCEERR_AR;
31452 }
31453 #endif
31454@@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31455 return 1;
31456 }
31457
31458+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31459+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31460+{
31461+ pte_t *pte;
31462+ pmd_t *pmd;
31463+ spinlock_t *ptl;
31464+ unsigned char pte_mask;
31465+
31466+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31467+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
31468+ return 0;
31469+
31470+ /* PaX: it's our fault, let's handle it if we can */
31471+
31472+ /* PaX: take a look at read faults before acquiring any locks */
31473+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31474+ /* instruction fetch attempt from a protected page in user mode */
31475+ up_read(&mm->mmap_sem);
31476+
31477+#ifdef CONFIG_PAX_EMUTRAMP
31478+ switch (pax_handle_fetch_fault(regs)) {
31479+ case 2:
31480+ return 1;
31481+ }
31482+#endif
31483+
31484+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31485+ do_group_exit(SIGKILL);
31486+ }
31487+
31488+ pmd = pax_get_pmd(mm, address);
31489+ if (unlikely(!pmd))
31490+ return 0;
31491+
31492+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31493+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31494+ pte_unmap_unlock(pte, ptl);
31495+ return 0;
31496+ }
31497+
31498+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31499+ /* write attempt to a protected page in user mode */
31500+ pte_unmap_unlock(pte, ptl);
31501+ return 0;
31502+ }
31503+
31504+#ifdef CONFIG_SMP
31505+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31506+#else
31507+ if (likely(address > get_limit(regs->cs)))
31508+#endif
31509+ {
31510+ set_pte(pte, pte_mkread(*pte));
31511+ __flush_tlb_one(address);
31512+ pte_unmap_unlock(pte, ptl);
31513+ up_read(&mm->mmap_sem);
31514+ return 1;
31515+ }
31516+
31517+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31518+
31519+ /*
31520+ * PaX: fill DTLB with user rights and retry
31521+ */
31522+ __asm__ __volatile__ (
31523+ "orb %2,(%1)\n"
31524+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31525+/*
31526+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31527+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31528+ * page fault when examined during a TLB load attempt. this is true not only
31529+ * for PTEs holding a non-present entry but also present entries that will
31530+ * raise a page fault (such as those set up by PaX, or the copy-on-write
31531+ * mechanism). in effect it means that we do *not* need to flush the TLBs
31532+ * for our target pages since their PTEs are simply not in the TLBs at all.
31533+
31534+ * the best thing in omitting it is that we gain around 15-20% speed in the
31535+ * fast path of the page fault handler and can get rid of tracing since we
31536+ * can no longer flush unintended entries.
31537+ */
31538+ "invlpg (%0)\n"
31539+#endif
31540+ __copyuser_seg"testb $0,(%0)\n"
31541+ "xorb %3,(%1)\n"
31542+ :
31543+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31544+ : "memory", "cc");
31545+ pte_unmap_unlock(pte, ptl);
31546+ up_read(&mm->mmap_sem);
31547+ return 1;
31548+}
31549+#endif
31550+
31551 /*
31552 * Handle a spurious fault caused by a stale TLB entry.
31553 *
31554@@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31555 static inline int
31556 access_error(unsigned long error_code, struct vm_area_struct *vma)
31557 {
31558+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31559+ return 1;
31560+
31561 if (error_code & PF_WRITE) {
31562 /* write, present and write, not present: */
31563 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31564@@ -1010,7 +1218,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31565 if (error_code & PF_USER)
31566 return false;
31567
31568- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31569+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31570 return false;
31571
31572 return true;
31573@@ -1037,6 +1245,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31574 /* Get the faulting address: */
31575 address = read_cr2();
31576
31577+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31578+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31579+ if (!search_exception_tables(regs->ip)) {
31580+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31581+ bad_area_nosemaphore(regs, error_code, address);
31582+ return;
31583+ }
31584+ if (address < pax_user_shadow_base) {
31585+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31586+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31587+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31588+ } else
31589+ address -= pax_user_shadow_base;
31590+ }
31591+#endif
31592+
31593 /*
31594 * Detect and handle instructions that would cause a page fault for
31595 * both a tracked kernel page and a userspace page.
31596@@ -1114,7 +1338,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31597 * User-mode registers count as a user access even for any
31598 * potential system fault or CPU buglet:
31599 */
31600- if (user_mode_vm(regs)) {
31601+ if (user_mode(regs)) {
31602 local_irq_enable();
31603 error_code |= PF_USER;
31604 flags |= FAULT_FLAG_USER;
31605@@ -1161,6 +1385,11 @@ retry:
31606 might_sleep();
31607 }
31608
31609+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31610+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31611+ return;
31612+#endif
31613+
31614 vma = find_vma(mm, address);
31615 if (unlikely(!vma)) {
31616 bad_area(regs, error_code, address);
31617@@ -1172,18 +1401,24 @@ retry:
31618 bad_area(regs, error_code, address);
31619 return;
31620 }
31621- if (error_code & PF_USER) {
31622- /*
31623- * Accessing the stack below %sp is always a bug.
31624- * The large cushion allows instructions like enter
31625- * and pusha to work. ("enter $65535, $31" pushes
31626- * 32 pointers and then decrements %sp by 65535.)
31627- */
31628- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31629- bad_area(regs, error_code, address);
31630- return;
31631- }
31632+ /*
31633+ * Accessing the stack below %sp is always a bug.
31634+ * The large cushion allows instructions like enter
31635+ * and pusha to work. ("enter $65535, $31" pushes
31636+ * 32 pointers and then decrements %sp by 65535.)
31637+ */
31638+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31639+ bad_area(regs, error_code, address);
31640+ return;
31641 }
31642+
31643+#ifdef CONFIG_PAX_SEGMEXEC
31644+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31645+ bad_area(regs, error_code, address);
31646+ return;
31647+ }
31648+#endif
31649+
31650 if (unlikely(expand_stack(vma, address))) {
31651 bad_area(regs, error_code, address);
31652 return;
31653@@ -1277,3 +1512,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31654 __do_page_fault(regs, error_code);
31655 exception_exit(prev_state);
31656 }
31657+
31658+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31659+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31660+{
31661+ struct mm_struct *mm = current->mm;
31662+ unsigned long ip = regs->ip;
31663+
31664+ if (v8086_mode(regs))
31665+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31666+
31667+#ifdef CONFIG_PAX_PAGEEXEC
31668+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31669+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31670+ return true;
31671+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31672+ return true;
31673+ return false;
31674+ }
31675+#endif
31676+
31677+#ifdef CONFIG_PAX_SEGMEXEC
31678+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31679+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31680+ return true;
31681+ return false;
31682+ }
31683+#endif
31684+
31685+ return false;
31686+}
31687+#endif
31688+
31689+#ifdef CONFIG_PAX_EMUTRAMP
31690+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31691+{
31692+ int err;
31693+
31694+ do { /* PaX: libffi trampoline emulation */
31695+ unsigned char mov, jmp;
31696+ unsigned int addr1, addr2;
31697+
31698+#ifdef CONFIG_X86_64
31699+ if ((regs->ip + 9) >> 32)
31700+ break;
31701+#endif
31702+
31703+ err = get_user(mov, (unsigned char __user *)regs->ip);
31704+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31705+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31706+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31707+
31708+ if (err)
31709+ break;
31710+
31711+ if (mov == 0xB8 && jmp == 0xE9) {
31712+ regs->ax = addr1;
31713+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31714+ return 2;
31715+ }
31716+ } while (0);
31717+
31718+ do { /* PaX: gcc trampoline emulation #1 */
31719+ unsigned char mov1, mov2;
31720+ unsigned short jmp;
31721+ unsigned int addr1, addr2;
31722+
31723+#ifdef CONFIG_X86_64
31724+ if ((regs->ip + 11) >> 32)
31725+ break;
31726+#endif
31727+
31728+ err = get_user(mov1, (unsigned char __user *)regs->ip);
31729+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31730+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31731+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31732+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31733+
31734+ if (err)
31735+ break;
31736+
31737+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31738+ regs->cx = addr1;
31739+ regs->ax = addr2;
31740+ regs->ip = addr2;
31741+ return 2;
31742+ }
31743+ } while (0);
31744+
31745+ do { /* PaX: gcc trampoline emulation #2 */
31746+ unsigned char mov, jmp;
31747+ unsigned int addr1, addr2;
31748+
31749+#ifdef CONFIG_X86_64
31750+ if ((regs->ip + 9) >> 32)
31751+ break;
31752+#endif
31753+
31754+ err = get_user(mov, (unsigned char __user *)regs->ip);
31755+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31756+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31757+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31758+
31759+ if (err)
31760+ break;
31761+
31762+ if (mov == 0xB9 && jmp == 0xE9) {
31763+ regs->cx = addr1;
31764+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31765+ return 2;
31766+ }
31767+ } while (0);
31768+
31769+ return 1; /* PaX in action */
31770+}
31771+
31772+#ifdef CONFIG_X86_64
31773+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31774+{
31775+ int err;
31776+
31777+ do { /* PaX: libffi trampoline emulation */
31778+ unsigned short mov1, mov2, jmp1;
31779+ unsigned char stcclc, jmp2;
31780+ unsigned long addr1, addr2;
31781+
31782+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31783+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31784+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31785+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31786+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31787+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31788+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31789+
31790+ if (err)
31791+ break;
31792+
31793+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31794+ regs->r11 = addr1;
31795+ regs->r10 = addr2;
31796+ if (stcclc == 0xF8)
31797+ regs->flags &= ~X86_EFLAGS_CF;
31798+ else
31799+ regs->flags |= X86_EFLAGS_CF;
31800+ regs->ip = addr1;
31801+ return 2;
31802+ }
31803+ } while (0);
31804+
31805+ do { /* PaX: gcc trampoline emulation #1 */
31806+ unsigned short mov1, mov2, jmp1;
31807+ unsigned char jmp2;
31808+ unsigned int addr1;
31809+ unsigned long addr2;
31810+
31811+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31812+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31813+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31814+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31815+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31816+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31817+
31818+ if (err)
31819+ break;
31820+
31821+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31822+ regs->r11 = addr1;
31823+ regs->r10 = addr2;
31824+ regs->ip = addr1;
31825+ return 2;
31826+ }
31827+ } while (0);
31828+
31829+ do { /* PaX: gcc trampoline emulation #2 */
31830+ unsigned short mov1, mov2, jmp1;
31831+ unsigned char jmp2;
31832+ unsigned long addr1, addr2;
31833+
31834+ err = get_user(mov1, (unsigned short __user *)regs->ip);
31835+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31836+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31837+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31838+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31839+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31840+
31841+ if (err)
31842+ break;
31843+
31844+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31845+ regs->r11 = addr1;
31846+ regs->r10 = addr2;
31847+ regs->ip = addr1;
31848+ return 2;
31849+ }
31850+ } while (0);
31851+
31852+ return 1; /* PaX in action */
31853+}
31854+#endif
31855+
31856+/*
31857+ * PaX: decide what to do with offenders (regs->ip = fault address)
31858+ *
31859+ * returns 1 when task should be killed
31860+ * 2 when gcc trampoline was detected
31861+ */
31862+static int pax_handle_fetch_fault(struct pt_regs *regs)
31863+{
31864+ if (v8086_mode(regs))
31865+ return 1;
31866+
31867+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31868+ return 1;
31869+
31870+#ifdef CONFIG_X86_32
31871+ return pax_handle_fetch_fault_32(regs);
31872+#else
31873+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31874+ return pax_handle_fetch_fault_32(regs);
31875+ else
31876+ return pax_handle_fetch_fault_64(regs);
31877+#endif
31878+}
31879+#endif
31880+
31881+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31882+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31883+{
31884+ long i;
31885+
31886+ printk(KERN_ERR "PAX: bytes at PC: ");
31887+ for (i = 0; i < 20; i++) {
31888+ unsigned char c;
31889+ if (get_user(c, (unsigned char __force_user *)pc+i))
31890+ printk(KERN_CONT "?? ");
31891+ else
31892+ printk(KERN_CONT "%02x ", c);
31893+ }
31894+ printk("\n");
31895+
31896+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31897+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
31898+ unsigned long c;
31899+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
31900+#ifdef CONFIG_X86_32
31901+ printk(KERN_CONT "???????? ");
31902+#else
31903+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31904+ printk(KERN_CONT "???????? ???????? ");
31905+ else
31906+ printk(KERN_CONT "???????????????? ");
31907+#endif
31908+ } else {
31909+#ifdef CONFIG_X86_64
31910+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31911+ printk(KERN_CONT "%08x ", (unsigned int)c);
31912+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31913+ } else
31914+#endif
31915+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31916+ }
31917+ }
31918+ printk("\n");
31919+}
31920+#endif
31921+
31922+/**
31923+ * probe_kernel_write(): safely attempt to write to a location
31924+ * @dst: address to write to
31925+ * @src: pointer to the data that shall be written
31926+ * @size: size of the data chunk
31927+ *
31928+ * Safely write to address @dst from the buffer at @src. If a kernel fault
31929+ * happens, handle that and return -EFAULT.
31930+ */
31931+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31932+{
31933+ long ret;
31934+ mm_segment_t old_fs = get_fs();
31935+
31936+ set_fs(KERNEL_DS);
31937+ pagefault_disable();
31938+ pax_open_kernel();
31939+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31940+ pax_close_kernel();
31941+ pagefault_enable();
31942+ set_fs(old_fs);
31943+
31944+ return ret ? -EFAULT : 0;
31945+}
31946diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31947index 0596e8e..5626789 100644
31948--- a/arch/x86/mm/gup.c
31949+++ b/arch/x86/mm/gup.c
31950@@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31951 addr = start;
31952 len = (unsigned long) nr_pages << PAGE_SHIFT;
31953 end = start + len;
31954- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31955+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31956 (void __user *)start, len)))
31957 return 0;
31958
31959@@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31960 goto slow_irqon;
31961 #endif
31962
31963+ if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
31964+ (void __user *)start, len)))
31965+ return 0;
31966+
31967 /*
31968 * XXX: batch / limit 'nr', to avoid large irq off latency
31969 * needs some instrumenting to determine the common sizes used by
31970diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31971index 4500142..53a363c 100644
31972--- a/arch/x86/mm/highmem_32.c
31973+++ b/arch/x86/mm/highmem_32.c
31974@@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31975 idx = type + KM_TYPE_NR*smp_processor_id();
31976 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31977 BUG_ON(!pte_none(*(kmap_pte-idx)));
31978+
31979+ pax_open_kernel();
31980 set_pte(kmap_pte-idx, mk_pte(page, prot));
31981+ pax_close_kernel();
31982+
31983 arch_flush_lazy_mmu_mode();
31984
31985 return (void *)vaddr;
31986diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31987index 9d980d8..6bbfacb 100644
31988--- a/arch/x86/mm/hugetlbpage.c
31989+++ b/arch/x86/mm/hugetlbpage.c
31990@@ -92,23 +92,30 @@ int pmd_huge_support(void)
31991 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31992 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31993 unsigned long addr, unsigned long len,
31994- unsigned long pgoff, unsigned long flags)
31995+ unsigned long pgoff, unsigned long flags, unsigned long offset)
31996 {
31997 struct hstate *h = hstate_file(file);
31998 struct vm_unmapped_area_info info;
31999-
32000+
32001 info.flags = 0;
32002 info.length = len;
32003 info.low_limit = TASK_UNMAPPED_BASE;
32004+
32005+#ifdef CONFIG_PAX_RANDMMAP
32006+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32007+ info.low_limit += current->mm->delta_mmap;
32008+#endif
32009+
32010 info.high_limit = TASK_SIZE;
32011 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32012 info.align_offset = 0;
32013+ info.threadstack_offset = offset;
32014 return vm_unmapped_area(&info);
32015 }
32016
32017 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32018 unsigned long addr0, unsigned long len,
32019- unsigned long pgoff, unsigned long flags)
32020+ unsigned long pgoff, unsigned long flags, unsigned long offset)
32021 {
32022 struct hstate *h = hstate_file(file);
32023 struct vm_unmapped_area_info info;
32024@@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32025 info.high_limit = current->mm->mmap_base;
32026 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32027 info.align_offset = 0;
32028+ info.threadstack_offset = offset;
32029 addr = vm_unmapped_area(&info);
32030
32031 /*
32032@@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32033 VM_BUG_ON(addr != -ENOMEM);
32034 info.flags = 0;
32035 info.low_limit = TASK_UNMAPPED_BASE;
32036+
32037+#ifdef CONFIG_PAX_RANDMMAP
32038+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32039+ info.low_limit += current->mm->delta_mmap;
32040+#endif
32041+
32042 info.high_limit = TASK_SIZE;
32043 addr = vm_unmapped_area(&info);
32044 }
32045@@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32046 struct hstate *h = hstate_file(file);
32047 struct mm_struct *mm = current->mm;
32048 struct vm_area_struct *vma;
32049+ unsigned long pax_task_size = TASK_SIZE;
32050+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32051
32052 if (len & ~huge_page_mask(h))
32053 return -EINVAL;
32054- if (len > TASK_SIZE)
32055+
32056+#ifdef CONFIG_PAX_SEGMEXEC
32057+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32058+ pax_task_size = SEGMEXEC_TASK_SIZE;
32059+#endif
32060+
32061+ pax_task_size -= PAGE_SIZE;
32062+
32063+ if (len > pax_task_size)
32064 return -ENOMEM;
32065
32066 if (flags & MAP_FIXED) {
32067@@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32068 return addr;
32069 }
32070
32071+#ifdef CONFIG_PAX_RANDMMAP
32072+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32073+#endif
32074+
32075 if (addr) {
32076 addr = ALIGN(addr, huge_page_size(h));
32077 vma = find_vma(mm, addr);
32078- if (TASK_SIZE - len >= addr &&
32079- (!vma || addr + len <= vma->vm_start))
32080+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32081 return addr;
32082 }
32083 if (mm->get_unmapped_area == arch_get_unmapped_area)
32084 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32085- pgoff, flags);
32086+ pgoff, flags, offset);
32087 else
32088 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32089- pgoff, flags);
32090+ pgoff, flags, offset);
32091 }
32092
32093 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
32094diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32095index f971306..e83e0f6 100644
32096--- a/arch/x86/mm/init.c
32097+++ b/arch/x86/mm/init.c
32098@@ -4,6 +4,7 @@
32099 #include <linux/swap.h>
32100 #include <linux/memblock.h>
32101 #include <linux/bootmem.h> /* for max_low_pfn */
32102+#include <linux/tboot.h>
32103
32104 #include <asm/cacheflush.h>
32105 #include <asm/e820.h>
32106@@ -17,6 +18,8 @@
32107 #include <asm/proto.h>
32108 #include <asm/dma.h> /* for MAX_DMA_PFN */
32109 #include <asm/microcode.h>
32110+#include <asm/desc.h>
32111+#include <asm/bios_ebda.h>
32112
32113 #include "mm_internal.h"
32114
32115@@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32116 early_ioremap_page_table_range_init();
32117 #endif
32118
32119+#ifdef CONFIG_PAX_PER_CPU_PGD
32120+ clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32121+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32122+ KERNEL_PGD_PTRS);
32123+ clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32124+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32125+ KERNEL_PGD_PTRS);
32126+ load_cr3(get_cpu_pgd(0, kernel));
32127+#else
32128 load_cr3(swapper_pg_dir);
32129+#endif
32130+
32131 __flush_tlb_all();
32132
32133 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32134@@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32135 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32136 * mmio resources as well as potential bios/acpi data regions.
32137 */
32138+
32139+#ifdef CONFIG_GRKERNSEC_KMEM
32140+static unsigned int ebda_start __read_only;
32141+static unsigned int ebda_end __read_only;
32142+#endif
32143+
32144 int devmem_is_allowed(unsigned long pagenr)
32145 {
32146- if (pagenr < 256)
32147+#ifdef CONFIG_GRKERNSEC_KMEM
32148+ /* allow BDA */
32149+ if (!pagenr)
32150 return 1;
32151+ /* allow EBDA */
32152+ if (pagenr >= ebda_start && pagenr < ebda_end)
32153+ return 1;
32154+ /* if tboot is in use, allow access to its hardcoded serial log range */
32155+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32156+ return 1;
32157+#else
32158+ if (!pagenr)
32159+ return 1;
32160+#ifdef CONFIG_VM86
32161+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32162+ return 1;
32163+#endif
32164+#endif
32165+
32166+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32167+ return 1;
32168+#ifdef CONFIG_GRKERNSEC_KMEM
32169+ /* throw out everything else below 1MB */
32170+ if (pagenr <= 256)
32171+ return 0;
32172+#endif
32173 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32174 return 0;
32175 if (!page_is_ram(pagenr))
32176@@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32177 #endif
32178 }
32179
32180+#ifdef CONFIG_GRKERNSEC_KMEM
32181+static inline void gr_init_ebda(void)
32182+{
32183+ unsigned int ebda_addr;
32184+ unsigned int ebda_size = 0;
32185+
32186+ ebda_addr = get_bios_ebda();
32187+ if (ebda_addr) {
32188+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32189+ ebda_size <<= 10;
32190+ }
32191+ if (ebda_addr && ebda_size) {
32192+ ebda_start = ebda_addr >> PAGE_SHIFT;
32193+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32194+ } else {
32195+ ebda_start = 0x9f000 >> PAGE_SHIFT;
32196+ ebda_end = 0xa0000 >> PAGE_SHIFT;
32197+ }
32198+}
32199+#else
32200+static inline void gr_init_ebda(void) { }
32201+#endif
32202+
32203 void free_initmem(void)
32204 {
32205+#ifdef CONFIG_PAX_KERNEXEC
32206+#ifdef CONFIG_X86_32
32207+ /* PaX: limit KERNEL_CS to actual size */
32208+ unsigned long addr, limit;
32209+ struct desc_struct d;
32210+ int cpu;
32211+#else
32212+ pgd_t *pgd;
32213+ pud_t *pud;
32214+ pmd_t *pmd;
32215+ unsigned long addr, end;
32216+#endif
32217+#endif
32218+
32219+ gr_init_ebda();
32220+
32221+#ifdef CONFIG_PAX_KERNEXEC
32222+#ifdef CONFIG_X86_32
32223+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32224+ limit = (limit - 1UL) >> PAGE_SHIFT;
32225+
32226+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32227+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32228+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32229+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32230+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32231+ }
32232+
32233+ /* PaX: make KERNEL_CS read-only */
32234+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32235+ if (!paravirt_enabled())
32236+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32237+/*
32238+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32239+ pgd = pgd_offset_k(addr);
32240+ pud = pud_offset(pgd, addr);
32241+ pmd = pmd_offset(pud, addr);
32242+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32243+ }
32244+*/
32245+#ifdef CONFIG_X86_PAE
32246+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32247+/*
32248+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32249+ pgd = pgd_offset_k(addr);
32250+ pud = pud_offset(pgd, addr);
32251+ pmd = pmd_offset(pud, addr);
32252+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32253+ }
32254+*/
32255+#endif
32256+
32257+#ifdef CONFIG_MODULES
32258+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32259+#endif
32260+
32261+#else
32262+ /* PaX: make kernel code/rodata read-only, rest non-executable */
32263+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32264+ pgd = pgd_offset_k(addr);
32265+ pud = pud_offset(pgd, addr);
32266+ pmd = pmd_offset(pud, addr);
32267+ if (!pmd_present(*pmd))
32268+ continue;
32269+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32270+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32271+ else
32272+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32273+ }
32274+
32275+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32276+ end = addr + KERNEL_IMAGE_SIZE;
32277+ for (; addr < end; addr += PMD_SIZE) {
32278+ pgd = pgd_offset_k(addr);
32279+ pud = pud_offset(pgd, addr);
32280+ pmd = pmd_offset(pud, addr);
32281+ if (!pmd_present(*pmd))
32282+ continue;
32283+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32284+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32285+ }
32286+#endif
32287+
32288+ flush_tlb_all();
32289+#endif
32290+
32291 free_init_pages("unused kernel",
32292 (unsigned long)(&__init_begin),
32293 (unsigned long)(&__init_end));
32294diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32295index 4287f1f..3b99c71 100644
32296--- a/arch/x86/mm/init_32.c
32297+++ b/arch/x86/mm/init_32.c
32298@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32299 bool __read_mostly __vmalloc_start_set = false;
32300
32301 /*
32302- * Creates a middle page table and puts a pointer to it in the
32303- * given global directory entry. This only returns the gd entry
32304- * in non-PAE compilation mode, since the middle layer is folded.
32305- */
32306-static pmd_t * __init one_md_table_init(pgd_t *pgd)
32307-{
32308- pud_t *pud;
32309- pmd_t *pmd_table;
32310-
32311-#ifdef CONFIG_X86_PAE
32312- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32313- pmd_table = (pmd_t *)alloc_low_page();
32314- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32315- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32316- pud = pud_offset(pgd, 0);
32317- BUG_ON(pmd_table != pmd_offset(pud, 0));
32318-
32319- return pmd_table;
32320- }
32321-#endif
32322- pud = pud_offset(pgd, 0);
32323- pmd_table = pmd_offset(pud, 0);
32324-
32325- return pmd_table;
32326-}
32327-
32328-/*
32329 * Create a page table and place a pointer to it in a middle page
32330 * directory entry:
32331 */
32332@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32333 pte_t *page_table = (pte_t *)alloc_low_page();
32334
32335 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32336+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32337+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32338+#else
32339 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32340+#endif
32341 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32342 }
32343
32344 return pte_offset_kernel(pmd, 0);
32345 }
32346
32347+static pmd_t * __init one_md_table_init(pgd_t *pgd)
32348+{
32349+ pud_t *pud;
32350+ pmd_t *pmd_table;
32351+
32352+ pud = pud_offset(pgd, 0);
32353+ pmd_table = pmd_offset(pud, 0);
32354+
32355+ return pmd_table;
32356+}
32357+
32358 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32359 {
32360 int pgd_idx = pgd_index(vaddr);
32361@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32362 int pgd_idx, pmd_idx;
32363 unsigned long vaddr;
32364 pgd_t *pgd;
32365+ pud_t *pud;
32366 pmd_t *pmd;
32367 pte_t *pte = NULL;
32368 unsigned long count = page_table_range_init_count(start, end);
32369@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32370 pgd = pgd_base + pgd_idx;
32371
32372 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32373- pmd = one_md_table_init(pgd);
32374- pmd = pmd + pmd_index(vaddr);
32375+ pud = pud_offset(pgd, vaddr);
32376+ pmd = pmd_offset(pud, vaddr);
32377+
32378+#ifdef CONFIG_X86_PAE
32379+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32380+#endif
32381+
32382 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32383 pmd++, pmd_idx++) {
32384 pte = page_table_kmap_check(one_page_table_init(pmd),
32385@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32386 }
32387 }
32388
32389-static inline int is_kernel_text(unsigned long addr)
32390+static inline int is_kernel_text(unsigned long start, unsigned long end)
32391 {
32392- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32393- return 1;
32394- return 0;
32395+ if ((start > ktla_ktva((unsigned long)_etext) ||
32396+ end <= ktla_ktva((unsigned long)_stext)) &&
32397+ (start > ktla_ktva((unsigned long)_einittext) ||
32398+ end <= ktla_ktva((unsigned long)_sinittext)) &&
32399+
32400+#ifdef CONFIG_ACPI_SLEEP
32401+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32402+#endif
32403+
32404+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32405+ return 0;
32406+ return 1;
32407 }
32408
32409 /*
32410@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32411 unsigned long last_map_addr = end;
32412 unsigned long start_pfn, end_pfn;
32413 pgd_t *pgd_base = swapper_pg_dir;
32414- int pgd_idx, pmd_idx, pte_ofs;
32415+ unsigned int pgd_idx, pmd_idx, pte_ofs;
32416 unsigned long pfn;
32417 pgd_t *pgd;
32418+ pud_t *pud;
32419 pmd_t *pmd;
32420 pte_t *pte;
32421 unsigned pages_2m, pages_4k;
32422@@ -291,8 +295,13 @@ repeat:
32423 pfn = start_pfn;
32424 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32425 pgd = pgd_base + pgd_idx;
32426- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32427- pmd = one_md_table_init(pgd);
32428+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32429+ pud = pud_offset(pgd, 0);
32430+ pmd = pmd_offset(pud, 0);
32431+
32432+#ifdef CONFIG_X86_PAE
32433+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32434+#endif
32435
32436 if (pfn >= end_pfn)
32437 continue;
32438@@ -304,14 +313,13 @@ repeat:
32439 #endif
32440 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32441 pmd++, pmd_idx++) {
32442- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32443+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32444
32445 /*
32446 * Map with big pages if possible, otherwise
32447 * create normal page tables:
32448 */
32449 if (use_pse) {
32450- unsigned int addr2;
32451 pgprot_t prot = PAGE_KERNEL_LARGE;
32452 /*
32453 * first pass will use the same initial
32454@@ -322,11 +330,7 @@ repeat:
32455 _PAGE_PSE);
32456
32457 pfn &= PMD_MASK >> PAGE_SHIFT;
32458- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32459- PAGE_OFFSET + PAGE_SIZE-1;
32460-
32461- if (is_kernel_text(addr) ||
32462- is_kernel_text(addr2))
32463+ if (is_kernel_text(address, address + PMD_SIZE))
32464 prot = PAGE_KERNEL_LARGE_EXEC;
32465
32466 pages_2m++;
32467@@ -343,7 +347,7 @@ repeat:
32468 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32469 pte += pte_ofs;
32470 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32471- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32472+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32473 pgprot_t prot = PAGE_KERNEL;
32474 /*
32475 * first pass will use the same initial
32476@@ -351,7 +355,7 @@ repeat:
32477 */
32478 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32479
32480- if (is_kernel_text(addr))
32481+ if (is_kernel_text(address, address + PAGE_SIZE))
32482 prot = PAGE_KERNEL_EXEC;
32483
32484 pages_4k++;
32485@@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32486
32487 pud = pud_offset(pgd, va);
32488 pmd = pmd_offset(pud, va);
32489- if (!pmd_present(*pmd))
32490+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32491 break;
32492
32493 /* should not be large page here */
32494@@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32495
32496 static void __init pagetable_init(void)
32497 {
32498- pgd_t *pgd_base = swapper_pg_dir;
32499-
32500- permanent_kmaps_init(pgd_base);
32501+ permanent_kmaps_init(swapper_pg_dir);
32502 }
32503
32504-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32505+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32506 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32507
32508 /* user-defined highmem size */
32509@@ -787,10 +789,10 @@ void __init mem_init(void)
32510 ((unsigned long)&__init_end -
32511 (unsigned long)&__init_begin) >> 10,
32512
32513- (unsigned long)&_etext, (unsigned long)&_edata,
32514- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32515+ (unsigned long)&_sdata, (unsigned long)&_edata,
32516+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32517
32518- (unsigned long)&_text, (unsigned long)&_etext,
32519+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32520 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32521
32522 /*
32523@@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32524 if (!kernel_set_to_readonly)
32525 return;
32526
32527+ start = ktla_ktva(start);
32528 pr_debug("Set kernel text: %lx - %lx for read write\n",
32529 start, start+size);
32530
32531@@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32532 if (!kernel_set_to_readonly)
32533 return;
32534
32535+ start = ktla_ktva(start);
32536 pr_debug("Set kernel text: %lx - %lx for read only\n",
32537 start, start+size);
32538
32539@@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32540 unsigned long start = PFN_ALIGN(_text);
32541 unsigned long size = PFN_ALIGN(_etext) - start;
32542
32543+ start = ktla_ktva(start);
32544 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32545 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32546 size >> 10);
32547diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32548index 104d56a..62ba13f1 100644
32549--- a/arch/x86/mm/init_64.c
32550+++ b/arch/x86/mm/init_64.c
32551@@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32552 * around without checking the pgd every time.
32553 */
32554
32555-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32556+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32557 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32558
32559 int force_personality32;
32560@@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32561
32562 for (address = start; address <= end; address += PGDIR_SIZE) {
32563 const pgd_t *pgd_ref = pgd_offset_k(address);
32564+
32565+#ifdef CONFIG_PAX_PER_CPU_PGD
32566+ unsigned long cpu;
32567+#else
32568 struct page *page;
32569+#endif
32570
32571 if (pgd_none(*pgd_ref))
32572 continue;
32573
32574 spin_lock(&pgd_lock);
32575+
32576+#ifdef CONFIG_PAX_PER_CPU_PGD
32577+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32578+ pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32579+
32580+ if (pgd_none(*pgd))
32581+ set_pgd(pgd, *pgd_ref);
32582+ else
32583+ BUG_ON(pgd_page_vaddr(*pgd)
32584+ != pgd_page_vaddr(*pgd_ref));
32585+ pgd = pgd_offset_cpu(cpu, kernel, address);
32586+#else
32587 list_for_each_entry(page, &pgd_list, lru) {
32588 pgd_t *pgd;
32589 spinlock_t *pgt_lock;
32590@@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32591 /* the pgt_lock only for Xen */
32592 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32593 spin_lock(pgt_lock);
32594+#endif
32595
32596 if (pgd_none(*pgd))
32597 set_pgd(pgd, *pgd_ref);
32598@@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32599 BUG_ON(pgd_page_vaddr(*pgd)
32600 != pgd_page_vaddr(*pgd_ref));
32601
32602+#ifndef CONFIG_PAX_PER_CPU_PGD
32603 spin_unlock(pgt_lock);
32604+#endif
32605+
32606 }
32607 spin_unlock(&pgd_lock);
32608 }
32609@@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32610 {
32611 if (pgd_none(*pgd)) {
32612 pud_t *pud = (pud_t *)spp_getpage();
32613- pgd_populate(&init_mm, pgd, pud);
32614+ pgd_populate_kernel(&init_mm, pgd, pud);
32615 if (pud != pud_offset(pgd, 0))
32616 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32617 pud, pud_offset(pgd, 0));
32618@@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32619 {
32620 if (pud_none(*pud)) {
32621 pmd_t *pmd = (pmd_t *) spp_getpage();
32622- pud_populate(&init_mm, pud, pmd);
32623+ pud_populate_kernel(&init_mm, pud, pmd);
32624 if (pmd != pmd_offset(pud, 0))
32625 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32626 pmd, pmd_offset(pud, 0));
32627@@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32628 pmd = fill_pmd(pud, vaddr);
32629 pte = fill_pte(pmd, vaddr);
32630
32631+ pax_open_kernel();
32632 set_pte(pte, new_pte);
32633+ pax_close_kernel();
32634
32635 /*
32636 * It's enough to flush this one mapping.
32637@@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32638 pgd = pgd_offset_k((unsigned long)__va(phys));
32639 if (pgd_none(*pgd)) {
32640 pud = (pud_t *) spp_getpage();
32641- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32642- _PAGE_USER));
32643+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32644 }
32645 pud = pud_offset(pgd, (unsigned long)__va(phys));
32646 if (pud_none(*pud)) {
32647 pmd = (pmd_t *) spp_getpage();
32648- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32649- _PAGE_USER));
32650+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32651 }
32652 pmd = pmd_offset(pud, phys);
32653 BUG_ON(!pmd_none(*pmd));
32654@@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32655 prot);
32656
32657 spin_lock(&init_mm.page_table_lock);
32658- pud_populate(&init_mm, pud, pmd);
32659+ pud_populate_kernel(&init_mm, pud, pmd);
32660 spin_unlock(&init_mm.page_table_lock);
32661 }
32662 __flush_tlb_all();
32663@@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32664 page_size_mask);
32665
32666 spin_lock(&init_mm.page_table_lock);
32667- pgd_populate(&init_mm, pgd, pud);
32668+ pgd_populate_kernel(&init_mm, pgd, pud);
32669 spin_unlock(&init_mm.page_table_lock);
32670 pgd_changed = true;
32671 }
32672@@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32673 static struct vm_area_struct gate_vma = {
32674 .vm_start = VSYSCALL_START,
32675 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32676- .vm_page_prot = PAGE_READONLY_EXEC,
32677- .vm_flags = VM_READ | VM_EXEC
32678+ .vm_page_prot = PAGE_READONLY,
32679+ .vm_flags = VM_READ
32680 };
32681
32682 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32683@@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32684
32685 const char *arch_vma_name(struct vm_area_struct *vma)
32686 {
32687- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32688+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32689 return "[vdso]";
32690 if (vma == &gate_vma)
32691 return "[vsyscall]";
32692diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32693index 7b179b4..6bd17777 100644
32694--- a/arch/x86/mm/iomap_32.c
32695+++ b/arch/x86/mm/iomap_32.c
32696@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32697 type = kmap_atomic_idx_push();
32698 idx = type + KM_TYPE_NR * smp_processor_id();
32699 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32700+
32701+ pax_open_kernel();
32702 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32703+ pax_close_kernel();
32704+
32705 arch_flush_lazy_mmu_mode();
32706
32707 return (void *)vaddr;
32708diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32709index 799580c..72f9fe0 100644
32710--- a/arch/x86/mm/ioremap.c
32711+++ b/arch/x86/mm/ioremap.c
32712@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32713 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32714 int is_ram = page_is_ram(pfn);
32715
32716- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32717+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32718 return NULL;
32719 WARN_ON_ONCE(is_ram);
32720 }
32721@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32722 *
32723 * Caller must ensure there is only one unmapping for the same pointer.
32724 */
32725-void iounmap(volatile void __iomem *addr)
32726+void iounmap(const volatile void __iomem *addr)
32727 {
32728 struct vm_struct *p, *o;
32729
32730@@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32731
32732 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32733 if (page_is_ram(start >> PAGE_SHIFT))
32734+#ifdef CONFIG_HIGHMEM
32735+ if ((start >> PAGE_SHIFT) < max_low_pfn)
32736+#endif
32737 return __va(phys);
32738
32739 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32740@@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32741 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32742 {
32743 if (page_is_ram(phys >> PAGE_SHIFT))
32744+#ifdef CONFIG_HIGHMEM
32745+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
32746+#endif
32747 return;
32748
32749 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32750@@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32751 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32752
32753 static __initdata int after_paging_init;
32754-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32755+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32756
32757 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32758 {
32759@@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32760 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32761
32762 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32763- memset(bm_pte, 0, sizeof(bm_pte));
32764- pmd_populate_kernel(&init_mm, pmd, bm_pte);
32765+ pmd_populate_user(&init_mm, pmd, bm_pte);
32766
32767 /*
32768 * The boot-ioremap range spans multiple pmds, for which
32769diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32770index d87dd6d..bf3fa66 100644
32771--- a/arch/x86/mm/kmemcheck/kmemcheck.c
32772+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32773@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32774 * memory (e.g. tracked pages)? For now, we need this to avoid
32775 * invoking kmemcheck for PnP BIOS calls.
32776 */
32777- if (regs->flags & X86_VM_MASK)
32778+ if (v8086_mode(regs))
32779 return false;
32780- if (regs->cs != __KERNEL_CS)
32781+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32782 return false;
32783
32784 pte = kmemcheck_pte_lookup(address);
32785diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32786index 25e7e13..1964579 100644
32787--- a/arch/x86/mm/mmap.c
32788+++ b/arch/x86/mm/mmap.c
32789@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32790 * Leave an at least ~128 MB hole with possible stack randomization.
32791 */
32792 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32793-#define MAX_GAP (TASK_SIZE/6*5)
32794+#define MAX_GAP (pax_task_size/6*5)
32795
32796 static int mmap_is_legacy(void)
32797 {
32798@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32799 return rnd << PAGE_SHIFT;
32800 }
32801
32802-static unsigned long mmap_base(void)
32803+static unsigned long mmap_base(struct mm_struct *mm)
32804 {
32805 unsigned long gap = rlimit(RLIMIT_STACK);
32806+ unsigned long pax_task_size = TASK_SIZE;
32807+
32808+#ifdef CONFIG_PAX_SEGMEXEC
32809+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32810+ pax_task_size = SEGMEXEC_TASK_SIZE;
32811+#endif
32812
32813 if (gap < MIN_GAP)
32814 gap = MIN_GAP;
32815 else if (gap > MAX_GAP)
32816 gap = MAX_GAP;
32817
32818- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32819+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32820 }
32821
32822 /*
32823 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32824 * does, but not when emulating X86_32
32825 */
32826-static unsigned long mmap_legacy_base(void)
32827+static unsigned long mmap_legacy_base(struct mm_struct *mm)
32828 {
32829- if (mmap_is_ia32())
32830+ if (mmap_is_ia32()) {
32831+
32832+#ifdef CONFIG_PAX_SEGMEXEC
32833+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
32834+ return SEGMEXEC_TASK_UNMAPPED_BASE;
32835+ else
32836+#endif
32837+
32838 return TASK_UNMAPPED_BASE;
32839- else
32840+ } else
32841 return TASK_UNMAPPED_BASE + mmap_rnd();
32842 }
32843
32844@@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32845 */
32846 void arch_pick_mmap_layout(struct mm_struct *mm)
32847 {
32848- mm->mmap_legacy_base = mmap_legacy_base();
32849- mm->mmap_base = mmap_base();
32850+ mm->mmap_legacy_base = mmap_legacy_base(mm);
32851+ mm->mmap_base = mmap_base(mm);
32852+
32853+#ifdef CONFIG_PAX_RANDMMAP
32854+ if (mm->pax_flags & MF_PAX_RANDMMAP) {
32855+ mm->mmap_legacy_base += mm->delta_mmap;
32856+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32857+ }
32858+#endif
32859
32860 if (mmap_is_legacy()) {
32861 mm->mmap_base = mm->mmap_legacy_base;
32862diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32863index 0057a7a..95c7edd 100644
32864--- a/arch/x86/mm/mmio-mod.c
32865+++ b/arch/x86/mm/mmio-mod.c
32866@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32867 break;
32868 default:
32869 {
32870- unsigned char *ip = (unsigned char *)instptr;
32871+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32872 my_trace->opcode = MMIO_UNKNOWN_OP;
32873 my_trace->width = 0;
32874 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32875@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32876 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32877 void __iomem *addr)
32878 {
32879- static atomic_t next_id;
32880+ static atomic_unchecked_t next_id;
32881 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32882 /* These are page-unaligned. */
32883 struct mmiotrace_map map = {
32884@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32885 .private = trace
32886 },
32887 .phys = offset,
32888- .id = atomic_inc_return(&next_id)
32889+ .id = atomic_inc_return_unchecked(&next_id)
32890 };
32891 map.map_id = trace->id;
32892
32893@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32894 ioremap_trace_core(offset, size, addr);
32895 }
32896
32897-static void iounmap_trace_core(volatile void __iomem *addr)
32898+static void iounmap_trace_core(const volatile void __iomem *addr)
32899 {
32900 struct mmiotrace_map map = {
32901 .phys = 0,
32902@@ -328,7 +328,7 @@ not_enabled:
32903 }
32904 }
32905
32906-void mmiotrace_iounmap(volatile void __iomem *addr)
32907+void mmiotrace_iounmap(const volatile void __iomem *addr)
32908 {
32909 might_sleep();
32910 if (is_enabled()) /* recheck and proper locking in *_core() */
32911diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32912index 24aec58..c39fe8b 100644
32913--- a/arch/x86/mm/numa.c
32914+++ b/arch/x86/mm/numa.c
32915@@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32916 return true;
32917 }
32918
32919-static int __init numa_register_memblks(struct numa_meminfo *mi)
32920+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32921 {
32922 unsigned long uninitialized_var(pfn_align);
32923 int i, nid;
32924diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32925index d0b1773..4c3327c 100644
32926--- a/arch/x86/mm/pageattr-test.c
32927+++ b/arch/x86/mm/pageattr-test.c
32928@@ -36,7 +36,7 @@ enum {
32929
32930 static int pte_testbit(pte_t pte)
32931 {
32932- return pte_flags(pte) & _PAGE_UNUSED1;
32933+ return pte_flags(pte) & _PAGE_CPA_TEST;
32934 }
32935
32936 struct split_state {
32937diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32938index bb32480..75f2f5e 100644
32939--- a/arch/x86/mm/pageattr.c
32940+++ b/arch/x86/mm/pageattr.c
32941@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32942 */
32943 #ifdef CONFIG_PCI_BIOS
32944 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32945- pgprot_val(forbidden) |= _PAGE_NX;
32946+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32947 #endif
32948
32949 /*
32950@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32951 * Does not cover __inittext since that is gone later on. On
32952 * 64bit we do not enforce !NX on the low mapping
32953 */
32954- if (within(address, (unsigned long)_text, (unsigned long)_etext))
32955- pgprot_val(forbidden) |= _PAGE_NX;
32956+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32957+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32958
32959+#ifdef CONFIG_DEBUG_RODATA
32960 /*
32961 * The .rodata section needs to be read-only. Using the pfn
32962 * catches all aliases.
32963@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32964 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32965 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32966 pgprot_val(forbidden) |= _PAGE_RW;
32967+#endif
32968
32969 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32970 /*
32971@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32972 }
32973 #endif
32974
32975+#ifdef CONFIG_PAX_KERNEXEC
32976+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32977+ pgprot_val(forbidden) |= _PAGE_RW;
32978+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32979+ }
32980+#endif
32981+
32982 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32983
32984 return prot;
32985@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32986 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32987 {
32988 /* change init_mm */
32989+ pax_open_kernel();
32990 set_pte_atomic(kpte, pte);
32991+
32992 #ifdef CONFIG_X86_32
32993 if (!SHARED_KERNEL_PMD) {
32994+
32995+#ifdef CONFIG_PAX_PER_CPU_PGD
32996+ unsigned long cpu;
32997+#else
32998 struct page *page;
32999+#endif
33000
33001+#ifdef CONFIG_PAX_PER_CPU_PGD
33002+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33003+ pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33004+#else
33005 list_for_each_entry(page, &pgd_list, lru) {
33006- pgd_t *pgd;
33007+ pgd_t *pgd = (pgd_t *)page_address(page);
33008+#endif
33009+
33010 pud_t *pud;
33011 pmd_t *pmd;
33012
33013- pgd = (pgd_t *)page_address(page) + pgd_index(address);
33014+ pgd += pgd_index(address);
33015 pud = pud_offset(pgd, address);
33016 pmd = pmd_offset(pud, address);
33017 set_pte_atomic((pte_t *)pmd, pte);
33018 }
33019 }
33020 #endif
33021+ pax_close_kernel();
33022 }
33023
33024 static int
33025diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33026index 6574388..87e9bef 100644
33027--- a/arch/x86/mm/pat.c
33028+++ b/arch/x86/mm/pat.c
33029@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33030
33031 if (!entry) {
33032 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33033- current->comm, current->pid, start, end - 1);
33034+ current->comm, task_pid_nr(current), start, end - 1);
33035 return -EINVAL;
33036 }
33037
33038@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33039
33040 while (cursor < to) {
33041 if (!devmem_is_allowed(pfn)) {
33042- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33043- current->comm, from, to - 1);
33044+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33045+ current->comm, from, to - 1, cursor);
33046 return 0;
33047 }
33048 cursor += PAGE_SIZE;
33049@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33050 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33051 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33052 "for [mem %#010Lx-%#010Lx]\n",
33053- current->comm, current->pid,
33054+ current->comm, task_pid_nr(current),
33055 cattr_name(flags),
33056 base, (unsigned long long)(base + size-1));
33057 return -EINVAL;
33058@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33059 flags = lookup_memtype(paddr);
33060 if (want_flags != flags) {
33061 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33062- current->comm, current->pid,
33063+ current->comm, task_pid_nr(current),
33064 cattr_name(want_flags),
33065 (unsigned long long)paddr,
33066 (unsigned long long)(paddr + size - 1),
33067@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33068 free_memtype(paddr, paddr + size);
33069 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33070 " for [mem %#010Lx-%#010Lx], got %s\n",
33071- current->comm, current->pid,
33072+ current->comm, task_pid_nr(current),
33073 cattr_name(want_flags),
33074 (unsigned long long)paddr,
33075 (unsigned long long)(paddr + size - 1),
33076diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33077index 415f6c4..d319983 100644
33078--- a/arch/x86/mm/pat_rbtree.c
33079+++ b/arch/x86/mm/pat_rbtree.c
33080@@ -160,7 +160,7 @@ success:
33081
33082 failure:
33083 printk(KERN_INFO "%s:%d conflicting memory types "
33084- "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33085+ "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33086 end, cattr_name(found_type), cattr_name(match->type));
33087 return -EBUSY;
33088 }
33089diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33090index 9f0614d..92ae64a 100644
33091--- a/arch/x86/mm/pf_in.c
33092+++ b/arch/x86/mm/pf_in.c
33093@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33094 int i;
33095 enum reason_type rv = OTHERS;
33096
33097- p = (unsigned char *)ins_addr;
33098+ p = (unsigned char *)ktla_ktva(ins_addr);
33099 p += skip_prefix(p, &prf);
33100 p += get_opcode(p, &opcode);
33101
33102@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33103 struct prefix_bits prf;
33104 int i;
33105
33106- p = (unsigned char *)ins_addr;
33107+ p = (unsigned char *)ktla_ktva(ins_addr);
33108 p += skip_prefix(p, &prf);
33109 p += get_opcode(p, &opcode);
33110
33111@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33112 struct prefix_bits prf;
33113 int i;
33114
33115- p = (unsigned char *)ins_addr;
33116+ p = (unsigned char *)ktla_ktva(ins_addr);
33117 p += skip_prefix(p, &prf);
33118 p += get_opcode(p, &opcode);
33119
33120@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33121 struct prefix_bits prf;
33122 int i;
33123
33124- p = (unsigned char *)ins_addr;
33125+ p = (unsigned char *)ktla_ktva(ins_addr);
33126 p += skip_prefix(p, &prf);
33127 p += get_opcode(p, &opcode);
33128 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33129@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33130 struct prefix_bits prf;
33131 int i;
33132
33133- p = (unsigned char *)ins_addr;
33134+ p = (unsigned char *)ktla_ktva(ins_addr);
33135 p += skip_prefix(p, &prf);
33136 p += get_opcode(p, &opcode);
33137 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33138diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33139index c96314a..433b127 100644
33140--- a/arch/x86/mm/pgtable.c
33141+++ b/arch/x86/mm/pgtable.c
33142@@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33143 list_del(&page->lru);
33144 }
33145
33146-#define UNSHARED_PTRS_PER_PGD \
33147- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33148+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33149+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33150
33151+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33152+{
33153+ unsigned int count = USER_PGD_PTRS;
33154
33155+ if (!pax_user_shadow_base)
33156+ return;
33157+
33158+ while (count--)
33159+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33160+}
33161+#endif
33162+
33163+#ifdef CONFIG_PAX_PER_CPU_PGD
33164+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33165+{
33166+ unsigned int count = USER_PGD_PTRS;
33167+
33168+ while (count--) {
33169+ pgd_t pgd;
33170+
33171+#ifdef CONFIG_X86_64
33172+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33173+#else
33174+ pgd = *src++;
33175+#endif
33176+
33177+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33178+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33179+#endif
33180+
33181+ *dst++ = pgd;
33182+ }
33183+
33184+}
33185+#endif
33186+
33187+#ifdef CONFIG_X86_64
33188+#define pxd_t pud_t
33189+#define pyd_t pgd_t
33190+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33191+#define pgtable_pxd_page_ctor(page) true
33192+#define pgtable_pxd_page_dtor(page)
33193+#define pxd_free(mm, pud) pud_free((mm), (pud))
33194+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33195+#define pyd_offset(mm, address) pgd_offset((mm), (address))
33196+#define PYD_SIZE PGDIR_SIZE
33197+#else
33198+#define pxd_t pmd_t
33199+#define pyd_t pud_t
33200+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33201+#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33202+#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33203+#define pxd_free(mm, pud) pmd_free((mm), (pud))
33204+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33205+#define pyd_offset(mm, address) pud_offset((mm), (address))
33206+#define PYD_SIZE PUD_SIZE
33207+#endif
33208+
33209+#ifdef CONFIG_PAX_PER_CPU_PGD
33210+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33211+static inline void pgd_dtor(pgd_t *pgd) {}
33212+#else
33213 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33214 {
33215 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33216@@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33217 pgd_list_del(pgd);
33218 spin_unlock(&pgd_lock);
33219 }
33220+#endif
33221
33222 /*
33223 * List of all pgd's needed for non-PAE so it can invalidate entries
33224@@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33225 * -- nyc
33226 */
33227
33228-#ifdef CONFIG_X86_PAE
33229+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33230 /*
33231 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33232 * updating the top-level pagetable entries to guarantee the
33233@@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33234 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33235 * and initialize the kernel pmds here.
33236 */
33237-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33238+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33239
33240 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33241 {
33242@@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33243 */
33244 flush_tlb_mm(mm);
33245 }
33246+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33247+#define PREALLOCATED_PXDS USER_PGD_PTRS
33248 #else /* !CONFIG_X86_PAE */
33249
33250 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33251-#define PREALLOCATED_PMDS 0
33252+#define PREALLOCATED_PXDS 0
33253
33254 #endif /* CONFIG_X86_PAE */
33255
33256-static void free_pmds(pmd_t *pmds[])
33257+static void free_pxds(pxd_t *pxds[])
33258 {
33259 int i;
33260
33261- for(i = 0; i < PREALLOCATED_PMDS; i++)
33262- if (pmds[i]) {
33263- pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33264- free_page((unsigned long)pmds[i]);
33265+ for(i = 0; i < PREALLOCATED_PXDS; i++)
33266+ if (pxds[i]) {
33267+ pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33268+ free_page((unsigned long)pxds[i]);
33269 }
33270 }
33271
33272-static int preallocate_pmds(pmd_t *pmds[])
33273+static int preallocate_pxds(pxd_t *pxds[])
33274 {
33275 int i;
33276 bool failed = false;
33277
33278- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33279- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33280- if (!pmd)
33281+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33282+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33283+ if (!pxd)
33284 failed = true;
33285- if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33286- free_page((unsigned long)pmd);
33287- pmd = NULL;
33288+ if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33289+ free_page((unsigned long)pxd);
33290+ pxd = NULL;
33291 failed = true;
33292 }
33293- pmds[i] = pmd;
33294+ pxds[i] = pxd;
33295 }
33296
33297 if (failed) {
33298- free_pmds(pmds);
33299+ free_pxds(pxds);
33300 return -ENOMEM;
33301 }
33302
33303@@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33304 * preallocate which never got a corresponding vma will need to be
33305 * freed manually.
33306 */
33307-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33308+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33309 {
33310 int i;
33311
33312- for(i = 0; i < PREALLOCATED_PMDS; i++) {
33313+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
33314 pgd_t pgd = pgdp[i];
33315
33316 if (pgd_val(pgd) != 0) {
33317- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33318+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33319
33320- pgdp[i] = native_make_pgd(0);
33321+ set_pgd(pgdp + i, native_make_pgd(0));
33322
33323- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33324- pmd_free(mm, pmd);
33325+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33326+ pxd_free(mm, pxd);
33327 }
33328 }
33329 }
33330
33331-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33332+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33333 {
33334- pud_t *pud;
33335+ pyd_t *pyd;
33336 int i;
33337
33338- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33339+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33340 return;
33341
33342- pud = pud_offset(pgd, 0);
33343-
33344- for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33345- pmd_t *pmd = pmds[i];
33346+#ifdef CONFIG_X86_64
33347+ pyd = pyd_offset(mm, 0L);
33348+#else
33349+ pyd = pyd_offset(pgd, 0L);
33350+#endif
33351
33352+ for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33353+ pxd_t *pxd = pxds[i];
33354 if (i >= KERNEL_PGD_BOUNDARY)
33355- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33356- sizeof(pmd_t) * PTRS_PER_PMD);
33357+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33358+ sizeof(pxd_t) * PTRS_PER_PMD);
33359
33360- pud_populate(mm, pud, pmd);
33361+ pyd_populate(mm, pyd, pxd);
33362 }
33363 }
33364
33365 pgd_t *pgd_alloc(struct mm_struct *mm)
33366 {
33367 pgd_t *pgd;
33368- pmd_t *pmds[PREALLOCATED_PMDS];
33369+ pxd_t *pxds[PREALLOCATED_PXDS];
33370
33371 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33372
33373@@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33374
33375 mm->pgd = pgd;
33376
33377- if (preallocate_pmds(pmds) != 0)
33378+ if (preallocate_pxds(pxds) != 0)
33379 goto out_free_pgd;
33380
33381 if (paravirt_pgd_alloc(mm) != 0)
33382- goto out_free_pmds;
33383+ goto out_free_pxds;
33384
33385 /*
33386 * Make sure that pre-populating the pmds is atomic with
33387@@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33388 spin_lock(&pgd_lock);
33389
33390 pgd_ctor(mm, pgd);
33391- pgd_prepopulate_pmd(mm, pgd, pmds);
33392+ pgd_prepopulate_pxd(mm, pgd, pxds);
33393
33394 spin_unlock(&pgd_lock);
33395
33396 return pgd;
33397
33398-out_free_pmds:
33399- free_pmds(pmds);
33400+out_free_pxds:
33401+ free_pxds(pxds);
33402 out_free_pgd:
33403 free_page((unsigned long)pgd);
33404 out:
33405@@ -313,7 +380,7 @@ out:
33406
33407 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33408 {
33409- pgd_mop_up_pmds(mm, pgd);
33410+ pgd_mop_up_pxds(mm, pgd);
33411 pgd_dtor(pgd);
33412 paravirt_pgd_free(mm, pgd);
33413 free_page((unsigned long)pgd);
33414diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33415index a69bcb8..19068ab 100644
33416--- a/arch/x86/mm/pgtable_32.c
33417+++ b/arch/x86/mm/pgtable_32.c
33418@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33419 return;
33420 }
33421 pte = pte_offset_kernel(pmd, vaddr);
33422+
33423+ pax_open_kernel();
33424 if (pte_val(pteval))
33425 set_pte_at(&init_mm, vaddr, pte, pteval);
33426 else
33427 pte_clear(&init_mm, vaddr, pte);
33428+ pax_close_kernel();
33429
33430 /*
33431 * It's enough to flush this one mapping.
33432diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33433index e666cbb..61788c45 100644
33434--- a/arch/x86/mm/physaddr.c
33435+++ b/arch/x86/mm/physaddr.c
33436@@ -10,7 +10,7 @@
33437 #ifdef CONFIG_X86_64
33438
33439 #ifdef CONFIG_DEBUG_VIRTUAL
33440-unsigned long __phys_addr(unsigned long x)
33441+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33442 {
33443 unsigned long y = x - __START_KERNEL_map;
33444
33445@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33446 #else
33447
33448 #ifdef CONFIG_DEBUG_VIRTUAL
33449-unsigned long __phys_addr(unsigned long x)
33450+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33451 {
33452 unsigned long phys_addr = x - PAGE_OFFSET;
33453 /* VMALLOC_* aren't constants */
33454diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33455index 90555bf..f5f1828 100644
33456--- a/arch/x86/mm/setup_nx.c
33457+++ b/arch/x86/mm/setup_nx.c
33458@@ -5,8 +5,10 @@
33459 #include <asm/pgtable.h>
33460 #include <asm/proto.h>
33461
33462+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33463 static int disable_nx;
33464
33465+#ifndef CONFIG_PAX_PAGEEXEC
33466 /*
33467 * noexec = on|off
33468 *
33469@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33470 return 0;
33471 }
33472 early_param("noexec", noexec_setup);
33473+#endif
33474+
33475+#endif
33476
33477 void x86_configure_nx(void)
33478 {
33479+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33480 if (cpu_has_nx && !disable_nx)
33481 __supported_pte_mask |= _PAGE_NX;
33482 else
33483+#endif
33484 __supported_pte_mask &= ~_PAGE_NX;
33485 }
33486
33487diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33488index ae699b3..f1b2ad2 100644
33489--- a/arch/x86/mm/tlb.c
33490+++ b/arch/x86/mm/tlb.c
33491@@ -48,7 +48,11 @@ void leave_mm(int cpu)
33492 BUG();
33493 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33494 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33495+
33496+#ifndef CONFIG_PAX_PER_CPU_PGD
33497 load_cr3(swapper_pg_dir);
33498+#endif
33499+
33500 }
33501 }
33502 EXPORT_SYMBOL_GPL(leave_mm);
33503diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33504new file mode 100644
33505index 0000000..dace51c
33506--- /dev/null
33507+++ b/arch/x86/mm/uderef_64.c
33508@@ -0,0 +1,37 @@
33509+#include <linux/mm.h>
33510+#include <asm/pgtable.h>
33511+#include <asm/uaccess.h>
33512+
33513+#ifdef CONFIG_PAX_MEMORY_UDEREF
33514+/* PaX: due to the special call convention these functions must
33515+ * - remain leaf functions under all configurations,
33516+ * - never be called directly, only dereferenced from the wrappers.
33517+ */
33518+void __pax_open_userland(void)
33519+{
33520+ unsigned int cpu;
33521+
33522+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33523+ return;
33524+
33525+ cpu = raw_get_cpu();
33526+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33527+ write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33528+ raw_put_cpu_no_resched();
33529+}
33530+EXPORT_SYMBOL(__pax_open_userland);
33531+
33532+void __pax_close_userland(void)
33533+{
33534+ unsigned int cpu;
33535+
33536+ if (unlikely(!segment_eq(get_fs(), USER_DS)))
33537+ return;
33538+
33539+ cpu = raw_get_cpu();
33540+ BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33541+ write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33542+ raw_put_cpu_no_resched();
33543+}
33544+EXPORT_SYMBOL(__pax_close_userland);
33545+#endif
33546diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33547index 0149575..f746de8 100644
33548--- a/arch/x86/net/bpf_jit.S
33549+++ b/arch/x86/net/bpf_jit.S
33550@@ -9,6 +9,7 @@
33551 */
33552 #include <linux/linkage.h>
33553 #include <asm/dwarf2.h>
33554+#include <asm/alternative-asm.h>
33555
33556 /*
33557 * Calling convention :
33558@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33559 jle bpf_slow_path_word
33560 mov (SKBDATA,%rsi),%eax
33561 bswap %eax /* ntohl() */
33562+ pax_force_retaddr
33563 ret
33564
33565 sk_load_half:
33566@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33567 jle bpf_slow_path_half
33568 movzwl (SKBDATA,%rsi),%eax
33569 rol $8,%ax # ntohs()
33570+ pax_force_retaddr
33571 ret
33572
33573 sk_load_byte:
33574@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33575 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33576 jle bpf_slow_path_byte
33577 movzbl (SKBDATA,%rsi),%eax
33578+ pax_force_retaddr
33579 ret
33580
33581 /**
33582@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33583 movzbl (SKBDATA,%rsi),%ebx
33584 and $15,%bl
33585 shl $2,%bl
33586+ pax_force_retaddr
33587 ret
33588
33589 /* rsi contains offset and can be scratched */
33590@@ -109,6 +114,7 @@ bpf_slow_path_word:
33591 js bpf_error
33592 mov -12(%rbp),%eax
33593 bswap %eax
33594+ pax_force_retaddr
33595 ret
33596
33597 bpf_slow_path_half:
33598@@ -117,12 +123,14 @@ bpf_slow_path_half:
33599 mov -12(%rbp),%ax
33600 rol $8,%ax
33601 movzwl %ax,%eax
33602+ pax_force_retaddr
33603 ret
33604
33605 bpf_slow_path_byte:
33606 bpf_slow_path_common(1)
33607 js bpf_error
33608 movzbl -12(%rbp),%eax
33609+ pax_force_retaddr
33610 ret
33611
33612 bpf_slow_path_byte_msh:
33613@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33614 and $15,%al
33615 shl $2,%al
33616 xchg %eax,%ebx
33617+ pax_force_retaddr
33618 ret
33619
33620 #define sk_negative_common(SIZE) \
33621@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33622 sk_negative_common(4)
33623 mov (%rax), %eax
33624 bswap %eax
33625+ pax_force_retaddr
33626 ret
33627
33628 bpf_slow_path_half_neg:
33629@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33630 mov (%rax),%ax
33631 rol $8,%ax
33632 movzwl %ax,%eax
33633+ pax_force_retaddr
33634 ret
33635
33636 bpf_slow_path_byte_neg:
33637@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33638 .globl sk_load_byte_negative_offset
33639 sk_negative_common(1)
33640 movzbl (%rax), %eax
33641+ pax_force_retaddr
33642 ret
33643
33644 bpf_slow_path_byte_msh_neg:
33645@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33646 and $15,%al
33647 shl $2,%al
33648 xchg %eax,%ebx
33649+ pax_force_retaddr
33650 ret
33651
33652 bpf_error:
33653@@ -197,4 +210,5 @@ bpf_error:
33654 xor %eax,%eax
33655 mov -8(%rbp),%rbx
33656 leaveq
33657+ pax_force_retaddr
33658 ret
33659diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33660index 4ed75dd..3cf24f0b 100644
33661--- a/arch/x86/net/bpf_jit_comp.c
33662+++ b/arch/x86/net/bpf_jit_comp.c
33663@@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33664 return ptr + len;
33665 }
33666
33667+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33668+#define MAX_INSTR_CODE_SIZE 96
33669+#else
33670+#define MAX_INSTR_CODE_SIZE 64
33671+#endif
33672+
33673 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33674
33675 #define EMIT1(b1) EMIT(b1, 1)
33676 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33677 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33678 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33679+
33680+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33681+/* original constant will appear in ecx */
33682+#define DILUTE_CONST_SEQUENCE(_off, _key) \
33683+do { \
33684+ /* mov ecx, randkey */ \
33685+ EMIT1(0xb9); \
33686+ EMIT(_key, 4); \
33687+ /* xor ecx, randkey ^ off */ \
33688+ EMIT2(0x81, 0xf1); \
33689+ EMIT((_key) ^ (_off), 4); \
33690+} while (0)
33691+
33692+#define EMIT1_off32(b1, _off) \
33693+do { \
33694+ switch (b1) { \
33695+ case 0x05: /* add eax, imm32 */ \
33696+ case 0x2d: /* sub eax, imm32 */ \
33697+ case 0x25: /* and eax, imm32 */ \
33698+ case 0x0d: /* or eax, imm32 */ \
33699+ case 0xb8: /* mov eax, imm32 */ \
33700+ case 0x35: /* xor eax, imm32 */ \
33701+ case 0x3d: /* cmp eax, imm32 */ \
33702+ case 0xa9: /* test eax, imm32 */ \
33703+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33704+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33705+ break; \
33706+ case 0xbb: /* mov ebx, imm32 */ \
33707+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33708+ /* mov ebx, ecx */ \
33709+ EMIT2(0x89, 0xcb); \
33710+ break; \
33711+ case 0xbe: /* mov esi, imm32 */ \
33712+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33713+ /* mov esi, ecx */ \
33714+ EMIT2(0x89, 0xce); \
33715+ break; \
33716+ case 0xe8: /* call rel imm32, always to known funcs */ \
33717+ EMIT1(b1); \
33718+ EMIT(_off, 4); \
33719+ break; \
33720+ case 0xe9: /* jmp rel imm32 */ \
33721+ EMIT1(b1); \
33722+ EMIT(_off, 4); \
33723+ /* prevent fall-through, we're not called if off = 0 */ \
33724+ EMIT(0xcccccccc, 4); \
33725+ EMIT(0xcccccccc, 4); \
33726+ break; \
33727+ default: \
33728+ BUILD_BUG(); \
33729+ } \
33730+} while (0)
33731+
33732+#define EMIT2_off32(b1, b2, _off) \
33733+do { \
33734+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33735+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33736+ EMIT(randkey, 4); \
33737+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33738+ EMIT((_off) - randkey, 4); \
33739+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33740+ DILUTE_CONST_SEQUENCE(_off, randkey); \
33741+ /* imul eax, ecx */ \
33742+ EMIT3(0x0f, 0xaf, 0xc1); \
33743+ } else { \
33744+ BUILD_BUG(); \
33745+ } \
33746+} while (0)
33747+#else
33748 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33749+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33750+#endif
33751
33752 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33753 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33754@@ -91,6 +168,24 @@ do { \
33755 #define X86_JBE 0x76
33756 #define X86_JA 0x77
33757
33758+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33759+#define APPEND_FLOW_VERIFY() \
33760+do { \
33761+ /* mov ecx, randkey */ \
33762+ EMIT1(0xb9); \
33763+ EMIT(randkey, 4); \
33764+ /* cmp ecx, randkey */ \
33765+ EMIT2(0x81, 0xf9); \
33766+ EMIT(randkey, 4); \
33767+ /* jz after 8 int 3s */ \
33768+ EMIT2(0x74, 0x08); \
33769+ EMIT(0xcccccccc, 4); \
33770+ EMIT(0xcccccccc, 4); \
33771+} while (0)
33772+#else
33773+#define APPEND_FLOW_VERIFY() do { } while (0)
33774+#endif
33775+
33776 #define EMIT_COND_JMP(op, offset) \
33777 do { \
33778 if (is_near(offset)) \
33779@@ -98,6 +193,7 @@ do { \
33780 else { \
33781 EMIT2(0x0f, op + 0x10); \
33782 EMIT(offset, 4); /* jxx .+off32 */ \
33783+ APPEND_FLOW_VERIFY(); \
33784 } \
33785 } while (0)
33786
33787@@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33788 return -1;
33789 }
33790
33791-struct bpf_binary_header {
33792- unsigned int pages;
33793- /* Note : for security reasons, bpf code will follow a randomly
33794- * sized amount of int3 instructions
33795- */
33796- u8 image[];
33797-};
33798-
33799-static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33800+/* Note : for security reasons, bpf code will follow a randomly
33801+ * sized amount of int3 instructions
33802+ */
33803+static u8 *bpf_alloc_binary(unsigned int proglen,
33804 u8 **image_ptr)
33805 {
33806 unsigned int sz, hole;
33807- struct bpf_binary_header *header;
33808+ u8 *header;
33809
33810 /* Most of BPF filters are really small,
33811 * but if some of them fill a page, allow at least
33812 * 128 extra bytes to insert a random section of int3
33813 */
33814- sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33815- header = module_alloc(sz);
33816+ sz = round_up(proglen + 128, PAGE_SIZE);
33817+ header = module_alloc_exec(sz);
33818 if (!header)
33819 return NULL;
33820
33821+ pax_open_kernel();
33822 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33823+ pax_close_kernel();
33824
33825- header->pages = sz / PAGE_SIZE;
33826- hole = sz - (proglen + sizeof(*header));
33827+ hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33828
33829 /* insert a random number of int3 instructions before BPF code */
33830- *image_ptr = &header->image[prandom_u32() % hole];
33831+ *image_ptr = &header[prandom_u32() % hole];
33832 return header;
33833 }
33834
33835 void bpf_jit_compile(struct sk_filter *fp)
33836 {
33837- u8 temp[64];
33838+ u8 temp[MAX_INSTR_CODE_SIZE];
33839 u8 *prog;
33840 unsigned int proglen, oldproglen = 0;
33841 int ilen, i;
33842 int t_offset, f_offset;
33843 u8 t_op, f_op, seen = 0, pass;
33844 u8 *image = NULL;
33845- struct bpf_binary_header *header = NULL;
33846+ u8 *header = NULL;
33847 u8 *func;
33848 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33849 unsigned int cleanup_addr; /* epilogue code offset */
33850 unsigned int *addrs;
33851 const struct sock_filter *filter = fp->insns;
33852 int flen = fp->len;
33853+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854+ unsigned int randkey;
33855+#endif
33856
33857 if (!bpf_jit_enable)
33858 return;
33859@@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33860 return;
33861
33862 /* Before first pass, make a rough estimation of addrs[]
33863- * each bpf instruction is translated to less than 64 bytes
33864+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33865 */
33866 for (proglen = 0, i = 0; i < flen; i++) {
33867- proglen += 64;
33868+ proglen += MAX_INSTR_CODE_SIZE;
33869 addrs[i] = proglen;
33870 }
33871 cleanup_addr = proglen; /* epilogue address */
33872@@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
33873 for (i = 0; i < flen; i++) {
33874 unsigned int K = filter[i].k;
33875
33876+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33877+ randkey = prandom_u32();
33878+#endif
33879+
33880 switch (filter[i].code) {
33881 case BPF_S_ALU_ADD_X: /* A += X; */
33882 seen |= SEEN_XREG;
33883@@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33884 case BPF_S_ALU_MUL_K: /* A *= K */
33885 if (is_imm8(K))
33886 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33887- else {
33888- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33889- EMIT(K, 4);
33890- }
33891+ else
33892+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33893 break;
33894 case BPF_S_ALU_DIV_X: /* A /= X; */
33895 seen |= SEEN_XREG;
33896@@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33897 break;
33898 }
33899 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33900+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33901+ DILUTE_CONST_SEQUENCE(K, randkey);
33902+#else
33903 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33904+#endif
33905 EMIT2(0xf7, 0xf1); /* div %ecx */
33906 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33907 break;
33908@@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33909 if (K == 1)
33910 break;
33911 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33912+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33913+ DILUTE_CONST_SEQUENCE(K, randkey);
33914+#else
33915 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33916+#endif
33917 EMIT2(0xf7, 0xf1); /* div %ecx */
33918 break;
33919 case BPF_S_ALU_AND_X:
33920@@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33921 if (is_imm8(K)) {
33922 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33923 } else {
33924- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33925- EMIT(K, 4);
33926+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33927 }
33928 } else {
33929 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33930@@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33931 if (unlikely(proglen + ilen > oldproglen)) {
33932 pr_err("bpb_jit_compile fatal error\n");
33933 kfree(addrs);
33934- module_free(NULL, header);
33935+ module_free_exec(NULL, image);
33936 return;
33937 }
33938+ pax_open_kernel();
33939 memcpy(image + proglen, temp, ilen);
33940+ pax_close_kernel();
33941 }
33942 proglen += ilen;
33943 addrs[i] = proglen;
33944@@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33945
33946 if (image) {
33947 bpf_flush_icache(header, image + proglen);
33948- set_memory_ro((unsigned long)header, header->pages);
33949 fp->bpf_func = (void *)image;
33950 }
33951 out:
33952@@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33953 {
33954 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33955 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33956- struct bpf_binary_header *header = (void *)addr;
33957
33958- set_memory_rw(addr, header->pages);
33959- module_free(NULL, header);
33960+ set_memory_rw(addr, 1);
33961+ module_free_exec(NULL, (void *)addr);
33962 kfree(fp);
33963 }
33964
33965diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33966index 5d04be5..2beeaa2 100644
33967--- a/arch/x86/oprofile/backtrace.c
33968+++ b/arch/x86/oprofile/backtrace.c
33969@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33970 struct stack_frame_ia32 *fp;
33971 unsigned long bytes;
33972
33973- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33974+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33975 if (bytes != 0)
33976 return NULL;
33977
33978- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33979+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33980
33981 oprofile_add_trace(bufhead[0].return_address);
33982
33983@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33984 struct stack_frame bufhead[2];
33985 unsigned long bytes;
33986
33987- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33988+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33989 if (bytes != 0)
33990 return NULL;
33991
33992@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33993 {
33994 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33995
33996- if (!user_mode_vm(regs)) {
33997+ if (!user_mode(regs)) {
33998 unsigned long stack = kernel_stack_pointer(regs);
33999 if (depth)
34000 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34001diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34002index 6890d84..1dad1f1 100644
34003--- a/arch/x86/oprofile/nmi_int.c
34004+++ b/arch/x86/oprofile/nmi_int.c
34005@@ -23,6 +23,7 @@
34006 #include <asm/nmi.h>
34007 #include <asm/msr.h>
34008 #include <asm/apic.h>
34009+#include <asm/pgtable.h>
34010
34011 #include "op_counter.h"
34012 #include "op_x86_model.h"
34013@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34014 if (ret)
34015 return ret;
34016
34017- if (!model->num_virt_counters)
34018- model->num_virt_counters = model->num_counters;
34019+ if (!model->num_virt_counters) {
34020+ pax_open_kernel();
34021+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
34022+ pax_close_kernel();
34023+ }
34024
34025 mux_init(ops);
34026
34027diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34028index 50d86c0..7985318 100644
34029--- a/arch/x86/oprofile/op_model_amd.c
34030+++ b/arch/x86/oprofile/op_model_amd.c
34031@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34032 num_counters = AMD64_NUM_COUNTERS;
34033 }
34034
34035- op_amd_spec.num_counters = num_counters;
34036- op_amd_spec.num_controls = num_counters;
34037- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34038+ pax_open_kernel();
34039+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34040+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34041+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34042+ pax_close_kernel();
34043
34044 return 0;
34045 }
34046diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34047index d90528e..0127e2b 100644
34048--- a/arch/x86/oprofile/op_model_ppro.c
34049+++ b/arch/x86/oprofile/op_model_ppro.c
34050@@ -19,6 +19,7 @@
34051 #include <asm/msr.h>
34052 #include <asm/apic.h>
34053 #include <asm/nmi.h>
34054+#include <asm/pgtable.h>
34055
34056 #include "op_x86_model.h"
34057 #include "op_counter.h"
34058@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34059
34060 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34061
34062- op_arch_perfmon_spec.num_counters = num_counters;
34063- op_arch_perfmon_spec.num_controls = num_counters;
34064+ pax_open_kernel();
34065+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34066+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34067+ pax_close_kernel();
34068 }
34069
34070 static int arch_perfmon_init(struct oprofile_operations *ignore)
34071diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34072index 71e8a67..6a313bb 100644
34073--- a/arch/x86/oprofile/op_x86_model.h
34074+++ b/arch/x86/oprofile/op_x86_model.h
34075@@ -52,7 +52,7 @@ struct op_x86_model_spec {
34076 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34077 struct op_msrs const * const msrs);
34078 #endif
34079-};
34080+} __do_const;
34081
34082 struct op_counter_config;
34083
34084diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34085index 51384ca..a25f51e 100644
34086--- a/arch/x86/pci/intel_mid_pci.c
34087+++ b/arch/x86/pci/intel_mid_pci.c
34088@@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
34089 pr_info("Intel MID platform detected, using MID PCI ops\n");
34090 pci_mmcfg_late_init();
34091 pcibios_enable_irq = intel_mid_pci_irq_enable;
34092- pci_root_ops = intel_mid_pci_ops;
34093+ memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34094 pci_soc_mode = 1;
34095 /* Continue with standard init */
34096 return 1;
34097diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34098index 372e9b8..e775a6c 100644
34099--- a/arch/x86/pci/irq.c
34100+++ b/arch/x86/pci/irq.c
34101@@ -50,7 +50,7 @@ struct irq_router {
34102 struct irq_router_handler {
34103 u16 vendor;
34104 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34105-};
34106+} __do_const;
34107
34108 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34109 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34110@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34111 return 0;
34112 }
34113
34114-static __initdata struct irq_router_handler pirq_routers[] = {
34115+static __initconst const struct irq_router_handler pirq_routers[] = {
34116 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34117 { PCI_VENDOR_ID_AL, ali_router_probe },
34118 { PCI_VENDOR_ID_ITE, ite_router_probe },
34119@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
34120 static void __init pirq_find_router(struct irq_router *r)
34121 {
34122 struct irq_routing_table *rt = pirq_table;
34123- struct irq_router_handler *h;
34124+ const struct irq_router_handler *h;
34125
34126 #ifdef CONFIG_PCI_BIOS
34127 if (!rt->signature) {
34128@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34129 return 0;
34130 }
34131
34132-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34133+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34134 {
34135 .callback = fix_broken_hp_bios_irq9,
34136 .ident = "HP Pavilion N5400 Series Laptop",
34137diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34138index c77b24a..c979855 100644
34139--- a/arch/x86/pci/pcbios.c
34140+++ b/arch/x86/pci/pcbios.c
34141@@ -79,7 +79,7 @@ union bios32 {
34142 static struct {
34143 unsigned long address;
34144 unsigned short segment;
34145-} bios32_indirect = { 0, __KERNEL_CS };
34146+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34147
34148 /*
34149 * Returns the entry point for the given service, NULL on error
34150@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34151 unsigned long length; /* %ecx */
34152 unsigned long entry; /* %edx */
34153 unsigned long flags;
34154+ struct desc_struct d, *gdt;
34155
34156 local_irq_save(flags);
34157- __asm__("lcall *(%%edi); cld"
34158+
34159+ gdt = get_cpu_gdt_table(smp_processor_id());
34160+
34161+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34162+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34163+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34164+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34165+
34166+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34167 : "=a" (return_code),
34168 "=b" (address),
34169 "=c" (length),
34170 "=d" (entry)
34171 : "0" (service),
34172 "1" (0),
34173- "D" (&bios32_indirect));
34174+ "D" (&bios32_indirect),
34175+ "r"(__PCIBIOS_DS)
34176+ : "memory");
34177+
34178+ pax_open_kernel();
34179+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34180+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34181+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34182+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34183+ pax_close_kernel();
34184+
34185 local_irq_restore(flags);
34186
34187 switch (return_code) {
34188- case 0:
34189- return address + entry;
34190- case 0x80: /* Not present */
34191- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34192- return 0;
34193- default: /* Shouldn't happen */
34194- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34195- service, return_code);
34196+ case 0: {
34197+ int cpu;
34198+ unsigned char flags;
34199+
34200+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34201+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34202+ printk(KERN_WARNING "bios32_service: not valid\n");
34203 return 0;
34204+ }
34205+ address = address + PAGE_OFFSET;
34206+ length += 16UL; /* some BIOSs underreport this... */
34207+ flags = 4;
34208+ if (length >= 64*1024*1024) {
34209+ length >>= PAGE_SHIFT;
34210+ flags |= 8;
34211+ }
34212+
34213+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34214+ gdt = get_cpu_gdt_table(cpu);
34215+ pack_descriptor(&d, address, length, 0x9b, flags);
34216+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34217+ pack_descriptor(&d, address, length, 0x93, flags);
34218+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34219+ }
34220+ return entry;
34221+ }
34222+ case 0x80: /* Not present */
34223+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34224+ return 0;
34225+ default: /* Shouldn't happen */
34226+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34227+ service, return_code);
34228+ return 0;
34229 }
34230 }
34231
34232 static struct {
34233 unsigned long address;
34234 unsigned short segment;
34235-} pci_indirect = { 0, __KERNEL_CS };
34236+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34237
34238-static int pci_bios_present;
34239+static int pci_bios_present __read_only;
34240
34241 static int check_pcibios(void)
34242 {
34243@@ -131,11 +174,13 @@ static int check_pcibios(void)
34244 unsigned long flags, pcibios_entry;
34245
34246 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34247- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34248+ pci_indirect.address = pcibios_entry;
34249
34250 local_irq_save(flags);
34251- __asm__(
34252- "lcall *(%%edi); cld\n\t"
34253+ __asm__("movw %w6, %%ds\n\t"
34254+ "lcall *%%ss:(%%edi); cld\n\t"
34255+ "push %%ss\n\t"
34256+ "pop %%ds\n\t"
34257 "jc 1f\n\t"
34258 "xor %%ah, %%ah\n"
34259 "1:"
34260@@ -144,7 +189,8 @@ static int check_pcibios(void)
34261 "=b" (ebx),
34262 "=c" (ecx)
34263 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34264- "D" (&pci_indirect)
34265+ "D" (&pci_indirect),
34266+ "r" (__PCIBIOS_DS)
34267 : "memory");
34268 local_irq_restore(flags);
34269
34270@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34271
34272 switch (len) {
34273 case 1:
34274- __asm__("lcall *(%%esi); cld\n\t"
34275+ __asm__("movw %w6, %%ds\n\t"
34276+ "lcall *%%ss:(%%esi); cld\n\t"
34277+ "push %%ss\n\t"
34278+ "pop %%ds\n\t"
34279 "jc 1f\n\t"
34280 "xor %%ah, %%ah\n"
34281 "1:"
34282@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34283 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34284 "b" (bx),
34285 "D" ((long)reg),
34286- "S" (&pci_indirect));
34287+ "S" (&pci_indirect),
34288+ "r" (__PCIBIOS_DS));
34289 /*
34290 * Zero-extend the result beyond 8 bits, do not trust the
34291 * BIOS having done it:
34292@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34293 *value &= 0xff;
34294 break;
34295 case 2:
34296- __asm__("lcall *(%%esi); cld\n\t"
34297+ __asm__("movw %w6, %%ds\n\t"
34298+ "lcall *%%ss:(%%esi); cld\n\t"
34299+ "push %%ss\n\t"
34300+ "pop %%ds\n\t"
34301 "jc 1f\n\t"
34302 "xor %%ah, %%ah\n"
34303 "1:"
34304@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34305 : "1" (PCIBIOS_READ_CONFIG_WORD),
34306 "b" (bx),
34307 "D" ((long)reg),
34308- "S" (&pci_indirect));
34309+ "S" (&pci_indirect),
34310+ "r" (__PCIBIOS_DS));
34311 /*
34312 * Zero-extend the result beyond 16 bits, do not trust the
34313 * BIOS having done it:
34314@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34315 *value &= 0xffff;
34316 break;
34317 case 4:
34318- __asm__("lcall *(%%esi); cld\n\t"
34319+ __asm__("movw %w6, %%ds\n\t"
34320+ "lcall *%%ss:(%%esi); cld\n\t"
34321+ "push %%ss\n\t"
34322+ "pop %%ds\n\t"
34323 "jc 1f\n\t"
34324 "xor %%ah, %%ah\n"
34325 "1:"
34326@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34327 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34328 "b" (bx),
34329 "D" ((long)reg),
34330- "S" (&pci_indirect));
34331+ "S" (&pci_indirect),
34332+ "r" (__PCIBIOS_DS));
34333 break;
34334 }
34335
34336@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34337
34338 switch (len) {
34339 case 1:
34340- __asm__("lcall *(%%esi); cld\n\t"
34341+ __asm__("movw %w6, %%ds\n\t"
34342+ "lcall *%%ss:(%%esi); cld\n\t"
34343+ "push %%ss\n\t"
34344+ "pop %%ds\n\t"
34345 "jc 1f\n\t"
34346 "xor %%ah, %%ah\n"
34347 "1:"
34348@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34349 "c" (value),
34350 "b" (bx),
34351 "D" ((long)reg),
34352- "S" (&pci_indirect));
34353+ "S" (&pci_indirect),
34354+ "r" (__PCIBIOS_DS));
34355 break;
34356 case 2:
34357- __asm__("lcall *(%%esi); cld\n\t"
34358+ __asm__("movw %w6, %%ds\n\t"
34359+ "lcall *%%ss:(%%esi); cld\n\t"
34360+ "push %%ss\n\t"
34361+ "pop %%ds\n\t"
34362 "jc 1f\n\t"
34363 "xor %%ah, %%ah\n"
34364 "1:"
34365@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34366 "c" (value),
34367 "b" (bx),
34368 "D" ((long)reg),
34369- "S" (&pci_indirect));
34370+ "S" (&pci_indirect),
34371+ "r" (__PCIBIOS_DS));
34372 break;
34373 case 4:
34374- __asm__("lcall *(%%esi); cld\n\t"
34375+ __asm__("movw %w6, %%ds\n\t"
34376+ "lcall *%%ss:(%%esi); cld\n\t"
34377+ "push %%ss\n\t"
34378+ "pop %%ds\n\t"
34379 "jc 1f\n\t"
34380 "xor %%ah, %%ah\n"
34381 "1:"
34382@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34383 "c" (value),
34384 "b" (bx),
34385 "D" ((long)reg),
34386- "S" (&pci_indirect));
34387+ "S" (&pci_indirect),
34388+ "r" (__PCIBIOS_DS));
34389 break;
34390 }
34391
34392@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34393
34394 DBG("PCI: Fetching IRQ routing table... ");
34395 __asm__("push %%es\n\t"
34396+ "movw %w8, %%ds\n\t"
34397 "push %%ds\n\t"
34398 "pop %%es\n\t"
34399- "lcall *(%%esi); cld\n\t"
34400+ "lcall *%%ss:(%%esi); cld\n\t"
34401 "pop %%es\n\t"
34402+ "push %%ss\n\t"
34403+ "pop %%ds\n"
34404 "jc 1f\n\t"
34405 "xor %%ah, %%ah\n"
34406 "1:"
34407@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34408 "1" (0),
34409 "D" ((long) &opt),
34410 "S" (&pci_indirect),
34411- "m" (opt)
34412+ "m" (opt),
34413+ "r" (__PCIBIOS_DS)
34414 : "memory");
34415 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34416 if (ret & 0xff00)
34417@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34418 {
34419 int ret;
34420
34421- __asm__("lcall *(%%esi); cld\n\t"
34422+ __asm__("movw %w5, %%ds\n\t"
34423+ "lcall *%%ss:(%%esi); cld\n\t"
34424+ "push %%ss\n\t"
34425+ "pop %%ds\n"
34426 "jc 1f\n\t"
34427 "xor %%ah, %%ah\n"
34428 "1:"
34429@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34430 : "0" (PCIBIOS_SET_PCI_HW_INT),
34431 "b" ((dev->bus->number << 8) | dev->devfn),
34432 "c" ((irq << 8) | (pin + 10)),
34433- "S" (&pci_indirect));
34434+ "S" (&pci_indirect),
34435+ "r" (__PCIBIOS_DS));
34436 return !(ret & 0xff00);
34437 }
34438 EXPORT_SYMBOL(pcibios_set_irq_routing);
34439diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34440index 40e4469..d915bf9 100644
34441--- a/arch/x86/platform/efi/efi_32.c
34442+++ b/arch/x86/platform/efi/efi_32.c
34443@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
34444 {
34445 struct desc_ptr gdt_descr;
34446
34447+#ifdef CONFIG_PAX_KERNEXEC
34448+ struct desc_struct d;
34449+#endif
34450+
34451 local_irq_save(efi_rt_eflags);
34452
34453 load_cr3(initial_page_table);
34454 __flush_tlb_all();
34455
34456+#ifdef CONFIG_PAX_KERNEXEC
34457+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34458+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34459+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34460+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34461+#endif
34462+
34463 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34464 gdt_descr.size = GDT_SIZE - 1;
34465 load_gdt(&gdt_descr);
34466@@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
34467 {
34468 struct desc_ptr gdt_descr;
34469
34470+#ifdef CONFIG_PAX_KERNEXEC
34471+ struct desc_struct d;
34472+
34473+ memset(&d, 0, sizeof d);
34474+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34475+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34476+#endif
34477+
34478 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34479 gdt_descr.size = GDT_SIZE - 1;
34480 load_gdt(&gdt_descr);
34481
34482+#ifdef CONFIG_PAX_PER_CPU_PGD
34483+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34484+#else
34485 load_cr3(swapper_pg_dir);
34486+#endif
34487+
34488 __flush_tlb_all();
34489
34490 local_irq_restore(efi_rt_eflags);
34491diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34492index 39a0e7f1..872396e 100644
34493--- a/arch/x86/platform/efi/efi_64.c
34494+++ b/arch/x86/platform/efi/efi_64.c
34495@@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
34496 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34497 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34498 }
34499+
34500+#ifdef CONFIG_PAX_PER_CPU_PGD
34501+ load_cr3(swapper_pg_dir);
34502+#endif
34503+
34504 __flush_tlb_all();
34505 }
34506
34507@@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
34508 for (pgd = 0; pgd < n_pgds; pgd++)
34509 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34510 kfree(save_pgd);
34511+
34512+#ifdef CONFIG_PAX_PER_CPU_PGD
34513+ load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34514+#endif
34515+
34516 __flush_tlb_all();
34517 local_irq_restore(efi_flags);
34518 early_code_mapping_set_exec(0);
34519diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34520index fbe66e6..eae5e38 100644
34521--- a/arch/x86/platform/efi/efi_stub_32.S
34522+++ b/arch/x86/platform/efi/efi_stub_32.S
34523@@ -6,7 +6,9 @@
34524 */
34525
34526 #include <linux/linkage.h>
34527+#include <linux/init.h>
34528 #include <asm/page_types.h>
34529+#include <asm/segment.h>
34530
34531 /*
34532 * efi_call_phys(void *, ...) is a function with variable parameters.
34533@@ -20,7 +22,7 @@
34534 * service functions will comply with gcc calling convention, too.
34535 */
34536
34537-.text
34538+__INIT
34539 ENTRY(efi_call_phys)
34540 /*
34541 * 0. The function can only be called in Linux kernel. So CS has been
34542@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34543 * The mapping of lower virtual memory has been created in prelog and
34544 * epilog.
34545 */
34546- movl $1f, %edx
34547- subl $__PAGE_OFFSET, %edx
34548- jmp *%edx
34549+#ifdef CONFIG_PAX_KERNEXEC
34550+ movl $(__KERNEXEC_EFI_DS), %edx
34551+ mov %edx, %ds
34552+ mov %edx, %es
34553+ mov %edx, %ss
34554+ addl $2f,(1f)
34555+ ljmp *(1f)
34556+
34557+__INITDATA
34558+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34559+.previous
34560+
34561+2:
34562+ subl $2b,(1b)
34563+#else
34564+ jmp 1f-__PAGE_OFFSET
34565 1:
34566+#endif
34567
34568 /*
34569 * 2. Now on the top of stack is the return
34570@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34571 * parameter 2, ..., param n. To make things easy, we save the return
34572 * address of efi_call_phys in a global variable.
34573 */
34574- popl %edx
34575- movl %edx, saved_return_addr
34576- /* get the function pointer into ECX*/
34577- popl %ecx
34578- movl %ecx, efi_rt_function_ptr
34579- movl $2f, %edx
34580- subl $__PAGE_OFFSET, %edx
34581- pushl %edx
34582+ popl (saved_return_addr)
34583+ popl (efi_rt_function_ptr)
34584
34585 /*
34586 * 3. Clear PG bit in %CR0.
34587@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34588 /*
34589 * 5. Call the physical function.
34590 */
34591- jmp *%ecx
34592+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
34593
34594-2:
34595 /*
34596 * 6. After EFI runtime service returns, control will return to
34597 * following instruction. We'd better readjust stack pointer first.
34598@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34599 movl %cr0, %edx
34600 orl $0x80000000, %edx
34601 movl %edx, %cr0
34602- jmp 1f
34603-1:
34604+
34605 /*
34606 * 8. Now restore the virtual mode from flat mode by
34607 * adding EIP with PAGE_OFFSET.
34608 */
34609- movl $1f, %edx
34610- jmp *%edx
34611+#ifdef CONFIG_PAX_KERNEXEC
34612+ movl $(__KERNEL_DS), %edx
34613+ mov %edx, %ds
34614+ mov %edx, %es
34615+ mov %edx, %ss
34616+ ljmp $(__KERNEL_CS),$1f
34617+#else
34618+ jmp 1f+__PAGE_OFFSET
34619+#endif
34620 1:
34621
34622 /*
34623 * 9. Balance the stack. And because EAX contain the return value,
34624 * we'd better not clobber it.
34625 */
34626- leal efi_rt_function_ptr, %edx
34627- movl (%edx), %ecx
34628- pushl %ecx
34629+ pushl (efi_rt_function_ptr)
34630
34631 /*
34632- * 10. Push the saved return address onto the stack and return.
34633+ * 10. Return to the saved return address.
34634 */
34635- leal saved_return_addr, %edx
34636- movl (%edx), %ecx
34637- pushl %ecx
34638- ret
34639+ jmpl *(saved_return_addr)
34640 ENDPROC(efi_call_phys)
34641 .previous
34642
34643-.data
34644+__INITDATA
34645 saved_return_addr:
34646 .long 0
34647 efi_rt_function_ptr:
34648diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34649index 4c07cca..2c8427d 100644
34650--- a/arch/x86/platform/efi/efi_stub_64.S
34651+++ b/arch/x86/platform/efi/efi_stub_64.S
34652@@ -7,6 +7,7 @@
34653 */
34654
34655 #include <linux/linkage.h>
34656+#include <asm/alternative-asm.h>
34657
34658 #define SAVE_XMM \
34659 mov %rsp, %rax; \
34660@@ -40,6 +41,7 @@ ENTRY(efi_call0)
34661 call *%rdi
34662 addq $32, %rsp
34663 RESTORE_XMM
34664+ pax_force_retaddr 0, 1
34665 ret
34666 ENDPROC(efi_call0)
34667
34668@@ -50,6 +52,7 @@ ENTRY(efi_call1)
34669 call *%rdi
34670 addq $32, %rsp
34671 RESTORE_XMM
34672+ pax_force_retaddr 0, 1
34673 ret
34674 ENDPROC(efi_call1)
34675
34676@@ -60,6 +63,7 @@ ENTRY(efi_call2)
34677 call *%rdi
34678 addq $32, %rsp
34679 RESTORE_XMM
34680+ pax_force_retaddr 0, 1
34681 ret
34682 ENDPROC(efi_call2)
34683
34684@@ -71,6 +75,7 @@ ENTRY(efi_call3)
34685 call *%rdi
34686 addq $32, %rsp
34687 RESTORE_XMM
34688+ pax_force_retaddr 0, 1
34689 ret
34690 ENDPROC(efi_call3)
34691
34692@@ -83,6 +88,7 @@ ENTRY(efi_call4)
34693 call *%rdi
34694 addq $32, %rsp
34695 RESTORE_XMM
34696+ pax_force_retaddr 0, 1
34697 ret
34698 ENDPROC(efi_call4)
34699
34700@@ -96,6 +102,7 @@ ENTRY(efi_call5)
34701 call *%rdi
34702 addq $48, %rsp
34703 RESTORE_XMM
34704+ pax_force_retaddr 0, 1
34705 ret
34706 ENDPROC(efi_call5)
34707
34708@@ -112,5 +119,6 @@ ENTRY(efi_call6)
34709 call *%rdi
34710 addq $48, %rsp
34711 RESTORE_XMM
34712+ pax_force_retaddr 0, 1
34713 ret
34714 ENDPROC(efi_call6)
34715diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34716index f90e290..435f0dd 100644
34717--- a/arch/x86/platform/intel-mid/intel-mid.c
34718+++ b/arch/x86/platform/intel-mid/intel-mid.c
34719@@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34720 {
34721 }
34722
34723-static void intel_mid_reboot(void)
34724+static void __noreturn intel_mid_reboot(void)
34725 {
34726 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34727+ BUG();
34728 }
34729
34730 static unsigned long __init intel_mid_calibrate_tsc(void)
34731diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34732index d6ee929..3637cb5 100644
34733--- a/arch/x86/platform/olpc/olpc_dt.c
34734+++ b/arch/x86/platform/olpc/olpc_dt.c
34735@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34736 return res;
34737 }
34738
34739-static struct of_pdt_ops prom_olpc_ops __initdata = {
34740+static struct of_pdt_ops prom_olpc_ops __initconst = {
34741 .nextprop = olpc_dt_nextprop,
34742 .getproplen = olpc_dt_getproplen,
34743 .getproperty = olpc_dt_getproperty,
34744diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34745index 424f4c9..f2a2988 100644
34746--- a/arch/x86/power/cpu.c
34747+++ b/arch/x86/power/cpu.c
34748@@ -137,11 +137,8 @@ static void do_fpu_end(void)
34749 static void fix_processor_context(void)
34750 {
34751 int cpu = smp_processor_id();
34752- struct tss_struct *t = &per_cpu(init_tss, cpu);
34753-#ifdef CONFIG_X86_64
34754- struct desc_struct *desc = get_cpu_gdt_table(cpu);
34755- tss_desc tss;
34756-#endif
34757+ struct tss_struct *t = init_tss + cpu;
34758+
34759 set_tss_desc(cpu, t); /*
34760 * This just modifies memory; should not be
34761 * necessary. But... This is necessary, because
34762@@ -150,10 +147,6 @@ static void fix_processor_context(void)
34763 */
34764
34765 #ifdef CONFIG_X86_64
34766- memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34767- tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34768- write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34769-
34770 syscall_init(); /* This sets MSR_*STAR and related */
34771 #endif
34772 load_TR_desc(); /* This does ltr */
34773diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34774index a44f457..9140171 100644
34775--- a/arch/x86/realmode/init.c
34776+++ b/arch/x86/realmode/init.c
34777@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34778 __va(real_mode_header->trampoline_header);
34779
34780 #ifdef CONFIG_X86_32
34781- trampoline_header->start = __pa_symbol(startup_32_smp);
34782+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34783+
34784+#ifdef CONFIG_PAX_KERNEXEC
34785+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34786+#endif
34787+
34788+ trampoline_header->boot_cs = __BOOT_CS;
34789 trampoline_header->gdt_limit = __BOOT_DS + 7;
34790 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34791 #else
34792@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34793 *trampoline_cr4_features = read_cr4();
34794
34795 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34796- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34797+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34798 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34799 #endif
34800 }
34801diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34802index 9cac825..4890b25 100644
34803--- a/arch/x86/realmode/rm/Makefile
34804+++ b/arch/x86/realmode/rm/Makefile
34805@@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34806 $(call cc-option, -fno-unit-at-a-time)) \
34807 $(call cc-option, -fno-stack-protector) \
34808 $(call cc-option, -mpreferred-stack-boundary=2)
34809+ifdef CONSTIFY_PLUGIN
34810+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34811+endif
34812 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34813 GCOV_PROFILE := n
34814diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34815index a28221d..93c40f1 100644
34816--- a/arch/x86/realmode/rm/header.S
34817+++ b/arch/x86/realmode/rm/header.S
34818@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34819 #endif
34820 /* APM/BIOS reboot */
34821 .long pa_machine_real_restart_asm
34822-#ifdef CONFIG_X86_64
34823+#ifdef CONFIG_X86_32
34824+ .long __KERNEL_CS
34825+#else
34826 .long __KERNEL32_CS
34827 #endif
34828 END(real_mode_header)
34829diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34830index c1b2791..f9e31c7 100644
34831--- a/arch/x86/realmode/rm/trampoline_32.S
34832+++ b/arch/x86/realmode/rm/trampoline_32.S
34833@@ -25,6 +25,12 @@
34834 #include <asm/page_types.h>
34835 #include "realmode.h"
34836
34837+#ifdef CONFIG_PAX_KERNEXEC
34838+#define ta(X) (X)
34839+#else
34840+#define ta(X) (pa_ ## X)
34841+#endif
34842+
34843 .text
34844 .code16
34845
34846@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34847
34848 cli # We should be safe anyway
34849
34850- movl tr_start, %eax # where we need to go
34851-
34852 movl $0xA5A5A5A5, trampoline_status
34853 # write marker for master knows we're running
34854
34855@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34856 movw $1, %dx # protected mode (PE) bit
34857 lmsw %dx # into protected mode
34858
34859- ljmpl $__BOOT_CS, $pa_startup_32
34860+ ljmpl *(trampoline_header)
34861
34862 .section ".text32","ax"
34863 .code32
34864@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34865 .balign 8
34866 GLOBAL(trampoline_header)
34867 tr_start: .space 4
34868- tr_gdt_pad: .space 2
34869+ tr_boot_cs: .space 2
34870 tr_gdt: .space 6
34871 END(trampoline_header)
34872
34873diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34874index bb360dc..d0fd8f8 100644
34875--- a/arch/x86/realmode/rm/trampoline_64.S
34876+++ b/arch/x86/realmode/rm/trampoline_64.S
34877@@ -94,6 +94,7 @@ ENTRY(startup_32)
34878 movl %edx, %gs
34879
34880 movl pa_tr_cr4, %eax
34881+ andl $~X86_CR4_PCIDE, %eax
34882 movl %eax, %cr4 # Enable PAE mode
34883
34884 # Setup trampoline 4 level pagetables
34885@@ -107,7 +108,7 @@ ENTRY(startup_32)
34886 wrmsr
34887
34888 # Enable paging and in turn activate Long Mode
34889- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34890+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
34891 movl %eax, %cr0
34892
34893 /*
34894diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34895index e812034..c747134 100644
34896--- a/arch/x86/tools/Makefile
34897+++ b/arch/x86/tools/Makefile
34898@@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34899
34900 $(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
34901
34902-HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34903+HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34904 hostprogs-y += relocs
34905 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34906 relocs: $(obj)/relocs
34907diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34908index f7bab68..b6d9886 100644
34909--- a/arch/x86/tools/relocs.c
34910+++ b/arch/x86/tools/relocs.c
34911@@ -1,5 +1,7 @@
34912 /* This is included from relocs_32/64.c */
34913
34914+#include "../../../include/generated/autoconf.h"
34915+
34916 #define ElfW(type) _ElfW(ELF_BITS, type)
34917 #define _ElfW(bits, type) __ElfW(bits, type)
34918 #define __ElfW(bits, type) Elf##bits##_##type
34919@@ -11,6 +13,7 @@
34920 #define Elf_Sym ElfW(Sym)
34921
34922 static Elf_Ehdr ehdr;
34923+static Elf_Phdr *phdr;
34924
34925 struct relocs {
34926 uint32_t *offset;
34927@@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34928 }
34929 }
34930
34931+static void read_phdrs(FILE *fp)
34932+{
34933+ unsigned int i;
34934+
34935+ phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34936+ if (!phdr) {
34937+ die("Unable to allocate %d program headers\n",
34938+ ehdr.e_phnum);
34939+ }
34940+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34941+ die("Seek to %d failed: %s\n",
34942+ ehdr.e_phoff, strerror(errno));
34943+ }
34944+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34945+ die("Cannot read ELF program headers: %s\n",
34946+ strerror(errno));
34947+ }
34948+ for(i = 0; i < ehdr.e_phnum; i++) {
34949+ phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34950+ phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34951+ phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34952+ phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34953+ phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34954+ phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34955+ phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34956+ phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34957+ }
34958+
34959+}
34960+
34961 static void read_shdrs(FILE *fp)
34962 {
34963- int i;
34964+ unsigned int i;
34965 Elf_Shdr shdr;
34966
34967 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34968@@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34969
34970 static void read_strtabs(FILE *fp)
34971 {
34972- int i;
34973+ unsigned int i;
34974 for (i = 0; i < ehdr.e_shnum; i++) {
34975 struct section *sec = &secs[i];
34976 if (sec->shdr.sh_type != SHT_STRTAB) {
34977@@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34978
34979 static void read_symtabs(FILE *fp)
34980 {
34981- int i,j;
34982+ unsigned int i,j;
34983 for (i = 0; i < ehdr.e_shnum; i++) {
34984 struct section *sec = &secs[i];
34985 if (sec->shdr.sh_type != SHT_SYMTAB) {
34986@@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34987 }
34988
34989
34990-static void read_relocs(FILE *fp)
34991+static void read_relocs(FILE *fp, int use_real_mode)
34992 {
34993- int i,j;
34994+ unsigned int i,j;
34995+ uint32_t base;
34996+
34997 for (i = 0; i < ehdr.e_shnum; i++) {
34998 struct section *sec = &secs[i];
34999 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35000@@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35001 die("Cannot read symbol table: %s\n",
35002 strerror(errno));
35003 }
35004+ base = 0;
35005+
35006+#ifdef CONFIG_X86_32
35007+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35008+ if (phdr[j].p_type != PT_LOAD )
35009+ continue;
35010+ 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)
35011+ continue;
35012+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35013+ break;
35014+ }
35015+#endif
35016+
35017 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35018 Elf_Rel *rel = &sec->reltab[j];
35019- rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35020+ rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35021 rel->r_info = elf_xword_to_cpu(rel->r_info);
35022 #if (SHT_REL_TYPE == SHT_RELA)
35023 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35024@@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35025
35026 static void print_absolute_symbols(void)
35027 {
35028- int i;
35029+ unsigned int i;
35030 const char *format;
35031
35032 if (ELF_BITS == 64)
35033@@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35034 for (i = 0; i < ehdr.e_shnum; i++) {
35035 struct section *sec = &secs[i];
35036 char *sym_strtab;
35037- int j;
35038+ unsigned int j;
35039
35040 if (sec->shdr.sh_type != SHT_SYMTAB) {
35041 continue;
35042@@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35043
35044 static void print_absolute_relocs(void)
35045 {
35046- int i, printed = 0;
35047+ unsigned int i, printed = 0;
35048 const char *format;
35049
35050 if (ELF_BITS == 64)
35051@@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35052 struct section *sec_applies, *sec_symtab;
35053 char *sym_strtab;
35054 Elf_Sym *sh_symtab;
35055- int j;
35056+ unsigned int j;
35057 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35058 continue;
35059 }
35060@@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35061 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35062 Elf_Sym *sym, const char *symname))
35063 {
35064- int i;
35065+ unsigned int i;
35066 /* Walk through the relocations */
35067 for (i = 0; i < ehdr.e_shnum; i++) {
35068 char *sym_strtab;
35069 Elf_Sym *sh_symtab;
35070 struct section *sec_applies, *sec_symtab;
35071- int j;
35072+ unsigned int j;
35073 struct section *sec = &secs[i];
35074
35075 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35076@@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35077 {
35078 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35079 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35080+ char *sym_strtab = sec->link->link->strtab;
35081+
35082+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35083+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35084+ return 0;
35085+
35086+#ifdef CONFIG_PAX_KERNEXEC
35087+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35088+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35089+ return 0;
35090+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35091+ return 0;
35092+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35093+ return 0;
35094+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35095+ return 0;
35096+#endif
35097
35098 switch (r_type) {
35099 case R_386_NONE:
35100@@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35101
35102 static void emit_relocs(int as_text, int use_real_mode)
35103 {
35104- int i;
35105+ unsigned int i;
35106 int (*write_reloc)(uint32_t, FILE *) = write32;
35107 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35108 const char *symname);
35109@@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35110 {
35111 regex_init(use_real_mode);
35112 read_ehdr(fp);
35113+ read_phdrs(fp);
35114 read_shdrs(fp);
35115 read_strtabs(fp);
35116 read_symtabs(fp);
35117- read_relocs(fp);
35118+ read_relocs(fp, use_real_mode);
35119 if (ELF_BITS == 64)
35120 percpu_init();
35121 if (show_absolute_syms) {
35122diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35123index 80ffa5b..a33bd15 100644
35124--- a/arch/x86/um/tls_32.c
35125+++ b/arch/x86/um/tls_32.c
35126@@ -260,7 +260,7 @@ out:
35127 if (unlikely(task == current &&
35128 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35129 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35130- "without flushed TLS.", current->pid);
35131+ "without flushed TLS.", task_pid_nr(current));
35132 }
35133
35134 return 0;
35135diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35136index fd14be1..e3c79c0 100644
35137--- a/arch/x86/vdso/Makefile
35138+++ b/arch/x86/vdso/Makefile
35139@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
35140 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35141 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35142
35143-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35144+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
35145 GCOV_PROFILE := n
35146
35147 #
35148diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35149index d6bfb87..876ee18 100644
35150--- a/arch/x86/vdso/vdso32-setup.c
35151+++ b/arch/x86/vdso/vdso32-setup.c
35152@@ -25,6 +25,7 @@
35153 #include <asm/tlbflush.h>
35154 #include <asm/vdso.h>
35155 #include <asm/proto.h>
35156+#include <asm/mman.h>
35157
35158 enum {
35159 VDSO_DISABLED = 0,
35160@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
35161 void enable_sep_cpu(void)
35162 {
35163 int cpu = get_cpu();
35164- struct tss_struct *tss = &per_cpu(init_tss, cpu);
35165+ struct tss_struct *tss = init_tss + cpu;
35166
35167 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35168 put_cpu();
35169@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
35170 gate_vma.vm_start = FIXADDR_USER_START;
35171 gate_vma.vm_end = FIXADDR_USER_END;
35172 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35173- gate_vma.vm_page_prot = __P101;
35174+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35175
35176 return 0;
35177 }
35178@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35179 if (compat)
35180 addr = VDSO_HIGH_BASE;
35181 else {
35182- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
35183+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
35184 if (IS_ERR_VALUE(addr)) {
35185 ret = addr;
35186 goto up_fail;
35187 }
35188 }
35189
35190- current->mm->context.vdso = (void *)addr;
35191+ current->mm->context.vdso = addr;
35192
35193 if (compat_uses_vma || !compat) {
35194 /*
35195@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35196 }
35197
35198 current_thread_info()->sysenter_return =
35199- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35200+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35201
35202 up_fail:
35203 if (ret)
35204- current->mm->context.vdso = NULL;
35205+ current->mm->context.vdso = 0;
35206
35207 up_write(&mm->mmap_sem);
35208
35209@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
35210
35211 const char *arch_vma_name(struct vm_area_struct *vma)
35212 {
35213- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35214+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35215 return "[vdso]";
35216+
35217+#ifdef CONFIG_PAX_SEGMEXEC
35218+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35219+ return "[vdso]";
35220+#endif
35221+
35222 return NULL;
35223 }
35224
35225@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
35226 * Check to see if the corresponding task was created in compat vdso
35227 * mode.
35228 */
35229- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
35230+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
35231 return &gate_vma;
35232 return NULL;
35233 }
35234diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35235index 431e875..cbb23f3 100644
35236--- a/arch/x86/vdso/vma.c
35237+++ b/arch/x86/vdso/vma.c
35238@@ -16,8 +16,6 @@
35239 #include <asm/vdso.h>
35240 #include <asm/page.h>
35241
35242-unsigned int __read_mostly vdso_enabled = 1;
35243-
35244 extern char vdso_start[], vdso_end[];
35245 extern unsigned short vdso_sync_cpuid;
35246
35247@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35248 * unaligned here as a result of stack start randomization.
35249 */
35250 addr = PAGE_ALIGN(addr);
35251- addr = align_vdso_addr(addr);
35252
35253 return addr;
35254 }
35255@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35256 unsigned size)
35257 {
35258 struct mm_struct *mm = current->mm;
35259- unsigned long addr;
35260+ unsigned long addr = 0;
35261 int ret;
35262
35263- if (!vdso_enabled)
35264- return 0;
35265-
35266 down_write(&mm->mmap_sem);
35267+
35268+#ifdef CONFIG_PAX_RANDMMAP
35269+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35270+#endif
35271+
35272 addr = vdso_addr(mm->start_stack, size);
35273+ addr = align_vdso_addr(addr);
35274 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35275 if (IS_ERR_VALUE(addr)) {
35276 ret = addr;
35277 goto up_fail;
35278 }
35279
35280- current->mm->context.vdso = (void *)addr;
35281+ mm->context.vdso = addr;
35282
35283 ret = install_special_mapping(mm, addr, size,
35284 VM_READ|VM_EXEC|
35285 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35286 pages);
35287- if (ret) {
35288- current->mm->context.vdso = NULL;
35289- goto up_fail;
35290- }
35291+ if (ret)
35292+ mm->context.vdso = 0;
35293
35294 up_fail:
35295 up_write(&mm->mmap_sem);
35296@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35297 vdsox32_size);
35298 }
35299 #endif
35300-
35301-static __init int vdso_setup(char *s)
35302-{
35303- vdso_enabled = simple_strtoul(s, NULL, 0);
35304- return 0;
35305-}
35306-__setup("vdso=", vdso_setup);
35307diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35308index 1a3c765..3d2e8d1 100644
35309--- a/arch/x86/xen/Kconfig
35310+++ b/arch/x86/xen/Kconfig
35311@@ -9,6 +9,7 @@ config XEN
35312 select XEN_HAVE_PVMMU
35313 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
35314 depends on X86_TSC
35315+ depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35316 help
35317 This is the Linux Xen port. Enabling this will allow the
35318 kernel to boot in a paravirtualized environment under the
35319diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35320index fa6ade7..73da73a5 100644
35321--- a/arch/x86/xen/enlighten.c
35322+++ b/arch/x86/xen/enlighten.c
35323@@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35324
35325 struct shared_info xen_dummy_shared_info;
35326
35327-void *xen_initial_gdt;
35328-
35329 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35330 __read_mostly int xen_have_vector_callback;
35331 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35332@@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35333 {
35334 unsigned long va = dtr->address;
35335 unsigned int size = dtr->size + 1;
35336- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35337- unsigned long frames[pages];
35338+ unsigned long frames[65536 / PAGE_SIZE];
35339 int f;
35340
35341 /*
35342@@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35343 {
35344 unsigned long va = dtr->address;
35345 unsigned int size = dtr->size + 1;
35346- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35347- unsigned long frames[pages];
35348+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35349 int f;
35350
35351 /*
35352@@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35353 * 8-byte entries, or 16 4k pages..
35354 */
35355
35356- BUG_ON(size > 65536);
35357+ BUG_ON(size > GDT_SIZE);
35358 BUG_ON(va & ~PAGE_MASK);
35359
35360 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35361@@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35362 return 0;
35363 }
35364
35365-static void set_xen_basic_apic_ops(void)
35366+static void __init set_xen_basic_apic_ops(void)
35367 {
35368 apic->read = xen_apic_read;
35369 apic->write = xen_apic_write;
35370@@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35371 #endif
35372 };
35373
35374-static void xen_reboot(int reason)
35375+static __noreturn void xen_reboot(int reason)
35376 {
35377 struct sched_shutdown r = { .reason = reason };
35378
35379- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35380- BUG();
35381+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35382+ BUG();
35383 }
35384
35385-static void xen_restart(char *msg)
35386+static __noreturn void xen_restart(char *msg)
35387 {
35388 xen_reboot(SHUTDOWN_reboot);
35389 }
35390
35391-static void xen_emergency_restart(void)
35392+static __noreturn void xen_emergency_restart(void)
35393 {
35394 xen_reboot(SHUTDOWN_reboot);
35395 }
35396
35397-static void xen_machine_halt(void)
35398+static __noreturn void xen_machine_halt(void)
35399 {
35400 xen_reboot(SHUTDOWN_poweroff);
35401 }
35402
35403-static void xen_machine_power_off(void)
35404+static __noreturn void xen_machine_power_off(void)
35405 {
35406 if (pm_power_off)
35407 pm_power_off();
35408@@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
35409 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35410
35411 /* Work out if we support NX */
35412- x86_configure_nx();
35413+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35414+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35415+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35416+ unsigned l, h;
35417+
35418+ __supported_pte_mask |= _PAGE_NX;
35419+ rdmsr(MSR_EFER, l, h);
35420+ l |= EFER_NX;
35421+ wrmsr(MSR_EFER, l, h);
35422+ }
35423+#endif
35424
35425 xen_setup_features();
35426
35427@@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
35428
35429 machine_ops = xen_machine_ops;
35430
35431- /*
35432- * The only reliable way to retain the initial address of the
35433- * percpu gdt_page is to remember it here, so we can go and
35434- * mark it RW later, when the initial percpu area is freed.
35435- */
35436- xen_initial_gdt = &per_cpu(gdt_page, 0);
35437-
35438 xen_smp_init();
35439
35440 #ifdef CONFIG_ACPI_NUMA
35441diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35442index ce563be..7327d91 100644
35443--- a/arch/x86/xen/mmu.c
35444+++ b/arch/x86/xen/mmu.c
35445@@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35446 return val;
35447 }
35448
35449-static pteval_t pte_pfn_to_mfn(pteval_t val)
35450+static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35451 {
35452 if (val & _PAGE_PRESENT) {
35453 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35454@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35455 /* L3_k[510] -> level2_kernel_pgt
35456 * L3_i[511] -> level2_fixmap_pgt */
35457 convert_pfn_mfn(level3_kernel_pgt);
35458+ convert_pfn_mfn(level3_vmalloc_start_pgt);
35459+ convert_pfn_mfn(level3_vmalloc_end_pgt);
35460+ convert_pfn_mfn(level3_vmemmap_pgt);
35461
35462 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35463 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35464@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35465 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35466 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35467 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35468+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35469+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35470+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35471 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35472 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35473+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35474 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35475 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35476
35477@@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
35478 pv_mmu_ops.set_pud = xen_set_pud;
35479 #if PAGETABLE_LEVELS == 4
35480 pv_mmu_ops.set_pgd = xen_set_pgd;
35481+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35482 #endif
35483
35484 /* This will work as long as patching hasn't happened yet
35485@@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35486 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35487 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35488 .set_pgd = xen_set_pgd_hyper,
35489+ .set_pgd_batched = xen_set_pgd_hyper,
35490
35491 .alloc_pud = xen_alloc_pmd_init,
35492 .release_pud = xen_release_pmd_init,
35493diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35494index c36b325..b0f1518 100644
35495--- a/arch/x86/xen/smp.c
35496+++ b/arch/x86/xen/smp.c
35497@@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35498 native_smp_prepare_boot_cpu();
35499
35500 if (xen_pv_domain()) {
35501- /* We've switched to the "real" per-cpu gdt, so make sure the
35502- old memory can be recycled */
35503- make_lowmem_page_readwrite(xen_initial_gdt);
35504-
35505 #ifdef CONFIG_X86_32
35506 /*
35507 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35508 * expects __USER_DS
35509 */
35510- loadsegment(ds, __USER_DS);
35511- loadsegment(es, __USER_DS);
35512+ loadsegment(ds, __KERNEL_DS);
35513+ loadsegment(es, __KERNEL_DS);
35514 #endif
35515
35516 xen_filter_cpu_maps();
35517@@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35518 ctxt->user_regs.ss = __KERNEL_DS;
35519 #ifdef CONFIG_X86_32
35520 ctxt->user_regs.fs = __KERNEL_PERCPU;
35521- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35522+ savesegment(gs, ctxt->user_regs.gs);
35523 #else
35524 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35525 #endif
35526@@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35527
35528 {
35529 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35530- ctxt->user_regs.ds = __USER_DS;
35531- ctxt->user_regs.es = __USER_DS;
35532+ ctxt->user_regs.ds = __KERNEL_DS;
35533+ ctxt->user_regs.es = __KERNEL_DS;
35534
35535 xen_copy_trap_info(ctxt->trap_ctxt);
35536
35537@@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35538 int rc;
35539
35540 per_cpu(current_task, cpu) = idle;
35541+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
35542 #ifdef CONFIG_X86_32
35543 irq_ctx_init(cpu);
35544 #else
35545 clear_tsk_thread_flag(idle, TIF_FORK);
35546- per_cpu(kernel_stack, cpu) =
35547- (unsigned long)task_stack_page(idle) -
35548- KERNEL_STACK_OFFSET + THREAD_SIZE;
35549+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35550 #endif
35551 xen_setup_runstate_info(cpu);
35552 xen_setup_timer(cpu);
35553@@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35554
35555 void __init xen_smp_init(void)
35556 {
35557- smp_ops = xen_smp_ops;
35558+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35559 xen_fill_possible_map();
35560 }
35561
35562diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35563index 33ca6e4..0ded929 100644
35564--- a/arch/x86/xen/xen-asm_32.S
35565+++ b/arch/x86/xen/xen-asm_32.S
35566@@ -84,14 +84,14 @@ ENTRY(xen_iret)
35567 ESP_OFFSET=4 # bytes pushed onto stack
35568
35569 /*
35570- * Store vcpu_info pointer for easy access. Do it this way to
35571- * avoid having to reload %fs
35572+ * Store vcpu_info pointer for easy access.
35573 */
35574 #ifdef CONFIG_SMP
35575- GET_THREAD_INFO(%eax)
35576- movl %ss:TI_cpu(%eax), %eax
35577- movl %ss:__per_cpu_offset(,%eax,4), %eax
35578- mov %ss:xen_vcpu(%eax), %eax
35579+ push %fs
35580+ mov $(__KERNEL_PERCPU), %eax
35581+ mov %eax, %fs
35582+ mov PER_CPU_VAR(xen_vcpu), %eax
35583+ pop %fs
35584 #else
35585 movl %ss:xen_vcpu, %eax
35586 #endif
35587diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35588index 7faed58..ba4427c 100644
35589--- a/arch/x86/xen/xen-head.S
35590+++ b/arch/x86/xen/xen-head.S
35591@@ -19,6 +19,17 @@ ENTRY(startup_xen)
35592 #ifdef CONFIG_X86_32
35593 mov %esi,xen_start_info
35594 mov $init_thread_union+THREAD_SIZE,%esp
35595+#ifdef CONFIG_SMP
35596+ movl $cpu_gdt_table,%edi
35597+ movl $__per_cpu_load,%eax
35598+ movw %ax,__KERNEL_PERCPU + 2(%edi)
35599+ rorl $16,%eax
35600+ movb %al,__KERNEL_PERCPU + 4(%edi)
35601+ movb %ah,__KERNEL_PERCPU + 7(%edi)
35602+ movl $__per_cpu_end - 1,%eax
35603+ subl $__per_cpu_start,%eax
35604+ movw %ax,__KERNEL_PERCPU + 0(%edi)
35605+#endif
35606 #else
35607 mov %rsi,xen_start_info
35608 mov $init_thread_union+THREAD_SIZE,%rsp
35609diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35610index 95f8c61..611d6e8 100644
35611--- a/arch/x86/xen/xen-ops.h
35612+++ b/arch/x86/xen/xen-ops.h
35613@@ -10,8 +10,6 @@
35614 extern const char xen_hypervisor_callback[];
35615 extern const char xen_failsafe_callback[];
35616
35617-extern void *xen_initial_gdt;
35618-
35619 struct trap_info;
35620 void xen_copy_trap_info(struct trap_info *traps);
35621
35622diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35623index 525bd3d..ef888b1 100644
35624--- a/arch/xtensa/variants/dc232b/include/variant/core.h
35625+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35626@@ -119,9 +119,9 @@
35627 ----------------------------------------------------------------------*/
35628
35629 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35630-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35631 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35632 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35633+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35634
35635 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35636 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35637diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35638index 2f33760..835e50a 100644
35639--- a/arch/xtensa/variants/fsf/include/variant/core.h
35640+++ b/arch/xtensa/variants/fsf/include/variant/core.h
35641@@ -11,6 +11,7 @@
35642 #ifndef _XTENSA_CORE_H
35643 #define _XTENSA_CORE_H
35644
35645+#include <linux/const.h>
35646
35647 /****************************************************************************
35648 Parameters Useful for Any Code, USER or PRIVILEGED
35649@@ -112,9 +113,9 @@
35650 ----------------------------------------------------------------------*/
35651
35652 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35653-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35654 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35655 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35656+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35657
35658 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35659 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35660diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35661index af00795..2bb8105 100644
35662--- a/arch/xtensa/variants/s6000/include/variant/core.h
35663+++ b/arch/xtensa/variants/s6000/include/variant/core.h
35664@@ -11,6 +11,7 @@
35665 #ifndef _XTENSA_CORE_CONFIGURATION_H
35666 #define _XTENSA_CORE_CONFIGURATION_H
35667
35668+#include <linux/const.h>
35669
35670 /****************************************************************************
35671 Parameters Useful for Any Code, USER or PRIVILEGED
35672@@ -118,9 +119,9 @@
35673 ----------------------------------------------------------------------*/
35674
35675 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35676-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35677 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35678 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35679+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35680
35681 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35682 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35683diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35684index 4e491d9..c8e18e4 100644
35685--- a/block/blk-cgroup.c
35686+++ b/block/blk-cgroup.c
35687@@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35688 static struct cgroup_subsys_state *
35689 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35690 {
35691- static atomic64_t id_seq = ATOMIC64_INIT(0);
35692+ static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35693 struct blkcg *blkcg;
35694
35695 if (!parent_css) {
35696@@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35697
35698 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35699 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35700- blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35701+ blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35702 done:
35703 spin_lock_init(&blkcg->lock);
35704 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35705diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35706index 1855bf5..af12b06 100644
35707--- a/block/blk-iopoll.c
35708+++ b/block/blk-iopoll.c
35709@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35710 }
35711 EXPORT_SYMBOL(blk_iopoll_complete);
35712
35713-static void blk_iopoll_softirq(struct softirq_action *h)
35714+static __latent_entropy void blk_iopoll_softirq(void)
35715 {
35716 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35717 int rearm = 0, budget = blk_iopoll_budget;
35718diff --git a/block/blk-map.c b/block/blk-map.c
35719index 623e1cd..ca1e109 100644
35720--- a/block/blk-map.c
35721+++ b/block/blk-map.c
35722@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35723 if (!len || !kbuf)
35724 return -EINVAL;
35725
35726- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35727+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35728 if (do_copy)
35729 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35730 else
35731diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35732index 57790c1..5e988dd 100644
35733--- a/block/blk-softirq.c
35734+++ b/block/blk-softirq.c
35735@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35736 * Softirq action handler - move entries to local list and loop over them
35737 * while passing them to the queue registered handler.
35738 */
35739-static void blk_done_softirq(struct softirq_action *h)
35740+static __latent_entropy void blk_done_softirq(void)
35741 {
35742 struct list_head *cpu_list, local_list;
35743
35744diff --git a/block/bsg.c b/block/bsg.c
35745index 420a5a9..23834aa 100644
35746--- a/block/bsg.c
35747+++ b/block/bsg.c
35748@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35749 struct sg_io_v4 *hdr, struct bsg_device *bd,
35750 fmode_t has_write_perm)
35751 {
35752+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35753+ unsigned char *cmdptr;
35754+
35755 if (hdr->request_len > BLK_MAX_CDB) {
35756 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35757 if (!rq->cmd)
35758 return -ENOMEM;
35759- }
35760+ cmdptr = rq->cmd;
35761+ } else
35762+ cmdptr = tmpcmd;
35763
35764- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35765+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35766 hdr->request_len))
35767 return -EFAULT;
35768
35769+ if (cmdptr != rq->cmd)
35770+ memcpy(rq->cmd, cmdptr, hdr->request_len);
35771+
35772 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35773 if (blk_verify_command(rq->cmd, has_write_perm))
35774 return -EPERM;
35775diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35776index fbd5a67..f24fd95 100644
35777--- a/block/compat_ioctl.c
35778+++ b/block/compat_ioctl.c
35779@@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35780 cgc = compat_alloc_user_space(sizeof(*cgc));
35781 cgc32 = compat_ptr(arg);
35782
35783- if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35784+ if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35785 get_user(data, &cgc32->buffer) ||
35786 put_user(compat_ptr(data), &cgc->buffer) ||
35787 copy_in_user(&cgc->buflen, &cgc32->buflen,
35788@@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35789 err |= __get_user(f->spec1, &uf->spec1);
35790 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35791 err |= __get_user(name, &uf->name);
35792- f->name = compat_ptr(name);
35793+ f->name = (void __force_kernel *)compat_ptr(name);
35794 if (err) {
35795 err = -EFAULT;
35796 goto out;
35797diff --git a/block/genhd.c b/block/genhd.c
35798index 791f419..89f21c4 100644
35799--- a/block/genhd.c
35800+++ b/block/genhd.c
35801@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35802
35803 /*
35804 * Register device numbers dev..(dev+range-1)
35805- * range must be nonzero
35806+ * Noop if @range is zero.
35807 * The hash chain is sorted on range, so that subranges can override.
35808 */
35809 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35810 struct kobject *(*probe)(dev_t, int *, void *),
35811 int (*lock)(dev_t, void *), void *data)
35812 {
35813- kobj_map(bdev_map, devt, range, module, probe, lock, data);
35814+ if (range)
35815+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
35816 }
35817
35818 EXPORT_SYMBOL(blk_register_region);
35819
35820+/* undo blk_register_region(), noop if @range is zero */
35821 void blk_unregister_region(dev_t devt, unsigned long range)
35822 {
35823- kobj_unmap(bdev_map, devt, range);
35824+ if (range)
35825+ kobj_unmap(bdev_map, devt, range);
35826 }
35827
35828 EXPORT_SYMBOL(blk_unregister_region);
35829diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35830index dc51f46..d5446a8 100644
35831--- a/block/partitions/efi.c
35832+++ b/block/partitions/efi.c
35833@@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35834 if (!gpt)
35835 return NULL;
35836
35837+ if (!le32_to_cpu(gpt->num_partition_entries))
35838+ return NULL;
35839+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35840+ if (!pte)
35841+ return NULL;
35842+
35843 count = le32_to_cpu(gpt->num_partition_entries) *
35844 le32_to_cpu(gpt->sizeof_partition_entry);
35845- if (!count)
35846- return NULL;
35847- pte = kmalloc(count, GFP_KERNEL);
35848- if (!pte)
35849- return NULL;
35850-
35851 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35852 (u8 *) pte, count) < count) {
35853 kfree(pte);
35854diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35855index 625e3e4..b5339f9 100644
35856--- a/block/scsi_ioctl.c
35857+++ b/block/scsi_ioctl.c
35858@@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35859 return put_user(0, p);
35860 }
35861
35862-static int sg_get_timeout(struct request_queue *q)
35863+static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35864 {
35865 return jiffies_to_clock_t(q->sg_timeout);
35866 }
35867@@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35868 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35869 struct sg_io_hdr *hdr, fmode_t mode)
35870 {
35871- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35872+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35873+ unsigned char *cmdptr;
35874+
35875+ if (rq->cmd != rq->__cmd)
35876+ cmdptr = rq->cmd;
35877+ else
35878+ cmdptr = tmpcmd;
35879+
35880+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35881 return -EFAULT;
35882+
35883+ if (cmdptr != rq->cmd)
35884+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35885+
35886 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35887 return -EPERM;
35888
35889@@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35890 int err;
35891 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35892 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35893+ unsigned char tmpcmd[sizeof(rq->__cmd)];
35894+ unsigned char *cmdptr;
35895
35896 if (!sic)
35897 return -EINVAL;
35898@@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35899 */
35900 err = -EFAULT;
35901 rq->cmd_len = cmdlen;
35902- if (copy_from_user(rq->cmd, sic->data, cmdlen))
35903+
35904+ if (rq->cmd != rq->__cmd)
35905+ cmdptr = rq->cmd;
35906+ else
35907+ cmdptr = tmpcmd;
35908+
35909+ if (copy_from_user(cmdptr, sic->data, cmdlen))
35910 goto error;
35911
35912+ if (rq->cmd != cmdptr)
35913+ memcpy(rq->cmd, cmdptr, cmdlen);
35914+
35915 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35916 goto error;
35917
35918diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35919index 7bdd61b..afec999 100644
35920--- a/crypto/cryptd.c
35921+++ b/crypto/cryptd.c
35922@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35923
35924 struct cryptd_blkcipher_request_ctx {
35925 crypto_completion_t complete;
35926-};
35927+} __no_const;
35928
35929 struct cryptd_hash_ctx {
35930 struct crypto_shash *child;
35931@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35932
35933 struct cryptd_aead_request_ctx {
35934 crypto_completion_t complete;
35935-};
35936+} __no_const;
35937
35938 static void cryptd_queue_worker(struct work_struct *work);
35939
35940diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35941index f8c920c..ab2cb5a 100644
35942--- a/crypto/pcrypt.c
35943+++ b/crypto/pcrypt.c
35944@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35945 int ret;
35946
35947 pinst->kobj.kset = pcrypt_kset;
35948- ret = kobject_add(&pinst->kobj, NULL, name);
35949+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35950 if (!ret)
35951 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35952
35953diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35954index 15dddc1..b61cf0c 100644
35955--- a/drivers/acpi/acpica/hwxfsleep.c
35956+++ b/drivers/acpi/acpica/hwxfsleep.c
35957@@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35958 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35959
35960 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35961- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35962- acpi_hw_extended_sleep},
35963- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35964- acpi_hw_extended_wake_prep},
35965- {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35966+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35967+ .extended_function = acpi_hw_extended_sleep},
35968+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35969+ .extended_function = acpi_hw_extended_wake_prep},
35970+ {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35971+ .extended_function = acpi_hw_extended_wake}
35972 };
35973
35974 /*
35975diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35976index 21ba34a..cb05966 100644
35977--- a/drivers/acpi/apei/apei-internal.h
35978+++ b/drivers/acpi/apei/apei-internal.h
35979@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35980 struct apei_exec_ins_type {
35981 u32 flags;
35982 apei_exec_ins_func_t run;
35983-};
35984+} __do_const;
35985
35986 struct apei_exec_context {
35987 u32 ip;
35988diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35989index a30bc31..b91c4d5 100644
35990--- a/drivers/acpi/apei/ghes.c
35991+++ b/drivers/acpi/apei/ghes.c
35992@@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35993 const struct acpi_hest_generic *generic,
35994 const struct acpi_generic_status *estatus)
35995 {
35996- static atomic_t seqno;
35997+ static atomic_unchecked_t seqno;
35998 unsigned int curr_seqno;
35999 char pfx_seq[64];
36000
36001@@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
36002 else
36003 pfx = KERN_ERR;
36004 }
36005- curr_seqno = atomic_inc_return(&seqno);
36006+ curr_seqno = atomic_inc_return_unchecked(&seqno);
36007 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36008 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36009 pfx_seq, generic->header.source_id);
36010diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36011index a83e3c6..c3d617f 100644
36012--- a/drivers/acpi/bgrt.c
36013+++ b/drivers/acpi/bgrt.c
36014@@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36015 if (!bgrt_image)
36016 return -ENODEV;
36017
36018- bin_attr_image.private = bgrt_image;
36019- bin_attr_image.size = bgrt_image_size;
36020+ pax_open_kernel();
36021+ *(void **)&bin_attr_image.private = bgrt_image;
36022+ *(size_t *)&bin_attr_image.size = bgrt_image_size;
36023+ pax_close_kernel();
36024
36025 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36026 if (!bgrt_kobj)
36027diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36028index 078c4f7..410e272 100644
36029--- a/drivers/acpi/blacklist.c
36030+++ b/drivers/acpi/blacklist.c
36031@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
36032 u32 is_critical_error;
36033 };
36034
36035-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36036+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36037
36038 /*
36039 * POLICY: If *anything* doesn't work, put it on the blacklist.
36040@@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36041 return 0;
36042 }
36043
36044-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36045+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36046 {
36047 .callback = dmi_disable_osi_vista,
36048 .ident = "Fujitsu Siemens",
36049diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36050index 12b62f2..dc2aac8 100644
36051--- a/drivers/acpi/custom_method.c
36052+++ b/drivers/acpi/custom_method.c
36053@@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36054 struct acpi_table_header table;
36055 acpi_status status;
36056
36057+#ifdef CONFIG_GRKERNSEC_KMEM
36058+ return -EPERM;
36059+#endif
36060+
36061 if (!(*ppos)) {
36062 /* parse the table header to get the table length */
36063 if (count <= sizeof(struct acpi_table_header))
36064diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36065index 644516d..643937e 100644
36066--- a/drivers/acpi/processor_idle.c
36067+++ b/drivers/acpi/processor_idle.c
36068@@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36069 {
36070 int i, count = CPUIDLE_DRIVER_STATE_START;
36071 struct acpi_processor_cx *cx;
36072- struct cpuidle_state *state;
36073+ cpuidle_state_no_const *state;
36074 struct cpuidle_driver *drv = &acpi_idle_driver;
36075
36076 if (!pr->flags.power_setup_done)
36077diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36078index 6dbc3ca..b8b59a0 100644
36079--- a/drivers/acpi/sysfs.c
36080+++ b/drivers/acpi/sysfs.c
36081@@ -425,11 +425,11 @@ static u32 num_counters;
36082 static struct attribute **all_attrs;
36083 static u32 acpi_gpe_count;
36084
36085-static struct attribute_group interrupt_stats_attr_group = {
36086+static attribute_group_no_const interrupt_stats_attr_group = {
36087 .name = "interrupts",
36088 };
36089
36090-static struct kobj_attribute *counter_attrs;
36091+static kobj_attribute_no_const *counter_attrs;
36092
36093 static void delete_gpe_attr_array(void)
36094 {
36095diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36096index c482f8c..c832240 100644
36097--- a/drivers/ata/libahci.c
36098+++ b/drivers/ata/libahci.c
36099@@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
36100 }
36101 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36102
36103-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36104+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36105 struct ata_taskfile *tf, int is_cmd, u16 flags,
36106 unsigned long timeout_msec)
36107 {
36108diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36109index 8cb2522..a815e54 100644
36110--- a/drivers/ata/libata-core.c
36111+++ b/drivers/ata/libata-core.c
36112@@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36113 static void ata_dev_xfermask(struct ata_device *dev);
36114 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36115
36116-atomic_t ata_print_id = ATOMIC_INIT(0);
36117+atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36118
36119 struct ata_force_param {
36120 const char *name;
36121@@ -4851,7 +4851,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36122 struct ata_port *ap;
36123 unsigned int tag;
36124
36125- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36126+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36127 ap = qc->ap;
36128
36129 qc->flags = 0;
36130@@ -4867,7 +4867,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36131 struct ata_port *ap;
36132 struct ata_link *link;
36133
36134- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36135+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36136 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36137 ap = qc->ap;
36138 link = qc->dev->link;
36139@@ -5986,6 +5986,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36140 return;
36141
36142 spin_lock(&lock);
36143+ pax_open_kernel();
36144
36145 for (cur = ops->inherits; cur; cur = cur->inherits) {
36146 void **inherit = (void **)cur;
36147@@ -5999,8 +6000,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36148 if (IS_ERR(*pp))
36149 *pp = NULL;
36150
36151- ops->inherits = NULL;
36152+ *(struct ata_port_operations **)&ops->inherits = NULL;
36153
36154+ pax_close_kernel();
36155 spin_unlock(&lock);
36156 }
36157
36158@@ -6193,7 +6195,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36159
36160 /* give ports names and add SCSI hosts */
36161 for (i = 0; i < host->n_ports; i++) {
36162- host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36163+ host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36164 host->ports[i]->local_port_no = i + 1;
36165 }
36166
36167diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36168index ef8567d..8bdbd03 100644
36169--- a/drivers/ata/libata-scsi.c
36170+++ b/drivers/ata/libata-scsi.c
36171@@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36172
36173 if (rc)
36174 return rc;
36175- ap->print_id = atomic_inc_return(&ata_print_id);
36176+ ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36177 return 0;
36178 }
36179 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36180diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36181index 45b5ab3..98446b8 100644
36182--- a/drivers/ata/libata.h
36183+++ b/drivers/ata/libata.h
36184@@ -53,7 +53,7 @@ enum {
36185 ATA_DNXFER_QUIET = (1 << 31),
36186 };
36187
36188-extern atomic_t ata_print_id;
36189+extern atomic_unchecked_t ata_print_id;
36190 extern int atapi_passthru16;
36191 extern int libata_fua;
36192 extern int libata_noacpi;
36193diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36194index 73492dd..ca2bff5 100644
36195--- a/drivers/ata/pata_arasan_cf.c
36196+++ b/drivers/ata/pata_arasan_cf.c
36197@@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36198 /* Handle platform specific quirks */
36199 if (quirk) {
36200 if (quirk & CF_BROKEN_PIO) {
36201- ap->ops->set_piomode = NULL;
36202+ pax_open_kernel();
36203+ *(void **)&ap->ops->set_piomode = NULL;
36204+ pax_close_kernel();
36205 ap->pio_mask = 0;
36206 }
36207 if (quirk & CF_BROKEN_MWDMA)
36208diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36209index f9b983a..887b9d8 100644
36210--- a/drivers/atm/adummy.c
36211+++ b/drivers/atm/adummy.c
36212@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36213 vcc->pop(vcc, skb);
36214 else
36215 dev_kfree_skb_any(skb);
36216- atomic_inc(&vcc->stats->tx);
36217+ atomic_inc_unchecked(&vcc->stats->tx);
36218
36219 return 0;
36220 }
36221diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36222index 62a7607..cc4be104 100644
36223--- a/drivers/atm/ambassador.c
36224+++ b/drivers/atm/ambassador.c
36225@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36226 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36227
36228 // VC layer stats
36229- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36230+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36231
36232 // free the descriptor
36233 kfree (tx_descr);
36234@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36235 dump_skb ("<<<", vc, skb);
36236
36237 // VC layer stats
36238- atomic_inc(&atm_vcc->stats->rx);
36239+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36240 __net_timestamp(skb);
36241 // end of our responsibility
36242 atm_vcc->push (atm_vcc, skb);
36243@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36244 } else {
36245 PRINTK (KERN_INFO, "dropped over-size frame");
36246 // should we count this?
36247- atomic_inc(&atm_vcc->stats->rx_drop);
36248+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36249 }
36250
36251 } else {
36252@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36253 }
36254
36255 if (check_area (skb->data, skb->len)) {
36256- atomic_inc(&atm_vcc->stats->tx_err);
36257+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36258 return -ENOMEM; // ?
36259 }
36260
36261diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36262index 0e3f8f9..765a7a5 100644
36263--- a/drivers/atm/atmtcp.c
36264+++ b/drivers/atm/atmtcp.c
36265@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36266 if (vcc->pop) vcc->pop(vcc,skb);
36267 else dev_kfree_skb(skb);
36268 if (dev_data) return 0;
36269- atomic_inc(&vcc->stats->tx_err);
36270+ atomic_inc_unchecked(&vcc->stats->tx_err);
36271 return -ENOLINK;
36272 }
36273 size = skb->len+sizeof(struct atmtcp_hdr);
36274@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36275 if (!new_skb) {
36276 if (vcc->pop) vcc->pop(vcc,skb);
36277 else dev_kfree_skb(skb);
36278- atomic_inc(&vcc->stats->tx_err);
36279+ atomic_inc_unchecked(&vcc->stats->tx_err);
36280 return -ENOBUFS;
36281 }
36282 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36283@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36284 if (vcc->pop) vcc->pop(vcc,skb);
36285 else dev_kfree_skb(skb);
36286 out_vcc->push(out_vcc,new_skb);
36287- atomic_inc(&vcc->stats->tx);
36288- atomic_inc(&out_vcc->stats->rx);
36289+ atomic_inc_unchecked(&vcc->stats->tx);
36290+ atomic_inc_unchecked(&out_vcc->stats->rx);
36291 return 0;
36292 }
36293
36294@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36295 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36296 read_unlock(&vcc_sklist_lock);
36297 if (!out_vcc) {
36298- atomic_inc(&vcc->stats->tx_err);
36299+ atomic_inc_unchecked(&vcc->stats->tx_err);
36300 goto done;
36301 }
36302 skb_pull(skb,sizeof(struct atmtcp_hdr));
36303@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36304 __net_timestamp(new_skb);
36305 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36306 out_vcc->push(out_vcc,new_skb);
36307- atomic_inc(&vcc->stats->tx);
36308- atomic_inc(&out_vcc->stats->rx);
36309+ atomic_inc_unchecked(&vcc->stats->tx);
36310+ atomic_inc_unchecked(&out_vcc->stats->rx);
36311 done:
36312 if (vcc->pop) vcc->pop(vcc,skb);
36313 else dev_kfree_skb(skb);
36314diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36315index b1955ba..b179940 100644
36316--- a/drivers/atm/eni.c
36317+++ b/drivers/atm/eni.c
36318@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36319 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36320 vcc->dev->number);
36321 length = 0;
36322- atomic_inc(&vcc->stats->rx_err);
36323+ atomic_inc_unchecked(&vcc->stats->rx_err);
36324 }
36325 else {
36326 length = ATM_CELL_SIZE-1; /* no HEC */
36327@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36328 size);
36329 }
36330 eff = length = 0;
36331- atomic_inc(&vcc->stats->rx_err);
36332+ atomic_inc_unchecked(&vcc->stats->rx_err);
36333 }
36334 else {
36335 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36336@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36337 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36338 vcc->dev->number,vcc->vci,length,size << 2,descr);
36339 length = eff = 0;
36340- atomic_inc(&vcc->stats->rx_err);
36341+ atomic_inc_unchecked(&vcc->stats->rx_err);
36342 }
36343 }
36344 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36345@@ -767,7 +767,7 @@ rx_dequeued++;
36346 vcc->push(vcc,skb);
36347 pushed++;
36348 }
36349- atomic_inc(&vcc->stats->rx);
36350+ atomic_inc_unchecked(&vcc->stats->rx);
36351 }
36352 wake_up(&eni_dev->rx_wait);
36353 }
36354@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36355 PCI_DMA_TODEVICE);
36356 if (vcc->pop) vcc->pop(vcc,skb);
36357 else dev_kfree_skb_irq(skb);
36358- atomic_inc(&vcc->stats->tx);
36359+ atomic_inc_unchecked(&vcc->stats->tx);
36360 wake_up(&eni_dev->tx_wait);
36361 dma_complete++;
36362 }
36363diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36364index b41c948..a002b17 100644
36365--- a/drivers/atm/firestream.c
36366+++ b/drivers/atm/firestream.c
36367@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36368 }
36369 }
36370
36371- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36372+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36373
36374 fs_dprintk (FS_DEBUG_TXMEM, "i");
36375 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36376@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36377 #endif
36378 skb_put (skb, qe->p1 & 0xffff);
36379 ATM_SKB(skb)->vcc = atm_vcc;
36380- atomic_inc(&atm_vcc->stats->rx);
36381+ atomic_inc_unchecked(&atm_vcc->stats->rx);
36382 __net_timestamp(skb);
36383 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36384 atm_vcc->push (atm_vcc, skb);
36385@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36386 kfree (pe);
36387 }
36388 if (atm_vcc)
36389- atomic_inc(&atm_vcc->stats->rx_drop);
36390+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36391 break;
36392 case 0x1f: /* Reassembly abort: no buffers. */
36393 /* Silently increment error counter. */
36394 if (atm_vcc)
36395- atomic_inc(&atm_vcc->stats->rx_drop);
36396+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36397 break;
36398 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36399 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36400diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36401index 204814e..cede831 100644
36402--- a/drivers/atm/fore200e.c
36403+++ b/drivers/atm/fore200e.c
36404@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36405 #endif
36406 /* check error condition */
36407 if (*entry->status & STATUS_ERROR)
36408- atomic_inc(&vcc->stats->tx_err);
36409+ atomic_inc_unchecked(&vcc->stats->tx_err);
36410 else
36411- atomic_inc(&vcc->stats->tx);
36412+ atomic_inc_unchecked(&vcc->stats->tx);
36413 }
36414 }
36415
36416@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36417 if (skb == NULL) {
36418 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36419
36420- atomic_inc(&vcc->stats->rx_drop);
36421+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36422 return -ENOMEM;
36423 }
36424
36425@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36426
36427 dev_kfree_skb_any(skb);
36428
36429- atomic_inc(&vcc->stats->rx_drop);
36430+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36431 return -ENOMEM;
36432 }
36433
36434 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36435
36436 vcc->push(vcc, skb);
36437- atomic_inc(&vcc->stats->rx);
36438+ atomic_inc_unchecked(&vcc->stats->rx);
36439
36440 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36441
36442@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36443 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36444 fore200e->atm_dev->number,
36445 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36446- atomic_inc(&vcc->stats->rx_err);
36447+ atomic_inc_unchecked(&vcc->stats->rx_err);
36448 }
36449 }
36450
36451@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36452 goto retry_here;
36453 }
36454
36455- atomic_inc(&vcc->stats->tx_err);
36456+ atomic_inc_unchecked(&vcc->stats->tx_err);
36457
36458 fore200e->tx_sat++;
36459 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36460diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36461index 8557adc..3fb5d55 100644
36462--- a/drivers/atm/he.c
36463+++ b/drivers/atm/he.c
36464@@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36465
36466 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36467 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36468- atomic_inc(&vcc->stats->rx_drop);
36469+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36470 goto return_host_buffers;
36471 }
36472
36473@@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36474 RBRQ_LEN_ERR(he_dev->rbrq_head)
36475 ? "LEN_ERR" : "",
36476 vcc->vpi, vcc->vci);
36477- atomic_inc(&vcc->stats->rx_err);
36478+ atomic_inc_unchecked(&vcc->stats->rx_err);
36479 goto return_host_buffers;
36480 }
36481
36482@@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36483 vcc->push(vcc, skb);
36484 spin_lock(&he_dev->global_lock);
36485
36486- atomic_inc(&vcc->stats->rx);
36487+ atomic_inc_unchecked(&vcc->stats->rx);
36488
36489 return_host_buffers:
36490 ++pdus_assembled;
36491@@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36492 tpd->vcc->pop(tpd->vcc, tpd->skb);
36493 else
36494 dev_kfree_skb_any(tpd->skb);
36495- atomic_inc(&tpd->vcc->stats->tx_err);
36496+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36497 }
36498 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36499 return;
36500@@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36501 vcc->pop(vcc, skb);
36502 else
36503 dev_kfree_skb_any(skb);
36504- atomic_inc(&vcc->stats->tx_err);
36505+ atomic_inc_unchecked(&vcc->stats->tx_err);
36506 return -EINVAL;
36507 }
36508
36509@@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36510 vcc->pop(vcc, skb);
36511 else
36512 dev_kfree_skb_any(skb);
36513- atomic_inc(&vcc->stats->tx_err);
36514+ atomic_inc_unchecked(&vcc->stats->tx_err);
36515 return -EINVAL;
36516 }
36517 #endif
36518@@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36519 vcc->pop(vcc, skb);
36520 else
36521 dev_kfree_skb_any(skb);
36522- atomic_inc(&vcc->stats->tx_err);
36523+ atomic_inc_unchecked(&vcc->stats->tx_err);
36524 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36525 return -ENOMEM;
36526 }
36527@@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36528 vcc->pop(vcc, skb);
36529 else
36530 dev_kfree_skb_any(skb);
36531- atomic_inc(&vcc->stats->tx_err);
36532+ atomic_inc_unchecked(&vcc->stats->tx_err);
36533 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36534 return -ENOMEM;
36535 }
36536@@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36537 __enqueue_tpd(he_dev, tpd, cid);
36538 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36539
36540- atomic_inc(&vcc->stats->tx);
36541+ atomic_inc_unchecked(&vcc->stats->tx);
36542
36543 return 0;
36544 }
36545diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36546index 1dc0519..1aadaf7 100644
36547--- a/drivers/atm/horizon.c
36548+++ b/drivers/atm/horizon.c
36549@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36550 {
36551 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36552 // VC layer stats
36553- atomic_inc(&vcc->stats->rx);
36554+ atomic_inc_unchecked(&vcc->stats->rx);
36555 __net_timestamp(skb);
36556 // end of our responsibility
36557 vcc->push (vcc, skb);
36558@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36559 dev->tx_iovec = NULL;
36560
36561 // VC layer stats
36562- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36563+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36564
36565 // free the skb
36566 hrz_kfree_skb (skb);
36567diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36568index 1bdf104..9dc44b1 100644
36569--- a/drivers/atm/idt77252.c
36570+++ b/drivers/atm/idt77252.c
36571@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36572 else
36573 dev_kfree_skb(skb);
36574
36575- atomic_inc(&vcc->stats->tx);
36576+ atomic_inc_unchecked(&vcc->stats->tx);
36577 }
36578
36579 atomic_dec(&scq->used);
36580@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36581 if ((sb = dev_alloc_skb(64)) == NULL) {
36582 printk("%s: Can't allocate buffers for aal0.\n",
36583 card->name);
36584- atomic_add(i, &vcc->stats->rx_drop);
36585+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36586 break;
36587 }
36588 if (!atm_charge(vcc, sb->truesize)) {
36589 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36590 card->name);
36591- atomic_add(i - 1, &vcc->stats->rx_drop);
36592+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36593 dev_kfree_skb(sb);
36594 break;
36595 }
36596@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36597 ATM_SKB(sb)->vcc = vcc;
36598 __net_timestamp(sb);
36599 vcc->push(vcc, sb);
36600- atomic_inc(&vcc->stats->rx);
36601+ atomic_inc_unchecked(&vcc->stats->rx);
36602
36603 cell += ATM_CELL_PAYLOAD;
36604 }
36605@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36606 "(CDC: %08x)\n",
36607 card->name, len, rpp->len, readl(SAR_REG_CDC));
36608 recycle_rx_pool_skb(card, rpp);
36609- atomic_inc(&vcc->stats->rx_err);
36610+ atomic_inc_unchecked(&vcc->stats->rx_err);
36611 return;
36612 }
36613 if (stat & SAR_RSQE_CRC) {
36614 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36615 recycle_rx_pool_skb(card, rpp);
36616- atomic_inc(&vcc->stats->rx_err);
36617+ atomic_inc_unchecked(&vcc->stats->rx_err);
36618 return;
36619 }
36620 if (skb_queue_len(&rpp->queue) > 1) {
36621@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36622 RXPRINTK("%s: Can't alloc RX skb.\n",
36623 card->name);
36624 recycle_rx_pool_skb(card, rpp);
36625- atomic_inc(&vcc->stats->rx_err);
36626+ atomic_inc_unchecked(&vcc->stats->rx_err);
36627 return;
36628 }
36629 if (!atm_charge(vcc, skb->truesize)) {
36630@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36631 __net_timestamp(skb);
36632
36633 vcc->push(vcc, skb);
36634- atomic_inc(&vcc->stats->rx);
36635+ atomic_inc_unchecked(&vcc->stats->rx);
36636
36637 return;
36638 }
36639@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36640 __net_timestamp(skb);
36641
36642 vcc->push(vcc, skb);
36643- atomic_inc(&vcc->stats->rx);
36644+ atomic_inc_unchecked(&vcc->stats->rx);
36645
36646 if (skb->truesize > SAR_FB_SIZE_3)
36647 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36648@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36649 if (vcc->qos.aal != ATM_AAL0) {
36650 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36651 card->name, vpi, vci);
36652- atomic_inc(&vcc->stats->rx_drop);
36653+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36654 goto drop;
36655 }
36656
36657 if ((sb = dev_alloc_skb(64)) == NULL) {
36658 printk("%s: Can't allocate buffers for AAL0.\n",
36659 card->name);
36660- atomic_inc(&vcc->stats->rx_err);
36661+ atomic_inc_unchecked(&vcc->stats->rx_err);
36662 goto drop;
36663 }
36664
36665@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36666 ATM_SKB(sb)->vcc = vcc;
36667 __net_timestamp(sb);
36668 vcc->push(vcc, sb);
36669- atomic_inc(&vcc->stats->rx);
36670+ atomic_inc_unchecked(&vcc->stats->rx);
36671
36672 drop:
36673 skb_pull(queue, 64);
36674@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36675
36676 if (vc == NULL) {
36677 printk("%s: NULL connection in send().\n", card->name);
36678- atomic_inc(&vcc->stats->tx_err);
36679+ atomic_inc_unchecked(&vcc->stats->tx_err);
36680 dev_kfree_skb(skb);
36681 return -EINVAL;
36682 }
36683 if (!test_bit(VCF_TX, &vc->flags)) {
36684 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36685- atomic_inc(&vcc->stats->tx_err);
36686+ atomic_inc_unchecked(&vcc->stats->tx_err);
36687 dev_kfree_skb(skb);
36688 return -EINVAL;
36689 }
36690@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36691 break;
36692 default:
36693 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36694- atomic_inc(&vcc->stats->tx_err);
36695+ atomic_inc_unchecked(&vcc->stats->tx_err);
36696 dev_kfree_skb(skb);
36697 return -EINVAL;
36698 }
36699
36700 if (skb_shinfo(skb)->nr_frags != 0) {
36701 printk("%s: No scatter-gather yet.\n", card->name);
36702- atomic_inc(&vcc->stats->tx_err);
36703+ atomic_inc_unchecked(&vcc->stats->tx_err);
36704 dev_kfree_skb(skb);
36705 return -EINVAL;
36706 }
36707@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36708
36709 err = queue_skb(card, vc, skb, oam);
36710 if (err) {
36711- atomic_inc(&vcc->stats->tx_err);
36712+ atomic_inc_unchecked(&vcc->stats->tx_err);
36713 dev_kfree_skb(skb);
36714 return err;
36715 }
36716@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36717 skb = dev_alloc_skb(64);
36718 if (!skb) {
36719 printk("%s: Out of memory in send_oam().\n", card->name);
36720- atomic_inc(&vcc->stats->tx_err);
36721+ atomic_inc_unchecked(&vcc->stats->tx_err);
36722 return -ENOMEM;
36723 }
36724 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36725diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36726index 4217f29..88f547a 100644
36727--- a/drivers/atm/iphase.c
36728+++ b/drivers/atm/iphase.c
36729@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36730 status = (u_short) (buf_desc_ptr->desc_mode);
36731 if (status & (RX_CER | RX_PTE | RX_OFL))
36732 {
36733- atomic_inc(&vcc->stats->rx_err);
36734+ atomic_inc_unchecked(&vcc->stats->rx_err);
36735 IF_ERR(printk("IA: bad packet, dropping it");)
36736 if (status & RX_CER) {
36737 IF_ERR(printk(" cause: packet CRC error\n");)
36738@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36739 len = dma_addr - buf_addr;
36740 if (len > iadev->rx_buf_sz) {
36741 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36742- atomic_inc(&vcc->stats->rx_err);
36743+ atomic_inc_unchecked(&vcc->stats->rx_err);
36744 goto out_free_desc;
36745 }
36746
36747@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36748 ia_vcc = INPH_IA_VCC(vcc);
36749 if (ia_vcc == NULL)
36750 {
36751- atomic_inc(&vcc->stats->rx_err);
36752+ atomic_inc_unchecked(&vcc->stats->rx_err);
36753 atm_return(vcc, skb->truesize);
36754 dev_kfree_skb_any(skb);
36755 goto INCR_DLE;
36756@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36757 if ((length > iadev->rx_buf_sz) || (length >
36758 (skb->len - sizeof(struct cpcs_trailer))))
36759 {
36760- atomic_inc(&vcc->stats->rx_err);
36761+ atomic_inc_unchecked(&vcc->stats->rx_err);
36762 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36763 length, skb->len);)
36764 atm_return(vcc, skb->truesize);
36765@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36766
36767 IF_RX(printk("rx_dle_intr: skb push");)
36768 vcc->push(vcc,skb);
36769- atomic_inc(&vcc->stats->rx);
36770+ atomic_inc_unchecked(&vcc->stats->rx);
36771 iadev->rx_pkt_cnt++;
36772 }
36773 INCR_DLE:
36774@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36775 {
36776 struct k_sonet_stats *stats;
36777 stats = &PRIV(_ia_dev[board])->sonet_stats;
36778- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36779- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36780- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36781- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36782- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36783- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36784- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36785- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36786- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36787+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36788+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36789+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36790+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36791+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36792+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36793+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36794+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36795+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36796 }
36797 ia_cmds.status = 0;
36798 break;
36799@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36800 if ((desc == 0) || (desc > iadev->num_tx_desc))
36801 {
36802 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36803- atomic_inc(&vcc->stats->tx);
36804+ atomic_inc_unchecked(&vcc->stats->tx);
36805 if (vcc->pop)
36806 vcc->pop(vcc, skb);
36807 else
36808@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36809 ATM_DESC(skb) = vcc->vci;
36810 skb_queue_tail(&iadev->tx_dma_q, skb);
36811
36812- atomic_inc(&vcc->stats->tx);
36813+ atomic_inc_unchecked(&vcc->stats->tx);
36814 iadev->tx_pkt_cnt++;
36815 /* Increment transaction counter */
36816 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36817
36818 #if 0
36819 /* add flow control logic */
36820- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36821+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36822 if (iavcc->vc_desc_cnt > 10) {
36823 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36824 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36825diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36826index fa7d701..1e404c7 100644
36827--- a/drivers/atm/lanai.c
36828+++ b/drivers/atm/lanai.c
36829@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36830 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36831 lanai_endtx(lanai, lvcc);
36832 lanai_free_skb(lvcc->tx.atmvcc, skb);
36833- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36834+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36835 }
36836
36837 /* Try to fill the buffer - don't call unless there is backlog */
36838@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36839 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36840 __net_timestamp(skb);
36841 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36842- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36843+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36844 out:
36845 lvcc->rx.buf.ptr = end;
36846 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36847@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36848 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36849 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36850 lanai->stats.service_rxnotaal5++;
36851- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36852+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36853 return 0;
36854 }
36855 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36856@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36857 int bytes;
36858 read_unlock(&vcc_sklist_lock);
36859 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36860- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36861+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36862 lvcc->stats.x.aal5.service_trash++;
36863 bytes = (SERVICE_GET_END(s) * 16) -
36864 (((unsigned long) lvcc->rx.buf.ptr) -
36865@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36866 }
36867 if (s & SERVICE_STREAM) {
36868 read_unlock(&vcc_sklist_lock);
36869- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36870+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36871 lvcc->stats.x.aal5.service_stream++;
36872 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36873 "PDU on VCI %d!\n", lanai->number, vci);
36874@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36875 return 0;
36876 }
36877 DPRINTK("got rx crc error on vci %d\n", vci);
36878- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36879+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36880 lvcc->stats.x.aal5.service_rxcrc++;
36881 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36882 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36883diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36884index 5aca5f4..ce3a6b0 100644
36885--- a/drivers/atm/nicstar.c
36886+++ b/drivers/atm/nicstar.c
36887@@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36888 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36889 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36890 card->index);
36891- atomic_inc(&vcc->stats->tx_err);
36892+ atomic_inc_unchecked(&vcc->stats->tx_err);
36893 dev_kfree_skb_any(skb);
36894 return -EINVAL;
36895 }
36896@@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36897 if (!vc->tx) {
36898 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36899 card->index);
36900- atomic_inc(&vcc->stats->tx_err);
36901+ atomic_inc_unchecked(&vcc->stats->tx_err);
36902 dev_kfree_skb_any(skb);
36903 return -EINVAL;
36904 }
36905@@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36906 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36907 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36908 card->index);
36909- atomic_inc(&vcc->stats->tx_err);
36910+ atomic_inc_unchecked(&vcc->stats->tx_err);
36911 dev_kfree_skb_any(skb);
36912 return -EINVAL;
36913 }
36914
36915 if (skb_shinfo(skb)->nr_frags != 0) {
36916 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36917- atomic_inc(&vcc->stats->tx_err);
36918+ atomic_inc_unchecked(&vcc->stats->tx_err);
36919 dev_kfree_skb_any(skb);
36920 return -EINVAL;
36921 }
36922@@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36923 }
36924
36925 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36926- atomic_inc(&vcc->stats->tx_err);
36927+ atomic_inc_unchecked(&vcc->stats->tx_err);
36928 dev_kfree_skb_any(skb);
36929 return -EIO;
36930 }
36931- atomic_inc(&vcc->stats->tx);
36932+ atomic_inc_unchecked(&vcc->stats->tx);
36933
36934 return 0;
36935 }
36936@@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36937 printk
36938 ("nicstar%d: Can't allocate buffers for aal0.\n",
36939 card->index);
36940- atomic_add(i, &vcc->stats->rx_drop);
36941+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
36942 break;
36943 }
36944 if (!atm_charge(vcc, sb->truesize)) {
36945 RXPRINTK
36946 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36947 card->index);
36948- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36949+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36950 dev_kfree_skb_any(sb);
36951 break;
36952 }
36953@@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36954 ATM_SKB(sb)->vcc = vcc;
36955 __net_timestamp(sb);
36956 vcc->push(vcc, sb);
36957- atomic_inc(&vcc->stats->rx);
36958+ atomic_inc_unchecked(&vcc->stats->rx);
36959 cell += ATM_CELL_PAYLOAD;
36960 }
36961
36962@@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36963 if (iovb == NULL) {
36964 printk("nicstar%d: Out of iovec buffers.\n",
36965 card->index);
36966- atomic_inc(&vcc->stats->rx_drop);
36967+ atomic_inc_unchecked(&vcc->stats->rx_drop);
36968 recycle_rx_buf(card, skb);
36969 return;
36970 }
36971@@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36972 small or large buffer itself. */
36973 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36974 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36975- atomic_inc(&vcc->stats->rx_err);
36976+ atomic_inc_unchecked(&vcc->stats->rx_err);
36977 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36978 NS_MAX_IOVECS);
36979 NS_PRV_IOVCNT(iovb) = 0;
36980@@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36981 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36982 card->index);
36983 which_list(card, skb);
36984- atomic_inc(&vcc->stats->rx_err);
36985+ atomic_inc_unchecked(&vcc->stats->rx_err);
36986 recycle_rx_buf(card, skb);
36987 vc->rx_iov = NULL;
36988 recycle_iov_buf(card, iovb);
36989@@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36990 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36991 card->index);
36992 which_list(card, skb);
36993- atomic_inc(&vcc->stats->rx_err);
36994+ atomic_inc_unchecked(&vcc->stats->rx_err);
36995 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36996 NS_PRV_IOVCNT(iovb));
36997 vc->rx_iov = NULL;
36998@@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36999 printk(" - PDU size mismatch.\n");
37000 else
37001 printk(".\n");
37002- atomic_inc(&vcc->stats->rx_err);
37003+ atomic_inc_unchecked(&vcc->stats->rx_err);
37004 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37005 NS_PRV_IOVCNT(iovb));
37006 vc->rx_iov = NULL;
37007@@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37008 /* skb points to a small buffer */
37009 if (!atm_charge(vcc, skb->truesize)) {
37010 push_rxbufs(card, skb);
37011- atomic_inc(&vcc->stats->rx_drop);
37012+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37013 } else {
37014 skb_put(skb, len);
37015 dequeue_sm_buf(card, skb);
37016@@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37017 ATM_SKB(skb)->vcc = vcc;
37018 __net_timestamp(skb);
37019 vcc->push(vcc, skb);
37020- atomic_inc(&vcc->stats->rx);
37021+ atomic_inc_unchecked(&vcc->stats->rx);
37022 }
37023 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37024 struct sk_buff *sb;
37025@@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37026 if (len <= NS_SMBUFSIZE) {
37027 if (!atm_charge(vcc, sb->truesize)) {
37028 push_rxbufs(card, sb);
37029- atomic_inc(&vcc->stats->rx_drop);
37030+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37031 } else {
37032 skb_put(sb, len);
37033 dequeue_sm_buf(card, sb);
37034@@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37035 ATM_SKB(sb)->vcc = vcc;
37036 __net_timestamp(sb);
37037 vcc->push(vcc, sb);
37038- atomic_inc(&vcc->stats->rx);
37039+ atomic_inc_unchecked(&vcc->stats->rx);
37040 }
37041
37042 push_rxbufs(card, skb);
37043@@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37044
37045 if (!atm_charge(vcc, skb->truesize)) {
37046 push_rxbufs(card, skb);
37047- atomic_inc(&vcc->stats->rx_drop);
37048+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37049 } else {
37050 dequeue_lg_buf(card, skb);
37051 #ifdef NS_USE_DESTRUCTORS
37052@@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37053 ATM_SKB(skb)->vcc = vcc;
37054 __net_timestamp(skb);
37055 vcc->push(vcc, skb);
37056- atomic_inc(&vcc->stats->rx);
37057+ atomic_inc_unchecked(&vcc->stats->rx);
37058 }
37059
37060 push_rxbufs(card, sb);
37061@@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37062 printk
37063 ("nicstar%d: Out of huge buffers.\n",
37064 card->index);
37065- atomic_inc(&vcc->stats->rx_drop);
37066+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37067 recycle_iovec_rx_bufs(card,
37068 (struct iovec *)
37069 iovb->data,
37070@@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37071 card->hbpool.count++;
37072 } else
37073 dev_kfree_skb_any(hb);
37074- atomic_inc(&vcc->stats->rx_drop);
37075+ atomic_inc_unchecked(&vcc->stats->rx_drop);
37076 } else {
37077 /* Copy the small buffer to the huge buffer */
37078 sb = (struct sk_buff *)iov->iov_base;
37079@@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37080 #endif /* NS_USE_DESTRUCTORS */
37081 __net_timestamp(hb);
37082 vcc->push(vcc, hb);
37083- atomic_inc(&vcc->stats->rx);
37084+ atomic_inc_unchecked(&vcc->stats->rx);
37085 }
37086 }
37087
37088diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37089index 32784d1..4a8434a 100644
37090--- a/drivers/atm/solos-pci.c
37091+++ b/drivers/atm/solos-pci.c
37092@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
37093 }
37094 atm_charge(vcc, skb->truesize);
37095 vcc->push(vcc, skb);
37096- atomic_inc(&vcc->stats->rx);
37097+ atomic_inc_unchecked(&vcc->stats->rx);
37098 break;
37099
37100 case PKT_STATUS:
37101@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37102 vcc = SKB_CB(oldskb)->vcc;
37103
37104 if (vcc) {
37105- atomic_inc(&vcc->stats->tx);
37106+ atomic_inc_unchecked(&vcc->stats->tx);
37107 solos_pop(vcc, oldskb);
37108 } else {
37109 dev_kfree_skb_irq(oldskb);
37110diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37111index 0215934..ce9f5b1 100644
37112--- a/drivers/atm/suni.c
37113+++ b/drivers/atm/suni.c
37114@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37115
37116
37117 #define ADD_LIMITED(s,v) \
37118- atomic_add((v),&stats->s); \
37119- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37120+ atomic_add_unchecked((v),&stats->s); \
37121+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37122
37123
37124 static void suni_hz(unsigned long from_timer)
37125diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37126index 5120a96..e2572bd 100644
37127--- a/drivers/atm/uPD98402.c
37128+++ b/drivers/atm/uPD98402.c
37129@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37130 struct sonet_stats tmp;
37131 int error = 0;
37132
37133- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37134+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37135 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37136 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37137 if (zero && !error) {
37138@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37139
37140
37141 #define ADD_LIMITED(s,v) \
37142- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37143- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37144- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37145+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37146+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37147+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37148
37149
37150 static void stat_event(struct atm_dev *dev)
37151@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37152 if (reason & uPD98402_INT_PFM) stat_event(dev);
37153 if (reason & uPD98402_INT_PCO) {
37154 (void) GET(PCOCR); /* clear interrupt cause */
37155- atomic_add(GET(HECCT),
37156+ atomic_add_unchecked(GET(HECCT),
37157 &PRIV(dev)->sonet_stats.uncorr_hcs);
37158 }
37159 if ((reason & uPD98402_INT_RFO) &&
37160@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37161 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37162 uPD98402_INT_LOS),PIMR); /* enable them */
37163 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37164- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37165- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37166- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37167+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37168+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37169+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37170 return 0;
37171 }
37172
37173diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37174index 969c3c2..9b72956 100644
37175--- a/drivers/atm/zatm.c
37176+++ b/drivers/atm/zatm.c
37177@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37178 }
37179 if (!size) {
37180 dev_kfree_skb_irq(skb);
37181- if (vcc) atomic_inc(&vcc->stats->rx_err);
37182+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37183 continue;
37184 }
37185 if (!atm_charge(vcc,skb->truesize)) {
37186@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37187 skb->len = size;
37188 ATM_SKB(skb)->vcc = vcc;
37189 vcc->push(vcc,skb);
37190- atomic_inc(&vcc->stats->rx);
37191+ atomic_inc_unchecked(&vcc->stats->rx);
37192 }
37193 zout(pos & 0xffff,MTA(mbx));
37194 #if 0 /* probably a stupid idea */
37195@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37196 skb_queue_head(&zatm_vcc->backlog,skb);
37197 break;
37198 }
37199- atomic_inc(&vcc->stats->tx);
37200+ atomic_inc_unchecked(&vcc->stats->tx);
37201 wake_up(&zatm_vcc->tx_wait);
37202 }
37203
37204diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37205index 73f6c29..b0c0e13 100644
37206--- a/drivers/base/bus.c
37207+++ b/drivers/base/bus.c
37208@@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37209 return -EINVAL;
37210
37211 mutex_lock(&subsys->p->mutex);
37212- list_add_tail(&sif->node, &subsys->p->interfaces);
37213+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37214 if (sif->add_dev) {
37215 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37216 while ((dev = subsys_dev_iter_next(&iter)))
37217@@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37218 subsys = sif->subsys;
37219
37220 mutex_lock(&subsys->p->mutex);
37221- list_del_init(&sif->node);
37222+ pax_list_del_init((struct list_head *)&sif->node);
37223 if (sif->remove_dev) {
37224 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37225 while ((dev = subsys_dev_iter_next(&iter)))
37226diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37227index 0f38201..6c2b444 100644
37228--- a/drivers/base/devtmpfs.c
37229+++ b/drivers/base/devtmpfs.c
37230@@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37231 if (!thread)
37232 return 0;
37233
37234- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37235+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37236 if (err)
37237 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37238 else
37239@@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37240 *err = sys_unshare(CLONE_NEWNS);
37241 if (*err)
37242 goto out;
37243- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37244+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37245 if (*err)
37246 goto out;
37247- sys_chdir("/.."); /* will traverse into overmounted root */
37248- sys_chroot(".");
37249+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37250+ sys_chroot((char __force_user *)".");
37251 complete(&setup_done);
37252 while (1) {
37253 spin_lock(&req_lock);
37254diff --git a/drivers/base/node.c b/drivers/base/node.c
37255index bc9f43b..29703b8 100644
37256--- a/drivers/base/node.c
37257+++ b/drivers/base/node.c
37258@@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37259 struct node_attr {
37260 struct device_attribute attr;
37261 enum node_states state;
37262-};
37263+} __do_const;
37264
37265 static ssize_t show_node_state(struct device *dev,
37266 struct device_attribute *attr, char *buf)
37267diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37268index bfb8955..4ebff34 100644
37269--- a/drivers/base/power/domain.c
37270+++ b/drivers/base/power/domain.c
37271@@ -1809,9 +1809,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37272
37273 if (dev->power.subsys_data->domain_data) {
37274 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37275- gpd_data->ops = (struct gpd_dev_ops){ NULL };
37276+ memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37277 if (clear_td)
37278- gpd_data->td = (struct gpd_timing_data){ 0 };
37279+ memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37280
37281 if (--gpd_data->refcount == 0) {
37282 dev->power.subsys_data->domain_data = NULL;
37283@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37284 {
37285 struct cpuidle_driver *cpuidle_drv;
37286 struct gpd_cpu_data *cpu_data;
37287- struct cpuidle_state *idle_state;
37288+ cpuidle_state_no_const *idle_state;
37289 int ret = 0;
37290
37291 if (IS_ERR_OR_NULL(genpd) || state < 0)
37292@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37293 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37294 {
37295 struct gpd_cpu_data *cpu_data;
37296- struct cpuidle_state *idle_state;
37297+ cpuidle_state_no_const *idle_state;
37298 int ret = 0;
37299
37300 if (IS_ERR_OR_NULL(genpd))
37301diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37302index 03e089a..0e9560c 100644
37303--- a/drivers/base/power/sysfs.c
37304+++ b/drivers/base/power/sysfs.c
37305@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37306 return -EIO;
37307 }
37308 }
37309- return sprintf(buf, p);
37310+ return sprintf(buf, "%s", p);
37311 }
37312
37313 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37314diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37315index 2d56f41..8830f19 100644
37316--- a/drivers/base/power/wakeup.c
37317+++ b/drivers/base/power/wakeup.c
37318@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37319 * They need to be modified together atomically, so it's better to use one
37320 * atomic variable to hold them both.
37321 */
37322-static atomic_t combined_event_count = ATOMIC_INIT(0);
37323+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37324
37325 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37326 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37327
37328 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37329 {
37330- unsigned int comb = atomic_read(&combined_event_count);
37331+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
37332
37333 *cnt = (comb >> IN_PROGRESS_BITS);
37334 *inpr = comb & MAX_IN_PROGRESS;
37335@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37336 ws->start_prevent_time = ws->last_time;
37337
37338 /* Increment the counter of events in progress. */
37339- cec = atomic_inc_return(&combined_event_count);
37340+ cec = atomic_inc_return_unchecked(&combined_event_count);
37341
37342 trace_wakeup_source_activate(ws->name, cec);
37343 }
37344@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37345 * Increment the counter of registered wakeup events and decrement the
37346 * couter of wakeup events in progress simultaneously.
37347 */
37348- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37349+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37350 trace_wakeup_source_deactivate(ws->name, cec);
37351
37352 split_counters(&cnt, &inpr);
37353diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37354index e8d11b6..7b1b36f 100644
37355--- a/drivers/base/syscore.c
37356+++ b/drivers/base/syscore.c
37357@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37358 void register_syscore_ops(struct syscore_ops *ops)
37359 {
37360 mutex_lock(&syscore_ops_lock);
37361- list_add_tail(&ops->node, &syscore_ops_list);
37362+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37363 mutex_unlock(&syscore_ops_lock);
37364 }
37365 EXPORT_SYMBOL_GPL(register_syscore_ops);
37366@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37367 void unregister_syscore_ops(struct syscore_ops *ops)
37368 {
37369 mutex_lock(&syscore_ops_lock);
37370- list_del(&ops->node);
37371+ pax_list_del((struct list_head *)&ops->node);
37372 mutex_unlock(&syscore_ops_lock);
37373 }
37374 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37375diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37376index b35fc4f..c902870 100644
37377--- a/drivers/block/cciss.c
37378+++ b/drivers/block/cciss.c
37379@@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37380 while (!list_empty(&h->reqQ)) {
37381 c = list_entry(h->reqQ.next, CommandList_struct, list);
37382 /* can't do anything if fifo is full */
37383- if ((h->access.fifo_full(h))) {
37384+ if ((h->access->fifo_full(h))) {
37385 dev_warn(&h->pdev->dev, "fifo full\n");
37386 break;
37387 }
37388@@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37389 h->Qdepth--;
37390
37391 /* Tell the controller execute command */
37392- h->access.submit_command(h, c);
37393+ h->access->submit_command(h, c);
37394
37395 /* Put job onto the completed Q */
37396 addQ(&h->cmpQ, c);
37397@@ -3447,17 +3447,17 @@ startio:
37398
37399 static inline unsigned long get_next_completion(ctlr_info_t *h)
37400 {
37401- return h->access.command_completed(h);
37402+ return h->access->command_completed(h);
37403 }
37404
37405 static inline int interrupt_pending(ctlr_info_t *h)
37406 {
37407- return h->access.intr_pending(h);
37408+ return h->access->intr_pending(h);
37409 }
37410
37411 static inline long interrupt_not_for_us(ctlr_info_t *h)
37412 {
37413- return ((h->access.intr_pending(h) == 0) ||
37414+ return ((h->access->intr_pending(h) == 0) ||
37415 (h->interrupts_enabled == 0));
37416 }
37417
37418@@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37419 u32 a;
37420
37421 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37422- return h->access.command_completed(h);
37423+ return h->access->command_completed(h);
37424
37425 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37426 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37427@@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37428 trans_support & CFGTBL_Trans_use_short_tags);
37429
37430 /* Change the access methods to the performant access methods */
37431- h->access = SA5_performant_access;
37432+ h->access = &SA5_performant_access;
37433 h->transMethod = CFGTBL_Trans_Performant;
37434
37435 return;
37436@@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37437 if (prod_index < 0)
37438 return -ENODEV;
37439 h->product_name = products[prod_index].product_name;
37440- h->access = *(products[prod_index].access);
37441+ h->access = products[prod_index].access;
37442
37443 if (cciss_board_disabled(h)) {
37444 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37445@@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
37446 }
37447
37448 /* make sure the board interrupts are off */
37449- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37450+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37451 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37452 if (rc)
37453 goto clean2;
37454@@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
37455 * fake ones to scoop up any residual completions.
37456 */
37457 spin_lock_irqsave(&h->lock, flags);
37458- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37459+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37460 spin_unlock_irqrestore(&h->lock, flags);
37461 free_irq(h->intr[h->intr_mode], h);
37462 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37463@@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
37464 dev_info(&h->pdev->dev, "Board READY.\n");
37465 dev_info(&h->pdev->dev,
37466 "Waiting for stale completions to drain.\n");
37467- h->access.set_intr_mask(h, CCISS_INTR_ON);
37468+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37469 msleep(10000);
37470- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37471+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37472
37473 rc = controller_reset_failed(h->cfgtable);
37474 if (rc)
37475@@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
37476 cciss_scsi_setup(h);
37477
37478 /* Turn the interrupts on so we can service requests */
37479- h->access.set_intr_mask(h, CCISS_INTR_ON);
37480+ h->access->set_intr_mask(h, CCISS_INTR_ON);
37481
37482 /* Get the firmware version */
37483 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37484@@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37485 kfree(flush_buf);
37486 if (return_code != IO_OK)
37487 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37488- h->access.set_intr_mask(h, CCISS_INTR_OFF);
37489+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
37490 free_irq(h->intr[h->intr_mode], h);
37491 }
37492
37493diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37494index 7fda30e..2f27946 100644
37495--- a/drivers/block/cciss.h
37496+++ b/drivers/block/cciss.h
37497@@ -101,7 +101,7 @@ struct ctlr_info
37498 /* information about each logical volume */
37499 drive_info_struct *drv[CISS_MAX_LUN];
37500
37501- struct access_method access;
37502+ struct access_method *access;
37503
37504 /* queue and queue Info */
37505 struct list_head reqQ;
37506@@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37507 }
37508
37509 static struct access_method SA5_access = {
37510- SA5_submit_command,
37511- SA5_intr_mask,
37512- SA5_fifo_full,
37513- SA5_intr_pending,
37514- SA5_completed,
37515+ .submit_command = SA5_submit_command,
37516+ .set_intr_mask = SA5_intr_mask,
37517+ .fifo_full = SA5_fifo_full,
37518+ .intr_pending = SA5_intr_pending,
37519+ .command_completed = SA5_completed,
37520 };
37521
37522 static struct access_method SA5B_access = {
37523- SA5_submit_command,
37524- SA5B_intr_mask,
37525- SA5_fifo_full,
37526- SA5B_intr_pending,
37527- SA5_completed,
37528+ .submit_command = SA5_submit_command,
37529+ .set_intr_mask = SA5B_intr_mask,
37530+ .fifo_full = SA5_fifo_full,
37531+ .intr_pending = SA5B_intr_pending,
37532+ .command_completed = SA5_completed,
37533 };
37534
37535 static struct access_method SA5_performant_access = {
37536- SA5_submit_command,
37537- SA5_performant_intr_mask,
37538- SA5_fifo_full,
37539- SA5_performant_intr_pending,
37540- SA5_performant_completed,
37541+ .submit_command = SA5_submit_command,
37542+ .set_intr_mask = SA5_performant_intr_mask,
37543+ .fifo_full = SA5_fifo_full,
37544+ .intr_pending = SA5_performant_intr_pending,
37545+ .command_completed = SA5_performant_completed,
37546 };
37547
37548 struct board_type {
37549diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37550index 2b94403..fd6ad1f 100644
37551--- a/drivers/block/cpqarray.c
37552+++ b/drivers/block/cpqarray.c
37553@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37554 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37555 goto Enomem4;
37556 }
37557- hba[i]->access.set_intr_mask(hba[i], 0);
37558+ hba[i]->access->set_intr_mask(hba[i], 0);
37559 if (request_irq(hba[i]->intr, do_ida_intr,
37560 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37561 {
37562@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37563 add_timer(&hba[i]->timer);
37564
37565 /* Enable IRQ now that spinlock and rate limit timer are set up */
37566- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37567+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37568
37569 for(j=0; j<NWD; j++) {
37570 struct gendisk *disk = ida_gendisk[i][j];
37571@@ -694,7 +694,7 @@ DBGINFO(
37572 for(i=0; i<NR_PRODUCTS; i++) {
37573 if (board_id == products[i].board_id) {
37574 c->product_name = products[i].product_name;
37575- c->access = *(products[i].access);
37576+ c->access = products[i].access;
37577 break;
37578 }
37579 }
37580@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37581 hba[ctlr]->intr = intr;
37582 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37583 hba[ctlr]->product_name = products[j].product_name;
37584- hba[ctlr]->access = *(products[j].access);
37585+ hba[ctlr]->access = products[j].access;
37586 hba[ctlr]->ctlr = ctlr;
37587 hba[ctlr]->board_id = board_id;
37588 hba[ctlr]->pci_dev = NULL; /* not PCI */
37589@@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37590
37591 while((c = h->reqQ) != NULL) {
37592 /* Can't do anything if we're busy */
37593- if (h->access.fifo_full(h) == 0)
37594+ if (h->access->fifo_full(h) == 0)
37595 return;
37596
37597 /* Get the first entry from the request Q */
37598@@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37599 h->Qdepth--;
37600
37601 /* Tell the controller to do our bidding */
37602- h->access.submit_command(h, c);
37603+ h->access->submit_command(h, c);
37604
37605 /* Get onto the completion Q */
37606 addQ(&h->cmpQ, c);
37607@@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37608 unsigned long flags;
37609 __u32 a,a1;
37610
37611- istat = h->access.intr_pending(h);
37612+ istat = h->access->intr_pending(h);
37613 /* Is this interrupt for us? */
37614 if (istat == 0)
37615 return IRQ_NONE;
37616@@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37617 */
37618 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37619 if (istat & FIFO_NOT_EMPTY) {
37620- while((a = h->access.command_completed(h))) {
37621+ while((a = h->access->command_completed(h))) {
37622 a1 = a; a &= ~3;
37623 if ((c = h->cmpQ) == NULL)
37624 {
37625@@ -1448,11 +1448,11 @@ static int sendcmd(
37626 /*
37627 * Disable interrupt
37628 */
37629- info_p->access.set_intr_mask(info_p, 0);
37630+ info_p->access->set_intr_mask(info_p, 0);
37631 /* Make sure there is room in the command FIFO */
37632 /* Actually it should be completely empty at this time. */
37633 for (i = 200000; i > 0; i--) {
37634- temp = info_p->access.fifo_full(info_p);
37635+ temp = info_p->access->fifo_full(info_p);
37636 if (temp != 0) {
37637 break;
37638 }
37639@@ -1465,7 +1465,7 @@ DBG(
37640 /*
37641 * Send the cmd
37642 */
37643- info_p->access.submit_command(info_p, c);
37644+ info_p->access->submit_command(info_p, c);
37645 complete = pollcomplete(ctlr);
37646
37647 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37648@@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37649 * we check the new geometry. Then turn interrupts back on when
37650 * we're done.
37651 */
37652- host->access.set_intr_mask(host, 0);
37653+ host->access->set_intr_mask(host, 0);
37654 getgeometry(ctlr);
37655- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37656+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37657
37658 for(i=0; i<NWD; i++) {
37659 struct gendisk *disk = ida_gendisk[ctlr][i];
37660@@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37661 /* Wait (up to 2 seconds) for a command to complete */
37662
37663 for (i = 200000; i > 0; i--) {
37664- done = hba[ctlr]->access.command_completed(hba[ctlr]);
37665+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
37666 if (done == 0) {
37667 udelay(10); /* a short fixed delay */
37668 } else
37669diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37670index be73e9d..7fbf140 100644
37671--- a/drivers/block/cpqarray.h
37672+++ b/drivers/block/cpqarray.h
37673@@ -99,7 +99,7 @@ struct ctlr_info {
37674 drv_info_t drv[NWD];
37675 struct proc_dir_entry *proc;
37676
37677- struct access_method access;
37678+ struct access_method *access;
37679
37680 cmdlist_t *reqQ;
37681 cmdlist_t *cmpQ;
37682diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37683index 0e06f0c..c47b81d 100644
37684--- a/drivers/block/drbd/drbd_int.h
37685+++ b/drivers/block/drbd/drbd_int.h
37686@@ -582,7 +582,7 @@ struct drbd_epoch {
37687 struct drbd_tconn *tconn;
37688 struct list_head list;
37689 unsigned int barrier_nr;
37690- atomic_t epoch_size; /* increased on every request added. */
37691+ atomic_unchecked_t epoch_size; /* increased on every request added. */
37692 atomic_t active; /* increased on every req. added, and dec on every finished. */
37693 unsigned long flags;
37694 };
37695@@ -1022,7 +1022,7 @@ struct drbd_conf {
37696 unsigned int al_tr_number;
37697 int al_tr_cycle;
37698 wait_queue_head_t seq_wait;
37699- atomic_t packet_seq;
37700+ atomic_unchecked_t packet_seq;
37701 unsigned int peer_seq;
37702 spinlock_t peer_seq_lock;
37703 unsigned int minor;
37704@@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37705 char __user *uoptval;
37706 int err;
37707
37708- uoptval = (char __user __force *)optval;
37709+ uoptval = (char __force_user *)optval;
37710
37711 set_fs(KERNEL_DS);
37712 if (level == SOL_SOCKET)
37713diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37714index 89c497c..9c736ae 100644
37715--- a/drivers/block/drbd/drbd_interval.c
37716+++ b/drivers/block/drbd/drbd_interval.c
37717@@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37718 }
37719
37720 static const struct rb_augment_callbacks augment_callbacks = {
37721- augment_propagate,
37722- augment_copy,
37723- augment_rotate,
37724+ .propagate = augment_propagate,
37725+ .copy = augment_copy,
37726+ .rotate = augment_rotate,
37727 };
37728
37729 /**
37730diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37731index 9e3818b..7b64c92 100644
37732--- a/drivers/block/drbd/drbd_main.c
37733+++ b/drivers/block/drbd/drbd_main.c
37734@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37735 p->sector = sector;
37736 p->block_id = block_id;
37737 p->blksize = blksize;
37738- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37739+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37740 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37741 }
37742
37743@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37744 return -EIO;
37745 p->sector = cpu_to_be64(req->i.sector);
37746 p->block_id = (unsigned long)req;
37747- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37748+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37749 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37750 if (mdev->state.conn >= C_SYNC_SOURCE &&
37751 mdev->state.conn <= C_PAUSED_SYNC_T)
37752@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37753 {
37754 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37755
37756- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37757- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37758+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37759+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37760 kfree(tconn->current_epoch);
37761
37762 idr_destroy(&tconn->volumes);
37763diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37764index c706d50..5e1b472 100644
37765--- a/drivers/block/drbd/drbd_nl.c
37766+++ b/drivers/block/drbd/drbd_nl.c
37767@@ -3440,7 +3440,7 @@ out:
37768
37769 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37770 {
37771- static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37772+ static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37773 struct sk_buff *msg;
37774 struct drbd_genlmsghdr *d_out;
37775 unsigned seq;
37776@@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37777 return;
37778 }
37779
37780- seq = atomic_inc_return(&drbd_genl_seq);
37781+ seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37782 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37783 if (!msg)
37784 goto failed;
37785diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37786index 6fa6673..b7f97e9 100644
37787--- a/drivers/block/drbd/drbd_receiver.c
37788+++ b/drivers/block/drbd/drbd_receiver.c
37789@@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37790 {
37791 int err;
37792
37793- atomic_set(&mdev->packet_seq, 0);
37794+ atomic_set_unchecked(&mdev->packet_seq, 0);
37795 mdev->peer_seq = 0;
37796
37797 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37798@@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37799 do {
37800 next_epoch = NULL;
37801
37802- epoch_size = atomic_read(&epoch->epoch_size);
37803+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37804
37805 switch (ev & ~EV_CLEANUP) {
37806 case EV_PUT:
37807@@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37808 rv = FE_DESTROYED;
37809 } else {
37810 epoch->flags = 0;
37811- atomic_set(&epoch->epoch_size, 0);
37812+ atomic_set_unchecked(&epoch->epoch_size, 0);
37813 /* atomic_set(&epoch->active, 0); is already zero */
37814 if (rv == FE_STILL_LIVE)
37815 rv = FE_RECYCLED;
37816@@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37817 conn_wait_active_ee_empty(tconn);
37818 drbd_flush(tconn);
37819
37820- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37821+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37822 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37823 if (epoch)
37824 break;
37825@@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37826 }
37827
37828 epoch->flags = 0;
37829- atomic_set(&epoch->epoch_size, 0);
37830+ atomic_set_unchecked(&epoch->epoch_size, 0);
37831 atomic_set(&epoch->active, 0);
37832
37833 spin_lock(&tconn->epoch_lock);
37834- if (atomic_read(&tconn->current_epoch->epoch_size)) {
37835+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37836 list_add(&epoch->list, &tconn->current_epoch->list);
37837 tconn->current_epoch = epoch;
37838 tconn->epochs++;
37839@@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37840
37841 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37842 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37843- atomic_inc(&tconn->current_epoch->epoch_size);
37844+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37845 err2 = drbd_drain_block(mdev, pi->size);
37846 if (!err)
37847 err = err2;
37848@@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37849
37850 spin_lock(&tconn->epoch_lock);
37851 peer_req->epoch = tconn->current_epoch;
37852- atomic_inc(&peer_req->epoch->epoch_size);
37853+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37854 atomic_inc(&peer_req->epoch->active);
37855 spin_unlock(&tconn->epoch_lock);
37856
37857@@ -4344,7 +4344,7 @@ struct data_cmd {
37858 int expect_payload;
37859 size_t pkt_size;
37860 int (*fn)(struct drbd_tconn *, struct packet_info *);
37861-};
37862+} __do_const;
37863
37864 static struct data_cmd drbd_cmd_handler[] = {
37865 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37866@@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37867 if (!list_empty(&tconn->current_epoch->list))
37868 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37869 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37870- atomic_set(&tconn->current_epoch->epoch_size, 0);
37871+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37872 tconn->send.seen_any_write_yet = false;
37873
37874 conn_info(tconn, "Connection closed\n");
37875@@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37876 struct asender_cmd {
37877 size_t pkt_size;
37878 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37879-};
37880+} __do_const;
37881
37882 static struct asender_cmd asender_tbl[] = {
37883 [P_PING] = { 0, got_Ping },
37884diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37885index c8dac73..1800093 100644
37886--- a/drivers/block/loop.c
37887+++ b/drivers/block/loop.c
37888@@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37889
37890 file_start_write(file);
37891 set_fs(get_ds());
37892- bw = file->f_op->write(file, buf, len, &pos);
37893+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37894 set_fs(old_fs);
37895 file_end_write(file);
37896 if (likely(bw == len))
37897diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37898index 83a598e..2de5ce3 100644
37899--- a/drivers/block/null_blk.c
37900+++ b/drivers/block/null_blk.c
37901@@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37902 return 0;
37903 }
37904
37905-static struct blk_mq_ops null_mq_ops = {
37906- .queue_rq = null_queue_rq,
37907- .map_queue = blk_mq_map_queue,
37908+static struct blk_mq_ops null_mq_single_ops = {
37909+ .queue_rq = null_queue_rq,
37910+ .map_queue = blk_mq_map_queue,
37911 .init_hctx = null_init_hctx,
37912+ .alloc_hctx = blk_mq_alloc_single_hw_queue,
37913+ .free_hctx = blk_mq_free_single_hw_queue,
37914+};
37915+
37916+static struct blk_mq_ops null_mq_per_node_ops = {
37917+ .queue_rq = null_queue_rq,
37918+ .map_queue = blk_mq_map_queue,
37919+ .init_hctx = null_init_hctx,
37920+ .alloc_hctx = null_alloc_hctx,
37921+ .free_hctx = null_free_hctx,
37922 };
37923
37924 static struct blk_mq_reg null_mq_reg = {
37925- .ops = &null_mq_ops,
37926+ .ops = &null_mq_single_ops,
37927 .queue_depth = 64,
37928 .cmd_size = sizeof(struct nullb_cmd),
37929 .flags = BLK_MQ_F_SHOULD_MERGE,
37930@@ -545,13 +555,8 @@ static int null_add_dev(void)
37931 null_mq_reg.queue_depth = hw_queue_depth;
37932 null_mq_reg.nr_hw_queues = submit_queues;
37933
37934- if (use_per_node_hctx) {
37935- null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37936- null_mq_reg.ops->free_hctx = null_free_hctx;
37937- } else {
37938- null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37939- null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37940- }
37941+ if (use_per_node_hctx)
37942+ null_mq_reg.ops = &null_mq_per_node_ops;
37943
37944 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37945 } else if (queue_mode == NULL_Q_BIO) {
37946diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37947index ff8668c..f62167a 100644
37948--- a/drivers/block/pktcdvd.c
37949+++ b/drivers/block/pktcdvd.c
37950@@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37951
37952 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37953 {
37954- return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37955+ return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37956 }
37957
37958 /*
37959@@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37960 return -EROFS;
37961 }
37962 pd->settings.fp = ti.fp;
37963- pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37964+ pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37965
37966 if (ti.nwa_v) {
37967 pd->nwa = be32_to_cpu(ti.next_writable);
37968diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37969index e5565fb..71be10b4 100644
37970--- a/drivers/block/smart1,2.h
37971+++ b/drivers/block/smart1,2.h
37972@@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37973 }
37974
37975 static struct access_method smart4_access = {
37976- smart4_submit_command,
37977- smart4_intr_mask,
37978- smart4_fifo_full,
37979- smart4_intr_pending,
37980- smart4_completed,
37981+ .submit_command = smart4_submit_command,
37982+ .set_intr_mask = smart4_intr_mask,
37983+ .fifo_full = smart4_fifo_full,
37984+ .intr_pending = smart4_intr_pending,
37985+ .command_completed = smart4_completed,
37986 };
37987
37988 /*
37989@@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37990 }
37991
37992 static struct access_method smart2_access = {
37993- smart2_submit_command,
37994- smart2_intr_mask,
37995- smart2_fifo_full,
37996- smart2_intr_pending,
37997- smart2_completed,
37998+ .submit_command = smart2_submit_command,
37999+ .set_intr_mask = smart2_intr_mask,
38000+ .fifo_full = smart2_fifo_full,
38001+ .intr_pending = smart2_intr_pending,
38002+ .command_completed = smart2_completed,
38003 };
38004
38005 /*
38006@@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38007 }
38008
38009 static struct access_method smart2e_access = {
38010- smart2e_submit_command,
38011- smart2e_intr_mask,
38012- smart2e_fifo_full,
38013- smart2e_intr_pending,
38014- smart2e_completed,
38015+ .submit_command = smart2e_submit_command,
38016+ .set_intr_mask = smart2e_intr_mask,
38017+ .fifo_full = smart2e_fifo_full,
38018+ .intr_pending = smart2e_intr_pending,
38019+ .command_completed = smart2e_completed,
38020 };
38021
38022 /*
38023@@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38024 }
38025
38026 static struct access_method smart1_access = {
38027- smart1_submit_command,
38028- smart1_intr_mask,
38029- smart1_fifo_full,
38030- smart1_intr_pending,
38031- smart1_completed,
38032+ .submit_command = smart1_submit_command,
38033+ .set_intr_mask = smart1_intr_mask,
38034+ .fifo_full = smart1_fifo_full,
38035+ .intr_pending = smart1_intr_pending,
38036+ .command_completed = smart1_completed,
38037 };
38038diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38039index f038dba..bb74c08 100644
38040--- a/drivers/bluetooth/btwilink.c
38041+++ b/drivers/bluetooth/btwilink.c
38042@@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38043
38044 static int bt_ti_probe(struct platform_device *pdev)
38045 {
38046- static struct ti_st *hst;
38047+ struct ti_st *hst;
38048 struct hci_dev *hdev;
38049 int err;
38050
38051diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
38052index b6739cb..962fd35 100644
38053--- a/drivers/bus/arm-cci.c
38054+++ b/drivers/bus/arm-cci.c
38055@@ -979,7 +979,7 @@ static int cci_probe(void)
38056
38057 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
38058
38059- ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
38060+ ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
38061 if (!ports)
38062 return -ENOMEM;
38063
38064diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38065index 8a3aff7..d7538c2 100644
38066--- a/drivers/cdrom/cdrom.c
38067+++ b/drivers/cdrom/cdrom.c
38068@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38069 ENSURE(reset, CDC_RESET);
38070 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38071 cdi->mc_flags = 0;
38072- cdo->n_minors = 0;
38073 cdi->options = CDO_USE_FFLAGS;
38074
38075 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38076@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38077 else
38078 cdi->cdda_method = CDDA_OLD;
38079
38080- if (!cdo->generic_packet)
38081- cdo->generic_packet = cdrom_dummy_generic_packet;
38082+ if (!cdo->generic_packet) {
38083+ pax_open_kernel();
38084+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38085+ pax_close_kernel();
38086+ }
38087
38088 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38089 mutex_lock(&cdrom_mutex);
38090@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38091 if (cdi->exit)
38092 cdi->exit(cdi);
38093
38094- cdi->ops->n_minors--;
38095 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38096 }
38097
38098@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38099 */
38100 nr = nframes;
38101 do {
38102- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38103+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38104 if (cgc.buffer)
38105 break;
38106
38107@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38108 struct cdrom_device_info *cdi;
38109 int ret;
38110
38111- ret = scnprintf(info + *pos, max_size - *pos, header);
38112+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38113 if (!ret)
38114 return 1;
38115
38116diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38117index 5980cb9..6d7bd7e 100644
38118--- a/drivers/cdrom/gdrom.c
38119+++ b/drivers/cdrom/gdrom.c
38120@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38121 .audio_ioctl = gdrom_audio_ioctl,
38122 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38123 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38124- .n_minors = 1,
38125 };
38126
38127 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38128diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38129index fa3243d..8c98297 100644
38130--- a/drivers/char/Kconfig
38131+++ b/drivers/char/Kconfig
38132@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38133
38134 config DEVKMEM
38135 bool "/dev/kmem virtual device support"
38136- default y
38137+ default n
38138+ depends on !GRKERNSEC_KMEM
38139 help
38140 Say Y here if you want to support the /dev/kmem device. The
38141 /dev/kmem device is rarely used, but can be used for certain
38142@@ -576,6 +577,7 @@ config DEVPORT
38143 bool
38144 depends on !M68K
38145 depends on ISA || PCI
38146+ depends on !GRKERNSEC_KMEM
38147 default y
38148
38149 source "drivers/s390/char/Kconfig"
38150diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38151index a48e05b..6bac831 100644
38152--- a/drivers/char/agp/compat_ioctl.c
38153+++ b/drivers/char/agp/compat_ioctl.c
38154@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38155 return -ENOMEM;
38156 }
38157
38158- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38159+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38160 sizeof(*usegment) * ureserve.seg_count)) {
38161 kfree(usegment);
38162 kfree(ksegment);
38163diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38164index 1b19239..b87b143 100644
38165--- a/drivers/char/agp/frontend.c
38166+++ b/drivers/char/agp/frontend.c
38167@@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38168 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38169 return -EFAULT;
38170
38171- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38172+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38173 return -EFAULT;
38174
38175 client = agp_find_client_by_pid(reserve.pid);
38176@@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38177 if (segment == NULL)
38178 return -ENOMEM;
38179
38180- if (copy_from_user(segment, (void __user *) reserve.seg_list,
38181+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38182 sizeof(struct agp_segment) * reserve.seg_count)) {
38183 kfree(segment);
38184 return -EFAULT;
38185diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38186index 4f94375..413694e 100644
38187--- a/drivers/char/genrtc.c
38188+++ b/drivers/char/genrtc.c
38189@@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38190 switch (cmd) {
38191
38192 case RTC_PLL_GET:
38193+ memset(&pll, 0, sizeof(pll));
38194 if (get_rtc_pll(&pll))
38195 return -EINVAL;
38196 else
38197diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38198index 5d9c31d..c94ccb5 100644
38199--- a/drivers/char/hpet.c
38200+++ b/drivers/char/hpet.c
38201@@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38202 }
38203
38204 static int
38205-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38206+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38207 struct hpet_info *info)
38208 {
38209 struct hpet_timer __iomem *timer;
38210diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38211index 86fe45c..c0ea948 100644
38212--- a/drivers/char/hw_random/intel-rng.c
38213+++ b/drivers/char/hw_random/intel-rng.c
38214@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38215
38216 if (no_fwh_detect)
38217 return -ENODEV;
38218- printk(warning);
38219+ printk("%s", warning);
38220 return -EBUSY;
38221 }
38222
38223diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38224index ec4e10f..f2a763b 100644
38225--- a/drivers/char/ipmi/ipmi_msghandler.c
38226+++ b/drivers/char/ipmi/ipmi_msghandler.c
38227@@ -420,7 +420,7 @@ struct ipmi_smi {
38228 struct proc_dir_entry *proc_dir;
38229 char proc_dir_name[10];
38230
38231- atomic_t stats[IPMI_NUM_STATS];
38232+ atomic_unchecked_t stats[IPMI_NUM_STATS];
38233
38234 /*
38235 * run_to_completion duplicate of smb_info, smi_info
38236@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
38237
38238
38239 #define ipmi_inc_stat(intf, stat) \
38240- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38241+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38242 #define ipmi_get_stat(intf, stat) \
38243- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38244+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38245
38246 static int is_lan_addr(struct ipmi_addr *addr)
38247 {
38248@@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38249 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38250 init_waitqueue_head(&intf->waitq);
38251 for (i = 0; i < IPMI_NUM_STATS; i++)
38252- atomic_set(&intf->stats[i], 0);
38253+ atomic_set_unchecked(&intf->stats[i], 0);
38254
38255 intf->proc_dir = NULL;
38256
38257diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38258index 15e4a60..b046093 100644
38259--- a/drivers/char/ipmi/ipmi_si_intf.c
38260+++ b/drivers/char/ipmi/ipmi_si_intf.c
38261@@ -280,7 +280,7 @@ struct smi_info {
38262 unsigned char slave_addr;
38263
38264 /* Counters and things for the proc filesystem. */
38265- atomic_t stats[SI_NUM_STATS];
38266+ atomic_unchecked_t stats[SI_NUM_STATS];
38267
38268 struct task_struct *thread;
38269
38270@@ -289,9 +289,9 @@ struct smi_info {
38271 };
38272
38273 #define smi_inc_stat(smi, stat) \
38274- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38275+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38276 #define smi_get_stat(smi, stat) \
38277- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38278+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38279
38280 #define SI_MAX_PARMS 4
38281
38282@@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
38283 atomic_set(&new_smi->req_events, 0);
38284 new_smi->run_to_completion = 0;
38285 for (i = 0; i < SI_NUM_STATS; i++)
38286- atomic_set(&new_smi->stats[i], 0);
38287+ atomic_set_unchecked(&new_smi->stats[i], 0);
38288
38289 new_smi->interrupt_disabled = 1;
38290 atomic_set(&new_smi->stop_operation, 0);
38291diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38292index f895a8c..2bc9147 100644
38293--- a/drivers/char/mem.c
38294+++ b/drivers/char/mem.c
38295@@ -18,6 +18,7 @@
38296 #include <linux/raw.h>
38297 #include <linux/tty.h>
38298 #include <linux/capability.h>
38299+#include <linux/security.h>
38300 #include <linux/ptrace.h>
38301 #include <linux/device.h>
38302 #include <linux/highmem.h>
38303@@ -37,6 +38,10 @@
38304
38305 #define DEVPORT_MINOR 4
38306
38307+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38308+extern const struct file_operations grsec_fops;
38309+#endif
38310+
38311 static inline unsigned long size_inside_page(unsigned long start,
38312 unsigned long size)
38313 {
38314@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38315
38316 while (cursor < to) {
38317 if (!devmem_is_allowed(pfn)) {
38318+#ifdef CONFIG_GRKERNSEC_KMEM
38319+ gr_handle_mem_readwrite(from, to);
38320+#else
38321 printk(KERN_INFO
38322 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38323 current->comm, from, to);
38324+#endif
38325 return 0;
38326 }
38327 cursor += PAGE_SIZE;
38328@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38329 }
38330 return 1;
38331 }
38332+#elif defined(CONFIG_GRKERNSEC_KMEM)
38333+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38334+{
38335+ return 0;
38336+}
38337 #else
38338 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38339 {
38340@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38341
38342 while (count > 0) {
38343 unsigned long remaining;
38344+ char *temp;
38345
38346 sz = size_inside_page(p, count);
38347
38348@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38349 if (!ptr)
38350 return -EFAULT;
38351
38352- remaining = copy_to_user(buf, ptr, sz);
38353+#ifdef CONFIG_PAX_USERCOPY
38354+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38355+ if (!temp) {
38356+ unxlate_dev_mem_ptr(p, ptr);
38357+ return -ENOMEM;
38358+ }
38359+ memcpy(temp, ptr, sz);
38360+#else
38361+ temp = ptr;
38362+#endif
38363+
38364+ remaining = copy_to_user(buf, temp, sz);
38365+
38366+#ifdef CONFIG_PAX_USERCOPY
38367+ kfree(temp);
38368+#endif
38369+
38370 unxlate_dev_mem_ptr(p, ptr);
38371 if (remaining)
38372 return -EFAULT;
38373@@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38374 size_t count, loff_t *ppos)
38375 {
38376 unsigned long p = *ppos;
38377- ssize_t low_count, read, sz;
38378+ ssize_t low_count, read, sz, err = 0;
38379 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38380- int err = 0;
38381
38382 read = 0;
38383 if (p < (unsigned long) high_memory) {
38384@@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38385 }
38386 #endif
38387 while (low_count > 0) {
38388+ char *temp;
38389+
38390 sz = size_inside_page(p, low_count);
38391
38392 /*
38393@@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38394 */
38395 kbuf = xlate_dev_kmem_ptr((char *)p);
38396
38397- if (copy_to_user(buf, kbuf, sz))
38398+#ifdef CONFIG_PAX_USERCOPY
38399+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38400+ if (!temp)
38401+ return -ENOMEM;
38402+ memcpy(temp, kbuf, sz);
38403+#else
38404+ temp = kbuf;
38405+#endif
38406+
38407+ err = copy_to_user(buf, temp, sz);
38408+
38409+#ifdef CONFIG_PAX_USERCOPY
38410+ kfree(temp);
38411+#endif
38412+
38413+ if (err)
38414 return -EFAULT;
38415 buf += sz;
38416 p += sz;
38417@@ -822,6 +869,9 @@ static const struct memdev {
38418 #ifdef CONFIG_PRINTK
38419 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38420 #endif
38421+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38422+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38423+#endif
38424 };
38425
38426 static int memory_open(struct inode *inode, struct file *filp)
38427@@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
38428 continue;
38429
38430 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38431- NULL, devlist[minor].name);
38432+ NULL, "%s", devlist[minor].name);
38433 }
38434
38435 return tty_init();
38436diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38437index 9df78e2..01ba9ae 100644
38438--- a/drivers/char/nvram.c
38439+++ b/drivers/char/nvram.c
38440@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38441
38442 spin_unlock_irq(&rtc_lock);
38443
38444- if (copy_to_user(buf, contents, tmp - contents))
38445+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38446 return -EFAULT;
38447
38448 *ppos = i;
38449diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38450index d39cca6..8c1e269 100644
38451--- a/drivers/char/pcmcia/synclink_cs.c
38452+++ b/drivers/char/pcmcia/synclink_cs.c
38453@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38454
38455 if (debug_level >= DEBUG_LEVEL_INFO)
38456 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38457- __FILE__, __LINE__, info->device_name, port->count);
38458+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38459
38460- WARN_ON(!port->count);
38461+ WARN_ON(!atomic_read(&port->count));
38462
38463 if (tty_port_close_start(port, tty, filp) == 0)
38464 goto cleanup;
38465@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38466 cleanup:
38467 if (debug_level >= DEBUG_LEVEL_INFO)
38468 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38469- tty->driver->name, port->count);
38470+ tty->driver->name, atomic_read(&port->count));
38471 }
38472
38473 /* Wait until the transmitter is empty.
38474@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38475
38476 if (debug_level >= DEBUG_LEVEL_INFO)
38477 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38478- __FILE__, __LINE__, tty->driver->name, port->count);
38479+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38480
38481 /* If port is closing, signal caller to try again */
38482 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38483@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38484 goto cleanup;
38485 }
38486 spin_lock(&port->lock);
38487- port->count++;
38488+ atomic_inc(&port->count);
38489 spin_unlock(&port->lock);
38490 spin_unlock_irqrestore(&info->netlock, flags);
38491
38492- if (port->count == 1) {
38493+ if (atomic_read(&port->count) == 1) {
38494 /* 1st open on this device, init hardware */
38495 retval = startup(info, tty);
38496 if (retval < 0)
38497@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38498 unsigned short new_crctype;
38499
38500 /* return error if TTY interface open */
38501- if (info->port.count)
38502+ if (atomic_read(&info->port.count))
38503 return -EBUSY;
38504
38505 switch (encoding)
38506@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38507
38508 /* arbitrate between network and tty opens */
38509 spin_lock_irqsave(&info->netlock, flags);
38510- if (info->port.count != 0 || info->netcount != 0) {
38511+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38512 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38513 spin_unlock_irqrestore(&info->netlock, flags);
38514 return -EBUSY;
38515@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38516 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38517
38518 /* return error if TTY interface open */
38519- if (info->port.count)
38520+ if (atomic_read(&info->port.count))
38521 return -EBUSY;
38522
38523 if (cmd != SIOCWANDEV)
38524diff --git a/drivers/char/random.c b/drivers/char/random.c
38525index 429b75b..a7f4145 100644
38526--- a/drivers/char/random.c
38527+++ b/drivers/char/random.c
38528@@ -270,10 +270,17 @@
38529 /*
38530 * Configuration information
38531 */
38532+#ifdef CONFIG_GRKERNSEC_RANDNET
38533+#define INPUT_POOL_SHIFT 14
38534+#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38535+#define OUTPUT_POOL_SHIFT 12
38536+#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38537+#else
38538 #define INPUT_POOL_SHIFT 12
38539 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38540 #define OUTPUT_POOL_SHIFT 10
38541 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38542+#endif
38543 #define SEC_XFER_SIZE 512
38544 #define EXTRACT_SIZE 10
38545
38546@@ -284,9 +291,6 @@
38547 /*
38548 * To allow fractional bits to be tracked, the entropy_count field is
38549 * denominated in units of 1/8th bits.
38550- *
38551- * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38552- * credit_entropy_bits() needs to be 64 bits wide.
38553 */
38554 #define ENTROPY_SHIFT 3
38555 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38556@@ -361,12 +365,19 @@ static struct poolinfo {
38557 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38558 int tap1, tap2, tap3, tap4, tap5;
38559 } poolinfo_table[] = {
38560+#ifdef CONFIG_GRKERNSEC_RANDNET
38561+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38562+ { S(512), 411, 308, 208, 104, 1 },
38563+ /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38564+ { S(128), 104, 76, 51, 25, 1 },
38565+#else
38566 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38567 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38568 { S(128), 104, 76, 51, 25, 1 },
38569 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38570 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38571 { S(32), 26, 19, 14, 7, 1 },
38572+#endif
38573 #if 0
38574 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38575 { S(2048), 1638, 1231, 819, 411, 1 },
38576@@ -433,9 +444,9 @@ struct entropy_store {
38577 };
38578
38579 static void push_to_pool(struct work_struct *work);
38580-static __u32 input_pool_data[INPUT_POOL_WORDS];
38581-static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38582-static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38583+static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38584+static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38585+static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38586
38587 static struct entropy_store input_pool = {
38588 .poolinfo = &poolinfo_table[0],
38589@@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38590 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38591 }
38592
38593- ACCESS_ONCE(r->input_rotate) = input_rotate;
38594- ACCESS_ONCE(r->add_ptr) = i;
38595+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38596+ ACCESS_ONCE_RW(r->add_ptr) = i;
38597 smp_wmb();
38598
38599 if (out)
38600@@ -632,7 +643,7 @@ retry:
38601 /* The +2 corresponds to the /4 in the denominator */
38602
38603 do {
38604- unsigned int anfrac = min(pnfrac, pool_size/2);
38605+ u64 anfrac = min(pnfrac, pool_size/2);
38606 unsigned int add =
38607 ((pool_size - entropy_count)*anfrac*3) >> s;
38608
38609@@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38610
38611 extract_buf(r, tmp);
38612 i = min_t(int, nbytes, EXTRACT_SIZE);
38613- if (copy_to_user(buf, tmp, i)) {
38614+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38615 ret = -EFAULT;
38616 break;
38617 }
38618@@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38619 #include <linux/sysctl.h>
38620
38621 static int min_read_thresh = 8, min_write_thresh;
38622-static int max_read_thresh = INPUT_POOL_WORDS * 32;
38623+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38624 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38625 static char sysctl_bootid[16];
38626
38627@@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38628 static int proc_do_uuid(struct ctl_table *table, int write,
38629 void __user *buffer, size_t *lenp, loff_t *ppos)
38630 {
38631- struct ctl_table fake_table;
38632+ ctl_table_no_const fake_table;
38633 unsigned char buf[64], tmp_uuid[16], *uuid;
38634
38635 uuid = table->data;
38636@@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38637 static int proc_do_entropy(ctl_table *table, int write,
38638 void __user *buffer, size_t *lenp, loff_t *ppos)
38639 {
38640- ctl_table fake_table;
38641+ ctl_table_no_const fake_table;
38642 int entropy_count;
38643
38644 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38645diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38646index 7cc1fe22..b602d6b 100644
38647--- a/drivers/char/sonypi.c
38648+++ b/drivers/char/sonypi.c
38649@@ -54,6 +54,7 @@
38650
38651 #include <asm/uaccess.h>
38652 #include <asm/io.h>
38653+#include <asm/local.h>
38654
38655 #include <linux/sonypi.h>
38656
38657@@ -490,7 +491,7 @@ static struct sonypi_device {
38658 spinlock_t fifo_lock;
38659 wait_queue_head_t fifo_proc_list;
38660 struct fasync_struct *fifo_async;
38661- int open_count;
38662+ local_t open_count;
38663 int model;
38664 struct input_dev *input_jog_dev;
38665 struct input_dev *input_key_dev;
38666@@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38667 static int sonypi_misc_release(struct inode *inode, struct file *file)
38668 {
38669 mutex_lock(&sonypi_device.lock);
38670- sonypi_device.open_count--;
38671+ local_dec(&sonypi_device.open_count);
38672 mutex_unlock(&sonypi_device.lock);
38673 return 0;
38674 }
38675@@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38676 {
38677 mutex_lock(&sonypi_device.lock);
38678 /* Flush input queue on first open */
38679- if (!sonypi_device.open_count)
38680+ if (!local_read(&sonypi_device.open_count))
38681 kfifo_reset(&sonypi_device.fifo);
38682- sonypi_device.open_count++;
38683+ local_inc(&sonypi_device.open_count);
38684 mutex_unlock(&sonypi_device.lock);
38685
38686 return 0;
38687diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38688index 64420b3..5c40b56 100644
38689--- a/drivers/char/tpm/tpm_acpi.c
38690+++ b/drivers/char/tpm/tpm_acpi.c
38691@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38692 virt = acpi_os_map_memory(start, len);
38693 if (!virt) {
38694 kfree(log->bios_event_log);
38695+ log->bios_event_log = NULL;
38696 printk("%s: ERROR - Unable to map memory\n", __func__);
38697 return -EIO;
38698 }
38699
38700- memcpy_fromio(log->bios_event_log, virt, len);
38701+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38702
38703 acpi_os_unmap_memory(virt, len);
38704 return 0;
38705diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38706index 59f7cb2..bac8b6d 100644
38707--- a/drivers/char/tpm/tpm_eventlog.c
38708+++ b/drivers/char/tpm/tpm_eventlog.c
38709@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38710 event = addr;
38711
38712 if ((event->event_type == 0 && event->event_size == 0) ||
38713- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38714+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38715 return NULL;
38716
38717 return addr;
38718@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38719 return NULL;
38720
38721 if ((event->event_type == 0 && event->event_size == 0) ||
38722- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38723+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38724 return NULL;
38725
38726 (*pos)++;
38727@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38728 int i;
38729
38730 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38731- seq_putc(m, data[i]);
38732+ if (!seq_putc(m, data[i]))
38733+ return -EFAULT;
38734
38735 return 0;
38736 }
38737diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38738index feea87c..18aefff 100644
38739--- a/drivers/char/virtio_console.c
38740+++ b/drivers/char/virtio_console.c
38741@@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38742 if (to_user) {
38743 ssize_t ret;
38744
38745- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38746+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38747 if (ret)
38748 return -EFAULT;
38749 } else {
38750@@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38751 if (!port_has_data(port) && !port->host_connected)
38752 return 0;
38753
38754- return fill_readbuf(port, ubuf, count, true);
38755+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38756 }
38757
38758 static int wait_port_writable(struct port *port, bool nonblock)
38759diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38760index a33f46f..a720eed 100644
38761--- a/drivers/clk/clk-composite.c
38762+++ b/drivers/clk/clk-composite.c
38763@@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38764 struct clk *clk;
38765 struct clk_init_data init;
38766 struct clk_composite *composite;
38767- struct clk_ops *clk_composite_ops;
38768+ clk_ops_no_const *clk_composite_ops;
38769
38770 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38771 if (!composite) {
38772diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38773index 81dd31a..ef5c542 100644
38774--- a/drivers/clk/socfpga/clk.c
38775+++ b/drivers/clk/socfpga/clk.c
38776@@ -22,6 +22,7 @@
38777 #include <linux/clk-provider.h>
38778 #include <linux/io.h>
38779 #include <linux/of.h>
38780+#include <asm/pgtable.h>
38781
38782 /* Clock Manager offsets */
38783 #define CLKMGR_CTRL 0x0
38784@@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38785 streq(clk_name, "periph_pll") ||
38786 streq(clk_name, "sdram_pll")) {
38787 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38788- clk_pll_ops.enable = clk_gate_ops.enable;
38789- clk_pll_ops.disable = clk_gate_ops.disable;
38790+ pax_open_kernel();
38791+ *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38792+ *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38793+ pax_close_kernel();
38794 }
38795
38796 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38797@@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38798 return parent_rate / div;
38799 }
38800
38801-static struct clk_ops gateclk_ops = {
38802+static clk_ops_no_const gateclk_ops __read_only = {
38803 .recalc_rate = socfpga_clk_recalc_rate,
38804 .get_parent = socfpga_clk_get_parent,
38805 .set_parent = socfpga_clk_set_parent,
38806diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38807index caf41eb..223d27a 100644
38808--- a/drivers/cpufreq/acpi-cpufreq.c
38809+++ b/drivers/cpufreq/acpi-cpufreq.c
38810@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38811 return sprintf(buf, "%u\n", boost_enabled);
38812 }
38813
38814-static struct global_attr global_boost = __ATTR(boost, 0644,
38815+static global_attr_no_const global_boost = __ATTR(boost, 0644,
38816 show_global_boost,
38817 store_global_boost);
38818
38819@@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38820 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38821 per_cpu(acfreq_data, cpu) = data;
38822
38823- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38824- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38825+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38826+ pax_open_kernel();
38827+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38828+ pax_close_kernel();
38829+ }
38830
38831 result = acpi_processor_register_performance(data->acpi_data, cpu);
38832 if (result)
38833@@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38834 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38835 break;
38836 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38837- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38838+ pax_open_kernel();
38839+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38840+ pax_close_kernel();
38841 break;
38842 default:
38843 break;
38844diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38845index 99a443e..8cb6f02 100644
38846--- a/drivers/cpufreq/cpufreq.c
38847+++ b/drivers/cpufreq/cpufreq.c
38848@@ -1878,7 +1878,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38849 #endif
38850
38851 mutex_lock(&cpufreq_governor_mutex);
38852- list_del(&governor->governor_list);
38853+ pax_list_del(&governor->governor_list);
38854 mutex_unlock(&cpufreq_governor_mutex);
38855 return;
38856 }
38857@@ -2108,7 +2108,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38858 return NOTIFY_OK;
38859 }
38860
38861-static struct notifier_block __refdata cpufreq_cpu_notifier = {
38862+static struct notifier_block cpufreq_cpu_notifier = {
38863 .notifier_call = cpufreq_cpu_callback,
38864 };
38865
38866@@ -2141,8 +2141,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38867
38868 pr_debug("trying to register driver %s\n", driver_data->name);
38869
38870- if (driver_data->setpolicy)
38871- driver_data->flags |= CPUFREQ_CONST_LOOPS;
38872+ if (driver_data->setpolicy) {
38873+ pax_open_kernel();
38874+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38875+ pax_close_kernel();
38876+ }
38877
38878 write_lock_irqsave(&cpufreq_driver_lock, flags);
38879 if (cpufreq_driver) {
38880diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38881index e6be635..f8a90dc 100644
38882--- a/drivers/cpufreq/cpufreq_governor.c
38883+++ b/drivers/cpufreq/cpufreq_governor.c
38884@@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38885 struct dbs_data *dbs_data;
38886 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38887 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38888- struct od_ops *od_ops = NULL;
38889+ const struct od_ops *od_ops = NULL;
38890 struct od_dbs_tuners *od_tuners = NULL;
38891 struct cs_dbs_tuners *cs_tuners = NULL;
38892 struct cpu_dbs_common_info *cpu_cdbs;
38893@@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38894
38895 if ((cdata->governor == GOV_CONSERVATIVE) &&
38896 (!policy->governor->initialized)) {
38897- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38898+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38899
38900 cpufreq_register_notifier(cs_ops->notifier_block,
38901 CPUFREQ_TRANSITION_NOTIFIER);
38902@@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38903
38904 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38905 (policy->governor->initialized == 1)) {
38906- struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38907+ const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38908
38909 cpufreq_unregister_notifier(cs_ops->notifier_block,
38910 CPUFREQ_TRANSITION_NOTIFIER);
38911diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38912index b5f2b86..daa801b 100644
38913--- a/drivers/cpufreq/cpufreq_governor.h
38914+++ b/drivers/cpufreq/cpufreq_governor.h
38915@@ -205,7 +205,7 @@ struct common_dbs_data {
38916 void (*exit)(struct dbs_data *dbs_data);
38917
38918 /* Governor specific ops, see below */
38919- void *gov_ops;
38920+ const void *gov_ops;
38921 };
38922
38923 /* Governor Per policy data */
38924@@ -225,7 +225,7 @@ struct od_ops {
38925 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38926 unsigned int freq_next, unsigned int relation);
38927 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38928-};
38929+} __no_const;
38930
38931 struct cs_ops {
38932 struct notifier_block *notifier_block;
38933diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38934index 18d4091..434be15 100644
38935--- a/drivers/cpufreq/cpufreq_ondemand.c
38936+++ b/drivers/cpufreq/cpufreq_ondemand.c
38937@@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38938
38939 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38940
38941-static struct od_ops od_ops = {
38942+static struct od_ops od_ops __read_only = {
38943 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38944 .powersave_bias_target = generic_powersave_bias_target,
38945 .freq_increase = dbs_freq_increase,
38946@@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38947 (struct cpufreq_policy *, unsigned int, unsigned int),
38948 unsigned int powersave_bias)
38949 {
38950- od_ops.powersave_bias_target = f;
38951+ pax_open_kernel();
38952+ *(void **)&od_ops.powersave_bias_target = f;
38953+ pax_close_kernel();
38954 od_set_powersave_bias(powersave_bias);
38955 }
38956 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38957
38958 void od_unregister_powersave_bias_handler(void)
38959 {
38960- od_ops.powersave_bias_target = generic_powersave_bias_target;
38961+ pax_open_kernel();
38962+ *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38963+ pax_close_kernel();
38964 od_set_powersave_bias(0);
38965 }
38966 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38967diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38968index 4cf0d28..5830372 100644
38969--- a/drivers/cpufreq/cpufreq_stats.c
38970+++ b/drivers/cpufreq/cpufreq_stats.c
38971@@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38972 }
38973
38974 /* priority=1 so this will get called before cpufreq_remove_dev */
38975-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38976+static struct notifier_block cpufreq_stat_cpu_notifier = {
38977 .notifier_call = cpufreq_stat_cpu_callback,
38978 .priority = 1,
38979 };
38980diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38981index b687df8..ae733fc 100644
38982--- a/drivers/cpufreq/intel_pstate.c
38983+++ b/drivers/cpufreq/intel_pstate.c
38984@@ -123,10 +123,10 @@ struct pstate_funcs {
38985 struct cpu_defaults {
38986 struct pstate_adjust_policy pid_policy;
38987 struct pstate_funcs funcs;
38988-};
38989+} __do_const;
38990
38991 static struct pstate_adjust_policy pid_params;
38992-static struct pstate_funcs pstate_funcs;
38993+static struct pstate_funcs *pstate_funcs;
38994
38995 struct perf_limits {
38996 int no_turbo;
38997@@ -517,7 +517,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38998
38999 cpu->pstate.current_pstate = pstate;
39000
39001- pstate_funcs.set(cpu, pstate);
39002+ pstate_funcs->set(cpu, pstate);
39003 }
39004
39005 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39006@@ -539,12 +539,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39007 {
39008 sprintf(cpu->name, "Intel 2nd generation core");
39009
39010- cpu->pstate.min_pstate = pstate_funcs.get_min();
39011- cpu->pstate.max_pstate = pstate_funcs.get_max();
39012- cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39013+ cpu->pstate.min_pstate = pstate_funcs->get_min();
39014+ cpu->pstate.max_pstate = pstate_funcs->get_max();
39015+ cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39016
39017- if (pstate_funcs.get_vid)
39018- pstate_funcs.get_vid(cpu);
39019+ if (pstate_funcs->get_vid)
39020+ pstate_funcs->get_vid(cpu);
39021
39022 /*
39023 * goto max pstate so we don't slow up boot if we are built-in if we are
39024@@ -808,9 +808,9 @@ static int intel_pstate_msrs_not_valid(void)
39025 rdmsrl(MSR_IA32_APERF, aperf);
39026 rdmsrl(MSR_IA32_MPERF, mperf);
39027
39028- if (!pstate_funcs.get_max() ||
39029- !pstate_funcs.get_min() ||
39030- !pstate_funcs.get_turbo())
39031+ if (!pstate_funcs->get_max() ||
39032+ !pstate_funcs->get_min() ||
39033+ !pstate_funcs->get_turbo())
39034 return -ENODEV;
39035
39036 rdmsrl(MSR_IA32_APERF, tmp);
39037@@ -824,7 +824,7 @@ static int intel_pstate_msrs_not_valid(void)
39038 return 0;
39039 }
39040
39041-static void copy_pid_params(struct pstate_adjust_policy *policy)
39042+static void copy_pid_params(const struct pstate_adjust_policy *policy)
39043 {
39044 pid_params.sample_rate_ms = policy->sample_rate_ms;
39045 pid_params.p_gain_pct = policy->p_gain_pct;
39046@@ -836,11 +836,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39047
39048 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39049 {
39050- pstate_funcs.get_max = funcs->get_max;
39051- pstate_funcs.get_min = funcs->get_min;
39052- pstate_funcs.get_turbo = funcs->get_turbo;
39053- pstate_funcs.set = funcs->set;
39054- pstate_funcs.get_vid = funcs->get_vid;
39055+ pstate_funcs = funcs;
39056 }
39057
39058 #if IS_ENABLED(CONFIG_ACPI)
39059diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39060index 3d1cba9..0ab21d2 100644
39061--- a/drivers/cpufreq/p4-clockmod.c
39062+++ b/drivers/cpufreq/p4-clockmod.c
39063@@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39064 case 0x0F: /* Core Duo */
39065 case 0x16: /* Celeron Core */
39066 case 0x1C: /* Atom */
39067- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39068+ pax_open_kernel();
39069+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39070+ pax_close_kernel();
39071 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39072 case 0x0D: /* Pentium M (Dothan) */
39073- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39074+ pax_open_kernel();
39075+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39076+ pax_close_kernel();
39077 /* fall through */
39078 case 0x09: /* Pentium M (Banias) */
39079 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39080@@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39081
39082 /* on P-4s, the TSC runs with constant frequency independent whether
39083 * throttling is active or not. */
39084- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39085+ pax_open_kernel();
39086+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39087+ pax_close_kernel();
39088
39089 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39090 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39091diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39092index 724ffbd..ad83692 100644
39093--- a/drivers/cpufreq/sparc-us3-cpufreq.c
39094+++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39095@@ -18,14 +18,12 @@
39096 #include <asm/head.h>
39097 #include <asm/timer.h>
39098
39099-static struct cpufreq_driver *cpufreq_us3_driver;
39100-
39101 struct us3_freq_percpu_info {
39102 struct cpufreq_frequency_table table[4];
39103 };
39104
39105 /* Indexed by cpu number. */
39106-static struct us3_freq_percpu_info *us3_freq_table;
39107+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39108
39109 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39110 * in the Safari config register.
39111@@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39112
39113 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39114 {
39115- if (cpufreq_us3_driver) {
39116- cpufreq_frequency_table_put_attr(policy->cpu);
39117- us3_freq_target(policy, 0);
39118- }
39119+ cpufreq_frequency_table_put_attr(policy->cpu);
39120+ us3_freq_target(policy, 0);
39121
39122 return 0;
39123 }
39124
39125+static int __init us3_freq_init(void);
39126+static void __exit us3_freq_exit(void);
39127+
39128+static struct cpufreq_driver cpufreq_us3_driver = {
39129+ .init = us3_freq_cpu_init,
39130+ .verify = cpufreq_generic_frequency_table_verify,
39131+ .target_index = us3_freq_target,
39132+ .get = us3_freq_get,
39133+ .exit = us3_freq_cpu_exit,
39134+ .owner = THIS_MODULE,
39135+ .name = "UltraSPARC-III",
39136+
39137+};
39138+
39139 static int __init us3_freq_init(void)
39140 {
39141 unsigned long manuf, impl, ver;
39142@@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
39143 (impl == CHEETAH_IMPL ||
39144 impl == CHEETAH_PLUS_IMPL ||
39145 impl == JAGUAR_IMPL ||
39146- impl == PANTHER_IMPL)) {
39147- struct cpufreq_driver *driver;
39148-
39149- ret = -ENOMEM;
39150- driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39151- if (!driver)
39152- goto err_out;
39153-
39154- us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39155- GFP_KERNEL);
39156- if (!us3_freq_table)
39157- goto err_out;
39158-
39159- driver->init = us3_freq_cpu_init;
39160- driver->verify = cpufreq_generic_frequency_table_verify;
39161- driver->target_index = us3_freq_target;
39162- driver->get = us3_freq_get;
39163- driver->exit = us3_freq_cpu_exit;
39164- strcpy(driver->name, "UltraSPARC-III");
39165-
39166- cpufreq_us3_driver = driver;
39167- ret = cpufreq_register_driver(driver);
39168- if (ret)
39169- goto err_out;
39170-
39171- return 0;
39172-
39173-err_out:
39174- if (driver) {
39175- kfree(driver);
39176- cpufreq_us3_driver = NULL;
39177- }
39178- kfree(us3_freq_table);
39179- us3_freq_table = NULL;
39180- return ret;
39181- }
39182+ impl == PANTHER_IMPL))
39183+ return cpufreq_register_driver(&cpufreq_us3_driver);
39184
39185 return -ENODEV;
39186 }
39187
39188 static void __exit us3_freq_exit(void)
39189 {
39190- if (cpufreq_us3_driver) {
39191- cpufreq_unregister_driver(cpufreq_us3_driver);
39192- kfree(cpufreq_us3_driver);
39193- cpufreq_us3_driver = NULL;
39194- kfree(us3_freq_table);
39195- us3_freq_table = NULL;
39196- }
39197+ cpufreq_unregister_driver(&cpufreq_us3_driver);
39198 }
39199
39200 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39201diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39202index 4e1daca..e707b61 100644
39203--- a/drivers/cpufreq/speedstep-centrino.c
39204+++ b/drivers/cpufreq/speedstep-centrino.c
39205@@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39206 !cpu_has(cpu, X86_FEATURE_EST))
39207 return -ENODEV;
39208
39209- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39210- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39211+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39212+ pax_open_kernel();
39213+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39214+ pax_close_kernel();
39215+ }
39216
39217 if (policy->cpu != 0)
39218 return -ENODEV;
39219diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39220index 06dbe7c..c2c8671 100644
39221--- a/drivers/cpuidle/driver.c
39222+++ b/drivers/cpuidle/driver.c
39223@@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39224
39225 static void poll_idle_init(struct cpuidle_driver *drv)
39226 {
39227- struct cpuidle_state *state = &drv->states[0];
39228+ cpuidle_state_no_const *state = &drv->states[0];
39229
39230 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39231 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39232diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39233index ca89412..a7b9c49 100644
39234--- a/drivers/cpuidle/governor.c
39235+++ b/drivers/cpuidle/governor.c
39236@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39237 mutex_lock(&cpuidle_lock);
39238 if (__cpuidle_find_governor(gov->name) == NULL) {
39239 ret = 0;
39240- list_add_tail(&gov->governor_list, &cpuidle_governors);
39241+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39242 if (!cpuidle_curr_governor ||
39243 cpuidle_curr_governor->rating < gov->rating)
39244 cpuidle_switch_governor(gov);
39245diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39246index e918b6d..f87ea80 100644
39247--- a/drivers/cpuidle/sysfs.c
39248+++ b/drivers/cpuidle/sysfs.c
39249@@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39250 NULL
39251 };
39252
39253-static struct attribute_group cpuidle_attr_group = {
39254+static attribute_group_no_const cpuidle_attr_group = {
39255 .attrs = cpuidle_default_attrs,
39256 .name = "cpuidle",
39257 };
39258diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39259index 12fea3e..1e28f47 100644
39260--- a/drivers/crypto/hifn_795x.c
39261+++ b/drivers/crypto/hifn_795x.c
39262@@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39263 MODULE_PARM_DESC(hifn_pll_ref,
39264 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39265
39266-static atomic_t hifn_dev_number;
39267+static atomic_unchecked_t hifn_dev_number;
39268
39269 #define ACRYPTO_OP_DECRYPT 0
39270 #define ACRYPTO_OP_ENCRYPT 1
39271@@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39272 goto err_out_disable_pci_device;
39273
39274 snprintf(name, sizeof(name), "hifn%d",
39275- atomic_inc_return(&hifn_dev_number)-1);
39276+ atomic_inc_return_unchecked(&hifn_dev_number)-1);
39277
39278 err = pci_request_regions(pdev, name);
39279 if (err)
39280diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39281index a0b2f7e..1b6f028 100644
39282--- a/drivers/devfreq/devfreq.c
39283+++ b/drivers/devfreq/devfreq.c
39284@@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39285 goto err_out;
39286 }
39287
39288- list_add(&governor->node, &devfreq_governor_list);
39289+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39290
39291 list_for_each_entry(devfreq, &devfreq_list, node) {
39292 int ret = 0;
39293@@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39294 }
39295 }
39296
39297- list_del(&governor->node);
39298+ pax_list_del((struct list_head *)&governor->node);
39299 err_out:
39300 mutex_unlock(&devfreq_list_lock);
39301
39302diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39303index 0d765c0..60b7480 100644
39304--- a/drivers/dma/sh/shdmac.c
39305+++ b/drivers/dma/sh/shdmac.c
39306@@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39307 return ret;
39308 }
39309
39310-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39311+static struct notifier_block sh_dmae_nmi_notifier = {
39312 .notifier_call = sh_dmae_nmi_handler,
39313
39314 /* Run before NMI debug handler and KGDB */
39315diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39316index 1026743..80b081c 100644
39317--- a/drivers/edac/edac_device.c
39318+++ b/drivers/edac/edac_device.c
39319@@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39320 */
39321 int edac_device_alloc_index(void)
39322 {
39323- static atomic_t device_indexes = ATOMIC_INIT(0);
39324+ static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39325
39326- return atomic_inc_return(&device_indexes) - 1;
39327+ return atomic_inc_return_unchecked(&device_indexes) - 1;
39328 }
39329 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39330
39331diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39332index e5bdf21..b8f9055 100644
39333--- a/drivers/edac/edac_mc_sysfs.c
39334+++ b/drivers/edac/edac_mc_sysfs.c
39335@@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39336 struct dev_ch_attribute {
39337 struct device_attribute attr;
39338 int channel;
39339-};
39340+} __do_const;
39341
39342 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39343 struct dev_ch_attribute dev_attr_legacy_##_name = \
39344@@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39345 }
39346
39347 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39348+ pax_open_kernel();
39349 if (mci->get_sdram_scrub_rate) {
39350- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39351- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39352+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39353+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39354 }
39355 if (mci->set_sdram_scrub_rate) {
39356- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39357- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39358+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39359+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39360 }
39361+ pax_close_kernel();
39362 err = device_create_file(&mci->dev,
39363 &dev_attr_sdram_scrub_rate);
39364 if (err) {
39365diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39366index 2cf44b4d..6dd2dc7 100644
39367--- a/drivers/edac/edac_pci.c
39368+++ b/drivers/edac/edac_pci.c
39369@@ -29,7 +29,7 @@
39370
39371 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39372 static LIST_HEAD(edac_pci_list);
39373-static atomic_t pci_indexes = ATOMIC_INIT(0);
39374+static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39375
39376 /*
39377 * edac_pci_alloc_ctl_info
39378@@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39379 */
39380 int edac_pci_alloc_index(void)
39381 {
39382- return atomic_inc_return(&pci_indexes) - 1;
39383+ return atomic_inc_return_unchecked(&pci_indexes) - 1;
39384 }
39385 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39386
39387diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39388index e8658e4..22746d6 100644
39389--- a/drivers/edac/edac_pci_sysfs.c
39390+++ b/drivers/edac/edac_pci_sysfs.c
39391@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39392 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39393 static int edac_pci_poll_msec = 1000; /* one second workq period */
39394
39395-static atomic_t pci_parity_count = ATOMIC_INIT(0);
39396-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39397+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39398+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39399
39400 static struct kobject *edac_pci_top_main_kobj;
39401 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39402@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39403 void *value;
39404 ssize_t(*show) (void *, char *);
39405 ssize_t(*store) (void *, const char *, size_t);
39406-};
39407+} __do_const;
39408
39409 /* Set of show/store abstract level functions for PCI Parity object */
39410 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39411@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39412 edac_printk(KERN_CRIT, EDAC_PCI,
39413 "Signaled System Error on %s\n",
39414 pci_name(dev));
39415- atomic_inc(&pci_nonparity_count);
39416+ atomic_inc_unchecked(&pci_nonparity_count);
39417 }
39418
39419 if (status & (PCI_STATUS_PARITY)) {
39420@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39421 "Master Data Parity Error on %s\n",
39422 pci_name(dev));
39423
39424- atomic_inc(&pci_parity_count);
39425+ atomic_inc_unchecked(&pci_parity_count);
39426 }
39427
39428 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39429@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39430 "Detected Parity Error on %s\n",
39431 pci_name(dev));
39432
39433- atomic_inc(&pci_parity_count);
39434+ atomic_inc_unchecked(&pci_parity_count);
39435 }
39436 }
39437
39438@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39439 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39440 "Signaled System Error on %s\n",
39441 pci_name(dev));
39442- atomic_inc(&pci_nonparity_count);
39443+ atomic_inc_unchecked(&pci_nonparity_count);
39444 }
39445
39446 if (status & (PCI_STATUS_PARITY)) {
39447@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39448 "Master Data Parity Error on "
39449 "%s\n", pci_name(dev));
39450
39451- atomic_inc(&pci_parity_count);
39452+ atomic_inc_unchecked(&pci_parity_count);
39453 }
39454
39455 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39456@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39457 "Detected Parity Error on %s\n",
39458 pci_name(dev));
39459
39460- atomic_inc(&pci_parity_count);
39461+ atomic_inc_unchecked(&pci_parity_count);
39462 }
39463 }
39464 }
39465@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39466 if (!check_pci_errors)
39467 return;
39468
39469- before_count = atomic_read(&pci_parity_count);
39470+ before_count = atomic_read_unchecked(&pci_parity_count);
39471
39472 /* scan all PCI devices looking for a Parity Error on devices and
39473 * bridges.
39474@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39475 /* Only if operator has selected panic on PCI Error */
39476 if (edac_pci_get_panic_on_pe()) {
39477 /* If the count is different 'after' from 'before' */
39478- if (before_count != atomic_read(&pci_parity_count))
39479+ if (before_count != atomic_read_unchecked(&pci_parity_count))
39480 panic("EDAC: PCI Parity Error");
39481 }
39482 }
39483diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39484index 51b7e3a..aa8a3e8 100644
39485--- a/drivers/edac/mce_amd.h
39486+++ b/drivers/edac/mce_amd.h
39487@@ -77,7 +77,7 @@ struct amd_decoder_ops {
39488 bool (*mc0_mce)(u16, u8);
39489 bool (*mc1_mce)(u16, u8);
39490 bool (*mc2_mce)(u16, u8);
39491-};
39492+} __no_const;
39493
39494 void amd_report_gart_errors(bool);
39495 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39496diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39497index 57ea7f4..af06b76 100644
39498--- a/drivers/firewire/core-card.c
39499+++ b/drivers/firewire/core-card.c
39500@@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39501 const struct fw_card_driver *driver,
39502 struct device *device)
39503 {
39504- static atomic_t index = ATOMIC_INIT(-1);
39505+ static atomic_unchecked_t index = ATOMIC_INIT(-1);
39506
39507- card->index = atomic_inc_return(&index);
39508+ card->index = atomic_inc_return_unchecked(&index);
39509 card->driver = driver;
39510 card->device = device;
39511 card->current_tlabel = 0;
39512@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39513
39514 void fw_core_remove_card(struct fw_card *card)
39515 {
39516- struct fw_card_driver dummy_driver = dummy_driver_template;
39517+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
39518
39519 card->driver->update_phy_reg(card, 4,
39520 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39521diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39522index 2c6d5e1..a2cca6b 100644
39523--- a/drivers/firewire/core-device.c
39524+++ b/drivers/firewire/core-device.c
39525@@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39526 struct config_rom_attribute {
39527 struct device_attribute attr;
39528 u32 key;
39529-};
39530+} __do_const;
39531
39532 static ssize_t show_immediate(struct device *dev,
39533 struct device_attribute *dattr, char *buf)
39534diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39535index 0e79951..b180217 100644
39536--- a/drivers/firewire/core-transaction.c
39537+++ b/drivers/firewire/core-transaction.c
39538@@ -38,6 +38,7 @@
39539 #include <linux/timer.h>
39540 #include <linux/types.h>
39541 #include <linux/workqueue.h>
39542+#include <linux/sched.h>
39543
39544 #include <asm/byteorder.h>
39545
39546diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39547index 515a42c..5ecf3ba 100644
39548--- a/drivers/firewire/core.h
39549+++ b/drivers/firewire/core.h
39550@@ -111,6 +111,7 @@ struct fw_card_driver {
39551
39552 int (*stop_iso)(struct fw_iso_context *ctx);
39553 };
39554+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39555
39556 void fw_card_initialize(struct fw_card *card,
39557 const struct fw_card_driver *driver, struct device *device);
39558diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39559index 94a58a0..f5eba42 100644
39560--- a/drivers/firmware/dmi-id.c
39561+++ b/drivers/firmware/dmi-id.c
39562@@ -16,7 +16,7 @@
39563 struct dmi_device_attribute{
39564 struct device_attribute dev_attr;
39565 int field;
39566-};
39567+} __do_const;
39568 #define to_dmi_dev_attr(_dev_attr) \
39569 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39570
39571diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39572index c7e81ff..94a7401 100644
39573--- a/drivers/firmware/dmi_scan.c
39574+++ b/drivers/firmware/dmi_scan.c
39575@@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39576 if (buf == NULL)
39577 return -1;
39578
39579- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39580+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39581
39582 iounmap(buf);
39583 return 0;
39584diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39585index 1491dd4..aa910db 100644
39586--- a/drivers/firmware/efi/cper.c
39587+++ b/drivers/firmware/efi/cper.c
39588@@ -41,12 +41,12 @@
39589 */
39590 u64 cper_next_record_id(void)
39591 {
39592- static atomic64_t seq;
39593+ static atomic64_unchecked_t seq;
39594
39595- if (!atomic64_read(&seq))
39596- atomic64_set(&seq, ((u64)get_seconds()) << 32);
39597+ if (!atomic64_read_unchecked(&seq))
39598+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39599
39600- return atomic64_inc_return(&seq);
39601+ return atomic64_inc_return_unchecked(&seq);
39602 }
39603 EXPORT_SYMBOL_GPL(cper_next_record_id);
39604
39605diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39606index 2e2fbde..7676c8b 100644
39607--- a/drivers/firmware/efi/efi.c
39608+++ b/drivers/firmware/efi/efi.c
39609@@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39610 };
39611
39612 static struct efivars generic_efivars;
39613-static struct efivar_operations generic_ops;
39614+static efivar_operations_no_const generic_ops __read_only;
39615
39616 static int generic_ops_register(void)
39617 {
39618- generic_ops.get_variable = efi.get_variable;
39619- generic_ops.set_variable = efi.set_variable;
39620- generic_ops.get_next_variable = efi.get_next_variable;
39621- generic_ops.query_variable_store = efi_query_variable_store;
39622+ pax_open_kernel();
39623+ *(void **)&generic_ops.get_variable = efi.get_variable;
39624+ *(void **)&generic_ops.set_variable = efi.set_variable;
39625+ *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39626+ *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39627+ pax_close_kernel();
39628
39629 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39630 }
39631diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39632index 3dc2482..7bd2f61 100644
39633--- a/drivers/firmware/efi/efivars.c
39634+++ b/drivers/firmware/efi/efivars.c
39635@@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39636 static int
39637 create_efivars_bin_attributes(void)
39638 {
39639- struct bin_attribute *attr;
39640+ bin_attribute_no_const *attr;
39641 int error;
39642
39643 /* new_var */
39644diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39645index 2a90ba6..07f3733 100644
39646--- a/drivers/firmware/google/memconsole.c
39647+++ b/drivers/firmware/google/memconsole.c
39648@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39649 if (!found_memconsole())
39650 return -ENODEV;
39651
39652- memconsole_bin_attr.size = memconsole_length;
39653+ pax_open_kernel();
39654+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39655+ pax_close_kernel();
39656
39657 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39658
39659diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39660index ec19036..8ffafc2 100644
39661--- a/drivers/gpio/gpio-em.c
39662+++ b/drivers/gpio/gpio-em.c
39663@@ -257,7 +257,7 @@ static int em_gio_probe(struct platform_device *pdev)
39664 struct em_gio_priv *p;
39665 struct resource *io[2], *irq[2];
39666 struct gpio_chip *gpio_chip;
39667- struct irq_chip *irq_chip;
39668+ irq_chip_no_const *irq_chip;
39669 const char *name = dev_name(&pdev->dev);
39670 int ret;
39671
39672diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39673index 814addb..0937d7f 100644
39674--- a/drivers/gpio/gpio-ich.c
39675+++ b/drivers/gpio/gpio-ich.c
39676@@ -71,7 +71,7 @@ struct ichx_desc {
39677 /* Some chipsets have quirks, let these use their own request/get */
39678 int (*request)(struct gpio_chip *chip, unsigned offset);
39679 int (*get)(struct gpio_chip *chip, unsigned offset);
39680-};
39681+} __do_const;
39682
39683 static struct {
39684 spinlock_t lock;
39685diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39686index 8b7e719..dc089dc 100644
39687--- a/drivers/gpio/gpio-rcar.c
39688+++ b/drivers/gpio/gpio-rcar.c
39689@@ -316,7 +316,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39690 struct gpio_rcar_priv *p;
39691 struct resource *io, *irq;
39692 struct gpio_chip *gpio_chip;
39693- struct irq_chip *irq_chip;
39694+ irq_chip_no_const *irq_chip;
39695 const char *name = dev_name(&pdev->dev);
39696 int ret;
39697
39698diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39699index 9902732..64b62dd 100644
39700--- a/drivers/gpio/gpio-vr41xx.c
39701+++ b/drivers/gpio/gpio-vr41xx.c
39702@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39703 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39704 maskl, pendl, maskh, pendh);
39705
39706- atomic_inc(&irq_err_count);
39707+ atomic_inc_unchecked(&irq_err_count);
39708
39709 return -EINVAL;
39710 }
39711diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39712index d6cf77c..2842146 100644
39713--- a/drivers/gpu/drm/drm_crtc.c
39714+++ b/drivers/gpu/drm/drm_crtc.c
39715@@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39716 goto done;
39717 }
39718
39719- if (copy_to_user(&enum_ptr[copied].name,
39720+ if (copy_to_user(enum_ptr[copied].name,
39721 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39722 ret = -EFAULT;
39723 goto done;
39724diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39725index 01361ab..891e821 100644
39726--- a/drivers/gpu/drm/drm_crtc_helper.c
39727+++ b/drivers/gpu/drm/drm_crtc_helper.c
39728@@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39729 struct drm_crtc *tmp;
39730 int crtc_mask = 1;
39731
39732- WARN(!crtc, "checking null crtc?\n");
39733+ BUG_ON(!crtc);
39734
39735 dev = crtc->dev;
39736
39737diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39738index d9137e4..69b73a0 100644
39739--- a/drivers/gpu/drm/drm_drv.c
39740+++ b/drivers/gpu/drm/drm_drv.c
39741@@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39742 /**
39743 * Copy and IOCTL return string to user space
39744 */
39745-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39746+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39747 {
39748 int len;
39749
39750@@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39751 struct drm_file *file_priv = filp->private_data;
39752 struct drm_device *dev;
39753 const struct drm_ioctl_desc *ioctl = NULL;
39754- drm_ioctl_t *func;
39755+ drm_ioctl_no_const_t func;
39756 unsigned int nr = DRM_IOCTL_NR(cmd);
39757 int retcode = -EINVAL;
39758 char stack_kdata[128];
39759diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39760index c5b929c..8a3b8be 100644
39761--- a/drivers/gpu/drm/drm_fops.c
39762+++ b/drivers/gpu/drm/drm_fops.c
39763@@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39764 if (drm_device_is_unplugged(dev))
39765 return -ENODEV;
39766
39767- if (!dev->open_count++)
39768+ if (local_inc_return(&dev->open_count) == 1)
39769 need_setup = 1;
39770 mutex_lock(&dev->struct_mutex);
39771 old_imapping = inode->i_mapping;
39772@@ -127,7 +127,7 @@ err_undo:
39773 iput(container_of(dev->dev_mapping, struct inode, i_data));
39774 dev->dev_mapping = old_mapping;
39775 mutex_unlock(&dev->struct_mutex);
39776- dev->open_count--;
39777+ local_dec(&dev->open_count);
39778 return retcode;
39779 }
39780 EXPORT_SYMBOL(drm_open);
39781@@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39782
39783 mutex_lock(&drm_global_mutex);
39784
39785- DRM_DEBUG("open_count = %d\n", dev->open_count);
39786+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39787
39788 if (dev->driver->preclose)
39789 dev->driver->preclose(dev, file_priv);
39790@@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39791 * Begin inline drm_release
39792 */
39793
39794- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39795+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39796 task_pid_nr(current),
39797 (long)old_encode_dev(file_priv->minor->device),
39798- dev->open_count);
39799+ local_read(&dev->open_count));
39800
39801 /* Release any auth tokens that might point to this file_priv,
39802 (do that under the drm_global_mutex) */
39803@@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39804 * End inline drm_release
39805 */
39806
39807- if (!--dev->open_count) {
39808+ if (local_dec_and_test(&dev->open_count)) {
39809 if (atomic_read(&dev->ioctl_count)) {
39810 DRM_ERROR("Device busy: %d\n",
39811 atomic_read(&dev->ioctl_count));
39812diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39813index 3d2e91c..d31c4c9 100644
39814--- a/drivers/gpu/drm/drm_global.c
39815+++ b/drivers/gpu/drm/drm_global.c
39816@@ -36,7 +36,7 @@
39817 struct drm_global_item {
39818 struct mutex mutex;
39819 void *object;
39820- int refcount;
39821+ atomic_t refcount;
39822 };
39823
39824 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39825@@ -49,7 +49,7 @@ void drm_global_init(void)
39826 struct drm_global_item *item = &glob[i];
39827 mutex_init(&item->mutex);
39828 item->object = NULL;
39829- item->refcount = 0;
39830+ atomic_set(&item->refcount, 0);
39831 }
39832 }
39833
39834@@ -59,7 +59,7 @@ void drm_global_release(void)
39835 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39836 struct drm_global_item *item = &glob[i];
39837 BUG_ON(item->object != NULL);
39838- BUG_ON(item->refcount != 0);
39839+ BUG_ON(atomic_read(&item->refcount) != 0);
39840 }
39841 }
39842
39843@@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39844 struct drm_global_item *item = &glob[ref->global_type];
39845
39846 mutex_lock(&item->mutex);
39847- if (item->refcount == 0) {
39848+ if (atomic_read(&item->refcount) == 0) {
39849 item->object = kzalloc(ref->size, GFP_KERNEL);
39850 if (unlikely(item->object == NULL)) {
39851 ret = -ENOMEM;
39852@@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39853 goto out_err;
39854
39855 }
39856- ++item->refcount;
39857+ atomic_inc(&item->refcount);
39858 ref->object = item->object;
39859 mutex_unlock(&item->mutex);
39860 return 0;
39861@@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39862 struct drm_global_item *item = &glob[ref->global_type];
39863
39864 mutex_lock(&item->mutex);
39865- BUG_ON(item->refcount == 0);
39866+ BUG_ON(atomic_read(&item->refcount) == 0);
39867 BUG_ON(ref->object != item->object);
39868- if (--item->refcount == 0) {
39869+ if (atomic_dec_and_test(&item->refcount)) {
39870 ref->release(ref);
39871 item->object = NULL;
39872 }
39873diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39874index 7d5a152..d7186da 100644
39875--- a/drivers/gpu/drm/drm_info.c
39876+++ b/drivers/gpu/drm/drm_info.c
39877@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39878 struct drm_local_map *map;
39879 struct drm_map_list *r_list;
39880
39881- /* Hardcoded from _DRM_FRAME_BUFFER,
39882- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39883- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39884- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39885+ static const char * const types[] = {
39886+ [_DRM_FRAME_BUFFER] = "FB",
39887+ [_DRM_REGISTERS] = "REG",
39888+ [_DRM_SHM] = "SHM",
39889+ [_DRM_AGP] = "AGP",
39890+ [_DRM_SCATTER_GATHER] = "SG",
39891+ [_DRM_CONSISTENT] = "PCI",
39892+ [_DRM_GEM] = "GEM" };
39893 const char *type;
39894 int i;
39895
39896@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39897 map = r_list->map;
39898 if (!map)
39899 continue;
39900- if (map->type < 0 || map->type > 5)
39901+ if (map->type >= ARRAY_SIZE(types))
39902 type = "??";
39903 else
39904 type = types[map->type];
39905@@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39906 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39907 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39908 vma->vm_flags & VM_IO ? 'i' : '-',
39909+#ifdef CONFIG_GRKERNSEC_HIDESYM
39910+ 0);
39911+#else
39912 vma->vm_pgoff);
39913+#endif
39914
39915 #if defined(__i386__)
39916 pgprot = pgprot_val(vma->vm_page_prot);
39917diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39918index 2f4c4343..dd12cd2 100644
39919--- a/drivers/gpu/drm/drm_ioc32.c
39920+++ b/drivers/gpu/drm/drm_ioc32.c
39921@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39922 request = compat_alloc_user_space(nbytes);
39923 if (!access_ok(VERIFY_WRITE, request, nbytes))
39924 return -EFAULT;
39925- list = (struct drm_buf_desc *) (request + 1);
39926+ list = (struct drm_buf_desc __user *) (request + 1);
39927
39928 if (__put_user(count, &request->count)
39929 || __put_user(list, &request->list))
39930@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39931 request = compat_alloc_user_space(nbytes);
39932 if (!access_ok(VERIFY_WRITE, request, nbytes))
39933 return -EFAULT;
39934- list = (struct drm_buf_pub *) (request + 1);
39935+ list = (struct drm_buf_pub __user *) (request + 1);
39936
39937 if (__put_user(count, &request->count)
39938 || __put_user(list, &request->list))
39939@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39940 return 0;
39941 }
39942
39943-drm_ioctl_compat_t *drm_compat_ioctls[] = {
39944+drm_ioctl_compat_t drm_compat_ioctls[] = {
39945 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39946 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39947 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39948@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39949 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39950 {
39951 unsigned int nr = DRM_IOCTL_NR(cmd);
39952- drm_ioctl_compat_t *fn;
39953 int ret;
39954
39955 /* Assume that ioctls without an explicit compat routine will just
39956@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39957 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39958 return drm_ioctl(filp, cmd, arg);
39959
39960- fn = drm_compat_ioctls[nr];
39961-
39962- if (fn != NULL)
39963- ret = (*fn) (filp, cmd, arg);
39964+ if (drm_compat_ioctls[nr] != NULL)
39965+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39966 else
39967 ret = drm_ioctl(filp, cmd, arg);
39968
39969diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39970index 66dd3a0..3bed6c4 100644
39971--- a/drivers/gpu/drm/drm_stub.c
39972+++ b/drivers/gpu/drm/drm_stub.c
39973@@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39974
39975 drm_device_set_unplugged(dev);
39976
39977- if (dev->open_count == 0) {
39978+ if (local_read(&dev->open_count) == 0) {
39979 drm_put_dev(dev);
39980 }
39981 mutex_unlock(&drm_global_mutex);
39982diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39983index c22c309..ae758c3 100644
39984--- a/drivers/gpu/drm/drm_sysfs.c
39985+++ b/drivers/gpu/drm/drm_sysfs.c
39986@@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39987 */
39988 int drm_sysfs_device_add(struct drm_minor *minor)
39989 {
39990- char *minor_str;
39991+ const char *minor_str;
39992 int r;
39993
39994 if (minor->type == DRM_MINOR_CONTROL)
39995diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39996index d4d16ed..8fb0b51 100644
39997--- a/drivers/gpu/drm/i810/i810_drv.h
39998+++ b/drivers/gpu/drm/i810/i810_drv.h
39999@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40000 int page_flipping;
40001
40002 wait_queue_head_t irq_queue;
40003- atomic_t irq_received;
40004- atomic_t irq_emitted;
40005+ atomic_unchecked_t irq_received;
40006+ atomic_unchecked_t irq_emitted;
40007
40008 int front_offset;
40009 } drm_i810_private_t;
40010diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
40011index 6ed45a9..eb6dc41 100644
40012--- a/drivers/gpu/drm/i915/i915_debugfs.c
40013+++ b/drivers/gpu/drm/i915/i915_debugfs.c
40014@@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
40015 I915_READ(GTIMR));
40016 }
40017 seq_printf(m, "Interrupts received: %d\n",
40018- atomic_read(&dev_priv->irq_received));
40019+ atomic_read_unchecked(&dev_priv->irq_received));
40020 for_each_ring(ring, dev_priv, i) {
40021 if (INTEL_INFO(dev)->gen >= 6) {
40022 seq_printf(m,
40023diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40024index e02266a..e3411aa 100644
40025--- a/drivers/gpu/drm/i915/i915_dma.c
40026+++ b/drivers/gpu/drm/i915/i915_dma.c
40027@@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40028 bool can_switch;
40029
40030 spin_lock(&dev->count_lock);
40031- can_switch = (dev->open_count == 0);
40032+ can_switch = (local_read(&dev->open_count) == 0);
40033 spin_unlock(&dev->count_lock);
40034 return can_switch;
40035 }
40036diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
40037index 221ac62..f56acc8 100644
40038--- a/drivers/gpu/drm/i915/i915_drv.h
40039+++ b/drivers/gpu/drm/i915/i915_drv.h
40040@@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
40041 drm_dma_handle_t *status_page_dmah;
40042 struct resource mch_res;
40043
40044- atomic_t irq_received;
40045+ atomic_unchecked_t irq_received;
40046
40047 /* protects the irq masks */
40048 spinlock_t irq_lock;
40049diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40050index a3ba9a8..ee52ddd 100644
40051--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40052+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40053@@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40054
40055 static int
40056 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40057- int count)
40058+ unsigned int count)
40059 {
40060- int i;
40061+ unsigned int i;
40062 unsigned relocs_total = 0;
40063 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40064
40065diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40066index 3c59584..500f2e9 100644
40067--- a/drivers/gpu/drm/i915/i915_ioc32.c
40068+++ b/drivers/gpu/drm/i915/i915_ioc32.c
40069@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40070 (unsigned long)request);
40071 }
40072
40073-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40074+static drm_ioctl_compat_t i915_compat_ioctls[] = {
40075 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40076 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40077 [DRM_I915_GETPARAM] = compat_i915_getparam,
40078@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40079 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40080 {
40081 unsigned int nr = DRM_IOCTL_NR(cmd);
40082- drm_ioctl_compat_t *fn = NULL;
40083 int ret;
40084
40085 if (nr < DRM_COMMAND_BASE)
40086 return drm_compat_ioctl(filp, cmd, arg);
40087
40088- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40089- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40090-
40091- if (fn != NULL)
40092+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40093+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40094 ret = (*fn) (filp, cmd, arg);
40095- else
40096+ } else
40097 ret = drm_ioctl(filp, cmd, arg);
40098
40099 return ret;
40100diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
40101index 9702704..3fb9e40 100644
40102--- a/drivers/gpu/drm/i915/i915_irq.c
40103+++ b/drivers/gpu/drm/i915/i915_irq.c
40104@@ -1419,7 +1419,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
40105 int pipe;
40106 u32 pipe_stats[I915_MAX_PIPES];
40107
40108- atomic_inc(&dev_priv->irq_received);
40109+ atomic_inc_unchecked(&dev_priv->irq_received);
40110
40111 while (true) {
40112 iir = I915_READ(VLV_IIR);
40113@@ -1729,7 +1729,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
40114 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
40115 irqreturn_t ret = IRQ_NONE;
40116
40117- atomic_inc(&dev_priv->irq_received);
40118+ atomic_inc_unchecked(&dev_priv->irq_received);
40119
40120 /* We get interrupts on unclaimed registers, so check for this before we
40121 * do any I915_{READ,WRITE}. */
40122@@ -1799,7 +1799,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
40123 uint32_t tmp = 0;
40124 enum pipe pipe;
40125
40126- atomic_inc(&dev_priv->irq_received);
40127+ atomic_inc_unchecked(&dev_priv->irq_received);
40128
40129 master_ctl = I915_READ(GEN8_MASTER_IRQ);
40130 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
40131@@ -2623,7 +2623,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
40132 {
40133 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40134
40135- atomic_set(&dev_priv->irq_received, 0);
40136+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40137
40138 I915_WRITE(HWSTAM, 0xeffe);
40139
40140@@ -2641,7 +2641,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
40141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
40142 int pipe;
40143
40144- atomic_set(&dev_priv->irq_received, 0);
40145+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40146
40147 /* VLV magic */
40148 I915_WRITE(VLV_IMR, 0);
40149@@ -2672,7 +2672,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
40150 struct drm_i915_private *dev_priv = dev->dev_private;
40151 int pipe;
40152
40153- atomic_set(&dev_priv->irq_received, 0);
40154+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40155
40156 I915_WRITE(GEN8_MASTER_IRQ, 0);
40157 POSTING_READ(GEN8_MASTER_IRQ);
40158@@ -2996,7 +2996,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
40159 if (!dev_priv)
40160 return;
40161
40162- atomic_set(&dev_priv->irq_received, 0);
40163+ atomic_set_unchecked(&dev_priv->irq_received, 0);
40164
40165 I915_WRITE(GEN8_MASTER_IRQ, 0);
40166
40167@@ -3090,7 +3090,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
40168 drm_i915_private_t *dev_priv = (drm_i915_private_t *) 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 for_each_pipe(pipe)
40175 I915_WRITE(PIPESTAT(pipe), 0);
40176@@ -3176,7 +3176,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
40177 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40178 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40179
40180- atomic_inc(&dev_priv->irq_received);
40181+ atomic_inc_unchecked(&dev_priv->irq_received);
40182
40183 iir = I915_READ16(IIR);
40184 if (iir == 0)
40185@@ -3251,7 +3251,7 @@ static void i915_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 if (I915_HAS_HOTPLUG(dev)) {
40193 I915_WRITE(PORT_HOTPLUG_EN, 0);
40194@@ -3358,7 +3358,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
40195 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40196 int pipe, ret = IRQ_NONE;
40197
40198- atomic_inc(&dev_priv->irq_received);
40199+ atomic_inc_unchecked(&dev_priv->irq_received);
40200
40201 iir = I915_READ(IIR);
40202 do {
40203@@ -3485,7 +3485,7 @@ static void i965_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 I915_WRITE(PORT_HOTPLUG_EN, 0);
40211 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
40212@@ -3601,7 +3601,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
40213 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
40214 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
40215
40216- atomic_inc(&dev_priv->irq_received);
40217+ atomic_inc_unchecked(&dev_priv->irq_received);
40218
40219 iir = I915_READ(IIR);
40220
40221diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40222index 3c5ff7a..ae759ca 100644
40223--- a/drivers/gpu/drm/i915/intel_display.c
40224+++ b/drivers/gpu/drm/i915/intel_display.c
40225@@ -10506,13 +10506,13 @@ struct intel_quirk {
40226 int subsystem_vendor;
40227 int subsystem_device;
40228 void (*hook)(struct drm_device *dev);
40229-};
40230+} __do_const;
40231
40232 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40233 struct intel_dmi_quirk {
40234 void (*hook)(struct drm_device *dev);
40235 const struct dmi_system_id (*dmi_id_list)[];
40236-};
40237+} __do_const;
40238
40239 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40240 {
40241@@ -10520,18 +10520,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40242 return 1;
40243 }
40244
40245-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40246+static const struct dmi_system_id intel_dmi_quirks_table[] = {
40247 {
40248- .dmi_id_list = &(const struct dmi_system_id[]) {
40249- {
40250- .callback = intel_dmi_reverse_brightness,
40251- .ident = "NCR Corporation",
40252- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40253- DMI_MATCH(DMI_PRODUCT_NAME, ""),
40254- },
40255- },
40256- { } /* terminating entry */
40257+ .callback = intel_dmi_reverse_brightness,
40258+ .ident = "NCR Corporation",
40259+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40260+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
40261 },
40262+ },
40263+ { } /* terminating entry */
40264+};
40265+
40266+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40267+ {
40268+ .dmi_id_list = &intel_dmi_quirks_table,
40269 .hook = quirk_invert_brightness,
40270 },
40271 };
40272diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40273index ca4bc54..ee598a2 100644
40274--- a/drivers/gpu/drm/mga/mga_drv.h
40275+++ b/drivers/gpu/drm/mga/mga_drv.h
40276@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40277 u32 clear_cmd;
40278 u32 maccess;
40279
40280- atomic_t vbl_received; /**< Number of vblanks received. */
40281+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40282 wait_queue_head_t fence_queue;
40283- atomic_t last_fence_retired;
40284+ atomic_unchecked_t last_fence_retired;
40285 u32 next_fence_to_post;
40286
40287 unsigned int fb_cpp;
40288diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40289index 709e90d..89a1c0d 100644
40290--- a/drivers/gpu/drm/mga/mga_ioc32.c
40291+++ b/drivers/gpu/drm/mga/mga_ioc32.c
40292@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40293 return 0;
40294 }
40295
40296-drm_ioctl_compat_t *mga_compat_ioctls[] = {
40297+drm_ioctl_compat_t mga_compat_ioctls[] = {
40298 [DRM_MGA_INIT] = compat_mga_init,
40299 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40300 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40301@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40302 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40303 {
40304 unsigned int nr = DRM_IOCTL_NR(cmd);
40305- drm_ioctl_compat_t *fn = NULL;
40306 int ret;
40307
40308 if (nr < DRM_COMMAND_BASE)
40309 return drm_compat_ioctl(filp, cmd, arg);
40310
40311- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40312- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40313-
40314- if (fn != NULL)
40315+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40316+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40317 ret = (*fn) (filp, cmd, arg);
40318- else
40319+ } else
40320 ret = drm_ioctl(filp, cmd, arg);
40321
40322 return ret;
40323diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40324index 2b0ceb8..517e99e 100644
40325--- a/drivers/gpu/drm/mga/mga_irq.c
40326+++ b/drivers/gpu/drm/mga/mga_irq.c
40327@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40328 if (crtc != 0)
40329 return 0;
40330
40331- return atomic_read(&dev_priv->vbl_received);
40332+ return atomic_read_unchecked(&dev_priv->vbl_received);
40333 }
40334
40335
40336@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40337 /* VBLANK interrupt */
40338 if (status & MGA_VLINEPEN) {
40339 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40340- atomic_inc(&dev_priv->vbl_received);
40341+ atomic_inc_unchecked(&dev_priv->vbl_received);
40342 drm_handle_vblank(dev, 0);
40343 handled = 1;
40344 }
40345@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
40346 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40347 MGA_WRITE(MGA_PRIMEND, prim_end);
40348
40349- atomic_inc(&dev_priv->last_fence_retired);
40350+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
40351 DRM_WAKEUP(&dev_priv->fence_queue);
40352 handled = 1;
40353 }
40354@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40355 * using fences.
40356 */
40357 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
40358- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40359+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40360 - *sequence) <= (1 << 23)));
40361
40362 *sequence = cur_fence;
40363diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40364index 4c3feaa..26391ce 100644
40365--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40366+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40367@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40368 struct bit_table {
40369 const char id;
40370 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40371-};
40372+} __no_const;
40373
40374 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40375
40376diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40377index 4b0fb6c..67667a9 100644
40378--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40379+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40380@@ -96,7 +96,6 @@ struct nouveau_drm {
40381 struct drm_global_reference mem_global_ref;
40382 struct ttm_bo_global_ref bo_global_ref;
40383 struct ttm_bo_device bdev;
40384- atomic_t validate_sequence;
40385 int (*move)(struct nouveau_channel *,
40386 struct ttm_buffer_object *,
40387 struct ttm_mem_reg *, struct ttm_mem_reg *);
40388diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40389index c1a7e5a..38b8539 100644
40390--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40391+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40392@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40393 unsigned long arg)
40394 {
40395 unsigned int nr = DRM_IOCTL_NR(cmd);
40396- drm_ioctl_compat_t *fn = NULL;
40397+ drm_ioctl_compat_t fn = NULL;
40398 int ret;
40399
40400 if (nr < DRM_COMMAND_BASE)
40401diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40402index 19e3757..ad16478 100644
40403--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40404+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40405@@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40406 }
40407
40408 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40409- nouveau_vram_manager_init,
40410- nouveau_vram_manager_fini,
40411- nouveau_vram_manager_new,
40412- nouveau_vram_manager_del,
40413- nouveau_vram_manager_debug
40414+ .init = nouveau_vram_manager_init,
40415+ .takedown = nouveau_vram_manager_fini,
40416+ .get_node = nouveau_vram_manager_new,
40417+ .put_node = nouveau_vram_manager_del,
40418+ .debug = nouveau_vram_manager_debug
40419 };
40420
40421 static int
40422@@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40423 }
40424
40425 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40426- nouveau_gart_manager_init,
40427- nouveau_gart_manager_fini,
40428- nouveau_gart_manager_new,
40429- nouveau_gart_manager_del,
40430- nouveau_gart_manager_debug
40431+ .init = nouveau_gart_manager_init,
40432+ .takedown = nouveau_gart_manager_fini,
40433+ .get_node = nouveau_gart_manager_new,
40434+ .put_node = nouveau_gart_manager_del,
40435+ .debug = nouveau_gart_manager_debug
40436 };
40437
40438 #include <core/subdev/vm/nv04.h>
40439@@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40440 }
40441
40442 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40443- nv04_gart_manager_init,
40444- nv04_gart_manager_fini,
40445- nv04_gart_manager_new,
40446- nv04_gart_manager_del,
40447- nv04_gart_manager_debug
40448+ .init = nv04_gart_manager_init,
40449+ .takedown = nv04_gart_manager_fini,
40450+ .get_node = nv04_gart_manager_new,
40451+ .put_node = nv04_gart_manager_del,
40452+ .debug = nv04_gart_manager_debug
40453 };
40454
40455 int
40456diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40457index 81638d7..2e45854 100644
40458--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40459+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40460@@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40461 bool can_switch;
40462
40463 spin_lock(&dev->count_lock);
40464- can_switch = (dev->open_count == 0);
40465+ can_switch = (local_read(&dev->open_count) == 0);
40466 spin_unlock(&dev->count_lock);
40467 return can_switch;
40468 }
40469diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40470index eb89653..613cf71 100644
40471--- a/drivers/gpu/drm/qxl/qxl_cmd.c
40472+++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40473@@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40474 int ret;
40475
40476 mutex_lock(&qdev->async_io_mutex);
40477- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40478+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40479 if (qdev->last_sent_io_cmd > irq_num) {
40480 if (intr)
40481 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40482- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40483+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40484 else
40485 ret = wait_event_timeout(qdev->io_cmd_event,
40486- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40487+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40488 /* 0 is timeout, just bail the "hw" has gone away */
40489 if (ret <= 0)
40490 goto out;
40491- irq_num = atomic_read(&qdev->irq_received_io_cmd);
40492+ irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40493 }
40494 outb(val, addr);
40495 qdev->last_sent_io_cmd = irq_num + 1;
40496 if (intr)
40497 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40498- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40499+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40500 else
40501 ret = wait_event_timeout(qdev->io_cmd_event,
40502- atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40503+ atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40504 out:
40505 if (ret > 0)
40506 ret = 0;
40507diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40508index c3c2bbd..bc3c0fb 100644
40509--- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40510+++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40511@@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40512 struct drm_info_node *node = (struct drm_info_node *) m->private;
40513 struct qxl_device *qdev = node->minor->dev->dev_private;
40514
40515- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40516- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40517- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40518- seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40519+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40520+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40521+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40522+ seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40523 seq_printf(m, "%d\n", qdev->irq_received_error);
40524 return 0;
40525 }
40526diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40527index 7bda32f..dd98fc5 100644
40528--- a/drivers/gpu/drm/qxl/qxl_drv.h
40529+++ b/drivers/gpu/drm/qxl/qxl_drv.h
40530@@ -290,10 +290,10 @@ struct qxl_device {
40531 unsigned int last_sent_io_cmd;
40532
40533 /* interrupt handling */
40534- atomic_t irq_received;
40535- atomic_t irq_received_display;
40536- atomic_t irq_received_cursor;
40537- atomic_t irq_received_io_cmd;
40538+ atomic_unchecked_t irq_received;
40539+ atomic_unchecked_t irq_received_display;
40540+ atomic_unchecked_t irq_received_cursor;
40541+ atomic_unchecked_t irq_received_io_cmd;
40542 unsigned irq_received_error;
40543 wait_queue_head_t display_event;
40544 wait_queue_head_t cursor_event;
40545diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40546index 7b95c75..9cffb4f 100644
40547--- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40548+++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40549@@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40550
40551 /* TODO copy slow path code from i915 */
40552 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40553- 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);
40554+ 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);
40555
40556 {
40557 struct qxl_drawable *draw = fb_cmd;
40558@@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40559 struct drm_qxl_reloc reloc;
40560
40561 if (DRM_COPY_FROM_USER(&reloc,
40562- &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40563+ &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40564 sizeof(reloc))) {
40565 ret = -EFAULT;
40566 goto out_free_bos;
40567@@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40568 struct drm_qxl_command *commands =
40569 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40570
40571- if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40572+ if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40573 sizeof(user_cmd)))
40574 return -EFAULT;
40575
40576diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40577index 21393dc..329f3a9 100644
40578--- a/drivers/gpu/drm/qxl/qxl_irq.c
40579+++ b/drivers/gpu/drm/qxl/qxl_irq.c
40580@@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40581
40582 pending = xchg(&qdev->ram_header->int_pending, 0);
40583
40584- atomic_inc(&qdev->irq_received);
40585+ atomic_inc_unchecked(&qdev->irq_received);
40586
40587 if (pending & QXL_INTERRUPT_DISPLAY) {
40588- atomic_inc(&qdev->irq_received_display);
40589+ atomic_inc_unchecked(&qdev->irq_received_display);
40590 wake_up_all(&qdev->display_event);
40591 qxl_queue_garbage_collect(qdev, false);
40592 }
40593 if (pending & QXL_INTERRUPT_CURSOR) {
40594- atomic_inc(&qdev->irq_received_cursor);
40595+ atomic_inc_unchecked(&qdev->irq_received_cursor);
40596 wake_up_all(&qdev->cursor_event);
40597 }
40598 if (pending & QXL_INTERRUPT_IO_CMD) {
40599- atomic_inc(&qdev->irq_received_io_cmd);
40600+ atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40601 wake_up_all(&qdev->io_cmd_event);
40602 }
40603 if (pending & QXL_INTERRUPT_ERROR) {
40604@@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40605 init_waitqueue_head(&qdev->io_cmd_event);
40606 INIT_WORK(&qdev->client_monitors_config_work,
40607 qxl_client_monitors_config_work_func);
40608- atomic_set(&qdev->irq_received, 0);
40609- atomic_set(&qdev->irq_received_display, 0);
40610- atomic_set(&qdev->irq_received_cursor, 0);
40611- atomic_set(&qdev->irq_received_io_cmd, 0);
40612+ atomic_set_unchecked(&qdev->irq_received, 0);
40613+ atomic_set_unchecked(&qdev->irq_received_display, 0);
40614+ atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40615+ atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40616 qdev->irq_received_error = 0;
40617 ret = drm_irq_install(qdev->ddev);
40618 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40619diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40620index c7e7e65..7dddd4d 100644
40621--- a/drivers/gpu/drm/qxl/qxl_ttm.c
40622+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40623@@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40624 }
40625 }
40626
40627-static struct vm_operations_struct qxl_ttm_vm_ops;
40628+static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40629 static const struct vm_operations_struct *ttm_vm_ops;
40630
40631 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40632@@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40633 return r;
40634 if (unlikely(ttm_vm_ops == NULL)) {
40635 ttm_vm_ops = vma->vm_ops;
40636+ pax_open_kernel();
40637 qxl_ttm_vm_ops = *ttm_vm_ops;
40638 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40639+ pax_close_kernel();
40640 }
40641 vma->vm_ops = &qxl_ttm_vm_ops;
40642 return 0;
40643@@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40644 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40645 {
40646 #if defined(CONFIG_DEBUG_FS)
40647- static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40648- static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40649- unsigned i;
40650+ static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40651+ {
40652+ .name = "qxl_mem_mm",
40653+ .show = &qxl_mm_dump_table,
40654+ },
40655+ {
40656+ .name = "qxl_surf_mm",
40657+ .show = &qxl_mm_dump_table,
40658+ }
40659+ };
40660
40661- for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40662- if (i == 0)
40663- sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40664- else
40665- sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40666- qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40667- qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40668- qxl_mem_types_list[i].driver_features = 0;
40669- if (i == 0)
40670- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40671- else
40672- qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40673+ pax_open_kernel();
40674+ *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40675+ *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40676+ pax_close_kernel();
40677
40678- }
40679- return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40680+ return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40681 #else
40682 return 0;
40683 #endif
40684diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40685index c451257..0ad2134 100644
40686--- a/drivers/gpu/drm/r128/r128_cce.c
40687+++ b/drivers/gpu/drm/r128/r128_cce.c
40688@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40689
40690 /* GH: Simple idle check.
40691 */
40692- atomic_set(&dev_priv->idle_count, 0);
40693+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40694
40695 /* We don't support anything other than bus-mastering ring mode,
40696 * but the ring can be in either AGP or PCI space for the ring
40697diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40698index 56eb5e3..c4ec43d 100644
40699--- a/drivers/gpu/drm/r128/r128_drv.h
40700+++ b/drivers/gpu/drm/r128/r128_drv.h
40701@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40702 int is_pci;
40703 unsigned long cce_buffers_offset;
40704
40705- atomic_t idle_count;
40706+ atomic_unchecked_t idle_count;
40707
40708 int page_flipping;
40709 int current_page;
40710 u32 crtc_offset;
40711 u32 crtc_offset_cntl;
40712
40713- atomic_t vbl_received;
40714+ atomic_unchecked_t vbl_received;
40715
40716 u32 color_fmt;
40717 unsigned int front_offset;
40718diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40719index a954c54..9cc595c 100644
40720--- a/drivers/gpu/drm/r128/r128_ioc32.c
40721+++ b/drivers/gpu/drm/r128/r128_ioc32.c
40722@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40723 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40724 }
40725
40726-drm_ioctl_compat_t *r128_compat_ioctls[] = {
40727+drm_ioctl_compat_t r128_compat_ioctls[] = {
40728 [DRM_R128_INIT] = compat_r128_init,
40729 [DRM_R128_DEPTH] = compat_r128_depth,
40730 [DRM_R128_STIPPLE] = compat_r128_stipple,
40731@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40732 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40733 {
40734 unsigned int nr = DRM_IOCTL_NR(cmd);
40735- drm_ioctl_compat_t *fn = NULL;
40736 int ret;
40737
40738 if (nr < DRM_COMMAND_BASE)
40739 return drm_compat_ioctl(filp, cmd, arg);
40740
40741- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40742- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40743-
40744- if (fn != NULL)
40745+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40746+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40747 ret = (*fn) (filp, cmd, arg);
40748- else
40749+ } else
40750 ret = drm_ioctl(filp, cmd, arg);
40751
40752 return ret;
40753diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40754index 2ea4f09..d391371 100644
40755--- a/drivers/gpu/drm/r128/r128_irq.c
40756+++ b/drivers/gpu/drm/r128/r128_irq.c
40757@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40758 if (crtc != 0)
40759 return 0;
40760
40761- return atomic_read(&dev_priv->vbl_received);
40762+ return atomic_read_unchecked(&dev_priv->vbl_received);
40763 }
40764
40765 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40766@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40767 /* VBLANK interrupt */
40768 if (status & R128_CRTC_VBLANK_INT) {
40769 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40770- atomic_inc(&dev_priv->vbl_received);
40771+ atomic_inc_unchecked(&dev_priv->vbl_received);
40772 drm_handle_vblank(dev, 0);
40773 return IRQ_HANDLED;
40774 }
40775diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40776index 01dd9ae..6352f04 100644
40777--- a/drivers/gpu/drm/r128/r128_state.c
40778+++ b/drivers/gpu/drm/r128/r128_state.c
40779@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40780
40781 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40782 {
40783- if (atomic_read(&dev_priv->idle_count) == 0)
40784+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40785 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40786 else
40787- atomic_set(&dev_priv->idle_count, 0);
40788+ atomic_set_unchecked(&dev_priv->idle_count, 0);
40789 }
40790
40791 #endif
40792diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40793index af85299..ed9ac8d 100644
40794--- a/drivers/gpu/drm/radeon/mkregtable.c
40795+++ b/drivers/gpu/drm/radeon/mkregtable.c
40796@@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40797 regex_t mask_rex;
40798 regmatch_t match[4];
40799 char buf[1024];
40800- size_t end;
40801+ long end;
40802 int len;
40803 int done = 0;
40804 int r;
40805 unsigned o;
40806 struct offset *offset;
40807 char last_reg_s[10];
40808- int last_reg;
40809+ unsigned long last_reg;
40810
40811 if (regcomp
40812 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40813diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40814index 39b033b..6efc056 100644
40815--- a/drivers/gpu/drm/radeon/radeon_device.c
40816+++ b/drivers/gpu/drm/radeon/radeon_device.c
40817@@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40818 bool can_switch;
40819
40820 spin_lock(&dev->count_lock);
40821- can_switch = (dev->open_count == 0);
40822+ can_switch = (local_read(&dev->open_count) == 0);
40823 spin_unlock(&dev->count_lock);
40824 return can_switch;
40825 }
40826diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40827index 00e0d44..08381a4 100644
40828--- a/drivers/gpu/drm/radeon/radeon_drv.h
40829+++ b/drivers/gpu/drm/radeon/radeon_drv.h
40830@@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40831
40832 /* SW interrupt */
40833 wait_queue_head_t swi_queue;
40834- atomic_t swi_emitted;
40835+ atomic_unchecked_t swi_emitted;
40836 int vblank_crtc;
40837 uint32_t irq_enable_reg;
40838 uint32_t r500_disp_irq_reg;
40839diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40840index bdb0f93..5ff558f 100644
40841--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40842+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40843@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40844 request = compat_alloc_user_space(sizeof(*request));
40845 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40846 || __put_user(req32.param, &request->param)
40847- || __put_user((void __user *)(unsigned long)req32.value,
40848+ || __put_user((unsigned long)req32.value,
40849 &request->value))
40850 return -EFAULT;
40851
40852@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40853 #define compat_radeon_cp_setparam NULL
40854 #endif /* X86_64 || IA64 */
40855
40856-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40857+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40858 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40859 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40860 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40861@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40862 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40863 {
40864 unsigned int nr = DRM_IOCTL_NR(cmd);
40865- drm_ioctl_compat_t *fn = NULL;
40866 int ret;
40867
40868 if (nr < DRM_COMMAND_BASE)
40869 return drm_compat_ioctl(filp, cmd, arg);
40870
40871- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40872- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40873-
40874- if (fn != NULL)
40875+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40876+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40877 ret = (*fn) (filp, cmd, arg);
40878- else
40879+ } else
40880 ret = drm_ioctl(filp, cmd, arg);
40881
40882 return ret;
40883diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40884index 8d68e97..9dcfed8 100644
40885--- a/drivers/gpu/drm/radeon/radeon_irq.c
40886+++ b/drivers/gpu/drm/radeon/radeon_irq.c
40887@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40888 unsigned int ret;
40889 RING_LOCALS;
40890
40891- atomic_inc(&dev_priv->swi_emitted);
40892- ret = atomic_read(&dev_priv->swi_emitted);
40893+ atomic_inc_unchecked(&dev_priv->swi_emitted);
40894+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40895
40896 BEGIN_RING(4);
40897 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40898@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40899 drm_radeon_private_t *dev_priv =
40900 (drm_radeon_private_t *) dev->dev_private;
40901
40902- atomic_set(&dev_priv->swi_emitted, 0);
40903+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40904 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40905
40906 dev->max_vblank_count = 0x001fffff;
40907diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40908index 4d20910..6726b6d 100644
40909--- a/drivers/gpu/drm/radeon/radeon_state.c
40910+++ b/drivers/gpu/drm/radeon/radeon_state.c
40911@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40912 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40913 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40914
40915- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40916+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40917 sarea_priv->nbox * sizeof(depth_boxes[0])))
40918 return -EFAULT;
40919
40920@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40921 {
40922 drm_radeon_private_t *dev_priv = dev->dev_private;
40923 drm_radeon_getparam_t *param = data;
40924- int value;
40925+ int value = 0;
40926
40927 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40928
40929diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40930index 84323c9..cf07baf 100644
40931--- a/drivers/gpu/drm/radeon/radeon_ttm.c
40932+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40933@@ -787,7 +787,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40934 man->size = size >> PAGE_SHIFT;
40935 }
40936
40937-static struct vm_operations_struct radeon_ttm_vm_ops;
40938+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40939 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40940
40941 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40942@@ -828,8 +828,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40943 }
40944 if (unlikely(ttm_vm_ops == NULL)) {
40945 ttm_vm_ops = vma->vm_ops;
40946+ pax_open_kernel();
40947 radeon_ttm_vm_ops = *ttm_vm_ops;
40948 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40949+ pax_close_kernel();
40950 }
40951 vma->vm_ops = &radeon_ttm_vm_ops;
40952 return 0;
40953@@ -858,38 +860,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40954 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40955 {
40956 #if defined(CONFIG_DEBUG_FS)
40957- static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40958- static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40959- unsigned i;
40960+ static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40961+ {
40962+ .name = "radeon_vram_mm",
40963+ .show = &radeon_mm_dump_table,
40964+ },
40965+ {
40966+ .name = "radeon_gtt_mm",
40967+ .show = &radeon_mm_dump_table,
40968+ },
40969+ {
40970+ .name = "ttm_page_pool",
40971+ .show = &ttm_page_alloc_debugfs,
40972+ },
40973+ {
40974+ .name = "ttm_dma_page_pool",
40975+ .show = &ttm_dma_page_alloc_debugfs,
40976+ },
40977+ };
40978+ unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40979
40980- for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40981- if (i == 0)
40982- sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40983- else
40984- sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40985- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40986- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40987- radeon_mem_types_list[i].driver_features = 0;
40988- if (i == 0)
40989- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40990- else
40991- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40992-
40993- }
40994- /* Add ttm page pool to debugfs */
40995- sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40996- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40997- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40998- radeon_mem_types_list[i].driver_features = 0;
40999- radeon_mem_types_list[i++].data = NULL;
41000+ pax_open_kernel();
41001+ *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
41002+ *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
41003+ pax_close_kernel();
41004 #ifdef CONFIG_SWIOTLB
41005- if (swiotlb_nr_tbl()) {
41006- sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
41007- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
41008- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
41009- radeon_mem_types_list[i].driver_features = 0;
41010- radeon_mem_types_list[i++].data = NULL;
41011- }
41012+ if (swiotlb_nr_tbl())
41013+ i++;
41014 #endif
41015 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
41016
41017diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41018index ae1cb31..5b5b6b7c 100644
41019--- a/drivers/gpu/drm/tegra/dc.c
41020+++ b/drivers/gpu/drm/tegra/dc.c
41021@@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41022 }
41023
41024 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41025- dc->debugfs_files[i].data = dc;
41026+ *(void **)&dc->debugfs_files[i].data = dc;
41027
41028 err = drm_debugfs_create_files(dc->debugfs_files,
41029 ARRAY_SIZE(debugfs_files),
41030diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41031index 0cd9bc2..9759be4 100644
41032--- a/drivers/gpu/drm/tegra/hdmi.c
41033+++ b/drivers/gpu/drm/tegra/hdmi.c
41034@@ -57,7 +57,7 @@ struct tegra_hdmi {
41035 bool stereo;
41036 bool dvi;
41037
41038- struct drm_info_list *debugfs_files;
41039+ drm_info_list_no_const *debugfs_files;
41040 struct drm_minor *minor;
41041 struct dentry *debugfs;
41042 };
41043diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41044index c58eba33..83c2728 100644
41045--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41046+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41047@@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41048 }
41049
41050 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41051- ttm_bo_man_init,
41052- ttm_bo_man_takedown,
41053- ttm_bo_man_get_node,
41054- ttm_bo_man_put_node,
41055- ttm_bo_man_debug
41056+ .init = ttm_bo_man_init,
41057+ .takedown = ttm_bo_man_takedown,
41058+ .get_node = ttm_bo_man_get_node,
41059+ .put_node = ttm_bo_man_put_node,
41060+ .debug = ttm_bo_man_debug
41061 };
41062 EXPORT_SYMBOL(ttm_bo_manager_func);
41063diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41064index dbc2def..0a9f710 100644
41065--- a/drivers/gpu/drm/ttm/ttm_memory.c
41066+++ b/drivers/gpu/drm/ttm/ttm_memory.c
41067@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41068 zone->glob = glob;
41069 glob->zone_kernel = zone;
41070 ret = kobject_init_and_add(
41071- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41072+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41073 if (unlikely(ret != 0)) {
41074 kobject_put(&zone->kobj);
41075 return ret;
41076@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41077 zone->glob = glob;
41078 glob->zone_dma32 = zone;
41079 ret = kobject_init_and_add(
41080- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41081+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41082 if (unlikely(ret != 0)) {
41083 kobject_put(&zone->kobj);
41084 return ret;
41085diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41086index 863bef9..cba15cf 100644
41087--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41088+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41089@@ -391,9 +391,9 @@ out:
41090 static unsigned long
41091 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41092 {
41093- static atomic_t start_pool = ATOMIC_INIT(0);
41094+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41095 unsigned i;
41096- unsigned pool_offset = atomic_add_return(1, &start_pool);
41097+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41098 struct ttm_page_pool *pool;
41099 int shrink_pages = sc->nr_to_scan;
41100 unsigned long freed = 0;
41101diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41102index 97e9d61..bf23c461 100644
41103--- a/drivers/gpu/drm/udl/udl_fb.c
41104+++ b/drivers/gpu/drm/udl/udl_fb.c
41105@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41106 fb_deferred_io_cleanup(info);
41107 kfree(info->fbdefio);
41108 info->fbdefio = NULL;
41109- info->fbops->fb_mmap = udl_fb_mmap;
41110 }
41111
41112 pr_warn("released /dev/fb%d user=%d count=%d\n",
41113diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41114index a811ef2..ff99b05 100644
41115--- a/drivers/gpu/drm/via/via_drv.h
41116+++ b/drivers/gpu/drm/via/via_drv.h
41117@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41118 typedef uint32_t maskarray_t[5];
41119
41120 typedef struct drm_via_irq {
41121- atomic_t irq_received;
41122+ atomic_unchecked_t irq_received;
41123 uint32_t pending_mask;
41124 uint32_t enable_mask;
41125 wait_queue_head_t irq_queue;
41126@@ -75,7 +75,7 @@ typedef struct drm_via_private {
41127 struct timeval last_vblank;
41128 int last_vblank_valid;
41129 unsigned usec_per_vblank;
41130- atomic_t vbl_received;
41131+ atomic_unchecked_t vbl_received;
41132 drm_via_state_t hc_state;
41133 char pci_buf[VIA_PCI_BUF_SIZE];
41134 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41135diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41136index ac98964..5dbf512 100644
41137--- a/drivers/gpu/drm/via/via_irq.c
41138+++ b/drivers/gpu/drm/via/via_irq.c
41139@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41140 if (crtc != 0)
41141 return 0;
41142
41143- return atomic_read(&dev_priv->vbl_received);
41144+ return atomic_read_unchecked(&dev_priv->vbl_received);
41145 }
41146
41147 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41148@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41149
41150 status = VIA_READ(VIA_REG_INTERRUPT);
41151 if (status & VIA_IRQ_VBLANK_PENDING) {
41152- atomic_inc(&dev_priv->vbl_received);
41153- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41154+ atomic_inc_unchecked(&dev_priv->vbl_received);
41155+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41156 do_gettimeofday(&cur_vblank);
41157 if (dev_priv->last_vblank_valid) {
41158 dev_priv->usec_per_vblank =
41159@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41160 dev_priv->last_vblank = cur_vblank;
41161 dev_priv->last_vblank_valid = 1;
41162 }
41163- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41164+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41165 DRM_DEBUG("US per vblank is: %u\n",
41166 dev_priv->usec_per_vblank);
41167 }
41168@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
41169
41170 for (i = 0; i < dev_priv->num_irqs; ++i) {
41171 if (status & cur_irq->pending_mask) {
41172- atomic_inc(&cur_irq->irq_received);
41173+ atomic_inc_unchecked(&cur_irq->irq_received);
41174 DRM_WAKEUP(&cur_irq->irq_queue);
41175 handled = 1;
41176 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41177@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41178 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41179 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41180 masks[irq][4]));
41181- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41182+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41183 } else {
41184 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
41185 (((cur_irq_sequence =
41186- atomic_read(&cur_irq->irq_received)) -
41187+ atomic_read_unchecked(&cur_irq->irq_received)) -
41188 *sequence) <= (1 << 23)));
41189 }
41190 *sequence = cur_irq_sequence;
41191@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41192 }
41193
41194 for (i = 0; i < dev_priv->num_irqs; ++i) {
41195- atomic_set(&cur_irq->irq_received, 0);
41196+ atomic_set_unchecked(&cur_irq->irq_received, 0);
41197 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41198 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41199 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
41200@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41201 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41202 case VIA_IRQ_RELATIVE:
41203 irqwait->request.sequence +=
41204- atomic_read(&cur_irq->irq_received);
41205+ atomic_read_unchecked(&cur_irq->irq_received);
41206 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41207 case VIA_IRQ_ABSOLUTE:
41208 break;
41209diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41210index c0b73b9..f6f7f34 100644
41211--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41212+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41213@@ -341,7 +341,7 @@ struct vmw_private {
41214 * Fencing and IRQs.
41215 */
41216
41217- atomic_t marker_seq;
41218+ atomic_unchecked_t marker_seq;
41219 wait_queue_head_t fence_queue;
41220 wait_queue_head_t fifo_queue;
41221 int fence_queue_waiters; /* Protected by hw_mutex */
41222diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41223index 3eb1486..0a47ee9 100644
41224--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41225+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41226@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41227 (unsigned int) min,
41228 (unsigned int) fifo->capabilities);
41229
41230- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41231+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41232 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41233 vmw_marker_queue_init(&fifo->marker_queue);
41234 return vmw_fifo_send_fence(dev_priv, &dummy);
41235@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41236 if (reserveable)
41237 iowrite32(bytes, fifo_mem +
41238 SVGA_FIFO_RESERVED);
41239- return fifo_mem + (next_cmd >> 2);
41240+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41241 } else {
41242 need_bounce = true;
41243 }
41244@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41245
41246 fm = vmw_fifo_reserve(dev_priv, bytes);
41247 if (unlikely(fm == NULL)) {
41248- *seqno = atomic_read(&dev_priv->marker_seq);
41249+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41250 ret = -ENOMEM;
41251 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41252 false, 3*HZ);
41253@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41254 }
41255
41256 do {
41257- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41258+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41259 } while (*seqno == 0);
41260
41261 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41262diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41263index c5c054a..46f0548 100644
41264--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41265+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41266@@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41267 }
41268
41269 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41270- vmw_gmrid_man_init,
41271- vmw_gmrid_man_takedown,
41272- vmw_gmrid_man_get_node,
41273- vmw_gmrid_man_put_node,
41274- vmw_gmrid_man_debug
41275+ .init = vmw_gmrid_man_init,
41276+ .takedown = vmw_gmrid_man_takedown,
41277+ .get_node = vmw_gmrid_man_get_node,
41278+ .put_node = vmw_gmrid_man_put_node,
41279+ .debug = vmw_gmrid_man_debug
41280 };
41281diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41282index 45d5b5a..f3f5e4e 100644
41283--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41284+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41285@@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41286 int ret;
41287
41288 num_clips = arg->num_clips;
41289- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41290+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41291
41292 if (unlikely(num_clips == 0))
41293 return 0;
41294@@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41295 int ret;
41296
41297 num_clips = arg->num_clips;
41298- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41299+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41300
41301 if (unlikely(num_clips == 0))
41302 return 0;
41303diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41304index 4640adb..e1384ed 100644
41305--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41306+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41307@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41308 * emitted. Then the fence is stale and signaled.
41309 */
41310
41311- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41312+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41313 > VMW_FENCE_WRAP);
41314
41315 return ret;
41316@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41317
41318 if (fifo_idle)
41319 down_read(&fifo_state->rwsem);
41320- signal_seq = atomic_read(&dev_priv->marker_seq);
41321+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41322 ret = 0;
41323
41324 for (;;) {
41325diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41326index 8a8725c2..afed796 100644
41327--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41328+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41329@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41330 while (!vmw_lag_lt(queue, us)) {
41331 spin_lock(&queue->lock);
41332 if (list_empty(&queue->head))
41333- seqno = atomic_read(&dev_priv->marker_seq);
41334+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41335 else {
41336 marker = list_first_entry(&queue->head,
41337 struct vmw_marker, head);
41338diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41339index ec0ae2d..dc0780b 100644
41340--- a/drivers/gpu/vga/vga_switcheroo.c
41341+++ b/drivers/gpu/vga/vga_switcheroo.c
41342@@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41343
41344 /* this version is for the case where the power switch is separate
41345 to the device being powered down. */
41346-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41347+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41348 {
41349 /* copy over all the bus versions */
41350 if (dev->bus && dev->bus->pm) {
41351@@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41352 return ret;
41353 }
41354
41355-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41356+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41357 {
41358 /* copy over all the bus versions */
41359 if (dev->bus && dev->bus->pm) {
41360diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41361index 253fe23..0dfec5f 100644
41362--- a/drivers/hid/hid-core.c
41363+++ b/drivers/hid/hid-core.c
41364@@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41365
41366 int hid_add_device(struct hid_device *hdev)
41367 {
41368- static atomic_t id = ATOMIC_INIT(0);
41369+ static atomic_unchecked_t id = ATOMIC_INIT(0);
41370 int ret;
41371
41372 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41373@@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
41374 /* XXX hack, any other cleaner solution after the driver core
41375 * is converted to allow more than 20 bytes as the device name? */
41376 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41377- hdev->vendor, hdev->product, atomic_inc_return(&id));
41378+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41379
41380 hid_debug_register(hdev, dev_name(&hdev->dev));
41381 ret = device_add(&hdev->dev);
41382diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41383index c13fb5b..55a3802 100644
41384--- a/drivers/hid/hid-wiimote-debug.c
41385+++ b/drivers/hid/hid-wiimote-debug.c
41386@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41387 else if (size == 0)
41388 return -EIO;
41389
41390- if (copy_to_user(u, buf, size))
41391+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
41392 return -EFAULT;
41393
41394 *off += size;
41395diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41396index cedc6da..2c3da2a 100644
41397--- a/drivers/hid/uhid.c
41398+++ b/drivers/hid/uhid.c
41399@@ -47,7 +47,7 @@ struct uhid_device {
41400 struct mutex report_lock;
41401 wait_queue_head_t report_wait;
41402 atomic_t report_done;
41403- atomic_t report_id;
41404+ atomic_unchecked_t report_id;
41405 struct uhid_event report_buf;
41406 };
41407
41408@@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41409
41410 spin_lock_irqsave(&uhid->qlock, flags);
41411 ev->type = UHID_FEATURE;
41412- ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41413+ ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41414 ev->u.feature.rnum = rnum;
41415 ev->u.feature.rtype = report_type;
41416
41417@@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41418 spin_lock_irqsave(&uhid->qlock, flags);
41419
41420 /* id for old report; drop it silently */
41421- if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41422+ if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41423 goto unlock;
41424 if (atomic_read(&uhid->report_done))
41425 goto unlock;
41426diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41427index cea623c..73011b0 100644
41428--- a/drivers/hv/channel.c
41429+++ b/drivers/hv/channel.c
41430@@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41431 int ret = 0;
41432 int t;
41433
41434- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41435- atomic_inc(&vmbus_connection.next_gpadl_handle);
41436+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41437+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41438
41439 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41440 if (ret)
41441diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41442index f0c5e07..49a4d4a 100644
41443--- a/drivers/hv/hv.c
41444+++ b/drivers/hv/hv.c
41445@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41446 u64 output_address = (output) ? virt_to_phys(output) : 0;
41447 u32 output_address_hi = output_address >> 32;
41448 u32 output_address_lo = output_address & 0xFFFFFFFF;
41449- void *hypercall_page = hv_context.hypercall_page;
41450+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41451
41452 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41453 "=a"(hv_status_lo) : "d" (control_hi),
41454@@ -154,7 +154,7 @@ int hv_init(void)
41455 /* See if the hypercall page is already set */
41456 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41457
41458- virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41459+ virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41460
41461 if (!virtaddr)
41462 goto cleanup;
41463diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41464index 7e17a54..a50a33d 100644
41465--- a/drivers/hv/hv_balloon.c
41466+++ b/drivers/hv/hv_balloon.c
41467@@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41468
41469 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41470 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41471-static atomic_t trans_id = ATOMIC_INIT(0);
41472+static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41473
41474 static int dm_ring_size = (5 * PAGE_SIZE);
41475
41476@@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
41477 pr_info("Memory hot add failed\n");
41478
41479 dm->state = DM_INITIALIZED;
41480- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41481+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41482 vmbus_sendpacket(dm->dev->channel, &resp,
41483 sizeof(struct dm_hot_add_response),
41484 (unsigned long)NULL,
41485@@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
41486 memset(&status, 0, sizeof(struct dm_status));
41487 status.hdr.type = DM_STATUS_REPORT;
41488 status.hdr.size = sizeof(struct dm_status);
41489- status.hdr.trans_id = atomic_inc_return(&trans_id);
41490+ status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41491
41492 /*
41493 * The host expects the guest to report free memory.
41494@@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
41495 * send the status. This can happen if we were interrupted
41496 * after we picked our transaction ID.
41497 */
41498- if (status.hdr.trans_id != atomic_read(&trans_id))
41499+ if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41500 return;
41501
41502 vmbus_sendpacket(dm->dev->channel, &status,
41503@@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
41504 */
41505
41506 do {
41507- bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41508+ bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41509 ret = vmbus_sendpacket(dm_device.dev->channel,
41510 bl_resp,
41511 bl_resp->hdr.size,
41512@@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41513
41514 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41515 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41516- resp.hdr.trans_id = atomic_inc_return(&trans_id);
41517+ resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41518 resp.hdr.size = sizeof(struct dm_unballoon_response);
41519
41520 vmbus_sendpacket(dm_device.dev->channel, &resp,
41521@@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41522 memset(&version_req, 0, sizeof(struct dm_version_request));
41523 version_req.hdr.type = DM_VERSION_REQUEST;
41524 version_req.hdr.size = sizeof(struct dm_version_request);
41525- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41526+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41527 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41528 version_req.is_last_attempt = 1;
41529
41530@@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
41531 memset(&version_req, 0, sizeof(struct dm_version_request));
41532 version_req.hdr.type = DM_VERSION_REQUEST;
41533 version_req.hdr.size = sizeof(struct dm_version_request);
41534- version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41535+ version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41536 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41537 version_req.is_last_attempt = 0;
41538
41539@@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
41540 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41541 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41542 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41543- cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41544+ cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41545
41546 cap_msg.caps.cap_bits.balloon = 1;
41547 cap_msg.caps.cap_bits.hot_add = 1;
41548diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41549index e055176..c22ff1f 100644
41550--- a/drivers/hv/hyperv_vmbus.h
41551+++ b/drivers/hv/hyperv_vmbus.h
41552@@ -602,7 +602,7 @@ enum vmbus_connect_state {
41553 struct vmbus_connection {
41554 enum vmbus_connect_state conn_state;
41555
41556- atomic_t next_gpadl_handle;
41557+ atomic_unchecked_t next_gpadl_handle;
41558
41559 /*
41560 * Represents channel interrupts. Each bit position represents a
41561diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41562index 48aad4f..c768fb2 100644
41563--- a/drivers/hv/vmbus_drv.c
41564+++ b/drivers/hv/vmbus_drv.c
41565@@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41566 {
41567 int ret = 0;
41568
41569- static atomic_t device_num = ATOMIC_INIT(0);
41570+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41571
41572 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41573- atomic_inc_return(&device_num));
41574+ atomic_inc_return_unchecked(&device_num));
41575
41576 child_device_obj->device.bus = &hv_bus;
41577 child_device_obj->device.parent = &hv_acpi_dev->dev;
41578diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41579index 6a34f7f..aa4c3a6 100644
41580--- a/drivers/hwmon/acpi_power_meter.c
41581+++ b/drivers/hwmon/acpi_power_meter.c
41582@@ -117,7 +117,7 @@ struct sensor_template {
41583 struct device_attribute *devattr,
41584 const char *buf, size_t count);
41585 int index;
41586-};
41587+} __do_const;
41588
41589 /* Averaging interval */
41590 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41591@@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41592 struct sensor_template *attrs)
41593 {
41594 struct device *dev = &resource->acpi_dev->dev;
41595- struct sensor_device_attribute *sensors =
41596+ sensor_device_attribute_no_const *sensors =
41597 &resource->sensors[resource->num_sensors];
41598 int res = 0;
41599
41600diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41601index 3288f13..71cfb4e 100644
41602--- a/drivers/hwmon/applesmc.c
41603+++ b/drivers/hwmon/applesmc.c
41604@@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41605 {
41606 struct applesmc_node_group *grp;
41607 struct applesmc_dev_attr *node;
41608- struct attribute *attr;
41609+ attribute_no_const *attr;
41610 int ret, i;
41611
41612 for (grp = groups; grp->format; grp++) {
41613diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41614index dafc63c..4abb96c 100644
41615--- a/drivers/hwmon/asus_atk0110.c
41616+++ b/drivers/hwmon/asus_atk0110.c
41617@@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41618 struct atk_sensor_data {
41619 struct list_head list;
41620 struct atk_data *data;
41621- struct device_attribute label_attr;
41622- struct device_attribute input_attr;
41623- struct device_attribute limit1_attr;
41624- struct device_attribute limit2_attr;
41625+ device_attribute_no_const label_attr;
41626+ device_attribute_no_const input_attr;
41627+ device_attribute_no_const limit1_attr;
41628+ device_attribute_no_const limit2_attr;
41629 char label_attr_name[ATTR_NAME_SIZE];
41630 char input_attr_name[ATTR_NAME_SIZE];
41631 char limit1_attr_name[ATTR_NAME_SIZE];
41632@@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41633 static struct device_attribute atk_name_attr =
41634 __ATTR(name, 0444, atk_name_show, NULL);
41635
41636-static void atk_init_attribute(struct device_attribute *attr, char *name,
41637+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41638 sysfs_show_func show)
41639 {
41640 sysfs_attr_init(&attr->attr);
41641diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41642index 9425098..7646cc5 100644
41643--- a/drivers/hwmon/coretemp.c
41644+++ b/drivers/hwmon/coretemp.c
41645@@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41646 return NOTIFY_OK;
41647 }
41648
41649-static struct notifier_block coretemp_cpu_notifier __refdata = {
41650+static struct notifier_block coretemp_cpu_notifier = {
41651 .notifier_call = coretemp_cpu_callback,
41652 };
41653
41654diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41655index 632f1dc..57e6a58 100644
41656--- a/drivers/hwmon/ibmaem.c
41657+++ b/drivers/hwmon/ibmaem.c
41658@@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41659 struct aem_rw_sensor_template *rw)
41660 {
41661 struct device *dev = &data->pdev->dev;
41662- struct sensor_device_attribute *sensors = data->sensors;
41663+ sensor_device_attribute_no_const *sensors = data->sensors;
41664 int err;
41665
41666 /* Set up read-only sensors */
41667diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41668index 708081b..fe2d4ab 100644
41669--- a/drivers/hwmon/iio_hwmon.c
41670+++ b/drivers/hwmon/iio_hwmon.c
41671@@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41672 {
41673 struct device *dev = &pdev->dev;
41674 struct iio_hwmon_state *st;
41675- struct sensor_device_attribute *a;
41676+ sensor_device_attribute_no_const *a;
41677 int ret, i;
41678 int in_i = 1, temp_i = 1, curr_i = 1;
41679 enum iio_chan_type type;
41680diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41681index cf811c1..4c17110 100644
41682--- a/drivers/hwmon/nct6775.c
41683+++ b/drivers/hwmon/nct6775.c
41684@@ -944,10 +944,10 @@ static struct attribute_group *
41685 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41686 int repeat)
41687 {
41688- struct attribute_group *group;
41689+ attribute_group_no_const *group;
41690 struct sensor_device_attr_u *su;
41691- struct sensor_device_attribute *a;
41692- struct sensor_device_attribute_2 *a2;
41693+ sensor_device_attribute_no_const *a;
41694+ sensor_device_attribute_2_no_const *a2;
41695 struct attribute **attrs;
41696 struct sensor_device_template **t;
41697 int i, count;
41698diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41699index 3cbf66e..8c5cc2a 100644
41700--- a/drivers/hwmon/pmbus/pmbus_core.c
41701+++ b/drivers/hwmon/pmbus/pmbus_core.c
41702@@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41703 return 0;
41704 }
41705
41706-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41707+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41708 const char *name,
41709 umode_t mode,
41710 ssize_t (*show)(struct device *dev,
41711@@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41712 dev_attr->store = store;
41713 }
41714
41715-static void pmbus_attr_init(struct sensor_device_attribute *a,
41716+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41717 const char *name,
41718 umode_t mode,
41719 ssize_t (*show)(struct device *dev,
41720@@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41721 u16 reg, u8 mask)
41722 {
41723 struct pmbus_boolean *boolean;
41724- struct sensor_device_attribute *a;
41725+ sensor_device_attribute_no_const *a;
41726
41727 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41728 if (!boolean)
41729@@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41730 bool update, bool readonly)
41731 {
41732 struct pmbus_sensor *sensor;
41733- struct device_attribute *a;
41734+ device_attribute_no_const *a;
41735
41736 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41737 if (!sensor)
41738@@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41739 const char *lstring, int index)
41740 {
41741 struct pmbus_label *label;
41742- struct device_attribute *a;
41743+ device_attribute_no_const *a;
41744
41745 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41746 if (!label)
41747diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41748index 97cd45a..ac54d8b 100644
41749--- a/drivers/hwmon/sht15.c
41750+++ b/drivers/hwmon/sht15.c
41751@@ -169,7 +169,7 @@ struct sht15_data {
41752 int supply_uv;
41753 bool supply_uv_valid;
41754 struct work_struct update_supply_work;
41755- atomic_t interrupt_handled;
41756+ atomic_unchecked_t interrupt_handled;
41757 };
41758
41759 /**
41760@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41761 ret = gpio_direction_input(data->pdata->gpio_data);
41762 if (ret)
41763 return ret;
41764- atomic_set(&data->interrupt_handled, 0);
41765+ atomic_set_unchecked(&data->interrupt_handled, 0);
41766
41767 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41768 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41769 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41770 /* Only relevant if the interrupt hasn't occurred. */
41771- if (!atomic_read(&data->interrupt_handled))
41772+ if (!atomic_read_unchecked(&data->interrupt_handled))
41773 schedule_work(&data->read_work);
41774 }
41775 ret = wait_event_timeout(data->wait_queue,
41776@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41777
41778 /* First disable the interrupt */
41779 disable_irq_nosync(irq);
41780- atomic_inc(&data->interrupt_handled);
41781+ atomic_inc_unchecked(&data->interrupt_handled);
41782 /* Then schedule a reading work struct */
41783 if (data->state != SHT15_READING_NOTHING)
41784 schedule_work(&data->read_work);
41785@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41786 * If not, then start the interrupt again - care here as could
41787 * have gone low in meantime so verify it hasn't!
41788 */
41789- atomic_set(&data->interrupt_handled, 0);
41790+ atomic_set_unchecked(&data->interrupt_handled, 0);
41791 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41792 /* If still not occurred or another handler was scheduled */
41793 if (gpio_get_value(data->pdata->gpio_data)
41794- || atomic_read(&data->interrupt_handled))
41795+ || atomic_read_unchecked(&data->interrupt_handled))
41796 return;
41797 }
41798
41799diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41800index 38944e9..ae9e5ed 100644
41801--- a/drivers/hwmon/via-cputemp.c
41802+++ b/drivers/hwmon/via-cputemp.c
41803@@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41804 return NOTIFY_OK;
41805 }
41806
41807-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41808+static struct notifier_block via_cputemp_cpu_notifier = {
41809 .notifier_call = via_cputemp_cpu_callback,
41810 };
41811
41812diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41813index 07f01ac..d79ad3d 100644
41814--- a/drivers/i2c/busses/i2c-amd756-s4882.c
41815+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41816@@ -43,7 +43,7 @@
41817 extern struct i2c_adapter amd756_smbus;
41818
41819 static struct i2c_adapter *s4882_adapter;
41820-static struct i2c_algorithm *s4882_algo;
41821+static i2c_algorithm_no_const *s4882_algo;
41822
41823 /* Wrapper access functions for multiplexed SMBus */
41824 static DEFINE_MUTEX(amd756_lock);
41825diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41826index 721f7eb..0fd2a09 100644
41827--- a/drivers/i2c/busses/i2c-diolan-u2c.c
41828+++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41829@@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41830 /* usb layer */
41831
41832 /* Send command to device, and get response. */
41833-static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41834+static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41835 {
41836 int ret = 0;
41837 int actual;
41838diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41839index 2ca268d..c6acbdf 100644
41840--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41841+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41842@@ -41,7 +41,7 @@
41843 extern struct i2c_adapter *nforce2_smbus;
41844
41845 static struct i2c_adapter *s4985_adapter;
41846-static struct i2c_algorithm *s4985_algo;
41847+static i2c_algorithm_no_const *s4985_algo;
41848
41849 /* Wrapper access functions for multiplexed SMBus */
41850 static DEFINE_MUTEX(nforce2_lock);
41851diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41852index 80b47e8..1a6040d9 100644
41853--- a/drivers/i2c/i2c-dev.c
41854+++ b/drivers/i2c/i2c-dev.c
41855@@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41856 break;
41857 }
41858
41859- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41860+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41861 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41862 if (IS_ERR(rdwr_pa[i].buf)) {
41863 res = PTR_ERR(rdwr_pa[i].buf);
41864diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41865index 0b510ba..4fbb5085 100644
41866--- a/drivers/ide/ide-cd.c
41867+++ b/drivers/ide/ide-cd.c
41868@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41869 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41870 if ((unsigned long)buf & alignment
41871 || blk_rq_bytes(rq) & q->dma_pad_mask
41872- || object_is_on_stack(buf))
41873+ || object_starts_on_stack(buf))
41874 drive->dma = 0;
41875 }
41876 }
41877diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41878index 18f72e3..3722327 100644
41879--- a/drivers/iio/industrialio-core.c
41880+++ b/drivers/iio/industrialio-core.c
41881@@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41882 }
41883
41884 static
41885-int __iio_device_attr_init(struct device_attribute *dev_attr,
41886+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41887 const char *postfix,
41888 struct iio_chan_spec const *chan,
41889 ssize_t (*readfunc)(struct device *dev,
41890diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41891index f2ef7ef..743d02f 100644
41892--- a/drivers/infiniband/core/cm.c
41893+++ b/drivers/infiniband/core/cm.c
41894@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41895
41896 struct cm_counter_group {
41897 struct kobject obj;
41898- atomic_long_t counter[CM_ATTR_COUNT];
41899+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41900 };
41901
41902 struct cm_counter_attribute {
41903@@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41904 struct ib_mad_send_buf *msg = NULL;
41905 int ret;
41906
41907- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41908+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41909 counter[CM_REQ_COUNTER]);
41910
41911 /* Quick state check to discard duplicate REQs. */
41912@@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41913 if (!cm_id_priv)
41914 return;
41915
41916- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41917+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41918 counter[CM_REP_COUNTER]);
41919 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41920 if (ret)
41921@@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41922 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41923 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41924 spin_unlock_irq(&cm_id_priv->lock);
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_RTU_COUNTER]);
41928 goto out;
41929 }
41930@@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41931 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41932 dreq_msg->local_comm_id);
41933 if (!cm_id_priv) {
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_DREQ_COUNTER]);
41937 cm_issue_drep(work->port, work->mad_recv_wc);
41938 return -EINVAL;
41939@@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41940 case IB_CM_MRA_REP_RCVD:
41941 break;
41942 case IB_CM_TIMEWAIT:
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_DREQ_COUNTER]);
41946 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41947 goto unlock;
41948@@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41949 cm_free_msg(msg);
41950 goto deref;
41951 case IB_CM_DREQ_RCVD:
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 goto unlock;
41956 default:
41957@@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41958 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41959 cm_id_priv->msg, timeout)) {
41960 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41961- atomic_long_inc(&work->port->
41962+ atomic_long_inc_unchecked(&work->port->
41963 counter_group[CM_RECV_DUPLICATES].
41964 counter[CM_MRA_COUNTER]);
41965 goto out;
41966@@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41967 break;
41968 case IB_CM_MRA_REQ_RCVD:
41969 case IB_CM_MRA_REP_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_MRA_COUNTER]);
41973 /* fall through */
41974 default:
41975@@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41976 case IB_CM_LAP_IDLE:
41977 break;
41978 case IB_CM_MRA_LAP_SENT:
41979- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41980+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41981 counter[CM_LAP_COUNTER]);
41982 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41983 goto unlock;
41984@@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41985 cm_free_msg(msg);
41986 goto deref;
41987 case IB_CM_LAP_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_LAP_COUNTER]);
41991 goto unlock;
41992 default:
41993@@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41994 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41995 if (cur_cm_id_priv) {
41996 spin_unlock_irq(&cm.lock);
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_SIDR_REQ_COUNTER]);
42000 goto out; /* Duplicate message. */
42001 }
42002@@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42003 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42004 msg->retries = 1;
42005
42006- atomic_long_add(1 + msg->retries,
42007+ atomic_long_add_unchecked(1 + msg->retries,
42008 &port->counter_group[CM_XMIT].counter[attr_index]);
42009 if (msg->retries)
42010- atomic_long_add(msg->retries,
42011+ atomic_long_add_unchecked(msg->retries,
42012 &port->counter_group[CM_XMIT_RETRIES].
42013 counter[attr_index]);
42014
42015@@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42016 }
42017
42018 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42019- atomic_long_inc(&port->counter_group[CM_RECV].
42020+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42021 counter[attr_id - CM_ATTR_ID_OFFSET]);
42022
42023 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42024@@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42025 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42026
42027 return sprintf(buf, "%ld\n",
42028- atomic_long_read(&group->counter[cm_attr->index]));
42029+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42030 }
42031
42032 static const struct sysfs_ops cm_counter_ops = {
42033diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42034index 9f5ad7c..588cd84 100644
42035--- a/drivers/infiniband/core/fmr_pool.c
42036+++ b/drivers/infiniband/core/fmr_pool.c
42037@@ -98,8 +98,8 @@ struct ib_fmr_pool {
42038
42039 struct task_struct *thread;
42040
42041- atomic_t req_ser;
42042- atomic_t flush_ser;
42043+ atomic_unchecked_t req_ser;
42044+ atomic_unchecked_t flush_ser;
42045
42046 wait_queue_head_t force_wait;
42047 };
42048@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42049 struct ib_fmr_pool *pool = pool_ptr;
42050
42051 do {
42052- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42053+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42054 ib_fmr_batch_release(pool);
42055
42056- atomic_inc(&pool->flush_ser);
42057+ atomic_inc_unchecked(&pool->flush_ser);
42058 wake_up_interruptible(&pool->force_wait);
42059
42060 if (pool->flush_function)
42061@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42062 }
42063
42064 set_current_state(TASK_INTERRUPTIBLE);
42065- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42066+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42067 !kthread_should_stop())
42068 schedule();
42069 __set_current_state(TASK_RUNNING);
42070@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42071 pool->dirty_watermark = params->dirty_watermark;
42072 pool->dirty_len = 0;
42073 spin_lock_init(&pool->pool_lock);
42074- atomic_set(&pool->req_ser, 0);
42075- atomic_set(&pool->flush_ser, 0);
42076+ atomic_set_unchecked(&pool->req_ser, 0);
42077+ atomic_set_unchecked(&pool->flush_ser, 0);
42078 init_waitqueue_head(&pool->force_wait);
42079
42080 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42081@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42082 }
42083 spin_unlock_irq(&pool->pool_lock);
42084
42085- serial = atomic_inc_return(&pool->req_ser);
42086+ serial = atomic_inc_return_unchecked(&pool->req_ser);
42087 wake_up_process(pool->thread);
42088
42089 if (wait_event_interruptible(pool->force_wait,
42090- atomic_read(&pool->flush_ser) - serial >= 0))
42091+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42092 return -EINTR;
42093
42094 return 0;
42095@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42096 } else {
42097 list_add_tail(&fmr->list, &pool->dirty_list);
42098 if (++pool->dirty_len >= pool->dirty_watermark) {
42099- atomic_inc(&pool->req_ser);
42100+ atomic_inc_unchecked(&pool->req_ser);
42101 wake_up_process(pool->thread);
42102 }
42103 }
42104diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42105index 84e4500..2c9beeb 100644
42106--- a/drivers/infiniband/hw/cxgb4/mem.c
42107+++ b/drivers/infiniband/hw/cxgb4/mem.c
42108@@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42109 int err;
42110 struct fw_ri_tpte tpt;
42111 u32 stag_idx;
42112- static atomic_t key;
42113+ static atomic_unchecked_t key;
42114
42115 if (c4iw_fatal_error(rdev))
42116 return -EIO;
42117@@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42118 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42119 rdev->stats.stag.max = rdev->stats.stag.cur;
42120 mutex_unlock(&rdev->stats.lock);
42121- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42122+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42123 }
42124 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42125 __func__, stag_state, type, pdid, stag_idx);
42126diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
42127index 644c2c7..ecf0879 100644
42128--- a/drivers/infiniband/hw/ipath/ipath_dma.c
42129+++ b/drivers/infiniband/hw/ipath/ipath_dma.c
42130@@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
42131 }
42132
42133 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
42134- ipath_mapping_error,
42135- ipath_dma_map_single,
42136- ipath_dma_unmap_single,
42137- ipath_dma_map_page,
42138- ipath_dma_unmap_page,
42139- ipath_map_sg,
42140- ipath_unmap_sg,
42141- ipath_sg_dma_address,
42142- ipath_sg_dma_len,
42143- ipath_sync_single_for_cpu,
42144- ipath_sync_single_for_device,
42145- ipath_dma_alloc_coherent,
42146- ipath_dma_free_coherent
42147+ .mapping_error = ipath_mapping_error,
42148+ .map_single = ipath_dma_map_single,
42149+ .unmap_single = ipath_dma_unmap_single,
42150+ .map_page = ipath_dma_map_page,
42151+ .unmap_page = ipath_dma_unmap_page,
42152+ .map_sg = ipath_map_sg,
42153+ .unmap_sg = ipath_unmap_sg,
42154+ .dma_address = ipath_sg_dma_address,
42155+ .dma_len = ipath_sg_dma_len,
42156+ .sync_single_for_cpu = ipath_sync_single_for_cpu,
42157+ .sync_single_for_device = ipath_sync_single_for_device,
42158+ .alloc_coherent = ipath_dma_alloc_coherent,
42159+ .free_coherent = ipath_dma_free_coherent
42160 };
42161diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42162index 79b3dbc..96e5fcc 100644
42163--- a/drivers/infiniband/hw/ipath/ipath_rc.c
42164+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42165@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42166 struct ib_atomic_eth *ateth;
42167 struct ipath_ack_entry *e;
42168 u64 vaddr;
42169- atomic64_t *maddr;
42170+ atomic64_unchecked_t *maddr;
42171 u64 sdata;
42172 u32 rkey;
42173 u8 next;
42174@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42175 IB_ACCESS_REMOTE_ATOMIC)))
42176 goto nack_acc_unlck;
42177 /* Perform atomic OP and save result. */
42178- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42179+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42180 sdata = be64_to_cpu(ateth->swap_data);
42181 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42182 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42183- (u64) atomic64_add_return(sdata, maddr) - sdata :
42184+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42185 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42186 be64_to_cpu(ateth->compare_data),
42187 sdata);
42188diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42189index 1f95bba..9530f87 100644
42190--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42191+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42192@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42193 unsigned long flags;
42194 struct ib_wc wc;
42195 u64 sdata;
42196- atomic64_t *maddr;
42197+ atomic64_unchecked_t *maddr;
42198 enum ib_wc_status send_status;
42199
42200 /*
42201@@ -382,11 +382,11 @@ again:
42202 IB_ACCESS_REMOTE_ATOMIC)))
42203 goto acc_err;
42204 /* Perform atomic OP and save result. */
42205- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42206+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42207 sdata = wqe->wr.wr.atomic.compare_add;
42208 *(u64 *) sqp->s_sge.sge.vaddr =
42209 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42210- (u64) atomic64_add_return(sdata, maddr) - sdata :
42211+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42212 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42213 sdata, wqe->wr.wr.atomic.swap);
42214 goto send_comp;
42215diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42216index f2a3f48..673ec79 100644
42217--- a/drivers/infiniband/hw/mlx4/mad.c
42218+++ b/drivers/infiniband/hw/mlx4/mad.c
42219@@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42220
42221 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42222 {
42223- return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42224+ return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42225 cpu_to_be64(0xff00000000000000LL);
42226 }
42227
42228diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42229index 25b2cdf..099ff97 100644
42230--- a/drivers/infiniband/hw/mlx4/mcg.c
42231+++ b/drivers/infiniband/hw/mlx4/mcg.c
42232@@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42233 {
42234 char name[20];
42235
42236- atomic_set(&ctx->tid, 0);
42237+ atomic_set_unchecked(&ctx->tid, 0);
42238 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42239 ctx->mcg_wq = create_singlethread_workqueue(name);
42240 if (!ctx->mcg_wq)
42241diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42242index 036b663..c9a8c73 100644
42243--- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42244+++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42245@@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
42246 struct list_head mcg_mgid0_list;
42247 struct workqueue_struct *mcg_wq;
42248 struct mlx4_ib_demux_pv_ctx **tun;
42249- atomic_t tid;
42250+ atomic_unchecked_t tid;
42251 int flushing; /* flushing the work queue */
42252 };
42253
42254diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42255index 9d3e5c1..6f166df 100644
42256--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42257+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42258@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42259 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42260 }
42261
42262-int mthca_QUERY_FW(struct mthca_dev *dev)
42263+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42264 {
42265 struct mthca_mailbox *mailbox;
42266 u32 *outbox;
42267@@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42268 CMD_TIME_CLASS_B);
42269 }
42270
42271-int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42272+int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42273 int num_mtt)
42274 {
42275 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42276@@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42277 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42278 }
42279
42280-int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42281+int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42282 int eq_num)
42283 {
42284 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42285@@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42286 CMD_TIME_CLASS_B);
42287 }
42288
42289-int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42290+int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42291 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42292 void *in_mad, void *response_mad)
42293 {
42294diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42295index 87897b9..7e79542 100644
42296--- a/drivers/infiniband/hw/mthca/mthca_main.c
42297+++ b/drivers/infiniband/hw/mthca/mthca_main.c
42298@@ -692,7 +692,7 @@ err_close:
42299 return err;
42300 }
42301
42302-static int mthca_setup_hca(struct mthca_dev *dev)
42303+static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42304 {
42305 int err;
42306
42307diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42308index ed9a989..6aa5dc2 100644
42309--- a/drivers/infiniband/hw/mthca/mthca_mr.c
42310+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42311@@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42312 * through the bitmaps)
42313 */
42314
42315-static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42316+static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42317 {
42318 int o;
42319 int m;
42320@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42321 return key;
42322 }
42323
42324-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42325+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42326 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42327 {
42328 struct mthca_mailbox *mailbox;
42329@@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42330 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42331 }
42332
42333-int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42334+int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42335 u64 *buffer_list, int buffer_size_shift,
42336 int list_len, u64 iova, u64 total_size,
42337 u32 access, struct mthca_mr *mr)
42338diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42339index 5b71d43..35a9e14 100644
42340--- a/drivers/infiniband/hw/mthca/mthca_provider.c
42341+++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42342@@ -763,7 +763,7 @@ unlock:
42343 return 0;
42344 }
42345
42346-static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42347+static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42348 {
42349 struct mthca_dev *dev = to_mdev(ibcq->device);
42350 struct mthca_cq *cq = to_mcq(ibcq);
42351diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42352index 4291410..d2ab1fb 100644
42353--- a/drivers/infiniband/hw/nes/nes.c
42354+++ b/drivers/infiniband/hw/nes/nes.c
42355@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42356 LIST_HEAD(nes_adapter_list);
42357 static LIST_HEAD(nes_dev_list);
42358
42359-atomic_t qps_destroyed;
42360+atomic_unchecked_t qps_destroyed;
42361
42362 static unsigned int ee_flsh_adapter;
42363 static unsigned int sysfs_nonidx_addr;
42364@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42365 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42366 struct nes_adapter *nesadapter = nesdev->nesadapter;
42367
42368- atomic_inc(&qps_destroyed);
42369+ atomic_inc_unchecked(&qps_destroyed);
42370
42371 /* Free the control structures */
42372
42373diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42374index 33cc589..3bd6538 100644
42375--- a/drivers/infiniband/hw/nes/nes.h
42376+++ b/drivers/infiniband/hw/nes/nes.h
42377@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42378 extern unsigned int wqm_quanta;
42379 extern struct list_head nes_adapter_list;
42380
42381-extern atomic_t cm_connects;
42382-extern atomic_t cm_accepts;
42383-extern atomic_t cm_disconnects;
42384-extern atomic_t cm_closes;
42385-extern atomic_t cm_connecteds;
42386-extern atomic_t cm_connect_reqs;
42387-extern atomic_t cm_rejects;
42388-extern atomic_t mod_qp_timouts;
42389-extern atomic_t qps_created;
42390-extern atomic_t qps_destroyed;
42391-extern atomic_t sw_qps_destroyed;
42392+extern atomic_unchecked_t cm_connects;
42393+extern atomic_unchecked_t cm_accepts;
42394+extern atomic_unchecked_t cm_disconnects;
42395+extern atomic_unchecked_t cm_closes;
42396+extern atomic_unchecked_t cm_connecteds;
42397+extern atomic_unchecked_t cm_connect_reqs;
42398+extern atomic_unchecked_t cm_rejects;
42399+extern atomic_unchecked_t mod_qp_timouts;
42400+extern atomic_unchecked_t qps_created;
42401+extern atomic_unchecked_t qps_destroyed;
42402+extern atomic_unchecked_t sw_qps_destroyed;
42403 extern u32 mh_detected;
42404 extern u32 mh_pauses_sent;
42405 extern u32 cm_packets_sent;
42406@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42407 extern u32 cm_packets_received;
42408 extern u32 cm_packets_dropped;
42409 extern u32 cm_packets_retrans;
42410-extern atomic_t cm_listens_created;
42411-extern atomic_t cm_listens_destroyed;
42412+extern atomic_unchecked_t cm_listens_created;
42413+extern atomic_unchecked_t cm_listens_destroyed;
42414 extern u32 cm_backlog_drops;
42415-extern atomic_t cm_loopbacks;
42416-extern atomic_t cm_nodes_created;
42417-extern atomic_t cm_nodes_destroyed;
42418-extern atomic_t cm_accel_dropped_pkts;
42419-extern atomic_t cm_resets_recvd;
42420-extern atomic_t pau_qps_created;
42421-extern atomic_t pau_qps_destroyed;
42422+extern atomic_unchecked_t cm_loopbacks;
42423+extern atomic_unchecked_t cm_nodes_created;
42424+extern atomic_unchecked_t cm_nodes_destroyed;
42425+extern atomic_unchecked_t cm_accel_dropped_pkts;
42426+extern atomic_unchecked_t cm_resets_recvd;
42427+extern atomic_unchecked_t pau_qps_created;
42428+extern atomic_unchecked_t pau_qps_destroyed;
42429
42430 extern u32 int_mod_timer_init;
42431 extern u32 int_mod_cq_depth_256;
42432diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42433index 6b29249..461d143 100644
42434--- a/drivers/infiniband/hw/nes/nes_cm.c
42435+++ b/drivers/infiniband/hw/nes/nes_cm.c
42436@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42437 u32 cm_packets_retrans;
42438 u32 cm_packets_created;
42439 u32 cm_packets_received;
42440-atomic_t cm_listens_created;
42441-atomic_t cm_listens_destroyed;
42442+atomic_unchecked_t cm_listens_created;
42443+atomic_unchecked_t cm_listens_destroyed;
42444 u32 cm_backlog_drops;
42445-atomic_t cm_loopbacks;
42446-atomic_t cm_nodes_created;
42447-atomic_t cm_nodes_destroyed;
42448-atomic_t cm_accel_dropped_pkts;
42449-atomic_t cm_resets_recvd;
42450+atomic_unchecked_t cm_loopbacks;
42451+atomic_unchecked_t cm_nodes_created;
42452+atomic_unchecked_t cm_nodes_destroyed;
42453+atomic_unchecked_t cm_accel_dropped_pkts;
42454+atomic_unchecked_t cm_resets_recvd;
42455
42456 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42457 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42458@@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
42459 /* instance of function pointers for client API */
42460 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42461 static struct nes_cm_ops nes_cm_api = {
42462- mini_cm_accelerated,
42463- mini_cm_listen,
42464- mini_cm_del_listen,
42465- mini_cm_connect,
42466- mini_cm_close,
42467- mini_cm_accept,
42468- mini_cm_reject,
42469- mini_cm_recv_pkt,
42470- mini_cm_dealloc_core,
42471- mini_cm_get,
42472- mini_cm_set
42473+ .accelerated = mini_cm_accelerated,
42474+ .listen = mini_cm_listen,
42475+ .stop_listener = mini_cm_del_listen,
42476+ .connect = mini_cm_connect,
42477+ .close = mini_cm_close,
42478+ .accept = mini_cm_accept,
42479+ .reject = mini_cm_reject,
42480+ .recv_pkt = mini_cm_recv_pkt,
42481+ .destroy_cm_core = mini_cm_dealloc_core,
42482+ .get = mini_cm_get,
42483+ .set = mini_cm_set
42484 };
42485
42486 static struct nes_cm_core *g_cm_core;
42487
42488-atomic_t cm_connects;
42489-atomic_t cm_accepts;
42490-atomic_t cm_disconnects;
42491-atomic_t cm_closes;
42492-atomic_t cm_connecteds;
42493-atomic_t cm_connect_reqs;
42494-atomic_t cm_rejects;
42495+atomic_unchecked_t cm_connects;
42496+atomic_unchecked_t cm_accepts;
42497+atomic_unchecked_t cm_disconnects;
42498+atomic_unchecked_t cm_closes;
42499+atomic_unchecked_t cm_connecteds;
42500+atomic_unchecked_t cm_connect_reqs;
42501+atomic_unchecked_t cm_rejects;
42502
42503 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42504 {
42505@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42506 kfree(listener);
42507 listener = NULL;
42508 ret = 0;
42509- atomic_inc(&cm_listens_destroyed);
42510+ atomic_inc_unchecked(&cm_listens_destroyed);
42511 } else {
42512 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42513 }
42514@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42515 cm_node->rem_mac);
42516
42517 add_hte_node(cm_core, cm_node);
42518- atomic_inc(&cm_nodes_created);
42519+ atomic_inc_unchecked(&cm_nodes_created);
42520
42521 return cm_node;
42522 }
42523@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42524 }
42525
42526 atomic_dec(&cm_core->node_cnt);
42527- atomic_inc(&cm_nodes_destroyed);
42528+ atomic_inc_unchecked(&cm_nodes_destroyed);
42529 nesqp = cm_node->nesqp;
42530 if (nesqp) {
42531 nesqp->cm_node = NULL;
42532@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42533
42534 static void drop_packet(struct sk_buff *skb)
42535 {
42536- atomic_inc(&cm_accel_dropped_pkts);
42537+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42538 dev_kfree_skb_any(skb);
42539 }
42540
42541@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42542 {
42543
42544 int reset = 0; /* whether to send reset in case of err.. */
42545- atomic_inc(&cm_resets_recvd);
42546+ atomic_inc_unchecked(&cm_resets_recvd);
42547 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42548 " refcnt=%d\n", cm_node, cm_node->state,
42549 atomic_read(&cm_node->ref_count));
42550@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42551 rem_ref_cm_node(cm_node->cm_core, cm_node);
42552 return NULL;
42553 }
42554- atomic_inc(&cm_loopbacks);
42555+ atomic_inc_unchecked(&cm_loopbacks);
42556 loopbackremotenode->loopbackpartner = cm_node;
42557 loopbackremotenode->tcp_cntxt.rcv_wscale =
42558 NES_CM_DEFAULT_RCV_WND_SCALE;
42559@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42560 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42561 else {
42562 rem_ref_cm_node(cm_core, cm_node);
42563- atomic_inc(&cm_accel_dropped_pkts);
42564+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
42565 dev_kfree_skb_any(skb);
42566 }
42567 break;
42568@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42569
42570 if ((cm_id) && (cm_id->event_handler)) {
42571 if (issue_disconn) {
42572- atomic_inc(&cm_disconnects);
42573+ atomic_inc_unchecked(&cm_disconnects);
42574 cm_event.event = IW_CM_EVENT_DISCONNECT;
42575 cm_event.status = disconn_status;
42576 cm_event.local_addr = cm_id->local_addr;
42577@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42578 }
42579
42580 if (issue_close) {
42581- atomic_inc(&cm_closes);
42582+ atomic_inc_unchecked(&cm_closes);
42583 nes_disconnect(nesqp, 1);
42584
42585 cm_id->provider_data = nesqp;
42586@@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42587
42588 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42589 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42590- atomic_inc(&cm_accepts);
42591+ atomic_inc_unchecked(&cm_accepts);
42592
42593 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42594 netdev_refcnt_read(nesvnic->netdev));
42595@@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42596 struct nes_cm_core *cm_core;
42597 u8 *start_buff;
42598
42599- atomic_inc(&cm_rejects);
42600+ atomic_inc_unchecked(&cm_rejects);
42601 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42602 loopback = cm_node->loopbackpartner;
42603 cm_core = cm_node->cm_core;
42604@@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42605 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42606 ntohs(laddr->sin_port));
42607
42608- atomic_inc(&cm_connects);
42609+ atomic_inc_unchecked(&cm_connects);
42610 nesqp->active_conn = 1;
42611
42612 /* cache the cm_id in the qp */
42613@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42614 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42615 return err;
42616 }
42617- atomic_inc(&cm_listens_created);
42618+ atomic_inc_unchecked(&cm_listens_created);
42619 }
42620
42621 cm_id->add_ref(cm_id);
42622@@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42623
42624 if (nesqp->destroyed)
42625 return;
42626- atomic_inc(&cm_connecteds);
42627+ atomic_inc_unchecked(&cm_connecteds);
42628 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42629 " local port 0x%04X. jiffies = %lu.\n",
42630 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42631@@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42632
42633 cm_id->add_ref(cm_id);
42634 ret = cm_id->event_handler(cm_id, &cm_event);
42635- atomic_inc(&cm_closes);
42636+ atomic_inc_unchecked(&cm_closes);
42637 cm_event.event = IW_CM_EVENT_CLOSE;
42638 cm_event.status = 0;
42639 cm_event.provider_data = cm_id->provider_data;
42640@@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42641 return;
42642 cm_id = cm_node->cm_id;
42643
42644- atomic_inc(&cm_connect_reqs);
42645+ atomic_inc_unchecked(&cm_connect_reqs);
42646 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42647 cm_node, cm_id, jiffies);
42648
42649@@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42650 return;
42651 cm_id = cm_node->cm_id;
42652
42653- atomic_inc(&cm_connect_reqs);
42654+ atomic_inc_unchecked(&cm_connect_reqs);
42655 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42656 cm_node, cm_id, jiffies);
42657
42658diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42659index 4166452..fc952c3 100644
42660--- a/drivers/infiniband/hw/nes/nes_mgt.c
42661+++ b/drivers/infiniband/hw/nes/nes_mgt.c
42662@@ -40,8 +40,8 @@
42663 #include "nes.h"
42664 #include "nes_mgt.h"
42665
42666-atomic_t pau_qps_created;
42667-atomic_t pau_qps_destroyed;
42668+atomic_unchecked_t pau_qps_created;
42669+atomic_unchecked_t pau_qps_destroyed;
42670
42671 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42672 {
42673@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42674 {
42675 struct sk_buff *skb;
42676 unsigned long flags;
42677- atomic_inc(&pau_qps_destroyed);
42678+ atomic_inc_unchecked(&pau_qps_destroyed);
42679
42680 /* Free packets that have not yet been forwarded */
42681 /* Lock is acquired by skb_dequeue when removing the skb */
42682@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42683 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42684 skb_queue_head_init(&nesqp->pau_list);
42685 spin_lock_init(&nesqp->pau_lock);
42686- atomic_inc(&pau_qps_created);
42687+ atomic_inc_unchecked(&pau_qps_created);
42688 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42689 }
42690
42691diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42692index 49eb511..a774366 100644
42693--- a/drivers/infiniband/hw/nes/nes_nic.c
42694+++ b/drivers/infiniband/hw/nes/nes_nic.c
42695@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42696 target_stat_values[++index] = mh_detected;
42697 target_stat_values[++index] = mh_pauses_sent;
42698 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42699- target_stat_values[++index] = atomic_read(&cm_connects);
42700- target_stat_values[++index] = atomic_read(&cm_accepts);
42701- target_stat_values[++index] = atomic_read(&cm_disconnects);
42702- target_stat_values[++index] = atomic_read(&cm_connecteds);
42703- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42704- target_stat_values[++index] = atomic_read(&cm_rejects);
42705- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42706- target_stat_values[++index] = atomic_read(&qps_created);
42707- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42708- target_stat_values[++index] = atomic_read(&qps_destroyed);
42709- target_stat_values[++index] = atomic_read(&cm_closes);
42710+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42711+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42712+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42713+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42714+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42715+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42716+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42717+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42718+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42719+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42720+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42721 target_stat_values[++index] = cm_packets_sent;
42722 target_stat_values[++index] = cm_packets_bounced;
42723 target_stat_values[++index] = cm_packets_created;
42724 target_stat_values[++index] = cm_packets_received;
42725 target_stat_values[++index] = cm_packets_dropped;
42726 target_stat_values[++index] = cm_packets_retrans;
42727- target_stat_values[++index] = atomic_read(&cm_listens_created);
42728- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42729+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42730+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42731 target_stat_values[++index] = cm_backlog_drops;
42732- target_stat_values[++index] = atomic_read(&cm_loopbacks);
42733- target_stat_values[++index] = atomic_read(&cm_nodes_created);
42734- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42735- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42736- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42737+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42738+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42739+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42740+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42741+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42742 target_stat_values[++index] = nesadapter->free_4kpbl;
42743 target_stat_values[++index] = nesadapter->free_256pbl;
42744 target_stat_values[++index] = int_mod_timer_init;
42745 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42746 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42747 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42748- target_stat_values[++index] = atomic_read(&pau_qps_created);
42749- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42750+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42751+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42752 }
42753
42754 /**
42755diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42756index 8308e36..ae0d3b5 100644
42757--- a/drivers/infiniband/hw/nes/nes_verbs.c
42758+++ b/drivers/infiniband/hw/nes/nes_verbs.c
42759@@ -46,9 +46,9 @@
42760
42761 #include <rdma/ib_umem.h>
42762
42763-atomic_t mod_qp_timouts;
42764-atomic_t qps_created;
42765-atomic_t sw_qps_destroyed;
42766+atomic_unchecked_t mod_qp_timouts;
42767+atomic_unchecked_t qps_created;
42768+atomic_unchecked_t sw_qps_destroyed;
42769
42770 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42771
42772@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42773 if (init_attr->create_flags)
42774 return ERR_PTR(-EINVAL);
42775
42776- atomic_inc(&qps_created);
42777+ atomic_inc_unchecked(&qps_created);
42778 switch (init_attr->qp_type) {
42779 case IB_QPT_RC:
42780 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42781@@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42782 struct iw_cm_event cm_event;
42783 int ret = 0;
42784
42785- atomic_inc(&sw_qps_destroyed);
42786+ atomic_inc_unchecked(&sw_qps_destroyed);
42787 nesqp->destroyed = 1;
42788
42789 /* Blow away the connection if it exists. */
42790diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42791index 1946101..09766d2 100644
42792--- a/drivers/infiniband/hw/qib/qib.h
42793+++ b/drivers/infiniband/hw/qib/qib.h
42794@@ -52,6 +52,7 @@
42795 #include <linux/kref.h>
42796 #include <linux/sched.h>
42797 #include <linux/kthread.h>
42798+#include <linux/slab.h>
42799
42800 #include "qib_common.h"
42801 #include "qib_verbs.h"
42802diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42803index 24c41ba..102d71f 100644
42804--- a/drivers/input/gameport/gameport.c
42805+++ b/drivers/input/gameport/gameport.c
42806@@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42807 */
42808 static void gameport_init_port(struct gameport *gameport)
42809 {
42810- static atomic_t gameport_no = ATOMIC_INIT(0);
42811+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42812
42813 __module_get(THIS_MODULE);
42814
42815 mutex_init(&gameport->drv_mutex);
42816 device_initialize(&gameport->dev);
42817 dev_set_name(&gameport->dev, "gameport%lu",
42818- (unsigned long)atomic_inc_return(&gameport_no) - 1);
42819+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42820 gameport->dev.bus = &gameport_bus;
42821 gameport->dev.release = gameport_release_port;
42822 if (gameport->parent)
42823diff --git a/drivers/input/input.c b/drivers/input/input.c
42824index d2965e4..f52b7d7 100644
42825--- a/drivers/input/input.c
42826+++ b/drivers/input/input.c
42827@@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42828 */
42829 struct input_dev *input_allocate_device(void)
42830 {
42831- static atomic_t input_no = ATOMIC_INIT(0);
42832+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42833 struct input_dev *dev;
42834
42835 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42836@@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42837 INIT_LIST_HEAD(&dev->node);
42838
42839 dev_set_name(&dev->dev, "input%ld",
42840- (unsigned long) atomic_inc_return(&input_no) - 1);
42841+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42842
42843 __module_get(THIS_MODULE);
42844 }
42845diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42846index 04c69af..5f92d00 100644
42847--- a/drivers/input/joystick/sidewinder.c
42848+++ b/drivers/input/joystick/sidewinder.c
42849@@ -30,6 +30,7 @@
42850 #include <linux/kernel.h>
42851 #include <linux/module.h>
42852 #include <linux/slab.h>
42853+#include <linux/sched.h>
42854 #include <linux/init.h>
42855 #include <linux/input.h>
42856 #include <linux/gameport.h>
42857diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42858index 75e3b10..fb390fd 100644
42859--- a/drivers/input/joystick/xpad.c
42860+++ b/drivers/input/joystick/xpad.c
42861@@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42862
42863 static int xpad_led_probe(struct usb_xpad *xpad)
42864 {
42865- static atomic_t led_seq = ATOMIC_INIT(0);
42866+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42867 long led_no;
42868 struct xpad_led *led;
42869 struct led_classdev *led_cdev;
42870@@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42871 if (!led)
42872 return -ENOMEM;
42873
42874- led_no = (long)atomic_inc_return(&led_seq) - 1;
42875+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42876
42877 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42878 led->xpad = xpad;
42879diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42880index e204f26..8459f15 100644
42881--- a/drivers/input/misc/ims-pcu.c
42882+++ b/drivers/input/misc/ims-pcu.c
42883@@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42884
42885 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42886 {
42887- static atomic_t device_no = ATOMIC_INIT(0);
42888+ static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42889
42890 const struct ims_pcu_device_info *info;
42891 u8 device_id;
42892@@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42893 }
42894
42895 /* Device appears to be operable, complete initialization */
42896- pcu->device_no = atomic_inc_return(&device_no) - 1;
42897+ pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42898
42899 error = ims_pcu_setup_backlight(pcu);
42900 if (error)
42901diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42902index 2f0b39d..7370f13 100644
42903--- a/drivers/input/mouse/psmouse.h
42904+++ b/drivers/input/mouse/psmouse.h
42905@@ -116,7 +116,7 @@ struct psmouse_attribute {
42906 ssize_t (*set)(struct psmouse *psmouse, void *data,
42907 const char *buf, size_t count);
42908 bool protect;
42909-};
42910+} __do_const;
42911 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42912
42913 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42914diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42915index b604564..3f14ae4 100644
42916--- a/drivers/input/mousedev.c
42917+++ b/drivers/input/mousedev.c
42918@@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42919
42920 spin_unlock_irq(&client->packet_lock);
42921
42922- if (copy_to_user(buffer, data, count))
42923+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
42924 return -EFAULT;
42925
42926 return count;
42927diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42928index 8f4c4ab..5fc8a45 100644
42929--- a/drivers/input/serio/serio.c
42930+++ b/drivers/input/serio/serio.c
42931@@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42932 */
42933 static void serio_init_port(struct serio *serio)
42934 {
42935- static atomic_t serio_no = ATOMIC_INIT(0);
42936+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42937
42938 __module_get(THIS_MODULE);
42939
42940@@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42941 mutex_init(&serio->drv_mutex);
42942 device_initialize(&serio->dev);
42943 dev_set_name(&serio->dev, "serio%ld",
42944- (long)atomic_inc_return(&serio_no) - 1);
42945+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
42946 serio->dev.bus = &serio_bus;
42947 serio->dev.release = serio_release_port;
42948 serio->dev.groups = serio_device_attr_groups;
42949diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42950index 59df2e7..8f1cafb 100644
42951--- a/drivers/input/serio/serio_raw.c
42952+++ b/drivers/input/serio/serio_raw.c
42953@@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42954
42955 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42956 {
42957- static atomic_t serio_raw_no = ATOMIC_INIT(0);
42958+ static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42959 struct serio_raw *serio_raw;
42960 int err;
42961
42962@@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42963 }
42964
42965 snprintf(serio_raw->name, sizeof(serio_raw->name),
42966- "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42967+ "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42968 kref_init(&serio_raw->kref);
42969 INIT_LIST_HEAD(&serio_raw->client_list);
42970 init_waitqueue_head(&serio_raw->wait);
42971diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42972index e5555fc..937986d 100644
42973--- a/drivers/iommu/iommu.c
42974+++ b/drivers/iommu/iommu.c
42975@@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42976 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42977 {
42978 bus_register_notifier(bus, &iommu_bus_nb);
42979- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42980+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42981 }
42982
42983 /**
42984diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42985index 39f81ae..2660096 100644
42986--- a/drivers/iommu/irq_remapping.c
42987+++ b/drivers/iommu/irq_remapping.c
42988@@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42989 void panic_if_irq_remap(const char *msg)
42990 {
42991 if (irq_remapping_enabled)
42992- panic(msg);
42993+ panic("%s", msg);
42994 }
42995
42996 static void ir_ack_apic_edge(struct irq_data *data)
42997@@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42998
42999 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43000 {
43001- chip->irq_print_chip = ir_print_prefix;
43002- chip->irq_ack = ir_ack_apic_edge;
43003- chip->irq_eoi = ir_ack_apic_level;
43004- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43005+ pax_open_kernel();
43006+ *(void **)&chip->irq_print_chip = ir_print_prefix;
43007+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
43008+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
43009+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43010+ pax_close_kernel();
43011 }
43012
43013 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43014diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43015index 341c601..e5f407e 100644
43016--- a/drivers/irqchip/irq-gic.c
43017+++ b/drivers/irqchip/irq-gic.c
43018@@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43019 * Supported arch specific GIC irq extension.
43020 * Default make them NULL.
43021 */
43022-struct irq_chip gic_arch_extn = {
43023+irq_chip_no_const gic_arch_extn = {
43024 .irq_eoi = NULL,
43025 .irq_mask = NULL,
43026 .irq_unmask = NULL,
43027@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43028 chained_irq_exit(chip, desc);
43029 }
43030
43031-static struct irq_chip gic_chip = {
43032+static irq_chip_no_const gic_chip __read_only = {
43033 .name = "GIC",
43034 .irq_mask = gic_mask_irq,
43035 .irq_unmask = gic_unmask_irq,
43036diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43037index ac6f72b..81150f2 100644
43038--- a/drivers/isdn/capi/capi.c
43039+++ b/drivers/isdn/capi/capi.c
43040@@ -81,8 +81,8 @@ struct capiminor {
43041
43042 struct capi20_appl *ap;
43043 u32 ncci;
43044- atomic_t datahandle;
43045- atomic_t msgid;
43046+ atomic_unchecked_t datahandle;
43047+ atomic_unchecked_t msgid;
43048
43049 struct tty_port port;
43050 int ttyinstop;
43051@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43052 capimsg_setu16(s, 2, mp->ap->applid);
43053 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43054 capimsg_setu8 (s, 5, CAPI_RESP);
43055- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43056+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43057 capimsg_setu32(s, 8, mp->ncci);
43058 capimsg_setu16(s, 12, datahandle);
43059 }
43060@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43061 mp->outbytes -= len;
43062 spin_unlock_bh(&mp->outlock);
43063
43064- datahandle = atomic_inc_return(&mp->datahandle);
43065+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43066 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43067 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43068 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43069 capimsg_setu16(skb->data, 2, mp->ap->applid);
43070 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43071 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43072- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43073+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43074 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43075 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43076 capimsg_setu16(skb->data, 16, len); /* Data length */
43077diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43078index c44950d..10ac276 100644
43079--- a/drivers/isdn/gigaset/bas-gigaset.c
43080+++ b/drivers/isdn/gigaset/bas-gigaset.c
43081@@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43082
43083
43084 static const struct gigaset_ops gigops = {
43085- gigaset_write_cmd,
43086- gigaset_write_room,
43087- gigaset_chars_in_buffer,
43088- gigaset_brkchars,
43089- gigaset_init_bchannel,
43090- gigaset_close_bchannel,
43091- gigaset_initbcshw,
43092- gigaset_freebcshw,
43093- gigaset_reinitbcshw,
43094- gigaset_initcshw,
43095- gigaset_freecshw,
43096- gigaset_set_modem_ctrl,
43097- gigaset_baud_rate,
43098- gigaset_set_line_ctrl,
43099- gigaset_isoc_send_skb,
43100- gigaset_isoc_input,
43101+ .write_cmd = gigaset_write_cmd,
43102+ .write_room = gigaset_write_room,
43103+ .chars_in_buffer = gigaset_chars_in_buffer,
43104+ .brkchars = gigaset_brkchars,
43105+ .init_bchannel = gigaset_init_bchannel,
43106+ .close_bchannel = gigaset_close_bchannel,
43107+ .initbcshw = gigaset_initbcshw,
43108+ .freebcshw = gigaset_freebcshw,
43109+ .reinitbcshw = gigaset_reinitbcshw,
43110+ .initcshw = gigaset_initcshw,
43111+ .freecshw = gigaset_freecshw,
43112+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43113+ .baud_rate = gigaset_baud_rate,
43114+ .set_line_ctrl = gigaset_set_line_ctrl,
43115+ .send_skb = gigaset_isoc_send_skb,
43116+ .handle_input = gigaset_isoc_input,
43117 };
43118
43119 /* bas_gigaset_init
43120diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43121index 600c79b..3752bab 100644
43122--- a/drivers/isdn/gigaset/interface.c
43123+++ b/drivers/isdn/gigaset/interface.c
43124@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43125 }
43126 tty->driver_data = cs;
43127
43128- ++cs->port.count;
43129+ atomic_inc(&cs->port.count);
43130
43131- if (cs->port.count == 1) {
43132+ if (atomic_read(&cs->port.count) == 1) {
43133 tty_port_tty_set(&cs->port, tty);
43134 cs->port.low_latency = 1;
43135 }
43136@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43137
43138 if (!cs->connected)
43139 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43140- else if (!cs->port.count)
43141+ else if (!atomic_read(&cs->port.count))
43142 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43143- else if (!--cs->port.count)
43144+ else if (!atomic_dec_return(&cs->port.count))
43145 tty_port_tty_set(&cs->port, NULL);
43146
43147 mutex_unlock(&cs->mutex);
43148diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43149index 8c91fd5..14f13ce 100644
43150--- a/drivers/isdn/gigaset/ser-gigaset.c
43151+++ b/drivers/isdn/gigaset/ser-gigaset.c
43152@@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43153 }
43154
43155 static const struct gigaset_ops ops = {
43156- gigaset_write_cmd,
43157- gigaset_write_room,
43158- gigaset_chars_in_buffer,
43159- gigaset_brkchars,
43160- gigaset_init_bchannel,
43161- gigaset_close_bchannel,
43162- gigaset_initbcshw,
43163- gigaset_freebcshw,
43164- gigaset_reinitbcshw,
43165- gigaset_initcshw,
43166- gigaset_freecshw,
43167- gigaset_set_modem_ctrl,
43168- gigaset_baud_rate,
43169- gigaset_set_line_ctrl,
43170- gigaset_m10x_send_skb, /* asyncdata.c */
43171- gigaset_m10x_input, /* asyncdata.c */
43172+ .write_cmd = gigaset_write_cmd,
43173+ .write_room = gigaset_write_room,
43174+ .chars_in_buffer = gigaset_chars_in_buffer,
43175+ .brkchars = gigaset_brkchars,
43176+ .init_bchannel = gigaset_init_bchannel,
43177+ .close_bchannel = gigaset_close_bchannel,
43178+ .initbcshw = gigaset_initbcshw,
43179+ .freebcshw = gigaset_freebcshw,
43180+ .reinitbcshw = gigaset_reinitbcshw,
43181+ .initcshw = gigaset_initcshw,
43182+ .freecshw = gigaset_freecshw,
43183+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43184+ .baud_rate = gigaset_baud_rate,
43185+ .set_line_ctrl = gigaset_set_line_ctrl,
43186+ .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43187+ .handle_input = gigaset_m10x_input, /* asyncdata.c */
43188 };
43189
43190
43191diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43192index d0a41cb..b953e50 100644
43193--- a/drivers/isdn/gigaset/usb-gigaset.c
43194+++ b/drivers/isdn/gigaset/usb-gigaset.c
43195@@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43196 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43197 memcpy(cs->hw.usb->bchars, buf, 6);
43198 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43199- 0, 0, &buf, 6, 2000);
43200+ 0, 0, buf, 6, 2000);
43201 }
43202
43203 static void gigaset_freebcshw(struct bc_state *bcs)
43204@@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43205 }
43206
43207 static const struct gigaset_ops ops = {
43208- gigaset_write_cmd,
43209- gigaset_write_room,
43210- gigaset_chars_in_buffer,
43211- gigaset_brkchars,
43212- gigaset_init_bchannel,
43213- gigaset_close_bchannel,
43214- gigaset_initbcshw,
43215- gigaset_freebcshw,
43216- gigaset_reinitbcshw,
43217- gigaset_initcshw,
43218- gigaset_freecshw,
43219- gigaset_set_modem_ctrl,
43220- gigaset_baud_rate,
43221- gigaset_set_line_ctrl,
43222- gigaset_m10x_send_skb,
43223- gigaset_m10x_input,
43224+ .write_cmd = gigaset_write_cmd,
43225+ .write_room = gigaset_write_room,
43226+ .chars_in_buffer = gigaset_chars_in_buffer,
43227+ .brkchars = gigaset_brkchars,
43228+ .init_bchannel = gigaset_init_bchannel,
43229+ .close_bchannel = gigaset_close_bchannel,
43230+ .initbcshw = gigaset_initbcshw,
43231+ .freebcshw = gigaset_freebcshw,
43232+ .reinitbcshw = gigaset_reinitbcshw,
43233+ .initcshw = gigaset_initcshw,
43234+ .freecshw = gigaset_freecshw,
43235+ .set_modem_ctrl = gigaset_set_modem_ctrl,
43236+ .baud_rate = gigaset_baud_rate,
43237+ .set_line_ctrl = gigaset_set_line_ctrl,
43238+ .send_skb = gigaset_m10x_send_skb,
43239+ .handle_input = gigaset_m10x_input,
43240 };
43241
43242 /*
43243diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43244index 4d9b195..455075c 100644
43245--- a/drivers/isdn/hardware/avm/b1.c
43246+++ b/drivers/isdn/hardware/avm/b1.c
43247@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43248 }
43249 if (left) {
43250 if (t4file->user) {
43251- if (copy_from_user(buf, dp, left))
43252+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43253 return -EFAULT;
43254 } else {
43255 memcpy(buf, dp, left);
43256@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43257 }
43258 if (left) {
43259 if (config->user) {
43260- if (copy_from_user(buf, dp, left))
43261+ if (left > sizeof buf || copy_from_user(buf, dp, left))
43262 return -EFAULT;
43263 } else {
43264 memcpy(buf, dp, left);
43265diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43266index 9bb12ba..d4262f7 100644
43267--- a/drivers/isdn/i4l/isdn_common.c
43268+++ b/drivers/isdn/i4l/isdn_common.c
43269@@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43270 } else
43271 return -EINVAL;
43272 case IIOCDBGVAR:
43273+ if (!capable(CAP_SYS_RAWIO))
43274+ return -EPERM;
43275 if (arg) {
43276 if (copy_to_user(argp, &dev, sizeof(ulong)))
43277 return -EFAULT;
43278diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43279index 91d5730..336523e 100644
43280--- a/drivers/isdn/i4l/isdn_concap.c
43281+++ b/drivers/isdn/i4l/isdn_concap.c
43282@@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43283 }
43284
43285 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43286- &isdn_concap_dl_data_req,
43287- &isdn_concap_dl_connect_req,
43288- &isdn_concap_dl_disconn_req
43289+ .data_req = &isdn_concap_dl_data_req,
43290+ .connect_req = &isdn_concap_dl_connect_req,
43291+ .disconn_req = &isdn_concap_dl_disconn_req
43292 };
43293
43294 /* The following should better go into a dedicated source file such that
43295diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43296index 3c5f249..5fac4d0 100644
43297--- a/drivers/isdn/i4l/isdn_tty.c
43298+++ b/drivers/isdn/i4l/isdn_tty.c
43299@@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43300
43301 #ifdef ISDN_DEBUG_MODEM_OPEN
43302 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43303- port->count);
43304+ atomic_read(&port->count));
43305 #endif
43306- port->count++;
43307+ atomic_inc(&port->count);
43308 port->tty = tty;
43309 /*
43310 * Start up serial port
43311@@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43312 #endif
43313 return;
43314 }
43315- if ((tty->count == 1) && (port->count != 1)) {
43316+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43317 /*
43318 * Uh, oh. tty->count is 1, which means that the tty
43319 * structure will be freed. Info->count should always
43320@@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43321 * serial port won't be shutdown.
43322 */
43323 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43324- "info->count is %d\n", port->count);
43325- port->count = 1;
43326+ "info->count is %d\n", atomic_read(&port->count));
43327+ atomic_set(&port->count, 1);
43328 }
43329- if (--port->count < 0) {
43330+ if (atomic_dec_return(&port->count) < 0) {
43331 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43332- info->line, port->count);
43333- port->count = 0;
43334+ info->line, atomic_read(&port->count));
43335+ atomic_set(&port->count, 0);
43336 }
43337- if (port->count) {
43338+ if (atomic_read(&port->count)) {
43339 #ifdef ISDN_DEBUG_MODEM_OPEN
43340 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43341 #endif
43342@@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43343 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43344 return;
43345 isdn_tty_shutdown(info);
43346- port->count = 0;
43347+ atomic_set(&port->count, 0);
43348 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43349 port->tty = NULL;
43350 wake_up_interruptible(&port->open_wait);
43351@@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43352 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43353 modem_info *info = &dev->mdm.info[i];
43354
43355- if (info->port.count == 0)
43356+ if (atomic_read(&info->port.count) == 0)
43357 continue;
43358 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43359 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43360diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43361index e2d4e58..40cd045 100644
43362--- a/drivers/isdn/i4l/isdn_x25iface.c
43363+++ b/drivers/isdn/i4l/isdn_x25iface.c
43364@@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43365
43366
43367 static struct concap_proto_ops ix25_pops = {
43368- &isdn_x25iface_proto_new,
43369- &isdn_x25iface_proto_del,
43370- &isdn_x25iface_proto_restart,
43371- &isdn_x25iface_proto_close,
43372- &isdn_x25iface_xmit,
43373- &isdn_x25iface_receive,
43374- &isdn_x25iface_connect_ind,
43375- &isdn_x25iface_disconn_ind
43376+ .proto_new = &isdn_x25iface_proto_new,
43377+ .proto_del = &isdn_x25iface_proto_del,
43378+ .restart = &isdn_x25iface_proto_restart,
43379+ .close = &isdn_x25iface_proto_close,
43380+ .encap_and_xmit = &isdn_x25iface_xmit,
43381+ .data_ind = &isdn_x25iface_receive,
43382+ .connect_ind = &isdn_x25iface_connect_ind,
43383+ .disconn_ind = &isdn_x25iface_disconn_ind
43384 };
43385
43386 /* error message helper function */
43387diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43388index 53d487f..f020f41 100644
43389--- a/drivers/isdn/icn/icn.c
43390+++ b/drivers/isdn/icn/icn.c
43391@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43392 if (count > len)
43393 count = len;
43394 if (user) {
43395- if (copy_from_user(msg, buf, count))
43396+ if (count > sizeof msg || copy_from_user(msg, buf, count))
43397 return -EFAULT;
43398 } else
43399 memcpy(msg, buf, count);
43400diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43401index a4f05c5..1433bc5 100644
43402--- a/drivers/isdn/mISDN/dsp_cmx.c
43403+++ b/drivers/isdn/mISDN/dsp_cmx.c
43404@@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43405 static u16 dsp_count; /* last sample count */
43406 static int dsp_count_valid; /* if we have last sample count */
43407
43408-void
43409+void __intentional_overflow(-1)
43410 dsp_cmx_send(void *arg)
43411 {
43412 struct dsp_conf *conf;
43413diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43414index d93e245..e7ece6b 100644
43415--- a/drivers/leds/leds-clevo-mail.c
43416+++ b/drivers/leds/leds-clevo-mail.c
43417@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43418 * detected as working, but in reality it is not) as low as
43419 * possible.
43420 */
43421-static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43422+static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43423 {
43424 .callback = clevo_mail_led_dmi_callback,
43425 .ident = "Clevo D410J",
43426diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43427index 5b8f938..b73d657 100644
43428--- a/drivers/leds/leds-ss4200.c
43429+++ b/drivers/leds/leds-ss4200.c
43430@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43431 * detected as working, but in reality it is not) as low as
43432 * possible.
43433 */
43434-static struct dmi_system_id nas_led_whitelist[] __initdata = {
43435+static struct dmi_system_id nas_led_whitelist[] __initconst = {
43436 {
43437 .callback = ss4200_led_dmi_callback,
43438 .ident = "Intel SS4200-E",
43439diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43440index 0bf1e4e..b4bf44e 100644
43441--- a/drivers/lguest/core.c
43442+++ b/drivers/lguest/core.c
43443@@ -97,9 +97,17 @@ static __init int map_switcher(void)
43444 * The end address needs +1 because __get_vm_area allocates an
43445 * extra guard page, so we need space for that.
43446 */
43447+
43448+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43449+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43450+ VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43451+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43452+#else
43453 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43454 VM_ALLOC, switcher_addr, switcher_addr
43455 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43456+#endif
43457+
43458 if (!switcher_vma) {
43459 err = -ENOMEM;
43460 printk("lguest: could not map switcher pages high\n");
43461@@ -124,7 +132,7 @@ static __init int map_switcher(void)
43462 * Now the Switcher is mapped at the right address, we can't fail!
43463 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43464 */
43465- memcpy(switcher_vma->addr, start_switcher_text,
43466+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43467 end_switcher_text - start_switcher_text);
43468
43469 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43470diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43471index bfb39bb..08a603b 100644
43472--- a/drivers/lguest/page_tables.c
43473+++ b/drivers/lguest/page_tables.c
43474@@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43475 /*:*/
43476
43477 #ifdef CONFIG_X86_PAE
43478-static void release_pmd(pmd_t *spmd)
43479+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43480 {
43481 /* If the entry's not present, there's nothing to release. */
43482 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43483diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43484index 922a1ac..9dd0c2a 100644
43485--- a/drivers/lguest/x86/core.c
43486+++ b/drivers/lguest/x86/core.c
43487@@ -59,7 +59,7 @@ static struct {
43488 /* Offset from where switcher.S was compiled to where we've copied it */
43489 static unsigned long switcher_offset(void)
43490 {
43491- return switcher_addr - (unsigned long)start_switcher_text;
43492+ return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43493 }
43494
43495 /* This cpu's struct lguest_pages (after the Switcher text page) */
43496@@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43497 * These copies are pretty cheap, so we do them unconditionally: */
43498 /* Save the current Host top-level page directory.
43499 */
43500+
43501+#ifdef CONFIG_PAX_PER_CPU_PGD
43502+ pages->state.host_cr3 = read_cr3();
43503+#else
43504 pages->state.host_cr3 = __pa(current->mm->pgd);
43505+#endif
43506+
43507 /*
43508 * Set up the Guest's page tables to see this CPU's pages (and no
43509 * other CPU's pages).
43510@@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43511 * compiled-in switcher code and the high-mapped copy we just made.
43512 */
43513 for (i = 0; i < IDT_ENTRIES; i++)
43514- default_idt_entries[i] += switcher_offset();
43515+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43516
43517 /*
43518 * Set up the Switcher's per-cpu areas.
43519@@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43520 * it will be undisturbed when we switch. To change %cs and jump we
43521 * need this structure to feed to Intel's "lcall" instruction.
43522 */
43523- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43524+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43525 lguest_entry.segment = LGUEST_CS;
43526
43527 /*
43528diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43529index 40634b0..4f5855e 100644
43530--- a/drivers/lguest/x86/switcher_32.S
43531+++ b/drivers/lguest/x86/switcher_32.S
43532@@ -87,6 +87,7 @@
43533 #include <asm/page.h>
43534 #include <asm/segment.h>
43535 #include <asm/lguest.h>
43536+#include <asm/processor-flags.h>
43537
43538 // We mark the start of the code to copy
43539 // It's placed in .text tho it's never run here
43540@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43541 // Changes type when we load it: damn Intel!
43542 // For after we switch over our page tables
43543 // That entry will be read-only: we'd crash.
43544+
43545+#ifdef CONFIG_PAX_KERNEXEC
43546+ mov %cr0, %edx
43547+ xor $X86_CR0_WP, %edx
43548+ mov %edx, %cr0
43549+#endif
43550+
43551 movl $(GDT_ENTRY_TSS*8), %edx
43552 ltr %dx
43553
43554@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43555 // Let's clear it again for our return.
43556 // The GDT descriptor of the Host
43557 // Points to the table after two "size" bytes
43558- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43559+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43560 // Clear "used" from type field (byte 5, bit 2)
43561- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43562+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43563+
43564+#ifdef CONFIG_PAX_KERNEXEC
43565+ mov %cr0, %eax
43566+ xor $X86_CR0_WP, %eax
43567+ mov %eax, %cr0
43568+#endif
43569
43570 // Once our page table's switched, the Guest is live!
43571 // The Host fades as we run this final step.
43572@@ -295,13 +309,12 @@ deliver_to_host:
43573 // I consulted gcc, and it gave
43574 // These instructions, which I gladly credit:
43575 leal (%edx,%ebx,8), %eax
43576- movzwl (%eax),%edx
43577- movl 4(%eax), %eax
43578- xorw %ax, %ax
43579- orl %eax, %edx
43580+ movl 4(%eax), %edx
43581+ movw (%eax), %dx
43582 // Now the address of the handler's in %edx
43583 // We call it now: its "iret" drops us home.
43584- jmp *%edx
43585+ ljmp $__KERNEL_CS, $1f
43586+1: jmp *%edx
43587
43588 // Every interrupt can come to us here
43589 // But we must truly tell each apart.
43590diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43591index 9762f1b..3e79734 100644
43592--- a/drivers/md/bcache/closure.h
43593+++ b/drivers/md/bcache/closure.h
43594@@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43595 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43596 struct workqueue_struct *wq)
43597 {
43598- BUG_ON(object_is_on_stack(cl));
43599+ BUG_ON(object_starts_on_stack(cl));
43600 closure_set_ip(cl);
43601 cl->fn = fn;
43602 cl->wq = wq;
43603diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43604index 12dc29b..1596277 100644
43605--- a/drivers/md/bitmap.c
43606+++ b/drivers/md/bitmap.c
43607@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43608 chunk_kb ? "KB" : "B");
43609 if (bitmap->storage.file) {
43610 seq_printf(seq, ", file: ");
43611- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43612+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43613 }
43614
43615 seq_printf(seq, "\n");
43616diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43617index 5152142..623d141 100644
43618--- a/drivers/md/dm-ioctl.c
43619+++ b/drivers/md/dm-ioctl.c
43620@@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43621 cmd == DM_LIST_VERSIONS_CMD)
43622 return 0;
43623
43624- if ((cmd == DM_DEV_CREATE_CMD)) {
43625+ if (cmd == DM_DEV_CREATE_CMD) {
43626 if (!*param->name) {
43627 DMWARN("name not supplied when creating device");
43628 return -EINVAL;
43629diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43630index 9584443..9fc9ac9 100644
43631--- a/drivers/md/dm-raid1.c
43632+++ b/drivers/md/dm-raid1.c
43633@@ -40,7 +40,7 @@ enum dm_raid1_error {
43634
43635 struct mirror {
43636 struct mirror_set *ms;
43637- atomic_t error_count;
43638+ atomic_unchecked_t error_count;
43639 unsigned long error_type;
43640 struct dm_dev *dev;
43641 sector_t offset;
43642@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43643 struct mirror *m;
43644
43645 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43646- if (!atomic_read(&m->error_count))
43647+ if (!atomic_read_unchecked(&m->error_count))
43648 return m;
43649
43650 return NULL;
43651@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43652 * simple way to tell if a device has encountered
43653 * errors.
43654 */
43655- atomic_inc(&m->error_count);
43656+ atomic_inc_unchecked(&m->error_count);
43657
43658 if (test_and_set_bit(error_type, &m->error_type))
43659 return;
43660@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43661 struct mirror *m = get_default_mirror(ms);
43662
43663 do {
43664- if (likely(!atomic_read(&m->error_count)))
43665+ if (likely(!atomic_read_unchecked(&m->error_count)))
43666 return m;
43667
43668 if (m-- == ms->mirror)
43669@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43670 {
43671 struct mirror *default_mirror = get_default_mirror(m->ms);
43672
43673- return !atomic_read(&default_mirror->error_count);
43674+ return !atomic_read_unchecked(&default_mirror->error_count);
43675 }
43676
43677 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43678@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43679 */
43680 if (likely(region_in_sync(ms, region, 1)))
43681 m = choose_mirror(ms, bio->bi_sector);
43682- else if (m && atomic_read(&m->error_count))
43683+ else if (m && atomic_read_unchecked(&m->error_count))
43684 m = NULL;
43685
43686 if (likely(m))
43687@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43688 }
43689
43690 ms->mirror[mirror].ms = ms;
43691- atomic_set(&(ms->mirror[mirror].error_count), 0);
43692+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43693 ms->mirror[mirror].error_type = 0;
43694 ms->mirror[mirror].offset = offset;
43695
43696@@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43697 */
43698 static char device_status_char(struct mirror *m)
43699 {
43700- if (!atomic_read(&(m->error_count)))
43701+ if (!atomic_read_unchecked(&(m->error_count)))
43702 return 'A';
43703
43704 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43705diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43706index 28a9012..9c0f6a5 100644
43707--- a/drivers/md/dm-stats.c
43708+++ b/drivers/md/dm-stats.c
43709@@ -382,7 +382,7 @@ do_sync_free:
43710 synchronize_rcu_expedited();
43711 dm_stat_free(&s->rcu_head);
43712 } else {
43713- ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43714+ ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43715 call_rcu(&s->rcu_head, dm_stat_free);
43716 }
43717 return 0;
43718@@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43719 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43720 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43721 ));
43722- ACCESS_ONCE(last->last_sector) = end_sector;
43723- ACCESS_ONCE(last->last_rw) = bi_rw;
43724+ ACCESS_ONCE_RW(last->last_sector) = end_sector;
43725+ ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43726 }
43727
43728 rcu_read_lock();
43729diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43730index 73c1712..7347292 100644
43731--- a/drivers/md/dm-stripe.c
43732+++ b/drivers/md/dm-stripe.c
43733@@ -21,7 +21,7 @@ struct stripe {
43734 struct dm_dev *dev;
43735 sector_t physical_start;
43736
43737- atomic_t error_count;
43738+ atomic_unchecked_t error_count;
43739 };
43740
43741 struct stripe_c {
43742@@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43743 kfree(sc);
43744 return r;
43745 }
43746- atomic_set(&(sc->stripe[i].error_count), 0);
43747+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43748 }
43749
43750 ti->private = sc;
43751@@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43752 DMEMIT("%d ", sc->stripes);
43753 for (i = 0; i < sc->stripes; i++) {
43754 DMEMIT("%s ", sc->stripe[i].dev->name);
43755- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43756+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43757 'D' : 'A';
43758 }
43759 buffer[i] = '\0';
43760@@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43761 */
43762 for (i = 0; i < sc->stripes; i++)
43763 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43764- atomic_inc(&(sc->stripe[i].error_count));
43765- if (atomic_read(&(sc->stripe[i].error_count)) <
43766+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
43767+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43768 DM_IO_ERROR_THRESHOLD)
43769 schedule_work(&sc->trigger_event);
43770 }
43771diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43772index 3ba6a38..b0fa9b0 100644
43773--- a/drivers/md/dm-table.c
43774+++ b/drivers/md/dm-table.c
43775@@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43776 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43777 struct mapped_device *md)
43778 {
43779- static char *_claim_ptr = "I belong to device-mapper";
43780+ static char _claim_ptr[] = "I belong to device-mapper";
43781 struct block_device *bdev;
43782
43783 int r;
43784@@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43785 if (!dev_size)
43786 return 0;
43787
43788- if ((start >= dev_size) || (start + len > dev_size)) {
43789+ if ((start >= dev_size) || (len > dev_size - start)) {
43790 DMWARN("%s: %s too small for target: "
43791 "start=%llu, len=%llu, dev_size=%llu",
43792 dm_device_name(ti->table->md), bdevname(bdev, b),
43793diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43794index 3bb4506..56e20cc 100644
43795--- a/drivers/md/dm-thin-metadata.c
43796+++ b/drivers/md/dm-thin-metadata.c
43797@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43798 {
43799 pmd->info.tm = pmd->tm;
43800 pmd->info.levels = 2;
43801- pmd->info.value_type.context = pmd->data_sm;
43802+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43803 pmd->info.value_type.size = sizeof(__le64);
43804 pmd->info.value_type.inc = data_block_inc;
43805 pmd->info.value_type.dec = data_block_dec;
43806@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43807
43808 pmd->bl_info.tm = pmd->tm;
43809 pmd->bl_info.levels = 1;
43810- pmd->bl_info.value_type.context = pmd->data_sm;
43811+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43812 pmd->bl_info.value_type.size = sizeof(__le64);
43813 pmd->bl_info.value_type.inc = data_block_inc;
43814 pmd->bl_info.value_type.dec = data_block_dec;
43815diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43816index b49c762..c9503cf 100644
43817--- a/drivers/md/dm.c
43818+++ b/drivers/md/dm.c
43819@@ -185,9 +185,9 @@ struct mapped_device {
43820 /*
43821 * Event handling.
43822 */
43823- atomic_t event_nr;
43824+ atomic_unchecked_t event_nr;
43825 wait_queue_head_t eventq;
43826- atomic_t uevent_seq;
43827+ atomic_unchecked_t uevent_seq;
43828 struct list_head uevent_list;
43829 spinlock_t uevent_lock; /* Protect access to uevent_list */
43830
43831@@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43832 spin_lock_init(&md->deferred_lock);
43833 atomic_set(&md->holders, 1);
43834 atomic_set(&md->open_count, 0);
43835- atomic_set(&md->event_nr, 0);
43836- atomic_set(&md->uevent_seq, 0);
43837+ atomic_set_unchecked(&md->event_nr, 0);
43838+ atomic_set_unchecked(&md->uevent_seq, 0);
43839 INIT_LIST_HEAD(&md->uevent_list);
43840 spin_lock_init(&md->uevent_lock);
43841
43842@@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43843
43844 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43845
43846- atomic_inc(&md->event_nr);
43847+ atomic_inc_unchecked(&md->event_nr);
43848 wake_up(&md->eventq);
43849 }
43850
43851@@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43852
43853 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43854 {
43855- return atomic_add_return(1, &md->uevent_seq);
43856+ return atomic_add_return_unchecked(1, &md->uevent_seq);
43857 }
43858
43859 uint32_t dm_get_event_nr(struct mapped_device *md)
43860 {
43861- return atomic_read(&md->event_nr);
43862+ return atomic_read_unchecked(&md->event_nr);
43863 }
43864
43865 int dm_wait_event(struct mapped_device *md, int event_nr)
43866 {
43867 return wait_event_interruptible(md->eventq,
43868- (event_nr != atomic_read(&md->event_nr)));
43869+ (event_nr != atomic_read_unchecked(&md->event_nr)));
43870 }
43871
43872 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43873diff --git a/drivers/md/md.c b/drivers/md/md.c
43874index 369d919..ba7049c 100644
43875--- a/drivers/md/md.c
43876+++ b/drivers/md/md.c
43877@@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43878 * start build, activate spare
43879 */
43880 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43881-static atomic_t md_event_count;
43882+static atomic_unchecked_t md_event_count;
43883 void md_new_event(struct mddev *mddev)
43884 {
43885- atomic_inc(&md_event_count);
43886+ atomic_inc_unchecked(&md_event_count);
43887 wake_up(&md_event_waiters);
43888 }
43889 EXPORT_SYMBOL_GPL(md_new_event);
43890@@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43891 */
43892 static void md_new_event_inintr(struct mddev *mddev)
43893 {
43894- atomic_inc(&md_event_count);
43895+ atomic_inc_unchecked(&md_event_count);
43896 wake_up(&md_event_waiters);
43897 }
43898
43899@@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43900 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43901 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43902 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43903- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43904+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43905
43906 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43907 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43908@@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43909 else
43910 sb->resync_offset = cpu_to_le64(0);
43911
43912- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43913+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43914
43915 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43916 sb->size = cpu_to_le64(mddev->dev_sectors);
43917@@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43918 static ssize_t
43919 errors_show(struct md_rdev *rdev, char *page)
43920 {
43921- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43922+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43923 }
43924
43925 static ssize_t
43926@@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43927 char *e;
43928 unsigned long n = simple_strtoul(buf, &e, 10);
43929 if (*buf && (*e == 0 || *e == '\n')) {
43930- atomic_set(&rdev->corrected_errors, n);
43931+ atomic_set_unchecked(&rdev->corrected_errors, n);
43932 return len;
43933 }
43934 return -EINVAL;
43935@@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43936 rdev->sb_loaded = 0;
43937 rdev->bb_page = NULL;
43938 atomic_set(&rdev->nr_pending, 0);
43939- atomic_set(&rdev->read_errors, 0);
43940- atomic_set(&rdev->corrected_errors, 0);
43941+ atomic_set_unchecked(&rdev->read_errors, 0);
43942+ atomic_set_unchecked(&rdev->corrected_errors, 0);
43943
43944 INIT_LIST_HEAD(&rdev->same_set);
43945 init_waitqueue_head(&rdev->blocked_wait);
43946@@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43947
43948 spin_unlock(&pers_lock);
43949 seq_printf(seq, "\n");
43950- seq->poll_event = atomic_read(&md_event_count);
43951+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43952 return 0;
43953 }
43954 if (v == (void*)2) {
43955@@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43956 return error;
43957
43958 seq = file->private_data;
43959- seq->poll_event = atomic_read(&md_event_count);
43960+ seq->poll_event = atomic_read_unchecked(&md_event_count);
43961 return error;
43962 }
43963
43964@@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43965 /* always allow read */
43966 mask = POLLIN | POLLRDNORM;
43967
43968- if (seq->poll_event != atomic_read(&md_event_count))
43969+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43970 mask |= POLLERR | POLLPRI;
43971 return mask;
43972 }
43973@@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43974 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43975 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43976 (int)part_stat_read(&disk->part0, sectors[1]) -
43977- atomic_read(&disk->sync_io);
43978+ atomic_read_unchecked(&disk->sync_io);
43979 /* sync IO will cause sync_io to increase before the disk_stats
43980 * as sync_io is counted when a request starts, and
43981 * disk_stats is counted when it completes.
43982diff --git a/drivers/md/md.h b/drivers/md/md.h
43983index 0095ec8..c89277a 100644
43984--- a/drivers/md/md.h
43985+++ b/drivers/md/md.h
43986@@ -94,13 +94,13 @@ struct md_rdev {
43987 * only maintained for arrays that
43988 * support hot removal
43989 */
43990- atomic_t read_errors; /* number of consecutive read errors that
43991+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
43992 * we have tried to ignore.
43993 */
43994 struct timespec last_read_error; /* monotonic time since our
43995 * last read error
43996 */
43997- atomic_t corrected_errors; /* number of corrected read errors,
43998+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43999 * for reporting to userspace and storing
44000 * in superblock.
44001 */
44002@@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44003
44004 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44005 {
44006- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44007+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44008 }
44009
44010 struct md_personality
44011diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44012index 579b582..9fb6185 100644
44013--- a/drivers/md/persistent-data/dm-space-map-metadata.c
44014+++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44015@@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44016 * Flick into a mode where all blocks get allocated in the new area.
44017 */
44018 smm->begin = old_len;
44019- memcpy(sm, &bootstrap_ops, sizeof(*sm));
44020+ memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44021
44022 /*
44023 * Extend.
44024@@ -710,7 +710,7 @@ out:
44025 /*
44026 * Switch back to normal behaviour.
44027 */
44028- memcpy(sm, &ops, sizeof(*sm));
44029+ memcpy((void *)sm, &ops, sizeof(*sm));
44030 return r;
44031 }
44032
44033diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44034index 3e6d115..ffecdeb 100644
44035--- a/drivers/md/persistent-data/dm-space-map.h
44036+++ b/drivers/md/persistent-data/dm-space-map.h
44037@@ -71,6 +71,7 @@ struct dm_space_map {
44038 dm_sm_threshold_fn fn,
44039 void *context);
44040 };
44041+typedef struct dm_space_map __no_const dm_space_map_no_const;
44042
44043 /*----------------------------------------------------------------*/
44044
44045diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44046index 63b2e8d..225f16b 100644
44047--- a/drivers/md/raid1.c
44048+++ b/drivers/md/raid1.c
44049@@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44050 if (r1_sync_page_io(rdev, sect, s,
44051 bio->bi_io_vec[idx].bv_page,
44052 READ) != 0)
44053- atomic_add(s, &rdev->corrected_errors);
44054+ atomic_add_unchecked(s, &rdev->corrected_errors);
44055 }
44056 sectors -= s;
44057 sect += s;
44058@@ -2155,7 +2155,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44059 test_bit(In_sync, &rdev->flags)) {
44060 if (r1_sync_page_io(rdev, sect, s,
44061 conf->tmppage, READ)) {
44062- atomic_add(s, &rdev->corrected_errors);
44063+ atomic_add_unchecked(s, &rdev->corrected_errors);
44064 printk(KERN_INFO
44065 "md/raid1:%s: read error corrected "
44066 "(%d sectors at %llu on %s)\n",
44067diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44068index 06eeb99..770613e 100644
44069--- a/drivers/md/raid10.c
44070+++ b/drivers/md/raid10.c
44071@@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
44072 /* The write handler will notice the lack of
44073 * R10BIO_Uptodate and record any errors etc
44074 */
44075- atomic_add(r10_bio->sectors,
44076+ atomic_add_unchecked(r10_bio->sectors,
44077 &conf->mirrors[d].rdev->corrected_errors);
44078
44079 /* for reconstruct, we always reschedule after a read.
44080@@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44081 {
44082 struct timespec cur_time_mon;
44083 unsigned long hours_since_last;
44084- unsigned int read_errors = atomic_read(&rdev->read_errors);
44085+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44086
44087 ktime_get_ts(&cur_time_mon);
44088
44089@@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44090 * overflowing the shift of read_errors by hours_since_last.
44091 */
44092 if (hours_since_last >= 8 * sizeof(read_errors))
44093- atomic_set(&rdev->read_errors, 0);
44094+ atomic_set_unchecked(&rdev->read_errors, 0);
44095 else
44096- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44097+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44098 }
44099
44100 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44101@@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44102 return;
44103
44104 check_decay_read_errors(mddev, rdev);
44105- atomic_inc(&rdev->read_errors);
44106- if (atomic_read(&rdev->read_errors) > max_read_errors) {
44107+ atomic_inc_unchecked(&rdev->read_errors);
44108+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44109 char b[BDEVNAME_SIZE];
44110 bdevname(rdev->bdev, b);
44111
44112@@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44113 "md/raid10:%s: %s: Raid device exceeded "
44114 "read_error threshold [cur %d:max %d]\n",
44115 mdname(mddev), b,
44116- atomic_read(&rdev->read_errors), max_read_errors);
44117+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44118 printk(KERN_NOTICE
44119 "md/raid10:%s: %s: Failing raid device\n",
44120 mdname(mddev), b);
44121@@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44122 sect +
44123 choose_data_offset(r10_bio, rdev)),
44124 bdevname(rdev->bdev, b));
44125- atomic_add(s, &rdev->corrected_errors);
44126+ atomic_add_unchecked(s, &rdev->corrected_errors);
44127 }
44128
44129 rdev_dec_pending(rdev, mddev);
44130diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44131index 48cdec8..c7726b1 100644
44132--- a/drivers/md/raid5.c
44133+++ b/drivers/md/raid5.c
44134@@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44135 mdname(conf->mddev), STRIPE_SECTORS,
44136 (unsigned long long)s,
44137 bdevname(rdev->bdev, b));
44138- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44139+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44140 clear_bit(R5_ReadError, &sh->dev[i].flags);
44141 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44142 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44143 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44144
44145- if (atomic_read(&rdev->read_errors))
44146- atomic_set(&rdev->read_errors, 0);
44147+ if (atomic_read_unchecked(&rdev->read_errors))
44148+ atomic_set_unchecked(&rdev->read_errors, 0);
44149 } else {
44150 const char *bdn = bdevname(rdev->bdev, b);
44151 int retry = 0;
44152 int set_bad = 0;
44153
44154 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44155- atomic_inc(&rdev->read_errors);
44156+ atomic_inc_unchecked(&rdev->read_errors);
44157 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44158 printk_ratelimited(
44159 KERN_WARNING
44160@@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44161 mdname(conf->mddev),
44162 (unsigned long long)s,
44163 bdn);
44164- } else if (atomic_read(&rdev->read_errors)
44165+ } else if (atomic_read_unchecked(&rdev->read_errors)
44166 > conf->max_nr_stripes)
44167 printk(KERN_WARNING
44168 "md/raid:%s: Too many read errors, failing device %s.\n",
44169diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44170index 983db75..ef9248c 100644
44171--- a/drivers/media/dvb-core/dvbdev.c
44172+++ b/drivers/media/dvb-core/dvbdev.c
44173@@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44174 const struct dvb_device *template, void *priv, int type)
44175 {
44176 struct dvb_device *dvbdev;
44177- struct file_operations *dvbdevfops;
44178+ file_operations_no_const *dvbdevfops;
44179 struct device *clsdev;
44180 int minor;
44181 int id;
44182diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44183index 9b6c3bb..baeb5c7 100644
44184--- a/drivers/media/dvb-frontends/dib3000.h
44185+++ b/drivers/media/dvb-frontends/dib3000.h
44186@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44187 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44188 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44189 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44190-};
44191+} __no_const;
44192
44193 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44194 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44195diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44196index ed8cb90..5ef7f79 100644
44197--- a/drivers/media/pci/cx88/cx88-video.c
44198+++ b/drivers/media/pci/cx88/cx88-video.c
44199@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44200
44201 /* ------------------------------------------------------------------ */
44202
44203-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44204-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44205-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44206+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44207+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44208+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44209
44210 module_param_array(video_nr, int, NULL, 0444);
44211 module_param_array(vbi_nr, int, NULL, 0444);
44212diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44213index 802642d..5534900 100644
44214--- a/drivers/media/pci/ivtv/ivtv-driver.c
44215+++ b/drivers/media/pci/ivtv/ivtv-driver.c
44216@@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44217 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44218
44219 /* ivtv instance counter */
44220-static atomic_t ivtv_instance = ATOMIC_INIT(0);
44221+static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44222
44223 /* Parameter declarations */
44224 static int cardtype[IVTV_MAX_CARDS];
44225diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44226index dfd0a21..6bbb465 100644
44227--- a/drivers/media/platform/omap/omap_vout.c
44228+++ b/drivers/media/platform/omap/omap_vout.c
44229@@ -63,7 +63,6 @@ enum omap_vout_channels {
44230 OMAP_VIDEO2,
44231 };
44232
44233-static struct videobuf_queue_ops video_vbq_ops;
44234 /* Variables configurable through module params*/
44235 static u32 video1_numbuffers = 3;
44236 static u32 video2_numbuffers = 3;
44237@@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
44238 {
44239 struct videobuf_queue *q;
44240 struct omap_vout_device *vout = NULL;
44241+ static struct videobuf_queue_ops video_vbq_ops = {
44242+ .buf_setup = omap_vout_buffer_setup,
44243+ .buf_prepare = omap_vout_buffer_prepare,
44244+ .buf_release = omap_vout_buffer_release,
44245+ .buf_queue = omap_vout_buffer_queue,
44246+ };
44247
44248 vout = video_drvdata(file);
44249 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44250@@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
44251 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44252
44253 q = &vout->vbq;
44254- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44255- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44256- video_vbq_ops.buf_release = omap_vout_buffer_release;
44257- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44258 spin_lock_init(&vout->vbq_lock);
44259
44260 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44261diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44262index fb2acc5..a2fcbdc4 100644
44263--- a/drivers/media/platform/s5p-tv/mixer.h
44264+++ b/drivers/media/platform/s5p-tv/mixer.h
44265@@ -156,7 +156,7 @@ struct mxr_layer {
44266 /** layer index (unique identifier) */
44267 int idx;
44268 /** callbacks for layer methods */
44269- struct mxr_layer_ops ops;
44270+ struct mxr_layer_ops *ops;
44271 /** format array */
44272 const struct mxr_format **fmt_array;
44273 /** size of format array */
44274diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44275index 74344c7..a39e70e 100644
44276--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44277+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44278@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44279 {
44280 struct mxr_layer *layer;
44281 int ret;
44282- struct mxr_layer_ops ops = {
44283+ static struct mxr_layer_ops ops = {
44284 .release = mxr_graph_layer_release,
44285 .buffer_set = mxr_graph_buffer_set,
44286 .stream_set = mxr_graph_stream_set,
44287diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44288index b713403..53cb5ad 100644
44289--- a/drivers/media/platform/s5p-tv/mixer_reg.c
44290+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44291@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44292 layer->update_buf = next;
44293 }
44294
44295- layer->ops.buffer_set(layer, layer->update_buf);
44296+ layer->ops->buffer_set(layer, layer->update_buf);
44297
44298 if (done && done != layer->shadow_buf)
44299 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44300diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44301index 81b97db..b089ccd 100644
44302--- a/drivers/media/platform/s5p-tv/mixer_video.c
44303+++ b/drivers/media/platform/s5p-tv/mixer_video.c
44304@@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44305 layer->geo.src.height = layer->geo.src.full_height;
44306
44307 mxr_geometry_dump(mdev, &layer->geo);
44308- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44309+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44310 mxr_geometry_dump(mdev, &layer->geo);
44311 }
44312
44313@@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44314 layer->geo.dst.full_width = mbus_fmt.width;
44315 layer->geo.dst.full_height = mbus_fmt.height;
44316 layer->geo.dst.field = mbus_fmt.field;
44317- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44318+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44319
44320 mxr_geometry_dump(mdev, &layer->geo);
44321 }
44322@@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44323 /* set source size to highest accepted value */
44324 geo->src.full_width = max(geo->dst.full_width, pix->width);
44325 geo->src.full_height = max(geo->dst.full_height, pix->height);
44326- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44327+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44328 mxr_geometry_dump(mdev, &layer->geo);
44329 /* set cropping to total visible screen */
44330 geo->src.width = pix->width;
44331@@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44332 geo->src.x_offset = 0;
44333 geo->src.y_offset = 0;
44334 /* assure consistency of geometry */
44335- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44336+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44337 mxr_geometry_dump(mdev, &layer->geo);
44338 /* set full size to lowest possible value */
44339 geo->src.full_width = 0;
44340 geo->src.full_height = 0;
44341- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44342+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44343 mxr_geometry_dump(mdev, &layer->geo);
44344
44345 /* returning results */
44346@@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44347 target->width = s->r.width;
44348 target->height = s->r.height;
44349
44350- layer->ops.fix_geometry(layer, stage, s->flags);
44351+ layer->ops->fix_geometry(layer, stage, s->flags);
44352
44353 /* retrieve update selection rectangle */
44354 res.left = target->x_offset;
44355@@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44356 mxr_output_get(mdev);
44357
44358 mxr_layer_update_output(layer);
44359- layer->ops.format_set(layer);
44360+ layer->ops->format_set(layer);
44361 /* enabling layer in hardware */
44362 spin_lock_irqsave(&layer->enq_slock, flags);
44363 layer->state = MXR_LAYER_STREAMING;
44364 spin_unlock_irqrestore(&layer->enq_slock, flags);
44365
44366- layer->ops.stream_set(layer, MXR_ENABLE);
44367+ layer->ops->stream_set(layer, MXR_ENABLE);
44368 mxr_streamer_get(mdev);
44369
44370 return 0;
44371@@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
44372 spin_unlock_irqrestore(&layer->enq_slock, flags);
44373
44374 /* disabling layer in hardware */
44375- layer->ops.stream_set(layer, MXR_DISABLE);
44376+ layer->ops->stream_set(layer, MXR_DISABLE);
44377 /* remove one streamer */
44378 mxr_streamer_put(mdev);
44379 /* allow changes in output configuration */
44380@@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44381
44382 void mxr_layer_release(struct mxr_layer *layer)
44383 {
44384- if (layer->ops.release)
44385- layer->ops.release(layer);
44386+ if (layer->ops->release)
44387+ layer->ops->release(layer);
44388 }
44389
44390 void mxr_base_layer_release(struct mxr_layer *layer)
44391@@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44392
44393 layer->mdev = mdev;
44394 layer->idx = idx;
44395- layer->ops = *ops;
44396+ layer->ops = ops;
44397
44398 spin_lock_init(&layer->enq_slock);
44399 INIT_LIST_HEAD(&layer->enq_list);
44400diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44401index c9388c4..ce71ece 100644
44402--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44403+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44404@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44405 {
44406 struct mxr_layer *layer;
44407 int ret;
44408- struct mxr_layer_ops ops = {
44409+ static struct mxr_layer_ops ops = {
44410 .release = mxr_vp_layer_release,
44411 .buffer_set = mxr_vp_buffer_set,
44412 .stream_set = mxr_vp_stream_set,
44413diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44414index 2d4e73b..8b4d5b6 100644
44415--- a/drivers/media/platform/vivi.c
44416+++ b/drivers/media/platform/vivi.c
44417@@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44418 MODULE_LICENSE("Dual BSD/GPL");
44419 MODULE_VERSION(VIVI_VERSION);
44420
44421-static unsigned video_nr = -1;
44422-module_param(video_nr, uint, 0644);
44423+static int video_nr = -1;
44424+module_param(video_nr, int, 0644);
44425 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44426
44427 static unsigned n_devs = 1;
44428diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44429index 545c04c..a14bded 100644
44430--- a/drivers/media/radio/radio-cadet.c
44431+++ b/drivers/media/radio/radio-cadet.c
44432@@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44433 unsigned char readbuf[RDS_BUFFER];
44434 int i = 0;
44435
44436+ if (count > RDS_BUFFER)
44437+ return -EFAULT;
44438 mutex_lock(&dev->lock);
44439 if (dev->rdsstat == 0)
44440 cadet_start_rds(dev);
44441@@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44442 while (i < count && dev->rdsin != dev->rdsout)
44443 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44444
44445- if (i && copy_to_user(data, readbuf, i))
44446+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
44447 i = -EFAULT;
44448 unlock:
44449 mutex_unlock(&dev->lock);
44450diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44451index 5236035..c622c74 100644
44452--- a/drivers/media/radio/radio-maxiradio.c
44453+++ b/drivers/media/radio/radio-maxiradio.c
44454@@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44455 /* TEA5757 pin mappings */
44456 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44457
44458-static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44459+static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44460
44461 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44462 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44463diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44464index 050b3bb..79f62b9 100644
44465--- a/drivers/media/radio/radio-shark.c
44466+++ b/drivers/media/radio/radio-shark.c
44467@@ -79,7 +79,7 @@ struct shark_device {
44468 u32 last_val;
44469 };
44470
44471-static atomic_t shark_instance = ATOMIC_INIT(0);
44472+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44473
44474 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44475 {
44476diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44477index 8654e0d..0608a64 100644
44478--- a/drivers/media/radio/radio-shark2.c
44479+++ b/drivers/media/radio/radio-shark2.c
44480@@ -74,7 +74,7 @@ struct shark_device {
44481 u8 *transfer_buffer;
44482 };
44483
44484-static atomic_t shark_instance = ATOMIC_INIT(0);
44485+static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44486
44487 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44488 {
44489diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44490index 2fd9009..278cc1e 100644
44491--- a/drivers/media/radio/radio-si476x.c
44492+++ b/drivers/media/radio/radio-si476x.c
44493@@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44494 struct si476x_radio *radio;
44495 struct v4l2_ctrl *ctrl;
44496
44497- static atomic_t instance = ATOMIC_INIT(0);
44498+ static atomic_unchecked_t instance = ATOMIC_INIT(0);
44499
44500 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44501 if (!radio)
44502diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
44503index 46da365..3ba4206 100644
44504--- a/drivers/media/rc/rc-main.c
44505+++ b/drivers/media/rc/rc-main.c
44506@@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
44507 int rc_register_device(struct rc_dev *dev)
44508 {
44509 static bool raw_init = false; /* raw decoders loaded? */
44510- static atomic_t devno = ATOMIC_INIT(0);
44511+ static atomic_unchecked_t devno = ATOMIC_INIT(0);
44512 struct rc_map *rc_map;
44513 const char *path;
44514 int rc;
44515@@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
44516 */
44517 mutex_lock(&dev->lock);
44518
44519- dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
44520+ dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
44521 dev_set_name(&dev->dev, "rc%ld", dev->devno);
44522 dev_set_drvdata(&dev->dev, dev);
44523 rc = device_add(&dev->dev);
44524diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44525index a1c641e..3007da9 100644
44526--- a/drivers/media/usb/dvb-usb/cxusb.c
44527+++ b/drivers/media/usb/dvb-usb/cxusb.c
44528@@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44529
44530 struct dib0700_adapter_state {
44531 int (*set_param_save) (struct dvb_frontend *);
44532-};
44533+} __no_const;
44534
44535 static int dib7070_set_param_override(struct dvb_frontend *fe)
44536 {
44537diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44538index f272ed8..6289f9c 100644
44539--- a/drivers/media/usb/dvb-usb/dw2102.c
44540+++ b/drivers/media/usb/dvb-usb/dw2102.c
44541@@ -121,7 +121,7 @@ struct su3000_state {
44542
44543 struct s6x0_state {
44544 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44545-};
44546+} __no_const;
44547
44548 /* debug */
44549 static int dvb_usb_dw2102_debug;
44550diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44551index 8f7a6a4..eb0e1d4 100644
44552--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44553+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44554@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
44555 __u32 reserved;
44556 };
44557
44558-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44559+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44560 enum v4l2_memory memory)
44561 {
44562 void __user *up_pln;
44563@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44564 return 0;
44565 }
44566
44567-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44568+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44569 enum v4l2_memory memory)
44570 {
44571 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44572@@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44573 * by passing a very big num_planes value */
44574 uplane = compat_alloc_user_space(num_planes *
44575 sizeof(struct v4l2_plane));
44576- kp->m.planes = uplane;
44577+ kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44578
44579 while (--num_planes >= 0) {
44580 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44581@@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44582 if (num_planes == 0)
44583 return 0;
44584
44585- uplane = kp->m.planes;
44586+ uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44587 if (get_user(p, &up->m.planes))
44588 return -EFAULT;
44589 uplane32 = compat_ptr(p);
44590@@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44591 get_user(kp->capability, &up->capability) ||
44592 get_user(kp->flags, &up->flags))
44593 return -EFAULT;
44594- kp->base = compat_ptr(tmp);
44595+ kp->base = (void __force_kernel *)compat_ptr(tmp);
44596 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44597 return 0;
44598 }
44599@@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44600 n * sizeof(struct v4l2_ext_control32)))
44601 return -EFAULT;
44602 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44603- kp->controls = kcontrols;
44604+ kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44605 while (--n >= 0) {
44606 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44607 return -EFAULT;
44608@@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44609 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44610 {
44611 struct v4l2_ext_control32 __user *ucontrols;
44612- struct v4l2_ext_control __user *kcontrols = kp->controls;
44613+ struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44614 int n = kp->count;
44615 compat_caddr_t p;
44616
44617@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44618 put_user(kp->start_block, &up->start_block) ||
44619 put_user(kp->blocks, &up->blocks) ||
44620 put_user(tmp, &up->edid) ||
44621- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44622+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44623 return -EFAULT;
44624 return 0;
44625 }
44626diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44627index fb46790..ae1f8fa 100644
44628--- a/drivers/media/v4l2-core/v4l2-ctrls.c
44629+++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44630@@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44631 return 0;
44632
44633 case V4L2_CTRL_TYPE_STRING:
44634- len = strlen(c->string);
44635- if (len < ctrl->minimum)
44636+ len = strlen_user(c->string);
44637+ if (!len || len < ctrl->minimum)
44638 return -ERANGE;
44639 if ((len - ctrl->minimum) % ctrl->step)
44640 return -ERANGE;
44641diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44642index 02d1b63..5fd6b16 100644
44643--- a/drivers/media/v4l2-core/v4l2-device.c
44644+++ b/drivers/media/v4l2-core/v4l2-device.c
44645@@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44646 EXPORT_SYMBOL_GPL(v4l2_device_put);
44647
44648 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44649- atomic_t *instance)
44650+ atomic_unchecked_t *instance)
44651 {
44652- int num = atomic_inc_return(instance) - 1;
44653+ int num = atomic_inc_return_unchecked(instance) - 1;
44654 int len = strlen(basename);
44655
44656 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44657diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44658index 68e6b5e..8eb2aec 100644
44659--- a/drivers/media/v4l2-core/v4l2-ioctl.c
44660+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44661@@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44662 struct file *file, void *fh, void *p);
44663 } u;
44664 void (*debug)(const void *arg, bool write_only);
44665-};
44666+} __do_const;
44667+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44668
44669 /* This control needs a priority check */
44670 #define INFO_FL_PRIO (1 << 0)
44671@@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44672 struct video_device *vfd = video_devdata(file);
44673 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44674 bool write_only = false;
44675- struct v4l2_ioctl_info default_info;
44676+ v4l2_ioctl_info_no_const default_info;
44677 const struct v4l2_ioctl_info *info;
44678 void *fh = file->private_data;
44679 struct v4l2_fh *vfh = NULL;
44680@@ -2194,7 +2195,7 @@ done:
44681 }
44682
44683 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44684- void * __user *user_ptr, void ***kernel_ptr)
44685+ void __user **user_ptr, void ***kernel_ptr)
44686 {
44687 int ret = 0;
44688
44689@@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44690 ret = -EINVAL;
44691 break;
44692 }
44693- *user_ptr = (void __user *)buf->m.planes;
44694+ *user_ptr = (void __force_user *)buf->m.planes;
44695 *kernel_ptr = (void *)&buf->m.planes;
44696 *array_size = sizeof(struct v4l2_plane) * buf->length;
44697 ret = 1;
44698@@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44699 ret = -EINVAL;
44700 break;
44701 }
44702- *user_ptr = (void __user *)ctrls->controls;
44703+ *user_ptr = (void __force_user *)ctrls->controls;
44704 *kernel_ptr = (void *)&ctrls->controls;
44705 *array_size = sizeof(struct v4l2_ext_control)
44706 * ctrls->count;
44707@@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44708 err = -ENOTTY;
44709
44710 if (has_array_args) {
44711- *kernel_ptr = user_ptr;
44712+ *kernel_ptr = (void __force_kernel *)user_ptr;
44713 if (copy_to_user(user_ptr, mbuf, array_size))
44714 err = -EFAULT;
44715 goto out_array_args;
44716diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44717index 767ff4d..c69d259 100644
44718--- a/drivers/message/fusion/mptbase.c
44719+++ b/drivers/message/fusion/mptbase.c
44720@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44721 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44722 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44723
44724+#ifdef CONFIG_GRKERNSEC_HIDESYM
44725+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44726+#else
44727 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44728 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44729+#endif
44730+
44731 /*
44732 * Rounding UP to nearest 4-kB boundary here...
44733 */
44734@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44735 ioc->facts.GlobalCredits);
44736
44737 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44738+#ifdef CONFIG_GRKERNSEC_HIDESYM
44739+ NULL, NULL);
44740+#else
44741 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44742+#endif
44743 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44744 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44745 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44746diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44747index dd239bd..689c4f7 100644
44748--- a/drivers/message/fusion/mptsas.c
44749+++ b/drivers/message/fusion/mptsas.c
44750@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44751 return 0;
44752 }
44753
44754+static inline void
44755+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44756+{
44757+ if (phy_info->port_details) {
44758+ phy_info->port_details->rphy = rphy;
44759+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44760+ ioc->name, rphy));
44761+ }
44762+
44763+ if (rphy) {
44764+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44765+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44766+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44767+ ioc->name, rphy, rphy->dev.release));
44768+ }
44769+}
44770+
44771 /* no mutex */
44772 static void
44773 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44774@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44775 return NULL;
44776 }
44777
44778-static inline void
44779-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44780-{
44781- if (phy_info->port_details) {
44782- phy_info->port_details->rphy = rphy;
44783- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44784- ioc->name, rphy));
44785- }
44786-
44787- if (rphy) {
44788- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44789- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44790- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44791- ioc->name, rphy, rphy->dev.release));
44792- }
44793-}
44794-
44795 static inline struct sas_port *
44796 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44797 {
44798diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44799index 727819c..ad74694 100644
44800--- a/drivers/message/fusion/mptscsih.c
44801+++ b/drivers/message/fusion/mptscsih.c
44802@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44803
44804 h = shost_priv(SChost);
44805
44806- if (h) {
44807- if (h->info_kbuf == NULL)
44808- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44809- return h->info_kbuf;
44810- h->info_kbuf[0] = '\0';
44811+ if (!h)
44812+ return NULL;
44813
44814- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44815- h->info_kbuf[size-1] = '\0';
44816- }
44817+ if (h->info_kbuf == NULL)
44818+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44819+ return h->info_kbuf;
44820+ h->info_kbuf[0] = '\0';
44821+
44822+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44823+ h->info_kbuf[size-1] = '\0';
44824
44825 return h->info_kbuf;
44826 }
44827diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44828index b7d87cd..3fb36da 100644
44829--- a/drivers/message/i2o/i2o_proc.c
44830+++ b/drivers/message/i2o/i2o_proc.c
44831@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44832 "Array Controller Device"
44833 };
44834
44835-static char *chtostr(char *tmp, u8 *chars, int n)
44836-{
44837- tmp[0] = 0;
44838- return strncat(tmp, (char *)chars, n);
44839-}
44840-
44841 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44842 char *group)
44843 {
44844@@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44845 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44846 {
44847 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44848- static u32 work32[5];
44849- static u8 *work8 = (u8 *) work32;
44850- static u16 *work16 = (u16 *) work32;
44851+ u32 work32[5];
44852+ u8 *work8 = (u8 *) work32;
44853+ u16 *work16 = (u16 *) work32;
44854 int token;
44855 u32 hwcap;
44856
44857@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44858 } *result;
44859
44860 i2o_exec_execute_ddm_table ddm_table;
44861- char tmp[28 + 1];
44862
44863 result = kmalloc(sizeof(*result), GFP_KERNEL);
44864 if (!result)
44865@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44866
44867 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44868 seq_printf(seq, "%-#8x", ddm_table.module_id);
44869- seq_printf(seq, "%-29s",
44870- chtostr(tmp, ddm_table.module_name_version, 28));
44871+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44872 seq_printf(seq, "%9d ", ddm_table.data_size);
44873 seq_printf(seq, "%8d", ddm_table.code_size);
44874
44875@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44876
44877 i2o_driver_result_table *result;
44878 i2o_driver_store_table *dst;
44879- char tmp[28 + 1];
44880
44881 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44882 if (result == NULL)
44883@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44884
44885 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44886 seq_printf(seq, "%-#8x", dst->module_id);
44887- seq_printf(seq, "%-29s",
44888- chtostr(tmp, dst->module_name_version, 28));
44889- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44890+ seq_printf(seq, "%-.28s", dst->module_name_version);
44891+ seq_printf(seq, "%-.8s", dst->date);
44892 seq_printf(seq, "%8d ", dst->module_size);
44893 seq_printf(seq, "%8d ", dst->mpb_size);
44894 seq_printf(seq, "0x%04x", dst->module_flags);
44895@@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44896 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44897 {
44898 struct i2o_device *d = (struct i2o_device *)seq->private;
44899- static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44900+ u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44901 // == (allow) 512d bytes (max)
44902- static u16 *work16 = (u16 *) work32;
44903+ u16 *work16 = (u16 *) work32;
44904 int token;
44905- char tmp[16 + 1];
44906
44907 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44908
44909@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44910 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44911 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44912 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44913- seq_printf(seq, "Vendor info : %s\n",
44914- chtostr(tmp, (u8 *) (work32 + 2), 16));
44915- seq_printf(seq, "Product info : %s\n",
44916- chtostr(tmp, (u8 *) (work32 + 6), 16));
44917- seq_printf(seq, "Description : %s\n",
44918- chtostr(tmp, (u8 *) (work32 + 10), 16));
44919- seq_printf(seq, "Product rev. : %s\n",
44920- chtostr(tmp, (u8 *) (work32 + 14), 8));
44921+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44922+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44923+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44924+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44925
44926 seq_printf(seq, "Serial number : ");
44927 print_serial_number(seq, (u8 *) (work32 + 16),
44928@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44929 u8 pad[256]; // allow up to 256 byte (max) serial number
44930 } result;
44931
44932- char tmp[24 + 1];
44933-
44934 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44935
44936 if (token < 0) {
44937@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44938 }
44939
44940 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44941- seq_printf(seq, "Module name : %s\n",
44942- chtostr(tmp, result.module_name, 24));
44943- seq_printf(seq, "Module revision : %s\n",
44944- chtostr(tmp, result.module_rev, 8));
44945+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
44946+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44947
44948 seq_printf(seq, "Serial number : ");
44949 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44950@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44951 u8 instance_number[4];
44952 } result;
44953
44954- char tmp[64 + 1];
44955-
44956 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44957
44958 if (token < 0) {
44959@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44960 return 0;
44961 }
44962
44963- seq_printf(seq, "Device name : %s\n",
44964- chtostr(tmp, result.device_name, 64));
44965- seq_printf(seq, "Service name : %s\n",
44966- chtostr(tmp, result.service_name, 64));
44967- seq_printf(seq, "Physical name : %s\n",
44968- chtostr(tmp, result.physical_location, 64));
44969- seq_printf(seq, "Instance number : %s\n",
44970- chtostr(tmp, result.instance_number, 4));
44971+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
44972+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
44973+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44974+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44975
44976 return 0;
44977 }
44978@@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44979 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44980 {
44981 struct i2o_device *d = (struct i2o_device *)seq->private;
44982- static u32 work32[12];
44983- static u16 *work16 = (u16 *) work32;
44984- static u8 *work8 = (u8 *) work32;
44985+ u32 work32[12];
44986+ u16 *work16 = (u16 *) work32;
44987+ u8 *work8 = (u8 *) work32;
44988 int token;
44989
44990 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44991diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44992index a8c08f3..155fe3d 100644
44993--- a/drivers/message/i2o/iop.c
44994+++ b/drivers/message/i2o/iop.c
44995@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44996
44997 spin_lock_irqsave(&c->context_list_lock, flags);
44998
44999- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45000- atomic_inc(&c->context_list_counter);
45001+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45002+ atomic_inc_unchecked(&c->context_list_counter);
45003
45004- entry->context = atomic_read(&c->context_list_counter);
45005+ entry->context = atomic_read_unchecked(&c->context_list_counter);
45006
45007 list_add(&entry->list, &c->context_list);
45008
45009@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45010
45011 #if BITS_PER_LONG == 64
45012 spin_lock_init(&c->context_list_lock);
45013- atomic_set(&c->context_list_counter, 0);
45014+ atomic_set_unchecked(&c->context_list_counter, 0);
45015 INIT_LIST_HEAD(&c->context_list);
45016 #endif
45017
45018diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45019index e33e385..28dfd23 100644
45020--- a/drivers/mfd/ab8500-debugfs.c
45021+++ b/drivers/mfd/ab8500-debugfs.c
45022@@ -100,7 +100,7 @@ static int irq_last;
45023 static u32 *irq_count;
45024 static int num_irqs;
45025
45026-static struct device_attribute **dev_attr;
45027+static device_attribute_no_const **dev_attr;
45028 static char **event_name;
45029
45030 static u8 avg_sample = SAMPLE_16;
45031diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
45032index fcbb2e9..2635e11 100644
45033--- a/drivers/mfd/janz-cmodio.c
45034+++ b/drivers/mfd/janz-cmodio.c
45035@@ -13,6 +13,7 @@
45036
45037 #include <linux/kernel.h>
45038 #include <linux/module.h>
45039+#include <linux/slab.h>
45040 #include <linux/init.h>
45041 #include <linux/pci.h>
45042 #include <linux/interrupt.h>
45043diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45044index 176aa26..27811b2 100644
45045--- a/drivers/mfd/max8925-i2c.c
45046+++ b/drivers/mfd/max8925-i2c.c
45047@@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45048 const struct i2c_device_id *id)
45049 {
45050 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45051- static struct max8925_chip *chip;
45052+ struct max8925_chip *chip;
45053 struct device_node *node = client->dev.of_node;
45054
45055 if (node && !pdata) {
45056diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45057index c0f608e..286f8ec 100644
45058--- a/drivers/mfd/tps65910.c
45059+++ b/drivers/mfd/tps65910.c
45060@@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45061 struct tps65910_platform_data *pdata)
45062 {
45063 int ret = 0;
45064- static struct regmap_irq_chip *tps6591x_irqs_chip;
45065+ struct regmap_irq_chip *tps6591x_irqs_chip;
45066
45067 if (!irq) {
45068 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45069diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45070index 9aa6d1e..1631bfc 100644
45071--- a/drivers/mfd/twl4030-irq.c
45072+++ b/drivers/mfd/twl4030-irq.c
45073@@ -35,6 +35,7 @@
45074 #include <linux/of.h>
45075 #include <linux/irqdomain.h>
45076 #include <linux/i2c/twl.h>
45077+#include <asm/pgtable.h>
45078
45079 #include "twl-core.h"
45080
45081@@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45082 * Install an irq handler for each of the SIH modules;
45083 * clone dummy irq_chip since PIH can't *do* anything
45084 */
45085- twl4030_irq_chip = dummy_irq_chip;
45086- twl4030_irq_chip.name = "twl4030";
45087+ pax_open_kernel();
45088+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45089+ *(const char **)&twl4030_irq_chip.name = "twl4030";
45090
45091- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45092+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45093+ pax_close_kernel();
45094
45095 for (i = irq_base; i < irq_end; i++) {
45096 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45097diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45098index 464419b..64bae8d 100644
45099--- a/drivers/misc/c2port/core.c
45100+++ b/drivers/misc/c2port/core.c
45101@@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45102 goto error_idr_alloc;
45103 c2dev->id = ret;
45104
45105- bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45106+ pax_open_kernel();
45107+ *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45108+ pax_close_kernel();
45109
45110 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45111 "c2port%d", c2dev->id);
45112diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45113index 9c34e57..b981cda 100644
45114--- a/drivers/misc/eeprom/sunxi_sid.c
45115+++ b/drivers/misc/eeprom/sunxi_sid.c
45116@@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45117
45118 platform_set_drvdata(pdev, sid_data);
45119
45120- sid_bin_attr.size = sid_data->keysize;
45121+ pax_open_kernel();
45122+ *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45123+ pax_close_kernel();
45124 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45125 return -ENODEV;
45126
45127diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45128index 36f5d52..32311c3 100644
45129--- a/drivers/misc/kgdbts.c
45130+++ b/drivers/misc/kgdbts.c
45131@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45132 char before[BREAK_INSTR_SIZE];
45133 char after[BREAK_INSTR_SIZE];
45134
45135- probe_kernel_read(before, (char *)kgdbts_break_test,
45136+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45137 BREAK_INSTR_SIZE);
45138 init_simple_test();
45139 ts.tst = plant_and_detach_test;
45140@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45141 /* Activate test with initial breakpoint */
45142 if (!is_early)
45143 kgdb_breakpoint();
45144- probe_kernel_read(after, (char *)kgdbts_break_test,
45145+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45146 BREAK_INSTR_SIZE);
45147 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45148 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45149diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45150index 036effe..b3a6336 100644
45151--- a/drivers/misc/lis3lv02d/lis3lv02d.c
45152+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45153@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45154 * the lid is closed. This leads to interrupts as soon as a little move
45155 * is done.
45156 */
45157- atomic_inc(&lis3->count);
45158+ atomic_inc_unchecked(&lis3->count);
45159
45160 wake_up_interruptible(&lis3->misc_wait);
45161 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45162@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45163 if (lis3->pm_dev)
45164 pm_runtime_get_sync(lis3->pm_dev);
45165
45166- atomic_set(&lis3->count, 0);
45167+ atomic_set_unchecked(&lis3->count, 0);
45168 return 0;
45169 }
45170
45171@@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45172 add_wait_queue(&lis3->misc_wait, &wait);
45173 while (true) {
45174 set_current_state(TASK_INTERRUPTIBLE);
45175- data = atomic_xchg(&lis3->count, 0);
45176+ data = atomic_xchg_unchecked(&lis3->count, 0);
45177 if (data)
45178 break;
45179
45180@@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45181 struct lis3lv02d, miscdev);
45182
45183 poll_wait(file, &lis3->misc_wait, wait);
45184- if (atomic_read(&lis3->count))
45185+ if (atomic_read_unchecked(&lis3->count))
45186 return POLLIN | POLLRDNORM;
45187 return 0;
45188 }
45189diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45190index c439c82..1f20f57 100644
45191--- a/drivers/misc/lis3lv02d/lis3lv02d.h
45192+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45193@@ -297,7 +297,7 @@ struct lis3lv02d {
45194 struct input_polled_dev *idev; /* input device */
45195 struct platform_device *pdev; /* platform device */
45196 struct regulator_bulk_data regulators[2];
45197- atomic_t count; /* interrupt count after last read */
45198+ atomic_unchecked_t count; /* interrupt count after last read */
45199 union axis_conversion ac; /* hw -> logical axis */
45200 int mapped_btns[3];
45201
45202diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45203index 2f30bad..c4c13d0 100644
45204--- a/drivers/misc/sgi-gru/gruhandles.c
45205+++ b/drivers/misc/sgi-gru/gruhandles.c
45206@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45207 unsigned long nsec;
45208
45209 nsec = CLKS2NSEC(clks);
45210- atomic_long_inc(&mcs_op_statistics[op].count);
45211- atomic_long_add(nsec, &mcs_op_statistics[op].total);
45212+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45213+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45214 if (mcs_op_statistics[op].max < nsec)
45215 mcs_op_statistics[op].max = nsec;
45216 }
45217diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45218index 4f76359..cdfcb2e 100644
45219--- a/drivers/misc/sgi-gru/gruprocfs.c
45220+++ b/drivers/misc/sgi-gru/gruprocfs.c
45221@@ -32,9 +32,9 @@
45222
45223 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45224
45225-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45226+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45227 {
45228- unsigned long val = atomic_long_read(v);
45229+ unsigned long val = atomic_long_read_unchecked(v);
45230
45231 seq_printf(s, "%16lu %s\n", val, id);
45232 }
45233@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45234
45235 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45236 for (op = 0; op < mcsop_last; op++) {
45237- count = atomic_long_read(&mcs_op_statistics[op].count);
45238- total = atomic_long_read(&mcs_op_statistics[op].total);
45239+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45240+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45241 max = mcs_op_statistics[op].max;
45242 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45243 count ? total / count : 0, max);
45244diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45245index 5c3ce24..4915ccb 100644
45246--- a/drivers/misc/sgi-gru/grutables.h
45247+++ b/drivers/misc/sgi-gru/grutables.h
45248@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45249 * GRU statistics.
45250 */
45251 struct gru_stats_s {
45252- atomic_long_t vdata_alloc;
45253- atomic_long_t vdata_free;
45254- atomic_long_t gts_alloc;
45255- atomic_long_t gts_free;
45256- atomic_long_t gms_alloc;
45257- atomic_long_t gms_free;
45258- atomic_long_t gts_double_allocate;
45259- atomic_long_t assign_context;
45260- atomic_long_t assign_context_failed;
45261- atomic_long_t free_context;
45262- atomic_long_t load_user_context;
45263- atomic_long_t load_kernel_context;
45264- atomic_long_t lock_kernel_context;
45265- atomic_long_t unlock_kernel_context;
45266- atomic_long_t steal_user_context;
45267- atomic_long_t steal_kernel_context;
45268- atomic_long_t steal_context_failed;
45269- atomic_long_t nopfn;
45270- atomic_long_t asid_new;
45271- atomic_long_t asid_next;
45272- atomic_long_t asid_wrap;
45273- atomic_long_t asid_reuse;
45274- atomic_long_t intr;
45275- atomic_long_t intr_cbr;
45276- atomic_long_t intr_tfh;
45277- atomic_long_t intr_spurious;
45278- atomic_long_t intr_mm_lock_failed;
45279- atomic_long_t call_os;
45280- atomic_long_t call_os_wait_queue;
45281- atomic_long_t user_flush_tlb;
45282- atomic_long_t user_unload_context;
45283- atomic_long_t user_exception;
45284- atomic_long_t set_context_option;
45285- atomic_long_t check_context_retarget_intr;
45286- atomic_long_t check_context_unload;
45287- atomic_long_t tlb_dropin;
45288- atomic_long_t tlb_preload_page;
45289- atomic_long_t tlb_dropin_fail_no_asid;
45290- atomic_long_t tlb_dropin_fail_upm;
45291- atomic_long_t tlb_dropin_fail_invalid;
45292- atomic_long_t tlb_dropin_fail_range_active;
45293- atomic_long_t tlb_dropin_fail_idle;
45294- atomic_long_t tlb_dropin_fail_fmm;
45295- atomic_long_t tlb_dropin_fail_no_exception;
45296- atomic_long_t tfh_stale_on_fault;
45297- atomic_long_t mmu_invalidate_range;
45298- atomic_long_t mmu_invalidate_page;
45299- atomic_long_t flush_tlb;
45300- atomic_long_t flush_tlb_gru;
45301- atomic_long_t flush_tlb_gru_tgh;
45302- atomic_long_t flush_tlb_gru_zero_asid;
45303+ atomic_long_unchecked_t vdata_alloc;
45304+ atomic_long_unchecked_t vdata_free;
45305+ atomic_long_unchecked_t gts_alloc;
45306+ atomic_long_unchecked_t gts_free;
45307+ atomic_long_unchecked_t gms_alloc;
45308+ atomic_long_unchecked_t gms_free;
45309+ atomic_long_unchecked_t gts_double_allocate;
45310+ atomic_long_unchecked_t assign_context;
45311+ atomic_long_unchecked_t assign_context_failed;
45312+ atomic_long_unchecked_t free_context;
45313+ atomic_long_unchecked_t load_user_context;
45314+ atomic_long_unchecked_t load_kernel_context;
45315+ atomic_long_unchecked_t lock_kernel_context;
45316+ atomic_long_unchecked_t unlock_kernel_context;
45317+ atomic_long_unchecked_t steal_user_context;
45318+ atomic_long_unchecked_t steal_kernel_context;
45319+ atomic_long_unchecked_t steal_context_failed;
45320+ atomic_long_unchecked_t nopfn;
45321+ atomic_long_unchecked_t asid_new;
45322+ atomic_long_unchecked_t asid_next;
45323+ atomic_long_unchecked_t asid_wrap;
45324+ atomic_long_unchecked_t asid_reuse;
45325+ atomic_long_unchecked_t intr;
45326+ atomic_long_unchecked_t intr_cbr;
45327+ atomic_long_unchecked_t intr_tfh;
45328+ atomic_long_unchecked_t intr_spurious;
45329+ atomic_long_unchecked_t intr_mm_lock_failed;
45330+ atomic_long_unchecked_t call_os;
45331+ atomic_long_unchecked_t call_os_wait_queue;
45332+ atomic_long_unchecked_t user_flush_tlb;
45333+ atomic_long_unchecked_t user_unload_context;
45334+ atomic_long_unchecked_t user_exception;
45335+ atomic_long_unchecked_t set_context_option;
45336+ atomic_long_unchecked_t check_context_retarget_intr;
45337+ atomic_long_unchecked_t check_context_unload;
45338+ atomic_long_unchecked_t tlb_dropin;
45339+ atomic_long_unchecked_t tlb_preload_page;
45340+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45341+ atomic_long_unchecked_t tlb_dropin_fail_upm;
45342+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
45343+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
45344+ atomic_long_unchecked_t tlb_dropin_fail_idle;
45345+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
45346+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45347+ atomic_long_unchecked_t tfh_stale_on_fault;
45348+ atomic_long_unchecked_t mmu_invalidate_range;
45349+ atomic_long_unchecked_t mmu_invalidate_page;
45350+ atomic_long_unchecked_t flush_tlb;
45351+ atomic_long_unchecked_t flush_tlb_gru;
45352+ atomic_long_unchecked_t flush_tlb_gru_tgh;
45353+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45354
45355- atomic_long_t copy_gpa;
45356- atomic_long_t read_gpa;
45357+ atomic_long_unchecked_t copy_gpa;
45358+ atomic_long_unchecked_t read_gpa;
45359
45360- atomic_long_t mesq_receive;
45361- atomic_long_t mesq_receive_none;
45362- atomic_long_t mesq_send;
45363- atomic_long_t mesq_send_failed;
45364- atomic_long_t mesq_noop;
45365- atomic_long_t mesq_send_unexpected_error;
45366- atomic_long_t mesq_send_lb_overflow;
45367- atomic_long_t mesq_send_qlimit_reached;
45368- atomic_long_t mesq_send_amo_nacked;
45369- atomic_long_t mesq_send_put_nacked;
45370- atomic_long_t mesq_page_overflow;
45371- atomic_long_t mesq_qf_locked;
45372- atomic_long_t mesq_qf_noop_not_full;
45373- atomic_long_t mesq_qf_switch_head_failed;
45374- atomic_long_t mesq_qf_unexpected_error;
45375- atomic_long_t mesq_noop_unexpected_error;
45376- atomic_long_t mesq_noop_lb_overflow;
45377- atomic_long_t mesq_noop_qlimit_reached;
45378- atomic_long_t mesq_noop_amo_nacked;
45379- atomic_long_t mesq_noop_put_nacked;
45380- atomic_long_t mesq_noop_page_overflow;
45381+ atomic_long_unchecked_t mesq_receive;
45382+ atomic_long_unchecked_t mesq_receive_none;
45383+ atomic_long_unchecked_t mesq_send;
45384+ atomic_long_unchecked_t mesq_send_failed;
45385+ atomic_long_unchecked_t mesq_noop;
45386+ atomic_long_unchecked_t mesq_send_unexpected_error;
45387+ atomic_long_unchecked_t mesq_send_lb_overflow;
45388+ atomic_long_unchecked_t mesq_send_qlimit_reached;
45389+ atomic_long_unchecked_t mesq_send_amo_nacked;
45390+ atomic_long_unchecked_t mesq_send_put_nacked;
45391+ atomic_long_unchecked_t mesq_page_overflow;
45392+ atomic_long_unchecked_t mesq_qf_locked;
45393+ atomic_long_unchecked_t mesq_qf_noop_not_full;
45394+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
45395+ atomic_long_unchecked_t mesq_qf_unexpected_error;
45396+ atomic_long_unchecked_t mesq_noop_unexpected_error;
45397+ atomic_long_unchecked_t mesq_noop_lb_overflow;
45398+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
45399+ atomic_long_unchecked_t mesq_noop_amo_nacked;
45400+ atomic_long_unchecked_t mesq_noop_put_nacked;
45401+ atomic_long_unchecked_t mesq_noop_page_overflow;
45402
45403 };
45404
45405@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45406 tghop_invalidate, mcsop_last};
45407
45408 struct mcs_op_statistic {
45409- atomic_long_t count;
45410- atomic_long_t total;
45411+ atomic_long_unchecked_t count;
45412+ atomic_long_unchecked_t total;
45413 unsigned long max;
45414 };
45415
45416@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45417
45418 #define STAT(id) do { \
45419 if (gru_options & OPT_STATS) \
45420- atomic_long_inc(&gru_stats.id); \
45421+ atomic_long_inc_unchecked(&gru_stats.id); \
45422 } while (0)
45423
45424 #ifdef CONFIG_SGI_GRU_DEBUG
45425diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45426index c862cd4..0d176fe 100644
45427--- a/drivers/misc/sgi-xp/xp.h
45428+++ b/drivers/misc/sgi-xp/xp.h
45429@@ -288,7 +288,7 @@ struct xpc_interface {
45430 xpc_notify_func, void *);
45431 void (*received) (short, int, void *);
45432 enum xp_retval (*partid_to_nasids) (short, void *);
45433-};
45434+} __no_const;
45435
45436 extern struct xpc_interface xpc_interface;
45437
45438diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45439index 01be66d..e3a0c7e 100644
45440--- a/drivers/misc/sgi-xp/xp_main.c
45441+++ b/drivers/misc/sgi-xp/xp_main.c
45442@@ -78,13 +78,13 @@ xpc_notloaded(void)
45443 }
45444
45445 struct xpc_interface xpc_interface = {
45446- (void (*)(int))xpc_notloaded,
45447- (void (*)(int))xpc_notloaded,
45448- (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45449- (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45450+ .connect = (void (*)(int))xpc_notloaded,
45451+ .disconnect = (void (*)(int))xpc_notloaded,
45452+ .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45453+ .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45454 void *))xpc_notloaded,
45455- (void (*)(short, int, void *))xpc_notloaded,
45456- (enum xp_retval(*)(short, void *))xpc_notloaded
45457+ .received = (void (*)(short, int, void *))xpc_notloaded,
45458+ .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45459 };
45460 EXPORT_SYMBOL_GPL(xpc_interface);
45461
45462diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45463index b94d5f7..7f494c5 100644
45464--- a/drivers/misc/sgi-xp/xpc.h
45465+++ b/drivers/misc/sgi-xp/xpc.h
45466@@ -835,6 +835,7 @@ struct xpc_arch_operations {
45467 void (*received_payload) (struct xpc_channel *, void *);
45468 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45469 };
45470+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45471
45472 /* struct xpc_partition act_state values (for XPC HB) */
45473
45474@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45475 /* found in xpc_main.c */
45476 extern struct device *xpc_part;
45477 extern struct device *xpc_chan;
45478-extern struct xpc_arch_operations xpc_arch_ops;
45479+extern xpc_arch_operations_no_const xpc_arch_ops;
45480 extern int xpc_disengage_timelimit;
45481 extern int xpc_disengage_timedout;
45482 extern int xpc_activate_IRQ_rcvd;
45483diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45484index 82dc574..8539ab2 100644
45485--- a/drivers/misc/sgi-xp/xpc_main.c
45486+++ b/drivers/misc/sgi-xp/xpc_main.c
45487@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45488 .notifier_call = xpc_system_die,
45489 };
45490
45491-struct xpc_arch_operations xpc_arch_ops;
45492+xpc_arch_operations_no_const xpc_arch_ops;
45493
45494 /*
45495 * Timer function to enforce the timelimit on the partition disengage.
45496@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45497
45498 if (((die_args->trapnr == X86_TRAP_MF) ||
45499 (die_args->trapnr == X86_TRAP_XF)) &&
45500- !user_mode_vm(die_args->regs))
45501+ !user_mode(die_args->regs))
45502 xpc_die_deactivate();
45503
45504 break;
45505diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45506index 7b5424f..ed1d6ac 100644
45507--- a/drivers/mmc/card/block.c
45508+++ b/drivers/mmc/card/block.c
45509@@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45510 if (idata->ic.postsleep_min_us)
45511 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45512
45513- if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45514+ if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45515 err = -EFAULT;
45516 goto cmd_rel_host;
45517 }
45518diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45519index e5b5eeb..7bf2212 100644
45520--- a/drivers/mmc/core/mmc_ops.c
45521+++ b/drivers/mmc/core/mmc_ops.c
45522@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45523 void *data_buf;
45524 int is_on_stack;
45525
45526- is_on_stack = object_is_on_stack(buf);
45527+ is_on_stack = object_starts_on_stack(buf);
45528 if (is_on_stack) {
45529 /*
45530 * dma onto stack is unsafe/nonportable, but callers to this
45531diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45532index 6bf24ab..13d0293b 100644
45533--- a/drivers/mmc/host/dw_mmc.h
45534+++ b/drivers/mmc/host/dw_mmc.h
45535@@ -258,5 +258,5 @@ struct dw_mci_drv_data {
45536 int (*parse_dt)(struct dw_mci *host);
45537 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45538 struct dw_mci_tuning_data *tuning_data);
45539-};
45540+} __do_const;
45541 #endif /* _DW_MMC_H_ */
45542diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45543index f320579..7b7ebac 100644
45544--- a/drivers/mmc/host/mmci.c
45545+++ b/drivers/mmc/host/mmci.c
45546@@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
45547 }
45548
45549 if (variant->busy_detect) {
45550- mmci_ops.card_busy = mmci_card_busy;
45551+ pax_open_kernel();
45552+ *(void **)&mmci_ops.card_busy = mmci_card_busy;
45553+ pax_close_kernel();
45554 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45555 }
45556
45557diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45558index 1dcaf8a..025af25 100644
45559--- a/drivers/mmc/host/sdhci-esdhc-imx.c
45560+++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45561@@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45562 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
45563 }
45564
45565- if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45566- sdhci_esdhc_ops.platform_execute_tuning =
45567+ if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45568+ pax_open_kernel();
45569+ *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45570 esdhc_executing_tuning;
45571+ pax_close_kernel();
45572+ }
45573 boarddata = &imx_data->boarddata;
45574 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
45575 if (!host->mmc->parent->platform_data) {
45576diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45577index 6debda9..2ba7427 100644
45578--- a/drivers/mmc/host/sdhci-s3c.c
45579+++ b/drivers/mmc/host/sdhci-s3c.c
45580@@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45581 * we can use overriding functions instead of default.
45582 */
45583 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45584- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45585- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45586- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45587+ pax_open_kernel();
45588+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45589+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45590+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45591+ pax_close_kernel();
45592 }
45593
45594 /* It supports additional host capabilities if needed */
45595diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45596index 096993f..f02c23b 100644
45597--- a/drivers/mtd/chips/cfi_cmdset_0020.c
45598+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45599@@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45600 size_t totlen = 0, thislen;
45601 int ret = 0;
45602 size_t buflen = 0;
45603- static char *buffer;
45604+ char *buffer;
45605
45606 if (!ECCBUF_SIZE) {
45607 /* We should fall back to a general writev implementation.
45608diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45609index 370b9dd..1a1176b 100644
45610--- a/drivers/mtd/nand/denali.c
45611+++ b/drivers/mtd/nand/denali.c
45612@@ -24,6 +24,7 @@
45613 #include <linux/slab.h>
45614 #include <linux/mtd/mtd.h>
45615 #include <linux/module.h>
45616+#include <linux/slab.h>
45617
45618 #include "denali.h"
45619
45620diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45621index 51b9d6a..52af9a7 100644
45622--- a/drivers/mtd/nftlmount.c
45623+++ b/drivers/mtd/nftlmount.c
45624@@ -24,6 +24,7 @@
45625 #include <asm/errno.h>
45626 #include <linux/delay.h>
45627 #include <linux/slab.h>
45628+#include <linux/sched.h>
45629 #include <linux/mtd/mtd.h>
45630 #include <linux/mtd/nand.h>
45631 #include <linux/mtd/nftl.h>
45632diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45633index 4b8e895..6b3c498 100644
45634--- a/drivers/mtd/sm_ftl.c
45635+++ b/drivers/mtd/sm_ftl.c
45636@@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45637 #define SM_CIS_VENDOR_OFFSET 0x59
45638 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45639 {
45640- struct attribute_group *attr_group;
45641+ attribute_group_no_const *attr_group;
45642 struct attribute **attributes;
45643 struct sm_sysfs_attribute *vendor_attribute;
45644
45645diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45646index 4b8c58b..a200546 100644
45647--- a/drivers/net/bonding/bond_main.c
45648+++ b/drivers/net/bonding/bond_main.c
45649@@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45650
45651 bond_netlink_fini();
45652 unregister_pernet_subsys(&bond_net_ops);
45653+ rtnl_link_unregister(&bond_link_ops);
45654
45655 #ifdef CONFIG_NET_POLL_CONTROLLER
45656 /*
45657diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45658index 40e7b1c..6a70fff 100644
45659--- a/drivers/net/bonding/bond_netlink.c
45660+++ b/drivers/net/bonding/bond_netlink.c
45661@@ -102,7 +102,7 @@ nla_put_failure:
45662 return -EMSGSIZE;
45663 }
45664
45665-struct rtnl_link_ops bond_link_ops __read_mostly = {
45666+struct rtnl_link_ops bond_link_ops = {
45667 .kind = "bond",
45668 .priv_size = sizeof(struct bonding),
45669 .setup = bond_setup,
45670diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45671index 3c06947..fd0e5de 100644
45672--- a/drivers/net/can/Kconfig
45673+++ b/drivers/net/can/Kconfig
45674@@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45675
45676 config CAN_FLEXCAN
45677 tristate "Support for Freescale FLEXCAN based chips"
45678- depends on ARM || PPC
45679+ depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45680 ---help---
45681 Say Y here if you want to support for Freescale FlexCAN.
45682
45683diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45684index 36fa577..a158806 100644
45685--- a/drivers/net/ethernet/8390/ax88796.c
45686+++ b/drivers/net/ethernet/8390/ax88796.c
45687@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45688 if (ax->plat->reg_offsets)
45689 ei_local->reg_offset = ax->plat->reg_offsets;
45690 else {
45691+ resource_size_t _mem_size = mem_size;
45692+ do_div(_mem_size, 0x18);
45693 ei_local->reg_offset = ax->reg_offsets;
45694 for (ret = 0; ret < 0x18; ret++)
45695- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45696+ ax->reg_offsets[ret] = _mem_size * ret;
45697 }
45698
45699 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45700diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45701index 41f3ca5a..1ee5364 100644
45702--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45703+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45704@@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45705 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45706 {
45707 /* RX_MODE controlling object */
45708- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45709+ bnx2x_init_rx_mode_obj(bp);
45710
45711 /* multicast configuration controlling object */
45712 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45713diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45714index 18438a5..c923b8e 100644
45715--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45716+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45717@@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45718 return rc;
45719 }
45720
45721-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45722- struct bnx2x_rx_mode_obj *o)
45723+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45724 {
45725 if (CHIP_IS_E1x(bp)) {
45726- o->wait_comp = bnx2x_empty_rx_mode_wait;
45727- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45728+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45729+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45730 } else {
45731- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45732- o->config_rx_mode = bnx2x_set_rx_mode_e2;
45733+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45734+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45735 }
45736 }
45737
45738diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45739index 6a53c15..6e7d1e7 100644
45740--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45741+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45742@@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45743
45744 /********************* RX MODE ****************/
45745
45746-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45747- struct bnx2x_rx_mode_obj *o);
45748+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45749
45750 /**
45751 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45752diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45753index cf9917b..c658558 100644
45754--- a/drivers/net/ethernet/broadcom/tg3.h
45755+++ b/drivers/net/ethernet/broadcom/tg3.h
45756@@ -150,6 +150,7 @@
45757 #define CHIPREV_ID_5750_A0 0x4000
45758 #define CHIPREV_ID_5750_A1 0x4001
45759 #define CHIPREV_ID_5750_A3 0x4003
45760+#define CHIPREV_ID_5750_C1 0x4201
45761 #define CHIPREV_ID_5750_C2 0x4202
45762 #define CHIPREV_ID_5752_A0_HW 0x5000
45763 #define CHIPREV_ID_5752_A0 0x6000
45764diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45765index 3ca77fa..fcc015f 100644
45766--- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45767+++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45768@@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45769 }
45770
45771 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45772- bna_cb_ioceth_enable,
45773- bna_cb_ioceth_disable,
45774- bna_cb_ioceth_hbfail,
45775- bna_cb_ioceth_reset
45776+ .enable_cbfn = bna_cb_ioceth_enable,
45777+ .disable_cbfn = bna_cb_ioceth_disable,
45778+ .hbfail_cbfn = bna_cb_ioceth_hbfail,
45779+ .reset_cbfn = bna_cb_ioceth_reset
45780 };
45781
45782 static void bna_attr_init(struct bna_ioceth *ioceth)
45783diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45784index 8cffcdf..aadf043 100644
45785--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45786+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45787@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45788 */
45789 struct l2t_skb_cb {
45790 arp_failure_handler_func arp_failure_handler;
45791-};
45792+} __no_const;
45793
45794 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45795
45796diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45797index fff02ed..d421412 100644
45798--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45799+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45800@@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45801
45802 int i;
45803 struct adapter *ap = netdev2adap(dev);
45804- static const unsigned int *reg_ranges;
45805+ const unsigned int *reg_ranges;
45806 int arr_size = 0, buf_size = 0;
45807
45808 if (is_t4(ap->params.chip)) {
45809diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45810index c05b66d..ed69872 100644
45811--- a/drivers/net/ethernet/dec/tulip/de4x5.c
45812+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45813@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45814 for (i=0; i<ETH_ALEN; i++) {
45815 tmp.addr[i] = dev->dev_addr[i];
45816 }
45817- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45818+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45819 break;
45820
45821 case DE4X5_SET_HWADDR: /* Set the hardware address */
45822@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45823 spin_lock_irqsave(&lp->lock, flags);
45824 memcpy(&statbuf, &lp->pktStats, ioc->len);
45825 spin_unlock_irqrestore(&lp->lock, flags);
45826- if (copy_to_user(ioc->data, &statbuf, ioc->len))
45827+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45828 return -EFAULT;
45829 break;
45830 }
45831diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45832index a37039d..a51d7e8 100644
45833--- a/drivers/net/ethernet/emulex/benet/be_main.c
45834+++ b/drivers/net/ethernet/emulex/benet/be_main.c
45835@@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45836
45837 if (wrapped)
45838 newacc += 65536;
45839- ACCESS_ONCE(*acc) = newacc;
45840+ ACCESS_ONCE_RW(*acc) = newacc;
45841 }
45842
45843 static void populate_erx_stats(struct be_adapter *adapter,
45844diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45845index 212f44b..fb69959 100644
45846--- a/drivers/net/ethernet/faraday/ftgmac100.c
45847+++ b/drivers/net/ethernet/faraday/ftgmac100.c
45848@@ -31,6 +31,8 @@
45849 #include <linux/netdevice.h>
45850 #include <linux/phy.h>
45851 #include <linux/platform_device.h>
45852+#include <linux/interrupt.h>
45853+#include <linux/irqreturn.h>
45854 #include <net/ip.h>
45855
45856 #include "ftgmac100.h"
45857diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45858index 8be5b40..081bc1b 100644
45859--- a/drivers/net/ethernet/faraday/ftmac100.c
45860+++ b/drivers/net/ethernet/faraday/ftmac100.c
45861@@ -31,6 +31,8 @@
45862 #include <linux/module.h>
45863 #include <linux/netdevice.h>
45864 #include <linux/platform_device.h>
45865+#include <linux/interrupt.h>
45866+#include <linux/irqreturn.h>
45867
45868 #include "ftmac100.h"
45869
45870diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45871index 5184e2a..acb28c3 100644
45872--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45873+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45874@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45875 }
45876
45877 /* update the base incval used to calculate frequency adjustment */
45878- ACCESS_ONCE(adapter->base_incval) = incval;
45879+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
45880 smp_mb();
45881
45882 /* need lock to prevent incorrect read while modifying cyclecounter */
45883diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45884index fbe5363..266b4e3 100644
45885--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45886+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45887@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45888 struct __vxge_hw_fifo *fifo;
45889 struct vxge_hw_fifo_config *config;
45890 u32 txdl_size, txdl_per_memblock;
45891- struct vxge_hw_mempool_cbs fifo_mp_callback;
45892+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45893+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45894+ };
45895+
45896 struct __vxge_hw_virtualpath *vpath;
45897
45898 if ((vp == NULL) || (attr == NULL)) {
45899@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45900 goto exit;
45901 }
45902
45903- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45904-
45905 fifo->mempool =
45906 __vxge_hw_mempool_create(vpath->hldev,
45907 fifo->config->memblock_size,
45908diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45909index 918e18d..4ca3650 100644
45910--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45911+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45912@@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45913 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45914 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45915 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45916- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45917+ pax_open_kernel();
45918+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45919+ pax_close_kernel();
45920 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45921 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45922 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45923diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45924index 734d286..b017bf5 100644
45925--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45926+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45927@@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45928 case QLCNIC_NON_PRIV_FUNC:
45929 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45930 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45931- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45932+ pax_open_kernel();
45933+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45934+ pax_close_kernel();
45935 break;
45936 case QLCNIC_PRIV_FUNC:
45937 ahw->op_mode = QLCNIC_PRIV_FUNC;
45938 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45939- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45940+ pax_open_kernel();
45941+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45942+ pax_close_kernel();
45943 break;
45944 case QLCNIC_MGMT_FUNC:
45945 ahw->op_mode = QLCNIC_MGMT_FUNC;
45946 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45947- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45948+ pax_open_kernel();
45949+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45950+ pax_close_kernel();
45951 break;
45952 default:
45953 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45954diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45955index 7763962..c3499a7 100644
45956--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45957+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45958@@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45959 struct qlcnic_dump_entry *entry;
45960 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45961 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45962- static const struct qlcnic_dump_operations *fw_dump_ops;
45963+ const struct qlcnic_dump_operations *fw_dump_ops;
45964 struct device *dev = &adapter->pdev->dev;
45965 struct qlcnic_hardware_context *ahw;
45966 void *temp_buffer;
45967diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45968index c737f0e..32b8682 100644
45969--- a/drivers/net/ethernet/realtek/r8169.c
45970+++ b/drivers/net/ethernet/realtek/r8169.c
45971@@ -759,22 +759,22 @@ struct rtl8169_private {
45972 struct mdio_ops {
45973 void (*write)(struct rtl8169_private *, int, int);
45974 int (*read)(struct rtl8169_private *, int);
45975- } mdio_ops;
45976+ } __no_const mdio_ops;
45977
45978 struct pll_power_ops {
45979 void (*down)(struct rtl8169_private *);
45980 void (*up)(struct rtl8169_private *);
45981- } pll_power_ops;
45982+ } __no_const pll_power_ops;
45983
45984 struct jumbo_ops {
45985 void (*enable)(struct rtl8169_private *);
45986 void (*disable)(struct rtl8169_private *);
45987- } jumbo_ops;
45988+ } __no_const jumbo_ops;
45989
45990 struct csi_ops {
45991 void (*write)(struct rtl8169_private *, int, int);
45992 u32 (*read)(struct rtl8169_private *, int);
45993- } csi_ops;
45994+ } __no_const csi_ops;
45995
45996 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45997 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45998diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45999index a124103..59c74f8 100644
46000--- a/drivers/net/ethernet/sfc/ptp.c
46001+++ b/drivers/net/ethernet/sfc/ptp.c
46002@@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46003 ptp->start.dma_addr);
46004
46005 /* Clear flag that signals MC ready */
46006- ACCESS_ONCE(*start) = 0;
46007+ ACCESS_ONCE_RW(*start) = 0;
46008 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46009 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46010 EFX_BUG_ON_PARANOID(rc);
46011diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46012index 50617c5..b13724c 100644
46013--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46014+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46015@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46016
46017 writel(value, ioaddr + MMC_CNTRL);
46018
46019- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46020- MMC_CNTRL, value);
46021+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46022+// MMC_CNTRL, value);
46023 }
46024
46025 /* To mask all all interrupts.*/
46026diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46027index e6fe0d8..2b7d752 100644
46028--- a/drivers/net/hyperv/hyperv_net.h
46029+++ b/drivers/net/hyperv/hyperv_net.h
46030@@ -101,7 +101,7 @@ struct rndis_device {
46031
46032 enum rndis_device_state state;
46033 bool link_state;
46034- atomic_t new_req_id;
46035+ atomic_unchecked_t new_req_id;
46036
46037 spinlock_t request_lock;
46038 struct list_head req_list;
46039diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46040index 0775f0a..d4fb316 100644
46041--- a/drivers/net/hyperv/rndis_filter.c
46042+++ b/drivers/net/hyperv/rndis_filter.c
46043@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46044 * template
46045 */
46046 set = &rndis_msg->msg.set_req;
46047- set->req_id = atomic_inc_return(&dev->new_req_id);
46048+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46049
46050 /* Add to the request list */
46051 spin_lock_irqsave(&dev->request_lock, flags);
46052@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46053
46054 /* Setup the rndis set */
46055 halt = &request->request_msg.msg.halt_req;
46056- halt->req_id = atomic_inc_return(&dev->new_req_id);
46057+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46058
46059 /* Ignore return since this msg is optional. */
46060 rndis_filter_send_request(dev, request);
46061diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46062index bf0d55e..82bcfbd1 100644
46063--- a/drivers/net/ieee802154/fakehard.c
46064+++ b/drivers/net/ieee802154/fakehard.c
46065@@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46066 phy->transmit_power = 0xbf;
46067
46068 dev->netdev_ops = &fake_ops;
46069- dev->ml_priv = &fake_mlme;
46070+ dev->ml_priv = (void *)&fake_mlme;
46071
46072 priv = netdev_priv(dev);
46073 priv->phy = phy;
46074diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46075index d7e2907..1f8bfee 100644
46076--- a/drivers/net/macvlan.c
46077+++ b/drivers/net/macvlan.c
46078@@ -993,13 +993,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46079 int macvlan_link_register(struct rtnl_link_ops *ops)
46080 {
46081 /* common fields */
46082- ops->priv_size = sizeof(struct macvlan_dev);
46083- ops->validate = macvlan_validate;
46084- ops->maxtype = IFLA_MACVLAN_MAX;
46085- ops->policy = macvlan_policy;
46086- ops->changelink = macvlan_changelink;
46087- ops->get_size = macvlan_get_size;
46088- ops->fill_info = macvlan_fill_info;
46089+ pax_open_kernel();
46090+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46091+ *(void **)&ops->validate = macvlan_validate;
46092+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46093+ *(const void **)&ops->policy = macvlan_policy;
46094+ *(void **)&ops->changelink = macvlan_changelink;
46095+ *(void **)&ops->get_size = macvlan_get_size;
46096+ *(void **)&ops->fill_info = macvlan_fill_info;
46097+ pax_close_kernel();
46098
46099 return rtnl_link_register(ops);
46100 };
46101@@ -1054,7 +1056,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46102 return NOTIFY_DONE;
46103 }
46104
46105-static struct notifier_block macvlan_notifier_block __read_mostly = {
46106+static struct notifier_block macvlan_notifier_block = {
46107 .notifier_call = macvlan_device_event,
46108 };
46109
46110diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46111index 2a89da0..c17fe1d 100644
46112--- a/drivers/net/macvtap.c
46113+++ b/drivers/net/macvtap.c
46114@@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46115 }
46116
46117 ret = 0;
46118- if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46119+ if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46120 put_user(q->flags, &ifr->ifr_flags))
46121 ret = -EFAULT;
46122 macvtap_put_vlan(vlan);
46123@@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46124 return NOTIFY_DONE;
46125 }
46126
46127-static struct notifier_block macvtap_notifier_block __read_mostly = {
46128+static struct notifier_block macvtap_notifier_block = {
46129 .notifier_call = macvtap_device_event,
46130 };
46131
46132diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
46133index daec9b0..6428fcb 100644
46134--- a/drivers/net/phy/mdio-bitbang.c
46135+++ b/drivers/net/phy/mdio-bitbang.c
46136@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
46137 struct mdiobb_ctrl *ctrl = bus->priv;
46138
46139 module_put(ctrl->ops->owner);
46140+ mdiobus_unregister(bus);
46141 mdiobus_free(bus);
46142 }
46143 EXPORT_SYMBOL(free_mdio_bitbang);
46144diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46145index 72ff14b..11d442d 100644
46146--- a/drivers/net/ppp/ppp_generic.c
46147+++ b/drivers/net/ppp/ppp_generic.c
46148@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46149 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46150 struct ppp_stats stats;
46151 struct ppp_comp_stats cstats;
46152- char *vers;
46153
46154 switch (cmd) {
46155 case SIOCGPPPSTATS:
46156@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46157 break;
46158
46159 case SIOCGPPPVER:
46160- vers = PPP_VERSION;
46161- if (copy_to_user(addr, vers, strlen(vers) + 1))
46162+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46163 break;
46164 err = 0;
46165 break;
46166diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46167index 1252d9c..80e660b 100644
46168--- a/drivers/net/slip/slhc.c
46169+++ b/drivers/net/slip/slhc.c
46170@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46171 register struct tcphdr *thp;
46172 register struct iphdr *ip;
46173 register struct cstate *cs;
46174- int len, hdrlen;
46175+ long len, hdrlen;
46176 unsigned char *cp = icp;
46177
46178 /* We've got a compressed packet; read the change byte */
46179diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46180index b75ae5b..953c157 100644
46181--- a/drivers/net/team/team.c
46182+++ b/drivers/net/team/team.c
46183@@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
46184 return NOTIFY_DONE;
46185 }
46186
46187-static struct notifier_block team_notifier_block __read_mostly = {
46188+static struct notifier_block team_notifier_block = {
46189 .notifier_call = team_device_event,
46190 };
46191
46192diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46193index 55c9238..ebb6ee5 100644
46194--- a/drivers/net/tun.c
46195+++ b/drivers/net/tun.c
46196@@ -1841,7 +1841,7 @@ unlock:
46197 }
46198
46199 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46200- unsigned long arg, int ifreq_len)
46201+ unsigned long arg, size_t ifreq_len)
46202 {
46203 struct tun_file *tfile = file->private_data;
46204 struct tun_struct *tun;
46205@@ -1854,6 +1854,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46206 unsigned int ifindex;
46207 int ret;
46208
46209+ if (ifreq_len > sizeof ifr)
46210+ return -EFAULT;
46211+
46212 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46213 if (copy_from_user(&ifr, argp, ifreq_len))
46214 return -EFAULT;
46215diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46216index 1a48234..a555339 100644
46217--- a/drivers/net/usb/hso.c
46218+++ b/drivers/net/usb/hso.c
46219@@ -71,7 +71,7 @@
46220 #include <asm/byteorder.h>
46221 #include <linux/serial_core.h>
46222 #include <linux/serial.h>
46223-
46224+#include <asm/local.h>
46225
46226 #define MOD_AUTHOR "Option Wireless"
46227 #define MOD_DESCRIPTION "USB High Speed Option driver"
46228@@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46229 struct urb *urb;
46230
46231 urb = serial->rx_urb[0];
46232- if (serial->port.count > 0) {
46233+ if (atomic_read(&serial->port.count) > 0) {
46234 count = put_rxbuf_data(urb, serial);
46235 if (count == -1)
46236 return;
46237@@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46238 DUMP1(urb->transfer_buffer, urb->actual_length);
46239
46240 /* Anyone listening? */
46241- if (serial->port.count == 0)
46242+ if (atomic_read(&serial->port.count) == 0)
46243 return;
46244
46245 if (status == 0) {
46246@@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46247 tty_port_tty_set(&serial->port, tty);
46248
46249 /* check for port already opened, if not set the termios */
46250- serial->port.count++;
46251- if (serial->port.count == 1) {
46252+ if (atomic_inc_return(&serial->port.count) == 1) {
46253 serial->rx_state = RX_IDLE;
46254 /* Force default termio settings */
46255 _hso_serial_set_termios(tty, NULL);
46256@@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46257 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46258 if (result) {
46259 hso_stop_serial_device(serial->parent);
46260- serial->port.count--;
46261+ atomic_dec(&serial->port.count);
46262 kref_put(&serial->parent->ref, hso_serial_ref_free);
46263 }
46264 } else {
46265@@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46266
46267 /* reset the rts and dtr */
46268 /* do the actual close */
46269- serial->port.count--;
46270+ atomic_dec(&serial->port.count);
46271
46272- if (serial->port.count <= 0) {
46273- serial->port.count = 0;
46274+ if (atomic_read(&serial->port.count) <= 0) {
46275+ atomic_set(&serial->port.count, 0);
46276 tty_port_tty_set(&serial->port, NULL);
46277 if (!usb_gone)
46278 hso_stop_serial_device(serial->parent);
46279@@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46280
46281 /* the actual setup */
46282 spin_lock_irqsave(&serial->serial_lock, flags);
46283- if (serial->port.count)
46284+ if (atomic_read(&serial->port.count))
46285 _hso_serial_set_termios(tty, old);
46286 else
46287 tty->termios = *old;
46288@@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
46289 D1("Pending read interrupt on port %d\n", i);
46290 spin_lock(&serial->serial_lock);
46291 if (serial->rx_state == RX_IDLE &&
46292- serial->port.count > 0) {
46293+ atomic_read(&serial->port.count) > 0) {
46294 /* Setup and send a ctrl req read on
46295 * port i */
46296 if (!serial->rx_urb_filled[0]) {
46297@@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
46298 /* Start all serial ports */
46299 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46300 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46301- if (dev2ser(serial_table[i])->port.count) {
46302+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46303 result =
46304 hso_start_serial_device(serial_table[i], GFP_NOIO);
46305 hso_kick_transmit(dev2ser(serial_table[i]));
46306diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46307index a79e9d3..78cd4fa 100644
46308--- a/drivers/net/usb/sierra_net.c
46309+++ b/drivers/net/usb/sierra_net.c
46310@@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
46311 /* atomic counter partially included in MAC address to make sure 2 devices
46312 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46313 */
46314-static atomic_t iface_counter = ATOMIC_INIT(0);
46315+static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46316
46317 /*
46318 * SYNC Timer Delay definition used to set the expiry time
46319@@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46320 dev->net->netdev_ops = &sierra_net_device_ops;
46321
46322 /* change MAC addr to include, ifacenum, and to be unique */
46323- dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46324+ dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46325 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46326
46327 /* we will have to manufacture ethernet headers, prepare template */
46328diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46329index fc5d2b7..48e2984 100644
46330--- a/drivers/net/vxlan.c
46331+++ b/drivers/net/vxlan.c
46332@@ -2721,7 +2721,7 @@ nla_put_failure:
46333 return -EMSGSIZE;
46334 }
46335
46336-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46337+static struct rtnl_link_ops vxlan_link_ops = {
46338 .kind = "vxlan",
46339 .maxtype = IFLA_VXLAN_MAX,
46340 .policy = vxlan_policy,
46341diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46342index 5920c99..ff2e4a5 100644
46343--- a/drivers/net/wan/lmc/lmc_media.c
46344+++ b/drivers/net/wan/lmc/lmc_media.c
46345@@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46346 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46347
46348 lmc_media_t lmc_ds3_media = {
46349- lmc_ds3_init, /* special media init stuff */
46350- lmc_ds3_default, /* reset to default state */
46351- lmc_ds3_set_status, /* reset status to state provided */
46352- lmc_dummy_set_1, /* set clock source */
46353- lmc_dummy_set2_1, /* set line speed */
46354- lmc_ds3_set_100ft, /* set cable length */
46355- lmc_ds3_set_scram, /* set scrambler */
46356- lmc_ds3_get_link_status, /* get link status */
46357- lmc_dummy_set_1, /* set link status */
46358- lmc_ds3_set_crc_length, /* set CRC length */
46359- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46360- lmc_ds3_watchdog
46361+ .init = lmc_ds3_init, /* special media init stuff */
46362+ .defaults = lmc_ds3_default, /* reset to default state */
46363+ .set_status = lmc_ds3_set_status, /* reset status to state provided */
46364+ .set_clock_source = lmc_dummy_set_1, /* set clock source */
46365+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46366+ .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46367+ .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46368+ .get_link_status = lmc_ds3_get_link_status, /* get link status */
46369+ .set_link_status = lmc_dummy_set_1, /* set link status */
46370+ .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46371+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46372+ .watchdog = lmc_ds3_watchdog
46373 };
46374
46375 lmc_media_t lmc_hssi_media = {
46376- lmc_hssi_init, /* special media init stuff */
46377- lmc_hssi_default, /* reset to default state */
46378- lmc_hssi_set_status, /* reset status to state provided */
46379- lmc_hssi_set_clock, /* set clock source */
46380- lmc_dummy_set2_1, /* set line speed */
46381- lmc_dummy_set_1, /* set cable length */
46382- lmc_dummy_set_1, /* set scrambler */
46383- lmc_hssi_get_link_status, /* get link status */
46384- lmc_hssi_set_link_status, /* set link status */
46385- lmc_hssi_set_crc_length, /* set CRC length */
46386- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46387- lmc_hssi_watchdog
46388+ .init = lmc_hssi_init, /* special media init stuff */
46389+ .defaults = lmc_hssi_default, /* reset to default state */
46390+ .set_status = lmc_hssi_set_status, /* reset status to state provided */
46391+ .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46392+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46393+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46394+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46395+ .get_link_status = lmc_hssi_get_link_status, /* get link status */
46396+ .set_link_status = lmc_hssi_set_link_status, /* set link status */
46397+ .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46398+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46399+ .watchdog = lmc_hssi_watchdog
46400 };
46401
46402-lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46403- lmc_ssi_default, /* reset to default state */
46404- lmc_ssi_set_status, /* reset status to state provided */
46405- lmc_ssi_set_clock, /* set clock source */
46406- lmc_ssi_set_speed, /* set line speed */
46407- lmc_dummy_set_1, /* set cable length */
46408- lmc_dummy_set_1, /* set scrambler */
46409- lmc_ssi_get_link_status, /* get link status */
46410- lmc_ssi_set_link_status, /* set link status */
46411- lmc_ssi_set_crc_length, /* set CRC length */
46412- lmc_dummy_set_1, /* set T1 or E1 circuit type */
46413- lmc_ssi_watchdog
46414+lmc_media_t lmc_ssi_media = {
46415+ .init = lmc_ssi_init, /* special media init stuff */
46416+ .defaults = lmc_ssi_default, /* reset to default state */
46417+ .set_status = lmc_ssi_set_status, /* reset status to state provided */
46418+ .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46419+ .set_speed = lmc_ssi_set_speed, /* set line speed */
46420+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46421+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46422+ .get_link_status = lmc_ssi_get_link_status, /* get link status */
46423+ .set_link_status = lmc_ssi_set_link_status, /* set link status */
46424+ .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46425+ .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46426+ .watchdog = lmc_ssi_watchdog
46427 };
46428
46429 lmc_media_t lmc_t1_media = {
46430- lmc_t1_init, /* special media init stuff */
46431- lmc_t1_default, /* reset to default state */
46432- lmc_t1_set_status, /* reset status to state provided */
46433- lmc_t1_set_clock, /* set clock source */
46434- lmc_dummy_set2_1, /* set line speed */
46435- lmc_dummy_set_1, /* set cable length */
46436- lmc_dummy_set_1, /* set scrambler */
46437- lmc_t1_get_link_status, /* get link status */
46438- lmc_dummy_set_1, /* set link status */
46439- lmc_t1_set_crc_length, /* set CRC length */
46440- lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46441- lmc_t1_watchdog
46442+ .init = lmc_t1_init, /* special media init stuff */
46443+ .defaults = lmc_t1_default, /* reset to default state */
46444+ .set_status = lmc_t1_set_status, /* reset status to state provided */
46445+ .set_clock_source = lmc_t1_set_clock, /* set clock source */
46446+ .set_speed = lmc_dummy_set2_1, /* set line speed */
46447+ .set_cable_length = lmc_dummy_set_1, /* set cable length */
46448+ .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46449+ .get_link_status = lmc_t1_get_link_status, /* get link status */
46450+ .set_link_status = lmc_dummy_set_1, /* set link status */
46451+ .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46452+ .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46453+ .watchdog = lmc_t1_watchdog
46454 };
46455
46456 static void
46457diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46458index feacc3b..5bac0de 100644
46459--- a/drivers/net/wan/z85230.c
46460+++ b/drivers/net/wan/z85230.c
46461@@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46462
46463 struct z8530_irqhandler z8530_sync =
46464 {
46465- z8530_rx,
46466- z8530_tx,
46467- z8530_status
46468+ .rx = z8530_rx,
46469+ .tx = z8530_tx,
46470+ .status = z8530_status
46471 };
46472
46473 EXPORT_SYMBOL(z8530_sync);
46474@@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46475 }
46476
46477 static struct z8530_irqhandler z8530_dma_sync = {
46478- z8530_dma_rx,
46479- z8530_dma_tx,
46480- z8530_dma_status
46481+ .rx = z8530_dma_rx,
46482+ .tx = z8530_dma_tx,
46483+ .status = z8530_dma_status
46484 };
46485
46486 static struct z8530_irqhandler z8530_txdma_sync = {
46487- z8530_rx,
46488- z8530_dma_tx,
46489- z8530_dma_status
46490+ .rx = z8530_rx,
46491+ .tx = z8530_dma_tx,
46492+ .status = z8530_dma_status
46493 };
46494
46495 /**
46496@@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46497
46498 struct z8530_irqhandler z8530_nop=
46499 {
46500- z8530_rx_clear,
46501- z8530_tx_clear,
46502- z8530_status_clear
46503+ .rx = z8530_rx_clear,
46504+ .tx = z8530_tx_clear,
46505+ .status = z8530_status_clear
46506 };
46507
46508
46509diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46510index 0b60295..b8bfa5b 100644
46511--- a/drivers/net/wimax/i2400m/rx.c
46512+++ b/drivers/net/wimax/i2400m/rx.c
46513@@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46514 if (i2400m->rx_roq == NULL)
46515 goto error_roq_alloc;
46516
46517- rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46518+ rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46519 GFP_KERNEL);
46520 if (rd == NULL) {
46521 result = -ENOMEM;
46522diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46523index edf4b57..68b51c0 100644
46524--- a/drivers/net/wireless/airo.c
46525+++ b/drivers/net/wireless/airo.c
46526@@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46527 struct airo_info *ai = dev->ml_priv;
46528 int ridcode;
46529 int enabled;
46530- static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46531+ int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46532 unsigned char *iobuf;
46533
46534 /* Only super-user can write RIDs */
46535diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46536index 34c8a33..3261fdc 100644
46537--- a/drivers/net/wireless/at76c50x-usb.c
46538+++ b/drivers/net/wireless/at76c50x-usb.c
46539@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46540 }
46541
46542 /* Convert timeout from the DFU status to jiffies */
46543-static inline unsigned long at76_get_timeout(struct dfu_status *s)
46544+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46545 {
46546 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46547 | (s->poll_timeout[1] << 8)
46548diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46549index edae50b..b24278c 100644
46550--- a/drivers/net/wireless/ath/ath10k/htc.c
46551+++ b/drivers/net/wireless/ath/ath10k/htc.c
46552@@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46553 /* registered target arrival callback from the HIF layer */
46554 int ath10k_htc_init(struct ath10k *ar)
46555 {
46556- struct ath10k_hif_cb htc_callbacks;
46557+ static struct ath10k_hif_cb htc_callbacks = {
46558+ .rx_completion = ath10k_htc_rx_completion_handler,
46559+ .tx_completion = ath10k_htc_tx_completion_handler,
46560+ };
46561 struct ath10k_htc_ep *ep = NULL;
46562 struct ath10k_htc *htc = &ar->htc;
46563
46564@@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
46565 ath10k_htc_reset_endpoint_states(htc);
46566
46567 /* setup HIF layer callbacks */
46568- htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46569- htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46570 htc->ar = ar;
46571
46572 /* Get HIF default pipe for HTC message exchange */
46573diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46574index 4716d33..a688310 100644
46575--- a/drivers/net/wireless/ath/ath10k/htc.h
46576+++ b/drivers/net/wireless/ath/ath10k/htc.h
46577@@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46578
46579 struct ath10k_htc_ops {
46580 void (*target_send_suspend_complete)(struct ath10k *ar);
46581-};
46582+} __no_const;
46583
46584 struct ath10k_htc_ep_ops {
46585 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46586 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46587 void (*ep_tx_credits)(struct ath10k *);
46588-};
46589+} __no_const;
46590
46591 /* service connection information */
46592 struct ath10k_htc_svc_conn_req {
46593diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46594index a366d6b..b6f28f8 100644
46595--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46596+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46597@@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46598 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46599 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46600
46601- ACCESS_ONCE(ads->ds_link) = i->link;
46602- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46603+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
46604+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46605
46606 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46607 ctl6 = SM(i->keytype, AR_EncrType);
46608@@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46609
46610 if ((i->is_first || i->is_last) &&
46611 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46612- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46613+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46614 | set11nTries(i->rates, 1)
46615 | set11nTries(i->rates, 2)
46616 | set11nTries(i->rates, 3)
46617 | (i->dur_update ? AR_DurUpdateEna : 0)
46618 | SM(0, AR_BurstDur);
46619
46620- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46621+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46622 | set11nRate(i->rates, 1)
46623 | set11nRate(i->rates, 2)
46624 | set11nRate(i->rates, 3);
46625 } else {
46626- ACCESS_ONCE(ads->ds_ctl2) = 0;
46627- ACCESS_ONCE(ads->ds_ctl3) = 0;
46628+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46629+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46630 }
46631
46632 if (!i->is_first) {
46633- ACCESS_ONCE(ads->ds_ctl0) = 0;
46634- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46635- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46636+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46637+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46638+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46639 return;
46640 }
46641
46642@@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46643 break;
46644 }
46645
46646- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46647+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46648 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46649 | SM(i->txpower, AR_XmitPower)
46650 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46651@@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46652 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46653 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46654
46655- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46656- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46657+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46658+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46659
46660 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46661 return;
46662
46663- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46664+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46665 | set11nPktDurRTSCTS(i->rates, 1);
46666
46667- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46668+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46669 | set11nPktDurRTSCTS(i->rates, 3);
46670
46671- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46672+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46673 | set11nRateFlags(i->rates, 1)
46674 | set11nRateFlags(i->rates, 2)
46675 | set11nRateFlags(i->rates, 3)
46676diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46677index f6c5c1b..6058354 100644
46678--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46679+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46680@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46681 (i->qcu << AR_TxQcuNum_S) | desc_len;
46682
46683 checksum += val;
46684- ACCESS_ONCE(ads->info) = val;
46685+ ACCESS_ONCE_RW(ads->info) = val;
46686
46687 checksum += i->link;
46688- ACCESS_ONCE(ads->link) = i->link;
46689+ ACCESS_ONCE_RW(ads->link) = i->link;
46690
46691 checksum += i->buf_addr[0];
46692- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46693+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46694 checksum += i->buf_addr[1];
46695- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46696+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46697 checksum += i->buf_addr[2];
46698- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46699+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46700 checksum += i->buf_addr[3];
46701- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46702+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46703
46704 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46705- ACCESS_ONCE(ads->ctl3) = val;
46706+ ACCESS_ONCE_RW(ads->ctl3) = val;
46707 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46708- ACCESS_ONCE(ads->ctl5) = val;
46709+ ACCESS_ONCE_RW(ads->ctl5) = val;
46710 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46711- ACCESS_ONCE(ads->ctl7) = val;
46712+ ACCESS_ONCE_RW(ads->ctl7) = val;
46713 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46714- ACCESS_ONCE(ads->ctl9) = val;
46715+ ACCESS_ONCE_RW(ads->ctl9) = val;
46716
46717 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46718- ACCESS_ONCE(ads->ctl10) = checksum;
46719+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
46720
46721 if (i->is_first || i->is_last) {
46722- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46723+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46724 | set11nTries(i->rates, 1)
46725 | set11nTries(i->rates, 2)
46726 | set11nTries(i->rates, 3)
46727 | (i->dur_update ? AR_DurUpdateEna : 0)
46728 | SM(0, AR_BurstDur);
46729
46730- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46731+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46732 | set11nRate(i->rates, 1)
46733 | set11nRate(i->rates, 2)
46734 | set11nRate(i->rates, 3);
46735 } else {
46736- ACCESS_ONCE(ads->ctl13) = 0;
46737- ACCESS_ONCE(ads->ctl14) = 0;
46738+ ACCESS_ONCE_RW(ads->ctl13) = 0;
46739+ ACCESS_ONCE_RW(ads->ctl14) = 0;
46740 }
46741
46742 ads->ctl20 = 0;
46743@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46744
46745 ctl17 = SM(i->keytype, AR_EncrType);
46746 if (!i->is_first) {
46747- ACCESS_ONCE(ads->ctl11) = 0;
46748- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46749- ACCESS_ONCE(ads->ctl15) = 0;
46750- ACCESS_ONCE(ads->ctl16) = 0;
46751- ACCESS_ONCE(ads->ctl17) = ctl17;
46752- ACCESS_ONCE(ads->ctl18) = 0;
46753- ACCESS_ONCE(ads->ctl19) = 0;
46754+ ACCESS_ONCE_RW(ads->ctl11) = 0;
46755+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46756+ ACCESS_ONCE_RW(ads->ctl15) = 0;
46757+ ACCESS_ONCE_RW(ads->ctl16) = 0;
46758+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46759+ ACCESS_ONCE_RW(ads->ctl18) = 0;
46760+ ACCESS_ONCE_RW(ads->ctl19) = 0;
46761 return;
46762 }
46763
46764- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46765+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46766 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46767 | SM(i->txpower, AR_XmitPower)
46768 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46769@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46770 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46771 ctl12 |= SM(val, AR_PAPRDChainMask);
46772
46773- ACCESS_ONCE(ads->ctl12) = ctl12;
46774- ACCESS_ONCE(ads->ctl17) = ctl17;
46775+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46776+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46777
46778- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46779+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46780 | set11nPktDurRTSCTS(i->rates, 1);
46781
46782- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46783+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46784 | set11nPktDurRTSCTS(i->rates, 3);
46785
46786- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46787+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46788 | set11nRateFlags(i->rates, 1)
46789 | set11nRateFlags(i->rates, 2)
46790 | set11nRateFlags(i->rates, 3)
46791 | SM(i->rtscts_rate, AR_RTSCTSRate);
46792
46793- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46794+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46795 }
46796
46797 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46798diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46799index a2c9a5d..b52273e 100644
46800--- a/drivers/net/wireless/ath/ath9k/hw.h
46801+++ b/drivers/net/wireless/ath/ath9k/hw.h
46802@@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46803
46804 /* ANI */
46805 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46806-};
46807+} __no_const;
46808
46809 /**
46810 * struct ath_spec_scan - parameters for Atheros spectral scan
46811@@ -711,7 +711,7 @@ struct ath_hw_ops {
46812 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46813 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46814 #endif
46815-};
46816+} __no_const;
46817
46818 struct ath_nf_limits {
46819 s16 max;
46820diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46821index 92190da..f3a4c4c 100644
46822--- a/drivers/net/wireless/b43/phy_lp.c
46823+++ b/drivers/net/wireless/b43/phy_lp.c
46824@@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46825 {
46826 struct ssb_bus *bus = dev->dev->sdev->bus;
46827
46828- static const struct b206x_channel *chandata = NULL;
46829+ const struct b206x_channel *chandata = NULL;
46830 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46831 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46832 u16 old_comm15, scale;
46833diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46834index dea3b50..543db99 100644
46835--- a/drivers/net/wireless/iwlegacy/3945-mac.c
46836+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46837@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46838 */
46839 if (il3945_mod_params.disable_hw_scan) {
46840 D_INFO("Disabling hw_scan\n");
46841- il3945_mac_ops.hw_scan = NULL;
46842+ pax_open_kernel();
46843+ *(void **)&il3945_mac_ops.hw_scan = NULL;
46844+ pax_close_kernel();
46845 }
46846
46847 D_INFO("*** LOAD DRIVER ***\n");
46848diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46849index d94f8ab..5b568c8 100644
46850--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46851+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46852@@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46853 {
46854 struct iwl_priv *priv = file->private_data;
46855 char buf[64];
46856- int buf_size;
46857+ size_t buf_size;
46858 u32 offset, len;
46859
46860 memset(buf, 0, sizeof(buf));
46861@@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46862 struct iwl_priv *priv = file->private_data;
46863
46864 char buf[8];
46865- int buf_size;
46866+ size_t buf_size;
46867 u32 reset_flag;
46868
46869 memset(buf, 0, sizeof(buf));
46870@@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46871 {
46872 struct iwl_priv *priv = file->private_data;
46873 char buf[8];
46874- int buf_size;
46875+ size_t buf_size;
46876 int ht40;
46877
46878 memset(buf, 0, sizeof(buf));
46879@@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46880 {
46881 struct iwl_priv *priv = file->private_data;
46882 char buf[8];
46883- int buf_size;
46884+ size_t buf_size;
46885 int value;
46886
46887 memset(buf, 0, sizeof(buf));
46888@@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46889 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46890 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46891
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+static const char fmt_value[] = " %-30s %10u\n";
46897+static const char fmt_hex[] = " %-30s 0x%02X\n";
46898+static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46899+static const char fmt_header[] =
46900 "%-32s current cumulative delta max\n";
46901
46902 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46903@@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46904 {
46905 struct iwl_priv *priv = file->private_data;
46906 char buf[8];
46907- int buf_size;
46908+ size_t buf_size;
46909 int clear;
46910
46911 memset(buf, 0, sizeof(buf));
46912@@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46913 {
46914 struct iwl_priv *priv = file->private_data;
46915 char buf[8];
46916- int buf_size;
46917+ size_t buf_size;
46918 int trace;
46919
46920 memset(buf, 0, sizeof(buf));
46921@@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46922 {
46923 struct iwl_priv *priv = file->private_data;
46924 char buf[8];
46925- int buf_size;
46926+ size_t buf_size;
46927 int missed;
46928
46929 memset(buf, 0, sizeof(buf));
46930@@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46931
46932 struct iwl_priv *priv = file->private_data;
46933 char buf[8];
46934- int buf_size;
46935+ size_t buf_size;
46936 int plcp;
46937
46938 memset(buf, 0, sizeof(buf));
46939@@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46940
46941 struct iwl_priv *priv = file->private_data;
46942 char buf[8];
46943- int buf_size;
46944+ size_t buf_size;
46945 int flush;
46946
46947 memset(buf, 0, sizeof(buf));
46948@@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46949
46950 struct iwl_priv *priv = file->private_data;
46951 char buf[8];
46952- int buf_size;
46953+ size_t buf_size;
46954 int rts;
46955
46956 if (!priv->cfg->ht_params)
46957@@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46958 {
46959 struct iwl_priv *priv = file->private_data;
46960 char buf[8];
46961- int buf_size;
46962+ size_t buf_size;
46963
46964 memset(buf, 0, sizeof(buf));
46965 buf_size = min(count, sizeof(buf) - 1);
46966@@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46967 struct iwl_priv *priv = file->private_data;
46968 u32 event_log_flag;
46969 char buf[8];
46970- int buf_size;
46971+ size_t buf_size;
46972
46973 /* check that the interface is up */
46974 if (!iwl_is_ready(priv))
46975@@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46976 struct iwl_priv *priv = file->private_data;
46977 char buf[8];
46978 u32 calib_disabled;
46979- int buf_size;
46980+ size_t buf_size;
46981
46982 memset(buf, 0, sizeof(buf));
46983 buf_size = min(count, sizeof(buf) - 1);
46984diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46985index 7aad766..06addb4 100644
46986--- a/drivers/net/wireless/iwlwifi/dvm/main.c
46987+++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46988@@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46989 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46990 {
46991 struct iwl_nvm_data *data = priv->nvm_data;
46992- char *debug_msg;
46993+ static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46994
46995 if (data->sku_cap_11n_enable &&
46996 !priv->cfg->ht_params) {
46997@@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46998 return -EINVAL;
46999 }
47000
47001- debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47002 IWL_DEBUG_INFO(priv, debug_msg,
47003 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47004 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47005diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47006index f53ef83..5e34bcb 100644
47007--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47008+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47009@@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47010 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47011
47012 char buf[8];
47013- int buf_size;
47014+ size_t buf_size;
47015 u32 reset_flag;
47016
47017 memset(buf, 0, sizeof(buf));
47018@@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47019 {
47020 struct iwl_trans *trans = file->private_data;
47021 char buf[8];
47022- int buf_size;
47023+ size_t buf_size;
47024 int csr;
47025
47026 memset(buf, 0, sizeof(buf));
47027diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47028index a1b32ee..94b3c3d 100644
47029--- a/drivers/net/wireless/mac80211_hwsim.c
47030+++ b/drivers/net/wireless/mac80211_hwsim.c
47031@@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
47032
47033 if (channels > 1) {
47034 hwsim_if_comb.num_different_channels = channels;
47035- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47036- mac80211_hwsim_ops.cancel_hw_scan =
47037- mac80211_hwsim_cancel_hw_scan;
47038- mac80211_hwsim_ops.sw_scan_start = NULL;
47039- mac80211_hwsim_ops.sw_scan_complete = NULL;
47040- mac80211_hwsim_ops.remain_on_channel =
47041- mac80211_hwsim_roc;
47042- mac80211_hwsim_ops.cancel_remain_on_channel =
47043- mac80211_hwsim_croc;
47044- mac80211_hwsim_ops.add_chanctx =
47045- mac80211_hwsim_add_chanctx;
47046- mac80211_hwsim_ops.remove_chanctx =
47047- mac80211_hwsim_remove_chanctx;
47048- mac80211_hwsim_ops.change_chanctx =
47049- mac80211_hwsim_change_chanctx;
47050- mac80211_hwsim_ops.assign_vif_chanctx =
47051- mac80211_hwsim_assign_vif_chanctx;
47052- mac80211_hwsim_ops.unassign_vif_chanctx =
47053- mac80211_hwsim_unassign_vif_chanctx;
47054+ pax_open_kernel();
47055+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
47056+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47057+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
47058+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
47059+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
47060+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47061+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47062+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47063+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47064+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47065+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47066+ pax_close_kernel();
47067 }
47068
47069 spin_lock_init(&hwsim_radio_lock);
47070diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47071index 8169a85..7fa3b47 100644
47072--- a/drivers/net/wireless/rndis_wlan.c
47073+++ b/drivers/net/wireless/rndis_wlan.c
47074@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47075
47076 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47077
47078- if (rts_threshold < 0 || rts_threshold > 2347)
47079+ if (rts_threshold > 2347)
47080 rts_threshold = 2347;
47081
47082 tmp = cpu_to_le32(rts_threshold);
47083diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47084index e4ba2ce..63d7417 100644
47085--- a/drivers/net/wireless/rt2x00/rt2x00.h
47086+++ b/drivers/net/wireless/rt2x00/rt2x00.h
47087@@ -377,7 +377,7 @@ struct rt2x00_intf {
47088 * for hardware which doesn't support hardware
47089 * sequence counting.
47090 */
47091- atomic_t seqno;
47092+ atomic_unchecked_t seqno;
47093 };
47094
47095 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47096diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47097index a5d38e8..d3c24ea 100644
47098--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47099+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47100@@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47101 * sequence counter given by mac80211.
47102 */
47103 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47104- seqno = atomic_add_return(0x10, &intf->seqno);
47105+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47106 else
47107- seqno = atomic_read(&intf->seqno);
47108+ seqno = atomic_read_unchecked(&intf->seqno);
47109
47110 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47111 hdr->seq_ctrl |= cpu_to_le16(seqno);
47112diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47113index e2b3d9c..67a5184 100644
47114--- a/drivers/net/wireless/ti/wl1251/sdio.c
47115+++ b/drivers/net/wireless/ti/wl1251/sdio.c
47116@@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47117
47118 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47119
47120- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47121- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47122+ pax_open_kernel();
47123+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47124+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47125+ pax_close_kernel();
47126
47127 wl1251_info("using dedicated interrupt line");
47128 } else {
47129- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47130- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47131+ pax_open_kernel();
47132+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47133+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47134+ pax_close_kernel();
47135
47136 wl1251_info("using SDIO interrupt");
47137 }
47138diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47139index be7129b..4161356 100644
47140--- a/drivers/net/wireless/ti/wl12xx/main.c
47141+++ b/drivers/net/wireless/ti/wl12xx/main.c
47142@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47143 sizeof(wl->conf.mem));
47144
47145 /* read data preparation is only needed by wl127x */
47146- wl->ops->prepare_read = wl127x_prepare_read;
47147+ pax_open_kernel();
47148+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47149+ pax_close_kernel();
47150
47151 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47152 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47153@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47154 sizeof(wl->conf.mem));
47155
47156 /* read data preparation is only needed by wl127x */
47157- wl->ops->prepare_read = wl127x_prepare_read;
47158+ pax_open_kernel();
47159+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47160+ pax_close_kernel();
47161
47162 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47163 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47164diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47165index ec37b16..7e34d66 100644
47166--- a/drivers/net/wireless/ti/wl18xx/main.c
47167+++ b/drivers/net/wireless/ti/wl18xx/main.c
47168@@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47169 }
47170
47171 if (!checksum_param) {
47172- wl18xx_ops.set_rx_csum = NULL;
47173- wl18xx_ops.init_vif = NULL;
47174+ pax_open_kernel();
47175+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
47176+ *(void **)&wl18xx_ops.init_vif = NULL;
47177+ pax_close_kernel();
47178 }
47179
47180 /* Enable 11a Band only if we have 5G antennas */
47181diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47182index 84d94f5..bd6c61c 100644
47183--- a/drivers/net/wireless/zd1211rw/zd_usb.c
47184+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47185@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
47186 {
47187 struct zd_usb *usb = urb->context;
47188 struct zd_usb_interrupt *intr = &usb->intr;
47189- int len;
47190+ unsigned int len;
47191 u16 int_num;
47192
47193 ZD_ASSERT(in_interrupt());
47194diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47195index 7130864..00e64de 100644
47196--- a/drivers/nfc/nfcwilink.c
47197+++ b/drivers/nfc/nfcwilink.c
47198@@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
47199
47200 static int nfcwilink_probe(struct platform_device *pdev)
47201 {
47202- static struct nfcwilink *drv;
47203+ struct nfcwilink *drv;
47204 int rc;
47205 __u32 protocols;
47206
47207diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47208index d93b2b6..ae50401 100644
47209--- a/drivers/oprofile/buffer_sync.c
47210+++ b/drivers/oprofile/buffer_sync.c
47211@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47212 if (cookie == NO_COOKIE)
47213 offset = pc;
47214 if (cookie == INVALID_COOKIE) {
47215- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47216+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47217 offset = pc;
47218 }
47219 if (cookie != last_cookie) {
47220@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47221 /* add userspace sample */
47222
47223 if (!mm) {
47224- atomic_inc(&oprofile_stats.sample_lost_no_mm);
47225+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47226 return 0;
47227 }
47228
47229 cookie = lookup_dcookie(mm, s->eip, &offset);
47230
47231 if (cookie == INVALID_COOKIE) {
47232- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47233+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47234 return 0;
47235 }
47236
47237@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47238 /* ignore backtraces if failed to add a sample */
47239 if (state == sb_bt_start) {
47240 state = sb_bt_ignore;
47241- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47242+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47243 }
47244 }
47245 release_mm(mm);
47246diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47247index c0cc4e7..44d4e54 100644
47248--- a/drivers/oprofile/event_buffer.c
47249+++ b/drivers/oprofile/event_buffer.c
47250@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47251 }
47252
47253 if (buffer_pos == buffer_size) {
47254- atomic_inc(&oprofile_stats.event_lost_overflow);
47255+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47256 return;
47257 }
47258
47259diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47260index ed2c3ec..deda85a 100644
47261--- a/drivers/oprofile/oprof.c
47262+++ b/drivers/oprofile/oprof.c
47263@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47264 if (oprofile_ops.switch_events())
47265 return;
47266
47267- atomic_inc(&oprofile_stats.multiplex_counter);
47268+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47269 start_switch_worker();
47270 }
47271
47272diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47273index ee2cfce..7f8f699 100644
47274--- a/drivers/oprofile/oprofile_files.c
47275+++ b/drivers/oprofile/oprofile_files.c
47276@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47277
47278 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47279
47280-static ssize_t timeout_read(struct file *file, char __user *buf,
47281+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47282 size_t count, loff_t *offset)
47283 {
47284 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47285diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47286index 59659ce..6c860a0 100644
47287--- a/drivers/oprofile/oprofile_stats.c
47288+++ b/drivers/oprofile/oprofile_stats.c
47289@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47290 cpu_buf->sample_invalid_eip = 0;
47291 }
47292
47293- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47294- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47295- atomic_set(&oprofile_stats.event_lost_overflow, 0);
47296- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47297- atomic_set(&oprofile_stats.multiplex_counter, 0);
47298+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47299+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47300+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47301+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47302+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47303 }
47304
47305
47306diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47307index 1fc622b..8c48fc3 100644
47308--- a/drivers/oprofile/oprofile_stats.h
47309+++ b/drivers/oprofile/oprofile_stats.h
47310@@ -13,11 +13,11 @@
47311 #include <linux/atomic.h>
47312
47313 struct oprofile_stat_struct {
47314- atomic_t sample_lost_no_mm;
47315- atomic_t sample_lost_no_mapping;
47316- atomic_t bt_lost_no_mapping;
47317- atomic_t event_lost_overflow;
47318- atomic_t multiplex_counter;
47319+ atomic_unchecked_t sample_lost_no_mm;
47320+ atomic_unchecked_t sample_lost_no_mapping;
47321+ atomic_unchecked_t bt_lost_no_mapping;
47322+ atomic_unchecked_t event_lost_overflow;
47323+ atomic_unchecked_t multiplex_counter;
47324 };
47325
47326 extern struct oprofile_stat_struct oprofile_stats;
47327diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47328index 3f49345..c750d0b 100644
47329--- a/drivers/oprofile/oprofilefs.c
47330+++ b/drivers/oprofile/oprofilefs.c
47331@@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47332
47333 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47334 {
47335- atomic_t *val = file->private_data;
47336- return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47337+ atomic_unchecked_t *val = file->private_data;
47338+ return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47339 }
47340
47341
47342@@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47343
47344
47345 int oprofilefs_create_ro_atomic(struct dentry *root,
47346- char const *name, atomic_t *val)
47347+ char const *name, atomic_unchecked_t *val)
47348 {
47349 return __oprofilefs_create_file(root, name,
47350 &atomic_ro_fops, 0444, val);
47351diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47352index 61be1d9..dec05d7 100644
47353--- a/drivers/oprofile/timer_int.c
47354+++ b/drivers/oprofile/timer_int.c
47355@@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47356 return NOTIFY_OK;
47357 }
47358
47359-static struct notifier_block __refdata oprofile_cpu_notifier = {
47360+static struct notifier_block oprofile_cpu_notifier = {
47361 .notifier_call = oprofile_cpu_notify,
47362 };
47363
47364diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47365index 92ed045..62d39bd7 100644
47366--- a/drivers/parport/procfs.c
47367+++ b/drivers/parport/procfs.c
47368@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47369
47370 *ppos += len;
47371
47372- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47373+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47374 }
47375
47376 #ifdef CONFIG_PARPORT_1284
47377@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47378
47379 *ppos += len;
47380
47381- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47382+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47383 }
47384 #endif /* IEEE1284.3 support. */
47385
47386diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47387index ecfac7e..41be7028 100644
47388--- a/drivers/pci/hotplug/acpiphp_ibm.c
47389+++ b/drivers/pci/hotplug/acpiphp_ibm.c
47390@@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
47391 goto init_cleanup;
47392 }
47393
47394- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47395+ pax_open_kernel();
47396+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47397+ pax_close_kernel();
47398 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47399
47400 return retval;
47401diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47402index 7536eef..52dc8fa 100644
47403--- a/drivers/pci/hotplug/cpcihp_generic.c
47404+++ b/drivers/pci/hotplug/cpcihp_generic.c
47405@@ -73,7 +73,6 @@ static u16 port;
47406 static unsigned int enum_bit;
47407 static u8 enum_mask;
47408
47409-static struct cpci_hp_controller_ops generic_hpc_ops;
47410 static struct cpci_hp_controller generic_hpc;
47411
47412 static int __init validate_parameters(void)
47413@@ -139,6 +138,10 @@ static int query_enum(void)
47414 return ((value & enum_mask) == enum_mask);
47415 }
47416
47417+static struct cpci_hp_controller_ops generic_hpc_ops = {
47418+ .query_enum = query_enum,
47419+};
47420+
47421 static int __init cpcihp_generic_init(void)
47422 {
47423 int status;
47424@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47425 pci_dev_put(dev);
47426
47427 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47428- generic_hpc_ops.query_enum = query_enum;
47429 generic_hpc.ops = &generic_hpc_ops;
47430
47431 status = cpci_hp_register_controller(&generic_hpc);
47432diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47433index e8c4a7c..7046f5c 100644
47434--- a/drivers/pci/hotplug/cpcihp_zt5550.c
47435+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47436@@ -59,7 +59,6 @@
47437 /* local variables */
47438 static bool debug;
47439 static bool poll;
47440-static struct cpci_hp_controller_ops zt5550_hpc_ops;
47441 static struct cpci_hp_controller zt5550_hpc;
47442
47443 /* Primary cPCI bus bridge device */
47444@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47445 return 0;
47446 }
47447
47448+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47449+ .query_enum = zt5550_hc_query_enum,
47450+};
47451+
47452 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47453 {
47454 int status;
47455@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47456 dbg("returned from zt5550_hc_config");
47457
47458 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47459- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47460 zt5550_hpc.ops = &zt5550_hpc_ops;
47461 if(!poll) {
47462 zt5550_hpc.irq = hc_dev->irq;
47463 zt5550_hpc.irq_flags = IRQF_SHARED;
47464 zt5550_hpc.dev_id = hc_dev;
47465
47466- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47467- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47468- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47469+ pax_open_kernel();
47470+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47471+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47472+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47473+ pax_open_kernel();
47474 } else {
47475 info("using ENUM# polling mode");
47476 }
47477diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47478index 76ba8a1..20ca857 100644
47479--- a/drivers/pci/hotplug/cpqphp_nvram.c
47480+++ b/drivers/pci/hotplug/cpqphp_nvram.c
47481@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47482
47483 void compaq_nvram_init (void __iomem *rom_start)
47484 {
47485+
47486+#ifndef CONFIG_PAX_KERNEXEC
47487 if (rom_start) {
47488 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47489 }
47490+#endif
47491+
47492 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47493
47494 /* initialize our int15 lock */
47495diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47496index cfa92a9..29539c5 100644
47497--- a/drivers/pci/hotplug/pci_hotplug_core.c
47498+++ b/drivers/pci/hotplug/pci_hotplug_core.c
47499@@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47500 return -EINVAL;
47501 }
47502
47503- slot->ops->owner = owner;
47504- slot->ops->mod_name = mod_name;
47505+ pax_open_kernel();
47506+ *(struct module **)&slot->ops->owner = owner;
47507+ *(const char **)&slot->ops->mod_name = mod_name;
47508+ pax_close_kernel();
47509
47510 mutex_lock(&pci_hp_mutex);
47511 /*
47512diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47513index bbd48bb..6907ef4 100644
47514--- a/drivers/pci/hotplug/pciehp_core.c
47515+++ b/drivers/pci/hotplug/pciehp_core.c
47516@@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47517 struct slot *slot = ctrl->slot;
47518 struct hotplug_slot *hotplug = NULL;
47519 struct hotplug_slot_info *info = NULL;
47520- struct hotplug_slot_ops *ops = NULL;
47521+ hotplug_slot_ops_no_const *ops = NULL;
47522 char name[SLOT_NAME_SIZE];
47523 int retval = -ENOMEM;
47524
47525diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47526index c91e6c1..5c723ef 100644
47527--- a/drivers/pci/pci-sysfs.c
47528+++ b/drivers/pci/pci-sysfs.c
47529@@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47530 {
47531 /* allocate attribute structure, piggyback attribute name */
47532 int name_len = write_combine ? 13 : 10;
47533- struct bin_attribute *res_attr;
47534+ bin_attribute_no_const *res_attr;
47535 int retval;
47536
47537 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47538@@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47539 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47540 {
47541 int retval;
47542- struct bin_attribute *attr;
47543+ bin_attribute_no_const *attr;
47544
47545 /* If the device has VPD, try to expose it in sysfs. */
47546 if (dev->vpd) {
47547@@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47548 {
47549 int retval;
47550 int rom_size = 0;
47551- struct bin_attribute *attr;
47552+ bin_attribute_no_const *attr;
47553
47554 if (!sysfs_initialized)
47555 return -EACCES;
47556diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47557index 9c91ecc..bda4796 100644
47558--- a/drivers/pci/pci.h
47559+++ b/drivers/pci/pci.h
47560@@ -95,7 +95,7 @@ struct pci_vpd_ops {
47561 struct pci_vpd {
47562 unsigned int len;
47563 const struct pci_vpd_ops *ops;
47564- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47565+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47566 };
47567
47568 int pci_vpd_pci22_init(struct pci_dev *dev);
47569diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47570index f1272dc..e92a1ac 100644
47571--- a/drivers/pci/pcie/aspm.c
47572+++ b/drivers/pci/pcie/aspm.c
47573@@ -27,9 +27,9 @@
47574 #define MODULE_PARAM_PREFIX "pcie_aspm."
47575
47576 /* Note: those are not register definitions */
47577-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47578-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47579-#define ASPM_STATE_L1 (4) /* L1 state */
47580+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47581+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47582+#define ASPM_STATE_L1 (4U) /* L1 state */
47583 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47584 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47585
47586diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47587index 38e403d..a2ce55a 100644
47588--- a/drivers/pci/probe.c
47589+++ b/drivers/pci/probe.c
47590@@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47591 struct pci_bus_region region, inverted_region;
47592 bool bar_too_big = false, bar_disabled = false;
47593
47594- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47595+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47596
47597 /* No printks while decoding is disabled! */
47598 if (!dev->mmio_always_on) {
47599diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47600index 46d1378..30e452b 100644
47601--- a/drivers/pci/proc.c
47602+++ b/drivers/pci/proc.c
47603@@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47604 static int __init pci_proc_init(void)
47605 {
47606 struct pci_dev *dev = NULL;
47607+
47608+#ifdef CONFIG_GRKERNSEC_PROC_ADD
47609+#ifdef CONFIG_GRKERNSEC_PROC_USER
47610+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47611+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47612+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47613+#endif
47614+#else
47615 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47616+#endif
47617 proc_create("devices", 0, proc_bus_pci_dir,
47618 &proc_bus_pci_dev_operations);
47619 proc_initialized = 1;
47620diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47621index 3e5b4497..dcdfb70 100644
47622--- a/drivers/platform/chrome/chromeos_laptop.c
47623+++ b/drivers/platform/chrome/chromeos_laptop.c
47624@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47625 return 0;
47626 }
47627
47628-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47629+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47630 {
47631 .ident = "Samsung Series 5 550 - Touchpad",
47632 .matches = {
47633diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47634index 19c313b..ed28b38 100644
47635--- a/drivers/platform/x86/asus-wmi.c
47636+++ b/drivers/platform/x86/asus-wmi.c
47637@@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47638 int err;
47639 u32 retval = -1;
47640
47641+#ifdef CONFIG_GRKERNSEC_KMEM
47642+ return -EPERM;
47643+#endif
47644+
47645 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47646
47647 if (err < 0)
47648@@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47649 int err;
47650 u32 retval = -1;
47651
47652+#ifdef CONFIG_GRKERNSEC_KMEM
47653+ return -EPERM;
47654+#endif
47655+
47656 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47657 &retval);
47658
47659@@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47660 union acpi_object *obj;
47661 acpi_status status;
47662
47663+#ifdef CONFIG_GRKERNSEC_KMEM
47664+ return -EPERM;
47665+#endif
47666+
47667 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47668 1, asus->debug.method_id,
47669 &input, &output);
47670diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47671index 62f8030..c7f2a45 100644
47672--- a/drivers/platform/x86/msi-laptop.c
47673+++ b/drivers/platform/x86/msi-laptop.c
47674@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47675
47676 if (!quirks->ec_read_only) {
47677 /* allow userland write sysfs file */
47678- dev_attr_bluetooth.store = store_bluetooth;
47679- dev_attr_wlan.store = store_wlan;
47680- dev_attr_threeg.store = store_threeg;
47681- dev_attr_bluetooth.attr.mode |= S_IWUSR;
47682- dev_attr_wlan.attr.mode |= S_IWUSR;
47683- dev_attr_threeg.attr.mode |= S_IWUSR;
47684+ pax_open_kernel();
47685+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47686+ *(void **)&dev_attr_wlan.store = store_wlan;
47687+ *(void **)&dev_attr_threeg.store = store_threeg;
47688+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47689+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47690+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47691+ pax_close_kernel();
47692 }
47693
47694 /* disable hardware control by fn key */
47695diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47696index 70222f2..8c8ce66 100644
47697--- a/drivers/platform/x86/msi-wmi.c
47698+++ b/drivers/platform/x86/msi-wmi.c
47699@@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47700 static void msi_wmi_notify(u32 value, void *context)
47701 {
47702 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47703- static struct key_entry *key;
47704+ struct key_entry *key;
47705 union acpi_object *obj;
47706 acpi_status status;
47707
47708diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47709index fb233ae..23a325c 100644
47710--- a/drivers/platform/x86/sony-laptop.c
47711+++ b/drivers/platform/x86/sony-laptop.c
47712@@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47713 }
47714
47715 /* High speed charging function */
47716-static struct device_attribute *hsc_handle;
47717+static device_attribute_no_const *hsc_handle;
47718
47719 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47720 struct device_attribute *attr,
47721diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47722index 58b0274..6704626 100644
47723--- a/drivers/platform/x86/thinkpad_acpi.c
47724+++ b/drivers/platform/x86/thinkpad_acpi.c
47725@@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47726 return 0;
47727 }
47728
47729-void static hotkey_mask_warn_incomplete_mask(void)
47730+static void hotkey_mask_warn_incomplete_mask(void)
47731 {
47732 /* log only what the user can fix... */
47733 const u32 wantedmask = hotkey_driver_mask &
47734@@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47735 }
47736 }
47737
47738-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47739- struct tp_nvram_state *newn,
47740- const u32 event_mask)
47741-{
47742-
47743 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47744 do { \
47745 if ((event_mask & (1 << __scancode)) && \
47746@@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47747 tpacpi_hotkey_send_key(__scancode); \
47748 } while (0)
47749
47750- void issue_volchange(const unsigned int oldvol,
47751- const unsigned int newvol)
47752- {
47753- unsigned int i = oldvol;
47754+static void issue_volchange(const unsigned int oldvol,
47755+ const unsigned int newvol,
47756+ const u32 event_mask)
47757+{
47758+ unsigned int i = oldvol;
47759
47760- while (i > newvol) {
47761- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47762- i--;
47763- }
47764- while (i < newvol) {
47765- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47766- i++;
47767- }
47768+ while (i > newvol) {
47769+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47770+ i--;
47771 }
47772+ while (i < newvol) {
47773+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47774+ i++;
47775+ }
47776+}
47777
47778- void issue_brightnesschange(const unsigned int oldbrt,
47779- const unsigned int newbrt)
47780- {
47781- unsigned int i = oldbrt;
47782+static void issue_brightnesschange(const unsigned int oldbrt,
47783+ const unsigned int newbrt,
47784+ const u32 event_mask)
47785+{
47786+ unsigned int i = oldbrt;
47787
47788- while (i > newbrt) {
47789- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47790- i--;
47791- }
47792- while (i < newbrt) {
47793- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47794- i++;
47795- }
47796+ while (i > newbrt) {
47797+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47798+ i--;
47799+ }
47800+ while (i < newbrt) {
47801+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47802+ i++;
47803 }
47804+}
47805
47806+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47807+ struct tp_nvram_state *newn,
47808+ const u32 event_mask)
47809+{
47810 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47811 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47812 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47813@@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47814 oldn->volume_level != newn->volume_level) {
47815 /* recently muted, or repeated mute keypress, or
47816 * multiple presses ending in mute */
47817- issue_volchange(oldn->volume_level, newn->volume_level);
47818+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47819 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47820 }
47821 } else {
47822@@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47823 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47824 }
47825 if (oldn->volume_level != newn->volume_level) {
47826- issue_volchange(oldn->volume_level, newn->volume_level);
47827+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47828 } else if (oldn->volume_toggle != newn->volume_toggle) {
47829 /* repeated vol up/down keypress at end of scale ? */
47830 if (newn->volume_level == 0)
47831@@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47832 /* handle brightness */
47833 if (oldn->brightness_level != newn->brightness_level) {
47834 issue_brightnesschange(oldn->brightness_level,
47835- newn->brightness_level);
47836+ newn->brightness_level,
47837+ event_mask);
47838 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47839 /* repeated key presses that didn't change state */
47840 if (newn->brightness_level == 0)
47841@@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47842 && !tp_features.bright_unkfw)
47843 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47844 }
47845+}
47846
47847 #undef TPACPI_COMPARE_KEY
47848 #undef TPACPI_MAY_SEND_KEY
47849-}
47850
47851 /*
47852 * Polling driver
47853diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47854index 769d265..a3a05ca 100644
47855--- a/drivers/pnp/pnpbios/bioscalls.c
47856+++ b/drivers/pnp/pnpbios/bioscalls.c
47857@@ -58,7 +58,7 @@ do { \
47858 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47859 } while(0)
47860
47861-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47862+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47863 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47864
47865 /*
47866@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47867
47868 cpu = get_cpu();
47869 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47870+
47871+ pax_open_kernel();
47872 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47873+ pax_close_kernel();
47874
47875 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47876 spin_lock_irqsave(&pnp_bios_lock, flags);
47877@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47878 :"memory");
47879 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47880
47881+ pax_open_kernel();
47882 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47883+ pax_close_kernel();
47884+
47885 put_cpu();
47886
47887 /* If we get here and this is set then the PnP BIOS faulted on us. */
47888@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47889 return status;
47890 }
47891
47892-void pnpbios_calls_init(union pnp_bios_install_struct *header)
47893+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47894 {
47895 int i;
47896
47897@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47898 pnp_bios_callpoint.offset = header->fields.pm16offset;
47899 pnp_bios_callpoint.segment = PNP_CS16;
47900
47901+ pax_open_kernel();
47902+
47903 for_each_possible_cpu(i) {
47904 struct desc_struct *gdt = get_cpu_gdt_table(i);
47905 if (!gdt)
47906@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47907 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47908 (unsigned long)__va(header->fields.pm16dseg));
47909 }
47910+
47911+ pax_close_kernel();
47912 }
47913diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47914index d95e101..67f0c3f 100644
47915--- a/drivers/pnp/resource.c
47916+++ b/drivers/pnp/resource.c
47917@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47918 return 1;
47919
47920 /* check if the resource is valid */
47921- if (*irq < 0 || *irq > 15)
47922+ if (*irq > 15)
47923 return 0;
47924
47925 /* check if the resource is reserved */
47926@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47927 return 1;
47928
47929 /* check if the resource is valid */
47930- if (*dma < 0 || *dma == 4 || *dma > 7)
47931+ if (*dma == 4 || *dma > 7)
47932 return 0;
47933
47934 /* check if the resource is reserved */
47935diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47936index 0c52e2a..3421ab7 100644
47937--- a/drivers/power/pda_power.c
47938+++ b/drivers/power/pda_power.c
47939@@ -37,7 +37,11 @@ static int polling;
47940
47941 #if IS_ENABLED(CONFIG_USB_PHY)
47942 static struct usb_phy *transceiver;
47943-static struct notifier_block otg_nb;
47944+static int otg_handle_notification(struct notifier_block *nb,
47945+ unsigned long event, void *unused);
47946+static struct notifier_block otg_nb = {
47947+ .notifier_call = otg_handle_notification
47948+};
47949 #endif
47950
47951 static struct regulator *ac_draw;
47952@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47953
47954 #if IS_ENABLED(CONFIG_USB_PHY)
47955 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47956- otg_nb.notifier_call = otg_handle_notification;
47957 ret = usb_register_notifier(transceiver, &otg_nb);
47958 if (ret) {
47959 dev_err(dev, "failure to register otg notifier\n");
47960diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47961index cc439fd..8fa30df 100644
47962--- a/drivers/power/power_supply.h
47963+++ b/drivers/power/power_supply.h
47964@@ -16,12 +16,12 @@ struct power_supply;
47965
47966 #ifdef CONFIG_SYSFS
47967
47968-extern void power_supply_init_attrs(struct device_type *dev_type);
47969+extern void power_supply_init_attrs(void);
47970 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47971
47972 #else
47973
47974-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47975+static inline void power_supply_init_attrs(void) {}
47976 #define power_supply_uevent NULL
47977
47978 #endif /* CONFIG_SYSFS */
47979diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47980index 557af94..84dc1fe 100644
47981--- a/drivers/power/power_supply_core.c
47982+++ b/drivers/power/power_supply_core.c
47983@@ -24,7 +24,10 @@
47984 struct class *power_supply_class;
47985 EXPORT_SYMBOL_GPL(power_supply_class);
47986
47987-static struct device_type power_supply_dev_type;
47988+extern const struct attribute_group *power_supply_attr_groups[];
47989+static struct device_type power_supply_dev_type = {
47990+ .groups = power_supply_attr_groups,
47991+};
47992
47993 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47994 struct power_supply *supply)
47995@@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47996 return PTR_ERR(power_supply_class);
47997
47998 power_supply_class->dev_uevent = power_supply_uevent;
47999- power_supply_init_attrs(&power_supply_dev_type);
48000+ power_supply_init_attrs();
48001
48002 return 0;
48003 }
48004diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48005index 44420d1..967126e 100644
48006--- a/drivers/power/power_supply_sysfs.c
48007+++ b/drivers/power/power_supply_sysfs.c
48008@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48009 .is_visible = power_supply_attr_is_visible,
48010 };
48011
48012-static const struct attribute_group *power_supply_attr_groups[] = {
48013+const struct attribute_group *power_supply_attr_groups[] = {
48014 &power_supply_attr_group,
48015 NULL,
48016 };
48017
48018-void power_supply_init_attrs(struct device_type *dev_type)
48019+void power_supply_init_attrs(void)
48020 {
48021 int i;
48022
48023- dev_type->groups = power_supply_attr_groups;
48024-
48025 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48026 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48027 }
48028diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48029index 84419af..268ede8 100644
48030--- a/drivers/powercap/powercap_sys.c
48031+++ b/drivers/powercap/powercap_sys.c
48032@@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48033 struct device_attribute name_attr;
48034 };
48035
48036+static ssize_t show_constraint_name(struct device *dev,
48037+ struct device_attribute *dev_attr,
48038+ char *buf);
48039+
48040 static struct powercap_constraint_attr
48041- constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48042+ constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48043+ [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48044+ .power_limit_attr = {
48045+ .attr = {
48046+ .name = NULL,
48047+ .mode = S_IWUSR | S_IRUGO
48048+ },
48049+ .show = show_constraint_power_limit_uw,
48050+ .store = store_constraint_power_limit_uw
48051+ },
48052+
48053+ .time_window_attr = {
48054+ .attr = {
48055+ .name = NULL,
48056+ .mode = S_IWUSR | S_IRUGO
48057+ },
48058+ .show = show_constraint_time_window_us,
48059+ .store = store_constraint_time_window_us
48060+ },
48061+
48062+ .max_power_attr = {
48063+ .attr = {
48064+ .name = NULL,
48065+ .mode = S_IRUGO
48066+ },
48067+ .show = show_constraint_max_power_uw,
48068+ .store = NULL
48069+ },
48070+
48071+ .min_power_attr = {
48072+ .attr = {
48073+ .name = NULL,
48074+ .mode = S_IRUGO
48075+ },
48076+ .show = show_constraint_min_power_uw,
48077+ .store = NULL
48078+ },
48079+
48080+ .max_time_window_attr = {
48081+ .attr = {
48082+ .name = NULL,
48083+ .mode = S_IRUGO
48084+ },
48085+ .show = show_constraint_max_time_window_us,
48086+ .store = NULL
48087+ },
48088+
48089+ .min_time_window_attr = {
48090+ .attr = {
48091+ .name = NULL,
48092+ .mode = S_IRUGO
48093+ },
48094+ .show = show_constraint_min_time_window_us,
48095+ .store = NULL
48096+ },
48097+
48098+ .name_attr = {
48099+ .attr = {
48100+ .name = NULL,
48101+ .mode = S_IRUGO
48102+ },
48103+ .show = show_constraint_name,
48104+ .store = NULL
48105+ }
48106+ }
48107+};
48108
48109 /* A list of powercap control_types */
48110 static LIST_HEAD(powercap_cntrl_list);
48111@@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48112 }
48113
48114 static int create_constraint_attribute(int id, const char *name,
48115- int mode,
48116- struct device_attribute *dev_attr,
48117- ssize_t (*show)(struct device *,
48118- struct device_attribute *, char *),
48119- ssize_t (*store)(struct device *,
48120- struct device_attribute *,
48121- const char *, size_t)
48122- )
48123+ struct device_attribute *dev_attr)
48124 {
48125+ name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48126
48127- dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48128- id, name);
48129- if (!dev_attr->attr.name)
48130+ if (!name)
48131 return -ENOMEM;
48132- dev_attr->attr.mode = mode;
48133- dev_attr->show = show;
48134- dev_attr->store = store;
48135+
48136+ pax_open_kernel();
48137+ *(const char **)&dev_attr->attr.name = name;
48138+ pax_close_kernel();
48139
48140 return 0;
48141 }
48142@@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48143
48144 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48145 ret = create_constraint_attribute(i, "power_limit_uw",
48146- S_IWUSR | S_IRUGO,
48147- &constraint_attrs[i].power_limit_attr,
48148- show_constraint_power_limit_uw,
48149- store_constraint_power_limit_uw);
48150+ &constraint_attrs[i].power_limit_attr);
48151 if (ret)
48152 goto err_alloc;
48153 ret = create_constraint_attribute(i, "time_window_us",
48154- S_IWUSR | S_IRUGO,
48155- &constraint_attrs[i].time_window_attr,
48156- show_constraint_time_window_us,
48157- store_constraint_time_window_us);
48158+ &constraint_attrs[i].time_window_attr);
48159 if (ret)
48160 goto err_alloc;
48161- ret = create_constraint_attribute(i, "name", S_IRUGO,
48162- &constraint_attrs[i].name_attr,
48163- show_constraint_name,
48164- NULL);
48165+ ret = create_constraint_attribute(i, "name",
48166+ &constraint_attrs[i].name_attr);
48167 if (ret)
48168 goto err_alloc;
48169- ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48170- &constraint_attrs[i].max_power_attr,
48171- show_constraint_max_power_uw,
48172- NULL);
48173+ ret = create_constraint_attribute(i, "max_power_uw",
48174+ &constraint_attrs[i].max_power_attr);
48175 if (ret)
48176 goto err_alloc;
48177- ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48178- &constraint_attrs[i].min_power_attr,
48179- show_constraint_min_power_uw,
48180- NULL);
48181+ ret = create_constraint_attribute(i, "min_power_uw",
48182+ &constraint_attrs[i].min_power_attr);
48183 if (ret)
48184 goto err_alloc;
48185 ret = create_constraint_attribute(i, "max_time_window_us",
48186- S_IRUGO,
48187- &constraint_attrs[i].max_time_window_attr,
48188- show_constraint_max_time_window_us,
48189- NULL);
48190+ &constraint_attrs[i].max_time_window_attr);
48191 if (ret)
48192 goto err_alloc;
48193 ret = create_constraint_attribute(i, "min_time_window_us",
48194- S_IRUGO,
48195- &constraint_attrs[i].min_time_window_attr,
48196- show_constraint_min_time_window_us,
48197- NULL);
48198+ &constraint_attrs[i].min_time_window_attr);
48199 if (ret)
48200 goto err_alloc;
48201
48202@@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48203 power_zone->zone_dev_attrs[count++] =
48204 &dev_attr_max_energy_range_uj.attr;
48205 if (power_zone->ops->get_energy_uj) {
48206+ pax_open_kernel();
48207 if (power_zone->ops->reset_energy_uj)
48208- dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48209+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48210 else
48211- dev_attr_energy_uj.attr.mode = S_IRUGO;
48212+ *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48213+ pax_close_kernel();
48214 power_zone->zone_dev_attrs[count++] =
48215 &dev_attr_energy_uj.attr;
48216 }
48217diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48218index 7271299..20217a5 100644
48219--- a/drivers/regulator/core.c
48220+++ b/drivers/regulator/core.c
48221@@ -3366,7 +3366,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48222 {
48223 const struct regulation_constraints *constraints = NULL;
48224 const struct regulator_init_data *init_data;
48225- static atomic_t regulator_no = ATOMIC_INIT(0);
48226+ static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48227 struct regulator_dev *rdev;
48228 struct device *dev;
48229 int ret, i;
48230@@ -3436,7 +3436,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48231 rdev->dev.of_node = config->of_node;
48232 rdev->dev.parent = dev;
48233 dev_set_name(&rdev->dev, "regulator.%d",
48234- atomic_inc_return(&regulator_no) - 1);
48235+ atomic_inc_return_unchecked(&regulator_no) - 1);
48236 ret = device_register(&rdev->dev);
48237 if (ret != 0) {
48238 put_device(&rdev->dev);
48239diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48240index 8d94d3d..653b623 100644
48241--- a/drivers/regulator/max8660.c
48242+++ b/drivers/regulator/max8660.c
48243@@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
48244 max8660->shadow_regs[MAX8660_OVER1] = 5;
48245 } else {
48246 /* Otherwise devices can be toggled via software */
48247- max8660_dcdc_ops.enable = max8660_dcdc_enable;
48248- max8660_dcdc_ops.disable = max8660_dcdc_disable;
48249+ pax_open_kernel();
48250+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48251+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48252+ pax_close_kernel();
48253 }
48254
48255 /*
48256diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48257index 892aa1e..ebd1b9c 100644
48258--- a/drivers/regulator/max8973-regulator.c
48259+++ b/drivers/regulator/max8973-regulator.c
48260@@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
48261 if (!pdata || !pdata->enable_ext_control) {
48262 max->desc.enable_reg = MAX8973_VOUT;
48263 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48264- max->ops.enable = regulator_enable_regmap;
48265- max->ops.disable = regulator_disable_regmap;
48266- max->ops.is_enabled = regulator_is_enabled_regmap;
48267+ pax_open_kernel();
48268+ *(void **)&max->ops.enable = regulator_enable_regmap;
48269+ *(void **)&max->ops.disable = regulator_disable_regmap;
48270+ *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48271+ pax_close_kernel();
48272 }
48273
48274 if (pdata) {
48275diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48276index 96c9f80..90974ca 100644
48277--- a/drivers/regulator/mc13892-regulator.c
48278+++ b/drivers/regulator/mc13892-regulator.c
48279@@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48280 }
48281 mc13xxx_unlock(mc13892);
48282
48283- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48284+ pax_open_kernel();
48285+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48286 = mc13892_vcam_set_mode;
48287- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48288+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48289 = mc13892_vcam_get_mode;
48290+ pax_close_kernel();
48291
48292 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48293 ARRAY_SIZE(mc13892_regulators));
48294diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48295index a2325bc..04c549f 100644
48296--- a/drivers/rtc/rtc-cmos.c
48297+++ b/drivers/rtc/rtc-cmos.c
48298@@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48299 hpet_rtc_timer_init();
48300
48301 /* export at least the first block of NVRAM */
48302- nvram.size = address_space - NVRAM_OFFSET;
48303+ pax_open_kernel();
48304+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48305+ pax_close_kernel();
48306 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48307 if (retval < 0) {
48308 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48309diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48310index d049393..bb20be0 100644
48311--- a/drivers/rtc/rtc-dev.c
48312+++ b/drivers/rtc/rtc-dev.c
48313@@ -16,6 +16,7 @@
48314 #include <linux/module.h>
48315 #include <linux/rtc.h>
48316 #include <linux/sched.h>
48317+#include <linux/grsecurity.h>
48318 #include "rtc-core.h"
48319
48320 static dev_t rtc_devt;
48321@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48322 if (copy_from_user(&tm, uarg, sizeof(tm)))
48323 return -EFAULT;
48324
48325+ gr_log_timechange();
48326+
48327 return rtc_set_time(rtc, &tm);
48328
48329 case RTC_PIE_ON:
48330diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48331index 4e75345..09f8663 100644
48332--- a/drivers/rtc/rtc-ds1307.c
48333+++ b/drivers/rtc/rtc-ds1307.c
48334@@ -107,7 +107,7 @@ struct ds1307 {
48335 u8 offset; /* register's offset */
48336 u8 regs[11];
48337 u16 nvram_offset;
48338- struct bin_attribute *nvram;
48339+ bin_attribute_no_const *nvram;
48340 enum ds_type type;
48341 unsigned long flags;
48342 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48343diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48344index 11880c1..b823aa4 100644
48345--- a/drivers/rtc/rtc-m48t59.c
48346+++ b/drivers/rtc/rtc-m48t59.c
48347@@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48348 if (IS_ERR(m48t59->rtc))
48349 return PTR_ERR(m48t59->rtc);
48350
48351- m48t59_nvram_attr.size = pdata->offset;
48352+ pax_open_kernel();
48353+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48354+ pax_close_kernel();
48355
48356 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48357 if (ret)
48358diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48359index 14b5f8d..cc9bd26 100644
48360--- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48361+++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48362@@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48363 for (bit = 0; bit < 8; bit++) {
48364
48365 if ((pci_status[i] & (0x1 << bit)) != 0) {
48366- static const char *s;
48367+ const char *s;
48368
48369 s = pci_status_strings[bit];
48370 if (i == 7/*TARG*/ && bit == 3)
48371@@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48372
48373 for (bit = 0; bit < 8; bit++) {
48374
48375- if ((split_status[i] & (0x1 << bit)) != 0) {
48376- static const char *s;
48377-
48378- s = split_status_strings[bit];
48379- printk(s, ahd_name(ahd),
48380+ if ((split_status[i] & (0x1 << bit)) != 0)
48381+ printk(split_status_strings[bit], ahd_name(ahd),
48382 split_status_source[i]);
48383- }
48384
48385 if (i > 1)
48386 continue;
48387
48388- if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48389- static const char *s;
48390-
48391- s = split_status_strings[bit];
48392- printk(s, ahd_name(ahd), "SG");
48393- }
48394+ if ((sg_split_status[i] & (0x1 << bit)) != 0)
48395+ printk(split_status_strings[bit], ahd_name(ahd), "SG");
48396 }
48397 }
48398 /*
48399diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48400index e693af6..2e525b6 100644
48401--- a/drivers/scsi/bfa/bfa_fcpim.h
48402+++ b/drivers/scsi/bfa/bfa_fcpim.h
48403@@ -36,7 +36,7 @@ struct bfa_iotag_s {
48404
48405 struct bfa_itn_s {
48406 bfa_isr_func_t isr;
48407-};
48408+} __no_const;
48409
48410 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48411 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48412diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48413index a3ab5cc..8143622 100644
48414--- a/drivers/scsi/bfa/bfa_fcs.c
48415+++ b/drivers/scsi/bfa/bfa_fcs.c
48416@@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48417 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48418
48419 static struct bfa_fcs_mod_s fcs_modules[] = {
48420- { bfa_fcs_port_attach, NULL, NULL },
48421- { bfa_fcs_uf_attach, NULL, NULL },
48422- { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48423- bfa_fcs_fabric_modexit },
48424+ {
48425+ .attach = bfa_fcs_port_attach,
48426+ .modinit = NULL,
48427+ .modexit = NULL
48428+ },
48429+ {
48430+ .attach = bfa_fcs_uf_attach,
48431+ .modinit = NULL,
48432+ .modexit = NULL
48433+ },
48434+ {
48435+ .attach = bfa_fcs_fabric_attach,
48436+ .modinit = bfa_fcs_fabric_modinit,
48437+ .modexit = bfa_fcs_fabric_modexit
48438+ },
48439 };
48440
48441 /*
48442diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48443index f5e4e61..a0acaf6 100644
48444--- a/drivers/scsi/bfa/bfa_fcs_lport.c
48445+++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48446@@ -89,15 +89,26 @@ static struct {
48447 void (*offline) (struct bfa_fcs_lport_s *port);
48448 } __port_action[] = {
48449 {
48450- bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48451- bfa_fcs_lport_unknown_offline}, {
48452- bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48453- bfa_fcs_lport_fab_offline}, {
48454- bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48455- bfa_fcs_lport_n2n_offline}, {
48456- bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48457- bfa_fcs_lport_loop_offline},
48458- };
48459+ .init = bfa_fcs_lport_unknown_init,
48460+ .online = bfa_fcs_lport_unknown_online,
48461+ .offline = bfa_fcs_lport_unknown_offline
48462+ },
48463+ {
48464+ .init = bfa_fcs_lport_fab_init,
48465+ .online = bfa_fcs_lport_fab_online,
48466+ .offline = bfa_fcs_lport_fab_offline
48467+ },
48468+ {
48469+ .init = bfa_fcs_lport_n2n_init,
48470+ .online = bfa_fcs_lport_n2n_online,
48471+ .offline = bfa_fcs_lport_n2n_offline
48472+ },
48473+ {
48474+ .init = bfa_fcs_lport_loop_init,
48475+ .online = bfa_fcs_lport_loop_online,
48476+ .offline = bfa_fcs_lport_loop_offline
48477+ },
48478+};
48479
48480 /*
48481 * fcs_port_sm FCS logical port state machine
48482diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48483index 90814fe..4384138 100644
48484--- a/drivers/scsi/bfa/bfa_ioc.h
48485+++ b/drivers/scsi/bfa/bfa_ioc.h
48486@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48487 bfa_ioc_disable_cbfn_t disable_cbfn;
48488 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48489 bfa_ioc_reset_cbfn_t reset_cbfn;
48490-};
48491+} __no_const;
48492
48493 /*
48494 * IOC event notification mechanism.
48495@@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48496 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48497 enum bfi_ioc_state fwstate);
48498 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48499-};
48500+} __no_const;
48501
48502 /*
48503 * Queue element to wait for room in request queue. FIFO order is
48504diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48505index a14c784..6de6790 100644
48506--- a/drivers/scsi/bfa/bfa_modules.h
48507+++ b/drivers/scsi/bfa/bfa_modules.h
48508@@ -78,12 +78,12 @@ enum {
48509 \
48510 extern struct bfa_module_s hal_mod_ ## __mod; \
48511 struct bfa_module_s hal_mod_ ## __mod = { \
48512- bfa_ ## __mod ## _meminfo, \
48513- bfa_ ## __mod ## _attach, \
48514- bfa_ ## __mod ## _detach, \
48515- bfa_ ## __mod ## _start, \
48516- bfa_ ## __mod ## _stop, \
48517- bfa_ ## __mod ## _iocdisable, \
48518+ .meminfo = bfa_ ## __mod ## _meminfo, \
48519+ .attach = bfa_ ## __mod ## _attach, \
48520+ .detach = bfa_ ## __mod ## _detach, \
48521+ .start = bfa_ ## __mod ## _start, \
48522+ .stop = bfa_ ## __mod ## _stop, \
48523+ .iocdisable = bfa_ ## __mod ## _iocdisable, \
48524 }
48525
48526 #define BFA_CACHELINE_SZ (256)
48527diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48528index 045c4e1..13de803 100644
48529--- a/drivers/scsi/fcoe/fcoe_sysfs.c
48530+++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48531@@ -33,8 +33,8 @@
48532 */
48533 #include "libfcoe.h"
48534
48535-static atomic_t ctlr_num;
48536-static atomic_t fcf_num;
48537+static atomic_unchecked_t ctlr_num;
48538+static atomic_unchecked_t fcf_num;
48539
48540 /*
48541 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48542@@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48543 if (!ctlr)
48544 goto out;
48545
48546- ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48547+ ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48548 ctlr->f = f;
48549 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48550 INIT_LIST_HEAD(&ctlr->fcfs);
48551@@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48552 fcf->dev.parent = &ctlr->dev;
48553 fcf->dev.bus = &fcoe_bus_type;
48554 fcf->dev.type = &fcoe_fcf_device_type;
48555- fcf->id = atomic_inc_return(&fcf_num) - 1;
48556+ fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48557 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48558
48559 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48560@@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48561 {
48562 int error;
48563
48564- atomic_set(&ctlr_num, 0);
48565- atomic_set(&fcf_num, 0);
48566+ atomic_set_unchecked(&ctlr_num, 0);
48567+ atomic_set_unchecked(&fcf_num, 0);
48568
48569 error = bus_register(&fcoe_bus_type);
48570 if (error)
48571diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48572index f2c5005..db36c02 100644
48573--- a/drivers/scsi/hosts.c
48574+++ b/drivers/scsi/hosts.c
48575@@ -42,7 +42,7 @@
48576 #include "scsi_logging.h"
48577
48578
48579-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48580+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48581
48582
48583 static void scsi_host_cls_release(struct device *dev)
48584@@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48585 * subtract one because we increment first then return, but we need to
48586 * know what the next host number was before increment
48587 */
48588- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48589+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48590 shost->dma_channel = 0xff;
48591
48592 /* These three are default values which can be overridden */
48593diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48594index 20a5e6e..8b23cea 100644
48595--- a/drivers/scsi/hpsa.c
48596+++ b/drivers/scsi/hpsa.c
48597@@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48598 unsigned long flags;
48599
48600 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48601- return h->access.command_completed(h, q);
48602+ return h->access->command_completed(h, q);
48603
48604 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48605 a = rq->head[rq->current_entry];
48606@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48607 while (!list_empty(&h->reqQ)) {
48608 c = list_entry(h->reqQ.next, struct CommandList, list);
48609 /* can't do anything if fifo is full */
48610- if ((h->access.fifo_full(h))) {
48611+ if ((h->access->fifo_full(h))) {
48612 dev_warn(&h->pdev->dev, "fifo full\n");
48613 break;
48614 }
48615@@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48616
48617 /* Tell the controller execute command */
48618 spin_unlock_irqrestore(&h->lock, flags);
48619- h->access.submit_command(h, c);
48620+ h->access->submit_command(h, c);
48621 spin_lock_irqsave(&h->lock, flags);
48622 }
48623 spin_unlock_irqrestore(&h->lock, flags);
48624@@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48625
48626 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48627 {
48628- return h->access.command_completed(h, q);
48629+ return h->access->command_completed(h, q);
48630 }
48631
48632 static inline bool interrupt_pending(struct ctlr_info *h)
48633 {
48634- return h->access.intr_pending(h);
48635+ return h->access->intr_pending(h);
48636 }
48637
48638 static inline long interrupt_not_for_us(struct ctlr_info *h)
48639 {
48640- return (h->access.intr_pending(h) == 0) ||
48641+ return (h->access->intr_pending(h) == 0) ||
48642 (h->interrupts_enabled == 0);
48643 }
48644
48645@@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48646 if (prod_index < 0)
48647 return -ENODEV;
48648 h->product_name = products[prod_index].product_name;
48649- h->access = *(products[prod_index].access);
48650+ h->access = products[prod_index].access;
48651
48652 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48653 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48654@@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48655
48656 assert_spin_locked(&lockup_detector_lock);
48657 remove_ctlr_from_lockup_detector_list(h);
48658- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48659+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48660 spin_lock_irqsave(&h->lock, flags);
48661 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48662 spin_unlock_irqrestore(&h->lock, flags);
48663@@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48664 }
48665
48666 /* make sure the board interrupts are off */
48667- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48668+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48669
48670 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48671 goto clean2;
48672@@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48673 * fake ones to scoop up any residual completions.
48674 */
48675 spin_lock_irqsave(&h->lock, flags);
48676- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48677+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48678 spin_unlock_irqrestore(&h->lock, flags);
48679 free_irqs(h);
48680 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48681@@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48682 dev_info(&h->pdev->dev, "Board READY.\n");
48683 dev_info(&h->pdev->dev,
48684 "Waiting for stale completions to drain.\n");
48685- h->access.set_intr_mask(h, HPSA_INTR_ON);
48686+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48687 msleep(10000);
48688- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48689+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48690
48691 rc = controller_reset_failed(h->cfgtable);
48692 if (rc)
48693@@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48694 }
48695
48696 /* Turn the interrupts on so we can service requests */
48697- h->access.set_intr_mask(h, HPSA_INTR_ON);
48698+ h->access->set_intr_mask(h, HPSA_INTR_ON);
48699
48700 hpsa_hba_inquiry(h);
48701 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48702@@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48703 * To write all data in the battery backed cache to disks
48704 */
48705 hpsa_flush_cache(h);
48706- h->access.set_intr_mask(h, HPSA_INTR_OFF);
48707+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
48708 hpsa_free_irqs_and_disable_msix(h);
48709 }
48710
48711@@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48712 return;
48713 }
48714 /* Change the access methods to the performant access methods */
48715- h->access = SA5_performant_access;
48716+ h->access = &SA5_performant_access;
48717 h->transMethod = CFGTBL_Trans_Performant;
48718 }
48719
48720diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48721index bc85e72..d463049 100644
48722--- a/drivers/scsi/hpsa.h
48723+++ b/drivers/scsi/hpsa.h
48724@@ -79,7 +79,7 @@ struct ctlr_info {
48725 unsigned int msix_vector;
48726 unsigned int msi_vector;
48727 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48728- struct access_method access;
48729+ struct access_method *access;
48730
48731 /* queue and queue Info */
48732 struct list_head reqQ;
48733@@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48734 }
48735
48736 static struct access_method SA5_access = {
48737- SA5_submit_command,
48738- SA5_intr_mask,
48739- SA5_fifo_full,
48740- SA5_intr_pending,
48741- SA5_completed,
48742+ .submit_command = SA5_submit_command,
48743+ .set_intr_mask = SA5_intr_mask,
48744+ .fifo_full = SA5_fifo_full,
48745+ .intr_pending = SA5_intr_pending,
48746+ .command_completed = SA5_completed,
48747 };
48748
48749 static struct access_method SA5_performant_access = {
48750- SA5_submit_command,
48751- SA5_performant_intr_mask,
48752- SA5_fifo_full,
48753- SA5_performant_intr_pending,
48754- SA5_performant_completed,
48755+ .submit_command = SA5_submit_command,
48756+ .set_intr_mask = SA5_performant_intr_mask,
48757+ .fifo_full = SA5_fifo_full,
48758+ .intr_pending = SA5_performant_intr_pending,
48759+ .command_completed = SA5_performant_completed,
48760 };
48761
48762 struct board_type {
48763diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48764index 1b3a094..068e683 100644
48765--- a/drivers/scsi/libfc/fc_exch.c
48766+++ b/drivers/scsi/libfc/fc_exch.c
48767@@ -101,12 +101,12 @@ struct fc_exch_mgr {
48768 u16 pool_max_index;
48769
48770 struct {
48771- atomic_t no_free_exch;
48772- atomic_t no_free_exch_xid;
48773- atomic_t xid_not_found;
48774- atomic_t xid_busy;
48775- atomic_t seq_not_found;
48776- atomic_t non_bls_resp;
48777+ atomic_unchecked_t no_free_exch;
48778+ atomic_unchecked_t no_free_exch_xid;
48779+ atomic_unchecked_t xid_not_found;
48780+ atomic_unchecked_t xid_busy;
48781+ atomic_unchecked_t seq_not_found;
48782+ atomic_unchecked_t non_bls_resp;
48783 } stats;
48784 };
48785
48786@@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48787 /* allocate memory for exchange */
48788 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48789 if (!ep) {
48790- atomic_inc(&mp->stats.no_free_exch);
48791+ atomic_inc_unchecked(&mp->stats.no_free_exch);
48792 goto out;
48793 }
48794 memset(ep, 0, sizeof(*ep));
48795@@ -874,7 +874,7 @@ out:
48796 return ep;
48797 err:
48798 spin_unlock_bh(&pool->lock);
48799- atomic_inc(&mp->stats.no_free_exch_xid);
48800+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48801 mempool_free(ep, mp->ep_pool);
48802 return NULL;
48803 }
48804@@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48805 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48806 ep = fc_exch_find(mp, xid);
48807 if (!ep) {
48808- atomic_inc(&mp->stats.xid_not_found);
48809+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48810 reject = FC_RJT_OX_ID;
48811 goto out;
48812 }
48813@@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48814 ep = fc_exch_find(mp, xid);
48815 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48816 if (ep) {
48817- atomic_inc(&mp->stats.xid_busy);
48818+ atomic_inc_unchecked(&mp->stats.xid_busy);
48819 reject = FC_RJT_RX_ID;
48820 goto rel;
48821 }
48822@@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48823 }
48824 xid = ep->xid; /* get our XID */
48825 } else if (!ep) {
48826- atomic_inc(&mp->stats.xid_not_found);
48827+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48828 reject = FC_RJT_RX_ID; /* XID not found */
48829 goto out;
48830 }
48831@@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48832 } else {
48833 sp = &ep->seq;
48834 if (sp->id != fh->fh_seq_id) {
48835- atomic_inc(&mp->stats.seq_not_found);
48836+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48837 if (f_ctl & FC_FC_END_SEQ) {
48838 /*
48839 * Update sequence_id based on incoming last
48840@@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48841
48842 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48843 if (!ep) {
48844- atomic_inc(&mp->stats.xid_not_found);
48845+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48846 goto out;
48847 }
48848 if (ep->esb_stat & ESB_ST_COMPLETE) {
48849- atomic_inc(&mp->stats.xid_not_found);
48850+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48851 goto rel;
48852 }
48853 if (ep->rxid == FC_XID_UNKNOWN)
48854 ep->rxid = ntohs(fh->fh_rx_id);
48855 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48856- atomic_inc(&mp->stats.xid_not_found);
48857+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48858 goto rel;
48859 }
48860 if (ep->did != ntoh24(fh->fh_s_id) &&
48861 ep->did != FC_FID_FLOGI) {
48862- atomic_inc(&mp->stats.xid_not_found);
48863+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48864 goto rel;
48865 }
48866 sof = fr_sof(fp);
48867@@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48868 sp->ssb_stat |= SSB_ST_RESP;
48869 sp->id = fh->fh_seq_id;
48870 } else if (sp->id != fh->fh_seq_id) {
48871- atomic_inc(&mp->stats.seq_not_found);
48872+ atomic_inc_unchecked(&mp->stats.seq_not_found);
48873 goto rel;
48874 }
48875
48876@@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48877 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48878
48879 if (!sp)
48880- atomic_inc(&mp->stats.xid_not_found);
48881+ atomic_inc_unchecked(&mp->stats.xid_not_found);
48882 else
48883- atomic_inc(&mp->stats.non_bls_resp);
48884+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
48885
48886 fc_frame_free(fp);
48887 }
48888@@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48889
48890 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48891 mp = ema->mp;
48892- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48893+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48894 st->fc_no_free_exch_xid +=
48895- atomic_read(&mp->stats.no_free_exch_xid);
48896- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48897- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48898- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48899- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48900+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48901+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48902+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48903+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48904+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48905 }
48906 }
48907 EXPORT_SYMBOL(fc_exch_update_stats);
48908diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48909index d289583..b745eec 100644
48910--- a/drivers/scsi/libsas/sas_ata.c
48911+++ b/drivers/scsi/libsas/sas_ata.c
48912@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48913 .postreset = ata_std_postreset,
48914 .error_handler = ata_std_error_handler,
48915 .post_internal_cmd = sas_ata_post_internal,
48916- .qc_defer = ata_std_qc_defer,
48917+ .qc_defer = ata_std_qc_defer,
48918 .qc_prep = ata_noop_qc_prep,
48919 .qc_issue = sas_ata_qc_issue,
48920 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48921diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48922index 4e1b75c..0bbdfa9 100644
48923--- a/drivers/scsi/lpfc/lpfc.h
48924+++ b/drivers/scsi/lpfc/lpfc.h
48925@@ -432,7 +432,7 @@ struct lpfc_vport {
48926 struct dentry *debug_nodelist;
48927 struct dentry *vport_debugfs_root;
48928 struct lpfc_debugfs_trc *disc_trc;
48929- atomic_t disc_trc_cnt;
48930+ atomic_unchecked_t disc_trc_cnt;
48931 #endif
48932 uint8_t stat_data_enabled;
48933 uint8_t stat_data_blocked;
48934@@ -865,8 +865,8 @@ struct lpfc_hba {
48935 struct timer_list fabric_block_timer;
48936 unsigned long bit_flags;
48937 #define FABRIC_COMANDS_BLOCKED 0
48938- atomic_t num_rsrc_err;
48939- atomic_t num_cmd_success;
48940+ atomic_unchecked_t num_rsrc_err;
48941+ atomic_unchecked_t num_cmd_success;
48942 unsigned long last_rsrc_error_time;
48943 unsigned long last_ramp_down_time;
48944 unsigned long last_ramp_up_time;
48945@@ -902,7 +902,7 @@ struct lpfc_hba {
48946
48947 struct dentry *debug_slow_ring_trc;
48948 struct lpfc_debugfs_trc *slow_ring_trc;
48949- atomic_t slow_ring_trc_cnt;
48950+ atomic_unchecked_t slow_ring_trc_cnt;
48951 /* iDiag debugfs sub-directory */
48952 struct dentry *idiag_root;
48953 struct dentry *idiag_pci_cfg;
48954diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48955index 60084e6..0e2e700 100644
48956--- a/drivers/scsi/lpfc/lpfc_debugfs.c
48957+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48958@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48959
48960 #include <linux/debugfs.h>
48961
48962-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48963+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48964 static unsigned long lpfc_debugfs_start_time = 0L;
48965
48966 /* iDiag */
48967@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48968 lpfc_debugfs_enable = 0;
48969
48970 len = 0;
48971- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48972+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48973 (lpfc_debugfs_max_disc_trc - 1);
48974 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48975 dtp = vport->disc_trc + i;
48976@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48977 lpfc_debugfs_enable = 0;
48978
48979 len = 0;
48980- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48981+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48982 (lpfc_debugfs_max_slow_ring_trc - 1);
48983 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48984 dtp = phba->slow_ring_trc + i;
48985@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48986 !vport || !vport->disc_trc)
48987 return;
48988
48989- index = atomic_inc_return(&vport->disc_trc_cnt) &
48990+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48991 (lpfc_debugfs_max_disc_trc - 1);
48992 dtp = vport->disc_trc + index;
48993 dtp->fmt = fmt;
48994 dtp->data1 = data1;
48995 dtp->data2 = data2;
48996 dtp->data3 = data3;
48997- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48998+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48999 dtp->jif = jiffies;
49000 #endif
49001 return;
49002@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49003 !phba || !phba->slow_ring_trc)
49004 return;
49005
49006- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49007+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49008 (lpfc_debugfs_max_slow_ring_trc - 1);
49009 dtp = phba->slow_ring_trc + index;
49010 dtp->fmt = fmt;
49011 dtp->data1 = data1;
49012 dtp->data2 = data2;
49013 dtp->data3 = data3;
49014- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49015+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49016 dtp->jif = jiffies;
49017 #endif
49018 return;
49019@@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49020 "slow_ring buffer\n");
49021 goto debug_failed;
49022 }
49023- atomic_set(&phba->slow_ring_trc_cnt, 0);
49024+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49025 memset(phba->slow_ring_trc, 0,
49026 (sizeof(struct lpfc_debugfs_trc) *
49027 lpfc_debugfs_max_slow_ring_trc));
49028@@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49029 "buffer\n");
49030 goto debug_failed;
49031 }
49032- atomic_set(&vport->disc_trc_cnt, 0);
49033+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49034
49035 snprintf(name, sizeof(name), "discovery_trace");
49036 vport->debug_disc_trc =
49037diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49038index 68c94cc..8c27be5 100644
49039--- a/drivers/scsi/lpfc/lpfc_init.c
49040+++ b/drivers/scsi/lpfc/lpfc_init.c
49041@@ -10949,8 +10949,10 @@ lpfc_init(void)
49042 "misc_register returned with status %d", error);
49043
49044 if (lpfc_enable_npiv) {
49045- lpfc_transport_functions.vport_create = lpfc_vport_create;
49046- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49047+ pax_open_kernel();
49048+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49049+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49050+ pax_close_kernel();
49051 }
49052 lpfc_transport_template =
49053 fc_attach_transport(&lpfc_transport_functions);
49054diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49055index b2ede05..aaf482ca 100644
49056--- a/drivers/scsi/lpfc/lpfc_scsi.c
49057+++ b/drivers/scsi/lpfc/lpfc_scsi.c
49058@@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49059 uint32_t evt_posted;
49060
49061 spin_lock_irqsave(&phba->hbalock, flags);
49062- atomic_inc(&phba->num_rsrc_err);
49063+ atomic_inc_unchecked(&phba->num_rsrc_err);
49064 phba->last_rsrc_error_time = jiffies;
49065
49066 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49067@@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
49068 unsigned long flags;
49069 struct lpfc_hba *phba = vport->phba;
49070 uint32_t evt_posted;
49071- atomic_inc(&phba->num_cmd_success);
49072+ atomic_inc_unchecked(&phba->num_cmd_success);
49073
49074 if (vport->cfg_lun_queue_depth <= queue_depth)
49075 return;
49076@@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49077 unsigned long num_rsrc_err, num_cmd_success;
49078 int i;
49079
49080- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49081- num_cmd_success = atomic_read(&phba->num_cmd_success);
49082+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49083+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49084
49085 /*
49086 * The error and success command counters are global per
49087@@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49088 }
49089 }
49090 lpfc_destroy_vport_work_array(phba, vports);
49091- atomic_set(&phba->num_rsrc_err, 0);
49092- atomic_set(&phba->num_cmd_success, 0);
49093+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49094+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49095 }
49096
49097 /**
49098@@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
49099 }
49100 }
49101 lpfc_destroy_vport_work_array(phba, vports);
49102- atomic_set(&phba->num_rsrc_err, 0);
49103- atomic_set(&phba->num_cmd_success, 0);
49104+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
49105+ atomic_set_unchecked(&phba->num_cmd_success, 0);
49106 }
49107
49108 /**
49109diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49110index 7f0af4f..193ac3e 100644
49111--- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49112+++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49113@@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49114 {
49115 struct scsi_device *sdev = to_scsi_device(dev);
49116 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49117- static struct _raid_device *raid_device;
49118+ struct _raid_device *raid_device;
49119 unsigned long flags;
49120 Mpi2RaidVolPage0_t vol_pg0;
49121 Mpi2ConfigReply_t mpi_reply;
49122@@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49123 {
49124 struct scsi_device *sdev = to_scsi_device(dev);
49125 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49126- static struct _raid_device *raid_device;
49127+ struct _raid_device *raid_device;
49128 unsigned long flags;
49129 Mpi2RaidVolPage0_t vol_pg0;
49130 Mpi2ConfigReply_t mpi_reply;
49131@@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49132 struct fw_event_work *fw_event)
49133 {
49134 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49135- static struct _raid_device *raid_device;
49136+ struct _raid_device *raid_device;
49137 unsigned long flags;
49138 u16 handle;
49139
49140@@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49141 u64 sas_address;
49142 struct _sas_device *sas_device;
49143 struct _sas_node *expander_device;
49144- static struct _raid_device *raid_device;
49145+ struct _raid_device *raid_device;
49146 u8 retry_count;
49147 unsigned long flags;
49148
49149diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49150index be8ce54..94ed33a 100644
49151--- a/drivers/scsi/pmcraid.c
49152+++ b/drivers/scsi/pmcraid.c
49153@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49154 res->scsi_dev = scsi_dev;
49155 scsi_dev->hostdata = res;
49156 res->change_detected = 0;
49157- atomic_set(&res->read_failures, 0);
49158- atomic_set(&res->write_failures, 0);
49159+ atomic_set_unchecked(&res->read_failures, 0);
49160+ atomic_set_unchecked(&res->write_failures, 0);
49161 rc = 0;
49162 }
49163 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49164@@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49165
49166 /* If this was a SCSI read/write command keep count of errors */
49167 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49168- atomic_inc(&res->read_failures);
49169+ atomic_inc_unchecked(&res->read_failures);
49170 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49171- atomic_inc(&res->write_failures);
49172+ atomic_inc_unchecked(&res->write_failures);
49173
49174 if (!RES_IS_GSCSI(res->cfg_entry) &&
49175 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49176@@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49177 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49178 * hrrq_id assigned here in queuecommand
49179 */
49180- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49181+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49182 pinstance->num_hrrq;
49183 cmd->cmd_done = pmcraid_io_done;
49184
49185@@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49186 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49187 * hrrq_id assigned here in queuecommand
49188 */
49189- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49190+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49191 pinstance->num_hrrq;
49192
49193 if (request_size) {
49194@@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49195
49196 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49197 /* add resources only after host is added into system */
49198- if (!atomic_read(&pinstance->expose_resources))
49199+ if (!atomic_read_unchecked(&pinstance->expose_resources))
49200 return;
49201
49202 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49203@@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49204 init_waitqueue_head(&pinstance->reset_wait_q);
49205
49206 atomic_set(&pinstance->outstanding_cmds, 0);
49207- atomic_set(&pinstance->last_message_id, 0);
49208- atomic_set(&pinstance->expose_resources, 0);
49209+ atomic_set_unchecked(&pinstance->last_message_id, 0);
49210+ atomic_set_unchecked(&pinstance->expose_resources, 0);
49211
49212 INIT_LIST_HEAD(&pinstance->free_res_q);
49213 INIT_LIST_HEAD(&pinstance->used_res_q);
49214@@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49215 /* Schedule worker thread to handle CCN and take care of adding and
49216 * removing devices to OS
49217 */
49218- atomic_set(&pinstance->expose_resources, 1);
49219+ atomic_set_unchecked(&pinstance->expose_resources, 1);
49220 schedule_work(&pinstance->worker_q);
49221 return rc;
49222
49223diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49224index e1d150f..6c6df44 100644
49225--- a/drivers/scsi/pmcraid.h
49226+++ b/drivers/scsi/pmcraid.h
49227@@ -748,7 +748,7 @@ struct pmcraid_instance {
49228 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49229
49230 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49231- atomic_t last_message_id;
49232+ atomic_unchecked_t last_message_id;
49233
49234 /* configuration table */
49235 struct pmcraid_config_table *cfg_table;
49236@@ -777,7 +777,7 @@ struct pmcraid_instance {
49237 atomic_t outstanding_cmds;
49238
49239 /* should add/delete resources to mid-layer now ?*/
49240- atomic_t expose_resources;
49241+ atomic_unchecked_t expose_resources;
49242
49243
49244
49245@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49246 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49247 };
49248 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49249- atomic_t read_failures; /* count of failed READ commands */
49250- atomic_t write_failures; /* count of failed WRITE commands */
49251+ atomic_unchecked_t read_failures; /* count of failed READ commands */
49252+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49253
49254 /* To indicate add/delete/modify during CCN */
49255 u8 change_detected;
49256diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49257index 5f174b8..98d32b0 100644
49258--- a/drivers/scsi/qla2xxx/qla_attr.c
49259+++ b/drivers/scsi/qla2xxx/qla_attr.c
49260@@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49261 return 0;
49262 }
49263
49264-struct fc_function_template qla2xxx_transport_functions = {
49265+fc_function_template_no_const qla2xxx_transport_functions = {
49266
49267 .show_host_node_name = 1,
49268 .show_host_port_name = 1,
49269@@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49270 .bsg_timeout = qla24xx_bsg_timeout,
49271 };
49272
49273-struct fc_function_template qla2xxx_transport_vport_functions = {
49274+fc_function_template_no_const qla2xxx_transport_vport_functions = {
49275
49276 .show_host_node_name = 1,
49277 .show_host_port_name = 1,
49278diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49279index 4446bf5..9a3574d 100644
49280--- a/drivers/scsi/qla2xxx/qla_gbl.h
49281+++ b/drivers/scsi/qla2xxx/qla_gbl.h
49282@@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49283 struct device_attribute;
49284 extern struct device_attribute *qla2x00_host_attrs[];
49285 struct fc_function_template;
49286-extern struct fc_function_template qla2xxx_transport_functions;
49287-extern struct fc_function_template qla2xxx_transport_vport_functions;
49288+extern fc_function_template_no_const qla2xxx_transport_functions;
49289+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49290 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49291 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
49292 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49293diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49294index 52be35e..b933907 100644
49295--- a/drivers/scsi/qla2xxx/qla_os.c
49296+++ b/drivers/scsi/qla2xxx/qla_os.c
49297@@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49298 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49299 /* Ok, a 64bit DMA mask is applicable. */
49300 ha->flags.enable_64bit_addressing = 1;
49301- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49302- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49303+ pax_open_kernel();
49304+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49305+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49306+ pax_close_kernel();
49307 return;
49308 }
49309 }
49310diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49311index 084d1fd..9f939eb 100644
49312--- a/drivers/scsi/qla4xxx/ql4_def.h
49313+++ b/drivers/scsi/qla4xxx/ql4_def.h
49314@@ -296,7 +296,7 @@ struct ddb_entry {
49315 * (4000 only) */
49316 atomic_t relogin_timer; /* Max Time to wait for
49317 * relogin to complete */
49318- atomic_t relogin_retry_count; /* Num of times relogin has been
49319+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49320 * retried */
49321 uint32_t default_time2wait; /* Default Min time between
49322 * relogins (+aens) */
49323diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49324index cf174a4..128a420 100644
49325--- a/drivers/scsi/qla4xxx/ql4_os.c
49326+++ b/drivers/scsi/qla4xxx/ql4_os.c
49327@@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49328 */
49329 if (!iscsi_is_session_online(cls_sess)) {
49330 /* Reset retry relogin timer */
49331- atomic_inc(&ddb_entry->relogin_retry_count);
49332+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49333 DEBUG2(ql4_printk(KERN_INFO, ha,
49334 "%s: index[%d] relogin timed out-retrying"
49335 " relogin (%d), retry (%d)\n", __func__,
49336 ddb_entry->fw_ddb_index,
49337- atomic_read(&ddb_entry->relogin_retry_count),
49338+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49339 ddb_entry->default_time2wait + 4));
49340 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49341 atomic_set(&ddb_entry->retry_relogin_timer,
49342@@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49343
49344 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49345 atomic_set(&ddb_entry->relogin_timer, 0);
49346- atomic_set(&ddb_entry->relogin_retry_count, 0);
49347+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49348 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49349 ddb_entry->default_relogin_timeout =
49350 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49351diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49352index fe0bcb1..c9255be 100644
49353--- a/drivers/scsi/scsi.c
49354+++ b/drivers/scsi/scsi.c
49355@@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49356 struct Scsi_Host *host = cmd->device->host;
49357 int rtn = 0;
49358
49359- atomic_inc(&cmd->device->iorequest_cnt);
49360+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49361
49362 /* check if the device is still usable */
49363 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49364diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49365index 62ec84b..93159d8 100644
49366--- a/drivers/scsi/scsi_lib.c
49367+++ b/drivers/scsi/scsi_lib.c
49368@@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49369 shost = sdev->host;
49370 scsi_init_cmd_errh(cmd);
49371 cmd->result = DID_NO_CONNECT << 16;
49372- atomic_inc(&cmd->device->iorequest_cnt);
49373+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49374
49375 /*
49376 * SCSI request completion path will do scsi_device_unbusy(),
49377@@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
49378
49379 INIT_LIST_HEAD(&cmd->eh_entry);
49380
49381- atomic_inc(&cmd->device->iodone_cnt);
49382+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
49383 if (cmd->result)
49384- atomic_inc(&cmd->device->ioerr_cnt);
49385+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49386
49387 disposition = scsi_decide_disposition(cmd);
49388 if (disposition != SUCCESS &&
49389diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49390index 8ff62c2..693b6f7 100644
49391--- a/drivers/scsi/scsi_sysfs.c
49392+++ b/drivers/scsi/scsi_sysfs.c
49393@@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49394 char *buf) \
49395 { \
49396 struct scsi_device *sdev = to_scsi_device(dev); \
49397- unsigned long long count = atomic_read(&sdev->field); \
49398+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
49399 return snprintf(buf, 20, "0x%llx\n", count); \
49400 } \
49401 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49402diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49403index 84a1fdf..693b0d6 100644
49404--- a/drivers/scsi/scsi_tgt_lib.c
49405+++ b/drivers/scsi/scsi_tgt_lib.c
49406@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49407 int err;
49408
49409 dprintk("%lx %u\n", uaddr, len);
49410- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49411+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49412 if (err) {
49413 /*
49414 * TODO: need to fixup sg_tablesize, max_segment_size,
49415diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49416index 4628fd5..a94a1c2 100644
49417--- a/drivers/scsi/scsi_transport_fc.c
49418+++ b/drivers/scsi/scsi_transport_fc.c
49419@@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49420 * Netlink Infrastructure
49421 */
49422
49423-static atomic_t fc_event_seq;
49424+static atomic_unchecked_t fc_event_seq;
49425
49426 /**
49427 * fc_get_event_number - Obtain the next sequential FC event number
49428@@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
49429 u32
49430 fc_get_event_number(void)
49431 {
49432- return atomic_add_return(1, &fc_event_seq);
49433+ return atomic_add_return_unchecked(1, &fc_event_seq);
49434 }
49435 EXPORT_SYMBOL(fc_get_event_number);
49436
49437@@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
49438 {
49439 int error;
49440
49441- atomic_set(&fc_event_seq, 0);
49442+ atomic_set_unchecked(&fc_event_seq, 0);
49443
49444 error = transport_class_register(&fc_host_class);
49445 if (error)
49446@@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49447 char *cp;
49448
49449 *val = simple_strtoul(buf, &cp, 0);
49450- if ((*cp && (*cp != '\n')) || (*val < 0))
49451+ if (*cp && (*cp != '\n'))
49452 return -EINVAL;
49453 /*
49454 * Check for overflow; dev_loss_tmo is u32
49455diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49456index 63a6ca4..5d5cadd 100644
49457--- a/drivers/scsi/scsi_transport_iscsi.c
49458+++ b/drivers/scsi/scsi_transport_iscsi.c
49459@@ -79,7 +79,7 @@ struct iscsi_internal {
49460 struct transport_container session_cont;
49461 };
49462
49463-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49464+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49465 static struct workqueue_struct *iscsi_eh_timer_workq;
49466
49467 static DEFINE_IDA(iscsi_sess_ida);
49468@@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49469 int err;
49470
49471 ihost = shost->shost_data;
49472- session->sid = atomic_add_return(1, &iscsi_session_nr);
49473+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49474
49475 if (target_id == ISCSI_MAX_TARGET) {
49476 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49477@@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
49478 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49479 ISCSI_TRANSPORT_VERSION);
49480
49481- atomic_set(&iscsi_session_nr, 0);
49482+ atomic_set_unchecked(&iscsi_session_nr, 0);
49483
49484 err = class_register(&iscsi_transport_class);
49485 if (err)
49486diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49487index 2700a5a..752ec38 100644
49488--- a/drivers/scsi/scsi_transport_srp.c
49489+++ b/drivers/scsi/scsi_transport_srp.c
49490@@ -36,7 +36,7 @@
49491 #include "scsi_transport_srp_internal.h"
49492
49493 struct srp_host_attrs {
49494- atomic_t next_port_id;
49495+ atomic_unchecked_t next_port_id;
49496 };
49497 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49498
49499@@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49500 struct Scsi_Host *shost = dev_to_shost(dev);
49501 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49502
49503- atomic_set(&srp_host->next_port_id, 0);
49504+ atomic_set_unchecked(&srp_host->next_port_id, 0);
49505 return 0;
49506 }
49507
49508@@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49509 rport_fast_io_fail_timedout);
49510 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49511
49512- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49513+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49514 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49515
49516 transport_setup_device(&rport->dev);
49517diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49518index 69725f7..03aaee1 100644
49519--- a/drivers/scsi/sd.c
49520+++ b/drivers/scsi/sd.c
49521@@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
49522 sdkp->disk = gd;
49523 sdkp->index = index;
49524 atomic_set(&sdkp->openers, 0);
49525- atomic_set(&sdkp->device->ioerr_cnt, 0);
49526+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49527
49528 if (!sdp->request_queue->rq_timeout) {
49529 if (sdp->type != TYPE_MOD)
49530diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49531index df5e961..df6b97f 100644
49532--- a/drivers/scsi/sg.c
49533+++ b/drivers/scsi/sg.c
49534@@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49535 sdp->disk->disk_name,
49536 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49537 NULL,
49538- (char *)arg);
49539+ (char __user *)arg);
49540 case BLKTRACESTART:
49541 return blk_trace_startstop(sdp->device->request_queue, 1);
49542 case BLKTRACESTOP:
49543diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49544index 349ebba..ff2a249 100644
49545--- a/drivers/spi/spi.c
49546+++ b/drivers/spi/spi.c
49547@@ -1945,7 +1945,7 @@ int spi_bus_unlock(struct spi_master *master)
49548 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49549
49550 /* portable code must never pass more than 32 bytes */
49551-#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49552+#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49553
49554 static u8 *buf;
49555
49556diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49557index 2c61783..4d49e4e 100644
49558--- a/drivers/staging/android/timed_output.c
49559+++ b/drivers/staging/android/timed_output.c
49560@@ -25,7 +25,7 @@
49561 #include "timed_output.h"
49562
49563 static struct class *timed_output_class;
49564-static atomic_t device_count;
49565+static atomic_unchecked_t device_count;
49566
49567 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49568 char *buf)
49569@@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49570 timed_output_class = class_create(THIS_MODULE, "timed_output");
49571 if (IS_ERR(timed_output_class))
49572 return PTR_ERR(timed_output_class);
49573- atomic_set(&device_count, 0);
49574+ atomic_set_unchecked(&device_count, 0);
49575 timed_output_class->dev_groups = timed_output_groups;
49576 }
49577
49578@@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49579 if (ret < 0)
49580 return ret;
49581
49582- tdev->index = atomic_inc_return(&device_count);
49583+ tdev->index = atomic_inc_return_unchecked(&device_count);
49584 tdev->dev = device_create(timed_output_class, NULL,
49585 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49586 if (IS_ERR(tdev->dev))
49587diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49588index c0f7cd7..5424212 100644
49589--- a/drivers/staging/gdm724x/gdm_tty.c
49590+++ b/drivers/staging/gdm724x/gdm_tty.c
49591@@ -45,7 +45,7 @@
49592 #define gdm_tty_send_control(n, r, v, d, l) (\
49593 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49594
49595-#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49596+#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49597
49598 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49599 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49600diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49601index 96e4eee..6d7c37e 100644
49602--- a/drivers/staging/imx-drm/imx-drm-core.c
49603+++ b/drivers/staging/imx-drm/imx-drm-core.c
49604@@ -510,7 +510,7 @@ int imx_drm_add_crtc(struct drm_crtc *crtc,
49605 goto err_busy;
49606 }
49607
49608- if (imxdrm->drm->open_count) {
49609+ if (local_read(&imxdrm->drm->open_count)) {
49610 ret = -EBUSY;
49611 goto err_busy;
49612 }
49613@@ -590,7 +590,7 @@ int imx_drm_add_encoder(struct drm_encoder *encoder,
49614
49615 mutex_lock(&imxdrm->mutex);
49616
49617- if (imxdrm->drm->open_count) {
49618+ if (local_read(&imxdrm->drm->open_count)) {
49619 ret = -EBUSY;
49620 goto err_busy;
49621 }
49622@@ -729,7 +729,7 @@ int imx_drm_add_connector(struct drm_connector *connector,
49623
49624 mutex_lock(&imxdrm->mutex);
49625
49626- if (imxdrm->drm->open_count) {
49627+ if (local_read(&imxdrm->drm->open_count)) {
49628 ret = -EBUSY;
49629 goto err_busy;
49630 }
49631diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49632index b7613c8..c302392 100644
49633--- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49634+++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49635@@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49636 return 0;
49637 }
49638
49639-sfw_test_client_ops_t brw_test_client;
49640-void brw_init_test_client(void)
49641-{
49642- brw_test_client.tso_init = brw_client_init;
49643- brw_test_client.tso_fini = brw_client_fini;
49644- brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49645- brw_test_client.tso_done_rpc = brw_client_done_rpc;
49646+sfw_test_client_ops_t brw_test_client = {
49647+ .tso_init = brw_client_init,
49648+ .tso_fini = brw_client_fini,
49649+ .tso_prep_rpc = brw_client_prep_rpc,
49650+ .tso_done_rpc = brw_client_done_rpc,
49651 };
49652
49653 srpc_service_t brw_test_service;
49654diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49655index 483c785..e1a2a7b 100644
49656--- a/drivers/staging/lustre/lnet/selftest/framework.c
49657+++ b/drivers/staging/lustre/lnet/selftest/framework.c
49658@@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49659
49660 extern sfw_test_client_ops_t ping_test_client;
49661 extern srpc_service_t ping_test_service;
49662-extern void ping_init_test_client(void);
49663 extern void ping_init_test_service(void);
49664
49665 extern sfw_test_client_ops_t brw_test_client;
49666 extern srpc_service_t brw_test_service;
49667-extern void brw_init_test_client(void);
49668 extern void brw_init_test_service(void);
49669
49670
49671@@ -1684,12 +1682,10 @@ sfw_startup (void)
49672 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49673 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49674
49675- brw_init_test_client();
49676 brw_init_test_service();
49677 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49678 LASSERT (rc == 0);
49679
49680- ping_init_test_client();
49681 ping_init_test_service();
49682 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49683 LASSERT (rc == 0);
49684diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49685index f0f9194..b589047 100644
49686--- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49687+++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49688@@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49689 return 0;
49690 }
49691
49692-sfw_test_client_ops_t ping_test_client;
49693-void ping_init_test_client(void)
49694-{
49695- ping_test_client.tso_init = ping_client_init;
49696- ping_test_client.tso_fini = ping_client_fini;
49697- ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49698- ping_test_client.tso_done_rpc = ping_client_done_rpc;
49699-}
49700+sfw_test_client_ops_t ping_test_client = {
49701+ .tso_init = ping_client_init,
49702+ .tso_fini = ping_client_fini,
49703+ .tso_prep_rpc = ping_client_prep_rpc,
49704+ .tso_done_rpc = ping_client_done_rpc,
49705+};
49706
49707 srpc_service_t ping_test_service;
49708 void ping_init_test_service(void)
49709diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49710index bc2b82f..67fd598 100644
49711--- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49712+++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49713@@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49714 ldlm_completion_callback lcs_completion;
49715 ldlm_blocking_callback lcs_blocking;
49716 ldlm_glimpse_callback lcs_glimpse;
49717-};
49718+} __no_const;
49719
49720 /* ldlm_lockd.c */
49721 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49722diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49723index d0aea15..7af68e1 100644
49724--- a/drivers/staging/lustre/lustre/include/obd.h
49725+++ b/drivers/staging/lustre/lustre/include/obd.h
49726@@ -1417,7 +1417,7 @@ struct md_ops {
49727 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49728 * wrapper function in include/linux/obd_class.h.
49729 */
49730-};
49731+} __no_const;
49732
49733 struct lsm_operations {
49734 void (*lsm_free)(struct lov_stripe_md *);
49735diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49736index 39fcdac..222780f 100644
49737--- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49738+++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49739@@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49740 int added = (mode == LCK_NL);
49741 int overlaps = 0;
49742 int splitted = 0;
49743- const struct ldlm_callback_suite null_cbs = { NULL };
49744+ const struct ldlm_callback_suite null_cbs = { };
49745 int rc;
49746
49747 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49748diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49749index fc6c977..df1f956 100644
49750--- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49751+++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49752@@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49753 int LL_PROC_PROTO(proc_console_max_delay_cs)
49754 {
49755 int rc, max_delay_cs;
49756- ctl_table_t dummy = *table;
49757+ ctl_table_no_const dummy = *table;
49758 cfs_duration_t d;
49759
49760 dummy.data = &max_delay_cs;
49761@@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49762 int LL_PROC_PROTO(proc_console_min_delay_cs)
49763 {
49764 int rc, min_delay_cs;
49765- ctl_table_t dummy = *table;
49766+ ctl_table_no_const dummy = *table;
49767 cfs_duration_t d;
49768
49769 dummy.data = &min_delay_cs;
49770@@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49771 int LL_PROC_PROTO(proc_console_backoff)
49772 {
49773 int rc, backoff;
49774- ctl_table_t dummy = *table;
49775+ ctl_table_no_const dummy = *table;
49776
49777 dummy.data = &backoff;
49778 dummy.proc_handler = &proc_dointvec;
49779diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49780index f3108c7..cd4f9da 100644
49781--- a/drivers/staging/lustre/lustre/libcfs/module.c
49782+++ b/drivers/staging/lustre/lustre/libcfs/module.c
49783@@ -348,11 +348,11 @@ out:
49784
49785
49786 struct cfs_psdev_ops libcfs_psdev_ops = {
49787- libcfs_psdev_open,
49788- libcfs_psdev_release,
49789- NULL,
49790- NULL,
49791- libcfs_ioctl
49792+ .p_open = libcfs_psdev_open,
49793+ .p_close = libcfs_psdev_release,
49794+ .p_read = NULL,
49795+ .p_write = NULL,
49796+ .p_ioctl = libcfs_ioctl
49797 };
49798
49799 extern int insert_proc(void);
49800diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
49801index a4e0472..05d854c 100644
49802--- a/drivers/staging/lustre/lustre/llite/dir.c
49803+++ b/drivers/staging/lustre/lustre/llite/dir.c
49804@@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
49805 int mode;
49806 int err;
49807
49808- mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
49809+ mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
49810 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
49811 strlen(filename), mode, LUSTRE_OPC_MKDIR,
49812 lump);
49813diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49814index 3675020..e80d92c 100644
49815--- a/drivers/staging/media/solo6x10/solo6x10-core.c
49816+++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49817@@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49818
49819 static int solo_sysfs_init(struct solo_dev *solo_dev)
49820 {
49821- struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49822+ bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49823 struct device *dev = &solo_dev->dev;
49824 const char *driver;
49825 int i;
49826diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49827index 1db18c7..35e6afc 100644
49828--- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49829+++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49830@@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49831
49832 int solo_g723_init(struct solo_dev *solo_dev)
49833 {
49834- static struct snd_device_ops ops = { NULL };
49835+ static struct snd_device_ops ops = { };
49836 struct snd_card *card;
49837 struct snd_kcontrol_new kctl;
49838 char name[32];
49839diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49840index 7f2f247..d999137 100644
49841--- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49842+++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49843@@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49844
49845 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49846 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49847- p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49848+ p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49849 if (p2m_id < 0)
49850 p2m_id = -p2m_id;
49851 }
49852diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49853index f1bbb8c..a73eaba 100644
49854--- a/drivers/staging/media/solo6x10/solo6x10.h
49855+++ b/drivers/staging/media/solo6x10/solo6x10.h
49856@@ -237,7 +237,7 @@ struct solo_dev {
49857
49858 /* P2M DMA Engine */
49859 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49860- atomic_t p2m_count;
49861+ atomic_unchecked_t p2m_count;
49862 int p2m_jiffies;
49863 unsigned int p2m_timeouts;
49864
49865diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49866index 0315f60..ce93f406 100644
49867--- a/drivers/staging/octeon/ethernet-rx.c
49868+++ b/drivers/staging/octeon/ethernet-rx.c
49869@@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49870 /* Increment RX stats for virtual ports */
49871 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49872 #ifdef CONFIG_64BIT
49873- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49874- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49875+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49876+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49877 #else
49878- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49879- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49880+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49881+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49882 #endif
49883 }
49884 netif_receive_skb(skb);
49885@@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49886 dev->name);
49887 */
49888 #ifdef CONFIG_64BIT
49889- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49890+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49891 #else
49892- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49893+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49894 #endif
49895 dev_kfree_skb_irq(skb);
49896 }
49897diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49898index bd6ca71..8f0961e 100644
49899--- a/drivers/staging/octeon/ethernet.c
49900+++ b/drivers/staging/octeon/ethernet.c
49901@@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49902 * since the RX tasklet also increments it.
49903 */
49904 #ifdef CONFIG_64BIT
49905- atomic64_add(rx_status.dropped_packets,
49906- (atomic64_t *)&priv->stats.rx_dropped);
49907+ atomic64_add_unchecked(rx_status.dropped_packets,
49908+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49909 #else
49910- atomic_add(rx_status.dropped_packets,
49911- (atomic_t *)&priv->stats.rx_dropped);
49912+ atomic_add_unchecked(rx_status.dropped_packets,
49913+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
49914 #endif
49915 }
49916
49917diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49918index 439c3c9..2d74293 100644
49919--- a/drivers/staging/rtl8188eu/include/hal_intf.h
49920+++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49921@@ -271,7 +271,7 @@ struct hal_ops {
49922 s32 (*c2h_handler)(struct adapter *padapter,
49923 struct c2h_evt_hdr *c2h_evt);
49924 c2h_id_filter c2h_id_filter_ccx;
49925-};
49926+} __no_const;
49927
49928 enum rt_eeprom_type {
49929 EEPROM_93C46,
49930diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49931index eb6f0e5..e6a0958 100644
49932--- a/drivers/staging/rtl8188eu/include/rtw_io.h
49933+++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49934@@ -126,7 +126,7 @@ struct _io_ops {
49935 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49936 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49937 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49938-};
49939+} __no_const;
49940
49941 struct io_req {
49942 struct list_head list;
49943diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49944index dc23395..cf7e9b1 100644
49945--- a/drivers/staging/rtl8712/rtl871x_io.h
49946+++ b/drivers/staging/rtl8712/rtl871x_io.h
49947@@ -108,7 +108,7 @@ struct _io_ops {
49948 u8 *pmem);
49949 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49950 u8 *pmem);
49951-};
49952+} __no_const;
49953
49954 struct io_req {
49955 struct list_head list;
49956diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49957index 1f5088b..0e59820 100644
49958--- a/drivers/staging/sbe-2t3e3/netdev.c
49959+++ b/drivers/staging/sbe-2t3e3/netdev.c
49960@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49961 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49962
49963 if (rlen)
49964- if (copy_to_user(data, &resp, rlen))
49965+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49966 return -EFAULT;
49967
49968 return 0;
49969diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49970index a863a98..d272795 100644
49971--- a/drivers/staging/usbip/vhci.h
49972+++ b/drivers/staging/usbip/vhci.h
49973@@ -83,7 +83,7 @@ struct vhci_hcd {
49974 unsigned resuming:1;
49975 unsigned long re_timeout;
49976
49977- atomic_t seqnum;
49978+ atomic_unchecked_t seqnum;
49979
49980 /*
49981 * NOTE:
49982diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49983index e810ad5..931336f 100644
49984--- a/drivers/staging/usbip/vhci_hcd.c
49985+++ b/drivers/staging/usbip/vhci_hcd.c
49986@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49987
49988 spin_lock(&vdev->priv_lock);
49989
49990- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49991+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49992 if (priv->seqnum == 0xffff)
49993 dev_info(&urb->dev->dev, "seqnum max\n");
49994
49995@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49996 return -ENOMEM;
49997 }
49998
49999- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50000+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50001 if (unlink->seqnum == 0xffff)
50002 pr_info("seqnum max\n");
50003
50004@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
50005 vdev->rhport = rhport;
50006 }
50007
50008- atomic_set(&vhci->seqnum, 0);
50009+ atomic_set_unchecked(&vhci->seqnum, 0);
50010 spin_lock_init(&vhci->lock);
50011
50012 hcd->power_budget = 0; /* no limit */
50013diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50014index d07fcb5..358e1e1 100644
50015--- a/drivers/staging/usbip/vhci_rx.c
50016+++ b/drivers/staging/usbip/vhci_rx.c
50017@@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50018 if (!urb) {
50019 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50020 pr_info("max seqnum %d\n",
50021- atomic_read(&the_controller->seqnum));
50022+ atomic_read_unchecked(&the_controller->seqnum));
50023 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50024 return;
50025 }
50026diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50027index ab8b2ba..99184aa 100644
50028--- a/drivers/staging/vt6655/hostap.c
50029+++ b/drivers/staging/vt6655/hostap.c
50030@@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50031 *
50032 */
50033
50034+static net_device_ops_no_const apdev_netdev_ops;
50035+
50036 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50037 {
50038 PSDevice apdev_priv;
50039 struct net_device *dev = pDevice->dev;
50040 int ret;
50041- const struct net_device_ops apdev_netdev_ops = {
50042- .ndo_start_xmit = pDevice->tx_80211,
50043- };
50044
50045 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50046
50047@@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50048 *apdev_priv = *pDevice;
50049 eth_hw_addr_inherit(pDevice->apdev, dev);
50050
50051+ /* only half broken now */
50052+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50053 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50054
50055 pDevice->apdev->type = ARPHRD_IEEE80211;
50056diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50057index 67ba48b..24e602f 100644
50058--- a/drivers/staging/vt6656/hostap.c
50059+++ b/drivers/staging/vt6656/hostap.c
50060@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50061 *
50062 */
50063
50064+static net_device_ops_no_const apdev_netdev_ops;
50065+
50066 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50067 {
50068 struct vnt_private *apdev_priv;
50069 struct net_device *dev = pDevice->dev;
50070 int ret;
50071- const struct net_device_ops apdev_netdev_ops = {
50072- .ndo_start_xmit = pDevice->tx_80211,
50073- };
50074
50075 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50076
50077@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50078 *apdev_priv = *pDevice;
50079 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50080
50081+ /* only half broken now */
50082+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50083 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50084
50085 pDevice->apdev->type = ARPHRD_IEEE80211;
50086diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50087index 24884ca..26c8220 100644
50088--- a/drivers/target/sbp/sbp_target.c
50089+++ b/drivers/target/sbp/sbp_target.c
50090@@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50091
50092 #define SESSION_MAINTENANCE_INTERVAL HZ
50093
50094-static atomic_t login_id = ATOMIC_INIT(0);
50095+static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50096
50097 static void session_maintenance_work(struct work_struct *);
50098 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50099@@ -444,7 +444,7 @@ static void sbp_management_request_login(
50100 login->lun = se_lun;
50101 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50102 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50103- login->login_id = atomic_inc_return(&login_id);
50104+ login->login_id = atomic_inc_return_unchecked(&login_id);
50105
50106 login->tgt_agt = sbp_target_agent_register(login);
50107 if (IS_ERR(login->tgt_agt)) {
50108diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50109index d06de84..fd38c9b 100644
50110--- a/drivers/target/target_core_device.c
50111+++ b/drivers/target/target_core_device.c
50112@@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50113 spin_lock_init(&dev->se_tmr_lock);
50114 spin_lock_init(&dev->qf_cmd_lock);
50115 sema_init(&dev->caw_sem, 1);
50116- atomic_set(&dev->dev_ordered_id, 0);
50117+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
50118 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50119 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50120 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50121diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50122index dee2be1..f5fd8ca 100644
50123--- a/drivers/target/target_core_transport.c
50124+++ b/drivers/target/target_core_transport.c
50125@@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50126 * Used to determine when ORDERED commands should go from
50127 * Dormant to Active status.
50128 */
50129- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50130+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50131 smp_mb__after_atomic_inc();
50132 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50133 cmd->se_ordered_id, cmd->sam_task_attr,
50134diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50135index 33f83fe..d80f8e1 100644
50136--- a/drivers/tty/cyclades.c
50137+++ b/drivers/tty/cyclades.c
50138@@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50139 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50140 info->port.count);
50141 #endif
50142- info->port.count++;
50143+ atomic_inc(&info->port.count);
50144 #ifdef CY_DEBUG_COUNT
50145 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50146- current->pid, info->port.count);
50147+ current->pid, atomic_read(&info->port.count));
50148 #endif
50149
50150 /*
50151@@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50152 for (j = 0; j < cy_card[i].nports; j++) {
50153 info = &cy_card[i].ports[j];
50154
50155- if (info->port.count) {
50156+ if (atomic_read(&info->port.count)) {
50157 /* XXX is the ldisc num worth this? */
50158 struct tty_struct *tty;
50159 struct tty_ldisc *ld;
50160diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50161index 9eba119..5070303 100644
50162--- a/drivers/tty/hvc/hvc_console.c
50163+++ b/drivers/tty/hvc/hvc_console.c
50164@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50165
50166 spin_lock_irqsave(&hp->port.lock, flags);
50167 /* Check and then increment for fast path open. */
50168- if (hp->port.count++ > 0) {
50169+ if (atomic_inc_return(&hp->port.count) > 1) {
50170 spin_unlock_irqrestore(&hp->port.lock, flags);
50171 hvc_kick();
50172 return 0;
50173@@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50174
50175 spin_lock_irqsave(&hp->port.lock, flags);
50176
50177- if (--hp->port.count == 0) {
50178+ if (atomic_dec_return(&hp->port.count) == 0) {
50179 spin_unlock_irqrestore(&hp->port.lock, flags);
50180 /* We are done with the tty pointer now. */
50181 tty_port_tty_set(&hp->port, NULL);
50182@@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50183 */
50184 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50185 } else {
50186- if (hp->port.count < 0)
50187+ if (atomic_read(&hp->port.count) < 0)
50188 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50189- hp->vtermno, hp->port.count);
50190+ hp->vtermno, atomic_read(&hp->port.count));
50191 spin_unlock_irqrestore(&hp->port.lock, flags);
50192 }
50193 }
50194@@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
50195 * open->hangup case this can be called after the final close so prevent
50196 * that from happening for now.
50197 */
50198- if (hp->port.count <= 0) {
50199+ if (atomic_read(&hp->port.count) <= 0) {
50200 spin_unlock_irqrestore(&hp->port.lock, flags);
50201 return;
50202 }
50203
50204- hp->port.count = 0;
50205+ atomic_set(&hp->port.count, 0);
50206 spin_unlock_irqrestore(&hp->port.lock, flags);
50207 tty_port_tty_set(&hp->port, NULL);
50208
50209@@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50210 return -EPIPE;
50211
50212 /* FIXME what's this (unprotected) check for? */
50213- if (hp->port.count <= 0)
50214+ if (atomic_read(&hp->port.count) <= 0)
50215 return -EIO;
50216
50217 spin_lock_irqsave(&hp->lock, flags);
50218diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50219index 81e939e..95ead10 100644
50220--- a/drivers/tty/hvc/hvcs.c
50221+++ b/drivers/tty/hvc/hvcs.c
50222@@ -83,6 +83,7 @@
50223 #include <asm/hvcserver.h>
50224 #include <asm/uaccess.h>
50225 #include <asm/vio.h>
50226+#include <asm/local.h>
50227
50228 /*
50229 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50230@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50231
50232 spin_lock_irqsave(&hvcsd->lock, flags);
50233
50234- if (hvcsd->port.count > 0) {
50235+ if (atomic_read(&hvcsd->port.count) > 0) {
50236 spin_unlock_irqrestore(&hvcsd->lock, flags);
50237 printk(KERN_INFO "HVCS: vterm state unchanged. "
50238 "The hvcs device node is still in use.\n");
50239@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50240 }
50241 }
50242
50243- hvcsd->port.count = 0;
50244+ atomic_set(&hvcsd->port.count, 0);
50245 hvcsd->port.tty = tty;
50246 tty->driver_data = hvcsd;
50247
50248@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50249 unsigned long flags;
50250
50251 spin_lock_irqsave(&hvcsd->lock, flags);
50252- hvcsd->port.count++;
50253+ atomic_inc(&hvcsd->port.count);
50254 hvcsd->todo_mask |= HVCS_SCHED_READ;
50255 spin_unlock_irqrestore(&hvcsd->lock, flags);
50256
50257@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50258 hvcsd = tty->driver_data;
50259
50260 spin_lock_irqsave(&hvcsd->lock, flags);
50261- if (--hvcsd->port.count == 0) {
50262+ if (atomic_dec_and_test(&hvcsd->port.count)) {
50263
50264 vio_disable_interrupts(hvcsd->vdev);
50265
50266@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50267
50268 free_irq(irq, hvcsd);
50269 return;
50270- } else if (hvcsd->port.count < 0) {
50271+ } else if (atomic_read(&hvcsd->port.count) < 0) {
50272 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50273 " is missmanaged.\n",
50274- hvcsd->vdev->unit_address, hvcsd->port.count);
50275+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50276 }
50277
50278 spin_unlock_irqrestore(&hvcsd->lock, flags);
50279@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50280
50281 spin_lock_irqsave(&hvcsd->lock, flags);
50282 /* Preserve this so that we know how many kref refs to put */
50283- temp_open_count = hvcsd->port.count;
50284+ temp_open_count = atomic_read(&hvcsd->port.count);
50285
50286 /*
50287 * Don't kref put inside the spinlock because the destruction
50288@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50289 tty->driver_data = NULL;
50290 hvcsd->port.tty = NULL;
50291
50292- hvcsd->port.count = 0;
50293+ atomic_set(&hvcsd->port.count, 0);
50294
50295 /* This will drop any buffered data on the floor which is OK in a hangup
50296 * scenario. */
50297@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50298 * the middle of a write operation? This is a crummy place to do this
50299 * but we want to keep it all in the spinlock.
50300 */
50301- if (hvcsd->port.count <= 0) {
50302+ if (atomic_read(&hvcsd->port.count) <= 0) {
50303 spin_unlock_irqrestore(&hvcsd->lock, flags);
50304 return -ENODEV;
50305 }
50306@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50307 {
50308 struct hvcs_struct *hvcsd = tty->driver_data;
50309
50310- if (!hvcsd || hvcsd->port.count <= 0)
50311+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50312 return 0;
50313
50314 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50315diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50316index 4190199..06d5bfa 100644
50317--- a/drivers/tty/hvc/hvsi.c
50318+++ b/drivers/tty/hvc/hvsi.c
50319@@ -85,7 +85,7 @@ struct hvsi_struct {
50320 int n_outbuf;
50321 uint32_t vtermno;
50322 uint32_t virq;
50323- atomic_t seqno; /* HVSI packet sequence number */
50324+ atomic_unchecked_t seqno; /* HVSI packet sequence number */
50325 uint16_t mctrl;
50326 uint8_t state; /* HVSI protocol state */
50327 uint8_t flags;
50328@@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50329
50330 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50331 packet.hdr.len = sizeof(struct hvsi_query_response);
50332- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50333+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50334 packet.verb = VSV_SEND_VERSION_NUMBER;
50335 packet.u.version = HVSI_VERSION;
50336 packet.query_seqno = query_seqno+1;
50337@@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50338
50339 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50340 packet.hdr.len = sizeof(struct hvsi_query);
50341- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50342+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50343 packet.verb = verb;
50344
50345 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50346@@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50347 int wrote;
50348
50349 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50350- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50351+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50352 packet.hdr.len = sizeof(struct hvsi_control);
50353 packet.verb = VSV_SET_MODEM_CTL;
50354 packet.mask = HVSI_TSDTR;
50355@@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50356 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50357
50358 packet.hdr.type = VS_DATA_PACKET_HEADER;
50359- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50360+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50361 packet.hdr.len = count + sizeof(struct hvsi_header);
50362 memcpy(&packet.data, buf, count);
50363
50364@@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50365 struct hvsi_control packet __ALIGNED__;
50366
50367 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50368- packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50369+ packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50370 packet.hdr.len = 6;
50371 packet.verb = VSV_CLOSE_PROTOCOL;
50372
50373@@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50374
50375 tty_port_tty_set(&hp->port, tty);
50376 spin_lock_irqsave(&hp->lock, flags);
50377- hp->port.count++;
50378+ atomic_inc(&hp->port.count);
50379 atomic_set(&hp->seqno, 0);
50380 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50381 spin_unlock_irqrestore(&hp->lock, flags);
50382@@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50383
50384 spin_lock_irqsave(&hp->lock, flags);
50385
50386- if (--hp->port.count == 0) {
50387+ if (atomic_dec_return(&hp->port.count) == 0) {
50388 tty_port_tty_set(&hp->port, NULL);
50389 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50390
50391@@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50392
50393 spin_lock_irqsave(&hp->lock, flags);
50394 }
50395- } else if (hp->port.count < 0)
50396+ } else if (atomic_read(&hp->port.count) < 0)
50397 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50398- hp - hvsi_ports, hp->port.count);
50399+ hp - hvsi_ports, atomic_read(&hp->port.count));
50400
50401 spin_unlock_irqrestore(&hp->lock, flags);
50402 }
50403@@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50404 tty_port_tty_set(&hp->port, NULL);
50405
50406 spin_lock_irqsave(&hp->lock, flags);
50407- hp->port.count = 0;
50408+ atomic_set(&hp->port.count, 0);
50409 hp->n_outbuf = 0;
50410 spin_unlock_irqrestore(&hp->lock, flags);
50411 }
50412diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50413index 347050e..14f8fbf 100644
50414--- a/drivers/tty/hvc/hvsi_lib.c
50415+++ b/drivers/tty/hvc/hvsi_lib.c
50416@@ -9,7 +9,7 @@
50417
50418 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50419 {
50420- packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50421+ packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50422
50423 /* Assumes that always succeeds, works in practice */
50424 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50425@@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50426
50427 /* Reset state */
50428 pv->established = 0;
50429- atomic_set(&pv->seqno, 0);
50430+ atomic_set_unchecked(&pv->seqno, 0);
50431
50432 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50433
50434diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50435index 8fd72ff..34a0bed 100644
50436--- a/drivers/tty/ipwireless/tty.c
50437+++ b/drivers/tty/ipwireless/tty.c
50438@@ -29,6 +29,7 @@
50439 #include <linux/tty_driver.h>
50440 #include <linux/tty_flip.h>
50441 #include <linux/uaccess.h>
50442+#include <asm/local.h>
50443
50444 #include "tty.h"
50445 #include "network.h"
50446@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50447 mutex_unlock(&tty->ipw_tty_mutex);
50448 return -ENODEV;
50449 }
50450- if (tty->port.count == 0)
50451+ if (atomic_read(&tty->port.count) == 0)
50452 tty->tx_bytes_queued = 0;
50453
50454- tty->port.count++;
50455+ atomic_inc(&tty->port.count);
50456
50457 tty->port.tty = linux_tty;
50458 linux_tty->driver_data = tty;
50459@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50460
50461 static void do_ipw_close(struct ipw_tty *tty)
50462 {
50463- tty->port.count--;
50464-
50465- if (tty->port.count == 0) {
50466+ if (atomic_dec_return(&tty->port.count) == 0) {
50467 struct tty_struct *linux_tty = tty->port.tty;
50468
50469 if (linux_tty != NULL) {
50470@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50471 return;
50472
50473 mutex_lock(&tty->ipw_tty_mutex);
50474- if (tty->port.count == 0) {
50475+ if (atomic_read(&tty->port.count) == 0) {
50476 mutex_unlock(&tty->ipw_tty_mutex);
50477 return;
50478 }
50479@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50480
50481 mutex_lock(&tty->ipw_tty_mutex);
50482
50483- if (!tty->port.count) {
50484+ if (!atomic_read(&tty->port.count)) {
50485 mutex_unlock(&tty->ipw_tty_mutex);
50486 return;
50487 }
50488@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50489 return -ENODEV;
50490
50491 mutex_lock(&tty->ipw_tty_mutex);
50492- if (!tty->port.count) {
50493+ if (!atomic_read(&tty->port.count)) {
50494 mutex_unlock(&tty->ipw_tty_mutex);
50495 return -EINVAL;
50496 }
50497@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50498 if (!tty)
50499 return -ENODEV;
50500
50501- if (!tty->port.count)
50502+ if (!atomic_read(&tty->port.count))
50503 return -EINVAL;
50504
50505 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50506@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50507 if (!tty)
50508 return 0;
50509
50510- if (!tty->port.count)
50511+ if (!atomic_read(&tty->port.count))
50512 return 0;
50513
50514 return tty->tx_bytes_queued;
50515@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50516 if (!tty)
50517 return -ENODEV;
50518
50519- if (!tty->port.count)
50520+ if (!atomic_read(&tty->port.count))
50521 return -EINVAL;
50522
50523 return get_control_lines(tty);
50524@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50525 if (!tty)
50526 return -ENODEV;
50527
50528- if (!tty->port.count)
50529+ if (!atomic_read(&tty->port.count))
50530 return -EINVAL;
50531
50532 return set_control_lines(tty, set, clear);
50533@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50534 if (!tty)
50535 return -ENODEV;
50536
50537- if (!tty->port.count)
50538+ if (!atomic_read(&tty->port.count))
50539 return -EINVAL;
50540
50541 /* FIXME: Exactly how is the tty object locked here .. */
50542@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50543 * are gone */
50544 mutex_lock(&ttyj->ipw_tty_mutex);
50545 }
50546- while (ttyj->port.count)
50547+ while (atomic_read(&ttyj->port.count))
50548 do_ipw_close(ttyj);
50549 ipwireless_disassociate_network_ttys(network,
50550 ttyj->channel_idx);
50551diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50552index 1deaca4..c8582d4 100644
50553--- a/drivers/tty/moxa.c
50554+++ b/drivers/tty/moxa.c
50555@@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50556 }
50557
50558 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50559- ch->port.count++;
50560+ atomic_inc(&ch->port.count);
50561 tty->driver_data = ch;
50562 tty_port_tty_set(&ch->port, tty);
50563 mutex_lock(&ch->port.mutex);
50564diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50565index 5056090..c80ca04 100644
50566--- a/drivers/tty/n_gsm.c
50567+++ b/drivers/tty/n_gsm.c
50568@@ -1643,7 +1643,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50569 spin_lock_init(&dlci->lock);
50570 mutex_init(&dlci->mutex);
50571 dlci->fifo = &dlci->_fifo;
50572- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50573+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50574 kfree(dlci);
50575 return NULL;
50576 }
50577@@ -2946,7 +2946,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50578 struct gsm_dlci *dlci = tty->driver_data;
50579 struct tty_port *port = &dlci->port;
50580
50581- port->count++;
50582+ atomic_inc(&port->count);
50583 dlci_get(dlci);
50584 dlci_get(dlci->gsm->dlci[0]);
50585 mux_get(dlci->gsm);
50586diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50587index 4c10837..a40ec45 100644
50588--- a/drivers/tty/n_tty.c
50589+++ b/drivers/tty/n_tty.c
50590@@ -114,7 +114,7 @@ struct n_tty_data {
50591 int minimum_to_wake;
50592
50593 /* consumer-published */
50594- size_t read_tail;
50595+ size_t read_tail __intentional_overflow(-1);
50596 size_t line_start;
50597
50598 /* protected by output lock */
50599@@ -2504,6 +2504,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50600 {
50601 *ops = tty_ldisc_N_TTY;
50602 ops->owner = NULL;
50603- ops->refcount = ops->flags = 0;
50604+ atomic_set(&ops->refcount, 0);
50605+ ops->flags = 0;
50606 }
50607 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50608diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50609index 25c9bc7..24077b7 100644
50610--- a/drivers/tty/pty.c
50611+++ b/drivers/tty/pty.c
50612@@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50613 panic("Couldn't register Unix98 pts driver");
50614
50615 /* Now create the /dev/ptmx special device */
50616+ pax_open_kernel();
50617 tty_default_fops(&ptmx_fops);
50618- ptmx_fops.open = ptmx_open;
50619+ *(void **)&ptmx_fops.open = ptmx_open;
50620+ pax_close_kernel();
50621
50622 cdev_init(&ptmx_cdev, &ptmx_fops);
50623 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50624diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50625index 354564e..fe50d9a 100644
50626--- a/drivers/tty/rocket.c
50627+++ b/drivers/tty/rocket.c
50628@@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50629 tty->driver_data = info;
50630 tty_port_tty_set(port, tty);
50631
50632- if (port->count++ == 0) {
50633+ if (atomic_inc_return(&port->count) == 1) {
50634 atomic_inc(&rp_num_ports_open);
50635
50636 #ifdef ROCKET_DEBUG_OPEN
50637@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50638 #endif
50639 }
50640 #ifdef ROCKET_DEBUG_OPEN
50641- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50642+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50643 #endif
50644
50645 /*
50646@@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50647 spin_unlock_irqrestore(&info->port.lock, flags);
50648 return;
50649 }
50650- if (info->port.count)
50651+ if (atomic_read(&info->port.count))
50652 atomic_dec(&rp_num_ports_open);
50653 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
50654 spin_unlock_irqrestore(&info->port.lock, flags);
50655diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
50656index 1274499..f541382 100644
50657--- a/drivers/tty/serial/ioc4_serial.c
50658+++ b/drivers/tty/serial/ioc4_serial.c
50659@@ -437,7 +437,7 @@ struct ioc4_soft {
50660 } is_intr_info[MAX_IOC4_INTR_ENTS];
50661
50662 /* Number of entries active in the above array */
50663- atomic_t is_num_intrs;
50664+ atomic_unchecked_t is_num_intrs;
50665 } is_intr_type[IOC4_NUM_INTR_TYPES];
50666
50667 /* is_ir_lock must be held while
50668@@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
50669 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
50670 || (type == IOC4_OTHER_INTR_TYPE)));
50671
50672- i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
50673+ i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
50674 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
50675
50676 /* Save off the lower level interrupt handler */
50677@@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
50678
50679 soft = arg;
50680 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
50681- num_intrs = (int)atomic_read(
50682+ num_intrs = (int)atomic_read_unchecked(
50683 &soft->is_intr_type[intr_type].is_num_intrs);
50684
50685 this_mir = this_ir = pending_intrs(soft, intr_type);
50686diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50687index a260cde..6b2b5ce 100644
50688--- a/drivers/tty/serial/kgdboc.c
50689+++ b/drivers/tty/serial/kgdboc.c
50690@@ -24,8 +24,9 @@
50691 #define MAX_CONFIG_LEN 40
50692
50693 static struct kgdb_io kgdboc_io_ops;
50694+static struct kgdb_io kgdboc_io_ops_console;
50695
50696-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50697+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50698 static int configured = -1;
50699
50700 static char config[MAX_CONFIG_LEN];
50701@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50702 kgdboc_unregister_kbd();
50703 if (configured == 1)
50704 kgdb_unregister_io_module(&kgdboc_io_ops);
50705+ else if (configured == 2)
50706+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
50707 }
50708
50709 static int configure_kgdboc(void)
50710@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50711 int err;
50712 char *cptr = config;
50713 struct console *cons;
50714+ int is_console = 0;
50715
50716 err = kgdboc_option_setup(config);
50717 if (err || !strlen(config) || isspace(config[0]))
50718 goto noconfig;
50719
50720 err = -ENODEV;
50721- kgdboc_io_ops.is_console = 0;
50722 kgdb_tty_driver = NULL;
50723
50724 kgdboc_use_kms = 0;
50725@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50726 int idx;
50727 if (cons->device && cons->device(cons, &idx) == p &&
50728 idx == tty_line) {
50729- kgdboc_io_ops.is_console = 1;
50730+ is_console = 1;
50731 break;
50732 }
50733 cons = cons->next;
50734@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50735 kgdb_tty_line = tty_line;
50736
50737 do_register:
50738- err = kgdb_register_io_module(&kgdboc_io_ops);
50739+ if (is_console) {
50740+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
50741+ configured = 2;
50742+ } else {
50743+ err = kgdb_register_io_module(&kgdboc_io_ops);
50744+ configured = 1;
50745+ }
50746 if (err)
50747 goto noconfig;
50748
50749@@ -205,8 +214,6 @@ do_register:
50750 if (err)
50751 goto nmi_con_failed;
50752
50753- configured = 1;
50754-
50755 return 0;
50756
50757 nmi_con_failed:
50758@@ -223,7 +230,7 @@ noconfig:
50759 static int __init init_kgdboc(void)
50760 {
50761 /* Already configured? */
50762- if (configured == 1)
50763+ if (configured >= 1)
50764 return 0;
50765
50766 return configure_kgdboc();
50767@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50768 if (config[len - 1] == '\n')
50769 config[len - 1] = '\0';
50770
50771- if (configured == 1)
50772+ if (configured >= 1)
50773 cleanup_kgdboc();
50774
50775 /* Go and configure with the new params. */
50776@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50777 .post_exception = kgdboc_post_exp_handler,
50778 };
50779
50780+static struct kgdb_io kgdboc_io_ops_console = {
50781+ .name = "kgdboc",
50782+ .read_char = kgdboc_get_char,
50783+ .write_char = kgdboc_put_char,
50784+ .pre_exception = kgdboc_pre_exp_handler,
50785+ .post_exception = kgdboc_post_exp_handler,
50786+ .is_console = 1
50787+};
50788+
50789 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50790 /* This is only available if kgdboc is a built in for early debugging */
50791 static int __init kgdboc_early_init(char *opt)
50792diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50793index b5d779c..3622cfe 100644
50794--- a/drivers/tty/serial/msm_serial.c
50795+++ b/drivers/tty/serial/msm_serial.c
50796@@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50797 .cons = MSM_CONSOLE,
50798 };
50799
50800-static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50801+static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50802
50803 static const struct of_device_id msm_uartdm_table[] = {
50804 { .compatible = "qcom,msm-uartdm" },
50805@@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50806 int irq;
50807
50808 if (pdev->id == -1)
50809- pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50810+ pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50811
50812 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50813 return -ENXIO;
50814diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50815index c1af04d..0815c8a 100644
50816--- a/drivers/tty/serial/samsung.c
50817+++ b/drivers/tty/serial/samsung.c
50818@@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50819 }
50820 }
50821
50822+static int s3c64xx_serial_startup(struct uart_port *port);
50823 static int s3c24xx_serial_startup(struct uart_port *port)
50824 {
50825 struct s3c24xx_uart_port *ourport = to_ourport(port);
50826 int ret;
50827
50828+ /* Startup sequence is different for s3c64xx and higher SoC's */
50829+ if (s3c24xx_serial_has_interrupt_mask(port))
50830+ return s3c64xx_serial_startup(port);
50831+
50832 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50833 port->mapbase, port->membase);
50834
50835@@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50836 /* setup info for port */
50837 port->dev = &platdev->dev;
50838
50839- /* Startup sequence is different for s3c64xx and higher SoC's */
50840- if (s3c24xx_serial_has_interrupt_mask(port))
50841- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50842-
50843 port->uartclk = 1;
50844
50845 if (cfg->uart_flags & UPF_CONS_FLOW) {
50846diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50847index 0f02351..07c59c5 100644
50848--- a/drivers/tty/serial/serial_core.c
50849+++ b/drivers/tty/serial/serial_core.c
50850@@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50851 uart_flush_buffer(tty);
50852 uart_shutdown(tty, state);
50853 spin_lock_irqsave(&port->lock, flags);
50854- port->count = 0;
50855+ atomic_set(&port->count, 0);
50856 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50857 spin_unlock_irqrestore(&port->lock, flags);
50858 tty_port_tty_set(port, NULL);
50859@@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50860 goto end;
50861 }
50862
50863- port->count++;
50864+ atomic_inc(&port->count);
50865 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50866 retval = -ENXIO;
50867 goto err_dec_count;
50868@@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50869 /*
50870 * Make sure the device is in D0 state.
50871 */
50872- if (port->count == 1)
50873+ if (atomic_read(&port->count) == 1)
50874 uart_change_pm(state, UART_PM_STATE_ON);
50875
50876 /*
50877@@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50878 end:
50879 return retval;
50880 err_dec_count:
50881- port->count--;
50882+ atomic_inc(&port->count);
50883 mutex_unlock(&port->mutex);
50884 goto end;
50885 }
50886diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50887index e1ce141..6d4ed80 100644
50888--- a/drivers/tty/synclink.c
50889+++ b/drivers/tty/synclink.c
50890@@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50891
50892 if (debug_level >= DEBUG_LEVEL_INFO)
50893 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50894- __FILE__,__LINE__, info->device_name, info->port.count);
50895+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50896
50897 if (tty_port_close_start(&info->port, tty, filp) == 0)
50898 goto cleanup;
50899@@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50900 cleanup:
50901 if (debug_level >= DEBUG_LEVEL_INFO)
50902 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50903- tty->driver->name, info->port.count);
50904+ tty->driver->name, atomic_read(&info->port.count));
50905
50906 } /* end of mgsl_close() */
50907
50908@@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50909
50910 mgsl_flush_buffer(tty);
50911 shutdown(info);
50912-
50913- info->port.count = 0;
50914+
50915+ atomic_set(&info->port.count, 0);
50916 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50917 info->port.tty = NULL;
50918
50919@@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50920
50921 if (debug_level >= DEBUG_LEVEL_INFO)
50922 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50923- __FILE__,__LINE__, tty->driver->name, port->count );
50924+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50925
50926 spin_lock_irqsave(&info->irq_spinlock, flags);
50927 if (!tty_hung_up_p(filp)) {
50928 extra_count = true;
50929- port->count--;
50930+ atomic_dec(&port->count);
50931 }
50932 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50933 port->blocked_open++;
50934@@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50935
50936 if (debug_level >= DEBUG_LEVEL_INFO)
50937 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50938- __FILE__,__LINE__, tty->driver->name, port->count );
50939+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50940
50941 tty_unlock(tty);
50942 schedule();
50943@@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50944
50945 /* FIXME: Racy on hangup during close wait */
50946 if (extra_count)
50947- port->count++;
50948+ atomic_inc(&port->count);
50949 port->blocked_open--;
50950
50951 if (debug_level >= DEBUG_LEVEL_INFO)
50952 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50953- __FILE__,__LINE__, tty->driver->name, port->count );
50954+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50955
50956 if (!retval)
50957 port->flags |= ASYNC_NORMAL_ACTIVE;
50958@@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50959
50960 if (debug_level >= DEBUG_LEVEL_INFO)
50961 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50962- __FILE__,__LINE__,tty->driver->name, info->port.count);
50963+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50964
50965 /* If port is closing, signal caller to try again */
50966 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50967@@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50968 spin_unlock_irqrestore(&info->netlock, flags);
50969 goto cleanup;
50970 }
50971- info->port.count++;
50972+ atomic_inc(&info->port.count);
50973 spin_unlock_irqrestore(&info->netlock, flags);
50974
50975- if (info->port.count == 1) {
50976+ if (atomic_read(&info->port.count) == 1) {
50977 /* 1st open on this device, init hardware */
50978 retval = startup(info);
50979 if (retval < 0)
50980@@ -3446,8 +3446,8 @@ cleanup:
50981 if (retval) {
50982 if (tty->count == 1)
50983 info->port.tty = NULL; /* tty layer will release tty struct */
50984- if(info->port.count)
50985- info->port.count--;
50986+ if (atomic_read(&info->port.count))
50987+ atomic_dec(&info->port.count);
50988 }
50989
50990 return retval;
50991@@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50992 unsigned short new_crctype;
50993
50994 /* return error if TTY interface open */
50995- if (info->port.count)
50996+ if (atomic_read(&info->port.count))
50997 return -EBUSY;
50998
50999 switch (encoding)
51000@@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51001
51002 /* arbitrate between network and tty opens */
51003 spin_lock_irqsave(&info->netlock, flags);
51004- if (info->port.count != 0 || info->netcount != 0) {
51005+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51006 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51007 spin_unlock_irqrestore(&info->netlock, flags);
51008 return -EBUSY;
51009@@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51010 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51011
51012 /* return error if TTY interface open */
51013- if (info->port.count)
51014+ if (atomic_read(&info->port.count))
51015 return -EBUSY;
51016
51017 if (cmd != SIOCWANDEV)
51018diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51019index 1abf946..1ee34fc 100644
51020--- a/drivers/tty/synclink_gt.c
51021+++ b/drivers/tty/synclink_gt.c
51022@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51023 tty->driver_data = info;
51024 info->port.tty = tty;
51025
51026- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51027+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51028
51029 /* If port is closing, signal caller to try again */
51030 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51031@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51032 mutex_unlock(&info->port.mutex);
51033 goto cleanup;
51034 }
51035- info->port.count++;
51036+ atomic_inc(&info->port.count);
51037 spin_unlock_irqrestore(&info->netlock, flags);
51038
51039- if (info->port.count == 1) {
51040+ if (atomic_read(&info->port.count) == 1) {
51041 /* 1st open on this device, init hardware */
51042 retval = startup(info);
51043 if (retval < 0) {
51044@@ -715,8 +715,8 @@ cleanup:
51045 if (retval) {
51046 if (tty->count == 1)
51047 info->port.tty = NULL; /* tty layer will release tty struct */
51048- if(info->port.count)
51049- info->port.count--;
51050+ if(atomic_read(&info->port.count))
51051+ atomic_dec(&info->port.count);
51052 }
51053
51054 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51055@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51056
51057 if (sanity_check(info, tty->name, "close"))
51058 return;
51059- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51060+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51061
51062 if (tty_port_close_start(&info->port, tty, filp) == 0)
51063 goto cleanup;
51064@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51065 tty_port_close_end(&info->port, tty);
51066 info->port.tty = NULL;
51067 cleanup:
51068- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51069+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51070 }
51071
51072 static void hangup(struct tty_struct *tty)
51073@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51074 shutdown(info);
51075
51076 spin_lock_irqsave(&info->port.lock, flags);
51077- info->port.count = 0;
51078+ atomic_set(&info->port.count, 0);
51079 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51080 info->port.tty = NULL;
51081 spin_unlock_irqrestore(&info->port.lock, flags);
51082@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51083 unsigned short new_crctype;
51084
51085 /* return error if TTY interface open */
51086- if (info->port.count)
51087+ if (atomic_read(&info->port.count))
51088 return -EBUSY;
51089
51090 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51091@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51092
51093 /* arbitrate between network and tty opens */
51094 spin_lock_irqsave(&info->netlock, flags);
51095- if (info->port.count != 0 || info->netcount != 0) {
51096+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51097 DBGINFO(("%s hdlc_open busy\n", dev->name));
51098 spin_unlock_irqrestore(&info->netlock, flags);
51099 return -EBUSY;
51100@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51101 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51102
51103 /* return error if TTY interface open */
51104- if (info->port.count)
51105+ if (atomic_read(&info->port.count))
51106 return -EBUSY;
51107
51108 if (cmd != SIOCWANDEV)
51109@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51110 if (port == NULL)
51111 continue;
51112 spin_lock(&port->lock);
51113- if ((port->port.count || port->netcount) &&
51114+ if ((atomic_read(&port->port.count) || port->netcount) &&
51115 port->pending_bh && !port->bh_running &&
51116 !port->bh_requested) {
51117 DBGISR(("%s bh queued\n", port->device_name));
51118@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51119 spin_lock_irqsave(&info->lock, flags);
51120 if (!tty_hung_up_p(filp)) {
51121 extra_count = true;
51122- port->count--;
51123+ atomic_dec(&port->count);
51124 }
51125 spin_unlock_irqrestore(&info->lock, flags);
51126 port->blocked_open++;
51127@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51128 remove_wait_queue(&port->open_wait, &wait);
51129
51130 if (extra_count)
51131- port->count++;
51132+ atomic_inc(&port->count);
51133 port->blocked_open--;
51134
51135 if (!retval)
51136diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51137index dc6e969..5dc8786 100644
51138--- a/drivers/tty/synclinkmp.c
51139+++ b/drivers/tty/synclinkmp.c
51140@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51141
51142 if (debug_level >= DEBUG_LEVEL_INFO)
51143 printk("%s(%d):%s open(), old ref count = %d\n",
51144- __FILE__,__LINE__,tty->driver->name, info->port.count);
51145+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51146
51147 /* If port is closing, signal caller to try again */
51148 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51149@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51150 spin_unlock_irqrestore(&info->netlock, flags);
51151 goto cleanup;
51152 }
51153- info->port.count++;
51154+ atomic_inc(&info->port.count);
51155 spin_unlock_irqrestore(&info->netlock, flags);
51156
51157- if (info->port.count == 1) {
51158+ if (atomic_read(&info->port.count) == 1) {
51159 /* 1st open on this device, init hardware */
51160 retval = startup(info);
51161 if (retval < 0)
51162@@ -796,8 +796,8 @@ cleanup:
51163 if (retval) {
51164 if (tty->count == 1)
51165 info->port.tty = NULL; /* tty layer will release tty struct */
51166- if(info->port.count)
51167- info->port.count--;
51168+ if(atomic_read(&info->port.count))
51169+ atomic_dec(&info->port.count);
51170 }
51171
51172 return retval;
51173@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51174
51175 if (debug_level >= DEBUG_LEVEL_INFO)
51176 printk("%s(%d):%s close() entry, count=%d\n",
51177- __FILE__,__LINE__, info->device_name, info->port.count);
51178+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51179
51180 if (tty_port_close_start(&info->port, tty, filp) == 0)
51181 goto cleanup;
51182@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51183 cleanup:
51184 if (debug_level >= DEBUG_LEVEL_INFO)
51185 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51186- tty->driver->name, info->port.count);
51187+ tty->driver->name, atomic_read(&info->port.count));
51188 }
51189
51190 /* Called by tty_hangup() when a hangup is signaled.
51191@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51192 shutdown(info);
51193
51194 spin_lock_irqsave(&info->port.lock, flags);
51195- info->port.count = 0;
51196+ atomic_set(&info->port.count, 0);
51197 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51198 info->port.tty = NULL;
51199 spin_unlock_irqrestore(&info->port.lock, flags);
51200@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51201 unsigned short new_crctype;
51202
51203 /* return error if TTY interface open */
51204- if (info->port.count)
51205+ if (atomic_read(&info->port.count))
51206 return -EBUSY;
51207
51208 switch (encoding)
51209@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51210
51211 /* arbitrate between network and tty opens */
51212 spin_lock_irqsave(&info->netlock, flags);
51213- if (info->port.count != 0 || info->netcount != 0) {
51214+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51215 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51216 spin_unlock_irqrestore(&info->netlock, flags);
51217 return -EBUSY;
51218@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51219 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51220
51221 /* return error if TTY interface open */
51222- if (info->port.count)
51223+ if (atomic_read(&info->port.count))
51224 return -EBUSY;
51225
51226 if (cmd != SIOCWANDEV)
51227@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51228 * do not request bottom half processing if the
51229 * device is not open in a normal mode.
51230 */
51231- if ( port && (port->port.count || port->netcount) &&
51232+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51233 port->pending_bh && !port->bh_running &&
51234 !port->bh_requested ) {
51235 if ( debug_level >= DEBUG_LEVEL_ISR )
51236@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51237
51238 if (debug_level >= DEBUG_LEVEL_INFO)
51239 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51240- __FILE__,__LINE__, tty->driver->name, port->count );
51241+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51242
51243 spin_lock_irqsave(&info->lock, flags);
51244 if (!tty_hung_up_p(filp)) {
51245 extra_count = true;
51246- port->count--;
51247+ atomic_dec(&port->count);
51248 }
51249 spin_unlock_irqrestore(&info->lock, flags);
51250 port->blocked_open++;
51251@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51252
51253 if (debug_level >= DEBUG_LEVEL_INFO)
51254 printk("%s(%d):%s block_til_ready() count=%d\n",
51255- __FILE__,__LINE__, tty->driver->name, port->count );
51256+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51257
51258 tty_unlock(tty);
51259 schedule();
51260@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51261 remove_wait_queue(&port->open_wait, &wait);
51262
51263 if (extra_count)
51264- port->count++;
51265+ atomic_inc(&port->count);
51266 port->blocked_open--;
51267
51268 if (debug_level >= DEBUG_LEVEL_INFO)
51269 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51270- __FILE__,__LINE__, tty->driver->name, port->count );
51271+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51272
51273 if (!retval)
51274 port->flags |= ASYNC_NORMAL_ACTIVE;
51275diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51276index ce396ec..04a37be 100644
51277--- a/drivers/tty/sysrq.c
51278+++ b/drivers/tty/sysrq.c
51279@@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51280 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51281 size_t count, loff_t *ppos)
51282 {
51283- if (count) {
51284+ if (count && capable(CAP_SYS_ADMIN)) {
51285 char c;
51286
51287 if (get_user(c, buf))
51288diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51289index c74a00a..02cf211a 100644
51290--- a/drivers/tty/tty_io.c
51291+++ b/drivers/tty/tty_io.c
51292@@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51293
51294 void tty_default_fops(struct file_operations *fops)
51295 {
51296- *fops = tty_fops;
51297+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51298 }
51299
51300 /*
51301diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51302index 6458e11..6cfc218 100644
51303--- a/drivers/tty/tty_ldisc.c
51304+++ b/drivers/tty/tty_ldisc.c
51305@@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51306 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51307 tty_ldiscs[disc] = new_ldisc;
51308 new_ldisc->num = disc;
51309- new_ldisc->refcount = 0;
51310+ atomic_set(&new_ldisc->refcount, 0);
51311 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51312
51313 return ret;
51314@@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
51315 return -EINVAL;
51316
51317 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51318- if (tty_ldiscs[disc]->refcount)
51319+ if (atomic_read(&tty_ldiscs[disc]->refcount))
51320 ret = -EBUSY;
51321 else
51322 tty_ldiscs[disc] = NULL;
51323@@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51324 if (ldops) {
51325 ret = ERR_PTR(-EAGAIN);
51326 if (try_module_get(ldops->owner)) {
51327- ldops->refcount++;
51328+ atomic_inc(&ldops->refcount);
51329 ret = ldops;
51330 }
51331 }
51332@@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51333 unsigned long flags;
51334
51335 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51336- ldops->refcount--;
51337+ atomic_dec(&ldops->refcount);
51338 module_put(ldops->owner);
51339 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51340 }
51341diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51342index c94d234..8210f2d 100644
51343--- a/drivers/tty/tty_port.c
51344+++ b/drivers/tty/tty_port.c
51345@@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
51346 unsigned long flags;
51347
51348 spin_lock_irqsave(&port->lock, flags);
51349- port->count = 0;
51350+ atomic_set(&port->count, 0);
51351 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51352 tty = port->tty;
51353 if (tty)
51354@@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51355 /* The port lock protects the port counts */
51356 spin_lock_irqsave(&port->lock, flags);
51357 if (!tty_hung_up_p(filp))
51358- port->count--;
51359+ atomic_dec(&port->count);
51360 port->blocked_open++;
51361 spin_unlock_irqrestore(&port->lock, flags);
51362
51363@@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51364 we must not mess that up further */
51365 spin_lock_irqsave(&port->lock, flags);
51366 if (!tty_hung_up_p(filp))
51367- port->count++;
51368+ atomic_inc(&port->count);
51369 port->blocked_open--;
51370 if (retval == 0)
51371 port->flags |= ASYNC_NORMAL_ACTIVE;
51372@@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
51373 return 0;
51374 }
51375
51376- if (tty->count == 1 && port->count != 1) {
51377+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
51378 printk(KERN_WARNING
51379 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51380- port->count);
51381- port->count = 1;
51382+ atomic_read(&port->count));
51383+ atomic_set(&port->count, 1);
51384 }
51385- if (--port->count < 0) {
51386+ if (atomic_dec_return(&port->count) < 0) {
51387 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51388- port->count);
51389- port->count = 0;
51390+ atomic_read(&port->count));
51391+ atomic_set(&port->count, 0);
51392 }
51393
51394- if (port->count) {
51395+ if (atomic_read(&port->count)) {
51396 spin_unlock_irqrestore(&port->lock, flags);
51397 return 0;
51398 }
51399@@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51400 {
51401 spin_lock_irq(&port->lock);
51402 if (!tty_hung_up_p(filp))
51403- ++port->count;
51404+ atomic_inc(&port->count);
51405 spin_unlock_irq(&port->lock);
51406 tty_port_tty_set(port, tty);
51407
51408diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51409index d0e3a44..5f8b754 100644
51410--- a/drivers/tty/vt/keyboard.c
51411+++ b/drivers/tty/vt/keyboard.c
51412@@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51413 kbd->kbdmode == VC_OFF) &&
51414 value != KVAL(K_SAK))
51415 return; /* SAK is allowed even in raw mode */
51416+
51417+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51418+ {
51419+ void *func = fn_handler[value];
51420+ if (func == fn_show_state || func == fn_show_ptregs ||
51421+ func == fn_show_mem)
51422+ return;
51423+ }
51424+#endif
51425+
51426 fn_handler[value](vc);
51427 }
51428
51429@@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51430 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51431 return -EFAULT;
51432
51433- if (!capable(CAP_SYS_TTY_CONFIG))
51434- perm = 0;
51435-
51436 switch (cmd) {
51437 case KDGKBENT:
51438 /* Ensure another thread doesn't free it under us */
51439@@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51440 spin_unlock_irqrestore(&kbd_event_lock, flags);
51441 return put_user(val, &user_kbe->kb_value);
51442 case KDSKBENT:
51443+ if (!capable(CAP_SYS_TTY_CONFIG))
51444+ perm = 0;
51445+
51446 if (!perm)
51447 return -EPERM;
51448 if (!i && v == K_NOSUCHMAP) {
51449@@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51450 int i, j, k;
51451 int ret;
51452
51453- if (!capable(CAP_SYS_TTY_CONFIG))
51454- perm = 0;
51455-
51456 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51457 if (!kbs) {
51458 ret = -ENOMEM;
51459@@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51460 kfree(kbs);
51461 return ((p && *p) ? -EOVERFLOW : 0);
51462 case KDSKBSENT:
51463+ if (!capable(CAP_SYS_TTY_CONFIG))
51464+ perm = 0;
51465+
51466 if (!perm) {
51467 ret = -EPERM;
51468 goto reterr;
51469diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51470index a673e5b..36e5d32 100644
51471--- a/drivers/uio/uio.c
51472+++ b/drivers/uio/uio.c
51473@@ -25,6 +25,7 @@
51474 #include <linux/kobject.h>
51475 #include <linux/cdev.h>
51476 #include <linux/uio_driver.h>
51477+#include <asm/local.h>
51478
51479 #define UIO_MAX_DEVICES (1U << MINORBITS)
51480
51481@@ -32,7 +33,7 @@ struct uio_device {
51482 struct module *owner;
51483 struct device *dev;
51484 int minor;
51485- atomic_t event;
51486+ atomic_unchecked_t event;
51487 struct fasync_struct *async_queue;
51488 wait_queue_head_t wait;
51489 struct uio_info *info;
51490@@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51491 struct device_attribute *attr, char *buf)
51492 {
51493 struct uio_device *idev = dev_get_drvdata(dev);
51494- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51495+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51496 }
51497 static DEVICE_ATTR_RO(event);
51498
51499@@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51500 {
51501 struct uio_device *idev = info->uio_dev;
51502
51503- atomic_inc(&idev->event);
51504+ atomic_inc_unchecked(&idev->event);
51505 wake_up_interruptible(&idev->wait);
51506 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51507 }
51508@@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51509 }
51510
51511 listener->dev = idev;
51512- listener->event_count = atomic_read(&idev->event);
51513+ listener->event_count = atomic_read_unchecked(&idev->event);
51514 filep->private_data = listener;
51515
51516 if (idev->info->open) {
51517@@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51518 return -EIO;
51519
51520 poll_wait(filep, &idev->wait, wait);
51521- if (listener->event_count != atomic_read(&idev->event))
51522+ if (listener->event_count != atomic_read_unchecked(&idev->event))
51523 return POLLIN | POLLRDNORM;
51524 return 0;
51525 }
51526@@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51527 do {
51528 set_current_state(TASK_INTERRUPTIBLE);
51529
51530- event_count = atomic_read(&idev->event);
51531+ event_count = atomic_read_unchecked(&idev->event);
51532 if (event_count != listener->event_count) {
51533 if (copy_to_user(buf, &event_count, count))
51534 retval = -EFAULT;
51535@@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51536 static int uio_find_mem_index(struct vm_area_struct *vma)
51537 {
51538 struct uio_device *idev = vma->vm_private_data;
51539+ unsigned long size;
51540
51541 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51542- if (idev->info->mem[vma->vm_pgoff].size == 0)
51543+ size = idev->info->mem[vma->vm_pgoff].size;
51544+ if (size == 0)
51545+ return -1;
51546+ if (vma->vm_end - vma->vm_start > size)
51547 return -1;
51548 return (int)vma->vm_pgoff;
51549 }
51550@@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51551 idev->owner = owner;
51552 idev->info = info;
51553 init_waitqueue_head(&idev->wait);
51554- atomic_set(&idev->event, 0);
51555+ atomic_set_unchecked(&idev->event, 0);
51556
51557 ret = uio_get_minor(idev);
51558 if (ret)
51559diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51560index 8a7eb77..c00402f 100644
51561--- a/drivers/usb/atm/cxacru.c
51562+++ b/drivers/usb/atm/cxacru.c
51563@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51564 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51565 if (ret < 2)
51566 return -EINVAL;
51567- if (index < 0 || index > 0x7f)
51568+ if (index > 0x7f)
51569 return -EINVAL;
51570 pos += tmp;
51571
51572diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51573index 25a7bfc..57f3cf5 100644
51574--- a/drivers/usb/atm/usbatm.c
51575+++ b/drivers/usb/atm/usbatm.c
51576@@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51577 if (printk_ratelimit())
51578 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51579 __func__, vpi, vci);
51580- atomic_inc(&vcc->stats->rx_err);
51581+ atomic_inc_unchecked(&vcc->stats->rx_err);
51582 return;
51583 }
51584
51585@@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51586 if (length > ATM_MAX_AAL5_PDU) {
51587 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51588 __func__, length, vcc);
51589- atomic_inc(&vcc->stats->rx_err);
51590+ atomic_inc_unchecked(&vcc->stats->rx_err);
51591 goto out;
51592 }
51593
51594@@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51595 if (sarb->len < pdu_length) {
51596 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51597 __func__, pdu_length, sarb->len, vcc);
51598- atomic_inc(&vcc->stats->rx_err);
51599+ atomic_inc_unchecked(&vcc->stats->rx_err);
51600 goto out;
51601 }
51602
51603 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51604 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51605 __func__, vcc);
51606- atomic_inc(&vcc->stats->rx_err);
51607+ atomic_inc_unchecked(&vcc->stats->rx_err);
51608 goto out;
51609 }
51610
51611@@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51612 if (printk_ratelimit())
51613 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51614 __func__, length);
51615- atomic_inc(&vcc->stats->rx_drop);
51616+ atomic_inc_unchecked(&vcc->stats->rx_drop);
51617 goto out;
51618 }
51619
51620@@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51621
51622 vcc->push(vcc, skb);
51623
51624- atomic_inc(&vcc->stats->rx);
51625+ atomic_inc_unchecked(&vcc->stats->rx);
51626 out:
51627 skb_trim(sarb, 0);
51628 }
51629@@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51630 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51631
51632 usbatm_pop(vcc, skb);
51633- atomic_inc(&vcc->stats->tx);
51634+ atomic_inc_unchecked(&vcc->stats->tx);
51635
51636 skb = skb_dequeue(&instance->sndqueue);
51637 }
51638@@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
51639 if (!left--)
51640 return sprintf(page,
51641 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51642- atomic_read(&atm_dev->stats.aal5.tx),
51643- atomic_read(&atm_dev->stats.aal5.tx_err),
51644- atomic_read(&atm_dev->stats.aal5.rx),
51645- atomic_read(&atm_dev->stats.aal5.rx_err),
51646- atomic_read(&atm_dev->stats.aal5.rx_drop));
51647+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51648+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51649+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51650+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
51651+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
51652
51653 if (!left--) {
51654 if (instance->disconnected)
51655diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
51656index 2a3bbdf..91d72cf 100644
51657--- a/drivers/usb/core/devices.c
51658+++ b/drivers/usb/core/devices.c
51659@@ -126,7 +126,7 @@ static const char format_endpt[] =
51660 * time it gets called.
51661 */
51662 static struct device_connect_event {
51663- atomic_t count;
51664+ atomic_unchecked_t count;
51665 wait_queue_head_t wait;
51666 } device_event = {
51667 .count = ATOMIC_INIT(1),
51668@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
51669
51670 void usbfs_conn_disc_event(void)
51671 {
51672- atomic_add(2, &device_event.count);
51673+ atomic_add_unchecked(2, &device_event.count);
51674 wake_up(&device_event.wait);
51675 }
51676
51677@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
51678
51679 poll_wait(file, &device_event.wait, wait);
51680
51681- event_count = atomic_read(&device_event.count);
51682+ event_count = atomic_read_unchecked(&device_event.count);
51683 if (file->f_version != event_count) {
51684 file->f_version = event_count;
51685 return POLLIN | POLLRDNORM;
51686diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51687index 967152a..16fa2e5 100644
51688--- a/drivers/usb/core/devio.c
51689+++ b/drivers/usb/core/devio.c
51690@@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51691 struct dev_state *ps = file->private_data;
51692 struct usb_device *dev = ps->dev;
51693 ssize_t ret = 0;
51694- unsigned len;
51695+ size_t len;
51696 loff_t pos;
51697 int i;
51698
51699@@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51700 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51701 struct usb_config_descriptor *config =
51702 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51703- unsigned int length = le16_to_cpu(config->wTotalLength);
51704+ size_t length = le16_to_cpu(config->wTotalLength);
51705
51706 if (*ppos < pos + length) {
51707
51708 /* The descriptor may claim to be longer than it
51709 * really is. Here is the actual allocated length. */
51710- unsigned alloclen =
51711+ size_t alloclen =
51712 le16_to_cpu(dev->config[i].desc.wTotalLength);
51713
51714- len = length - (*ppos - pos);
51715+ len = length + pos - *ppos;
51716 if (len > nbytes)
51717 len = nbytes;
51718
51719 /* Simply don't write (skip over) unallocated parts */
51720 if (alloclen > (*ppos - pos)) {
51721- alloclen -= (*ppos - pos);
51722+ alloclen = alloclen + pos - *ppos;
51723 if (copy_to_user(buf,
51724 dev->rawdescriptors[i] + (*ppos - pos),
51725 min(len, alloclen))) {
51726diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51727index d39106c..bfe13a4 100644
51728--- a/drivers/usb/core/hcd.c
51729+++ b/drivers/usb/core/hcd.c
51730@@ -1549,7 +1549,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51731 */
51732 usb_get_urb(urb);
51733 atomic_inc(&urb->use_count);
51734- atomic_inc(&urb->dev->urbnum);
51735+ atomic_inc_unchecked(&urb->dev->urbnum);
51736 usbmon_urb_submit(&hcd->self, urb);
51737
51738 /* NOTE requirements on root-hub callers (usbfs and the hub
51739@@ -1576,7 +1576,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51740 urb->hcpriv = NULL;
51741 INIT_LIST_HEAD(&urb->urb_list);
51742 atomic_dec(&urb->use_count);
51743- atomic_dec(&urb->dev->urbnum);
51744+ atomic_dec_unchecked(&urb->dev->urbnum);
51745 if (atomic_read(&urb->reject))
51746 wake_up(&usb_kill_urb_queue);
51747 usb_put_urb(urb);
51748diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51749index ebcd3bf..be93a64 100644
51750--- a/drivers/usb/core/hub.c
51751+++ b/drivers/usb/core/hub.c
51752@@ -27,6 +27,7 @@
51753 #include <linux/freezer.h>
51754 #include <linux/random.h>
51755 #include <linux/pm_qos.h>
51756+#include <linux/grsecurity.h>
51757
51758 #include <asm/uaccess.h>
51759 #include <asm/byteorder.h>
51760@@ -4437,6 +4438,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51761 goto done;
51762 return;
51763 }
51764+
51765+ if (gr_handle_new_usb())
51766+ goto done;
51767+
51768 if (hub_is_superspeed(hub->hdev))
51769 unit_load = 150;
51770 else
51771diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51772index bb31597..6c5ef8b 100644
51773--- a/drivers/usb/core/message.c
51774+++ b/drivers/usb/core/message.c
51775@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51776 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51777 * error number.
51778 */
51779-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51780+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51781 __u8 requesttype, __u16 value, __u16 index, void *data,
51782 __u16 size, int timeout)
51783 {
51784@@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51785 * If successful, 0. Otherwise a negative error number. The number of actual
51786 * bytes transferred will be stored in the @actual_length paramater.
51787 */
51788-int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51789+int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51790 void *data, int len, int *actual_length, int timeout)
51791 {
51792 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51793@@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51794 * bytes transferred will be stored in the @actual_length paramater.
51795 *
51796 */
51797-int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51798+int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51799 void *data, int len, int *actual_length, int timeout)
51800 {
51801 struct urb *urb;
51802diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51803index 52a97ad..e73330f 100644
51804--- a/drivers/usb/core/sysfs.c
51805+++ b/drivers/usb/core/sysfs.c
51806@@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51807 struct usb_device *udev;
51808
51809 udev = to_usb_device(dev);
51810- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51811+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51812 }
51813 static DEVICE_ATTR_RO(urbnum);
51814
51815diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51816index 4d11449..f4ccabf 100644
51817--- a/drivers/usb/core/usb.c
51818+++ b/drivers/usb/core/usb.c
51819@@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51820 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51821 dev->state = USB_STATE_ATTACHED;
51822 dev->lpm_disable_count = 1;
51823- atomic_set(&dev->urbnum, 0);
51824+ atomic_set_unchecked(&dev->urbnum, 0);
51825
51826 INIT_LIST_HEAD(&dev->ep0.urb_list);
51827 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51828diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51829index 02e44fc..3c4fe64 100644
51830--- a/drivers/usb/dwc3/gadget.c
51831+++ b/drivers/usb/dwc3/gadget.c
51832@@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51833 if (!usb_endpoint_xfer_isoc(desc))
51834 return 0;
51835
51836- memset(&trb_link, 0, sizeof(trb_link));
51837-
51838 /* Link TRB for ISOC. The HWO bit is never reset */
51839 trb_st_hw = &dep->trb_pool[0];
51840
51841diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51842index 8cfc319..4868255 100644
51843--- a/drivers/usb/early/ehci-dbgp.c
51844+++ b/drivers/usb/early/ehci-dbgp.c
51845@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51846
51847 #ifdef CONFIG_KGDB
51848 static struct kgdb_io kgdbdbgp_io_ops;
51849-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51850+static struct kgdb_io kgdbdbgp_io_ops_console;
51851+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51852 #else
51853 #define dbgp_kgdb_mode (0)
51854 #endif
51855@@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51856 .write_char = kgdbdbgp_write_char,
51857 };
51858
51859+static struct kgdb_io kgdbdbgp_io_ops_console = {
51860+ .name = "kgdbdbgp",
51861+ .read_char = kgdbdbgp_read_char,
51862+ .write_char = kgdbdbgp_write_char,
51863+ .is_console = 1
51864+};
51865+
51866 static int kgdbdbgp_wait_time;
51867
51868 static int __init kgdbdbgp_parse_config(char *str)
51869@@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51870 ptr++;
51871 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51872 }
51873- kgdb_register_io_module(&kgdbdbgp_io_ops);
51874- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51875+ if (early_dbgp_console.index != -1)
51876+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51877+ else
51878+ kgdb_register_io_module(&kgdbdbgp_io_ops);
51879
51880 return 0;
51881 }
51882diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51883index b369292..9f3ba40 100644
51884--- a/drivers/usb/gadget/u_serial.c
51885+++ b/drivers/usb/gadget/u_serial.c
51886@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51887 spin_lock_irq(&port->port_lock);
51888
51889 /* already open? Great. */
51890- if (port->port.count) {
51891+ if (atomic_read(&port->port.count)) {
51892 status = 0;
51893- port->port.count++;
51894+ atomic_inc(&port->port.count);
51895
51896 /* currently opening/closing? wait ... */
51897 } else if (port->openclose) {
51898@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51899 tty->driver_data = port;
51900 port->port.tty = tty;
51901
51902- port->port.count = 1;
51903+ atomic_set(&port->port.count, 1);
51904 port->openclose = false;
51905
51906 /* if connected, start the I/O stream */
51907@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51908
51909 spin_lock_irq(&port->port_lock);
51910
51911- if (port->port.count != 1) {
51912- if (port->port.count == 0)
51913+ if (atomic_read(&port->port.count) != 1) {
51914+ if (atomic_read(&port->port.count) == 0)
51915 WARN_ON(1);
51916 else
51917- --port->port.count;
51918+ atomic_dec(&port->port.count);
51919 goto exit;
51920 }
51921
51922@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51923 * and sleep if necessary
51924 */
51925 port->openclose = true;
51926- port->port.count = 0;
51927+ atomic_set(&port->port.count, 0);
51928
51929 gser = port->port_usb;
51930 if (gser && gser->disconnect)
51931@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51932 int cond;
51933
51934 spin_lock_irq(&port->port_lock);
51935- cond = (port->port.count == 0) && !port->openclose;
51936+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51937 spin_unlock_irq(&port->port_lock);
51938 return cond;
51939 }
51940@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51941 /* if it's already open, start I/O ... and notify the serial
51942 * protocol about open/close status (connect/disconnect).
51943 */
51944- if (port->port.count) {
51945+ if (atomic_read(&port->port.count)) {
51946 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51947 gs_start_io(port);
51948 if (gser->connect)
51949@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51950
51951 port->port_usb = NULL;
51952 gser->ioport = NULL;
51953- if (port->port.count > 0 || port->openclose) {
51954+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
51955 wake_up_interruptible(&port->drain_wait);
51956 if (port->port.tty)
51957 tty_hangup(port->port.tty);
51958@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51959
51960 /* finally, free any unused/unusable I/O buffers */
51961 spin_lock_irqsave(&port->port_lock, flags);
51962- if (port->port.count == 0 && !port->openclose)
51963+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
51964 gs_buf_free(&port->port_write_buf);
51965 gs_free_requests(gser->out, &port->read_pool, NULL);
51966 gs_free_requests(gser->out, &port->read_queue, NULL);
51967diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51968index 1bb85be..29e28d9 100644
51969--- a/drivers/usb/host/ehci-hub.c
51970+++ b/drivers/usb/host/ehci-hub.c
51971@@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
51972 urb->transfer_flags = URB_DIR_IN;
51973 usb_get_urb(urb);
51974 atomic_inc(&urb->use_count);
51975- atomic_inc(&urb->dev->urbnum);
51976+ atomic_inc_unchecked(&urb->dev->urbnum);
51977 urb->setup_dma = dma_map_single(
51978 hcd->self.controller,
51979 urb->setup_packet,
51980@@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51981 urb->status = -EINPROGRESS;
51982 usb_get_urb(urb);
51983 atomic_inc(&urb->use_count);
51984- atomic_inc(&urb->dev->urbnum);
51985+ atomic_inc_unchecked(&urb->dev->urbnum);
51986 retval = submit_single_step_set_feature(hcd, urb, 0);
51987 if (!retval && !wait_for_completion_timeout(&done,
51988 msecs_to_jiffies(2000))) {
51989diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51990index ba6a5d6..f88f7f3 100644
51991--- a/drivers/usb/misc/appledisplay.c
51992+++ b/drivers/usb/misc/appledisplay.c
51993@@ -83,7 +83,7 @@ struct appledisplay {
51994 spinlock_t lock;
51995 };
51996
51997-static atomic_t count_displays = ATOMIC_INIT(0);
51998+static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51999 static struct workqueue_struct *wq;
52000
52001 static void appledisplay_complete(struct urb *urb)
52002@@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52003
52004 /* Register backlight device */
52005 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52006- atomic_inc_return(&count_displays) - 1);
52007+ atomic_inc_return_unchecked(&count_displays) - 1);
52008 memset(&props, 0, sizeof(struct backlight_properties));
52009 props.type = BACKLIGHT_RAW;
52010 props.max_brightness = 0xff;
52011diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52012index c69bb50..215ef37 100644
52013--- a/drivers/usb/serial/console.c
52014+++ b/drivers/usb/serial/console.c
52015@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
52016
52017 info->port = port;
52018
52019- ++port->port.count;
52020+ atomic_inc(&port->port.count);
52021 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52022 if (serial->type->set_termios) {
52023 /*
52024@@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
52025 }
52026 /* Now that any required fake tty operations are completed restore
52027 * the tty port count */
52028- --port->port.count;
52029+ atomic_dec(&port->port.count);
52030 /* The console is special in terms of closing the device so
52031 * indicate this port is now acting as a system console. */
52032 port->port.console = 1;
52033@@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
52034 free_tty:
52035 kfree(tty);
52036 reset_open_count:
52037- port->port.count = 0;
52038+ atomic_set(&port->port.count, 0);
52039 usb_autopm_put_interface(serial->interface);
52040 error_get_interface:
52041 usb_serial_put(serial);
52042@@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
52043 static void usb_console_write(struct console *co,
52044 const char *buf, unsigned count)
52045 {
52046- static struct usbcons_info *info = &usbcons_info;
52047+ struct usbcons_info *info = &usbcons_info;
52048 struct usb_serial_port *port = info->port;
52049 struct usb_serial *serial;
52050 int retval = -ENODEV;
52051diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52052index 75f70f0..d467e1a 100644
52053--- a/drivers/usb/storage/usb.h
52054+++ b/drivers/usb/storage/usb.h
52055@@ -63,7 +63,7 @@ struct us_unusual_dev {
52056 __u8 useProtocol;
52057 __u8 useTransport;
52058 int (*initFunction)(struct us_data *);
52059-};
52060+} __do_const;
52061
52062
52063 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52064diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52065index e614f02..3fd60e2 100644
52066--- a/drivers/usb/wusbcore/wa-hc.h
52067+++ b/drivers/usb/wusbcore/wa-hc.h
52068@@ -225,7 +225,7 @@ struct wahc {
52069 spinlock_t xfer_list_lock;
52070 struct work_struct xfer_enqueue_work;
52071 struct work_struct xfer_error_work;
52072- atomic_t xfer_id_count;
52073+ atomic_unchecked_t xfer_id_count;
52074
52075 kernel_ulong_t quirks;
52076 };
52077@@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
52078 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52079 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52080 wa->dto_in_use = 0;
52081- atomic_set(&wa->xfer_id_count, 1);
52082+ atomic_set_unchecked(&wa->xfer_id_count, 1);
52083 }
52084
52085 /**
52086diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52087index ed5abe8..7036400 100644
52088--- a/drivers/usb/wusbcore/wa-xfer.c
52089+++ b/drivers/usb/wusbcore/wa-xfer.c
52090@@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52091 */
52092 static void wa_xfer_id_init(struct wa_xfer *xfer)
52093 {
52094- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52095+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52096 }
52097
52098 /* Return the xfer's ID. */
52099diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52100index 1eab4ac..e21efc9 100644
52101--- a/drivers/vfio/vfio.c
52102+++ b/drivers/vfio/vfio.c
52103@@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52104 return 0;
52105
52106 /* TODO Prevent device auto probing */
52107- WARN("Device %s added to live group %d!\n", dev_name(dev),
52108+ WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52109 iommu_group_id(group->iommu_group));
52110
52111 return 0;
52112diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52113index 5174eba..451e6bc 100644
52114--- a/drivers/vhost/vringh.c
52115+++ b/drivers/vhost/vringh.c
52116@@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52117 /* Userspace access helpers: in this case, addresses are really userspace. */
52118 static inline int getu16_user(u16 *val, const u16 *p)
52119 {
52120- return get_user(*val, (__force u16 __user *)p);
52121+ return get_user(*val, (u16 __force_user *)p);
52122 }
52123
52124 static inline int putu16_user(u16 *p, u16 val)
52125 {
52126- return put_user(val, (__force u16 __user *)p);
52127+ return put_user(val, (u16 __force_user *)p);
52128 }
52129
52130 static inline int copydesc_user(void *dst, const void *src, size_t len)
52131 {
52132- return copy_from_user(dst, (__force void __user *)src, len) ?
52133+ return copy_from_user(dst, (void __force_user *)src, len) ?
52134 -EFAULT : 0;
52135 }
52136
52137@@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52138 const struct vring_used_elem *src,
52139 unsigned int num)
52140 {
52141- return copy_to_user((__force void __user *)dst, src,
52142+ return copy_to_user((void __force_user *)dst, src,
52143 sizeof(*dst) * num) ? -EFAULT : 0;
52144 }
52145
52146 static inline int xfer_from_user(void *src, void *dst, size_t len)
52147 {
52148- return copy_from_user(dst, (__force void __user *)src, len) ?
52149+ return copy_from_user(dst, (void __force_user *)src, len) ?
52150 -EFAULT : 0;
52151 }
52152
52153 static inline int xfer_to_user(void *dst, void *src, size_t len)
52154 {
52155- return copy_to_user((__force void __user *)dst, src, len) ?
52156+ return copy_to_user((void __force_user *)dst, src, len) ?
52157 -EFAULT : 0;
52158 }
52159
52160@@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52161 vrh->last_used_idx = 0;
52162 vrh->vring.num = num;
52163 /* vring expects kernel addresses, but only used via accessors. */
52164- vrh->vring.desc = (__force struct vring_desc *)desc;
52165- vrh->vring.avail = (__force struct vring_avail *)avail;
52166- vrh->vring.used = (__force struct vring_used *)used;
52167+ vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52168+ vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52169+ vrh->vring.used = (__force_kernel struct vring_used *)used;
52170 return 0;
52171 }
52172 EXPORT_SYMBOL(vringh_init_user);
52173@@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52174
52175 static inline int putu16_kern(u16 *p, u16 val)
52176 {
52177- ACCESS_ONCE(*p) = val;
52178+ ACCESS_ONCE_RW(*p) = val;
52179 return 0;
52180 }
52181
52182diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
52183index 1b0b233..6f34c2c 100644
52184--- a/drivers/video/arcfb.c
52185+++ b/drivers/video/arcfb.c
52186@@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52187 return -ENOSPC;
52188
52189 err = 0;
52190- if ((count + p) > fbmemlength) {
52191+ if (count > (fbmemlength - p)) {
52192 count = fbmemlength - p;
52193 err = -ENOSPC;
52194 }
52195diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
52196index 12ca031..84a8a74 100644
52197--- a/drivers/video/aty/aty128fb.c
52198+++ b/drivers/video/aty/aty128fb.c
52199@@ -149,7 +149,7 @@ enum {
52200 };
52201
52202 /* Must match above enum */
52203-static char * const r128_family[] = {
52204+static const char * const r128_family[] = {
52205 "AGP",
52206 "PCI",
52207 "PRO AGP",
52208diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
52209index 28fafbf..ae91651 100644
52210--- a/drivers/video/aty/atyfb_base.c
52211+++ b/drivers/video/aty/atyfb_base.c
52212@@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52213 par->accel_flags = var->accel_flags; /* hack */
52214
52215 if (var->accel_flags) {
52216- info->fbops->fb_sync = atyfb_sync;
52217+ pax_open_kernel();
52218+ *(void **)&info->fbops->fb_sync = atyfb_sync;
52219+ pax_close_kernel();
52220 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52221 } else {
52222- info->fbops->fb_sync = NULL;
52223+ pax_open_kernel();
52224+ *(void **)&info->fbops->fb_sync = NULL;
52225+ pax_close_kernel();
52226 info->flags |= FBINFO_HWACCEL_DISABLED;
52227 }
52228
52229diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
52230index 95ec042..e6affdd 100644
52231--- a/drivers/video/aty/mach64_cursor.c
52232+++ b/drivers/video/aty/mach64_cursor.c
52233@@ -7,6 +7,7 @@
52234 #include <linux/string.h>
52235
52236 #include <asm/io.h>
52237+#include <asm/pgtable.h>
52238
52239 #ifdef __sparc__
52240 #include <asm/fbio.h>
52241@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
52242 info->sprite.buf_align = 16; /* and 64 lines tall. */
52243 info->sprite.flags = FB_PIXMAP_IO;
52244
52245- info->fbops->fb_cursor = atyfb_cursor;
52246+ pax_open_kernel();
52247+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52248+ pax_close_kernel();
52249
52250 return 0;
52251 }
52252diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52253index 7592cc2..92feb56 100644
52254--- a/drivers/video/backlight/kb3886_bl.c
52255+++ b/drivers/video/backlight/kb3886_bl.c
52256@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52257 static unsigned long kb3886bl_flags;
52258 #define KB3886BL_SUSPENDED 0x01
52259
52260-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
52261+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
52262 {
52263 .ident = "Sahara Touch-iT",
52264 .matches = {
52265diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
52266index 900aa4e..6d49418 100644
52267--- a/drivers/video/fb_defio.c
52268+++ b/drivers/video/fb_defio.c
52269@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52270
52271 BUG_ON(!fbdefio);
52272 mutex_init(&fbdefio->lock);
52273- info->fbops->fb_mmap = fb_deferred_io_mmap;
52274+ pax_open_kernel();
52275+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52276+ pax_close_kernel();
52277 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52278 INIT_LIST_HEAD(&fbdefio->pagelist);
52279 if (fbdefio->delay == 0) /* set a default of 1 s */
52280@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52281 page->mapping = NULL;
52282 }
52283
52284- info->fbops->fb_mmap = NULL;
52285+ *(void **)&info->fbops->fb_mmap = NULL;
52286 mutex_destroy(&fbdefio->lock);
52287 }
52288 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52289diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
52290index 010d191..7b8235a 100644
52291--- a/drivers/video/fbmem.c
52292+++ b/drivers/video/fbmem.c
52293@@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52294 image->dx += image->width + 8;
52295 }
52296 } else if (rotate == FB_ROTATE_UD) {
52297- for (x = 0; x < num && image->dx >= 0; x++) {
52298+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52299 info->fbops->fb_imageblit(info, image);
52300 image->dx -= image->width + 8;
52301 }
52302@@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52303 image->dy += image->height + 8;
52304 }
52305 } else if (rotate == FB_ROTATE_CCW) {
52306- for (x = 0; x < num && image->dy >= 0; x++) {
52307+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52308 info->fbops->fb_imageblit(info, image);
52309 image->dy -= image->height + 8;
52310 }
52311@@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52312 return -EFAULT;
52313 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52314 return -EINVAL;
52315- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52316+ if (con2fb.framebuffer >= FB_MAX)
52317 return -EINVAL;
52318 if (!registered_fb[con2fb.framebuffer])
52319 request_module("fb%d", con2fb.framebuffer);
52320@@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52321 __u32 data;
52322 int err;
52323
52324- err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52325+ err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52326
52327 data = (__u32) (unsigned long) fix->smem_start;
52328 err |= put_user(data, &fix32->smem_start);
52329diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
52330index 130708f..cdac1a9 100644
52331--- a/drivers/video/hyperv_fb.c
52332+++ b/drivers/video/hyperv_fb.c
52333@@ -233,7 +233,7 @@ static uint screen_fb_size;
52334 static inline int synthvid_send(struct hv_device *hdev,
52335 struct synthvid_msg *msg)
52336 {
52337- static atomic64_t request_id = ATOMIC64_INIT(0);
52338+ static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52339 int ret;
52340
52341 msg->pipe_hdr.type = PIPE_MSG_DATA;
52342@@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52343
52344 ret = vmbus_sendpacket(hdev->channel, msg,
52345 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52346- atomic64_inc_return(&request_id),
52347+ atomic64_inc_return_unchecked(&request_id),
52348 VM_PKT_DATA_INBAND, 0);
52349
52350 if (ret)
52351diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
52352index 7672d2e..b56437f 100644
52353--- a/drivers/video/i810/i810_accel.c
52354+++ b/drivers/video/i810/i810_accel.c
52355@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52356 }
52357 }
52358 printk("ringbuffer lockup!!!\n");
52359+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52360 i810_report_error(mmio);
52361 par->dev_flags |= LOCKUP;
52362 info->pixmap.scan_align = 1;
52363diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
52364index 3c14e43..2630570 100644
52365--- a/drivers/video/logo/logo_linux_clut224.ppm
52366+++ b/drivers/video/logo/logo_linux_clut224.ppm
52367@@ -2,1603 +2,1123 @@ P3
52368 # Standard 224-color Linux logo
52369 80 80
52370 255
52371- 0 0 0 0 0 0 0 0 0 0 0 0
52372- 0 0 0 0 0 0 0 0 0 0 0 0
52373- 0 0 0 0 0 0 0 0 0 0 0 0
52374- 0 0 0 0 0 0 0 0 0 0 0 0
52375- 0 0 0 0 0 0 0 0 0 0 0 0
52376- 0 0 0 0 0 0 0 0 0 0 0 0
52377- 0 0 0 0 0 0 0 0 0 0 0 0
52378- 0 0 0 0 0 0 0 0 0 0 0 0
52379- 0 0 0 0 0 0 0 0 0 0 0 0
52380- 6 6 6 6 6 6 10 10 10 10 10 10
52381- 10 10 10 6 6 6 6 6 6 6 6 6
52382- 0 0 0 0 0 0 0 0 0 0 0 0
52383- 0 0 0 0 0 0 0 0 0 0 0 0
52384- 0 0 0 0 0 0 0 0 0 0 0 0
52385- 0 0 0 0 0 0 0 0 0 0 0 0
52386- 0 0 0 0 0 0 0 0 0 0 0 0
52387- 0 0 0 0 0 0 0 0 0 0 0 0
52388- 0 0 0 0 0 0 0 0 0 0 0 0
52389- 0 0 0 0 0 0 0 0 0 0 0 0
52390- 0 0 0 0 0 0 0 0 0 0 0 0
52391- 0 0 0 0 0 0 0 0 0 0 0 0
52392- 0 0 0 0 0 0 0 0 0 0 0 0
52393- 0 0 0 0 0 0 0 0 0 0 0 0
52394- 0 0 0 0 0 0 0 0 0 0 0 0
52395- 0 0 0 0 0 0 0 0 0 0 0 0
52396- 0 0 0 0 0 0 0 0 0 0 0 0
52397- 0 0 0 0 0 0 0 0 0 0 0 0
52398- 0 0 0 0 0 0 0 0 0 0 0 0
52399- 0 0 0 6 6 6 10 10 10 14 14 14
52400- 22 22 22 26 26 26 30 30 30 34 34 34
52401- 30 30 30 30 30 30 26 26 26 18 18 18
52402- 14 14 14 10 10 10 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
52409- 0 0 0 0 0 0 0 0 0 0 0 0
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 1 0 0 1 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- 6 6 6 14 14 14 26 26 26 42 42 42
52420- 54 54 54 66 66 66 78 78 78 78 78 78
52421- 78 78 78 74 74 74 66 66 66 54 54 54
52422- 42 42 42 26 26 26 18 18 18 10 10 10
52423- 6 6 6 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 0 0 0 0 0 0 0 0 0
52428- 0 0 0 0 0 0 0 0 0 0 0 0
52429- 0 0 0 0 0 0 0 0 0 0 0 0
52430- 0 0 0 0 0 0 0 0 0 0 0 0
52431- 0 0 0 0 0 0 0 0 0 0 0 0
52432- 0 0 1 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 10 10 10
52439- 22 22 22 42 42 42 66 66 66 86 86 86
52440- 66 66 66 38 38 38 38 38 38 22 22 22
52441- 26 26 26 34 34 34 54 54 54 66 66 66
52442- 86 86 86 70 70 70 46 46 46 26 26 26
52443- 14 14 14 6 6 6 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- 0 0 0 0 0 0 0 0 0 0 0 0
52448- 0 0 0 0 0 0 0 0 0 0 0 0
52449- 0 0 0 0 0 0 0 0 0 0 0 0
52450- 0 0 0 0 0 0 0 0 0 0 0 0
52451- 0 0 0 0 0 0 0 0 0 0 0 0
52452- 0 0 1 0 0 1 0 0 1 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 10 10 10 26 26 26
52459- 50 50 50 82 82 82 58 58 58 6 6 6
52460- 2 2 6 2 2 6 2 2 6 2 2 6
52461- 2 2 6 2 2 6 2 2 6 2 2 6
52462- 6 6 6 54 54 54 86 86 86 66 66 66
52463- 38 38 38 18 18 18 6 6 6 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 0 0 0
52467- 0 0 0 0 0 0 0 0 0 0 0 0
52468- 0 0 0 0 0 0 0 0 0 0 0 0
52469- 0 0 0 0 0 0 0 0 0 0 0 0
52470- 0 0 0 0 0 0 0 0 0 0 0 0
52471- 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
52479- 78 78 78 34 34 34 2 2 6 2 2 6
52480- 2 2 6 2 2 6 2 2 6 2 2 6
52481- 2 2 6 2 2 6 2 2 6 2 2 6
52482- 2 2 6 2 2 6 6 6 6 70 70 70
52483- 78 78 78 46 46 46 22 22 22 6 6 6
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 0 0 0 0 0 0
52487- 0 0 0 0 0 0 0 0 0 0 0 0
52488- 0 0 0 0 0 0 0 0 0 0 0 0
52489- 0 0 0 0 0 0 0 0 0 0 0 0
52490- 0 0 0 0 0 0 0 0 0 0 0 0
52491- 0 0 0 0 0 0 0 0 0 0 0 0
52492- 0 0 1 0 0 1 0 0 1 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- 6 6 6 18 18 18 42 42 42 82 82 82
52499- 26 26 26 2 2 6 2 2 6 2 2 6
52500- 2 2 6 2 2 6 2 2 6 2 2 6
52501- 2 2 6 2 2 6 2 2 6 14 14 14
52502- 46 46 46 34 34 34 6 6 6 2 2 6
52503- 42 42 42 78 78 78 42 42 42 18 18 18
52504- 6 6 6 0 0 0 0 0 0 0 0 0
52505- 0 0 0 0 0 0 0 0 0 0 0 0
52506- 0 0 0 0 0 0 0 0 0 0 0 0
52507- 0 0 0 0 0 0 0 0 0 0 0 0
52508- 0 0 0 0 0 0 0 0 0 0 0 0
52509- 0 0 0 0 0 0 0 0 0 0 0 0
52510- 0 0 0 0 0 0 0 0 0 0 0 0
52511- 0 0 0 0 0 0 0 0 0 0 0 0
52512- 0 0 1 0 0 0 0 0 1 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- 10 10 10 30 30 30 66 66 66 58 58 58
52519- 2 2 6 2 2 6 2 2 6 2 2 6
52520- 2 2 6 2 2 6 2 2 6 2 2 6
52521- 2 2 6 2 2 6 2 2 6 26 26 26
52522- 86 86 86 101 101 101 46 46 46 10 10 10
52523- 2 2 6 58 58 58 70 70 70 34 34 34
52524- 10 10 10 0 0 0 0 0 0 0 0 0
52525- 0 0 0 0 0 0 0 0 0 0 0 0
52526- 0 0 0 0 0 0 0 0 0 0 0 0
52527- 0 0 0 0 0 0 0 0 0 0 0 0
52528- 0 0 0 0 0 0 0 0 0 0 0 0
52529- 0 0 0 0 0 0 0 0 0 0 0 0
52530- 0 0 0 0 0 0 0 0 0 0 0 0
52531- 0 0 0 0 0 0 0 0 0 0 0 0
52532- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
52539- 2 2 6 2 2 6 2 2 6 2 2 6
52540- 2 2 6 2 2 6 2 2 6 2 2 6
52541- 2 2 6 2 2 6 2 2 6 30 30 30
52542- 94 94 94 94 94 94 58 58 58 26 26 26
52543- 2 2 6 6 6 6 78 78 78 54 54 54
52544- 22 22 22 6 6 6 0 0 0 0 0 0
52545- 0 0 0 0 0 0 0 0 0 0 0 0
52546- 0 0 0 0 0 0 0 0 0 0 0 0
52547- 0 0 0 0 0 0 0 0 0 0 0 0
52548- 0 0 0 0 0 0 0 0 0 0 0 0
52549- 0 0 0 0 0 0 0 0 0 0 0 0
52550- 0 0 0 0 0 0 0 0 0 0 0 0
52551- 0 0 0 0 0 0 0 0 0 0 0 0
52552- 0 0 0 0 0 0 0 0 0 0 0 0
52553- 0 0 0 0 0 0 0 0 0 0 0 0
52554- 0 0 0 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 6 6 6
52558- 22 22 22 62 62 62 62 62 62 2 2 6
52559- 2 2 6 2 2 6 2 2 6 2 2 6
52560- 2 2 6 2 2 6 2 2 6 2 2 6
52561- 2 2 6 2 2 6 2 2 6 26 26 26
52562- 54 54 54 38 38 38 18 18 18 10 10 10
52563- 2 2 6 2 2 6 34 34 34 82 82 82
52564- 38 38 38 14 14 14 0 0 0 0 0 0
52565- 0 0 0 0 0 0 0 0 0 0 0 0
52566- 0 0 0 0 0 0 0 0 0 0 0 0
52567- 0 0 0 0 0 0 0 0 0 0 0 0
52568- 0 0 0 0 0 0 0 0 0 0 0 0
52569- 0 0 0 0 0 0 0 0 0 0 0 0
52570- 0 0 0 0 0 0 0 0 0 0 0 0
52571- 0 0 0 0 0 0 0 0 0 0 0 0
52572- 0 0 0 0 0 1 0 0 1 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 6 6 6
52578- 30 30 30 78 78 78 30 30 30 2 2 6
52579- 2 2 6 2 2 6 2 2 6 2 2 6
52580- 2 2 6 2 2 6 2 2 6 2 2 6
52581- 2 2 6 2 2 6 2 2 6 10 10 10
52582- 10 10 10 2 2 6 2 2 6 2 2 6
52583- 2 2 6 2 2 6 2 2 6 78 78 78
52584- 50 50 50 18 18 18 6 6 6 0 0 0
52585- 0 0 0 0 0 0 0 0 0 0 0 0
52586- 0 0 0 0 0 0 0 0 0 0 0 0
52587- 0 0 0 0 0 0 0 0 0 0 0 0
52588- 0 0 0 0 0 0 0 0 0 0 0 0
52589- 0 0 0 0 0 0 0 0 0 0 0 0
52590- 0 0 0 0 0 0 0 0 0 0 0 0
52591- 0 0 0 0 0 0 0 0 0 0 0 0
52592- 0 0 1 0 0 0 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 10 10 10
52598- 38 38 38 86 86 86 14 14 14 2 2 6
52599- 2 2 6 2 2 6 2 2 6 2 2 6
52600- 2 2 6 2 2 6 2 2 6 2 2 6
52601- 2 2 6 2 2 6 2 2 6 2 2 6
52602- 2 2 6 2 2 6 2 2 6 2 2 6
52603- 2 2 6 2 2 6 2 2 6 54 54 54
52604- 66 66 66 26 26 26 6 6 6 0 0 0
52605- 0 0 0 0 0 0 0 0 0 0 0 0
52606- 0 0 0 0 0 0 0 0 0 0 0 0
52607- 0 0 0 0 0 0 0 0 0 0 0 0
52608- 0 0 0 0 0 0 0 0 0 0 0 0
52609- 0 0 0 0 0 0 0 0 0 0 0 0
52610- 0 0 0 0 0 0 0 0 0 0 0 0
52611- 0 0 0 0 0 0 0 0 0 0 0 0
52612- 0 0 0 0 0 1 0 0 1 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 14 14 14
52618- 42 42 42 82 82 82 2 2 6 2 2 6
52619- 2 2 6 6 6 6 10 10 10 2 2 6
52620- 2 2 6 2 2 6 2 2 6 2 2 6
52621- 2 2 6 2 2 6 2 2 6 6 6 6
52622- 14 14 14 10 10 10 2 2 6 2 2 6
52623- 2 2 6 2 2 6 2 2 6 18 18 18
52624- 82 82 82 34 34 34 10 10 10 0 0 0
52625- 0 0 0 0 0 0 0 0 0 0 0 0
52626- 0 0 0 0 0 0 0 0 0 0 0 0
52627- 0 0 0 0 0 0 0 0 0 0 0 0
52628- 0 0 0 0 0 0 0 0 0 0 0 0
52629- 0 0 0 0 0 0 0 0 0 0 0 0
52630- 0 0 0 0 0 0 0 0 0 0 0 0
52631- 0 0 0 0 0 0 0 0 0 0 0 0
52632- 0 0 1 0 0 0 0 0 0 0 0 0
52633- 0 0 0 0 0 0 0 0 0 0 0 0
52634- 0 0 0 0 0 0 0 0 0 0 0 0
52635- 0 0 0 0 0 0 0 0 0 0 0 0
52636- 0 0 0 0 0 0 0 0 0 0 0 0
52637- 0 0 0 0 0 0 0 0 0 14 14 14
52638- 46 46 46 86 86 86 2 2 6 2 2 6
52639- 6 6 6 6 6 6 22 22 22 34 34 34
52640- 6 6 6 2 2 6 2 2 6 2 2 6
52641- 2 2 6 2 2 6 18 18 18 34 34 34
52642- 10 10 10 50 50 50 22 22 22 2 2 6
52643- 2 2 6 2 2 6 2 2 6 10 10 10
52644- 86 86 86 42 42 42 14 14 14 0 0 0
52645- 0 0 0 0 0 0 0 0 0 0 0 0
52646- 0 0 0 0 0 0 0 0 0 0 0 0
52647- 0 0 0 0 0 0 0 0 0 0 0 0
52648- 0 0 0 0 0 0 0 0 0 0 0 0
52649- 0 0 0 0 0 0 0 0 0 0 0 0
52650- 0 0 0 0 0 0 0 0 0 0 0 0
52651- 0 0 0 0 0 0 0 0 0 0 0 0
52652- 0 0 1 0 0 1 0 0 1 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 14 14 14
52658- 46 46 46 86 86 86 2 2 6 2 2 6
52659- 38 38 38 116 116 116 94 94 94 22 22 22
52660- 22 22 22 2 2 6 2 2 6 2 2 6
52661- 14 14 14 86 86 86 138 138 138 162 162 162
52662-154 154 154 38 38 38 26 26 26 6 6 6
52663- 2 2 6 2 2 6 2 2 6 2 2 6
52664- 86 86 86 46 46 46 14 14 14 0 0 0
52665- 0 0 0 0 0 0 0 0 0 0 0 0
52666- 0 0 0 0 0 0 0 0 0 0 0 0
52667- 0 0 0 0 0 0 0 0 0 0 0 0
52668- 0 0 0 0 0 0 0 0 0 0 0 0
52669- 0 0 0 0 0 0 0 0 0 0 0 0
52670- 0 0 0 0 0 0 0 0 0 0 0 0
52671- 0 0 0 0 0 0 0 0 0 0 0 0
52672- 0 0 0 0 0 0 0 0 0 0 0 0
52673- 0 0 0 0 0 0 0 0 0 0 0 0
52674- 0 0 0 0 0 0 0 0 0 0 0 0
52675- 0 0 0 0 0 0 0 0 0 0 0 0
52676- 0 0 0 0 0 0 0 0 0 0 0 0
52677- 0 0 0 0 0 0 0 0 0 14 14 14
52678- 46 46 46 86 86 86 2 2 6 14 14 14
52679-134 134 134 198 198 198 195 195 195 116 116 116
52680- 10 10 10 2 2 6 2 2 6 6 6 6
52681-101 98 89 187 187 187 210 210 210 218 218 218
52682-214 214 214 134 134 134 14 14 14 6 6 6
52683- 2 2 6 2 2 6 2 2 6 2 2 6
52684- 86 86 86 50 50 50 18 18 18 6 6 6
52685- 0 0 0 0 0 0 0 0 0 0 0 0
52686- 0 0 0 0 0 0 0 0 0 0 0 0
52687- 0 0 0 0 0 0 0 0 0 0 0 0
52688- 0 0 0 0 0 0 0 0 0 0 0 0
52689- 0 0 0 0 0 0 0 0 0 0 0 0
52690- 0 0 0 0 0 0 0 0 0 0 0 0
52691- 0 0 0 0 0 0 0 0 1 0 0 0
52692- 0 0 1 0 0 1 0 0 1 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 14 14 14
52698- 46 46 46 86 86 86 2 2 6 54 54 54
52699-218 218 218 195 195 195 226 226 226 246 246 246
52700- 58 58 58 2 2 6 2 2 6 30 30 30
52701-210 210 210 253 253 253 174 174 174 123 123 123
52702-221 221 221 234 234 234 74 74 74 2 2 6
52703- 2 2 6 2 2 6 2 2 6 2 2 6
52704- 70 70 70 58 58 58 22 22 22 6 6 6
52705- 0 0 0 0 0 0 0 0 0 0 0 0
52706- 0 0 0 0 0 0 0 0 0 0 0 0
52707- 0 0 0 0 0 0 0 0 0 0 0 0
52708- 0 0 0 0 0 0 0 0 0 0 0 0
52709- 0 0 0 0 0 0 0 0 0 0 0 0
52710- 0 0 0 0 0 0 0 0 0 0 0 0
52711- 0 0 0 0 0 0 0 0 0 0 0 0
52712- 0 0 0 0 0 0 0 0 0 0 0 0
52713- 0 0 0 0 0 0 0 0 0 0 0 0
52714- 0 0 0 0 0 0 0 0 0 0 0 0
52715- 0 0 0 0 0 0 0 0 0 0 0 0
52716- 0 0 0 0 0 0 0 0 0 0 0 0
52717- 0 0 0 0 0 0 0 0 0 14 14 14
52718- 46 46 46 82 82 82 2 2 6 106 106 106
52719-170 170 170 26 26 26 86 86 86 226 226 226
52720-123 123 123 10 10 10 14 14 14 46 46 46
52721-231 231 231 190 190 190 6 6 6 70 70 70
52722- 90 90 90 238 238 238 158 158 158 2 2 6
52723- 2 2 6 2 2 6 2 2 6 2 2 6
52724- 70 70 70 58 58 58 22 22 22 6 6 6
52725- 0 0 0 0 0 0 0 0 0 0 0 0
52726- 0 0 0 0 0 0 0 0 0 0 0 0
52727- 0 0 0 0 0 0 0 0 0 0 0 0
52728- 0 0 0 0 0 0 0 0 0 0 0 0
52729- 0 0 0 0 0 0 0 0 0 0 0 0
52730- 0 0 0 0 0 0 0 0 0 0 0 0
52731- 0 0 0 0 0 0 0 0 1 0 0 0
52732- 0 0 1 0 0 1 0 0 1 0 0 0
52733- 0 0 0 0 0 0 0 0 0 0 0 0
52734- 0 0 0 0 0 0 0 0 0 0 0 0
52735- 0 0 0 0 0 0 0 0 0 0 0 0
52736- 0 0 0 0 0 0 0 0 0 0 0 0
52737- 0 0 0 0 0 0 0 0 0 14 14 14
52738- 42 42 42 86 86 86 6 6 6 116 116 116
52739-106 106 106 6 6 6 70 70 70 149 149 149
52740-128 128 128 18 18 18 38 38 38 54 54 54
52741-221 221 221 106 106 106 2 2 6 14 14 14
52742- 46 46 46 190 190 190 198 198 198 2 2 6
52743- 2 2 6 2 2 6 2 2 6 2 2 6
52744- 74 74 74 62 62 62 22 22 22 6 6 6
52745- 0 0 0 0 0 0 0 0 0 0 0 0
52746- 0 0 0 0 0 0 0 0 0 0 0 0
52747- 0 0 0 0 0 0 0 0 0 0 0 0
52748- 0 0 0 0 0 0 0 0 0 0 0 0
52749- 0 0 0 0 0 0 0 0 0 0 0 0
52750- 0 0 0 0 0 0 0 0 0 0 0 0
52751- 0 0 0 0 0 0 0 0 1 0 0 0
52752- 0 0 1 0 0 0 0 0 1 0 0 0
52753- 0 0 0 0 0 0 0 0 0 0 0 0
52754- 0 0 0 0 0 0 0 0 0 0 0 0
52755- 0 0 0 0 0 0 0 0 0 0 0 0
52756- 0 0 0 0 0 0 0 0 0 0 0 0
52757- 0 0 0 0 0 0 0 0 0 14 14 14
52758- 42 42 42 94 94 94 14 14 14 101 101 101
52759-128 128 128 2 2 6 18 18 18 116 116 116
52760-118 98 46 121 92 8 121 92 8 98 78 10
52761-162 162 162 106 106 106 2 2 6 2 2 6
52762- 2 2 6 195 195 195 195 195 195 6 6 6
52763- 2 2 6 2 2 6 2 2 6 2 2 6
52764- 74 74 74 62 62 62 22 22 22 6 6 6
52765- 0 0 0 0 0 0 0 0 0 0 0 0
52766- 0 0 0 0 0 0 0 0 0 0 0 0
52767- 0 0 0 0 0 0 0 0 0 0 0 0
52768- 0 0 0 0 0 0 0 0 0 0 0 0
52769- 0 0 0 0 0 0 0 0 0 0 0 0
52770- 0 0 0 0 0 0 0 0 0 0 0 0
52771- 0 0 0 0 0 0 0 0 1 0 0 1
52772- 0 0 1 0 0 0 0 0 1 0 0 0
52773- 0 0 0 0 0 0 0 0 0 0 0 0
52774- 0 0 0 0 0 0 0 0 0 0 0 0
52775- 0 0 0 0 0 0 0 0 0 0 0 0
52776- 0 0 0 0 0 0 0 0 0 0 0 0
52777- 0 0 0 0 0 0 0 0 0 10 10 10
52778- 38 38 38 90 90 90 14 14 14 58 58 58
52779-210 210 210 26 26 26 54 38 6 154 114 10
52780-226 170 11 236 186 11 225 175 15 184 144 12
52781-215 174 15 175 146 61 37 26 9 2 2 6
52782- 70 70 70 246 246 246 138 138 138 2 2 6
52783- 2 2 6 2 2 6 2 2 6 2 2 6
52784- 70 70 70 66 66 66 26 26 26 6 6 6
52785- 0 0 0 0 0 0 0 0 0 0 0 0
52786- 0 0 0 0 0 0 0 0 0 0 0 0
52787- 0 0 0 0 0 0 0 0 0 0 0 0
52788- 0 0 0 0 0 0 0 0 0 0 0 0
52789- 0 0 0 0 0 0 0 0 0 0 0 0
52790- 0 0 0 0 0 0 0 0 0 0 0 0
52791- 0 0 0 0 0 0 0 0 0 0 0 0
52792- 0 0 0 0 0 0 0 0 0 0 0 0
52793- 0 0 0 0 0 0 0 0 0 0 0 0
52794- 0 0 0 0 0 0 0 0 0 0 0 0
52795- 0 0 0 0 0 0 0 0 0 0 0 0
52796- 0 0 0 0 0 0 0 0 0 0 0 0
52797- 0 0 0 0 0 0 0 0 0 10 10 10
52798- 38 38 38 86 86 86 14 14 14 10 10 10
52799-195 195 195 188 164 115 192 133 9 225 175 15
52800-239 182 13 234 190 10 232 195 16 232 200 30
52801-245 207 45 241 208 19 232 195 16 184 144 12
52802-218 194 134 211 206 186 42 42 42 2 2 6
52803- 2 2 6 2 2 6 2 2 6 2 2 6
52804- 50 50 50 74 74 74 30 30 30 6 6 6
52805- 0 0 0 0 0 0 0 0 0 0 0 0
52806- 0 0 0 0 0 0 0 0 0 0 0 0
52807- 0 0 0 0 0 0 0 0 0 0 0 0
52808- 0 0 0 0 0 0 0 0 0 0 0 0
52809- 0 0 0 0 0 0 0 0 0 0 0 0
52810- 0 0 0 0 0 0 0 0 0 0 0 0
52811- 0 0 0 0 0 0 0 0 0 0 0 0
52812- 0 0 0 0 0 0 0 0 0 0 0 0
52813- 0 0 0 0 0 0 0 0 0 0 0 0
52814- 0 0 0 0 0 0 0 0 0 0 0 0
52815- 0 0 0 0 0 0 0 0 0 0 0 0
52816- 0 0 0 0 0 0 0 0 0 0 0 0
52817- 0 0 0 0 0 0 0 0 0 10 10 10
52818- 34 34 34 86 86 86 14 14 14 2 2 6
52819-121 87 25 192 133 9 219 162 10 239 182 13
52820-236 186 11 232 195 16 241 208 19 244 214 54
52821-246 218 60 246 218 38 246 215 20 241 208 19
52822-241 208 19 226 184 13 121 87 25 2 2 6
52823- 2 2 6 2 2 6 2 2 6 2 2 6
52824- 50 50 50 82 82 82 34 34 34 10 10 10
52825- 0 0 0 0 0 0 0 0 0 0 0 0
52826- 0 0 0 0 0 0 0 0 0 0 0 0
52827- 0 0 0 0 0 0 0 0 0 0 0 0
52828- 0 0 0 0 0 0 0 0 0 0 0 0
52829- 0 0 0 0 0 0 0 0 0 0 0 0
52830- 0 0 0 0 0 0 0 0 0 0 0 0
52831- 0 0 0 0 0 0 0 0 0 0 0 0
52832- 0 0 0 0 0 0 0 0 0 0 0 0
52833- 0 0 0 0 0 0 0 0 0 0 0 0
52834- 0 0 0 0 0 0 0 0 0 0 0 0
52835- 0 0 0 0 0 0 0 0 0 0 0 0
52836- 0 0 0 0 0 0 0 0 0 0 0 0
52837- 0 0 0 0 0 0 0 0 0 10 10 10
52838- 34 34 34 82 82 82 30 30 30 61 42 6
52839-180 123 7 206 145 10 230 174 11 239 182 13
52840-234 190 10 238 202 15 241 208 19 246 218 74
52841-246 218 38 246 215 20 246 215 20 246 215 20
52842-226 184 13 215 174 15 184 144 12 6 6 6
52843- 2 2 6 2 2 6 2 2 6 2 2 6
52844- 26 26 26 94 94 94 42 42 42 14 14 14
52845- 0 0 0 0 0 0 0 0 0 0 0 0
52846- 0 0 0 0 0 0 0 0 0 0 0 0
52847- 0 0 0 0 0 0 0 0 0 0 0 0
52848- 0 0 0 0 0 0 0 0 0 0 0 0
52849- 0 0 0 0 0 0 0 0 0 0 0 0
52850- 0 0 0 0 0 0 0 0 0 0 0 0
52851- 0 0 0 0 0 0 0 0 0 0 0 0
52852- 0 0 0 0 0 0 0 0 0 0 0 0
52853- 0 0 0 0 0 0 0 0 0 0 0 0
52854- 0 0 0 0 0 0 0 0 0 0 0 0
52855- 0 0 0 0 0 0 0 0 0 0 0 0
52856- 0 0 0 0 0 0 0 0 0 0 0 0
52857- 0 0 0 0 0 0 0 0 0 10 10 10
52858- 30 30 30 78 78 78 50 50 50 104 69 6
52859-192 133 9 216 158 10 236 178 12 236 186 11
52860-232 195 16 241 208 19 244 214 54 245 215 43
52861-246 215 20 246 215 20 241 208 19 198 155 10
52862-200 144 11 216 158 10 156 118 10 2 2 6
52863- 2 2 6 2 2 6 2 2 6 2 2 6
52864- 6 6 6 90 90 90 54 54 54 18 18 18
52865- 6 6 6 0 0 0 0 0 0 0 0 0
52866- 0 0 0 0 0 0 0 0 0 0 0 0
52867- 0 0 0 0 0 0 0 0 0 0 0 0
52868- 0 0 0 0 0 0 0 0 0 0 0 0
52869- 0 0 0 0 0 0 0 0 0 0 0 0
52870- 0 0 0 0 0 0 0 0 0 0 0 0
52871- 0 0 0 0 0 0 0 0 0 0 0 0
52872- 0 0 0 0 0 0 0 0 0 0 0 0
52873- 0 0 0 0 0 0 0 0 0 0 0 0
52874- 0 0 0 0 0 0 0 0 0 0 0 0
52875- 0 0 0 0 0 0 0 0 0 0 0 0
52876- 0 0 0 0 0 0 0 0 0 0 0 0
52877- 0 0 0 0 0 0 0 0 0 10 10 10
52878- 30 30 30 78 78 78 46 46 46 22 22 22
52879-137 92 6 210 162 10 239 182 13 238 190 10
52880-238 202 15 241 208 19 246 215 20 246 215 20
52881-241 208 19 203 166 17 185 133 11 210 150 10
52882-216 158 10 210 150 10 102 78 10 2 2 6
52883- 6 6 6 54 54 54 14 14 14 2 2 6
52884- 2 2 6 62 62 62 74 74 74 30 30 30
52885- 10 10 10 0 0 0 0 0 0 0 0 0
52886- 0 0 0 0 0 0 0 0 0 0 0 0
52887- 0 0 0 0 0 0 0 0 0 0 0 0
52888- 0 0 0 0 0 0 0 0 0 0 0 0
52889- 0 0 0 0 0 0 0 0 0 0 0 0
52890- 0 0 0 0 0 0 0 0 0 0 0 0
52891- 0 0 0 0 0 0 0 0 0 0 0 0
52892- 0 0 0 0 0 0 0 0 0 0 0 0
52893- 0 0 0 0 0 0 0 0 0 0 0 0
52894- 0 0 0 0 0 0 0 0 0 0 0 0
52895- 0 0 0 0 0 0 0 0 0 0 0 0
52896- 0 0 0 0 0 0 0 0 0 0 0 0
52897- 0 0 0 0 0 0 0 0 0 10 10 10
52898- 34 34 34 78 78 78 50 50 50 6 6 6
52899- 94 70 30 139 102 15 190 146 13 226 184 13
52900-232 200 30 232 195 16 215 174 15 190 146 13
52901-168 122 10 192 133 9 210 150 10 213 154 11
52902-202 150 34 182 157 106 101 98 89 2 2 6
52903- 2 2 6 78 78 78 116 116 116 58 58 58
52904- 2 2 6 22 22 22 90 90 90 46 46 46
52905- 18 18 18 6 6 6 0 0 0 0 0 0
52906- 0 0 0 0 0 0 0 0 0 0 0 0
52907- 0 0 0 0 0 0 0 0 0 0 0 0
52908- 0 0 0 0 0 0 0 0 0 0 0 0
52909- 0 0 0 0 0 0 0 0 0 0 0 0
52910- 0 0 0 0 0 0 0 0 0 0 0 0
52911- 0 0 0 0 0 0 0 0 0 0 0 0
52912- 0 0 0 0 0 0 0 0 0 0 0 0
52913- 0 0 0 0 0 0 0 0 0 0 0 0
52914- 0 0 0 0 0 0 0 0 0 0 0 0
52915- 0 0 0 0 0 0 0 0 0 0 0 0
52916- 0 0 0 0 0 0 0 0 0 0 0 0
52917- 0 0 0 0 0 0 0 0 0 10 10 10
52918- 38 38 38 86 86 86 50 50 50 6 6 6
52919-128 128 128 174 154 114 156 107 11 168 122 10
52920-198 155 10 184 144 12 197 138 11 200 144 11
52921-206 145 10 206 145 10 197 138 11 188 164 115
52922-195 195 195 198 198 198 174 174 174 14 14 14
52923- 2 2 6 22 22 22 116 116 116 116 116 116
52924- 22 22 22 2 2 6 74 74 74 70 70 70
52925- 30 30 30 10 10 10 0 0 0 0 0 0
52926- 0 0 0 0 0 0 0 0 0 0 0 0
52927- 0 0 0 0 0 0 0 0 0 0 0 0
52928- 0 0 0 0 0 0 0 0 0 0 0 0
52929- 0 0 0 0 0 0 0 0 0 0 0 0
52930- 0 0 0 0 0 0 0 0 0 0 0 0
52931- 0 0 0 0 0 0 0 0 0 0 0 0
52932- 0 0 0 0 0 0 0 0 0 0 0 0
52933- 0 0 0 0 0 0 0 0 0 0 0 0
52934- 0 0 0 0 0 0 0 0 0 0 0 0
52935- 0 0 0 0 0 0 0 0 0 0 0 0
52936- 0 0 0 0 0 0 0 0 0 0 0 0
52937- 0 0 0 0 0 0 6 6 6 18 18 18
52938- 50 50 50 101 101 101 26 26 26 10 10 10
52939-138 138 138 190 190 190 174 154 114 156 107 11
52940-197 138 11 200 144 11 197 138 11 192 133 9
52941-180 123 7 190 142 34 190 178 144 187 187 187
52942-202 202 202 221 221 221 214 214 214 66 66 66
52943- 2 2 6 2 2 6 50 50 50 62 62 62
52944- 6 6 6 2 2 6 10 10 10 90 90 90
52945- 50 50 50 18 18 18 6 6 6 0 0 0
52946- 0 0 0 0 0 0 0 0 0 0 0 0
52947- 0 0 0 0 0 0 0 0 0 0 0 0
52948- 0 0 0 0 0 0 0 0 0 0 0 0
52949- 0 0 0 0 0 0 0 0 0 0 0 0
52950- 0 0 0 0 0 0 0 0 0 0 0 0
52951- 0 0 0 0 0 0 0 0 0 0 0 0
52952- 0 0 0 0 0 0 0 0 0 0 0 0
52953- 0 0 0 0 0 0 0 0 0 0 0 0
52954- 0 0 0 0 0 0 0 0 0 0 0 0
52955- 0 0 0 0 0 0 0 0 0 0 0 0
52956- 0 0 0 0 0 0 0 0 0 0 0 0
52957- 0 0 0 0 0 0 10 10 10 34 34 34
52958- 74 74 74 74 74 74 2 2 6 6 6 6
52959-144 144 144 198 198 198 190 190 190 178 166 146
52960-154 121 60 156 107 11 156 107 11 168 124 44
52961-174 154 114 187 187 187 190 190 190 210 210 210
52962-246 246 246 253 253 253 253 253 253 182 182 182
52963- 6 6 6 2 2 6 2 2 6 2 2 6
52964- 2 2 6 2 2 6 2 2 6 62 62 62
52965- 74 74 74 34 34 34 14 14 14 0 0 0
52966- 0 0 0 0 0 0 0 0 0 0 0 0
52967- 0 0 0 0 0 0 0 0 0 0 0 0
52968- 0 0 0 0 0 0 0 0 0 0 0 0
52969- 0 0 0 0 0 0 0 0 0 0 0 0
52970- 0 0 0 0 0 0 0 0 0 0 0 0
52971- 0 0 0 0 0 0 0 0 0 0 0 0
52972- 0 0 0 0 0 0 0 0 0 0 0 0
52973- 0 0 0 0 0 0 0 0 0 0 0 0
52974- 0 0 0 0 0 0 0 0 0 0 0 0
52975- 0 0 0 0 0 0 0 0 0 0 0 0
52976- 0 0 0 0 0 0 0 0 0 0 0 0
52977- 0 0 0 10 10 10 22 22 22 54 54 54
52978- 94 94 94 18 18 18 2 2 6 46 46 46
52979-234 234 234 221 221 221 190 190 190 190 190 190
52980-190 190 190 187 187 187 187 187 187 190 190 190
52981-190 190 190 195 195 195 214 214 214 242 242 242
52982-253 253 253 253 253 253 253 253 253 253 253 253
52983- 82 82 82 2 2 6 2 2 6 2 2 6
52984- 2 2 6 2 2 6 2 2 6 14 14 14
52985- 86 86 86 54 54 54 22 22 22 6 6 6
52986- 0 0 0 0 0 0 0 0 0 0 0 0
52987- 0 0 0 0 0 0 0 0 0 0 0 0
52988- 0 0 0 0 0 0 0 0 0 0 0 0
52989- 0 0 0 0 0 0 0 0 0 0 0 0
52990- 0 0 0 0 0 0 0 0 0 0 0 0
52991- 0 0 0 0 0 0 0 0 0 0 0 0
52992- 0 0 0 0 0 0 0 0 0 0 0 0
52993- 0 0 0 0 0 0 0 0 0 0 0 0
52994- 0 0 0 0 0 0 0 0 0 0 0 0
52995- 0 0 0 0 0 0 0 0 0 0 0 0
52996- 0 0 0 0 0 0 0 0 0 0 0 0
52997- 6 6 6 18 18 18 46 46 46 90 90 90
52998- 46 46 46 18 18 18 6 6 6 182 182 182
52999-253 253 253 246 246 246 206 206 206 190 190 190
53000-190 190 190 190 190 190 190 190 190 190 190 190
53001-206 206 206 231 231 231 250 250 250 253 253 253
53002-253 253 253 253 253 253 253 253 253 253 253 253
53003-202 202 202 14 14 14 2 2 6 2 2 6
53004- 2 2 6 2 2 6 2 2 6 2 2 6
53005- 42 42 42 86 86 86 42 42 42 18 18 18
53006- 6 6 6 0 0 0 0 0 0 0 0 0
53007- 0 0 0 0 0 0 0 0 0 0 0 0
53008- 0 0 0 0 0 0 0 0 0 0 0 0
53009- 0 0 0 0 0 0 0 0 0 0 0 0
53010- 0 0 0 0 0 0 0 0 0 0 0 0
53011- 0 0 0 0 0 0 0 0 0 0 0 0
53012- 0 0 0 0 0 0 0 0 0 0 0 0
53013- 0 0 0 0 0 0 0 0 0 0 0 0
53014- 0 0 0 0 0 0 0 0 0 0 0 0
53015- 0 0 0 0 0 0 0 0 0 0 0 0
53016- 0 0 0 0 0 0 0 0 0 6 6 6
53017- 14 14 14 38 38 38 74 74 74 66 66 66
53018- 2 2 6 6 6 6 90 90 90 250 250 250
53019-253 253 253 253 253 253 238 238 238 198 198 198
53020-190 190 190 190 190 190 195 195 195 221 221 221
53021-246 246 246 253 253 253 253 253 253 253 253 253
53022-253 253 253 253 253 253 253 253 253 253 253 253
53023-253 253 253 82 82 82 2 2 6 2 2 6
53024- 2 2 6 2 2 6 2 2 6 2 2 6
53025- 2 2 6 78 78 78 70 70 70 34 34 34
53026- 14 14 14 6 6 6 0 0 0 0 0 0
53027- 0 0 0 0 0 0 0 0 0 0 0 0
53028- 0 0 0 0 0 0 0 0 0 0 0 0
53029- 0 0 0 0 0 0 0 0 0 0 0 0
53030- 0 0 0 0 0 0 0 0 0 0 0 0
53031- 0 0 0 0 0 0 0 0 0 0 0 0
53032- 0 0 0 0 0 0 0 0 0 0 0 0
53033- 0 0 0 0 0 0 0 0 0 0 0 0
53034- 0 0 0 0 0 0 0 0 0 0 0 0
53035- 0 0 0 0 0 0 0 0 0 0 0 0
53036- 0 0 0 0 0 0 0 0 0 14 14 14
53037- 34 34 34 66 66 66 78 78 78 6 6 6
53038- 2 2 6 18 18 18 218 218 218 253 253 253
53039-253 253 253 253 253 253 253 253 253 246 246 246
53040-226 226 226 231 231 231 246 246 246 253 253 253
53041-253 253 253 253 253 253 253 253 253 253 253 253
53042-253 253 253 253 253 253 253 253 253 253 253 253
53043-253 253 253 178 178 178 2 2 6 2 2 6
53044- 2 2 6 2 2 6 2 2 6 2 2 6
53045- 2 2 6 18 18 18 90 90 90 62 62 62
53046- 30 30 30 10 10 10 0 0 0 0 0 0
53047- 0 0 0 0 0 0 0 0 0 0 0 0
53048- 0 0 0 0 0 0 0 0 0 0 0 0
53049- 0 0 0 0 0 0 0 0 0 0 0 0
53050- 0 0 0 0 0 0 0 0 0 0 0 0
53051- 0 0 0 0 0 0 0 0 0 0 0 0
53052- 0 0 0 0 0 0 0 0 0 0 0 0
53053- 0 0 0 0 0 0 0 0 0 0 0 0
53054- 0 0 0 0 0 0 0 0 0 0 0 0
53055- 0 0 0 0 0 0 0 0 0 0 0 0
53056- 0 0 0 0 0 0 10 10 10 26 26 26
53057- 58 58 58 90 90 90 18 18 18 2 2 6
53058- 2 2 6 110 110 110 253 253 253 253 253 253
53059-253 253 253 253 253 253 253 253 253 253 253 253
53060-250 250 250 253 253 253 253 253 253 253 253 253
53061-253 253 253 253 253 253 253 253 253 253 253 253
53062-253 253 253 253 253 253 253 253 253 253 253 253
53063-253 253 253 231 231 231 18 18 18 2 2 6
53064- 2 2 6 2 2 6 2 2 6 2 2 6
53065- 2 2 6 2 2 6 18 18 18 94 94 94
53066- 54 54 54 26 26 26 10 10 10 0 0 0
53067- 0 0 0 0 0 0 0 0 0 0 0 0
53068- 0 0 0 0 0 0 0 0 0 0 0 0
53069- 0 0 0 0 0 0 0 0 0 0 0 0
53070- 0 0 0 0 0 0 0 0 0 0 0 0
53071- 0 0 0 0 0 0 0 0 0 0 0 0
53072- 0 0 0 0 0 0 0 0 0 0 0 0
53073- 0 0 0 0 0 0 0 0 0 0 0 0
53074- 0 0 0 0 0 0 0 0 0 0 0 0
53075- 0 0 0 0 0 0 0 0 0 0 0 0
53076- 0 0 0 6 6 6 22 22 22 50 50 50
53077- 90 90 90 26 26 26 2 2 6 2 2 6
53078- 14 14 14 195 195 195 250 250 250 253 253 253
53079-253 253 253 253 253 253 253 253 253 253 253 253
53080-253 253 253 253 253 253 253 253 253 253 253 253
53081-253 253 253 253 253 253 253 253 253 253 253 253
53082-253 253 253 253 253 253 253 253 253 253 253 253
53083-250 250 250 242 242 242 54 54 54 2 2 6
53084- 2 2 6 2 2 6 2 2 6 2 2 6
53085- 2 2 6 2 2 6 2 2 6 38 38 38
53086- 86 86 86 50 50 50 22 22 22 6 6 6
53087- 0 0 0 0 0 0 0 0 0 0 0 0
53088- 0 0 0 0 0 0 0 0 0 0 0 0
53089- 0 0 0 0 0 0 0 0 0 0 0 0
53090- 0 0 0 0 0 0 0 0 0 0 0 0
53091- 0 0 0 0 0 0 0 0 0 0 0 0
53092- 0 0 0 0 0 0 0 0 0 0 0 0
53093- 0 0 0 0 0 0 0 0 0 0 0 0
53094- 0 0 0 0 0 0 0 0 0 0 0 0
53095- 0 0 0 0 0 0 0 0 0 0 0 0
53096- 6 6 6 14 14 14 38 38 38 82 82 82
53097- 34 34 34 2 2 6 2 2 6 2 2 6
53098- 42 42 42 195 195 195 246 246 246 253 253 253
53099-253 253 253 253 253 253 253 253 253 250 250 250
53100-242 242 242 242 242 242 250 250 250 253 253 253
53101-253 253 253 253 253 253 253 253 253 253 253 253
53102-253 253 253 250 250 250 246 246 246 238 238 238
53103-226 226 226 231 231 231 101 101 101 6 6 6
53104- 2 2 6 2 2 6 2 2 6 2 2 6
53105- 2 2 6 2 2 6 2 2 6 2 2 6
53106- 38 38 38 82 82 82 42 42 42 14 14 14
53107- 6 6 6 0 0 0 0 0 0 0 0 0
53108- 0 0 0 0 0 0 0 0 0 0 0 0
53109- 0 0 0 0 0 0 0 0 0 0 0 0
53110- 0 0 0 0 0 0 0 0 0 0 0 0
53111- 0 0 0 0 0 0 0 0 0 0 0 0
53112- 0 0 0 0 0 0 0 0 0 0 0 0
53113- 0 0 0 0 0 0 0 0 0 0 0 0
53114- 0 0 0 0 0 0 0 0 0 0 0 0
53115- 0 0 0 0 0 0 0 0 0 0 0 0
53116- 10 10 10 26 26 26 62 62 62 66 66 66
53117- 2 2 6 2 2 6 2 2 6 6 6 6
53118- 70 70 70 170 170 170 206 206 206 234 234 234
53119-246 246 246 250 250 250 250 250 250 238 238 238
53120-226 226 226 231 231 231 238 238 238 250 250 250
53121-250 250 250 250 250 250 246 246 246 231 231 231
53122-214 214 214 206 206 206 202 202 202 202 202 202
53123-198 198 198 202 202 202 182 182 182 18 18 18
53124- 2 2 6 2 2 6 2 2 6 2 2 6
53125- 2 2 6 2 2 6 2 2 6 2 2 6
53126- 2 2 6 62 62 62 66 66 66 30 30 30
53127- 10 10 10 0 0 0 0 0 0 0 0 0
53128- 0 0 0 0 0 0 0 0 0 0 0 0
53129- 0 0 0 0 0 0 0 0 0 0 0 0
53130- 0 0 0 0 0 0 0 0 0 0 0 0
53131- 0 0 0 0 0 0 0 0 0 0 0 0
53132- 0 0 0 0 0 0 0 0 0 0 0 0
53133- 0 0 0 0 0 0 0 0 0 0 0 0
53134- 0 0 0 0 0 0 0 0 0 0 0 0
53135- 0 0 0 0 0 0 0 0 0 0 0 0
53136- 14 14 14 42 42 42 82 82 82 18 18 18
53137- 2 2 6 2 2 6 2 2 6 10 10 10
53138- 94 94 94 182 182 182 218 218 218 242 242 242
53139-250 250 250 253 253 253 253 253 253 250 250 250
53140-234 234 234 253 253 253 253 253 253 253 253 253
53141-253 253 253 253 253 253 253 253 253 246 246 246
53142-238 238 238 226 226 226 210 210 210 202 202 202
53143-195 195 195 195 195 195 210 210 210 158 158 158
53144- 6 6 6 14 14 14 50 50 50 14 14 14
53145- 2 2 6 2 2 6 2 2 6 2 2 6
53146- 2 2 6 6 6 6 86 86 86 46 46 46
53147- 18 18 18 6 6 6 0 0 0 0 0 0
53148- 0 0 0 0 0 0 0 0 0 0 0 0
53149- 0 0 0 0 0 0 0 0 0 0 0 0
53150- 0 0 0 0 0 0 0 0 0 0 0 0
53151- 0 0 0 0 0 0 0 0 0 0 0 0
53152- 0 0 0 0 0 0 0 0 0 0 0 0
53153- 0 0 0 0 0 0 0 0 0 0 0 0
53154- 0 0 0 0 0 0 0 0 0 0 0 0
53155- 0 0 0 0 0 0 0 0 0 6 6 6
53156- 22 22 22 54 54 54 70 70 70 2 2 6
53157- 2 2 6 10 10 10 2 2 6 22 22 22
53158-166 166 166 231 231 231 250 250 250 253 253 253
53159-253 253 253 253 253 253 253 253 253 250 250 250
53160-242 242 242 253 253 253 253 253 253 253 253 253
53161-253 253 253 253 253 253 253 253 253 253 253 253
53162-253 253 253 253 253 253 253 253 253 246 246 246
53163-231 231 231 206 206 206 198 198 198 226 226 226
53164- 94 94 94 2 2 6 6 6 6 38 38 38
53165- 30 30 30 2 2 6 2 2 6 2 2 6
53166- 2 2 6 2 2 6 62 62 62 66 66 66
53167- 26 26 26 10 10 10 0 0 0 0 0 0
53168- 0 0 0 0 0 0 0 0 0 0 0 0
53169- 0 0 0 0 0 0 0 0 0 0 0 0
53170- 0 0 0 0 0 0 0 0 0 0 0 0
53171- 0 0 0 0 0 0 0 0 0 0 0 0
53172- 0 0 0 0 0 0 0 0 0 0 0 0
53173- 0 0 0 0 0 0 0 0 0 0 0 0
53174- 0 0 0 0 0 0 0 0 0 0 0 0
53175- 0 0 0 0 0 0 0 0 0 10 10 10
53176- 30 30 30 74 74 74 50 50 50 2 2 6
53177- 26 26 26 26 26 26 2 2 6 106 106 106
53178-238 238 238 253 253 253 253 253 253 253 253 253
53179-253 253 253 253 253 253 253 253 253 253 253 253
53180-253 253 253 253 253 253 253 253 253 253 253 253
53181-253 253 253 253 253 253 253 253 253 253 253 253
53182-253 253 253 253 253 253 253 253 253 253 253 253
53183-253 253 253 246 246 246 218 218 218 202 202 202
53184-210 210 210 14 14 14 2 2 6 2 2 6
53185- 30 30 30 22 22 22 2 2 6 2 2 6
53186- 2 2 6 2 2 6 18 18 18 86 86 86
53187- 42 42 42 14 14 14 0 0 0 0 0 0
53188- 0 0 0 0 0 0 0 0 0 0 0 0
53189- 0 0 0 0 0 0 0 0 0 0 0 0
53190- 0 0 0 0 0 0 0 0 0 0 0 0
53191- 0 0 0 0 0 0 0 0 0 0 0 0
53192- 0 0 0 0 0 0 0 0 0 0 0 0
53193- 0 0 0 0 0 0 0 0 0 0 0 0
53194- 0 0 0 0 0 0 0 0 0 0 0 0
53195- 0 0 0 0 0 0 0 0 0 14 14 14
53196- 42 42 42 90 90 90 22 22 22 2 2 6
53197- 42 42 42 2 2 6 18 18 18 218 218 218
53198-253 253 253 253 253 253 253 253 253 253 253 253
53199-253 253 253 253 253 253 253 253 253 253 253 253
53200-253 253 253 253 253 253 253 253 253 253 253 253
53201-253 253 253 253 253 253 253 253 253 253 253 253
53202-253 253 253 253 253 253 253 253 253 253 253 253
53203-253 253 253 253 253 253 250 250 250 221 221 221
53204-218 218 218 101 101 101 2 2 6 14 14 14
53205- 18 18 18 38 38 38 10 10 10 2 2 6
53206- 2 2 6 2 2 6 2 2 6 78 78 78
53207- 58 58 58 22 22 22 6 6 6 0 0 0
53208- 0 0 0 0 0 0 0 0 0 0 0 0
53209- 0 0 0 0 0 0 0 0 0 0 0 0
53210- 0 0 0 0 0 0 0 0 0 0 0 0
53211- 0 0 0 0 0 0 0 0 0 0 0 0
53212- 0 0 0 0 0 0 0 0 0 0 0 0
53213- 0 0 0 0 0 0 0 0 0 0 0 0
53214- 0 0 0 0 0 0 0 0 0 0 0 0
53215- 0 0 0 0 0 0 6 6 6 18 18 18
53216- 54 54 54 82 82 82 2 2 6 26 26 26
53217- 22 22 22 2 2 6 123 123 123 253 253 253
53218-253 253 253 253 253 253 253 253 253 253 253 253
53219-253 253 253 253 253 253 253 253 253 253 253 253
53220-253 253 253 253 253 253 253 253 253 253 253 253
53221-253 253 253 253 253 253 253 253 253 253 253 253
53222-253 253 253 253 253 253 253 253 253 253 253 253
53223-253 253 253 253 253 253 253 253 253 250 250 250
53224-238 238 238 198 198 198 6 6 6 38 38 38
53225- 58 58 58 26 26 26 38 38 38 2 2 6
53226- 2 2 6 2 2 6 2 2 6 46 46 46
53227- 78 78 78 30 30 30 10 10 10 0 0 0
53228- 0 0 0 0 0 0 0 0 0 0 0 0
53229- 0 0 0 0 0 0 0 0 0 0 0 0
53230- 0 0 0 0 0 0 0 0 0 0 0 0
53231- 0 0 0 0 0 0 0 0 0 0 0 0
53232- 0 0 0 0 0 0 0 0 0 0 0 0
53233- 0 0 0 0 0 0 0 0 0 0 0 0
53234- 0 0 0 0 0 0 0 0 0 0 0 0
53235- 0 0 0 0 0 0 10 10 10 30 30 30
53236- 74 74 74 58 58 58 2 2 6 42 42 42
53237- 2 2 6 22 22 22 231 231 231 253 253 253
53238-253 253 253 253 253 253 253 253 253 253 253 253
53239-253 253 253 253 253 253 253 253 253 250 250 250
53240-253 253 253 253 253 253 253 253 253 253 253 253
53241-253 253 253 253 253 253 253 253 253 253 253 253
53242-253 253 253 253 253 253 253 253 253 253 253 253
53243-253 253 253 253 253 253 253 253 253 253 253 253
53244-253 253 253 246 246 246 46 46 46 38 38 38
53245- 42 42 42 14 14 14 38 38 38 14 14 14
53246- 2 2 6 2 2 6 2 2 6 6 6 6
53247- 86 86 86 46 46 46 14 14 14 0 0 0
53248- 0 0 0 0 0 0 0 0 0 0 0 0
53249- 0 0 0 0 0 0 0 0 0 0 0 0
53250- 0 0 0 0 0 0 0 0 0 0 0 0
53251- 0 0 0 0 0 0 0 0 0 0 0 0
53252- 0 0 0 0 0 0 0 0 0 0 0 0
53253- 0 0 0 0 0 0 0 0 0 0 0 0
53254- 0 0 0 0 0 0 0 0 0 0 0 0
53255- 0 0 0 6 6 6 14 14 14 42 42 42
53256- 90 90 90 18 18 18 18 18 18 26 26 26
53257- 2 2 6 116 116 116 253 253 253 253 253 253
53258-253 253 253 253 253 253 253 253 253 253 253 253
53259-253 253 253 253 253 253 250 250 250 238 238 238
53260-253 253 253 253 253 253 253 253 253 253 253 253
53261-253 253 253 253 253 253 253 253 253 253 253 253
53262-253 253 253 253 253 253 253 253 253 253 253 253
53263-253 253 253 253 253 253 253 253 253 253 253 253
53264-253 253 253 253 253 253 94 94 94 6 6 6
53265- 2 2 6 2 2 6 10 10 10 34 34 34
53266- 2 2 6 2 2 6 2 2 6 2 2 6
53267- 74 74 74 58 58 58 22 22 22 6 6 6
53268- 0 0 0 0 0 0 0 0 0 0 0 0
53269- 0 0 0 0 0 0 0 0 0 0 0 0
53270- 0 0 0 0 0 0 0 0 0 0 0 0
53271- 0 0 0 0 0 0 0 0 0 0 0 0
53272- 0 0 0 0 0 0 0 0 0 0 0 0
53273- 0 0 0 0 0 0 0 0 0 0 0 0
53274- 0 0 0 0 0 0 0 0 0 0 0 0
53275- 0 0 0 10 10 10 26 26 26 66 66 66
53276- 82 82 82 2 2 6 38 38 38 6 6 6
53277- 14 14 14 210 210 210 253 253 253 253 253 253
53278-253 253 253 253 253 253 253 253 253 253 253 253
53279-253 253 253 253 253 253 246 246 246 242 242 242
53280-253 253 253 253 253 253 253 253 253 253 253 253
53281-253 253 253 253 253 253 253 253 253 253 253 253
53282-253 253 253 253 253 253 253 253 253 253 253 253
53283-253 253 253 253 253 253 253 253 253 253 253 253
53284-253 253 253 253 253 253 144 144 144 2 2 6
53285- 2 2 6 2 2 6 2 2 6 46 46 46
53286- 2 2 6 2 2 6 2 2 6 2 2 6
53287- 42 42 42 74 74 74 30 30 30 10 10 10
53288- 0 0 0 0 0 0 0 0 0 0 0 0
53289- 0 0 0 0 0 0 0 0 0 0 0 0
53290- 0 0 0 0 0 0 0 0 0 0 0 0
53291- 0 0 0 0 0 0 0 0 0 0 0 0
53292- 0 0 0 0 0 0 0 0 0 0 0 0
53293- 0 0 0 0 0 0 0 0 0 0 0 0
53294- 0 0 0 0 0 0 0 0 0 0 0 0
53295- 6 6 6 14 14 14 42 42 42 90 90 90
53296- 26 26 26 6 6 6 42 42 42 2 2 6
53297- 74 74 74 250 250 250 253 253 253 253 253 253
53298-253 253 253 253 253 253 253 253 253 253 253 253
53299-253 253 253 253 253 253 242 242 242 242 242 242
53300-253 253 253 253 253 253 253 253 253 253 253 253
53301-253 253 253 253 253 253 253 253 253 253 253 253
53302-253 253 253 253 253 253 253 253 253 253 253 253
53303-253 253 253 253 253 253 253 253 253 253 253 253
53304-253 253 253 253 253 253 182 182 182 2 2 6
53305- 2 2 6 2 2 6 2 2 6 46 46 46
53306- 2 2 6 2 2 6 2 2 6 2 2 6
53307- 10 10 10 86 86 86 38 38 38 10 10 10
53308- 0 0 0 0 0 0 0 0 0 0 0 0
53309- 0 0 0 0 0 0 0 0 0 0 0 0
53310- 0 0 0 0 0 0 0 0 0 0 0 0
53311- 0 0 0 0 0 0 0 0 0 0 0 0
53312- 0 0 0 0 0 0 0 0 0 0 0 0
53313- 0 0 0 0 0 0 0 0 0 0 0 0
53314- 0 0 0 0 0 0 0 0 0 0 0 0
53315- 10 10 10 26 26 26 66 66 66 82 82 82
53316- 2 2 6 22 22 22 18 18 18 2 2 6
53317-149 149 149 253 253 253 253 253 253 253 253 253
53318-253 253 253 253 253 253 253 253 253 253 253 253
53319-253 253 253 253 253 253 234 234 234 242 242 242
53320-253 253 253 253 253 253 253 253 253 253 253 253
53321-253 253 253 253 253 253 253 253 253 253 253 253
53322-253 253 253 253 253 253 253 253 253 253 253 253
53323-253 253 253 253 253 253 253 253 253 253 253 253
53324-253 253 253 253 253 253 206 206 206 2 2 6
53325- 2 2 6 2 2 6 2 2 6 38 38 38
53326- 2 2 6 2 2 6 2 2 6 2 2 6
53327- 6 6 6 86 86 86 46 46 46 14 14 14
53328- 0 0 0 0 0 0 0 0 0 0 0 0
53329- 0 0 0 0 0 0 0 0 0 0 0 0
53330- 0 0 0 0 0 0 0 0 0 0 0 0
53331- 0 0 0 0 0 0 0 0 0 0 0 0
53332- 0 0 0 0 0 0 0 0 0 0 0 0
53333- 0 0 0 0 0 0 0 0 0 0 0 0
53334- 0 0 0 0 0 0 0 0 0 6 6 6
53335- 18 18 18 46 46 46 86 86 86 18 18 18
53336- 2 2 6 34 34 34 10 10 10 6 6 6
53337-210 210 210 253 253 253 253 253 253 253 253 253
53338-253 253 253 253 253 253 253 253 253 253 253 253
53339-253 253 253 253 253 253 234 234 234 242 242 242
53340-253 253 253 253 253 253 253 253 253 253 253 253
53341-253 253 253 253 253 253 253 253 253 253 253 253
53342-253 253 253 253 253 253 253 253 253 253 253 253
53343-253 253 253 253 253 253 253 253 253 253 253 253
53344-253 253 253 253 253 253 221 221 221 6 6 6
53345- 2 2 6 2 2 6 6 6 6 30 30 30
53346- 2 2 6 2 2 6 2 2 6 2 2 6
53347- 2 2 6 82 82 82 54 54 54 18 18 18
53348- 6 6 6 0 0 0 0 0 0 0 0 0
53349- 0 0 0 0 0 0 0 0 0 0 0 0
53350- 0 0 0 0 0 0 0 0 0 0 0 0
53351- 0 0 0 0 0 0 0 0 0 0 0 0
53352- 0 0 0 0 0 0 0 0 0 0 0 0
53353- 0 0 0 0 0 0 0 0 0 0 0 0
53354- 0 0 0 0 0 0 0 0 0 10 10 10
53355- 26 26 26 66 66 66 62 62 62 2 2 6
53356- 2 2 6 38 38 38 10 10 10 26 26 26
53357-238 238 238 253 253 253 253 253 253 253 253 253
53358-253 253 253 253 253 253 253 253 253 253 253 253
53359-253 253 253 253 253 253 231 231 231 238 238 238
53360-253 253 253 253 253 253 253 253 253 253 253 253
53361-253 253 253 253 253 253 253 253 253 253 253 253
53362-253 253 253 253 253 253 253 253 253 253 253 253
53363-253 253 253 253 253 253 253 253 253 253 253 253
53364-253 253 253 253 253 253 231 231 231 6 6 6
53365- 2 2 6 2 2 6 10 10 10 30 30 30
53366- 2 2 6 2 2 6 2 2 6 2 2 6
53367- 2 2 6 66 66 66 58 58 58 22 22 22
53368- 6 6 6 0 0 0 0 0 0 0 0 0
53369- 0 0 0 0 0 0 0 0 0 0 0 0
53370- 0 0 0 0 0 0 0 0 0 0 0 0
53371- 0 0 0 0 0 0 0 0 0 0 0 0
53372- 0 0 0 0 0 0 0 0 0 0 0 0
53373- 0 0 0 0 0 0 0 0 0 0 0 0
53374- 0 0 0 0 0 0 0 0 0 10 10 10
53375- 38 38 38 78 78 78 6 6 6 2 2 6
53376- 2 2 6 46 46 46 14 14 14 42 42 42
53377-246 246 246 253 253 253 253 253 253 253 253 253
53378-253 253 253 253 253 253 253 253 253 253 253 253
53379-253 253 253 253 253 253 231 231 231 242 242 242
53380-253 253 253 253 253 253 253 253 253 253 253 253
53381-253 253 253 253 253 253 253 253 253 253 253 253
53382-253 253 253 253 253 253 253 253 253 253 253 253
53383-253 253 253 253 253 253 253 253 253 253 253 253
53384-253 253 253 253 253 253 234 234 234 10 10 10
53385- 2 2 6 2 2 6 22 22 22 14 14 14
53386- 2 2 6 2 2 6 2 2 6 2 2 6
53387- 2 2 6 66 66 66 62 62 62 22 22 22
53388- 6 6 6 0 0 0 0 0 0 0 0 0
53389- 0 0 0 0 0 0 0 0 0 0 0 0
53390- 0 0 0 0 0 0 0 0 0 0 0 0
53391- 0 0 0 0 0 0 0 0 0 0 0 0
53392- 0 0 0 0 0 0 0 0 0 0 0 0
53393- 0 0 0 0 0 0 0 0 0 0 0 0
53394- 0 0 0 0 0 0 6 6 6 18 18 18
53395- 50 50 50 74 74 74 2 2 6 2 2 6
53396- 14 14 14 70 70 70 34 34 34 62 62 62
53397-250 250 250 253 253 253 253 253 253 253 253 253
53398-253 253 253 253 253 253 253 253 253 253 253 253
53399-253 253 253 253 253 253 231 231 231 246 246 246
53400-253 253 253 253 253 253 253 253 253 253 253 253
53401-253 253 253 253 253 253 253 253 253 253 253 253
53402-253 253 253 253 253 253 253 253 253 253 253 253
53403-253 253 253 253 253 253 253 253 253 253 253 253
53404-253 253 253 253 253 253 234 234 234 14 14 14
53405- 2 2 6 2 2 6 30 30 30 2 2 6
53406- 2 2 6 2 2 6 2 2 6 2 2 6
53407- 2 2 6 66 66 66 62 62 62 22 22 22
53408- 6 6 6 0 0 0 0 0 0 0 0 0
53409- 0 0 0 0 0 0 0 0 0 0 0 0
53410- 0 0 0 0 0 0 0 0 0 0 0 0
53411- 0 0 0 0 0 0 0 0 0 0 0 0
53412- 0 0 0 0 0 0 0 0 0 0 0 0
53413- 0 0 0 0 0 0 0 0 0 0 0 0
53414- 0 0 0 0 0 0 6 6 6 18 18 18
53415- 54 54 54 62 62 62 2 2 6 2 2 6
53416- 2 2 6 30 30 30 46 46 46 70 70 70
53417-250 250 250 253 253 253 253 253 253 253 253 253
53418-253 253 253 253 253 253 253 253 253 253 253 253
53419-253 253 253 253 253 253 231 231 231 246 246 246
53420-253 253 253 253 253 253 253 253 253 253 253 253
53421-253 253 253 253 253 253 253 253 253 253 253 253
53422-253 253 253 253 253 253 253 253 253 253 253 253
53423-253 253 253 253 253 253 253 253 253 253 253 253
53424-253 253 253 253 253 253 226 226 226 10 10 10
53425- 2 2 6 6 6 6 30 30 30 2 2 6
53426- 2 2 6 2 2 6 2 2 6 2 2 6
53427- 2 2 6 66 66 66 58 58 58 22 22 22
53428- 6 6 6 0 0 0 0 0 0 0 0 0
53429- 0 0 0 0 0 0 0 0 0 0 0 0
53430- 0 0 0 0 0 0 0 0 0 0 0 0
53431- 0 0 0 0 0 0 0 0 0 0 0 0
53432- 0 0 0 0 0 0 0 0 0 0 0 0
53433- 0 0 0 0 0 0 0 0 0 0 0 0
53434- 0 0 0 0 0 0 6 6 6 22 22 22
53435- 58 58 58 62 62 62 2 2 6 2 2 6
53436- 2 2 6 2 2 6 30 30 30 78 78 78
53437-250 250 250 253 253 253 253 253 253 253 253 253
53438-253 253 253 253 253 253 253 253 253 253 253 253
53439-253 253 253 253 253 253 231 231 231 246 246 246
53440-253 253 253 253 253 253 253 253 253 253 253 253
53441-253 253 253 253 253 253 253 253 253 253 253 253
53442-253 253 253 253 253 253 253 253 253 253 253 253
53443-253 253 253 253 253 253 253 253 253 253 253 253
53444-253 253 253 253 253 253 206 206 206 2 2 6
53445- 22 22 22 34 34 34 18 14 6 22 22 22
53446- 26 26 26 18 18 18 6 6 6 2 2 6
53447- 2 2 6 82 82 82 54 54 54 18 18 18
53448- 6 6 6 0 0 0 0 0 0 0 0 0
53449- 0 0 0 0 0 0 0 0 0 0 0 0
53450- 0 0 0 0 0 0 0 0 0 0 0 0
53451- 0 0 0 0 0 0 0 0 0 0 0 0
53452- 0 0 0 0 0 0 0 0 0 0 0 0
53453- 0 0 0 0 0 0 0 0 0 0 0 0
53454- 0 0 0 0 0 0 6 6 6 26 26 26
53455- 62 62 62 106 106 106 74 54 14 185 133 11
53456-210 162 10 121 92 8 6 6 6 62 62 62
53457-238 238 238 253 253 253 253 253 253 253 253 253
53458-253 253 253 253 253 253 253 253 253 253 253 253
53459-253 253 253 253 253 253 231 231 231 246 246 246
53460-253 253 253 253 253 253 253 253 253 253 253 253
53461-253 253 253 253 253 253 253 253 253 253 253 253
53462-253 253 253 253 253 253 253 253 253 253 253 253
53463-253 253 253 253 253 253 253 253 253 253 253 253
53464-253 253 253 253 253 253 158 158 158 18 18 18
53465- 14 14 14 2 2 6 2 2 6 2 2 6
53466- 6 6 6 18 18 18 66 66 66 38 38 38
53467- 6 6 6 94 94 94 50 50 50 18 18 18
53468- 6 6 6 0 0 0 0 0 0 0 0 0
53469- 0 0 0 0 0 0 0 0 0 0 0 0
53470- 0 0 0 0 0 0 0 0 0 0 0 0
53471- 0 0 0 0 0 0 0 0 0 0 0 0
53472- 0 0 0 0 0 0 0 0 0 0 0 0
53473- 0 0 0 0 0 0 0 0 0 6 6 6
53474- 10 10 10 10 10 10 18 18 18 38 38 38
53475- 78 78 78 142 134 106 216 158 10 242 186 14
53476-246 190 14 246 190 14 156 118 10 10 10 10
53477- 90 90 90 238 238 238 253 253 253 253 253 253
53478-253 253 253 253 253 253 253 253 253 253 253 253
53479-253 253 253 253 253 253 231 231 231 250 250 250
53480-253 253 253 253 253 253 253 253 253 253 253 253
53481-253 253 253 253 253 253 253 253 253 253 253 253
53482-253 253 253 253 253 253 253 253 253 253 253 253
53483-253 253 253 253 253 253 253 253 253 246 230 190
53484-238 204 91 238 204 91 181 142 44 37 26 9
53485- 2 2 6 2 2 6 2 2 6 2 2 6
53486- 2 2 6 2 2 6 38 38 38 46 46 46
53487- 26 26 26 106 106 106 54 54 54 18 18 18
53488- 6 6 6 0 0 0 0 0 0 0 0 0
53489- 0 0 0 0 0 0 0 0 0 0 0 0
53490- 0 0 0 0 0 0 0 0 0 0 0 0
53491- 0 0 0 0 0 0 0 0 0 0 0 0
53492- 0 0 0 0 0 0 0 0 0 0 0 0
53493- 0 0 0 6 6 6 14 14 14 22 22 22
53494- 30 30 30 38 38 38 50 50 50 70 70 70
53495-106 106 106 190 142 34 226 170 11 242 186 14
53496-246 190 14 246 190 14 246 190 14 154 114 10
53497- 6 6 6 74 74 74 226 226 226 253 253 253
53498-253 253 253 253 253 253 253 253 253 253 253 253
53499-253 253 253 253 253 253 231 231 231 250 250 250
53500-253 253 253 253 253 253 253 253 253 253 253 253
53501-253 253 253 253 253 253 253 253 253 253 253 253
53502-253 253 253 253 253 253 253 253 253 253 253 253
53503-253 253 253 253 253 253 253 253 253 228 184 62
53504-241 196 14 241 208 19 232 195 16 38 30 10
53505- 2 2 6 2 2 6 2 2 6 2 2 6
53506- 2 2 6 6 6 6 30 30 30 26 26 26
53507-203 166 17 154 142 90 66 66 66 26 26 26
53508- 6 6 6 0 0 0 0 0 0 0 0 0
53509- 0 0 0 0 0 0 0 0 0 0 0 0
53510- 0 0 0 0 0 0 0 0 0 0 0 0
53511- 0 0 0 0 0 0 0 0 0 0 0 0
53512- 0 0 0 0 0 0 0 0 0 0 0 0
53513- 6 6 6 18 18 18 38 38 38 58 58 58
53514- 78 78 78 86 86 86 101 101 101 123 123 123
53515-175 146 61 210 150 10 234 174 13 246 186 14
53516-246 190 14 246 190 14 246 190 14 238 190 10
53517-102 78 10 2 2 6 46 46 46 198 198 198
53518-253 253 253 253 253 253 253 253 253 253 253 253
53519-253 253 253 253 253 253 234 234 234 242 242 242
53520-253 253 253 253 253 253 253 253 253 253 253 253
53521-253 253 253 253 253 253 253 253 253 253 253 253
53522-253 253 253 253 253 253 253 253 253 253 253 253
53523-253 253 253 253 253 253 253 253 253 224 178 62
53524-242 186 14 241 196 14 210 166 10 22 18 6
53525- 2 2 6 2 2 6 2 2 6 2 2 6
53526- 2 2 6 2 2 6 6 6 6 121 92 8
53527-238 202 15 232 195 16 82 82 82 34 34 34
53528- 10 10 10 0 0 0 0 0 0 0 0 0
53529- 0 0 0 0 0 0 0 0 0 0 0 0
53530- 0 0 0 0 0 0 0 0 0 0 0 0
53531- 0 0 0 0 0 0 0 0 0 0 0 0
53532- 0 0 0 0 0 0 0 0 0 0 0 0
53533- 14 14 14 38 38 38 70 70 70 154 122 46
53534-190 142 34 200 144 11 197 138 11 197 138 11
53535-213 154 11 226 170 11 242 186 14 246 190 14
53536-246 190 14 246 190 14 246 190 14 246 190 14
53537-225 175 15 46 32 6 2 2 6 22 22 22
53538-158 158 158 250 250 250 253 253 253 253 253 253
53539-253 253 253 253 253 253 253 253 253 253 253 253
53540-253 253 253 253 253 253 253 253 253 253 253 253
53541-253 253 253 253 253 253 253 253 253 253 253 253
53542-253 253 253 253 253 253 253 253 253 253 253 253
53543-253 253 253 250 250 250 242 242 242 224 178 62
53544-239 182 13 236 186 11 213 154 11 46 32 6
53545- 2 2 6 2 2 6 2 2 6 2 2 6
53546- 2 2 6 2 2 6 61 42 6 225 175 15
53547-238 190 10 236 186 11 112 100 78 42 42 42
53548- 14 14 14 0 0 0 0 0 0 0 0 0
53549- 0 0 0 0 0 0 0 0 0 0 0 0
53550- 0 0 0 0 0 0 0 0 0 0 0 0
53551- 0 0 0 0 0 0 0 0 0 0 0 0
53552- 0 0 0 0 0 0 0 0 0 6 6 6
53553- 22 22 22 54 54 54 154 122 46 213 154 11
53554-226 170 11 230 174 11 226 170 11 226 170 11
53555-236 178 12 242 186 14 246 190 14 246 190 14
53556-246 190 14 246 190 14 246 190 14 246 190 14
53557-241 196 14 184 144 12 10 10 10 2 2 6
53558- 6 6 6 116 116 116 242 242 242 253 253 253
53559-253 253 253 253 253 253 253 253 253 253 253 253
53560-253 253 253 253 253 253 253 253 253 253 253 253
53561-253 253 253 253 253 253 253 253 253 253 253 253
53562-253 253 253 253 253 253 253 253 253 253 253 253
53563-253 253 253 231 231 231 198 198 198 214 170 54
53564-236 178 12 236 178 12 210 150 10 137 92 6
53565- 18 14 6 2 2 6 2 2 6 2 2 6
53566- 6 6 6 70 47 6 200 144 11 236 178 12
53567-239 182 13 239 182 13 124 112 88 58 58 58
53568- 22 22 22 6 6 6 0 0 0 0 0 0
53569- 0 0 0 0 0 0 0 0 0 0 0 0
53570- 0 0 0 0 0 0 0 0 0 0 0 0
53571- 0 0 0 0 0 0 0 0 0 0 0 0
53572- 0 0 0 0 0 0 0 0 0 10 10 10
53573- 30 30 30 70 70 70 180 133 36 226 170 11
53574-239 182 13 242 186 14 242 186 14 246 186 14
53575-246 190 14 246 190 14 246 190 14 246 190 14
53576-246 190 14 246 190 14 246 190 14 246 190 14
53577-246 190 14 232 195 16 98 70 6 2 2 6
53578- 2 2 6 2 2 6 66 66 66 221 221 221
53579-253 253 253 253 253 253 253 253 253 253 253 253
53580-253 253 253 253 253 253 253 253 253 253 253 253
53581-253 253 253 253 253 253 253 253 253 253 253 253
53582-253 253 253 253 253 253 253 253 253 253 253 253
53583-253 253 253 206 206 206 198 198 198 214 166 58
53584-230 174 11 230 174 11 216 158 10 192 133 9
53585-163 110 8 116 81 8 102 78 10 116 81 8
53586-167 114 7 197 138 11 226 170 11 239 182 13
53587-242 186 14 242 186 14 162 146 94 78 78 78
53588- 34 34 34 14 14 14 6 6 6 0 0 0
53589- 0 0 0 0 0 0 0 0 0 0 0 0
53590- 0 0 0 0 0 0 0 0 0 0 0 0
53591- 0 0 0 0 0 0 0 0 0 0 0 0
53592- 0 0 0 0 0 0 0 0 0 6 6 6
53593- 30 30 30 78 78 78 190 142 34 226 170 11
53594-239 182 13 246 190 14 246 190 14 246 190 14
53595-246 190 14 246 190 14 246 190 14 246 190 14
53596-246 190 14 246 190 14 246 190 14 246 190 14
53597-246 190 14 241 196 14 203 166 17 22 18 6
53598- 2 2 6 2 2 6 2 2 6 38 38 38
53599-218 218 218 253 253 253 253 253 253 253 253 253
53600-253 253 253 253 253 253 253 253 253 253 253 253
53601-253 253 253 253 253 253 253 253 253 253 253 253
53602-253 253 253 253 253 253 253 253 253 253 253 253
53603-250 250 250 206 206 206 198 198 198 202 162 69
53604-226 170 11 236 178 12 224 166 10 210 150 10
53605-200 144 11 197 138 11 192 133 9 197 138 11
53606-210 150 10 226 170 11 242 186 14 246 190 14
53607-246 190 14 246 186 14 225 175 15 124 112 88
53608- 62 62 62 30 30 30 14 14 14 6 6 6
53609- 0 0 0 0 0 0 0 0 0 0 0 0
53610- 0 0 0 0 0 0 0 0 0 0 0 0
53611- 0 0 0 0 0 0 0 0 0 0 0 0
53612- 0 0 0 0 0 0 0 0 0 10 10 10
53613- 30 30 30 78 78 78 174 135 50 224 166 10
53614-239 182 13 246 190 14 246 190 14 246 190 14
53615-246 190 14 246 190 14 246 190 14 246 190 14
53616-246 190 14 246 190 14 246 190 14 246 190 14
53617-246 190 14 246 190 14 241 196 14 139 102 15
53618- 2 2 6 2 2 6 2 2 6 2 2 6
53619- 78 78 78 250 250 250 253 253 253 253 253 253
53620-253 253 253 253 253 253 253 253 253 253 253 253
53621-253 253 253 253 253 253 253 253 253 253 253 253
53622-253 253 253 253 253 253 253 253 253 253 253 253
53623-250 250 250 214 214 214 198 198 198 190 150 46
53624-219 162 10 236 178 12 234 174 13 224 166 10
53625-216 158 10 213 154 11 213 154 11 216 158 10
53626-226 170 11 239 182 13 246 190 14 246 190 14
53627-246 190 14 246 190 14 242 186 14 206 162 42
53628-101 101 101 58 58 58 30 30 30 14 14 14
53629- 6 6 6 0 0 0 0 0 0 0 0 0
53630- 0 0 0 0 0 0 0 0 0 0 0 0
53631- 0 0 0 0 0 0 0 0 0 0 0 0
53632- 0 0 0 0 0 0 0 0 0 10 10 10
53633- 30 30 30 74 74 74 174 135 50 216 158 10
53634-236 178 12 246 190 14 246 190 14 246 190 14
53635-246 190 14 246 190 14 246 190 14 246 190 14
53636-246 190 14 246 190 14 246 190 14 246 190 14
53637-246 190 14 246 190 14 241 196 14 226 184 13
53638- 61 42 6 2 2 6 2 2 6 2 2 6
53639- 22 22 22 238 238 238 253 253 253 253 253 253
53640-253 253 253 253 253 253 253 253 253 253 253 253
53641-253 253 253 253 253 253 253 253 253 253 253 253
53642-253 253 253 253 253 253 253 253 253 253 253 253
53643-253 253 253 226 226 226 187 187 187 180 133 36
53644-216 158 10 236 178 12 239 182 13 236 178 12
53645-230 174 11 226 170 11 226 170 11 230 174 11
53646-236 178 12 242 186 14 246 190 14 246 190 14
53647-246 190 14 246 190 14 246 186 14 239 182 13
53648-206 162 42 106 106 106 66 66 66 34 34 34
53649- 14 14 14 6 6 6 0 0 0 0 0 0
53650- 0 0 0 0 0 0 0 0 0 0 0 0
53651- 0 0 0 0 0 0 0 0 0 0 0 0
53652- 0 0 0 0 0 0 0 0 0 6 6 6
53653- 26 26 26 70 70 70 163 133 67 213 154 11
53654-236 178 12 246 190 14 246 190 14 246 190 14
53655-246 190 14 246 190 14 246 190 14 246 190 14
53656-246 190 14 246 190 14 246 190 14 246 190 14
53657-246 190 14 246 190 14 246 190 14 241 196 14
53658-190 146 13 18 14 6 2 2 6 2 2 6
53659- 46 46 46 246 246 246 253 253 253 253 253 253
53660-253 253 253 253 253 253 253 253 253 253 253 253
53661-253 253 253 253 253 253 253 253 253 253 253 253
53662-253 253 253 253 253 253 253 253 253 253 253 253
53663-253 253 253 221 221 221 86 86 86 156 107 11
53664-216 158 10 236 178 12 242 186 14 246 186 14
53665-242 186 14 239 182 13 239 182 13 242 186 14
53666-242 186 14 246 186 14 246 190 14 246 190 14
53667-246 190 14 246 190 14 246 190 14 246 190 14
53668-242 186 14 225 175 15 142 122 72 66 66 66
53669- 30 30 30 10 10 10 0 0 0 0 0 0
53670- 0 0 0 0 0 0 0 0 0 0 0 0
53671- 0 0 0 0 0 0 0 0 0 0 0 0
53672- 0 0 0 0 0 0 0 0 0 6 6 6
53673- 26 26 26 70 70 70 163 133 67 210 150 10
53674-236 178 12 246 190 14 246 190 14 246 190 14
53675-246 190 14 246 190 14 246 190 14 246 190 14
53676-246 190 14 246 190 14 246 190 14 246 190 14
53677-246 190 14 246 190 14 246 190 14 246 190 14
53678-232 195 16 121 92 8 34 34 34 106 106 106
53679-221 221 221 253 253 253 253 253 253 253 253 253
53680-253 253 253 253 253 253 253 253 253 253 253 253
53681-253 253 253 253 253 253 253 253 253 253 253 253
53682-253 253 253 253 253 253 253 253 253 253 253 253
53683-242 242 242 82 82 82 18 14 6 163 110 8
53684-216 158 10 236 178 12 242 186 14 246 190 14
53685-246 190 14 246 190 14 246 190 14 246 190 14
53686-246 190 14 246 190 14 246 190 14 246 190 14
53687-246 190 14 246 190 14 246 190 14 246 190 14
53688-246 190 14 246 190 14 242 186 14 163 133 67
53689- 46 46 46 18 18 18 6 6 6 0 0 0
53690- 0 0 0 0 0 0 0 0 0 0 0 0
53691- 0 0 0 0 0 0 0 0 0 0 0 0
53692- 0 0 0 0 0 0 0 0 0 10 10 10
53693- 30 30 30 78 78 78 163 133 67 210 150 10
53694-236 178 12 246 186 14 246 190 14 246 190 14
53695-246 190 14 246 190 14 246 190 14 246 190 14
53696-246 190 14 246 190 14 246 190 14 246 190 14
53697-246 190 14 246 190 14 246 190 14 246 190 14
53698-241 196 14 215 174 15 190 178 144 253 253 253
53699-253 253 253 253 253 253 253 253 253 253 253 253
53700-253 253 253 253 253 253 253 253 253 253 253 253
53701-253 253 253 253 253 253 253 253 253 253 253 253
53702-253 253 253 253 253 253 253 253 253 218 218 218
53703- 58 58 58 2 2 6 22 18 6 167 114 7
53704-216 158 10 236 178 12 246 186 14 246 190 14
53705-246 190 14 246 190 14 246 190 14 246 190 14
53706-246 190 14 246 190 14 246 190 14 246 190 14
53707-246 190 14 246 190 14 246 190 14 246 190 14
53708-246 190 14 246 186 14 242 186 14 190 150 46
53709- 54 54 54 22 22 22 6 6 6 0 0 0
53710- 0 0 0 0 0 0 0 0 0 0 0 0
53711- 0 0 0 0 0 0 0 0 0 0 0 0
53712- 0 0 0 0 0 0 0 0 0 14 14 14
53713- 38 38 38 86 86 86 180 133 36 213 154 11
53714-236 178 12 246 186 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 246 190 14 246 190 14
53717-246 190 14 246 190 14 246 190 14 246 190 14
53718-246 190 14 232 195 16 190 146 13 214 214 214
53719-253 253 253 253 253 253 253 253 253 253 253 253
53720-253 253 253 253 253 253 253 253 253 253 253 253
53721-253 253 253 253 253 253 253 253 253 253 253 253
53722-253 253 253 250 250 250 170 170 170 26 26 26
53723- 2 2 6 2 2 6 37 26 9 163 110 8
53724-219 162 10 239 182 13 246 186 14 246 190 14
53725-246 190 14 246 190 14 246 190 14 246 190 14
53726-246 190 14 246 190 14 246 190 14 246 190 14
53727-246 190 14 246 190 14 246 190 14 246 190 14
53728-246 186 14 236 178 12 224 166 10 142 122 72
53729- 46 46 46 18 18 18 6 6 6 0 0 0
53730- 0 0 0 0 0 0 0 0 0 0 0 0
53731- 0 0 0 0 0 0 0 0 0 0 0 0
53732- 0 0 0 0 0 0 6 6 6 18 18 18
53733- 50 50 50 109 106 95 192 133 9 224 166 10
53734-242 186 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 190 14 246 190 14 246 190 14
53737-246 190 14 246 190 14 246 190 14 246 190 14
53738-242 186 14 226 184 13 210 162 10 142 110 46
53739-226 226 226 253 253 253 253 253 253 253 253 253
53740-253 253 253 253 253 253 253 253 253 253 253 253
53741-253 253 253 253 253 253 253 253 253 253 253 253
53742-198 198 198 66 66 66 2 2 6 2 2 6
53743- 2 2 6 2 2 6 50 34 6 156 107 11
53744-219 162 10 239 182 13 246 186 14 246 190 14
53745-246 190 14 246 190 14 246 190 14 246 190 14
53746-246 190 14 246 190 14 246 190 14 246 190 14
53747-246 190 14 246 190 14 246 190 14 242 186 14
53748-234 174 13 213 154 11 154 122 46 66 66 66
53749- 30 30 30 10 10 10 0 0 0 0 0 0
53750- 0 0 0 0 0 0 0 0 0 0 0 0
53751- 0 0 0 0 0 0 0 0 0 0 0 0
53752- 0 0 0 0 0 0 6 6 6 22 22 22
53753- 58 58 58 154 121 60 206 145 10 234 174 13
53754-242 186 14 246 186 14 246 190 14 246 190 14
53755-246 190 14 246 190 14 246 190 14 246 190 14
53756-246 190 14 246 190 14 246 190 14 246 190 14
53757-246 190 14 246 190 14 246 190 14 246 190 14
53758-246 186 14 236 178 12 210 162 10 163 110 8
53759- 61 42 6 138 138 138 218 218 218 250 250 250
53760-253 253 253 253 253 253 253 253 253 250 250 250
53761-242 242 242 210 210 210 144 144 144 66 66 66
53762- 6 6 6 2 2 6 2 2 6 2 2 6
53763- 2 2 6 2 2 6 61 42 6 163 110 8
53764-216 158 10 236 178 12 246 190 14 246 190 14
53765-246 190 14 246 190 14 246 190 14 246 190 14
53766-246 190 14 246 190 14 246 190 14 246 190 14
53767-246 190 14 239 182 13 230 174 11 216 158 10
53768-190 142 34 124 112 88 70 70 70 38 38 38
53769- 18 18 18 6 6 6 0 0 0 0 0 0
53770- 0 0 0 0 0 0 0 0 0 0 0 0
53771- 0 0 0 0 0 0 0 0 0 0 0 0
53772- 0 0 0 0 0 0 6 6 6 22 22 22
53773- 62 62 62 168 124 44 206 145 10 224 166 10
53774-236 178 12 239 182 13 242 186 14 242 186 14
53775-246 186 14 246 190 14 246 190 14 246 190 14
53776-246 190 14 246 190 14 246 190 14 246 190 14
53777-246 190 14 246 190 14 246 190 14 246 190 14
53778-246 190 14 236 178 12 216 158 10 175 118 6
53779- 80 54 7 2 2 6 6 6 6 30 30 30
53780- 54 54 54 62 62 62 50 50 50 38 38 38
53781- 14 14 14 2 2 6 2 2 6 2 2 6
53782- 2 2 6 2 2 6 2 2 6 2 2 6
53783- 2 2 6 6 6 6 80 54 7 167 114 7
53784-213 154 11 236 178 12 246 190 14 246 190 14
53785-246 190 14 246 190 14 246 190 14 246 190 14
53786-246 190 14 242 186 14 239 182 13 239 182 13
53787-230 174 11 210 150 10 174 135 50 124 112 88
53788- 82 82 82 54 54 54 34 34 34 18 18 18
53789- 6 6 6 0 0 0 0 0 0 0 0 0
53790- 0 0 0 0 0 0 0 0 0 0 0 0
53791- 0 0 0 0 0 0 0 0 0 0 0 0
53792- 0 0 0 0 0 0 6 6 6 18 18 18
53793- 50 50 50 158 118 36 192 133 9 200 144 11
53794-216 158 10 219 162 10 224 166 10 226 170 11
53795-230 174 11 236 178 12 239 182 13 239 182 13
53796-242 186 14 246 186 14 246 190 14 246 190 14
53797-246 190 14 246 190 14 246 190 14 246 190 14
53798-246 186 14 230 174 11 210 150 10 163 110 8
53799-104 69 6 10 10 10 2 2 6 2 2 6
53800- 2 2 6 2 2 6 2 2 6 2 2 6
53801- 2 2 6 2 2 6 2 2 6 2 2 6
53802- 2 2 6 2 2 6 2 2 6 2 2 6
53803- 2 2 6 6 6 6 91 60 6 167 114 7
53804-206 145 10 230 174 11 242 186 14 246 190 14
53805-246 190 14 246 190 14 246 186 14 242 186 14
53806-239 182 13 230 174 11 224 166 10 213 154 11
53807-180 133 36 124 112 88 86 86 86 58 58 58
53808- 38 38 38 22 22 22 10 10 10 6 6 6
53809- 0 0 0 0 0 0 0 0 0 0 0 0
53810- 0 0 0 0 0 0 0 0 0 0 0 0
53811- 0 0 0 0 0 0 0 0 0 0 0 0
53812- 0 0 0 0 0 0 0 0 0 14 14 14
53813- 34 34 34 70 70 70 138 110 50 158 118 36
53814-167 114 7 180 123 7 192 133 9 197 138 11
53815-200 144 11 206 145 10 213 154 11 219 162 10
53816-224 166 10 230 174 11 239 182 13 242 186 14
53817-246 186 14 246 186 14 246 186 14 246 186 14
53818-239 182 13 216 158 10 185 133 11 152 99 6
53819-104 69 6 18 14 6 2 2 6 2 2 6
53820- 2 2 6 2 2 6 2 2 6 2 2 6
53821- 2 2 6 2 2 6 2 2 6 2 2 6
53822- 2 2 6 2 2 6 2 2 6 2 2 6
53823- 2 2 6 6 6 6 80 54 7 152 99 6
53824-192 133 9 219 162 10 236 178 12 239 182 13
53825-246 186 14 242 186 14 239 182 13 236 178 12
53826-224 166 10 206 145 10 192 133 9 154 121 60
53827- 94 94 94 62 62 62 42 42 42 22 22 22
53828- 14 14 14 6 6 6 0 0 0 0 0 0
53829- 0 0 0 0 0 0 0 0 0 0 0 0
53830- 0 0 0 0 0 0 0 0 0 0 0 0
53831- 0 0 0 0 0 0 0 0 0 0 0 0
53832- 0 0 0 0 0 0 0 0 0 6 6 6
53833- 18 18 18 34 34 34 58 58 58 78 78 78
53834-101 98 89 124 112 88 142 110 46 156 107 11
53835-163 110 8 167 114 7 175 118 6 180 123 7
53836-185 133 11 197 138 11 210 150 10 219 162 10
53837-226 170 11 236 178 12 236 178 12 234 174 13
53838-219 162 10 197 138 11 163 110 8 130 83 6
53839- 91 60 6 10 10 10 2 2 6 2 2 6
53840- 18 18 18 38 38 38 38 38 38 38 38 38
53841- 38 38 38 38 38 38 38 38 38 38 38 38
53842- 38 38 38 38 38 38 26 26 26 2 2 6
53843- 2 2 6 6 6 6 70 47 6 137 92 6
53844-175 118 6 200 144 11 219 162 10 230 174 11
53845-234 174 13 230 174 11 219 162 10 210 150 10
53846-192 133 9 163 110 8 124 112 88 82 82 82
53847- 50 50 50 30 30 30 14 14 14 6 6 6
53848- 0 0 0 0 0 0 0 0 0 0 0 0
53849- 0 0 0 0 0 0 0 0 0 0 0 0
53850- 0 0 0 0 0 0 0 0 0 0 0 0
53851- 0 0 0 0 0 0 0 0 0 0 0 0
53852- 0 0 0 0 0 0 0 0 0 0 0 0
53853- 6 6 6 14 14 14 22 22 22 34 34 34
53854- 42 42 42 58 58 58 74 74 74 86 86 86
53855-101 98 89 122 102 70 130 98 46 121 87 25
53856-137 92 6 152 99 6 163 110 8 180 123 7
53857-185 133 11 197 138 11 206 145 10 200 144 11
53858-180 123 7 156 107 11 130 83 6 104 69 6
53859- 50 34 6 54 54 54 110 110 110 101 98 89
53860- 86 86 86 82 82 82 78 78 78 78 78 78
53861- 78 78 78 78 78 78 78 78 78 78 78 78
53862- 78 78 78 82 82 82 86 86 86 94 94 94
53863-106 106 106 101 101 101 86 66 34 124 80 6
53864-156 107 11 180 123 7 192 133 9 200 144 11
53865-206 145 10 200 144 11 192 133 9 175 118 6
53866-139 102 15 109 106 95 70 70 70 42 42 42
53867- 22 22 22 10 10 10 0 0 0 0 0 0
53868- 0 0 0 0 0 0 0 0 0 0 0 0
53869- 0 0 0 0 0 0 0 0 0 0 0 0
53870- 0 0 0 0 0 0 0 0 0 0 0 0
53871- 0 0 0 0 0 0 0 0 0 0 0 0
53872- 0 0 0 0 0 0 0 0 0 0 0 0
53873- 0 0 0 0 0 0 6 6 6 10 10 10
53874- 14 14 14 22 22 22 30 30 30 38 38 38
53875- 50 50 50 62 62 62 74 74 74 90 90 90
53876-101 98 89 112 100 78 121 87 25 124 80 6
53877-137 92 6 152 99 6 152 99 6 152 99 6
53878-138 86 6 124 80 6 98 70 6 86 66 30
53879-101 98 89 82 82 82 58 58 58 46 46 46
53880- 38 38 38 34 34 34 34 34 34 34 34 34
53881- 34 34 34 34 34 34 34 34 34 34 34 34
53882- 34 34 34 34 34 34 38 38 38 42 42 42
53883- 54 54 54 82 82 82 94 86 76 91 60 6
53884-134 86 6 156 107 11 167 114 7 175 118 6
53885-175 118 6 167 114 7 152 99 6 121 87 25
53886-101 98 89 62 62 62 34 34 34 18 18 18
53887- 6 6 6 0 0 0 0 0 0 0 0 0
53888- 0 0 0 0 0 0 0 0 0 0 0 0
53889- 0 0 0 0 0 0 0 0 0 0 0 0
53890- 0 0 0 0 0 0 0 0 0 0 0 0
53891- 0 0 0 0 0 0 0 0 0 0 0 0
53892- 0 0 0 0 0 0 0 0 0 0 0 0
53893- 0 0 0 0 0 0 0 0 0 0 0 0
53894- 0 0 0 6 6 6 6 6 6 10 10 10
53895- 18 18 18 22 22 22 30 30 30 42 42 42
53896- 50 50 50 66 66 66 86 86 86 101 98 89
53897-106 86 58 98 70 6 104 69 6 104 69 6
53898-104 69 6 91 60 6 82 62 34 90 90 90
53899- 62 62 62 38 38 38 22 22 22 14 14 14
53900- 10 10 10 10 10 10 10 10 10 10 10 10
53901- 10 10 10 10 10 10 6 6 6 10 10 10
53902- 10 10 10 10 10 10 10 10 10 14 14 14
53903- 22 22 22 42 42 42 70 70 70 89 81 66
53904- 80 54 7 104 69 6 124 80 6 137 92 6
53905-134 86 6 116 81 8 100 82 52 86 86 86
53906- 58 58 58 30 30 30 14 14 14 6 6 6
53907- 0 0 0 0 0 0 0 0 0 0 0 0
53908- 0 0 0 0 0 0 0 0 0 0 0 0
53909- 0 0 0 0 0 0 0 0 0 0 0 0
53910- 0 0 0 0 0 0 0 0 0 0 0 0
53911- 0 0 0 0 0 0 0 0 0 0 0 0
53912- 0 0 0 0 0 0 0 0 0 0 0 0
53913- 0 0 0 0 0 0 0 0 0 0 0 0
53914- 0 0 0 0 0 0 0 0 0 0 0 0
53915- 0 0 0 6 6 6 10 10 10 14 14 14
53916- 18 18 18 26 26 26 38 38 38 54 54 54
53917- 70 70 70 86 86 86 94 86 76 89 81 66
53918- 89 81 66 86 86 86 74 74 74 50 50 50
53919- 30 30 30 14 14 14 6 6 6 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 0 0 0 0 0 0 0 0 0
53923- 6 6 6 18 18 18 34 34 34 58 58 58
53924- 82 82 82 89 81 66 89 81 66 89 81 66
53925- 94 86 66 94 86 76 74 74 74 50 50 50
53926- 26 26 26 14 14 14 6 6 6 0 0 0
53927- 0 0 0 0 0 0 0 0 0 0 0 0
53928- 0 0 0 0 0 0 0 0 0 0 0 0
53929- 0 0 0 0 0 0 0 0 0 0 0 0
53930- 0 0 0 0 0 0 0 0 0 0 0 0
53931- 0 0 0 0 0 0 0 0 0 0 0 0
53932- 0 0 0 0 0 0 0 0 0 0 0 0
53933- 0 0 0 0 0 0 0 0 0 0 0 0
53934- 0 0 0 0 0 0 0 0 0 0 0 0
53935- 0 0 0 0 0 0 0 0 0 0 0 0
53936- 6 6 6 6 6 6 14 14 14 18 18 18
53937- 30 30 30 38 38 38 46 46 46 54 54 54
53938- 50 50 50 42 42 42 30 30 30 18 18 18
53939- 10 10 10 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 14 14 14 26 26 26
53944- 38 38 38 50 50 50 58 58 58 58 58 58
53945- 54 54 54 42 42 42 30 30 30 18 18 18
53946- 10 10 10 0 0 0 0 0 0 0 0 0
53947- 0 0 0 0 0 0 0 0 0 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- 0 0 0 0 0 0 0 0 0 0 0 0
53952- 0 0 0 0 0 0 0 0 0 0 0 0
53953- 0 0 0 0 0 0 0 0 0 0 0 0
53954- 0 0 0 0 0 0 0 0 0 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 6 6 6
53957- 6 6 6 10 10 10 14 14 14 18 18 18
53958- 18 18 18 14 14 14 10 10 10 6 6 6
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 6 6 6
53964- 14 14 14 18 18 18 22 22 22 22 22 22
53965- 18 18 18 14 14 14 10 10 10 6 6 6
53966- 0 0 0 0 0 0 0 0 0 0 0 0
53967- 0 0 0 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+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53972+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53973+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53974+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53975+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53976+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53977+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53978+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53979+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53980+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53981+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53984+4 4 4 4 4 4
53985+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53986+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53987+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53988+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53989+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53990+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53991+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53992+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53993+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53994+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53995+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53997+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53998+4 4 4 4 4 4
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 3 3 3 0 0 0 0 0 0
54060+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 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 1 1 1 0 0 0
54065+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
54066+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
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 2 2 2 0 0 0 3 4 3 26 28 28
54074+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
54075+5 5 5 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 3 3 3 0 0 0 1 1 1 6 6 6
54079+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
54080+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
54081+1 1 1 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+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
54088+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
54089+0 0 0 3 3 3 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 0 0 0 4 4 4 41 54 63 125 124 125
54093+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
54094+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
54095+2 2 2 2 1 0 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 5 5 5 5 5 5 2 2 2 0 0 0
54101+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
54102+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
54103+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 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 5 5 5 5 5 5
54106+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
54107+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
54108+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
54109+37 51 59 2 0 0 1 1 1 4 5 5 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 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
54115+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
54116+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
54117+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
54118+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54119+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
54120+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
54121+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
54122+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
54123+64 123 161 14 17 19 0 0 0 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 5 5 5
54128+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
54129+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
54130+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
54131+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
54132+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54133+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
54134+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
54135+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
54136+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
54137+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 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 5 5 5 3 3 3
54142+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
54143+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
54144+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
54145+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
54146+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
54147+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
54148+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
54149+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
54150+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
54151+31 91 132 3 6 7 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 2 2 2 0 0 0 4 0 0
54156+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
54157+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
54158+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
54159+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
54160+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
54161+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
54162+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
54163+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
54164+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
54165+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
54170+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
54171+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
54172+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
54173+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
54174+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
54175+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
54176+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
54177+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
54178+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
54179+1 1 2 4 3 3 4 4 4 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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
54184+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
54185+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
54186+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
54187+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
54188+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
54189+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
54190+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
54191+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
54192+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
54193+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 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 3 3 3 0 0 0
54197+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
54198+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
54199+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
54200+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
54201+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
54202+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
54203+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
54204+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
54205+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
54206+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
54207+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
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 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
54211+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
54212+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
54213+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54214+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
54215+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
54216+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
54217+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
54218+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
54219+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
54220+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
54221+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
54222+0 0 0 4 4 4
54223+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
54224+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
54225+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
54226+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
54227+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
54228+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
54229+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
54230+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
54231+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
54232+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
54233+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
54234+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
54235+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
54236+2 0 0 0 0 0
54237+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
54238+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
54239+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
54240+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
54241+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
54242+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
54243+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
54244+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
54245+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
54246+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
54247+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
54248+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
54249+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
54250+37 38 37 0 0 0
54251+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54252+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
54253+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
54254+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
54255+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
54256+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
54257+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
54258+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
54259+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
54260+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
54261+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
54262+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
54263+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
54264+85 115 134 4 0 0
54265+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
54266+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
54267+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
54268+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
54269+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
54270+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
54271+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
54272+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
54273+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
54274+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
54275+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
54276+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
54277+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
54278+60 73 81 4 0 0
54279+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
54280+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
54281+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
54282+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
54283+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
54284+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
54285+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
54286+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
54287+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
54288+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
54289+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
54290+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
54291+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
54292+16 19 21 4 0 0
54293+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
54294+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
54295+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
54296+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
54297+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
54298+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
54299+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
54300+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
54301+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
54302+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
54303+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
54304+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
54305+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
54306+4 0 0 4 3 3
54307+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
54308+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
54309+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
54310+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
54311+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
54312+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
54313+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
54314+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
54315+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
54316+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
54317+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
54318+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
54319+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
54320+3 2 2 4 4 4
54321+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
54322+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
54323+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
54324+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
54325+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
54326+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
54327+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
54328+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
54329+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
54330+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
54331+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
54332+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
54333+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
54334+4 4 4 4 4 4
54335+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
54336+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
54337+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
54338+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
54339+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
54340+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
54341+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
54342+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
54343+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
54344+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
54345+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
54346+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
54347+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
54348+4 4 4 4 4 4
54349+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
54350+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
54351+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
54352+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
54353+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
54354+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54355+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
54356+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
54357+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
54358+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
54359+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
54360+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
54361+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
54362+5 5 5 5 5 5
54363+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
54364+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
54365+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
54366+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
54367+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
54368+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54369+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
54370+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
54371+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
54372+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
54373+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
54374+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
54375+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54376+5 5 5 4 4 4
54377+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
54378+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
54379+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
54380+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
54381+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54382+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
54383+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
54384+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
54385+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
54386+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
54387+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
54388+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54389+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54390+4 4 4 4 4 4
54391+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
54392+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
54393+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
54394+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
54395+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
54396+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54397+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
54398+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
54399+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
54400+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
54401+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
54402+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
54403+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54404+4 4 4 4 4 4
54405+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
54406+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
54407+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
54408+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
54409+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54410+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
54411+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
54412+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
54413+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
54414+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
54415+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
54416+4 4 4 4 4 4 4 4 4 4 4 4 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 157 156 157 155 154 155 137 136 137
54420+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
54421+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
54422+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
54423+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 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 136 185 209 90 154 193 26 108 161 22 40 52
54427+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
54428+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
54429+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
54430+4 4 4 4 4 4 4 4 4 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 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
54434+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
54435+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
54436+90 154 193 64 123 161 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 90 154 193
54438+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
54439+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
54440+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
54441+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
54442+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
54443+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 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+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
54448+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
54449+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
54450+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
54451+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
54452+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
54453+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
54454+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
54455+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
54456+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
54457+6 6 6 4 0 0 6 6 6 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 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
54462+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
54463+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
54464+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
54465+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
54466+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
54467+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
54468+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
54469+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
54470+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
54471+4 0 0 3 2 2 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+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
54476+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
54477+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
54478+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
54479+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
54480+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
54481+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
54482+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
54483+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
54484+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
54485+4 0 0 4 3 3 5 5 5 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 60 73 81 167 166 167 174 174 174 163 162 163
54490+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
54491+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
54492+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
54493+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54494+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
54495+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
54496+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
54497+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
54498+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
54499+4 0 0 4 3 3 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 167 166 167 174 174 174 166 165 166
54504+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
54505+5 5 5 4 3 3 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 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54508+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
54509+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
54510+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
54511+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
54512+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
54513+4 0 0 3 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+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
54518+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
54519+5 5 5 4 4 4 1 1 2 6 10 14 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+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
54523+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
54524+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
54525+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
54526+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54527+0 0 0 3 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 174 174 174 177 184 187 174 174 174
54532+174 174 174 190 197 201 157 156 157 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 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
54535+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
54536+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
54537+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
54538+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
54539+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
54540+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54541+0 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+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
54546+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
54547+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
54548+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
54549+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54550+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
54551+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
54552+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
54553+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 177 184 187 193 200 203 174 174 174
54560+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
54561+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
54562+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
54563+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
54564+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
54565+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
54566+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
54567+4 4 4 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 190 197 201 174 174 174
54574+177 184 187 193 200 203 163 162 163 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 10 87 144
54576+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
54577+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
54578+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
54579+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
54580+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
54581+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
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+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54588+190 197 201 193 200 203 165 164 165 37 38 37 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 16 89 141 18 97 151 18 97 151 10 87 144
54591+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
54592+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
54593+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
54594+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 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 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
54602+190 197 201 193 200 203 165 164 165 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 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
54605+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
54606+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
54607+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
54608+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
54609+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
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+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
54616+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
54617+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
54618+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
54619+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
54620+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
54621+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
54622+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 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 220 221 221 174 174 174
54630+190 197 201 205 212 215 167 166 167 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 10 87 144 22 40 52 1 1 2
54633+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
54634+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
54635+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
54636+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
54637+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
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 220 221 221 190 197 201 174 174 174
54644+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
54645+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
54646+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
54647+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
54648+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
54649+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54650+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
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 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
54659+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
54660+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54661+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
54662+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
54663+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
54664+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
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 26 28 28 4 0 0 4 3 3
54673+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
54674+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
54675+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
54676+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
54677+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
54678+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
54679+4 4 4 5 5 5 4 4 4 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 190 197 201 41 54 63 4 0 0 2 2 2
54687+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54688+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54689+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54690+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54691+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54692+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54693+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
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 193 200 203 174 174 174
54700+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54701+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54702+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54703+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54704+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54705+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54706+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54707+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54708+131 129 131 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+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54715+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54716+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54717+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54718+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54719+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54720+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54721+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54722+125 124 125 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 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54728+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54729+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54730+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54731+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54732+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54733+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54734+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54735+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54736+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
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 26 28 28 156 155 156 220 221 221 220 221 221
54742+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54743+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54744+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54745+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54746+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54747+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54748+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54749+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54750+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54751+0 0 0 4 4 4 4 4 4 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+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54756+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54757+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54758+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54759+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54760+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54761+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54762+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54763+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54764+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54765+4 3 3 5 5 5 4 4 4 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 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54770+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54771+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54772+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54773+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54774+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54775+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54776+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54777+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54778+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54779+5 5 5 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 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54784+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54785+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54786+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54787+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54788+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54789+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54790+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54791+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54792+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54793+4 4 4 4 4 4 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 6 6 6 6 6 6 6 6 6
54798+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54799+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54800+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54801+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54802+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54803+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54804+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54805+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54806+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54807+4 4 4 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 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54812+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54813+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54814+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54815+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54816+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54817+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54818+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54819+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54820+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
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+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54826+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54827+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54828+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54829+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54830+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54831+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54832+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54833+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54834+4 3 3 5 5 5 4 4 4 4 4 4 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+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54840+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54841+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54842+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54843+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54844+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54845+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54846+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54847+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54848+4 4 4 4 4 4 4 4 4 4 4 4 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 5 5 5 4 3 3 6 6 6 4 0 0
54854+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54855+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54856+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54857+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54858+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54859+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54860+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54861+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54862+4 4 4 4 4 4 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 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54868+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54869+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54870+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54871+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54872+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54873+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54874+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54875+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54882+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54883+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54884+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54885+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54886+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54887+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54888+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54889+4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 5 5 5 4 3 3
54896+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54897+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54898+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54899+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54900+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54901+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54902+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54903+4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5
54910+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54911+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54912+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54913+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54914+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54915+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54916+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
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 4 4 4 4 4 4
54924+4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54925+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54926+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54927+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54928+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54929+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54930+6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4
54938+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54939+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54940+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54941+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54942+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54943+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54944+5 5 5 5 5 5 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54953+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54954+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54955+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54956+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54957+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54958+4 3 3 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
54967+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54968+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54969+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54970+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54971+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54972+4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54982+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54983+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54984+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54985+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54986+4 4 4 4 4 4 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 4 4 4
54996+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54997+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54998+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54999+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
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 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55011+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55012+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55013+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
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 4 4 4 4 4 4 4 4 4 5 5 5
55025+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55026+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55027+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4
55039+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55040+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55041+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 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 4 4 4
55053+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55054+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55055+5 5 5 4 4 4 4 4 4 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 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
55068+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
55069+4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55082+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
55083+4 4 4 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
55091diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
55092index a01147f..5d896f8 100644
55093--- a/drivers/video/matrox/matroxfb_DAC1064.c
55094+++ b/drivers/video/matrox/matroxfb_DAC1064.c
55095@@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
55096
55097 #ifdef CONFIG_FB_MATROX_MYSTIQUE
55098 struct matrox_switch matrox_mystique = {
55099- MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
55100+ .preinit = MGA1064_preinit,
55101+ .reset = MGA1064_reset,
55102+ .init = MGA1064_init,
55103+ .restore = MGA1064_restore,
55104 };
55105 EXPORT_SYMBOL(matrox_mystique);
55106 #endif
55107
55108 #ifdef CONFIG_FB_MATROX_G
55109 struct matrox_switch matrox_G100 = {
55110- MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
55111+ .preinit = MGAG100_preinit,
55112+ .reset = MGAG100_reset,
55113+ .init = MGAG100_init,
55114+ .restore = MGAG100_restore,
55115 };
55116 EXPORT_SYMBOL(matrox_G100);
55117 #endif
55118diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
55119index 195ad7c..09743fc 100644
55120--- a/drivers/video/matrox/matroxfb_Ti3026.c
55121+++ b/drivers/video/matrox/matroxfb_Ti3026.c
55122@@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
55123 }
55124
55125 struct matrox_switch matrox_millennium = {
55126- Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
55127+ .preinit = Ti3026_preinit,
55128+ .reset = Ti3026_reset,
55129+ .init = Ti3026_init,
55130+ .restore = Ti3026_restore
55131 };
55132 EXPORT_SYMBOL(matrox_millennium);
55133 #endif
55134diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
55135index fe92eed..106e085 100644
55136--- a/drivers/video/mb862xx/mb862xxfb_accel.c
55137+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
55138@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
55139 struct mb862xxfb_par *par = info->par;
55140
55141 if (info->var.bits_per_pixel == 32) {
55142- info->fbops->fb_fillrect = cfb_fillrect;
55143- info->fbops->fb_copyarea = cfb_copyarea;
55144- info->fbops->fb_imageblit = cfb_imageblit;
55145+ pax_open_kernel();
55146+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55147+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55148+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55149+ pax_close_kernel();
55150 } else {
55151 outreg(disp, GC_L0EM, 3);
55152- info->fbops->fb_fillrect = mb86290fb_fillrect;
55153- info->fbops->fb_copyarea = mb86290fb_copyarea;
55154- info->fbops->fb_imageblit = mb86290fb_imageblit;
55155+ pax_open_kernel();
55156+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
55157+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
55158+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
55159+ pax_close_kernel();
55160 }
55161 outreg(draw, GDC_REG_DRAW_BASE, 0);
55162 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
55163diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
55164index ff22871..b129bed 100644
55165--- a/drivers/video/nvidia/nvidia.c
55166+++ b/drivers/video/nvidia/nvidia.c
55167@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
55168 info->fix.line_length = (info->var.xres_virtual *
55169 info->var.bits_per_pixel) >> 3;
55170 if (info->var.accel_flags) {
55171- info->fbops->fb_imageblit = nvidiafb_imageblit;
55172- info->fbops->fb_fillrect = nvidiafb_fillrect;
55173- info->fbops->fb_copyarea = nvidiafb_copyarea;
55174- info->fbops->fb_sync = nvidiafb_sync;
55175+ pax_open_kernel();
55176+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
55177+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
55178+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
55179+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
55180+ pax_close_kernel();
55181 info->pixmap.scan_align = 4;
55182 info->flags &= ~FBINFO_HWACCEL_DISABLED;
55183 info->flags |= FBINFO_READS_FAST;
55184 NVResetGraphics(info);
55185 } else {
55186- info->fbops->fb_imageblit = cfb_imageblit;
55187- info->fbops->fb_fillrect = cfb_fillrect;
55188- info->fbops->fb_copyarea = cfb_copyarea;
55189- info->fbops->fb_sync = NULL;
55190+ pax_open_kernel();
55191+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
55192+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
55193+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
55194+ *(void **)&info->fbops->fb_sync = NULL;
55195+ pax_close_kernel();
55196 info->pixmap.scan_align = 1;
55197 info->flags |= FBINFO_HWACCEL_DISABLED;
55198 info->flags &= ~FBINFO_READS_FAST;
55199@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
55200 info->pixmap.size = 8 * 1024;
55201 info->pixmap.flags = FB_PIXMAP_SYSTEM;
55202
55203- if (!hwcur)
55204- info->fbops->fb_cursor = NULL;
55205+ if (!hwcur) {
55206+ pax_open_kernel();
55207+ *(void **)&info->fbops->fb_cursor = NULL;
55208+ pax_close_kernel();
55209+ }
55210
55211 info->var.accel_flags = (!noaccel);
55212
55213diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
55214index 669a81f..e216d76 100644
55215--- a/drivers/video/omap2/dss/display.c
55216+++ b/drivers/video/omap2/dss/display.c
55217@@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
55218 snprintf(dssdev->alias, sizeof(dssdev->alias),
55219 "display%d", disp_num_counter++);
55220
55221+ pax_open_kernel();
55222 if (drv && drv->get_resolution == NULL)
55223- drv->get_resolution = omapdss_default_get_resolution;
55224+ *(void **)&drv->get_resolution = omapdss_default_get_resolution;
55225 if (drv && drv->get_recommended_bpp == NULL)
55226- drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55227+ *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
55228 if (drv && drv->get_timings == NULL)
55229- drv->get_timings = omapdss_default_get_timings;
55230+ *(void **)&drv->get_timings = omapdss_default_get_timings;
55231+ pax_close_kernel();
55232
55233 mutex_lock(&panel_list_mutex);
55234 list_add_tail(&dssdev->panel_list, &panel_list);
55235diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
55236index 83433cb..71e9b98 100644
55237--- a/drivers/video/s1d13xxxfb.c
55238+++ b/drivers/video/s1d13xxxfb.c
55239@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
55240
55241 switch(prod_id) {
55242 case S1D13506_PROD_ID: /* activate acceleration */
55243- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55244- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55245+ pax_open_kernel();
55246+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
55247+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
55248+ pax_close_kernel();
55249 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
55250 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
55251 break;
55252diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
55253index d513ed6..90b0de9 100644
55254--- a/drivers/video/smscufx.c
55255+++ b/drivers/video/smscufx.c
55256@@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
55257 fb_deferred_io_cleanup(info);
55258 kfree(info->fbdefio);
55259 info->fbdefio = NULL;
55260- info->fbops->fb_mmap = ufx_ops_mmap;
55261+ pax_open_kernel();
55262+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
55263+ pax_close_kernel();
55264 }
55265
55266 pr_debug("released /dev/fb%d user=%d count=%d",
55267diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
55268index 025f14e..20eb4db 100644
55269--- a/drivers/video/udlfb.c
55270+++ b/drivers/video/udlfb.c
55271@@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
55272 dlfb_urb_completion(urb);
55273
55274 error:
55275- atomic_add(bytes_sent, &dev->bytes_sent);
55276- atomic_add(bytes_identical, &dev->bytes_identical);
55277- atomic_add(width*height*2, &dev->bytes_rendered);
55278+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55279+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55280+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
55281 end_cycles = get_cycles();
55282- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55283+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55284 >> 10)), /* Kcycles */
55285 &dev->cpu_kcycles_used);
55286
55287@@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
55288 dlfb_urb_completion(urb);
55289
55290 error:
55291- atomic_add(bytes_sent, &dev->bytes_sent);
55292- atomic_add(bytes_identical, &dev->bytes_identical);
55293- atomic_add(bytes_rendered, &dev->bytes_rendered);
55294+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
55295+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
55296+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
55297 end_cycles = get_cycles();
55298- atomic_add(((unsigned int) ((end_cycles - start_cycles)
55299+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
55300 >> 10)), /* Kcycles */
55301 &dev->cpu_kcycles_used);
55302 }
55303@@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
55304 fb_deferred_io_cleanup(info);
55305 kfree(info->fbdefio);
55306 info->fbdefio = NULL;
55307- info->fbops->fb_mmap = dlfb_ops_mmap;
55308+ pax_open_kernel();
55309+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
55310+ pax_close_kernel();
55311 }
55312
55313 pr_warn("released /dev/fb%d user=%d count=%d\n",
55314@@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
55315 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55316 struct dlfb_data *dev = fb_info->par;
55317 return snprintf(buf, PAGE_SIZE, "%u\n",
55318- atomic_read(&dev->bytes_rendered));
55319+ atomic_read_unchecked(&dev->bytes_rendered));
55320 }
55321
55322 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55323@@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
55324 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55325 struct dlfb_data *dev = fb_info->par;
55326 return snprintf(buf, PAGE_SIZE, "%u\n",
55327- atomic_read(&dev->bytes_identical));
55328+ atomic_read_unchecked(&dev->bytes_identical));
55329 }
55330
55331 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55332@@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
55333 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55334 struct dlfb_data *dev = fb_info->par;
55335 return snprintf(buf, PAGE_SIZE, "%u\n",
55336- atomic_read(&dev->bytes_sent));
55337+ atomic_read_unchecked(&dev->bytes_sent));
55338 }
55339
55340 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55341@@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
55342 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55343 struct dlfb_data *dev = fb_info->par;
55344 return snprintf(buf, PAGE_SIZE, "%u\n",
55345- atomic_read(&dev->cpu_kcycles_used));
55346+ atomic_read_unchecked(&dev->cpu_kcycles_used));
55347 }
55348
55349 static ssize_t edid_show(
55350@@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
55351 struct fb_info *fb_info = dev_get_drvdata(fbdev);
55352 struct dlfb_data *dev = fb_info->par;
55353
55354- atomic_set(&dev->bytes_rendered, 0);
55355- atomic_set(&dev->bytes_identical, 0);
55356- atomic_set(&dev->bytes_sent, 0);
55357- atomic_set(&dev->cpu_kcycles_used, 0);
55358+ atomic_set_unchecked(&dev->bytes_rendered, 0);
55359+ atomic_set_unchecked(&dev->bytes_identical, 0);
55360+ atomic_set_unchecked(&dev->bytes_sent, 0);
55361+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
55362
55363 return count;
55364 }
55365diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
55366index 256fba7..6e75516 100644
55367--- a/drivers/video/uvesafb.c
55368+++ b/drivers/video/uvesafb.c
55369@@ -19,6 +19,7 @@
55370 #include <linux/io.h>
55371 #include <linux/mutex.h>
55372 #include <linux/slab.h>
55373+#include <linux/moduleloader.h>
55374 #include <video/edid.h>
55375 #include <video/uvesafb.h>
55376 #ifdef CONFIG_X86
55377@@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
55378 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
55379 par->pmi_setpal = par->ypan = 0;
55380 } else {
55381+
55382+#ifdef CONFIG_PAX_KERNEXEC
55383+#ifdef CONFIG_MODULES
55384+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
55385+#endif
55386+ if (!par->pmi_code) {
55387+ par->pmi_setpal = par->ypan = 0;
55388+ return 0;
55389+ }
55390+#endif
55391+
55392 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
55393 + task->t.regs.edi);
55394+
55395+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55396+ pax_open_kernel();
55397+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
55398+ pax_close_kernel();
55399+
55400+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
55401+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
55402+#else
55403 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
55404 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
55405+#endif
55406+
55407 printk(KERN_INFO "uvesafb: protected mode interface info at "
55408 "%04x:%04x\n",
55409 (u16)task->t.regs.es, (u16)task->t.regs.edi);
55410@@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
55411 par->ypan = ypan;
55412
55413 if (par->pmi_setpal || par->ypan) {
55414+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
55415 if (__supported_pte_mask & _PAGE_NX) {
55416 par->pmi_setpal = par->ypan = 0;
55417 printk(KERN_WARNING "uvesafb: NX protection is active, "
55418 "better not use the PMI.\n");
55419- } else {
55420+ } else
55421+#endif
55422 uvesafb_vbe_getpmi(task, par);
55423- }
55424 }
55425 #else
55426 /* The protected mode interface is not available on non-x86. */
55427@@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55428 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
55429
55430 /* Disable blanking if the user requested so. */
55431- if (!blank)
55432- info->fbops->fb_blank = NULL;
55433+ if (!blank) {
55434+ pax_open_kernel();
55435+ *(void **)&info->fbops->fb_blank = NULL;
55436+ pax_close_kernel();
55437+ }
55438
55439 /*
55440 * Find out how much IO memory is required for the mode with
55441@@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
55442 info->flags = FBINFO_FLAG_DEFAULT |
55443 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
55444
55445- if (!par->ypan)
55446- info->fbops->fb_pan_display = NULL;
55447+ if (!par->ypan) {
55448+ pax_open_kernel();
55449+ *(void **)&info->fbops->fb_pan_display = NULL;
55450+ pax_close_kernel();
55451+ }
55452 }
55453
55454 static void uvesafb_init_mtrr(struct fb_info *info)
55455@@ -1792,6 +1822,11 @@ out_mode:
55456 out:
55457 kfree(par->vbe_modes);
55458
55459+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55460+ if (par->pmi_code)
55461+ module_free_exec(NULL, par->pmi_code);
55462+#endif
55463+
55464 framebuffer_release(info);
55465 return err;
55466 }
55467@@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
55468 kfree(par->vbe_modes);
55469 kfree(par->vbe_state_orig);
55470 kfree(par->vbe_state_saved);
55471+
55472+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55473+ if (par->pmi_code)
55474+ module_free_exec(NULL, par->pmi_code);
55475+#endif
55476+
55477 }
55478
55479 framebuffer_release(info);
55480diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
55481index 1c7da3b..56ea0bd 100644
55482--- a/drivers/video/vesafb.c
55483+++ b/drivers/video/vesafb.c
55484@@ -9,6 +9,7 @@
55485 */
55486
55487 #include <linux/module.h>
55488+#include <linux/moduleloader.h>
55489 #include <linux/kernel.h>
55490 #include <linux/errno.h>
55491 #include <linux/string.h>
55492@@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
55493 static int vram_total; /* Set total amount of memory */
55494 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
55495 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
55496-static void (*pmi_start)(void) __read_mostly;
55497-static void (*pmi_pal) (void) __read_mostly;
55498+static void (*pmi_start)(void) __read_only;
55499+static void (*pmi_pal) (void) __read_only;
55500 static int depth __read_mostly;
55501 static int vga_compat __read_mostly;
55502 /* --------------------------------------------------------------------- */
55503@@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
55504 unsigned int size_remap;
55505 unsigned int size_total;
55506 char *option = NULL;
55507+ void *pmi_code = NULL;
55508
55509 /* ignore error return of fb_get_options */
55510 fb_get_options("vesafb", &option);
55511@@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
55512 size_remap = size_total;
55513 vesafb_fix.smem_len = size_remap;
55514
55515-#ifndef __i386__
55516- screen_info.vesapm_seg = 0;
55517-#endif
55518-
55519 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
55520 printk(KERN_WARNING
55521 "vesafb: cannot reserve video memory at 0x%lx\n",
55522@@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
55523 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
55524 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
55525
55526+#ifdef __i386__
55527+
55528+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55529+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
55530+ if (!pmi_code)
55531+#elif !defined(CONFIG_PAX_KERNEXEC)
55532+ if (0)
55533+#endif
55534+
55535+#endif
55536+ screen_info.vesapm_seg = 0;
55537+
55538 if (screen_info.vesapm_seg) {
55539- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
55540- screen_info.vesapm_seg,screen_info.vesapm_off);
55541+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
55542+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
55543 }
55544
55545 if (screen_info.vesapm_seg < 0xc000)
55546@@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
55547
55548 if (ypan || pmi_setpal) {
55549 unsigned short *pmi_base;
55550+
55551 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
55552- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
55553- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
55554+
55555+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55556+ pax_open_kernel();
55557+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
55558+#else
55559+ pmi_code = pmi_base;
55560+#endif
55561+
55562+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
55563+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
55564+
55565+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55566+ pmi_start = ktva_ktla(pmi_start);
55567+ pmi_pal = ktva_ktla(pmi_pal);
55568+ pax_close_kernel();
55569+#endif
55570+
55571 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
55572 if (pmi_base[3]) {
55573 printk(KERN_INFO "vesafb: pmi: ports = ");
55574@@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
55575 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
55576 (ypan ? FBINFO_HWACCEL_YPAN : 0);
55577
55578- if (!ypan)
55579- info->fbops->fb_pan_display = NULL;
55580+ if (!ypan) {
55581+ pax_open_kernel();
55582+ *(void **)&info->fbops->fb_pan_display = NULL;
55583+ pax_close_kernel();
55584+ }
55585
55586 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
55587 err = -ENOMEM;
55588@@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
55589 fb_info(info, "%s frame buffer device\n", info->fix.id);
55590 return 0;
55591 err:
55592+
55593+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
55594+ module_free_exec(NULL, pmi_code);
55595+#endif
55596+
55597 if (info->screen_base)
55598 iounmap(info->screen_base);
55599 framebuffer_release(info);
55600diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
55601index 88714ae..16c2e11 100644
55602--- a/drivers/video/via/via_clock.h
55603+++ b/drivers/video/via/via_clock.h
55604@@ -56,7 +56,7 @@ struct via_clock {
55605
55606 void (*set_engine_pll_state)(u8 state);
55607 void (*set_engine_pll)(struct via_pll_config config);
55608-};
55609+} __no_const;
55610
55611
55612 static inline u32 get_pll_internal_frequency(u32 ref_freq,
55613diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
55614index fef20db..d28b1ab 100644
55615--- a/drivers/xen/xenfs/xenstored.c
55616+++ b/drivers/xen/xenfs/xenstored.c
55617@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
55618 static int xsd_kva_open(struct inode *inode, struct file *file)
55619 {
55620 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
55621+#ifdef CONFIG_GRKERNSEC_HIDESYM
55622+ NULL);
55623+#else
55624 xen_store_interface);
55625+#endif
55626+
55627 if (!file->private_data)
55628 return -ENOMEM;
55629 return 0;
55630diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
55631index 9ff073f..05cef23 100644
55632--- a/fs/9p/vfs_addr.c
55633+++ b/fs/9p/vfs_addr.c
55634@@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
55635
55636 retval = v9fs_file_write_internal(inode,
55637 v9inode->writeback_fid,
55638- (__force const char __user *)buffer,
55639+ (const char __force_user *)buffer,
55640 len, &offset, 0);
55641 if (retval > 0)
55642 retval = 0;
55643diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
55644index 4e65aa9..043dc9a 100644
55645--- a/fs/9p/vfs_inode.c
55646+++ b/fs/9p/vfs_inode.c
55647@@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55648 void
55649 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
55650 {
55651- char *s = nd_get_link(nd);
55652+ const char *s = nd_get_link(nd);
55653
55654 p9_debug(P9_DEBUG_VFS, " %s %s\n",
55655 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
55656diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
55657index 370b24c..ff0be7b 100644
55658--- a/fs/Kconfig.binfmt
55659+++ b/fs/Kconfig.binfmt
55660@@ -103,7 +103,7 @@ config HAVE_AOUT
55661
55662 config BINFMT_AOUT
55663 tristate "Kernel support for a.out and ECOFF binaries"
55664- depends on HAVE_AOUT
55665+ depends on HAVE_AOUT && BROKEN
55666 ---help---
55667 A.out (Assembler.OUTput) is a set of formats for libraries and
55668 executables used in the earliest versions of UNIX. Linux used
55669diff --git a/fs/afs/inode.c b/fs/afs/inode.c
55670index ce25d75..dc09eeb 100644
55671--- a/fs/afs/inode.c
55672+++ b/fs/afs/inode.c
55673@@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55674 struct afs_vnode *vnode;
55675 struct super_block *sb;
55676 struct inode *inode;
55677- static atomic_t afs_autocell_ino;
55678+ static atomic_unchecked_t afs_autocell_ino;
55679
55680 _enter("{%x:%u},%*.*s,",
55681 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
55682@@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
55683 data.fid.unique = 0;
55684 data.fid.vnode = 0;
55685
55686- inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55687+ inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55688 afs_iget5_autocell_test, afs_iget5_set,
55689 &data);
55690 if (!inode) {
55691diff --git a/fs/aio.c b/fs/aio.c
55692index 062a5f6..e5618e0 100644
55693--- a/fs/aio.c
55694+++ b/fs/aio.c
55695@@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55696 size += sizeof(struct io_event) * nr_events;
55697
55698 nr_pages = PFN_UP(size);
55699- if (nr_pages < 0)
55700+ if (nr_pages <= 0)
55701 return -EINVAL;
55702
55703 file = aio_private_file(ctx, nr_pages);
55704diff --git a/fs/anon_inodes.c b/fs/anon_inodes.c
55705index 2408473..80ef38c 100644
55706--- a/fs/anon_inodes.c
55707+++ b/fs/anon_inodes.c
55708@@ -41,19 +41,8 @@ static const struct dentry_operations anon_inodefs_dentry_operations = {
55709 static struct dentry *anon_inodefs_mount(struct file_system_type *fs_type,
55710 int flags, const char *dev_name, void *data)
55711 {
55712- struct dentry *root;
55713- root = mount_pseudo(fs_type, "anon_inode:", NULL,
55714+ return mount_pseudo(fs_type, "anon_inode:", NULL,
55715 &anon_inodefs_dentry_operations, ANON_INODE_FS_MAGIC);
55716- if (!IS_ERR(root)) {
55717- struct super_block *s = root->d_sb;
55718- anon_inode_inode = alloc_anon_inode(s);
55719- if (IS_ERR(anon_inode_inode)) {
55720- dput(root);
55721- deactivate_locked_super(s);
55722- root = ERR_CAST(anon_inode_inode);
55723- }
55724- }
55725- return root;
55726 }
55727
55728 static struct file_system_type anon_inode_fs_type = {
55729@@ -175,22 +164,15 @@ EXPORT_SYMBOL_GPL(anon_inode_getfd);
55730
55731 static int __init anon_inode_init(void)
55732 {
55733- int error;
55734-
55735- error = register_filesystem(&anon_inode_fs_type);
55736- if (error)
55737- goto err_exit;
55738 anon_inode_mnt = kern_mount(&anon_inode_fs_type);
55739- if (IS_ERR(anon_inode_mnt)) {
55740- error = PTR_ERR(anon_inode_mnt);
55741- goto err_unregister_filesystem;
55742- }
55743+ if (IS_ERR(anon_inode_mnt))
55744+ panic("anon_inode_init() kernel mount failed (%ld)\n", PTR_ERR(anon_inode_mnt));
55745+
55746+ anon_inode_inode = alloc_anon_inode(anon_inode_mnt->mnt_sb);
55747+ if (IS_ERR(anon_inode_inode))
55748+ panic("anon_inode_init() inode allocation failed (%ld)\n", PTR_ERR(anon_inode_inode));
55749+
55750 return 0;
55751-
55752-err_unregister_filesystem:
55753- unregister_filesystem(&anon_inode_fs_type);
55754-err_exit:
55755- panic(KERN_ERR "anon_inode_init() failed (%d)\n", error);
55756 }
55757
55758 fs_initcall(anon_inode_init);
55759diff --git a/fs/attr.c b/fs/attr.c
55760index 5d4e59d..fd02418 100644
55761--- a/fs/attr.c
55762+++ b/fs/attr.c
55763@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55764 unsigned long limit;
55765
55766 limit = rlimit(RLIMIT_FSIZE);
55767+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55768 if (limit != RLIM_INFINITY && offset > limit)
55769 goto out_sig;
55770 if (offset > inode->i_sb->s_maxbytes)
55771diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55772index 689e40d..515cac5 100644
55773--- a/fs/autofs4/waitq.c
55774+++ b/fs/autofs4/waitq.c
55775@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55776 {
55777 unsigned long sigpipe, flags;
55778 mm_segment_t fs;
55779- const char *data = (const char *)addr;
55780+ const char __user *data = (const char __force_user *)addr;
55781 ssize_t wr = 0;
55782
55783 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55784@@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55785 return 1;
55786 }
55787
55788+#ifdef CONFIG_GRKERNSEC_HIDESYM
55789+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55790+#endif
55791+
55792 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55793 enum autofs_notify notify)
55794 {
55795@@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55796
55797 /* If this is a direct mount request create a dummy name */
55798 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55799+#ifdef CONFIG_GRKERNSEC_HIDESYM
55800+ /* this name does get written to userland via autofs4_write() */
55801+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55802+#else
55803 qstr.len = sprintf(name, "%p", dentry);
55804+#endif
55805 else {
55806 qstr.len = autofs4_getpath(sbi, dentry, &name);
55807 if (!qstr.len) {
55808diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55809index 2722387..56059b5 100644
55810--- a/fs/befs/endian.h
55811+++ b/fs/befs/endian.h
55812@@ -11,7 +11,7 @@
55813
55814 #include <asm/byteorder.h>
55815
55816-static inline u64
55817+static inline u64 __intentional_overflow(-1)
55818 fs64_to_cpu(const struct super_block *sb, fs64 n)
55819 {
55820 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55821@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55822 return (__force fs64)cpu_to_be64(n);
55823 }
55824
55825-static inline u32
55826+static inline u32 __intentional_overflow(-1)
55827 fs32_to_cpu(const struct super_block *sb, fs32 n)
55828 {
55829 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55830@@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55831 return (__force fs32)cpu_to_be32(n);
55832 }
55833
55834-static inline u16
55835+static inline u16 __intentional_overflow(-1)
55836 fs16_to_cpu(const struct super_block *sb, fs16 n)
55837 {
55838 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55839diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55840index ca0ba15..0fa3257 100644
55841--- a/fs/binfmt_aout.c
55842+++ b/fs/binfmt_aout.c
55843@@ -16,6 +16,7 @@
55844 #include <linux/string.h>
55845 #include <linux/fs.h>
55846 #include <linux/file.h>
55847+#include <linux/security.h>
55848 #include <linux/stat.h>
55849 #include <linux/fcntl.h>
55850 #include <linux/ptrace.h>
55851@@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55852 #endif
55853 # define START_STACK(u) ((void __user *)u.start_stack)
55854
55855+ memset(&dump, 0, sizeof(dump));
55856+
55857 fs = get_fs();
55858 set_fs(KERNEL_DS);
55859 has_dumped = 1;
55860@@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55861
55862 /* If the size of the dump file exceeds the rlimit, then see what would happen
55863 if we wrote the stack, but not the data area. */
55864+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55865 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55866 dump.u_dsize = 0;
55867
55868 /* Make sure we have enough room to write the stack and data areas. */
55869+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55870 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55871 dump.u_ssize = 0;
55872
55873@@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55874 rlim = rlimit(RLIMIT_DATA);
55875 if (rlim >= RLIM_INFINITY)
55876 rlim = ~0;
55877+
55878+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55879 if (ex.a_data + ex.a_bss > rlim)
55880 return -ENOMEM;
55881
55882@@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55883
55884 install_exec_creds(bprm);
55885
55886+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55887+ current->mm->pax_flags = 0UL;
55888+#endif
55889+
55890+#ifdef CONFIG_PAX_PAGEEXEC
55891+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55892+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55893+
55894+#ifdef CONFIG_PAX_EMUTRAMP
55895+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55896+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55897+#endif
55898+
55899+#ifdef CONFIG_PAX_MPROTECT
55900+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55901+ current->mm->pax_flags |= MF_PAX_MPROTECT;
55902+#endif
55903+
55904+ }
55905+#endif
55906+
55907 if (N_MAGIC(ex) == OMAGIC) {
55908 unsigned long text_addr, map_size;
55909 loff_t pos;
55910@@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55911 }
55912
55913 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55914- PROT_READ | PROT_WRITE | PROT_EXEC,
55915+ PROT_READ | PROT_WRITE,
55916 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55917 fd_offset + ex.a_text);
55918 if (error != N_DATADDR(ex)) {
55919diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55920index 571a423..eed5754 100644
55921--- a/fs/binfmt_elf.c
55922+++ b/fs/binfmt_elf.c
55923@@ -34,6 +34,7 @@
55924 #include <linux/utsname.h>
55925 #include <linux/coredump.h>
55926 #include <linux/sched.h>
55927+#include <linux/xattr.h>
55928 #include <asm/uaccess.h>
55929 #include <asm/param.h>
55930 #include <asm/page.h>
55931@@ -48,7 +49,7 @@
55932 static int load_elf_binary(struct linux_binprm *bprm);
55933 static int load_elf_library(struct file *);
55934 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
55935- int, int, unsigned long);
55936+ int, int, unsigned long) __intentional_overflow(-1);
55937
55938 /*
55939 * If we don't support core dumping, then supply a NULL so we
55940@@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55941 #define elf_core_dump NULL
55942 #endif
55943
55944+#ifdef CONFIG_PAX_MPROTECT
55945+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55946+#endif
55947+
55948+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55949+static void elf_handle_mmap(struct file *file);
55950+#endif
55951+
55952 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55953 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55954 #else
55955@@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55956 .load_binary = load_elf_binary,
55957 .load_shlib = load_elf_library,
55958 .core_dump = elf_core_dump,
55959+
55960+#ifdef CONFIG_PAX_MPROTECT
55961+ .handle_mprotect= elf_handle_mprotect,
55962+#endif
55963+
55964+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55965+ .handle_mmap = elf_handle_mmap,
55966+#endif
55967+
55968 .min_coredump = ELF_EXEC_PAGESIZE,
55969 };
55970
55971@@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55972
55973 static int set_brk(unsigned long start, unsigned long end)
55974 {
55975+ unsigned long e = end;
55976+
55977 start = ELF_PAGEALIGN(start);
55978 end = ELF_PAGEALIGN(end);
55979 if (end > start) {
55980@@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55981 if (BAD_ADDR(addr))
55982 return addr;
55983 }
55984- current->mm->start_brk = current->mm->brk = end;
55985+ current->mm->start_brk = current->mm->brk = e;
55986 return 0;
55987 }
55988
55989@@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55990 elf_addr_t __user *u_rand_bytes;
55991 const char *k_platform = ELF_PLATFORM;
55992 const char *k_base_platform = ELF_BASE_PLATFORM;
55993- unsigned char k_rand_bytes[16];
55994+ u32 k_rand_bytes[4];
55995 int items;
55996 elf_addr_t *elf_info;
55997 int ei_index = 0;
55998 const struct cred *cred = current_cred();
55999 struct vm_area_struct *vma;
56000+ unsigned long saved_auxv[AT_VECTOR_SIZE];
56001
56002 /*
56003 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56004@@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56005 * Generate 16 random bytes for userspace PRNG seeding.
56006 */
56007 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56008- u_rand_bytes = (elf_addr_t __user *)
56009- STACK_ALLOC(p, sizeof(k_rand_bytes));
56010+ prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56011+ prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56012+ prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56013+ prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56014+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
56015+ u_rand_bytes = (elf_addr_t __user *) p;
56016 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56017 return -EFAULT;
56018
56019@@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56020 return -EFAULT;
56021 current->mm->env_end = p;
56022
56023+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56024+
56025 /* Put the elf_info on the stack in the right place. */
56026 sp = (elf_addr_t __user *)envp + 1;
56027- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56028+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56029 return -EFAULT;
56030 return 0;
56031 }
56032@@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56033 an ELF header */
56034
56035 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56036- struct file *interpreter, unsigned long *interp_map_addr,
56037- unsigned long no_base)
56038+ struct file *interpreter, unsigned long no_base)
56039 {
56040 struct elf_phdr *elf_phdata;
56041 struct elf_phdr *eppnt;
56042- unsigned long load_addr = 0;
56043+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56044 int load_addr_set = 0;
56045 unsigned long last_bss = 0, elf_bss = 0;
56046- unsigned long error = ~0UL;
56047+ unsigned long error = -EINVAL;
56048 unsigned long total_size;
56049 int retval, i, size;
56050
56051@@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56052 goto out_close;
56053 }
56054
56055+#ifdef CONFIG_PAX_SEGMEXEC
56056+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56057+ pax_task_size = SEGMEXEC_TASK_SIZE;
56058+#endif
56059+
56060 eppnt = elf_phdata;
56061 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56062 if (eppnt->p_type == PT_LOAD) {
56063@@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56064 map_addr = elf_map(interpreter, load_addr + vaddr,
56065 eppnt, elf_prot, elf_type, total_size);
56066 total_size = 0;
56067- if (!*interp_map_addr)
56068- *interp_map_addr = map_addr;
56069 error = map_addr;
56070 if (BAD_ADDR(map_addr))
56071 goto out_close;
56072@@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56073 k = load_addr + eppnt->p_vaddr;
56074 if (BAD_ADDR(k) ||
56075 eppnt->p_filesz > eppnt->p_memsz ||
56076- eppnt->p_memsz > TASK_SIZE ||
56077- TASK_SIZE - eppnt->p_memsz < k) {
56078+ eppnt->p_memsz > pax_task_size ||
56079+ pax_task_size - eppnt->p_memsz < k) {
56080 error = -ENOMEM;
56081 goto out_close;
56082 }
56083@@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56084 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56085
56086 /* Map the last of the bss segment */
56087- error = vm_brk(elf_bss, last_bss - elf_bss);
56088- if (BAD_ADDR(error))
56089- goto out_close;
56090+ if (last_bss > elf_bss) {
56091+ error = vm_brk(elf_bss, last_bss - elf_bss);
56092+ if (BAD_ADDR(error))
56093+ goto out_close;
56094+ }
56095 }
56096
56097 error = load_addr;
56098@@ -538,6 +569,336 @@ out:
56099 return error;
56100 }
56101
56102+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56103+#ifdef CONFIG_PAX_SOFTMODE
56104+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56105+{
56106+ unsigned long pax_flags = 0UL;
56107+
56108+#ifdef CONFIG_PAX_PAGEEXEC
56109+ if (elf_phdata->p_flags & PF_PAGEEXEC)
56110+ pax_flags |= MF_PAX_PAGEEXEC;
56111+#endif
56112+
56113+#ifdef CONFIG_PAX_SEGMEXEC
56114+ if (elf_phdata->p_flags & PF_SEGMEXEC)
56115+ pax_flags |= MF_PAX_SEGMEXEC;
56116+#endif
56117+
56118+#ifdef CONFIG_PAX_EMUTRAMP
56119+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56120+ pax_flags |= MF_PAX_EMUTRAMP;
56121+#endif
56122+
56123+#ifdef CONFIG_PAX_MPROTECT
56124+ if (elf_phdata->p_flags & PF_MPROTECT)
56125+ pax_flags |= MF_PAX_MPROTECT;
56126+#endif
56127+
56128+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56129+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56130+ pax_flags |= MF_PAX_RANDMMAP;
56131+#endif
56132+
56133+ return pax_flags;
56134+}
56135+#endif
56136+
56137+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56138+{
56139+ unsigned long pax_flags = 0UL;
56140+
56141+#ifdef CONFIG_PAX_PAGEEXEC
56142+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56143+ pax_flags |= MF_PAX_PAGEEXEC;
56144+#endif
56145+
56146+#ifdef CONFIG_PAX_SEGMEXEC
56147+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56148+ pax_flags |= MF_PAX_SEGMEXEC;
56149+#endif
56150+
56151+#ifdef CONFIG_PAX_EMUTRAMP
56152+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56153+ pax_flags |= MF_PAX_EMUTRAMP;
56154+#endif
56155+
56156+#ifdef CONFIG_PAX_MPROTECT
56157+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56158+ pax_flags |= MF_PAX_MPROTECT;
56159+#endif
56160+
56161+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56162+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56163+ pax_flags |= MF_PAX_RANDMMAP;
56164+#endif
56165+
56166+ return pax_flags;
56167+}
56168+#endif
56169+
56170+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56171+#ifdef CONFIG_PAX_SOFTMODE
56172+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56173+{
56174+ unsigned long pax_flags = 0UL;
56175+
56176+#ifdef CONFIG_PAX_PAGEEXEC
56177+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56178+ pax_flags |= MF_PAX_PAGEEXEC;
56179+#endif
56180+
56181+#ifdef CONFIG_PAX_SEGMEXEC
56182+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56183+ pax_flags |= MF_PAX_SEGMEXEC;
56184+#endif
56185+
56186+#ifdef CONFIG_PAX_EMUTRAMP
56187+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56188+ pax_flags |= MF_PAX_EMUTRAMP;
56189+#endif
56190+
56191+#ifdef CONFIG_PAX_MPROTECT
56192+ if (pax_flags_softmode & MF_PAX_MPROTECT)
56193+ pax_flags |= MF_PAX_MPROTECT;
56194+#endif
56195+
56196+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56197+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56198+ pax_flags |= MF_PAX_RANDMMAP;
56199+#endif
56200+
56201+ return pax_flags;
56202+}
56203+#endif
56204+
56205+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56206+{
56207+ unsigned long pax_flags = 0UL;
56208+
56209+#ifdef CONFIG_PAX_PAGEEXEC
56210+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56211+ pax_flags |= MF_PAX_PAGEEXEC;
56212+#endif
56213+
56214+#ifdef CONFIG_PAX_SEGMEXEC
56215+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56216+ pax_flags |= MF_PAX_SEGMEXEC;
56217+#endif
56218+
56219+#ifdef CONFIG_PAX_EMUTRAMP
56220+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56221+ pax_flags |= MF_PAX_EMUTRAMP;
56222+#endif
56223+
56224+#ifdef CONFIG_PAX_MPROTECT
56225+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56226+ pax_flags |= MF_PAX_MPROTECT;
56227+#endif
56228+
56229+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56230+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56231+ pax_flags |= MF_PAX_RANDMMAP;
56232+#endif
56233+
56234+ return pax_flags;
56235+}
56236+#endif
56237+
56238+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56239+static unsigned long pax_parse_defaults(void)
56240+{
56241+ unsigned long pax_flags = 0UL;
56242+
56243+#ifdef CONFIG_PAX_SOFTMODE
56244+ if (pax_softmode)
56245+ return pax_flags;
56246+#endif
56247+
56248+#ifdef CONFIG_PAX_PAGEEXEC
56249+ pax_flags |= MF_PAX_PAGEEXEC;
56250+#endif
56251+
56252+#ifdef CONFIG_PAX_SEGMEXEC
56253+ pax_flags |= MF_PAX_SEGMEXEC;
56254+#endif
56255+
56256+#ifdef CONFIG_PAX_MPROTECT
56257+ pax_flags |= MF_PAX_MPROTECT;
56258+#endif
56259+
56260+#ifdef CONFIG_PAX_RANDMMAP
56261+ if (randomize_va_space)
56262+ pax_flags |= MF_PAX_RANDMMAP;
56263+#endif
56264+
56265+ return pax_flags;
56266+}
56267+
56268+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56269+{
56270+ unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56271+
56272+#ifdef CONFIG_PAX_EI_PAX
56273+
56274+#ifdef CONFIG_PAX_SOFTMODE
56275+ if (pax_softmode)
56276+ return pax_flags;
56277+#endif
56278+
56279+ pax_flags = 0UL;
56280+
56281+#ifdef CONFIG_PAX_PAGEEXEC
56282+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56283+ pax_flags |= MF_PAX_PAGEEXEC;
56284+#endif
56285+
56286+#ifdef CONFIG_PAX_SEGMEXEC
56287+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56288+ pax_flags |= MF_PAX_SEGMEXEC;
56289+#endif
56290+
56291+#ifdef CONFIG_PAX_EMUTRAMP
56292+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56293+ pax_flags |= MF_PAX_EMUTRAMP;
56294+#endif
56295+
56296+#ifdef CONFIG_PAX_MPROTECT
56297+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56298+ pax_flags |= MF_PAX_MPROTECT;
56299+#endif
56300+
56301+#ifdef CONFIG_PAX_ASLR
56302+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56303+ pax_flags |= MF_PAX_RANDMMAP;
56304+#endif
56305+
56306+#endif
56307+
56308+ return pax_flags;
56309+
56310+}
56311+
56312+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56313+{
56314+
56315+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56316+ unsigned long i;
56317+
56318+ for (i = 0UL; i < elf_ex->e_phnum; i++)
56319+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56320+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56321+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56322+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56323+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56324+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56325+ return PAX_PARSE_FLAGS_FALLBACK;
56326+
56327+#ifdef CONFIG_PAX_SOFTMODE
56328+ if (pax_softmode)
56329+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56330+ else
56331+#endif
56332+
56333+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56334+ break;
56335+ }
56336+#endif
56337+
56338+ return PAX_PARSE_FLAGS_FALLBACK;
56339+}
56340+
56341+static unsigned long pax_parse_xattr_pax(struct file * const file)
56342+{
56343+
56344+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56345+ ssize_t xattr_size, i;
56346+ unsigned char xattr_value[sizeof("pemrs") - 1];
56347+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56348+
56349+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56350+ if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56351+ return PAX_PARSE_FLAGS_FALLBACK;
56352+
56353+ for (i = 0; i < xattr_size; i++)
56354+ switch (xattr_value[i]) {
56355+ default:
56356+ return PAX_PARSE_FLAGS_FALLBACK;
56357+
56358+#define parse_flag(option1, option2, flag) \
56359+ case option1: \
56360+ if (pax_flags_hardmode & MF_PAX_##flag) \
56361+ return PAX_PARSE_FLAGS_FALLBACK;\
56362+ pax_flags_hardmode |= MF_PAX_##flag; \
56363+ break; \
56364+ case option2: \
56365+ if (pax_flags_softmode & MF_PAX_##flag) \
56366+ return PAX_PARSE_FLAGS_FALLBACK;\
56367+ pax_flags_softmode |= MF_PAX_##flag; \
56368+ break;
56369+
56370+ parse_flag('p', 'P', PAGEEXEC);
56371+ parse_flag('e', 'E', EMUTRAMP);
56372+ parse_flag('m', 'M', MPROTECT);
56373+ parse_flag('r', 'R', RANDMMAP);
56374+ parse_flag('s', 'S', SEGMEXEC);
56375+
56376+#undef parse_flag
56377+ }
56378+
56379+ if (pax_flags_hardmode & pax_flags_softmode)
56380+ return PAX_PARSE_FLAGS_FALLBACK;
56381+
56382+#ifdef CONFIG_PAX_SOFTMODE
56383+ if (pax_softmode)
56384+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56385+ else
56386+#endif
56387+
56388+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56389+#else
56390+ return PAX_PARSE_FLAGS_FALLBACK;
56391+#endif
56392+
56393+}
56394+
56395+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56396+{
56397+ unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56398+
56399+ pax_flags = pax_parse_defaults();
56400+ ei_pax_flags = pax_parse_ei_pax(elf_ex);
56401+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56402+ xattr_pax_flags = pax_parse_xattr_pax(file);
56403+
56404+ if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56405+ xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56406+ pt_pax_flags != xattr_pax_flags)
56407+ return -EINVAL;
56408+ if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56409+ pax_flags = xattr_pax_flags;
56410+ else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56411+ pax_flags = pt_pax_flags;
56412+ else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56413+ pax_flags = ei_pax_flags;
56414+
56415+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56416+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56417+ if ((__supported_pte_mask & _PAGE_NX))
56418+ pax_flags &= ~MF_PAX_SEGMEXEC;
56419+ else
56420+ pax_flags &= ~MF_PAX_PAGEEXEC;
56421+ }
56422+#endif
56423+
56424+ if (0 > pax_check_flags(&pax_flags))
56425+ return -EINVAL;
56426+
56427+ current->mm->pax_flags = pax_flags;
56428+ return 0;
56429+}
56430+#endif
56431+
56432 /*
56433 * These are the functions used to load ELF style executables and shared
56434 * libraries. There is no binary dependent code anywhere else.
56435@@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56436 {
56437 unsigned int random_variable = 0;
56438
56439+#ifdef CONFIG_PAX_RANDUSTACK
56440+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56441+ return stack_top - current->mm->delta_stack;
56442+#endif
56443+
56444 if ((current->flags & PF_RANDOMIZE) &&
56445 !(current->personality & ADDR_NO_RANDOMIZE)) {
56446 random_variable = get_random_int() & STACK_RND_MASK;
56447@@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56448 unsigned long load_addr = 0, load_bias = 0;
56449 int load_addr_set = 0;
56450 char * elf_interpreter = NULL;
56451- unsigned long error;
56452+ unsigned long error = 0;
56453 struct elf_phdr *elf_ppnt, *elf_phdata;
56454 unsigned long elf_bss, elf_brk;
56455 int retval, i;
56456@@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
56457 unsigned long start_code, end_code, start_data, end_data;
56458 unsigned long reloc_func_desc __maybe_unused = 0;
56459 int executable_stack = EXSTACK_DEFAULT;
56460- unsigned long def_flags = 0;
56461 struct pt_regs *regs = current_pt_regs();
56462 struct {
56463 struct elfhdr elf_ex;
56464 struct elfhdr interp_elf_ex;
56465 } *loc;
56466+ unsigned long pax_task_size;
56467
56468 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56469 if (!loc) {
56470@@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
56471 goto out_free_dentry;
56472
56473 /* OK, This is the point of no return */
56474- current->mm->def_flags = def_flags;
56475+ current->mm->def_flags = 0;
56476
56477 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56478 may depend on the personality. */
56479 SET_PERSONALITY(loc->elf_ex);
56480+
56481+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56482+ current->mm->pax_flags = 0UL;
56483+#endif
56484+
56485+#ifdef CONFIG_PAX_DLRESOLVE
56486+ current->mm->call_dl_resolve = 0UL;
56487+#endif
56488+
56489+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56490+ current->mm->call_syscall = 0UL;
56491+#endif
56492+
56493+#ifdef CONFIG_PAX_ASLR
56494+ current->mm->delta_mmap = 0UL;
56495+ current->mm->delta_stack = 0UL;
56496+#endif
56497+
56498+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56499+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56500+ send_sig(SIGKILL, current, 0);
56501+ goto out_free_dentry;
56502+ }
56503+#endif
56504+
56505+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56506+ pax_set_initial_flags(bprm);
56507+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56508+ if (pax_set_initial_flags_func)
56509+ (pax_set_initial_flags_func)(bprm);
56510+#endif
56511+
56512+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56513+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56514+ current->mm->context.user_cs_limit = PAGE_SIZE;
56515+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56516+ }
56517+#endif
56518+
56519+#ifdef CONFIG_PAX_SEGMEXEC
56520+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56521+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56522+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56523+ pax_task_size = SEGMEXEC_TASK_SIZE;
56524+ current->mm->def_flags |= VM_NOHUGEPAGE;
56525+ } else
56526+#endif
56527+
56528+ pax_task_size = TASK_SIZE;
56529+
56530+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56531+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56532+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56533+ put_cpu();
56534+ }
56535+#endif
56536+
56537+#ifdef CONFIG_PAX_ASLR
56538+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56539+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56540+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56541+ }
56542+#endif
56543+
56544+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56545+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56546+ executable_stack = EXSTACK_DISABLE_X;
56547+ current->personality &= ~READ_IMPLIES_EXEC;
56548+ } else
56549+#endif
56550+
56551 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56552 current->personality |= READ_IMPLIES_EXEC;
56553
56554@@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56555 #else
56556 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56557 #endif
56558+
56559+#ifdef CONFIG_PAX_RANDMMAP
56560+ /* PaX: randomize base address at the default exe base if requested */
56561+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56562+#ifdef CONFIG_SPARC64
56563+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56564+#else
56565+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56566+#endif
56567+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56568+ elf_flags |= MAP_FIXED;
56569+ }
56570+#endif
56571+
56572 }
56573
56574 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56575@@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56576 * allowed task size. Note that p_filesz must always be
56577 * <= p_memsz so it is only necessary to check p_memsz.
56578 */
56579- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56580- elf_ppnt->p_memsz > TASK_SIZE ||
56581- TASK_SIZE - elf_ppnt->p_memsz < k) {
56582+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56583+ elf_ppnt->p_memsz > pax_task_size ||
56584+ pax_task_size - elf_ppnt->p_memsz < k) {
56585 /* set_brk can never work. Avoid overflows. */
56586 send_sig(SIGKILL, current, 0);
56587 retval = -EINVAL;
56588@@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56589 goto out_free_dentry;
56590 }
56591 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56592- send_sig(SIGSEGV, current, 0);
56593- retval = -EFAULT; /* Nobody gets to see this, but.. */
56594- goto out_free_dentry;
56595+ /*
56596+ * This bss-zeroing can fail if the ELF
56597+ * file specifies odd protections. So
56598+ * we don't check the return value
56599+ */
56600 }
56601
56602+#ifdef CONFIG_PAX_RANDMMAP
56603+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56604+ unsigned long start, size, flags;
56605+ vm_flags_t vm_flags;
56606+
56607+ start = ELF_PAGEALIGN(elf_brk);
56608+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56609+ flags = MAP_FIXED | MAP_PRIVATE;
56610+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56611+
56612+ down_write(&current->mm->mmap_sem);
56613+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56614+ retval = -ENOMEM;
56615+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56616+// if (current->personality & ADDR_NO_RANDOMIZE)
56617+// vm_flags |= VM_READ | VM_MAYREAD;
56618+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56619+ retval = IS_ERR_VALUE(start) ? start : 0;
56620+ }
56621+ up_write(&current->mm->mmap_sem);
56622+ if (retval == 0)
56623+ retval = set_brk(start + size, start + size + PAGE_SIZE);
56624+ if (retval < 0) {
56625+ send_sig(SIGKILL, current, 0);
56626+ goto out_free_dentry;
56627+ }
56628+ }
56629+#endif
56630+
56631 if (elf_interpreter) {
56632- unsigned long interp_map_addr = 0;
56633-
56634 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56635 interpreter,
56636- &interp_map_addr,
56637 load_bias);
56638 if (!IS_ERR((void *)elf_entry)) {
56639 /*
56640@@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56641 * Decide what to dump of a segment, part, all or none.
56642 */
56643 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56644- unsigned long mm_flags)
56645+ unsigned long mm_flags, long signr)
56646 {
56647 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
56648
56649@@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
56650 if (vma->vm_file == NULL)
56651 return 0;
56652
56653- if (FILTER(MAPPED_PRIVATE))
56654+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
56655 goto whole;
56656
56657 /*
56658@@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
56659 {
56660 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
56661 int i = 0;
56662- do
56663+ do {
56664 i += 2;
56665- while (auxv[i - 2] != AT_NULL);
56666+ } while (auxv[i - 2] != AT_NULL);
56667 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
56668 }
56669
56670@@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
56671 {
56672 mm_segment_t old_fs = get_fs();
56673 set_fs(KERNEL_DS);
56674- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
56675+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
56676 set_fs(old_fs);
56677 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
56678 }
56679@@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
56680 }
56681
56682 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
56683- unsigned long mm_flags)
56684+ struct coredump_params *cprm)
56685 {
56686 struct vm_area_struct *vma;
56687 size_t size = 0;
56688
56689 for (vma = first_vma(current, gate_vma); vma != NULL;
56690 vma = next_vma(vma, gate_vma))
56691- size += vma_dump_size(vma, mm_flags);
56692+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56693 return size;
56694 }
56695
56696@@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56697
56698 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
56699
56700- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
56701+ offset += elf_core_vma_data_size(gate_vma, cprm);
56702 offset += elf_core_extra_data_size();
56703 e_shoff = offset;
56704
56705@@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56706 phdr.p_offset = offset;
56707 phdr.p_vaddr = vma->vm_start;
56708 phdr.p_paddr = 0;
56709- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
56710+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56711 phdr.p_memsz = vma->vm_end - vma->vm_start;
56712 offset += phdr.p_filesz;
56713 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
56714@@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
56715 unsigned long addr;
56716 unsigned long end;
56717
56718- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
56719+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
56720
56721 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
56722 struct page *page;
56723@@ -2202,6 +2681,167 @@ out:
56724
56725 #endif /* CONFIG_ELF_CORE */
56726
56727+#ifdef CONFIG_PAX_MPROTECT
56728+/* PaX: non-PIC ELF libraries need relocations on their executable segments
56729+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
56730+ * we'll remove VM_MAYWRITE for good on RELRO segments.
56731+ *
56732+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
56733+ * basis because we want to allow the common case and not the special ones.
56734+ */
56735+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
56736+{
56737+ struct elfhdr elf_h;
56738+ struct elf_phdr elf_p;
56739+ unsigned long i;
56740+ unsigned long oldflags;
56741+ bool is_textrel_rw, is_textrel_rx, is_relro;
56742+
56743+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
56744+ return;
56745+
56746+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
56747+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
56748+
56749+#ifdef CONFIG_PAX_ELFRELOCS
56750+ /* possible TEXTREL */
56751+ is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56752+ is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56753+#else
56754+ is_textrel_rw = false;
56755+ is_textrel_rx = false;
56756+#endif
56757+
56758+ /* possible RELRO */
56759+ is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56760+
56761+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56762+ return;
56763+
56764+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56765+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56766+
56767+#ifdef CONFIG_PAX_ETEXECRELOCS
56768+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56769+#else
56770+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56771+#endif
56772+
56773+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56774+ !elf_check_arch(&elf_h) ||
56775+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56776+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56777+ return;
56778+
56779+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56780+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56781+ return;
56782+ switch (elf_p.p_type) {
56783+ case PT_DYNAMIC:
56784+ if (!is_textrel_rw && !is_textrel_rx)
56785+ continue;
56786+ i = 0UL;
56787+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56788+ elf_dyn dyn;
56789+
56790+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56791+ break;
56792+ if (dyn.d_tag == DT_NULL)
56793+ break;
56794+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56795+ gr_log_textrel(vma);
56796+ if (is_textrel_rw)
56797+ vma->vm_flags |= VM_MAYWRITE;
56798+ else
56799+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56800+ vma->vm_flags &= ~VM_MAYWRITE;
56801+ break;
56802+ }
56803+ i++;
56804+ }
56805+ is_textrel_rw = false;
56806+ is_textrel_rx = false;
56807+ continue;
56808+
56809+ case PT_GNU_RELRO:
56810+ if (!is_relro)
56811+ continue;
56812+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56813+ vma->vm_flags &= ~VM_MAYWRITE;
56814+ is_relro = false;
56815+ continue;
56816+
56817+#ifdef CONFIG_PAX_PT_PAX_FLAGS
56818+ case PT_PAX_FLAGS: {
56819+ const char *msg_mprotect = "", *msg_emutramp = "";
56820+ char *buffer_lib, *buffer_exe;
56821+
56822+ if (elf_p.p_flags & PF_NOMPROTECT)
56823+ msg_mprotect = "MPROTECT disabled";
56824+
56825+#ifdef CONFIG_PAX_EMUTRAMP
56826+ if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56827+ msg_emutramp = "EMUTRAMP enabled";
56828+#endif
56829+
56830+ if (!msg_mprotect[0] && !msg_emutramp[0])
56831+ continue;
56832+
56833+ if (!printk_ratelimit())
56834+ continue;
56835+
56836+ buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56837+ buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56838+ if (buffer_lib && buffer_exe) {
56839+ char *path_lib, *path_exe;
56840+
56841+ path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56842+ path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56843+
56844+ pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56845+ (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56846+
56847+ }
56848+ free_page((unsigned long)buffer_exe);
56849+ free_page((unsigned long)buffer_lib);
56850+ continue;
56851+ }
56852+#endif
56853+
56854+ }
56855+ }
56856+}
56857+#endif
56858+
56859+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56860+
56861+extern int grsec_enable_log_rwxmaps;
56862+
56863+static void elf_handle_mmap(struct file *file)
56864+{
56865+ struct elfhdr elf_h;
56866+ struct elf_phdr elf_p;
56867+ unsigned long i;
56868+
56869+ if (!grsec_enable_log_rwxmaps)
56870+ return;
56871+
56872+ if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56873+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56874+ (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56875+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56876+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56877+ return;
56878+
56879+ for (i = 0UL; i < elf_h.e_phnum; i++) {
56880+ if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56881+ return;
56882+ if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56883+ gr_log_ptgnustack(file);
56884+ }
56885+}
56886+#endif
56887+
56888 static int __init init_elf_binfmt(void)
56889 {
56890 register_binfmt(&elf_format);
56891diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56892index d50bbe5..af3b649 100644
56893--- a/fs/binfmt_flat.c
56894+++ b/fs/binfmt_flat.c
56895@@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56896 realdatastart = (unsigned long) -ENOMEM;
56897 printk("Unable to allocate RAM for process data, errno %d\n",
56898 (int)-realdatastart);
56899+ down_write(&current->mm->mmap_sem);
56900 vm_munmap(textpos, text_len);
56901+ up_write(&current->mm->mmap_sem);
56902 ret = realdatastart;
56903 goto err;
56904 }
56905@@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56906 }
56907 if (IS_ERR_VALUE(result)) {
56908 printk("Unable to read data+bss, errno %d\n", (int)-result);
56909+ down_write(&current->mm->mmap_sem);
56910 vm_munmap(textpos, text_len);
56911 vm_munmap(realdatastart, len);
56912+ up_write(&current->mm->mmap_sem);
56913 ret = result;
56914 goto err;
56915 }
56916@@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56917 }
56918 if (IS_ERR_VALUE(result)) {
56919 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56920+ down_write(&current->mm->mmap_sem);
56921 vm_munmap(textpos, text_len + data_len + extra +
56922 MAX_SHARED_LIBS * sizeof(unsigned long));
56923+ up_write(&current->mm->mmap_sem);
56924 ret = result;
56925 goto err;
56926 }
56927diff --git a/fs/bio.c b/fs/bio.c
56928index 33d79a4..c3c9893 100644
56929--- a/fs/bio.c
56930+++ b/fs/bio.c
56931@@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56932 /*
56933 * Overflow, abort
56934 */
56935- if (end < start)
56936+ if (end < start || end - start > INT_MAX - nr_pages)
56937 return ERR_PTR(-EINVAL);
56938
56939 nr_pages += end - start;
56940@@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56941 /*
56942 * Overflow, abort
56943 */
56944- if (end < start)
56945+ if (end < start || end - start > INT_MAX - nr_pages)
56946 return ERR_PTR(-EINVAL);
56947
56948 nr_pages += end - start;
56949@@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56950 const int read = bio_data_dir(bio) == READ;
56951 struct bio_map_data *bmd = bio->bi_private;
56952 int i;
56953- char *p = bmd->sgvecs[0].iov_base;
56954+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56955
56956 bio_for_each_segment_all(bvec, bio, i) {
56957 char *addr = page_address(bvec->bv_page);
56958diff --git a/fs/block_dev.c b/fs/block_dev.c
56959index 1e86823..8e34695 100644
56960--- a/fs/block_dev.c
56961+++ b/fs/block_dev.c
56962@@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56963 else if (bdev->bd_contains == bdev)
56964 return true; /* is a whole device which isn't held */
56965
56966- else if (whole->bd_holder == bd_may_claim)
56967+ else if (whole->bd_holder == (void *)bd_may_claim)
56968 return true; /* is a partition of a device that is being partitioned */
56969 else if (whole->bd_holder != NULL)
56970 return false; /* is a partition of a held device */
56971diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56972index 3de01b4..6547c39 100644
56973--- a/fs/btrfs/ctree.c
56974+++ b/fs/btrfs/ctree.c
56975@@ -1217,9 +1217,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56976 free_extent_buffer(buf);
56977 add_root_to_dirty_list(root);
56978 } else {
56979- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56980- parent_start = parent->start;
56981- else
56982+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56983+ if (parent)
56984+ parent_start = parent->start;
56985+ else
56986+ parent_start = 0;
56987+ } else
56988 parent_start = 0;
56989
56990 WARN_ON(trans->transid != btrfs_header_generation(parent));
56991diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56992index 8d292fb..bc205c2 100644
56993--- a/fs/btrfs/delayed-inode.c
56994+++ b/fs/btrfs/delayed-inode.c
56995@@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56996
56997 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56998 {
56999- int seq = atomic_inc_return(&delayed_root->items_seq);
57000+ int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57001 if ((atomic_dec_return(&delayed_root->items) <
57002 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57003 waitqueue_active(&delayed_root->wait))
57004@@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57005 static int refs_newer(struct btrfs_delayed_root *delayed_root,
57006 int seq, int count)
57007 {
57008- int val = atomic_read(&delayed_root->items_seq);
57009+ int val = atomic_read_unchecked(&delayed_root->items_seq);
57010
57011 if (val < seq || val >= seq + count)
57012 return 1;
57013@@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57014 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
57015 return;
57016
57017- seq = atomic_read(&delayed_root->items_seq);
57018+ seq = atomic_read_unchecked(&delayed_root->items_seq);
57019
57020 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
57021 int ret;
57022diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57023index a4b38f9..f86a509 100644
57024--- a/fs/btrfs/delayed-inode.h
57025+++ b/fs/btrfs/delayed-inode.h
57026@@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57027 */
57028 struct list_head prepare_list;
57029 atomic_t items; /* for delayed items */
57030- atomic_t items_seq; /* for delayed items */
57031+ atomic_unchecked_t items_seq; /* for delayed items */
57032 int nodes; /* for delayed nodes */
57033 wait_queue_head_t wait;
57034 };
57035@@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
57036 struct btrfs_delayed_root *delayed_root)
57037 {
57038 atomic_set(&delayed_root->items, 0);
57039- atomic_set(&delayed_root->items_seq, 0);
57040+ atomic_set_unchecked(&delayed_root->items_seq, 0);
57041 delayed_root->nodes = 0;
57042 spin_lock_init(&delayed_root->lock);
57043 init_waitqueue_head(&delayed_root->wait);
57044diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57045index 9f831bb..14afde5 100644
57046--- a/fs/btrfs/ioctl.c
57047+++ b/fs/btrfs/ioctl.c
57048@@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57049 for (i = 0; i < num_types; i++) {
57050 struct btrfs_space_info *tmp;
57051
57052+ /* Don't copy in more than we allocated */
57053 if (!slot_count)
57054 break;
57055
57056+ slot_count--;
57057+
57058 info = NULL;
57059 rcu_read_lock();
57060 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57061@@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57062 memcpy(dest, &space, sizeof(space));
57063 dest++;
57064 space_args.total_spaces++;
57065- slot_count--;
57066 }
57067- if (!slot_count)
57068- break;
57069 }
57070 up_read(&info->groups_sem);
57071 }
57072diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57073index d71a11d..384e2c4 100644
57074--- a/fs/btrfs/super.c
57075+++ b/fs/btrfs/super.c
57076@@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57077 function, line, errstr);
57078 return;
57079 }
57080- ACCESS_ONCE(trans->transaction->aborted) = errno;
57081+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57082 /* Wake up anybody who may be waiting on this transaction */
57083 wake_up(&root->fs_info->transaction_wait);
57084 wake_up(&root->fs_info->transaction_blocked_wait);
57085diff --git a/fs/buffer.c b/fs/buffer.c
57086index aeeea65..7651d590 100644
57087--- a/fs/buffer.c
57088+++ b/fs/buffer.c
57089@@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57090 bh_cachep = kmem_cache_create("buffer_head",
57091 sizeof(struct buffer_head), 0,
57092 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57093- SLAB_MEM_SPREAD),
57094+ SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57095 NULL);
57096
57097 /*
57098diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57099index 622f469..e8d2d55 100644
57100--- a/fs/cachefiles/bind.c
57101+++ b/fs/cachefiles/bind.c
57102@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57103 args);
57104
57105 /* start by checking things over */
57106- ASSERT(cache->fstop_percent >= 0 &&
57107- cache->fstop_percent < cache->fcull_percent &&
57108+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
57109 cache->fcull_percent < cache->frun_percent &&
57110 cache->frun_percent < 100);
57111
57112- ASSERT(cache->bstop_percent >= 0 &&
57113- cache->bstop_percent < cache->bcull_percent &&
57114+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
57115 cache->bcull_percent < cache->brun_percent &&
57116 cache->brun_percent < 100);
57117
57118diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57119index 0a1467b..6a53245 100644
57120--- a/fs/cachefiles/daemon.c
57121+++ b/fs/cachefiles/daemon.c
57122@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57123 if (n > buflen)
57124 return -EMSGSIZE;
57125
57126- if (copy_to_user(_buffer, buffer, n) != 0)
57127+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57128 return -EFAULT;
57129
57130 return n;
57131@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57132 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57133 return -EIO;
57134
57135- if (datalen < 0 || datalen > PAGE_SIZE - 1)
57136+ if (datalen > PAGE_SIZE - 1)
57137 return -EOPNOTSUPP;
57138
57139 /* drag the command string into the kernel so we can parse it */
57140@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57141 if (args[0] != '%' || args[1] != '\0')
57142 return -EINVAL;
57143
57144- if (fstop < 0 || fstop >= cache->fcull_percent)
57145+ if (fstop >= cache->fcull_percent)
57146 return cachefiles_daemon_range_error(cache, args);
57147
57148 cache->fstop_percent = fstop;
57149@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57150 if (args[0] != '%' || args[1] != '\0')
57151 return -EINVAL;
57152
57153- if (bstop < 0 || bstop >= cache->bcull_percent)
57154+ if (bstop >= cache->bcull_percent)
57155 return cachefiles_daemon_range_error(cache, args);
57156
57157 cache->bstop_percent = bstop;
57158diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57159index 5349473..d6c0b93 100644
57160--- a/fs/cachefiles/internal.h
57161+++ b/fs/cachefiles/internal.h
57162@@ -59,7 +59,7 @@ struct cachefiles_cache {
57163 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57164 struct rb_root active_nodes; /* active nodes (can't be culled) */
57165 rwlock_t active_lock; /* lock for active_nodes */
57166- atomic_t gravecounter; /* graveyard uniquifier */
57167+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57168 unsigned frun_percent; /* when to stop culling (% files) */
57169 unsigned fcull_percent; /* when to start culling (% files) */
57170 unsigned fstop_percent; /* when to stop allocating (% files) */
57171@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57172 * proc.c
57173 */
57174 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57175-extern atomic_t cachefiles_lookup_histogram[HZ];
57176-extern atomic_t cachefiles_mkdir_histogram[HZ];
57177-extern atomic_t cachefiles_create_histogram[HZ];
57178+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57179+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57180+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57181
57182 extern int __init cachefiles_proc_init(void);
57183 extern void cachefiles_proc_cleanup(void);
57184 static inline
57185-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57186+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57187 {
57188 unsigned long jif = jiffies - start_jif;
57189 if (jif >= HZ)
57190 jif = HZ - 1;
57191- atomic_inc(&histogram[jif]);
57192+ atomic_inc_unchecked(&histogram[jif]);
57193 }
57194
57195 #else
57196diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57197index ca65f39..48921e3 100644
57198--- a/fs/cachefiles/namei.c
57199+++ b/fs/cachefiles/namei.c
57200@@ -317,7 +317,7 @@ try_again:
57201 /* first step is to make up a grave dentry in the graveyard */
57202 sprintf(nbuffer, "%08x%08x",
57203 (uint32_t) get_seconds(),
57204- (uint32_t) atomic_inc_return(&cache->gravecounter));
57205+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57206
57207 /* do the multiway lock magic */
57208 trap = lock_rename(cache->graveyard, dir);
57209diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57210index eccd339..4c1d995 100644
57211--- a/fs/cachefiles/proc.c
57212+++ b/fs/cachefiles/proc.c
57213@@ -14,9 +14,9 @@
57214 #include <linux/seq_file.h>
57215 #include "internal.h"
57216
57217-atomic_t cachefiles_lookup_histogram[HZ];
57218-atomic_t cachefiles_mkdir_histogram[HZ];
57219-atomic_t cachefiles_create_histogram[HZ];
57220+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57221+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57222+atomic_unchecked_t cachefiles_create_histogram[HZ];
57223
57224 /*
57225 * display the latency histogram
57226@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57227 return 0;
57228 default:
57229 index = (unsigned long) v - 3;
57230- x = atomic_read(&cachefiles_lookup_histogram[index]);
57231- y = atomic_read(&cachefiles_mkdir_histogram[index]);
57232- z = atomic_read(&cachefiles_create_histogram[index]);
57233+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57234+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57235+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57236 if (x == 0 && y == 0 && z == 0)
57237 return 0;
57238
57239diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57240index ebaff36..7e3ea26 100644
57241--- a/fs/cachefiles/rdwr.c
57242+++ b/fs/cachefiles/rdwr.c
57243@@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57244 old_fs = get_fs();
57245 set_fs(KERNEL_DS);
57246 ret = file->f_op->write(
57247- file, (const void __user *) data, len, &pos);
57248+ file, (const void __force_user *) data, len, &pos);
57249 set_fs(old_fs);
57250 kunmap(page);
57251 file_end_write(file);
57252diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57253index 2a0bcae..34ec24e 100644
57254--- a/fs/ceph/dir.c
57255+++ b/fs/ceph/dir.c
57256@@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57257 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57258 struct ceph_mds_client *mdsc = fsc->mdsc;
57259 unsigned frag = fpos_frag(ctx->pos);
57260- int off = fpos_off(ctx->pos);
57261+ unsigned int off = fpos_off(ctx->pos);
57262 int err;
57263 u32 ftype;
57264 struct ceph_mds_reply_info_parsed *rinfo;
57265diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57266index 6a0951e..03fac6d 100644
57267--- a/fs/ceph/super.c
57268+++ b/fs/ceph/super.c
57269@@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57270 /*
57271 * construct our own bdi so we can control readahead, etc.
57272 */
57273-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57274+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57275
57276 static int ceph_register_bdi(struct super_block *sb,
57277 struct ceph_fs_client *fsc)
57278@@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
57279 default_backing_dev_info.ra_pages;
57280
57281 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57282- atomic_long_inc_return(&bdi_seq));
57283+ atomic_long_inc_return_unchecked(&bdi_seq));
57284 if (!err)
57285 sb->s_bdi = &fsc->backing_dev_info;
57286 return err;
57287diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57288index f3ac415..3d2420c 100644
57289--- a/fs/cifs/cifs_debug.c
57290+++ b/fs/cifs/cifs_debug.c
57291@@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57292
57293 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57294 #ifdef CONFIG_CIFS_STATS2
57295- atomic_set(&totBufAllocCount, 0);
57296- atomic_set(&totSmBufAllocCount, 0);
57297+ atomic_set_unchecked(&totBufAllocCount, 0);
57298+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57299 #endif /* CONFIG_CIFS_STATS2 */
57300 spin_lock(&cifs_tcp_ses_lock);
57301 list_for_each(tmp1, &cifs_tcp_ses_list) {
57302@@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57303 tcon = list_entry(tmp3,
57304 struct cifs_tcon,
57305 tcon_list);
57306- atomic_set(&tcon->num_smbs_sent, 0);
57307+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57308 if (server->ops->clear_stats)
57309 server->ops->clear_stats(tcon);
57310 }
57311@@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57312 smBufAllocCount.counter, cifs_min_small);
57313 #ifdef CONFIG_CIFS_STATS2
57314 seq_printf(m, "Total Large %d Small %d Allocations\n",
57315- atomic_read(&totBufAllocCount),
57316- atomic_read(&totSmBufAllocCount));
57317+ atomic_read_unchecked(&totBufAllocCount),
57318+ atomic_read_unchecked(&totSmBufAllocCount));
57319 #endif /* CONFIG_CIFS_STATS2 */
57320
57321 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57322@@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57323 if (tcon->need_reconnect)
57324 seq_puts(m, "\tDISCONNECTED ");
57325 seq_printf(m, "\nSMBs: %d",
57326- atomic_read(&tcon->num_smbs_sent));
57327+ atomic_read_unchecked(&tcon->num_smbs_sent));
57328 if (server->ops->print_stats)
57329 server->ops->print_stats(m, tcon);
57330 }
57331diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57332index 849f613..eae6dec 100644
57333--- a/fs/cifs/cifsfs.c
57334+++ b/fs/cifs/cifsfs.c
57335@@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
57336 */
57337 cifs_req_cachep = kmem_cache_create("cifs_request",
57338 CIFSMaxBufSize + max_hdr_size, 0,
57339- SLAB_HWCACHE_ALIGN, NULL);
57340+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57341 if (cifs_req_cachep == NULL)
57342 return -ENOMEM;
57343
57344@@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
57345 efficient to alloc 1 per page off the slab compared to 17K (5page)
57346 alloc of large cifs buffers even when page debugging is on */
57347 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57348- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57349+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57350 NULL);
57351 if (cifs_sm_req_cachep == NULL) {
57352 mempool_destroy(cifs_req_poolp);
57353@@ -1168,8 +1168,8 @@ init_cifs(void)
57354 atomic_set(&bufAllocCount, 0);
57355 atomic_set(&smBufAllocCount, 0);
57356 #ifdef CONFIG_CIFS_STATS2
57357- atomic_set(&totBufAllocCount, 0);
57358- atomic_set(&totSmBufAllocCount, 0);
57359+ atomic_set_unchecked(&totBufAllocCount, 0);
57360+ atomic_set_unchecked(&totSmBufAllocCount, 0);
57361 #endif /* CONFIG_CIFS_STATS2 */
57362
57363 atomic_set(&midCount, 0);
57364diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57365index 579c6d5..95b6d03353 100644
57366--- a/fs/cifs/cifsglob.h
57367+++ b/fs/cifs/cifsglob.h
57368@@ -797,35 +797,35 @@ struct cifs_tcon {
57369 __u16 Flags; /* optional support bits */
57370 enum statusEnum tidStatus;
57371 #ifdef CONFIG_CIFS_STATS
57372- atomic_t num_smbs_sent;
57373+ atomic_unchecked_t num_smbs_sent;
57374 union {
57375 struct {
57376- atomic_t num_writes;
57377- atomic_t num_reads;
57378- atomic_t num_flushes;
57379- atomic_t num_oplock_brks;
57380- atomic_t num_opens;
57381- atomic_t num_closes;
57382- atomic_t num_deletes;
57383- atomic_t num_mkdirs;
57384- atomic_t num_posixopens;
57385- atomic_t num_posixmkdirs;
57386- atomic_t num_rmdirs;
57387- atomic_t num_renames;
57388- atomic_t num_t2renames;
57389- atomic_t num_ffirst;
57390- atomic_t num_fnext;
57391- atomic_t num_fclose;
57392- atomic_t num_hardlinks;
57393- atomic_t num_symlinks;
57394- atomic_t num_locks;
57395- atomic_t num_acl_get;
57396- atomic_t num_acl_set;
57397+ atomic_unchecked_t num_writes;
57398+ atomic_unchecked_t num_reads;
57399+ atomic_unchecked_t num_flushes;
57400+ atomic_unchecked_t num_oplock_brks;
57401+ atomic_unchecked_t num_opens;
57402+ atomic_unchecked_t num_closes;
57403+ atomic_unchecked_t num_deletes;
57404+ atomic_unchecked_t num_mkdirs;
57405+ atomic_unchecked_t num_posixopens;
57406+ atomic_unchecked_t num_posixmkdirs;
57407+ atomic_unchecked_t num_rmdirs;
57408+ atomic_unchecked_t num_renames;
57409+ atomic_unchecked_t num_t2renames;
57410+ atomic_unchecked_t num_ffirst;
57411+ atomic_unchecked_t num_fnext;
57412+ atomic_unchecked_t num_fclose;
57413+ atomic_unchecked_t num_hardlinks;
57414+ atomic_unchecked_t num_symlinks;
57415+ atomic_unchecked_t num_locks;
57416+ atomic_unchecked_t num_acl_get;
57417+ atomic_unchecked_t num_acl_set;
57418 } cifs_stats;
57419 #ifdef CONFIG_CIFS_SMB2
57420 struct {
57421- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57422- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57423+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57424+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57425 } smb2_stats;
57426 #endif /* CONFIG_CIFS_SMB2 */
57427 } stats;
57428@@ -1155,7 +1155,7 @@ convert_delimiter(char *path, char delim)
57429 }
57430
57431 #ifdef CONFIG_CIFS_STATS
57432-#define cifs_stats_inc atomic_inc
57433+#define cifs_stats_inc atomic_inc_unchecked
57434
57435 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57436 unsigned int bytes)
57437@@ -1521,8 +1521,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57438 /* Various Debug counters */
57439 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57440 #ifdef CONFIG_CIFS_STATS2
57441-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57442-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57443+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57444+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57445 #endif
57446 GLOBAL_EXTERN atomic_t smBufAllocCount;
57447 GLOBAL_EXTERN atomic_t midCount;
57448diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57449index a1c9ead..63e4c62 100644
57450--- a/fs/cifs/file.c
57451+++ b/fs/cifs/file.c
57452@@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57453 index = mapping->writeback_index; /* Start from prev offset */
57454 end = -1;
57455 } else {
57456- index = wbc->range_start >> PAGE_CACHE_SHIFT;
57457- end = wbc->range_end >> PAGE_CACHE_SHIFT;
57458- if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57459+ if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57460 range_whole = true;
57461+ index = 0;
57462+ end = ULONG_MAX;
57463+ } else {
57464+ index = wbc->range_start >> PAGE_CACHE_SHIFT;
57465+ end = wbc->range_end >> PAGE_CACHE_SHIFT;
57466+ }
57467 scanned = true;
57468 }
57469 retry:
57470diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57471index 2f9f379..43f8025 100644
57472--- a/fs/cifs/misc.c
57473+++ b/fs/cifs/misc.c
57474@@ -170,7 +170,7 @@ cifs_buf_get(void)
57475 memset(ret_buf, 0, buf_size + 3);
57476 atomic_inc(&bufAllocCount);
57477 #ifdef CONFIG_CIFS_STATS2
57478- atomic_inc(&totBufAllocCount);
57479+ atomic_inc_unchecked(&totBufAllocCount);
57480 #endif /* CONFIG_CIFS_STATS2 */
57481 }
57482
57483@@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57484 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57485 atomic_inc(&smBufAllocCount);
57486 #ifdef CONFIG_CIFS_STATS2
57487- atomic_inc(&totSmBufAllocCount);
57488+ atomic_inc_unchecked(&totSmBufAllocCount);
57489 #endif /* CONFIG_CIFS_STATS2 */
57490
57491 }
57492diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57493index ffc9ef9..b3c992b 100644
57494--- a/fs/cifs/smb1ops.c
57495+++ b/fs/cifs/smb1ops.c
57496@@ -609,27 +609,27 @@ static void
57497 cifs_clear_stats(struct cifs_tcon *tcon)
57498 {
57499 #ifdef CONFIG_CIFS_STATS
57500- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57501- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57502- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57503- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57504- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57505- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57506- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57507- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57508- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57509- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57510- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57511- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57512- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57513- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57514- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57515- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57516- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57517- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57518- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57519- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57520- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57521+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57522+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57523+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57524+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57525+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57526+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57527+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57528+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57529+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57530+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57531+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57532+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57533+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57534+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57535+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57536+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57537+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57538+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57539+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57540+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57541+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57542 #endif
57543 }
57544
57545@@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57546 {
57547 #ifdef CONFIG_CIFS_STATS
57548 seq_printf(m, " Oplocks breaks: %d",
57549- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57550+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57551 seq_printf(m, "\nReads: %d Bytes: %llu",
57552- atomic_read(&tcon->stats.cifs_stats.num_reads),
57553+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57554 (long long)(tcon->bytes_read));
57555 seq_printf(m, "\nWrites: %d Bytes: %llu",
57556- atomic_read(&tcon->stats.cifs_stats.num_writes),
57557+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57558 (long long)(tcon->bytes_written));
57559 seq_printf(m, "\nFlushes: %d",
57560- atomic_read(&tcon->stats.cifs_stats.num_flushes));
57561+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57562 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57563- atomic_read(&tcon->stats.cifs_stats.num_locks),
57564- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57565- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57566+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57567+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57568+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57569 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57570- atomic_read(&tcon->stats.cifs_stats.num_opens),
57571- atomic_read(&tcon->stats.cifs_stats.num_closes),
57572- atomic_read(&tcon->stats.cifs_stats.num_deletes));
57573+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57574+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57575+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57576 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57577- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57578- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57579+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57580+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57581 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57582- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57583- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57584+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57585+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57586 seq_printf(m, "\nRenames: %d T2 Renames %d",
57587- atomic_read(&tcon->stats.cifs_stats.num_renames),
57588- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57589+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57590+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57591 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57592- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57593- atomic_read(&tcon->stats.cifs_stats.num_fnext),
57594- atomic_read(&tcon->stats.cifs_stats.num_fclose));
57595+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57596+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57597+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57598 #endif
57599 }
57600
57601diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57602index 192f51a..539307e 100644
57603--- a/fs/cifs/smb2ops.c
57604+++ b/fs/cifs/smb2ops.c
57605@@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57606 #ifdef CONFIG_CIFS_STATS
57607 int i;
57608 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57609- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57610- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57611+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57612+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57613 }
57614 #endif
57615 }
57616@@ -405,65 +405,65 @@ static void
57617 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57618 {
57619 #ifdef CONFIG_CIFS_STATS
57620- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57621- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57622+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57623+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
57624 seq_printf(m, "\nNegotiates: %d sent %d failed",
57625- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
57626- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
57627+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
57628+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
57629 seq_printf(m, "\nSessionSetups: %d sent %d failed",
57630- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
57631- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
57632+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
57633+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
57634 seq_printf(m, "\nLogoffs: %d sent %d failed",
57635- atomic_read(&sent[SMB2_LOGOFF_HE]),
57636- atomic_read(&failed[SMB2_LOGOFF_HE]));
57637+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
57638+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
57639 seq_printf(m, "\nTreeConnects: %d sent %d failed",
57640- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
57641- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
57642+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
57643+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
57644 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
57645- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
57646- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
57647+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
57648+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
57649 seq_printf(m, "\nCreates: %d sent %d failed",
57650- atomic_read(&sent[SMB2_CREATE_HE]),
57651- atomic_read(&failed[SMB2_CREATE_HE]));
57652+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
57653+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
57654 seq_printf(m, "\nCloses: %d sent %d failed",
57655- atomic_read(&sent[SMB2_CLOSE_HE]),
57656- atomic_read(&failed[SMB2_CLOSE_HE]));
57657+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
57658+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
57659 seq_printf(m, "\nFlushes: %d sent %d failed",
57660- atomic_read(&sent[SMB2_FLUSH_HE]),
57661- atomic_read(&failed[SMB2_FLUSH_HE]));
57662+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
57663+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
57664 seq_printf(m, "\nReads: %d sent %d failed",
57665- atomic_read(&sent[SMB2_READ_HE]),
57666- atomic_read(&failed[SMB2_READ_HE]));
57667+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
57668+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
57669 seq_printf(m, "\nWrites: %d sent %d failed",
57670- atomic_read(&sent[SMB2_WRITE_HE]),
57671- atomic_read(&failed[SMB2_WRITE_HE]));
57672+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
57673+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
57674 seq_printf(m, "\nLocks: %d sent %d failed",
57675- atomic_read(&sent[SMB2_LOCK_HE]),
57676- atomic_read(&failed[SMB2_LOCK_HE]));
57677+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
57678+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
57679 seq_printf(m, "\nIOCTLs: %d sent %d failed",
57680- atomic_read(&sent[SMB2_IOCTL_HE]),
57681- atomic_read(&failed[SMB2_IOCTL_HE]));
57682+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
57683+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
57684 seq_printf(m, "\nCancels: %d sent %d failed",
57685- atomic_read(&sent[SMB2_CANCEL_HE]),
57686- atomic_read(&failed[SMB2_CANCEL_HE]));
57687+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
57688+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
57689 seq_printf(m, "\nEchos: %d sent %d failed",
57690- atomic_read(&sent[SMB2_ECHO_HE]),
57691- atomic_read(&failed[SMB2_ECHO_HE]));
57692+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
57693+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
57694 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
57695- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
57696- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
57697+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
57698+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
57699 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
57700- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
57701- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
57702+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
57703+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
57704 seq_printf(m, "\nQueryInfos: %d sent %d failed",
57705- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
57706- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
57707+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
57708+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
57709 seq_printf(m, "\nSetInfos: %d sent %d failed",
57710- atomic_read(&sent[SMB2_SET_INFO_HE]),
57711- atomic_read(&failed[SMB2_SET_INFO_HE]));
57712+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
57713+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
57714 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
57715- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
57716- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
57717+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
57718+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
57719 #endif
57720 }
57721
57722diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
57723index 787e171..31dcd0a 100644
57724--- a/fs/cifs/smb2pdu.c
57725+++ b/fs/cifs/smb2pdu.c
57726@@ -2093,8 +2093,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
57727 default:
57728 cifs_dbg(VFS, "info level %u isn't supported\n",
57729 srch_inf->info_level);
57730- rc = -EINVAL;
57731- goto qdir_exit;
57732+ return -EINVAL;
57733 }
57734
57735 req->FileIndex = cpu_to_le32(index);
57736diff --git a/fs/coda/cache.c b/fs/coda/cache.c
57737index 1da168c..8bc7ff6 100644
57738--- a/fs/coda/cache.c
57739+++ b/fs/coda/cache.c
57740@@ -24,7 +24,7 @@
57741 #include "coda_linux.h"
57742 #include "coda_cache.h"
57743
57744-static atomic_t permission_epoch = ATOMIC_INIT(0);
57745+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
57746
57747 /* replace or extend an acl cache hit */
57748 void coda_cache_enter(struct inode *inode, int mask)
57749@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
57750 struct coda_inode_info *cii = ITOC(inode);
57751
57752 spin_lock(&cii->c_lock);
57753- cii->c_cached_epoch = atomic_read(&permission_epoch);
57754+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57755 if (!uid_eq(cii->c_uid, current_fsuid())) {
57756 cii->c_uid = current_fsuid();
57757 cii->c_cached_perm = mask;
57758@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57759 {
57760 struct coda_inode_info *cii = ITOC(inode);
57761 spin_lock(&cii->c_lock);
57762- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57763+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57764 spin_unlock(&cii->c_lock);
57765 }
57766
57767 /* remove all acl caches */
57768 void coda_cache_clear_all(struct super_block *sb)
57769 {
57770- atomic_inc(&permission_epoch);
57771+ atomic_inc_unchecked(&permission_epoch);
57772 }
57773
57774
57775@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57776 spin_lock(&cii->c_lock);
57777 hit = (mask & cii->c_cached_perm) == mask &&
57778 uid_eq(cii->c_uid, current_fsuid()) &&
57779- cii->c_cached_epoch == atomic_read(&permission_epoch);
57780+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57781 spin_unlock(&cii->c_lock);
57782
57783 return hit;
57784diff --git a/fs/compat.c b/fs/compat.c
57785index 6af20de..fec3fbb 100644
57786--- a/fs/compat.c
57787+++ b/fs/compat.c
57788@@ -54,7 +54,7 @@
57789 #include <asm/ioctls.h>
57790 #include "internal.h"
57791
57792-int compat_log = 1;
57793+int compat_log = 0;
57794
57795 int compat_printk(const char *fmt, ...)
57796 {
57797@@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57798
57799 set_fs(KERNEL_DS);
57800 /* The __user pointer cast is valid because of the set_fs() */
57801- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57802+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57803 set_fs(oldfs);
57804 /* truncating is ok because it's a user address */
57805 if (!ret)
57806@@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57807 goto out;
57808
57809 ret = -EINVAL;
57810- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57811+ if (nr_segs > UIO_MAXIOV)
57812 goto out;
57813 if (nr_segs > fast_segs) {
57814 ret = -ENOMEM;
57815@@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57816 struct compat_readdir_callback {
57817 struct dir_context ctx;
57818 struct compat_old_linux_dirent __user *dirent;
57819+ struct file * file;
57820 int result;
57821 };
57822
57823@@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57824 buf->result = -EOVERFLOW;
57825 return -EOVERFLOW;
57826 }
57827+
57828+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57829+ return 0;
57830+
57831 buf->result++;
57832 dirent = buf->dirent;
57833 if (!access_ok(VERIFY_WRITE, dirent,
57834@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57835 if (!f.file)
57836 return -EBADF;
57837
57838+ buf.file = f.file;
57839 error = iterate_dir(f.file, &buf.ctx);
57840 if (buf.result)
57841 error = buf.result;
57842@@ -901,6 +907,7 @@ struct compat_getdents_callback {
57843 struct dir_context ctx;
57844 struct compat_linux_dirent __user *current_dir;
57845 struct compat_linux_dirent __user *previous;
57846+ struct file * file;
57847 int count;
57848 int error;
57849 };
57850@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57851 buf->error = -EOVERFLOW;
57852 return -EOVERFLOW;
57853 }
57854+
57855+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57856+ return 0;
57857+
57858 dirent = buf->previous;
57859 if (dirent) {
57860 if (__put_user(offset, &dirent->d_off))
57861@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57862 if (!f.file)
57863 return -EBADF;
57864
57865+ buf.file = f.file;
57866 error = iterate_dir(f.file, &buf.ctx);
57867 if (error >= 0)
57868 error = buf.error;
57869@@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57870 struct dir_context ctx;
57871 struct linux_dirent64 __user *current_dir;
57872 struct linux_dirent64 __user *previous;
57873+ struct file * file;
57874 int count;
57875 int error;
57876 };
57877@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57878 buf->error = -EINVAL; /* only used if we fail.. */
57879 if (reclen > buf->count)
57880 return -EINVAL;
57881+
57882+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57883+ return 0;
57884+
57885 dirent = buf->previous;
57886
57887 if (dirent) {
57888@@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57889 if (!f.file)
57890 return -EBADF;
57891
57892+ buf.file = f.file;
57893 error = iterate_dir(f.file, &buf.ctx);
57894 if (error >= 0)
57895 error = buf.error;
57896diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57897index a81147e..20bf2b5 100644
57898--- a/fs/compat_binfmt_elf.c
57899+++ b/fs/compat_binfmt_elf.c
57900@@ -30,11 +30,13 @@
57901 #undef elf_phdr
57902 #undef elf_shdr
57903 #undef elf_note
57904+#undef elf_dyn
57905 #undef elf_addr_t
57906 #define elfhdr elf32_hdr
57907 #define elf_phdr elf32_phdr
57908 #define elf_shdr elf32_shdr
57909 #define elf_note elf32_note
57910+#define elf_dyn Elf32_Dyn
57911 #define elf_addr_t Elf32_Addr
57912
57913 /*
57914diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57915index dc52e13..ec61057 100644
57916--- a/fs/compat_ioctl.c
57917+++ b/fs/compat_ioctl.c
57918@@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57919 return -EFAULT;
57920 if (__get_user(udata, &ss32->iomem_base))
57921 return -EFAULT;
57922- ss.iomem_base = compat_ptr(udata);
57923+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57924 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57925 __get_user(ss.port_high, &ss32->port_high))
57926 return -EFAULT;
57927@@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57928 for (i = 0; i < nmsgs; i++) {
57929 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57930 return -EFAULT;
57931- if (get_user(datap, &umsgs[i].buf) ||
57932- put_user(compat_ptr(datap), &tmsgs[i].buf))
57933+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57934+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57935 return -EFAULT;
57936 }
57937 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57938@@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57939 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57940 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57941 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57942- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57943+ copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57944 return -EFAULT;
57945
57946 return ioctl_preallocate(file, p);
57947@@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57948 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57949 {
57950 unsigned int a, b;
57951- a = *(unsigned int *)p;
57952- b = *(unsigned int *)q;
57953+ a = *(const unsigned int *)p;
57954+ b = *(const unsigned int *)q;
57955 if (a > b)
57956 return 1;
57957 if (a < b)
57958diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57959index e081acb..911df21 100644
57960--- a/fs/configfs/dir.c
57961+++ b/fs/configfs/dir.c
57962@@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57963 }
57964 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57965 struct configfs_dirent *next;
57966- const char *name;
57967+ const unsigned char * name;
57968+ char d_name[sizeof(next->s_dentry->d_iname)];
57969 int len;
57970 struct inode *inode = NULL;
57971
57972@@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57973 continue;
57974
57975 name = configfs_get_name(next);
57976- len = strlen(name);
57977+ if (next->s_dentry && name == next->s_dentry->d_iname) {
57978+ len = next->s_dentry->d_name.len;
57979+ memcpy(d_name, name, len);
57980+ name = d_name;
57981+ } else
57982+ len = strlen(name);
57983
57984 /*
57985 * We'll have a dentry and an inode for
57986diff --git a/fs/coredump.c b/fs/coredump.c
57987index bc3fbcd..6031650 100644
57988--- a/fs/coredump.c
57989+++ b/fs/coredump.c
57990@@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57991 struct pipe_inode_info *pipe = file->private_data;
57992
57993 pipe_lock(pipe);
57994- pipe->readers++;
57995- pipe->writers--;
57996+ atomic_inc(&pipe->readers);
57997+ atomic_dec(&pipe->writers);
57998 wake_up_interruptible_sync(&pipe->wait);
57999 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58000 pipe_unlock(pipe);
58001@@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
58002 * We actually want wait_event_freezable() but then we need
58003 * to clear TIF_SIGPENDING and improve dump_interrupted().
58004 */
58005- wait_event_interruptible(pipe->wait, pipe->readers == 1);
58006+ wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58007
58008 pipe_lock(pipe);
58009- pipe->readers--;
58010- pipe->writers++;
58011+ atomic_dec(&pipe->readers);
58012+ atomic_inc(&pipe->writers);
58013 pipe_unlock(pipe);
58014 }
58015
58016@@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
58017 struct files_struct *displaced;
58018 bool need_nonrelative = false;
58019 bool core_dumped = false;
58020- static atomic_t core_dump_count = ATOMIC_INIT(0);
58021+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58022+ long signr = siginfo->si_signo;
58023+ int dumpable;
58024 struct coredump_params cprm = {
58025 .siginfo = siginfo,
58026 .regs = signal_pt_regs(),
58027@@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
58028 .mm_flags = mm->flags,
58029 };
58030
58031- audit_core_dumps(siginfo->si_signo);
58032+ audit_core_dumps(signr);
58033+
58034+ dumpable = __get_dumpable(cprm.mm_flags);
58035+
58036+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58037+ gr_handle_brute_attach(dumpable);
58038
58039 binfmt = mm->binfmt;
58040 if (!binfmt || !binfmt->core_dump)
58041 goto fail;
58042- if (!__get_dumpable(cprm.mm_flags))
58043+ if (!dumpable)
58044 goto fail;
58045
58046 cred = prepare_creds();
58047@@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
58048 need_nonrelative = true;
58049 }
58050
58051- retval = coredump_wait(siginfo->si_signo, &core_state);
58052+ retval = coredump_wait(signr, &core_state);
58053 if (retval < 0)
58054 goto fail_creds;
58055
58056@@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
58057 }
58058 cprm.limit = RLIM_INFINITY;
58059
58060- dump_count = atomic_inc_return(&core_dump_count);
58061+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
58062 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58063 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58064 task_tgid_vnr(current), current->comm);
58065@@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
58066 } else {
58067 struct inode *inode;
58068
58069+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58070+
58071 if (cprm.limit < binfmt->min_coredump)
58072 goto fail_unlock;
58073
58074@@ -669,7 +678,7 @@ close_fail:
58075 filp_close(cprm.file, NULL);
58076 fail_dropcount:
58077 if (ispipe)
58078- atomic_dec(&core_dump_count);
58079+ atomic_dec_unchecked(&core_dump_count);
58080 fail_unlock:
58081 kfree(cn.corename);
58082 coredump_finish(mm, core_dumped);
58083@@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58084 struct file *file = cprm->file;
58085 loff_t pos = file->f_pos;
58086 ssize_t n;
58087+
58088+ gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58089 if (cprm->written + nr > cprm->limit)
58090 return 0;
58091 while (nr) {
58092diff --git a/fs/dcache.c b/fs/dcache.c
58093index f7ad6d7..d852932 100644
58094--- a/fs/dcache.c
58095+++ b/fs/dcache.c
58096@@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58097 */
58098 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58099 if (name->len > DNAME_INLINE_LEN-1) {
58100- dname = kmalloc(name->len + 1, GFP_KERNEL);
58101+ dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58102 if (!dname) {
58103 kmem_cache_free(dentry_cache, dentry);
58104 return NULL;
58105@@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
58106 mempages -= reserve;
58107
58108 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58109- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58110+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58111+ SLAB_NO_SANITIZE, NULL);
58112
58113 dcache_init();
58114 inode_init();
58115diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58116index 9c0444c..628490c 100644
58117--- a/fs/debugfs/inode.c
58118+++ b/fs/debugfs/inode.c
58119@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58120 */
58121 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58122 {
58123+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58124+ return __create_file(name, S_IFDIR | S_IRWXU,
58125+#else
58126 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58127+#endif
58128 parent, NULL, NULL);
58129 }
58130 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58131diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58132index c36c448..fc96710 100644
58133--- a/fs/ecryptfs/inode.c
58134+++ b/fs/ecryptfs/inode.c
58135@@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
58136 old_fs = get_fs();
58137 set_fs(get_ds());
58138 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58139- (char __user *)lower_buf,
58140+ (char __force_user *)lower_buf,
58141 PATH_MAX);
58142 set_fs(old_fs);
58143 if (rc < 0)
58144diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58145index e4141f2..d8263e8 100644
58146--- a/fs/ecryptfs/miscdev.c
58147+++ b/fs/ecryptfs/miscdev.c
58148@@ -304,7 +304,7 @@ check_list:
58149 goto out_unlock_msg_ctx;
58150 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58151 if (msg_ctx->msg) {
58152- if (copy_to_user(&buf[i], packet_length, packet_length_size))
58153+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58154 goto out_unlock_msg_ctx;
58155 i += packet_length_size;
58156 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58157diff --git a/fs/exec.c b/fs/exec.c
58158index 7ea097f..0158d8a 100644
58159--- a/fs/exec.c
58160+++ b/fs/exec.c
58161@@ -55,8 +55,20 @@
58162 #include <linux/pipe_fs_i.h>
58163 #include <linux/oom.h>
58164 #include <linux/compat.h>
58165+#include <linux/random.h>
58166+#include <linux/seq_file.h>
58167+#include <linux/coredump.h>
58168+#include <linux/mman.h>
58169+
58170+#ifdef CONFIG_PAX_REFCOUNT
58171+#include <linux/kallsyms.h>
58172+#include <linux/kdebug.h>
58173+#endif
58174+
58175+#include <trace/events/fs.h>
58176
58177 #include <asm/uaccess.h>
58178+#include <asm/sections.h>
58179 #include <asm/mmu_context.h>
58180 #include <asm/tlb.h>
58181
58182@@ -66,19 +78,34 @@
58183
58184 #include <trace/events/sched.h>
58185
58186+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58187+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58188+{
58189+ 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");
58190+}
58191+#endif
58192+
58193+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58194+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58195+EXPORT_SYMBOL(pax_set_initial_flags_func);
58196+#endif
58197+
58198 int suid_dumpable = 0;
58199
58200 static LIST_HEAD(formats);
58201 static DEFINE_RWLOCK(binfmt_lock);
58202
58203+extern int gr_process_kernel_exec_ban(void);
58204+extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58205+
58206 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58207 {
58208 BUG_ON(!fmt);
58209 if (WARN_ON(!fmt->load_binary))
58210 return;
58211 write_lock(&binfmt_lock);
58212- insert ? list_add(&fmt->lh, &formats) :
58213- list_add_tail(&fmt->lh, &formats);
58214+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58215+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58216 write_unlock(&binfmt_lock);
58217 }
58218
58219@@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58220 void unregister_binfmt(struct linux_binfmt * fmt)
58221 {
58222 write_lock(&binfmt_lock);
58223- list_del(&fmt->lh);
58224+ pax_list_del((struct list_head *)&fmt->lh);
58225 write_unlock(&binfmt_lock);
58226 }
58227
58228@@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58229 int write)
58230 {
58231 struct page *page;
58232- int ret;
58233
58234-#ifdef CONFIG_STACK_GROWSUP
58235- if (write) {
58236- ret = expand_downwards(bprm->vma, pos);
58237- if (ret < 0)
58238- return NULL;
58239- }
58240-#endif
58241- ret = get_user_pages(current, bprm->mm, pos,
58242- 1, write, 1, &page, NULL);
58243- if (ret <= 0)
58244+ if (0 > expand_downwards(bprm->vma, pos))
58245+ return NULL;
58246+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58247 return NULL;
58248
58249 if (write) {
58250@@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58251 if (size <= ARG_MAX)
58252 return page;
58253
58254+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58255+ // only allow 512KB for argv+env on suid/sgid binaries
58256+ // to prevent easy ASLR exhaustion
58257+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58258+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
58259+ (size > (512 * 1024))) {
58260+ put_page(page);
58261+ return NULL;
58262+ }
58263+#endif
58264+
58265 /*
58266 * Limit to 1/4-th the stack size for the argv+env strings.
58267 * This ensures that:
58268@@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58269 vma->vm_end = STACK_TOP_MAX;
58270 vma->vm_start = vma->vm_end - PAGE_SIZE;
58271 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58272+
58273+#ifdef CONFIG_PAX_SEGMEXEC
58274+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58275+#endif
58276+
58277 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58278 INIT_LIST_HEAD(&vma->anon_vma_chain);
58279
58280@@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58281 mm->stack_vm = mm->total_vm = 1;
58282 up_write(&mm->mmap_sem);
58283 bprm->p = vma->vm_end - sizeof(void *);
58284+
58285+#ifdef CONFIG_PAX_RANDUSTACK
58286+ if (randomize_va_space)
58287+ bprm->p ^= prandom_u32() & ~PAGE_MASK;
58288+#endif
58289+
58290 return 0;
58291 err:
58292 up_write(&mm->mmap_sem);
58293@@ -397,7 +438,7 @@ struct user_arg_ptr {
58294 } ptr;
58295 };
58296
58297-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58298+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58299 {
58300 const char __user *native;
58301
58302@@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58303 compat_uptr_t compat;
58304
58305 if (get_user(compat, argv.ptr.compat + nr))
58306- return ERR_PTR(-EFAULT);
58307+ return (const char __force_user *)ERR_PTR(-EFAULT);
58308
58309 return compat_ptr(compat);
58310 }
58311 #endif
58312
58313 if (get_user(native, argv.ptr.native + nr))
58314- return ERR_PTR(-EFAULT);
58315+ return (const char __force_user *)ERR_PTR(-EFAULT);
58316
58317 return native;
58318 }
58319@@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
58320 if (!p)
58321 break;
58322
58323- if (IS_ERR(p))
58324+ if (IS_ERR((const char __force_kernel *)p))
58325 return -EFAULT;
58326
58327 if (i >= max)
58328@@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58329
58330 ret = -EFAULT;
58331 str = get_user_arg_ptr(argv, argc);
58332- if (IS_ERR(str))
58333+ if (IS_ERR((const char __force_kernel *)str))
58334 goto out;
58335
58336 len = strnlen_user(str, MAX_ARG_STRLEN);
58337@@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58338 int r;
58339 mm_segment_t oldfs = get_fs();
58340 struct user_arg_ptr argv = {
58341- .ptr.native = (const char __user *const __user *)__argv,
58342+ .ptr.native = (const char __user * const __force_user *)__argv,
58343 };
58344
58345 set_fs(KERNEL_DS);
58346@@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58347 unsigned long new_end = old_end - shift;
58348 struct mmu_gather tlb;
58349
58350- BUG_ON(new_start > new_end);
58351+ if (new_start >= new_end || new_start < mmap_min_addr)
58352+ return -ENOMEM;
58353
58354 /*
58355 * ensure there are no vmas between where we want to go
58356@@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58357 if (vma != find_vma(mm, new_start))
58358 return -EFAULT;
58359
58360+#ifdef CONFIG_PAX_SEGMEXEC
58361+ BUG_ON(pax_find_mirror_vma(vma));
58362+#endif
58363+
58364 /*
58365 * cover the whole range: [new_start, old_end)
58366 */
58367@@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58368 stack_top = arch_align_stack(stack_top);
58369 stack_top = PAGE_ALIGN(stack_top);
58370
58371- if (unlikely(stack_top < mmap_min_addr) ||
58372- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58373- return -ENOMEM;
58374-
58375 stack_shift = vma->vm_end - stack_top;
58376
58377 bprm->p -= stack_shift;
58378@@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58379 bprm->exec -= stack_shift;
58380
58381 down_write(&mm->mmap_sem);
58382+
58383+ /* Move stack pages down in memory. */
58384+ if (stack_shift) {
58385+ ret = shift_arg_pages(vma, stack_shift);
58386+ if (ret)
58387+ goto out_unlock;
58388+ }
58389+
58390 vm_flags = VM_STACK_FLAGS;
58391
58392+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58393+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58394+ vm_flags &= ~VM_EXEC;
58395+
58396+#ifdef CONFIG_PAX_MPROTECT
58397+ if (mm->pax_flags & MF_PAX_MPROTECT)
58398+ vm_flags &= ~VM_MAYEXEC;
58399+#endif
58400+
58401+ }
58402+#endif
58403+
58404 /*
58405 * Adjust stack execute permissions; explicitly enable for
58406 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58407@@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58408 goto out_unlock;
58409 BUG_ON(prev != vma);
58410
58411- /* Move stack pages down in memory. */
58412- if (stack_shift) {
58413- ret = shift_arg_pages(vma, stack_shift);
58414- if (ret)
58415- goto out_unlock;
58416- }
58417-
58418 /* mprotect_fixup is overkill to remove the temporary stack flags */
58419 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58420
58421@@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58422 #endif
58423 current->mm->start_stack = bprm->p;
58424 ret = expand_stack(vma, stack_base);
58425+
58426+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58427+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58428+ unsigned long size;
58429+ vm_flags_t vm_flags;
58430+
58431+ size = STACK_TOP - vma->vm_end;
58432+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58433+
58434+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58435+
58436+#ifdef CONFIG_X86
58437+ if (!ret) {
58438+ size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58439+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58440+ }
58441+#endif
58442+
58443+ }
58444+#endif
58445+
58446 if (ret)
58447 ret = -EFAULT;
58448
58449@@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
58450
58451 fsnotify_open(file);
58452
58453+ trace_open_exec(name);
58454+
58455 err = deny_write_access(file);
58456 if (err)
58457 goto exit;
58458@@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
58459 old_fs = get_fs();
58460 set_fs(get_ds());
58461 /* The cast to a user pointer is valid due to the set_fs() */
58462- result = vfs_read(file, (void __user *)addr, count, &pos);
58463+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
58464 set_fs(old_fs);
58465 return result;
58466 }
58467@@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
58468 }
58469 rcu_read_unlock();
58470
58471- if (p->fs->users > n_fs) {
58472+ if (atomic_read(&p->fs->users) > n_fs) {
58473 bprm->unsafe |= LSM_UNSAFE_SHARE;
58474 } else {
58475 res = -EAGAIN;
58476@@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58477 return ret;
58478 }
58479
58480+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58481+static DEFINE_PER_CPU(u64, exec_counter);
58482+static int __init init_exec_counters(void)
58483+{
58484+ unsigned int cpu;
58485+
58486+ for_each_possible_cpu(cpu) {
58487+ per_cpu(exec_counter, cpu) = (u64)cpu;
58488+ }
58489+
58490+ return 0;
58491+}
58492+early_initcall(init_exec_counters);
58493+static inline void increment_exec_counter(void)
58494+{
58495+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
58496+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58497+}
58498+#else
58499+static inline void increment_exec_counter(void) {}
58500+#endif
58501+
58502+extern void gr_handle_exec_args(struct linux_binprm *bprm,
58503+ struct user_arg_ptr argv);
58504+
58505 /*
58506 * sys_execve() executes a new program.
58507 */
58508@@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
58509 struct user_arg_ptr argv,
58510 struct user_arg_ptr envp)
58511 {
58512+#ifdef CONFIG_GRKERNSEC
58513+ struct file *old_exec_file;
58514+ struct acl_subject_label *old_acl;
58515+ struct rlimit old_rlim[RLIM_NLIMITS];
58516+#endif
58517 struct linux_binprm *bprm;
58518 struct file *file;
58519 struct files_struct *displaced;
58520 bool clear_in_exec;
58521 int retval;
58522
58523+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58524+
58525 /*
58526 * We move the actual failure in case of RLIMIT_NPROC excess from
58527 * set*uid() to execve() because too many poorly written programs
58528@@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
58529 if (IS_ERR(file))
58530 goto out_unmark;
58531
58532+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
58533+ retval = -EPERM;
58534+ goto out_file;
58535+ }
58536+
58537 sched_exec();
58538
58539 bprm->file = file;
58540 bprm->filename = filename;
58541 bprm->interp = filename;
58542
58543+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58544+ retval = -EACCES;
58545+ goto out_file;
58546+ }
58547+
58548 retval = bprm_mm_init(bprm);
58549 if (retval)
58550 goto out_file;
58551@@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
58552 if (retval < 0)
58553 goto out;
58554
58555+#ifdef CONFIG_GRKERNSEC
58556+ old_acl = current->acl;
58557+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58558+ old_exec_file = current->exec_file;
58559+ get_file(file);
58560+ current->exec_file = file;
58561+#endif
58562+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58563+ /* limit suid stack to 8MB
58564+ * we saved the old limits above and will restore them if this exec fails
58565+ */
58566+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58567+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58568+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58569+#endif
58570+
58571+ if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58572+ retval = -EPERM;
58573+ goto out_fail;
58574+ }
58575+
58576+ if (!gr_tpe_allow(file)) {
58577+ retval = -EACCES;
58578+ goto out_fail;
58579+ }
58580+
58581+ if (gr_check_crash_exec(file)) {
58582+ retval = -EACCES;
58583+ goto out_fail;
58584+ }
58585+
58586+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58587+ bprm->unsafe);
58588+ if (retval < 0)
58589+ goto out_fail;
58590+
58591 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58592 if (retval < 0)
58593- goto out;
58594+ goto out_fail;
58595
58596 bprm->exec = bprm->p;
58597 retval = copy_strings(bprm->envc, envp, bprm);
58598 if (retval < 0)
58599- goto out;
58600+ goto out_fail;
58601
58602 retval = copy_strings(bprm->argc, argv, bprm);
58603 if (retval < 0)
58604- goto out;
58605+ goto out_fail;
58606+
58607+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58608+
58609+ gr_handle_exec_args(bprm, argv);
58610
58611 retval = exec_binprm(bprm);
58612 if (retval < 0)
58613- goto out;
58614+ goto out_fail;
58615+#ifdef CONFIG_GRKERNSEC
58616+ if (old_exec_file)
58617+ fput(old_exec_file);
58618+#endif
58619
58620 /* execve succeeded */
58621+
58622+ increment_exec_counter();
58623 current->fs->in_exec = 0;
58624 current->in_execve = 0;
58625 acct_update_integrals(current);
58626@@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
58627 put_files_struct(displaced);
58628 return retval;
58629
58630+out_fail:
58631+#ifdef CONFIG_GRKERNSEC
58632+ current->acl = old_acl;
58633+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
58634+ fput(current->exec_file);
58635+ current->exec_file = old_exec_file;
58636+#endif
58637+
58638 out:
58639 if (bprm->mm) {
58640 acct_arg_size(bprm, 0);
58641@@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
58642 return error;
58643 }
58644 #endif
58645+
58646+int pax_check_flags(unsigned long *flags)
58647+{
58648+ int retval = 0;
58649+
58650+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
58651+ if (*flags & MF_PAX_SEGMEXEC)
58652+ {
58653+ *flags &= ~MF_PAX_SEGMEXEC;
58654+ retval = -EINVAL;
58655+ }
58656+#endif
58657+
58658+ if ((*flags & MF_PAX_PAGEEXEC)
58659+
58660+#ifdef CONFIG_PAX_PAGEEXEC
58661+ && (*flags & MF_PAX_SEGMEXEC)
58662+#endif
58663+
58664+ )
58665+ {
58666+ *flags &= ~MF_PAX_PAGEEXEC;
58667+ retval = -EINVAL;
58668+ }
58669+
58670+ if ((*flags & MF_PAX_MPROTECT)
58671+
58672+#ifdef CONFIG_PAX_MPROTECT
58673+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58674+#endif
58675+
58676+ )
58677+ {
58678+ *flags &= ~MF_PAX_MPROTECT;
58679+ retval = -EINVAL;
58680+ }
58681+
58682+ if ((*flags & MF_PAX_EMUTRAMP)
58683+
58684+#ifdef CONFIG_PAX_EMUTRAMP
58685+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
58686+#endif
58687+
58688+ )
58689+ {
58690+ *flags &= ~MF_PAX_EMUTRAMP;
58691+ retval = -EINVAL;
58692+ }
58693+
58694+ return retval;
58695+}
58696+
58697+EXPORT_SYMBOL(pax_check_flags);
58698+
58699+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58700+char *pax_get_path(const struct path *path, char *buf, int buflen)
58701+{
58702+ char *pathname = d_path(path, buf, buflen);
58703+
58704+ if (IS_ERR(pathname))
58705+ goto toolong;
58706+
58707+ pathname = mangle_path(buf, pathname, "\t\n\\");
58708+ if (!pathname)
58709+ goto toolong;
58710+
58711+ *pathname = 0;
58712+ return buf;
58713+
58714+toolong:
58715+ return "<path too long>";
58716+}
58717+EXPORT_SYMBOL(pax_get_path);
58718+
58719+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
58720+{
58721+ struct task_struct *tsk = current;
58722+ struct mm_struct *mm = current->mm;
58723+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
58724+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
58725+ char *path_exec = NULL;
58726+ char *path_fault = NULL;
58727+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
58728+ siginfo_t info = { };
58729+
58730+ if (buffer_exec && buffer_fault) {
58731+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
58732+
58733+ down_read(&mm->mmap_sem);
58734+ vma = mm->mmap;
58735+ while (vma && (!vma_exec || !vma_fault)) {
58736+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
58737+ vma_exec = vma;
58738+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
58739+ vma_fault = vma;
58740+ vma = vma->vm_next;
58741+ }
58742+ if (vma_exec)
58743+ path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
58744+ if (vma_fault) {
58745+ start = vma_fault->vm_start;
58746+ end = vma_fault->vm_end;
58747+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
58748+ if (vma_fault->vm_file)
58749+ path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
58750+ else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58751+ path_fault = "<heap>";
58752+ else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58753+ path_fault = "<stack>";
58754+ else
58755+ path_fault = "<anonymous mapping>";
58756+ }
58757+ up_read(&mm->mmap_sem);
58758+ }
58759+ if (tsk->signal->curr_ip)
58760+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58761+ else
58762+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58763+ 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),
58764+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58765+ free_page((unsigned long)buffer_exec);
58766+ free_page((unsigned long)buffer_fault);
58767+ pax_report_insns(regs, pc, sp);
58768+ info.si_signo = SIGKILL;
58769+ info.si_errno = 0;
58770+ info.si_code = SI_KERNEL;
58771+ info.si_pid = 0;
58772+ info.si_uid = 0;
58773+ do_coredump(&info);
58774+}
58775+#endif
58776+
58777+#ifdef CONFIG_PAX_REFCOUNT
58778+void pax_report_refcount_overflow(struct pt_regs *regs)
58779+{
58780+ if (current->signal->curr_ip)
58781+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58782+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
58783+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58784+ else
58785+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58786+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58787+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58788+ preempt_disable();
58789+ show_regs(regs);
58790+ preempt_enable();
58791+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58792+}
58793+#endif
58794+
58795+#ifdef CONFIG_PAX_USERCOPY
58796+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58797+static noinline int check_stack_object(const void *obj, unsigned long len)
58798+{
58799+ const void * const stack = task_stack_page(current);
58800+ const void * const stackend = stack + THREAD_SIZE;
58801+
58802+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58803+ const void *frame = NULL;
58804+ const void *oldframe;
58805+#endif
58806+
58807+ if (obj + len < obj)
58808+ return -1;
58809+
58810+ if (obj + len <= stack || stackend <= obj)
58811+ return 0;
58812+
58813+ if (obj < stack || stackend < obj + len)
58814+ return -1;
58815+
58816+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58817+ oldframe = __builtin_frame_address(1);
58818+ if (oldframe)
58819+ frame = __builtin_frame_address(2);
58820+ /*
58821+ low ----------------------------------------------> high
58822+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
58823+ ^----------------^
58824+ allow copies only within here
58825+ */
58826+ while (stack <= frame && frame < stackend) {
58827+ /* if obj + len extends past the last frame, this
58828+ check won't pass and the next frame will be 0,
58829+ causing us to bail out and correctly report
58830+ the copy as invalid
58831+ */
58832+ if (obj + len <= frame)
58833+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58834+ oldframe = frame;
58835+ frame = *(const void * const *)frame;
58836+ }
58837+ return -1;
58838+#else
58839+ return 1;
58840+#endif
58841+}
58842+
58843+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58844+{
58845+ if (current->signal->curr_ip)
58846+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58847+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58848+ else
58849+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58850+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58851+ dump_stack();
58852+ gr_handle_kernel_exploit();
58853+ do_group_exit(SIGKILL);
58854+}
58855+#endif
58856+
58857+#ifdef CONFIG_PAX_USERCOPY
58858+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58859+{
58860+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58861+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
58862+#ifdef CONFIG_MODULES
58863+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58864+#else
58865+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58866+#endif
58867+
58868+#else
58869+ unsigned long textlow = (unsigned long)_stext;
58870+ unsigned long texthigh = (unsigned long)_etext;
58871+
58872+#ifdef CONFIG_X86_64
58873+ /* check against linear mapping as well */
58874+ if (high > (unsigned long)__va(__pa(textlow)) &&
58875+ low <= (unsigned long)__va(__pa(texthigh)))
58876+ return true;
58877+#endif
58878+
58879+#endif
58880+
58881+ if (high <= textlow || low > texthigh)
58882+ return false;
58883+ else
58884+ return true;
58885+}
58886+#endif
58887+
58888+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58889+{
58890+
58891+#ifdef CONFIG_PAX_USERCOPY
58892+ const char *type;
58893+
58894+ if (!n)
58895+ return;
58896+
58897+ type = check_heap_object(ptr, n);
58898+ if (!type) {
58899+ int ret = check_stack_object(ptr, n);
58900+ if (ret == 1 || ret == 2)
58901+ return;
58902+ if (ret == 0) {
58903+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58904+ type = "<kernel text>";
58905+ else
58906+ return;
58907+ } else
58908+ type = "<process stack>";
58909+ }
58910+
58911+ pax_report_usercopy(ptr, n, to_user, type);
58912+#endif
58913+
58914+}
58915+EXPORT_SYMBOL(__check_object_size);
58916+
58917+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58918+void pax_track_stack(void)
58919+{
58920+ unsigned long sp = (unsigned long)&sp;
58921+ if (sp < current_thread_info()->lowest_stack &&
58922+ sp > (unsigned long)task_stack_page(current))
58923+ current_thread_info()->lowest_stack = sp;
58924+}
58925+EXPORT_SYMBOL(pax_track_stack);
58926+#endif
58927+
58928+#ifdef CONFIG_PAX_SIZE_OVERFLOW
58929+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58930+{
58931+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58932+ dump_stack();
58933+ do_group_exit(SIGKILL);
58934+}
58935+EXPORT_SYMBOL(report_size_overflow);
58936+#endif
58937diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58938index 9f9992b..8b59411 100644
58939--- a/fs/ext2/balloc.c
58940+++ b/fs/ext2/balloc.c
58941@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58942
58943 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58944 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58945- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58946+ if (free_blocks < root_blocks + 1 &&
58947 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58948 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58949- !in_group_p (sbi->s_resgid))) {
58950+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58951 return 0;
58952 }
58953 return 1;
58954diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58955index 2d7557d..14e38f94 100644
58956--- a/fs/ext2/xattr.c
58957+++ b/fs/ext2/xattr.c
58958@@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58959 struct buffer_head *bh = NULL;
58960 struct ext2_xattr_entry *entry;
58961 char *end;
58962- size_t rest = buffer_size;
58963+ size_t rest = buffer_size, total_size = 0;
58964 int error;
58965
58966 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58967@@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58968 buffer += size;
58969 }
58970 rest -= size;
58971+ total_size += size;
58972 }
58973 }
58974- error = buffer_size - rest; /* total size */
58975+ error = total_size;
58976
58977 cleanup:
58978 brelse(bh);
58979diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58980index 22548f5..41521d8 100644
58981--- a/fs/ext3/balloc.c
58982+++ b/fs/ext3/balloc.c
58983@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58984
58985 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58986 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58987- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58988+ if (free_blocks < root_blocks + 1 &&
58989 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58990 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58991- !in_group_p (sbi->s_resgid))) {
58992+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58993 return 0;
58994 }
58995 return 1;
58996diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58997index b1fc963..881228c 100644
58998--- a/fs/ext3/xattr.c
58999+++ b/fs/ext3/xattr.c
59000@@ -330,7 +330,7 @@ static int
59001 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59002 char *buffer, size_t buffer_size)
59003 {
59004- size_t rest = buffer_size;
59005+ size_t rest = buffer_size, total_size = 0;
59006
59007 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59008 const struct xattr_handler *handler =
59009@@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59010 buffer += size;
59011 }
59012 rest -= size;
59013+ total_size += size;
59014 }
59015 }
59016- return buffer_size - rest;
59017+ return total_size;
59018 }
59019
59020 static int
59021diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59022index 6ea7b14..8fa16d9 100644
59023--- a/fs/ext4/balloc.c
59024+++ b/fs/ext4/balloc.c
59025@@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59026 /* Hm, nope. Are (enough) root reserved clusters available? */
59027 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59028 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59029- capable(CAP_SYS_RESOURCE) ||
59030- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59031+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59032+ capable_nolog(CAP_SYS_RESOURCE)) {
59033
59034 if (free_clusters >= (nclusters + dirty_clusters +
59035 resv_clusters))
59036diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59037index d3a534f..242c50a 100644
59038--- a/fs/ext4/ext4.h
59039+++ b/fs/ext4/ext4.h
59040@@ -1269,19 +1269,19 @@ struct ext4_sb_info {
59041 unsigned long s_mb_last_start;
59042
59043 /* stats for buddy allocator */
59044- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59045- atomic_t s_bal_success; /* we found long enough chunks */
59046- atomic_t s_bal_allocated; /* in blocks */
59047- atomic_t s_bal_ex_scanned; /* total extents scanned */
59048- atomic_t s_bal_goals; /* goal hits */
59049- atomic_t s_bal_breaks; /* too long searches */
59050- atomic_t s_bal_2orders; /* 2^order hits */
59051+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59052+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59053+ atomic_unchecked_t s_bal_allocated; /* in blocks */
59054+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59055+ atomic_unchecked_t s_bal_goals; /* goal hits */
59056+ atomic_unchecked_t s_bal_breaks; /* too long searches */
59057+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59058 spinlock_t s_bal_lock;
59059 unsigned long s_mb_buddies_generated;
59060 unsigned long long s_mb_generation_time;
59061- atomic_t s_mb_lost_chunks;
59062- atomic_t s_mb_preallocated;
59063- atomic_t s_mb_discarded;
59064+ atomic_unchecked_t s_mb_lost_chunks;
59065+ atomic_unchecked_t s_mb_preallocated;
59066+ atomic_unchecked_t s_mb_discarded;
59067 atomic_t s_lock_busy;
59068
59069 /* locality groups */
59070diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59071index 04a5c75..09894fa 100644
59072--- a/fs/ext4/mballoc.c
59073+++ b/fs/ext4/mballoc.c
59074@@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59075 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59076
59077 if (EXT4_SB(sb)->s_mb_stats)
59078- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59079+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59080
59081 break;
59082 }
59083@@ -2189,7 +2189,7 @@ repeat:
59084 ac->ac_status = AC_STATUS_CONTINUE;
59085 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59086 cr = 3;
59087- atomic_inc(&sbi->s_mb_lost_chunks);
59088+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59089 goto repeat;
59090 }
59091 }
59092@@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
59093 if (sbi->s_mb_stats) {
59094 ext4_msg(sb, KERN_INFO,
59095 "mballoc: %u blocks %u reqs (%u success)",
59096- atomic_read(&sbi->s_bal_allocated),
59097- atomic_read(&sbi->s_bal_reqs),
59098- atomic_read(&sbi->s_bal_success));
59099+ atomic_read_unchecked(&sbi->s_bal_allocated),
59100+ atomic_read_unchecked(&sbi->s_bal_reqs),
59101+ atomic_read_unchecked(&sbi->s_bal_success));
59102 ext4_msg(sb, KERN_INFO,
59103 "mballoc: %u extents scanned, %u goal hits, "
59104 "%u 2^N hits, %u breaks, %u lost",
59105- atomic_read(&sbi->s_bal_ex_scanned),
59106- atomic_read(&sbi->s_bal_goals),
59107- atomic_read(&sbi->s_bal_2orders),
59108- atomic_read(&sbi->s_bal_breaks),
59109- atomic_read(&sbi->s_mb_lost_chunks));
59110+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59111+ atomic_read_unchecked(&sbi->s_bal_goals),
59112+ atomic_read_unchecked(&sbi->s_bal_2orders),
59113+ atomic_read_unchecked(&sbi->s_bal_breaks),
59114+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59115 ext4_msg(sb, KERN_INFO,
59116 "mballoc: %lu generated and it took %Lu",
59117 sbi->s_mb_buddies_generated,
59118 sbi->s_mb_generation_time);
59119 ext4_msg(sb, KERN_INFO,
59120 "mballoc: %u preallocated, %u discarded",
59121- atomic_read(&sbi->s_mb_preallocated),
59122- atomic_read(&sbi->s_mb_discarded));
59123+ atomic_read_unchecked(&sbi->s_mb_preallocated),
59124+ atomic_read_unchecked(&sbi->s_mb_discarded));
59125 }
59126
59127 free_percpu(sbi->s_locality_groups);
59128@@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59129 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59130
59131 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59132- atomic_inc(&sbi->s_bal_reqs);
59133- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59134+ atomic_inc_unchecked(&sbi->s_bal_reqs);
59135+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59136 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59137- atomic_inc(&sbi->s_bal_success);
59138- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59139+ atomic_inc_unchecked(&sbi->s_bal_success);
59140+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59141 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59142 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59143- atomic_inc(&sbi->s_bal_goals);
59144+ atomic_inc_unchecked(&sbi->s_bal_goals);
59145 if (ac->ac_found > sbi->s_mb_max_to_scan)
59146- atomic_inc(&sbi->s_bal_breaks);
59147+ atomic_inc_unchecked(&sbi->s_bal_breaks);
59148 }
59149
59150 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59151@@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59152 trace_ext4_mb_new_inode_pa(ac, pa);
59153
59154 ext4_mb_use_inode_pa(ac, pa);
59155- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59156+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59157
59158 ei = EXT4_I(ac->ac_inode);
59159 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59160@@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59161 trace_ext4_mb_new_group_pa(ac, pa);
59162
59163 ext4_mb_use_group_pa(ac, pa);
59164- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59165+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59166
59167 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59168 lg = ac->ac_lg;
59169@@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59170 * from the bitmap and continue.
59171 */
59172 }
59173- atomic_add(free, &sbi->s_mb_discarded);
59174+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
59175
59176 return err;
59177 }
59178@@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59179 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59180 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59181 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59182- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59183+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59184 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59185
59186 return 0;
59187diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59188index 04434ad..6404663 100644
59189--- a/fs/ext4/mmp.c
59190+++ b/fs/ext4/mmp.c
59191@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59192 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59193 const char *function, unsigned int line, const char *msg)
59194 {
59195- __ext4_warning(sb, function, line, msg);
59196+ __ext4_warning(sb, function, line, "%s", msg);
59197 __ext4_warning(sb, function, line,
59198 "MMP failure info: last update time: %llu, last update "
59199 "node: %s, last update device: %s\n",
59200diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59201index 710fed2..a82e4e8 100644
59202--- a/fs/ext4/super.c
59203+++ b/fs/ext4/super.c
59204@@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59205 }
59206
59207 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59208-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59209+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59210 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59211
59212 #ifdef CONFIG_QUOTA
59213@@ -2450,7 +2450,7 @@ struct ext4_attr {
59214 int offset;
59215 int deprecated_val;
59216 } u;
59217-};
59218+} __do_const;
59219
59220 static int parse_strtoull(const char *buf,
59221 unsigned long long max, unsigned long long *value)
59222diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59223index 1423c48..9c0c6dc 100644
59224--- a/fs/ext4/xattr.c
59225+++ b/fs/ext4/xattr.c
59226@@ -381,7 +381,7 @@ static int
59227 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59228 char *buffer, size_t buffer_size)
59229 {
59230- size_t rest = buffer_size;
59231+ size_t rest = buffer_size, total_size = 0;
59232
59233 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59234 const struct xattr_handler *handler =
59235@@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59236 buffer += size;
59237 }
59238 rest -= size;
59239+ total_size += size;
59240 }
59241 }
59242- return buffer_size - rest;
59243+ return total_size;
59244 }
59245
59246 static int
59247diff --git a/fs/fcntl.c b/fs/fcntl.c
59248index ef68665..5deacdc 100644
59249--- a/fs/fcntl.c
59250+++ b/fs/fcntl.c
59251@@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59252 if (err)
59253 return err;
59254
59255+ if (gr_handle_chroot_fowner(pid, type))
59256+ return -ENOENT;
59257+ if (gr_check_protected_task_fowner(pid, type))
59258+ return -EACCES;
59259+
59260 f_modown(filp, pid, type, force);
59261 return 0;
59262 }
59263diff --git a/fs/fhandle.c b/fs/fhandle.c
59264index 999ff5c..41f4109 100644
59265--- a/fs/fhandle.c
59266+++ b/fs/fhandle.c
59267@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
59268 } else
59269 retval = 0;
59270 /* copy the mount id */
59271- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59272- sizeof(*mnt_id)) ||
59273+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59274 copy_to_user(ufh, handle,
59275 sizeof(struct file_handle) + handle_bytes))
59276 retval = -EFAULT;
59277diff --git a/fs/file.c b/fs/file.c
59278index 9de2026..8e334ca 100644
59279--- a/fs/file.c
59280+++ b/fs/file.c
59281@@ -16,6 +16,7 @@
59282 #include <linux/slab.h>
59283 #include <linux/vmalloc.h>
59284 #include <linux/file.h>
59285+#include <linux/security.h>
59286 #include <linux/fdtable.h>
59287 #include <linux/bitops.h>
59288 #include <linux/interrupt.h>
59289@@ -141,7 +142,7 @@ out:
59290 * Return <0 error code on error; 1 on successful completion.
59291 * The files->file_lock should be held on entry, and will be held on exit.
59292 */
59293-static int expand_fdtable(struct files_struct *files, int nr)
59294+static int expand_fdtable(struct files_struct *files, unsigned int nr)
59295 __releases(files->file_lock)
59296 __acquires(files->file_lock)
59297 {
59298@@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59299 * expanded and execution may have blocked.
59300 * The files->file_lock should be held on entry, and will be held on exit.
59301 */
59302-static int expand_files(struct files_struct *files, int nr)
59303+static int expand_files(struct files_struct *files, unsigned int nr)
59304 {
59305 struct fdtable *fdt;
59306
59307@@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59308 if (!file)
59309 return __close_fd(files, fd);
59310
59311+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59312 if (fd >= rlimit(RLIMIT_NOFILE))
59313 return -EBADF;
59314
59315@@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59316 if (unlikely(oldfd == newfd))
59317 return -EINVAL;
59318
59319+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59320 if (newfd >= rlimit(RLIMIT_NOFILE))
59321 return -EBADF;
59322
59323@@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59324 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59325 {
59326 int err;
59327+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59328 if (from >= rlimit(RLIMIT_NOFILE))
59329 return -EINVAL;
59330 err = alloc_fd(from, flags);
59331diff --git a/fs/filesystems.c b/fs/filesystems.c
59332index 92567d9..fcd8cbf 100644
59333--- a/fs/filesystems.c
59334+++ b/fs/filesystems.c
59335@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
59336 int len = dot ? dot - name : strlen(name);
59337
59338 fs = __get_fs_type(name, len);
59339+#ifdef CONFIG_GRKERNSEC_MODHARDEN
59340+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59341+#else
59342 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59343+#endif
59344 fs = __get_fs_type(name, len);
59345
59346 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59347diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59348index 7dca743..543d620 100644
59349--- a/fs/fs_struct.c
59350+++ b/fs/fs_struct.c
59351@@ -4,6 +4,7 @@
59352 #include <linux/path.h>
59353 #include <linux/slab.h>
59354 #include <linux/fs_struct.h>
59355+#include <linux/grsecurity.h>
59356 #include "internal.h"
59357
59358 /*
59359@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59360 write_seqcount_begin(&fs->seq);
59361 old_root = fs->root;
59362 fs->root = *path;
59363+ gr_set_chroot_entries(current, path);
59364 write_seqcount_end(&fs->seq);
59365 spin_unlock(&fs->lock);
59366 if (old_root.dentry)
59367@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59368 int hits = 0;
59369 spin_lock(&fs->lock);
59370 write_seqcount_begin(&fs->seq);
59371+ /* this root replacement is only done by pivot_root,
59372+ leave grsec's chroot tagging alone for this task
59373+ so that a pivoted root isn't treated as a chroot
59374+ */
59375 hits += replace_path(&fs->root, old_root, new_root);
59376 hits += replace_path(&fs->pwd, old_root, new_root);
59377 write_seqcount_end(&fs->seq);
59378@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59379 task_lock(tsk);
59380 spin_lock(&fs->lock);
59381 tsk->fs = NULL;
59382- kill = !--fs->users;
59383+ gr_clear_chroot_entries(tsk);
59384+ kill = !atomic_dec_return(&fs->users);
59385 spin_unlock(&fs->lock);
59386 task_unlock(tsk);
59387 if (kill)
59388@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59389 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59390 /* We don't need to lock fs - think why ;-) */
59391 if (fs) {
59392- fs->users = 1;
59393+ atomic_set(&fs->users, 1);
59394 fs->in_exec = 0;
59395 spin_lock_init(&fs->lock);
59396 seqcount_init(&fs->seq);
59397@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59398 spin_lock(&old->lock);
59399 fs->root = old->root;
59400 path_get(&fs->root);
59401+ /* instead of calling gr_set_chroot_entries here,
59402+ we call it from every caller of this function
59403+ */
59404 fs->pwd = old->pwd;
59405 path_get(&fs->pwd);
59406 spin_unlock(&old->lock);
59407@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59408
59409 task_lock(current);
59410 spin_lock(&fs->lock);
59411- kill = !--fs->users;
59412+ kill = !atomic_dec_return(&fs->users);
59413 current->fs = new_fs;
59414+ gr_set_chroot_entries(current, &new_fs->root);
59415 spin_unlock(&fs->lock);
59416 task_unlock(current);
59417
59418@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59419
59420 int current_umask(void)
59421 {
59422- return current->fs->umask;
59423+ return current->fs->umask | gr_acl_umask();
59424 }
59425 EXPORT_SYMBOL(current_umask);
59426
59427 /* to be mentioned only in INIT_TASK */
59428 struct fs_struct init_fs = {
59429- .users = 1,
59430+ .users = ATOMIC_INIT(1),
59431 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59432 .seq = SEQCNT_ZERO(init_fs.seq),
59433 .umask = 0022,
59434diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59435index 29d7feb..303644d 100644
59436--- a/fs/fscache/cookie.c
59437+++ b/fs/fscache/cookie.c
59438@@ -19,7 +19,7 @@
59439
59440 struct kmem_cache *fscache_cookie_jar;
59441
59442-static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59443+static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59444
59445 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59446 static int fscache_alloc_object(struct fscache_cache *cache,
59447@@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59448 parent ? (char *) parent->def->name : "<no-parent>",
59449 def->name, netfs_data, enable);
59450
59451- fscache_stat(&fscache_n_acquires);
59452+ fscache_stat_unchecked(&fscache_n_acquires);
59453
59454 /* if there's no parent cookie, then we don't create one here either */
59455 if (!parent) {
59456- fscache_stat(&fscache_n_acquires_null);
59457+ fscache_stat_unchecked(&fscache_n_acquires_null);
59458 _leave(" [no parent]");
59459 return NULL;
59460 }
59461@@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59462 /* allocate and initialise a cookie */
59463 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59464 if (!cookie) {
59465- fscache_stat(&fscache_n_acquires_oom);
59466+ fscache_stat_unchecked(&fscache_n_acquires_oom);
59467 _leave(" [ENOMEM]");
59468 return NULL;
59469 }
59470@@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59471
59472 switch (cookie->def->type) {
59473 case FSCACHE_COOKIE_TYPE_INDEX:
59474- fscache_stat(&fscache_n_cookie_index);
59475+ fscache_stat_unchecked(&fscache_n_cookie_index);
59476 break;
59477 case FSCACHE_COOKIE_TYPE_DATAFILE:
59478- fscache_stat(&fscache_n_cookie_data);
59479+ fscache_stat_unchecked(&fscache_n_cookie_data);
59480 break;
59481 default:
59482- fscache_stat(&fscache_n_cookie_special);
59483+ fscache_stat_unchecked(&fscache_n_cookie_special);
59484 break;
59485 }
59486
59487@@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59488 } else {
59489 atomic_dec(&parent->n_children);
59490 __fscache_cookie_put(cookie);
59491- fscache_stat(&fscache_n_acquires_nobufs);
59492+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59493 _leave(" = NULL");
59494 return NULL;
59495 }
59496@@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59497 }
59498 }
59499
59500- fscache_stat(&fscache_n_acquires_ok);
59501+ fscache_stat_unchecked(&fscache_n_acquires_ok);
59502 _leave(" = %p", cookie);
59503 return cookie;
59504 }
59505@@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59506 cache = fscache_select_cache_for_object(cookie->parent);
59507 if (!cache) {
59508 up_read(&fscache_addremove_sem);
59509- fscache_stat(&fscache_n_acquires_no_cache);
59510+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59511 _leave(" = -ENOMEDIUM [no cache]");
59512 return -ENOMEDIUM;
59513 }
59514@@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59515 object = cache->ops->alloc_object(cache, cookie);
59516 fscache_stat_d(&fscache_n_cop_alloc_object);
59517 if (IS_ERR(object)) {
59518- fscache_stat(&fscache_n_object_no_alloc);
59519+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
59520 ret = PTR_ERR(object);
59521 goto error;
59522 }
59523
59524- fscache_stat(&fscache_n_object_alloc);
59525+ fscache_stat_unchecked(&fscache_n_object_alloc);
59526
59527- object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59528+ object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59529
59530 _debug("ALLOC OBJ%x: %s {%lx}",
59531 object->debug_id, cookie->def->name, object->events);
59532@@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59533
59534 _enter("{%s}", cookie->def->name);
59535
59536- fscache_stat(&fscache_n_invalidates);
59537+ fscache_stat_unchecked(&fscache_n_invalidates);
59538
59539 /* Only permit invalidation of data files. Invalidating an index will
59540 * require the caller to release all its attachments to the tree rooted
59541@@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59542 {
59543 struct fscache_object *object;
59544
59545- fscache_stat(&fscache_n_updates);
59546+ fscache_stat_unchecked(&fscache_n_updates);
59547
59548 if (!cookie) {
59549- fscache_stat(&fscache_n_updates_null);
59550+ fscache_stat_unchecked(&fscache_n_updates_null);
59551 _leave(" [no cookie]");
59552 return;
59553 }
59554@@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59555 */
59556 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59557 {
59558- fscache_stat(&fscache_n_relinquishes);
59559+ fscache_stat_unchecked(&fscache_n_relinquishes);
59560 if (retire)
59561- fscache_stat(&fscache_n_relinquishes_retire);
59562+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59563
59564 if (!cookie) {
59565- fscache_stat(&fscache_n_relinquishes_null);
59566+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
59567 _leave(" [no cookie]");
59568 return;
59569 }
59570@@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
59571 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
59572 goto inconsistent;
59573
59574- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
59575+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59576
59577 __fscache_use_cookie(cookie);
59578 if (fscache_submit_op(object, op) < 0)
59579diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
59580index 4226f66..0fb3f45 100644
59581--- a/fs/fscache/internal.h
59582+++ b/fs/fscache/internal.h
59583@@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
59584 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
59585 extern int fscache_wait_for_operation_activation(struct fscache_object *,
59586 struct fscache_operation *,
59587- atomic_t *,
59588- atomic_t *,
59589+ atomic_unchecked_t *,
59590+ atomic_unchecked_t *,
59591 void (*)(struct fscache_operation *));
59592 extern void fscache_invalidate_writes(struct fscache_cookie *);
59593
59594@@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
59595 * stats.c
59596 */
59597 #ifdef CONFIG_FSCACHE_STATS
59598-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59599-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59600+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
59601+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
59602
59603-extern atomic_t fscache_n_op_pend;
59604-extern atomic_t fscache_n_op_run;
59605-extern atomic_t fscache_n_op_enqueue;
59606-extern atomic_t fscache_n_op_deferred_release;
59607-extern atomic_t fscache_n_op_release;
59608-extern atomic_t fscache_n_op_gc;
59609-extern atomic_t fscache_n_op_cancelled;
59610-extern atomic_t fscache_n_op_rejected;
59611+extern atomic_unchecked_t fscache_n_op_pend;
59612+extern atomic_unchecked_t fscache_n_op_run;
59613+extern atomic_unchecked_t fscache_n_op_enqueue;
59614+extern atomic_unchecked_t fscache_n_op_deferred_release;
59615+extern atomic_unchecked_t fscache_n_op_release;
59616+extern atomic_unchecked_t fscache_n_op_gc;
59617+extern atomic_unchecked_t fscache_n_op_cancelled;
59618+extern atomic_unchecked_t fscache_n_op_rejected;
59619
59620-extern atomic_t fscache_n_attr_changed;
59621-extern atomic_t fscache_n_attr_changed_ok;
59622-extern atomic_t fscache_n_attr_changed_nobufs;
59623-extern atomic_t fscache_n_attr_changed_nomem;
59624-extern atomic_t fscache_n_attr_changed_calls;
59625+extern atomic_unchecked_t fscache_n_attr_changed;
59626+extern atomic_unchecked_t fscache_n_attr_changed_ok;
59627+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
59628+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
59629+extern atomic_unchecked_t fscache_n_attr_changed_calls;
59630
59631-extern atomic_t fscache_n_allocs;
59632-extern atomic_t fscache_n_allocs_ok;
59633-extern atomic_t fscache_n_allocs_wait;
59634-extern atomic_t fscache_n_allocs_nobufs;
59635-extern atomic_t fscache_n_allocs_intr;
59636-extern atomic_t fscache_n_allocs_object_dead;
59637-extern atomic_t fscache_n_alloc_ops;
59638-extern atomic_t fscache_n_alloc_op_waits;
59639+extern atomic_unchecked_t fscache_n_allocs;
59640+extern atomic_unchecked_t fscache_n_allocs_ok;
59641+extern atomic_unchecked_t fscache_n_allocs_wait;
59642+extern atomic_unchecked_t fscache_n_allocs_nobufs;
59643+extern atomic_unchecked_t fscache_n_allocs_intr;
59644+extern atomic_unchecked_t fscache_n_allocs_object_dead;
59645+extern atomic_unchecked_t fscache_n_alloc_ops;
59646+extern atomic_unchecked_t fscache_n_alloc_op_waits;
59647
59648-extern atomic_t fscache_n_retrievals;
59649-extern atomic_t fscache_n_retrievals_ok;
59650-extern atomic_t fscache_n_retrievals_wait;
59651-extern atomic_t fscache_n_retrievals_nodata;
59652-extern atomic_t fscache_n_retrievals_nobufs;
59653-extern atomic_t fscache_n_retrievals_intr;
59654-extern atomic_t fscache_n_retrievals_nomem;
59655-extern atomic_t fscache_n_retrievals_object_dead;
59656-extern atomic_t fscache_n_retrieval_ops;
59657-extern atomic_t fscache_n_retrieval_op_waits;
59658+extern atomic_unchecked_t fscache_n_retrievals;
59659+extern atomic_unchecked_t fscache_n_retrievals_ok;
59660+extern atomic_unchecked_t fscache_n_retrievals_wait;
59661+extern atomic_unchecked_t fscache_n_retrievals_nodata;
59662+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
59663+extern atomic_unchecked_t fscache_n_retrievals_intr;
59664+extern atomic_unchecked_t fscache_n_retrievals_nomem;
59665+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
59666+extern atomic_unchecked_t fscache_n_retrieval_ops;
59667+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
59668
59669-extern atomic_t fscache_n_stores;
59670-extern atomic_t fscache_n_stores_ok;
59671-extern atomic_t fscache_n_stores_again;
59672-extern atomic_t fscache_n_stores_nobufs;
59673-extern atomic_t fscache_n_stores_oom;
59674-extern atomic_t fscache_n_store_ops;
59675-extern atomic_t fscache_n_store_calls;
59676-extern atomic_t fscache_n_store_pages;
59677-extern atomic_t fscache_n_store_radix_deletes;
59678-extern atomic_t fscache_n_store_pages_over_limit;
59679+extern atomic_unchecked_t fscache_n_stores;
59680+extern atomic_unchecked_t fscache_n_stores_ok;
59681+extern atomic_unchecked_t fscache_n_stores_again;
59682+extern atomic_unchecked_t fscache_n_stores_nobufs;
59683+extern atomic_unchecked_t fscache_n_stores_oom;
59684+extern atomic_unchecked_t fscache_n_store_ops;
59685+extern atomic_unchecked_t fscache_n_store_calls;
59686+extern atomic_unchecked_t fscache_n_store_pages;
59687+extern atomic_unchecked_t fscache_n_store_radix_deletes;
59688+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
59689
59690-extern atomic_t fscache_n_store_vmscan_not_storing;
59691-extern atomic_t fscache_n_store_vmscan_gone;
59692-extern atomic_t fscache_n_store_vmscan_busy;
59693-extern atomic_t fscache_n_store_vmscan_cancelled;
59694-extern atomic_t fscache_n_store_vmscan_wait;
59695+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59696+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
59697+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
59698+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59699+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
59700
59701-extern atomic_t fscache_n_marks;
59702-extern atomic_t fscache_n_uncaches;
59703+extern atomic_unchecked_t fscache_n_marks;
59704+extern atomic_unchecked_t fscache_n_uncaches;
59705
59706-extern atomic_t fscache_n_acquires;
59707-extern atomic_t fscache_n_acquires_null;
59708-extern atomic_t fscache_n_acquires_no_cache;
59709-extern atomic_t fscache_n_acquires_ok;
59710-extern atomic_t fscache_n_acquires_nobufs;
59711-extern atomic_t fscache_n_acquires_oom;
59712+extern atomic_unchecked_t fscache_n_acquires;
59713+extern atomic_unchecked_t fscache_n_acquires_null;
59714+extern atomic_unchecked_t fscache_n_acquires_no_cache;
59715+extern atomic_unchecked_t fscache_n_acquires_ok;
59716+extern atomic_unchecked_t fscache_n_acquires_nobufs;
59717+extern atomic_unchecked_t fscache_n_acquires_oom;
59718
59719-extern atomic_t fscache_n_invalidates;
59720-extern atomic_t fscache_n_invalidates_run;
59721+extern atomic_unchecked_t fscache_n_invalidates;
59722+extern atomic_unchecked_t fscache_n_invalidates_run;
59723
59724-extern atomic_t fscache_n_updates;
59725-extern atomic_t fscache_n_updates_null;
59726-extern atomic_t fscache_n_updates_run;
59727+extern atomic_unchecked_t fscache_n_updates;
59728+extern atomic_unchecked_t fscache_n_updates_null;
59729+extern atomic_unchecked_t fscache_n_updates_run;
59730
59731-extern atomic_t fscache_n_relinquishes;
59732-extern atomic_t fscache_n_relinquishes_null;
59733-extern atomic_t fscache_n_relinquishes_waitcrt;
59734-extern atomic_t fscache_n_relinquishes_retire;
59735+extern atomic_unchecked_t fscache_n_relinquishes;
59736+extern atomic_unchecked_t fscache_n_relinquishes_null;
59737+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59738+extern atomic_unchecked_t fscache_n_relinquishes_retire;
59739
59740-extern atomic_t fscache_n_cookie_index;
59741-extern atomic_t fscache_n_cookie_data;
59742-extern atomic_t fscache_n_cookie_special;
59743+extern atomic_unchecked_t fscache_n_cookie_index;
59744+extern atomic_unchecked_t fscache_n_cookie_data;
59745+extern atomic_unchecked_t fscache_n_cookie_special;
59746
59747-extern atomic_t fscache_n_object_alloc;
59748-extern atomic_t fscache_n_object_no_alloc;
59749-extern atomic_t fscache_n_object_lookups;
59750-extern atomic_t fscache_n_object_lookups_negative;
59751-extern atomic_t fscache_n_object_lookups_positive;
59752-extern atomic_t fscache_n_object_lookups_timed_out;
59753-extern atomic_t fscache_n_object_created;
59754-extern atomic_t fscache_n_object_avail;
59755-extern atomic_t fscache_n_object_dead;
59756+extern atomic_unchecked_t fscache_n_object_alloc;
59757+extern atomic_unchecked_t fscache_n_object_no_alloc;
59758+extern atomic_unchecked_t fscache_n_object_lookups;
59759+extern atomic_unchecked_t fscache_n_object_lookups_negative;
59760+extern atomic_unchecked_t fscache_n_object_lookups_positive;
59761+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59762+extern atomic_unchecked_t fscache_n_object_created;
59763+extern atomic_unchecked_t fscache_n_object_avail;
59764+extern atomic_unchecked_t fscache_n_object_dead;
59765
59766-extern atomic_t fscache_n_checkaux_none;
59767-extern atomic_t fscache_n_checkaux_okay;
59768-extern atomic_t fscache_n_checkaux_update;
59769-extern atomic_t fscache_n_checkaux_obsolete;
59770+extern atomic_unchecked_t fscache_n_checkaux_none;
59771+extern atomic_unchecked_t fscache_n_checkaux_okay;
59772+extern atomic_unchecked_t fscache_n_checkaux_update;
59773+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59774
59775 extern atomic_t fscache_n_cop_alloc_object;
59776 extern atomic_t fscache_n_cop_lookup_object;
59777@@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59778 atomic_inc(stat);
59779 }
59780
59781+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59782+{
59783+ atomic_inc_unchecked(stat);
59784+}
59785+
59786 static inline void fscache_stat_d(atomic_t *stat)
59787 {
59788 atomic_dec(stat);
59789@@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59790
59791 #define __fscache_stat(stat) (NULL)
59792 #define fscache_stat(stat) do {} while (0)
59793+#define fscache_stat_unchecked(stat) do {} while (0)
59794 #define fscache_stat_d(stat) do {} while (0)
59795 #endif
59796
59797diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59798index 53d35c5..5d68ed4 100644
59799--- a/fs/fscache/object.c
59800+++ b/fs/fscache/object.c
59801@@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59802 _debug("LOOKUP \"%s\" in \"%s\"",
59803 cookie->def->name, object->cache->tag->name);
59804
59805- fscache_stat(&fscache_n_object_lookups);
59806+ fscache_stat_unchecked(&fscache_n_object_lookups);
59807 fscache_stat(&fscache_n_cop_lookup_object);
59808 ret = object->cache->ops->lookup_object(object);
59809 fscache_stat_d(&fscache_n_cop_lookup_object);
59810@@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59811 if (ret == -ETIMEDOUT) {
59812 /* probably stuck behind another object, so move this one to
59813 * the back of the queue */
59814- fscache_stat(&fscache_n_object_lookups_timed_out);
59815+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59816 _leave(" [timeout]");
59817 return NO_TRANSIT;
59818 }
59819@@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59820 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59821
59822 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59823- fscache_stat(&fscache_n_object_lookups_negative);
59824+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59825
59826 /* Allow write requests to begin stacking up and read requests to begin
59827 * returning ENODATA.
59828@@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59829 /* if we were still looking up, then we must have a positive lookup
59830 * result, in which case there may be data available */
59831 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59832- fscache_stat(&fscache_n_object_lookups_positive);
59833+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59834
59835 /* We do (presumably) have data */
59836 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59837@@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59838 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59839 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59840 } else {
59841- fscache_stat(&fscache_n_object_created);
59842+ fscache_stat_unchecked(&fscache_n_object_created);
59843 }
59844
59845 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59846@@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59847 fscache_stat_d(&fscache_n_cop_lookup_complete);
59848
59849 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59850- fscache_stat(&fscache_n_object_avail);
59851+ fscache_stat_unchecked(&fscache_n_object_avail);
59852
59853 _leave("");
59854 return transit_to(JUMPSTART_DEPS);
59855@@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59856
59857 /* this just shifts the object release to the work processor */
59858 fscache_put_object(object);
59859- fscache_stat(&fscache_n_object_dead);
59860+ fscache_stat_unchecked(&fscache_n_object_dead);
59861
59862 _leave("");
59863 return transit_to(OBJECT_DEAD);
59864@@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59865 enum fscache_checkaux result;
59866
59867 if (!object->cookie->def->check_aux) {
59868- fscache_stat(&fscache_n_checkaux_none);
59869+ fscache_stat_unchecked(&fscache_n_checkaux_none);
59870 return FSCACHE_CHECKAUX_OKAY;
59871 }
59872
59873@@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59874 switch (result) {
59875 /* entry okay as is */
59876 case FSCACHE_CHECKAUX_OKAY:
59877- fscache_stat(&fscache_n_checkaux_okay);
59878+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
59879 break;
59880
59881 /* entry requires update */
59882 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59883- fscache_stat(&fscache_n_checkaux_update);
59884+ fscache_stat_unchecked(&fscache_n_checkaux_update);
59885 break;
59886
59887 /* entry requires deletion */
59888 case FSCACHE_CHECKAUX_OBSOLETE:
59889- fscache_stat(&fscache_n_checkaux_obsolete);
59890+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59891 break;
59892
59893 default:
59894@@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59895 {
59896 const struct fscache_state *s;
59897
59898- fscache_stat(&fscache_n_invalidates_run);
59899+ fscache_stat_unchecked(&fscache_n_invalidates_run);
59900 fscache_stat(&fscache_n_cop_invalidate_object);
59901 s = _fscache_invalidate_object(object, event);
59902 fscache_stat_d(&fscache_n_cop_invalidate_object);
59903@@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59904 {
59905 _enter("{OBJ%x},%d", object->debug_id, event);
59906
59907- fscache_stat(&fscache_n_updates_run);
59908+ fscache_stat_unchecked(&fscache_n_updates_run);
59909 fscache_stat(&fscache_n_cop_update_object);
59910 object->cache->ops->update_object(object);
59911 fscache_stat_d(&fscache_n_cop_update_object);
59912diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59913index 318071a..379938b 100644
59914--- a/fs/fscache/operation.c
59915+++ b/fs/fscache/operation.c
59916@@ -17,7 +17,7 @@
59917 #include <linux/slab.h>
59918 #include "internal.h"
59919
59920-atomic_t fscache_op_debug_id;
59921+atomic_unchecked_t fscache_op_debug_id;
59922 EXPORT_SYMBOL(fscache_op_debug_id);
59923
59924 /**
59925@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59926 ASSERTCMP(atomic_read(&op->usage), >, 0);
59927 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59928
59929- fscache_stat(&fscache_n_op_enqueue);
59930+ fscache_stat_unchecked(&fscache_n_op_enqueue);
59931 switch (op->flags & FSCACHE_OP_TYPE) {
59932 case FSCACHE_OP_ASYNC:
59933 _debug("queue async");
59934@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59935 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59936 if (op->processor)
59937 fscache_enqueue_operation(op);
59938- fscache_stat(&fscache_n_op_run);
59939+ fscache_stat_unchecked(&fscache_n_op_run);
59940 }
59941
59942 /*
59943@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59944 if (object->n_in_progress > 0) {
59945 atomic_inc(&op->usage);
59946 list_add_tail(&op->pend_link, &object->pending_ops);
59947- fscache_stat(&fscache_n_op_pend);
59948+ fscache_stat_unchecked(&fscache_n_op_pend);
59949 } else if (!list_empty(&object->pending_ops)) {
59950 atomic_inc(&op->usage);
59951 list_add_tail(&op->pend_link, &object->pending_ops);
59952- fscache_stat(&fscache_n_op_pend);
59953+ fscache_stat_unchecked(&fscache_n_op_pend);
59954 fscache_start_operations(object);
59955 } else {
59956 ASSERTCMP(object->n_in_progress, ==, 0);
59957@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59958 object->n_exclusive++; /* reads and writes must wait */
59959 atomic_inc(&op->usage);
59960 list_add_tail(&op->pend_link, &object->pending_ops);
59961- fscache_stat(&fscache_n_op_pend);
59962+ fscache_stat_unchecked(&fscache_n_op_pend);
59963 ret = 0;
59964 } else {
59965 /* If we're in any other state, there must have been an I/O
59966@@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59967 if (object->n_exclusive > 0) {
59968 atomic_inc(&op->usage);
59969 list_add_tail(&op->pend_link, &object->pending_ops);
59970- fscache_stat(&fscache_n_op_pend);
59971+ fscache_stat_unchecked(&fscache_n_op_pend);
59972 } else if (!list_empty(&object->pending_ops)) {
59973 atomic_inc(&op->usage);
59974 list_add_tail(&op->pend_link, &object->pending_ops);
59975- fscache_stat(&fscache_n_op_pend);
59976+ fscache_stat_unchecked(&fscache_n_op_pend);
59977 fscache_start_operations(object);
59978 } else {
59979 ASSERTCMP(object->n_exclusive, ==, 0);
59980@@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59981 object->n_ops++;
59982 atomic_inc(&op->usage);
59983 list_add_tail(&op->pend_link, &object->pending_ops);
59984- fscache_stat(&fscache_n_op_pend);
59985+ fscache_stat_unchecked(&fscache_n_op_pend);
59986 ret = 0;
59987 } else if (fscache_object_is_dying(object)) {
59988- fscache_stat(&fscache_n_op_rejected);
59989+ fscache_stat_unchecked(&fscache_n_op_rejected);
59990 op->state = FSCACHE_OP_ST_CANCELLED;
59991 ret = -ENOBUFS;
59992 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59993@@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59994 ret = -EBUSY;
59995 if (op->state == FSCACHE_OP_ST_PENDING) {
59996 ASSERT(!list_empty(&op->pend_link));
59997- fscache_stat(&fscache_n_op_cancelled);
59998+ fscache_stat_unchecked(&fscache_n_op_cancelled);
59999 list_del_init(&op->pend_link);
60000 if (do_cancel)
60001 do_cancel(op);
60002@@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60003 while (!list_empty(&object->pending_ops)) {
60004 op = list_entry(object->pending_ops.next,
60005 struct fscache_operation, pend_link);
60006- fscache_stat(&fscache_n_op_cancelled);
60007+ fscache_stat_unchecked(&fscache_n_op_cancelled);
60008 list_del_init(&op->pend_link);
60009
60010 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60011@@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60012 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60013 op->state = FSCACHE_OP_ST_DEAD;
60014
60015- fscache_stat(&fscache_n_op_release);
60016+ fscache_stat_unchecked(&fscache_n_op_release);
60017
60018 if (op->release) {
60019 op->release(op);
60020@@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60021 * lock, and defer it otherwise */
60022 if (!spin_trylock(&object->lock)) {
60023 _debug("defer put");
60024- fscache_stat(&fscache_n_op_deferred_release);
60025+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
60026
60027 cache = object->cache;
60028 spin_lock(&cache->op_gc_list_lock);
60029@@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60030
60031 _debug("GC DEFERRED REL OBJ%x OP%x",
60032 object->debug_id, op->debug_id);
60033- fscache_stat(&fscache_n_op_gc);
60034+ fscache_stat_unchecked(&fscache_n_op_gc);
60035
60036 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60037 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60038diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60039index 7f5c658..6c1e164 100644
60040--- a/fs/fscache/page.c
60041+++ b/fs/fscache/page.c
60042@@ -61,7 +61,7 @@ try_again:
60043 val = radix_tree_lookup(&cookie->stores, page->index);
60044 if (!val) {
60045 rcu_read_unlock();
60046- fscache_stat(&fscache_n_store_vmscan_not_storing);
60047+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60048 __fscache_uncache_page(cookie, page);
60049 return true;
60050 }
60051@@ -91,11 +91,11 @@ try_again:
60052 spin_unlock(&cookie->stores_lock);
60053
60054 if (xpage) {
60055- fscache_stat(&fscache_n_store_vmscan_cancelled);
60056- fscache_stat(&fscache_n_store_radix_deletes);
60057+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60058+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60059 ASSERTCMP(xpage, ==, page);
60060 } else {
60061- fscache_stat(&fscache_n_store_vmscan_gone);
60062+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60063 }
60064
60065 wake_up_bit(&cookie->flags, 0);
60066@@ -110,11 +110,11 @@ page_busy:
60067 * sleeping on memory allocation, so we may need to impose a timeout
60068 * too. */
60069 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60070- fscache_stat(&fscache_n_store_vmscan_busy);
60071+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60072 return false;
60073 }
60074
60075- fscache_stat(&fscache_n_store_vmscan_wait);
60076+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60077 __fscache_wait_on_page_write(cookie, page);
60078 gfp &= ~__GFP_WAIT;
60079 goto try_again;
60080@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60081 FSCACHE_COOKIE_STORING_TAG);
60082 if (!radix_tree_tag_get(&cookie->stores, page->index,
60083 FSCACHE_COOKIE_PENDING_TAG)) {
60084- fscache_stat(&fscache_n_store_radix_deletes);
60085+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60086 xpage = radix_tree_delete(&cookie->stores, page->index);
60087 }
60088 spin_unlock(&cookie->stores_lock);
60089@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60090
60091 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60092
60093- fscache_stat(&fscache_n_attr_changed_calls);
60094+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60095
60096 if (fscache_object_is_active(object)) {
60097 fscache_stat(&fscache_n_cop_attr_changed);
60098@@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60099
60100 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60101
60102- fscache_stat(&fscache_n_attr_changed);
60103+ fscache_stat_unchecked(&fscache_n_attr_changed);
60104
60105 op = kzalloc(sizeof(*op), GFP_KERNEL);
60106 if (!op) {
60107- fscache_stat(&fscache_n_attr_changed_nomem);
60108+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60109 _leave(" = -ENOMEM");
60110 return -ENOMEM;
60111 }
60112@@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60113 if (fscache_submit_exclusive_op(object, op) < 0)
60114 goto nobufs;
60115 spin_unlock(&cookie->lock);
60116- fscache_stat(&fscache_n_attr_changed_ok);
60117+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60118 fscache_put_operation(op);
60119 _leave(" = 0");
60120 return 0;
60121@@ -225,7 +225,7 @@ nobufs:
60122 kfree(op);
60123 if (wake_cookie)
60124 __fscache_wake_unused_cookie(cookie);
60125- fscache_stat(&fscache_n_attr_changed_nobufs);
60126+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60127 _leave(" = %d", -ENOBUFS);
60128 return -ENOBUFS;
60129 }
60130@@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60131 /* allocate a retrieval operation and attempt to submit it */
60132 op = kzalloc(sizeof(*op), GFP_NOIO);
60133 if (!op) {
60134- fscache_stat(&fscache_n_retrievals_nomem);
60135+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60136 return NULL;
60137 }
60138
60139@@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60140 return 0;
60141 }
60142
60143- fscache_stat(&fscache_n_retrievals_wait);
60144+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
60145
60146 jif = jiffies;
60147 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60148 fscache_wait_bit_interruptible,
60149 TASK_INTERRUPTIBLE) != 0) {
60150- fscache_stat(&fscache_n_retrievals_intr);
60151+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60152 _leave(" = -ERESTARTSYS");
60153 return -ERESTARTSYS;
60154 }
60155@@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60156 */
60157 int fscache_wait_for_operation_activation(struct fscache_object *object,
60158 struct fscache_operation *op,
60159- atomic_t *stat_op_waits,
60160- atomic_t *stat_object_dead,
60161+ atomic_unchecked_t *stat_op_waits,
60162+ atomic_unchecked_t *stat_object_dead,
60163 void (*do_cancel)(struct fscache_operation *))
60164 {
60165 int ret;
60166@@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60167
60168 _debug(">>> WT");
60169 if (stat_op_waits)
60170- fscache_stat(stat_op_waits);
60171+ fscache_stat_unchecked(stat_op_waits);
60172 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60173 fscache_wait_bit_interruptible,
60174 TASK_INTERRUPTIBLE) != 0) {
60175@@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60176 check_if_dead:
60177 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60178 if (stat_object_dead)
60179- fscache_stat(stat_object_dead);
60180+ fscache_stat_unchecked(stat_object_dead);
60181 _leave(" = -ENOBUFS [cancelled]");
60182 return -ENOBUFS;
60183 }
60184@@ -366,7 +366,7 @@ check_if_dead:
60185 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60186 fscache_cancel_op(op, do_cancel);
60187 if (stat_object_dead)
60188- fscache_stat(stat_object_dead);
60189+ fscache_stat_unchecked(stat_object_dead);
60190 return -ENOBUFS;
60191 }
60192 return 0;
60193@@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60194
60195 _enter("%p,%p,,,", cookie, page);
60196
60197- fscache_stat(&fscache_n_retrievals);
60198+ fscache_stat_unchecked(&fscache_n_retrievals);
60199
60200 if (hlist_empty(&cookie->backing_objects))
60201 goto nobufs;
60202@@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60203 goto nobufs_unlock_dec;
60204 spin_unlock(&cookie->lock);
60205
60206- fscache_stat(&fscache_n_retrieval_ops);
60207+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60208
60209 /* pin the netfs read context in case we need to do the actual netfs
60210 * read because we've encountered a cache read failure */
60211@@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60212
60213 error:
60214 if (ret == -ENOMEM)
60215- fscache_stat(&fscache_n_retrievals_nomem);
60216+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60217 else if (ret == -ERESTARTSYS)
60218- fscache_stat(&fscache_n_retrievals_intr);
60219+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60220 else if (ret == -ENODATA)
60221- fscache_stat(&fscache_n_retrievals_nodata);
60222+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60223 else if (ret < 0)
60224- fscache_stat(&fscache_n_retrievals_nobufs);
60225+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60226 else
60227- fscache_stat(&fscache_n_retrievals_ok);
60228+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60229
60230 fscache_put_retrieval(op);
60231 _leave(" = %d", ret);
60232@@ -490,7 +490,7 @@ nobufs_unlock:
60233 __fscache_wake_unused_cookie(cookie);
60234 kfree(op);
60235 nobufs:
60236- fscache_stat(&fscache_n_retrievals_nobufs);
60237+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60238 _leave(" = -ENOBUFS");
60239 return -ENOBUFS;
60240 }
60241@@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60242
60243 _enter("%p,,%d,,,", cookie, *nr_pages);
60244
60245- fscache_stat(&fscache_n_retrievals);
60246+ fscache_stat_unchecked(&fscache_n_retrievals);
60247
60248 if (hlist_empty(&cookie->backing_objects))
60249 goto nobufs;
60250@@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60251 goto nobufs_unlock_dec;
60252 spin_unlock(&cookie->lock);
60253
60254- fscache_stat(&fscache_n_retrieval_ops);
60255+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
60256
60257 /* pin the netfs read context in case we need to do the actual netfs
60258 * read because we've encountered a cache read failure */
60259@@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60260
60261 error:
60262 if (ret == -ENOMEM)
60263- fscache_stat(&fscache_n_retrievals_nomem);
60264+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60265 else if (ret == -ERESTARTSYS)
60266- fscache_stat(&fscache_n_retrievals_intr);
60267+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
60268 else if (ret == -ENODATA)
60269- fscache_stat(&fscache_n_retrievals_nodata);
60270+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60271 else if (ret < 0)
60272- fscache_stat(&fscache_n_retrievals_nobufs);
60273+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60274 else
60275- fscache_stat(&fscache_n_retrievals_ok);
60276+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
60277
60278 fscache_put_retrieval(op);
60279 _leave(" = %d", ret);
60280@@ -621,7 +621,7 @@ nobufs_unlock:
60281 if (wake_cookie)
60282 __fscache_wake_unused_cookie(cookie);
60283 nobufs:
60284- fscache_stat(&fscache_n_retrievals_nobufs);
60285+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60286 _leave(" = -ENOBUFS");
60287 return -ENOBUFS;
60288 }
60289@@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60290
60291 _enter("%p,%p,,,", cookie, page);
60292
60293- fscache_stat(&fscache_n_allocs);
60294+ fscache_stat_unchecked(&fscache_n_allocs);
60295
60296 if (hlist_empty(&cookie->backing_objects))
60297 goto nobufs;
60298@@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60299 goto nobufs_unlock_dec;
60300 spin_unlock(&cookie->lock);
60301
60302- fscache_stat(&fscache_n_alloc_ops);
60303+ fscache_stat_unchecked(&fscache_n_alloc_ops);
60304
60305 ret = fscache_wait_for_operation_activation(
60306 object, &op->op,
60307@@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60308
60309 error:
60310 if (ret == -ERESTARTSYS)
60311- fscache_stat(&fscache_n_allocs_intr);
60312+ fscache_stat_unchecked(&fscache_n_allocs_intr);
60313 else if (ret < 0)
60314- fscache_stat(&fscache_n_allocs_nobufs);
60315+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60316 else
60317- fscache_stat(&fscache_n_allocs_ok);
60318+ fscache_stat_unchecked(&fscache_n_allocs_ok);
60319
60320 fscache_put_retrieval(op);
60321 _leave(" = %d", ret);
60322@@ -715,7 +715,7 @@ nobufs_unlock:
60323 if (wake_cookie)
60324 __fscache_wake_unused_cookie(cookie);
60325 nobufs:
60326- fscache_stat(&fscache_n_allocs_nobufs);
60327+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60328 _leave(" = -ENOBUFS");
60329 return -ENOBUFS;
60330 }
60331@@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60332
60333 spin_lock(&cookie->stores_lock);
60334
60335- fscache_stat(&fscache_n_store_calls);
60336+ fscache_stat_unchecked(&fscache_n_store_calls);
60337
60338 /* find a page to store */
60339 page = NULL;
60340@@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60341 page = results[0];
60342 _debug("gang %d [%lx]", n, page->index);
60343 if (page->index > op->store_limit) {
60344- fscache_stat(&fscache_n_store_pages_over_limit);
60345+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60346 goto superseded;
60347 }
60348
60349@@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60350 spin_unlock(&cookie->stores_lock);
60351 spin_unlock(&object->lock);
60352
60353- fscache_stat(&fscache_n_store_pages);
60354+ fscache_stat_unchecked(&fscache_n_store_pages);
60355 fscache_stat(&fscache_n_cop_write_page);
60356 ret = object->cache->ops->write_page(op, page);
60357 fscache_stat_d(&fscache_n_cop_write_page);
60358@@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60359 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60360 ASSERT(PageFsCache(page));
60361
60362- fscache_stat(&fscache_n_stores);
60363+ fscache_stat_unchecked(&fscache_n_stores);
60364
60365 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60366 _leave(" = -ENOBUFS [invalidating]");
60367@@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60368 spin_unlock(&cookie->stores_lock);
60369 spin_unlock(&object->lock);
60370
60371- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60372+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60373 op->store_limit = object->store_limit;
60374
60375 __fscache_use_cookie(cookie);
60376@@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60377
60378 spin_unlock(&cookie->lock);
60379 radix_tree_preload_end();
60380- fscache_stat(&fscache_n_store_ops);
60381- fscache_stat(&fscache_n_stores_ok);
60382+ fscache_stat_unchecked(&fscache_n_store_ops);
60383+ fscache_stat_unchecked(&fscache_n_stores_ok);
60384
60385 /* the work queue now carries its own ref on the object */
60386 fscache_put_operation(&op->op);
60387@@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60388 return 0;
60389
60390 already_queued:
60391- fscache_stat(&fscache_n_stores_again);
60392+ fscache_stat_unchecked(&fscache_n_stores_again);
60393 already_pending:
60394 spin_unlock(&cookie->stores_lock);
60395 spin_unlock(&object->lock);
60396 spin_unlock(&cookie->lock);
60397 radix_tree_preload_end();
60398 kfree(op);
60399- fscache_stat(&fscache_n_stores_ok);
60400+ fscache_stat_unchecked(&fscache_n_stores_ok);
60401 _leave(" = 0");
60402 return 0;
60403
60404@@ -1024,14 +1024,14 @@ nobufs:
60405 kfree(op);
60406 if (wake_cookie)
60407 __fscache_wake_unused_cookie(cookie);
60408- fscache_stat(&fscache_n_stores_nobufs);
60409+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
60410 _leave(" = -ENOBUFS");
60411 return -ENOBUFS;
60412
60413 nomem_free:
60414 kfree(op);
60415 nomem:
60416- fscache_stat(&fscache_n_stores_oom);
60417+ fscache_stat_unchecked(&fscache_n_stores_oom);
60418 _leave(" = -ENOMEM");
60419 return -ENOMEM;
60420 }
60421@@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60422 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60423 ASSERTCMP(page, !=, NULL);
60424
60425- fscache_stat(&fscache_n_uncaches);
60426+ fscache_stat_unchecked(&fscache_n_uncaches);
60427
60428 /* cache withdrawal may beat us to it */
60429 if (!PageFsCache(page))
60430@@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60431 struct fscache_cookie *cookie = op->op.object->cookie;
60432
60433 #ifdef CONFIG_FSCACHE_STATS
60434- atomic_inc(&fscache_n_marks);
60435+ atomic_inc_unchecked(&fscache_n_marks);
60436 #endif
60437
60438 _debug("- mark %p{%lx}", page, page->index);
60439diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60440index 40d13c7..ddf52b9 100644
60441--- a/fs/fscache/stats.c
60442+++ b/fs/fscache/stats.c
60443@@ -18,99 +18,99 @@
60444 /*
60445 * operation counters
60446 */
60447-atomic_t fscache_n_op_pend;
60448-atomic_t fscache_n_op_run;
60449-atomic_t fscache_n_op_enqueue;
60450-atomic_t fscache_n_op_requeue;
60451-atomic_t fscache_n_op_deferred_release;
60452-atomic_t fscache_n_op_release;
60453-atomic_t fscache_n_op_gc;
60454-atomic_t fscache_n_op_cancelled;
60455-atomic_t fscache_n_op_rejected;
60456+atomic_unchecked_t fscache_n_op_pend;
60457+atomic_unchecked_t fscache_n_op_run;
60458+atomic_unchecked_t fscache_n_op_enqueue;
60459+atomic_unchecked_t fscache_n_op_requeue;
60460+atomic_unchecked_t fscache_n_op_deferred_release;
60461+atomic_unchecked_t fscache_n_op_release;
60462+atomic_unchecked_t fscache_n_op_gc;
60463+atomic_unchecked_t fscache_n_op_cancelled;
60464+atomic_unchecked_t fscache_n_op_rejected;
60465
60466-atomic_t fscache_n_attr_changed;
60467-atomic_t fscache_n_attr_changed_ok;
60468-atomic_t fscache_n_attr_changed_nobufs;
60469-atomic_t fscache_n_attr_changed_nomem;
60470-atomic_t fscache_n_attr_changed_calls;
60471+atomic_unchecked_t fscache_n_attr_changed;
60472+atomic_unchecked_t fscache_n_attr_changed_ok;
60473+atomic_unchecked_t fscache_n_attr_changed_nobufs;
60474+atomic_unchecked_t fscache_n_attr_changed_nomem;
60475+atomic_unchecked_t fscache_n_attr_changed_calls;
60476
60477-atomic_t fscache_n_allocs;
60478-atomic_t fscache_n_allocs_ok;
60479-atomic_t fscache_n_allocs_wait;
60480-atomic_t fscache_n_allocs_nobufs;
60481-atomic_t fscache_n_allocs_intr;
60482-atomic_t fscache_n_allocs_object_dead;
60483-atomic_t fscache_n_alloc_ops;
60484-atomic_t fscache_n_alloc_op_waits;
60485+atomic_unchecked_t fscache_n_allocs;
60486+atomic_unchecked_t fscache_n_allocs_ok;
60487+atomic_unchecked_t fscache_n_allocs_wait;
60488+atomic_unchecked_t fscache_n_allocs_nobufs;
60489+atomic_unchecked_t fscache_n_allocs_intr;
60490+atomic_unchecked_t fscache_n_allocs_object_dead;
60491+atomic_unchecked_t fscache_n_alloc_ops;
60492+atomic_unchecked_t fscache_n_alloc_op_waits;
60493
60494-atomic_t fscache_n_retrievals;
60495-atomic_t fscache_n_retrievals_ok;
60496-atomic_t fscache_n_retrievals_wait;
60497-atomic_t fscache_n_retrievals_nodata;
60498-atomic_t fscache_n_retrievals_nobufs;
60499-atomic_t fscache_n_retrievals_intr;
60500-atomic_t fscache_n_retrievals_nomem;
60501-atomic_t fscache_n_retrievals_object_dead;
60502-atomic_t fscache_n_retrieval_ops;
60503-atomic_t fscache_n_retrieval_op_waits;
60504+atomic_unchecked_t fscache_n_retrievals;
60505+atomic_unchecked_t fscache_n_retrievals_ok;
60506+atomic_unchecked_t fscache_n_retrievals_wait;
60507+atomic_unchecked_t fscache_n_retrievals_nodata;
60508+atomic_unchecked_t fscache_n_retrievals_nobufs;
60509+atomic_unchecked_t fscache_n_retrievals_intr;
60510+atomic_unchecked_t fscache_n_retrievals_nomem;
60511+atomic_unchecked_t fscache_n_retrievals_object_dead;
60512+atomic_unchecked_t fscache_n_retrieval_ops;
60513+atomic_unchecked_t fscache_n_retrieval_op_waits;
60514
60515-atomic_t fscache_n_stores;
60516-atomic_t fscache_n_stores_ok;
60517-atomic_t fscache_n_stores_again;
60518-atomic_t fscache_n_stores_nobufs;
60519-atomic_t fscache_n_stores_oom;
60520-atomic_t fscache_n_store_ops;
60521-atomic_t fscache_n_store_calls;
60522-atomic_t fscache_n_store_pages;
60523-atomic_t fscache_n_store_radix_deletes;
60524-atomic_t fscache_n_store_pages_over_limit;
60525+atomic_unchecked_t fscache_n_stores;
60526+atomic_unchecked_t fscache_n_stores_ok;
60527+atomic_unchecked_t fscache_n_stores_again;
60528+atomic_unchecked_t fscache_n_stores_nobufs;
60529+atomic_unchecked_t fscache_n_stores_oom;
60530+atomic_unchecked_t fscache_n_store_ops;
60531+atomic_unchecked_t fscache_n_store_calls;
60532+atomic_unchecked_t fscache_n_store_pages;
60533+atomic_unchecked_t fscache_n_store_radix_deletes;
60534+atomic_unchecked_t fscache_n_store_pages_over_limit;
60535
60536-atomic_t fscache_n_store_vmscan_not_storing;
60537-atomic_t fscache_n_store_vmscan_gone;
60538-atomic_t fscache_n_store_vmscan_busy;
60539-atomic_t fscache_n_store_vmscan_cancelled;
60540-atomic_t fscache_n_store_vmscan_wait;
60541+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60542+atomic_unchecked_t fscache_n_store_vmscan_gone;
60543+atomic_unchecked_t fscache_n_store_vmscan_busy;
60544+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60545+atomic_unchecked_t fscache_n_store_vmscan_wait;
60546
60547-atomic_t fscache_n_marks;
60548-atomic_t fscache_n_uncaches;
60549+atomic_unchecked_t fscache_n_marks;
60550+atomic_unchecked_t fscache_n_uncaches;
60551
60552-atomic_t fscache_n_acquires;
60553-atomic_t fscache_n_acquires_null;
60554-atomic_t fscache_n_acquires_no_cache;
60555-atomic_t fscache_n_acquires_ok;
60556-atomic_t fscache_n_acquires_nobufs;
60557-atomic_t fscache_n_acquires_oom;
60558+atomic_unchecked_t fscache_n_acquires;
60559+atomic_unchecked_t fscache_n_acquires_null;
60560+atomic_unchecked_t fscache_n_acquires_no_cache;
60561+atomic_unchecked_t fscache_n_acquires_ok;
60562+atomic_unchecked_t fscache_n_acquires_nobufs;
60563+atomic_unchecked_t fscache_n_acquires_oom;
60564
60565-atomic_t fscache_n_invalidates;
60566-atomic_t fscache_n_invalidates_run;
60567+atomic_unchecked_t fscache_n_invalidates;
60568+atomic_unchecked_t fscache_n_invalidates_run;
60569
60570-atomic_t fscache_n_updates;
60571-atomic_t fscache_n_updates_null;
60572-atomic_t fscache_n_updates_run;
60573+atomic_unchecked_t fscache_n_updates;
60574+atomic_unchecked_t fscache_n_updates_null;
60575+atomic_unchecked_t fscache_n_updates_run;
60576
60577-atomic_t fscache_n_relinquishes;
60578-atomic_t fscache_n_relinquishes_null;
60579-atomic_t fscache_n_relinquishes_waitcrt;
60580-atomic_t fscache_n_relinquishes_retire;
60581+atomic_unchecked_t fscache_n_relinquishes;
60582+atomic_unchecked_t fscache_n_relinquishes_null;
60583+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60584+atomic_unchecked_t fscache_n_relinquishes_retire;
60585
60586-atomic_t fscache_n_cookie_index;
60587-atomic_t fscache_n_cookie_data;
60588-atomic_t fscache_n_cookie_special;
60589+atomic_unchecked_t fscache_n_cookie_index;
60590+atomic_unchecked_t fscache_n_cookie_data;
60591+atomic_unchecked_t fscache_n_cookie_special;
60592
60593-atomic_t fscache_n_object_alloc;
60594-atomic_t fscache_n_object_no_alloc;
60595-atomic_t fscache_n_object_lookups;
60596-atomic_t fscache_n_object_lookups_negative;
60597-atomic_t fscache_n_object_lookups_positive;
60598-atomic_t fscache_n_object_lookups_timed_out;
60599-atomic_t fscache_n_object_created;
60600-atomic_t fscache_n_object_avail;
60601-atomic_t fscache_n_object_dead;
60602+atomic_unchecked_t fscache_n_object_alloc;
60603+atomic_unchecked_t fscache_n_object_no_alloc;
60604+atomic_unchecked_t fscache_n_object_lookups;
60605+atomic_unchecked_t fscache_n_object_lookups_negative;
60606+atomic_unchecked_t fscache_n_object_lookups_positive;
60607+atomic_unchecked_t fscache_n_object_lookups_timed_out;
60608+atomic_unchecked_t fscache_n_object_created;
60609+atomic_unchecked_t fscache_n_object_avail;
60610+atomic_unchecked_t fscache_n_object_dead;
60611
60612-atomic_t fscache_n_checkaux_none;
60613-atomic_t fscache_n_checkaux_okay;
60614-atomic_t fscache_n_checkaux_update;
60615-atomic_t fscache_n_checkaux_obsolete;
60616+atomic_unchecked_t fscache_n_checkaux_none;
60617+atomic_unchecked_t fscache_n_checkaux_okay;
60618+atomic_unchecked_t fscache_n_checkaux_update;
60619+atomic_unchecked_t fscache_n_checkaux_obsolete;
60620
60621 atomic_t fscache_n_cop_alloc_object;
60622 atomic_t fscache_n_cop_lookup_object;
60623@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
60624 seq_puts(m, "FS-Cache statistics\n");
60625
60626 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
60627- atomic_read(&fscache_n_cookie_index),
60628- atomic_read(&fscache_n_cookie_data),
60629- atomic_read(&fscache_n_cookie_special));
60630+ atomic_read_unchecked(&fscache_n_cookie_index),
60631+ atomic_read_unchecked(&fscache_n_cookie_data),
60632+ atomic_read_unchecked(&fscache_n_cookie_special));
60633
60634 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
60635- atomic_read(&fscache_n_object_alloc),
60636- atomic_read(&fscache_n_object_no_alloc),
60637- atomic_read(&fscache_n_object_avail),
60638- atomic_read(&fscache_n_object_dead));
60639+ atomic_read_unchecked(&fscache_n_object_alloc),
60640+ atomic_read_unchecked(&fscache_n_object_no_alloc),
60641+ atomic_read_unchecked(&fscache_n_object_avail),
60642+ atomic_read_unchecked(&fscache_n_object_dead));
60643 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
60644- atomic_read(&fscache_n_checkaux_none),
60645- atomic_read(&fscache_n_checkaux_okay),
60646- atomic_read(&fscache_n_checkaux_update),
60647- atomic_read(&fscache_n_checkaux_obsolete));
60648+ atomic_read_unchecked(&fscache_n_checkaux_none),
60649+ atomic_read_unchecked(&fscache_n_checkaux_okay),
60650+ atomic_read_unchecked(&fscache_n_checkaux_update),
60651+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
60652
60653 seq_printf(m, "Pages : mrk=%u unc=%u\n",
60654- atomic_read(&fscache_n_marks),
60655- atomic_read(&fscache_n_uncaches));
60656+ atomic_read_unchecked(&fscache_n_marks),
60657+ atomic_read_unchecked(&fscache_n_uncaches));
60658
60659 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
60660 " oom=%u\n",
60661- atomic_read(&fscache_n_acquires),
60662- atomic_read(&fscache_n_acquires_null),
60663- atomic_read(&fscache_n_acquires_no_cache),
60664- atomic_read(&fscache_n_acquires_ok),
60665- atomic_read(&fscache_n_acquires_nobufs),
60666- atomic_read(&fscache_n_acquires_oom));
60667+ atomic_read_unchecked(&fscache_n_acquires),
60668+ atomic_read_unchecked(&fscache_n_acquires_null),
60669+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
60670+ atomic_read_unchecked(&fscache_n_acquires_ok),
60671+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
60672+ atomic_read_unchecked(&fscache_n_acquires_oom));
60673
60674 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
60675- atomic_read(&fscache_n_object_lookups),
60676- atomic_read(&fscache_n_object_lookups_negative),
60677- atomic_read(&fscache_n_object_lookups_positive),
60678- atomic_read(&fscache_n_object_created),
60679- atomic_read(&fscache_n_object_lookups_timed_out));
60680+ atomic_read_unchecked(&fscache_n_object_lookups),
60681+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
60682+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
60683+ atomic_read_unchecked(&fscache_n_object_created),
60684+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
60685
60686 seq_printf(m, "Invals : n=%u run=%u\n",
60687- atomic_read(&fscache_n_invalidates),
60688- atomic_read(&fscache_n_invalidates_run));
60689+ atomic_read_unchecked(&fscache_n_invalidates),
60690+ atomic_read_unchecked(&fscache_n_invalidates_run));
60691
60692 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
60693- atomic_read(&fscache_n_updates),
60694- atomic_read(&fscache_n_updates_null),
60695- atomic_read(&fscache_n_updates_run));
60696+ atomic_read_unchecked(&fscache_n_updates),
60697+ atomic_read_unchecked(&fscache_n_updates_null),
60698+ atomic_read_unchecked(&fscache_n_updates_run));
60699
60700 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
60701- atomic_read(&fscache_n_relinquishes),
60702- atomic_read(&fscache_n_relinquishes_null),
60703- atomic_read(&fscache_n_relinquishes_waitcrt),
60704- atomic_read(&fscache_n_relinquishes_retire));
60705+ atomic_read_unchecked(&fscache_n_relinquishes),
60706+ atomic_read_unchecked(&fscache_n_relinquishes_null),
60707+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
60708+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
60709
60710 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
60711- atomic_read(&fscache_n_attr_changed),
60712- atomic_read(&fscache_n_attr_changed_ok),
60713- atomic_read(&fscache_n_attr_changed_nobufs),
60714- atomic_read(&fscache_n_attr_changed_nomem),
60715- atomic_read(&fscache_n_attr_changed_calls));
60716+ atomic_read_unchecked(&fscache_n_attr_changed),
60717+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
60718+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
60719+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
60720+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
60721
60722 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
60723- atomic_read(&fscache_n_allocs),
60724- atomic_read(&fscache_n_allocs_ok),
60725- atomic_read(&fscache_n_allocs_wait),
60726- atomic_read(&fscache_n_allocs_nobufs),
60727- atomic_read(&fscache_n_allocs_intr));
60728+ atomic_read_unchecked(&fscache_n_allocs),
60729+ atomic_read_unchecked(&fscache_n_allocs_ok),
60730+ atomic_read_unchecked(&fscache_n_allocs_wait),
60731+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
60732+ atomic_read_unchecked(&fscache_n_allocs_intr));
60733 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
60734- atomic_read(&fscache_n_alloc_ops),
60735- atomic_read(&fscache_n_alloc_op_waits),
60736- atomic_read(&fscache_n_allocs_object_dead));
60737+ atomic_read_unchecked(&fscache_n_alloc_ops),
60738+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
60739+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
60740
60741 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
60742 " int=%u oom=%u\n",
60743- atomic_read(&fscache_n_retrievals),
60744- atomic_read(&fscache_n_retrievals_ok),
60745- atomic_read(&fscache_n_retrievals_wait),
60746- atomic_read(&fscache_n_retrievals_nodata),
60747- atomic_read(&fscache_n_retrievals_nobufs),
60748- atomic_read(&fscache_n_retrievals_intr),
60749- atomic_read(&fscache_n_retrievals_nomem));
60750+ atomic_read_unchecked(&fscache_n_retrievals),
60751+ atomic_read_unchecked(&fscache_n_retrievals_ok),
60752+ atomic_read_unchecked(&fscache_n_retrievals_wait),
60753+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
60754+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60755+ atomic_read_unchecked(&fscache_n_retrievals_intr),
60756+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
60757 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60758- atomic_read(&fscache_n_retrieval_ops),
60759- atomic_read(&fscache_n_retrieval_op_waits),
60760- atomic_read(&fscache_n_retrievals_object_dead));
60761+ atomic_read_unchecked(&fscache_n_retrieval_ops),
60762+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60763+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60764
60765 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60766- atomic_read(&fscache_n_stores),
60767- atomic_read(&fscache_n_stores_ok),
60768- atomic_read(&fscache_n_stores_again),
60769- atomic_read(&fscache_n_stores_nobufs),
60770- atomic_read(&fscache_n_stores_oom));
60771+ atomic_read_unchecked(&fscache_n_stores),
60772+ atomic_read_unchecked(&fscache_n_stores_ok),
60773+ atomic_read_unchecked(&fscache_n_stores_again),
60774+ atomic_read_unchecked(&fscache_n_stores_nobufs),
60775+ atomic_read_unchecked(&fscache_n_stores_oom));
60776 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60777- atomic_read(&fscache_n_store_ops),
60778- atomic_read(&fscache_n_store_calls),
60779- atomic_read(&fscache_n_store_pages),
60780- atomic_read(&fscache_n_store_radix_deletes),
60781- atomic_read(&fscache_n_store_pages_over_limit));
60782+ atomic_read_unchecked(&fscache_n_store_ops),
60783+ atomic_read_unchecked(&fscache_n_store_calls),
60784+ atomic_read_unchecked(&fscache_n_store_pages),
60785+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
60786+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60787
60788 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60789- atomic_read(&fscache_n_store_vmscan_not_storing),
60790- atomic_read(&fscache_n_store_vmscan_gone),
60791- atomic_read(&fscache_n_store_vmscan_busy),
60792- atomic_read(&fscache_n_store_vmscan_cancelled),
60793- atomic_read(&fscache_n_store_vmscan_wait));
60794+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60795+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60796+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60797+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60798+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60799
60800 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60801- atomic_read(&fscache_n_op_pend),
60802- atomic_read(&fscache_n_op_run),
60803- atomic_read(&fscache_n_op_enqueue),
60804- atomic_read(&fscache_n_op_cancelled),
60805- atomic_read(&fscache_n_op_rejected));
60806+ atomic_read_unchecked(&fscache_n_op_pend),
60807+ atomic_read_unchecked(&fscache_n_op_run),
60808+ atomic_read_unchecked(&fscache_n_op_enqueue),
60809+ atomic_read_unchecked(&fscache_n_op_cancelled),
60810+ atomic_read_unchecked(&fscache_n_op_rejected));
60811 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60812- atomic_read(&fscache_n_op_deferred_release),
60813- atomic_read(&fscache_n_op_release),
60814- atomic_read(&fscache_n_op_gc));
60815+ atomic_read_unchecked(&fscache_n_op_deferred_release),
60816+ atomic_read_unchecked(&fscache_n_op_release),
60817+ atomic_read_unchecked(&fscache_n_op_gc));
60818
60819 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60820 atomic_read(&fscache_n_cop_alloc_object),
60821diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60822index b96a49b..9bfdc47 100644
60823--- a/fs/fuse/cuse.c
60824+++ b/fs/fuse/cuse.c
60825@@ -606,10 +606,12 @@ static int __init cuse_init(void)
60826 INIT_LIST_HEAD(&cuse_conntbl[i]);
60827
60828 /* inherit and extend fuse_dev_operations */
60829- cuse_channel_fops = fuse_dev_operations;
60830- cuse_channel_fops.owner = THIS_MODULE;
60831- cuse_channel_fops.open = cuse_channel_open;
60832- cuse_channel_fops.release = cuse_channel_release;
60833+ pax_open_kernel();
60834+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60835+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60836+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
60837+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
60838+ pax_close_kernel();
60839
60840 cuse_class = class_create(THIS_MODULE, "cuse");
60841 if (IS_ERR(cuse_class))
60842diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60843index fa8cb4b..4acb935 100644
60844--- a/fs/fuse/dev.c
60845+++ b/fs/fuse/dev.c
60846@@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60847 ret = 0;
60848 pipe_lock(pipe);
60849
60850- if (!pipe->readers) {
60851+ if (!atomic_read(&pipe->readers)) {
60852 send_sig(SIGPIPE, current, 0);
60853 if (!ret)
60854 ret = -EPIPE;
60855@@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60856 page_nr++;
60857 ret += buf->len;
60858
60859- if (pipe->files)
60860+ if (atomic_read(&pipe->files))
60861 do_wakeup = 1;
60862 }
60863
60864diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60865index c3eb2c4..98007d4 100644
60866--- a/fs/fuse/dir.c
60867+++ b/fs/fuse/dir.c
60868@@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60869 return link;
60870 }
60871
60872-static void free_link(char *link)
60873+static void free_link(const char *link)
60874 {
60875 if (!IS_ERR(link))
60876 free_page((unsigned long) link);
60877diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60878index db23ce1..9e6cd9d 100644
60879--- a/fs/hostfs/hostfs_kern.c
60880+++ b/fs/hostfs/hostfs_kern.c
60881@@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60882
60883 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60884 {
60885- char *s = nd_get_link(nd);
60886+ const char *s = nd_get_link(nd);
60887 if (!IS_ERR(s))
60888 __putname(s);
60889 }
60890diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60891index d19b30a..ef89c36 100644
60892--- a/fs/hugetlbfs/inode.c
60893+++ b/fs/hugetlbfs/inode.c
60894@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60895 struct mm_struct *mm = current->mm;
60896 struct vm_area_struct *vma;
60897 struct hstate *h = hstate_file(file);
60898+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60899 struct vm_unmapped_area_info info;
60900
60901 if (len & ~huge_page_mask(h))
60902@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60903 return addr;
60904 }
60905
60906+#ifdef CONFIG_PAX_RANDMMAP
60907+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60908+#endif
60909+
60910 if (addr) {
60911 addr = ALIGN(addr, huge_page_size(h));
60912 vma = find_vma(mm, addr);
60913- if (TASK_SIZE - len >= addr &&
60914- (!vma || addr + len <= vma->vm_start))
60915+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60916 return addr;
60917 }
60918
60919 info.flags = 0;
60920 info.length = len;
60921 info.low_limit = TASK_UNMAPPED_BASE;
60922+
60923+#ifdef CONFIG_PAX_RANDMMAP
60924+ if (mm->pax_flags & MF_PAX_RANDMMAP)
60925+ info.low_limit += mm->delta_mmap;
60926+#endif
60927+
60928 info.high_limit = TASK_SIZE;
60929 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60930 info.align_offset = 0;
60931@@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60932 };
60933 MODULE_ALIAS_FS("hugetlbfs");
60934
60935-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60936+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60937
60938 static int can_do_hugetlb_shm(void)
60939 {
60940diff --git a/fs/inode.c b/fs/inode.c
60941index 4bcdad3..1883822 100644
60942--- a/fs/inode.c
60943+++ b/fs/inode.c
60944@@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60945
60946 #ifdef CONFIG_SMP
60947 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60948- static atomic_t shared_last_ino;
60949- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60950+ static atomic_unchecked_t shared_last_ino;
60951+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60952
60953 res = next - LAST_INO_BATCH;
60954 }
60955diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60956index 4a6cf28..d3a29d3 100644
60957--- a/fs/jffs2/erase.c
60958+++ b/fs/jffs2/erase.c
60959@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60960 struct jffs2_unknown_node marker = {
60961 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60962 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60963- .totlen = cpu_to_je32(c->cleanmarker_size)
60964+ .totlen = cpu_to_je32(c->cleanmarker_size),
60965+ .hdr_crc = cpu_to_je32(0)
60966 };
60967
60968 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60969diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60970index a6597d6..41b30ec 100644
60971--- a/fs/jffs2/wbuf.c
60972+++ b/fs/jffs2/wbuf.c
60973@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60974 {
60975 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60976 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60977- .totlen = constant_cpu_to_je32(8)
60978+ .totlen = constant_cpu_to_je32(8),
60979+ .hdr_crc = constant_cpu_to_je32(0)
60980 };
60981
60982 /*
60983diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60984index 6669aa2..36b033d 100644
60985--- a/fs/jfs/super.c
60986+++ b/fs/jfs/super.c
60987@@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60988
60989 jfs_inode_cachep =
60990 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60991- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60992+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60993 init_once);
60994 if (jfs_inode_cachep == NULL)
60995 return -ENOMEM;
60996diff --git a/fs/libfs.c b/fs/libfs.c
60997index a184424..944ddce 100644
60998--- a/fs/libfs.c
60999+++ b/fs/libfs.c
61000@@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61001
61002 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61003 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61004+ char d_name[sizeof(next->d_iname)];
61005+ const unsigned char *name;
61006+
61007 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61008 if (!simple_positive(next)) {
61009 spin_unlock(&next->d_lock);
61010@@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61011
61012 spin_unlock(&next->d_lock);
61013 spin_unlock(&dentry->d_lock);
61014- if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61015+ name = next->d_name.name;
61016+ if (name == next->d_iname) {
61017+ memcpy(d_name, name, next->d_name.len);
61018+ name = d_name;
61019+ }
61020+ if (!dir_emit(ctx, name, next->d_name.len,
61021 next->d_inode->i_ino, dt_type(next->d_inode)))
61022 return 0;
61023 spin_lock(&dentry->d_lock);
61024@@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61025 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61026 void *cookie)
61027 {
61028- char *s = nd_get_link(nd);
61029+ const char *s = nd_get_link(nd);
61030 if (!IS_ERR(s))
61031 kfree(s);
61032 }
61033diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61034index acd3947..1f896e2 100644
61035--- a/fs/lockd/clntproc.c
61036+++ b/fs/lockd/clntproc.c
61037@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61038 /*
61039 * Cookie counter for NLM requests
61040 */
61041-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61042+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61043
61044 void nlmclnt_next_cookie(struct nlm_cookie *c)
61045 {
61046- u32 cookie = atomic_inc_return(&nlm_cookie);
61047+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61048
61049 memcpy(c->data, &cookie, 4);
61050 c->len=4;
61051diff --git a/fs/locks.c b/fs/locks.c
61052index 92a0f0a..45a48f0 100644
61053--- a/fs/locks.c
61054+++ b/fs/locks.c
61055@@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
61056 return;
61057
61058 if (filp->f_op->flock) {
61059- struct file_lock fl = {
61060+ struct file_lock flock = {
61061 .fl_pid = current->tgid,
61062 .fl_file = filp,
61063 .fl_flags = FL_FLOCK,
61064 .fl_type = F_UNLCK,
61065 .fl_end = OFFSET_MAX,
61066 };
61067- filp->f_op->flock(filp, F_SETLKW, &fl);
61068- if (fl.fl_ops && fl.fl_ops->fl_release_private)
61069- fl.fl_ops->fl_release_private(&fl);
61070+ filp->f_op->flock(filp, F_SETLKW, &flock);
61071+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
61072+ flock.fl_ops->fl_release_private(&flock);
61073 }
61074
61075 spin_lock(&inode->i_lock);
61076diff --git a/fs/mount.h b/fs/mount.h
61077index b29e42f..5ea7fdf 100644
61078--- a/fs/mount.h
61079+++ b/fs/mount.h
61080@@ -11,7 +11,7 @@ struct mnt_namespace {
61081 u64 seq; /* Sequence number to prevent loops */
61082 wait_queue_head_t poll;
61083 int event;
61084-};
61085+} __randomize_layout;
61086
61087 struct mnt_pcp {
61088 int mnt_count;
61089@@ -57,7 +57,7 @@ struct mount {
61090 int mnt_expiry_mark; /* true if marked for expiry */
61091 int mnt_pinned;
61092 struct path mnt_ex_mountpoint;
61093-};
61094+} __randomize_layout;
61095
61096 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61097
61098diff --git a/fs/namei.c b/fs/namei.c
61099index 399f637..a24748c 100644
61100--- a/fs/namei.c
61101+++ b/fs/namei.c
61102@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
61103 if (ret != -EACCES)
61104 return ret;
61105
61106+#ifdef CONFIG_GRKERNSEC
61107+ /* we'll block if we have to log due to a denied capability use */
61108+ if (mask & MAY_NOT_BLOCK)
61109+ return -ECHILD;
61110+#endif
61111+
61112 if (S_ISDIR(inode->i_mode)) {
61113 /* DACs are overridable for directories */
61114- if (inode_capable(inode, CAP_DAC_OVERRIDE))
61115- return 0;
61116 if (!(mask & MAY_WRITE))
61117- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61118+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61119+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61120 return 0;
61121+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
61122+ return 0;
61123 return -EACCES;
61124 }
61125 /*
61126+ * Searching includes executable on directories, else just read.
61127+ */
61128+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61129+ if (mask == MAY_READ)
61130+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
61131+ inode_capable(inode, CAP_DAC_READ_SEARCH))
61132+ return 0;
61133+
61134+ /*
61135 * Read/write DACs are always overridable.
61136 * Executable DACs are overridable when there is
61137 * at least one exec bit set.
61138@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
61139 if (inode_capable(inode, CAP_DAC_OVERRIDE))
61140 return 0;
61141
61142- /*
61143- * Searching includes executable on directories, else just read.
61144- */
61145- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61146- if (mask == MAY_READ)
61147- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
61148- return 0;
61149-
61150 return -EACCES;
61151 }
61152
61153@@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61154 {
61155 struct dentry *dentry = link->dentry;
61156 int error;
61157- char *s;
61158+ const char *s;
61159
61160 BUG_ON(nd->flags & LOOKUP_RCU);
61161
61162@@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61163 if (error)
61164 goto out_put_nd_path;
61165
61166+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
61167+ dentry->d_inode, dentry, nd->path.mnt)) {
61168+ error = -EACCES;
61169+ goto out_put_nd_path;
61170+ }
61171+
61172 nd->last_type = LAST_BIND;
61173 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61174 error = PTR_ERR(*p);
61175@@ -1579,6 +1593,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61176 if (res)
61177 break;
61178 res = walk_component(nd, path, LOOKUP_FOLLOW);
61179+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61180+ res = -EACCES;
61181 put_link(nd, &link, cookie);
61182 } while (res > 0);
61183
61184@@ -1652,7 +1668,7 @@ EXPORT_SYMBOL(full_name_hash);
61185 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61186 {
61187 unsigned long a, b, adata, bdata, mask, hash, len;
61188- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61189+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61190
61191 hash = a = 0;
61192 len = -sizeof(unsigned long);
61193@@ -1936,6 +1952,8 @@ static int path_lookupat(int dfd, const char *name,
61194 if (err)
61195 break;
61196 err = lookup_last(nd, &path);
61197+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
61198+ err = -EACCES;
61199 put_link(nd, &link, cookie);
61200 }
61201 }
61202@@ -1943,6 +1961,13 @@ static int path_lookupat(int dfd, const char *name,
61203 if (!err)
61204 err = complete_walk(nd);
61205
61206+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
61207+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61208+ path_put(&nd->path);
61209+ err = -ENOENT;
61210+ }
61211+ }
61212+
61213 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61214 if (!d_is_directory(nd->path.dentry)) {
61215 path_put(&nd->path);
61216@@ -1970,8 +1995,15 @@ static int filename_lookup(int dfd, struct filename *name,
61217 retval = path_lookupat(dfd, name->name,
61218 flags | LOOKUP_REVAL, nd);
61219
61220- if (likely(!retval))
61221+ if (likely(!retval)) {
61222 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61223+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61224+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61225+ path_put(&nd->path);
61226+ return -ENOENT;
61227+ }
61228+ }
61229+ }
61230 return retval;
61231 }
61232
61233@@ -2545,6 +2577,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61234 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61235 return -EPERM;
61236
61237+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61238+ return -EPERM;
61239+ if (gr_handle_rawio(inode))
61240+ return -EPERM;
61241+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61242+ return -EACCES;
61243+
61244 return 0;
61245 }
61246
61247@@ -2776,7 +2815,7 @@ looked_up:
61248 * cleared otherwise prior to returning.
61249 */
61250 static int lookup_open(struct nameidata *nd, struct path *path,
61251- struct file *file,
61252+ struct path *link, struct file *file,
61253 const struct open_flags *op,
61254 bool got_write, int *opened)
61255 {
61256@@ -2811,6 +2850,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61257 /* Negative dentry, just create the file */
61258 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61259 umode_t mode = op->mode;
61260+
61261+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61262+ error = -EACCES;
61263+ goto out_dput;
61264+ }
61265+
61266+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61267+ error = -EACCES;
61268+ goto out_dput;
61269+ }
61270+
61271 if (!IS_POSIXACL(dir->d_inode))
61272 mode &= ~current_umask();
61273 /*
61274@@ -2832,6 +2882,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61275 nd->flags & LOOKUP_EXCL);
61276 if (error)
61277 goto out_dput;
61278+ else
61279+ gr_handle_create(dentry, nd->path.mnt);
61280 }
61281 out_no_open:
61282 path->dentry = dentry;
61283@@ -2846,7 +2898,7 @@ out_dput:
61284 /*
61285 * Handle the last step of open()
61286 */
61287-static int do_last(struct nameidata *nd, struct path *path,
61288+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61289 struct file *file, const struct open_flags *op,
61290 int *opened, struct filename *name)
61291 {
61292@@ -2896,6 +2948,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61293 if (error)
61294 return error;
61295
61296+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61297+ error = -ENOENT;
61298+ goto out;
61299+ }
61300+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61301+ error = -EACCES;
61302+ goto out;
61303+ }
61304+
61305 audit_inode(name, dir, LOOKUP_PARENT);
61306 error = -EISDIR;
61307 /* trailing slashes? */
61308@@ -2915,7 +2976,7 @@ retry_lookup:
61309 */
61310 }
61311 mutex_lock(&dir->d_inode->i_mutex);
61312- error = lookup_open(nd, path, file, op, got_write, opened);
61313+ error = lookup_open(nd, path, link, file, op, got_write, opened);
61314 mutex_unlock(&dir->d_inode->i_mutex);
61315
61316 if (error <= 0) {
61317@@ -2939,11 +3000,28 @@ retry_lookup:
61318 goto finish_open_created;
61319 }
61320
61321+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61322+ error = -ENOENT;
61323+ goto exit_dput;
61324+ }
61325+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61326+ error = -EACCES;
61327+ goto exit_dput;
61328+ }
61329+
61330 /*
61331 * create/update audit record if it already exists.
61332 */
61333- if (d_is_positive(path->dentry))
61334+ if (d_is_positive(path->dentry)) {
61335+ /* only check if O_CREAT is specified, all other checks need to go
61336+ into may_open */
61337+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61338+ error = -EACCES;
61339+ goto exit_dput;
61340+ }
61341+
61342 audit_inode(name, path->dentry, 0);
61343+ }
61344
61345 /*
61346 * If atomic_open() acquired write access it is dropped now due to
61347@@ -2984,6 +3062,11 @@ finish_lookup:
61348 }
61349 }
61350 BUG_ON(inode != path->dentry->d_inode);
61351+ /* if we're resolving a symlink to another symlink */
61352+ if (link && gr_handle_symlink_owner(link, inode)) {
61353+ error = -EACCES;
61354+ goto out;
61355+ }
61356 return 1;
61357 }
61358
61359@@ -2993,7 +3076,6 @@ finish_lookup:
61360 save_parent.dentry = nd->path.dentry;
61361 save_parent.mnt = mntget(path->mnt);
61362 nd->path.dentry = path->dentry;
61363-
61364 }
61365 nd->inode = inode;
61366 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61367@@ -3003,7 +3085,18 @@ finish_open:
61368 path_put(&save_parent);
61369 return error;
61370 }
61371+
61372+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61373+ error = -ENOENT;
61374+ goto out;
61375+ }
61376+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
61377+ error = -EACCES;
61378+ goto out;
61379+ }
61380+
61381 audit_inode(name, nd->path.dentry, 0);
61382+
61383 error = -EISDIR;
61384 if ((open_flag & O_CREAT) &&
61385 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
61386@@ -3167,7 +3260,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61387 if (unlikely(error))
61388 goto out;
61389
61390- error = do_last(nd, &path, file, op, &opened, pathname);
61391+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61392 while (unlikely(error > 0)) { /* trailing symlink */
61393 struct path link = path;
61394 void *cookie;
61395@@ -3185,7 +3278,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61396 error = follow_link(&link, nd, &cookie);
61397 if (unlikely(error))
61398 break;
61399- error = do_last(nd, &path, file, op, &opened, pathname);
61400+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
61401 put_link(nd, &link, cookie);
61402 }
61403 out:
61404@@ -3285,9 +3378,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61405 goto unlock;
61406
61407 error = -EEXIST;
61408- if (d_is_positive(dentry))
61409+ if (d_is_positive(dentry)) {
61410+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61411+ error = -ENOENT;
61412 goto fail;
61413-
61414+ }
61415 /*
61416 * Special case - lookup gave negative, but... we had foo/bar/
61417 * From the vfs_mknod() POV we just have a negative dentry -
61418@@ -3339,6 +3434,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61419 }
61420 EXPORT_SYMBOL(user_path_create);
61421
61422+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61423+{
61424+ struct filename *tmp = getname(pathname);
61425+ struct dentry *res;
61426+ if (IS_ERR(tmp))
61427+ return ERR_CAST(tmp);
61428+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61429+ if (IS_ERR(res))
61430+ putname(tmp);
61431+ else
61432+ *to = tmp;
61433+ return res;
61434+}
61435+
61436 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61437 {
61438 int error = may_create(dir, dentry);
61439@@ -3401,6 +3510,17 @@ retry:
61440
61441 if (!IS_POSIXACL(path.dentry->d_inode))
61442 mode &= ~current_umask();
61443+
61444+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61445+ error = -EPERM;
61446+ goto out;
61447+ }
61448+
61449+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61450+ error = -EACCES;
61451+ goto out;
61452+ }
61453+
61454 error = security_path_mknod(&path, dentry, mode, dev);
61455 if (error)
61456 goto out;
61457@@ -3417,6 +3537,8 @@ retry:
61458 break;
61459 }
61460 out:
61461+ if (!error)
61462+ gr_handle_create(dentry, path.mnt);
61463 done_path_create(&path, dentry);
61464 if (retry_estale(error, lookup_flags)) {
61465 lookup_flags |= LOOKUP_REVAL;
61466@@ -3469,9 +3591,16 @@ retry:
61467
61468 if (!IS_POSIXACL(path.dentry->d_inode))
61469 mode &= ~current_umask();
61470+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
61471+ error = -EACCES;
61472+ goto out;
61473+ }
61474 error = security_path_mkdir(&path, dentry, mode);
61475 if (!error)
61476 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
61477+ if (!error)
61478+ gr_handle_create(dentry, path.mnt);
61479+out:
61480 done_path_create(&path, dentry);
61481 if (retry_estale(error, lookup_flags)) {
61482 lookup_flags |= LOOKUP_REVAL;
61483@@ -3552,6 +3681,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
61484 struct filename *name;
61485 struct dentry *dentry;
61486 struct nameidata nd;
61487+ ino_t saved_ino = 0;
61488+ dev_t saved_dev = 0;
61489 unsigned int lookup_flags = 0;
61490 retry:
61491 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61492@@ -3584,10 +3715,21 @@ retry:
61493 error = -ENOENT;
61494 goto exit3;
61495 }
61496+
61497+ saved_ino = dentry->d_inode->i_ino;
61498+ saved_dev = gr_get_dev_from_dentry(dentry);
61499+
61500+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
61501+ error = -EACCES;
61502+ goto exit3;
61503+ }
61504+
61505 error = security_path_rmdir(&nd.path, dentry);
61506 if (error)
61507 goto exit3;
61508 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
61509+ if (!error && (saved_dev || saved_ino))
61510+ gr_handle_delete(saved_ino, saved_dev);
61511 exit3:
61512 dput(dentry);
61513 exit2:
61514@@ -3677,6 +3819,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
61515 struct nameidata nd;
61516 struct inode *inode = NULL;
61517 struct inode *delegated_inode = NULL;
61518+ ino_t saved_ino = 0;
61519+ dev_t saved_dev = 0;
61520 unsigned int lookup_flags = 0;
61521 retry:
61522 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
61523@@ -3703,10 +3847,22 @@ retry_deleg:
61524 if (d_is_negative(dentry))
61525 goto slashes;
61526 ihold(inode);
61527+
61528+ if (inode->i_nlink <= 1) {
61529+ saved_ino = inode->i_ino;
61530+ saved_dev = gr_get_dev_from_dentry(dentry);
61531+ }
61532+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
61533+ error = -EACCES;
61534+ goto exit2;
61535+ }
61536+
61537 error = security_path_unlink(&nd.path, dentry);
61538 if (error)
61539 goto exit2;
61540 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
61541+ if (!error && (saved_ino || saved_dev))
61542+ gr_handle_delete(saved_ino, saved_dev);
61543 exit2:
61544 dput(dentry);
61545 }
61546@@ -3794,9 +3950,17 @@ retry:
61547 if (IS_ERR(dentry))
61548 goto out_putname;
61549
61550+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
61551+ error = -EACCES;
61552+ goto out;
61553+ }
61554+
61555 error = security_path_symlink(&path, dentry, from->name);
61556 if (!error)
61557 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
61558+ if (!error)
61559+ gr_handle_create(dentry, path.mnt);
61560+out:
61561 done_path_create(&path, dentry);
61562 if (retry_estale(error, lookup_flags)) {
61563 lookup_flags |= LOOKUP_REVAL;
61564@@ -3899,6 +4063,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
61565 struct dentry *new_dentry;
61566 struct path old_path, new_path;
61567 struct inode *delegated_inode = NULL;
61568+ struct filename *to = NULL;
61569 int how = 0;
61570 int error;
61571
61572@@ -3922,7 +4087,7 @@ retry:
61573 if (error)
61574 return error;
61575
61576- new_dentry = user_path_create(newdfd, newname, &new_path,
61577+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
61578 (how & LOOKUP_REVAL));
61579 error = PTR_ERR(new_dentry);
61580 if (IS_ERR(new_dentry))
61581@@ -3934,11 +4099,28 @@ retry:
61582 error = may_linkat(&old_path);
61583 if (unlikely(error))
61584 goto out_dput;
61585+
61586+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
61587+ old_path.dentry->d_inode,
61588+ old_path.dentry->d_inode->i_mode, to)) {
61589+ error = -EACCES;
61590+ goto out_dput;
61591+ }
61592+
61593+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
61594+ old_path.dentry, old_path.mnt, to)) {
61595+ error = -EACCES;
61596+ goto out_dput;
61597+ }
61598+
61599 error = security_path_link(old_path.dentry, &new_path, new_dentry);
61600 if (error)
61601 goto out_dput;
61602 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
61603+ if (!error)
61604+ gr_handle_create(new_dentry, new_path.mnt);
61605 out_dput:
61606+ putname(to);
61607 done_path_create(&new_path, new_dentry);
61608 if (delegated_inode) {
61609 error = break_deleg_wait(&delegated_inode);
61610@@ -4225,6 +4407,12 @@ retry_deleg:
61611 if (new_dentry == trap)
61612 goto exit5;
61613
61614+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
61615+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
61616+ to);
61617+ if (error)
61618+ goto exit5;
61619+
61620 error = security_path_rename(&oldnd.path, old_dentry,
61621 &newnd.path, new_dentry);
61622 if (error)
61623@@ -4232,6 +4420,9 @@ retry_deleg:
61624 error = vfs_rename(old_dir->d_inode, old_dentry,
61625 new_dir->d_inode, new_dentry,
61626 &delegated_inode);
61627+ if (!error)
61628+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
61629+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
61630 exit5:
61631 dput(new_dentry);
61632 exit4:
61633@@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
61634
61635 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
61636 {
61637+ char tmpbuf[64];
61638+ const char *newlink;
61639 int len;
61640
61641 len = PTR_ERR(link);
61642@@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
61643 len = strlen(link);
61644 if (len > (unsigned) buflen)
61645 len = buflen;
61646- if (copy_to_user(buffer, link, len))
61647+
61648+ if (len < sizeof(tmpbuf)) {
61649+ memcpy(tmpbuf, link, len);
61650+ newlink = tmpbuf;
61651+ } else
61652+ newlink = link;
61653+
61654+ if (copy_to_user(buffer, newlink, len))
61655 len = -EFAULT;
61656 out:
61657 return len;
61658diff --git a/fs/namespace.c b/fs/namespace.c
61659index 6d0e54e..4c1f85e 100644
61660--- a/fs/namespace.c
61661+++ b/fs/namespace.c
61662@@ -1339,6 +1339,9 @@ static int do_umount(struct mount *mnt, int flags)
61663 if (!(sb->s_flags & MS_RDONLY))
61664 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
61665 up_write(&sb->s_umount);
61666+
61667+ gr_log_remount(mnt->mnt_devname, retval);
61668+
61669 return retval;
61670 }
61671
61672@@ -1361,6 +1364,9 @@ static int do_umount(struct mount *mnt, int flags)
61673 }
61674 unlock_mount_hash();
61675 namespace_unlock();
61676+
61677+ gr_log_unmount(mnt->mnt_devname, retval);
61678+
61679 return retval;
61680 }
61681
61682@@ -1380,7 +1386,7 @@ static inline bool may_mount(void)
61683 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
61684 */
61685
61686-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
61687+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
61688 {
61689 struct path path;
61690 struct mount *mnt;
61691@@ -1422,7 +1428,7 @@ out:
61692 /*
61693 * The 2.0 compatible umount. No flags.
61694 */
61695-SYSCALL_DEFINE1(oldumount, char __user *, name)
61696+SYSCALL_DEFINE1(oldumount, const char __user *, name)
61697 {
61698 return sys_umount(name, 0);
61699 }
61700@@ -2426,6 +2432,16 @@ long do_mount(const char *dev_name, const char *dir_name,
61701 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
61702 MS_STRICTATIME);
61703
61704+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
61705+ retval = -EPERM;
61706+ goto dput_out;
61707+ }
61708+
61709+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
61710+ retval = -EPERM;
61711+ goto dput_out;
61712+ }
61713+
61714 if (flags & MS_REMOUNT)
61715 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
61716 data_page);
61717@@ -2440,6 +2456,9 @@ long do_mount(const char *dev_name, const char *dir_name,
61718 dev_name, data_page);
61719 dput_out:
61720 path_put(&path);
61721+
61722+ gr_log_mount(dev_name, dir_name, retval);
61723+
61724 return retval;
61725 }
61726
61727@@ -2457,7 +2476,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
61728 * number incrementing at 10Ghz will take 12,427 years to wrap which
61729 * is effectively never, so we can ignore the possibility.
61730 */
61731-static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
61732+static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
61733
61734 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61735 {
61736@@ -2472,7 +2491,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61737 kfree(new_ns);
61738 return ERR_PTR(ret);
61739 }
61740- new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
61741+ new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
61742 atomic_set(&new_ns->count, 1);
61743 new_ns->root = NULL;
61744 INIT_LIST_HEAD(&new_ns->list);
61745@@ -2482,7 +2501,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
61746 return new_ns;
61747 }
61748
61749-struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61750+__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61751 struct user_namespace *user_ns, struct fs_struct *new_fs)
61752 {
61753 struct mnt_namespace *new_ns;
61754@@ -2603,8 +2622,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61755 }
61756 EXPORT_SYMBOL(mount_subtree);
61757
61758-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61759- char __user *, type, unsigned long, flags, void __user *, data)
61760+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61761+ const char __user *, type, unsigned long, flags, void __user *, data)
61762 {
61763 int ret;
61764 char *kernel_type;
61765@@ -2717,6 +2736,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61766 if (error)
61767 goto out2;
61768
61769+ if (gr_handle_chroot_pivot()) {
61770+ error = -EPERM;
61771+ goto out2;
61772+ }
61773+
61774 get_fs_root(current->fs, &root);
61775 old_mp = lock_mount(&old);
61776 error = PTR_ERR(old_mp);
61777@@ -2983,7 +3007,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61778 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61779 return -EPERM;
61780
61781- if (fs->users != 1)
61782+ if (atomic_read(&fs->users) != 1)
61783 return -EINVAL;
61784
61785 get_mnt_ns(mnt_ns);
61786diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61787index f4ccfe6..a5cf064 100644
61788--- a/fs/nfs/callback_xdr.c
61789+++ b/fs/nfs/callback_xdr.c
61790@@ -51,7 +51,7 @@ struct callback_op {
61791 callback_decode_arg_t decode_args;
61792 callback_encode_res_t encode_res;
61793 long res_maxsize;
61794-};
61795+} __do_const;
61796
61797 static struct callback_op callback_ops[];
61798
61799diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61800index 5d94c02..630214f 100644
61801--- a/fs/nfs/inode.c
61802+++ b/fs/nfs/inode.c
61803@@ -1153,16 +1153,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61804 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61805 }
61806
61807-static atomic_long_t nfs_attr_generation_counter;
61808+static atomic_long_unchecked_t nfs_attr_generation_counter;
61809
61810 static unsigned long nfs_read_attr_generation_counter(void)
61811 {
61812- return atomic_long_read(&nfs_attr_generation_counter);
61813+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61814 }
61815
61816 unsigned long nfs_inc_attr_generation_counter(void)
61817 {
61818- return atomic_long_inc_return(&nfs_attr_generation_counter);
61819+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61820 }
61821
61822 void nfs_fattr_init(struct nfs_fattr *fattr)
61823diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
61824index 0e90bf0..134691e 100644
61825--- a/fs/nfs/nfs4proc.c
61826+++ b/fs/nfs/nfs4proc.c
61827@@ -1070,6 +1070,7 @@ static void nfs4_opendata_free(struct kref *kref)
61828 dput(p->dentry);
61829 nfs_sb_deactive(sb);
61830 nfs_fattr_free_names(&p->f_attr);
61831+ kfree(p->f_attr.mdsthreshold);
61832 kfree(p);
61833 }
61834
61835@@ -2246,10 +2247,12 @@ static int _nfs4_do_open(struct inode *dir,
61836 }
61837 }
61838
61839- if (ctx_th && server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61840- opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61841- if (!opendata->f_attr.mdsthreshold)
61842- goto err_free_label;
61843+ if (server->attr_bitmask[2] & FATTR4_WORD2_MDSTHRESHOLD) {
61844+ if (!opendata->f_attr.mdsthreshold) {
61845+ opendata->f_attr.mdsthreshold = pnfs_mdsthreshold_alloc();
61846+ if (!opendata->f_attr.mdsthreshold)
61847+ goto err_free_label;
61848+ }
61849 opendata->o_arg.open_bitmap = &nfs4_pnfs_open_bitmap[0];
61850 }
61851 if (dentry->d_inode != NULL)
61852@@ -2277,11 +2280,10 @@ static int _nfs4_do_open(struct inode *dir,
61853 if (opendata->file_created)
61854 *opened |= FILE_CREATED;
61855
61856- if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server))
61857+ if (pnfs_use_threshold(ctx_th, opendata->f_attr.mdsthreshold, server)) {
61858 *ctx_th = opendata->f_attr.mdsthreshold;
61859- else
61860- kfree(opendata->f_attr.mdsthreshold);
61861- opendata->f_attr.mdsthreshold = NULL;
61862+ opendata->f_attr.mdsthreshold = NULL;
61863+ }
61864
61865 nfs4_label_free(olabel);
61866
61867@@ -2291,7 +2293,6 @@ static int _nfs4_do_open(struct inode *dir,
61868 err_free_label:
61869 nfs4_label_free(olabel);
61870 err_opendata_put:
61871- kfree(opendata->f_attr.mdsthreshold);
61872 nfs4_opendata_put(opendata);
61873 err_put_state_owner:
61874 nfs4_put_state_owner(sp);
61875diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61876index 419572f..5414a23 100644
61877--- a/fs/nfsd/nfs4proc.c
61878+++ b/fs/nfsd/nfs4proc.c
61879@@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61880 nfsd4op_rsize op_rsize_bop;
61881 stateid_getter op_get_currentstateid;
61882 stateid_setter op_set_currentstateid;
61883-};
61884+} __do_const;
61885
61886 static struct nfsd4_operation nfsd4_ops[];
61887
61888diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61889index ee7237f..e3ae60a 100644
61890--- a/fs/nfsd/nfs4xdr.c
61891+++ b/fs/nfsd/nfs4xdr.c
61892@@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61893
61894 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61895
61896-static nfsd4_dec nfsd4_dec_ops[] = {
61897+static const nfsd4_dec nfsd4_dec_ops[] = {
61898 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61899 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61900 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61901diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61902index b6af150..f6ec5e3 100644
61903--- a/fs/nfsd/nfscache.c
61904+++ b/fs/nfsd/nfscache.c
61905@@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61906 {
61907 struct svc_cacherep *rp = rqstp->rq_cacherep;
61908 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61909- int len;
61910+ long len;
61911 size_t bufsize = 0;
61912
61913 if (!rp)
61914 return;
61915
61916- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61917- len >>= 2;
61918+ if (statp) {
61919+ len = (char*)statp - (char*)resv->iov_base;
61920+ len = resv->iov_len - len;
61921+ len >>= 2;
61922+ }
61923
61924 /* Don't cache excessive amounts of data and XDR failures */
61925 if (!statp || len > (256 >> 2)) {
61926diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61927index 7eea63c..a35f4fb 100644
61928--- a/fs/nfsd/vfs.c
61929+++ b/fs/nfsd/vfs.c
61930@@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61931 } else {
61932 oldfs = get_fs();
61933 set_fs(KERNEL_DS);
61934- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61935+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61936 set_fs(oldfs);
61937 }
61938
61939@@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61940
61941 /* Write the data. */
61942 oldfs = get_fs(); set_fs(KERNEL_DS);
61943- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61944+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61945 set_fs(oldfs);
61946 if (host_err < 0)
61947 goto out_nfserr;
61948@@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61949 */
61950
61951 oldfs = get_fs(); set_fs(KERNEL_DS);
61952- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61953+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61954 set_fs(oldfs);
61955
61956 if (host_err < 0)
61957diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61958index fea6bd5..8ee9d81 100644
61959--- a/fs/nls/nls_base.c
61960+++ b/fs/nls/nls_base.c
61961@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61962
61963 int register_nls(struct nls_table * nls)
61964 {
61965- struct nls_table ** tmp = &tables;
61966+ struct nls_table *tmp = tables;
61967
61968 if (nls->next)
61969 return -EBUSY;
61970
61971 spin_lock(&nls_lock);
61972- while (*tmp) {
61973- if (nls == *tmp) {
61974+ while (tmp) {
61975+ if (nls == tmp) {
61976 spin_unlock(&nls_lock);
61977 return -EBUSY;
61978 }
61979- tmp = &(*tmp)->next;
61980+ tmp = tmp->next;
61981 }
61982- nls->next = tables;
61983+ pax_open_kernel();
61984+ *(struct nls_table **)&nls->next = tables;
61985+ pax_close_kernel();
61986 tables = nls;
61987 spin_unlock(&nls_lock);
61988 return 0;
61989@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61990
61991 int unregister_nls(struct nls_table * nls)
61992 {
61993- struct nls_table ** tmp = &tables;
61994+ struct nls_table * const * tmp = &tables;
61995
61996 spin_lock(&nls_lock);
61997 while (*tmp) {
61998 if (nls == *tmp) {
61999- *tmp = nls->next;
62000+ pax_open_kernel();
62001+ *(struct nls_table **)tmp = nls->next;
62002+ pax_close_kernel();
62003 spin_unlock(&nls_lock);
62004 return 0;
62005 }
62006diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62007index 7424929..35f6be5 100644
62008--- a/fs/nls/nls_euc-jp.c
62009+++ b/fs/nls/nls_euc-jp.c
62010@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
62011 p_nls = load_nls("cp932");
62012
62013 if (p_nls) {
62014- table.charset2upper = p_nls->charset2upper;
62015- table.charset2lower = p_nls->charset2lower;
62016+ pax_open_kernel();
62017+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62018+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62019+ pax_close_kernel();
62020 return register_nls(&table);
62021 }
62022
62023diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62024index e7bc1d7..06bd4bb 100644
62025--- a/fs/nls/nls_koi8-ru.c
62026+++ b/fs/nls/nls_koi8-ru.c
62027@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
62028 p_nls = load_nls("koi8-u");
62029
62030 if (p_nls) {
62031- table.charset2upper = p_nls->charset2upper;
62032- table.charset2lower = p_nls->charset2lower;
62033+ pax_open_kernel();
62034+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62035+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62036+ pax_close_kernel();
62037 return register_nls(&table);
62038 }
62039
62040diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62041index 6663511..7668ca4 100644
62042--- a/fs/notify/fanotify/fanotify_user.c
62043+++ b/fs/notify/fanotify/fanotify_user.c
62044@@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62045
62046 fd = fanotify_event_metadata.fd;
62047 ret = -EFAULT;
62048- if (copy_to_user(buf, &fanotify_event_metadata,
62049- fanotify_event_metadata.event_len))
62050+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62051+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62052 goto out_close_fd;
62053
62054 ret = prepare_for_access_response(group, event, fd);
62055diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62056index 7b51b05..5ea5ef6 100644
62057--- a/fs/notify/notification.c
62058+++ b/fs/notify/notification.c
62059@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
62060 * get set to 0 so it will never get 'freed'
62061 */
62062 static struct fsnotify_event *q_overflow_event;
62063-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62064+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62065
62066 /**
62067 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62068@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62069 */
62070 u32 fsnotify_get_cookie(void)
62071 {
62072- return atomic_inc_return(&fsnotify_sync_cookie);
62073+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62074 }
62075 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62076
62077diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62078index 9e38daf..5727cae 100644
62079--- a/fs/ntfs/dir.c
62080+++ b/fs/ntfs/dir.c
62081@@ -1310,7 +1310,7 @@ find_next_index_buffer:
62082 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62083 ~(s64)(ndir->itype.index.block_size - 1)));
62084 /* Bounds checks. */
62085- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62086+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62087 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62088 "inode 0x%lx or driver bug.", vdir->i_ino);
62089 goto err_out;
62090diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62091index ea4ba9d..1e13d34 100644
62092--- a/fs/ntfs/file.c
62093+++ b/fs/ntfs/file.c
62094@@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62095 char *addr;
62096 size_t total = 0;
62097 unsigned len;
62098- int left;
62099+ unsigned left;
62100
62101 do {
62102 len = PAGE_CACHE_SIZE - ofs;
62103diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62104index 82650d5..db37dcf 100644
62105--- a/fs/ntfs/super.c
62106+++ b/fs/ntfs/super.c
62107@@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62108 if (!silent)
62109 ntfs_error(sb, "Primary boot sector is invalid.");
62110 } else if (!silent)
62111- ntfs_error(sb, read_err_str, "primary");
62112+ ntfs_error(sb, read_err_str, "%s", "primary");
62113 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62114 if (bh_primary)
62115 brelse(bh_primary);
62116@@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62117 goto hotfix_primary_boot_sector;
62118 brelse(bh_backup);
62119 } else if (!silent)
62120- ntfs_error(sb, read_err_str, "backup");
62121+ ntfs_error(sb, read_err_str, "%s", "backup");
62122 /* Try to read NT3.51- backup boot sector. */
62123 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62124 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62125@@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62126 "sector.");
62127 brelse(bh_backup);
62128 } else if (!silent)
62129- ntfs_error(sb, read_err_str, "backup");
62130+ ntfs_error(sb, read_err_str, "%s", "backup");
62131 /* We failed. Cleanup and return. */
62132 if (bh_primary)
62133 brelse(bh_primary);
62134diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62135index cd5496b..26a1055 100644
62136--- a/fs/ocfs2/localalloc.c
62137+++ b/fs/ocfs2/localalloc.c
62138@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62139 goto bail;
62140 }
62141
62142- atomic_inc(&osb->alloc_stats.moves);
62143+ atomic_inc_unchecked(&osb->alloc_stats.moves);
62144
62145 bail:
62146 if (handle)
62147diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62148index 3a90347..c40bef8 100644
62149--- a/fs/ocfs2/ocfs2.h
62150+++ b/fs/ocfs2/ocfs2.h
62151@@ -235,11 +235,11 @@ enum ocfs2_vol_state
62152
62153 struct ocfs2_alloc_stats
62154 {
62155- atomic_t moves;
62156- atomic_t local_data;
62157- atomic_t bitmap_data;
62158- atomic_t bg_allocs;
62159- atomic_t bg_extends;
62160+ atomic_unchecked_t moves;
62161+ atomic_unchecked_t local_data;
62162+ atomic_unchecked_t bitmap_data;
62163+ atomic_unchecked_t bg_allocs;
62164+ atomic_unchecked_t bg_extends;
62165 };
62166
62167 enum ocfs2_local_alloc_state
62168diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62169index 2c91452..77a3cd2 100644
62170--- a/fs/ocfs2/suballoc.c
62171+++ b/fs/ocfs2/suballoc.c
62172@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62173 mlog_errno(status);
62174 goto bail;
62175 }
62176- atomic_inc(&osb->alloc_stats.bg_extends);
62177+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62178
62179 /* You should never ask for this much metadata */
62180 BUG_ON(bits_wanted >
62181@@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62182 mlog_errno(status);
62183 goto bail;
62184 }
62185- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62186+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62187
62188 *suballoc_loc = res.sr_bg_blkno;
62189 *suballoc_bit_start = res.sr_bit_offset;
62190@@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62191 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62192 res->sr_bits);
62193
62194- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62195+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62196
62197 BUG_ON(res->sr_bits != 1);
62198
62199@@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62200 mlog_errno(status);
62201 goto bail;
62202 }
62203- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62204+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62205
62206 BUG_ON(res.sr_bits != 1);
62207
62208@@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62209 cluster_start,
62210 num_clusters);
62211 if (!status)
62212- atomic_inc(&osb->alloc_stats.local_data);
62213+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
62214 } else {
62215 if (min_clusters > (osb->bitmap_cpg - 1)) {
62216 /* The only paths asking for contiguousness
62217@@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62218 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62219 res.sr_bg_blkno,
62220 res.sr_bit_offset);
62221- atomic_inc(&osb->alloc_stats.bitmap_data);
62222+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62223 *num_clusters = res.sr_bits;
62224 }
62225 }
62226diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62227index c414929..5c9ee542 100644
62228--- a/fs/ocfs2/super.c
62229+++ b/fs/ocfs2/super.c
62230@@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62231 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62232 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62233 "Stats",
62234- atomic_read(&osb->alloc_stats.bitmap_data),
62235- atomic_read(&osb->alloc_stats.local_data),
62236- atomic_read(&osb->alloc_stats.bg_allocs),
62237- atomic_read(&osb->alloc_stats.moves),
62238- atomic_read(&osb->alloc_stats.bg_extends));
62239+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62240+ atomic_read_unchecked(&osb->alloc_stats.local_data),
62241+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62242+ atomic_read_unchecked(&osb->alloc_stats.moves),
62243+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62244
62245 out += snprintf(buf + out, len - out,
62246 "%10s => State: %u Descriptor: %llu Size: %u bits "
62247@@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62248 spin_lock_init(&osb->osb_xattr_lock);
62249 ocfs2_init_steal_slots(osb);
62250
62251- atomic_set(&osb->alloc_stats.moves, 0);
62252- atomic_set(&osb->alloc_stats.local_data, 0);
62253- atomic_set(&osb->alloc_stats.bitmap_data, 0);
62254- atomic_set(&osb->alloc_stats.bg_allocs, 0);
62255- atomic_set(&osb->alloc_stats.bg_extends, 0);
62256+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62257+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62258+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62259+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62260+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62261
62262 /* Copy the blockcheck stats from the superblock probe */
62263 osb->osb_ecc_stats = *stats;
62264diff --git a/fs/open.c b/fs/open.c
62265index 4b3e1ed..1c84599 100644
62266--- a/fs/open.c
62267+++ b/fs/open.c
62268@@ -32,6 +32,8 @@
62269 #include <linux/dnotify.h>
62270 #include <linux/compat.h>
62271
62272+#define CREATE_TRACE_POINTS
62273+#include <trace/events/fs.h>
62274 #include "internal.h"
62275
62276 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62277@@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62278 error = locks_verify_truncate(inode, NULL, length);
62279 if (!error)
62280 error = security_path_truncate(path);
62281+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62282+ error = -EACCES;
62283 if (!error)
62284 error = do_truncate(path->dentry, length, 0, NULL);
62285
62286@@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62287 error = locks_verify_truncate(inode, f.file, length);
62288 if (!error)
62289 error = security_path_truncate(&f.file->f_path);
62290+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62291+ error = -EACCES;
62292 if (!error)
62293 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62294 sb_end_write(inode->i_sb);
62295@@ -361,6 +367,9 @@ retry:
62296 if (__mnt_is_readonly(path.mnt))
62297 res = -EROFS;
62298
62299+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62300+ res = -EACCES;
62301+
62302 out_path_release:
62303 path_put(&path);
62304 if (retry_estale(res, lookup_flags)) {
62305@@ -392,6 +401,8 @@ retry:
62306 if (error)
62307 goto dput_and_out;
62308
62309+ gr_log_chdir(path.dentry, path.mnt);
62310+
62311 set_fs_pwd(current->fs, &path);
62312
62313 dput_and_out:
62314@@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62315 goto out_putf;
62316
62317 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62318+
62319+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62320+ error = -EPERM;
62321+
62322+ if (!error)
62323+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62324+
62325 if (!error)
62326 set_fs_pwd(current->fs, &f.file->f_path);
62327 out_putf:
62328@@ -450,7 +468,13 @@ retry:
62329 if (error)
62330 goto dput_and_out;
62331
62332+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62333+ goto dput_and_out;
62334+
62335 set_fs_root(current->fs, &path);
62336+
62337+ gr_handle_chroot_chdir(&path);
62338+
62339 error = 0;
62340 dput_and_out:
62341 path_put(&path);
62342@@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
62343 return error;
62344 retry_deleg:
62345 mutex_lock(&inode->i_mutex);
62346+
62347+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62348+ error = -EACCES;
62349+ goto out_unlock;
62350+ }
62351+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62352+ error = -EACCES;
62353+ goto out_unlock;
62354+ }
62355+
62356 error = security_path_chmod(path, mode);
62357 if (error)
62358 goto out_unlock;
62359@@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62360 uid = make_kuid(current_user_ns(), user);
62361 gid = make_kgid(current_user_ns(), group);
62362
62363+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
62364+ return -EACCES;
62365+
62366 newattrs.ia_valid = ATTR_CTIME;
62367 if (user != (uid_t) -1) {
62368 if (!uid_valid(uid))
62369@@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62370 } else {
62371 fsnotify_open(f);
62372 fd_install(fd, f);
62373+ trace_do_sys_open(tmp->name, flags, mode);
62374 }
62375 }
62376 putname(tmp);
62377diff --git a/fs/pipe.c b/fs/pipe.c
62378index 0e0752e..7cfdd50 100644
62379--- a/fs/pipe.c
62380+++ b/fs/pipe.c
62381@@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62382
62383 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62384 {
62385- if (pipe->files)
62386+ if (atomic_read(&pipe->files))
62387 mutex_lock_nested(&pipe->mutex, subclass);
62388 }
62389
62390@@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62391
62392 void pipe_unlock(struct pipe_inode_info *pipe)
62393 {
62394- if (pipe->files)
62395+ if (atomic_read(&pipe->files))
62396 mutex_unlock(&pipe->mutex);
62397 }
62398 EXPORT_SYMBOL(pipe_unlock);
62399@@ -449,9 +449,9 @@ redo:
62400 }
62401 if (bufs) /* More to do? */
62402 continue;
62403- if (!pipe->writers)
62404+ if (!atomic_read(&pipe->writers))
62405 break;
62406- if (!pipe->waiting_writers) {
62407+ if (!atomic_read(&pipe->waiting_writers)) {
62408 /* syscall merging: Usually we must not sleep
62409 * if O_NONBLOCK is set, or if we got some data.
62410 * But if a writer sleeps in kernel space, then
62411@@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62412 ret = 0;
62413 __pipe_lock(pipe);
62414
62415- if (!pipe->readers) {
62416+ if (!atomic_read(&pipe->readers)) {
62417 send_sig(SIGPIPE, current, 0);
62418 ret = -EPIPE;
62419 goto out;
62420@@ -562,7 +562,7 @@ redo1:
62421 for (;;) {
62422 int bufs;
62423
62424- if (!pipe->readers) {
62425+ if (!atomic_read(&pipe->readers)) {
62426 send_sig(SIGPIPE, current, 0);
62427 if (!ret)
62428 ret = -EPIPE;
62429@@ -653,9 +653,9 @@ redo2:
62430 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62431 do_wakeup = 0;
62432 }
62433- pipe->waiting_writers++;
62434+ atomic_inc(&pipe->waiting_writers);
62435 pipe_wait(pipe);
62436- pipe->waiting_writers--;
62437+ atomic_dec(&pipe->waiting_writers);
62438 }
62439 out:
62440 __pipe_unlock(pipe);
62441@@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62442 mask = 0;
62443 if (filp->f_mode & FMODE_READ) {
62444 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62445- if (!pipe->writers && filp->f_version != pipe->w_counter)
62446+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62447 mask |= POLLHUP;
62448 }
62449
62450@@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62451 * Most Unices do not set POLLERR for FIFOs but on Linux they
62452 * behave exactly like pipes for poll().
62453 */
62454- if (!pipe->readers)
62455+ if (!atomic_read(&pipe->readers))
62456 mask |= POLLERR;
62457 }
62458
62459@@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62460 int kill = 0;
62461
62462 spin_lock(&inode->i_lock);
62463- if (!--pipe->files) {
62464+ if (atomic_dec_and_test(&pipe->files)) {
62465 inode->i_pipe = NULL;
62466 kill = 1;
62467 }
62468@@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
62469
62470 __pipe_lock(pipe);
62471 if (file->f_mode & FMODE_READ)
62472- pipe->readers--;
62473+ atomic_dec(&pipe->readers);
62474 if (file->f_mode & FMODE_WRITE)
62475- pipe->writers--;
62476+ atomic_dec(&pipe->writers);
62477
62478- if (pipe->readers || pipe->writers) {
62479+ if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62480 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62481 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62482 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62483@@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62484 kfree(pipe);
62485 }
62486
62487-static struct vfsmount *pipe_mnt __read_mostly;
62488+struct vfsmount *pipe_mnt __read_mostly;
62489
62490 /*
62491 * pipefs_dname() is called from d_path().
62492@@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
62493 goto fail_iput;
62494
62495 inode->i_pipe = pipe;
62496- pipe->files = 2;
62497- pipe->readers = pipe->writers = 1;
62498+ atomic_set(&pipe->files, 2);
62499+ atomic_set(&pipe->readers, 1);
62500+ atomic_set(&pipe->writers, 1);
62501 inode->i_fop = &pipefifo_fops;
62502
62503 /*
62504@@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62505 spin_lock(&inode->i_lock);
62506 if (inode->i_pipe) {
62507 pipe = inode->i_pipe;
62508- pipe->files++;
62509+ atomic_inc(&pipe->files);
62510 spin_unlock(&inode->i_lock);
62511 } else {
62512 spin_unlock(&inode->i_lock);
62513 pipe = alloc_pipe_info();
62514 if (!pipe)
62515 return -ENOMEM;
62516- pipe->files = 1;
62517+ atomic_set(&pipe->files, 1);
62518 spin_lock(&inode->i_lock);
62519 if (unlikely(inode->i_pipe)) {
62520- inode->i_pipe->files++;
62521+ atomic_inc(&inode->i_pipe->files);
62522 spin_unlock(&inode->i_lock);
62523 free_pipe_info(pipe);
62524 pipe = inode->i_pipe;
62525@@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
62526 * opened, even when there is no process writing the FIFO.
62527 */
62528 pipe->r_counter++;
62529- if (pipe->readers++ == 0)
62530+ if (atomic_inc_return(&pipe->readers) == 1)
62531 wake_up_partner(pipe);
62532
62533- if (!is_pipe && !pipe->writers) {
62534+ if (!is_pipe && !atomic_read(&pipe->writers)) {
62535 if ((filp->f_flags & O_NONBLOCK)) {
62536 /* suppress POLLHUP until we have
62537 * seen a writer */
62538@@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
62539 * errno=ENXIO when there is no process reading the FIFO.
62540 */
62541 ret = -ENXIO;
62542- if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
62543+ if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
62544 goto err;
62545
62546 pipe->w_counter++;
62547- if (!pipe->writers++)
62548+ if (atomic_inc_return(&pipe->writers) == 1)
62549 wake_up_partner(pipe);
62550
62551- if (!is_pipe && !pipe->readers) {
62552+ if (!is_pipe && !atomic_read(&pipe->readers)) {
62553 if (wait_for_partner(pipe, &pipe->r_counter))
62554 goto err_wr;
62555 }
62556@@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
62557 * the process can at least talk to itself.
62558 */
62559
62560- pipe->readers++;
62561- pipe->writers++;
62562+ atomic_inc(&pipe->readers);
62563+ atomic_inc(&pipe->writers);
62564 pipe->r_counter++;
62565 pipe->w_counter++;
62566- if (pipe->readers == 1 || pipe->writers == 1)
62567+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
62568 wake_up_partner(pipe);
62569 break;
62570
62571@@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
62572 return 0;
62573
62574 err_rd:
62575- if (!--pipe->readers)
62576+ if (atomic_dec_and_test(&pipe->readers))
62577 wake_up_interruptible(&pipe->wait);
62578 ret = -ERESTARTSYS;
62579 goto err;
62580
62581 err_wr:
62582- if (!--pipe->writers)
62583+ if (atomic_dec_and_test(&pipe->writers))
62584 wake_up_interruptible(&pipe->wait);
62585 ret = -ERESTARTSYS;
62586 goto err;
62587diff --git a/fs/posix_acl.c b/fs/posix_acl.c
62588index 8bd2135..eab9adb 100644
62589--- a/fs/posix_acl.c
62590+++ b/fs/posix_acl.c
62591@@ -19,6 +19,7 @@
62592 #include <linux/sched.h>
62593 #include <linux/posix_acl.h>
62594 #include <linux/export.h>
62595+#include <linux/grsecurity.h>
62596
62597 #include <linux/errno.h>
62598
62599@@ -183,7 +184,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
62600 }
62601 }
62602 if (mode_p)
62603- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62604+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62605 return not_equiv;
62606 }
62607
62608@@ -331,7 +332,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
62609 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
62610 }
62611
62612- *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
62613+ *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
62614 return not_equiv;
62615 }
62616
62617@@ -389,6 +390,8 @@ posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
62618 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
62619 int err = -ENOMEM;
62620 if (clone) {
62621+ *mode_p &= ~gr_acl_umask();
62622+
62623 err = posix_acl_create_masq(clone, mode_p);
62624 if (err < 0) {
62625 posix_acl_release(clone);
62626diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
62627index 2183fcf..3c32a98 100644
62628--- a/fs/proc/Kconfig
62629+++ b/fs/proc/Kconfig
62630@@ -30,7 +30,7 @@ config PROC_FS
62631
62632 config PROC_KCORE
62633 bool "/proc/kcore support" if !ARM
62634- depends on PROC_FS && MMU
62635+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
62636 help
62637 Provides a virtual ELF core file of the live kernel. This can
62638 be read with gdb and other ELF tools. No modifications can be
62639@@ -38,8 +38,8 @@ config PROC_KCORE
62640
62641 config PROC_VMCORE
62642 bool "/proc/vmcore support"
62643- depends on PROC_FS && CRASH_DUMP
62644- default y
62645+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
62646+ default n
62647 help
62648 Exports the dump image of crashed kernel in ELF format.
62649
62650@@ -63,8 +63,8 @@ config PROC_SYSCTL
62651 limited in memory.
62652
62653 config PROC_PAGE_MONITOR
62654- default y
62655- depends on PROC_FS && MMU
62656+ default n
62657+ depends on PROC_FS && MMU && !GRKERNSEC
62658 bool "Enable /proc page monitoring" if EXPERT
62659 help
62660 Various /proc files exist to monitor process memory utilization:
62661diff --git a/fs/proc/array.c b/fs/proc/array.c
62662index 1bd2077..2f7cfd5 100644
62663--- a/fs/proc/array.c
62664+++ b/fs/proc/array.c
62665@@ -60,6 +60,7 @@
62666 #include <linux/tty.h>
62667 #include <linux/string.h>
62668 #include <linux/mman.h>
62669+#include <linux/grsecurity.h>
62670 #include <linux/proc_fs.h>
62671 #include <linux/ioport.h>
62672 #include <linux/uaccess.h>
62673@@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
62674 seq_putc(m, '\n');
62675 }
62676
62677+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62678+static inline void task_pax(struct seq_file *m, struct task_struct *p)
62679+{
62680+ if (p->mm)
62681+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
62682+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
62683+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
62684+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
62685+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
62686+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
62687+ else
62688+ seq_printf(m, "PaX:\t-----\n");
62689+}
62690+#endif
62691+
62692 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62693 struct pid *pid, struct task_struct *task)
62694 {
62695@@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
62696 task_cpus_allowed(m, task);
62697 cpuset_task_status_allowed(m, task);
62698 task_context_switch_counts(m, task);
62699+
62700+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
62701+ task_pax(m, task);
62702+#endif
62703+
62704+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
62705+ task_grsec_rbac(m, task);
62706+#endif
62707+
62708 return 0;
62709 }
62710
62711+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62712+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62713+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62714+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62715+#endif
62716+
62717 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62718 struct pid *pid, struct task_struct *task, int whole)
62719 {
62720@@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62721 char tcomm[sizeof(task->comm)];
62722 unsigned long flags;
62723
62724+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62725+ if (current->exec_id != m->exec_id) {
62726+ gr_log_badprocpid("stat");
62727+ return 0;
62728+ }
62729+#endif
62730+
62731 state = *get_task_state(task);
62732 vsize = eip = esp = 0;
62733 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62734@@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62735 gtime = task_gtime(task);
62736 }
62737
62738+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62739+ if (PAX_RAND_FLAGS(mm)) {
62740+ eip = 0;
62741+ esp = 0;
62742+ wchan = 0;
62743+ }
62744+#endif
62745+#ifdef CONFIG_GRKERNSEC_HIDESYM
62746+ wchan = 0;
62747+ eip =0;
62748+ esp =0;
62749+#endif
62750+
62751 /* scale priority and nice values from timeslices to -20..20 */
62752 /* to make it look like a "normal" Unix priority/nice value */
62753 priority = task_prio(task);
62754@@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62755 seq_put_decimal_ull(m, ' ', vsize);
62756 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
62757 seq_put_decimal_ull(m, ' ', rsslim);
62758+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62759+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
62760+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
62761+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
62762+#else
62763 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
62764 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
62765 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
62766+#endif
62767 seq_put_decimal_ull(m, ' ', esp);
62768 seq_put_decimal_ull(m, ' ', eip);
62769 /* The signal information here is obsolete.
62770@@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
62771 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
62772 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
62773
62774- if (mm && permitted) {
62775+ if (mm && permitted
62776+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62777+ && !PAX_RAND_FLAGS(mm)
62778+#endif
62779+ ) {
62780 seq_put_decimal_ull(m, ' ', mm->start_data);
62781 seq_put_decimal_ull(m, ' ', mm->end_data);
62782 seq_put_decimal_ull(m, ' ', mm->start_brk);
62783@@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62784 struct pid *pid, struct task_struct *task)
62785 {
62786 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
62787- struct mm_struct *mm = get_task_mm(task);
62788+ struct mm_struct *mm;
62789
62790+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62791+ if (current->exec_id != m->exec_id) {
62792+ gr_log_badprocpid("statm");
62793+ return 0;
62794+ }
62795+#endif
62796+ mm = get_task_mm(task);
62797 if (mm) {
62798 size = task_statm(mm, &shared, &text, &data, &resident);
62799 mmput(mm);
62800@@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
62801 return 0;
62802 }
62803
62804+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62805+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
62806+{
62807+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
62808+}
62809+#endif
62810+
62811 #ifdef CONFIG_CHECKPOINT_RESTORE
62812 static struct pid *
62813 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
62814diff --git a/fs/proc/base.c b/fs/proc/base.c
62815index b59a34b..68a79e8 100644
62816--- a/fs/proc/base.c
62817+++ b/fs/proc/base.c
62818@@ -113,6 +113,14 @@ struct pid_entry {
62819 union proc_op op;
62820 };
62821
62822+struct getdents_callback {
62823+ struct linux_dirent __user * current_dir;
62824+ struct linux_dirent __user * previous;
62825+ struct file * file;
62826+ int count;
62827+ int error;
62828+};
62829+
62830 #define NOD(NAME, MODE, IOP, FOP, OP) { \
62831 .name = (NAME), \
62832 .len = sizeof(NAME) - 1, \
62833@@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
62834 if (!mm->arg_end)
62835 goto out_mm; /* Shh! No looking before we're done */
62836
62837+ if (gr_acl_handle_procpidmem(task))
62838+ goto out_mm;
62839+
62840 len = mm->arg_end - mm->arg_start;
62841
62842 if (len > PAGE_SIZE)
62843@@ -237,12 +248,28 @@ out:
62844 return res;
62845 }
62846
62847+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62848+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62849+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
62850+ _mm->pax_flags & MF_PAX_SEGMEXEC))
62851+#endif
62852+
62853 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62854 {
62855 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62856 int res = PTR_ERR(mm);
62857 if (mm && !IS_ERR(mm)) {
62858 unsigned int nwords = 0;
62859+
62860+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62861+ /* allow if we're currently ptracing this task */
62862+ if (PAX_RAND_FLAGS(mm) &&
62863+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62864+ mmput(mm);
62865+ return 0;
62866+ }
62867+#endif
62868+
62869 do {
62870 nwords += 2;
62871 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62872@@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62873 }
62874
62875
62876-#ifdef CONFIG_KALLSYMS
62877+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62878 /*
62879 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62880 * Returns the resolved symbol. If that fails, simply return the address.
62881@@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62882 mutex_unlock(&task->signal->cred_guard_mutex);
62883 }
62884
62885-#ifdef CONFIG_STACKTRACE
62886+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62887
62888 #define MAX_STACK_TRACE_DEPTH 64
62889
62890@@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62891 return count;
62892 }
62893
62894-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62895+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62896 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62897 {
62898 long nr;
62899@@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62900 /************************************************************************/
62901
62902 /* permission checks */
62903-static int proc_fd_access_allowed(struct inode *inode)
62904+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62905 {
62906 struct task_struct *task;
62907 int allowed = 0;
62908@@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62909 */
62910 task = get_proc_task(inode);
62911 if (task) {
62912- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62913+ if (log)
62914+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62915+ else
62916+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62917 put_task_struct(task);
62918 }
62919 return allowed;
62920@@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62921 struct task_struct *task,
62922 int hide_pid_min)
62923 {
62924+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62925+ return false;
62926+
62927+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62928+ rcu_read_lock();
62929+ {
62930+ const struct cred *tmpcred = current_cred();
62931+ const struct cred *cred = __task_cred(task);
62932+
62933+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62934+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62935+ || in_group_p(grsec_proc_gid)
62936+#endif
62937+ ) {
62938+ rcu_read_unlock();
62939+ return true;
62940+ }
62941+ }
62942+ rcu_read_unlock();
62943+
62944+ if (!pid->hide_pid)
62945+ return false;
62946+#endif
62947+
62948 if (pid->hide_pid < hide_pid_min)
62949 return true;
62950 if (in_group_p(pid->pid_gid))
62951 return true;
62952+
62953 return ptrace_may_access(task, PTRACE_MODE_READ);
62954 }
62955
62956@@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62957 put_task_struct(task);
62958
62959 if (!has_perms) {
62960+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62961+ {
62962+#else
62963 if (pid->hide_pid == 2) {
62964+#endif
62965 /*
62966 * Let's make getdents(), stat(), and open()
62967 * consistent with each other. If a process
62968@@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62969 if (!task)
62970 return -ESRCH;
62971
62972+ if (gr_acl_handle_procpidmem(task)) {
62973+ put_task_struct(task);
62974+ return -EPERM;
62975+ }
62976+
62977 mm = mm_access(task, mode);
62978 put_task_struct(task);
62979
62980@@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62981
62982 file->private_data = mm;
62983
62984+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62985+ file->f_version = current->exec_id;
62986+#endif
62987+
62988 return 0;
62989 }
62990
62991@@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62992 ssize_t copied;
62993 char *page;
62994
62995+#ifdef CONFIG_GRKERNSEC
62996+ if (write)
62997+ return -EPERM;
62998+#endif
62999+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63000+ if (file->f_version != current->exec_id) {
63001+ gr_log_badprocpid("mem");
63002+ return 0;
63003+ }
63004+#endif
63005+
63006 if (!mm)
63007 return 0;
63008
63009@@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63010 goto free;
63011
63012 while (count > 0) {
63013- int this_len = min_t(int, count, PAGE_SIZE);
63014+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63015
63016 if (write && copy_from_user(page, buf, this_len)) {
63017 copied = -EFAULT;
63018@@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63019 if (!mm)
63020 return 0;
63021
63022+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63023+ if (file->f_version != current->exec_id) {
63024+ gr_log_badprocpid("environ");
63025+ return 0;
63026+ }
63027+#endif
63028+
63029 page = (char *)__get_free_page(GFP_TEMPORARY);
63030 if (!page)
63031 return -ENOMEM;
63032@@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63033 goto free;
63034 while (count > 0) {
63035 size_t this_len, max_len;
63036- int retval;
63037+ ssize_t retval;
63038
63039 if (src >= (mm->env_end - mm->env_start))
63040 break;
63041@@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63042 int error = -EACCES;
63043
63044 /* Are we allowed to snoop on the tasks file descriptors? */
63045- if (!proc_fd_access_allowed(inode))
63046+ if (!proc_fd_access_allowed(inode, 0))
63047 goto out;
63048
63049 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63050@@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63051 struct path path;
63052
63053 /* Are we allowed to snoop on the tasks file descriptors? */
63054- if (!proc_fd_access_allowed(inode))
63055- goto out;
63056+ /* logging this is needed for learning on chromium to work properly,
63057+ but we don't want to flood the logs from 'ps' which does a readlink
63058+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63059+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
63060+ */
63061+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63062+ if (!proc_fd_access_allowed(inode,0))
63063+ goto out;
63064+ } else {
63065+ if (!proc_fd_access_allowed(inode,1))
63066+ goto out;
63067+ }
63068
63069 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63070 if (error)
63071@@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63072 rcu_read_lock();
63073 cred = __task_cred(task);
63074 inode->i_uid = cred->euid;
63075+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63076+ inode->i_gid = grsec_proc_gid;
63077+#else
63078 inode->i_gid = cred->egid;
63079+#endif
63080 rcu_read_unlock();
63081 }
63082 security_task_to_inode(task, inode);
63083@@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63084 return -ENOENT;
63085 }
63086 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63087+#ifdef CONFIG_GRKERNSEC_PROC_USER
63088+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63089+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63090+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63091+#endif
63092 task_dumpable(task)) {
63093 cred = __task_cred(task);
63094 stat->uid = cred->euid;
63095+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63096+ stat->gid = grsec_proc_gid;
63097+#else
63098 stat->gid = cred->egid;
63099+#endif
63100 }
63101 }
63102 rcu_read_unlock();
63103@@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63104
63105 if (task) {
63106 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63107+#ifdef CONFIG_GRKERNSEC_PROC_USER
63108+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63109+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63110+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63111+#endif
63112 task_dumpable(task)) {
63113 rcu_read_lock();
63114 cred = __task_cred(task);
63115 inode->i_uid = cred->euid;
63116+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63117+ inode->i_gid = grsec_proc_gid;
63118+#else
63119 inode->i_gid = cred->egid;
63120+#endif
63121 rcu_read_unlock();
63122 } else {
63123 inode->i_uid = GLOBAL_ROOT_UID;
63124@@ -2173,6 +2291,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63125 if (!task)
63126 goto out_no_task;
63127
63128+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63129+ goto out;
63130+
63131 /*
63132 * Yes, it does not scale. And it should not. Don't add
63133 * new entries into /proc/<tgid>/ without very good reasons.
63134@@ -2203,6 +2324,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63135 if (!task)
63136 return -ENOENT;
63137
63138+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63139+ goto out;
63140+
63141 if (!dir_emit_dots(file, ctx))
63142 goto out;
63143
63144@@ -2592,7 +2716,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63145 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63146 #endif
63147 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63148-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63149+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63150 INF("syscall", S_IRUGO, proc_pid_syscall),
63151 #endif
63152 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63153@@ -2617,10 +2741,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63154 #ifdef CONFIG_SECURITY
63155 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63156 #endif
63157-#ifdef CONFIG_KALLSYMS
63158+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63159 INF("wchan", S_IRUGO, proc_pid_wchan),
63160 #endif
63161-#ifdef CONFIG_STACKTRACE
63162+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63163 ONE("stack", S_IRUGO, proc_pid_stack),
63164 #endif
63165 #ifdef CONFIG_SCHEDSTATS
63166@@ -2654,6 +2778,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63167 #ifdef CONFIG_HARDWALL
63168 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63169 #endif
63170+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63171+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63172+#endif
63173 #ifdef CONFIG_USER_NS
63174 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63175 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63176@@ -2784,7 +2911,14 @@ static int proc_pid_instantiate(struct inode *dir,
63177 if (!inode)
63178 goto out;
63179
63180+#ifdef CONFIG_GRKERNSEC_PROC_USER
63181+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63182+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63183+ inode->i_gid = grsec_proc_gid;
63184+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63185+#else
63186 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63187+#endif
63188 inode->i_op = &proc_tgid_base_inode_operations;
63189 inode->i_fop = &proc_tgid_base_operations;
63190 inode->i_flags|=S_IMMUTABLE;
63191@@ -2822,7 +2956,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63192 if (!task)
63193 goto out;
63194
63195+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63196+ goto out_put_task;
63197+
63198 result = proc_pid_instantiate(dir, dentry, task, NULL);
63199+out_put_task:
63200 put_task_struct(task);
63201 out:
63202 return ERR_PTR(result);
63203@@ -2928,7 +3066,7 @@ static const struct pid_entry tid_base_stuff[] = {
63204 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63205 #endif
63206 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63207-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63208+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63209 INF("syscall", S_IRUGO, proc_pid_syscall),
63210 #endif
63211 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63212@@ -2955,10 +3093,10 @@ static const struct pid_entry tid_base_stuff[] = {
63213 #ifdef CONFIG_SECURITY
63214 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63215 #endif
63216-#ifdef CONFIG_KALLSYMS
63217+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63218 INF("wchan", S_IRUGO, proc_pid_wchan),
63219 #endif
63220-#ifdef CONFIG_STACKTRACE
63221+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63222 ONE("stack", S_IRUGO, proc_pid_stack),
63223 #endif
63224 #ifdef CONFIG_SCHEDSTATS
63225diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63226index 82676e3..5f8518a 100644
63227--- a/fs/proc/cmdline.c
63228+++ b/fs/proc/cmdline.c
63229@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63230
63231 static int __init proc_cmdline_init(void)
63232 {
63233+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63234+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63235+#else
63236 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63237+#endif
63238 return 0;
63239 }
63240 module_init(proc_cmdline_init);
63241diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63242index b143471..bb105e5 100644
63243--- a/fs/proc/devices.c
63244+++ b/fs/proc/devices.c
63245@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63246
63247 static int __init proc_devices_init(void)
63248 {
63249+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63250+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63251+#else
63252 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63253+#endif
63254 return 0;
63255 }
63256 module_init(proc_devices_init);
63257diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63258index 985ea88..d118a0a 100644
63259--- a/fs/proc/fd.c
63260+++ b/fs/proc/fd.c
63261@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
63262 if (!task)
63263 return -ENOENT;
63264
63265- files = get_files_struct(task);
63266+ if (!gr_acl_handle_procpidmem(task))
63267+ files = get_files_struct(task);
63268 put_task_struct(task);
63269
63270 if (files) {
63271@@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63272 */
63273 int proc_fd_permission(struct inode *inode, int mask)
63274 {
63275+ struct task_struct *task;
63276 int rv = generic_permission(inode, mask);
63277- if (rv == 0)
63278- return 0;
63279+
63280 if (task_tgid(current) == proc_pid(inode))
63281 rv = 0;
63282+
63283+ task = get_proc_task(inode);
63284+ if (task == NULL)
63285+ return rv;
63286+
63287+ if (gr_acl_handle_procpidmem(task))
63288+ rv = -EACCES;
63289+
63290+ put_task_struct(task);
63291+
63292 return rv;
63293 }
63294
63295diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63296index 124fc43..8afbb02 100644
63297--- a/fs/proc/inode.c
63298+++ b/fs/proc/inode.c
63299@@ -23,11 +23,17 @@
63300 #include <linux/slab.h>
63301 #include <linux/mount.h>
63302 #include <linux/magic.h>
63303+#include <linux/grsecurity.h>
63304
63305 #include <asm/uaccess.h>
63306
63307 #include "internal.h"
63308
63309+#ifdef CONFIG_PROC_SYSCTL
63310+extern const struct inode_operations proc_sys_inode_operations;
63311+extern const struct inode_operations proc_sys_dir_operations;
63312+#endif
63313+
63314 static void proc_evict_inode(struct inode *inode)
63315 {
63316 struct proc_dir_entry *de;
63317@@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63318 ns = PROC_I(inode)->ns.ns;
63319 if (ns_ops && ns)
63320 ns_ops->put(ns);
63321+
63322+#ifdef CONFIG_PROC_SYSCTL
63323+ if (inode->i_op == &proc_sys_inode_operations ||
63324+ inode->i_op == &proc_sys_dir_operations)
63325+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63326+#endif
63327+
63328 }
63329
63330 static struct kmem_cache * proc_inode_cachep;
63331@@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63332 if (de->mode) {
63333 inode->i_mode = de->mode;
63334 inode->i_uid = de->uid;
63335+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63336+ inode->i_gid = grsec_proc_gid;
63337+#else
63338 inode->i_gid = de->gid;
63339+#endif
63340 }
63341 if (de->size)
63342 inode->i_size = de->size;
63343diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63344index 651d09a..3d7f0bf 100644
63345--- a/fs/proc/internal.h
63346+++ b/fs/proc/internal.h
63347@@ -48,7 +48,7 @@ struct proc_dir_entry {
63348 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
63349 u8 namelen;
63350 char name[];
63351-};
63352+} __randomize_layout;
63353
63354 union proc_op {
63355 int (*proc_get_link)(struct dentry *, struct path *);
63356@@ -67,7 +67,7 @@ struct proc_inode {
63357 struct ctl_table *sysctl_entry;
63358 struct proc_ns ns;
63359 struct inode vfs_inode;
63360-};
63361+} __randomize_layout;
63362
63363 /*
63364 * General functions
63365@@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
63366 struct pid *, struct task_struct *);
63367 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
63368 struct pid *, struct task_struct *);
63369+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63370+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
63371+#endif
63372
63373 /*
63374 * base.c
63375diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
63376index 05029c0..7ea1987 100644
63377--- a/fs/proc/interrupts.c
63378+++ b/fs/proc/interrupts.c
63379@@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
63380
63381 static int __init proc_interrupts_init(void)
63382 {
63383+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63384+ proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
63385+#else
63386 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
63387+#endif
63388 return 0;
63389 }
63390 module_init(proc_interrupts_init);
63391diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
63392index 5ed0e52..a1c1f2e 100644
63393--- a/fs/proc/kcore.c
63394+++ b/fs/proc/kcore.c
63395@@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63396 * the addresses in the elf_phdr on our list.
63397 */
63398 start = kc_offset_to_vaddr(*fpos - elf_buflen);
63399- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
63400+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
63401+ if (tsz > buflen)
63402 tsz = buflen;
63403-
63404+
63405 while (buflen) {
63406 struct kcore_list *m;
63407
63408@@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63409 kfree(elf_buf);
63410 } else {
63411 if (kern_addr_valid(start)) {
63412- unsigned long n;
63413+ char *elf_buf;
63414+ mm_segment_t oldfs;
63415
63416- n = copy_to_user(buffer, (char *)start, tsz);
63417- /*
63418- * We cannot distinguish between fault on source
63419- * and fault on destination. When this happens
63420- * we clear too and hope it will trigger the
63421- * EFAULT again.
63422- */
63423- if (n) {
63424- if (clear_user(buffer + tsz - n,
63425- n))
63426+ elf_buf = kmalloc(tsz, GFP_KERNEL);
63427+ if (!elf_buf)
63428+ return -ENOMEM;
63429+ oldfs = get_fs();
63430+ set_fs(KERNEL_DS);
63431+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
63432+ set_fs(oldfs);
63433+ if (copy_to_user(buffer, elf_buf, tsz)) {
63434+ kfree(elf_buf);
63435 return -EFAULT;
63436+ }
63437 }
63438+ set_fs(oldfs);
63439+ kfree(elf_buf);
63440 } else {
63441 if (clear_user(buffer, tsz))
63442 return -EFAULT;
63443@@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
63444
63445 static int open_kcore(struct inode *inode, struct file *filp)
63446 {
63447+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
63448+ return -EPERM;
63449+#endif
63450 if (!capable(CAP_SYS_RAWIO))
63451 return -EPERM;
63452 if (kcore_need_update)
63453diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
63454index a77d2b2..a9153f0 100644
63455--- a/fs/proc/meminfo.c
63456+++ b/fs/proc/meminfo.c
63457@@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
63458 vmi.used >> 10,
63459 vmi.largest_chunk >> 10
63460 #ifdef CONFIG_MEMORY_FAILURE
63461- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63462+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
63463 #endif
63464 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
63465 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
63466diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
63467index 5f9bc8a..5c35f08 100644
63468--- a/fs/proc/nommu.c
63469+++ b/fs/proc/nommu.c
63470@@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
63471
63472 if (file) {
63473 seq_pad(m, ' ');
63474- seq_path(m, &file->f_path, "");
63475+ seq_path(m, &file->f_path, "\n\\");
63476 }
63477
63478 seq_putc(m, '\n');
63479diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
63480index 4677bb7..408e936 100644
63481--- a/fs/proc/proc_net.c
63482+++ b/fs/proc/proc_net.c
63483@@ -23,6 +23,7 @@
63484 #include <linux/nsproxy.h>
63485 #include <net/net_namespace.h>
63486 #include <linux/seq_file.h>
63487+#include <linux/grsecurity.h>
63488
63489 #include "internal.h"
63490
63491@@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
63492 struct task_struct *task;
63493 struct nsproxy *ns;
63494 struct net *net = NULL;
63495+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63496+ const struct cred *cred = current_cred();
63497+#endif
63498+
63499+#ifdef CONFIG_GRKERNSEC_PROC_USER
63500+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
63501+ return net;
63502+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63503+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
63504+ return net;
63505+#endif
63506
63507 rcu_read_lock();
63508 task = pid_task(proc_pid(dir), PIDTYPE_PID);
63509diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
63510index 7129046..6914844 100644
63511--- a/fs/proc/proc_sysctl.c
63512+++ b/fs/proc/proc_sysctl.c
63513@@ -11,13 +11,21 @@
63514 #include <linux/namei.h>
63515 #include <linux/mm.h>
63516 #include <linux/module.h>
63517+#include <linux/nsproxy.h>
63518+#ifdef CONFIG_GRKERNSEC
63519+#include <net/net_namespace.h>
63520+#endif
63521 #include "internal.h"
63522
63523+extern int gr_handle_chroot_sysctl(const int op);
63524+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
63525+ const int op);
63526+
63527 static const struct dentry_operations proc_sys_dentry_operations;
63528 static const struct file_operations proc_sys_file_operations;
63529-static const struct inode_operations proc_sys_inode_operations;
63530+const struct inode_operations proc_sys_inode_operations;
63531 static const struct file_operations proc_sys_dir_file_operations;
63532-static const struct inode_operations proc_sys_dir_operations;
63533+const struct inode_operations proc_sys_dir_operations;
63534
63535 void proc_sys_poll_notify(struct ctl_table_poll *poll)
63536 {
63537@@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
63538
63539 err = NULL;
63540 d_set_d_op(dentry, &proc_sys_dentry_operations);
63541+
63542+ gr_handle_proc_create(dentry, inode);
63543+
63544 d_add(dentry, inode);
63545
63546 out:
63547@@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63548 struct inode *inode = file_inode(filp);
63549 struct ctl_table_header *head = grab_header(inode);
63550 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
63551+ int op = write ? MAY_WRITE : MAY_READ;
63552 ssize_t error;
63553 size_t res;
63554
63555@@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63556 * and won't be until we finish.
63557 */
63558 error = -EPERM;
63559- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
63560+ if (sysctl_perm(head, table, op))
63561 goto out;
63562
63563 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
63564@@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
63565 if (!table->proc_handler)
63566 goto out;
63567
63568+#ifdef CONFIG_GRKERNSEC
63569+ error = -EPERM;
63570+ if (gr_handle_chroot_sysctl(op))
63571+ goto out;
63572+ dget(filp->f_path.dentry);
63573+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
63574+ dput(filp->f_path.dentry);
63575+ goto out;
63576+ }
63577+ dput(filp->f_path.dentry);
63578+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
63579+ goto out;
63580+ if (write) {
63581+ if (current->nsproxy->net_ns != table->extra2) {
63582+ if (!capable(CAP_SYS_ADMIN))
63583+ goto out;
63584+ } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
63585+ goto out;
63586+ }
63587+#endif
63588+
63589 /* careful: calling conventions are nasty here */
63590 res = count;
63591 error = table->proc_handler(table, write, buf, &res, ppos);
63592@@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
63593 return false;
63594 } else {
63595 d_set_d_op(child, &proc_sys_dentry_operations);
63596+
63597+ gr_handle_proc_create(child, inode);
63598+
63599 d_add(child, inode);
63600 }
63601 } else {
63602@@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
63603 if ((*pos)++ < ctx->pos)
63604 return true;
63605
63606+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
63607+ return 0;
63608+
63609 if (unlikely(S_ISLNK(table->mode)))
63610 res = proc_sys_link_fill_cache(file, ctx, head, table);
63611 else
63612@@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
63613 if (IS_ERR(head))
63614 return PTR_ERR(head);
63615
63616+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
63617+ return -ENOENT;
63618+
63619 generic_fillattr(inode, stat);
63620 if (table)
63621 stat->mode = (stat->mode & S_IFMT) | table->mode;
63622@@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
63623 .llseek = generic_file_llseek,
63624 };
63625
63626-static const struct inode_operations proc_sys_inode_operations = {
63627+const struct inode_operations proc_sys_inode_operations = {
63628 .permission = proc_sys_permission,
63629 .setattr = proc_sys_setattr,
63630 .getattr = proc_sys_getattr,
63631 };
63632
63633-static const struct inode_operations proc_sys_dir_operations = {
63634+const struct inode_operations proc_sys_dir_operations = {
63635 .lookup = proc_sys_lookup,
63636 .permission = proc_sys_permission,
63637 .setattr = proc_sys_setattr,
63638@@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
63639 static struct ctl_dir *new_dir(struct ctl_table_set *set,
63640 const char *name, int namelen)
63641 {
63642- struct ctl_table *table;
63643+ ctl_table_no_const *table;
63644 struct ctl_dir *new;
63645 struct ctl_node *node;
63646 char *new_name;
63647@@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
63648 return NULL;
63649
63650 node = (struct ctl_node *)(new + 1);
63651- table = (struct ctl_table *)(node + 1);
63652+ table = (ctl_table_no_const *)(node + 1);
63653 new_name = (char *)(table + 2);
63654 memcpy(new_name, name, namelen);
63655 new_name[namelen] = '\0';
63656@@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
63657 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
63658 struct ctl_table_root *link_root)
63659 {
63660- struct ctl_table *link_table, *entry, *link;
63661+ ctl_table_no_const *link_table, *link;
63662+ struct ctl_table *entry;
63663 struct ctl_table_header *links;
63664 struct ctl_node *node;
63665 char *link_name;
63666@@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
63667 return NULL;
63668
63669 node = (struct ctl_node *)(links + 1);
63670- link_table = (struct ctl_table *)(node + nr_entries);
63671+ link_table = (ctl_table_no_const *)(node + nr_entries);
63672 link_name = (char *)&link_table[nr_entries + 1];
63673
63674 for (link = link_table, entry = table; entry->procname; link++, entry++) {
63675@@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63676 struct ctl_table_header ***subheader, struct ctl_table_set *set,
63677 struct ctl_table *table)
63678 {
63679- struct ctl_table *ctl_table_arg = NULL;
63680- struct ctl_table *entry, *files;
63681+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
63682+ struct ctl_table *entry;
63683 int nr_files = 0;
63684 int nr_dirs = 0;
63685 int err = -ENOMEM;
63686@@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63687 nr_files++;
63688 }
63689
63690- files = table;
63691 /* If there are mixed files and directories we need a new table */
63692 if (nr_dirs && nr_files) {
63693- struct ctl_table *new;
63694+ ctl_table_no_const *new;
63695 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
63696 GFP_KERNEL);
63697 if (!files)
63698@@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
63699 /* Register everything except a directory full of subdirectories */
63700 if (nr_files || !nr_dirs) {
63701 struct ctl_table_header *header;
63702- header = __register_sysctl_table(set, path, files);
63703+ header = __register_sysctl_table(set, path, files ? files : table);
63704 if (!header) {
63705 kfree(ctl_table_arg);
63706 goto out;
63707diff --git a/fs/proc/root.c b/fs/proc/root.c
63708index 87dbcbe..55e1b4d 100644
63709--- a/fs/proc/root.c
63710+++ b/fs/proc/root.c
63711@@ -186,7 +186,15 @@ void __init proc_root_init(void)
63712 #ifdef CONFIG_PROC_DEVICETREE
63713 proc_device_tree_init();
63714 #endif
63715+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63716+#ifdef CONFIG_GRKERNSEC_PROC_USER
63717+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
63718+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63719+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
63720+#endif
63721+#else
63722 proc_mkdir("bus", NULL);
63723+#endif
63724 proc_sys_init();
63725 }
63726
63727diff --git a/fs/proc/stat.c b/fs/proc/stat.c
63728index 1cf86c0..0ee1ca5 100644
63729--- a/fs/proc/stat.c
63730+++ b/fs/proc/stat.c
63731@@ -11,6 +11,7 @@
63732 #include <linux/irqnr.h>
63733 #include <asm/cputime.h>
63734 #include <linux/tick.h>
63735+#include <linux/grsecurity.h>
63736
63737 #ifndef arch_irq_stat_cpu
63738 #define arch_irq_stat_cpu(cpu) 0
63739@@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
63740 u64 sum_softirq = 0;
63741 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
63742 struct timespec boottime;
63743+ int unrestricted = 1;
63744+
63745+#ifdef CONFIG_GRKERNSEC_PROC_ADD
63746+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63747+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
63748+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63749+ && !in_group_p(grsec_proc_gid)
63750+#endif
63751+ )
63752+ unrestricted = 0;
63753+#endif
63754+#endif
63755
63756 user = nice = system = idle = iowait =
63757 irq = softirq = steal = 0;
63758@@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
63759 getboottime(&boottime);
63760 jif = boottime.tv_sec;
63761
63762+ if (unrestricted) {
63763 for_each_possible_cpu(i) {
63764 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
63765 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63766@@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
63767 }
63768 }
63769 sum += arch_irq_stat();
63770+ }
63771
63772 seq_puts(p, "cpu ");
63773 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63774@@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
63775 seq_putc(p, '\n');
63776
63777 for_each_online_cpu(i) {
63778+ if (unrestricted) {
63779 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
63780 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
63781 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
63782@@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
63783 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
63784 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
63785 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
63786+ }
63787 seq_printf(p, "cpu%d", i);
63788 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
63789 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
63790@@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
63791
63792 /* sum again ? it could be updated? */
63793 for_each_irq_nr(j)
63794- seq_put_decimal_ull(p, ' ', kstat_irqs(j));
63795+ seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
63796
63797 seq_printf(p,
63798 "\nctxt %llu\n"
63799@@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
63800 "processes %lu\n"
63801 "procs_running %lu\n"
63802 "procs_blocked %lu\n",
63803- nr_context_switches(),
63804+ unrestricted ? nr_context_switches() : 0ULL,
63805 (unsigned long)jif,
63806- total_forks,
63807- nr_running(),
63808- nr_iowait());
63809+ unrestricted ? total_forks : 0UL,
63810+ unrestricted ? nr_running() : 0UL,
63811+ unrestricted ? nr_iowait() : 0UL);
63812
63813 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
63814
63815diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
63816index fb52b54..5fc7c14 100644
63817--- a/fs/proc/task_mmu.c
63818+++ b/fs/proc/task_mmu.c
63819@@ -12,12 +12,19 @@
63820 #include <linux/swap.h>
63821 #include <linux/swapops.h>
63822 #include <linux/mmu_notifier.h>
63823+#include <linux/grsecurity.h>
63824
63825 #include <asm/elf.h>
63826 #include <asm/uaccess.h>
63827 #include <asm/tlbflush.h>
63828 #include "internal.h"
63829
63830+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63831+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63832+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
63833+ _mm->pax_flags & MF_PAX_SEGMEXEC))
63834+#endif
63835+
63836 void task_mem(struct seq_file *m, struct mm_struct *mm)
63837 {
63838 unsigned long data, text, lib, swap;
63839@@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63840 "VmExe:\t%8lu kB\n"
63841 "VmLib:\t%8lu kB\n"
63842 "VmPTE:\t%8lu kB\n"
63843- "VmSwap:\t%8lu kB\n",
63844- hiwater_vm << (PAGE_SHIFT-10),
63845+ "VmSwap:\t%8lu kB\n"
63846+
63847+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63848+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63849+#endif
63850+
63851+ ,hiwater_vm << (PAGE_SHIFT-10),
63852 total_vm << (PAGE_SHIFT-10),
63853 mm->locked_vm << (PAGE_SHIFT-10),
63854 mm->pinned_vm << (PAGE_SHIFT-10),
63855@@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63856 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63857 (PTRS_PER_PTE * sizeof(pte_t) *
63858 atomic_long_read(&mm->nr_ptes)) >> 10,
63859- swap << (PAGE_SHIFT-10));
63860+ swap << (PAGE_SHIFT-10)
63861+
63862+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63863+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63864+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63865+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63866+#else
63867+ , mm->context.user_cs_base
63868+ , mm->context.user_cs_limit
63869+#endif
63870+#endif
63871+
63872+ );
63873 }
63874
63875 unsigned long task_vsize(struct mm_struct *mm)
63876@@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63877 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63878 }
63879
63880- /* We don't show the stack guard page in /proc/maps */
63881+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63882+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63883+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63884+#else
63885 start = vma->vm_start;
63886- if (stack_guard_page_start(vma, start))
63887- start += PAGE_SIZE;
63888 end = vma->vm_end;
63889- if (stack_guard_page_end(vma, end))
63890- end -= PAGE_SIZE;
63891+#endif
63892
63893 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63894 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63895@@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63896 flags & VM_WRITE ? 'w' : '-',
63897 flags & VM_EXEC ? 'x' : '-',
63898 flags & VM_MAYSHARE ? 's' : 'p',
63899+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63900+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63901+#else
63902 pgoff,
63903+#endif
63904 MAJOR(dev), MINOR(dev), ino);
63905
63906 /*
63907@@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63908 */
63909 if (file) {
63910 seq_pad(m, ' ');
63911- seq_path(m, &file->f_path, "\n");
63912+ seq_path(m, &file->f_path, "\n\\");
63913 goto done;
63914 }
63915
63916@@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63917 * Thread stack in /proc/PID/task/TID/maps or
63918 * the main process stack.
63919 */
63920- if (!is_pid || (vma->vm_start <= mm->start_stack &&
63921- vma->vm_end >= mm->start_stack)) {
63922+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63923+ (vma->vm_start <= mm->start_stack &&
63924+ vma->vm_end >= mm->start_stack)) {
63925 name = "[stack]";
63926 } else {
63927 /* Thread stack in /proc/PID/maps */
63928@@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63929 struct proc_maps_private *priv = m->private;
63930 struct task_struct *task = priv->task;
63931
63932+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63933+ if (current->exec_id != m->exec_id) {
63934+ gr_log_badprocpid("maps");
63935+ return 0;
63936+ }
63937+#endif
63938+
63939 show_map_vma(m, vma, is_pid);
63940
63941 if (m->count < m->size) /* vma is copied successfully */
63942@@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63943 .private = &mss,
63944 };
63945
63946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63947+ if (current->exec_id != m->exec_id) {
63948+ gr_log_badprocpid("smaps");
63949+ return 0;
63950+ }
63951+#endif
63952 memset(&mss, 0, sizeof mss);
63953- mss.vma = vma;
63954- /* mmap_sem is held in m_start */
63955- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63956- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63957-
63958+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63959+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63960+#endif
63961+ mss.vma = vma;
63962+ /* mmap_sem is held in m_start */
63963+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63964+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63965+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63966+ }
63967+#endif
63968 show_map_vma(m, vma, is_pid);
63969
63970 seq_printf(m,
63971@@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63972 "KernelPageSize: %8lu kB\n"
63973 "MMUPageSize: %8lu kB\n"
63974 "Locked: %8lu kB\n",
63975+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63976+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63977+#else
63978 (vma->vm_end - vma->vm_start) >> 10,
63979+#endif
63980 mss.resident >> 10,
63981 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63982 mss.shared_clean >> 10,
63983@@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63984 char buffer[64];
63985 int nid;
63986
63987+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63988+ if (current->exec_id != m->exec_id) {
63989+ gr_log_badprocpid("numa_maps");
63990+ return 0;
63991+ }
63992+#endif
63993+
63994 if (!mm)
63995 return 0;
63996
63997@@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63998 mpol_to_str(buffer, sizeof(buffer), pol);
63999 mpol_cond_put(pol);
64000
64001+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64002+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64003+#else
64004 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64005+#endif
64006
64007 if (file) {
64008 seq_printf(m, " file=");
64009- seq_path(m, &file->f_path, "\n\t= ");
64010+ seq_path(m, &file->f_path, "\n\t\\= ");
64011 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64012 seq_printf(m, " heap");
64013 } else {
64014diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64015index 678455d..ebd3245 100644
64016--- a/fs/proc/task_nommu.c
64017+++ b/fs/proc/task_nommu.c
64018@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64019 else
64020 bytes += kobjsize(mm);
64021
64022- if (current->fs && current->fs->users > 1)
64023+ if (current->fs && atomic_read(&current->fs->users) > 1)
64024 sbytes += kobjsize(current->fs);
64025 else
64026 bytes += kobjsize(current->fs);
64027@@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64028
64029 if (file) {
64030 seq_pad(m, ' ');
64031- seq_path(m, &file->f_path, "");
64032+ seq_path(m, &file->f_path, "\n\\");
64033 } else if (mm) {
64034 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64035
64036diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64037index 9100d69..51cd925 100644
64038--- a/fs/proc/vmcore.c
64039+++ b/fs/proc/vmcore.c
64040@@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64041 nr_bytes = count;
64042
64043 /* If pfn is not ram, return zeros for sparse dump files */
64044- if (pfn_is_ram(pfn) == 0)
64045- memset(buf, 0, nr_bytes);
64046- else {
64047+ if (pfn_is_ram(pfn) == 0) {
64048+ if (userbuf) {
64049+ if (clear_user((char __force_user *)buf, nr_bytes))
64050+ return -EFAULT;
64051+ } else
64052+ memset(buf, 0, nr_bytes);
64053+ } else {
64054 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64055 offset, userbuf);
64056 if (tmp < 0)
64057@@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64058 static int copy_to(void *target, void *src, size_t size, int userbuf)
64059 {
64060 if (userbuf) {
64061- if (copy_to_user((char __user *) target, src, size))
64062+ if (copy_to_user((char __force_user *) target, src, size))
64063 return -EFAULT;
64064 } else {
64065 memcpy(target, src, size);
64066@@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64067 if (*fpos < m->offset + m->size) {
64068 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64069 start = m->paddr + *fpos - m->offset;
64070- tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64071+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64072 if (tmp < 0)
64073 return tmp;
64074 buflen -= tsz;
64075@@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64076 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64077 size_t buflen, loff_t *fpos)
64078 {
64079- return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64080+ return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64081 }
64082
64083 /*
64084diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64085index b00fcc9..e0c6381 100644
64086--- a/fs/qnx6/qnx6.h
64087+++ b/fs/qnx6/qnx6.h
64088@@ -74,7 +74,7 @@ enum {
64089 BYTESEX_BE,
64090 };
64091
64092-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64093+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64094 {
64095 if (sbi->s_bytesex == BYTESEX_LE)
64096 return le64_to_cpu((__force __le64)n);
64097@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64098 return (__force __fs64)cpu_to_be64(n);
64099 }
64100
64101-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64102+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64103 {
64104 if (sbi->s_bytesex == BYTESEX_LE)
64105 return le32_to_cpu((__force __le32)n);
64106diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64107index 72d2917..c917c12 100644
64108--- a/fs/quota/netlink.c
64109+++ b/fs/quota/netlink.c
64110@@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64111 void quota_send_warning(struct kqid qid, dev_t dev,
64112 const char warntype)
64113 {
64114- static atomic_t seq;
64115+ static atomic_unchecked_t seq;
64116 struct sk_buff *skb;
64117 void *msg_head;
64118 int ret;
64119@@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64120 "VFS: Not enough memory to send quota warning.\n");
64121 return;
64122 }
64123- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64124+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64125 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64126 if (!msg_head) {
64127 printk(KERN_ERR
64128diff --git a/fs/read_write.c b/fs/read_write.c
64129index cfa18df..c110979 100644
64130--- a/fs/read_write.c
64131+++ b/fs/read_write.c
64132@@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64133
64134 old_fs = get_fs();
64135 set_fs(get_ds());
64136- p = (__force const char __user *)buf;
64137+ p = (const char __force_user *)buf;
64138 if (count > MAX_RW_COUNT)
64139 count = MAX_RW_COUNT;
64140 if (file->f_op->write)
64141diff --git a/fs/readdir.c b/fs/readdir.c
64142index 5b53d99..a6c3049 100644
64143--- a/fs/readdir.c
64144+++ b/fs/readdir.c
64145@@ -17,6 +17,7 @@
64146 #include <linux/security.h>
64147 #include <linux/syscalls.h>
64148 #include <linux/unistd.h>
64149+#include <linux/namei.h>
64150
64151 #include <asm/uaccess.h>
64152
64153@@ -69,6 +70,7 @@ struct old_linux_dirent {
64154 struct readdir_callback {
64155 struct dir_context ctx;
64156 struct old_linux_dirent __user * dirent;
64157+ struct file * file;
64158 int result;
64159 };
64160
64161@@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64162 buf->result = -EOVERFLOW;
64163 return -EOVERFLOW;
64164 }
64165+
64166+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64167+ return 0;
64168+
64169 buf->result++;
64170 dirent = buf->dirent;
64171 if (!access_ok(VERIFY_WRITE, dirent,
64172@@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64173 if (!f.file)
64174 return -EBADF;
64175
64176+ buf.file = f.file;
64177 error = iterate_dir(f.file, &buf.ctx);
64178 if (buf.result)
64179 error = buf.result;
64180@@ -142,6 +149,7 @@ struct getdents_callback {
64181 struct dir_context ctx;
64182 struct linux_dirent __user * current_dir;
64183 struct linux_dirent __user * previous;
64184+ struct file * file;
64185 int count;
64186 int error;
64187 };
64188@@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64189 buf->error = -EOVERFLOW;
64190 return -EOVERFLOW;
64191 }
64192+
64193+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64194+ return 0;
64195+
64196 dirent = buf->previous;
64197 if (dirent) {
64198 if (__put_user(offset, &dirent->d_off))
64199@@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64200 if (!f.file)
64201 return -EBADF;
64202
64203+ buf.file = f.file;
64204 error = iterate_dir(f.file, &buf.ctx);
64205 if (error >= 0)
64206 error = buf.error;
64207@@ -226,6 +239,7 @@ struct getdents_callback64 {
64208 struct dir_context ctx;
64209 struct linux_dirent64 __user * current_dir;
64210 struct linux_dirent64 __user * previous;
64211+ struct file *file;
64212 int count;
64213 int error;
64214 };
64215@@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64216 buf->error = -EINVAL; /* only used if we fail.. */
64217 if (reclen > buf->count)
64218 return -EINVAL;
64219+
64220+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64221+ return 0;
64222+
64223 dirent = buf->previous;
64224 if (dirent) {
64225 if (__put_user(offset, &dirent->d_off))
64226@@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64227 if (!f.file)
64228 return -EBADF;
64229
64230+ buf.file = f.file;
64231 error = iterate_dir(f.file, &buf.ctx);
64232 if (error >= 0)
64233 error = buf.error;
64234diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64235index 2b7882b..1c5ef48 100644
64236--- a/fs/reiserfs/do_balan.c
64237+++ b/fs/reiserfs/do_balan.c
64238@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64239 return;
64240 }
64241
64242- atomic_inc(&(fs_generation(tb->tb_sb)));
64243+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64244 do_balance_starts(tb);
64245
64246 /* balance leaf returns 0 except if combining L R and S into
64247diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64248index ee382ef..f4eb6eb5 100644
64249--- a/fs/reiserfs/item_ops.c
64250+++ b/fs/reiserfs/item_ops.c
64251@@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64252 }
64253
64254 static struct item_operations errcatch_ops = {
64255- errcatch_bytes_number,
64256- errcatch_decrement_key,
64257- errcatch_is_left_mergeable,
64258- errcatch_print_item,
64259- errcatch_check_item,
64260+ .bytes_number = errcatch_bytes_number,
64261+ .decrement_key = errcatch_decrement_key,
64262+ .is_left_mergeable = errcatch_is_left_mergeable,
64263+ .print_item = errcatch_print_item,
64264+ .check_item = errcatch_check_item,
64265
64266- errcatch_create_vi,
64267- errcatch_check_left,
64268- errcatch_check_right,
64269- errcatch_part_size,
64270- errcatch_unit_num,
64271- errcatch_print_vi
64272+ .create_vi = errcatch_create_vi,
64273+ .check_left = errcatch_check_left,
64274+ .check_right = errcatch_check_right,
64275+ .part_size = errcatch_part_size,
64276+ .unit_num = errcatch_unit_num,
64277+ .print_vi = errcatch_print_vi
64278 };
64279
64280 //////////////////////////////////////////////////////////////////////////////
64281diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
64282index a958444..42b2323 100644
64283--- a/fs/reiserfs/procfs.c
64284+++ b/fs/reiserfs/procfs.c
64285@@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
64286 "SMALL_TAILS " : "NO_TAILS ",
64287 replay_only(sb) ? "REPLAY_ONLY " : "",
64288 convert_reiserfs(sb) ? "CONV " : "",
64289- atomic_read(&r->s_generation_counter),
64290+ atomic_read_unchecked(&r->s_generation_counter),
64291 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
64292 SF(s_do_balance), SF(s_unneeded_left_neighbor),
64293 SF(s_good_search_by_key_reada), SF(s_bmaps),
64294diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
64295index f8adaee..0eeeeca 100644
64296--- a/fs/reiserfs/reiserfs.h
64297+++ b/fs/reiserfs/reiserfs.h
64298@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
64299 /* Comment? -Hans */
64300 wait_queue_head_t s_wait;
64301 /* To be obsoleted soon by per buffer seals.. -Hans */
64302- atomic_t s_generation_counter; // increased by one every time the
64303+ atomic_unchecked_t s_generation_counter; // increased by one every time the
64304 // tree gets re-balanced
64305 unsigned long s_properties; /* File system properties. Currently holds
64306 on-disk FS format */
64307@@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
64308 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
64309
64310 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
64311-#define get_generation(s) atomic_read (&fs_generation(s))
64312+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
64313 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
64314 #define __fs_changed(gen,s) (gen != get_generation (s))
64315 #define fs_changed(gen,s) \
64316diff --git a/fs/select.c b/fs/select.c
64317index 467bb1c..cf9d65a 100644
64318--- a/fs/select.c
64319+++ b/fs/select.c
64320@@ -20,6 +20,7 @@
64321 #include <linux/export.h>
64322 #include <linux/slab.h>
64323 #include <linux/poll.h>
64324+#include <linux/security.h>
64325 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
64326 #include <linux/file.h>
64327 #include <linux/fdtable.h>
64328@@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
64329 struct poll_list *walk = head;
64330 unsigned long todo = nfds;
64331
64332+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
64333 if (nfds > rlimit(RLIMIT_NOFILE))
64334 return -EINVAL;
64335
64336diff --git a/fs/seq_file.c b/fs/seq_file.c
64337index 1d641bb..e600623 100644
64338--- a/fs/seq_file.c
64339+++ b/fs/seq_file.c
64340@@ -10,6 +10,7 @@
64341 #include <linux/seq_file.h>
64342 #include <linux/slab.h>
64343 #include <linux/cred.h>
64344+#include <linux/sched.h>
64345
64346 #include <asm/uaccess.h>
64347 #include <asm/page.h>
64348@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
64349 #ifdef CONFIG_USER_NS
64350 p->user_ns = file->f_cred->user_ns;
64351 #endif
64352+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64353+ p->exec_id = current->exec_id;
64354+#endif
64355
64356 /*
64357 * Wrappers around seq_open(e.g. swaps_open) need to be
64358@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
64359 return 0;
64360 }
64361 if (!m->buf) {
64362- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64363+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64364 if (!m->buf)
64365 return -ENOMEM;
64366 }
64367@@ -137,7 +141,7 @@ Eoverflow:
64368 m->op->stop(m, p);
64369 kfree(m->buf);
64370 m->count = 0;
64371- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64372+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64373 return !m->buf ? -ENOMEM : -EAGAIN;
64374 }
64375
64376@@ -153,7 +157,7 @@ Eoverflow:
64377 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64378 {
64379 struct seq_file *m = file->private_data;
64380- size_t copied = 0;
64381+ ssize_t copied = 0;
64382 loff_t pos;
64383 size_t n;
64384 void *p;
64385@@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64386
64387 /* grab buffer if we didn't have one */
64388 if (!m->buf) {
64389- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
64390+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
64391 if (!m->buf)
64392 goto Enomem;
64393 }
64394@@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
64395 m->op->stop(m, p);
64396 kfree(m->buf);
64397 m->count = 0;
64398- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
64399+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
64400 if (!m->buf)
64401 goto Enomem;
64402 m->version = 0;
64403@@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
64404 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
64405 void *data)
64406 {
64407- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
64408+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
64409 int res = -ENOMEM;
64410
64411 if (op) {
64412diff --git a/fs/splice.c b/fs/splice.c
64413index 12028fa..a6f2619 100644
64414--- a/fs/splice.c
64415+++ b/fs/splice.c
64416@@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64417 pipe_lock(pipe);
64418
64419 for (;;) {
64420- if (!pipe->readers) {
64421+ if (!atomic_read(&pipe->readers)) {
64422 send_sig(SIGPIPE, current, 0);
64423 if (!ret)
64424 ret = -EPIPE;
64425@@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64426 page_nr++;
64427 ret += buf->len;
64428
64429- if (pipe->files)
64430+ if (atomic_read(&pipe->files))
64431 do_wakeup = 1;
64432
64433 if (!--spd->nr_pages)
64434@@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
64435 do_wakeup = 0;
64436 }
64437
64438- pipe->waiting_writers++;
64439+ atomic_inc(&pipe->waiting_writers);
64440 pipe_wait(pipe);
64441- pipe->waiting_writers--;
64442+ atomic_dec(&pipe->waiting_writers);
64443 }
64444
64445 pipe_unlock(pipe);
64446@@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
64447 old_fs = get_fs();
64448 set_fs(get_ds());
64449 /* The cast to a user pointer is valid due to the set_fs() */
64450- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
64451+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
64452 set_fs(old_fs);
64453
64454 return res;
64455@@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
64456 old_fs = get_fs();
64457 set_fs(get_ds());
64458 /* The cast to a user pointer is valid due to the set_fs() */
64459- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
64460+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
64461 set_fs(old_fs);
64462
64463 return res;
64464@@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
64465 goto err;
64466
64467 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
64468- vec[i].iov_base = (void __user *) page_address(page);
64469+ vec[i].iov_base = (void __force_user *) page_address(page);
64470 vec[i].iov_len = this_len;
64471 spd.pages[i] = page;
64472 spd.nr_pages++;
64473@@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
64474 ops->release(pipe, buf);
64475 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
64476 pipe->nrbufs--;
64477- if (pipe->files)
64478+ if (atomic_read(&pipe->files))
64479 sd->need_wakeup = true;
64480 }
64481
64482@@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
64483 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
64484 {
64485 while (!pipe->nrbufs) {
64486- if (!pipe->writers)
64487+ if (!atomic_read(&pipe->writers))
64488 return 0;
64489
64490- if (!pipe->waiting_writers && sd->num_spliced)
64491+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
64492 return 0;
64493
64494 if (sd->flags & SPLICE_F_NONBLOCK)
64495@@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
64496 * out of the pipe right after the splice_to_pipe(). So set
64497 * PIPE_READERS appropriately.
64498 */
64499- pipe->readers = 1;
64500+ atomic_set(&pipe->readers, 1);
64501
64502 current->splice_pipe = pipe;
64503 }
64504@@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
64505
64506 partial[buffers].offset = off;
64507 partial[buffers].len = plen;
64508+ partial[buffers].private = 0;
64509
64510 off = 0;
64511 len -= plen;
64512@@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64513 ret = -ERESTARTSYS;
64514 break;
64515 }
64516- if (!pipe->writers)
64517+ if (!atomic_read(&pipe->writers))
64518 break;
64519- if (!pipe->waiting_writers) {
64520+ if (!atomic_read(&pipe->waiting_writers)) {
64521 if (flags & SPLICE_F_NONBLOCK) {
64522 ret = -EAGAIN;
64523 break;
64524@@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64525 pipe_lock(pipe);
64526
64527 while (pipe->nrbufs >= pipe->buffers) {
64528- if (!pipe->readers) {
64529+ if (!atomic_read(&pipe->readers)) {
64530 send_sig(SIGPIPE, current, 0);
64531 ret = -EPIPE;
64532 break;
64533@@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
64534 ret = -ERESTARTSYS;
64535 break;
64536 }
64537- pipe->waiting_writers++;
64538+ atomic_inc(&pipe->waiting_writers);
64539 pipe_wait(pipe);
64540- pipe->waiting_writers--;
64541+ atomic_dec(&pipe->waiting_writers);
64542 }
64543
64544 pipe_unlock(pipe);
64545@@ -1880,14 +1881,14 @@ retry:
64546 pipe_double_lock(ipipe, opipe);
64547
64548 do {
64549- if (!opipe->readers) {
64550+ if (!atomic_read(&opipe->readers)) {
64551 send_sig(SIGPIPE, current, 0);
64552 if (!ret)
64553 ret = -EPIPE;
64554 break;
64555 }
64556
64557- if (!ipipe->nrbufs && !ipipe->writers)
64558+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
64559 break;
64560
64561 /*
64562@@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64563 pipe_double_lock(ipipe, opipe);
64564
64565 do {
64566- if (!opipe->readers) {
64567+ if (!atomic_read(&opipe->readers)) {
64568 send_sig(SIGPIPE, current, 0);
64569 if (!ret)
64570 ret = -EPIPE;
64571@@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
64572 * return EAGAIN if we have the potential of some data in the
64573 * future, otherwise just return 0
64574 */
64575- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
64576+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
64577 ret = -EAGAIN;
64578
64579 pipe_unlock(ipipe);
64580diff --git a/fs/stat.c b/fs/stat.c
64581index ae0c3ce..9ee641c 100644
64582--- a/fs/stat.c
64583+++ b/fs/stat.c
64584@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
64585 stat->gid = inode->i_gid;
64586 stat->rdev = inode->i_rdev;
64587 stat->size = i_size_read(inode);
64588- stat->atime = inode->i_atime;
64589- stat->mtime = inode->i_mtime;
64590+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64591+ stat->atime = inode->i_ctime;
64592+ stat->mtime = inode->i_ctime;
64593+ } else {
64594+ stat->atime = inode->i_atime;
64595+ stat->mtime = inode->i_mtime;
64596+ }
64597 stat->ctime = inode->i_ctime;
64598 stat->blksize = (1 << inode->i_blkbits);
64599 stat->blocks = inode->i_blocks;
64600@@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
64601 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
64602 {
64603 struct inode *inode = path->dentry->d_inode;
64604+ int retval;
64605
64606- if (inode->i_op->getattr)
64607- return inode->i_op->getattr(path->mnt, path->dentry, stat);
64608+ if (inode->i_op->getattr) {
64609+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
64610+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
64611+ stat->atime = stat->ctime;
64612+ stat->mtime = stat->ctime;
64613+ }
64614+ return retval;
64615+ }
64616
64617 generic_fillattr(inode, stat);
64618 return 0;
64619diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
64620index 5e73d66..4f165fd 100644
64621--- a/fs/sysfs/dir.c
64622+++ b/fs/sysfs/dir.c
64623@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
64624 *
64625 * Returns 31 bit hash of ns + name (so it fits in an off_t )
64626 */
64627-static unsigned int sysfs_name_hash(const char *name, const void *ns)
64628+static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
64629 {
64630 unsigned long hash = init_name_hash();
64631 unsigned int len = strlen(name);
64632@@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
64633 struct sysfs_dirent *sd;
64634 int rc;
64635
64636+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
64637+ const char *parent_name = parent_sd->s_name;
64638+
64639+ mode = S_IFDIR | S_IRWXU;
64640+
64641+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
64642+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
64643+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
64644+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
64645+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
64646+#endif
64647+
64648 /* allocate */
64649 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
64650 if (!sd)
64651diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
64652index 35e7d08..4d6e676 100644
64653--- a/fs/sysfs/file.c
64654+++ b/fs/sysfs/file.c
64655@@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
64656
64657 struct sysfs_open_dirent {
64658 atomic_t refcnt;
64659- atomic_t event;
64660+ atomic_unchecked_t event;
64661 wait_queue_head_t poll;
64662 struct list_head files; /* goes through sysfs_open_file.list */
64663 };
64664@@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
64665 return -ENODEV;
64666 }
64667
64668- of->event = atomic_read(&of->sd->s_attr.open->event);
64669+ of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
64670
64671 /*
64672 * Lookup @ops and invoke show(). Control may reach here via seq
64673@@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
64674 return ret;
64675 }
64676
64677-static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64678- void *buf, int len, int write)
64679+static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
64680+ void *buf, size_t len, int write)
64681 {
64682 struct file *file = vma->vm_file;
64683 struct sysfs_open_file *of = sysfs_of(file);
64684- int ret;
64685+ ssize_t ret;
64686
64687 if (!of->vm_ops)
64688 return -EINVAL;
64689@@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
64690 return -ENOMEM;
64691
64692 atomic_set(&new_od->refcnt, 0);
64693- atomic_set(&new_od->event, 1);
64694+ atomic_set_unchecked(&new_od->event, 1);
64695 init_waitqueue_head(&new_od->poll);
64696 INIT_LIST_HEAD(&new_od->files);
64697 goto retry;
64698@@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
64699
64700 sysfs_put_active(attr_sd);
64701
64702- if (of->event != atomic_read(&od->event))
64703+ if (of->event != atomic_read_unchecked(&od->event))
64704 goto trigger;
64705
64706 return DEFAULT_POLLMASK;
64707@@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
64708 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
64709 od = sd->s_attr.open;
64710 if (od) {
64711- atomic_inc(&od->event);
64712+ atomic_inc_unchecked(&od->event);
64713 wake_up_interruptible(&od->poll);
64714 }
64715 }
64716diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
64717index 3ae3f1b..081a26c 100644
64718--- a/fs/sysfs/symlink.c
64719+++ b/fs/sysfs/symlink.c
64720@@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
64721 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
64722 void *cookie)
64723 {
64724- char *page = nd_get_link(nd);
64725+ const char *page = nd_get_link(nd);
64726 if (!IS_ERR(page))
64727 free_page((unsigned long)page);
64728 }
64729diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
64730index 69d4889..a810bd4 100644
64731--- a/fs/sysv/sysv.h
64732+++ b/fs/sysv/sysv.h
64733@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
64734 #endif
64735 }
64736
64737-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64738+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
64739 {
64740 if (sbi->s_bytesex == BYTESEX_PDP)
64741 return PDP_swab((__force __u32)n);
64742diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
64743index e18b988..f1d4ad0f 100644
64744--- a/fs/ubifs/io.c
64745+++ b/fs/ubifs/io.c
64746@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
64747 return err;
64748 }
64749
64750-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64751+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
64752 {
64753 int err;
64754
64755diff --git a/fs/udf/misc.c b/fs/udf/misc.c
64756index c175b4d..8f36a16 100644
64757--- a/fs/udf/misc.c
64758+++ b/fs/udf/misc.c
64759@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
64760
64761 u8 udf_tag_checksum(const struct tag *t)
64762 {
64763- u8 *data = (u8 *)t;
64764+ const u8 *data = (const u8 *)t;
64765 u8 checksum = 0;
64766 int i;
64767 for (i = 0; i < sizeof(struct tag); ++i)
64768diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
64769index 8d974c4..b82f6ec 100644
64770--- a/fs/ufs/swab.h
64771+++ b/fs/ufs/swab.h
64772@@ -22,7 +22,7 @@ enum {
64773 BYTESEX_BE
64774 };
64775
64776-static inline u64
64777+static inline u64 __intentional_overflow(-1)
64778 fs64_to_cpu(struct super_block *sbp, __fs64 n)
64779 {
64780 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64781@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
64782 return (__force __fs64)cpu_to_be64(n);
64783 }
64784
64785-static inline u32
64786+static inline u32 __intentional_overflow(-1)
64787 fs32_to_cpu(struct super_block *sbp, __fs32 n)
64788 {
64789 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
64790diff --git a/fs/utimes.c b/fs/utimes.c
64791index aa138d6..5f3a811 100644
64792--- a/fs/utimes.c
64793+++ b/fs/utimes.c
64794@@ -1,6 +1,7 @@
64795 #include <linux/compiler.h>
64796 #include <linux/file.h>
64797 #include <linux/fs.h>
64798+#include <linux/security.h>
64799 #include <linux/linkage.h>
64800 #include <linux/mount.h>
64801 #include <linux/namei.h>
64802@@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
64803 }
64804 }
64805 retry_deleg:
64806+
64807+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
64808+ error = -EACCES;
64809+ goto mnt_drop_write_and_out;
64810+ }
64811+
64812 mutex_lock(&inode->i_mutex);
64813 error = notify_change(path->dentry, &newattrs, &delegated_inode);
64814 mutex_unlock(&inode->i_mutex);
64815diff --git a/fs/xattr.c b/fs/xattr.c
64816index 3377dff..f394815 100644
64817--- a/fs/xattr.c
64818+++ b/fs/xattr.c
64819@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
64820 return rc;
64821 }
64822
64823+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
64824+ssize_t
64825+pax_getxattr(struct dentry *dentry, void *value, size_t size)
64826+{
64827+ struct inode *inode = dentry->d_inode;
64828+ ssize_t error;
64829+
64830+ error = inode_permission(inode, MAY_EXEC);
64831+ if (error)
64832+ return error;
64833+
64834+ if (inode->i_op->getxattr)
64835+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
64836+ else
64837+ error = -EOPNOTSUPP;
64838+
64839+ return error;
64840+}
64841+EXPORT_SYMBOL(pax_getxattr);
64842+#endif
64843+
64844 ssize_t
64845 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64846 {
64847@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64848 * Extended attribute SET operations
64849 */
64850 static long
64851-setxattr(struct dentry *d, const char __user *name, const void __user *value,
64852+setxattr(struct path *path, const char __user *name, const void __user *value,
64853 size_t size, int flags)
64854 {
64855 int error;
64856@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64857 posix_acl_fix_xattr_from_user(kvalue, size);
64858 }
64859
64860- error = vfs_setxattr(d, kname, kvalue, size, flags);
64861+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64862+ error = -EACCES;
64863+ goto out;
64864+ }
64865+
64866+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64867 out:
64868 if (vvalue)
64869 vfree(vvalue);
64870@@ -377,7 +403,7 @@ retry:
64871 return error;
64872 error = mnt_want_write(path.mnt);
64873 if (!error) {
64874- error = setxattr(path.dentry, name, value, size, flags);
64875+ error = setxattr(&path, name, value, size, flags);
64876 mnt_drop_write(path.mnt);
64877 }
64878 path_put(&path);
64879@@ -401,7 +427,7 @@ retry:
64880 return error;
64881 error = mnt_want_write(path.mnt);
64882 if (!error) {
64883- error = setxattr(path.dentry, name, value, size, flags);
64884+ error = setxattr(&path, name, value, size, flags);
64885 mnt_drop_write(path.mnt);
64886 }
64887 path_put(&path);
64888@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64889 const void __user *,value, size_t, size, int, flags)
64890 {
64891 struct fd f = fdget(fd);
64892- struct dentry *dentry;
64893 int error = -EBADF;
64894
64895 if (!f.file)
64896 return error;
64897- dentry = f.file->f_path.dentry;
64898- audit_inode(NULL, dentry, 0);
64899+ audit_inode(NULL, f.file->f_path.dentry, 0);
64900 error = mnt_want_write_file(f.file);
64901 if (!error) {
64902- error = setxattr(dentry, name, value, size, flags);
64903+ error = setxattr(&f.file->f_path, name, value, size, flags);
64904 mnt_drop_write_file(f.file);
64905 }
64906 fdput(f);
64907@@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64908 * Extended attribute REMOVE operations
64909 */
64910 static long
64911-removexattr(struct dentry *d, const char __user *name)
64912+removexattr(struct path *path, const char __user *name)
64913 {
64914 int error;
64915 char kname[XATTR_NAME_MAX + 1];
64916@@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64917 if (error < 0)
64918 return error;
64919
64920- return vfs_removexattr(d, kname);
64921+ if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64922+ return -EACCES;
64923+
64924+ return vfs_removexattr(path->dentry, kname);
64925 }
64926
64927 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64928@@ -652,7 +679,7 @@ retry:
64929 return error;
64930 error = mnt_want_write(path.mnt);
64931 if (!error) {
64932- error = removexattr(path.dentry, name);
64933+ error = removexattr(&path, name);
64934 mnt_drop_write(path.mnt);
64935 }
64936 path_put(&path);
64937@@ -675,7 +702,7 @@ retry:
64938 return error;
64939 error = mnt_want_write(path.mnt);
64940 if (!error) {
64941- error = removexattr(path.dentry, name);
64942+ error = removexattr(&path, name);
64943 mnt_drop_write(path.mnt);
64944 }
64945 path_put(&path);
64946@@ -689,16 +716,16 @@ retry:
64947 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64948 {
64949 struct fd f = fdget(fd);
64950- struct dentry *dentry;
64951+ struct path *path;
64952 int error = -EBADF;
64953
64954 if (!f.file)
64955 return error;
64956- dentry = f.file->f_path.dentry;
64957- audit_inode(NULL, dentry, 0);
64958+ path = &f.file->f_path;
64959+ audit_inode(NULL, path->dentry, 0);
64960 error = mnt_want_write_file(f.file);
64961 if (!error) {
64962- error = removexattr(dentry, name);
64963+ error = removexattr(path, name);
64964 mnt_drop_write_file(f.file);
64965 }
64966 fdput(f);
64967diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64968index 9fbea87..417b3c2 100644
64969--- a/fs/xattr_acl.c
64970+++ b/fs/xattr_acl.c
64971@@ -10,6 +10,7 @@
64972 #include <linux/posix_acl_xattr.h>
64973 #include <linux/gfp.h>
64974 #include <linux/user_namespace.h>
64975+#include <linux/grsecurity.h>
64976
64977 /*
64978 * Fix up the uids and gids in posix acl extended attributes in place.
64979@@ -76,11 +77,12 @@ struct posix_acl *
64980 posix_acl_from_xattr(struct user_namespace *user_ns,
64981 const void *value, size_t size)
64982 {
64983- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64984- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64985+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64986+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64987 int count;
64988 struct posix_acl *acl;
64989 struct posix_acl_entry *acl_e;
64990+ umode_t umask = gr_acl_umask();
64991
64992 if (!value)
64993 return NULL;
64994@@ -106,12 +108,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
64995
64996 switch(acl_e->e_tag) {
64997 case ACL_USER_OBJ:
64998+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
64999+ break;
65000 case ACL_GROUP_OBJ:
65001 case ACL_MASK:
65002+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65003+ break;
65004 case ACL_OTHER:
65005+ acl_e->e_perm &= ~(umask & S_IRWXO);
65006 break;
65007
65008 case ACL_USER:
65009+ acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
65010 acl_e->e_uid =
65011 make_kuid(user_ns,
65012 le32_to_cpu(entry->e_id));
65013@@ -119,6 +127,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
65014 goto fail;
65015 break;
65016 case ACL_GROUP:
65017+ acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
65018 acl_e->e_gid =
65019 make_kgid(user_ns,
65020 le32_to_cpu(entry->e_id));
65021diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65022index 3b2c14b..de031fe 100644
65023--- a/fs/xfs/xfs_bmap.c
65024+++ b/fs/xfs/xfs_bmap.c
65025@@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65026
65027 #else
65028 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65029-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65030+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65031 #endif /* DEBUG */
65032
65033 /*
65034diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65035index c4e50c6..8ba93e3 100644
65036--- a/fs/xfs/xfs_dir2_readdir.c
65037+++ b/fs/xfs/xfs_dir2_readdir.c
65038@@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65039 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65040 filetype = dp->d_ops->sf_get_ftype(sfep);
65041 ctx->pos = off & 0x7fffffff;
65042- if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65043+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65044+ char name[sfep->namelen];
65045+ memcpy(name, sfep->name, sfep->namelen);
65046+ if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65047+ return 0;
65048+ } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65049 xfs_dir3_get_dtype(mp, filetype)))
65050 return 0;
65051 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65052diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65053index 33ad9a7..82c18ba 100644
65054--- a/fs/xfs/xfs_ioctl.c
65055+++ b/fs/xfs/xfs_ioctl.c
65056@@ -126,7 +126,7 @@ xfs_find_handle(
65057 }
65058
65059 error = -EFAULT;
65060- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65061+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65062 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65063 goto out_put;
65064
65065diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
65066index 104455b..764c512 100644
65067--- a/fs/xfs/xfs_iops.c
65068+++ b/fs/xfs/xfs_iops.c
65069@@ -397,7 +397,7 @@ xfs_vn_put_link(
65070 struct nameidata *nd,
65071 void *p)
65072 {
65073- char *s = nd_get_link(nd);
65074+ const char *s = nd_get_link(nd);
65075
65076 if (!IS_ERR(s))
65077 kfree(s);
65078diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65079new file mode 100644
65080index 0000000..3abaf02
65081--- /dev/null
65082+++ b/grsecurity/Kconfig
65083@@ -0,0 +1,1161 @@
65084+#
65085+# grecurity configuration
65086+#
65087+menu "Memory Protections"
65088+depends on GRKERNSEC
65089+
65090+config GRKERNSEC_KMEM
65091+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65092+ default y if GRKERNSEC_CONFIG_AUTO
65093+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65094+ help
65095+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65096+ be written to or read from to modify or leak the contents of the running
65097+ kernel. /dev/port will also not be allowed to be opened, writing to
65098+ /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65099+ If you have module support disabled, enabling this will close up several
65100+ ways that are currently used to insert malicious code into the running
65101+ kernel.
65102+
65103+ Even with this feature enabled, we still highly recommend that
65104+ you use the RBAC system, as it is still possible for an attacker to
65105+ modify the running kernel through other more obscure methods.
65106+
65107+ It is highly recommended that you say Y here if you meet all the
65108+ conditions above.
65109+
65110+config GRKERNSEC_VM86
65111+ bool "Restrict VM86 mode"
65112+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65113+ depends on X86_32
65114+
65115+ help
65116+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65117+ make use of a special execution mode on 32bit x86 processors called
65118+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65119+ video cards and will still work with this option enabled. The purpose
65120+ of the option is to prevent exploitation of emulation errors in
65121+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
65122+ Nearly all users should be able to enable this option.
65123+
65124+config GRKERNSEC_IO
65125+ bool "Disable privileged I/O"
65126+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65127+ depends on X86
65128+ select RTC_CLASS
65129+ select RTC_INTF_DEV
65130+ select RTC_DRV_CMOS
65131+
65132+ help
65133+ If you say Y here, all ioperm and iopl calls will return an error.
65134+ Ioperm and iopl can be used to modify the running kernel.
65135+ Unfortunately, some programs need this access to operate properly,
65136+ the most notable of which are XFree86 and hwclock. hwclock can be
65137+ remedied by having RTC support in the kernel, so real-time
65138+ clock support is enabled if this option is enabled, to ensure
65139+ that hwclock operates correctly. If hwclock still does not work,
65140+ either update udev or symlink /dev/rtc to /dev/rtc0.
65141+
65142+ If you're using XFree86 or a version of Xorg from 2012 or earlier,
65143+ you may not be able to boot into a graphical environment with this
65144+ option enabled. In this case, you should use the RBAC system instead.
65145+
65146+config GRKERNSEC_JIT_HARDEN
65147+ bool "Harden BPF JIT against spray attacks"
65148+ default y if GRKERNSEC_CONFIG_AUTO
65149+ depends on BPF_JIT && X86
65150+ help
65151+ If you say Y here, the native code generated by the kernel's Berkeley
65152+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65153+ attacks that attempt to fit attacker-beneficial instructions in
65154+ 32bit immediate fields of JIT-generated native instructions. The
65155+ attacker will generally aim to cause an unintended instruction sequence
65156+ of JIT-generated native code to execute by jumping into the middle of
65157+ a generated instruction. This feature effectively randomizes the 32bit
65158+ immediate constants present in the generated code to thwart such attacks.
65159+
65160+ If you're using KERNEXEC, it's recommended that you enable this option
65161+ to supplement the hardening of the kernel.
65162+
65163+config GRKERNSEC_PERF_HARDEN
65164+ bool "Disable unprivileged PERF_EVENTS usage by default"
65165+ default y if GRKERNSEC_CONFIG_AUTO
65166+ depends on PERF_EVENTS
65167+ help
65168+ If you say Y here, the range of acceptable values for the
65169+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65170+ default to a new value: 3. When the sysctl is set to this value, no
65171+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65172+
65173+ Though PERF_EVENTS can be used legitimately for performance monitoring
65174+ and low-level application profiling, it is forced on regardless of
65175+ configuration, has been at fault for several vulnerabilities, and
65176+ creates new opportunities for side channels and other information leaks.
65177+
65178+ This feature puts PERF_EVENTS into a secure default state and permits
65179+ the administrator to change out of it temporarily if unprivileged
65180+ application profiling is needed.
65181+
65182+config GRKERNSEC_RAND_THREADSTACK
65183+ bool "Insert random gaps between thread stacks"
65184+ default y if GRKERNSEC_CONFIG_AUTO
65185+ depends on PAX_RANDMMAP && !PPC
65186+ help
65187+ If you say Y here, a random-sized gap will be enforced between allocated
65188+ thread stacks. Glibc's NPTL and other threading libraries that
65189+ pass MAP_STACK to the kernel for thread stack allocation are supported.
65190+ The implementation currently provides 8 bits of entropy for the gap.
65191+
65192+ Many distributions do not compile threaded remote services with the
65193+ -fstack-check argument to GCC, causing the variable-sized stack-based
65194+ allocator, alloca(), to not probe the stack on allocation. This
65195+ permits an unbounded alloca() to skip over any guard page and potentially
65196+ modify another thread's stack reliably. An enforced random gap
65197+ reduces the reliability of such an attack and increases the chance
65198+ that such a read/write to another thread's stack instead lands in
65199+ an unmapped area, causing a crash and triggering grsecurity's
65200+ anti-bruteforcing logic.
65201+
65202+config GRKERNSEC_PROC_MEMMAP
65203+ bool "Harden ASLR against information leaks and entropy reduction"
65204+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65205+ depends on PAX_NOEXEC || PAX_ASLR
65206+ help
65207+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65208+ give no information about the addresses of its mappings if
65209+ PaX features that rely on random addresses are enabled on the task.
65210+ In addition to sanitizing this information and disabling other
65211+ dangerous sources of information, this option causes reads of sensitive
65212+ /proc/<pid> entries where the file descriptor was opened in a different
65213+ task than the one performing the read. Such attempts are logged.
65214+ This option also limits argv/env strings for suid/sgid binaries
65215+ to 512KB to prevent a complete exhaustion of the stack entropy provided
65216+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65217+ binaries to prevent alternative mmap layouts from being abused.
65218+
65219+ If you use PaX it is essential that you say Y here as it closes up
65220+ several holes that make full ASLR useless locally.
65221+
65222+config GRKERNSEC_BRUTE
65223+ bool "Deter exploit bruteforcing"
65224+ default y if GRKERNSEC_CONFIG_AUTO
65225+ help
65226+ If you say Y here, attempts to bruteforce exploits against forking
65227+ daemons such as apache or sshd, as well as against suid/sgid binaries
65228+ will be deterred. When a child of a forking daemon is killed by PaX
65229+ or crashes due to an illegal instruction or other suspicious signal,
65230+ the parent process will be delayed 30 seconds upon every subsequent
65231+ fork until the administrator is able to assess the situation and
65232+ restart the daemon.
65233+ In the suid/sgid case, the attempt is logged, the user has all their
65234+ existing instances of the suid/sgid binary terminated and will
65235+ be unable to execute any suid/sgid binaries for 15 minutes.
65236+
65237+ It is recommended that you also enable signal logging in the auditing
65238+ section so that logs are generated when a process triggers a suspicious
65239+ signal.
65240+ If the sysctl option is enabled, a sysctl option with name
65241+ "deter_bruteforce" is created.
65242+
65243+config GRKERNSEC_MODHARDEN
65244+ bool "Harden module auto-loading"
65245+ default y if GRKERNSEC_CONFIG_AUTO
65246+ depends on MODULES
65247+ help
65248+ If you say Y here, module auto-loading in response to use of some
65249+ feature implemented by an unloaded module will be restricted to
65250+ root users. Enabling this option helps defend against attacks
65251+ by unprivileged users who abuse the auto-loading behavior to
65252+ cause a vulnerable module to load that is then exploited.
65253+
65254+ If this option prevents a legitimate use of auto-loading for a
65255+ non-root user, the administrator can execute modprobe manually
65256+ with the exact name of the module mentioned in the alert log.
65257+ Alternatively, the administrator can add the module to the list
65258+ of modules loaded at boot by modifying init scripts.
65259+
65260+ Modification of init scripts will most likely be needed on
65261+ Ubuntu servers with encrypted home directory support enabled,
65262+ as the first non-root user logging in will cause the ecb(aes),
65263+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65264+
65265+config GRKERNSEC_HIDESYM
65266+ bool "Hide kernel symbols"
65267+ default y if GRKERNSEC_CONFIG_AUTO
65268+ select PAX_USERCOPY_SLABS
65269+ help
65270+ If you say Y here, getting information on loaded modules, and
65271+ displaying all kernel symbols through a syscall will be restricted
65272+ to users with CAP_SYS_MODULE. For software compatibility reasons,
65273+ /proc/kallsyms will be restricted to the root user. The RBAC
65274+ system can hide that entry even from root.
65275+
65276+ This option also prevents leaking of kernel addresses through
65277+ several /proc entries.
65278+
65279+ Note that this option is only effective provided the following
65280+ conditions are met:
65281+ 1) The kernel using grsecurity is not precompiled by some distribution
65282+ 2) You have also enabled GRKERNSEC_DMESG
65283+ 3) You are using the RBAC system and hiding other files such as your
65284+ kernel image and System.map. Alternatively, enabling this option
65285+ causes the permissions on /boot, /lib/modules, and the kernel
65286+ source directory to change at compile time to prevent
65287+ reading by non-root users.
65288+ If the above conditions are met, this option will aid in providing a
65289+ useful protection against local kernel exploitation of overflows
65290+ and arbitrary read/write vulnerabilities.
65291+
65292+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65293+ in addition to this feature.
65294+
65295+config GRKERNSEC_RANDSTRUCT
65296+ bool "Randomize layout of sensitive kernel structures"
65297+ default y if GRKERNSEC_CONFIG_AUTO
65298+ select GRKERNSEC_HIDESYM
65299+ select MODVERSIONS if MODULES
65300+ help
65301+ If you say Y here, the layouts of a number of sensitive kernel
65302+ structures (task, fs, cred, etc) and all structures composed entirely
65303+ of function pointers (aka "ops" structs) will be randomized at compile-time.
65304+ This can introduce the requirement of an additional infoleak
65305+ vulnerability for exploits targeting these structure types.
65306+
65307+ Enabling this feature will introduce some performance impact, slightly
65308+ increase memory usage, and prevent the use of forensic tools like
65309+ Volatility against the system (unless the kernel source tree isn't
65310+ cleaned after kernel installation).
65311+
65312+ The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65313+ It remains after a make clean to allow for external modules to be compiled
65314+ with the existing seed and will be removed by a make mrproper or
65315+ make distclean.
65316+
65317+ Note that the implementation requires gcc 4.6.4. or newer. You may need
65318+ to install the supporting headers explicitly in addition to the normal
65319+ gcc package.
65320+
65321+config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65322+ bool "Use cacheline-aware structure randomization"
65323+ depends on GRKERNSEC_RANDSTRUCT
65324+ default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65325+ help
65326+ If you say Y here, the RANDSTRUCT randomization will make a best effort
65327+ at restricting randomization to cacheline-sized groups of elements. It
65328+ will further not randomize bitfields in structures. This reduces the
65329+ performance hit of RANDSTRUCT at the cost of weakened randomization.
65330+
65331+config GRKERNSEC_KERN_LOCKOUT
65332+ bool "Active kernel exploit response"
65333+ default y if GRKERNSEC_CONFIG_AUTO
65334+ depends on X86 || ARM || PPC || SPARC
65335+ help
65336+ If you say Y here, when a PaX alert is triggered due to suspicious
65337+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65338+ or an OOPS occurs due to bad memory accesses, instead of just
65339+ terminating the offending process (and potentially allowing
65340+ a subsequent exploit from the same user), we will take one of two
65341+ actions:
65342+ If the user was root, we will panic the system
65343+ If the user was non-root, we will log the attempt, terminate
65344+ all processes owned by the user, then prevent them from creating
65345+ any new processes until the system is restarted
65346+ This deters repeated kernel exploitation/bruteforcing attempts
65347+ and is useful for later forensics.
65348+
65349+config GRKERNSEC_OLD_ARM_USERLAND
65350+ bool "Old ARM userland compatibility"
65351+ depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
65352+ help
65353+ If you say Y here, stubs of executable code to perform such operations
65354+ as "compare-exchange" will be placed at fixed locations in the ARM vector
65355+ table. This is unfortunately needed for old ARM userland meant to run
65356+ across a wide range of processors. Without this option enabled,
65357+ the get_tls and data memory barrier stubs will be emulated by the kernel,
65358+ which is enough for Linaro userlands or other userlands designed for v6
65359+ and newer ARM CPUs. It's recommended that you try without this option enabled
65360+ first, and only enable it if your userland does not boot (it will likely fail
65361+ at init time).
65362+
65363+endmenu
65364+menu "Role Based Access Control Options"
65365+depends on GRKERNSEC
65366+
65367+config GRKERNSEC_RBAC_DEBUG
65368+ bool
65369+
65370+config GRKERNSEC_NO_RBAC
65371+ bool "Disable RBAC system"
65372+ help
65373+ If you say Y here, the /dev/grsec device will be removed from the kernel,
65374+ preventing the RBAC system from being enabled. You should only say Y
65375+ here if you have no intention of using the RBAC system, so as to prevent
65376+ an attacker with root access from misusing the RBAC system to hide files
65377+ and processes when loadable module support and /dev/[k]mem have been
65378+ locked down.
65379+
65380+config GRKERNSEC_ACL_HIDEKERN
65381+ bool "Hide kernel processes"
65382+ help
65383+ If you say Y here, all kernel threads will be hidden to all
65384+ processes but those whose subject has the "view hidden processes"
65385+ flag.
65386+
65387+config GRKERNSEC_ACL_MAXTRIES
65388+ int "Maximum tries before password lockout"
65389+ default 3
65390+ help
65391+ This option enforces the maximum number of times a user can attempt
65392+ to authorize themselves with the grsecurity RBAC system before being
65393+ denied the ability to attempt authorization again for a specified time.
65394+ The lower the number, the harder it will be to brute-force a password.
65395+
65396+config GRKERNSEC_ACL_TIMEOUT
65397+ int "Time to wait after max password tries, in seconds"
65398+ default 30
65399+ help
65400+ This option specifies the time the user must wait after attempting to
65401+ authorize to the RBAC system with the maximum number of invalid
65402+ passwords. The higher the number, the harder it will be to brute-force
65403+ a password.
65404+
65405+endmenu
65406+menu "Filesystem Protections"
65407+depends on GRKERNSEC
65408+
65409+config GRKERNSEC_PROC
65410+ bool "Proc restrictions"
65411+ default y if GRKERNSEC_CONFIG_AUTO
65412+ help
65413+ If you say Y here, the permissions of the /proc filesystem
65414+ will be altered to enhance system security and privacy. You MUST
65415+ choose either a user only restriction or a user and group restriction.
65416+ Depending upon the option you choose, you can either restrict users to
65417+ see only the processes they themselves run, or choose a group that can
65418+ view all processes and files normally restricted to root if you choose
65419+ the "restrict to user only" option. NOTE: If you're running identd or
65420+ ntpd as a non-root user, you will have to run it as the group you
65421+ specify here.
65422+
65423+config GRKERNSEC_PROC_USER
65424+ bool "Restrict /proc to user only"
65425+ depends on GRKERNSEC_PROC
65426+ help
65427+ If you say Y here, non-root users will only be able to view their own
65428+ processes, and restricts them from viewing network-related information,
65429+ and viewing kernel symbol and module information.
65430+
65431+config GRKERNSEC_PROC_USERGROUP
65432+ bool "Allow special group"
65433+ default y if GRKERNSEC_CONFIG_AUTO
65434+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
65435+ help
65436+ If you say Y here, you will be able to select a group that will be
65437+ able to view all processes and network-related information. If you've
65438+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
65439+ remain hidden. This option is useful if you want to run identd as
65440+ a non-root user. The group you select may also be chosen at boot time
65441+ via "grsec_proc_gid=" on the kernel commandline.
65442+
65443+config GRKERNSEC_PROC_GID
65444+ int "GID for special group"
65445+ depends on GRKERNSEC_PROC_USERGROUP
65446+ default 1001
65447+
65448+config GRKERNSEC_PROC_ADD
65449+ bool "Additional restrictions"
65450+ default y if GRKERNSEC_CONFIG_AUTO
65451+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
65452+ help
65453+ If you say Y here, additional restrictions will be placed on
65454+ /proc that keep normal users from viewing device information and
65455+ slabinfo information that could be useful for exploits.
65456+
65457+config GRKERNSEC_LINK
65458+ bool "Linking restrictions"
65459+ default y if GRKERNSEC_CONFIG_AUTO
65460+ help
65461+ If you say Y here, /tmp race exploits will be prevented, since users
65462+ will no longer be able to follow symlinks owned by other users in
65463+ world-writable +t directories (e.g. /tmp), unless the owner of the
65464+ symlink is the owner of the directory. users will also not be
65465+ able to hardlink to files they do not own. If the sysctl option is
65466+ enabled, a sysctl option with name "linking_restrictions" is created.
65467+
65468+config GRKERNSEC_SYMLINKOWN
65469+ bool "Kernel-enforced SymlinksIfOwnerMatch"
65470+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65471+ help
65472+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
65473+ that prevents it from being used as a security feature. As Apache
65474+ verifies the symlink by performing a stat() against the target of
65475+ the symlink before it is followed, an attacker can setup a symlink
65476+ to point to a same-owned file, then replace the symlink with one
65477+ that targets another user's file just after Apache "validates" the
65478+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
65479+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
65480+ will be in place for the group you specify. If the sysctl option
65481+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
65482+ created.
65483+
65484+config GRKERNSEC_SYMLINKOWN_GID
65485+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
65486+ depends on GRKERNSEC_SYMLINKOWN
65487+ default 1006
65488+ help
65489+ Setting this GID determines what group kernel-enforced
65490+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
65491+ is enabled, a sysctl option with name "symlinkown_gid" is created.
65492+
65493+config GRKERNSEC_FIFO
65494+ bool "FIFO restrictions"
65495+ default y if GRKERNSEC_CONFIG_AUTO
65496+ help
65497+ If you say Y here, users will not be able to write to FIFOs they don't
65498+ own in world-writable +t directories (e.g. /tmp), unless the owner of
65499+ the FIFO is the same owner of the directory it's held in. If the sysctl
65500+ option is enabled, a sysctl option with name "fifo_restrictions" is
65501+ created.
65502+
65503+config GRKERNSEC_SYSFS_RESTRICT
65504+ bool "Sysfs/debugfs restriction"
65505+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65506+ depends on SYSFS
65507+ help
65508+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
65509+ any filesystem normally mounted under it (e.g. debugfs) will be
65510+ mostly accessible only by root. These filesystems generally provide access
65511+ to hardware and debug information that isn't appropriate for unprivileged
65512+ users of the system. Sysfs and debugfs have also become a large source
65513+ of new vulnerabilities, ranging from infoleaks to local compromise.
65514+ There has been very little oversight with an eye toward security involved
65515+ in adding new exporters of information to these filesystems, so their
65516+ use is discouraged.
65517+ For reasons of compatibility, a few directories have been whitelisted
65518+ for access by non-root users:
65519+ /sys/fs/selinux
65520+ /sys/fs/fuse
65521+ /sys/devices/system/cpu
65522+
65523+config GRKERNSEC_ROFS
65524+ bool "Runtime read-only mount protection"
65525+ depends on SYSCTL
65526+ help
65527+ If you say Y here, a sysctl option with name "romount_protect" will
65528+ be created. By setting this option to 1 at runtime, filesystems
65529+ will be protected in the following ways:
65530+ * No new writable mounts will be allowed
65531+ * Existing read-only mounts won't be able to be remounted read/write
65532+ * Write operations will be denied on all block devices
65533+ This option acts independently of grsec_lock: once it is set to 1,
65534+ it cannot be turned off. Therefore, please be mindful of the resulting
65535+ behavior if this option is enabled in an init script on a read-only
65536+ filesystem.
65537+ Also be aware that as with other root-focused features, GRKERNSEC_KMEM
65538+ and GRKERNSEC_IO should be enabled and module loading disabled via
65539+ config or at runtime.
65540+ This feature is mainly intended for secure embedded systems.
65541+
65542+
65543+config GRKERNSEC_DEVICE_SIDECHANNEL
65544+ bool "Eliminate stat/notify-based device sidechannels"
65545+ default y if GRKERNSEC_CONFIG_AUTO
65546+ help
65547+ If you say Y here, timing analyses on block or character
65548+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
65549+ will be thwarted for unprivileged users. If a process without
65550+ CAP_MKNOD stats such a device, the last access and last modify times
65551+ will match the device's create time. No access or modify events
65552+ will be triggered through inotify/dnotify/fanotify for such devices.
65553+ This feature will prevent attacks that may at a minimum
65554+ allow an attacker to determine the administrator's password length.
65555+
65556+config GRKERNSEC_CHROOT
65557+ bool "Chroot jail restrictions"
65558+ default y if GRKERNSEC_CONFIG_AUTO
65559+ help
65560+ If you say Y here, you will be able to choose several options that will
65561+ make breaking out of a chrooted jail much more difficult. If you
65562+ encounter no software incompatibilities with the following options, it
65563+ is recommended that you enable each one.
65564+
65565+ Note that the chroot restrictions are not intended to apply to "chroots"
65566+ to directories that are simple bind mounts of the global root filesystem.
65567+ For several other reasons, a user shouldn't expect any significant
65568+ security by performing such a chroot.
65569+
65570+config GRKERNSEC_CHROOT_MOUNT
65571+ bool "Deny mounts"
65572+ default y if GRKERNSEC_CONFIG_AUTO
65573+ depends on GRKERNSEC_CHROOT
65574+ help
65575+ If you say Y here, processes inside a chroot will not be able to
65576+ mount or remount filesystems. If the sysctl option is enabled, a
65577+ sysctl option with name "chroot_deny_mount" is created.
65578+
65579+config GRKERNSEC_CHROOT_DOUBLE
65580+ bool "Deny double-chroots"
65581+ default y if GRKERNSEC_CONFIG_AUTO
65582+ depends on GRKERNSEC_CHROOT
65583+ help
65584+ If you say Y here, processes inside a chroot will not be able to chroot
65585+ again outside the chroot. This is a widely used method of breaking
65586+ out of a chroot jail and should not be allowed. If the sysctl
65587+ option is enabled, a sysctl option with name
65588+ "chroot_deny_chroot" is created.
65589+
65590+config GRKERNSEC_CHROOT_PIVOT
65591+ bool "Deny pivot_root in chroot"
65592+ default y if GRKERNSEC_CONFIG_AUTO
65593+ depends on GRKERNSEC_CHROOT
65594+ help
65595+ If you say Y here, processes inside a chroot will not be able to use
65596+ a function called pivot_root() that was introduced in Linux 2.3.41. It
65597+ works similar to chroot in that it changes the root filesystem. This
65598+ function could be misused in a chrooted process to attempt to break out
65599+ of the chroot, and therefore should not be allowed. If the sysctl
65600+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
65601+ created.
65602+
65603+config GRKERNSEC_CHROOT_CHDIR
65604+ bool "Enforce chdir(\"/\") on all chroots"
65605+ default y if GRKERNSEC_CONFIG_AUTO
65606+ depends on GRKERNSEC_CHROOT
65607+ help
65608+ If you say Y here, the current working directory of all newly-chrooted
65609+ applications will be set to the the root directory of the chroot.
65610+ The man page on chroot(2) states:
65611+ Note that this call does not change the current working
65612+ directory, so that `.' can be outside the tree rooted at
65613+ `/'. In particular, the super-user can escape from a
65614+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
65615+
65616+ It is recommended that you say Y here, since it's not known to break
65617+ any software. If the sysctl option is enabled, a sysctl option with
65618+ name "chroot_enforce_chdir" is created.
65619+
65620+config GRKERNSEC_CHROOT_CHMOD
65621+ bool "Deny (f)chmod +s"
65622+ default y if GRKERNSEC_CONFIG_AUTO
65623+ depends on GRKERNSEC_CHROOT
65624+ help
65625+ If you say Y here, processes inside a chroot will not be able to chmod
65626+ or fchmod files to make them have suid or sgid bits. This protects
65627+ against another published method of breaking a chroot. If the sysctl
65628+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
65629+ created.
65630+
65631+config GRKERNSEC_CHROOT_FCHDIR
65632+ bool "Deny fchdir out of chroot"
65633+ default y if GRKERNSEC_CONFIG_AUTO
65634+ depends on GRKERNSEC_CHROOT
65635+ help
65636+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
65637+ to a file descriptor of the chrooting process that points to a directory
65638+ outside the filesystem will be stopped. If the sysctl option
65639+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
65640+
65641+config GRKERNSEC_CHROOT_MKNOD
65642+ bool "Deny mknod"
65643+ default y if GRKERNSEC_CONFIG_AUTO
65644+ depends on GRKERNSEC_CHROOT
65645+ help
65646+ If you say Y here, processes inside a chroot will not be allowed to
65647+ mknod. The problem with using mknod inside a chroot is that it
65648+ would allow an attacker to create a device entry that is the same
65649+ as one on the physical root of your system, which could range from
65650+ anything from the console device to a device for your harddrive (which
65651+ they could then use to wipe the drive or steal data). It is recommended
65652+ that you say Y here, unless you run into software incompatibilities.
65653+ If the sysctl option is enabled, a sysctl option with name
65654+ "chroot_deny_mknod" is created.
65655+
65656+config GRKERNSEC_CHROOT_SHMAT
65657+ bool "Deny shmat() out of chroot"
65658+ default y if GRKERNSEC_CONFIG_AUTO
65659+ depends on GRKERNSEC_CHROOT
65660+ help
65661+ If you say Y here, processes inside a chroot will not be able to attach
65662+ to shared memory segments that were created outside of the chroot jail.
65663+ It is recommended that you say Y here. If the sysctl option is enabled,
65664+ a sysctl option with name "chroot_deny_shmat" is created.
65665+
65666+config GRKERNSEC_CHROOT_UNIX
65667+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
65668+ default y if GRKERNSEC_CONFIG_AUTO
65669+ depends on GRKERNSEC_CHROOT
65670+ help
65671+ If you say Y here, processes inside a chroot will not be able to
65672+ connect to abstract (meaning not belonging to a filesystem) Unix
65673+ domain sockets that were bound outside of a chroot. It is recommended
65674+ that you say Y here. If the sysctl option is enabled, a sysctl option
65675+ with name "chroot_deny_unix" is created.
65676+
65677+config GRKERNSEC_CHROOT_FINDTASK
65678+ bool "Protect outside processes"
65679+ default y if GRKERNSEC_CONFIG_AUTO
65680+ depends on GRKERNSEC_CHROOT
65681+ help
65682+ If you say Y here, processes inside a chroot will not be able to
65683+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
65684+ getsid, or view any process outside of the chroot. If the sysctl
65685+ option is enabled, a sysctl option with name "chroot_findtask" is
65686+ created.
65687+
65688+config GRKERNSEC_CHROOT_NICE
65689+ bool "Restrict priority changes"
65690+ default y if GRKERNSEC_CONFIG_AUTO
65691+ depends on GRKERNSEC_CHROOT
65692+ help
65693+ If you say Y here, processes inside a chroot will not be able to raise
65694+ the priority of processes in the chroot, or alter the priority of
65695+ processes outside the chroot. This provides more security than simply
65696+ removing CAP_SYS_NICE from the process' capability set. If the
65697+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
65698+ is created.
65699+
65700+config GRKERNSEC_CHROOT_SYSCTL
65701+ bool "Deny sysctl writes"
65702+ default y if GRKERNSEC_CONFIG_AUTO
65703+ depends on GRKERNSEC_CHROOT
65704+ help
65705+ If you say Y here, an attacker in a chroot will not be able to
65706+ write to sysctl entries, either by sysctl(2) or through a /proc
65707+ interface. It is strongly recommended that you say Y here. If the
65708+ sysctl option is enabled, a sysctl option with name
65709+ "chroot_deny_sysctl" is created.
65710+
65711+config GRKERNSEC_CHROOT_CAPS
65712+ bool "Capability restrictions"
65713+ default y if GRKERNSEC_CONFIG_AUTO
65714+ depends on GRKERNSEC_CHROOT
65715+ help
65716+ If you say Y here, the capabilities on all processes within a
65717+ chroot jail will be lowered to stop module insertion, raw i/o,
65718+ system and net admin tasks, rebooting the system, modifying immutable
65719+ files, modifying IPC owned by another, and changing the system time.
65720+ This is left an option because it can break some apps. Disable this
65721+ if your chrooted apps are having problems performing those kinds of
65722+ tasks. If the sysctl option is enabled, a sysctl option with
65723+ name "chroot_caps" is created.
65724+
65725+config GRKERNSEC_CHROOT_INITRD
65726+ bool "Exempt initrd tasks from restrictions"
65727+ default y if GRKERNSEC_CONFIG_AUTO
65728+ depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
65729+ help
65730+ If you say Y here, tasks started prior to init will be exempted from
65731+ grsecurity's chroot restrictions. This option is mainly meant to
65732+ resolve Plymouth's performing privileged operations unnecessarily
65733+ in a chroot.
65734+
65735+endmenu
65736+menu "Kernel Auditing"
65737+depends on GRKERNSEC
65738+
65739+config GRKERNSEC_AUDIT_GROUP
65740+ bool "Single group for auditing"
65741+ help
65742+ If you say Y here, the exec and chdir logging features will only operate
65743+ on a group you specify. This option is recommended if you only want to
65744+ watch certain users instead of having a large amount of logs from the
65745+ entire system. If the sysctl option is enabled, a sysctl option with
65746+ name "audit_group" is created.
65747+
65748+config GRKERNSEC_AUDIT_GID
65749+ int "GID for auditing"
65750+ depends on GRKERNSEC_AUDIT_GROUP
65751+ default 1007
65752+
65753+config GRKERNSEC_EXECLOG
65754+ bool "Exec logging"
65755+ help
65756+ If you say Y here, all execve() calls will be logged (since the
65757+ other exec*() calls are frontends to execve(), all execution
65758+ will be logged). Useful for shell-servers that like to keep track
65759+ of their users. If the sysctl option is enabled, a sysctl option with
65760+ name "exec_logging" is created.
65761+ WARNING: This option when enabled will produce a LOT of logs, especially
65762+ on an active system.
65763+
65764+config GRKERNSEC_RESLOG
65765+ bool "Resource logging"
65766+ default y if GRKERNSEC_CONFIG_AUTO
65767+ help
65768+ If you say Y here, all attempts to overstep resource limits will
65769+ be logged with the resource name, the requested size, and the current
65770+ limit. It is highly recommended that you say Y here. If the sysctl
65771+ option is enabled, a sysctl option with name "resource_logging" is
65772+ created. If the RBAC system is enabled, the sysctl value is ignored.
65773+
65774+config GRKERNSEC_CHROOT_EXECLOG
65775+ bool "Log execs within chroot"
65776+ help
65777+ If you say Y here, all executions inside a chroot jail will be logged
65778+ to syslog. This can cause a large amount of logs if certain
65779+ applications (eg. djb's daemontools) are installed on the system, and
65780+ is therefore left as an option. If the sysctl option is enabled, a
65781+ sysctl option with name "chroot_execlog" is created.
65782+
65783+config GRKERNSEC_AUDIT_PTRACE
65784+ bool "Ptrace logging"
65785+ help
65786+ If you say Y here, all attempts to attach to a process via ptrace
65787+ will be logged. If the sysctl option is enabled, a sysctl option
65788+ with name "audit_ptrace" is created.
65789+
65790+config GRKERNSEC_AUDIT_CHDIR
65791+ bool "Chdir logging"
65792+ help
65793+ If you say Y here, all chdir() calls will be logged. If the sysctl
65794+ option is enabled, a sysctl option with name "audit_chdir" is created.
65795+
65796+config GRKERNSEC_AUDIT_MOUNT
65797+ bool "(Un)Mount logging"
65798+ help
65799+ If you say Y here, all mounts and unmounts will be logged. If the
65800+ sysctl option is enabled, a sysctl option with name "audit_mount" is
65801+ created.
65802+
65803+config GRKERNSEC_SIGNAL
65804+ bool "Signal logging"
65805+ default y if GRKERNSEC_CONFIG_AUTO
65806+ help
65807+ If you say Y here, certain important signals will be logged, such as
65808+ SIGSEGV, which will as a result inform you of when a error in a program
65809+ occurred, which in some cases could mean a possible exploit attempt.
65810+ If the sysctl option is enabled, a sysctl option with name
65811+ "signal_logging" is created.
65812+
65813+config GRKERNSEC_FORKFAIL
65814+ bool "Fork failure logging"
65815+ help
65816+ If you say Y here, all failed fork() attempts will be logged.
65817+ This could suggest a fork bomb, or someone attempting to overstep
65818+ their process limit. If the sysctl option is enabled, a sysctl option
65819+ with name "forkfail_logging" is created.
65820+
65821+config GRKERNSEC_TIME
65822+ bool "Time change logging"
65823+ default y if GRKERNSEC_CONFIG_AUTO
65824+ help
65825+ If you say Y here, any changes of the system clock will be logged.
65826+ If the sysctl option is enabled, a sysctl option with name
65827+ "timechange_logging" is created.
65828+
65829+config GRKERNSEC_PROC_IPADDR
65830+ bool "/proc/<pid>/ipaddr support"
65831+ default y if GRKERNSEC_CONFIG_AUTO
65832+ help
65833+ If you say Y here, a new entry will be added to each /proc/<pid>
65834+ directory that contains the IP address of the person using the task.
65835+ The IP is carried across local TCP and AF_UNIX stream sockets.
65836+ This information can be useful for IDS/IPSes to perform remote response
65837+ to a local attack. The entry is readable by only the owner of the
65838+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
65839+ the RBAC system), and thus does not create privacy concerns.
65840+
65841+config GRKERNSEC_RWXMAP_LOG
65842+ bool 'Denied RWX mmap/mprotect logging'
65843+ default y if GRKERNSEC_CONFIG_AUTO
65844+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
65845+ help
65846+ If you say Y here, calls to mmap() and mprotect() with explicit
65847+ usage of PROT_WRITE and PROT_EXEC together will be logged when
65848+ denied by the PAX_MPROTECT feature. This feature will also
65849+ log other problematic scenarios that can occur when PAX_MPROTECT
65850+ is enabled on a binary, like textrels and PT_GNU_STACK. If the
65851+ sysctl option is enabled, a sysctl option with name "rwxmap_logging"
65852+ is created.
65853+
65854+endmenu
65855+
65856+menu "Executable Protections"
65857+depends on GRKERNSEC
65858+
65859+config GRKERNSEC_DMESG
65860+ bool "Dmesg(8) restriction"
65861+ default y if GRKERNSEC_CONFIG_AUTO
65862+ help
65863+ If you say Y here, non-root users will not be able to use dmesg(8)
65864+ to view the contents of the kernel's circular log buffer.
65865+ The kernel's log buffer often contains kernel addresses and other
65866+ identifying information useful to an attacker in fingerprinting a
65867+ system for a targeted exploit.
65868+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
65869+ created.
65870+
65871+config GRKERNSEC_HARDEN_PTRACE
65872+ bool "Deter ptrace-based process snooping"
65873+ default y if GRKERNSEC_CONFIG_AUTO
65874+ help
65875+ If you say Y here, TTY sniffers and other malicious monitoring
65876+ programs implemented through ptrace will be defeated. If you
65877+ have been using the RBAC system, this option has already been
65878+ enabled for several years for all users, with the ability to make
65879+ fine-grained exceptions.
65880+
65881+ This option only affects the ability of non-root users to ptrace
65882+ processes that are not a descendent of the ptracing process.
65883+ This means that strace ./binary and gdb ./binary will still work,
65884+ but attaching to arbitrary processes will not. If the sysctl
65885+ option is enabled, a sysctl option with name "harden_ptrace" is
65886+ created.
65887+
65888+config GRKERNSEC_PTRACE_READEXEC
65889+ bool "Require read access to ptrace sensitive binaries"
65890+ default y if GRKERNSEC_CONFIG_AUTO
65891+ help
65892+ If you say Y here, unprivileged users will not be able to ptrace unreadable
65893+ binaries. This option is useful in environments that
65894+ remove the read bits (e.g. file mode 4711) from suid binaries to
65895+ prevent infoleaking of their contents. This option adds
65896+ consistency to the use of that file mode, as the binary could normally
65897+ be read out when run without privileges while ptracing.
65898+
65899+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65900+ is created.
65901+
65902+config GRKERNSEC_SETXID
65903+ bool "Enforce consistent multithreaded privileges"
65904+ default y if GRKERNSEC_CONFIG_AUTO
65905+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65906+ help
65907+ If you say Y here, a change from a root uid to a non-root uid
65908+ in a multithreaded application will cause the resulting uids,
65909+ gids, supplementary groups, and capabilities in that thread
65910+ to be propagated to the other threads of the process. In most
65911+ cases this is unnecessary, as glibc will emulate this behavior
65912+ on behalf of the application. Other libcs do not act in the
65913+ same way, allowing the other threads of the process to continue
65914+ running with root privileges. If the sysctl option is enabled,
65915+ a sysctl option with name "consistent_setxid" is created.
65916+
65917+config GRKERNSEC_HARDEN_IPC
65918+ bool "Disallow access to overly-permissive IPC objects"
65919+ default y if GRKERNSEC_CONFIG_AUTO
65920+ depends on SYSVIPC
65921+ help
65922+ If you say Y here, access to overly-permissive IPC objects (shared
65923+ memory, message queues, and semaphores) will be denied for processes
65924+ given the following criteria beyond normal permission checks:
65925+ 1) If the IPC object is world-accessible and the euid doesn't match
65926+ that of the creator or current uid for the IPC object
65927+ 2) If the IPC object is group-accessible and the egid doesn't
65928+ match that of the creator or current gid for the IPC object
65929+ It's a common error to grant too much permission to these objects,
65930+ with impact ranging from denial of service and information leaking to
65931+ privilege escalation. This feature was developed in response to
65932+ research by Tim Brown:
65933+ http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65934+ who found hundreds of such insecure usages. Processes with
65935+ CAP_IPC_OWNER are still permitted to access these IPC objects.
65936+ If the sysctl option is enabled, a sysctl option with name
65937+ "harden_ipc" is created.
65938+
65939+config GRKERNSEC_TPE
65940+ bool "Trusted Path Execution (TPE)"
65941+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65942+ help
65943+ If you say Y here, you will be able to choose a gid to add to the
65944+ supplementary groups of users you want to mark as "untrusted."
65945+ These users will not be able to execute any files that are not in
65946+ root-owned directories writable only by root. If the sysctl option
65947+ is enabled, a sysctl option with name "tpe" is created.
65948+
65949+config GRKERNSEC_TPE_ALL
65950+ bool "Partially restrict all non-root users"
65951+ depends on GRKERNSEC_TPE
65952+ help
65953+ If you say Y here, all non-root users will be covered under
65954+ a weaker TPE restriction. This is separate from, and in addition to,
65955+ the main TPE options that you have selected elsewhere. Thus, if a
65956+ "trusted" GID is chosen, this restriction applies to even that GID.
65957+ Under this restriction, all non-root users will only be allowed to
65958+ execute files in directories they own that are not group or
65959+ world-writable, or in directories owned by root and writable only by
65960+ root. If the sysctl option is enabled, a sysctl option with name
65961+ "tpe_restrict_all" is created.
65962+
65963+config GRKERNSEC_TPE_INVERT
65964+ bool "Invert GID option"
65965+ depends on GRKERNSEC_TPE
65966+ help
65967+ If you say Y here, the group you specify in the TPE configuration will
65968+ decide what group TPE restrictions will be *disabled* for. This
65969+ option is useful if you want TPE restrictions to be applied to most
65970+ users on the system. If the sysctl option is enabled, a sysctl option
65971+ with name "tpe_invert" is created. Unlike other sysctl options, this
65972+ entry will default to on for backward-compatibility.
65973+
65974+config GRKERNSEC_TPE_GID
65975+ int
65976+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65977+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65978+
65979+config GRKERNSEC_TPE_UNTRUSTED_GID
65980+ int "GID for TPE-untrusted users"
65981+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65982+ default 1005
65983+ help
65984+ Setting this GID determines what group TPE restrictions will be
65985+ *enabled* for. If the sysctl option is enabled, a sysctl option
65986+ with name "tpe_gid" is created.
65987+
65988+config GRKERNSEC_TPE_TRUSTED_GID
65989+ int "GID for TPE-trusted users"
65990+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65991+ default 1005
65992+ help
65993+ Setting this GID determines what group TPE restrictions will be
65994+ *disabled* for. If the sysctl option is enabled, a sysctl option
65995+ with name "tpe_gid" is created.
65996+
65997+endmenu
65998+menu "Network Protections"
65999+depends on GRKERNSEC
66000+
66001+config GRKERNSEC_RANDNET
66002+ bool "Larger entropy pools"
66003+ default y if GRKERNSEC_CONFIG_AUTO
66004+ help
66005+ If you say Y here, the entropy pools used for many features of Linux
66006+ and grsecurity will be doubled in size. Since several grsecurity
66007+ features use additional randomness, it is recommended that you say Y
66008+ here. Saying Y here has a similar effect as modifying
66009+ /proc/sys/kernel/random/poolsize.
66010+
66011+config GRKERNSEC_BLACKHOLE
66012+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66013+ default y if GRKERNSEC_CONFIG_AUTO
66014+ depends on NET
66015+ help
66016+ If you say Y here, neither TCP resets nor ICMP
66017+ destination-unreachable packets will be sent in response to packets
66018+ sent to ports for which no associated listening process exists.
66019+ This feature supports both IPV4 and IPV6 and exempts the
66020+ loopback interface from blackholing. Enabling this feature
66021+ makes a host more resilient to DoS attacks and reduces network
66022+ visibility against scanners.
66023+
66024+ The blackhole feature as-implemented is equivalent to the FreeBSD
66025+ blackhole feature, as it prevents RST responses to all packets, not
66026+ just SYNs. Under most application behavior this causes no
66027+ problems, but applications (like haproxy) may not close certain
66028+ connections in a way that cleanly terminates them on the remote
66029+ end, leaving the remote host in LAST_ACK state. Because of this
66030+ side-effect and to prevent intentional LAST_ACK DoSes, this
66031+ feature also adds automatic mitigation against such attacks.
66032+ The mitigation drastically reduces the amount of time a socket
66033+ can spend in LAST_ACK state. If you're using haproxy and not
66034+ all servers it connects to have this option enabled, consider
66035+ disabling this feature on the haproxy host.
66036+
66037+ If the sysctl option is enabled, two sysctl options with names
66038+ "ip_blackhole" and "lastack_retries" will be created.
66039+ While "ip_blackhole" takes the standard zero/non-zero on/off
66040+ toggle, "lastack_retries" uses the same kinds of values as
66041+ "tcp_retries1" and "tcp_retries2". The default value of 4
66042+ prevents a socket from lasting more than 45 seconds in LAST_ACK
66043+ state.
66044+
66045+config GRKERNSEC_NO_SIMULT_CONNECT
66046+ bool "Disable TCP Simultaneous Connect"
66047+ default y if GRKERNSEC_CONFIG_AUTO
66048+ depends on NET
66049+ help
66050+ If you say Y here, a feature by Willy Tarreau will be enabled that
66051+ removes a weakness in Linux's strict implementation of TCP that
66052+ allows two clients to connect to each other without either entering
66053+ a listening state. The weakness allows an attacker to easily prevent
66054+ a client from connecting to a known server provided the source port
66055+ for the connection is guessed correctly.
66056+
66057+ As the weakness could be used to prevent an antivirus or IPS from
66058+ fetching updates, or prevent an SSL gateway from fetching a CRL,
66059+ it should be eliminated by enabling this option. Though Linux is
66060+ one of few operating systems supporting simultaneous connect, it
66061+ has no legitimate use in practice and is rarely supported by firewalls.
66062+
66063+config GRKERNSEC_SOCKET
66064+ bool "Socket restrictions"
66065+ depends on NET
66066+ help
66067+ If you say Y here, you will be able to choose from several options.
66068+ If you assign a GID on your system and add it to the supplementary
66069+ groups of users you want to restrict socket access to, this patch
66070+ will perform up to three things, based on the option(s) you choose.
66071+
66072+config GRKERNSEC_SOCKET_ALL
66073+ bool "Deny any sockets to group"
66074+ depends on GRKERNSEC_SOCKET
66075+ help
66076+ If you say Y here, you will be able to choose a GID of whose users will
66077+ be unable to connect to other hosts from your machine or run server
66078+ applications from your machine. If the sysctl option is enabled, a
66079+ sysctl option with name "socket_all" is created.
66080+
66081+config GRKERNSEC_SOCKET_ALL_GID
66082+ int "GID to deny all sockets for"
66083+ depends on GRKERNSEC_SOCKET_ALL
66084+ default 1004
66085+ help
66086+ Here you can choose the GID to disable socket access for. Remember to
66087+ add the users you want socket access disabled for to the GID
66088+ specified here. If the sysctl option is enabled, a sysctl option
66089+ with name "socket_all_gid" is created.
66090+
66091+config GRKERNSEC_SOCKET_CLIENT
66092+ bool "Deny client sockets to group"
66093+ depends on GRKERNSEC_SOCKET
66094+ help
66095+ If you say Y here, you will be able to choose a GID of whose users will
66096+ be unable to connect to other hosts from your machine, but will be
66097+ able to run servers. If this option is enabled, all users in the group
66098+ you specify will have to use passive mode when initiating ftp transfers
66099+ from the shell on your machine. If the sysctl option is enabled, a
66100+ sysctl option with name "socket_client" is created.
66101+
66102+config GRKERNSEC_SOCKET_CLIENT_GID
66103+ int "GID to deny client sockets for"
66104+ depends on GRKERNSEC_SOCKET_CLIENT
66105+ default 1003
66106+ help
66107+ Here you can choose the GID to disable client socket access for.
66108+ Remember to add the users you want client socket access disabled for to
66109+ the GID specified here. If the sysctl option is enabled, a sysctl
66110+ option with name "socket_client_gid" is created.
66111+
66112+config GRKERNSEC_SOCKET_SERVER
66113+ bool "Deny server sockets to group"
66114+ depends on GRKERNSEC_SOCKET
66115+ help
66116+ If you say Y here, you will be able to choose a GID of whose users will
66117+ be unable to run server applications from your machine. If the sysctl
66118+ option is enabled, a sysctl option with name "socket_server" is created.
66119+
66120+config GRKERNSEC_SOCKET_SERVER_GID
66121+ int "GID to deny server sockets for"
66122+ depends on GRKERNSEC_SOCKET_SERVER
66123+ default 1002
66124+ help
66125+ Here you can choose the GID to disable server socket access for.
66126+ Remember to add the users you want server socket access disabled for to
66127+ the GID specified here. If the sysctl option is enabled, a sysctl
66128+ option with name "socket_server_gid" is created.
66129+
66130+endmenu
66131+
66132+menu "Physical Protections"
66133+depends on GRKERNSEC
66134+
66135+config GRKERNSEC_DENYUSB
66136+ bool "Deny new USB connections after toggle"
66137+ default y if GRKERNSEC_CONFIG_AUTO
66138+ depends on SYSCTL && USB_SUPPORT
66139+ help
66140+ If you say Y here, a new sysctl option with name "deny_new_usb"
66141+ will be created. Setting its value to 1 will prevent any new
66142+ USB devices from being recognized by the OS. Any attempted USB
66143+ device insertion will be logged. This option is intended to be
66144+ used against custom USB devices designed to exploit vulnerabilities
66145+ in various USB device drivers.
66146+
66147+ For greatest effectiveness, this sysctl should be set after any
66148+ relevant init scripts. This option is safe to enable in distros
66149+ as each user can choose whether or not to toggle the sysctl.
66150+
66151+config GRKERNSEC_DENYUSB_FORCE
66152+ bool "Reject all USB devices not connected at boot"
66153+ select USB
66154+ depends on GRKERNSEC_DENYUSB
66155+ help
66156+ If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66157+ that doesn't involve a sysctl entry. This option should only be
66158+ enabled if you're sure you want to deny all new USB connections
66159+ at runtime and don't want to modify init scripts. This should not
66160+ be enabled by distros. It forces the core USB code to be built
66161+ into the kernel image so that all devices connected at boot time
66162+ can be recognized and new USB device connections can be prevented
66163+ prior to init running.
66164+
66165+endmenu
66166+
66167+menu "Sysctl Support"
66168+depends on GRKERNSEC && SYSCTL
66169+
66170+config GRKERNSEC_SYSCTL
66171+ bool "Sysctl support"
66172+ default y if GRKERNSEC_CONFIG_AUTO
66173+ help
66174+ If you say Y here, you will be able to change the options that
66175+ grsecurity runs with at bootup, without having to recompile your
66176+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66177+ to enable (1) or disable (0) various features. All the sysctl entries
66178+ are mutable until the "grsec_lock" entry is set to a non-zero value.
66179+ All features enabled in the kernel configuration are disabled at boot
66180+ if you do not say Y to the "Turn on features by default" option.
66181+ All options should be set at startup, and the grsec_lock entry should
66182+ be set to a non-zero value after all the options are set.
66183+ *THIS IS EXTREMELY IMPORTANT*
66184+
66185+config GRKERNSEC_SYSCTL_DISTRO
66186+ bool "Extra sysctl support for distro makers (READ HELP)"
66187+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66188+ help
66189+ If you say Y here, additional sysctl options will be created
66190+ for features that affect processes running as root. Therefore,
66191+ it is critical when using this option that the grsec_lock entry be
66192+ enabled after boot. Only distros with prebuilt kernel packages
66193+ with this option enabled that can ensure grsec_lock is enabled
66194+ after boot should use this option.
66195+ *Failure to set grsec_lock after boot makes all grsec features
66196+ this option covers useless*
66197+
66198+ Currently this option creates the following sysctl entries:
66199+ "Disable Privileged I/O": "disable_priv_io"
66200+
66201+config GRKERNSEC_SYSCTL_ON
66202+ bool "Turn on features by default"
66203+ default y if GRKERNSEC_CONFIG_AUTO
66204+ depends on GRKERNSEC_SYSCTL
66205+ help
66206+ If you say Y here, instead of having all features enabled in the
66207+ kernel configuration disabled at boot time, the features will be
66208+ enabled at boot time. It is recommended you say Y here unless
66209+ there is some reason you would want all sysctl-tunable features to
66210+ be disabled by default. As mentioned elsewhere, it is important
66211+ to enable the grsec_lock entry once you have finished modifying
66212+ the sysctl entries.
66213+
66214+endmenu
66215+menu "Logging Options"
66216+depends on GRKERNSEC
66217+
66218+config GRKERNSEC_FLOODTIME
66219+ int "Seconds in between log messages (minimum)"
66220+ default 10
66221+ help
66222+ This option allows you to enforce the number of seconds between
66223+ grsecurity log messages. The default should be suitable for most
66224+ people, however, if you choose to change it, choose a value small enough
66225+ to allow informative logs to be produced, but large enough to
66226+ prevent flooding.
66227+
66228+ Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66229+ any rate limiting on grsecurity log messages.
66230+
66231+config GRKERNSEC_FLOODBURST
66232+ int "Number of messages in a burst (maximum)"
66233+ default 6
66234+ help
66235+ This option allows you to choose the maximum number of messages allowed
66236+ within the flood time interval you chose in a separate option. The
66237+ default should be suitable for most people, however if you find that
66238+ many of your logs are being interpreted as flooding, you may want to
66239+ raise this value.
66240+
66241+ Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66242+ any rate limiting on grsecurity log messages.
66243+
66244+endmenu
66245diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66246new file mode 100644
66247index 0000000..5307c8a
66248--- /dev/null
66249+++ b/grsecurity/Makefile
66250@@ -0,0 +1,54 @@
66251+# grsecurity – access control and security hardening for Linux
66252+# All code in this directory and various hooks located throughout the Linux kernel are
66253+# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66254+# http://www.grsecurity.net spender@grsecurity.net
66255+#
66256+# This program is free software; you can redistribute it and/or
66257+# modify it under the terms of the GNU General Public License version 2
66258+# as published by the Free Software Foundation.
66259+#
66260+# This program is distributed in the hope that it will be useful,
66261+# but WITHOUT ANY WARRANTY; without even the implied warranty of
66262+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66263+# GNU General Public License for more details.
66264+#
66265+# You should have received a copy of the GNU General Public License
66266+# along with this program; if not, write to the Free Software
66267+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66268+
66269+KBUILD_CFLAGS += -Werror
66270+
66271+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66272+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
66273+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66274+ grsec_usb.o grsec_ipc.o
66275+
66276+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66277+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66278+ gracl_learn.o grsec_log.o gracl_policy.o
66279+ifdef CONFIG_COMPAT
66280+obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66281+endif
66282+
66283+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66284+
66285+ifdef CONFIG_NET
66286+obj-y += grsec_sock.o
66287+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66288+endif
66289+
66290+ifndef CONFIG_GRKERNSEC
66291+obj-y += grsec_disabled.o
66292+endif
66293+
66294+ifdef CONFIG_GRKERNSEC_HIDESYM
66295+extra-y := grsec_hidesym.o
66296+$(obj)/grsec_hidesym.o:
66297+ @-chmod -f 500 /boot
66298+ @-chmod -f 500 /lib/modules
66299+ @-chmod -f 500 /lib64/modules
66300+ @-chmod -f 500 /lib32/modules
66301+ @-chmod -f 700 .
66302+ @-chmod -f 700 $(objtree)
66303+ @echo ' grsec: protected kernel image paths'
66304+endif
66305diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66306new file mode 100644
66307index 0000000..e56396f
66308--- /dev/null
66309+++ b/grsecurity/gracl.c
66310@@ -0,0 +1,2679 @@
66311+#include <linux/kernel.h>
66312+#include <linux/module.h>
66313+#include <linux/sched.h>
66314+#include <linux/mm.h>
66315+#include <linux/file.h>
66316+#include <linux/fs.h>
66317+#include <linux/namei.h>
66318+#include <linux/mount.h>
66319+#include <linux/tty.h>
66320+#include <linux/proc_fs.h>
66321+#include <linux/lglock.h>
66322+#include <linux/slab.h>
66323+#include <linux/vmalloc.h>
66324+#include <linux/types.h>
66325+#include <linux/sysctl.h>
66326+#include <linux/netdevice.h>
66327+#include <linux/ptrace.h>
66328+#include <linux/gracl.h>
66329+#include <linux/gralloc.h>
66330+#include <linux/security.h>
66331+#include <linux/grinternal.h>
66332+#include <linux/pid_namespace.h>
66333+#include <linux/stop_machine.h>
66334+#include <linux/fdtable.h>
66335+#include <linux/percpu.h>
66336+#include <linux/lglock.h>
66337+#include <linux/hugetlb.h>
66338+#include <linux/posix-timers.h>
66339+#include <linux/prefetch.h>
66340+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66341+#include <linux/magic.h>
66342+#include <linux/pagemap.h>
66343+#include "../fs/btrfs/async-thread.h"
66344+#include "../fs/btrfs/ctree.h"
66345+#include "../fs/btrfs/btrfs_inode.h"
66346+#endif
66347+#include "../fs/mount.h"
66348+
66349+#include <asm/uaccess.h>
66350+#include <asm/errno.h>
66351+#include <asm/mman.h>
66352+
66353+#define FOR_EACH_ROLE_START(role) \
66354+ role = running_polstate.role_list; \
66355+ while (role) {
66356+
66357+#define FOR_EACH_ROLE_END(role) \
66358+ role = role->prev; \
66359+ }
66360+
66361+extern struct path gr_real_root;
66362+
66363+static struct gr_policy_state running_polstate;
66364+struct gr_policy_state *polstate = &running_polstate;
66365+extern struct gr_alloc_state *current_alloc_state;
66366+
66367+extern char *gr_shared_page[4];
66368+DEFINE_RWLOCK(gr_inode_lock);
66369+
66370+static unsigned int gr_status __read_only = GR_STATUS_INIT;
66371+
66372+#ifdef CONFIG_NET
66373+extern struct vfsmount *sock_mnt;
66374+#endif
66375+
66376+extern struct vfsmount *pipe_mnt;
66377+extern struct vfsmount *shm_mnt;
66378+
66379+#ifdef CONFIG_HUGETLBFS
66380+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
66381+#endif
66382+
66383+extern u16 acl_sp_role_value;
66384+extern struct acl_object_label *fakefs_obj_rw;
66385+extern struct acl_object_label *fakefs_obj_rwx;
66386+
66387+int gr_acl_is_enabled(void)
66388+{
66389+ return (gr_status & GR_READY);
66390+}
66391+
66392+void gr_enable_rbac_system(void)
66393+{
66394+ pax_open_kernel();
66395+ gr_status |= GR_READY;
66396+ pax_close_kernel();
66397+}
66398+
66399+int gr_rbac_disable(void *unused)
66400+{
66401+ pax_open_kernel();
66402+ gr_status &= ~GR_READY;
66403+ pax_close_kernel();
66404+
66405+ return 0;
66406+}
66407+
66408+static inline dev_t __get_dev(const struct dentry *dentry)
66409+{
66410+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66411+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
66412+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
66413+ else
66414+#endif
66415+ return dentry->d_sb->s_dev;
66416+}
66417+
66418+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
66419+{
66420+ return __get_dev(dentry);
66421+}
66422+
66423+static char gr_task_roletype_to_char(struct task_struct *task)
66424+{
66425+ switch (task->role->roletype &
66426+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
66427+ GR_ROLE_SPECIAL)) {
66428+ case GR_ROLE_DEFAULT:
66429+ return 'D';
66430+ case GR_ROLE_USER:
66431+ return 'U';
66432+ case GR_ROLE_GROUP:
66433+ return 'G';
66434+ case GR_ROLE_SPECIAL:
66435+ return 'S';
66436+ }
66437+
66438+ return 'X';
66439+}
66440+
66441+char gr_roletype_to_char(void)
66442+{
66443+ return gr_task_roletype_to_char(current);
66444+}
66445+
66446+__inline__ int
66447+gr_acl_tpe_check(void)
66448+{
66449+ if (unlikely(!(gr_status & GR_READY)))
66450+ return 0;
66451+ if (current->role->roletype & GR_ROLE_TPE)
66452+ return 1;
66453+ else
66454+ return 0;
66455+}
66456+
66457+int
66458+gr_handle_rawio(const struct inode *inode)
66459+{
66460+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66461+ if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
66462+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
66463+ !capable(CAP_SYS_RAWIO))
66464+ return 1;
66465+#endif
66466+ return 0;
66467+}
66468+
66469+int
66470+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
66471+{
66472+ if (likely(lena != lenb))
66473+ return 0;
66474+
66475+ return !memcmp(a, b, lena);
66476+}
66477+
66478+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
66479+{
66480+ *buflen -= namelen;
66481+ if (*buflen < 0)
66482+ return -ENAMETOOLONG;
66483+ *buffer -= namelen;
66484+ memcpy(*buffer, str, namelen);
66485+ return 0;
66486+}
66487+
66488+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
66489+{
66490+ return prepend(buffer, buflen, name->name, name->len);
66491+}
66492+
66493+static int prepend_path(const struct path *path, struct path *root,
66494+ char **buffer, int *buflen)
66495+{
66496+ struct dentry *dentry = path->dentry;
66497+ struct vfsmount *vfsmnt = path->mnt;
66498+ struct mount *mnt = real_mount(vfsmnt);
66499+ bool slash = false;
66500+ int error = 0;
66501+
66502+ while (dentry != root->dentry || vfsmnt != root->mnt) {
66503+ struct dentry * parent;
66504+
66505+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
66506+ /* Global root? */
66507+ if (!mnt_has_parent(mnt)) {
66508+ goto out;
66509+ }
66510+ dentry = mnt->mnt_mountpoint;
66511+ mnt = mnt->mnt_parent;
66512+ vfsmnt = &mnt->mnt;
66513+ continue;
66514+ }
66515+ parent = dentry->d_parent;
66516+ prefetch(parent);
66517+ spin_lock(&dentry->d_lock);
66518+ error = prepend_name(buffer, buflen, &dentry->d_name);
66519+ spin_unlock(&dentry->d_lock);
66520+ if (!error)
66521+ error = prepend(buffer, buflen, "/", 1);
66522+ if (error)
66523+ break;
66524+
66525+ slash = true;
66526+ dentry = parent;
66527+ }
66528+
66529+out:
66530+ if (!error && !slash)
66531+ error = prepend(buffer, buflen, "/", 1);
66532+
66533+ return error;
66534+}
66535+
66536+/* this must be called with mount_lock and rename_lock held */
66537+
66538+static char *__our_d_path(const struct path *path, struct path *root,
66539+ char *buf, int buflen)
66540+{
66541+ char *res = buf + buflen;
66542+ int error;
66543+
66544+ prepend(&res, &buflen, "\0", 1);
66545+ error = prepend_path(path, root, &res, &buflen);
66546+ if (error)
66547+ return ERR_PTR(error);
66548+
66549+ return res;
66550+}
66551+
66552+static char *
66553+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
66554+{
66555+ char *retval;
66556+
66557+ retval = __our_d_path(path, root, buf, buflen);
66558+ if (unlikely(IS_ERR(retval)))
66559+ retval = strcpy(buf, "<path too long>");
66560+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
66561+ retval[1] = '\0';
66562+
66563+ return retval;
66564+}
66565+
66566+static char *
66567+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66568+ char *buf, int buflen)
66569+{
66570+ struct path path;
66571+ char *res;
66572+
66573+ path.dentry = (struct dentry *)dentry;
66574+ path.mnt = (struct vfsmount *)vfsmnt;
66575+
66576+ /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
66577+ by the RBAC system */
66578+ res = gen_full_path(&path, &gr_real_root, buf, buflen);
66579+
66580+ return res;
66581+}
66582+
66583+static char *
66584+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
66585+ char *buf, int buflen)
66586+{
66587+ char *res;
66588+ struct path path;
66589+ struct path root;
66590+ struct task_struct *reaper = init_pid_ns.child_reaper;
66591+
66592+ path.dentry = (struct dentry *)dentry;
66593+ path.mnt = (struct vfsmount *)vfsmnt;
66594+
66595+ /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
66596+ get_fs_root(reaper->fs, &root);
66597+
66598+ read_seqlock_excl(&mount_lock);
66599+ write_seqlock(&rename_lock);
66600+ res = gen_full_path(&path, &root, buf, buflen);
66601+ write_sequnlock(&rename_lock);
66602+ read_sequnlock_excl(&mount_lock);
66603+
66604+ path_put(&root);
66605+ return res;
66606+}
66607+
66608+char *
66609+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66610+{
66611+ char *ret;
66612+ read_seqlock_excl(&mount_lock);
66613+ write_seqlock(&rename_lock);
66614+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66615+ PAGE_SIZE);
66616+ write_sequnlock(&rename_lock);
66617+ read_sequnlock_excl(&mount_lock);
66618+ return ret;
66619+}
66620+
66621+static char *
66622+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
66623+{
66624+ char *ret;
66625+ char *buf;
66626+ int buflen;
66627+
66628+ read_seqlock_excl(&mount_lock);
66629+ write_seqlock(&rename_lock);
66630+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
66631+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
66632+ buflen = (int)(ret - buf);
66633+ if (buflen >= 5)
66634+ prepend(&ret, &buflen, "/proc", 5);
66635+ else
66636+ ret = strcpy(buf, "<path too long>");
66637+ write_sequnlock(&rename_lock);
66638+ read_sequnlock_excl(&mount_lock);
66639+ return ret;
66640+}
66641+
66642+char *
66643+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
66644+{
66645+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
66646+ PAGE_SIZE);
66647+}
66648+
66649+char *
66650+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
66651+{
66652+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
66653+ PAGE_SIZE);
66654+}
66655+
66656+char *
66657+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
66658+{
66659+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
66660+ PAGE_SIZE);
66661+}
66662+
66663+char *
66664+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
66665+{
66666+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
66667+ PAGE_SIZE);
66668+}
66669+
66670+char *
66671+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
66672+{
66673+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
66674+ PAGE_SIZE);
66675+}
66676+
66677+__inline__ __u32
66678+to_gr_audit(const __u32 reqmode)
66679+{
66680+ /* masks off auditable permission flags, then shifts them to create
66681+ auditing flags, and adds the special case of append auditing if
66682+ we're requesting write */
66683+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
66684+}
66685+
66686+struct acl_role_label *
66687+__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
66688+ const gid_t gid)
66689+{
66690+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
66691+ struct acl_role_label *match;
66692+ struct role_allowed_ip *ipp;
66693+ unsigned int x;
66694+ u32 curr_ip = task->signal->saved_ip;
66695+
66696+ match = state->acl_role_set.r_hash[index];
66697+
66698+ while (match) {
66699+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
66700+ for (x = 0; x < match->domain_child_num; x++) {
66701+ if (match->domain_children[x] == uid)
66702+ goto found;
66703+ }
66704+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
66705+ break;
66706+ match = match->next;
66707+ }
66708+found:
66709+ if (match == NULL) {
66710+ try_group:
66711+ index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
66712+ match = state->acl_role_set.r_hash[index];
66713+
66714+ while (match) {
66715+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
66716+ for (x = 0; x < match->domain_child_num; x++) {
66717+ if (match->domain_children[x] == gid)
66718+ goto found2;
66719+ }
66720+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
66721+ break;
66722+ match = match->next;
66723+ }
66724+found2:
66725+ if (match == NULL)
66726+ match = state->default_role;
66727+ if (match->allowed_ips == NULL)
66728+ return match;
66729+ else {
66730+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66731+ if (likely
66732+ ((ntohl(curr_ip) & ipp->netmask) ==
66733+ (ntohl(ipp->addr) & ipp->netmask)))
66734+ return match;
66735+ }
66736+ match = state->default_role;
66737+ }
66738+ } else if (match->allowed_ips == NULL) {
66739+ return match;
66740+ } else {
66741+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
66742+ if (likely
66743+ ((ntohl(curr_ip) & ipp->netmask) ==
66744+ (ntohl(ipp->addr) & ipp->netmask)))
66745+ return match;
66746+ }
66747+ goto try_group;
66748+ }
66749+
66750+ return match;
66751+}
66752+
66753+static struct acl_role_label *
66754+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
66755+ const gid_t gid)
66756+{
66757+ return __lookup_acl_role_label(&running_polstate, task, uid, gid);
66758+}
66759+
66760+struct acl_subject_label *
66761+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
66762+ const struct acl_role_label *role)
66763+{
66764+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66765+ struct acl_subject_label *match;
66766+
66767+ match = role->subj_hash[index];
66768+
66769+ while (match && (match->inode != ino || match->device != dev ||
66770+ (match->mode & GR_DELETED))) {
66771+ match = match->next;
66772+ }
66773+
66774+ if (match && !(match->mode & GR_DELETED))
66775+ return match;
66776+ else
66777+ return NULL;
66778+}
66779+
66780+struct acl_subject_label *
66781+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
66782+ const struct acl_role_label *role)
66783+{
66784+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
66785+ struct acl_subject_label *match;
66786+
66787+ match = role->subj_hash[index];
66788+
66789+ while (match && (match->inode != ino || match->device != dev ||
66790+ !(match->mode & GR_DELETED))) {
66791+ match = match->next;
66792+ }
66793+
66794+ if (match && (match->mode & GR_DELETED))
66795+ return match;
66796+ else
66797+ return NULL;
66798+}
66799+
66800+static struct acl_object_label *
66801+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
66802+ const struct acl_subject_label *subj)
66803+{
66804+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66805+ struct acl_object_label *match;
66806+
66807+ match = subj->obj_hash[index];
66808+
66809+ while (match && (match->inode != ino || match->device != dev ||
66810+ (match->mode & GR_DELETED))) {
66811+ match = match->next;
66812+ }
66813+
66814+ if (match && !(match->mode & GR_DELETED))
66815+ return match;
66816+ else
66817+ return NULL;
66818+}
66819+
66820+static struct acl_object_label *
66821+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
66822+ const struct acl_subject_label *subj)
66823+{
66824+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
66825+ struct acl_object_label *match;
66826+
66827+ match = subj->obj_hash[index];
66828+
66829+ while (match && (match->inode != ino || match->device != dev ||
66830+ !(match->mode & GR_DELETED))) {
66831+ match = match->next;
66832+ }
66833+
66834+ if (match && (match->mode & GR_DELETED))
66835+ return match;
66836+
66837+ match = subj->obj_hash[index];
66838+
66839+ while (match && (match->inode != ino || match->device != dev ||
66840+ (match->mode & GR_DELETED))) {
66841+ match = match->next;
66842+ }
66843+
66844+ if (match && !(match->mode & GR_DELETED))
66845+ return match;
66846+ else
66847+ return NULL;
66848+}
66849+
66850+struct name_entry *
66851+__lookup_name_entry(const struct gr_policy_state *state, const char *name)
66852+{
66853+ unsigned int len = strlen(name);
66854+ unsigned int key = full_name_hash(name, len);
66855+ unsigned int index = key % state->name_set.n_size;
66856+ struct name_entry *match;
66857+
66858+ match = state->name_set.n_hash[index];
66859+
66860+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
66861+ match = match->next;
66862+
66863+ return match;
66864+}
66865+
66866+static struct name_entry *
66867+lookup_name_entry(const char *name)
66868+{
66869+ return __lookup_name_entry(&running_polstate, name);
66870+}
66871+
66872+static struct name_entry *
66873+lookup_name_entry_create(const char *name)
66874+{
66875+ unsigned int len = strlen(name);
66876+ unsigned int key = full_name_hash(name, len);
66877+ unsigned int index = key % running_polstate.name_set.n_size;
66878+ struct name_entry *match;
66879+
66880+ match = running_polstate.name_set.n_hash[index];
66881+
66882+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66883+ !match->deleted))
66884+ match = match->next;
66885+
66886+ if (match && match->deleted)
66887+ return match;
66888+
66889+ match = running_polstate.name_set.n_hash[index];
66890+
66891+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
66892+ match->deleted))
66893+ match = match->next;
66894+
66895+ if (match && !match->deleted)
66896+ return match;
66897+ else
66898+ return NULL;
66899+}
66900+
66901+static struct inodev_entry *
66902+lookup_inodev_entry(const ino_t ino, const dev_t dev)
66903+{
66904+ unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66905+ struct inodev_entry *match;
66906+
66907+ match = running_polstate.inodev_set.i_hash[index];
66908+
66909+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66910+ match = match->next;
66911+
66912+ return match;
66913+}
66914+
66915+void
66916+__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66917+{
66918+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66919+ state->inodev_set.i_size);
66920+ struct inodev_entry **curr;
66921+
66922+ entry->prev = NULL;
66923+
66924+ curr = &state->inodev_set.i_hash[index];
66925+ if (*curr != NULL)
66926+ (*curr)->prev = entry;
66927+
66928+ entry->next = *curr;
66929+ *curr = entry;
66930+
66931+ return;
66932+}
66933+
66934+static void
66935+insert_inodev_entry(struct inodev_entry *entry)
66936+{
66937+ __insert_inodev_entry(&running_polstate, entry);
66938+}
66939+
66940+void
66941+insert_acl_obj_label(struct acl_object_label *obj,
66942+ struct acl_subject_label *subj)
66943+{
66944+ unsigned int index =
66945+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66946+ struct acl_object_label **curr;
66947+
66948+ obj->prev = NULL;
66949+
66950+ curr = &subj->obj_hash[index];
66951+ if (*curr != NULL)
66952+ (*curr)->prev = obj;
66953+
66954+ obj->next = *curr;
66955+ *curr = obj;
66956+
66957+ return;
66958+}
66959+
66960+void
66961+insert_acl_subj_label(struct acl_subject_label *obj,
66962+ struct acl_role_label *role)
66963+{
66964+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66965+ struct acl_subject_label **curr;
66966+
66967+ obj->prev = NULL;
66968+
66969+ curr = &role->subj_hash[index];
66970+ if (*curr != NULL)
66971+ (*curr)->prev = obj;
66972+
66973+ obj->next = *curr;
66974+ *curr = obj;
66975+
66976+ return;
66977+}
66978+
66979+/* derived from glibc fnmatch() 0: match, 1: no match*/
66980+
66981+static int
66982+glob_match(const char *p, const char *n)
66983+{
66984+ char c;
66985+
66986+ while ((c = *p++) != '\0') {
66987+ switch (c) {
66988+ case '?':
66989+ if (*n == '\0')
66990+ return 1;
66991+ else if (*n == '/')
66992+ return 1;
66993+ break;
66994+ case '\\':
66995+ if (*n != c)
66996+ return 1;
66997+ break;
66998+ case '*':
66999+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
67000+ if (*n == '/')
67001+ return 1;
67002+ else if (c == '?') {
67003+ if (*n == '\0')
67004+ return 1;
67005+ else
67006+ ++n;
67007+ }
67008+ }
67009+ if (c == '\0') {
67010+ return 0;
67011+ } else {
67012+ const char *endp;
67013+
67014+ if ((endp = strchr(n, '/')) == NULL)
67015+ endp = n + strlen(n);
67016+
67017+ if (c == '[') {
67018+ for (--p; n < endp; ++n)
67019+ if (!glob_match(p, n))
67020+ return 0;
67021+ } else if (c == '/') {
67022+ while (*n != '\0' && *n != '/')
67023+ ++n;
67024+ if (*n == '/' && !glob_match(p, n + 1))
67025+ return 0;
67026+ } else {
67027+ for (--p; n < endp; ++n)
67028+ if (*n == c && !glob_match(p, n))
67029+ return 0;
67030+ }
67031+
67032+ return 1;
67033+ }
67034+ case '[':
67035+ {
67036+ int not;
67037+ char cold;
67038+
67039+ if (*n == '\0' || *n == '/')
67040+ return 1;
67041+
67042+ not = (*p == '!' || *p == '^');
67043+ if (not)
67044+ ++p;
67045+
67046+ c = *p++;
67047+ for (;;) {
67048+ unsigned char fn = (unsigned char)*n;
67049+
67050+ if (c == '\0')
67051+ return 1;
67052+ else {
67053+ if (c == fn)
67054+ goto matched;
67055+ cold = c;
67056+ c = *p++;
67057+
67058+ if (c == '-' && *p != ']') {
67059+ unsigned char cend = *p++;
67060+
67061+ if (cend == '\0')
67062+ return 1;
67063+
67064+ if (cold <= fn && fn <= cend)
67065+ goto matched;
67066+
67067+ c = *p++;
67068+ }
67069+ }
67070+
67071+ if (c == ']')
67072+ break;
67073+ }
67074+ if (!not)
67075+ return 1;
67076+ break;
67077+ matched:
67078+ while (c != ']') {
67079+ if (c == '\0')
67080+ return 1;
67081+
67082+ c = *p++;
67083+ }
67084+ if (not)
67085+ return 1;
67086+ }
67087+ break;
67088+ default:
67089+ if (c != *n)
67090+ return 1;
67091+ }
67092+
67093+ ++n;
67094+ }
67095+
67096+ if (*n == '\0')
67097+ return 0;
67098+
67099+ if (*n == '/')
67100+ return 0;
67101+
67102+ return 1;
67103+}
67104+
67105+static struct acl_object_label *
67106+chk_glob_label(struct acl_object_label *globbed,
67107+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67108+{
67109+ struct acl_object_label *tmp;
67110+
67111+ if (*path == NULL)
67112+ *path = gr_to_filename_nolock(dentry, mnt);
67113+
67114+ tmp = globbed;
67115+
67116+ while (tmp) {
67117+ if (!glob_match(tmp->filename, *path))
67118+ return tmp;
67119+ tmp = tmp->next;
67120+ }
67121+
67122+ return NULL;
67123+}
67124+
67125+static struct acl_object_label *
67126+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67127+ const ino_t curr_ino, const dev_t curr_dev,
67128+ const struct acl_subject_label *subj, char **path, const int checkglob)
67129+{
67130+ struct acl_subject_label *tmpsubj;
67131+ struct acl_object_label *retval;
67132+ struct acl_object_label *retval2;
67133+
67134+ tmpsubj = (struct acl_subject_label *) subj;
67135+ read_lock(&gr_inode_lock);
67136+ do {
67137+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67138+ if (retval) {
67139+ if (checkglob && retval->globbed) {
67140+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67141+ if (retval2)
67142+ retval = retval2;
67143+ }
67144+ break;
67145+ }
67146+ } while ((tmpsubj = tmpsubj->parent_subject));
67147+ read_unlock(&gr_inode_lock);
67148+
67149+ return retval;
67150+}
67151+
67152+static __inline__ struct acl_object_label *
67153+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67154+ struct dentry *curr_dentry,
67155+ const struct acl_subject_label *subj, char **path, const int checkglob)
67156+{
67157+ int newglob = checkglob;
67158+ ino_t inode;
67159+ dev_t device;
67160+
67161+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67162+ as we don't want a / * rule to match instead of the / object
67163+ don't do this for create lookups that call this function though, since they're looking up
67164+ on the parent and thus need globbing checks on all paths
67165+ */
67166+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67167+ newglob = GR_NO_GLOB;
67168+
67169+ spin_lock(&curr_dentry->d_lock);
67170+ inode = curr_dentry->d_inode->i_ino;
67171+ device = __get_dev(curr_dentry);
67172+ spin_unlock(&curr_dentry->d_lock);
67173+
67174+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67175+}
67176+
67177+#ifdef CONFIG_HUGETLBFS
67178+static inline bool
67179+is_hugetlbfs_mnt(const struct vfsmount *mnt)
67180+{
67181+ int i;
67182+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67183+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67184+ return true;
67185+ }
67186+
67187+ return false;
67188+}
67189+#endif
67190+
67191+static struct acl_object_label *
67192+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67193+ const struct acl_subject_label *subj, char *path, const int checkglob)
67194+{
67195+ struct dentry *dentry = (struct dentry *) l_dentry;
67196+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67197+ struct mount *real_mnt = real_mount(mnt);
67198+ struct acl_object_label *retval;
67199+ struct dentry *parent;
67200+
67201+ read_seqlock_excl(&mount_lock);
67202+ write_seqlock(&rename_lock);
67203+
67204+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67205+#ifdef CONFIG_NET
67206+ mnt == sock_mnt ||
67207+#endif
67208+#ifdef CONFIG_HUGETLBFS
67209+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67210+#endif
67211+ /* ignore Eric Biederman */
67212+ IS_PRIVATE(l_dentry->d_inode))) {
67213+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67214+ goto out;
67215+ }
67216+
67217+ for (;;) {
67218+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67219+ break;
67220+
67221+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67222+ if (!mnt_has_parent(real_mnt))
67223+ break;
67224+
67225+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67226+ if (retval != NULL)
67227+ goto out;
67228+
67229+ dentry = real_mnt->mnt_mountpoint;
67230+ real_mnt = real_mnt->mnt_parent;
67231+ mnt = &real_mnt->mnt;
67232+ continue;
67233+ }
67234+
67235+ parent = dentry->d_parent;
67236+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67237+ if (retval != NULL)
67238+ goto out;
67239+
67240+ dentry = parent;
67241+ }
67242+
67243+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67244+
67245+ /* gr_real_root is pinned so we don't have to hold a reference */
67246+ if (retval == NULL)
67247+ retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67248+out:
67249+ write_sequnlock(&rename_lock);
67250+ read_sequnlock_excl(&mount_lock);
67251+
67252+ BUG_ON(retval == NULL);
67253+
67254+ return retval;
67255+}
67256+
67257+static __inline__ struct acl_object_label *
67258+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67259+ const struct acl_subject_label *subj)
67260+{
67261+ char *path = NULL;
67262+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67263+}
67264+
67265+static __inline__ struct acl_object_label *
67266+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67267+ const struct acl_subject_label *subj)
67268+{
67269+ char *path = NULL;
67270+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67271+}
67272+
67273+static __inline__ struct acl_object_label *
67274+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67275+ const struct acl_subject_label *subj, char *path)
67276+{
67277+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67278+}
67279+
67280+struct acl_subject_label *
67281+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67282+ const struct acl_role_label *role)
67283+{
67284+ struct dentry *dentry = (struct dentry *) l_dentry;
67285+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67286+ struct mount *real_mnt = real_mount(mnt);
67287+ struct acl_subject_label *retval;
67288+ struct dentry *parent;
67289+
67290+ read_seqlock_excl(&mount_lock);
67291+ write_seqlock(&rename_lock);
67292+
67293+ for (;;) {
67294+ if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67295+ break;
67296+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67297+ if (!mnt_has_parent(real_mnt))
67298+ break;
67299+
67300+ spin_lock(&dentry->d_lock);
67301+ read_lock(&gr_inode_lock);
67302+ retval =
67303+ lookup_acl_subj_label(dentry->d_inode->i_ino,
67304+ __get_dev(dentry), role);
67305+ read_unlock(&gr_inode_lock);
67306+ spin_unlock(&dentry->d_lock);
67307+ if (retval != NULL)
67308+ goto out;
67309+
67310+ dentry = real_mnt->mnt_mountpoint;
67311+ real_mnt = real_mnt->mnt_parent;
67312+ mnt = &real_mnt->mnt;
67313+ continue;
67314+ }
67315+
67316+ spin_lock(&dentry->d_lock);
67317+ read_lock(&gr_inode_lock);
67318+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67319+ __get_dev(dentry), role);
67320+ read_unlock(&gr_inode_lock);
67321+ parent = dentry->d_parent;
67322+ spin_unlock(&dentry->d_lock);
67323+
67324+ if (retval != NULL)
67325+ goto out;
67326+
67327+ dentry = parent;
67328+ }
67329+
67330+ spin_lock(&dentry->d_lock);
67331+ read_lock(&gr_inode_lock);
67332+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67333+ __get_dev(dentry), role);
67334+ read_unlock(&gr_inode_lock);
67335+ spin_unlock(&dentry->d_lock);
67336+
67337+ if (unlikely(retval == NULL)) {
67338+ /* gr_real_root is pinned, we don't need to hold a reference */
67339+ read_lock(&gr_inode_lock);
67340+ retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67341+ __get_dev(gr_real_root.dentry), role);
67342+ read_unlock(&gr_inode_lock);
67343+ }
67344+out:
67345+ write_sequnlock(&rename_lock);
67346+ read_sequnlock_excl(&mount_lock);
67347+
67348+ BUG_ON(retval == NULL);
67349+
67350+ return retval;
67351+}
67352+
67353+void
67354+assign_special_role(const char *rolename)
67355+{
67356+ struct acl_object_label *obj;
67357+ struct acl_role_label *r;
67358+ struct acl_role_label *assigned = NULL;
67359+ struct task_struct *tsk;
67360+ struct file *filp;
67361+
67362+ FOR_EACH_ROLE_START(r)
67363+ if (!strcmp(rolename, r->rolename) &&
67364+ (r->roletype & GR_ROLE_SPECIAL)) {
67365+ assigned = r;
67366+ break;
67367+ }
67368+ FOR_EACH_ROLE_END(r)
67369+
67370+ if (!assigned)
67371+ return;
67372+
67373+ read_lock(&tasklist_lock);
67374+ read_lock(&grsec_exec_file_lock);
67375+
67376+ tsk = current->real_parent;
67377+ if (tsk == NULL)
67378+ goto out_unlock;
67379+
67380+ filp = tsk->exec_file;
67381+ if (filp == NULL)
67382+ goto out_unlock;
67383+
67384+ tsk->is_writable = 0;
67385+ tsk->inherited = 0;
67386+
67387+ tsk->acl_sp_role = 1;
67388+ tsk->acl_role_id = ++acl_sp_role_value;
67389+ tsk->role = assigned;
67390+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
67391+
67392+ /* ignore additional mmap checks for processes that are writable
67393+ by the default ACL */
67394+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67395+ if (unlikely(obj->mode & GR_WRITE))
67396+ tsk->is_writable = 1;
67397+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
67398+ if (unlikely(obj->mode & GR_WRITE))
67399+ tsk->is_writable = 1;
67400+
67401+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67402+ printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
67403+ tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
67404+#endif
67405+
67406+out_unlock:
67407+ read_unlock(&grsec_exec_file_lock);
67408+ read_unlock(&tasklist_lock);
67409+ return;
67410+}
67411+
67412+
67413+static void
67414+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
67415+{
67416+ struct task_struct *task = current;
67417+ const struct cred *cred = current_cred();
67418+
67419+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
67420+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67421+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67422+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
67423+
67424+ return;
67425+}
67426+
67427+static void
67428+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
67429+{
67430+ struct task_struct *task = current;
67431+ const struct cred *cred = current_cred();
67432+
67433+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67434+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67435+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67436+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
67437+
67438+ return;
67439+}
67440+
67441+static void
67442+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
67443+{
67444+ struct task_struct *task = current;
67445+ const struct cred *cred = current_cred();
67446+
67447+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
67448+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
67449+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
67450+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
67451+
67452+ return;
67453+}
67454+
67455+static void
67456+gr_set_proc_res(struct task_struct *task)
67457+{
67458+ struct acl_subject_label *proc;
67459+ unsigned short i;
67460+
67461+ proc = task->acl;
67462+
67463+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
67464+ return;
67465+
67466+ for (i = 0; i < RLIM_NLIMITS; i++) {
67467+ if (!(proc->resmask & (1U << i)))
67468+ continue;
67469+
67470+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
67471+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
67472+
67473+ if (i == RLIMIT_CPU)
67474+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
67475+ }
67476+
67477+ return;
67478+}
67479+
67480+/* both of the below must be called with
67481+ rcu_read_lock();
67482+ read_lock(&tasklist_lock);
67483+ read_lock(&grsec_exec_file_lock);
67484+*/
67485+
67486+struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
67487+{
67488+ char *tmpname;
67489+ struct acl_subject_label *tmpsubj;
67490+ struct file *filp;
67491+ struct name_entry *nmatch;
67492+
67493+ filp = task->exec_file;
67494+ if (filp == NULL)
67495+ return NULL;
67496+
67497+ /* the following is to apply the correct subject
67498+ on binaries running when the RBAC system
67499+ is enabled, when the binaries have been
67500+ replaced or deleted since their execution
67501+ -----
67502+ when the RBAC system starts, the inode/dev
67503+ from exec_file will be one the RBAC system
67504+ is unaware of. It only knows the inode/dev
67505+ of the present file on disk, or the absence
67506+ of it.
67507+ */
67508+
67509+ if (filename)
67510+ nmatch = __lookup_name_entry(state, filename);
67511+ else {
67512+ preempt_disable();
67513+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
67514+
67515+ nmatch = __lookup_name_entry(state, tmpname);
67516+ preempt_enable();
67517+ }
67518+ tmpsubj = NULL;
67519+ if (nmatch) {
67520+ if (nmatch->deleted)
67521+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
67522+ else
67523+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
67524+ }
67525+ /* this also works for the reload case -- if we don't match a potentially inherited subject
67526+ then we fall back to a normal lookup based on the binary's ino/dev
67527+ */
67528+ if (tmpsubj == NULL)
67529+ tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
67530+
67531+ return tmpsubj;
67532+}
67533+
67534+static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
67535+{
67536+ return __gr_get_subject_for_task(&running_polstate, task, filename);
67537+}
67538+
67539+void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
67540+{
67541+ struct acl_object_label *obj;
67542+ struct file *filp;
67543+
67544+ filp = task->exec_file;
67545+
67546+ task->acl = subj;
67547+ task->is_writable = 0;
67548+ /* ignore additional mmap checks for processes that are writable
67549+ by the default ACL */
67550+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
67551+ if (unlikely(obj->mode & GR_WRITE))
67552+ task->is_writable = 1;
67553+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67554+ if (unlikely(obj->mode & GR_WRITE))
67555+ task->is_writable = 1;
67556+
67557+ gr_set_proc_res(task);
67558+
67559+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67560+ 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);
67561+#endif
67562+}
67563+
67564+static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
67565+{
67566+ __gr_apply_subject_to_task(&running_polstate, task, subj);
67567+}
67568+
67569+__u32
67570+gr_search_file(const struct dentry * dentry, const __u32 mode,
67571+ const struct vfsmount * mnt)
67572+{
67573+ __u32 retval = mode;
67574+ struct acl_subject_label *curracl;
67575+ struct acl_object_label *currobj;
67576+
67577+ if (unlikely(!(gr_status & GR_READY)))
67578+ return (mode & ~GR_AUDITS);
67579+
67580+ curracl = current->acl;
67581+
67582+ currobj = chk_obj_label(dentry, mnt, curracl);
67583+ retval = currobj->mode & mode;
67584+
67585+ /* if we're opening a specified transfer file for writing
67586+ (e.g. /dev/initctl), then transfer our role to init
67587+ */
67588+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
67589+ current->role->roletype & GR_ROLE_PERSIST)) {
67590+ struct task_struct *task = init_pid_ns.child_reaper;
67591+
67592+ if (task->role != current->role) {
67593+ struct acl_subject_label *subj;
67594+
67595+ task->acl_sp_role = 0;
67596+ task->acl_role_id = current->acl_role_id;
67597+ task->role = current->role;
67598+ rcu_read_lock();
67599+ read_lock(&grsec_exec_file_lock);
67600+ subj = gr_get_subject_for_task(task, NULL);
67601+ gr_apply_subject_to_task(task, subj);
67602+ read_unlock(&grsec_exec_file_lock);
67603+ rcu_read_unlock();
67604+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
67605+ }
67606+ }
67607+
67608+ if (unlikely
67609+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
67610+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
67611+ __u32 new_mode = mode;
67612+
67613+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67614+
67615+ retval = new_mode;
67616+
67617+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
67618+ new_mode |= GR_INHERIT;
67619+
67620+ if (!(mode & GR_NOLEARN))
67621+ gr_log_learn(dentry, mnt, new_mode);
67622+ }
67623+
67624+ return retval;
67625+}
67626+
67627+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
67628+ const struct dentry *parent,
67629+ const struct vfsmount *mnt)
67630+{
67631+ struct name_entry *match;
67632+ struct acl_object_label *matchpo;
67633+ struct acl_subject_label *curracl;
67634+ char *path;
67635+
67636+ if (unlikely(!(gr_status & GR_READY)))
67637+ return NULL;
67638+
67639+ preempt_disable();
67640+ path = gr_to_filename_rbac(new_dentry, mnt);
67641+ match = lookup_name_entry_create(path);
67642+
67643+ curracl = current->acl;
67644+
67645+ if (match) {
67646+ read_lock(&gr_inode_lock);
67647+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
67648+ read_unlock(&gr_inode_lock);
67649+
67650+ if (matchpo) {
67651+ preempt_enable();
67652+ return matchpo;
67653+ }
67654+ }
67655+
67656+ // lookup parent
67657+
67658+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
67659+
67660+ preempt_enable();
67661+ return matchpo;
67662+}
67663+
67664+__u32
67665+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
67666+ const struct vfsmount * mnt, const __u32 mode)
67667+{
67668+ struct acl_object_label *matchpo;
67669+ __u32 retval;
67670+
67671+ if (unlikely(!(gr_status & GR_READY)))
67672+ return (mode & ~GR_AUDITS);
67673+
67674+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
67675+
67676+ retval = matchpo->mode & mode;
67677+
67678+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
67679+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67680+ __u32 new_mode = mode;
67681+
67682+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
67683+
67684+ gr_log_learn(new_dentry, mnt, new_mode);
67685+ return new_mode;
67686+ }
67687+
67688+ return retval;
67689+}
67690+
67691+__u32
67692+gr_check_link(const struct dentry * new_dentry,
67693+ const struct dentry * parent_dentry,
67694+ const struct vfsmount * parent_mnt,
67695+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
67696+{
67697+ struct acl_object_label *obj;
67698+ __u32 oldmode, newmode;
67699+ __u32 needmode;
67700+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
67701+ GR_DELETE | GR_INHERIT;
67702+
67703+ if (unlikely(!(gr_status & GR_READY)))
67704+ return (GR_CREATE | GR_LINK);
67705+
67706+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
67707+ oldmode = obj->mode;
67708+
67709+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
67710+ newmode = obj->mode;
67711+
67712+ needmode = newmode & checkmodes;
67713+
67714+ // old name for hardlink must have at least the permissions of the new name
67715+ if ((oldmode & needmode) != needmode)
67716+ goto bad;
67717+
67718+ // if old name had restrictions/auditing, make sure the new name does as well
67719+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
67720+
67721+ // don't allow hardlinking of suid/sgid/fcapped files without permission
67722+ if (is_privileged_binary(old_dentry))
67723+ needmode |= GR_SETID;
67724+
67725+ if ((newmode & needmode) != needmode)
67726+ goto bad;
67727+
67728+ // enforce minimum permissions
67729+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
67730+ return newmode;
67731+bad:
67732+ needmode = oldmode;
67733+ if (is_privileged_binary(old_dentry))
67734+ needmode |= GR_SETID;
67735+
67736+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
67737+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
67738+ return (GR_CREATE | GR_LINK);
67739+ } else if (newmode & GR_SUPPRESS)
67740+ return GR_SUPPRESS;
67741+ else
67742+ return 0;
67743+}
67744+
67745+int
67746+gr_check_hidden_task(const struct task_struct *task)
67747+{
67748+ if (unlikely(!(gr_status & GR_READY)))
67749+ return 0;
67750+
67751+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
67752+ return 1;
67753+
67754+ return 0;
67755+}
67756+
67757+int
67758+gr_check_protected_task(const struct task_struct *task)
67759+{
67760+ if (unlikely(!(gr_status & GR_READY) || !task))
67761+ return 0;
67762+
67763+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67764+ task->acl != current->acl)
67765+ return 1;
67766+
67767+ return 0;
67768+}
67769+
67770+int
67771+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
67772+{
67773+ struct task_struct *p;
67774+ int ret = 0;
67775+
67776+ if (unlikely(!(gr_status & GR_READY) || !pid))
67777+ return ret;
67778+
67779+ read_lock(&tasklist_lock);
67780+ do_each_pid_task(pid, type, p) {
67781+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
67782+ p->acl != current->acl) {
67783+ ret = 1;
67784+ goto out;
67785+ }
67786+ } while_each_pid_task(pid, type, p);
67787+out:
67788+ read_unlock(&tasklist_lock);
67789+
67790+ return ret;
67791+}
67792+
67793+void
67794+gr_copy_label(struct task_struct *tsk)
67795+{
67796+ struct task_struct *p = current;
67797+
67798+ tsk->inherited = p->inherited;
67799+ tsk->acl_sp_role = 0;
67800+ tsk->acl_role_id = p->acl_role_id;
67801+ tsk->acl = p->acl;
67802+ tsk->role = p->role;
67803+ tsk->signal->used_accept = 0;
67804+ tsk->signal->curr_ip = p->signal->curr_ip;
67805+ tsk->signal->saved_ip = p->signal->saved_ip;
67806+ if (p->exec_file)
67807+ get_file(p->exec_file);
67808+ tsk->exec_file = p->exec_file;
67809+ tsk->is_writable = p->is_writable;
67810+ if (unlikely(p->signal->used_accept)) {
67811+ p->signal->curr_ip = 0;
67812+ p->signal->saved_ip = 0;
67813+ }
67814+
67815+ return;
67816+}
67817+
67818+extern int gr_process_kernel_setuid_ban(struct user_struct *user);
67819+
67820+int
67821+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
67822+{
67823+ unsigned int i;
67824+ __u16 num;
67825+ uid_t *uidlist;
67826+ uid_t curuid;
67827+ int realok = 0;
67828+ int effectiveok = 0;
67829+ int fsok = 0;
67830+ uid_t globalreal, globaleffective, globalfs;
67831+
67832+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
67833+ struct user_struct *user;
67834+
67835+ if (!uid_valid(real))
67836+ goto skipit;
67837+
67838+ /* find user based on global namespace */
67839+
67840+ globalreal = GR_GLOBAL_UID(real);
67841+
67842+ user = find_user(make_kuid(&init_user_ns, globalreal));
67843+ if (user == NULL)
67844+ goto skipit;
67845+
67846+ if (gr_process_kernel_setuid_ban(user)) {
67847+ /* for find_user */
67848+ free_uid(user);
67849+ return 1;
67850+ }
67851+
67852+ /* for find_user */
67853+ free_uid(user);
67854+
67855+skipit:
67856+#endif
67857+
67858+ if (unlikely(!(gr_status & GR_READY)))
67859+ return 0;
67860+
67861+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67862+ gr_log_learn_uid_change(real, effective, fs);
67863+
67864+ num = current->acl->user_trans_num;
67865+ uidlist = current->acl->user_transitions;
67866+
67867+ if (uidlist == NULL)
67868+ return 0;
67869+
67870+ if (!uid_valid(real)) {
67871+ realok = 1;
67872+ globalreal = (uid_t)-1;
67873+ } else {
67874+ globalreal = GR_GLOBAL_UID(real);
67875+ }
67876+ if (!uid_valid(effective)) {
67877+ effectiveok = 1;
67878+ globaleffective = (uid_t)-1;
67879+ } else {
67880+ globaleffective = GR_GLOBAL_UID(effective);
67881+ }
67882+ if (!uid_valid(fs)) {
67883+ fsok = 1;
67884+ globalfs = (uid_t)-1;
67885+ } else {
67886+ globalfs = GR_GLOBAL_UID(fs);
67887+ }
67888+
67889+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
67890+ for (i = 0; i < num; i++) {
67891+ curuid = uidlist[i];
67892+ if (globalreal == curuid)
67893+ realok = 1;
67894+ if (globaleffective == curuid)
67895+ effectiveok = 1;
67896+ if (globalfs == curuid)
67897+ fsok = 1;
67898+ }
67899+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
67900+ for (i = 0; i < num; i++) {
67901+ curuid = uidlist[i];
67902+ if (globalreal == curuid)
67903+ break;
67904+ if (globaleffective == curuid)
67905+ break;
67906+ if (globalfs == curuid)
67907+ break;
67908+ }
67909+ /* not in deny list */
67910+ if (i == num) {
67911+ realok = 1;
67912+ effectiveok = 1;
67913+ fsok = 1;
67914+ }
67915+ }
67916+
67917+ if (realok && effectiveok && fsok)
67918+ return 0;
67919+ else {
67920+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67921+ return 1;
67922+ }
67923+}
67924+
67925+int
67926+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67927+{
67928+ unsigned int i;
67929+ __u16 num;
67930+ gid_t *gidlist;
67931+ gid_t curgid;
67932+ int realok = 0;
67933+ int effectiveok = 0;
67934+ int fsok = 0;
67935+ gid_t globalreal, globaleffective, globalfs;
67936+
67937+ if (unlikely(!(gr_status & GR_READY)))
67938+ return 0;
67939+
67940+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67941+ gr_log_learn_gid_change(real, effective, fs);
67942+
67943+ num = current->acl->group_trans_num;
67944+ gidlist = current->acl->group_transitions;
67945+
67946+ if (gidlist == NULL)
67947+ return 0;
67948+
67949+ if (!gid_valid(real)) {
67950+ realok = 1;
67951+ globalreal = (gid_t)-1;
67952+ } else {
67953+ globalreal = GR_GLOBAL_GID(real);
67954+ }
67955+ if (!gid_valid(effective)) {
67956+ effectiveok = 1;
67957+ globaleffective = (gid_t)-1;
67958+ } else {
67959+ globaleffective = GR_GLOBAL_GID(effective);
67960+ }
67961+ if (!gid_valid(fs)) {
67962+ fsok = 1;
67963+ globalfs = (gid_t)-1;
67964+ } else {
67965+ globalfs = GR_GLOBAL_GID(fs);
67966+ }
67967+
67968+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
67969+ for (i = 0; i < num; i++) {
67970+ curgid = gidlist[i];
67971+ if (globalreal == curgid)
67972+ realok = 1;
67973+ if (globaleffective == curgid)
67974+ effectiveok = 1;
67975+ if (globalfs == curgid)
67976+ fsok = 1;
67977+ }
67978+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
67979+ for (i = 0; i < num; i++) {
67980+ curgid = gidlist[i];
67981+ if (globalreal == curgid)
67982+ break;
67983+ if (globaleffective == curgid)
67984+ break;
67985+ if (globalfs == curgid)
67986+ break;
67987+ }
67988+ /* not in deny list */
67989+ if (i == num) {
67990+ realok = 1;
67991+ effectiveok = 1;
67992+ fsok = 1;
67993+ }
67994+ }
67995+
67996+ if (realok && effectiveok && fsok)
67997+ return 0;
67998+ else {
67999+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68000+ return 1;
68001+ }
68002+}
68003+
68004+extern int gr_acl_is_capable(const int cap);
68005+
68006+void
68007+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68008+{
68009+ struct acl_role_label *role = task->role;
68010+ struct acl_subject_label *subj = NULL;
68011+ struct acl_object_label *obj;
68012+ struct file *filp;
68013+ uid_t uid;
68014+ gid_t gid;
68015+
68016+ if (unlikely(!(gr_status & GR_READY)))
68017+ return;
68018+
68019+ uid = GR_GLOBAL_UID(kuid);
68020+ gid = GR_GLOBAL_GID(kgid);
68021+
68022+ filp = task->exec_file;
68023+
68024+ /* kernel process, we'll give them the kernel role */
68025+ if (unlikely(!filp)) {
68026+ task->role = running_polstate.kernel_role;
68027+ task->acl = running_polstate.kernel_role->root_label;
68028+ return;
68029+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68030+ /* save the current ip at time of role lookup so that the proper
68031+ IP will be learned for role_allowed_ip */
68032+ task->signal->saved_ip = task->signal->curr_ip;
68033+ role = lookup_acl_role_label(task, uid, gid);
68034+ }
68035+
68036+ /* don't change the role if we're not a privileged process */
68037+ if (role && task->role != role &&
68038+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68039+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68040+ return;
68041+
68042+ /* perform subject lookup in possibly new role
68043+ we can use this result below in the case where role == task->role
68044+ */
68045+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68046+
68047+ /* if we changed uid/gid, but result in the same role
68048+ and are using inheritance, don't lose the inherited subject
68049+ if current subject is other than what normal lookup
68050+ would result in, we arrived via inheritance, don't
68051+ lose subject
68052+ */
68053+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68054+ (subj == task->acl)))
68055+ task->acl = subj;
68056+
68057+ /* leave task->inherited unaffected */
68058+
68059+ task->role = role;
68060+
68061+ task->is_writable = 0;
68062+
68063+ /* ignore additional mmap checks for processes that are writable
68064+ by the default ACL */
68065+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68066+ if (unlikely(obj->mode & GR_WRITE))
68067+ task->is_writable = 1;
68068+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68069+ if (unlikely(obj->mode & GR_WRITE))
68070+ task->is_writable = 1;
68071+
68072+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68073+ 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);
68074+#endif
68075+
68076+ gr_set_proc_res(task);
68077+
68078+ return;
68079+}
68080+
68081+int
68082+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68083+ const int unsafe_flags)
68084+{
68085+ struct task_struct *task = current;
68086+ struct acl_subject_label *newacl;
68087+ struct acl_object_label *obj;
68088+ __u32 retmode;
68089+
68090+ if (unlikely(!(gr_status & GR_READY)))
68091+ return 0;
68092+
68093+ newacl = chk_subj_label(dentry, mnt, task->role);
68094+
68095+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68096+ did an exec
68097+ */
68098+ rcu_read_lock();
68099+ read_lock(&tasklist_lock);
68100+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68101+ (task->parent->acl->mode & GR_POVERRIDE))) {
68102+ read_unlock(&tasklist_lock);
68103+ rcu_read_unlock();
68104+ goto skip_check;
68105+ }
68106+ read_unlock(&tasklist_lock);
68107+ rcu_read_unlock();
68108+
68109+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68110+ !(task->role->roletype & GR_ROLE_GOD) &&
68111+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68112+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68113+ if (unsafe_flags & LSM_UNSAFE_SHARE)
68114+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68115+ else
68116+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68117+ return -EACCES;
68118+ }
68119+
68120+skip_check:
68121+
68122+ obj = chk_obj_label(dentry, mnt, task->acl);
68123+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68124+
68125+ if (!(task->acl->mode & GR_INHERITLEARN) &&
68126+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68127+ if (obj->nested)
68128+ task->acl = obj->nested;
68129+ else
68130+ task->acl = newacl;
68131+ task->inherited = 0;
68132+ } else {
68133+ task->inherited = 1;
68134+ if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68135+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68136+ }
68137+
68138+ task->is_writable = 0;
68139+
68140+ /* ignore additional mmap checks for processes that are writable
68141+ by the default ACL */
68142+ obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68143+ if (unlikely(obj->mode & GR_WRITE))
68144+ task->is_writable = 1;
68145+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
68146+ if (unlikely(obj->mode & GR_WRITE))
68147+ task->is_writable = 1;
68148+
68149+ gr_set_proc_res(task);
68150+
68151+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68152+ 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);
68153+#endif
68154+ return 0;
68155+}
68156+
68157+/* always called with valid inodev ptr */
68158+static void
68159+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68160+{
68161+ struct acl_object_label *matchpo;
68162+ struct acl_subject_label *matchps;
68163+ struct acl_subject_label *subj;
68164+ struct acl_role_label *role;
68165+ unsigned int x;
68166+
68167+ FOR_EACH_ROLE_START(role)
68168+ FOR_EACH_SUBJECT_START(role, subj, x)
68169+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68170+ matchpo->mode |= GR_DELETED;
68171+ FOR_EACH_SUBJECT_END(subj,x)
68172+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68173+ /* nested subjects aren't in the role's subj_hash table */
68174+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68175+ matchpo->mode |= GR_DELETED;
68176+ FOR_EACH_NESTED_SUBJECT_END(subj)
68177+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68178+ matchps->mode |= GR_DELETED;
68179+ FOR_EACH_ROLE_END(role)
68180+
68181+ inodev->nentry->deleted = 1;
68182+
68183+ return;
68184+}
68185+
68186+void
68187+gr_handle_delete(const ino_t ino, const dev_t dev)
68188+{
68189+ struct inodev_entry *inodev;
68190+
68191+ if (unlikely(!(gr_status & GR_READY)))
68192+ return;
68193+
68194+ write_lock(&gr_inode_lock);
68195+ inodev = lookup_inodev_entry(ino, dev);
68196+ if (inodev != NULL)
68197+ do_handle_delete(inodev, ino, dev);
68198+ write_unlock(&gr_inode_lock);
68199+
68200+ return;
68201+}
68202+
68203+static void
68204+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68205+ const ino_t newinode, const dev_t newdevice,
68206+ struct acl_subject_label *subj)
68207+{
68208+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68209+ struct acl_object_label *match;
68210+
68211+ match = subj->obj_hash[index];
68212+
68213+ while (match && (match->inode != oldinode ||
68214+ match->device != olddevice ||
68215+ !(match->mode & GR_DELETED)))
68216+ match = match->next;
68217+
68218+ if (match && (match->inode == oldinode)
68219+ && (match->device == olddevice)
68220+ && (match->mode & GR_DELETED)) {
68221+ if (match->prev == NULL) {
68222+ subj->obj_hash[index] = match->next;
68223+ if (match->next != NULL)
68224+ match->next->prev = NULL;
68225+ } else {
68226+ match->prev->next = match->next;
68227+ if (match->next != NULL)
68228+ match->next->prev = match->prev;
68229+ }
68230+ match->prev = NULL;
68231+ match->next = NULL;
68232+ match->inode = newinode;
68233+ match->device = newdevice;
68234+ match->mode &= ~GR_DELETED;
68235+
68236+ insert_acl_obj_label(match, subj);
68237+ }
68238+
68239+ return;
68240+}
68241+
68242+static void
68243+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68244+ const ino_t newinode, const dev_t newdevice,
68245+ struct acl_role_label *role)
68246+{
68247+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68248+ struct acl_subject_label *match;
68249+
68250+ match = role->subj_hash[index];
68251+
68252+ while (match && (match->inode != oldinode ||
68253+ match->device != olddevice ||
68254+ !(match->mode & GR_DELETED)))
68255+ match = match->next;
68256+
68257+ if (match && (match->inode == oldinode)
68258+ && (match->device == olddevice)
68259+ && (match->mode & GR_DELETED)) {
68260+ if (match->prev == NULL) {
68261+ role->subj_hash[index] = match->next;
68262+ if (match->next != NULL)
68263+ match->next->prev = NULL;
68264+ } else {
68265+ match->prev->next = match->next;
68266+ if (match->next != NULL)
68267+ match->next->prev = match->prev;
68268+ }
68269+ match->prev = NULL;
68270+ match->next = NULL;
68271+ match->inode = newinode;
68272+ match->device = newdevice;
68273+ match->mode &= ~GR_DELETED;
68274+
68275+ insert_acl_subj_label(match, role);
68276+ }
68277+
68278+ return;
68279+}
68280+
68281+static void
68282+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68283+ const ino_t newinode, const dev_t newdevice)
68284+{
68285+ unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68286+ struct inodev_entry *match;
68287+
68288+ match = running_polstate.inodev_set.i_hash[index];
68289+
68290+ while (match && (match->nentry->inode != oldinode ||
68291+ match->nentry->device != olddevice || !match->nentry->deleted))
68292+ match = match->next;
68293+
68294+ if (match && (match->nentry->inode == oldinode)
68295+ && (match->nentry->device == olddevice) &&
68296+ match->nentry->deleted) {
68297+ if (match->prev == NULL) {
68298+ running_polstate.inodev_set.i_hash[index] = match->next;
68299+ if (match->next != NULL)
68300+ match->next->prev = NULL;
68301+ } else {
68302+ match->prev->next = match->next;
68303+ if (match->next != NULL)
68304+ match->next->prev = match->prev;
68305+ }
68306+ match->prev = NULL;
68307+ match->next = NULL;
68308+ match->nentry->inode = newinode;
68309+ match->nentry->device = newdevice;
68310+ match->nentry->deleted = 0;
68311+
68312+ insert_inodev_entry(match);
68313+ }
68314+
68315+ return;
68316+}
68317+
68318+static void
68319+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68320+{
68321+ struct acl_subject_label *subj;
68322+ struct acl_role_label *role;
68323+ unsigned int x;
68324+
68325+ FOR_EACH_ROLE_START(role)
68326+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68327+
68328+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
68329+ if ((subj->inode == ino) && (subj->device == dev)) {
68330+ subj->inode = ino;
68331+ subj->device = dev;
68332+ }
68333+ /* nested subjects aren't in the role's subj_hash table */
68334+ update_acl_obj_label(matchn->inode, matchn->device,
68335+ ino, dev, subj);
68336+ FOR_EACH_NESTED_SUBJECT_END(subj)
68337+ FOR_EACH_SUBJECT_START(role, subj, x)
68338+ update_acl_obj_label(matchn->inode, matchn->device,
68339+ ino, dev, subj);
68340+ FOR_EACH_SUBJECT_END(subj,x)
68341+ FOR_EACH_ROLE_END(role)
68342+
68343+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68344+
68345+ return;
68346+}
68347+
68348+static void
68349+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
68350+ const struct vfsmount *mnt)
68351+{
68352+ ino_t ino = dentry->d_inode->i_ino;
68353+ dev_t dev = __get_dev(dentry);
68354+
68355+ __do_handle_create(matchn, ino, dev);
68356+
68357+ return;
68358+}
68359+
68360+void
68361+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
68362+{
68363+ struct name_entry *matchn;
68364+
68365+ if (unlikely(!(gr_status & GR_READY)))
68366+ return;
68367+
68368+ preempt_disable();
68369+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
68370+
68371+ if (unlikely((unsigned long)matchn)) {
68372+ write_lock(&gr_inode_lock);
68373+ do_handle_create(matchn, dentry, mnt);
68374+ write_unlock(&gr_inode_lock);
68375+ }
68376+ preempt_enable();
68377+
68378+ return;
68379+}
68380+
68381+void
68382+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
68383+{
68384+ struct name_entry *matchn;
68385+
68386+ if (unlikely(!(gr_status & GR_READY)))
68387+ return;
68388+
68389+ preempt_disable();
68390+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
68391+
68392+ if (unlikely((unsigned long)matchn)) {
68393+ write_lock(&gr_inode_lock);
68394+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
68395+ write_unlock(&gr_inode_lock);
68396+ }
68397+ preempt_enable();
68398+
68399+ return;
68400+}
68401+
68402+void
68403+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68404+ struct dentry *old_dentry,
68405+ struct dentry *new_dentry,
68406+ struct vfsmount *mnt, const __u8 replace)
68407+{
68408+ struct name_entry *matchn;
68409+ struct inodev_entry *inodev;
68410+ struct inode *inode = new_dentry->d_inode;
68411+ ino_t old_ino = old_dentry->d_inode->i_ino;
68412+ dev_t old_dev = __get_dev(old_dentry);
68413+
68414+ /* vfs_rename swaps the name and parent link for old_dentry and
68415+ new_dentry
68416+ at this point, old_dentry has the new name, parent link, and inode
68417+ for the renamed file
68418+ if a file is being replaced by a rename, new_dentry has the inode
68419+ and name for the replaced file
68420+ */
68421+
68422+ if (unlikely(!(gr_status & GR_READY)))
68423+ return;
68424+
68425+ preempt_disable();
68426+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
68427+
68428+ /* we wouldn't have to check d_inode if it weren't for
68429+ NFS silly-renaming
68430+ */
68431+
68432+ write_lock(&gr_inode_lock);
68433+ if (unlikely(replace && inode)) {
68434+ ino_t new_ino = inode->i_ino;
68435+ dev_t new_dev = __get_dev(new_dentry);
68436+
68437+ inodev = lookup_inodev_entry(new_ino, new_dev);
68438+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
68439+ do_handle_delete(inodev, new_ino, new_dev);
68440+ }
68441+
68442+ inodev = lookup_inodev_entry(old_ino, old_dev);
68443+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
68444+ do_handle_delete(inodev, old_ino, old_dev);
68445+
68446+ if (unlikely((unsigned long)matchn))
68447+ do_handle_create(matchn, old_dentry, mnt);
68448+
68449+ write_unlock(&gr_inode_lock);
68450+ preempt_enable();
68451+
68452+ return;
68453+}
68454+
68455+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
68456+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
68457+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
68458+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
68459+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
68460+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
68461+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
68462+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
68463+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
68464+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
68465+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
68466+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
68467+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
68468+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
68469+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
68470+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
68471+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
68472+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
68473+};
68474+
68475+void
68476+gr_learn_resource(const struct task_struct *task,
68477+ const int res, const unsigned long wanted, const int gt)
68478+{
68479+ struct acl_subject_label *acl;
68480+ const struct cred *cred;
68481+
68482+ if (unlikely((gr_status & GR_READY) &&
68483+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
68484+ goto skip_reslog;
68485+
68486+ gr_log_resource(task, res, wanted, gt);
68487+skip_reslog:
68488+
68489+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
68490+ return;
68491+
68492+ acl = task->acl;
68493+
68494+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
68495+ !(acl->resmask & (1U << (unsigned short) res))))
68496+ return;
68497+
68498+ if (wanted >= acl->res[res].rlim_cur) {
68499+ unsigned long res_add;
68500+
68501+ res_add = wanted + res_learn_bumps[res];
68502+
68503+ acl->res[res].rlim_cur = res_add;
68504+
68505+ if (wanted > acl->res[res].rlim_max)
68506+ acl->res[res].rlim_max = res_add;
68507+
68508+ /* only log the subject filename, since resource logging is supported for
68509+ single-subject learning only */
68510+ rcu_read_lock();
68511+ cred = __task_cred(task);
68512+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68513+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
68514+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
68515+ "", (unsigned long) res, &task->signal->saved_ip);
68516+ rcu_read_unlock();
68517+ }
68518+
68519+ return;
68520+}
68521+EXPORT_SYMBOL_GPL(gr_learn_resource);
68522+#endif
68523+
68524+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
68525+void
68526+pax_set_initial_flags(struct linux_binprm *bprm)
68527+{
68528+ struct task_struct *task = current;
68529+ struct acl_subject_label *proc;
68530+ unsigned long flags;
68531+
68532+ if (unlikely(!(gr_status & GR_READY)))
68533+ return;
68534+
68535+ flags = pax_get_flags(task);
68536+
68537+ proc = task->acl;
68538+
68539+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
68540+ flags &= ~MF_PAX_PAGEEXEC;
68541+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
68542+ flags &= ~MF_PAX_SEGMEXEC;
68543+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
68544+ flags &= ~MF_PAX_RANDMMAP;
68545+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
68546+ flags &= ~MF_PAX_EMUTRAMP;
68547+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
68548+ flags &= ~MF_PAX_MPROTECT;
68549+
68550+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
68551+ flags |= MF_PAX_PAGEEXEC;
68552+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
68553+ flags |= MF_PAX_SEGMEXEC;
68554+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
68555+ flags |= MF_PAX_RANDMMAP;
68556+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
68557+ flags |= MF_PAX_EMUTRAMP;
68558+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
68559+ flags |= MF_PAX_MPROTECT;
68560+
68561+ pax_set_flags(task, flags);
68562+
68563+ return;
68564+}
68565+#endif
68566+
68567+int
68568+gr_handle_proc_ptrace(struct task_struct *task)
68569+{
68570+ struct file *filp;
68571+ struct task_struct *tmp = task;
68572+ struct task_struct *curtemp = current;
68573+ __u32 retmode;
68574+
68575+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68576+ if (unlikely(!(gr_status & GR_READY)))
68577+ return 0;
68578+#endif
68579+
68580+ read_lock(&tasklist_lock);
68581+ read_lock(&grsec_exec_file_lock);
68582+ filp = task->exec_file;
68583+
68584+ while (task_pid_nr(tmp) > 0) {
68585+ if (tmp == curtemp)
68586+ break;
68587+ tmp = tmp->real_parent;
68588+ }
68589+
68590+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68591+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
68592+ read_unlock(&grsec_exec_file_lock);
68593+ read_unlock(&tasklist_lock);
68594+ return 1;
68595+ }
68596+
68597+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68598+ if (!(gr_status & GR_READY)) {
68599+ read_unlock(&grsec_exec_file_lock);
68600+ read_unlock(&tasklist_lock);
68601+ return 0;
68602+ }
68603+#endif
68604+
68605+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
68606+ read_unlock(&grsec_exec_file_lock);
68607+ read_unlock(&tasklist_lock);
68608+
68609+ if (retmode & GR_NOPTRACE)
68610+ return 1;
68611+
68612+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
68613+ && (current->acl != task->acl || (current->acl != current->role->root_label
68614+ && task_pid_nr(current) != task_pid_nr(task))))
68615+ return 1;
68616+
68617+ return 0;
68618+}
68619+
68620+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
68621+{
68622+ if (unlikely(!(gr_status & GR_READY)))
68623+ return;
68624+
68625+ if (!(current->role->roletype & GR_ROLE_GOD))
68626+ return;
68627+
68628+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
68629+ p->role->rolename, gr_task_roletype_to_char(p),
68630+ p->acl->filename);
68631+}
68632+
68633+int
68634+gr_handle_ptrace(struct task_struct *task, const long request)
68635+{
68636+ struct task_struct *tmp = task;
68637+ struct task_struct *curtemp = current;
68638+ __u32 retmode;
68639+
68640+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
68641+ if (unlikely(!(gr_status & GR_READY)))
68642+ return 0;
68643+#endif
68644+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
68645+ read_lock(&tasklist_lock);
68646+ while (task_pid_nr(tmp) > 0) {
68647+ if (tmp == curtemp)
68648+ break;
68649+ tmp = tmp->real_parent;
68650+ }
68651+
68652+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
68653+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
68654+ read_unlock(&tasklist_lock);
68655+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68656+ return 1;
68657+ }
68658+ read_unlock(&tasklist_lock);
68659+ }
68660+
68661+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
68662+ if (!(gr_status & GR_READY))
68663+ return 0;
68664+#endif
68665+
68666+ read_lock(&grsec_exec_file_lock);
68667+ if (unlikely(!task->exec_file)) {
68668+ read_unlock(&grsec_exec_file_lock);
68669+ return 0;
68670+ }
68671+
68672+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
68673+ read_unlock(&grsec_exec_file_lock);
68674+
68675+ if (retmode & GR_NOPTRACE) {
68676+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68677+ return 1;
68678+ }
68679+
68680+ if (retmode & GR_PTRACERD) {
68681+ switch (request) {
68682+ case PTRACE_SEIZE:
68683+ case PTRACE_POKETEXT:
68684+ case PTRACE_POKEDATA:
68685+ case PTRACE_POKEUSR:
68686+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
68687+ case PTRACE_SETREGS:
68688+ case PTRACE_SETFPREGS:
68689+#endif
68690+#ifdef CONFIG_X86
68691+ case PTRACE_SETFPXREGS:
68692+#endif
68693+#ifdef CONFIG_ALTIVEC
68694+ case PTRACE_SETVRREGS:
68695+#endif
68696+ return 1;
68697+ default:
68698+ return 0;
68699+ }
68700+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
68701+ !(current->role->roletype & GR_ROLE_GOD) &&
68702+ (current->acl != task->acl)) {
68703+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
68704+ return 1;
68705+ }
68706+
68707+ return 0;
68708+}
68709+
68710+static int is_writable_mmap(const struct file *filp)
68711+{
68712+ struct task_struct *task = current;
68713+ struct acl_object_label *obj, *obj2;
68714+
68715+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
68716+ !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))) {
68717+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68718+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
68719+ task->role->root_label);
68720+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
68721+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
68722+ return 1;
68723+ }
68724+ }
68725+ return 0;
68726+}
68727+
68728+int
68729+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
68730+{
68731+ __u32 mode;
68732+
68733+ if (unlikely(!file || !(prot & PROT_EXEC)))
68734+ return 1;
68735+
68736+ if (is_writable_mmap(file))
68737+ return 0;
68738+
68739+ mode =
68740+ gr_search_file(file->f_path.dentry,
68741+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68742+ file->f_path.mnt);
68743+
68744+ if (!gr_tpe_allow(file))
68745+ return 0;
68746+
68747+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68748+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68749+ return 0;
68750+ } else if (unlikely(!(mode & GR_EXEC))) {
68751+ return 0;
68752+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68753+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68754+ return 1;
68755+ }
68756+
68757+ return 1;
68758+}
68759+
68760+int
68761+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
68762+{
68763+ __u32 mode;
68764+
68765+ if (unlikely(!file || !(prot & PROT_EXEC)))
68766+ return 1;
68767+
68768+ if (is_writable_mmap(file))
68769+ return 0;
68770+
68771+ mode =
68772+ gr_search_file(file->f_path.dentry,
68773+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
68774+ file->f_path.mnt);
68775+
68776+ if (!gr_tpe_allow(file))
68777+ return 0;
68778+
68779+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
68780+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68781+ return 0;
68782+ } else if (unlikely(!(mode & GR_EXEC))) {
68783+ return 0;
68784+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
68785+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
68786+ return 1;
68787+ }
68788+
68789+ return 1;
68790+}
68791+
68792+void
68793+gr_acl_handle_psacct(struct task_struct *task, const long code)
68794+{
68795+ unsigned long runtime, cputime;
68796+ cputime_t utime, stime;
68797+ unsigned int wday, cday;
68798+ __u8 whr, chr;
68799+ __u8 wmin, cmin;
68800+ __u8 wsec, csec;
68801+ struct timespec timeval;
68802+
68803+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
68804+ !(task->acl->mode & GR_PROCACCT)))
68805+ return;
68806+
68807+ do_posix_clock_monotonic_gettime(&timeval);
68808+ runtime = timeval.tv_sec - task->start_time.tv_sec;
68809+ wday = runtime / (60 * 60 * 24);
68810+ runtime -= wday * (60 * 60 * 24);
68811+ whr = runtime / (60 * 60);
68812+ runtime -= whr * (60 * 60);
68813+ wmin = runtime / 60;
68814+ runtime -= wmin * 60;
68815+ wsec = runtime;
68816+
68817+ task_cputime(task, &utime, &stime);
68818+ cputime = cputime_to_secs(utime + stime);
68819+ cday = cputime / (60 * 60 * 24);
68820+ cputime -= cday * (60 * 60 * 24);
68821+ chr = cputime / (60 * 60);
68822+ cputime -= chr * (60 * 60);
68823+ cmin = cputime / 60;
68824+ cputime -= cmin * 60;
68825+ csec = cputime;
68826+
68827+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
68828+
68829+ return;
68830+}
68831+
68832+#ifdef CONFIG_TASKSTATS
68833+int gr_is_taskstats_denied(int pid)
68834+{
68835+ struct task_struct *task;
68836+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68837+ const struct cred *cred;
68838+#endif
68839+ int ret = 0;
68840+
68841+ /* restrict taskstats viewing to un-chrooted root users
68842+ who have the 'view' subject flag if the RBAC system is enabled
68843+ */
68844+
68845+ rcu_read_lock();
68846+ read_lock(&tasklist_lock);
68847+ task = find_task_by_vpid(pid);
68848+ if (task) {
68849+#ifdef CONFIG_GRKERNSEC_CHROOT
68850+ if (proc_is_chrooted(task))
68851+ ret = -EACCES;
68852+#endif
68853+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68854+ cred = __task_cred(task);
68855+#ifdef CONFIG_GRKERNSEC_PROC_USER
68856+ if (gr_is_global_nonroot(cred->uid))
68857+ ret = -EACCES;
68858+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68859+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
68860+ ret = -EACCES;
68861+#endif
68862+#endif
68863+ if (gr_status & GR_READY) {
68864+ if (!(task->acl->mode & GR_VIEW))
68865+ ret = -EACCES;
68866+ }
68867+ } else
68868+ ret = -ENOENT;
68869+
68870+ read_unlock(&tasklist_lock);
68871+ rcu_read_unlock();
68872+
68873+ return ret;
68874+}
68875+#endif
68876+
68877+/* AUXV entries are filled via a descendant of search_binary_handler
68878+ after we've already applied the subject for the target
68879+*/
68880+int gr_acl_enable_at_secure(void)
68881+{
68882+ if (unlikely(!(gr_status & GR_READY)))
68883+ return 0;
68884+
68885+ if (current->acl->mode & GR_ATSECURE)
68886+ return 1;
68887+
68888+ return 0;
68889+}
68890+
68891+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
68892+{
68893+ struct task_struct *task = current;
68894+ struct dentry *dentry = file->f_path.dentry;
68895+ struct vfsmount *mnt = file->f_path.mnt;
68896+ struct acl_object_label *obj, *tmp;
68897+ struct acl_subject_label *subj;
68898+ unsigned int bufsize;
68899+ int is_not_root;
68900+ char *path;
68901+ dev_t dev = __get_dev(dentry);
68902+
68903+ if (unlikely(!(gr_status & GR_READY)))
68904+ return 1;
68905+
68906+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68907+ return 1;
68908+
68909+ /* ignore Eric Biederman */
68910+ if (IS_PRIVATE(dentry->d_inode))
68911+ return 1;
68912+
68913+ subj = task->acl;
68914+ read_lock(&gr_inode_lock);
68915+ do {
68916+ obj = lookup_acl_obj_label(ino, dev, subj);
68917+ if (obj != NULL) {
68918+ read_unlock(&gr_inode_lock);
68919+ return (obj->mode & GR_FIND) ? 1 : 0;
68920+ }
68921+ } while ((subj = subj->parent_subject));
68922+ read_unlock(&gr_inode_lock);
68923+
68924+ /* this is purely an optimization since we're looking for an object
68925+ for the directory we're doing a readdir on
68926+ if it's possible for any globbed object to match the entry we're
68927+ filling into the directory, then the object we find here will be
68928+ an anchor point with attached globbed objects
68929+ */
68930+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68931+ if (obj->globbed == NULL)
68932+ return (obj->mode & GR_FIND) ? 1 : 0;
68933+
68934+ is_not_root = ((obj->filename[0] == '/') &&
68935+ (obj->filename[1] == '\0')) ? 0 : 1;
68936+ bufsize = PAGE_SIZE - namelen - is_not_root;
68937+
68938+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
68939+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68940+ return 1;
68941+
68942+ preempt_disable();
68943+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68944+ bufsize);
68945+
68946+ bufsize = strlen(path);
68947+
68948+ /* if base is "/", don't append an additional slash */
68949+ if (is_not_root)
68950+ *(path + bufsize) = '/';
68951+ memcpy(path + bufsize + is_not_root, name, namelen);
68952+ *(path + bufsize + namelen + is_not_root) = '\0';
68953+
68954+ tmp = obj->globbed;
68955+ while (tmp) {
68956+ if (!glob_match(tmp->filename, path)) {
68957+ preempt_enable();
68958+ return (tmp->mode & GR_FIND) ? 1 : 0;
68959+ }
68960+ tmp = tmp->next;
68961+ }
68962+ preempt_enable();
68963+ return (obj->mode & GR_FIND) ? 1 : 0;
68964+}
68965+
68966+void gr_put_exec_file(struct task_struct *task)
68967+{
68968+ struct file *filp;
68969+
68970+ write_lock(&grsec_exec_file_lock);
68971+ filp = task->exec_file;
68972+ task->exec_file = NULL;
68973+ write_unlock(&grsec_exec_file_lock);
68974+
68975+ if (filp)
68976+ fput(filp);
68977+
68978+ return;
68979+}
68980+
68981+
68982+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68983+EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68984+#endif
68985+#ifdef CONFIG_SECURITY
68986+EXPORT_SYMBOL_GPL(gr_check_user_change);
68987+EXPORT_SYMBOL_GPL(gr_check_group_change);
68988+#endif
68989+
68990diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68991new file mode 100644
68992index 0000000..18ffbbd
68993--- /dev/null
68994+++ b/grsecurity/gracl_alloc.c
68995@@ -0,0 +1,105 @@
68996+#include <linux/kernel.h>
68997+#include <linux/mm.h>
68998+#include <linux/slab.h>
68999+#include <linux/vmalloc.h>
69000+#include <linux/gracl.h>
69001+#include <linux/grsecurity.h>
69002+
69003+static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69004+struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69005+
69006+static __inline__ int
69007+alloc_pop(void)
69008+{
69009+ if (current_alloc_state->alloc_stack_next == 1)
69010+ return 0;
69011+
69012+ kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69013+
69014+ current_alloc_state->alloc_stack_next--;
69015+
69016+ return 1;
69017+}
69018+
69019+static __inline__ int
69020+alloc_push(void *buf)
69021+{
69022+ if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69023+ return 1;
69024+
69025+ current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69026+
69027+ current_alloc_state->alloc_stack_next++;
69028+
69029+ return 0;
69030+}
69031+
69032+void *
69033+acl_alloc(unsigned long len)
69034+{
69035+ void *ret = NULL;
69036+
69037+ if (!len || len > PAGE_SIZE)
69038+ goto out;
69039+
69040+ ret = kmalloc(len, GFP_KERNEL);
69041+
69042+ if (ret) {
69043+ if (alloc_push(ret)) {
69044+ kfree(ret);
69045+ ret = NULL;
69046+ }
69047+ }
69048+
69049+out:
69050+ return ret;
69051+}
69052+
69053+void *
69054+acl_alloc_num(unsigned long num, unsigned long len)
69055+{
69056+ if (!len || (num > (PAGE_SIZE / len)))
69057+ return NULL;
69058+
69059+ return acl_alloc(num * len);
69060+}
69061+
69062+void
69063+acl_free_all(void)
69064+{
69065+ if (!current_alloc_state->alloc_stack)
69066+ return;
69067+
69068+ while (alloc_pop()) ;
69069+
69070+ if (current_alloc_state->alloc_stack) {
69071+ if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69072+ kfree(current_alloc_state->alloc_stack);
69073+ else
69074+ vfree(current_alloc_state->alloc_stack);
69075+ }
69076+
69077+ current_alloc_state->alloc_stack = NULL;
69078+ current_alloc_state->alloc_stack_size = 1;
69079+ current_alloc_state->alloc_stack_next = 1;
69080+
69081+ return;
69082+}
69083+
69084+int
69085+acl_alloc_stack_init(unsigned long size)
69086+{
69087+ if ((size * sizeof (void *)) <= PAGE_SIZE)
69088+ current_alloc_state->alloc_stack =
69089+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69090+ else
69091+ current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69092+
69093+ current_alloc_state->alloc_stack_size = size;
69094+ current_alloc_state->alloc_stack_next = 1;
69095+
69096+ if (!current_alloc_state->alloc_stack)
69097+ return 0;
69098+ else
69099+ return 1;
69100+}
69101diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69102new file mode 100644
69103index 0000000..bdd51ea
69104--- /dev/null
69105+++ b/grsecurity/gracl_cap.c
69106@@ -0,0 +1,110 @@
69107+#include <linux/kernel.h>
69108+#include <linux/module.h>
69109+#include <linux/sched.h>
69110+#include <linux/gracl.h>
69111+#include <linux/grsecurity.h>
69112+#include <linux/grinternal.h>
69113+
69114+extern const char *captab_log[];
69115+extern int captab_log_entries;
69116+
69117+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69118+{
69119+ struct acl_subject_label *curracl;
69120+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69121+ kernel_cap_t cap_audit = __cap_empty_set;
69122+
69123+ if (!gr_acl_is_enabled())
69124+ return 1;
69125+
69126+ curracl = task->acl;
69127+
69128+ cap_drop = curracl->cap_lower;
69129+ cap_mask = curracl->cap_mask;
69130+ cap_audit = curracl->cap_invert_audit;
69131+
69132+ while ((curracl = curracl->parent_subject)) {
69133+ /* if the cap isn't specified in the current computed mask but is specified in the
69134+ current level subject, and is lowered in the current level subject, then add
69135+ it to the set of dropped capabilities
69136+ otherwise, add the current level subject's mask to the current computed mask
69137+ */
69138+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69139+ cap_raise(cap_mask, cap);
69140+ if (cap_raised(curracl->cap_lower, cap))
69141+ cap_raise(cap_drop, cap);
69142+ if (cap_raised(curracl->cap_invert_audit, cap))
69143+ cap_raise(cap_audit, cap);
69144+ }
69145+ }
69146+
69147+ if (!cap_raised(cap_drop, cap)) {
69148+ if (cap_raised(cap_audit, cap))
69149+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69150+ return 1;
69151+ }
69152+
69153+ curracl = task->acl;
69154+
69155+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69156+ && cap_raised(cred->cap_effective, cap)) {
69157+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69158+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
69159+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
69160+ gr_to_filename(task->exec_file->f_path.dentry,
69161+ task->exec_file->f_path.mnt) : curracl->filename,
69162+ curracl->filename, 0UL,
69163+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69164+ return 1;
69165+ }
69166+
69167+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69168+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69169+
69170+ return 0;
69171+}
69172+
69173+int
69174+gr_acl_is_capable(const int cap)
69175+{
69176+ return gr_task_acl_is_capable(current, current_cred(), cap);
69177+}
69178+
69179+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69180+{
69181+ struct acl_subject_label *curracl;
69182+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69183+
69184+ if (!gr_acl_is_enabled())
69185+ return 1;
69186+
69187+ curracl = task->acl;
69188+
69189+ cap_drop = curracl->cap_lower;
69190+ cap_mask = curracl->cap_mask;
69191+
69192+ while ((curracl = curracl->parent_subject)) {
69193+ /* if the cap isn't specified in the current computed mask but is specified in the
69194+ current level subject, and is lowered in the current level subject, then add
69195+ it to the set of dropped capabilities
69196+ otherwise, add the current level subject's mask to the current computed mask
69197+ */
69198+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69199+ cap_raise(cap_mask, cap);
69200+ if (cap_raised(curracl->cap_lower, cap))
69201+ cap_raise(cap_drop, cap);
69202+ }
69203+ }
69204+
69205+ if (!cap_raised(cap_drop, cap))
69206+ return 1;
69207+
69208+ return 0;
69209+}
69210+
69211+int
69212+gr_acl_is_capable_nolog(const int cap)
69213+{
69214+ return gr_task_acl_is_capable_nolog(current, cap);
69215+}
69216+
69217diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69218new file mode 100644
69219index 0000000..ca25605
69220--- /dev/null
69221+++ b/grsecurity/gracl_compat.c
69222@@ -0,0 +1,270 @@
69223+#include <linux/kernel.h>
69224+#include <linux/gracl.h>
69225+#include <linux/compat.h>
69226+#include <linux/gracl_compat.h>
69227+
69228+#include <asm/uaccess.h>
69229+
69230+int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69231+{
69232+ struct gr_arg_wrapper_compat uwrapcompat;
69233+
69234+ if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69235+ return -EFAULT;
69236+
69237+ if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69238+ (uwrapcompat.version != 0x2901)) ||
69239+ (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69240+ return -EINVAL;
69241+
69242+ uwrap->arg = compat_ptr(uwrapcompat.arg);
69243+ uwrap->version = uwrapcompat.version;
69244+ uwrap->size = sizeof(struct gr_arg);
69245+
69246+ return 0;
69247+}
69248+
69249+int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69250+{
69251+ struct gr_arg_compat argcompat;
69252+
69253+ if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69254+ return -EFAULT;
69255+
69256+ arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69257+ arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69258+ arg->role_db.num_roles = argcompat.role_db.num_roles;
69259+ arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69260+ arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69261+ arg->role_db.num_objects = argcompat.role_db.num_objects;
69262+
69263+ memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69264+ memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69265+ memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69266+ memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69267+ arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69268+ arg->segv_device = argcompat.segv_device;
69269+ arg->segv_inode = argcompat.segv_inode;
69270+ arg->segv_uid = argcompat.segv_uid;
69271+ arg->num_sprole_pws = argcompat.num_sprole_pws;
69272+ arg->mode = argcompat.mode;
69273+
69274+ return 0;
69275+}
69276+
69277+int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69278+{
69279+ struct acl_object_label_compat objcompat;
69280+
69281+ if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69282+ return -EFAULT;
69283+
69284+ obj->filename = compat_ptr(objcompat.filename);
69285+ obj->inode = objcompat.inode;
69286+ obj->device = objcompat.device;
69287+ obj->mode = objcompat.mode;
69288+
69289+ obj->nested = compat_ptr(objcompat.nested);
69290+ obj->globbed = compat_ptr(objcompat.globbed);
69291+
69292+ obj->prev = compat_ptr(objcompat.prev);
69293+ obj->next = compat_ptr(objcompat.next);
69294+
69295+ return 0;
69296+}
69297+
69298+int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69299+{
69300+ unsigned int i;
69301+ struct acl_subject_label_compat subjcompat;
69302+
69303+ if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69304+ return -EFAULT;
69305+
69306+ subj->filename = compat_ptr(subjcompat.filename);
69307+ subj->inode = subjcompat.inode;
69308+ subj->device = subjcompat.device;
69309+ subj->mode = subjcompat.mode;
69310+ subj->cap_mask = subjcompat.cap_mask;
69311+ subj->cap_lower = subjcompat.cap_lower;
69312+ subj->cap_invert_audit = subjcompat.cap_invert_audit;
69313+
69314+ for (i = 0; i < GR_NLIMITS; i++) {
69315+ if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69316+ subj->res[i].rlim_cur = RLIM_INFINITY;
69317+ else
69318+ subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69319+ if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69320+ subj->res[i].rlim_max = RLIM_INFINITY;
69321+ else
69322+ subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
69323+ }
69324+ subj->resmask = subjcompat.resmask;
69325+
69326+ subj->user_trans_type = subjcompat.user_trans_type;
69327+ subj->group_trans_type = subjcompat.group_trans_type;
69328+ subj->user_transitions = compat_ptr(subjcompat.user_transitions);
69329+ subj->group_transitions = compat_ptr(subjcompat.group_transitions);
69330+ subj->user_trans_num = subjcompat.user_trans_num;
69331+ subj->group_trans_num = subjcompat.group_trans_num;
69332+
69333+ memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
69334+ memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
69335+ subj->ip_type = subjcompat.ip_type;
69336+ subj->ips = compat_ptr(subjcompat.ips);
69337+ subj->ip_num = subjcompat.ip_num;
69338+ subj->inaddr_any_override = subjcompat.inaddr_any_override;
69339+
69340+ subj->crashes = subjcompat.crashes;
69341+ subj->expires = subjcompat.expires;
69342+
69343+ subj->parent_subject = compat_ptr(subjcompat.parent_subject);
69344+ subj->hash = compat_ptr(subjcompat.hash);
69345+ subj->prev = compat_ptr(subjcompat.prev);
69346+ subj->next = compat_ptr(subjcompat.next);
69347+
69348+ subj->obj_hash = compat_ptr(subjcompat.obj_hash);
69349+ subj->obj_hash_size = subjcompat.obj_hash_size;
69350+ subj->pax_flags = subjcompat.pax_flags;
69351+
69352+ return 0;
69353+}
69354+
69355+int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
69356+{
69357+ struct acl_role_label_compat rolecompat;
69358+
69359+ if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
69360+ return -EFAULT;
69361+
69362+ role->rolename = compat_ptr(rolecompat.rolename);
69363+ role->uidgid = rolecompat.uidgid;
69364+ role->roletype = rolecompat.roletype;
69365+
69366+ role->auth_attempts = rolecompat.auth_attempts;
69367+ role->expires = rolecompat.expires;
69368+
69369+ role->root_label = compat_ptr(rolecompat.root_label);
69370+ role->hash = compat_ptr(rolecompat.hash);
69371+
69372+ role->prev = compat_ptr(rolecompat.prev);
69373+ role->next = compat_ptr(rolecompat.next);
69374+
69375+ role->transitions = compat_ptr(rolecompat.transitions);
69376+ role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
69377+ role->domain_children = compat_ptr(rolecompat.domain_children);
69378+ role->domain_child_num = rolecompat.domain_child_num;
69379+
69380+ role->umask = rolecompat.umask;
69381+
69382+ role->subj_hash = compat_ptr(rolecompat.subj_hash);
69383+ role->subj_hash_size = rolecompat.subj_hash_size;
69384+
69385+ return 0;
69386+}
69387+
69388+int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69389+{
69390+ struct role_allowed_ip_compat roleip_compat;
69391+
69392+ if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
69393+ return -EFAULT;
69394+
69395+ roleip->addr = roleip_compat.addr;
69396+ roleip->netmask = roleip_compat.netmask;
69397+
69398+ roleip->prev = compat_ptr(roleip_compat.prev);
69399+ roleip->next = compat_ptr(roleip_compat.next);
69400+
69401+ return 0;
69402+}
69403+
69404+int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
69405+{
69406+ struct role_transition_compat trans_compat;
69407+
69408+ if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
69409+ return -EFAULT;
69410+
69411+ trans->rolename = compat_ptr(trans_compat.rolename);
69412+
69413+ trans->prev = compat_ptr(trans_compat.prev);
69414+ trans->next = compat_ptr(trans_compat.next);
69415+
69416+ return 0;
69417+
69418+}
69419+
69420+int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69421+{
69422+ struct gr_hash_struct_compat hash_compat;
69423+
69424+ if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
69425+ return -EFAULT;
69426+
69427+ hash->table = compat_ptr(hash_compat.table);
69428+ hash->nametable = compat_ptr(hash_compat.nametable);
69429+ hash->first = compat_ptr(hash_compat.first);
69430+
69431+ hash->table_size = hash_compat.table_size;
69432+ hash->used_size = hash_compat.used_size;
69433+
69434+ hash->type = hash_compat.type;
69435+
69436+ return 0;
69437+}
69438+
69439+int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
69440+{
69441+ compat_uptr_t ptrcompat;
69442+
69443+ if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
69444+ return -EFAULT;
69445+
69446+ *(void **)ptr = compat_ptr(ptrcompat);
69447+
69448+ return 0;
69449+}
69450+
69451+int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69452+{
69453+ struct acl_ip_label_compat ip_compat;
69454+
69455+ if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
69456+ return -EFAULT;
69457+
69458+ ip->iface = compat_ptr(ip_compat.iface);
69459+ ip->addr = ip_compat.addr;
69460+ ip->netmask = ip_compat.netmask;
69461+ ip->low = ip_compat.low;
69462+ ip->high = ip_compat.high;
69463+ ip->mode = ip_compat.mode;
69464+ ip->type = ip_compat.type;
69465+
69466+ memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
69467+
69468+ ip->prev = compat_ptr(ip_compat.prev);
69469+ ip->next = compat_ptr(ip_compat.next);
69470+
69471+ return 0;
69472+}
69473+
69474+int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69475+{
69476+ struct sprole_pw_compat pw_compat;
69477+
69478+ if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
69479+ return -EFAULT;
69480+
69481+ pw->rolename = compat_ptr(pw_compat.rolename);
69482+ memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
69483+ memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
69484+
69485+ return 0;
69486+}
69487+
69488+size_t get_gr_arg_wrapper_size_compat(void)
69489+{
69490+ return sizeof(struct gr_arg_wrapper_compat);
69491+}
69492+
69493diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
69494new file mode 100644
69495index 0000000..a89b1f4
69496--- /dev/null
69497+++ b/grsecurity/gracl_fs.c
69498@@ -0,0 +1,437 @@
69499+#include <linux/kernel.h>
69500+#include <linux/sched.h>
69501+#include <linux/types.h>
69502+#include <linux/fs.h>
69503+#include <linux/file.h>
69504+#include <linux/stat.h>
69505+#include <linux/grsecurity.h>
69506+#include <linux/grinternal.h>
69507+#include <linux/gracl.h>
69508+
69509+umode_t
69510+gr_acl_umask(void)
69511+{
69512+ if (unlikely(!gr_acl_is_enabled()))
69513+ return 0;
69514+
69515+ return current->role->umask;
69516+}
69517+
69518+__u32
69519+gr_acl_handle_hidden_file(const struct dentry * dentry,
69520+ const struct vfsmount * mnt)
69521+{
69522+ __u32 mode;
69523+
69524+ if (unlikely(d_is_negative(dentry)))
69525+ return GR_FIND;
69526+
69527+ mode =
69528+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
69529+
69530+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
69531+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69532+ return mode;
69533+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
69534+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
69535+ return 0;
69536+ } else if (unlikely(!(mode & GR_FIND)))
69537+ return 0;
69538+
69539+ return GR_FIND;
69540+}
69541+
69542+__u32
69543+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
69544+ int acc_mode)
69545+{
69546+ __u32 reqmode = GR_FIND;
69547+ __u32 mode;
69548+
69549+ if (unlikely(d_is_negative(dentry)))
69550+ return reqmode;
69551+
69552+ if (acc_mode & MAY_APPEND)
69553+ reqmode |= GR_APPEND;
69554+ else if (acc_mode & MAY_WRITE)
69555+ reqmode |= GR_WRITE;
69556+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
69557+ reqmode |= GR_READ;
69558+
69559+ mode =
69560+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69561+ mnt);
69562+
69563+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69564+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69565+ reqmode & GR_READ ? " reading" : "",
69566+ reqmode & GR_WRITE ? " writing" : reqmode &
69567+ GR_APPEND ? " appending" : "");
69568+ return reqmode;
69569+ } else
69570+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69571+ {
69572+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
69573+ reqmode & GR_READ ? " reading" : "",
69574+ reqmode & GR_WRITE ? " writing" : reqmode &
69575+ GR_APPEND ? " appending" : "");
69576+ return 0;
69577+ } else if (unlikely((mode & reqmode) != reqmode))
69578+ return 0;
69579+
69580+ return reqmode;
69581+}
69582+
69583+__u32
69584+gr_acl_handle_creat(const struct dentry * dentry,
69585+ const struct dentry * p_dentry,
69586+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
69587+ const int imode)
69588+{
69589+ __u32 reqmode = GR_WRITE | GR_CREATE;
69590+ __u32 mode;
69591+
69592+ if (acc_mode & MAY_APPEND)
69593+ reqmode |= GR_APPEND;
69594+ // if a directory was required or the directory already exists, then
69595+ // don't count this open as a read
69596+ if ((acc_mode & MAY_READ) &&
69597+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
69598+ reqmode |= GR_READ;
69599+ if ((open_flags & O_CREAT) &&
69600+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69601+ reqmode |= GR_SETID;
69602+
69603+ mode =
69604+ gr_check_create(dentry, p_dentry, p_mnt,
69605+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69606+
69607+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69608+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69609+ reqmode & GR_READ ? " reading" : "",
69610+ reqmode & GR_WRITE ? " writing" : reqmode &
69611+ GR_APPEND ? " appending" : "");
69612+ return reqmode;
69613+ } else
69614+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69615+ {
69616+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
69617+ reqmode & GR_READ ? " reading" : "",
69618+ reqmode & GR_WRITE ? " writing" : reqmode &
69619+ GR_APPEND ? " appending" : "");
69620+ return 0;
69621+ } else if (unlikely((mode & reqmode) != reqmode))
69622+ return 0;
69623+
69624+ return reqmode;
69625+}
69626+
69627+__u32
69628+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
69629+ const int fmode)
69630+{
69631+ __u32 mode, reqmode = GR_FIND;
69632+
69633+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
69634+ reqmode |= GR_EXEC;
69635+ if (fmode & S_IWOTH)
69636+ reqmode |= GR_WRITE;
69637+ if (fmode & S_IROTH)
69638+ reqmode |= GR_READ;
69639+
69640+ mode =
69641+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
69642+ mnt);
69643+
69644+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
69645+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69646+ reqmode & GR_READ ? " reading" : "",
69647+ reqmode & GR_WRITE ? " writing" : "",
69648+ reqmode & GR_EXEC ? " executing" : "");
69649+ return reqmode;
69650+ } else
69651+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
69652+ {
69653+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
69654+ reqmode & GR_READ ? " reading" : "",
69655+ reqmode & GR_WRITE ? " writing" : "",
69656+ reqmode & GR_EXEC ? " executing" : "");
69657+ return 0;
69658+ } else if (unlikely((mode & reqmode) != reqmode))
69659+ return 0;
69660+
69661+ return reqmode;
69662+}
69663+
69664+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
69665+{
69666+ __u32 mode;
69667+
69668+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
69669+
69670+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69671+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
69672+ return mode;
69673+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69674+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
69675+ return 0;
69676+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69677+ return 0;
69678+
69679+ return (reqmode);
69680+}
69681+
69682+__u32
69683+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
69684+{
69685+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
69686+}
69687+
69688+__u32
69689+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
69690+{
69691+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
69692+}
69693+
69694+__u32
69695+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
69696+{
69697+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
69698+}
69699+
69700+__u32
69701+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
69702+{
69703+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
69704+}
69705+
69706+__u32
69707+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
69708+ umode_t *modeptr)
69709+{
69710+ umode_t mode;
69711+
69712+ *modeptr &= ~gr_acl_umask();
69713+ mode = *modeptr;
69714+
69715+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
69716+ return 1;
69717+
69718+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
69719+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
69720+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
69721+ GR_CHMOD_ACL_MSG);
69722+ } else {
69723+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
69724+ }
69725+}
69726+
69727+__u32
69728+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
69729+{
69730+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
69731+}
69732+
69733+__u32
69734+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
69735+{
69736+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
69737+}
69738+
69739+__u32
69740+gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
69741+{
69742+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
69743+}
69744+
69745+__u32
69746+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
69747+{
69748+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
69749+}
69750+
69751+__u32
69752+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
69753+{
69754+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
69755+ GR_UNIXCONNECT_ACL_MSG);
69756+}
69757+
69758+/* hardlinks require at minimum create and link permission,
69759+ any additional privilege required is based on the
69760+ privilege of the file being linked to
69761+*/
69762+__u32
69763+gr_acl_handle_link(const struct dentry * new_dentry,
69764+ const struct dentry * parent_dentry,
69765+ const struct vfsmount * parent_mnt,
69766+ const struct dentry * old_dentry,
69767+ const struct vfsmount * old_mnt, const struct filename *to)
69768+{
69769+ __u32 mode;
69770+ __u32 needmode = GR_CREATE | GR_LINK;
69771+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
69772+
69773+ mode =
69774+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
69775+ old_mnt);
69776+
69777+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
69778+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69779+ return mode;
69780+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69781+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
69782+ return 0;
69783+ } else if (unlikely((mode & needmode) != needmode))
69784+ return 0;
69785+
69786+ return 1;
69787+}
69788+
69789+__u32
69790+gr_acl_handle_symlink(const struct dentry * new_dentry,
69791+ const struct dentry * parent_dentry,
69792+ const struct vfsmount * parent_mnt, const struct filename *from)
69793+{
69794+ __u32 needmode = GR_WRITE | GR_CREATE;
69795+ __u32 mode;
69796+
69797+ mode =
69798+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
69799+ GR_CREATE | GR_AUDIT_CREATE |
69800+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
69801+
69802+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
69803+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69804+ return mode;
69805+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
69806+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
69807+ return 0;
69808+ } else if (unlikely((mode & needmode) != needmode))
69809+ return 0;
69810+
69811+ return (GR_WRITE | GR_CREATE);
69812+}
69813+
69814+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)
69815+{
69816+ __u32 mode;
69817+
69818+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
69819+
69820+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
69821+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
69822+ return mode;
69823+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
69824+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
69825+ return 0;
69826+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
69827+ return 0;
69828+
69829+ return (reqmode);
69830+}
69831+
69832+__u32
69833+gr_acl_handle_mknod(const struct dentry * new_dentry,
69834+ const struct dentry * parent_dentry,
69835+ const struct vfsmount * parent_mnt,
69836+ const int mode)
69837+{
69838+ __u32 reqmode = GR_WRITE | GR_CREATE;
69839+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
69840+ reqmode |= GR_SETID;
69841+
69842+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69843+ reqmode, GR_MKNOD_ACL_MSG);
69844+}
69845+
69846+__u32
69847+gr_acl_handle_mkdir(const struct dentry *new_dentry,
69848+ const struct dentry *parent_dentry,
69849+ const struct vfsmount *parent_mnt)
69850+{
69851+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
69852+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
69853+}
69854+
69855+#define RENAME_CHECK_SUCCESS(old, new) \
69856+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
69857+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
69858+
69859+int
69860+gr_acl_handle_rename(struct dentry *new_dentry,
69861+ struct dentry *parent_dentry,
69862+ const struct vfsmount *parent_mnt,
69863+ struct dentry *old_dentry,
69864+ struct inode *old_parent_inode,
69865+ struct vfsmount *old_mnt, const struct filename *newname)
69866+{
69867+ __u32 comp1, comp2;
69868+ int error = 0;
69869+
69870+ if (unlikely(!gr_acl_is_enabled()))
69871+ return 0;
69872+
69873+ if (d_is_negative(new_dentry)) {
69874+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
69875+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
69876+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
69877+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
69878+ GR_DELETE | GR_AUDIT_DELETE |
69879+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69880+ GR_SUPPRESS, old_mnt);
69881+ } else {
69882+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
69883+ GR_CREATE | GR_DELETE |
69884+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
69885+ GR_AUDIT_READ | GR_AUDIT_WRITE |
69886+ GR_SUPPRESS, parent_mnt);
69887+ comp2 =
69888+ gr_search_file(old_dentry,
69889+ GR_READ | GR_WRITE | GR_AUDIT_READ |
69890+ GR_DELETE | GR_AUDIT_DELETE |
69891+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
69892+ }
69893+
69894+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
69895+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69896+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69897+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69898+ && !(comp2 & GR_SUPPRESS)) {
69899+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69900+ error = -EACCES;
69901+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69902+ error = -EACCES;
69903+
69904+ return error;
69905+}
69906+
69907+void
69908+gr_acl_handle_exit(void)
69909+{
69910+ u16 id;
69911+ char *rolename;
69912+
69913+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69914+ !(current->role->roletype & GR_ROLE_PERSIST))) {
69915+ id = current->acl_role_id;
69916+ rolename = current->role->rolename;
69917+ gr_set_acls(1);
69918+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69919+ }
69920+
69921+ gr_put_exec_file(current);
69922+ return;
69923+}
69924+
69925+int
69926+gr_acl_handle_procpidmem(const struct task_struct *task)
69927+{
69928+ if (unlikely(!gr_acl_is_enabled()))
69929+ return 0;
69930+
69931+ if (task != current && task->acl->mode & GR_PROTPROCFD)
69932+ return -EACCES;
69933+
69934+ return 0;
69935+}
69936diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69937new file mode 100644
69938index 0000000..f056b81
69939--- /dev/null
69940+++ b/grsecurity/gracl_ip.c
69941@@ -0,0 +1,386 @@
69942+#include <linux/kernel.h>
69943+#include <asm/uaccess.h>
69944+#include <asm/errno.h>
69945+#include <net/sock.h>
69946+#include <linux/file.h>
69947+#include <linux/fs.h>
69948+#include <linux/net.h>
69949+#include <linux/in.h>
69950+#include <linux/skbuff.h>
69951+#include <linux/ip.h>
69952+#include <linux/udp.h>
69953+#include <linux/types.h>
69954+#include <linux/sched.h>
69955+#include <linux/netdevice.h>
69956+#include <linux/inetdevice.h>
69957+#include <linux/gracl.h>
69958+#include <linux/grsecurity.h>
69959+#include <linux/grinternal.h>
69960+
69961+#define GR_BIND 0x01
69962+#define GR_CONNECT 0x02
69963+#define GR_INVERT 0x04
69964+#define GR_BINDOVERRIDE 0x08
69965+#define GR_CONNECTOVERRIDE 0x10
69966+#define GR_SOCK_FAMILY 0x20
69967+
69968+static const char * gr_protocols[IPPROTO_MAX] = {
69969+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69970+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69971+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69972+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69973+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69974+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69975+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69976+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69977+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69978+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69979+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69980+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69981+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69982+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69983+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69984+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69985+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69986+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69987+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69988+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69989+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69990+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69991+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69992+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69993+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69994+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69995+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69996+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69997+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69998+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69999+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70000+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70001+ };
70002+
70003+static const char * gr_socktypes[SOCK_MAX] = {
70004+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70005+ "unknown:7", "unknown:8", "unknown:9", "packet"
70006+ };
70007+
70008+static const char * gr_sockfamilies[AF_MAX+1] = {
70009+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70010+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70011+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70012+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70013+ };
70014+
70015+const char *
70016+gr_proto_to_name(unsigned char proto)
70017+{
70018+ return gr_protocols[proto];
70019+}
70020+
70021+const char *
70022+gr_socktype_to_name(unsigned char type)
70023+{
70024+ return gr_socktypes[type];
70025+}
70026+
70027+const char *
70028+gr_sockfamily_to_name(unsigned char family)
70029+{
70030+ return gr_sockfamilies[family];
70031+}
70032+
70033+extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70034+
70035+int
70036+gr_search_socket(const int domain, const int type, const int protocol)
70037+{
70038+ struct acl_subject_label *curr;
70039+ const struct cred *cred = current_cred();
70040+
70041+ if (unlikely(!gr_acl_is_enabled()))
70042+ goto exit;
70043+
70044+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
70045+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70046+ goto exit; // let the kernel handle it
70047+
70048+ curr = current->acl;
70049+
70050+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70051+ /* the family is allowed, if this is PF_INET allow it only if
70052+ the extra sock type/protocol checks pass */
70053+ if (domain == PF_INET)
70054+ goto inet_check;
70055+ goto exit;
70056+ } else {
70057+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70058+ __u32 fakeip = 0;
70059+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70060+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70061+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70062+ gr_to_filename(current->exec_file->f_path.dentry,
70063+ current->exec_file->f_path.mnt) :
70064+ curr->filename, curr->filename,
70065+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70066+ &current->signal->saved_ip);
70067+ goto exit;
70068+ }
70069+ goto exit_fail;
70070+ }
70071+
70072+inet_check:
70073+ /* the rest of this checking is for IPv4 only */
70074+ if (!curr->ips)
70075+ goto exit;
70076+
70077+ if ((curr->ip_type & (1U << type)) &&
70078+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70079+ goto exit;
70080+
70081+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70082+ /* we don't place acls on raw sockets , and sometimes
70083+ dgram/ip sockets are opened for ioctl and not
70084+ bind/connect, so we'll fake a bind learn log */
70085+ if (type == SOCK_RAW || type == SOCK_PACKET) {
70086+ __u32 fakeip = 0;
70087+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70088+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70089+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70090+ gr_to_filename(current->exec_file->f_path.dentry,
70091+ current->exec_file->f_path.mnt) :
70092+ curr->filename, curr->filename,
70093+ &fakeip, 0, type,
70094+ protocol, GR_CONNECT, &current->signal->saved_ip);
70095+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70096+ __u32 fakeip = 0;
70097+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70098+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70099+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70100+ gr_to_filename(current->exec_file->f_path.dentry,
70101+ current->exec_file->f_path.mnt) :
70102+ curr->filename, curr->filename,
70103+ &fakeip, 0, type,
70104+ protocol, GR_BIND, &current->signal->saved_ip);
70105+ }
70106+ /* we'll log when they use connect or bind */
70107+ goto exit;
70108+ }
70109+
70110+exit_fail:
70111+ if (domain == PF_INET)
70112+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70113+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
70114+ else if (rcu_access_pointer(net_families[domain]) != NULL)
70115+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70116+ gr_socktype_to_name(type), protocol);
70117+
70118+ return 0;
70119+exit:
70120+ return 1;
70121+}
70122+
70123+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)
70124+{
70125+ if ((ip->mode & mode) &&
70126+ (ip_port >= ip->low) &&
70127+ (ip_port <= ip->high) &&
70128+ ((ntohl(ip_addr) & our_netmask) ==
70129+ (ntohl(our_addr) & our_netmask))
70130+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70131+ && (ip->type & (1U << type))) {
70132+ if (ip->mode & GR_INVERT)
70133+ return 2; // specifically denied
70134+ else
70135+ return 1; // allowed
70136+ }
70137+
70138+ return 0; // not specifically allowed, may continue parsing
70139+}
70140+
70141+static int
70142+gr_search_connectbind(const int full_mode, struct sock *sk,
70143+ struct sockaddr_in *addr, const int type)
70144+{
70145+ char iface[IFNAMSIZ] = {0};
70146+ struct acl_subject_label *curr;
70147+ struct acl_ip_label *ip;
70148+ struct inet_sock *isk;
70149+ struct net_device *dev;
70150+ struct in_device *idev;
70151+ unsigned long i;
70152+ int ret;
70153+ int mode = full_mode & (GR_BIND | GR_CONNECT);
70154+ __u32 ip_addr = 0;
70155+ __u32 our_addr;
70156+ __u32 our_netmask;
70157+ char *p;
70158+ __u16 ip_port = 0;
70159+ const struct cred *cred = current_cred();
70160+
70161+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70162+ return 0;
70163+
70164+ curr = current->acl;
70165+ isk = inet_sk(sk);
70166+
70167+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70168+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70169+ addr->sin_addr.s_addr = curr->inaddr_any_override;
70170+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70171+ struct sockaddr_in saddr;
70172+ int err;
70173+
70174+ saddr.sin_family = AF_INET;
70175+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
70176+ saddr.sin_port = isk->inet_sport;
70177+
70178+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70179+ if (err)
70180+ return err;
70181+
70182+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70183+ if (err)
70184+ return err;
70185+ }
70186+
70187+ if (!curr->ips)
70188+ return 0;
70189+
70190+ ip_addr = addr->sin_addr.s_addr;
70191+ ip_port = ntohs(addr->sin_port);
70192+
70193+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70194+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70195+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
70196+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
70197+ gr_to_filename(current->exec_file->f_path.dentry,
70198+ current->exec_file->f_path.mnt) :
70199+ curr->filename, curr->filename,
70200+ &ip_addr, ip_port, type,
70201+ sk->sk_protocol, mode, &current->signal->saved_ip);
70202+ return 0;
70203+ }
70204+
70205+ for (i = 0; i < curr->ip_num; i++) {
70206+ ip = *(curr->ips + i);
70207+ if (ip->iface != NULL) {
70208+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
70209+ p = strchr(iface, ':');
70210+ if (p != NULL)
70211+ *p = '\0';
70212+ dev = dev_get_by_name(sock_net(sk), iface);
70213+ if (dev == NULL)
70214+ continue;
70215+ idev = in_dev_get(dev);
70216+ if (idev == NULL) {
70217+ dev_put(dev);
70218+ continue;
70219+ }
70220+ rcu_read_lock();
70221+ for_ifa(idev) {
70222+ if (!strcmp(ip->iface, ifa->ifa_label)) {
70223+ our_addr = ifa->ifa_address;
70224+ our_netmask = 0xffffffff;
70225+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70226+ if (ret == 1) {
70227+ rcu_read_unlock();
70228+ in_dev_put(idev);
70229+ dev_put(dev);
70230+ return 0;
70231+ } else if (ret == 2) {
70232+ rcu_read_unlock();
70233+ in_dev_put(idev);
70234+ dev_put(dev);
70235+ goto denied;
70236+ }
70237+ }
70238+ } endfor_ifa(idev);
70239+ rcu_read_unlock();
70240+ in_dev_put(idev);
70241+ dev_put(dev);
70242+ } else {
70243+ our_addr = ip->addr;
70244+ our_netmask = ip->netmask;
70245+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70246+ if (ret == 1)
70247+ return 0;
70248+ else if (ret == 2)
70249+ goto denied;
70250+ }
70251+ }
70252+
70253+denied:
70254+ if (mode == GR_BIND)
70255+ 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));
70256+ else if (mode == GR_CONNECT)
70257+ 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));
70258+
70259+ return -EACCES;
70260+}
70261+
70262+int
70263+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70264+{
70265+ /* always allow disconnection of dgram sockets with connect */
70266+ if (addr->sin_family == AF_UNSPEC)
70267+ return 0;
70268+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70269+}
70270+
70271+int
70272+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70273+{
70274+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70275+}
70276+
70277+int gr_search_listen(struct socket *sock)
70278+{
70279+ struct sock *sk = sock->sk;
70280+ struct sockaddr_in addr;
70281+
70282+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70283+ addr.sin_port = inet_sk(sk)->inet_sport;
70284+
70285+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70286+}
70287+
70288+int gr_search_accept(struct socket *sock)
70289+{
70290+ struct sock *sk = sock->sk;
70291+ struct sockaddr_in addr;
70292+
70293+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70294+ addr.sin_port = inet_sk(sk)->inet_sport;
70295+
70296+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70297+}
70298+
70299+int
70300+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70301+{
70302+ if (addr)
70303+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70304+ else {
70305+ struct sockaddr_in sin;
70306+ const struct inet_sock *inet = inet_sk(sk);
70307+
70308+ sin.sin_addr.s_addr = inet->inet_daddr;
70309+ sin.sin_port = inet->inet_dport;
70310+
70311+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70312+ }
70313+}
70314+
70315+int
70316+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
70317+{
70318+ struct sockaddr_in sin;
70319+
70320+ if (unlikely(skb->len < sizeof (struct udphdr)))
70321+ return 0; // skip this packet
70322+
70323+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
70324+ sin.sin_port = udp_hdr(skb)->source;
70325+
70326+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70327+}
70328diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
70329new file mode 100644
70330index 0000000..25f54ef
70331--- /dev/null
70332+++ b/grsecurity/gracl_learn.c
70333@@ -0,0 +1,207 @@
70334+#include <linux/kernel.h>
70335+#include <linux/mm.h>
70336+#include <linux/sched.h>
70337+#include <linux/poll.h>
70338+#include <linux/string.h>
70339+#include <linux/file.h>
70340+#include <linux/types.h>
70341+#include <linux/vmalloc.h>
70342+#include <linux/grinternal.h>
70343+
70344+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
70345+ size_t count, loff_t *ppos);
70346+extern int gr_acl_is_enabled(void);
70347+
70348+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
70349+static int gr_learn_attached;
70350+
70351+/* use a 512k buffer */
70352+#define LEARN_BUFFER_SIZE (512 * 1024)
70353+
70354+static DEFINE_SPINLOCK(gr_learn_lock);
70355+static DEFINE_MUTEX(gr_learn_user_mutex);
70356+
70357+/* we need to maintain two buffers, so that the kernel context of grlearn
70358+ uses a semaphore around the userspace copying, and the other kernel contexts
70359+ use a spinlock when copying into the buffer, since they cannot sleep
70360+*/
70361+static char *learn_buffer;
70362+static char *learn_buffer_user;
70363+static int learn_buffer_len;
70364+static int learn_buffer_user_len;
70365+
70366+static ssize_t
70367+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
70368+{
70369+ DECLARE_WAITQUEUE(wait, current);
70370+ ssize_t retval = 0;
70371+
70372+ add_wait_queue(&learn_wait, &wait);
70373+ set_current_state(TASK_INTERRUPTIBLE);
70374+ do {
70375+ mutex_lock(&gr_learn_user_mutex);
70376+ spin_lock(&gr_learn_lock);
70377+ if (learn_buffer_len)
70378+ break;
70379+ spin_unlock(&gr_learn_lock);
70380+ mutex_unlock(&gr_learn_user_mutex);
70381+ if (file->f_flags & O_NONBLOCK) {
70382+ retval = -EAGAIN;
70383+ goto out;
70384+ }
70385+ if (signal_pending(current)) {
70386+ retval = -ERESTARTSYS;
70387+ goto out;
70388+ }
70389+
70390+ schedule();
70391+ } while (1);
70392+
70393+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
70394+ learn_buffer_user_len = learn_buffer_len;
70395+ retval = learn_buffer_len;
70396+ learn_buffer_len = 0;
70397+
70398+ spin_unlock(&gr_learn_lock);
70399+
70400+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
70401+ retval = -EFAULT;
70402+
70403+ mutex_unlock(&gr_learn_user_mutex);
70404+out:
70405+ set_current_state(TASK_RUNNING);
70406+ remove_wait_queue(&learn_wait, &wait);
70407+ return retval;
70408+}
70409+
70410+static unsigned int
70411+poll_learn(struct file * file, poll_table * wait)
70412+{
70413+ poll_wait(file, &learn_wait, wait);
70414+
70415+ if (learn_buffer_len)
70416+ return (POLLIN | POLLRDNORM);
70417+
70418+ return 0;
70419+}
70420+
70421+void
70422+gr_clear_learn_entries(void)
70423+{
70424+ char *tmp;
70425+
70426+ mutex_lock(&gr_learn_user_mutex);
70427+ spin_lock(&gr_learn_lock);
70428+ tmp = learn_buffer;
70429+ learn_buffer = NULL;
70430+ spin_unlock(&gr_learn_lock);
70431+ if (tmp)
70432+ vfree(tmp);
70433+ if (learn_buffer_user != NULL) {
70434+ vfree(learn_buffer_user);
70435+ learn_buffer_user = NULL;
70436+ }
70437+ learn_buffer_len = 0;
70438+ mutex_unlock(&gr_learn_user_mutex);
70439+
70440+ return;
70441+}
70442+
70443+void
70444+gr_add_learn_entry(const char *fmt, ...)
70445+{
70446+ va_list args;
70447+ unsigned int len;
70448+
70449+ if (!gr_learn_attached)
70450+ return;
70451+
70452+ spin_lock(&gr_learn_lock);
70453+
70454+ /* leave a gap at the end so we know when it's "full" but don't have to
70455+ compute the exact length of the string we're trying to append
70456+ */
70457+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
70458+ spin_unlock(&gr_learn_lock);
70459+ wake_up_interruptible(&learn_wait);
70460+ return;
70461+ }
70462+ if (learn_buffer == NULL) {
70463+ spin_unlock(&gr_learn_lock);
70464+ return;
70465+ }
70466+
70467+ va_start(args, fmt);
70468+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
70469+ va_end(args);
70470+
70471+ learn_buffer_len += len + 1;
70472+
70473+ spin_unlock(&gr_learn_lock);
70474+ wake_up_interruptible(&learn_wait);
70475+
70476+ return;
70477+}
70478+
70479+static int
70480+open_learn(struct inode *inode, struct file *file)
70481+{
70482+ if (file->f_mode & FMODE_READ && gr_learn_attached)
70483+ return -EBUSY;
70484+ if (file->f_mode & FMODE_READ) {
70485+ int retval = 0;
70486+ mutex_lock(&gr_learn_user_mutex);
70487+ if (learn_buffer == NULL)
70488+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
70489+ if (learn_buffer_user == NULL)
70490+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
70491+ if (learn_buffer == NULL) {
70492+ retval = -ENOMEM;
70493+ goto out_error;
70494+ }
70495+ if (learn_buffer_user == NULL) {
70496+ retval = -ENOMEM;
70497+ goto out_error;
70498+ }
70499+ learn_buffer_len = 0;
70500+ learn_buffer_user_len = 0;
70501+ gr_learn_attached = 1;
70502+out_error:
70503+ mutex_unlock(&gr_learn_user_mutex);
70504+ return retval;
70505+ }
70506+ return 0;
70507+}
70508+
70509+static int
70510+close_learn(struct inode *inode, struct file *file)
70511+{
70512+ if (file->f_mode & FMODE_READ) {
70513+ char *tmp = NULL;
70514+ mutex_lock(&gr_learn_user_mutex);
70515+ spin_lock(&gr_learn_lock);
70516+ tmp = learn_buffer;
70517+ learn_buffer = NULL;
70518+ spin_unlock(&gr_learn_lock);
70519+ if (tmp)
70520+ vfree(tmp);
70521+ if (learn_buffer_user != NULL) {
70522+ vfree(learn_buffer_user);
70523+ learn_buffer_user = NULL;
70524+ }
70525+ learn_buffer_len = 0;
70526+ learn_buffer_user_len = 0;
70527+ gr_learn_attached = 0;
70528+ mutex_unlock(&gr_learn_user_mutex);
70529+ }
70530+
70531+ return 0;
70532+}
70533+
70534+const struct file_operations grsec_fops = {
70535+ .read = read_learn,
70536+ .write = write_grsec_handler,
70537+ .open = open_learn,
70538+ .release = close_learn,
70539+ .poll = poll_learn,
70540+};
70541diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
70542new file mode 100644
70543index 0000000..361a099
70544--- /dev/null
70545+++ b/grsecurity/gracl_policy.c
70546@@ -0,0 +1,1782 @@
70547+#include <linux/kernel.h>
70548+#include <linux/module.h>
70549+#include <linux/sched.h>
70550+#include <linux/mm.h>
70551+#include <linux/file.h>
70552+#include <linux/fs.h>
70553+#include <linux/namei.h>
70554+#include <linux/mount.h>
70555+#include <linux/tty.h>
70556+#include <linux/proc_fs.h>
70557+#include <linux/lglock.h>
70558+#include <linux/slab.h>
70559+#include <linux/vmalloc.h>
70560+#include <linux/types.h>
70561+#include <linux/sysctl.h>
70562+#include <linux/netdevice.h>
70563+#include <linux/ptrace.h>
70564+#include <linux/gracl.h>
70565+#include <linux/gralloc.h>
70566+#include <linux/security.h>
70567+#include <linux/grinternal.h>
70568+#include <linux/pid_namespace.h>
70569+#include <linux/stop_machine.h>
70570+#include <linux/fdtable.h>
70571+#include <linux/percpu.h>
70572+#include <linux/lglock.h>
70573+#include <linux/hugetlb.h>
70574+#include <linux/posix-timers.h>
70575+#include "../fs/mount.h"
70576+
70577+#include <asm/uaccess.h>
70578+#include <asm/errno.h>
70579+#include <asm/mman.h>
70580+
70581+extern struct gr_policy_state *polstate;
70582+
70583+#define FOR_EACH_ROLE_START(role) \
70584+ role = polstate->role_list; \
70585+ while (role) {
70586+
70587+#define FOR_EACH_ROLE_END(role) \
70588+ role = role->prev; \
70589+ }
70590+
70591+struct path gr_real_root;
70592+
70593+extern struct gr_alloc_state *current_alloc_state;
70594+
70595+u16 acl_sp_role_value;
70596+
70597+static DEFINE_MUTEX(gr_dev_mutex);
70598+
70599+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
70600+extern void gr_clear_learn_entries(void);
70601+
70602+static struct gr_arg gr_usermode;
70603+static unsigned char gr_system_salt[GR_SALT_LEN];
70604+static unsigned char gr_system_sum[GR_SHA_LEN];
70605+
70606+static unsigned int gr_auth_attempts = 0;
70607+static unsigned long gr_auth_expires = 0UL;
70608+
70609+struct acl_object_label *fakefs_obj_rw;
70610+struct acl_object_label *fakefs_obj_rwx;
70611+
70612+extern int gr_init_uidset(void);
70613+extern void gr_free_uidset(void);
70614+extern void gr_remove_uid(uid_t uid);
70615+extern int gr_find_uid(uid_t uid);
70616+
70617+extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
70618+extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
70619+extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
70620+extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
70621+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);
70622+extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
70623+extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
70624+extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
70625+extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
70626+extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70627+extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
70628+extern void assign_special_role(const char *rolename);
70629+extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
70630+extern int gr_rbac_disable(void *unused);
70631+extern void gr_enable_rbac_system(void);
70632+
70633+static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
70634+{
70635+ if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
70636+ return -EFAULT;
70637+
70638+ return 0;
70639+}
70640+
70641+static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70642+{
70643+ if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
70644+ return -EFAULT;
70645+
70646+ return 0;
70647+}
70648+
70649+static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
70650+{
70651+ if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
70652+ return -EFAULT;
70653+
70654+ return 0;
70655+}
70656+
70657+static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
70658+{
70659+ if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
70660+ return -EFAULT;
70661+
70662+ return 0;
70663+}
70664+
70665+static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70666+{
70667+ if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
70668+ return -EFAULT;
70669+
70670+ return 0;
70671+}
70672+
70673+static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70674+{
70675+ if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
70676+ return -EFAULT;
70677+
70678+ return 0;
70679+}
70680+
70681+static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70682+{
70683+ if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
70684+ return -EFAULT;
70685+
70686+ return 0;
70687+}
70688+
70689+static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
70690+{
70691+ if (copy_from_user(trans, userp, sizeof(struct role_transition)))
70692+ return -EFAULT;
70693+
70694+ return 0;
70695+}
70696+
70697+int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
70698+{
70699+ if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
70700+ return -EFAULT;
70701+
70702+ return 0;
70703+}
70704+
70705+static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
70706+{
70707+ if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
70708+ return -EFAULT;
70709+
70710+ if (((uwrap->version != GRSECURITY_VERSION) &&
70711+ (uwrap->version != 0x2901)) ||
70712+ (uwrap->size != sizeof(struct gr_arg)))
70713+ return -EINVAL;
70714+
70715+ return 0;
70716+}
70717+
70718+static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
70719+{
70720+ if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
70721+ return -EFAULT;
70722+
70723+ return 0;
70724+}
70725+
70726+static size_t get_gr_arg_wrapper_size_normal(void)
70727+{
70728+ return sizeof(struct gr_arg_wrapper);
70729+}
70730+
70731+#ifdef CONFIG_COMPAT
70732+extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
70733+extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
70734+extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
70735+extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
70736+extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
70737+extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
70738+extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
70739+extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
70740+extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
70741+extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
70742+extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
70743+extern size_t get_gr_arg_wrapper_size_compat(void);
70744+
70745+int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
70746+int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
70747+int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
70748+int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
70749+int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
70750+int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
70751+int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
70752+int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
70753+int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
70754+int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
70755+int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
70756+size_t (* get_gr_arg_wrapper_size)(void) __read_only;
70757+
70758+#else
70759+#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
70760+#define copy_gr_arg copy_gr_arg_normal
70761+#define copy_gr_hash_struct copy_gr_hash_struct_normal
70762+#define copy_acl_object_label copy_acl_object_label_normal
70763+#define copy_acl_subject_label copy_acl_subject_label_normal
70764+#define copy_acl_role_label copy_acl_role_label_normal
70765+#define copy_acl_ip_label copy_acl_ip_label_normal
70766+#define copy_pointer_from_array copy_pointer_from_array_normal
70767+#define copy_sprole_pw copy_sprole_pw_normal
70768+#define copy_role_transition copy_role_transition_normal
70769+#define copy_role_allowed_ip copy_role_allowed_ip_normal
70770+#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
70771+#endif
70772+
70773+static struct acl_subject_label *
70774+lookup_subject_map(const struct acl_subject_label *userp)
70775+{
70776+ unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
70777+ struct subject_map *match;
70778+
70779+ match = polstate->subj_map_set.s_hash[index];
70780+
70781+ while (match && match->user != userp)
70782+ match = match->next;
70783+
70784+ if (match != NULL)
70785+ return match->kernel;
70786+ else
70787+ return NULL;
70788+}
70789+
70790+static void
70791+insert_subj_map_entry(struct subject_map *subjmap)
70792+{
70793+ unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
70794+ struct subject_map **curr;
70795+
70796+ subjmap->prev = NULL;
70797+
70798+ curr = &polstate->subj_map_set.s_hash[index];
70799+ if (*curr != NULL)
70800+ (*curr)->prev = subjmap;
70801+
70802+ subjmap->next = *curr;
70803+ *curr = subjmap;
70804+
70805+ return;
70806+}
70807+
70808+static void
70809+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
70810+{
70811+ unsigned int index =
70812+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
70813+ struct acl_role_label **curr;
70814+ struct acl_role_label *tmp, *tmp2;
70815+
70816+ curr = &polstate->acl_role_set.r_hash[index];
70817+
70818+ /* simple case, slot is empty, just set it to our role */
70819+ if (*curr == NULL) {
70820+ *curr = role;
70821+ } else {
70822+ /* example:
70823+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
70824+ 2 -> 3
70825+ */
70826+ /* first check to see if we can already be reached via this slot */
70827+ tmp = *curr;
70828+ while (tmp && tmp != role)
70829+ tmp = tmp->next;
70830+ if (tmp == role) {
70831+ /* we don't need to add ourselves to this slot's chain */
70832+ return;
70833+ }
70834+ /* we need to add ourselves to this chain, two cases */
70835+ if (role->next == NULL) {
70836+ /* simple case, append the current chain to our role */
70837+ role->next = *curr;
70838+ *curr = role;
70839+ } else {
70840+ /* 1 -> 2 -> 3 -> 4
70841+ 2 -> 3 -> 4
70842+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
70843+ */
70844+ /* trickier case: walk our role's chain until we find
70845+ the role for the start of the current slot's chain */
70846+ tmp = role;
70847+ tmp2 = *curr;
70848+ while (tmp->next && tmp->next != tmp2)
70849+ tmp = tmp->next;
70850+ if (tmp->next == tmp2) {
70851+ /* from example above, we found 3, so just
70852+ replace this slot's chain with ours */
70853+ *curr = role;
70854+ } else {
70855+ /* we didn't find a subset of our role's chain
70856+ in the current slot's chain, so append their
70857+ chain to ours, and set us as the first role in
70858+ the slot's chain
70859+
70860+ we could fold this case with the case above,
70861+ but making it explicit for clarity
70862+ */
70863+ tmp->next = tmp2;
70864+ *curr = role;
70865+ }
70866+ }
70867+ }
70868+
70869+ return;
70870+}
70871+
70872+static void
70873+insert_acl_role_label(struct acl_role_label *role)
70874+{
70875+ int i;
70876+
70877+ if (polstate->role_list == NULL) {
70878+ polstate->role_list = role;
70879+ role->prev = NULL;
70880+ } else {
70881+ role->prev = polstate->role_list;
70882+ polstate->role_list = role;
70883+ }
70884+
70885+ /* used for hash chains */
70886+ role->next = NULL;
70887+
70888+ if (role->roletype & GR_ROLE_DOMAIN) {
70889+ for (i = 0; i < role->domain_child_num; i++)
70890+ __insert_acl_role_label(role, role->domain_children[i]);
70891+ } else
70892+ __insert_acl_role_label(role, role->uidgid);
70893+}
70894+
70895+static int
70896+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70897+{
70898+ struct name_entry **curr, *nentry;
70899+ struct inodev_entry *ientry;
70900+ unsigned int len = strlen(name);
70901+ unsigned int key = full_name_hash(name, len);
70902+ unsigned int index = key % polstate->name_set.n_size;
70903+
70904+ curr = &polstate->name_set.n_hash[index];
70905+
70906+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70907+ curr = &((*curr)->next);
70908+
70909+ if (*curr != NULL)
70910+ return 1;
70911+
70912+ nentry = acl_alloc(sizeof (struct name_entry));
70913+ if (nentry == NULL)
70914+ return 0;
70915+ ientry = acl_alloc(sizeof (struct inodev_entry));
70916+ if (ientry == NULL)
70917+ return 0;
70918+ ientry->nentry = nentry;
70919+
70920+ nentry->key = key;
70921+ nentry->name = name;
70922+ nentry->inode = inode;
70923+ nentry->device = device;
70924+ nentry->len = len;
70925+ nentry->deleted = deleted;
70926+
70927+ nentry->prev = NULL;
70928+ curr = &polstate->name_set.n_hash[index];
70929+ if (*curr != NULL)
70930+ (*curr)->prev = nentry;
70931+ nentry->next = *curr;
70932+ *curr = nentry;
70933+
70934+ /* insert us into the table searchable by inode/dev */
70935+ __insert_inodev_entry(polstate, ientry);
70936+
70937+ return 1;
70938+}
70939+
70940+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70941+
70942+static void *
70943+create_table(__u32 * len, int elementsize)
70944+{
70945+ unsigned int table_sizes[] = {
70946+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70947+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70948+ 4194301, 8388593, 16777213, 33554393, 67108859
70949+ };
70950+ void *newtable = NULL;
70951+ unsigned int pwr = 0;
70952+
70953+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70954+ table_sizes[pwr] <= *len)
70955+ pwr++;
70956+
70957+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70958+ return newtable;
70959+
70960+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70961+ newtable =
70962+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70963+ else
70964+ newtable = vmalloc(table_sizes[pwr] * elementsize);
70965+
70966+ *len = table_sizes[pwr];
70967+
70968+ return newtable;
70969+}
70970+
70971+static int
70972+init_variables(const struct gr_arg *arg, bool reload)
70973+{
70974+ struct task_struct *reaper = init_pid_ns.child_reaper;
70975+ unsigned int stacksize;
70976+
70977+ polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70978+ polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70979+ polstate->name_set.n_size = arg->role_db.num_objects;
70980+ polstate->inodev_set.i_size = arg->role_db.num_objects;
70981+
70982+ if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70983+ !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70984+ return 1;
70985+
70986+ if (!reload) {
70987+ if (!gr_init_uidset())
70988+ return 1;
70989+ }
70990+
70991+ /* set up the stack that holds allocation info */
70992+
70993+ stacksize = arg->role_db.num_pointers + 5;
70994+
70995+ if (!acl_alloc_stack_init(stacksize))
70996+ return 1;
70997+
70998+ if (!reload) {
70999+ /* grab reference for the real root dentry and vfsmount */
71000+ get_fs_root(reaper->fs, &gr_real_root);
71001+
71002+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71003+ 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);
71004+#endif
71005+
71006+ fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71007+ if (fakefs_obj_rw == NULL)
71008+ return 1;
71009+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71010+
71011+ fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71012+ if (fakefs_obj_rwx == NULL)
71013+ return 1;
71014+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71015+ }
71016+
71017+ polstate->subj_map_set.s_hash =
71018+ (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71019+ polstate->acl_role_set.r_hash =
71020+ (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71021+ polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71022+ polstate->inodev_set.i_hash =
71023+ (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71024+
71025+ if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71026+ !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71027+ return 1;
71028+
71029+ memset(polstate->subj_map_set.s_hash, 0,
71030+ sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71031+ memset(polstate->acl_role_set.r_hash, 0,
71032+ sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71033+ memset(polstate->name_set.n_hash, 0,
71034+ sizeof (struct name_entry *) * polstate->name_set.n_size);
71035+ memset(polstate->inodev_set.i_hash, 0,
71036+ sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71037+
71038+ return 0;
71039+}
71040+
71041+/* free information not needed after startup
71042+ currently contains user->kernel pointer mappings for subjects
71043+*/
71044+
71045+static void
71046+free_init_variables(void)
71047+{
71048+ __u32 i;
71049+
71050+ if (polstate->subj_map_set.s_hash) {
71051+ for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71052+ if (polstate->subj_map_set.s_hash[i]) {
71053+ kfree(polstate->subj_map_set.s_hash[i]);
71054+ polstate->subj_map_set.s_hash[i] = NULL;
71055+ }
71056+ }
71057+
71058+ if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71059+ PAGE_SIZE)
71060+ kfree(polstate->subj_map_set.s_hash);
71061+ else
71062+ vfree(polstate->subj_map_set.s_hash);
71063+ }
71064+
71065+ return;
71066+}
71067+
71068+static void
71069+free_variables(bool reload)
71070+{
71071+ struct acl_subject_label *s;
71072+ struct acl_role_label *r;
71073+ struct task_struct *task, *task2;
71074+ unsigned int x;
71075+
71076+ if (!reload) {
71077+ gr_clear_learn_entries();
71078+
71079+ read_lock(&tasklist_lock);
71080+ do_each_thread(task2, task) {
71081+ task->acl_sp_role = 0;
71082+ task->acl_role_id = 0;
71083+ task->inherited = 0;
71084+ task->acl = NULL;
71085+ task->role = NULL;
71086+ } while_each_thread(task2, task);
71087+ read_unlock(&tasklist_lock);
71088+
71089+ kfree(fakefs_obj_rw);
71090+ fakefs_obj_rw = NULL;
71091+ kfree(fakefs_obj_rwx);
71092+ fakefs_obj_rwx = NULL;
71093+
71094+ /* release the reference to the real root dentry and vfsmount */
71095+ path_put(&gr_real_root);
71096+ memset(&gr_real_root, 0, sizeof(gr_real_root));
71097+ }
71098+
71099+ /* free all object hash tables */
71100+
71101+ FOR_EACH_ROLE_START(r)
71102+ if (r->subj_hash == NULL)
71103+ goto next_role;
71104+ FOR_EACH_SUBJECT_START(r, s, x)
71105+ if (s->obj_hash == NULL)
71106+ break;
71107+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71108+ kfree(s->obj_hash);
71109+ else
71110+ vfree(s->obj_hash);
71111+ FOR_EACH_SUBJECT_END(s, x)
71112+ FOR_EACH_NESTED_SUBJECT_START(r, s)
71113+ if (s->obj_hash == NULL)
71114+ break;
71115+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71116+ kfree(s->obj_hash);
71117+ else
71118+ vfree(s->obj_hash);
71119+ FOR_EACH_NESTED_SUBJECT_END(s)
71120+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71121+ kfree(r->subj_hash);
71122+ else
71123+ vfree(r->subj_hash);
71124+ r->subj_hash = NULL;
71125+next_role:
71126+ FOR_EACH_ROLE_END(r)
71127+
71128+ acl_free_all();
71129+
71130+ if (polstate->acl_role_set.r_hash) {
71131+ if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71132+ PAGE_SIZE)
71133+ kfree(polstate->acl_role_set.r_hash);
71134+ else
71135+ vfree(polstate->acl_role_set.r_hash);
71136+ }
71137+ if (polstate->name_set.n_hash) {
71138+ if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71139+ PAGE_SIZE)
71140+ kfree(polstate->name_set.n_hash);
71141+ else
71142+ vfree(polstate->name_set.n_hash);
71143+ }
71144+
71145+ if (polstate->inodev_set.i_hash) {
71146+ if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71147+ PAGE_SIZE)
71148+ kfree(polstate->inodev_set.i_hash);
71149+ else
71150+ vfree(polstate->inodev_set.i_hash);
71151+ }
71152+
71153+ if (!reload)
71154+ gr_free_uidset();
71155+
71156+ memset(&polstate->name_set, 0, sizeof (struct name_db));
71157+ memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71158+ memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71159+ memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71160+
71161+ polstate->default_role = NULL;
71162+ polstate->kernel_role = NULL;
71163+ polstate->role_list = NULL;
71164+
71165+ return;
71166+}
71167+
71168+static struct acl_subject_label *
71169+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71170+
71171+static int alloc_and_copy_string(char **name, unsigned int maxlen)
71172+{
71173+ unsigned int len = strnlen_user(*name, maxlen);
71174+ char *tmp;
71175+
71176+ if (!len || len >= maxlen)
71177+ return -EINVAL;
71178+
71179+ if ((tmp = (char *) acl_alloc(len)) == NULL)
71180+ return -ENOMEM;
71181+
71182+ if (copy_from_user(tmp, *name, len))
71183+ return -EFAULT;
71184+
71185+ tmp[len-1] = '\0';
71186+ *name = tmp;
71187+
71188+ return 0;
71189+}
71190+
71191+static int
71192+copy_user_glob(struct acl_object_label *obj)
71193+{
71194+ struct acl_object_label *g_tmp, **guser;
71195+ int error;
71196+
71197+ if (obj->globbed == NULL)
71198+ return 0;
71199+
71200+ guser = &obj->globbed;
71201+ while (*guser) {
71202+ g_tmp = (struct acl_object_label *)
71203+ acl_alloc(sizeof (struct acl_object_label));
71204+ if (g_tmp == NULL)
71205+ return -ENOMEM;
71206+
71207+ if (copy_acl_object_label(g_tmp, *guser))
71208+ return -EFAULT;
71209+
71210+ error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71211+ if (error)
71212+ return error;
71213+
71214+ *guser = g_tmp;
71215+ guser = &(g_tmp->next);
71216+ }
71217+
71218+ return 0;
71219+}
71220+
71221+static int
71222+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71223+ struct acl_role_label *role)
71224+{
71225+ struct acl_object_label *o_tmp;
71226+ int ret;
71227+
71228+ while (userp) {
71229+ if ((o_tmp = (struct acl_object_label *)
71230+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
71231+ return -ENOMEM;
71232+
71233+ if (copy_acl_object_label(o_tmp, userp))
71234+ return -EFAULT;
71235+
71236+ userp = o_tmp->prev;
71237+
71238+ ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71239+ if (ret)
71240+ return ret;
71241+
71242+ insert_acl_obj_label(o_tmp, subj);
71243+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71244+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71245+ return -ENOMEM;
71246+
71247+ ret = copy_user_glob(o_tmp);
71248+ if (ret)
71249+ return ret;
71250+
71251+ if (o_tmp->nested) {
71252+ int already_copied;
71253+
71254+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71255+ if (IS_ERR(o_tmp->nested))
71256+ return PTR_ERR(o_tmp->nested);
71257+
71258+ /* insert into nested subject list if we haven't copied this one yet
71259+ to prevent duplicate entries */
71260+ if (!already_copied) {
71261+ o_tmp->nested->next = role->hash->first;
71262+ role->hash->first = o_tmp->nested;
71263+ }
71264+ }
71265+ }
71266+
71267+ return 0;
71268+}
71269+
71270+static __u32
71271+count_user_subjs(struct acl_subject_label *userp)
71272+{
71273+ struct acl_subject_label s_tmp;
71274+ __u32 num = 0;
71275+
71276+ while (userp) {
71277+ if (copy_acl_subject_label(&s_tmp, userp))
71278+ break;
71279+
71280+ userp = s_tmp.prev;
71281+ }
71282+
71283+ return num;
71284+}
71285+
71286+static int
71287+copy_user_allowedips(struct acl_role_label *rolep)
71288+{
71289+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71290+
71291+ ruserip = rolep->allowed_ips;
71292+
71293+ while (ruserip) {
71294+ rlast = rtmp;
71295+
71296+ if ((rtmp = (struct role_allowed_ip *)
71297+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71298+ return -ENOMEM;
71299+
71300+ if (copy_role_allowed_ip(rtmp, ruserip))
71301+ return -EFAULT;
71302+
71303+ ruserip = rtmp->prev;
71304+
71305+ if (!rlast) {
71306+ rtmp->prev = NULL;
71307+ rolep->allowed_ips = rtmp;
71308+ } else {
71309+ rlast->next = rtmp;
71310+ rtmp->prev = rlast;
71311+ }
71312+
71313+ if (!ruserip)
71314+ rtmp->next = NULL;
71315+ }
71316+
71317+ return 0;
71318+}
71319+
71320+static int
71321+copy_user_transitions(struct acl_role_label *rolep)
71322+{
71323+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
71324+ int error;
71325+
71326+ rusertp = rolep->transitions;
71327+
71328+ while (rusertp) {
71329+ rlast = rtmp;
71330+
71331+ if ((rtmp = (struct role_transition *)
71332+ acl_alloc(sizeof (struct role_transition))) == NULL)
71333+ return -ENOMEM;
71334+
71335+ if (copy_role_transition(rtmp, rusertp))
71336+ return -EFAULT;
71337+
71338+ rusertp = rtmp->prev;
71339+
71340+ error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
71341+ if (error)
71342+ return error;
71343+
71344+ if (!rlast) {
71345+ rtmp->prev = NULL;
71346+ rolep->transitions = rtmp;
71347+ } else {
71348+ rlast->next = rtmp;
71349+ rtmp->prev = rlast;
71350+ }
71351+
71352+ if (!rusertp)
71353+ rtmp->next = NULL;
71354+ }
71355+
71356+ return 0;
71357+}
71358+
71359+static __u32 count_user_objs(const struct acl_object_label __user *userp)
71360+{
71361+ struct acl_object_label o_tmp;
71362+ __u32 num = 0;
71363+
71364+ while (userp) {
71365+ if (copy_acl_object_label(&o_tmp, userp))
71366+ break;
71367+
71368+ userp = o_tmp.prev;
71369+ num++;
71370+ }
71371+
71372+ return num;
71373+}
71374+
71375+static struct acl_subject_label *
71376+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
71377+{
71378+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
71379+ __u32 num_objs;
71380+ struct acl_ip_label **i_tmp, *i_utmp2;
71381+ struct gr_hash_struct ghash;
71382+ struct subject_map *subjmap;
71383+ unsigned int i_num;
71384+ int err;
71385+
71386+ if (already_copied != NULL)
71387+ *already_copied = 0;
71388+
71389+ s_tmp = lookup_subject_map(userp);
71390+
71391+ /* we've already copied this subject into the kernel, just return
71392+ the reference to it, and don't copy it over again
71393+ */
71394+ if (s_tmp) {
71395+ if (already_copied != NULL)
71396+ *already_copied = 1;
71397+ return(s_tmp);
71398+ }
71399+
71400+ if ((s_tmp = (struct acl_subject_label *)
71401+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
71402+ return ERR_PTR(-ENOMEM);
71403+
71404+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
71405+ if (subjmap == NULL)
71406+ return ERR_PTR(-ENOMEM);
71407+
71408+ subjmap->user = userp;
71409+ subjmap->kernel = s_tmp;
71410+ insert_subj_map_entry(subjmap);
71411+
71412+ if (copy_acl_subject_label(s_tmp, userp))
71413+ return ERR_PTR(-EFAULT);
71414+
71415+ err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
71416+ if (err)
71417+ return ERR_PTR(err);
71418+
71419+ if (!strcmp(s_tmp->filename, "/"))
71420+ role->root_label = s_tmp;
71421+
71422+ if (copy_gr_hash_struct(&ghash, s_tmp->hash))
71423+ return ERR_PTR(-EFAULT);
71424+
71425+ /* copy user and group transition tables */
71426+
71427+ if (s_tmp->user_trans_num) {
71428+ uid_t *uidlist;
71429+
71430+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
71431+ if (uidlist == NULL)
71432+ return ERR_PTR(-ENOMEM);
71433+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
71434+ return ERR_PTR(-EFAULT);
71435+
71436+ s_tmp->user_transitions = uidlist;
71437+ }
71438+
71439+ if (s_tmp->group_trans_num) {
71440+ gid_t *gidlist;
71441+
71442+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
71443+ if (gidlist == NULL)
71444+ return ERR_PTR(-ENOMEM);
71445+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
71446+ return ERR_PTR(-EFAULT);
71447+
71448+ s_tmp->group_transitions = gidlist;
71449+ }
71450+
71451+ /* set up object hash table */
71452+ num_objs = count_user_objs(ghash.first);
71453+
71454+ s_tmp->obj_hash_size = num_objs;
71455+ s_tmp->obj_hash =
71456+ (struct acl_object_label **)
71457+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
71458+
71459+ if (!s_tmp->obj_hash)
71460+ return ERR_PTR(-ENOMEM);
71461+
71462+ memset(s_tmp->obj_hash, 0,
71463+ s_tmp->obj_hash_size *
71464+ sizeof (struct acl_object_label *));
71465+
71466+ /* add in objects */
71467+ err = copy_user_objs(ghash.first, s_tmp, role);
71468+
71469+ if (err)
71470+ return ERR_PTR(err);
71471+
71472+ /* set pointer for parent subject */
71473+ if (s_tmp->parent_subject) {
71474+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
71475+
71476+ if (IS_ERR(s_tmp2))
71477+ return s_tmp2;
71478+
71479+ s_tmp->parent_subject = s_tmp2;
71480+ }
71481+
71482+ /* add in ip acls */
71483+
71484+ if (!s_tmp->ip_num) {
71485+ s_tmp->ips = NULL;
71486+ goto insert;
71487+ }
71488+
71489+ i_tmp =
71490+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
71491+ sizeof (struct acl_ip_label *));
71492+
71493+ if (!i_tmp)
71494+ return ERR_PTR(-ENOMEM);
71495+
71496+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
71497+ *(i_tmp + i_num) =
71498+ (struct acl_ip_label *)
71499+ acl_alloc(sizeof (struct acl_ip_label));
71500+ if (!*(i_tmp + i_num))
71501+ return ERR_PTR(-ENOMEM);
71502+
71503+ if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
71504+ return ERR_PTR(-EFAULT);
71505+
71506+ if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
71507+ return ERR_PTR(-EFAULT);
71508+
71509+ if ((*(i_tmp + i_num))->iface == NULL)
71510+ continue;
71511+
71512+ err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
71513+ if (err)
71514+ return ERR_PTR(err);
71515+ }
71516+
71517+ s_tmp->ips = i_tmp;
71518+
71519+insert:
71520+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
71521+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
71522+ return ERR_PTR(-ENOMEM);
71523+
71524+ return s_tmp;
71525+}
71526+
71527+static int
71528+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
71529+{
71530+ struct acl_subject_label s_pre;
71531+ struct acl_subject_label * ret;
71532+ int err;
71533+
71534+ while (userp) {
71535+ if (copy_acl_subject_label(&s_pre, userp))
71536+ return -EFAULT;
71537+
71538+ ret = do_copy_user_subj(userp, role, NULL);
71539+
71540+ err = PTR_ERR(ret);
71541+ if (IS_ERR(ret))
71542+ return err;
71543+
71544+ insert_acl_subj_label(ret, role);
71545+
71546+ userp = s_pre.prev;
71547+ }
71548+
71549+ return 0;
71550+}
71551+
71552+static int
71553+copy_user_acl(struct gr_arg *arg)
71554+{
71555+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
71556+ struct acl_subject_label *subj_list;
71557+ struct sprole_pw *sptmp;
71558+ struct gr_hash_struct *ghash;
71559+ uid_t *domainlist;
71560+ unsigned int r_num;
71561+ int err = 0;
71562+ __u16 i;
71563+ __u32 num_subjs;
71564+
71565+ /* we need a default and kernel role */
71566+ if (arg->role_db.num_roles < 2)
71567+ return -EINVAL;
71568+
71569+ /* copy special role authentication info from userspace */
71570+
71571+ polstate->num_sprole_pws = arg->num_sprole_pws;
71572+ polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
71573+
71574+ if (!polstate->acl_special_roles && polstate->num_sprole_pws)
71575+ return -ENOMEM;
71576+
71577+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71578+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
71579+ if (!sptmp)
71580+ return -ENOMEM;
71581+ if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
71582+ return -EFAULT;
71583+
71584+ err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
71585+ if (err)
71586+ return err;
71587+
71588+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71589+ printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
71590+#endif
71591+
71592+ polstate->acl_special_roles[i] = sptmp;
71593+ }
71594+
71595+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
71596+
71597+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
71598+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
71599+
71600+ if (!r_tmp)
71601+ return -ENOMEM;
71602+
71603+ if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
71604+ return -EFAULT;
71605+
71606+ if (copy_acl_role_label(r_tmp, r_utmp2))
71607+ return -EFAULT;
71608+
71609+ err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
71610+ if (err)
71611+ return err;
71612+
71613+ if (!strcmp(r_tmp->rolename, "default")
71614+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
71615+ polstate->default_role = r_tmp;
71616+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
71617+ polstate->kernel_role = r_tmp;
71618+ }
71619+
71620+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
71621+ return -ENOMEM;
71622+
71623+ if (copy_gr_hash_struct(ghash, r_tmp->hash))
71624+ return -EFAULT;
71625+
71626+ r_tmp->hash = ghash;
71627+
71628+ num_subjs = count_user_subjs(r_tmp->hash->first);
71629+
71630+ r_tmp->subj_hash_size = num_subjs;
71631+ r_tmp->subj_hash =
71632+ (struct acl_subject_label **)
71633+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
71634+
71635+ if (!r_tmp->subj_hash)
71636+ return -ENOMEM;
71637+
71638+ err = copy_user_allowedips(r_tmp);
71639+ if (err)
71640+ return err;
71641+
71642+ /* copy domain info */
71643+ if (r_tmp->domain_children != NULL) {
71644+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
71645+ if (domainlist == NULL)
71646+ return -ENOMEM;
71647+
71648+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
71649+ return -EFAULT;
71650+
71651+ r_tmp->domain_children = domainlist;
71652+ }
71653+
71654+ err = copy_user_transitions(r_tmp);
71655+ if (err)
71656+ return err;
71657+
71658+ memset(r_tmp->subj_hash, 0,
71659+ r_tmp->subj_hash_size *
71660+ sizeof (struct acl_subject_label *));
71661+
71662+ /* acquire the list of subjects, then NULL out
71663+ the list prior to parsing the subjects for this role,
71664+ as during this parsing the list is replaced with a list
71665+ of *nested* subjects for the role
71666+ */
71667+ subj_list = r_tmp->hash->first;
71668+
71669+ /* set nested subject list to null */
71670+ r_tmp->hash->first = NULL;
71671+
71672+ err = copy_user_subjs(subj_list, r_tmp);
71673+
71674+ if (err)
71675+ return err;
71676+
71677+ insert_acl_role_label(r_tmp);
71678+ }
71679+
71680+ if (polstate->default_role == NULL || polstate->kernel_role == NULL)
71681+ return -EINVAL;
71682+
71683+ return err;
71684+}
71685+
71686+static int gracl_reload_apply_policies(void *reload)
71687+{
71688+ struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
71689+ struct task_struct *task, *task2;
71690+ struct acl_role_label *role, *rtmp;
71691+ struct acl_subject_label *subj;
71692+ const struct cred *cred;
71693+ int role_applied;
71694+ int ret = 0;
71695+
71696+ memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
71697+ memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
71698+
71699+ /* first make sure we'll be able to apply the new policy cleanly */
71700+ do_each_thread(task2, task) {
71701+ if (task->exec_file == NULL)
71702+ continue;
71703+ role_applied = 0;
71704+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71705+ /* preserve special roles */
71706+ FOR_EACH_ROLE_START(role)
71707+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71708+ rtmp = task->role;
71709+ task->role = role;
71710+ role_applied = 1;
71711+ break;
71712+ }
71713+ FOR_EACH_ROLE_END(role)
71714+ }
71715+ if (!role_applied) {
71716+ cred = __task_cred(task);
71717+ rtmp = task->role;
71718+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71719+ }
71720+ /* this handles non-nested inherited subjects, nested subjects will still
71721+ be dropped currently */
71722+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71723+ task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
71724+ /* change the role back so that we've made no modifications to the policy */
71725+ task->role = rtmp;
71726+
71727+ if (subj == NULL || task->tmpacl == NULL) {
71728+ ret = -EINVAL;
71729+ goto out;
71730+ }
71731+ } while_each_thread(task2, task);
71732+
71733+ /* now actually apply the policy */
71734+
71735+ do_each_thread(task2, task) {
71736+ if (task->exec_file) {
71737+ role_applied = 0;
71738+ if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
71739+ /* preserve special roles */
71740+ FOR_EACH_ROLE_START(role)
71741+ if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
71742+ task->role = role;
71743+ role_applied = 1;
71744+ break;
71745+ }
71746+ FOR_EACH_ROLE_END(role)
71747+ }
71748+ if (!role_applied) {
71749+ cred = __task_cred(task);
71750+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71751+ }
71752+ /* this handles non-nested inherited subjects, nested subjects will still
71753+ be dropped currently */
71754+ if (!reload_state->oldmode && task->inherited)
71755+ subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
71756+ else {
71757+ /* looked up and tagged to the task previously */
71758+ subj = task->tmpacl;
71759+ }
71760+ /* subj will be non-null */
71761+ __gr_apply_subject_to_task(polstate, task, subj);
71762+ if (reload_state->oldmode) {
71763+ task->acl_role_id = 0;
71764+ task->acl_sp_role = 0;
71765+ task->inherited = 0;
71766+ }
71767+ } else {
71768+ // it's a kernel process
71769+ task->role = polstate->kernel_role;
71770+ task->acl = polstate->kernel_role->root_label;
71771+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71772+ task->acl->mode &= ~GR_PROCFIND;
71773+#endif
71774+ }
71775+ } while_each_thread(task2, task);
71776+
71777+ memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
71778+ memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
71779+
71780+out:
71781+
71782+ return ret;
71783+}
71784+
71785+static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
71786+{
71787+ struct gr_reload_state new_reload_state = { };
71788+ int err;
71789+
71790+ new_reload_state.oldpolicy_ptr = polstate;
71791+ new_reload_state.oldalloc_ptr = current_alloc_state;
71792+ new_reload_state.oldmode = oldmode;
71793+
71794+ current_alloc_state = &new_reload_state.newalloc;
71795+ polstate = &new_reload_state.newpolicy;
71796+
71797+ /* everything relevant is now saved off, copy in the new policy */
71798+ if (init_variables(args, true)) {
71799+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71800+ err = -ENOMEM;
71801+ goto error;
71802+ }
71803+
71804+ err = copy_user_acl(args);
71805+ free_init_variables();
71806+ if (err)
71807+ goto error;
71808+ /* the new policy is copied in, with the old policy available via saved_state
71809+ first go through applying roles, making sure to preserve special roles
71810+ then apply new subjects, making sure to preserve inherited and nested subjects,
71811+ though currently only inherited subjects will be preserved
71812+ */
71813+ err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
71814+ if (err)
71815+ goto error;
71816+
71817+ /* we've now applied the new policy, so restore the old policy state to free it */
71818+ polstate = &new_reload_state.oldpolicy;
71819+ current_alloc_state = &new_reload_state.oldalloc;
71820+ free_variables(true);
71821+
71822+ /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
71823+ to running_polstate/current_alloc_state inside stop_machine
71824+ */
71825+ err = 0;
71826+ goto out;
71827+error:
71828+ /* on error of loading the new policy, we'll just keep the previous
71829+ policy set around
71830+ */
71831+ free_variables(true);
71832+
71833+ /* doesn't affect runtime, but maintains consistent state */
71834+out:
71835+ polstate = new_reload_state.oldpolicy_ptr;
71836+ current_alloc_state = new_reload_state.oldalloc_ptr;
71837+
71838+ return err;
71839+}
71840+
71841+static int
71842+gracl_init(struct gr_arg *args)
71843+{
71844+ int error = 0;
71845+
71846+ memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
71847+ memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
71848+
71849+ if (init_variables(args, false)) {
71850+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
71851+ error = -ENOMEM;
71852+ goto out;
71853+ }
71854+
71855+ error = copy_user_acl(args);
71856+ free_init_variables();
71857+ if (error)
71858+ goto out;
71859+
71860+ error = gr_set_acls(0);
71861+ if (error)
71862+ goto out;
71863+
71864+ gr_enable_rbac_system();
71865+
71866+ return 0;
71867+
71868+out:
71869+ free_variables(false);
71870+ return error;
71871+}
71872+
71873+static int
71874+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
71875+ unsigned char **sum)
71876+{
71877+ struct acl_role_label *r;
71878+ struct role_allowed_ip *ipp;
71879+ struct role_transition *trans;
71880+ unsigned int i;
71881+ int found = 0;
71882+ u32 curr_ip = current->signal->curr_ip;
71883+
71884+ current->signal->saved_ip = curr_ip;
71885+
71886+ /* check transition table */
71887+
71888+ for (trans = current->role->transitions; trans; trans = trans->next) {
71889+ if (!strcmp(rolename, trans->rolename)) {
71890+ found = 1;
71891+ break;
71892+ }
71893+ }
71894+
71895+ if (!found)
71896+ return 0;
71897+
71898+ /* handle special roles that do not require authentication
71899+ and check ip */
71900+
71901+ FOR_EACH_ROLE_START(r)
71902+ if (!strcmp(rolename, r->rolename) &&
71903+ (r->roletype & GR_ROLE_SPECIAL)) {
71904+ found = 0;
71905+ if (r->allowed_ips != NULL) {
71906+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71907+ if ((ntohl(curr_ip) & ipp->netmask) ==
71908+ (ntohl(ipp->addr) & ipp->netmask))
71909+ found = 1;
71910+ }
71911+ } else
71912+ found = 2;
71913+ if (!found)
71914+ return 0;
71915+
71916+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71917+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71918+ *salt = NULL;
71919+ *sum = NULL;
71920+ return 1;
71921+ }
71922+ }
71923+ FOR_EACH_ROLE_END(r)
71924+
71925+ for (i = 0; i < polstate->num_sprole_pws; i++) {
71926+ if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71927+ *salt = polstate->acl_special_roles[i]->salt;
71928+ *sum = polstate->acl_special_roles[i]->sum;
71929+ return 1;
71930+ }
71931+ }
71932+
71933+ return 0;
71934+}
71935+
71936+int gr_check_secure_terminal(struct task_struct *task)
71937+{
71938+ struct task_struct *p, *p2, *p3;
71939+ struct files_struct *files;
71940+ struct fdtable *fdt;
71941+ struct file *our_file = NULL, *file;
71942+ int i;
71943+
71944+ if (task->signal->tty == NULL)
71945+ return 1;
71946+
71947+ files = get_files_struct(task);
71948+ if (files != NULL) {
71949+ rcu_read_lock();
71950+ fdt = files_fdtable(files);
71951+ for (i=0; i < fdt->max_fds; i++) {
71952+ file = fcheck_files(files, i);
71953+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71954+ get_file(file);
71955+ our_file = file;
71956+ }
71957+ }
71958+ rcu_read_unlock();
71959+ put_files_struct(files);
71960+ }
71961+
71962+ if (our_file == NULL)
71963+ return 1;
71964+
71965+ read_lock(&tasklist_lock);
71966+ do_each_thread(p2, p) {
71967+ files = get_files_struct(p);
71968+ if (files == NULL ||
71969+ (p->signal && p->signal->tty == task->signal->tty)) {
71970+ if (files != NULL)
71971+ put_files_struct(files);
71972+ continue;
71973+ }
71974+ rcu_read_lock();
71975+ fdt = files_fdtable(files);
71976+ for (i=0; i < fdt->max_fds; i++) {
71977+ file = fcheck_files(files, i);
71978+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71979+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71980+ p3 = task;
71981+ while (task_pid_nr(p3) > 0) {
71982+ if (p3 == p)
71983+ break;
71984+ p3 = p3->real_parent;
71985+ }
71986+ if (p3 == p)
71987+ break;
71988+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71989+ gr_handle_alertkill(p);
71990+ rcu_read_unlock();
71991+ put_files_struct(files);
71992+ read_unlock(&tasklist_lock);
71993+ fput(our_file);
71994+ return 0;
71995+ }
71996+ }
71997+ rcu_read_unlock();
71998+ put_files_struct(files);
71999+ } while_each_thread(p2, p);
72000+ read_unlock(&tasklist_lock);
72001+
72002+ fput(our_file);
72003+ return 1;
72004+}
72005+
72006+ssize_t
72007+write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72008+{
72009+ struct gr_arg_wrapper uwrap;
72010+ unsigned char *sprole_salt = NULL;
72011+ unsigned char *sprole_sum = NULL;
72012+ int error = 0;
72013+ int error2 = 0;
72014+ size_t req_count = 0;
72015+ unsigned char oldmode = 0;
72016+
72017+ mutex_lock(&gr_dev_mutex);
72018+
72019+ if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72020+ error = -EPERM;
72021+ goto out;
72022+ }
72023+
72024+#ifdef CONFIG_COMPAT
72025+ pax_open_kernel();
72026+ if (is_compat_task()) {
72027+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72028+ copy_gr_arg = &copy_gr_arg_compat;
72029+ copy_acl_object_label = &copy_acl_object_label_compat;
72030+ copy_acl_subject_label = &copy_acl_subject_label_compat;
72031+ copy_acl_role_label = &copy_acl_role_label_compat;
72032+ copy_acl_ip_label = &copy_acl_ip_label_compat;
72033+ copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72034+ copy_role_transition = &copy_role_transition_compat;
72035+ copy_sprole_pw = &copy_sprole_pw_compat;
72036+ copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72037+ copy_pointer_from_array = &copy_pointer_from_array_compat;
72038+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72039+ } else {
72040+ copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72041+ copy_gr_arg = &copy_gr_arg_normal;
72042+ copy_acl_object_label = &copy_acl_object_label_normal;
72043+ copy_acl_subject_label = &copy_acl_subject_label_normal;
72044+ copy_acl_role_label = &copy_acl_role_label_normal;
72045+ copy_acl_ip_label = &copy_acl_ip_label_normal;
72046+ copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72047+ copy_role_transition = &copy_role_transition_normal;
72048+ copy_sprole_pw = &copy_sprole_pw_normal;
72049+ copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72050+ copy_pointer_from_array = &copy_pointer_from_array_normal;
72051+ get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72052+ }
72053+ pax_close_kernel();
72054+#endif
72055+
72056+ req_count = get_gr_arg_wrapper_size();
72057+
72058+ if (count != req_count) {
72059+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72060+ error = -EINVAL;
72061+ goto out;
72062+ }
72063+
72064+
72065+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72066+ gr_auth_expires = 0;
72067+ gr_auth_attempts = 0;
72068+ }
72069+
72070+ error = copy_gr_arg_wrapper(buf, &uwrap);
72071+ if (error)
72072+ goto out;
72073+
72074+ error = copy_gr_arg(uwrap.arg, &gr_usermode);
72075+ if (error)
72076+ goto out;
72077+
72078+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72079+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72080+ time_after(gr_auth_expires, get_seconds())) {
72081+ error = -EBUSY;
72082+ goto out;
72083+ }
72084+
72085+ /* if non-root trying to do anything other than use a special role,
72086+ do not attempt authentication, do not count towards authentication
72087+ locking
72088+ */
72089+
72090+ if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72091+ gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72092+ gr_is_global_nonroot(current_uid())) {
72093+ error = -EPERM;
72094+ goto out;
72095+ }
72096+
72097+ /* ensure pw and special role name are null terminated */
72098+
72099+ gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72100+ gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72101+
72102+ /* Okay.
72103+ * We have our enough of the argument structure..(we have yet
72104+ * to copy_from_user the tables themselves) . Copy the tables
72105+ * only if we need them, i.e. for loading operations. */
72106+
72107+ switch (gr_usermode.mode) {
72108+ case GR_STATUS:
72109+ if (gr_acl_is_enabled()) {
72110+ error = 1;
72111+ if (!gr_check_secure_terminal(current))
72112+ error = 3;
72113+ } else
72114+ error = 2;
72115+ goto out;
72116+ case GR_SHUTDOWN:
72117+ if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72118+ stop_machine(gr_rbac_disable, NULL, NULL);
72119+ free_variables(false);
72120+ memset(&gr_usermode, 0, sizeof(gr_usermode));
72121+ memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72122+ memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72123+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72124+ } else if (gr_acl_is_enabled()) {
72125+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72126+ error = -EPERM;
72127+ } else {
72128+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72129+ error = -EAGAIN;
72130+ }
72131+ break;
72132+ case GR_ENABLE:
72133+ if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72134+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72135+ else {
72136+ if (gr_acl_is_enabled())
72137+ error = -EAGAIN;
72138+ else
72139+ error = error2;
72140+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72141+ }
72142+ break;
72143+ case GR_OLDRELOAD:
72144+ oldmode = 1;
72145+ case GR_RELOAD:
72146+ if (!gr_acl_is_enabled()) {
72147+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72148+ error = -EAGAIN;
72149+ } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72150+ error2 = gracl_reload(&gr_usermode, oldmode);
72151+ if (!error2)
72152+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72153+ else {
72154+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72155+ error = error2;
72156+ }
72157+ } else {
72158+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72159+ error = -EPERM;
72160+ }
72161+ break;
72162+ case GR_SEGVMOD:
72163+ if (unlikely(!gr_acl_is_enabled())) {
72164+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72165+ error = -EAGAIN;
72166+ break;
72167+ }
72168+
72169+ if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72170+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72171+ if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72172+ struct acl_subject_label *segvacl;
72173+ segvacl =
72174+ lookup_acl_subj_label(gr_usermode.segv_inode,
72175+ gr_usermode.segv_device,
72176+ current->role);
72177+ if (segvacl) {
72178+ segvacl->crashes = 0;
72179+ segvacl->expires = 0;
72180+ }
72181+ } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72182+ gr_remove_uid(gr_usermode.segv_uid);
72183+ }
72184+ } else {
72185+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72186+ error = -EPERM;
72187+ }
72188+ break;
72189+ case GR_SPROLE:
72190+ case GR_SPROLEPAM:
72191+ if (unlikely(!gr_acl_is_enabled())) {
72192+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72193+ error = -EAGAIN;
72194+ break;
72195+ }
72196+
72197+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72198+ current->role->expires = 0;
72199+ current->role->auth_attempts = 0;
72200+ }
72201+
72202+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72203+ time_after(current->role->expires, get_seconds())) {
72204+ error = -EBUSY;
72205+ goto out;
72206+ }
72207+
72208+ if (lookup_special_role_auth
72209+ (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72210+ && ((!sprole_salt && !sprole_sum)
72211+ || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72212+ char *p = "";
72213+ assign_special_role(gr_usermode.sp_role);
72214+ read_lock(&tasklist_lock);
72215+ if (current->real_parent)
72216+ p = current->real_parent->role->rolename;
72217+ read_unlock(&tasklist_lock);
72218+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72219+ p, acl_sp_role_value);
72220+ } else {
72221+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72222+ error = -EPERM;
72223+ if(!(current->role->auth_attempts++))
72224+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72225+
72226+ goto out;
72227+ }
72228+ break;
72229+ case GR_UNSPROLE:
72230+ if (unlikely(!gr_acl_is_enabled())) {
72231+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72232+ error = -EAGAIN;
72233+ break;
72234+ }
72235+
72236+ if (current->role->roletype & GR_ROLE_SPECIAL) {
72237+ char *p = "";
72238+ int i = 0;
72239+
72240+ read_lock(&tasklist_lock);
72241+ if (current->real_parent) {
72242+ p = current->real_parent->role->rolename;
72243+ i = current->real_parent->acl_role_id;
72244+ }
72245+ read_unlock(&tasklist_lock);
72246+
72247+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72248+ gr_set_acls(1);
72249+ } else {
72250+ error = -EPERM;
72251+ goto out;
72252+ }
72253+ break;
72254+ default:
72255+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72256+ error = -EINVAL;
72257+ break;
72258+ }
72259+
72260+ if (error != -EPERM)
72261+ goto out;
72262+
72263+ if(!(gr_auth_attempts++))
72264+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72265+
72266+ out:
72267+ mutex_unlock(&gr_dev_mutex);
72268+
72269+ if (!error)
72270+ error = req_count;
72271+
72272+ return error;
72273+}
72274+
72275+int
72276+gr_set_acls(const int type)
72277+{
72278+ struct task_struct *task, *task2;
72279+ struct acl_role_label *role = current->role;
72280+ struct acl_subject_label *subj;
72281+ __u16 acl_role_id = current->acl_role_id;
72282+ const struct cred *cred;
72283+ int ret;
72284+
72285+ rcu_read_lock();
72286+ read_lock(&tasklist_lock);
72287+ read_lock(&grsec_exec_file_lock);
72288+ do_each_thread(task2, task) {
72289+ /* check to see if we're called from the exit handler,
72290+ if so, only replace ACLs that have inherited the admin
72291+ ACL */
72292+
72293+ if (type && (task->role != role ||
72294+ task->acl_role_id != acl_role_id))
72295+ continue;
72296+
72297+ task->acl_role_id = 0;
72298+ task->acl_sp_role = 0;
72299+ task->inherited = 0;
72300+
72301+ if (task->exec_file) {
72302+ cred = __task_cred(task);
72303+ task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72304+ subj = __gr_get_subject_for_task(polstate, task, NULL);
72305+ if (subj == NULL) {
72306+ ret = -EINVAL;
72307+ read_unlock(&grsec_exec_file_lock);
72308+ read_unlock(&tasklist_lock);
72309+ rcu_read_unlock();
72310+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72311+ return ret;
72312+ }
72313+ __gr_apply_subject_to_task(polstate, task, subj);
72314+ } else {
72315+ // it's a kernel process
72316+ task->role = polstate->kernel_role;
72317+ task->acl = polstate->kernel_role->root_label;
72318+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72319+ task->acl->mode &= ~GR_PROCFIND;
72320+#endif
72321+ }
72322+ } while_each_thread(task2, task);
72323+ read_unlock(&grsec_exec_file_lock);
72324+ read_unlock(&tasklist_lock);
72325+ rcu_read_unlock();
72326+
72327+ return 0;
72328+}
72329diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
72330new file mode 100644
72331index 0000000..39645c9
72332--- /dev/null
72333+++ b/grsecurity/gracl_res.c
72334@@ -0,0 +1,68 @@
72335+#include <linux/kernel.h>
72336+#include <linux/sched.h>
72337+#include <linux/gracl.h>
72338+#include <linux/grinternal.h>
72339+
72340+static const char *restab_log[] = {
72341+ [RLIMIT_CPU] = "RLIMIT_CPU",
72342+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
72343+ [RLIMIT_DATA] = "RLIMIT_DATA",
72344+ [RLIMIT_STACK] = "RLIMIT_STACK",
72345+ [RLIMIT_CORE] = "RLIMIT_CORE",
72346+ [RLIMIT_RSS] = "RLIMIT_RSS",
72347+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
72348+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
72349+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
72350+ [RLIMIT_AS] = "RLIMIT_AS",
72351+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
72352+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
72353+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
72354+ [RLIMIT_NICE] = "RLIMIT_NICE",
72355+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
72356+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
72357+ [GR_CRASH_RES] = "RLIMIT_CRASH"
72358+};
72359+
72360+void
72361+gr_log_resource(const struct task_struct *task,
72362+ const int res, const unsigned long wanted, const int gt)
72363+{
72364+ const struct cred *cred;
72365+ unsigned long rlim;
72366+
72367+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
72368+ return;
72369+
72370+ // not yet supported resource
72371+ if (unlikely(!restab_log[res]))
72372+ return;
72373+
72374+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
72375+ rlim = task_rlimit_max(task, res);
72376+ else
72377+ rlim = task_rlimit(task, res);
72378+
72379+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
72380+ return;
72381+
72382+ rcu_read_lock();
72383+ cred = __task_cred(task);
72384+
72385+ if (res == RLIMIT_NPROC &&
72386+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
72387+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
72388+ goto out_rcu_unlock;
72389+ else if (res == RLIMIT_MEMLOCK &&
72390+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
72391+ goto out_rcu_unlock;
72392+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
72393+ goto out_rcu_unlock;
72394+ rcu_read_unlock();
72395+
72396+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
72397+
72398+ return;
72399+out_rcu_unlock:
72400+ rcu_read_unlock();
72401+ return;
72402+}
72403diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
72404new file mode 100644
72405index 0000000..2040e61
72406--- /dev/null
72407+++ b/grsecurity/gracl_segv.c
72408@@ -0,0 +1,313 @@
72409+#include <linux/kernel.h>
72410+#include <linux/mm.h>
72411+#include <asm/uaccess.h>
72412+#include <asm/errno.h>
72413+#include <asm/mman.h>
72414+#include <net/sock.h>
72415+#include <linux/file.h>
72416+#include <linux/fs.h>
72417+#include <linux/net.h>
72418+#include <linux/in.h>
72419+#include <linux/slab.h>
72420+#include <linux/types.h>
72421+#include <linux/sched.h>
72422+#include <linux/timer.h>
72423+#include <linux/gracl.h>
72424+#include <linux/grsecurity.h>
72425+#include <linux/grinternal.h>
72426+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72427+#include <linux/magic.h>
72428+#include <linux/pagemap.h>
72429+#include "../fs/btrfs/async-thread.h"
72430+#include "../fs/btrfs/ctree.h"
72431+#include "../fs/btrfs/btrfs_inode.h"
72432+#endif
72433+
72434+static struct crash_uid *uid_set;
72435+static unsigned short uid_used;
72436+static DEFINE_SPINLOCK(gr_uid_lock);
72437+extern rwlock_t gr_inode_lock;
72438+extern struct acl_subject_label *
72439+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
72440+ struct acl_role_label *role);
72441+
72442+static inline dev_t __get_dev(const struct dentry *dentry)
72443+{
72444+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
72445+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
72446+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
72447+ else
72448+#endif
72449+ return dentry->d_sb->s_dev;
72450+}
72451+
72452+int
72453+gr_init_uidset(void)
72454+{
72455+ uid_set =
72456+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
72457+ uid_used = 0;
72458+
72459+ return uid_set ? 1 : 0;
72460+}
72461+
72462+void
72463+gr_free_uidset(void)
72464+{
72465+ if (uid_set) {
72466+ struct crash_uid *tmpset;
72467+ spin_lock(&gr_uid_lock);
72468+ tmpset = uid_set;
72469+ uid_set = NULL;
72470+ uid_used = 0;
72471+ spin_unlock(&gr_uid_lock);
72472+ if (tmpset)
72473+ kfree(tmpset);
72474+ }
72475+
72476+ return;
72477+}
72478+
72479+int
72480+gr_find_uid(const uid_t uid)
72481+{
72482+ struct crash_uid *tmp = uid_set;
72483+ uid_t buid;
72484+ int low = 0, high = uid_used - 1, mid;
72485+
72486+ while (high >= low) {
72487+ mid = (low + high) >> 1;
72488+ buid = tmp[mid].uid;
72489+ if (buid == uid)
72490+ return mid;
72491+ if (buid > uid)
72492+ high = mid - 1;
72493+ if (buid < uid)
72494+ low = mid + 1;
72495+ }
72496+
72497+ return -1;
72498+}
72499+
72500+static __inline__ void
72501+gr_insertsort(void)
72502+{
72503+ unsigned short i, j;
72504+ struct crash_uid index;
72505+
72506+ for (i = 1; i < uid_used; i++) {
72507+ index = uid_set[i];
72508+ j = i;
72509+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
72510+ uid_set[j] = uid_set[j - 1];
72511+ j--;
72512+ }
72513+ uid_set[j] = index;
72514+ }
72515+
72516+ return;
72517+}
72518+
72519+static __inline__ void
72520+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
72521+{
72522+ int loc;
72523+ uid_t uid = GR_GLOBAL_UID(kuid);
72524+
72525+ if (uid_used == GR_UIDTABLE_MAX)
72526+ return;
72527+
72528+ loc = gr_find_uid(uid);
72529+
72530+ if (loc >= 0) {
72531+ uid_set[loc].expires = expires;
72532+ return;
72533+ }
72534+
72535+ uid_set[uid_used].uid = uid;
72536+ uid_set[uid_used].expires = expires;
72537+ uid_used++;
72538+
72539+ gr_insertsort();
72540+
72541+ return;
72542+}
72543+
72544+void
72545+gr_remove_uid(const unsigned short loc)
72546+{
72547+ unsigned short i;
72548+
72549+ for (i = loc + 1; i < uid_used; i++)
72550+ uid_set[i - 1] = uid_set[i];
72551+
72552+ uid_used--;
72553+
72554+ return;
72555+}
72556+
72557+int
72558+gr_check_crash_uid(const kuid_t kuid)
72559+{
72560+ int loc;
72561+ int ret = 0;
72562+ uid_t uid;
72563+
72564+ if (unlikely(!gr_acl_is_enabled()))
72565+ return 0;
72566+
72567+ uid = GR_GLOBAL_UID(kuid);
72568+
72569+ spin_lock(&gr_uid_lock);
72570+ loc = gr_find_uid(uid);
72571+
72572+ if (loc < 0)
72573+ goto out_unlock;
72574+
72575+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
72576+ gr_remove_uid(loc);
72577+ else
72578+ ret = 1;
72579+
72580+out_unlock:
72581+ spin_unlock(&gr_uid_lock);
72582+ return ret;
72583+}
72584+
72585+static __inline__ int
72586+proc_is_setxid(const struct cred *cred)
72587+{
72588+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
72589+ !uid_eq(cred->uid, cred->fsuid))
72590+ return 1;
72591+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
72592+ !gid_eq(cred->gid, cred->fsgid))
72593+ return 1;
72594+
72595+ return 0;
72596+}
72597+
72598+extern int gr_fake_force_sig(int sig, struct task_struct *t);
72599+
72600+void
72601+gr_handle_crash(struct task_struct *task, const int sig)
72602+{
72603+ struct acl_subject_label *curr;
72604+ struct task_struct *tsk, *tsk2;
72605+ const struct cred *cred;
72606+ const struct cred *cred2;
72607+
72608+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
72609+ return;
72610+
72611+ if (unlikely(!gr_acl_is_enabled()))
72612+ return;
72613+
72614+ curr = task->acl;
72615+
72616+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
72617+ return;
72618+
72619+ if (time_before_eq(curr->expires, get_seconds())) {
72620+ curr->expires = 0;
72621+ curr->crashes = 0;
72622+ }
72623+
72624+ curr->crashes++;
72625+
72626+ if (!curr->expires)
72627+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
72628+
72629+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72630+ time_after(curr->expires, get_seconds())) {
72631+ rcu_read_lock();
72632+ cred = __task_cred(task);
72633+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
72634+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72635+ spin_lock(&gr_uid_lock);
72636+ gr_insert_uid(cred->uid, curr->expires);
72637+ spin_unlock(&gr_uid_lock);
72638+ curr->expires = 0;
72639+ curr->crashes = 0;
72640+ read_lock(&tasklist_lock);
72641+ do_each_thread(tsk2, tsk) {
72642+ cred2 = __task_cred(tsk);
72643+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
72644+ gr_fake_force_sig(SIGKILL, tsk);
72645+ } while_each_thread(tsk2, tsk);
72646+ read_unlock(&tasklist_lock);
72647+ } else {
72648+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
72649+ read_lock(&tasklist_lock);
72650+ read_lock(&grsec_exec_file_lock);
72651+ do_each_thread(tsk2, tsk) {
72652+ if (likely(tsk != task)) {
72653+ // if this thread has the same subject as the one that triggered
72654+ // RES_CRASH and it's the same binary, kill it
72655+ if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
72656+ gr_fake_force_sig(SIGKILL, tsk);
72657+ }
72658+ } while_each_thread(tsk2, tsk);
72659+ read_unlock(&grsec_exec_file_lock);
72660+ read_unlock(&tasklist_lock);
72661+ }
72662+ rcu_read_unlock();
72663+ }
72664+
72665+ return;
72666+}
72667+
72668+int
72669+gr_check_crash_exec(const struct file *filp)
72670+{
72671+ struct acl_subject_label *curr;
72672+
72673+ if (unlikely(!gr_acl_is_enabled()))
72674+ return 0;
72675+
72676+ read_lock(&gr_inode_lock);
72677+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
72678+ __get_dev(filp->f_path.dentry),
72679+ current->role);
72680+ read_unlock(&gr_inode_lock);
72681+
72682+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
72683+ (!curr->crashes && !curr->expires))
72684+ return 0;
72685+
72686+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
72687+ time_after(curr->expires, get_seconds()))
72688+ return 1;
72689+ else if (time_before_eq(curr->expires, get_seconds())) {
72690+ curr->crashes = 0;
72691+ curr->expires = 0;
72692+ }
72693+
72694+ return 0;
72695+}
72696+
72697+void
72698+gr_handle_alertkill(struct task_struct *task)
72699+{
72700+ struct acl_subject_label *curracl;
72701+ __u32 curr_ip;
72702+ struct task_struct *p, *p2;
72703+
72704+ if (unlikely(!gr_acl_is_enabled()))
72705+ return;
72706+
72707+ curracl = task->acl;
72708+ curr_ip = task->signal->curr_ip;
72709+
72710+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
72711+ read_lock(&tasklist_lock);
72712+ do_each_thread(p2, p) {
72713+ if (p->signal->curr_ip == curr_ip)
72714+ gr_fake_force_sig(SIGKILL, p);
72715+ } while_each_thread(p2, p);
72716+ read_unlock(&tasklist_lock);
72717+ } else if (curracl->mode & GR_KILLPROC)
72718+ gr_fake_force_sig(SIGKILL, task);
72719+
72720+ return;
72721+}
72722diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
72723new file mode 100644
72724index 0000000..98011b0
72725--- /dev/null
72726+++ b/grsecurity/gracl_shm.c
72727@@ -0,0 +1,40 @@
72728+#include <linux/kernel.h>
72729+#include <linux/mm.h>
72730+#include <linux/sched.h>
72731+#include <linux/file.h>
72732+#include <linux/ipc.h>
72733+#include <linux/gracl.h>
72734+#include <linux/grsecurity.h>
72735+#include <linux/grinternal.h>
72736+
72737+int
72738+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72739+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
72740+{
72741+ struct task_struct *task;
72742+
72743+ if (!gr_acl_is_enabled())
72744+ return 1;
72745+
72746+ rcu_read_lock();
72747+ read_lock(&tasklist_lock);
72748+
72749+ task = find_task_by_vpid(shm_cprid);
72750+
72751+ if (unlikely(!task))
72752+ task = find_task_by_vpid(shm_lapid);
72753+
72754+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
72755+ (task_pid_nr(task) == shm_lapid)) &&
72756+ (task->acl->mode & GR_PROTSHM) &&
72757+ (task->acl != current->acl))) {
72758+ read_unlock(&tasklist_lock);
72759+ rcu_read_unlock();
72760+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
72761+ return 0;
72762+ }
72763+ read_unlock(&tasklist_lock);
72764+ rcu_read_unlock();
72765+
72766+ return 1;
72767+}
72768diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
72769new file mode 100644
72770index 0000000..bc0be01
72771--- /dev/null
72772+++ b/grsecurity/grsec_chdir.c
72773@@ -0,0 +1,19 @@
72774+#include <linux/kernel.h>
72775+#include <linux/sched.h>
72776+#include <linux/fs.h>
72777+#include <linux/file.h>
72778+#include <linux/grsecurity.h>
72779+#include <linux/grinternal.h>
72780+
72781+void
72782+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
72783+{
72784+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
72785+ if ((grsec_enable_chdir && grsec_enable_group &&
72786+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
72787+ !grsec_enable_group)) {
72788+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
72789+ }
72790+#endif
72791+ return;
72792+}
72793diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
72794new file mode 100644
72795index 0000000..651d6c2
72796--- /dev/null
72797+++ b/grsecurity/grsec_chroot.c
72798@@ -0,0 +1,370 @@
72799+#include <linux/kernel.h>
72800+#include <linux/module.h>
72801+#include <linux/sched.h>
72802+#include <linux/file.h>
72803+#include <linux/fs.h>
72804+#include <linux/mount.h>
72805+#include <linux/types.h>
72806+#include "../fs/mount.h"
72807+#include <linux/grsecurity.h>
72808+#include <linux/grinternal.h>
72809+
72810+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72811+int gr_init_ran;
72812+#endif
72813+
72814+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
72815+{
72816+#ifdef CONFIG_GRKERNSEC
72817+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
72818+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
72819+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72820+ && gr_init_ran
72821+#endif
72822+ )
72823+ task->gr_is_chrooted = 1;
72824+ else {
72825+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
72826+ if (task_pid_nr(task) == 1 && !gr_init_ran)
72827+ gr_init_ran = 1;
72828+#endif
72829+ task->gr_is_chrooted = 0;
72830+ }
72831+
72832+ task->gr_chroot_dentry = path->dentry;
72833+#endif
72834+ return;
72835+}
72836+
72837+void gr_clear_chroot_entries(struct task_struct *task)
72838+{
72839+#ifdef CONFIG_GRKERNSEC
72840+ task->gr_is_chrooted = 0;
72841+ task->gr_chroot_dentry = NULL;
72842+#endif
72843+ return;
72844+}
72845+
72846+int
72847+gr_handle_chroot_unix(const pid_t pid)
72848+{
72849+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
72850+ struct task_struct *p;
72851+
72852+ if (unlikely(!grsec_enable_chroot_unix))
72853+ return 1;
72854+
72855+ if (likely(!proc_is_chrooted(current)))
72856+ return 1;
72857+
72858+ rcu_read_lock();
72859+ read_lock(&tasklist_lock);
72860+ p = find_task_by_vpid_unrestricted(pid);
72861+ if (unlikely(p && !have_same_root(current, p))) {
72862+ read_unlock(&tasklist_lock);
72863+ rcu_read_unlock();
72864+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
72865+ return 0;
72866+ }
72867+ read_unlock(&tasklist_lock);
72868+ rcu_read_unlock();
72869+#endif
72870+ return 1;
72871+}
72872+
72873+int
72874+gr_handle_chroot_nice(void)
72875+{
72876+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72877+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
72878+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
72879+ return -EPERM;
72880+ }
72881+#endif
72882+ return 0;
72883+}
72884+
72885+int
72886+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
72887+{
72888+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
72889+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
72890+ && proc_is_chrooted(current)) {
72891+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
72892+ return -EACCES;
72893+ }
72894+#endif
72895+ return 0;
72896+}
72897+
72898+int
72899+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72900+{
72901+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72902+ struct task_struct *p;
72903+ int ret = 0;
72904+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72905+ return ret;
72906+
72907+ read_lock(&tasklist_lock);
72908+ do_each_pid_task(pid, type, p) {
72909+ if (!have_same_root(current, p)) {
72910+ ret = 1;
72911+ goto out;
72912+ }
72913+ } while_each_pid_task(pid, type, p);
72914+out:
72915+ read_unlock(&tasklist_lock);
72916+ return ret;
72917+#endif
72918+ return 0;
72919+}
72920+
72921+int
72922+gr_pid_is_chrooted(struct task_struct *p)
72923+{
72924+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72925+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72926+ return 0;
72927+
72928+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72929+ !have_same_root(current, p)) {
72930+ return 1;
72931+ }
72932+#endif
72933+ return 0;
72934+}
72935+
72936+EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72937+
72938+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72939+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72940+{
72941+ struct path path, currentroot;
72942+ int ret = 0;
72943+
72944+ path.dentry = (struct dentry *)u_dentry;
72945+ path.mnt = (struct vfsmount *)u_mnt;
72946+ get_fs_root(current->fs, &currentroot);
72947+ if (path_is_under(&path, &currentroot))
72948+ ret = 1;
72949+ path_put(&currentroot);
72950+
72951+ return ret;
72952+}
72953+#endif
72954+
72955+int
72956+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72957+{
72958+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72959+ if (!grsec_enable_chroot_fchdir)
72960+ return 1;
72961+
72962+ if (!proc_is_chrooted(current))
72963+ return 1;
72964+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72965+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72966+ return 0;
72967+ }
72968+#endif
72969+ return 1;
72970+}
72971+
72972+int
72973+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72974+ const time_t shm_createtime)
72975+{
72976+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72977+ struct task_struct *p;
72978+ time_t starttime;
72979+
72980+ if (unlikely(!grsec_enable_chroot_shmat))
72981+ return 1;
72982+
72983+ if (likely(!proc_is_chrooted(current)))
72984+ return 1;
72985+
72986+ rcu_read_lock();
72987+ read_lock(&tasklist_lock);
72988+
72989+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72990+ starttime = p->start_time.tv_sec;
72991+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72992+ if (have_same_root(current, p)) {
72993+ goto allow;
72994+ } else {
72995+ read_unlock(&tasklist_lock);
72996+ rcu_read_unlock();
72997+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72998+ return 0;
72999+ }
73000+ }
73001+ /* creator exited, pid reuse, fall through to next check */
73002+ }
73003+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73004+ if (unlikely(!have_same_root(current, p))) {
73005+ read_unlock(&tasklist_lock);
73006+ rcu_read_unlock();
73007+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73008+ return 0;
73009+ }
73010+ }
73011+
73012+allow:
73013+ read_unlock(&tasklist_lock);
73014+ rcu_read_unlock();
73015+#endif
73016+ return 1;
73017+}
73018+
73019+void
73020+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73021+{
73022+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73023+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73024+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73025+#endif
73026+ return;
73027+}
73028+
73029+int
73030+gr_handle_chroot_mknod(const struct dentry *dentry,
73031+ const struct vfsmount *mnt, const int mode)
73032+{
73033+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73034+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73035+ proc_is_chrooted(current)) {
73036+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73037+ return -EPERM;
73038+ }
73039+#endif
73040+ return 0;
73041+}
73042+
73043+int
73044+gr_handle_chroot_mount(const struct dentry *dentry,
73045+ const struct vfsmount *mnt, const char *dev_name)
73046+{
73047+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73048+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73049+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73050+ return -EPERM;
73051+ }
73052+#endif
73053+ return 0;
73054+}
73055+
73056+int
73057+gr_handle_chroot_pivot(void)
73058+{
73059+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73060+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73061+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73062+ return -EPERM;
73063+ }
73064+#endif
73065+ return 0;
73066+}
73067+
73068+int
73069+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73070+{
73071+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73072+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73073+ !gr_is_outside_chroot(dentry, mnt)) {
73074+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73075+ return -EPERM;
73076+ }
73077+#endif
73078+ return 0;
73079+}
73080+
73081+extern const char *captab_log[];
73082+extern int captab_log_entries;
73083+
73084+int
73085+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73086+{
73087+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73088+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73089+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73090+ if (cap_raised(chroot_caps, cap)) {
73091+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73092+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73093+ }
73094+ return 0;
73095+ }
73096+ }
73097+#endif
73098+ return 1;
73099+}
73100+
73101+int
73102+gr_chroot_is_capable(const int cap)
73103+{
73104+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73105+ return gr_task_chroot_is_capable(current, current_cred(), cap);
73106+#endif
73107+ return 1;
73108+}
73109+
73110+int
73111+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73112+{
73113+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73114+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73115+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73116+ if (cap_raised(chroot_caps, cap)) {
73117+ return 0;
73118+ }
73119+ }
73120+#endif
73121+ return 1;
73122+}
73123+
73124+int
73125+gr_chroot_is_capable_nolog(const int cap)
73126+{
73127+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73128+ return gr_task_chroot_is_capable_nolog(current, cap);
73129+#endif
73130+ return 1;
73131+}
73132+
73133+int
73134+gr_handle_chroot_sysctl(const int op)
73135+{
73136+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73137+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73138+ proc_is_chrooted(current))
73139+ return -EACCES;
73140+#endif
73141+ return 0;
73142+}
73143+
73144+void
73145+gr_handle_chroot_chdir(const struct path *path)
73146+{
73147+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73148+ if (grsec_enable_chroot_chdir)
73149+ set_fs_pwd(current->fs, path);
73150+#endif
73151+ return;
73152+}
73153+
73154+int
73155+gr_handle_chroot_chmod(const struct dentry *dentry,
73156+ const struct vfsmount *mnt, const int mode)
73157+{
73158+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73159+ /* allow chmod +s on directories, but not files */
73160+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73161+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73162+ proc_is_chrooted(current)) {
73163+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73164+ return -EPERM;
73165+ }
73166+#endif
73167+ return 0;
73168+}
73169diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73170new file mode 100644
73171index 0000000..4d6fce8
73172--- /dev/null
73173+++ b/grsecurity/grsec_disabled.c
73174@@ -0,0 +1,433 @@
73175+#include <linux/kernel.h>
73176+#include <linux/module.h>
73177+#include <linux/sched.h>
73178+#include <linux/file.h>
73179+#include <linux/fs.h>
73180+#include <linux/kdev_t.h>
73181+#include <linux/net.h>
73182+#include <linux/in.h>
73183+#include <linux/ip.h>
73184+#include <linux/skbuff.h>
73185+#include <linux/sysctl.h>
73186+
73187+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73188+void
73189+pax_set_initial_flags(struct linux_binprm *bprm)
73190+{
73191+ return;
73192+}
73193+#endif
73194+
73195+#ifdef CONFIG_SYSCTL
73196+__u32
73197+gr_handle_sysctl(const struct ctl_table * table, const int op)
73198+{
73199+ return 0;
73200+}
73201+#endif
73202+
73203+#ifdef CONFIG_TASKSTATS
73204+int gr_is_taskstats_denied(int pid)
73205+{
73206+ return 0;
73207+}
73208+#endif
73209+
73210+int
73211+gr_acl_is_enabled(void)
73212+{
73213+ return 0;
73214+}
73215+
73216+void
73217+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73218+{
73219+ return;
73220+}
73221+
73222+int
73223+gr_handle_rawio(const struct inode *inode)
73224+{
73225+ return 0;
73226+}
73227+
73228+void
73229+gr_acl_handle_psacct(struct task_struct *task, const long code)
73230+{
73231+ return;
73232+}
73233+
73234+int
73235+gr_handle_ptrace(struct task_struct *task, const long request)
73236+{
73237+ return 0;
73238+}
73239+
73240+int
73241+gr_handle_proc_ptrace(struct task_struct *task)
73242+{
73243+ return 0;
73244+}
73245+
73246+int
73247+gr_set_acls(const int type)
73248+{
73249+ return 0;
73250+}
73251+
73252+int
73253+gr_check_hidden_task(const struct task_struct *tsk)
73254+{
73255+ return 0;
73256+}
73257+
73258+int
73259+gr_check_protected_task(const struct task_struct *task)
73260+{
73261+ return 0;
73262+}
73263+
73264+int
73265+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73266+{
73267+ return 0;
73268+}
73269+
73270+void
73271+gr_copy_label(struct task_struct *tsk)
73272+{
73273+ return;
73274+}
73275+
73276+void
73277+gr_set_pax_flags(struct task_struct *task)
73278+{
73279+ return;
73280+}
73281+
73282+int
73283+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73284+ const int unsafe_share)
73285+{
73286+ return 0;
73287+}
73288+
73289+void
73290+gr_handle_delete(const ino_t ino, const dev_t dev)
73291+{
73292+ return;
73293+}
73294+
73295+void
73296+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
73297+{
73298+ return;
73299+}
73300+
73301+void
73302+gr_handle_crash(struct task_struct *task, const int sig)
73303+{
73304+ return;
73305+}
73306+
73307+int
73308+gr_check_crash_exec(const struct file *filp)
73309+{
73310+ return 0;
73311+}
73312+
73313+int
73314+gr_check_crash_uid(const kuid_t uid)
73315+{
73316+ return 0;
73317+}
73318+
73319+void
73320+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
73321+ struct dentry *old_dentry,
73322+ struct dentry *new_dentry,
73323+ struct vfsmount *mnt, const __u8 replace)
73324+{
73325+ return;
73326+}
73327+
73328+int
73329+gr_search_socket(const int family, const int type, const int protocol)
73330+{
73331+ return 1;
73332+}
73333+
73334+int
73335+gr_search_connectbind(const int mode, const struct socket *sock,
73336+ const struct sockaddr_in *addr)
73337+{
73338+ return 0;
73339+}
73340+
73341+void
73342+gr_handle_alertkill(struct task_struct *task)
73343+{
73344+ return;
73345+}
73346+
73347+__u32
73348+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
73349+{
73350+ return 1;
73351+}
73352+
73353+__u32
73354+gr_acl_handle_hidden_file(const struct dentry * dentry,
73355+ const struct vfsmount * mnt)
73356+{
73357+ return 1;
73358+}
73359+
73360+__u32
73361+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
73362+ int acc_mode)
73363+{
73364+ return 1;
73365+}
73366+
73367+__u32
73368+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
73369+{
73370+ return 1;
73371+}
73372+
73373+__u32
73374+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
73375+{
73376+ return 1;
73377+}
73378+
73379+int
73380+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
73381+ unsigned int *vm_flags)
73382+{
73383+ return 1;
73384+}
73385+
73386+__u32
73387+gr_acl_handle_truncate(const struct dentry * dentry,
73388+ const struct vfsmount * mnt)
73389+{
73390+ return 1;
73391+}
73392+
73393+__u32
73394+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
73395+{
73396+ return 1;
73397+}
73398+
73399+__u32
73400+gr_acl_handle_access(const struct dentry * dentry,
73401+ const struct vfsmount * mnt, const int fmode)
73402+{
73403+ return 1;
73404+}
73405+
73406+__u32
73407+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
73408+ umode_t *mode)
73409+{
73410+ return 1;
73411+}
73412+
73413+__u32
73414+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
73415+{
73416+ return 1;
73417+}
73418+
73419+__u32
73420+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
73421+{
73422+ return 1;
73423+}
73424+
73425+__u32
73426+gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
73427+{
73428+ return 1;
73429+}
73430+
73431+void
73432+grsecurity_init(void)
73433+{
73434+ return;
73435+}
73436+
73437+umode_t gr_acl_umask(void)
73438+{
73439+ return 0;
73440+}
73441+
73442+__u32
73443+gr_acl_handle_mknod(const struct dentry * new_dentry,
73444+ const struct dentry * parent_dentry,
73445+ const struct vfsmount * parent_mnt,
73446+ const int mode)
73447+{
73448+ return 1;
73449+}
73450+
73451+__u32
73452+gr_acl_handle_mkdir(const struct dentry * new_dentry,
73453+ const struct dentry * parent_dentry,
73454+ const struct vfsmount * parent_mnt)
73455+{
73456+ return 1;
73457+}
73458+
73459+__u32
73460+gr_acl_handle_symlink(const struct dentry * new_dentry,
73461+ const struct dentry * parent_dentry,
73462+ const struct vfsmount * parent_mnt, const struct filename *from)
73463+{
73464+ return 1;
73465+}
73466+
73467+__u32
73468+gr_acl_handle_link(const struct dentry * new_dentry,
73469+ const struct dentry * parent_dentry,
73470+ const struct vfsmount * parent_mnt,
73471+ const struct dentry * old_dentry,
73472+ const struct vfsmount * old_mnt, const struct filename *to)
73473+{
73474+ return 1;
73475+}
73476+
73477+int
73478+gr_acl_handle_rename(const struct dentry *new_dentry,
73479+ const struct dentry *parent_dentry,
73480+ const struct vfsmount *parent_mnt,
73481+ const struct dentry *old_dentry,
73482+ const struct inode *old_parent_inode,
73483+ const struct vfsmount *old_mnt, const struct filename *newname)
73484+{
73485+ return 0;
73486+}
73487+
73488+int
73489+gr_acl_handle_filldir(const struct file *file, const char *name,
73490+ const int namelen, const ino_t ino)
73491+{
73492+ return 1;
73493+}
73494+
73495+int
73496+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73497+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
73498+{
73499+ return 1;
73500+}
73501+
73502+int
73503+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
73504+{
73505+ return 0;
73506+}
73507+
73508+int
73509+gr_search_accept(const struct socket *sock)
73510+{
73511+ return 0;
73512+}
73513+
73514+int
73515+gr_search_listen(const struct socket *sock)
73516+{
73517+ return 0;
73518+}
73519+
73520+int
73521+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
73522+{
73523+ return 0;
73524+}
73525+
73526+__u32
73527+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
73528+{
73529+ return 1;
73530+}
73531+
73532+__u32
73533+gr_acl_handle_creat(const struct dentry * dentry,
73534+ const struct dentry * p_dentry,
73535+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
73536+ const int imode)
73537+{
73538+ return 1;
73539+}
73540+
73541+void
73542+gr_acl_handle_exit(void)
73543+{
73544+ return;
73545+}
73546+
73547+int
73548+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
73549+{
73550+ return 1;
73551+}
73552+
73553+void
73554+gr_set_role_label(const kuid_t uid, const kgid_t gid)
73555+{
73556+ return;
73557+}
73558+
73559+int
73560+gr_acl_handle_procpidmem(const struct task_struct *task)
73561+{
73562+ return 0;
73563+}
73564+
73565+int
73566+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
73567+{
73568+ return 0;
73569+}
73570+
73571+int
73572+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
73573+{
73574+ return 0;
73575+}
73576+
73577+int
73578+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
73579+{
73580+ return 0;
73581+}
73582+
73583+int
73584+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
73585+{
73586+ return 0;
73587+}
73588+
73589+int gr_acl_enable_at_secure(void)
73590+{
73591+ return 0;
73592+}
73593+
73594+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
73595+{
73596+ return dentry->d_sb->s_dev;
73597+}
73598+
73599+void gr_put_exec_file(struct task_struct *task)
73600+{
73601+ return;
73602+}
73603+
73604+#ifdef CONFIG_SECURITY
73605+EXPORT_SYMBOL_GPL(gr_check_user_change);
73606+EXPORT_SYMBOL_GPL(gr_check_group_change);
73607+#endif
73608diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
73609new file mode 100644
73610index 0000000..f35f454
73611--- /dev/null
73612+++ b/grsecurity/grsec_exec.c
73613@@ -0,0 +1,187 @@
73614+#include <linux/kernel.h>
73615+#include <linux/sched.h>
73616+#include <linux/file.h>
73617+#include <linux/binfmts.h>
73618+#include <linux/fs.h>
73619+#include <linux/types.h>
73620+#include <linux/grdefs.h>
73621+#include <linux/grsecurity.h>
73622+#include <linux/grinternal.h>
73623+#include <linux/capability.h>
73624+#include <linux/module.h>
73625+#include <linux/compat.h>
73626+
73627+#include <asm/uaccess.h>
73628+
73629+#ifdef CONFIG_GRKERNSEC_EXECLOG
73630+static char gr_exec_arg_buf[132];
73631+static DEFINE_MUTEX(gr_exec_arg_mutex);
73632+#endif
73633+
73634+struct user_arg_ptr {
73635+#ifdef CONFIG_COMPAT
73636+ bool is_compat;
73637+#endif
73638+ union {
73639+ const char __user *const __user *native;
73640+#ifdef CONFIG_COMPAT
73641+ const compat_uptr_t __user *compat;
73642+#endif
73643+ } ptr;
73644+};
73645+
73646+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
73647+
73648+void
73649+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
73650+{
73651+#ifdef CONFIG_GRKERNSEC_EXECLOG
73652+ char *grarg = gr_exec_arg_buf;
73653+ unsigned int i, x, execlen = 0;
73654+ char c;
73655+
73656+ if (!((grsec_enable_execlog && grsec_enable_group &&
73657+ in_group_p(grsec_audit_gid))
73658+ || (grsec_enable_execlog && !grsec_enable_group)))
73659+ return;
73660+
73661+ mutex_lock(&gr_exec_arg_mutex);
73662+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
73663+
73664+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
73665+ const char __user *p;
73666+ unsigned int len;
73667+
73668+ p = get_user_arg_ptr(argv, i);
73669+ if (IS_ERR(p))
73670+ goto log;
73671+
73672+ len = strnlen_user(p, 128 - execlen);
73673+ if (len > 128 - execlen)
73674+ len = 128 - execlen;
73675+ else if (len > 0)
73676+ len--;
73677+ if (copy_from_user(grarg + execlen, p, len))
73678+ goto log;
73679+
73680+ /* rewrite unprintable characters */
73681+ for (x = 0; x < len; x++) {
73682+ c = *(grarg + execlen + x);
73683+ if (c < 32 || c > 126)
73684+ *(grarg + execlen + x) = ' ';
73685+ }
73686+
73687+ execlen += len;
73688+ *(grarg + execlen) = ' ';
73689+ *(grarg + execlen + 1) = '\0';
73690+ execlen++;
73691+ }
73692+
73693+ log:
73694+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
73695+ bprm->file->f_path.mnt, grarg);
73696+ mutex_unlock(&gr_exec_arg_mutex);
73697+#endif
73698+ return;
73699+}
73700+
73701+#ifdef CONFIG_GRKERNSEC
73702+extern int gr_acl_is_capable(const int cap);
73703+extern int gr_acl_is_capable_nolog(const int cap);
73704+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73705+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
73706+extern int gr_chroot_is_capable(const int cap);
73707+extern int gr_chroot_is_capable_nolog(const int cap);
73708+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
73709+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
73710+#endif
73711+
73712+const char *captab_log[] = {
73713+ "CAP_CHOWN",
73714+ "CAP_DAC_OVERRIDE",
73715+ "CAP_DAC_READ_SEARCH",
73716+ "CAP_FOWNER",
73717+ "CAP_FSETID",
73718+ "CAP_KILL",
73719+ "CAP_SETGID",
73720+ "CAP_SETUID",
73721+ "CAP_SETPCAP",
73722+ "CAP_LINUX_IMMUTABLE",
73723+ "CAP_NET_BIND_SERVICE",
73724+ "CAP_NET_BROADCAST",
73725+ "CAP_NET_ADMIN",
73726+ "CAP_NET_RAW",
73727+ "CAP_IPC_LOCK",
73728+ "CAP_IPC_OWNER",
73729+ "CAP_SYS_MODULE",
73730+ "CAP_SYS_RAWIO",
73731+ "CAP_SYS_CHROOT",
73732+ "CAP_SYS_PTRACE",
73733+ "CAP_SYS_PACCT",
73734+ "CAP_SYS_ADMIN",
73735+ "CAP_SYS_BOOT",
73736+ "CAP_SYS_NICE",
73737+ "CAP_SYS_RESOURCE",
73738+ "CAP_SYS_TIME",
73739+ "CAP_SYS_TTY_CONFIG",
73740+ "CAP_MKNOD",
73741+ "CAP_LEASE",
73742+ "CAP_AUDIT_WRITE",
73743+ "CAP_AUDIT_CONTROL",
73744+ "CAP_SETFCAP",
73745+ "CAP_MAC_OVERRIDE",
73746+ "CAP_MAC_ADMIN",
73747+ "CAP_SYSLOG",
73748+ "CAP_WAKE_ALARM"
73749+};
73750+
73751+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
73752+
73753+int gr_is_capable(const int cap)
73754+{
73755+#ifdef CONFIG_GRKERNSEC
73756+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
73757+ return 1;
73758+ return 0;
73759+#else
73760+ return 1;
73761+#endif
73762+}
73763+
73764+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73765+{
73766+#ifdef CONFIG_GRKERNSEC
73767+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
73768+ return 1;
73769+ return 0;
73770+#else
73771+ return 1;
73772+#endif
73773+}
73774+
73775+int gr_is_capable_nolog(const int cap)
73776+{
73777+#ifdef CONFIG_GRKERNSEC
73778+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
73779+ return 1;
73780+ return 0;
73781+#else
73782+ return 1;
73783+#endif
73784+}
73785+
73786+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
73787+{
73788+#ifdef CONFIG_GRKERNSEC
73789+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
73790+ return 1;
73791+ return 0;
73792+#else
73793+ return 1;
73794+#endif
73795+}
73796+
73797+EXPORT_SYMBOL_GPL(gr_is_capable);
73798+EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
73799+EXPORT_SYMBOL_GPL(gr_task_is_capable);
73800+EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
73801diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
73802new file mode 100644
73803index 0000000..06cc6ea
73804--- /dev/null
73805+++ b/grsecurity/grsec_fifo.c
73806@@ -0,0 +1,24 @@
73807+#include <linux/kernel.h>
73808+#include <linux/sched.h>
73809+#include <linux/fs.h>
73810+#include <linux/file.h>
73811+#include <linux/grinternal.h>
73812+
73813+int
73814+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
73815+ const struct dentry *dir, const int flag, const int acc_mode)
73816+{
73817+#ifdef CONFIG_GRKERNSEC_FIFO
73818+ const struct cred *cred = current_cred();
73819+
73820+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
73821+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
73822+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
73823+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
73824+ if (!inode_permission(dentry->d_inode, acc_mode))
73825+ 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));
73826+ return -EACCES;
73827+ }
73828+#endif
73829+ return 0;
73830+}
73831diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
73832new file mode 100644
73833index 0000000..8ca18bf
73834--- /dev/null
73835+++ b/grsecurity/grsec_fork.c
73836@@ -0,0 +1,23 @@
73837+#include <linux/kernel.h>
73838+#include <linux/sched.h>
73839+#include <linux/grsecurity.h>
73840+#include <linux/grinternal.h>
73841+#include <linux/errno.h>
73842+
73843+void
73844+gr_log_forkfail(const int retval)
73845+{
73846+#ifdef CONFIG_GRKERNSEC_FORKFAIL
73847+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
73848+ switch (retval) {
73849+ case -EAGAIN:
73850+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
73851+ break;
73852+ case -ENOMEM:
73853+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
73854+ break;
73855+ }
73856+ }
73857+#endif
73858+ return;
73859+}
73860diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
73861new file mode 100644
73862index 0000000..ae6c028
73863--- /dev/null
73864+++ b/grsecurity/grsec_init.c
73865@@ -0,0 +1,272 @@
73866+#include <linux/kernel.h>
73867+#include <linux/sched.h>
73868+#include <linux/mm.h>
73869+#include <linux/gracl.h>
73870+#include <linux/slab.h>
73871+#include <linux/vmalloc.h>
73872+#include <linux/percpu.h>
73873+#include <linux/module.h>
73874+
73875+int grsec_enable_ptrace_readexec;
73876+int grsec_enable_setxid;
73877+int grsec_enable_symlinkown;
73878+kgid_t grsec_symlinkown_gid;
73879+int grsec_enable_brute;
73880+int grsec_enable_link;
73881+int grsec_enable_dmesg;
73882+int grsec_enable_harden_ptrace;
73883+int grsec_enable_harden_ipc;
73884+int grsec_enable_fifo;
73885+int grsec_enable_execlog;
73886+int grsec_enable_signal;
73887+int grsec_enable_forkfail;
73888+int grsec_enable_audit_ptrace;
73889+int grsec_enable_time;
73890+int grsec_enable_group;
73891+kgid_t grsec_audit_gid;
73892+int grsec_enable_chdir;
73893+int grsec_enable_mount;
73894+int grsec_enable_rofs;
73895+int grsec_deny_new_usb;
73896+int grsec_enable_chroot_findtask;
73897+int grsec_enable_chroot_mount;
73898+int grsec_enable_chroot_shmat;
73899+int grsec_enable_chroot_fchdir;
73900+int grsec_enable_chroot_double;
73901+int grsec_enable_chroot_pivot;
73902+int grsec_enable_chroot_chdir;
73903+int grsec_enable_chroot_chmod;
73904+int grsec_enable_chroot_mknod;
73905+int grsec_enable_chroot_nice;
73906+int grsec_enable_chroot_execlog;
73907+int grsec_enable_chroot_caps;
73908+int grsec_enable_chroot_sysctl;
73909+int grsec_enable_chroot_unix;
73910+int grsec_enable_tpe;
73911+kgid_t grsec_tpe_gid;
73912+int grsec_enable_blackhole;
73913+#ifdef CONFIG_IPV6_MODULE
73914+EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73915+#endif
73916+int grsec_lastack_retries;
73917+int grsec_enable_tpe_all;
73918+int grsec_enable_tpe_invert;
73919+int grsec_enable_socket_all;
73920+kgid_t grsec_socket_all_gid;
73921+int grsec_enable_socket_client;
73922+kgid_t grsec_socket_client_gid;
73923+int grsec_enable_socket_server;
73924+kgid_t grsec_socket_server_gid;
73925+int grsec_resource_logging;
73926+int grsec_disable_privio;
73927+int grsec_enable_log_rwxmaps;
73928+int grsec_lock;
73929+
73930+DEFINE_SPINLOCK(grsec_alert_lock);
73931+unsigned long grsec_alert_wtime = 0;
73932+unsigned long grsec_alert_fyet = 0;
73933+
73934+DEFINE_SPINLOCK(grsec_audit_lock);
73935+
73936+DEFINE_RWLOCK(grsec_exec_file_lock);
73937+
73938+char *gr_shared_page[4];
73939+
73940+char *gr_alert_log_fmt;
73941+char *gr_audit_log_fmt;
73942+char *gr_alert_log_buf;
73943+char *gr_audit_log_buf;
73944+
73945+void __init
73946+grsecurity_init(void)
73947+{
73948+ int j;
73949+ /* create the per-cpu shared pages */
73950+
73951+#ifdef CONFIG_X86
73952+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73953+#endif
73954+
73955+ for (j = 0; j < 4; j++) {
73956+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73957+ if (gr_shared_page[j] == NULL) {
73958+ panic("Unable to allocate grsecurity shared page");
73959+ return;
73960+ }
73961+ }
73962+
73963+ /* allocate log buffers */
73964+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73965+ if (!gr_alert_log_fmt) {
73966+ panic("Unable to allocate grsecurity alert log format buffer");
73967+ return;
73968+ }
73969+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73970+ if (!gr_audit_log_fmt) {
73971+ panic("Unable to allocate grsecurity audit log format buffer");
73972+ return;
73973+ }
73974+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73975+ if (!gr_alert_log_buf) {
73976+ panic("Unable to allocate grsecurity alert log buffer");
73977+ return;
73978+ }
73979+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73980+ if (!gr_audit_log_buf) {
73981+ panic("Unable to allocate grsecurity audit log buffer");
73982+ return;
73983+ }
73984+
73985+#ifdef CONFIG_GRKERNSEC_IO
73986+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73987+ grsec_disable_privio = 1;
73988+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73989+ grsec_disable_privio = 1;
73990+#else
73991+ grsec_disable_privio = 0;
73992+#endif
73993+#endif
73994+
73995+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73996+ /* for backward compatibility, tpe_invert always defaults to on if
73997+ enabled in the kernel
73998+ */
73999+ grsec_enable_tpe_invert = 1;
74000+#endif
74001+
74002+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74003+#ifndef CONFIG_GRKERNSEC_SYSCTL
74004+ grsec_lock = 1;
74005+#endif
74006+
74007+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74008+ grsec_enable_log_rwxmaps = 1;
74009+#endif
74010+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74011+ grsec_enable_group = 1;
74012+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74013+#endif
74014+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74015+ grsec_enable_ptrace_readexec = 1;
74016+#endif
74017+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74018+ grsec_enable_chdir = 1;
74019+#endif
74020+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74021+ grsec_enable_harden_ptrace = 1;
74022+#endif
74023+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74024+ grsec_enable_harden_ipc = 1;
74025+#endif
74026+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74027+ grsec_enable_mount = 1;
74028+#endif
74029+#ifdef CONFIG_GRKERNSEC_LINK
74030+ grsec_enable_link = 1;
74031+#endif
74032+#ifdef CONFIG_GRKERNSEC_BRUTE
74033+ grsec_enable_brute = 1;
74034+#endif
74035+#ifdef CONFIG_GRKERNSEC_DMESG
74036+ grsec_enable_dmesg = 1;
74037+#endif
74038+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74039+ grsec_enable_blackhole = 1;
74040+ grsec_lastack_retries = 4;
74041+#endif
74042+#ifdef CONFIG_GRKERNSEC_FIFO
74043+ grsec_enable_fifo = 1;
74044+#endif
74045+#ifdef CONFIG_GRKERNSEC_EXECLOG
74046+ grsec_enable_execlog = 1;
74047+#endif
74048+#ifdef CONFIG_GRKERNSEC_SETXID
74049+ grsec_enable_setxid = 1;
74050+#endif
74051+#ifdef CONFIG_GRKERNSEC_SIGNAL
74052+ grsec_enable_signal = 1;
74053+#endif
74054+#ifdef CONFIG_GRKERNSEC_FORKFAIL
74055+ grsec_enable_forkfail = 1;
74056+#endif
74057+#ifdef CONFIG_GRKERNSEC_TIME
74058+ grsec_enable_time = 1;
74059+#endif
74060+#ifdef CONFIG_GRKERNSEC_RESLOG
74061+ grsec_resource_logging = 1;
74062+#endif
74063+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74064+ grsec_enable_chroot_findtask = 1;
74065+#endif
74066+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74067+ grsec_enable_chroot_unix = 1;
74068+#endif
74069+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74070+ grsec_enable_chroot_mount = 1;
74071+#endif
74072+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74073+ grsec_enable_chroot_fchdir = 1;
74074+#endif
74075+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74076+ grsec_enable_chroot_shmat = 1;
74077+#endif
74078+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74079+ grsec_enable_audit_ptrace = 1;
74080+#endif
74081+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74082+ grsec_enable_chroot_double = 1;
74083+#endif
74084+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74085+ grsec_enable_chroot_pivot = 1;
74086+#endif
74087+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74088+ grsec_enable_chroot_chdir = 1;
74089+#endif
74090+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74091+ grsec_enable_chroot_chmod = 1;
74092+#endif
74093+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74094+ grsec_enable_chroot_mknod = 1;
74095+#endif
74096+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74097+ grsec_enable_chroot_nice = 1;
74098+#endif
74099+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74100+ grsec_enable_chroot_execlog = 1;
74101+#endif
74102+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74103+ grsec_enable_chroot_caps = 1;
74104+#endif
74105+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74106+ grsec_enable_chroot_sysctl = 1;
74107+#endif
74108+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74109+ grsec_enable_symlinkown = 1;
74110+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74111+#endif
74112+#ifdef CONFIG_GRKERNSEC_TPE
74113+ grsec_enable_tpe = 1;
74114+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74115+#ifdef CONFIG_GRKERNSEC_TPE_ALL
74116+ grsec_enable_tpe_all = 1;
74117+#endif
74118+#endif
74119+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74120+ grsec_enable_socket_all = 1;
74121+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74122+#endif
74123+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74124+ grsec_enable_socket_client = 1;
74125+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74126+#endif
74127+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74128+ grsec_enable_socket_server = 1;
74129+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74130+#endif
74131+#endif
74132+#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74133+ grsec_deny_new_usb = 1;
74134+#endif
74135+
74136+ return;
74137+}
74138diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74139new file mode 100644
74140index 0000000..1773300
74141--- /dev/null
74142+++ b/grsecurity/grsec_ipc.c
74143@@ -0,0 +1,48 @@
74144+#include <linux/kernel.h>
74145+#include <linux/mm.h>
74146+#include <linux/sched.h>
74147+#include <linux/file.h>
74148+#include <linux/ipc.h>
74149+#include <linux/ipc_namespace.h>
74150+#include <linux/grsecurity.h>
74151+#include <linux/grinternal.h>
74152+
74153+int
74154+gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74155+{
74156+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74157+ int write;
74158+ int orig_granted_mode;
74159+ kuid_t euid;
74160+ kgid_t egid;
74161+
74162+ if (!grsec_enable_harden_ipc)
74163+ return 1;
74164+
74165+ euid = current_euid();
74166+ egid = current_egid();
74167+
74168+ write = requested_mode & 00002;
74169+ orig_granted_mode = ipcp->mode;
74170+
74171+ if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74172+ orig_granted_mode >>= 6;
74173+ else {
74174+ /* if likely wrong permissions, lock to user */
74175+ if (orig_granted_mode & 0007)
74176+ orig_granted_mode = 0;
74177+ /* otherwise do a egid-only check */
74178+ else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74179+ orig_granted_mode >>= 3;
74180+ /* otherwise, no access */
74181+ else
74182+ orig_granted_mode = 0;
74183+ }
74184+ if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74185+ !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74186+ gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74187+ return 0;
74188+ }
74189+#endif
74190+ return 1;
74191+}
74192diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74193new file mode 100644
74194index 0000000..5e05e20
74195--- /dev/null
74196+++ b/grsecurity/grsec_link.c
74197@@ -0,0 +1,58 @@
74198+#include <linux/kernel.h>
74199+#include <linux/sched.h>
74200+#include <linux/fs.h>
74201+#include <linux/file.h>
74202+#include <linux/grinternal.h>
74203+
74204+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74205+{
74206+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74207+ const struct inode *link_inode = link->dentry->d_inode;
74208+
74209+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74210+ /* ignore root-owned links, e.g. /proc/self */
74211+ gr_is_global_nonroot(link_inode->i_uid) && target &&
74212+ !uid_eq(link_inode->i_uid, target->i_uid)) {
74213+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74214+ return 1;
74215+ }
74216+#endif
74217+ return 0;
74218+}
74219+
74220+int
74221+gr_handle_follow_link(const struct inode *parent,
74222+ const struct inode *inode,
74223+ const struct dentry *dentry, const struct vfsmount *mnt)
74224+{
74225+#ifdef CONFIG_GRKERNSEC_LINK
74226+ const struct cred *cred = current_cred();
74227+
74228+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74229+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74230+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74231+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74232+ return -EACCES;
74233+ }
74234+#endif
74235+ return 0;
74236+}
74237+
74238+int
74239+gr_handle_hardlink(const struct dentry *dentry,
74240+ const struct vfsmount *mnt,
74241+ struct inode *inode, const int mode, const struct filename *to)
74242+{
74243+#ifdef CONFIG_GRKERNSEC_LINK
74244+ const struct cred *cred = current_cred();
74245+
74246+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74247+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74248+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74249+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74250+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74251+ return -EPERM;
74252+ }
74253+#endif
74254+ return 0;
74255+}
74256diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74257new file mode 100644
74258index 0000000..dbe0a6b
74259--- /dev/null
74260+++ b/grsecurity/grsec_log.c
74261@@ -0,0 +1,341 @@
74262+#include <linux/kernel.h>
74263+#include <linux/sched.h>
74264+#include <linux/file.h>
74265+#include <linux/tty.h>
74266+#include <linux/fs.h>
74267+#include <linux/mm.h>
74268+#include <linux/grinternal.h>
74269+
74270+#ifdef CONFIG_TREE_PREEMPT_RCU
74271+#define DISABLE_PREEMPT() preempt_disable()
74272+#define ENABLE_PREEMPT() preempt_enable()
74273+#else
74274+#define DISABLE_PREEMPT()
74275+#define ENABLE_PREEMPT()
74276+#endif
74277+
74278+#define BEGIN_LOCKS(x) \
74279+ DISABLE_PREEMPT(); \
74280+ rcu_read_lock(); \
74281+ read_lock(&tasklist_lock); \
74282+ read_lock(&grsec_exec_file_lock); \
74283+ if (x != GR_DO_AUDIT) \
74284+ spin_lock(&grsec_alert_lock); \
74285+ else \
74286+ spin_lock(&grsec_audit_lock)
74287+
74288+#define END_LOCKS(x) \
74289+ if (x != GR_DO_AUDIT) \
74290+ spin_unlock(&grsec_alert_lock); \
74291+ else \
74292+ spin_unlock(&grsec_audit_lock); \
74293+ read_unlock(&grsec_exec_file_lock); \
74294+ read_unlock(&tasklist_lock); \
74295+ rcu_read_unlock(); \
74296+ ENABLE_PREEMPT(); \
74297+ if (x == GR_DONT_AUDIT) \
74298+ gr_handle_alertkill(current)
74299+
74300+enum {
74301+ FLOODING,
74302+ NO_FLOODING
74303+};
74304+
74305+extern char *gr_alert_log_fmt;
74306+extern char *gr_audit_log_fmt;
74307+extern char *gr_alert_log_buf;
74308+extern char *gr_audit_log_buf;
74309+
74310+static int gr_log_start(int audit)
74311+{
74312+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
74313+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
74314+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74315+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
74316+ unsigned long curr_secs = get_seconds();
74317+
74318+ if (audit == GR_DO_AUDIT)
74319+ goto set_fmt;
74320+
74321+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
74322+ grsec_alert_wtime = curr_secs;
74323+ grsec_alert_fyet = 0;
74324+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
74325+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
74326+ grsec_alert_fyet++;
74327+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
74328+ grsec_alert_wtime = curr_secs;
74329+ grsec_alert_fyet++;
74330+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
74331+ return FLOODING;
74332+ }
74333+ else return FLOODING;
74334+
74335+set_fmt:
74336+#endif
74337+ memset(buf, 0, PAGE_SIZE);
74338+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
74339+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
74340+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74341+ } else if (current->signal->curr_ip) {
74342+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
74343+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
74344+ } else if (gr_acl_is_enabled()) {
74345+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
74346+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
74347+ } else {
74348+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
74349+ strcpy(buf, fmt);
74350+ }
74351+
74352+ return NO_FLOODING;
74353+}
74354+
74355+static void gr_log_middle(int audit, const char *msg, va_list ap)
74356+ __attribute__ ((format (printf, 2, 0)));
74357+
74358+static void gr_log_middle(int audit, const char *msg, va_list ap)
74359+{
74360+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74361+ unsigned int len = strlen(buf);
74362+
74363+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74364+
74365+ return;
74366+}
74367+
74368+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74369+ __attribute__ ((format (printf, 2, 3)));
74370+
74371+static void gr_log_middle_varargs(int audit, const char *msg, ...)
74372+{
74373+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74374+ unsigned int len = strlen(buf);
74375+ va_list ap;
74376+
74377+ va_start(ap, msg);
74378+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
74379+ va_end(ap);
74380+
74381+ return;
74382+}
74383+
74384+static void gr_log_end(int audit, int append_default)
74385+{
74386+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
74387+ if (append_default) {
74388+ struct task_struct *task = current;
74389+ struct task_struct *parent = task->real_parent;
74390+ const struct cred *cred = __task_cred(task);
74391+ const struct cred *pcred = __task_cred(parent);
74392+ unsigned int len = strlen(buf);
74393+
74394+ 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));
74395+ }
74396+
74397+ printk("%s\n", buf);
74398+
74399+ return;
74400+}
74401+
74402+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
74403+{
74404+ int logtype;
74405+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
74406+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
74407+ void *voidptr = NULL;
74408+ int num1 = 0, num2 = 0;
74409+ unsigned long ulong1 = 0, ulong2 = 0;
74410+ struct dentry *dentry = NULL;
74411+ struct vfsmount *mnt = NULL;
74412+ struct file *file = NULL;
74413+ struct task_struct *task = NULL;
74414+ struct vm_area_struct *vma = NULL;
74415+ const struct cred *cred, *pcred;
74416+ va_list ap;
74417+
74418+ BEGIN_LOCKS(audit);
74419+ logtype = gr_log_start(audit);
74420+ if (logtype == FLOODING) {
74421+ END_LOCKS(audit);
74422+ return;
74423+ }
74424+ va_start(ap, argtypes);
74425+ switch (argtypes) {
74426+ case GR_TTYSNIFF:
74427+ task = va_arg(ap, struct task_struct *);
74428+ 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));
74429+ break;
74430+ case GR_SYSCTL_HIDDEN:
74431+ str1 = va_arg(ap, char *);
74432+ gr_log_middle_varargs(audit, msg, result, str1);
74433+ break;
74434+ case GR_RBAC:
74435+ dentry = va_arg(ap, struct dentry *);
74436+ mnt = va_arg(ap, struct vfsmount *);
74437+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
74438+ break;
74439+ case GR_RBAC_STR:
74440+ dentry = va_arg(ap, struct dentry *);
74441+ mnt = va_arg(ap, struct vfsmount *);
74442+ str1 = va_arg(ap, char *);
74443+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
74444+ break;
74445+ case GR_STR_RBAC:
74446+ str1 = va_arg(ap, char *);
74447+ dentry = va_arg(ap, struct dentry *);
74448+ mnt = va_arg(ap, struct vfsmount *);
74449+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
74450+ break;
74451+ case GR_RBAC_MODE2:
74452+ dentry = va_arg(ap, struct dentry *);
74453+ mnt = va_arg(ap, struct vfsmount *);
74454+ str1 = va_arg(ap, char *);
74455+ str2 = va_arg(ap, char *);
74456+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
74457+ break;
74458+ case GR_RBAC_MODE3:
74459+ dentry = va_arg(ap, struct dentry *);
74460+ mnt = va_arg(ap, struct vfsmount *);
74461+ str1 = va_arg(ap, char *);
74462+ str2 = va_arg(ap, char *);
74463+ str3 = va_arg(ap, char *);
74464+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
74465+ break;
74466+ case GR_FILENAME:
74467+ dentry = va_arg(ap, struct dentry *);
74468+ mnt = va_arg(ap, struct vfsmount *);
74469+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
74470+ break;
74471+ case GR_STR_FILENAME:
74472+ str1 = va_arg(ap, char *);
74473+ dentry = va_arg(ap, struct dentry *);
74474+ mnt = va_arg(ap, struct vfsmount *);
74475+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
74476+ break;
74477+ case GR_FILENAME_STR:
74478+ dentry = va_arg(ap, struct dentry *);
74479+ mnt = va_arg(ap, struct vfsmount *);
74480+ str1 = va_arg(ap, char *);
74481+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
74482+ break;
74483+ case GR_FILENAME_TWO_INT:
74484+ dentry = va_arg(ap, struct dentry *);
74485+ mnt = va_arg(ap, struct vfsmount *);
74486+ num1 = va_arg(ap, int);
74487+ num2 = va_arg(ap, int);
74488+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
74489+ break;
74490+ case GR_FILENAME_TWO_INT_STR:
74491+ dentry = va_arg(ap, struct dentry *);
74492+ mnt = va_arg(ap, struct vfsmount *);
74493+ num1 = va_arg(ap, int);
74494+ num2 = va_arg(ap, int);
74495+ str1 = va_arg(ap, char *);
74496+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
74497+ break;
74498+ case GR_TEXTREL:
74499+ file = va_arg(ap, struct file *);
74500+ ulong1 = va_arg(ap, unsigned long);
74501+ ulong2 = va_arg(ap, unsigned long);
74502+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
74503+ break;
74504+ case GR_PTRACE:
74505+ task = va_arg(ap, struct task_struct *);
74506+ 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));
74507+ break;
74508+ case GR_RESOURCE:
74509+ task = va_arg(ap, struct task_struct *);
74510+ cred = __task_cred(task);
74511+ pcred = __task_cred(task->real_parent);
74512+ ulong1 = va_arg(ap, unsigned long);
74513+ str1 = va_arg(ap, char *);
74514+ ulong2 = va_arg(ap, unsigned long);
74515+ 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));
74516+ break;
74517+ case GR_CAP:
74518+ task = va_arg(ap, struct task_struct *);
74519+ cred = __task_cred(task);
74520+ pcred = __task_cred(task->real_parent);
74521+ str1 = va_arg(ap, char *);
74522+ 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));
74523+ break;
74524+ case GR_SIG:
74525+ str1 = va_arg(ap, char *);
74526+ voidptr = va_arg(ap, void *);
74527+ gr_log_middle_varargs(audit, msg, str1, voidptr);
74528+ break;
74529+ case GR_SIG2:
74530+ task = va_arg(ap, struct task_struct *);
74531+ cred = __task_cred(task);
74532+ pcred = __task_cred(task->real_parent);
74533+ num1 = va_arg(ap, int);
74534+ 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));
74535+ break;
74536+ case GR_CRASH1:
74537+ task = va_arg(ap, struct task_struct *);
74538+ cred = __task_cred(task);
74539+ pcred = __task_cred(task->real_parent);
74540+ ulong1 = va_arg(ap, unsigned long);
74541+ 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);
74542+ break;
74543+ case GR_CRASH2:
74544+ task = va_arg(ap, struct task_struct *);
74545+ cred = __task_cred(task);
74546+ pcred = __task_cred(task->real_parent);
74547+ ulong1 = va_arg(ap, unsigned long);
74548+ 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);
74549+ break;
74550+ case GR_RWXMAP:
74551+ file = va_arg(ap, struct file *);
74552+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
74553+ break;
74554+ case GR_RWXMAPVMA:
74555+ vma = va_arg(ap, struct vm_area_struct *);
74556+ if (vma->vm_file)
74557+ str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
74558+ else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
74559+ str1 = "<stack>";
74560+ else if (vma->vm_start <= current->mm->brk &&
74561+ vma->vm_end >= current->mm->start_brk)
74562+ str1 = "<heap>";
74563+ else
74564+ str1 = "<anonymous mapping>";
74565+ gr_log_middle_varargs(audit, msg, str1);
74566+ break;
74567+ case GR_PSACCT:
74568+ {
74569+ unsigned int wday, cday;
74570+ __u8 whr, chr;
74571+ __u8 wmin, cmin;
74572+ __u8 wsec, csec;
74573+ char cur_tty[64] = { 0 };
74574+ char parent_tty[64] = { 0 };
74575+
74576+ task = va_arg(ap, struct task_struct *);
74577+ wday = va_arg(ap, unsigned int);
74578+ cday = va_arg(ap, unsigned int);
74579+ whr = va_arg(ap, int);
74580+ chr = va_arg(ap, int);
74581+ wmin = va_arg(ap, int);
74582+ cmin = va_arg(ap, int);
74583+ wsec = va_arg(ap, int);
74584+ csec = va_arg(ap, int);
74585+ ulong1 = va_arg(ap, unsigned long);
74586+ cred = __task_cred(task);
74587+ pcred = __task_cred(task->real_parent);
74588+
74589+ 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));
74590+ }
74591+ break;
74592+ default:
74593+ gr_log_middle(audit, msg, ap);
74594+ }
74595+ va_end(ap);
74596+ // these don't need DEFAULTSECARGS printed on the end
74597+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
74598+ gr_log_end(audit, 0);
74599+ else
74600+ gr_log_end(audit, 1);
74601+ END_LOCKS(audit);
74602+}
74603diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
74604new file mode 100644
74605index 0000000..0e39d8c
74606--- /dev/null
74607+++ b/grsecurity/grsec_mem.c
74608@@ -0,0 +1,48 @@
74609+#include <linux/kernel.h>
74610+#include <linux/sched.h>
74611+#include <linux/mm.h>
74612+#include <linux/mman.h>
74613+#include <linux/module.h>
74614+#include <linux/grinternal.h>
74615+
74616+void gr_handle_msr_write(void)
74617+{
74618+ gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
74619+ return;
74620+}
74621+EXPORT_SYMBOL_GPL(gr_handle_msr_write);
74622+
74623+void
74624+gr_handle_ioperm(void)
74625+{
74626+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
74627+ return;
74628+}
74629+
74630+void
74631+gr_handle_iopl(void)
74632+{
74633+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
74634+ return;
74635+}
74636+
74637+void
74638+gr_handle_mem_readwrite(u64 from, u64 to)
74639+{
74640+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
74641+ return;
74642+}
74643+
74644+void
74645+gr_handle_vm86(void)
74646+{
74647+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
74648+ return;
74649+}
74650+
74651+void
74652+gr_log_badprocpid(const char *entry)
74653+{
74654+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
74655+ return;
74656+}
74657diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
74658new file mode 100644
74659index 0000000..cd9e124
74660--- /dev/null
74661+++ b/grsecurity/grsec_mount.c
74662@@ -0,0 +1,65 @@
74663+#include <linux/kernel.h>
74664+#include <linux/sched.h>
74665+#include <linux/mount.h>
74666+#include <linux/major.h>
74667+#include <linux/grsecurity.h>
74668+#include <linux/grinternal.h>
74669+
74670+void
74671+gr_log_remount(const char *devname, const int retval)
74672+{
74673+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74674+ if (grsec_enable_mount && (retval >= 0))
74675+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
74676+#endif
74677+ return;
74678+}
74679+
74680+void
74681+gr_log_unmount(const char *devname, const int retval)
74682+{
74683+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74684+ if (grsec_enable_mount && (retval >= 0))
74685+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
74686+#endif
74687+ return;
74688+}
74689+
74690+void
74691+gr_log_mount(const char *from, const char *to, const int retval)
74692+{
74693+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74694+ if (grsec_enable_mount && (retval >= 0))
74695+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
74696+#endif
74697+ return;
74698+}
74699+
74700+int
74701+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
74702+{
74703+#ifdef CONFIG_GRKERNSEC_ROFS
74704+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
74705+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
74706+ return -EPERM;
74707+ } else
74708+ return 0;
74709+#endif
74710+ return 0;
74711+}
74712+
74713+int
74714+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
74715+{
74716+#ifdef CONFIG_GRKERNSEC_ROFS
74717+ struct inode *inode = dentry->d_inode;
74718+
74719+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
74720+ inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
74721+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
74722+ return -EPERM;
74723+ } else
74724+ return 0;
74725+#endif
74726+ return 0;
74727+}
74728diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
74729new file mode 100644
74730index 0000000..6ee9d50
74731--- /dev/null
74732+++ b/grsecurity/grsec_pax.c
74733@@ -0,0 +1,45 @@
74734+#include <linux/kernel.h>
74735+#include <linux/sched.h>
74736+#include <linux/mm.h>
74737+#include <linux/file.h>
74738+#include <linux/grinternal.h>
74739+#include <linux/grsecurity.h>
74740+
74741+void
74742+gr_log_textrel(struct vm_area_struct * vma)
74743+{
74744+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74745+ if (grsec_enable_log_rwxmaps)
74746+ gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
74747+#endif
74748+ return;
74749+}
74750+
74751+void gr_log_ptgnustack(struct file *file)
74752+{
74753+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74754+ if (grsec_enable_log_rwxmaps)
74755+ gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
74756+#endif
74757+ return;
74758+}
74759+
74760+void
74761+gr_log_rwxmmap(struct file *file)
74762+{
74763+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74764+ if (grsec_enable_log_rwxmaps)
74765+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
74766+#endif
74767+ return;
74768+}
74769+
74770+void
74771+gr_log_rwxmprotect(struct vm_area_struct *vma)
74772+{
74773+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74774+ if (grsec_enable_log_rwxmaps)
74775+ gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
74776+#endif
74777+ return;
74778+}
74779diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
74780new file mode 100644
74781index 0000000..f7f29aa
74782--- /dev/null
74783+++ b/grsecurity/grsec_ptrace.c
74784@@ -0,0 +1,30 @@
74785+#include <linux/kernel.h>
74786+#include <linux/sched.h>
74787+#include <linux/grinternal.h>
74788+#include <linux/security.h>
74789+
74790+void
74791+gr_audit_ptrace(struct task_struct *task)
74792+{
74793+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74794+ if (grsec_enable_audit_ptrace)
74795+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
74796+#endif
74797+ return;
74798+}
74799+
74800+int
74801+gr_ptrace_readexec(struct file *file, int unsafe_flags)
74802+{
74803+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74804+ const struct dentry *dentry = file->f_path.dentry;
74805+ const struct vfsmount *mnt = file->f_path.mnt;
74806+
74807+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
74808+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
74809+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
74810+ return -EACCES;
74811+ }
74812+#endif
74813+ return 0;
74814+}
74815diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
74816new file mode 100644
74817index 0000000..3860c7e
74818--- /dev/null
74819+++ b/grsecurity/grsec_sig.c
74820@@ -0,0 +1,236 @@
74821+#include <linux/kernel.h>
74822+#include <linux/sched.h>
74823+#include <linux/fs.h>
74824+#include <linux/delay.h>
74825+#include <linux/grsecurity.h>
74826+#include <linux/grinternal.h>
74827+#include <linux/hardirq.h>
74828+
74829+char *signames[] = {
74830+ [SIGSEGV] = "Segmentation fault",
74831+ [SIGILL] = "Illegal instruction",
74832+ [SIGABRT] = "Abort",
74833+ [SIGBUS] = "Invalid alignment/Bus error"
74834+};
74835+
74836+void
74837+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
74838+{
74839+#ifdef CONFIG_GRKERNSEC_SIGNAL
74840+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
74841+ (sig == SIGABRT) || (sig == SIGBUS))) {
74842+ if (task_pid_nr(t) == task_pid_nr(current)) {
74843+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
74844+ } else {
74845+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
74846+ }
74847+ }
74848+#endif
74849+ return;
74850+}
74851+
74852+int
74853+gr_handle_signal(const struct task_struct *p, const int sig)
74854+{
74855+#ifdef CONFIG_GRKERNSEC
74856+ /* ignore the 0 signal for protected task checks */
74857+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
74858+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
74859+ return -EPERM;
74860+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
74861+ return -EPERM;
74862+ }
74863+#endif
74864+ return 0;
74865+}
74866+
74867+#ifdef CONFIG_GRKERNSEC
74868+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
74869+
74870+int gr_fake_force_sig(int sig, struct task_struct *t)
74871+{
74872+ unsigned long int flags;
74873+ int ret, blocked, ignored;
74874+ struct k_sigaction *action;
74875+
74876+ spin_lock_irqsave(&t->sighand->siglock, flags);
74877+ action = &t->sighand->action[sig-1];
74878+ ignored = action->sa.sa_handler == SIG_IGN;
74879+ blocked = sigismember(&t->blocked, sig);
74880+ if (blocked || ignored) {
74881+ action->sa.sa_handler = SIG_DFL;
74882+ if (blocked) {
74883+ sigdelset(&t->blocked, sig);
74884+ recalc_sigpending_and_wake(t);
74885+ }
74886+ }
74887+ if (action->sa.sa_handler == SIG_DFL)
74888+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
74889+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
74890+
74891+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
74892+
74893+ return ret;
74894+}
74895+#endif
74896+
74897+#define GR_USER_BAN_TIME (15 * 60)
74898+#define GR_DAEMON_BRUTE_TIME (30 * 60)
74899+
74900+void gr_handle_brute_attach(int dumpable)
74901+{
74902+#ifdef CONFIG_GRKERNSEC_BRUTE
74903+ struct task_struct *p = current;
74904+ kuid_t uid = GLOBAL_ROOT_UID;
74905+ int daemon = 0;
74906+
74907+ if (!grsec_enable_brute)
74908+ return;
74909+
74910+ rcu_read_lock();
74911+ read_lock(&tasklist_lock);
74912+ read_lock(&grsec_exec_file_lock);
74913+ if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74914+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74915+ p->real_parent->brute = 1;
74916+ daemon = 1;
74917+ } else {
74918+ const struct cred *cred = __task_cred(p), *cred2;
74919+ struct task_struct *tsk, *tsk2;
74920+
74921+ if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74922+ struct user_struct *user;
74923+
74924+ uid = cred->uid;
74925+
74926+ /* this is put upon execution past expiration */
74927+ user = find_user(uid);
74928+ if (user == NULL)
74929+ goto unlock;
74930+ user->suid_banned = 1;
74931+ user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74932+ if (user->suid_ban_expires == ~0UL)
74933+ user->suid_ban_expires--;
74934+
74935+ /* only kill other threads of the same binary, from the same user */
74936+ do_each_thread(tsk2, tsk) {
74937+ cred2 = __task_cred(tsk);
74938+ if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74939+ gr_fake_force_sig(SIGKILL, tsk);
74940+ } while_each_thread(tsk2, tsk);
74941+ }
74942+ }
74943+unlock:
74944+ read_unlock(&grsec_exec_file_lock);
74945+ read_unlock(&tasklist_lock);
74946+ rcu_read_unlock();
74947+
74948+ if (gr_is_global_nonroot(uid))
74949+ 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);
74950+ else if (daemon)
74951+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74952+
74953+#endif
74954+ return;
74955+}
74956+
74957+void gr_handle_brute_check(void)
74958+{
74959+#ifdef CONFIG_GRKERNSEC_BRUTE
74960+ struct task_struct *p = current;
74961+
74962+ if (unlikely(p->brute)) {
74963+ if (!grsec_enable_brute)
74964+ p->brute = 0;
74965+ else if (time_before(get_seconds(), p->brute_expires))
74966+ msleep(30 * 1000);
74967+ }
74968+#endif
74969+ return;
74970+}
74971+
74972+void gr_handle_kernel_exploit(void)
74973+{
74974+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74975+ const struct cred *cred;
74976+ struct task_struct *tsk, *tsk2;
74977+ struct user_struct *user;
74978+ kuid_t uid;
74979+
74980+ if (in_irq() || in_serving_softirq() || in_nmi())
74981+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74982+
74983+ uid = current_uid();
74984+
74985+ if (gr_is_global_root(uid))
74986+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
74987+ else {
74988+ /* kill all the processes of this user, hold a reference
74989+ to their creds struct, and prevent them from creating
74990+ another process until system reset
74991+ */
74992+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74993+ GR_GLOBAL_UID(uid));
74994+ /* we intentionally leak this ref */
74995+ user = get_uid(current->cred->user);
74996+ if (user)
74997+ user->kernel_banned = 1;
74998+
74999+ /* kill all processes of this user */
75000+ read_lock(&tasklist_lock);
75001+ do_each_thread(tsk2, tsk) {
75002+ cred = __task_cred(tsk);
75003+ if (uid_eq(cred->uid, uid))
75004+ gr_fake_force_sig(SIGKILL, tsk);
75005+ } while_each_thread(tsk2, tsk);
75006+ read_unlock(&tasklist_lock);
75007+ }
75008+#endif
75009+}
75010+
75011+#ifdef CONFIG_GRKERNSEC_BRUTE
75012+static bool suid_ban_expired(struct user_struct *user)
75013+{
75014+ if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75015+ user->suid_banned = 0;
75016+ user->suid_ban_expires = 0;
75017+ free_uid(user);
75018+ return true;
75019+ }
75020+
75021+ return false;
75022+}
75023+#endif
75024+
75025+int gr_process_kernel_exec_ban(void)
75026+{
75027+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75028+ if (unlikely(current->cred->user->kernel_banned))
75029+ return -EPERM;
75030+#endif
75031+ return 0;
75032+}
75033+
75034+int gr_process_kernel_setuid_ban(struct user_struct *user)
75035+{
75036+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75037+ if (unlikely(user->kernel_banned))
75038+ gr_fake_force_sig(SIGKILL, current);
75039+#endif
75040+ return 0;
75041+}
75042+
75043+int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75044+{
75045+#ifdef CONFIG_GRKERNSEC_BRUTE
75046+ struct user_struct *user = current->cred->user;
75047+ if (unlikely(user->suid_banned)) {
75048+ if (suid_ban_expired(user))
75049+ return 0;
75050+ /* disallow execution of suid binaries only */
75051+ else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75052+ return -EPERM;
75053+ }
75054+#endif
75055+ return 0;
75056+}
75057diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75058new file mode 100644
75059index 0000000..c0aef3a
75060--- /dev/null
75061+++ b/grsecurity/grsec_sock.c
75062@@ -0,0 +1,244 @@
75063+#include <linux/kernel.h>
75064+#include <linux/module.h>
75065+#include <linux/sched.h>
75066+#include <linux/file.h>
75067+#include <linux/net.h>
75068+#include <linux/in.h>
75069+#include <linux/ip.h>
75070+#include <net/sock.h>
75071+#include <net/inet_sock.h>
75072+#include <linux/grsecurity.h>
75073+#include <linux/grinternal.h>
75074+#include <linux/gracl.h>
75075+
75076+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75077+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75078+
75079+EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75080+EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75081+
75082+#ifdef CONFIG_UNIX_MODULE
75083+EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75084+EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75085+EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75086+EXPORT_SYMBOL_GPL(gr_handle_create);
75087+#endif
75088+
75089+#ifdef CONFIG_GRKERNSEC
75090+#define gr_conn_table_size 32749
75091+struct conn_table_entry {
75092+ struct conn_table_entry *next;
75093+ struct signal_struct *sig;
75094+};
75095+
75096+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75097+DEFINE_SPINLOCK(gr_conn_table_lock);
75098+
75099+extern const char * gr_socktype_to_name(unsigned char type);
75100+extern const char * gr_proto_to_name(unsigned char proto);
75101+extern const char * gr_sockfamily_to_name(unsigned char family);
75102+
75103+static __inline__ int
75104+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75105+{
75106+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75107+}
75108+
75109+static __inline__ int
75110+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75111+ __u16 sport, __u16 dport)
75112+{
75113+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75114+ sig->gr_sport == sport && sig->gr_dport == dport))
75115+ return 1;
75116+ else
75117+ return 0;
75118+}
75119+
75120+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75121+{
75122+ struct conn_table_entry **match;
75123+ unsigned int index;
75124+
75125+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75126+ sig->gr_sport, sig->gr_dport,
75127+ gr_conn_table_size);
75128+
75129+ newent->sig = sig;
75130+
75131+ match = &gr_conn_table[index];
75132+ newent->next = *match;
75133+ *match = newent;
75134+
75135+ return;
75136+}
75137+
75138+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75139+{
75140+ struct conn_table_entry *match, *last = NULL;
75141+ unsigned int index;
75142+
75143+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75144+ sig->gr_sport, sig->gr_dport,
75145+ gr_conn_table_size);
75146+
75147+ match = gr_conn_table[index];
75148+ while (match && !conn_match(match->sig,
75149+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75150+ sig->gr_dport)) {
75151+ last = match;
75152+ match = match->next;
75153+ }
75154+
75155+ if (match) {
75156+ if (last)
75157+ last->next = match->next;
75158+ else
75159+ gr_conn_table[index] = NULL;
75160+ kfree(match);
75161+ }
75162+
75163+ return;
75164+}
75165+
75166+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75167+ __u16 sport, __u16 dport)
75168+{
75169+ struct conn_table_entry *match;
75170+ unsigned int index;
75171+
75172+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75173+
75174+ match = gr_conn_table[index];
75175+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75176+ match = match->next;
75177+
75178+ if (match)
75179+ return match->sig;
75180+ else
75181+ return NULL;
75182+}
75183+
75184+#endif
75185+
75186+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75187+{
75188+#ifdef CONFIG_GRKERNSEC
75189+ struct signal_struct *sig = task->signal;
75190+ struct conn_table_entry *newent;
75191+
75192+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75193+ if (newent == NULL)
75194+ return;
75195+ /* no bh lock needed since we are called with bh disabled */
75196+ spin_lock(&gr_conn_table_lock);
75197+ gr_del_task_from_ip_table_nolock(sig);
75198+ sig->gr_saddr = inet->inet_rcv_saddr;
75199+ sig->gr_daddr = inet->inet_daddr;
75200+ sig->gr_sport = inet->inet_sport;
75201+ sig->gr_dport = inet->inet_dport;
75202+ gr_add_to_task_ip_table_nolock(sig, newent);
75203+ spin_unlock(&gr_conn_table_lock);
75204+#endif
75205+ return;
75206+}
75207+
75208+void gr_del_task_from_ip_table(struct task_struct *task)
75209+{
75210+#ifdef CONFIG_GRKERNSEC
75211+ spin_lock_bh(&gr_conn_table_lock);
75212+ gr_del_task_from_ip_table_nolock(task->signal);
75213+ spin_unlock_bh(&gr_conn_table_lock);
75214+#endif
75215+ return;
75216+}
75217+
75218+void
75219+gr_attach_curr_ip(const struct sock *sk)
75220+{
75221+#ifdef CONFIG_GRKERNSEC
75222+ struct signal_struct *p, *set;
75223+ const struct inet_sock *inet = inet_sk(sk);
75224+
75225+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75226+ return;
75227+
75228+ set = current->signal;
75229+
75230+ spin_lock_bh(&gr_conn_table_lock);
75231+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75232+ inet->inet_dport, inet->inet_sport);
75233+ if (unlikely(p != NULL)) {
75234+ set->curr_ip = p->curr_ip;
75235+ set->used_accept = 1;
75236+ gr_del_task_from_ip_table_nolock(p);
75237+ spin_unlock_bh(&gr_conn_table_lock);
75238+ return;
75239+ }
75240+ spin_unlock_bh(&gr_conn_table_lock);
75241+
75242+ set->curr_ip = inet->inet_daddr;
75243+ set->used_accept = 1;
75244+#endif
75245+ return;
75246+}
75247+
75248+int
75249+gr_handle_sock_all(const int family, const int type, const int protocol)
75250+{
75251+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75252+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75253+ (family != AF_UNIX)) {
75254+ if (family == AF_INET)
75255+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75256+ else
75257+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75258+ return -EACCES;
75259+ }
75260+#endif
75261+ return 0;
75262+}
75263+
75264+int
75265+gr_handle_sock_server(const struct sockaddr *sck)
75266+{
75267+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75268+ if (grsec_enable_socket_server &&
75269+ in_group_p(grsec_socket_server_gid) &&
75270+ sck && (sck->sa_family != AF_UNIX) &&
75271+ (sck->sa_family != AF_LOCAL)) {
75272+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75273+ return -EACCES;
75274+ }
75275+#endif
75276+ return 0;
75277+}
75278+
75279+int
75280+gr_handle_sock_server_other(const struct sock *sck)
75281+{
75282+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75283+ if (grsec_enable_socket_server &&
75284+ in_group_p(grsec_socket_server_gid) &&
75285+ sck && (sck->sk_family != AF_UNIX) &&
75286+ (sck->sk_family != AF_LOCAL)) {
75287+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
75288+ return -EACCES;
75289+ }
75290+#endif
75291+ return 0;
75292+}
75293+
75294+int
75295+gr_handle_sock_client(const struct sockaddr *sck)
75296+{
75297+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75298+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
75299+ sck && (sck->sa_family != AF_UNIX) &&
75300+ (sck->sa_family != AF_LOCAL)) {
75301+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
75302+ return -EACCES;
75303+ }
75304+#endif
75305+ return 0;
75306+}
75307diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
75308new file mode 100644
75309index 0000000..8159888
75310--- /dev/null
75311+++ b/grsecurity/grsec_sysctl.c
75312@@ -0,0 +1,479 @@
75313+#include <linux/kernel.h>
75314+#include <linux/sched.h>
75315+#include <linux/sysctl.h>
75316+#include <linux/grsecurity.h>
75317+#include <linux/grinternal.h>
75318+
75319+int
75320+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
75321+{
75322+#ifdef CONFIG_GRKERNSEC_SYSCTL
75323+ if (dirname == NULL || name == NULL)
75324+ return 0;
75325+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
75326+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
75327+ return -EACCES;
75328+ }
75329+#endif
75330+ return 0;
75331+}
75332+
75333+#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
75334+static int __maybe_unused __read_only one = 1;
75335+#endif
75336+
75337+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
75338+ defined(CONFIG_GRKERNSEC_DENYUSB)
75339+struct ctl_table grsecurity_table[] = {
75340+#ifdef CONFIG_GRKERNSEC_SYSCTL
75341+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
75342+#ifdef CONFIG_GRKERNSEC_IO
75343+ {
75344+ .procname = "disable_priv_io",
75345+ .data = &grsec_disable_privio,
75346+ .maxlen = sizeof(int),
75347+ .mode = 0600,
75348+ .proc_handler = &proc_dointvec,
75349+ },
75350+#endif
75351+#endif
75352+#ifdef CONFIG_GRKERNSEC_LINK
75353+ {
75354+ .procname = "linking_restrictions",
75355+ .data = &grsec_enable_link,
75356+ .maxlen = sizeof(int),
75357+ .mode = 0600,
75358+ .proc_handler = &proc_dointvec,
75359+ },
75360+#endif
75361+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
75362+ {
75363+ .procname = "enforce_symlinksifowner",
75364+ .data = &grsec_enable_symlinkown,
75365+ .maxlen = sizeof(int),
75366+ .mode = 0600,
75367+ .proc_handler = &proc_dointvec,
75368+ },
75369+ {
75370+ .procname = "symlinkown_gid",
75371+ .data = &grsec_symlinkown_gid,
75372+ .maxlen = sizeof(int),
75373+ .mode = 0600,
75374+ .proc_handler = &proc_dointvec,
75375+ },
75376+#endif
75377+#ifdef CONFIG_GRKERNSEC_BRUTE
75378+ {
75379+ .procname = "deter_bruteforce",
75380+ .data = &grsec_enable_brute,
75381+ .maxlen = sizeof(int),
75382+ .mode = 0600,
75383+ .proc_handler = &proc_dointvec,
75384+ },
75385+#endif
75386+#ifdef CONFIG_GRKERNSEC_FIFO
75387+ {
75388+ .procname = "fifo_restrictions",
75389+ .data = &grsec_enable_fifo,
75390+ .maxlen = sizeof(int),
75391+ .mode = 0600,
75392+ .proc_handler = &proc_dointvec,
75393+ },
75394+#endif
75395+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75396+ {
75397+ .procname = "ptrace_readexec",
75398+ .data = &grsec_enable_ptrace_readexec,
75399+ .maxlen = sizeof(int),
75400+ .mode = 0600,
75401+ .proc_handler = &proc_dointvec,
75402+ },
75403+#endif
75404+#ifdef CONFIG_GRKERNSEC_SETXID
75405+ {
75406+ .procname = "consistent_setxid",
75407+ .data = &grsec_enable_setxid,
75408+ .maxlen = sizeof(int),
75409+ .mode = 0600,
75410+ .proc_handler = &proc_dointvec,
75411+ },
75412+#endif
75413+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
75414+ {
75415+ .procname = "ip_blackhole",
75416+ .data = &grsec_enable_blackhole,
75417+ .maxlen = sizeof(int),
75418+ .mode = 0600,
75419+ .proc_handler = &proc_dointvec,
75420+ },
75421+ {
75422+ .procname = "lastack_retries",
75423+ .data = &grsec_lastack_retries,
75424+ .maxlen = sizeof(int),
75425+ .mode = 0600,
75426+ .proc_handler = &proc_dointvec,
75427+ },
75428+#endif
75429+#ifdef CONFIG_GRKERNSEC_EXECLOG
75430+ {
75431+ .procname = "exec_logging",
75432+ .data = &grsec_enable_execlog,
75433+ .maxlen = sizeof(int),
75434+ .mode = 0600,
75435+ .proc_handler = &proc_dointvec,
75436+ },
75437+#endif
75438+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75439+ {
75440+ .procname = "rwxmap_logging",
75441+ .data = &grsec_enable_log_rwxmaps,
75442+ .maxlen = sizeof(int),
75443+ .mode = 0600,
75444+ .proc_handler = &proc_dointvec,
75445+ },
75446+#endif
75447+#ifdef CONFIG_GRKERNSEC_SIGNAL
75448+ {
75449+ .procname = "signal_logging",
75450+ .data = &grsec_enable_signal,
75451+ .maxlen = sizeof(int),
75452+ .mode = 0600,
75453+ .proc_handler = &proc_dointvec,
75454+ },
75455+#endif
75456+#ifdef CONFIG_GRKERNSEC_FORKFAIL
75457+ {
75458+ .procname = "forkfail_logging",
75459+ .data = &grsec_enable_forkfail,
75460+ .maxlen = sizeof(int),
75461+ .mode = 0600,
75462+ .proc_handler = &proc_dointvec,
75463+ },
75464+#endif
75465+#ifdef CONFIG_GRKERNSEC_TIME
75466+ {
75467+ .procname = "timechange_logging",
75468+ .data = &grsec_enable_time,
75469+ .maxlen = sizeof(int),
75470+ .mode = 0600,
75471+ .proc_handler = &proc_dointvec,
75472+ },
75473+#endif
75474+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
75475+ {
75476+ .procname = "chroot_deny_shmat",
75477+ .data = &grsec_enable_chroot_shmat,
75478+ .maxlen = sizeof(int),
75479+ .mode = 0600,
75480+ .proc_handler = &proc_dointvec,
75481+ },
75482+#endif
75483+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
75484+ {
75485+ .procname = "chroot_deny_unix",
75486+ .data = &grsec_enable_chroot_unix,
75487+ .maxlen = sizeof(int),
75488+ .mode = 0600,
75489+ .proc_handler = &proc_dointvec,
75490+ },
75491+#endif
75492+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
75493+ {
75494+ .procname = "chroot_deny_mount",
75495+ .data = &grsec_enable_chroot_mount,
75496+ .maxlen = sizeof(int),
75497+ .mode = 0600,
75498+ .proc_handler = &proc_dointvec,
75499+ },
75500+#endif
75501+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
75502+ {
75503+ .procname = "chroot_deny_fchdir",
75504+ .data = &grsec_enable_chroot_fchdir,
75505+ .maxlen = sizeof(int),
75506+ .mode = 0600,
75507+ .proc_handler = &proc_dointvec,
75508+ },
75509+#endif
75510+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
75511+ {
75512+ .procname = "chroot_deny_chroot",
75513+ .data = &grsec_enable_chroot_double,
75514+ .maxlen = sizeof(int),
75515+ .mode = 0600,
75516+ .proc_handler = &proc_dointvec,
75517+ },
75518+#endif
75519+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
75520+ {
75521+ .procname = "chroot_deny_pivot",
75522+ .data = &grsec_enable_chroot_pivot,
75523+ .maxlen = sizeof(int),
75524+ .mode = 0600,
75525+ .proc_handler = &proc_dointvec,
75526+ },
75527+#endif
75528+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
75529+ {
75530+ .procname = "chroot_enforce_chdir",
75531+ .data = &grsec_enable_chroot_chdir,
75532+ .maxlen = sizeof(int),
75533+ .mode = 0600,
75534+ .proc_handler = &proc_dointvec,
75535+ },
75536+#endif
75537+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
75538+ {
75539+ .procname = "chroot_deny_chmod",
75540+ .data = &grsec_enable_chroot_chmod,
75541+ .maxlen = sizeof(int),
75542+ .mode = 0600,
75543+ .proc_handler = &proc_dointvec,
75544+ },
75545+#endif
75546+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
75547+ {
75548+ .procname = "chroot_deny_mknod",
75549+ .data = &grsec_enable_chroot_mknod,
75550+ .maxlen = sizeof(int),
75551+ .mode = 0600,
75552+ .proc_handler = &proc_dointvec,
75553+ },
75554+#endif
75555+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
75556+ {
75557+ .procname = "chroot_restrict_nice",
75558+ .data = &grsec_enable_chroot_nice,
75559+ .maxlen = sizeof(int),
75560+ .mode = 0600,
75561+ .proc_handler = &proc_dointvec,
75562+ },
75563+#endif
75564+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
75565+ {
75566+ .procname = "chroot_execlog",
75567+ .data = &grsec_enable_chroot_execlog,
75568+ .maxlen = sizeof(int),
75569+ .mode = 0600,
75570+ .proc_handler = &proc_dointvec,
75571+ },
75572+#endif
75573+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
75574+ {
75575+ .procname = "chroot_caps",
75576+ .data = &grsec_enable_chroot_caps,
75577+ .maxlen = sizeof(int),
75578+ .mode = 0600,
75579+ .proc_handler = &proc_dointvec,
75580+ },
75581+#endif
75582+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
75583+ {
75584+ .procname = "chroot_deny_sysctl",
75585+ .data = &grsec_enable_chroot_sysctl,
75586+ .maxlen = sizeof(int),
75587+ .mode = 0600,
75588+ .proc_handler = &proc_dointvec,
75589+ },
75590+#endif
75591+#ifdef CONFIG_GRKERNSEC_TPE
75592+ {
75593+ .procname = "tpe",
75594+ .data = &grsec_enable_tpe,
75595+ .maxlen = sizeof(int),
75596+ .mode = 0600,
75597+ .proc_handler = &proc_dointvec,
75598+ },
75599+ {
75600+ .procname = "tpe_gid",
75601+ .data = &grsec_tpe_gid,
75602+ .maxlen = sizeof(int),
75603+ .mode = 0600,
75604+ .proc_handler = &proc_dointvec,
75605+ },
75606+#endif
75607+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75608+ {
75609+ .procname = "tpe_invert",
75610+ .data = &grsec_enable_tpe_invert,
75611+ .maxlen = sizeof(int),
75612+ .mode = 0600,
75613+ .proc_handler = &proc_dointvec,
75614+ },
75615+#endif
75616+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75617+ {
75618+ .procname = "tpe_restrict_all",
75619+ .data = &grsec_enable_tpe_all,
75620+ .maxlen = sizeof(int),
75621+ .mode = 0600,
75622+ .proc_handler = &proc_dointvec,
75623+ },
75624+#endif
75625+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75626+ {
75627+ .procname = "socket_all",
75628+ .data = &grsec_enable_socket_all,
75629+ .maxlen = sizeof(int),
75630+ .mode = 0600,
75631+ .proc_handler = &proc_dointvec,
75632+ },
75633+ {
75634+ .procname = "socket_all_gid",
75635+ .data = &grsec_socket_all_gid,
75636+ .maxlen = sizeof(int),
75637+ .mode = 0600,
75638+ .proc_handler = &proc_dointvec,
75639+ },
75640+#endif
75641+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
75642+ {
75643+ .procname = "socket_client",
75644+ .data = &grsec_enable_socket_client,
75645+ .maxlen = sizeof(int),
75646+ .mode = 0600,
75647+ .proc_handler = &proc_dointvec,
75648+ },
75649+ {
75650+ .procname = "socket_client_gid",
75651+ .data = &grsec_socket_client_gid,
75652+ .maxlen = sizeof(int),
75653+ .mode = 0600,
75654+ .proc_handler = &proc_dointvec,
75655+ },
75656+#endif
75657+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75658+ {
75659+ .procname = "socket_server",
75660+ .data = &grsec_enable_socket_server,
75661+ .maxlen = sizeof(int),
75662+ .mode = 0600,
75663+ .proc_handler = &proc_dointvec,
75664+ },
75665+ {
75666+ .procname = "socket_server_gid",
75667+ .data = &grsec_socket_server_gid,
75668+ .maxlen = sizeof(int),
75669+ .mode = 0600,
75670+ .proc_handler = &proc_dointvec,
75671+ },
75672+#endif
75673+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
75674+ {
75675+ .procname = "audit_group",
75676+ .data = &grsec_enable_group,
75677+ .maxlen = sizeof(int),
75678+ .mode = 0600,
75679+ .proc_handler = &proc_dointvec,
75680+ },
75681+ {
75682+ .procname = "audit_gid",
75683+ .data = &grsec_audit_gid,
75684+ .maxlen = sizeof(int),
75685+ .mode = 0600,
75686+ .proc_handler = &proc_dointvec,
75687+ },
75688+#endif
75689+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
75690+ {
75691+ .procname = "audit_chdir",
75692+ .data = &grsec_enable_chdir,
75693+ .maxlen = sizeof(int),
75694+ .mode = 0600,
75695+ .proc_handler = &proc_dointvec,
75696+ },
75697+#endif
75698+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75699+ {
75700+ .procname = "audit_mount",
75701+ .data = &grsec_enable_mount,
75702+ .maxlen = sizeof(int),
75703+ .mode = 0600,
75704+ .proc_handler = &proc_dointvec,
75705+ },
75706+#endif
75707+#ifdef CONFIG_GRKERNSEC_DMESG
75708+ {
75709+ .procname = "dmesg",
75710+ .data = &grsec_enable_dmesg,
75711+ .maxlen = sizeof(int),
75712+ .mode = 0600,
75713+ .proc_handler = &proc_dointvec,
75714+ },
75715+#endif
75716+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
75717+ {
75718+ .procname = "chroot_findtask",
75719+ .data = &grsec_enable_chroot_findtask,
75720+ .maxlen = sizeof(int),
75721+ .mode = 0600,
75722+ .proc_handler = &proc_dointvec,
75723+ },
75724+#endif
75725+#ifdef CONFIG_GRKERNSEC_RESLOG
75726+ {
75727+ .procname = "resource_logging",
75728+ .data = &grsec_resource_logging,
75729+ .maxlen = sizeof(int),
75730+ .mode = 0600,
75731+ .proc_handler = &proc_dointvec,
75732+ },
75733+#endif
75734+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75735+ {
75736+ .procname = "audit_ptrace",
75737+ .data = &grsec_enable_audit_ptrace,
75738+ .maxlen = sizeof(int),
75739+ .mode = 0600,
75740+ .proc_handler = &proc_dointvec,
75741+ },
75742+#endif
75743+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
75744+ {
75745+ .procname = "harden_ptrace",
75746+ .data = &grsec_enable_harden_ptrace,
75747+ .maxlen = sizeof(int),
75748+ .mode = 0600,
75749+ .proc_handler = &proc_dointvec,
75750+ },
75751+#endif
75752+#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
75753+ {
75754+ .procname = "harden_ipc",
75755+ .data = &grsec_enable_harden_ipc,
75756+ .maxlen = sizeof(int),
75757+ .mode = 0600,
75758+ .proc_handler = &proc_dointvec,
75759+ },
75760+#endif
75761+ {
75762+ .procname = "grsec_lock",
75763+ .data = &grsec_lock,
75764+ .maxlen = sizeof(int),
75765+ .mode = 0600,
75766+ .proc_handler = &proc_dointvec,
75767+ },
75768+#endif
75769+#ifdef CONFIG_GRKERNSEC_ROFS
75770+ {
75771+ .procname = "romount_protect",
75772+ .data = &grsec_enable_rofs,
75773+ .maxlen = sizeof(int),
75774+ .mode = 0600,
75775+ .proc_handler = &proc_dointvec_minmax,
75776+ .extra1 = &one,
75777+ .extra2 = &one,
75778+ },
75779+#endif
75780+#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
75781+ {
75782+ .procname = "deny_new_usb",
75783+ .data = &grsec_deny_new_usb,
75784+ .maxlen = sizeof(int),
75785+ .mode = 0600,
75786+ .proc_handler = &proc_dointvec,
75787+ },
75788+#endif
75789+ { }
75790+};
75791+#endif
75792diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
75793new file mode 100644
75794index 0000000..61b514e
75795--- /dev/null
75796+++ b/grsecurity/grsec_time.c
75797@@ -0,0 +1,16 @@
75798+#include <linux/kernel.h>
75799+#include <linux/sched.h>
75800+#include <linux/grinternal.h>
75801+#include <linux/module.h>
75802+
75803+void
75804+gr_log_timechange(void)
75805+{
75806+#ifdef CONFIG_GRKERNSEC_TIME
75807+ if (grsec_enable_time)
75808+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
75809+#endif
75810+ return;
75811+}
75812+
75813+EXPORT_SYMBOL_GPL(gr_log_timechange);
75814diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
75815new file mode 100644
75816index 0000000..ee57dcf
75817--- /dev/null
75818+++ b/grsecurity/grsec_tpe.c
75819@@ -0,0 +1,73 @@
75820+#include <linux/kernel.h>
75821+#include <linux/sched.h>
75822+#include <linux/file.h>
75823+#include <linux/fs.h>
75824+#include <linux/grinternal.h>
75825+
75826+extern int gr_acl_tpe_check(void);
75827+
75828+int
75829+gr_tpe_allow(const struct file *file)
75830+{
75831+#ifdef CONFIG_GRKERNSEC
75832+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
75833+ const struct cred *cred = current_cred();
75834+ char *msg = NULL;
75835+ char *msg2 = NULL;
75836+
75837+ // never restrict root
75838+ if (gr_is_global_root(cred->uid))
75839+ return 1;
75840+
75841+ if (grsec_enable_tpe) {
75842+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
75843+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
75844+ msg = "not being in trusted group";
75845+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
75846+ msg = "being in untrusted group";
75847+#else
75848+ if (in_group_p(grsec_tpe_gid))
75849+ msg = "being in untrusted group";
75850+#endif
75851+ }
75852+ if (!msg && gr_acl_tpe_check())
75853+ msg = "being in untrusted role";
75854+
75855+ // not in any affected group/role
75856+ if (!msg)
75857+ goto next_check;
75858+
75859+ if (gr_is_global_nonroot(inode->i_uid))
75860+ msg2 = "file in non-root-owned directory";
75861+ else if (inode->i_mode & S_IWOTH)
75862+ msg2 = "file in world-writable directory";
75863+ else if (inode->i_mode & S_IWGRP)
75864+ msg2 = "file in group-writable directory";
75865+
75866+ if (msg && msg2) {
75867+ char fullmsg[70] = {0};
75868+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
75869+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
75870+ return 0;
75871+ }
75872+ msg = NULL;
75873+next_check:
75874+#ifdef CONFIG_GRKERNSEC_TPE_ALL
75875+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
75876+ return 1;
75877+
75878+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
75879+ msg = "directory not owned by user";
75880+ else if (inode->i_mode & S_IWOTH)
75881+ msg = "file in world-writable directory";
75882+ else if (inode->i_mode & S_IWGRP)
75883+ msg = "file in group-writable directory";
75884+
75885+ if (msg) {
75886+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
75887+ return 0;
75888+ }
75889+#endif
75890+#endif
75891+ return 1;
75892+}
75893diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
75894new file mode 100644
75895index 0000000..ae02d8e
75896--- /dev/null
75897+++ b/grsecurity/grsec_usb.c
75898@@ -0,0 +1,15 @@
75899+#include <linux/kernel.h>
75900+#include <linux/grinternal.h>
75901+#include <linux/module.h>
75902+
75903+int gr_handle_new_usb(void)
75904+{
75905+#ifdef CONFIG_GRKERNSEC_DENYUSB
75906+ if (grsec_deny_new_usb) {
75907+ printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75908+ return 1;
75909+ }
75910+#endif
75911+ return 0;
75912+}
75913+EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75914diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75915new file mode 100644
75916index 0000000..9f7b1ac
75917--- /dev/null
75918+++ b/grsecurity/grsum.c
75919@@ -0,0 +1,61 @@
75920+#include <linux/err.h>
75921+#include <linux/kernel.h>
75922+#include <linux/sched.h>
75923+#include <linux/mm.h>
75924+#include <linux/scatterlist.h>
75925+#include <linux/crypto.h>
75926+#include <linux/gracl.h>
75927+
75928+
75929+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75930+#error "crypto and sha256 must be built into the kernel"
75931+#endif
75932+
75933+int
75934+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75935+{
75936+ char *p;
75937+ struct crypto_hash *tfm;
75938+ struct hash_desc desc;
75939+ struct scatterlist sg;
75940+ unsigned char temp_sum[GR_SHA_LEN];
75941+ volatile int retval = 0;
75942+ volatile int dummy = 0;
75943+ unsigned int i;
75944+
75945+ sg_init_table(&sg, 1);
75946+
75947+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75948+ if (IS_ERR(tfm)) {
75949+ /* should never happen, since sha256 should be built in */
75950+ return 1;
75951+ }
75952+
75953+ desc.tfm = tfm;
75954+ desc.flags = 0;
75955+
75956+ crypto_hash_init(&desc);
75957+
75958+ p = salt;
75959+ sg_set_buf(&sg, p, GR_SALT_LEN);
75960+ crypto_hash_update(&desc, &sg, sg.length);
75961+
75962+ p = entry->pw;
75963+ sg_set_buf(&sg, p, strlen(p));
75964+
75965+ crypto_hash_update(&desc, &sg, sg.length);
75966+
75967+ crypto_hash_final(&desc, temp_sum);
75968+
75969+ memset(entry->pw, 0, GR_PW_LEN);
75970+
75971+ for (i = 0; i < GR_SHA_LEN; i++)
75972+ if (sum[i] != temp_sum[i])
75973+ retval = 1;
75974+ else
75975+ dummy = 1; // waste a cycle
75976+
75977+ crypto_free_hash(tfm);
75978+
75979+ return retval;
75980+}
75981diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75982index 77ff547..181834f 100644
75983--- a/include/asm-generic/4level-fixup.h
75984+++ b/include/asm-generic/4level-fixup.h
75985@@ -13,8 +13,10 @@
75986 #define pmd_alloc(mm, pud, address) \
75987 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75988 NULL: pmd_offset(pud, address))
75989+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75990
75991 #define pud_alloc(mm, pgd, address) (pgd)
75992+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75993 #define pud_offset(pgd, start) (pgd)
75994 #define pud_none(pud) 0
75995 #define pud_bad(pud) 0
75996diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75997index b7babf0..97f4c4f 100644
75998--- a/include/asm-generic/atomic-long.h
75999+++ b/include/asm-generic/atomic-long.h
76000@@ -22,6 +22,12 @@
76001
76002 typedef atomic64_t atomic_long_t;
76003
76004+#ifdef CONFIG_PAX_REFCOUNT
76005+typedef atomic64_unchecked_t atomic_long_unchecked_t;
76006+#else
76007+typedef atomic64_t atomic_long_unchecked_t;
76008+#endif
76009+
76010 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76011
76012 static inline long atomic_long_read(atomic_long_t *l)
76013@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76014 return (long)atomic64_read(v);
76015 }
76016
76017+#ifdef CONFIG_PAX_REFCOUNT
76018+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76019+{
76020+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76021+
76022+ return (long)atomic64_read_unchecked(v);
76023+}
76024+#endif
76025+
76026 static inline void atomic_long_set(atomic_long_t *l, long i)
76027 {
76028 atomic64_t *v = (atomic64_t *)l;
76029@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76030 atomic64_set(v, i);
76031 }
76032
76033+#ifdef CONFIG_PAX_REFCOUNT
76034+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76035+{
76036+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76037+
76038+ atomic64_set_unchecked(v, i);
76039+}
76040+#endif
76041+
76042 static inline void atomic_long_inc(atomic_long_t *l)
76043 {
76044 atomic64_t *v = (atomic64_t *)l;
76045@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76046 atomic64_inc(v);
76047 }
76048
76049+#ifdef CONFIG_PAX_REFCOUNT
76050+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76051+{
76052+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76053+
76054+ atomic64_inc_unchecked(v);
76055+}
76056+#endif
76057+
76058 static inline void atomic_long_dec(atomic_long_t *l)
76059 {
76060 atomic64_t *v = (atomic64_t *)l;
76061@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76062 atomic64_dec(v);
76063 }
76064
76065+#ifdef CONFIG_PAX_REFCOUNT
76066+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76067+{
76068+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76069+
76070+ atomic64_dec_unchecked(v);
76071+}
76072+#endif
76073+
76074 static inline void atomic_long_add(long i, atomic_long_t *l)
76075 {
76076 atomic64_t *v = (atomic64_t *)l;
76077@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76078 atomic64_add(i, v);
76079 }
76080
76081+#ifdef CONFIG_PAX_REFCOUNT
76082+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76083+{
76084+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76085+
76086+ atomic64_add_unchecked(i, v);
76087+}
76088+#endif
76089+
76090 static inline void atomic_long_sub(long i, atomic_long_t *l)
76091 {
76092 atomic64_t *v = (atomic64_t *)l;
76093@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76094 atomic64_sub(i, v);
76095 }
76096
76097+#ifdef CONFIG_PAX_REFCOUNT
76098+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76099+{
76100+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76101+
76102+ atomic64_sub_unchecked(i, v);
76103+}
76104+#endif
76105+
76106 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76107 {
76108 atomic64_t *v = (atomic64_t *)l;
76109@@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76110 return atomic64_add_negative(i, v);
76111 }
76112
76113-static inline long atomic_long_add_return(long i, atomic_long_t *l)
76114+static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76115 {
76116 atomic64_t *v = (atomic64_t *)l;
76117
76118 return (long)atomic64_add_return(i, v);
76119 }
76120
76121+#ifdef CONFIG_PAX_REFCOUNT
76122+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76123+{
76124+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76125+
76126+ return (long)atomic64_add_return_unchecked(i, v);
76127+}
76128+#endif
76129+
76130 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76131 {
76132 atomic64_t *v = (atomic64_t *)l;
76133@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76134 return (long)atomic64_inc_return(v);
76135 }
76136
76137+#ifdef CONFIG_PAX_REFCOUNT
76138+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76139+{
76140+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76141+
76142+ return (long)atomic64_inc_return_unchecked(v);
76143+}
76144+#endif
76145+
76146 static inline long atomic_long_dec_return(atomic_long_t *l)
76147 {
76148 atomic64_t *v = (atomic64_t *)l;
76149@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76150
76151 typedef atomic_t atomic_long_t;
76152
76153+#ifdef CONFIG_PAX_REFCOUNT
76154+typedef atomic_unchecked_t atomic_long_unchecked_t;
76155+#else
76156+typedef atomic_t atomic_long_unchecked_t;
76157+#endif
76158+
76159 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76160 static inline long atomic_long_read(atomic_long_t *l)
76161 {
76162@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76163 return (long)atomic_read(v);
76164 }
76165
76166+#ifdef CONFIG_PAX_REFCOUNT
76167+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76168+{
76169+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76170+
76171+ return (long)atomic_read_unchecked(v);
76172+}
76173+#endif
76174+
76175 static inline void atomic_long_set(atomic_long_t *l, long i)
76176 {
76177 atomic_t *v = (atomic_t *)l;
76178@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76179 atomic_set(v, i);
76180 }
76181
76182+#ifdef CONFIG_PAX_REFCOUNT
76183+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76184+{
76185+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76186+
76187+ atomic_set_unchecked(v, i);
76188+}
76189+#endif
76190+
76191 static inline void atomic_long_inc(atomic_long_t *l)
76192 {
76193 atomic_t *v = (atomic_t *)l;
76194@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76195 atomic_inc(v);
76196 }
76197
76198+#ifdef CONFIG_PAX_REFCOUNT
76199+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76200+{
76201+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76202+
76203+ atomic_inc_unchecked(v);
76204+}
76205+#endif
76206+
76207 static inline void atomic_long_dec(atomic_long_t *l)
76208 {
76209 atomic_t *v = (atomic_t *)l;
76210@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76211 atomic_dec(v);
76212 }
76213
76214+#ifdef CONFIG_PAX_REFCOUNT
76215+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76216+{
76217+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76218+
76219+ atomic_dec_unchecked(v);
76220+}
76221+#endif
76222+
76223 static inline void atomic_long_add(long i, atomic_long_t *l)
76224 {
76225 atomic_t *v = (atomic_t *)l;
76226@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76227 atomic_add(i, v);
76228 }
76229
76230+#ifdef CONFIG_PAX_REFCOUNT
76231+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76232+{
76233+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76234+
76235+ atomic_add_unchecked(i, v);
76236+}
76237+#endif
76238+
76239 static inline void atomic_long_sub(long i, atomic_long_t *l)
76240 {
76241 atomic_t *v = (atomic_t *)l;
76242@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76243 atomic_sub(i, v);
76244 }
76245
76246+#ifdef CONFIG_PAX_REFCOUNT
76247+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76248+{
76249+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76250+
76251+ atomic_sub_unchecked(i, v);
76252+}
76253+#endif
76254+
76255 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76256 {
76257 atomic_t *v = (atomic_t *)l;
76258@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76259 return (long)atomic_add_return(i, v);
76260 }
76261
76262+#ifdef CONFIG_PAX_REFCOUNT
76263+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76264+{
76265+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76266+
76267+ return (long)atomic_add_return_unchecked(i, v);
76268+}
76269+
76270+#endif
76271+
76272 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76273 {
76274 atomic_t *v = (atomic_t *)l;
76275@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76276 return (long)atomic_inc_return(v);
76277 }
76278
76279+#ifdef CONFIG_PAX_REFCOUNT
76280+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76281+{
76282+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76283+
76284+ return (long)atomic_inc_return_unchecked(v);
76285+}
76286+#endif
76287+
76288 static inline long atomic_long_dec_return(atomic_long_t *l)
76289 {
76290 atomic_t *v = (atomic_t *)l;
76291@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76292
76293 #endif /* BITS_PER_LONG == 64 */
76294
76295+#ifdef CONFIG_PAX_REFCOUNT
76296+static inline void pax_refcount_needs_these_functions(void)
76297+{
76298+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
76299+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
76300+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
76301+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
76302+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
76303+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
76304+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
76305+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
76306+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
76307+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
76308+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
76309+#ifdef CONFIG_X86
76310+ atomic_clear_mask_unchecked(0, NULL);
76311+ atomic_set_mask_unchecked(0, NULL);
76312+#endif
76313+
76314+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
76315+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
76316+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
76317+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
76318+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
76319+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
76320+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
76321+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
76322+}
76323+#else
76324+#define atomic_read_unchecked(v) atomic_read(v)
76325+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
76326+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
76327+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
76328+#define atomic_inc_unchecked(v) atomic_inc(v)
76329+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
76330+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
76331+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
76332+#define atomic_dec_unchecked(v) atomic_dec(v)
76333+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
76334+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
76335+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
76336+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
76337+
76338+#define atomic_long_read_unchecked(v) atomic_long_read(v)
76339+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
76340+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
76341+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
76342+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
76343+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
76344+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
76345+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
76346+#endif
76347+
76348 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
76349diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
76350index 33bd2de..f31bff97 100644
76351--- a/include/asm-generic/atomic.h
76352+++ b/include/asm-generic/atomic.h
76353@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
76354 * Atomically clears the bits set in @mask from @v
76355 */
76356 #ifndef atomic_clear_mask
76357-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
76358+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
76359 {
76360 unsigned long flags;
76361
76362diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
76363index b18ce4f..2ee2843 100644
76364--- a/include/asm-generic/atomic64.h
76365+++ b/include/asm-generic/atomic64.h
76366@@ -16,6 +16,8 @@ typedef struct {
76367 long long counter;
76368 } atomic64_t;
76369
76370+typedef atomic64_t atomic64_unchecked_t;
76371+
76372 #define ATOMIC64_INIT(i) { (i) }
76373
76374 extern long long atomic64_read(const atomic64_t *v);
76375@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
76376 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
76377 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
76378
76379+#define atomic64_read_unchecked(v) atomic64_read(v)
76380+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
76381+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
76382+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
76383+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
76384+#define atomic64_inc_unchecked(v) atomic64_inc(v)
76385+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
76386+#define atomic64_dec_unchecked(v) atomic64_dec(v)
76387+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
76388+
76389 #endif /* _ASM_GENERIC_ATOMIC64_H */
76390diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
76391index a60a7cc..0fe12f2 100644
76392--- a/include/asm-generic/bitops/__fls.h
76393+++ b/include/asm-generic/bitops/__fls.h
76394@@ -9,7 +9,7 @@
76395 *
76396 * Undefined if no set bit exists, so code should check against 0 first.
76397 */
76398-static __always_inline unsigned long __fls(unsigned long word)
76399+static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
76400 {
76401 int num = BITS_PER_LONG - 1;
76402
76403diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
76404index 0576d1f..dad6c71 100644
76405--- a/include/asm-generic/bitops/fls.h
76406+++ b/include/asm-generic/bitops/fls.h
76407@@ -9,7 +9,7 @@
76408 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
76409 */
76410
76411-static __always_inline int fls(int x)
76412+static __always_inline int __intentional_overflow(-1) fls(int x)
76413 {
76414 int r = 32;
76415
76416diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
76417index b097cf8..3d40e14 100644
76418--- a/include/asm-generic/bitops/fls64.h
76419+++ b/include/asm-generic/bitops/fls64.h
76420@@ -15,7 +15,7 @@
76421 * at position 64.
76422 */
76423 #if BITS_PER_LONG == 32
76424-static __always_inline int fls64(__u64 x)
76425+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76426 {
76427 __u32 h = x >> 32;
76428 if (h)
76429@@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
76430 return fls(x);
76431 }
76432 #elif BITS_PER_LONG == 64
76433-static __always_inline int fls64(__u64 x)
76434+static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
76435 {
76436 if (x == 0)
76437 return 0;
76438diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
76439index 1bfcfe5..e04c5c9 100644
76440--- a/include/asm-generic/cache.h
76441+++ b/include/asm-generic/cache.h
76442@@ -6,7 +6,7 @@
76443 * cache lines need to provide their own cache.h.
76444 */
76445
76446-#define L1_CACHE_SHIFT 5
76447-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
76448+#define L1_CACHE_SHIFT 5UL
76449+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
76450
76451 #endif /* __ASM_GENERIC_CACHE_H */
76452diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
76453index 0d68a1e..b74a761 100644
76454--- a/include/asm-generic/emergency-restart.h
76455+++ b/include/asm-generic/emergency-restart.h
76456@@ -1,7 +1,7 @@
76457 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
76458 #define _ASM_GENERIC_EMERGENCY_RESTART_H
76459
76460-static inline void machine_emergency_restart(void)
76461+static inline __noreturn void machine_emergency_restart(void)
76462 {
76463 machine_restart(NULL);
76464 }
76465diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
76466index 90f99c7..00ce236 100644
76467--- a/include/asm-generic/kmap_types.h
76468+++ b/include/asm-generic/kmap_types.h
76469@@ -2,9 +2,9 @@
76470 #define _ASM_GENERIC_KMAP_TYPES_H
76471
76472 #ifdef __WITH_KM_FENCE
76473-# define KM_TYPE_NR 41
76474+# define KM_TYPE_NR 42
76475 #else
76476-# define KM_TYPE_NR 20
76477+# define KM_TYPE_NR 21
76478 #endif
76479
76480 #endif
76481diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
76482index 9ceb03b..62b0b8f 100644
76483--- a/include/asm-generic/local.h
76484+++ b/include/asm-generic/local.h
76485@@ -23,24 +23,37 @@ typedef struct
76486 atomic_long_t a;
76487 } local_t;
76488
76489+typedef struct {
76490+ atomic_long_unchecked_t a;
76491+} local_unchecked_t;
76492+
76493 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
76494
76495 #define local_read(l) atomic_long_read(&(l)->a)
76496+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
76497 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
76498+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
76499 #define local_inc(l) atomic_long_inc(&(l)->a)
76500+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
76501 #define local_dec(l) atomic_long_dec(&(l)->a)
76502+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
76503 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
76504+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
76505 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
76506+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
76507
76508 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
76509 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
76510 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
76511 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
76512 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
76513+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
76514 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
76515 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
76516+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
76517
76518 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76519+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
76520 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
76521 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
76522 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
76523diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
76524index 725612b..9cc513a 100644
76525--- a/include/asm-generic/pgtable-nopmd.h
76526+++ b/include/asm-generic/pgtable-nopmd.h
76527@@ -1,14 +1,19 @@
76528 #ifndef _PGTABLE_NOPMD_H
76529 #define _PGTABLE_NOPMD_H
76530
76531-#ifndef __ASSEMBLY__
76532-
76533 #include <asm-generic/pgtable-nopud.h>
76534
76535-struct mm_struct;
76536-
76537 #define __PAGETABLE_PMD_FOLDED
76538
76539+#define PMD_SHIFT PUD_SHIFT
76540+#define PTRS_PER_PMD 1
76541+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
76542+#define PMD_MASK (~(PMD_SIZE-1))
76543+
76544+#ifndef __ASSEMBLY__
76545+
76546+struct mm_struct;
76547+
76548 /*
76549 * Having the pmd type consist of a pud gets the size right, and allows
76550 * us to conceptually access the pud entry that this pmd is folded into
76551@@ -16,11 +21,6 @@ struct mm_struct;
76552 */
76553 typedef struct { pud_t pud; } pmd_t;
76554
76555-#define PMD_SHIFT PUD_SHIFT
76556-#define PTRS_PER_PMD 1
76557-#define PMD_SIZE (1UL << PMD_SHIFT)
76558-#define PMD_MASK (~(PMD_SIZE-1))
76559-
76560 /*
76561 * The "pud_xxx()" functions here are trivial for a folded two-level
76562 * setup: the pmd is never bad, and a pmd always exists (as it's folded
76563diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
76564index 810431d..0ec4804f 100644
76565--- a/include/asm-generic/pgtable-nopud.h
76566+++ b/include/asm-generic/pgtable-nopud.h
76567@@ -1,10 +1,15 @@
76568 #ifndef _PGTABLE_NOPUD_H
76569 #define _PGTABLE_NOPUD_H
76570
76571-#ifndef __ASSEMBLY__
76572-
76573 #define __PAGETABLE_PUD_FOLDED
76574
76575+#define PUD_SHIFT PGDIR_SHIFT
76576+#define PTRS_PER_PUD 1
76577+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
76578+#define PUD_MASK (~(PUD_SIZE-1))
76579+
76580+#ifndef __ASSEMBLY__
76581+
76582 /*
76583 * Having the pud type consist of a pgd gets the size right, and allows
76584 * us to conceptually access the pgd entry that this pud is folded into
76585@@ -12,11 +17,6 @@
76586 */
76587 typedef struct { pgd_t pgd; } pud_t;
76588
76589-#define PUD_SHIFT PGDIR_SHIFT
76590-#define PTRS_PER_PUD 1
76591-#define PUD_SIZE (1UL << PUD_SHIFT)
76592-#define PUD_MASK (~(PUD_SIZE-1))
76593-
76594 /*
76595 * The "pgd_xxx()" functions here are trivial for a folded two-level
76596 * setup: the pud is never bad, and a pud always exists (as it's folded
76597@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
76598 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
76599
76600 #define pgd_populate(mm, pgd, pud) do { } while (0)
76601+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
76602 /*
76603 * (puds are folded into pgds so this doesn't get actually called,
76604 * but the define is needed for a generic inline function.)
76605diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
76606index 8e4f41d..c5e9afd 100644
76607--- a/include/asm-generic/pgtable.h
76608+++ b/include/asm-generic/pgtable.h
76609@@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
76610 }
76611 #endif /* CONFIG_NUMA_BALANCING */
76612
76613+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
76614+#ifdef CONFIG_PAX_KERNEXEC
76615+#error KERNEXEC requires pax_open_kernel
76616+#else
76617+static inline unsigned long pax_open_kernel(void) { return 0; }
76618+#endif
76619+#endif
76620+
76621+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
76622+#ifdef CONFIG_PAX_KERNEXEC
76623+#error KERNEXEC requires pax_close_kernel
76624+#else
76625+static inline unsigned long pax_close_kernel(void) { return 0; }
76626+#endif
76627+#endif
76628+
76629 #endif /* CONFIG_MMU */
76630
76631 #endif /* !__ASSEMBLY__ */
76632diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
76633index dc1269c..48a4f51 100644
76634--- a/include/asm-generic/uaccess.h
76635+++ b/include/asm-generic/uaccess.h
76636@@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
76637 return __clear_user(to, n);
76638 }
76639
76640+#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
76641+#ifdef CONFIG_PAX_MEMORY_UDEREF
76642+#error UDEREF requires pax_open_userland
76643+#else
76644+static inline unsigned long pax_open_userland(void) { return 0; }
76645+#endif
76646+#endif
76647+
76648+#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
76649+#ifdef CONFIG_PAX_MEMORY_UDEREF
76650+#error UDEREF requires pax_close_userland
76651+#else
76652+static inline unsigned long pax_close_userland(void) { return 0; }
76653+#endif
76654+#endif
76655+
76656 #endif /* __ASM_GENERIC_UACCESS_H */
76657diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
76658index bc2121f..2f41f9a 100644
76659--- a/include/asm-generic/vmlinux.lds.h
76660+++ b/include/asm-generic/vmlinux.lds.h
76661@@ -232,6 +232,7 @@
76662 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
76663 VMLINUX_SYMBOL(__start_rodata) = .; \
76664 *(.rodata) *(.rodata.*) \
76665+ *(.data..read_only) \
76666 *(__vermagic) /* Kernel version magic */ \
76667 . = ALIGN(8); \
76668 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
76669@@ -716,17 +717,18 @@
76670 * section in the linker script will go there too. @phdr should have
76671 * a leading colon.
76672 *
76673- * Note that this macros defines __per_cpu_load as an absolute symbol.
76674+ * Note that this macros defines per_cpu_load as an absolute symbol.
76675 * If there is no need to put the percpu section at a predetermined
76676 * address, use PERCPU_SECTION.
76677 */
76678 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
76679- VMLINUX_SYMBOL(__per_cpu_load) = .; \
76680- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
76681+ per_cpu_load = .; \
76682+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
76683 - LOAD_OFFSET) { \
76684+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
76685 PERCPU_INPUT(cacheline) \
76686 } phdr \
76687- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
76688+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
76689
76690 /**
76691 * PERCPU_SECTION - define output section for percpu area, simple version
76692diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
76693index e73c19e..5b89e00 100644
76694--- a/include/crypto/algapi.h
76695+++ b/include/crypto/algapi.h
76696@@ -34,7 +34,7 @@ struct crypto_type {
76697 unsigned int maskclear;
76698 unsigned int maskset;
76699 unsigned int tfmsize;
76700-};
76701+} __do_const;
76702
76703 struct crypto_instance {
76704 struct crypto_alg alg;
76705diff --git a/include/drm/drmP.h b/include/drm/drmP.h
76706index 1d4a920..da65658 100644
76707--- a/include/drm/drmP.h
76708+++ b/include/drm/drmP.h
76709@@ -66,6 +66,7 @@
76710 #include <linux/workqueue.h>
76711 #include <linux/poll.h>
76712 #include <asm/pgalloc.h>
76713+#include <asm/local.h>
76714 #include <drm/drm.h>
76715 #include <drm/drm_sarea.h>
76716 #include <drm/drm_vma_manager.h>
76717@@ -278,10 +279,12 @@ do { \
76718 * \param cmd command.
76719 * \param arg argument.
76720 */
76721-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
76722+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
76723+ struct drm_file *file_priv);
76724+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
76725 struct drm_file *file_priv);
76726
76727-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76728+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
76729 unsigned long arg);
76730
76731 #define DRM_IOCTL_NR(n) _IOC_NR(n)
76732@@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
76733 struct drm_ioctl_desc {
76734 unsigned int cmd;
76735 int flags;
76736- drm_ioctl_t *func;
76737+ drm_ioctl_t func;
76738 unsigned int cmd_drv;
76739 const char *name;
76740-};
76741+} __do_const;
76742
76743 /**
76744 * Creates a driver or general drm_ioctl_desc array entry for the given
76745@@ -1013,7 +1016,8 @@ struct drm_info_list {
76746 int (*show)(struct seq_file*, void*); /** show callback */
76747 u32 driver_features; /**< Required driver features for this entry */
76748 void *data;
76749-};
76750+} __do_const;
76751+typedef struct drm_info_list __no_const drm_info_list_no_const;
76752
76753 /**
76754 * debugfs node structure. This structure represents a debugfs file.
76755@@ -1097,7 +1101,7 @@ struct drm_device {
76756
76757 /** \name Usage Counters */
76758 /*@{ */
76759- int open_count; /**< Outstanding files open */
76760+ local_t open_count; /**< Outstanding files open */
76761 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
76762 atomic_t vma_count; /**< Outstanding vma areas open */
76763 int buf_use; /**< Buffers in use -- cannot alloc */
76764diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
76765index ef6ad3a..be34b16 100644
76766--- a/include/drm/drm_crtc_helper.h
76767+++ b/include/drm/drm_crtc_helper.h
76768@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
76769 struct drm_connector *connector);
76770 /* disable encoder when not in use - more explicit than dpms off */
76771 void (*disable)(struct drm_encoder *encoder);
76772-};
76773+} __no_const;
76774
76775 /**
76776 * drm_connector_helper_funcs - helper operations for connectors
76777diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
76778index 940ece4..8cb727f 100644
76779--- a/include/drm/i915_pciids.h
76780+++ b/include/drm/i915_pciids.h
76781@@ -37,7 +37,7 @@
76782 */
76783 #define INTEL_VGA_DEVICE(id, info) { \
76784 0x8086, id, \
76785- ~0, ~0, \
76786+ PCI_ANY_ID, PCI_ANY_ID, \
76787 0x030000, 0xff0000, \
76788 (unsigned long) info }
76789
76790diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
76791index 72dcbe8..8db58d7 100644
76792--- a/include/drm/ttm/ttm_memory.h
76793+++ b/include/drm/ttm/ttm_memory.h
76794@@ -48,7 +48,7 @@
76795
76796 struct ttm_mem_shrink {
76797 int (*do_shrink) (struct ttm_mem_shrink *);
76798-};
76799+} __no_const;
76800
76801 /**
76802 * struct ttm_mem_global - Global memory accounting structure.
76803diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
76804index d1f61bf..2239439 100644
76805--- a/include/drm/ttm/ttm_page_alloc.h
76806+++ b/include/drm/ttm/ttm_page_alloc.h
76807@@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
76808 */
76809 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
76810
76811+struct device;
76812 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76813 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
76814
76815diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
76816index 4b840e8..155d235 100644
76817--- a/include/keys/asymmetric-subtype.h
76818+++ b/include/keys/asymmetric-subtype.h
76819@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
76820 /* Verify the signature on a key of this subtype (optional) */
76821 int (*verify_signature)(const struct key *key,
76822 const struct public_key_signature *sig);
76823-};
76824+} __do_const;
76825
76826 /**
76827 * asymmetric_key_subtype - Get the subtype from an asymmetric key
76828diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
76829index c1da539..1dcec55 100644
76830--- a/include/linux/atmdev.h
76831+++ b/include/linux/atmdev.h
76832@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
76833 #endif
76834
76835 struct k_atm_aal_stats {
76836-#define __HANDLE_ITEM(i) atomic_t i
76837+#define __HANDLE_ITEM(i) atomic_unchecked_t i
76838 __AAL_STAT_ITEMS
76839 #undef __HANDLE_ITEM
76840 };
76841@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
76842 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
76843 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
76844 struct module *owner;
76845-};
76846+} __do_const ;
76847
76848 struct atmphy_ops {
76849 int (*start)(struct atm_dev *dev);
76850diff --git a/include/linux/audit.h b/include/linux/audit.h
76851index bf1ef22..2a55e1b 100644
76852--- a/include/linux/audit.h
76853+++ b/include/linux/audit.h
76854@@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
76855 extern unsigned int audit_serial(void);
76856 extern int auditsc_get_stamp(struct audit_context *ctx,
76857 struct timespec *t, unsigned int *serial);
76858-extern int audit_set_loginuid(kuid_t loginuid);
76859+extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
76860
76861 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
76862 {
76863diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
76864index fd8bf32..49a5f5c 100644
76865--- a/include/linux/binfmts.h
76866+++ b/include/linux/binfmts.h
76867@@ -45,7 +45,7 @@ struct linux_binprm {
76868 unsigned interp_data;
76869 unsigned long loader, exec;
76870 char tcomm[TASK_COMM_LEN];
76871-};
76872+} __randomize_layout;
76873
76874 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
76875 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
76876@@ -74,8 +74,10 @@ struct linux_binfmt {
76877 int (*load_binary)(struct linux_binprm *);
76878 int (*load_shlib)(struct file *);
76879 int (*core_dump)(struct coredump_params *cprm);
76880+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
76881+ void (*handle_mmap)(struct file *);
76882 unsigned long min_coredump; /* minimal dump size */
76883-};
76884+} __do_const __randomize_layout;
76885
76886 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
76887
76888diff --git a/include/linux/bitops.h b/include/linux/bitops.h
76889index be5fd38..d71192a 100644
76890--- a/include/linux/bitops.h
76891+++ b/include/linux/bitops.h
76892@@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
76893 * @word: value to rotate
76894 * @shift: bits to roll
76895 */
76896-static inline __u32 rol32(__u32 word, unsigned int shift)
76897+static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
76898 {
76899 return (word << shift) | (word >> (32 - shift));
76900 }
76901@@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
76902 * @word: value to rotate
76903 * @shift: bits to roll
76904 */
76905-static inline __u32 ror32(__u32 word, unsigned int shift)
76906+static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76907 {
76908 return (word >> shift) | (word << (32 - shift));
76909 }
76910@@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76911 return (__s32)(value << shift) >> shift;
76912 }
76913
76914-static inline unsigned fls_long(unsigned long l)
76915+static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76916 {
76917 if (sizeof(l) == 4)
76918 return fls(l);
76919diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76920index 1b135d4..59fc876 100644
76921--- a/include/linux/blkdev.h
76922+++ b/include/linux/blkdev.h
76923@@ -1578,7 +1578,7 @@ struct block_device_operations {
76924 /* this callback is with swap_lock and sometimes page table lock held */
76925 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76926 struct module *owner;
76927-};
76928+} __do_const;
76929
76930 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76931 unsigned long);
76932diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76933index afc1343..9735539 100644
76934--- a/include/linux/blktrace_api.h
76935+++ b/include/linux/blktrace_api.h
76936@@ -25,7 +25,7 @@ struct blk_trace {
76937 struct dentry *dropped_file;
76938 struct dentry *msg_file;
76939 struct list_head running_list;
76940- atomic_t dropped;
76941+ atomic_unchecked_t dropped;
76942 };
76943
76944 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76945diff --git a/include/linux/cache.h b/include/linux/cache.h
76946index 4c57065..40346da 100644
76947--- a/include/linux/cache.h
76948+++ b/include/linux/cache.h
76949@@ -16,6 +16,14 @@
76950 #define __read_mostly
76951 #endif
76952
76953+#ifndef __read_only
76954+#ifdef CONFIG_PAX_KERNEXEC
76955+#error KERNEXEC requires __read_only
76956+#else
76957+#define __read_only __read_mostly
76958+#endif
76959+#endif
76960+
76961 #ifndef ____cacheline_aligned
76962 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76963 #endif
76964diff --git a/include/linux/capability.h b/include/linux/capability.h
76965index a6ee1f9..e1ca49d 100644
76966--- a/include/linux/capability.h
76967+++ b/include/linux/capability.h
76968@@ -212,8 +212,13 @@ extern bool capable(int cap);
76969 extern bool ns_capable(struct user_namespace *ns, int cap);
76970 extern bool inode_capable(const struct inode *inode, int cap);
76971 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76972+extern bool capable_nolog(int cap);
76973+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76974+extern bool inode_capable_nolog(const struct inode *inode, int cap);
76975
76976 /* audit system wants to get cap info from files as well */
76977 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76978
76979+extern int is_privileged_binary(const struct dentry *dentry);
76980+
76981 #endif /* !_LINUX_CAPABILITY_H */
76982diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76983index 8609d57..86e4d79 100644
76984--- a/include/linux/cdrom.h
76985+++ b/include/linux/cdrom.h
76986@@ -87,7 +87,6 @@ struct cdrom_device_ops {
76987
76988 /* driver specifications */
76989 const int capability; /* capability flags */
76990- int n_minors; /* number of active minor devices */
76991 /* handle uniform packets for scsi type devices (scsi,atapi) */
76992 int (*generic_packet) (struct cdrom_device_info *,
76993 struct packet_command *);
76994diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76995index 4ce9056..86caac6 100644
76996--- a/include/linux/cleancache.h
76997+++ b/include/linux/cleancache.h
76998@@ -31,7 +31,7 @@ struct cleancache_ops {
76999 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77000 void (*invalidate_inode)(int, struct cleancache_filekey);
77001 void (*invalidate_fs)(int);
77002-};
77003+} __no_const;
77004
77005 extern struct cleancache_ops *
77006 cleancache_register_ops(struct cleancache_ops *ops);
77007diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77008index 7e59253..d6e4cae 100644
77009--- a/include/linux/clk-provider.h
77010+++ b/include/linux/clk-provider.h
77011@@ -141,6 +141,7 @@ struct clk_ops {
77012 unsigned long);
77013 void (*init)(struct clk_hw *hw);
77014 };
77015+typedef struct clk_ops __no_const clk_ops_no_const;
77016
77017 /**
77018 * struct clk_init_data - holds init data that's common to all clocks and is
77019diff --git a/include/linux/compat.h b/include/linux/compat.h
77020index 19f6003..90b64f4 100644
77021--- a/include/linux/compat.h
77022+++ b/include/linux/compat.h
77023@@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77024 compat_size_t __user *len_ptr);
77025
77026 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77027-asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77028+asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77029 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77030 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77031 compat_ssize_t msgsz, int msgflg);
77032@@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77033 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77034 compat_ulong_t addr, compat_ulong_t data);
77035 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77036- compat_long_t addr, compat_long_t data);
77037+ compat_ulong_t addr, compat_ulong_t data);
77038
77039 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77040 /*
77041diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77042index 2507fd2..55203f8 100644
77043--- a/include/linux/compiler-gcc4.h
77044+++ b/include/linux/compiler-gcc4.h
77045@@ -39,9 +39,34 @@
77046 # define __compiletime_warning(message) __attribute__((warning(message)))
77047 # define __compiletime_error(message) __attribute__((error(message)))
77048 #endif /* __CHECKER__ */
77049+
77050+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77051+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77052+#define __bos0(ptr) __bos((ptr), 0)
77053+#define __bos1(ptr) __bos((ptr), 1)
77054 #endif /* GCC_VERSION >= 40300 */
77055
77056 #if GCC_VERSION >= 40500
77057+
77058+#ifdef RANDSTRUCT_PLUGIN
77059+#define __randomize_layout __attribute__((randomize_layout))
77060+#define __no_randomize_layout __attribute__((no_randomize_layout))
77061+#endif
77062+
77063+#ifdef CONSTIFY_PLUGIN
77064+#define __no_const __attribute__((no_const))
77065+#define __do_const __attribute__((do_const))
77066+#endif
77067+
77068+#ifdef SIZE_OVERFLOW_PLUGIN
77069+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77070+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77071+#endif
77072+
77073+#ifdef LATENT_ENTROPY_PLUGIN
77074+#define __latent_entropy __attribute__((latent_entropy))
77075+#endif
77076+
77077 /*
77078 * Mark a position in code as unreachable. This can be used to
77079 * suppress control flow warnings after asm blocks that transfer
77080diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77081index 92669cd..cc564c0 100644
77082--- a/include/linux/compiler.h
77083+++ b/include/linux/compiler.h
77084@@ -5,11 +5,14 @@
77085
77086 #ifdef __CHECKER__
77087 # define __user __attribute__((noderef, address_space(1)))
77088+# define __force_user __force __user
77089 # define __kernel __attribute__((address_space(0)))
77090+# define __force_kernel __force __kernel
77091 # define __safe __attribute__((safe))
77092 # define __force __attribute__((force))
77093 # define __nocast __attribute__((nocast))
77094 # define __iomem __attribute__((noderef, address_space(2)))
77095+# define __force_iomem __force __iomem
77096 # define __must_hold(x) __attribute__((context(x,1,1)))
77097 # define __acquires(x) __attribute__((context(x,0,1)))
77098 # define __releases(x) __attribute__((context(x,1,0)))
77099@@ -17,20 +20,37 @@
77100 # define __release(x) __context__(x,-1)
77101 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77102 # define __percpu __attribute__((noderef, address_space(3)))
77103+# define __force_percpu __force __percpu
77104 #ifdef CONFIG_SPARSE_RCU_POINTER
77105 # define __rcu __attribute__((noderef, address_space(4)))
77106+# define __force_rcu __force __rcu
77107 #else
77108 # define __rcu
77109+# define __force_rcu
77110 #endif
77111 extern void __chk_user_ptr(const volatile void __user *);
77112 extern void __chk_io_ptr(const volatile void __iomem *);
77113 #else
77114-# define __user
77115-# define __kernel
77116+# ifdef CHECKER_PLUGIN
77117+//# define __user
77118+//# define __force_user
77119+//# define __kernel
77120+//# define __force_kernel
77121+# else
77122+# ifdef STRUCTLEAK_PLUGIN
77123+# define __user __attribute__((user))
77124+# else
77125+# define __user
77126+# endif
77127+# define __force_user
77128+# define __kernel
77129+# define __force_kernel
77130+# endif
77131 # define __safe
77132 # define __force
77133 # define __nocast
77134 # define __iomem
77135+# define __force_iomem
77136 # define __chk_user_ptr(x) (void)0
77137 # define __chk_io_ptr(x) (void)0
77138 # define __builtin_warning(x, y...) (1)
77139@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77140 # define __release(x) (void)0
77141 # define __cond_lock(x,c) (c)
77142 # define __percpu
77143+# define __force_percpu
77144 # define __rcu
77145+# define __force_rcu
77146 #endif
77147
77148 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77149@@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77150 # define __attribute_const__ /* unimplemented */
77151 #endif
77152
77153+#ifndef __randomize_layout
77154+# define __randomize_layout
77155+#endif
77156+
77157+#ifndef __no_randomize_layout
77158+# define __no_randomize_layout
77159+#endif
77160+
77161+#ifndef __no_const
77162+# define __no_const
77163+#endif
77164+
77165+#ifndef __do_const
77166+# define __do_const
77167+#endif
77168+
77169+#ifndef __size_overflow
77170+# define __size_overflow(...)
77171+#endif
77172+
77173+#ifndef __intentional_overflow
77174+# define __intentional_overflow(...)
77175+#endif
77176+
77177+#ifndef __latent_entropy
77178+# define __latent_entropy
77179+#endif
77180+
77181 /*
77182 * Tell gcc if a function is cold. The compiler will assume any path
77183 * directly leading to the call is unlikely.
77184@@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77185 #define __cold
77186 #endif
77187
77188+#ifndef __alloc_size
77189+#define __alloc_size(...)
77190+#endif
77191+
77192+#ifndef __bos
77193+#define __bos(ptr, arg)
77194+#endif
77195+
77196+#ifndef __bos0
77197+#define __bos0(ptr)
77198+#endif
77199+
77200+#ifndef __bos1
77201+#define __bos1(ptr)
77202+#endif
77203+
77204 /* Simple shorthand for a section definition */
77205 #ifndef __section
77206 # define __section(S) __attribute__ ((__section__(#S)))
77207@@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77208 * use is to mediate communication between process-level code and irq/NMI
77209 * handlers, all running on the same CPU.
77210 */
77211-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77212+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77213+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77214
77215 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77216 #ifdef CONFIG_KPROBES
77217diff --git a/include/linux/completion.h b/include/linux/completion.h
77218index 5d5aaae..0ea9b84 100644
77219--- a/include/linux/completion.h
77220+++ b/include/linux/completion.h
77221@@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77222
77223 extern void wait_for_completion(struct completion *);
77224 extern void wait_for_completion_io(struct completion *);
77225-extern int wait_for_completion_interruptible(struct completion *x);
77226-extern int wait_for_completion_killable(struct completion *x);
77227+extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77228+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77229 extern unsigned long wait_for_completion_timeout(struct completion *x,
77230- unsigned long timeout);
77231+ unsigned long timeout) __intentional_overflow(-1);
77232 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77233- unsigned long timeout);
77234+ unsigned long timeout) __intentional_overflow(-1);
77235 extern long wait_for_completion_interruptible_timeout(
77236- struct completion *x, unsigned long timeout);
77237+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77238 extern long wait_for_completion_killable_timeout(
77239- struct completion *x, unsigned long timeout);
77240+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
77241 extern bool try_wait_for_completion(struct completion *x);
77242 extern bool completion_done(struct completion *x);
77243
77244diff --git a/include/linux/configfs.h b/include/linux/configfs.h
77245index 34025df..d94bbbc 100644
77246--- a/include/linux/configfs.h
77247+++ b/include/linux/configfs.h
77248@@ -125,7 +125,7 @@ struct configfs_attribute {
77249 const char *ca_name;
77250 struct module *ca_owner;
77251 umode_t ca_mode;
77252-};
77253+} __do_const;
77254
77255 /*
77256 * Users often need to create attribute structures for their configurable
77257diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
77258index dc196bb..c55a50f 100644
77259--- a/include/linux/cpufreq.h
77260+++ b/include/linux/cpufreq.h
77261@@ -189,6 +189,7 @@ struct global_attr {
77262 ssize_t (*store)(struct kobject *a, struct attribute *b,
77263 const char *c, size_t count);
77264 };
77265+typedef struct global_attr __no_const global_attr_no_const;
77266
77267 #define define_one_global_ro(_name) \
77268 static struct global_attr _name = \
77269@@ -225,7 +226,7 @@ struct cpufreq_driver {
77270 int (*suspend) (struct cpufreq_policy *policy);
77271 int (*resume) (struct cpufreq_policy *policy);
77272 struct freq_attr **attr;
77273-};
77274+} __do_const;
77275
77276 /* flags */
77277 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
77278diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
77279index 50fcbb0..9d2dbd9 100644
77280--- a/include/linux/cpuidle.h
77281+++ b/include/linux/cpuidle.h
77282@@ -50,7 +50,8 @@ struct cpuidle_state {
77283 int index);
77284
77285 int (*enter_dead) (struct cpuidle_device *dev, int index);
77286-};
77287+} __do_const;
77288+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
77289
77290 /* Idle State Flags */
77291 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
77292@@ -192,7 +193,7 @@ struct cpuidle_governor {
77293 void (*reflect) (struct cpuidle_device *dev, int index);
77294
77295 struct module *owner;
77296-};
77297+} __do_const;
77298
77299 #ifdef CONFIG_CPU_IDLE
77300 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
77301diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
77302index d08e4d2..95fad61 100644
77303--- a/include/linux/cpumask.h
77304+++ b/include/linux/cpumask.h
77305@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77306 }
77307
77308 /* Valid inputs for n are -1 and 0. */
77309-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77310+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77311 {
77312 return n+1;
77313 }
77314
77315-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77316+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77317 {
77318 return n+1;
77319 }
77320
77321-static inline unsigned int cpumask_next_and(int n,
77322+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
77323 const struct cpumask *srcp,
77324 const struct cpumask *andp)
77325 {
77326@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
77327 *
77328 * Returns >= nr_cpu_ids if no further cpus set.
77329 */
77330-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77331+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
77332 {
77333 /* -1 is a legal arg here. */
77334 if (n != -1)
77335@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
77336 *
77337 * Returns >= nr_cpu_ids if no further cpus unset.
77338 */
77339-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77340+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
77341 {
77342 /* -1 is a legal arg here. */
77343 if (n != -1)
77344@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
77345 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
77346 }
77347
77348-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
77349+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
77350 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
77351
77352 /**
77353diff --git a/include/linux/cred.h b/include/linux/cred.h
77354index 04421e8..117e17a 100644
77355--- a/include/linux/cred.h
77356+++ b/include/linux/cred.h
77357@@ -35,7 +35,7 @@ struct group_info {
77358 int nblocks;
77359 kgid_t small_block[NGROUPS_SMALL];
77360 kgid_t *blocks[0];
77361-};
77362+} __randomize_layout;
77363
77364 /**
77365 * get_group_info - Get a reference to a group info structure
77366@@ -136,7 +136,7 @@ struct cred {
77367 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
77368 struct group_info *group_info; /* supplementary groups for euid/fsgid */
77369 struct rcu_head rcu; /* RCU deletion hook */
77370-};
77371+} __randomize_layout;
77372
77373 extern void __put_cred(struct cred *);
77374 extern void exit_creds(struct task_struct *);
77375@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
77376 static inline void validate_process_creds(void)
77377 {
77378 }
77379+static inline void validate_task_creds(struct task_struct *task)
77380+{
77381+}
77382 #endif
77383
77384 /**
77385diff --git a/include/linux/crypto.h b/include/linux/crypto.h
77386index b92eadf..b4ecdc1 100644
77387--- a/include/linux/crypto.h
77388+++ b/include/linux/crypto.h
77389@@ -373,7 +373,7 @@ struct cipher_tfm {
77390 const u8 *key, unsigned int keylen);
77391 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77392 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
77393-};
77394+} __no_const;
77395
77396 struct hash_tfm {
77397 int (*init)(struct hash_desc *desc);
77398@@ -394,13 +394,13 @@ struct compress_tfm {
77399 int (*cot_decompress)(struct crypto_tfm *tfm,
77400 const u8 *src, unsigned int slen,
77401 u8 *dst, unsigned int *dlen);
77402-};
77403+} __no_const;
77404
77405 struct rng_tfm {
77406 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
77407 unsigned int dlen);
77408 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
77409-};
77410+} __no_const;
77411
77412 #define crt_ablkcipher crt_u.ablkcipher
77413 #define crt_aead crt_u.aead
77414diff --git a/include/linux/ctype.h b/include/linux/ctype.h
77415index 653589e..4ef254a 100644
77416--- a/include/linux/ctype.h
77417+++ b/include/linux/ctype.h
77418@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
77419 * Fast implementation of tolower() for internal usage. Do not use in your
77420 * code.
77421 */
77422-static inline char _tolower(const char c)
77423+static inline unsigned char _tolower(const unsigned char c)
77424 {
77425 return c | 0x20;
77426 }
77427diff --git a/include/linux/dcache.h b/include/linux/dcache.h
77428index bf72e9a..4ca7927 100644
77429--- a/include/linux/dcache.h
77430+++ b/include/linux/dcache.h
77431@@ -133,7 +133,7 @@ struct dentry {
77432 } d_u;
77433 struct list_head d_subdirs; /* our children */
77434 struct hlist_node d_alias; /* inode alias list */
77435-};
77436+} __randomize_layout;
77437
77438 /*
77439 * dentry->d_lock spinlock nesting subclasses:
77440diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
77441index 7925bf0..d5143d2 100644
77442--- a/include/linux/decompress/mm.h
77443+++ b/include/linux/decompress/mm.h
77444@@ -77,7 +77,7 @@ static void free(void *where)
77445 * warnings when not needed (indeed large_malloc / large_free are not
77446 * needed by inflate */
77447
77448-#define malloc(a) kmalloc(a, GFP_KERNEL)
77449+#define malloc(a) kmalloc((a), GFP_KERNEL)
77450 #define free(a) kfree(a)
77451
77452 #define large_malloc(a) vmalloc(a)
77453diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
77454index d48dc00..211ee54 100644
77455--- a/include/linux/devfreq.h
77456+++ b/include/linux/devfreq.h
77457@@ -114,7 +114,7 @@ struct devfreq_governor {
77458 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
77459 int (*event_handler)(struct devfreq *devfreq,
77460 unsigned int event, void *data);
77461-};
77462+} __do_const;
77463
77464 /**
77465 * struct devfreq - Device devfreq structure
77466diff --git a/include/linux/device.h b/include/linux/device.h
77467index 952b010..d5b7691 100644
77468--- a/include/linux/device.h
77469+++ b/include/linux/device.h
77470@@ -310,7 +310,7 @@ struct subsys_interface {
77471 struct list_head node;
77472 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
77473 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
77474-};
77475+} __do_const;
77476
77477 int subsys_interface_register(struct subsys_interface *sif);
77478 void subsys_interface_unregister(struct subsys_interface *sif);
77479@@ -506,7 +506,7 @@ struct device_type {
77480 void (*release)(struct device *dev);
77481
77482 const struct dev_pm_ops *pm;
77483-};
77484+} __do_const;
77485
77486 /* interface for exporting device attributes */
77487 struct device_attribute {
77488@@ -516,11 +516,12 @@ struct device_attribute {
77489 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
77490 const char *buf, size_t count);
77491 };
77492+typedef struct device_attribute __no_const device_attribute_no_const;
77493
77494 struct dev_ext_attribute {
77495 struct device_attribute attr;
77496 void *var;
77497-};
77498+} __do_const;
77499
77500 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
77501 char *buf);
77502diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
77503index fd4aee2..1f28db9 100644
77504--- a/include/linux/dma-mapping.h
77505+++ b/include/linux/dma-mapping.h
77506@@ -54,7 +54,7 @@ struct dma_map_ops {
77507 u64 (*get_required_mask)(struct device *dev);
77508 #endif
77509 int is_phys;
77510-};
77511+} __do_const;
77512
77513 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
77514
77515diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
77516index 41cf0c3..f3b771c 100644
77517--- a/include/linux/dmaengine.h
77518+++ b/include/linux/dmaengine.h
77519@@ -1114,9 +1114,9 @@ struct dma_pinned_list {
77520 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
77521 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
77522
77523-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77524+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
77525 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
77526-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77527+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
77528 struct dma_pinned_list *pinned_list, struct page *page,
77529 unsigned int offset, size_t len);
77530
77531diff --git a/include/linux/efi.h b/include/linux/efi.h
77532index 11ce678..7b8c69c 100644
77533--- a/include/linux/efi.h
77534+++ b/include/linux/efi.h
77535@@ -764,6 +764,7 @@ struct efivar_operations {
77536 efi_set_variable_t *set_variable;
77537 efi_query_variable_store_t *query_variable_store;
77538 };
77539+typedef struct efivar_operations __no_const efivar_operations_no_const;
77540
77541 struct efivars {
77542 /*
77543diff --git a/include/linux/elf.h b/include/linux/elf.h
77544index 67a5fa7..b817372 100644
77545--- a/include/linux/elf.h
77546+++ b/include/linux/elf.h
77547@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
77548 #define elf_note elf32_note
77549 #define elf_addr_t Elf32_Off
77550 #define Elf_Half Elf32_Half
77551+#define elf_dyn Elf32_Dyn
77552
77553 #else
77554
77555@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
77556 #define elf_note elf64_note
77557 #define elf_addr_t Elf64_Off
77558 #define Elf_Half Elf64_Half
77559+#define elf_dyn Elf64_Dyn
77560
77561 #endif
77562
77563diff --git a/include/linux/err.h b/include/linux/err.h
77564index 15f92e0..e825a8e 100644
77565--- a/include/linux/err.h
77566+++ b/include/linux/err.h
77567@@ -19,12 +19,12 @@
77568
77569 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
77570
77571-static inline void * __must_check ERR_PTR(long error)
77572+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
77573 {
77574 return (void *) error;
77575 }
77576
77577-static inline long __must_check PTR_ERR(__force const void *ptr)
77578+static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
77579 {
77580 return (long) ptr;
77581 }
77582diff --git a/include/linux/extcon.h b/include/linux/extcon.h
77583index 21c59af..6057a03 100644
77584--- a/include/linux/extcon.h
77585+++ b/include/linux/extcon.h
77586@@ -135,7 +135,7 @@ struct extcon_dev {
77587 /* /sys/class/extcon/.../mutually_exclusive/... */
77588 struct attribute_group attr_g_muex;
77589 struct attribute **attrs_muex;
77590- struct device_attribute *d_attrs_muex;
77591+ device_attribute_no_const *d_attrs_muex;
77592 };
77593
77594 /**
77595diff --git a/include/linux/fb.h b/include/linux/fb.h
77596index 70c4836..ff3daec 100644
77597--- a/include/linux/fb.h
77598+++ b/include/linux/fb.h
77599@@ -304,7 +304,7 @@ struct fb_ops {
77600 /* called at KDB enter and leave time to prepare the console */
77601 int (*fb_debug_enter)(struct fb_info *info);
77602 int (*fb_debug_leave)(struct fb_info *info);
77603-};
77604+} __do_const;
77605
77606 #ifdef CONFIG_FB_TILEBLITTING
77607 #define FB_TILE_CURSOR_NONE 0
77608diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
77609index 085197b..0fa6f0b 100644
77610--- a/include/linux/fdtable.h
77611+++ b/include/linux/fdtable.h
77612@@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
77613 void put_files_struct(struct files_struct *fs);
77614 void reset_files_struct(struct files_struct *);
77615 int unshare_files(struct files_struct **);
77616-struct files_struct *dup_fd(struct files_struct *, int *);
77617+struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
77618 void do_close_on_exec(struct files_struct *);
77619 int iterate_fd(struct files_struct *, unsigned,
77620 int (*)(const void *, struct file *, unsigned),
77621diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
77622index 8293262..2b3b8bd 100644
77623--- a/include/linux/frontswap.h
77624+++ b/include/linux/frontswap.h
77625@@ -11,7 +11,7 @@ struct frontswap_ops {
77626 int (*load)(unsigned, pgoff_t, struct page *);
77627 void (*invalidate_page)(unsigned, pgoff_t);
77628 void (*invalidate_area)(unsigned);
77629-};
77630+} __no_const;
77631
77632 extern bool frontswap_enabled;
77633 extern struct frontswap_ops *
77634diff --git a/include/linux/fs.h b/include/linux/fs.h
77635index 121f11f..0f2a863 100644
77636--- a/include/linux/fs.h
77637+++ b/include/linux/fs.h
77638@@ -423,7 +423,7 @@ struct address_space {
77639 spinlock_t private_lock; /* for use by the address_space */
77640 struct list_head private_list; /* ditto */
77641 void *private_data; /* ditto */
77642-} __attribute__((aligned(sizeof(long))));
77643+} __attribute__((aligned(sizeof(long)))) __randomize_layout;
77644 /*
77645 * On most architectures that alignment is already the case; but
77646 * must be enforced here for CRIS, to let the least significant bit
77647@@ -466,7 +466,7 @@ struct block_device {
77648 int bd_fsfreeze_count;
77649 /* Mutex for freeze */
77650 struct mutex bd_fsfreeze_mutex;
77651-};
77652+} __randomize_layout;
77653
77654 /*
77655 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
77656@@ -610,7 +610,7 @@ struct inode {
77657 atomic_t i_readcount; /* struct files open RO */
77658 #endif
77659 void *i_private; /* fs or device private pointer */
77660-};
77661+} __randomize_layout;
77662
77663 static inline int inode_unhashed(struct inode *inode)
77664 {
77665@@ -808,7 +808,7 @@ struct file {
77666 #ifdef CONFIG_DEBUG_WRITECOUNT
77667 unsigned long f_mnt_write_state;
77668 #endif
77669-};
77670+} __randomize_layout;
77671
77672 struct file_handle {
77673 __u32 handle_bytes;
77674@@ -978,7 +978,7 @@ struct file_lock {
77675 int state; /* state of grant or error if -ve */
77676 } afs;
77677 } fl_u;
77678-};
77679+} __randomize_layout;
77680
77681 /* The following constant reflects the upper bound of the file/locking space */
77682 #ifndef OFFSET_MAX
77683@@ -1325,7 +1325,7 @@ struct super_block {
77684 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
77685 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
77686 struct rcu_head rcu;
77687-};
77688+} __randomize_layout;
77689
77690 extern struct timespec current_fs_time(struct super_block *sb);
77691
77692@@ -1547,7 +1547,8 @@ struct file_operations {
77693 long (*fallocate)(struct file *file, int mode, loff_t offset,
77694 loff_t len);
77695 int (*show_fdinfo)(struct seq_file *m, struct file *f);
77696-};
77697+} __do_const __randomize_layout;
77698+typedef struct file_operations __no_const file_operations_no_const;
77699
77700 struct inode_operations {
77701 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
77702@@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
77703 return !IS_DEADDIR(inode);
77704 }
77705
77706+static inline bool is_sidechannel_device(const struct inode *inode)
77707+{
77708+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
77709+ umode_t mode = inode->i_mode;
77710+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
77711+#else
77712+ return false;
77713+#endif
77714+}
77715+
77716 #endif /* _LINUX_FS_H */
77717diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
77718index 0efc3e6..fd23610 100644
77719--- a/include/linux/fs_struct.h
77720+++ b/include/linux/fs_struct.h
77721@@ -6,13 +6,13 @@
77722 #include <linux/seqlock.h>
77723
77724 struct fs_struct {
77725- int users;
77726+ atomic_t users;
77727 spinlock_t lock;
77728 seqcount_t seq;
77729 int umask;
77730 int in_exec;
77731 struct path root, pwd;
77732-};
77733+} __randomize_layout;
77734
77735 extern struct kmem_cache *fs_cachep;
77736
77737diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
77738index 7714849..a4a5c7a 100644
77739--- a/include/linux/fscache-cache.h
77740+++ b/include/linux/fscache-cache.h
77741@@ -113,7 +113,7 @@ struct fscache_operation {
77742 fscache_operation_release_t release;
77743 };
77744
77745-extern atomic_t fscache_op_debug_id;
77746+extern atomic_unchecked_t fscache_op_debug_id;
77747 extern void fscache_op_work_func(struct work_struct *work);
77748
77749 extern void fscache_enqueue_operation(struct fscache_operation *);
77750@@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
77751 INIT_WORK(&op->work, fscache_op_work_func);
77752 atomic_set(&op->usage, 1);
77753 op->state = FSCACHE_OP_ST_INITIALISED;
77754- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
77755+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
77756 op->processor = processor;
77757 op->release = release;
77758 INIT_LIST_HEAD(&op->pend_link);
77759diff --git a/include/linux/fscache.h b/include/linux/fscache.h
77760index 115bb81..e7b812b 100644
77761--- a/include/linux/fscache.h
77762+++ b/include/linux/fscache.h
77763@@ -152,7 +152,7 @@ struct fscache_cookie_def {
77764 * - this is mandatory for any object that may have data
77765 */
77766 void (*now_uncached)(void *cookie_netfs_data);
77767-};
77768+} __do_const;
77769
77770 /*
77771 * fscache cached network filesystem type
77772diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
77773index 1c804b0..1432c2b 100644
77774--- a/include/linux/fsnotify.h
77775+++ b/include/linux/fsnotify.h
77776@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
77777 struct inode *inode = file_inode(file);
77778 __u32 mask = FS_ACCESS;
77779
77780+ if (is_sidechannel_device(inode))
77781+ return;
77782+
77783 if (S_ISDIR(inode->i_mode))
77784 mask |= FS_ISDIR;
77785
77786@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
77787 struct inode *inode = file_inode(file);
77788 __u32 mask = FS_MODIFY;
77789
77790+ if (is_sidechannel_device(inode))
77791+ return;
77792+
77793 if (S_ISDIR(inode->i_mode))
77794 mask |= FS_ISDIR;
77795
77796@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
77797 */
77798 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
77799 {
77800- return kstrdup(name, GFP_KERNEL);
77801+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
77802 }
77803
77804 /*
77805diff --git a/include/linux/genhd.h b/include/linux/genhd.h
77806index 9f3c275..8bdff5d 100644
77807--- a/include/linux/genhd.h
77808+++ b/include/linux/genhd.h
77809@@ -194,7 +194,7 @@ struct gendisk {
77810 struct kobject *slave_dir;
77811
77812 struct timer_rand_state *random;
77813- atomic_t sync_io; /* RAID */
77814+ atomic_unchecked_t sync_io; /* RAID */
77815 struct disk_events *ev;
77816 #ifdef CONFIG_BLK_DEV_INTEGRITY
77817 struct blk_integrity *integrity;
77818@@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
77819 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
77820
77821 /* drivers/char/random.c */
77822-extern void add_disk_randomness(struct gendisk *disk);
77823+extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
77824 extern void rand_initialize_disk(struct gendisk *disk);
77825
77826 static inline sector_t get_start_sect(struct block_device *bdev)
77827diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
77828index c0894dd..2fbf10c 100644
77829--- a/include/linux/genl_magic_func.h
77830+++ b/include/linux/genl_magic_func.h
77831@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
77832 },
77833
77834 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
77835-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
77836+static struct genl_ops ZZZ_genl_ops[] = {
77837 #include GENL_MAGIC_INCLUDE_FILE
77838 };
77839
77840diff --git a/include/linux/gfp.h b/include/linux/gfp.h
77841index 9b4dd49..61fd41d 100644
77842--- a/include/linux/gfp.h
77843+++ b/include/linux/gfp.h
77844@@ -35,6 +35,13 @@ struct vm_area_struct;
77845 #define ___GFP_NO_KSWAPD 0x400000u
77846 #define ___GFP_OTHER_NODE 0x800000u
77847 #define ___GFP_WRITE 0x1000000u
77848+
77849+#ifdef CONFIG_PAX_USERCOPY_SLABS
77850+#define ___GFP_USERCOPY 0x2000000u
77851+#else
77852+#define ___GFP_USERCOPY 0
77853+#endif
77854+
77855 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
77856
77857 /*
77858@@ -92,6 +99,7 @@ struct vm_area_struct;
77859 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
77860 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
77861 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
77862+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
77863
77864 /*
77865 * This may seem redundant, but it's a way of annotating false positives vs.
77866@@ -99,7 +107,7 @@ struct vm_area_struct;
77867 */
77868 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
77869
77870-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
77871+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
77872 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
77873
77874 /* This equals 0, but use constants in case they ever change */
77875@@ -153,6 +161,8 @@ struct vm_area_struct;
77876 /* 4GB DMA on some platforms */
77877 #define GFP_DMA32 __GFP_DMA32
77878
77879+#define GFP_USERCOPY __GFP_USERCOPY
77880+
77881 /* Convert GFP flags to their corresponding migrate type */
77882 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
77883 {
77884diff --git a/include/linux/gracl.h b/include/linux/gracl.h
77885new file mode 100644
77886index 0000000..edb2cb6
77887--- /dev/null
77888+++ b/include/linux/gracl.h
77889@@ -0,0 +1,340 @@
77890+#ifndef GR_ACL_H
77891+#define GR_ACL_H
77892+
77893+#include <linux/grdefs.h>
77894+#include <linux/resource.h>
77895+#include <linux/capability.h>
77896+#include <linux/dcache.h>
77897+#include <asm/resource.h>
77898+
77899+/* Major status information */
77900+
77901+#define GR_VERSION "grsecurity 3.0"
77902+#define GRSECURITY_VERSION 0x3000
77903+
77904+enum {
77905+ GR_SHUTDOWN = 0,
77906+ GR_ENABLE = 1,
77907+ GR_SPROLE = 2,
77908+ GR_OLDRELOAD = 3,
77909+ GR_SEGVMOD = 4,
77910+ GR_STATUS = 5,
77911+ GR_UNSPROLE = 6,
77912+ GR_PASSSET = 7,
77913+ GR_SPROLEPAM = 8,
77914+ GR_RELOAD = 9,
77915+};
77916+
77917+/* Password setup definitions
77918+ * kernel/grhash.c */
77919+enum {
77920+ GR_PW_LEN = 128,
77921+ GR_SALT_LEN = 16,
77922+ GR_SHA_LEN = 32,
77923+};
77924+
77925+enum {
77926+ GR_SPROLE_LEN = 64,
77927+};
77928+
77929+enum {
77930+ GR_NO_GLOB = 0,
77931+ GR_REG_GLOB,
77932+ GR_CREATE_GLOB
77933+};
77934+
77935+#define GR_NLIMITS 32
77936+
77937+/* Begin Data Structures */
77938+
77939+struct sprole_pw {
77940+ unsigned char *rolename;
77941+ unsigned char salt[GR_SALT_LEN];
77942+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77943+};
77944+
77945+struct name_entry {
77946+ __u32 key;
77947+ ino_t inode;
77948+ dev_t device;
77949+ char *name;
77950+ __u16 len;
77951+ __u8 deleted;
77952+ struct name_entry *prev;
77953+ struct name_entry *next;
77954+};
77955+
77956+struct inodev_entry {
77957+ struct name_entry *nentry;
77958+ struct inodev_entry *prev;
77959+ struct inodev_entry *next;
77960+};
77961+
77962+struct acl_role_db {
77963+ struct acl_role_label **r_hash;
77964+ __u32 r_size;
77965+};
77966+
77967+struct inodev_db {
77968+ struct inodev_entry **i_hash;
77969+ __u32 i_size;
77970+};
77971+
77972+struct name_db {
77973+ struct name_entry **n_hash;
77974+ __u32 n_size;
77975+};
77976+
77977+struct crash_uid {
77978+ uid_t uid;
77979+ unsigned long expires;
77980+};
77981+
77982+struct gr_hash_struct {
77983+ void **table;
77984+ void **nametable;
77985+ void *first;
77986+ __u32 table_size;
77987+ __u32 used_size;
77988+ int type;
77989+};
77990+
77991+/* Userspace Grsecurity ACL data structures */
77992+
77993+struct acl_subject_label {
77994+ char *filename;
77995+ ino_t inode;
77996+ dev_t device;
77997+ __u32 mode;
77998+ kernel_cap_t cap_mask;
77999+ kernel_cap_t cap_lower;
78000+ kernel_cap_t cap_invert_audit;
78001+
78002+ struct rlimit res[GR_NLIMITS];
78003+ __u32 resmask;
78004+
78005+ __u8 user_trans_type;
78006+ __u8 group_trans_type;
78007+ uid_t *user_transitions;
78008+ gid_t *group_transitions;
78009+ __u16 user_trans_num;
78010+ __u16 group_trans_num;
78011+
78012+ __u32 sock_families[2];
78013+ __u32 ip_proto[8];
78014+ __u32 ip_type;
78015+ struct acl_ip_label **ips;
78016+ __u32 ip_num;
78017+ __u32 inaddr_any_override;
78018+
78019+ __u32 crashes;
78020+ unsigned long expires;
78021+
78022+ struct acl_subject_label *parent_subject;
78023+ struct gr_hash_struct *hash;
78024+ struct acl_subject_label *prev;
78025+ struct acl_subject_label *next;
78026+
78027+ struct acl_object_label **obj_hash;
78028+ __u32 obj_hash_size;
78029+ __u16 pax_flags;
78030+};
78031+
78032+struct role_allowed_ip {
78033+ __u32 addr;
78034+ __u32 netmask;
78035+
78036+ struct role_allowed_ip *prev;
78037+ struct role_allowed_ip *next;
78038+};
78039+
78040+struct role_transition {
78041+ char *rolename;
78042+
78043+ struct role_transition *prev;
78044+ struct role_transition *next;
78045+};
78046+
78047+struct acl_role_label {
78048+ char *rolename;
78049+ uid_t uidgid;
78050+ __u16 roletype;
78051+
78052+ __u16 auth_attempts;
78053+ unsigned long expires;
78054+
78055+ struct acl_subject_label *root_label;
78056+ struct gr_hash_struct *hash;
78057+
78058+ struct acl_role_label *prev;
78059+ struct acl_role_label *next;
78060+
78061+ struct role_transition *transitions;
78062+ struct role_allowed_ip *allowed_ips;
78063+ uid_t *domain_children;
78064+ __u16 domain_child_num;
78065+
78066+ umode_t umask;
78067+
78068+ struct acl_subject_label **subj_hash;
78069+ __u32 subj_hash_size;
78070+};
78071+
78072+struct user_acl_role_db {
78073+ struct acl_role_label **r_table;
78074+ __u32 num_pointers; /* Number of allocations to track */
78075+ __u32 num_roles; /* Number of roles */
78076+ __u32 num_domain_children; /* Number of domain children */
78077+ __u32 num_subjects; /* Number of subjects */
78078+ __u32 num_objects; /* Number of objects */
78079+};
78080+
78081+struct acl_object_label {
78082+ char *filename;
78083+ ino_t inode;
78084+ dev_t device;
78085+ __u32 mode;
78086+
78087+ struct acl_subject_label *nested;
78088+ struct acl_object_label *globbed;
78089+
78090+ /* next two structures not used */
78091+
78092+ struct acl_object_label *prev;
78093+ struct acl_object_label *next;
78094+};
78095+
78096+struct acl_ip_label {
78097+ char *iface;
78098+ __u32 addr;
78099+ __u32 netmask;
78100+ __u16 low, high;
78101+ __u8 mode;
78102+ __u32 type;
78103+ __u32 proto[8];
78104+
78105+ /* next two structures not used */
78106+
78107+ struct acl_ip_label *prev;
78108+ struct acl_ip_label *next;
78109+};
78110+
78111+struct gr_arg {
78112+ struct user_acl_role_db role_db;
78113+ unsigned char pw[GR_PW_LEN];
78114+ unsigned char salt[GR_SALT_LEN];
78115+ unsigned char sum[GR_SHA_LEN];
78116+ unsigned char sp_role[GR_SPROLE_LEN];
78117+ struct sprole_pw *sprole_pws;
78118+ dev_t segv_device;
78119+ ino_t segv_inode;
78120+ uid_t segv_uid;
78121+ __u16 num_sprole_pws;
78122+ __u16 mode;
78123+};
78124+
78125+struct gr_arg_wrapper {
78126+ struct gr_arg *arg;
78127+ __u32 version;
78128+ __u32 size;
78129+};
78130+
78131+struct subject_map {
78132+ struct acl_subject_label *user;
78133+ struct acl_subject_label *kernel;
78134+ struct subject_map *prev;
78135+ struct subject_map *next;
78136+};
78137+
78138+struct acl_subj_map_db {
78139+ struct subject_map **s_hash;
78140+ __u32 s_size;
78141+};
78142+
78143+struct gr_policy_state {
78144+ struct sprole_pw **acl_special_roles;
78145+ __u16 num_sprole_pws;
78146+ struct acl_role_label *kernel_role;
78147+ struct acl_role_label *role_list;
78148+ struct acl_role_label *default_role;
78149+ struct acl_role_db acl_role_set;
78150+ struct acl_subj_map_db subj_map_set;
78151+ struct name_db name_set;
78152+ struct inodev_db inodev_set;
78153+};
78154+
78155+struct gr_alloc_state {
78156+ unsigned long alloc_stack_next;
78157+ unsigned long alloc_stack_size;
78158+ void **alloc_stack;
78159+};
78160+
78161+struct gr_reload_state {
78162+ struct gr_policy_state oldpolicy;
78163+ struct gr_alloc_state oldalloc;
78164+ struct gr_policy_state newpolicy;
78165+ struct gr_alloc_state newalloc;
78166+ struct gr_policy_state *oldpolicy_ptr;
78167+ struct gr_alloc_state *oldalloc_ptr;
78168+ unsigned char oldmode;
78169+};
78170+
78171+/* End Data Structures Section */
78172+
78173+/* Hash functions generated by empirical testing by Brad Spengler
78174+ Makes good use of the low bits of the inode. Generally 0-1 times
78175+ in loop for successful match. 0-3 for unsuccessful match.
78176+ Shift/add algorithm with modulus of table size and an XOR*/
78177+
78178+static __inline__ unsigned int
78179+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78180+{
78181+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
78182+}
78183+
78184+ static __inline__ unsigned int
78185+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78186+{
78187+ return ((const unsigned long)userp % sz);
78188+}
78189+
78190+static __inline__ unsigned int
78191+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78192+{
78193+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78194+}
78195+
78196+static __inline__ unsigned int
78197+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78198+{
78199+ return full_name_hash((const unsigned char *)name, len) % sz;
78200+}
78201+
78202+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78203+ subj = NULL; \
78204+ iter = 0; \
78205+ while (iter < role->subj_hash_size) { \
78206+ if (subj == NULL) \
78207+ subj = role->subj_hash[iter]; \
78208+ if (subj == NULL) { \
78209+ iter++; \
78210+ continue; \
78211+ }
78212+
78213+#define FOR_EACH_SUBJECT_END(subj,iter) \
78214+ subj = subj->next; \
78215+ if (subj == NULL) \
78216+ iter++; \
78217+ }
78218+
78219+
78220+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78221+ subj = role->hash->first; \
78222+ while (subj != NULL) {
78223+
78224+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78225+ subj = subj->next; \
78226+ }
78227+
78228+#endif
78229+
78230diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
78231new file mode 100644
78232index 0000000..33ebd1f
78233--- /dev/null
78234+++ b/include/linux/gracl_compat.h
78235@@ -0,0 +1,156 @@
78236+#ifndef GR_ACL_COMPAT_H
78237+#define GR_ACL_COMPAT_H
78238+
78239+#include <linux/resource.h>
78240+#include <asm/resource.h>
78241+
78242+struct sprole_pw_compat {
78243+ compat_uptr_t rolename;
78244+ unsigned char salt[GR_SALT_LEN];
78245+ unsigned char sum[GR_SHA_LEN];
78246+};
78247+
78248+struct gr_hash_struct_compat {
78249+ compat_uptr_t table;
78250+ compat_uptr_t nametable;
78251+ compat_uptr_t first;
78252+ __u32 table_size;
78253+ __u32 used_size;
78254+ int type;
78255+};
78256+
78257+struct acl_subject_label_compat {
78258+ compat_uptr_t filename;
78259+ compat_ino_t inode;
78260+ __u32 device;
78261+ __u32 mode;
78262+ kernel_cap_t cap_mask;
78263+ kernel_cap_t cap_lower;
78264+ kernel_cap_t cap_invert_audit;
78265+
78266+ struct compat_rlimit res[GR_NLIMITS];
78267+ __u32 resmask;
78268+
78269+ __u8 user_trans_type;
78270+ __u8 group_trans_type;
78271+ compat_uptr_t user_transitions;
78272+ compat_uptr_t group_transitions;
78273+ __u16 user_trans_num;
78274+ __u16 group_trans_num;
78275+
78276+ __u32 sock_families[2];
78277+ __u32 ip_proto[8];
78278+ __u32 ip_type;
78279+ compat_uptr_t ips;
78280+ __u32 ip_num;
78281+ __u32 inaddr_any_override;
78282+
78283+ __u32 crashes;
78284+ compat_ulong_t expires;
78285+
78286+ compat_uptr_t parent_subject;
78287+ compat_uptr_t hash;
78288+ compat_uptr_t prev;
78289+ compat_uptr_t next;
78290+
78291+ compat_uptr_t obj_hash;
78292+ __u32 obj_hash_size;
78293+ __u16 pax_flags;
78294+};
78295+
78296+struct role_allowed_ip_compat {
78297+ __u32 addr;
78298+ __u32 netmask;
78299+
78300+ compat_uptr_t prev;
78301+ compat_uptr_t next;
78302+};
78303+
78304+struct role_transition_compat {
78305+ compat_uptr_t rolename;
78306+
78307+ compat_uptr_t prev;
78308+ compat_uptr_t next;
78309+};
78310+
78311+struct acl_role_label_compat {
78312+ compat_uptr_t rolename;
78313+ uid_t uidgid;
78314+ __u16 roletype;
78315+
78316+ __u16 auth_attempts;
78317+ compat_ulong_t expires;
78318+
78319+ compat_uptr_t root_label;
78320+ compat_uptr_t hash;
78321+
78322+ compat_uptr_t prev;
78323+ compat_uptr_t next;
78324+
78325+ compat_uptr_t transitions;
78326+ compat_uptr_t allowed_ips;
78327+ compat_uptr_t domain_children;
78328+ __u16 domain_child_num;
78329+
78330+ umode_t umask;
78331+
78332+ compat_uptr_t subj_hash;
78333+ __u32 subj_hash_size;
78334+};
78335+
78336+struct user_acl_role_db_compat {
78337+ compat_uptr_t r_table;
78338+ __u32 num_pointers;
78339+ __u32 num_roles;
78340+ __u32 num_domain_children;
78341+ __u32 num_subjects;
78342+ __u32 num_objects;
78343+};
78344+
78345+struct acl_object_label_compat {
78346+ compat_uptr_t filename;
78347+ compat_ino_t inode;
78348+ __u32 device;
78349+ __u32 mode;
78350+
78351+ compat_uptr_t nested;
78352+ compat_uptr_t globbed;
78353+
78354+ compat_uptr_t prev;
78355+ compat_uptr_t next;
78356+};
78357+
78358+struct acl_ip_label_compat {
78359+ compat_uptr_t iface;
78360+ __u32 addr;
78361+ __u32 netmask;
78362+ __u16 low, high;
78363+ __u8 mode;
78364+ __u32 type;
78365+ __u32 proto[8];
78366+
78367+ compat_uptr_t prev;
78368+ compat_uptr_t next;
78369+};
78370+
78371+struct gr_arg_compat {
78372+ struct user_acl_role_db_compat role_db;
78373+ unsigned char pw[GR_PW_LEN];
78374+ unsigned char salt[GR_SALT_LEN];
78375+ unsigned char sum[GR_SHA_LEN];
78376+ unsigned char sp_role[GR_SPROLE_LEN];
78377+ compat_uptr_t sprole_pws;
78378+ __u32 segv_device;
78379+ compat_ino_t segv_inode;
78380+ uid_t segv_uid;
78381+ __u16 num_sprole_pws;
78382+ __u16 mode;
78383+};
78384+
78385+struct gr_arg_wrapper_compat {
78386+ compat_uptr_t arg;
78387+ __u32 version;
78388+ __u32 size;
78389+};
78390+
78391+#endif
78392diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
78393new file mode 100644
78394index 0000000..323ecf2
78395--- /dev/null
78396+++ b/include/linux/gralloc.h
78397@@ -0,0 +1,9 @@
78398+#ifndef __GRALLOC_H
78399+#define __GRALLOC_H
78400+
78401+void acl_free_all(void);
78402+int acl_alloc_stack_init(unsigned long size);
78403+void *acl_alloc(unsigned long len);
78404+void *acl_alloc_num(unsigned long num, unsigned long len);
78405+
78406+#endif
78407diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
78408new file mode 100644
78409index 0000000..be66033
78410--- /dev/null
78411+++ b/include/linux/grdefs.h
78412@@ -0,0 +1,140 @@
78413+#ifndef GRDEFS_H
78414+#define GRDEFS_H
78415+
78416+/* Begin grsecurity status declarations */
78417+
78418+enum {
78419+ GR_READY = 0x01,
78420+ GR_STATUS_INIT = 0x00 // disabled state
78421+};
78422+
78423+/* Begin ACL declarations */
78424+
78425+/* Role flags */
78426+
78427+enum {
78428+ GR_ROLE_USER = 0x0001,
78429+ GR_ROLE_GROUP = 0x0002,
78430+ GR_ROLE_DEFAULT = 0x0004,
78431+ GR_ROLE_SPECIAL = 0x0008,
78432+ GR_ROLE_AUTH = 0x0010,
78433+ GR_ROLE_NOPW = 0x0020,
78434+ GR_ROLE_GOD = 0x0040,
78435+ GR_ROLE_LEARN = 0x0080,
78436+ GR_ROLE_TPE = 0x0100,
78437+ GR_ROLE_DOMAIN = 0x0200,
78438+ GR_ROLE_PAM = 0x0400,
78439+ GR_ROLE_PERSIST = 0x0800
78440+};
78441+
78442+/* ACL Subject and Object mode flags */
78443+enum {
78444+ GR_DELETED = 0x80000000
78445+};
78446+
78447+/* ACL Object-only mode flags */
78448+enum {
78449+ GR_READ = 0x00000001,
78450+ GR_APPEND = 0x00000002,
78451+ GR_WRITE = 0x00000004,
78452+ GR_EXEC = 0x00000008,
78453+ GR_FIND = 0x00000010,
78454+ GR_INHERIT = 0x00000020,
78455+ GR_SETID = 0x00000040,
78456+ GR_CREATE = 0x00000080,
78457+ GR_DELETE = 0x00000100,
78458+ GR_LINK = 0x00000200,
78459+ GR_AUDIT_READ = 0x00000400,
78460+ GR_AUDIT_APPEND = 0x00000800,
78461+ GR_AUDIT_WRITE = 0x00001000,
78462+ GR_AUDIT_EXEC = 0x00002000,
78463+ GR_AUDIT_FIND = 0x00004000,
78464+ GR_AUDIT_INHERIT= 0x00008000,
78465+ GR_AUDIT_SETID = 0x00010000,
78466+ GR_AUDIT_CREATE = 0x00020000,
78467+ GR_AUDIT_DELETE = 0x00040000,
78468+ GR_AUDIT_LINK = 0x00080000,
78469+ GR_PTRACERD = 0x00100000,
78470+ GR_NOPTRACE = 0x00200000,
78471+ GR_SUPPRESS = 0x00400000,
78472+ GR_NOLEARN = 0x00800000,
78473+ GR_INIT_TRANSFER= 0x01000000
78474+};
78475+
78476+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
78477+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
78478+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
78479+
78480+/* ACL subject-only mode flags */
78481+enum {
78482+ GR_KILL = 0x00000001,
78483+ GR_VIEW = 0x00000002,
78484+ GR_PROTECTED = 0x00000004,
78485+ GR_LEARN = 0x00000008,
78486+ GR_OVERRIDE = 0x00000010,
78487+ /* just a placeholder, this mode is only used in userspace */
78488+ GR_DUMMY = 0x00000020,
78489+ GR_PROTSHM = 0x00000040,
78490+ GR_KILLPROC = 0x00000080,
78491+ GR_KILLIPPROC = 0x00000100,
78492+ /* just a placeholder, this mode is only used in userspace */
78493+ GR_NOTROJAN = 0x00000200,
78494+ GR_PROTPROCFD = 0x00000400,
78495+ GR_PROCACCT = 0x00000800,
78496+ GR_RELAXPTRACE = 0x00001000,
78497+ //GR_NESTED = 0x00002000,
78498+ GR_INHERITLEARN = 0x00004000,
78499+ GR_PROCFIND = 0x00008000,
78500+ GR_POVERRIDE = 0x00010000,
78501+ GR_KERNELAUTH = 0x00020000,
78502+ GR_ATSECURE = 0x00040000,
78503+ GR_SHMEXEC = 0x00080000
78504+};
78505+
78506+enum {
78507+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
78508+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
78509+ GR_PAX_ENABLE_MPROTECT = 0x0004,
78510+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
78511+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
78512+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
78513+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
78514+ GR_PAX_DISABLE_MPROTECT = 0x0400,
78515+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
78516+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
78517+};
78518+
78519+enum {
78520+ GR_ID_USER = 0x01,
78521+ GR_ID_GROUP = 0x02,
78522+};
78523+
78524+enum {
78525+ GR_ID_ALLOW = 0x01,
78526+ GR_ID_DENY = 0x02,
78527+};
78528+
78529+#define GR_CRASH_RES 31
78530+#define GR_UIDTABLE_MAX 500
78531+
78532+/* begin resource learning section */
78533+enum {
78534+ GR_RLIM_CPU_BUMP = 60,
78535+ GR_RLIM_FSIZE_BUMP = 50000,
78536+ GR_RLIM_DATA_BUMP = 10000,
78537+ GR_RLIM_STACK_BUMP = 1000,
78538+ GR_RLIM_CORE_BUMP = 10000,
78539+ GR_RLIM_RSS_BUMP = 500000,
78540+ GR_RLIM_NPROC_BUMP = 1,
78541+ GR_RLIM_NOFILE_BUMP = 5,
78542+ GR_RLIM_MEMLOCK_BUMP = 50000,
78543+ GR_RLIM_AS_BUMP = 500000,
78544+ GR_RLIM_LOCKS_BUMP = 2,
78545+ GR_RLIM_SIGPENDING_BUMP = 5,
78546+ GR_RLIM_MSGQUEUE_BUMP = 10000,
78547+ GR_RLIM_NICE_BUMP = 1,
78548+ GR_RLIM_RTPRIO_BUMP = 1,
78549+ GR_RLIM_RTTIME_BUMP = 1000000
78550+};
78551+
78552+#endif
78553diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
78554new file mode 100644
78555index 0000000..d25522e
78556--- /dev/null
78557+++ b/include/linux/grinternal.h
78558@@ -0,0 +1,229 @@
78559+#ifndef __GRINTERNAL_H
78560+#define __GRINTERNAL_H
78561+
78562+#ifdef CONFIG_GRKERNSEC
78563+
78564+#include <linux/fs.h>
78565+#include <linux/mnt_namespace.h>
78566+#include <linux/nsproxy.h>
78567+#include <linux/gracl.h>
78568+#include <linux/grdefs.h>
78569+#include <linux/grmsg.h>
78570+
78571+void gr_add_learn_entry(const char *fmt, ...)
78572+ __attribute__ ((format (printf, 1, 2)));
78573+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
78574+ const struct vfsmount *mnt);
78575+__u32 gr_check_create(const struct dentry *new_dentry,
78576+ const struct dentry *parent,
78577+ const struct vfsmount *mnt, const __u32 mode);
78578+int gr_check_protected_task(const struct task_struct *task);
78579+__u32 to_gr_audit(const __u32 reqmode);
78580+int gr_set_acls(const int type);
78581+int gr_acl_is_enabled(void);
78582+char gr_roletype_to_char(void);
78583+
78584+void gr_handle_alertkill(struct task_struct *task);
78585+char *gr_to_filename(const struct dentry *dentry,
78586+ const struct vfsmount *mnt);
78587+char *gr_to_filename1(const struct dentry *dentry,
78588+ const struct vfsmount *mnt);
78589+char *gr_to_filename2(const struct dentry *dentry,
78590+ const struct vfsmount *mnt);
78591+char *gr_to_filename3(const struct dentry *dentry,
78592+ const struct vfsmount *mnt);
78593+
78594+extern int grsec_enable_ptrace_readexec;
78595+extern int grsec_enable_harden_ptrace;
78596+extern int grsec_enable_link;
78597+extern int grsec_enable_fifo;
78598+extern int grsec_enable_execve;
78599+extern int grsec_enable_shm;
78600+extern int grsec_enable_execlog;
78601+extern int grsec_enable_signal;
78602+extern int grsec_enable_audit_ptrace;
78603+extern int grsec_enable_forkfail;
78604+extern int grsec_enable_time;
78605+extern int grsec_enable_rofs;
78606+extern int grsec_deny_new_usb;
78607+extern int grsec_enable_chroot_shmat;
78608+extern int grsec_enable_chroot_mount;
78609+extern int grsec_enable_chroot_double;
78610+extern int grsec_enable_chroot_pivot;
78611+extern int grsec_enable_chroot_chdir;
78612+extern int grsec_enable_chroot_chmod;
78613+extern int grsec_enable_chroot_mknod;
78614+extern int grsec_enable_chroot_fchdir;
78615+extern int grsec_enable_chroot_nice;
78616+extern int grsec_enable_chroot_execlog;
78617+extern int grsec_enable_chroot_caps;
78618+extern int grsec_enable_chroot_sysctl;
78619+extern int grsec_enable_chroot_unix;
78620+extern int grsec_enable_symlinkown;
78621+extern kgid_t grsec_symlinkown_gid;
78622+extern int grsec_enable_tpe;
78623+extern kgid_t grsec_tpe_gid;
78624+extern int grsec_enable_tpe_all;
78625+extern int grsec_enable_tpe_invert;
78626+extern int grsec_enable_socket_all;
78627+extern kgid_t grsec_socket_all_gid;
78628+extern int grsec_enable_socket_client;
78629+extern kgid_t grsec_socket_client_gid;
78630+extern int grsec_enable_socket_server;
78631+extern kgid_t grsec_socket_server_gid;
78632+extern kgid_t grsec_audit_gid;
78633+extern int grsec_enable_group;
78634+extern int grsec_enable_log_rwxmaps;
78635+extern int grsec_enable_mount;
78636+extern int grsec_enable_chdir;
78637+extern int grsec_resource_logging;
78638+extern int grsec_enable_blackhole;
78639+extern int grsec_lastack_retries;
78640+extern int grsec_enable_brute;
78641+extern int grsec_enable_harden_ipc;
78642+extern int grsec_lock;
78643+
78644+extern spinlock_t grsec_alert_lock;
78645+extern unsigned long grsec_alert_wtime;
78646+extern unsigned long grsec_alert_fyet;
78647+
78648+extern spinlock_t grsec_audit_lock;
78649+
78650+extern rwlock_t grsec_exec_file_lock;
78651+
78652+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
78653+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
78654+ (tsk)->exec_file->f_path.mnt) : "/")
78655+
78656+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
78657+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
78658+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78659+
78660+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
78661+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
78662+ (tsk)->exec_file->f_path.mnt) : "/")
78663+
78664+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
78665+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
78666+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
78667+
78668+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
78669+
78670+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
78671+
78672+static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
78673+{
78674+ if (file1 && file2) {
78675+ const struct inode *inode1 = file1->f_path.dentry->d_inode;
78676+ const struct inode *inode2 = file2->f_path.dentry->d_inode;
78677+ if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
78678+ return true;
78679+ }
78680+
78681+ return false;
78682+}
78683+
78684+#define GR_CHROOT_CAPS {{ \
78685+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
78686+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
78687+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
78688+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
78689+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
78690+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
78691+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
78692+
78693+#define security_learn(normal_msg,args...) \
78694+({ \
78695+ read_lock(&grsec_exec_file_lock); \
78696+ gr_add_learn_entry(normal_msg "\n", ## args); \
78697+ read_unlock(&grsec_exec_file_lock); \
78698+})
78699+
78700+enum {
78701+ GR_DO_AUDIT,
78702+ GR_DONT_AUDIT,
78703+ /* used for non-audit messages that we shouldn't kill the task on */
78704+ GR_DONT_AUDIT_GOOD
78705+};
78706+
78707+enum {
78708+ GR_TTYSNIFF,
78709+ GR_RBAC,
78710+ GR_RBAC_STR,
78711+ GR_STR_RBAC,
78712+ GR_RBAC_MODE2,
78713+ GR_RBAC_MODE3,
78714+ GR_FILENAME,
78715+ GR_SYSCTL_HIDDEN,
78716+ GR_NOARGS,
78717+ GR_ONE_INT,
78718+ GR_ONE_INT_TWO_STR,
78719+ GR_ONE_STR,
78720+ GR_STR_INT,
78721+ GR_TWO_STR_INT,
78722+ GR_TWO_INT,
78723+ GR_TWO_U64,
78724+ GR_THREE_INT,
78725+ GR_FIVE_INT_TWO_STR,
78726+ GR_TWO_STR,
78727+ GR_THREE_STR,
78728+ GR_FOUR_STR,
78729+ GR_STR_FILENAME,
78730+ GR_FILENAME_STR,
78731+ GR_FILENAME_TWO_INT,
78732+ GR_FILENAME_TWO_INT_STR,
78733+ GR_TEXTREL,
78734+ GR_PTRACE,
78735+ GR_RESOURCE,
78736+ GR_CAP,
78737+ GR_SIG,
78738+ GR_SIG2,
78739+ GR_CRASH1,
78740+ GR_CRASH2,
78741+ GR_PSACCT,
78742+ GR_RWXMAP,
78743+ GR_RWXMAPVMA
78744+};
78745+
78746+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
78747+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
78748+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
78749+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
78750+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
78751+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
78752+#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)
78753+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
78754+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
78755+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
78756+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
78757+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
78758+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
78759+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
78760+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
78761+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
78762+#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)
78763+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
78764+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
78765+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
78766+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
78767+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
78768+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
78769+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
78770+#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)
78771+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
78772+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
78773+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
78774+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
78775+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
78776+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
78777+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
78778+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
78779+#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)
78780+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
78781+#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
78782+
78783+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
78784+
78785+#endif
78786+
78787+#endif
78788diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
78789new file mode 100644
78790index 0000000..ba93581
78791--- /dev/null
78792+++ b/include/linux/grmsg.h
78793@@ -0,0 +1,116 @@
78794+#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"
78795+#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"
78796+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
78797+#define GR_STOPMOD_MSG "denied modification of module state by "
78798+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
78799+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
78800+#define GR_IOPERM_MSG "denied use of ioperm() by "
78801+#define GR_IOPL_MSG "denied use of iopl() by "
78802+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
78803+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
78804+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
78805+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
78806+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
78807+#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"
78808+#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"
78809+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
78810+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
78811+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
78812+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
78813+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
78814+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
78815+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
78816+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
78817+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
78818+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
78819+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
78820+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
78821+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
78822+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
78823+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
78824+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
78825+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
78826+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
78827+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
78828+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
78829+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
78830+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
78831+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
78832+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
78833+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
78834+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
78835+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
78836+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
78837+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
78838+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
78839+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
78840+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
78841+#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
78842+#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
78843+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
78844+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
78845+#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"
78846+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
78847+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
78848+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
78849+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
78850+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
78851+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
78852+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
78853+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
78854+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
78855+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
78856+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
78857+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
78858+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
78859+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
78860+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
78861+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
78862+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
78863+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
78864+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
78865+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
78866+#define GR_FAILFORK_MSG "failed fork with errno %s by "
78867+#define GR_NICE_CHROOT_MSG "denied priority change by "
78868+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
78869+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
78870+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
78871+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
78872+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
78873+#define GR_TIME_MSG "time set by "
78874+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
78875+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
78876+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
78877+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
78878+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
78879+#define GR_BIND_MSG "denied bind() by "
78880+#define GR_CONNECT_MSG "denied connect() by "
78881+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
78882+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
78883+#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"
78884+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
78885+#define GR_CAP_ACL_MSG "use of %s denied for "
78886+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
78887+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
78888+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
78889+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
78890+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
78891+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
78892+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
78893+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
78894+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
78895+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
78896+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
78897+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
78898+#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
78899+#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
78900+#define GR_VM86_MSG "denied use of vm86 by "
78901+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
78902+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
78903+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
78904+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78905+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78906+#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 "
78907+#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 "
78908+#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78909+#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78910diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78911new file mode 100644
78912index 0000000..8108301
78913--- /dev/null
78914+++ b/include/linux/grsecurity.h
78915@@ -0,0 +1,246 @@
78916+#ifndef GR_SECURITY_H
78917+#define GR_SECURITY_H
78918+#include <linux/fs.h>
78919+#include <linux/fs_struct.h>
78920+#include <linux/binfmts.h>
78921+#include <linux/gracl.h>
78922+
78923+/* notify of brain-dead configs */
78924+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78925+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78926+#endif
78927+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78928+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78929+#endif
78930+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78931+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78932+#endif
78933+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78934+#error "CONFIG_PAX enabled, but no PaX options are enabled."
78935+#endif
78936+
78937+int gr_handle_new_usb(void);
78938+
78939+void gr_handle_brute_attach(int dumpable);
78940+void gr_handle_brute_check(void);
78941+void gr_handle_kernel_exploit(void);
78942+
78943+char gr_roletype_to_char(void);
78944+
78945+int gr_acl_enable_at_secure(void);
78946+
78947+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78948+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78949+
78950+void gr_del_task_from_ip_table(struct task_struct *p);
78951+
78952+int gr_pid_is_chrooted(struct task_struct *p);
78953+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78954+int gr_handle_chroot_nice(void);
78955+int gr_handle_chroot_sysctl(const int op);
78956+int gr_handle_chroot_setpriority(struct task_struct *p,
78957+ const int niceval);
78958+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78959+int gr_handle_chroot_chroot(const struct dentry *dentry,
78960+ const struct vfsmount *mnt);
78961+void gr_handle_chroot_chdir(const struct path *path);
78962+int gr_handle_chroot_chmod(const struct dentry *dentry,
78963+ const struct vfsmount *mnt, const int mode);
78964+int gr_handle_chroot_mknod(const struct dentry *dentry,
78965+ const struct vfsmount *mnt, const int mode);
78966+int gr_handle_chroot_mount(const struct dentry *dentry,
78967+ const struct vfsmount *mnt,
78968+ const char *dev_name);
78969+int gr_handle_chroot_pivot(void);
78970+int gr_handle_chroot_unix(const pid_t pid);
78971+
78972+int gr_handle_rawio(const struct inode *inode);
78973+
78974+void gr_handle_ioperm(void);
78975+void gr_handle_iopl(void);
78976+void gr_handle_msr_write(void);
78977+
78978+umode_t gr_acl_umask(void);
78979+
78980+int gr_tpe_allow(const struct file *file);
78981+
78982+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78983+void gr_clear_chroot_entries(struct task_struct *task);
78984+
78985+void gr_log_forkfail(const int retval);
78986+void gr_log_timechange(void);
78987+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78988+void gr_log_chdir(const struct dentry *dentry,
78989+ const struct vfsmount *mnt);
78990+void gr_log_chroot_exec(const struct dentry *dentry,
78991+ const struct vfsmount *mnt);
78992+void gr_log_remount(const char *devname, const int retval);
78993+void gr_log_unmount(const char *devname, const int retval);
78994+void gr_log_mount(const char *from, const char *to, const int retval);
78995+void gr_log_textrel(struct vm_area_struct *vma);
78996+void gr_log_ptgnustack(struct file *file);
78997+void gr_log_rwxmmap(struct file *file);
78998+void gr_log_rwxmprotect(struct vm_area_struct *vma);
78999+
79000+int gr_handle_follow_link(const struct inode *parent,
79001+ const struct inode *inode,
79002+ const struct dentry *dentry,
79003+ const struct vfsmount *mnt);
79004+int gr_handle_fifo(const struct dentry *dentry,
79005+ const struct vfsmount *mnt,
79006+ const struct dentry *dir, const int flag,
79007+ const int acc_mode);
79008+int gr_handle_hardlink(const struct dentry *dentry,
79009+ const struct vfsmount *mnt,
79010+ struct inode *inode,
79011+ const int mode, const struct filename *to);
79012+
79013+int gr_is_capable(const int cap);
79014+int gr_is_capable_nolog(const int cap);
79015+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79016+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79017+
79018+void gr_copy_label(struct task_struct *tsk);
79019+void gr_handle_crash(struct task_struct *task, const int sig);
79020+int gr_handle_signal(const struct task_struct *p, const int sig);
79021+int gr_check_crash_uid(const kuid_t uid);
79022+int gr_check_protected_task(const struct task_struct *task);
79023+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79024+int gr_acl_handle_mmap(const struct file *file,
79025+ const unsigned long prot);
79026+int gr_acl_handle_mprotect(const struct file *file,
79027+ const unsigned long prot);
79028+int gr_check_hidden_task(const struct task_struct *tsk);
79029+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79030+ const struct vfsmount *mnt);
79031+__u32 gr_acl_handle_utime(const struct dentry *dentry,
79032+ const struct vfsmount *mnt);
79033+__u32 gr_acl_handle_access(const struct dentry *dentry,
79034+ const struct vfsmount *mnt, const int fmode);
79035+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79036+ const struct vfsmount *mnt, umode_t *mode);
79037+__u32 gr_acl_handle_chown(const struct dentry *dentry,
79038+ const struct vfsmount *mnt);
79039+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79040+ const struct vfsmount *mnt);
79041+__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79042+ const struct vfsmount *mnt);
79043+int gr_handle_ptrace(struct task_struct *task, const long request);
79044+int gr_handle_proc_ptrace(struct task_struct *task);
79045+__u32 gr_acl_handle_execve(const struct dentry *dentry,
79046+ const struct vfsmount *mnt);
79047+int gr_check_crash_exec(const struct file *filp);
79048+int gr_acl_is_enabled(void);
79049+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79050+ const kgid_t gid);
79051+int gr_set_proc_label(const struct dentry *dentry,
79052+ const struct vfsmount *mnt,
79053+ const int unsafe_flags);
79054+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79055+ const struct vfsmount *mnt);
79056+__u32 gr_acl_handle_open(const struct dentry *dentry,
79057+ const struct vfsmount *mnt, int acc_mode);
79058+__u32 gr_acl_handle_creat(const struct dentry *dentry,
79059+ const struct dentry *p_dentry,
79060+ const struct vfsmount *p_mnt,
79061+ int open_flags, int acc_mode, const int imode);
79062+void gr_handle_create(const struct dentry *dentry,
79063+ const struct vfsmount *mnt);
79064+void gr_handle_proc_create(const struct dentry *dentry,
79065+ const struct inode *inode);
79066+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79067+ const struct dentry *parent_dentry,
79068+ const struct vfsmount *parent_mnt,
79069+ const int mode);
79070+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79071+ const struct dentry *parent_dentry,
79072+ const struct vfsmount *parent_mnt);
79073+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79074+ const struct vfsmount *mnt);
79075+void gr_handle_delete(const ino_t ino, const dev_t dev);
79076+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79077+ const struct vfsmount *mnt);
79078+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79079+ const struct dentry *parent_dentry,
79080+ const struct vfsmount *parent_mnt,
79081+ const struct filename *from);
79082+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79083+ const struct dentry *parent_dentry,
79084+ const struct vfsmount *parent_mnt,
79085+ const struct dentry *old_dentry,
79086+ const struct vfsmount *old_mnt, const struct filename *to);
79087+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79088+int gr_acl_handle_rename(struct dentry *new_dentry,
79089+ struct dentry *parent_dentry,
79090+ const struct vfsmount *parent_mnt,
79091+ struct dentry *old_dentry,
79092+ struct inode *old_parent_inode,
79093+ struct vfsmount *old_mnt, const struct filename *newname);
79094+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79095+ struct dentry *old_dentry,
79096+ struct dentry *new_dentry,
79097+ struct vfsmount *mnt, const __u8 replace);
79098+__u32 gr_check_link(const struct dentry *new_dentry,
79099+ const struct dentry *parent_dentry,
79100+ const struct vfsmount *parent_mnt,
79101+ const struct dentry *old_dentry,
79102+ const struct vfsmount *old_mnt);
79103+int gr_acl_handle_filldir(const struct file *file, const char *name,
79104+ const unsigned int namelen, const ino_t ino);
79105+
79106+__u32 gr_acl_handle_unix(const struct dentry *dentry,
79107+ const struct vfsmount *mnt);
79108+void gr_acl_handle_exit(void);
79109+void gr_acl_handle_psacct(struct task_struct *task, const long code);
79110+int gr_acl_handle_procpidmem(const struct task_struct *task);
79111+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79112+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79113+void gr_audit_ptrace(struct task_struct *task);
79114+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79115+void gr_put_exec_file(struct task_struct *task);
79116+
79117+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79118+
79119+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79120+extern void gr_learn_resource(const struct task_struct *task, const int res,
79121+ const unsigned long wanted, const int gt);
79122+#else
79123+static inline void gr_learn_resource(const struct task_struct *task, const int res,
79124+ const unsigned long wanted, const int gt)
79125+{
79126+}
79127+#endif
79128+
79129+#ifdef CONFIG_GRKERNSEC_RESLOG
79130+extern void gr_log_resource(const struct task_struct *task, const int res,
79131+ const unsigned long wanted, const int gt);
79132+#else
79133+static inline void gr_log_resource(const struct task_struct *task, const int res,
79134+ const unsigned long wanted, const int gt)
79135+{
79136+}
79137+#endif
79138+
79139+#ifdef CONFIG_GRKERNSEC
79140+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79141+void gr_handle_vm86(void);
79142+void gr_handle_mem_readwrite(u64 from, u64 to);
79143+
79144+void gr_log_badprocpid(const char *entry);
79145+
79146+extern int grsec_enable_dmesg;
79147+extern int grsec_disable_privio;
79148+
79149+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79150+extern kgid_t grsec_proc_gid;
79151+#endif
79152+
79153+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79154+extern int grsec_enable_chroot_findtask;
79155+#endif
79156+#ifdef CONFIG_GRKERNSEC_SETXID
79157+extern int grsec_enable_setxid;
79158+#endif
79159+#endif
79160+
79161+#endif
79162diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79163new file mode 100644
79164index 0000000..e7ffaaf
79165--- /dev/null
79166+++ b/include/linux/grsock.h
79167@@ -0,0 +1,19 @@
79168+#ifndef __GRSOCK_H
79169+#define __GRSOCK_H
79170+
79171+extern void gr_attach_curr_ip(const struct sock *sk);
79172+extern int gr_handle_sock_all(const int family, const int type,
79173+ const int protocol);
79174+extern int gr_handle_sock_server(const struct sockaddr *sck);
79175+extern int gr_handle_sock_server_other(const struct sock *sck);
79176+extern int gr_handle_sock_client(const struct sockaddr *sck);
79177+extern int gr_search_connect(struct socket * sock,
79178+ struct sockaddr_in * addr);
79179+extern int gr_search_bind(struct socket * sock,
79180+ struct sockaddr_in * addr);
79181+extern int gr_search_listen(struct socket * sock);
79182+extern int gr_search_accept(struct socket * sock);
79183+extern int gr_search_socket(const int domain, const int type,
79184+ const int protocol);
79185+
79186+#endif
79187diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79188index 7fb31da..08b5114 100644
79189--- a/include/linux/highmem.h
79190+++ b/include/linux/highmem.h
79191@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79192 kunmap_atomic(kaddr);
79193 }
79194
79195+static inline void sanitize_highpage(struct page *page)
79196+{
79197+ void *kaddr;
79198+ unsigned long flags;
79199+
79200+ local_irq_save(flags);
79201+ kaddr = kmap_atomic(page);
79202+ clear_page(kaddr);
79203+ kunmap_atomic(kaddr);
79204+ local_irq_restore(flags);
79205+}
79206+
79207 static inline void zero_user_segments(struct page *page,
79208 unsigned start1, unsigned end1,
79209 unsigned start2, unsigned end2)
79210diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79211index 1c7b89a..7dda400 100644
79212--- a/include/linux/hwmon-sysfs.h
79213+++ b/include/linux/hwmon-sysfs.h
79214@@ -25,7 +25,8 @@
79215 struct sensor_device_attribute{
79216 struct device_attribute dev_attr;
79217 int index;
79218-};
79219+} __do_const;
79220+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
79221 #define to_sensor_dev_attr(_dev_attr) \
79222 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
79223
79224@@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
79225 struct device_attribute dev_attr;
79226 u8 index;
79227 u8 nr;
79228-};
79229+} __do_const;
79230+typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
79231 #define to_sensor_dev_attr_2(_dev_attr) \
79232 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
79233
79234diff --git a/include/linux/i2c.h b/include/linux/i2c.h
79235index d9c8dbd3..def6e5a 100644
79236--- a/include/linux/i2c.h
79237+++ b/include/linux/i2c.h
79238@@ -364,6 +364,7 @@ struct i2c_algorithm {
79239 /* To determine what the adapter supports */
79240 u32 (*functionality) (struct i2c_adapter *);
79241 };
79242+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
79243
79244 /**
79245 * struct i2c_bus_recovery_info - I2C bus recovery information
79246diff --git a/include/linux/i2o.h b/include/linux/i2o.h
79247index d23c3c2..eb63c81 100644
79248--- a/include/linux/i2o.h
79249+++ b/include/linux/i2o.h
79250@@ -565,7 +565,7 @@ struct i2o_controller {
79251 struct i2o_device *exec; /* Executive */
79252 #if BITS_PER_LONG == 64
79253 spinlock_t context_list_lock; /* lock for context_list */
79254- atomic_t context_list_counter; /* needed for unique contexts */
79255+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
79256 struct list_head context_list; /* list of context id's
79257 and pointers */
79258 #endif
79259diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
79260index aff7ad8..3942bbd 100644
79261--- a/include/linux/if_pppox.h
79262+++ b/include/linux/if_pppox.h
79263@@ -76,7 +76,7 @@ struct pppox_proto {
79264 int (*ioctl)(struct socket *sock, unsigned int cmd,
79265 unsigned long arg);
79266 struct module *owner;
79267-};
79268+} __do_const;
79269
79270 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
79271 extern void unregister_pppox_proto(int proto_num);
79272diff --git a/include/linux/init.h b/include/linux/init.h
79273index 8e68a64..3f977a0 100644
79274--- a/include/linux/init.h
79275+++ b/include/linux/init.h
79276@@ -37,9 +37,17 @@
79277 * section.
79278 */
79279
79280+#define add_init_latent_entropy __latent_entropy
79281+
79282+#ifdef CONFIG_MEMORY_HOTPLUG
79283+#define add_meminit_latent_entropy
79284+#else
79285+#define add_meminit_latent_entropy __latent_entropy
79286+#endif
79287+
79288 /* These are for everybody (although not all archs will actually
79289 discard it in modules) */
79290-#define __init __section(.init.text) __cold notrace
79291+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
79292 #define __initdata __section(.init.data)
79293 #define __initconst __constsection(.init.rodata)
79294 #define __exitdata __section(.exit.data)
79295@@ -100,7 +108,7 @@
79296 #define __cpuexitconst
79297
79298 /* Used for MEMORY_HOTPLUG */
79299-#define __meminit __section(.meminit.text) __cold notrace
79300+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
79301 #define __meminitdata __section(.meminit.data)
79302 #define __meminitconst __constsection(.meminit.rodata)
79303 #define __memexit __section(.memexit.text) __exitused __cold notrace
79304diff --git a/include/linux/init_task.h b/include/linux/init_task.h
79305index b0ed422..d79ea23 100644
79306--- a/include/linux/init_task.h
79307+++ b/include/linux/init_task.h
79308@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
79309
79310 #define INIT_TASK_COMM "swapper"
79311
79312+#ifdef CONFIG_X86
79313+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
79314+#else
79315+#define INIT_TASK_THREAD_INFO
79316+#endif
79317+
79318 /*
79319 * INIT_TASK is used to set up the first task table, touch at
79320 * your own risk!. Base=0, limit=0x1fffff (=2MB)
79321@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
79322 RCU_POINTER_INITIALIZER(cred, &init_cred), \
79323 .comm = INIT_TASK_COMM, \
79324 .thread = INIT_THREAD, \
79325+ INIT_TASK_THREAD_INFO \
79326 .fs = &init_fs, \
79327 .files = &init_files, \
79328 .signal = &init_signals, \
79329diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
79330index db43b58..5d5084b 100644
79331--- a/include/linux/interrupt.h
79332+++ b/include/linux/interrupt.h
79333@@ -360,7 +360,7 @@ enum
79334 /* map softirq index to softirq name. update 'softirq_to_name' in
79335 * kernel/softirq.c when adding a new softirq.
79336 */
79337-extern char *softirq_to_name[NR_SOFTIRQS];
79338+extern const char * const softirq_to_name[NR_SOFTIRQS];
79339
79340 /* softirq mask and active fields moved to irq_cpustat_t in
79341 * asm/hardirq.h to get better cache usage. KAO
79342@@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
79343
79344 struct softirq_action
79345 {
79346- void (*action)(struct softirq_action *);
79347-};
79348+ void (*action)(void);
79349+} __no_const;
79350
79351 asmlinkage void do_softirq(void);
79352 asmlinkage void __do_softirq(void);
79353@@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
79354 }
79355 #endif
79356
79357-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
79358+extern void open_softirq(int nr, void (*action)(void));
79359 extern void softirq_init(void);
79360 extern void __raise_softirq_irqoff(unsigned int nr);
79361
79362diff --git a/include/linux/iommu.h b/include/linux/iommu.h
79363index a444c79..8c41ea9 100644
79364--- a/include/linux/iommu.h
79365+++ b/include/linux/iommu.h
79366@@ -130,7 +130,7 @@ struct iommu_ops {
79367 u32 (*domain_get_windows)(struct iommu_domain *domain);
79368
79369 unsigned long pgsize_bitmap;
79370-};
79371+} __do_const;
79372
79373 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
79374 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
79375diff --git a/include/linux/ioport.h b/include/linux/ioport.h
79376index 89b7c24..382af74 100644
79377--- a/include/linux/ioport.h
79378+++ b/include/linux/ioport.h
79379@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
79380 int adjust_resource(struct resource *res, resource_size_t start,
79381 resource_size_t size);
79382 resource_size_t resource_alignment(struct resource *res);
79383-static inline resource_size_t resource_size(const struct resource *res)
79384+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
79385 {
79386 return res->end - res->start + 1;
79387 }
79388diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
79389index d6ad91f..f10f279 100644
79390--- a/include/linux/ipc_namespace.h
79391+++ b/include/linux/ipc_namespace.h
79392@@ -70,7 +70,7 @@ struct ipc_namespace {
79393 struct user_namespace *user_ns;
79394
79395 unsigned int proc_inum;
79396-};
79397+} __randomize_layout;
79398
79399 extern struct ipc_namespace init_ipc_ns;
79400 extern atomic_t nr_ipc_ns;
79401diff --git a/include/linux/irq.h b/include/linux/irq.h
79402index 7dc1003..407327b 100644
79403--- a/include/linux/irq.h
79404+++ b/include/linux/irq.h
79405@@ -338,7 +338,8 @@ struct irq_chip {
79406 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
79407
79408 unsigned long flags;
79409-};
79410+} __do_const;
79411+typedef struct irq_chip __no_const irq_chip_no_const;
79412
79413 /*
79414 * irq_chip specific flags
79415diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
79416index cac496b..ffa0567 100644
79417--- a/include/linux/irqchip/arm-gic.h
79418+++ b/include/linux/irqchip/arm-gic.h
79419@@ -61,9 +61,11 @@
79420
79421 #ifndef __ASSEMBLY__
79422
79423+#include <linux/irq.h>
79424+
79425 struct device_node;
79426
79427-extern struct irq_chip gic_arch_extn;
79428+extern irq_chip_no_const gic_arch_extn;
79429
79430 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
79431 u32 offset, struct device_node *);
79432diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
79433index d235e88..8ccbe74 100644
79434--- a/include/linux/jiffies.h
79435+++ b/include/linux/jiffies.h
79436@@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
79437 /*
79438 * Convert various time units to each other:
79439 */
79440-extern unsigned int jiffies_to_msecs(const unsigned long j);
79441-extern unsigned int jiffies_to_usecs(const unsigned long j);
79442-extern unsigned long msecs_to_jiffies(const unsigned int m);
79443-extern unsigned long usecs_to_jiffies(const unsigned int u);
79444-extern unsigned long timespec_to_jiffies(const struct timespec *value);
79445+extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
79446+extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
79447+extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
79448+extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
79449+extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
79450 extern void jiffies_to_timespec(const unsigned long jiffies,
79451 struct timespec *value);
79452-extern unsigned long timeval_to_jiffies(const struct timeval *value);
79453+extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
79454 extern void jiffies_to_timeval(const unsigned long jiffies,
79455 struct timeval *value);
79456
79457diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
79458index 6883e19..e854fcb 100644
79459--- a/include/linux/kallsyms.h
79460+++ b/include/linux/kallsyms.h
79461@@ -15,7 +15,8 @@
79462
79463 struct module;
79464
79465-#ifdef CONFIG_KALLSYMS
79466+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
79467+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
79468 /* Lookup the address for a symbol. Returns 0 if not found. */
79469 unsigned long kallsyms_lookup_name(const char *name);
79470
79471@@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
79472 /* Stupid that this does nothing, but I didn't create this mess. */
79473 #define __print_symbol(fmt, addr)
79474 #endif /*CONFIG_KALLSYMS*/
79475+#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
79476+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
79477+extern unsigned long kallsyms_lookup_name(const char *name);
79478+extern void __print_symbol(const char *fmt, unsigned long address);
79479+extern int sprint_backtrace(char *buffer, unsigned long address);
79480+extern int sprint_symbol(char *buffer, unsigned long address);
79481+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
79482+const char *kallsyms_lookup(unsigned long addr,
79483+ unsigned long *symbolsize,
79484+ unsigned long *offset,
79485+ char **modname, char *namebuf);
79486+extern int kallsyms_lookup_size_offset(unsigned long addr,
79487+ unsigned long *symbolsize,
79488+ unsigned long *offset);
79489+#endif
79490
79491 /* This macro allows us to keep printk typechecking */
79492 static __printf(1, 2)
79493diff --git a/include/linux/key-type.h b/include/linux/key-type.h
79494index a74c3a8..28d3f21 100644
79495--- a/include/linux/key-type.h
79496+++ b/include/linux/key-type.h
79497@@ -131,7 +131,7 @@ struct key_type {
79498 /* internal fields */
79499 struct list_head link; /* link in types list */
79500 struct lock_class_key lock_class; /* key->sem lock class */
79501-};
79502+} __do_const;
79503
79504 extern struct key_type key_type_keyring;
79505
79506diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
79507index dfb4f2f..7927e62 100644
79508--- a/include/linux/kgdb.h
79509+++ b/include/linux/kgdb.h
79510@@ -52,7 +52,7 @@ extern int kgdb_connected;
79511 extern int kgdb_io_module_registered;
79512
79513 extern atomic_t kgdb_setting_breakpoint;
79514-extern atomic_t kgdb_cpu_doing_single_step;
79515+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
79516
79517 extern struct task_struct *kgdb_usethread;
79518 extern struct task_struct *kgdb_contthread;
79519@@ -254,7 +254,7 @@ struct kgdb_arch {
79520 void (*correct_hw_break)(void);
79521
79522 void (*enable_nmi)(bool on);
79523-};
79524+} __do_const;
79525
79526 /**
79527 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
79528@@ -279,7 +279,7 @@ struct kgdb_io {
79529 void (*pre_exception) (void);
79530 void (*post_exception) (void);
79531 int is_console;
79532-};
79533+} __do_const;
79534
79535 extern struct kgdb_arch arch_kgdb_ops;
79536
79537diff --git a/include/linux/kmod.h b/include/linux/kmod.h
79538index 0555cc6..40116ce 100644
79539--- a/include/linux/kmod.h
79540+++ b/include/linux/kmod.h
79541@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
79542 * usually useless though. */
79543 extern __printf(2, 3)
79544 int __request_module(bool wait, const char *name, ...);
79545+extern __printf(3, 4)
79546+int ___request_module(bool wait, char *param_name, const char *name, ...);
79547 #define request_module(mod...) __request_module(true, mod)
79548 #define request_module_nowait(mod...) __request_module(false, mod)
79549 #define try_then_request_module(x, mod...) \
79550@@ -57,6 +59,9 @@ struct subprocess_info {
79551 struct work_struct work;
79552 struct completion *complete;
79553 char *path;
79554+#ifdef CONFIG_GRKERNSEC
79555+ char *origpath;
79556+#endif
79557 char **argv;
79558 char **envp;
79559 int wait;
79560diff --git a/include/linux/kobject.h b/include/linux/kobject.h
79561index e7ba650..0af3acb 100644
79562--- a/include/linux/kobject.h
79563+++ b/include/linux/kobject.h
79564@@ -116,7 +116,7 @@ struct kobj_type {
79565 struct attribute **default_attrs;
79566 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
79567 const void *(*namespace)(struct kobject *kobj);
79568-};
79569+} __do_const;
79570
79571 struct kobj_uevent_env {
79572 char *envp[UEVENT_NUM_ENVP];
79573@@ -139,6 +139,7 @@ struct kobj_attribute {
79574 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
79575 const char *buf, size_t count);
79576 };
79577+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
79578
79579 extern const struct sysfs_ops kobj_sysfs_ops;
79580
79581@@ -166,7 +167,7 @@ struct kset {
79582 spinlock_t list_lock;
79583 struct kobject kobj;
79584 const struct kset_uevent_ops *uevent_ops;
79585-};
79586+} __randomize_layout;
79587
79588 extern void kset_init(struct kset *kset);
79589 extern int __must_check kset_register(struct kset *kset);
79590diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
79591index df32d25..fb52e27 100644
79592--- a/include/linux/kobject_ns.h
79593+++ b/include/linux/kobject_ns.h
79594@@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
79595 const void *(*netlink_ns)(struct sock *sk);
79596 const void *(*initial_ns)(void);
79597 void (*drop_ns)(void *);
79598-};
79599+} __do_const;
79600
79601 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
79602 int kobj_ns_type_registered(enum kobj_ns_type type);
79603diff --git a/include/linux/kref.h b/include/linux/kref.h
79604index 484604d..0f6c5b6 100644
79605--- a/include/linux/kref.h
79606+++ b/include/linux/kref.h
79607@@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
79608 static inline int kref_sub(struct kref *kref, unsigned int count,
79609 void (*release)(struct kref *kref))
79610 {
79611- WARN_ON(release == NULL);
79612+ BUG_ON(release == NULL);
79613
79614 if (atomic_sub_and_test((int) count, &kref->refcount)) {
79615 release(kref);
79616diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
79617index 9523d2a..16c0424 100644
79618--- a/include/linux/kvm_host.h
79619+++ b/include/linux/kvm_host.h
79620@@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
79621 {
79622 }
79623 #endif
79624-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79625+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
79626 struct module *module);
79627 void kvm_exit(void);
79628
79629@@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
79630 struct kvm_guest_debug *dbg);
79631 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
79632
79633-int kvm_arch_init(void *opaque);
79634+int kvm_arch_init(const void *opaque);
79635 void kvm_arch_exit(void);
79636
79637 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
79638diff --git a/include/linux/libata.h b/include/linux/libata.h
79639index bec6dbe..2873d64 100644
79640--- a/include/linux/libata.h
79641+++ b/include/linux/libata.h
79642@@ -975,7 +975,7 @@ struct ata_port_operations {
79643 * fields must be pointers.
79644 */
79645 const struct ata_port_operations *inherits;
79646-};
79647+} __do_const;
79648
79649 struct ata_port_info {
79650 unsigned long flags;
79651diff --git a/include/linux/linkage.h b/include/linux/linkage.h
79652index d3e8ad2..a949f68 100644
79653--- a/include/linux/linkage.h
79654+++ b/include/linux/linkage.h
79655@@ -31,6 +31,7 @@
79656 #endif
79657
79658 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
79659+#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
79660 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
79661
79662 /*
79663diff --git a/include/linux/list.h b/include/linux/list.h
79664index ef95941..82db65a 100644
79665--- a/include/linux/list.h
79666+++ b/include/linux/list.h
79667@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
79668 extern void list_del(struct list_head *entry);
79669 #endif
79670
79671+extern void __pax_list_add(struct list_head *new,
79672+ struct list_head *prev,
79673+ struct list_head *next);
79674+static inline void pax_list_add(struct list_head *new, struct list_head *head)
79675+{
79676+ __pax_list_add(new, head, head->next);
79677+}
79678+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
79679+{
79680+ __pax_list_add(new, head->prev, head);
79681+}
79682+extern void pax_list_del(struct list_head *entry);
79683+
79684 /**
79685 * list_replace - replace old entry by new one
79686 * @old : the element to be replaced
79687@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
79688 INIT_LIST_HEAD(entry);
79689 }
79690
79691+extern void pax_list_del_init(struct list_head *entry);
79692+
79693 /**
79694 * list_move - delete from one list and add as another's head
79695 * @list: the entry to move
79696diff --git a/include/linux/math64.h b/include/linux/math64.h
79697index c45c089..298841c 100644
79698--- a/include/linux/math64.h
79699+++ b/include/linux/math64.h
79700@@ -15,7 +15,7 @@
79701 * This is commonly provided by 32bit archs to provide an optimized 64bit
79702 * divide.
79703 */
79704-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79705+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79706 {
79707 *remainder = dividend % divisor;
79708 return dividend / divisor;
79709@@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
79710 /**
79711 * div64_u64 - unsigned 64bit divide with 64bit divisor
79712 */
79713-static inline u64 div64_u64(u64 dividend, u64 divisor)
79714+static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
79715 {
79716 return dividend / divisor;
79717 }
79718@@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
79719 #define div64_ul(x, y) div_u64((x), (y))
79720
79721 #ifndef div_u64_rem
79722-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79723+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
79724 {
79725 *remainder = do_div(dividend, divisor);
79726 return dividend;
79727@@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
79728 #endif
79729
79730 #ifndef div64_u64
79731-extern u64 div64_u64(u64 dividend, u64 divisor);
79732+extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
79733 #endif
79734
79735 #ifndef div64_s64
79736@@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
79737 * divide.
79738 */
79739 #ifndef div_u64
79740-static inline u64 div_u64(u64 dividend, u32 divisor)
79741+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
79742 {
79743 u32 remainder;
79744 return div_u64_rem(dividend, divisor, &remainder);
79745diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
79746index 9fe426b..8148be6 100644
79747--- a/include/linux/mempolicy.h
79748+++ b/include/linux/mempolicy.h
79749@@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
79750 }
79751
79752 #define vma_policy(vma) ((vma)->vm_policy)
79753+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79754+{
79755+ vma->vm_policy = pol;
79756+}
79757
79758 static inline void mpol_get(struct mempolicy *pol)
79759 {
79760@@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
79761 }
79762
79763 #define vma_policy(vma) NULL
79764+static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
79765+{
79766+}
79767
79768 static inline int
79769 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
79770diff --git a/include/linux/mm.h b/include/linux/mm.h
79771index 5360b82..4eedf45 100644
79772--- a/include/linux/mm.h
79773+++ b/include/linux/mm.h
79774@@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
79775 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
79776 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
79777 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
79778+
79779+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
79780+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
79781+#endif
79782+
79783 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
79784
79785 #ifdef CONFIG_MEM_SOFT_DIRTY
79786@@ -219,8 +224,8 @@ struct vm_operations_struct {
79787 /* called by access_process_vm when get_user_pages() fails, typically
79788 * for use by special VMAs that can switch between memory and hardware
79789 */
79790- int (*access)(struct vm_area_struct *vma, unsigned long addr,
79791- void *buf, int len, int write);
79792+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
79793+ void *buf, size_t len, int write);
79794 #ifdef CONFIG_NUMA
79795 /*
79796 * set_policy() op must add a reference to any non-NULL @new mempolicy
79797@@ -250,6 +255,7 @@ struct vm_operations_struct {
79798 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
79799 unsigned long size, pgoff_t pgoff);
79800 };
79801+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
79802
79803 struct mmu_gather;
79804 struct inode;
79805@@ -1074,8 +1080,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
79806 unsigned long *pfn);
79807 int follow_phys(struct vm_area_struct *vma, unsigned long address,
79808 unsigned int flags, unsigned long *prot, resource_size_t *phys);
79809-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79810- void *buf, int len, int write);
79811+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
79812+ void *buf, size_t len, int write);
79813
79814 static inline void unmap_shared_mapping_range(struct address_space *mapping,
79815 loff_t const holebegin, loff_t const holelen)
79816@@ -1114,9 +1120,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
79817 }
79818 #endif
79819
79820-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
79821-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
79822- void *buf, int len, int write);
79823+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
79824+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
79825+ void *buf, size_t len, int write);
79826
79827 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79828 unsigned long start, unsigned long nr_pages,
79829@@ -1148,34 +1154,6 @@ int set_page_dirty(struct page *page);
79830 int set_page_dirty_lock(struct page *page);
79831 int clear_page_dirty_for_io(struct page *page);
79832
79833-/* Is the vma a continuation of the stack vma above it? */
79834-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
79835-{
79836- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
79837-}
79838-
79839-static inline int stack_guard_page_start(struct vm_area_struct *vma,
79840- unsigned long addr)
79841-{
79842- return (vma->vm_flags & VM_GROWSDOWN) &&
79843- (vma->vm_start == addr) &&
79844- !vma_growsdown(vma->vm_prev, addr);
79845-}
79846-
79847-/* Is the vma a continuation of the stack vma below it? */
79848-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
79849-{
79850- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
79851-}
79852-
79853-static inline int stack_guard_page_end(struct vm_area_struct *vma,
79854- unsigned long addr)
79855-{
79856- return (vma->vm_flags & VM_GROWSUP) &&
79857- (vma->vm_end == addr) &&
79858- !vma_growsup(vma->vm_next, addr);
79859-}
79860-
79861 extern pid_t
79862 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
79863
79864@@ -1275,6 +1253,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
79865 }
79866 #endif
79867
79868+#ifdef CONFIG_MMU
79869+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
79870+#else
79871+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
79872+{
79873+ return __pgprot(0);
79874+}
79875+#endif
79876+
79877 int vma_wants_writenotify(struct vm_area_struct *vma);
79878
79879 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
79880@@ -1293,8 +1280,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
79881 {
79882 return 0;
79883 }
79884+
79885+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
79886+ unsigned long address)
79887+{
79888+ return 0;
79889+}
79890 #else
79891 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79892+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
79893 #endif
79894
79895 #ifdef __PAGETABLE_PMD_FOLDED
79896@@ -1303,8 +1297,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
79897 {
79898 return 0;
79899 }
79900+
79901+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
79902+ unsigned long address)
79903+{
79904+ return 0;
79905+}
79906 #else
79907 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79908+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79909 #endif
79910
79911 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79912@@ -1322,11 +1323,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79913 NULL: pud_offset(pgd, address);
79914 }
79915
79916+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79917+{
79918+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79919+ NULL: pud_offset(pgd, address);
79920+}
79921+
79922 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79923 {
79924 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79925 NULL: pmd_offset(pud, address);
79926 }
79927+
79928+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79929+{
79930+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79931+ NULL: pmd_offset(pud, address);
79932+}
79933 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79934
79935 #if USE_SPLIT_PTE_PTLOCKS
79936@@ -1704,7 +1717,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79937 unsigned long addr, unsigned long len,
79938 unsigned long flags, struct page **pages);
79939
79940-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79941+extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79942
79943 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79944 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79945@@ -1712,6 +1725,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79946 unsigned long len, unsigned long prot, unsigned long flags,
79947 unsigned long pgoff, unsigned long *populate);
79948 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79949+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79950
79951 #ifdef CONFIG_MMU
79952 extern int __mm_populate(unsigned long addr, unsigned long len,
79953@@ -1740,10 +1754,11 @@ struct vm_unmapped_area_info {
79954 unsigned long high_limit;
79955 unsigned long align_mask;
79956 unsigned long align_offset;
79957+ unsigned long threadstack_offset;
79958 };
79959
79960-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79961-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79962+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79963+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79964
79965 /*
79966 * Search for an unmapped address range.
79967@@ -1755,7 +1770,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79968 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79969 */
79970 static inline unsigned long
79971-vm_unmapped_area(struct vm_unmapped_area_info *info)
79972+vm_unmapped_area(const struct vm_unmapped_area_info *info)
79973 {
79974 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79975 return unmapped_area(info);
79976@@ -1818,6 +1833,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79977 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79978 struct vm_area_struct **pprev);
79979
79980+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79981+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79982+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79983+
79984 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79985 NULL if none. Assume start_addr < end_addr. */
79986 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79987@@ -1846,15 +1865,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79988 return vma;
79989 }
79990
79991-#ifdef CONFIG_MMU
79992-pgprot_t vm_get_page_prot(unsigned long vm_flags);
79993-#else
79994-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79995-{
79996- return __pgprot(0);
79997-}
79998-#endif
79999-
80000 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
80001 unsigned long change_prot_numa(struct vm_area_struct *vma,
80002 unsigned long start, unsigned long end);
80003@@ -1906,6 +1916,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80004 static inline void vm_stat_account(struct mm_struct *mm,
80005 unsigned long flags, struct file *file, long pages)
80006 {
80007+
80008+#ifdef CONFIG_PAX_RANDMMAP
80009+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80010+#endif
80011+
80012 mm->total_vm += pages;
80013 }
80014 #endif /* CONFIG_PROC_FS */
80015@@ -1987,7 +2002,7 @@ extern int unpoison_memory(unsigned long pfn);
80016 extern int sysctl_memory_failure_early_kill;
80017 extern int sysctl_memory_failure_recovery;
80018 extern void shake_page(struct page *p, int access);
80019-extern atomic_long_t num_poisoned_pages;
80020+extern atomic_long_unchecked_t num_poisoned_pages;
80021 extern int soft_offline_page(struct page *page, int flags);
80022
80023 extern void dump_page(struct page *page);
80024@@ -2024,5 +2039,11 @@ void __init setup_nr_node_ids(void);
80025 static inline void setup_nr_node_ids(void) {}
80026 #endif
80027
80028+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80029+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80030+#else
80031+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80032+#endif
80033+
80034 #endif /* __KERNEL__ */
80035 #endif /* _LINUX_MM_H */
80036diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80037index 290901a..e99b01c 100644
80038--- a/include/linux/mm_types.h
80039+++ b/include/linux/mm_types.h
80040@@ -307,7 +307,9 @@ struct vm_area_struct {
80041 #ifdef CONFIG_NUMA
80042 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80043 #endif
80044-};
80045+
80046+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80047+} __randomize_layout;
80048
80049 struct core_thread {
80050 struct task_struct *task;
80051@@ -453,7 +455,25 @@ struct mm_struct {
80052 bool tlb_flush_pending;
80053 #endif
80054 struct uprobes_state uprobes_state;
80055-};
80056+
80057+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80058+ unsigned long pax_flags;
80059+#endif
80060+
80061+#ifdef CONFIG_PAX_DLRESOLVE
80062+ unsigned long call_dl_resolve;
80063+#endif
80064+
80065+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80066+ unsigned long call_syscall;
80067+#endif
80068+
80069+#ifdef CONFIG_PAX_ASLR
80070+ unsigned long delta_mmap; /* randomized offset */
80071+ unsigned long delta_stack; /* randomized offset */
80072+#endif
80073+
80074+} __randomize_layout;
80075
80076 static inline void mm_init_cpumask(struct mm_struct *mm)
80077 {
80078diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80079index c5d5278..f0b68c8 100644
80080--- a/include/linux/mmiotrace.h
80081+++ b/include/linux/mmiotrace.h
80082@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80083 /* Called from ioremap.c */
80084 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80085 void __iomem *addr);
80086-extern void mmiotrace_iounmap(volatile void __iomem *addr);
80087+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80088
80089 /* For anyone to insert markers. Remember trailing newline. */
80090 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80091@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80092 {
80093 }
80094
80095-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80096+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80097 {
80098 }
80099
80100diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80101index bd791e4..8617c34f 100644
80102--- a/include/linux/mmzone.h
80103+++ b/include/linux/mmzone.h
80104@@ -396,7 +396,7 @@ struct zone {
80105 unsigned long flags; /* zone flags, see below */
80106
80107 /* Zone statistics */
80108- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80109+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80110
80111 /*
80112 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80113diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80114index 45e9214..a7227d6 100644
80115--- a/include/linux/mod_devicetable.h
80116+++ b/include/linux/mod_devicetable.h
80117@@ -13,7 +13,7 @@
80118 typedef unsigned long kernel_ulong_t;
80119 #endif
80120
80121-#define PCI_ANY_ID (~0)
80122+#define PCI_ANY_ID ((__u16)~0)
80123
80124 struct pci_device_id {
80125 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
80126@@ -139,7 +139,7 @@ struct usb_device_id {
80127 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80128 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80129
80130-#define HID_ANY_ID (~0)
80131+#define HID_ANY_ID (~0U)
80132 #define HID_BUS_ANY 0xffff
80133 #define HID_GROUP_ANY 0x0000
80134
80135@@ -467,7 +467,7 @@ struct dmi_system_id {
80136 const char *ident;
80137 struct dmi_strmatch matches[4];
80138 void *driver_data;
80139-};
80140+} __do_const;
80141 /*
80142 * struct dmi_device_id appears during expansion of
80143 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80144diff --git a/include/linux/module.h b/include/linux/module.h
80145index 15cd6b1..f6e2e6a 100644
80146--- a/include/linux/module.h
80147+++ b/include/linux/module.h
80148@@ -17,9 +17,11 @@
80149 #include <linux/moduleparam.h>
80150 #include <linux/tracepoint.h>
80151 #include <linux/export.h>
80152+#include <linux/fs.h>
80153
80154 #include <linux/percpu.h>
80155 #include <asm/module.h>
80156+#include <asm/pgtable.h>
80157
80158 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80159 #define MODULE_SIG_STRING "~Module signature appended~\n"
80160@@ -43,7 +45,7 @@ struct module_kobject {
80161 struct kobject *drivers_dir;
80162 struct module_param_attrs *mp;
80163 struct completion *kobj_completion;
80164-};
80165+} __randomize_layout;
80166
80167 struct module_attribute {
80168 struct attribute attr;
80169@@ -55,12 +57,13 @@ struct module_attribute {
80170 int (*test)(struct module *);
80171 void (*free)(struct module *);
80172 };
80173+typedef struct module_attribute __no_const module_attribute_no_const;
80174
80175 struct module_version_attribute {
80176 struct module_attribute mattr;
80177 const char *module_name;
80178 const char *version;
80179-} __attribute__ ((__aligned__(sizeof(void *))));
80180+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80181
80182 extern ssize_t __modver_version_show(struct module_attribute *,
80183 struct module_kobject *, char *);
80184@@ -238,7 +241,7 @@ struct module
80185
80186 /* Sysfs stuff. */
80187 struct module_kobject mkobj;
80188- struct module_attribute *modinfo_attrs;
80189+ module_attribute_no_const *modinfo_attrs;
80190 const char *version;
80191 const char *srcversion;
80192 struct kobject *holders_dir;
80193@@ -287,19 +290,16 @@ struct module
80194 int (*init)(void);
80195
80196 /* If this is non-NULL, vfree after init() returns */
80197- void *module_init;
80198+ void *module_init_rx, *module_init_rw;
80199
80200 /* Here is the actual code + data, vfree'd on unload. */
80201- void *module_core;
80202+ void *module_core_rx, *module_core_rw;
80203
80204 /* Here are the sizes of the init and core sections */
80205- unsigned int init_size, core_size;
80206+ unsigned int init_size_rw, core_size_rw;
80207
80208 /* The size of the executable code in each section. */
80209- unsigned int init_text_size, core_text_size;
80210-
80211- /* Size of RO sections of the module (text+rodata) */
80212- unsigned int init_ro_size, core_ro_size;
80213+ unsigned int init_size_rx, core_size_rx;
80214
80215 /* Arch-specific module values */
80216 struct mod_arch_specific arch;
80217@@ -355,6 +355,10 @@ struct module
80218 #ifdef CONFIG_EVENT_TRACING
80219 struct ftrace_event_call **trace_events;
80220 unsigned int num_trace_events;
80221+ struct file_operations trace_id;
80222+ struct file_operations trace_enable;
80223+ struct file_operations trace_format;
80224+ struct file_operations trace_filter;
80225 #endif
80226 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
80227 unsigned int num_ftrace_callsites;
80228@@ -378,7 +382,7 @@ struct module
80229 ctor_fn_t *ctors;
80230 unsigned int num_ctors;
80231 #endif
80232-};
80233+} __randomize_layout;
80234 #ifndef MODULE_ARCH_INIT
80235 #define MODULE_ARCH_INIT {}
80236 #endif
80237@@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
80238 bool is_module_percpu_address(unsigned long addr);
80239 bool is_module_text_address(unsigned long addr);
80240
80241+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
80242+{
80243+
80244+#ifdef CONFIG_PAX_KERNEXEC
80245+ if (ktla_ktva(addr) >= (unsigned long)start &&
80246+ ktla_ktva(addr) < (unsigned long)start + size)
80247+ return 1;
80248+#endif
80249+
80250+ return ((void *)addr >= start && (void *)addr < start + size);
80251+}
80252+
80253+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
80254+{
80255+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
80256+}
80257+
80258+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
80259+{
80260+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
80261+}
80262+
80263+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
80264+{
80265+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
80266+}
80267+
80268+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
80269+{
80270+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
80271+}
80272+
80273 static inline int within_module_core(unsigned long addr, const struct module *mod)
80274 {
80275- return (unsigned long)mod->module_core <= addr &&
80276- addr < (unsigned long)mod->module_core + mod->core_size;
80277+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
80278 }
80279
80280 static inline int within_module_init(unsigned long addr, const struct module *mod)
80281 {
80282- return (unsigned long)mod->module_init <= addr &&
80283- addr < (unsigned long)mod->module_init + mod->init_size;
80284+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
80285 }
80286
80287 /* Search for module by name: must hold module_mutex. */
80288diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
80289index 560ca53..ef621ef 100644
80290--- a/include/linux/moduleloader.h
80291+++ b/include/linux/moduleloader.h
80292@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
80293 sections. Returns NULL on failure. */
80294 void *module_alloc(unsigned long size);
80295
80296+#ifdef CONFIG_PAX_KERNEXEC
80297+void *module_alloc_exec(unsigned long size);
80298+#else
80299+#define module_alloc_exec(x) module_alloc(x)
80300+#endif
80301+
80302 /* Free memory returned from module_alloc. */
80303 void module_free(struct module *mod, void *module_region);
80304
80305+#ifdef CONFIG_PAX_KERNEXEC
80306+void module_free_exec(struct module *mod, void *module_region);
80307+#else
80308+#define module_free_exec(x, y) module_free((x), (y))
80309+#endif
80310+
80311 /*
80312 * Apply the given relocation to the (simplified) ELF. Return -error
80313 * or 0.
80314@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
80315 unsigned int relsec,
80316 struct module *me)
80317 {
80318+#ifdef CONFIG_MODULES
80319 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80320+#endif
80321 return -ENOEXEC;
80322 }
80323 #endif
80324@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
80325 unsigned int relsec,
80326 struct module *me)
80327 {
80328+#ifdef CONFIG_MODULES
80329 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
80330+#endif
80331 return -ENOEXEC;
80332 }
80333 #endif
80334diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
80335index c3eb102..073c4a6 100644
80336--- a/include/linux/moduleparam.h
80337+++ b/include/linux/moduleparam.h
80338@@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
80339 * @len is usually just sizeof(string).
80340 */
80341 #define module_param_string(name, string, len, perm) \
80342- static const struct kparam_string __param_string_##name \
80343+ static const struct kparam_string __param_string_##name __used \
80344 = { len, string }; \
80345 __module_param_call(MODULE_PARAM_PREFIX, name, \
80346 &param_ops_string, \
80347@@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
80348 */
80349 #define module_param_array_named(name, array, type, nump, perm) \
80350 param_check_##type(name, &(array)[0]); \
80351- static const struct kparam_array __param_arr_##name \
80352+ static const struct kparam_array __param_arr_##name __used \
80353 = { .max = ARRAY_SIZE(array), .num = nump, \
80354 .ops = &param_ops_##type, \
80355 .elemsize = sizeof(array[0]), .elem = array }; \
80356diff --git a/include/linux/mount.h b/include/linux/mount.h
80357index 371d346..fba2819 100644
80358--- a/include/linux/mount.h
80359+++ b/include/linux/mount.h
80360@@ -56,7 +56,7 @@ struct vfsmount {
80361 struct dentry *mnt_root; /* root of the mounted tree */
80362 struct super_block *mnt_sb; /* pointer to superblock */
80363 int mnt_flags;
80364-};
80365+} __randomize_layout;
80366
80367 struct file; /* forward dec */
80368
80369diff --git a/include/linux/namei.h b/include/linux/namei.h
80370index 492de72..1bddcd4 100644
80371--- a/include/linux/namei.h
80372+++ b/include/linux/namei.h
80373@@ -19,7 +19,7 @@ struct nameidata {
80374 unsigned seq, m_seq;
80375 int last_type;
80376 unsigned depth;
80377- char *saved_names[MAX_NESTED_LINKS + 1];
80378+ const char *saved_names[MAX_NESTED_LINKS + 1];
80379 };
80380
80381 /*
80382@@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
80383
80384 extern void nd_jump_link(struct nameidata *nd, struct path *path);
80385
80386-static inline void nd_set_link(struct nameidata *nd, char *path)
80387+static inline void nd_set_link(struct nameidata *nd, const char *path)
80388 {
80389 nd->saved_names[nd->depth] = path;
80390 }
80391
80392-static inline char *nd_get_link(struct nameidata *nd)
80393+static inline const char *nd_get_link(const struct nameidata *nd)
80394 {
80395 return nd->saved_names[nd->depth];
80396 }
80397diff --git a/include/linux/net.h b/include/linux/net.h
80398index 69be3e6..0fb422d 100644
80399--- a/include/linux/net.h
80400+++ b/include/linux/net.h
80401@@ -192,7 +192,7 @@ struct net_proto_family {
80402 int (*create)(struct net *net, struct socket *sock,
80403 int protocol, int kern);
80404 struct module *owner;
80405-};
80406+} __do_const;
80407
80408 struct iovec;
80409 struct kvec;
80410diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
80411index 2177a6b..67fc561 100644
80412--- a/include/linux/netdevice.h
80413+++ b/include/linux/netdevice.h
80414@@ -1129,6 +1129,7 @@ struct net_device_ops {
80415 struct net_device *dev,
80416 void *priv);
80417 };
80418+typedef struct net_device_ops __no_const net_device_ops_no_const;
80419
80420 /*
80421 * The DEVICE structure.
80422@@ -1211,7 +1212,7 @@ struct net_device {
80423 int iflink;
80424
80425 struct net_device_stats stats;
80426- atomic_long_t rx_dropped; /* dropped packets by core network
80427+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
80428 * Do not use this in drivers.
80429 */
80430
80431diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
80432index 2077489..a15e561 100644
80433--- a/include/linux/netfilter.h
80434+++ b/include/linux/netfilter.h
80435@@ -84,7 +84,7 @@ struct nf_sockopt_ops {
80436 #endif
80437 /* Use the module struct to lock set/get code in place */
80438 struct module *owner;
80439-};
80440+} __do_const;
80441
80442 /* Function to register/unregister hook points. */
80443 int nf_register_hook(struct nf_hook_ops *reg);
80444diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
80445index 28c7436..2d6156a 100644
80446--- a/include/linux/netfilter/nfnetlink.h
80447+++ b/include/linux/netfilter/nfnetlink.h
80448@@ -19,7 +19,7 @@ struct nfnl_callback {
80449 const struct nlattr * const cda[]);
80450 const struct nla_policy *policy; /* netlink attribute policy */
80451 const u_int16_t attr_count; /* number of nlattr's */
80452-};
80453+} __do_const;
80454
80455 struct nfnetlink_subsystem {
80456 const char *name;
80457diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
80458new file mode 100644
80459index 0000000..33f4af8
80460--- /dev/null
80461+++ b/include/linux/netfilter/xt_gradm.h
80462@@ -0,0 +1,9 @@
80463+#ifndef _LINUX_NETFILTER_XT_GRADM_H
80464+#define _LINUX_NETFILTER_XT_GRADM_H 1
80465+
80466+struct xt_gradm_mtinfo {
80467+ __u16 flags;
80468+ __u16 invflags;
80469+};
80470+
80471+#endif
80472diff --git a/include/linux/nls.h b/include/linux/nls.h
80473index 5dc635f..35f5e11 100644
80474--- a/include/linux/nls.h
80475+++ b/include/linux/nls.h
80476@@ -31,7 +31,7 @@ struct nls_table {
80477 const unsigned char *charset2upper;
80478 struct module *owner;
80479 struct nls_table *next;
80480-};
80481+} __do_const;
80482
80483 /* this value hold the maximum octet of charset */
80484 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
80485diff --git a/include/linux/notifier.h b/include/linux/notifier.h
80486index d14a4c3..a078786 100644
80487--- a/include/linux/notifier.h
80488+++ b/include/linux/notifier.h
80489@@ -54,7 +54,8 @@ struct notifier_block {
80490 notifier_fn_t notifier_call;
80491 struct notifier_block __rcu *next;
80492 int priority;
80493-};
80494+} __do_const;
80495+typedef struct notifier_block __no_const notifier_block_no_const;
80496
80497 struct atomic_notifier_head {
80498 spinlock_t lock;
80499diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
80500index b2a0f15..4d7da32 100644
80501--- a/include/linux/oprofile.h
80502+++ b/include/linux/oprofile.h
80503@@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
80504 int oprofilefs_create_ro_ulong(struct dentry * root,
80505 char const * name, ulong * val);
80506
80507-/** Create a file for read-only access to an atomic_t. */
80508+/** Create a file for read-only access to an atomic_unchecked_t. */
80509 int oprofilefs_create_ro_atomic(struct dentry * root,
80510- char const * name, atomic_t * val);
80511+ char const * name, atomic_unchecked_t * val);
80512
80513 /** create a directory */
80514 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
80515diff --git a/include/linux/padata.h b/include/linux/padata.h
80516index 4386946..f50c615 100644
80517--- a/include/linux/padata.h
80518+++ b/include/linux/padata.h
80519@@ -129,7 +129,7 @@ struct parallel_data {
80520 struct padata_serial_queue __percpu *squeue;
80521 atomic_t reorder_objects;
80522 atomic_t refcnt;
80523- atomic_t seq_nr;
80524+ atomic_unchecked_t seq_nr;
80525 struct padata_cpumask cpumask;
80526 spinlock_t lock ____cacheline_aligned;
80527 unsigned int processed;
80528diff --git a/include/linux/path.h b/include/linux/path.h
80529index d137218..be0c176 100644
80530--- a/include/linux/path.h
80531+++ b/include/linux/path.h
80532@@ -1,13 +1,15 @@
80533 #ifndef _LINUX_PATH_H
80534 #define _LINUX_PATH_H
80535
80536+#include <linux/compiler.h>
80537+
80538 struct dentry;
80539 struct vfsmount;
80540
80541 struct path {
80542 struct vfsmount *mnt;
80543 struct dentry *dentry;
80544-};
80545+} __randomize_layout;
80546
80547 extern void path_get(const struct path *);
80548 extern void path_put(const struct path *);
80549diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
80550index a2e2f1d..8a391d2 100644
80551--- a/include/linux/pci_hotplug.h
80552+++ b/include/linux/pci_hotplug.h
80553@@ -71,7 +71,8 @@ struct hotplug_slot_ops {
80554 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
80555 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
80556 int (*reset_slot) (struct hotplug_slot *slot, int probe);
80557-};
80558+} __do_const;
80559+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
80560
80561 /**
80562 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
80563diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
80564index 2e069d1..27054b8 100644
80565--- a/include/linux/perf_event.h
80566+++ b/include/linux/perf_event.h
80567@@ -327,8 +327,8 @@ struct perf_event {
80568
80569 enum perf_event_active_state state;
80570 unsigned int attach_state;
80571- local64_t count;
80572- atomic64_t child_count;
80573+ local64_t count; /* PaX: fix it one day */
80574+ atomic64_unchecked_t child_count;
80575
80576 /*
80577 * These are the total time in nanoseconds that the event
80578@@ -379,8 +379,8 @@ struct perf_event {
80579 * These accumulate total time (in nanoseconds) that children
80580 * events have been enabled and running, respectively.
80581 */
80582- atomic64_t child_total_time_enabled;
80583- atomic64_t child_total_time_running;
80584+ atomic64_unchecked_t child_total_time_enabled;
80585+ atomic64_unchecked_t child_total_time_running;
80586
80587 /*
80588 * Protect attach/detach and child_list:
80589@@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
80590 entry->ip[entry->nr++] = ip;
80591 }
80592
80593-extern int sysctl_perf_event_paranoid;
80594+extern int sysctl_perf_event_legitimately_concerned;
80595 extern int sysctl_perf_event_mlock;
80596 extern int sysctl_perf_event_sample_rate;
80597 extern int sysctl_perf_cpu_time_max_percent;
80598@@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
80599 loff_t *ppos);
80600
80601
80602+static inline bool perf_paranoid_any(void)
80603+{
80604+ return sysctl_perf_event_legitimately_concerned > 2;
80605+}
80606+
80607 static inline bool perf_paranoid_tracepoint_raw(void)
80608 {
80609- return sysctl_perf_event_paranoid > -1;
80610+ return sysctl_perf_event_legitimately_concerned > -1;
80611 }
80612
80613 static inline bool perf_paranoid_cpu(void)
80614 {
80615- return sysctl_perf_event_paranoid > 0;
80616+ return sysctl_perf_event_legitimately_concerned > 0;
80617 }
80618
80619 static inline bool perf_paranoid_kernel(void)
80620 {
80621- return sysctl_perf_event_paranoid > 1;
80622+ return sysctl_perf_event_legitimately_concerned > 1;
80623 }
80624
80625 extern void perf_event_init(void);
80626@@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
80627 struct device_attribute attr;
80628 u64 id;
80629 const char *event_str;
80630-};
80631+} __do_const;
80632
80633 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
80634 static struct perf_pmu_events_attr _var = { \
80635diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
80636index 7246ef3..1539ea4 100644
80637--- a/include/linux/pid_namespace.h
80638+++ b/include/linux/pid_namespace.h
80639@@ -43,7 +43,7 @@ struct pid_namespace {
80640 int hide_pid;
80641 int reboot; /* group exit code if this pidns was rebooted */
80642 unsigned int proc_inum;
80643-};
80644+} __randomize_layout;
80645
80646 extern struct pid_namespace init_pid_ns;
80647
80648diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
80649index ab57526..94598804 100644
80650--- a/include/linux/pipe_fs_i.h
80651+++ b/include/linux/pipe_fs_i.h
80652@@ -47,10 +47,10 @@ struct pipe_inode_info {
80653 struct mutex mutex;
80654 wait_queue_head_t wait;
80655 unsigned int nrbufs, curbuf, buffers;
80656- unsigned int readers;
80657- unsigned int writers;
80658- unsigned int files;
80659- unsigned int waiting_writers;
80660+ atomic_t readers;
80661+ atomic_t writers;
80662+ atomic_t files;
80663+ atomic_t waiting_writers;
80664 unsigned int r_counter;
80665 unsigned int w_counter;
80666 struct page *tmp_page;
80667diff --git a/include/linux/pm.h b/include/linux/pm.h
80668index a224c7f..92d8a97 100644
80669--- a/include/linux/pm.h
80670+++ b/include/linux/pm.h
80671@@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
80672 struct dev_pm_domain {
80673 struct dev_pm_ops ops;
80674 };
80675+typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
80676
80677 /*
80678 * The PM_EVENT_ messages are also used by drivers implementing the legacy
80679diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
80680index 7c1d252..0e7061d 100644
80681--- a/include/linux/pm_domain.h
80682+++ b/include/linux/pm_domain.h
80683@@ -44,11 +44,11 @@ struct gpd_dev_ops {
80684 int (*thaw_early)(struct device *dev);
80685 int (*thaw)(struct device *dev);
80686 bool (*active_wakeup)(struct device *dev);
80687-};
80688+} __no_const;
80689
80690 struct gpd_cpu_data {
80691 unsigned int saved_exit_latency;
80692- struct cpuidle_state *idle_state;
80693+ cpuidle_state_no_const *idle_state;
80694 };
80695
80696 struct generic_pm_domain {
80697diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
80698index 6fa7cea..7bf6415 100644
80699--- a/include/linux/pm_runtime.h
80700+++ b/include/linux/pm_runtime.h
80701@@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
80702
80703 static inline void pm_runtime_mark_last_busy(struct device *dev)
80704 {
80705- ACCESS_ONCE(dev->power.last_busy) = jiffies;
80706+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
80707 }
80708
80709 #else /* !CONFIG_PM_RUNTIME */
80710diff --git a/include/linux/pnp.h b/include/linux/pnp.h
80711index 195aafc..49a7bc2 100644
80712--- a/include/linux/pnp.h
80713+++ b/include/linux/pnp.h
80714@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
80715 struct pnp_fixup {
80716 char id[7];
80717 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
80718-};
80719+} __do_const;
80720
80721 /* config parameters */
80722 #define PNP_CONFIG_NORMAL 0x0001
80723diff --git a/include/linux/poison.h b/include/linux/poison.h
80724index 2110a81..13a11bb 100644
80725--- a/include/linux/poison.h
80726+++ b/include/linux/poison.h
80727@@ -19,8 +19,8 @@
80728 * under normal circumstances, used to verify that nobody uses
80729 * non-initialized list entries.
80730 */
80731-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
80732-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
80733+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
80734+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
80735
80736 /********** include/linux/timer.h **********/
80737 /*
80738diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
80739index d8b187c3..9a9257a 100644
80740--- a/include/linux/power/smartreflex.h
80741+++ b/include/linux/power/smartreflex.h
80742@@ -238,7 +238,7 @@ struct omap_sr_class_data {
80743 int (*notify)(struct omap_sr *sr, u32 status);
80744 u8 notify_flags;
80745 u8 class_type;
80746-};
80747+} __do_const;
80748
80749 /**
80750 * struct omap_sr_nvalue_table - Smartreflex n-target value info
80751diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
80752index 4ea1d37..80f4b33 100644
80753--- a/include/linux/ppp-comp.h
80754+++ b/include/linux/ppp-comp.h
80755@@ -84,7 +84,7 @@ struct compressor {
80756 struct module *owner;
80757 /* Extra skb space needed by the compressor algorithm */
80758 unsigned int comp_extra;
80759-};
80760+} __do_const;
80761
80762 /*
80763 * The return value from decompress routine is the length of the
80764diff --git a/include/linux/preempt.h b/include/linux/preempt.h
80765index a3d9dc8..8af9922 100644
80766--- a/include/linux/preempt.h
80767+++ b/include/linux/preempt.h
80768@@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
80769 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
80770 #endif
80771
80772+#define raw_preempt_count_add(val) __preempt_count_add(val)
80773+#define raw_preempt_count_sub(val) __preempt_count_sub(val)
80774+
80775 #define __preempt_count_inc() __preempt_count_add(1)
80776 #define __preempt_count_dec() __preempt_count_sub(1)
80777
80778 #define preempt_count_inc() preempt_count_add(1)
80779+#define raw_preempt_count_inc() raw_preempt_count_add(1)
80780 #define preempt_count_dec() preempt_count_sub(1)
80781+#define raw_preempt_count_dec() raw_preempt_count_sub(1)
80782
80783 #ifdef CONFIG_PREEMPT_COUNT
80784
80785@@ -41,6 +46,12 @@ do { \
80786 barrier(); \
80787 } while (0)
80788
80789+#define raw_preempt_disable() \
80790+do { \
80791+ raw_preempt_count_inc(); \
80792+ barrier(); \
80793+} while (0)
80794+
80795 #define sched_preempt_enable_no_resched() \
80796 do { \
80797 barrier(); \
80798@@ -49,6 +60,12 @@ do { \
80799
80800 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
80801
80802+#define raw_preempt_enable_no_resched() \
80803+do { \
80804+ barrier(); \
80805+ raw_preempt_count_dec(); \
80806+} while (0)
80807+
80808 #ifdef CONFIG_PREEMPT
80809 #define preempt_enable() \
80810 do { \
80811@@ -105,8 +122,10 @@ do { \
80812 * region.
80813 */
80814 #define preempt_disable() barrier()
80815+#define raw_preempt_disable() barrier()
80816 #define sched_preempt_enable_no_resched() barrier()
80817 #define preempt_enable_no_resched() barrier()
80818+#define raw_preempt_enable_no_resched() barrier()
80819 #define preempt_enable() barrier()
80820 #define preempt_check_resched() do { } while (0)
80821
80822diff --git a/include/linux/printk.h b/include/linux/printk.h
80823index 6949258..7c4730e 100644
80824--- a/include/linux/printk.h
80825+++ b/include/linux/printk.h
80826@@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
80827 void early_printk(const char *s, ...) { }
80828 #endif
80829
80830+extern int kptr_restrict;
80831+
80832 #ifdef CONFIG_PRINTK
80833 asmlinkage __printf(5, 0)
80834 int vprintk_emit(int facility, int level,
80835@@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
80836
80837 extern int printk_delay_msec;
80838 extern int dmesg_restrict;
80839-extern int kptr_restrict;
80840
80841 extern void wake_up_klogd(void);
80842
80843diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
80844index 608e60a..c26f864 100644
80845--- a/include/linux/proc_fs.h
80846+++ b/include/linux/proc_fs.h
80847@@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
80848 return proc_create_data(name, mode, parent, proc_fops, NULL);
80849 }
80850
80851+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
80852+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
80853+{
80854+#ifdef CONFIG_GRKERNSEC_PROC_USER
80855+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
80856+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
80857+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
80858+#else
80859+ return proc_create_data(name, mode, parent, proc_fops, NULL);
80860+#endif
80861+}
80862+
80863+
80864 extern void proc_set_size(struct proc_dir_entry *, loff_t);
80865 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
80866 extern void *PDE_DATA(const struct inode *);
80867diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
80868index 34a1e10..70f6bde 100644
80869--- a/include/linux/proc_ns.h
80870+++ b/include/linux/proc_ns.h
80871@@ -14,7 +14,7 @@ struct proc_ns_operations {
80872 void (*put)(void *ns);
80873 int (*install)(struct nsproxy *nsproxy, void *ns);
80874 unsigned int (*inum)(void *ns);
80875-};
80876+} __do_const __randomize_layout;
80877
80878 struct proc_ns {
80879 void *ns;
80880diff --git a/include/linux/quota.h b/include/linux/quota.h
80881index cc7494a..1e27036 100644
80882--- a/include/linux/quota.h
80883+++ b/include/linux/quota.h
80884@@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
80885
80886 extern bool qid_eq(struct kqid left, struct kqid right);
80887 extern bool qid_lt(struct kqid left, struct kqid right);
80888-extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
80889+extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
80890 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
80891 extern bool qid_valid(struct kqid qid);
80892
80893diff --git a/include/linux/random.h b/include/linux/random.h
80894index 4002b3d..d5ad855 100644
80895--- a/include/linux/random.h
80896+++ b/include/linux/random.h
80897@@ -10,9 +10,19 @@
80898
80899
80900 extern void add_device_randomness(const void *, unsigned int);
80901+
80902+static inline void add_latent_entropy(void)
80903+{
80904+
80905+#ifdef LATENT_ENTROPY_PLUGIN
80906+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
80907+#endif
80908+
80909+}
80910+
80911 extern void add_input_randomness(unsigned int type, unsigned int code,
80912- unsigned int value);
80913-extern void add_interrupt_randomness(int irq, int irq_flags);
80914+ unsigned int value) __latent_entropy;
80915+extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
80916
80917 extern void get_random_bytes(void *buf, int nbytes);
80918 extern void get_random_bytes_arch(void *buf, int nbytes);
80919@@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
80920 extern const struct file_operations random_fops, urandom_fops;
80921 #endif
80922
80923-unsigned int get_random_int(void);
80924+unsigned int __intentional_overflow(-1) get_random_int(void);
80925 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
80926
80927-u32 prandom_u32(void);
80928+u32 prandom_u32(void) __intentional_overflow(-1);
80929 void prandom_bytes(void *buf, int nbytes);
80930 void prandom_seed(u32 seed);
80931 void prandom_reseed_late(void);
80932@@ -38,6 +48,11 @@ struct rnd_state {
80933 u32 prandom_u32_state(struct rnd_state *state);
80934 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80935
80936+static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80937+{
80938+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80939+}
80940+
80941 /*
80942 * Handle minimum values for seeds
80943 */
80944diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80945index fea49b5..2ac22bb 100644
80946--- a/include/linux/rbtree_augmented.h
80947+++ b/include/linux/rbtree_augmented.h
80948@@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80949 old->rbaugmented = rbcompute(old); \
80950 } \
80951 rbstatic const struct rb_augment_callbacks rbname = { \
80952- rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80953+ .propagate = rbname ## _propagate, \
80954+ .copy = rbname ## _copy, \
80955+ .rotate = rbname ## _rotate \
80956 };
80957
80958
80959diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80960index 45a0a9e..e83788e 100644
80961--- a/include/linux/rculist.h
80962+++ b/include/linux/rculist.h
80963@@ -29,8 +29,8 @@
80964 */
80965 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80966 {
80967- ACCESS_ONCE(list->next) = list;
80968- ACCESS_ONCE(list->prev) = list;
80969+ ACCESS_ONCE_RW(list->next) = list;
80970+ ACCESS_ONCE_RW(list->prev) = list;
80971 }
80972
80973 /*
80974@@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80975 struct list_head *prev, struct list_head *next);
80976 #endif
80977
80978+extern void __pax_list_add_rcu(struct list_head *new,
80979+ struct list_head *prev, struct list_head *next);
80980+
80981 /**
80982 * list_add_rcu - add a new entry to rcu-protected list
80983 * @new: new entry to be added
80984@@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80985 __list_add_rcu(new, head, head->next);
80986 }
80987
80988+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80989+{
80990+ __pax_list_add_rcu(new, head, head->next);
80991+}
80992+
80993 /**
80994 * list_add_tail_rcu - add a new entry to rcu-protected list
80995 * @new: new entry to be added
80996@@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80997 __list_add_rcu(new, head->prev, head);
80998 }
80999
81000+static inline void pax_list_add_tail_rcu(struct list_head *new,
81001+ struct list_head *head)
81002+{
81003+ __pax_list_add_rcu(new, head->prev, head);
81004+}
81005+
81006 /**
81007 * list_del_rcu - deletes entry from list without re-initialization
81008 * @entry: the element to delete from the list.
81009@@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81010 entry->prev = LIST_POISON2;
81011 }
81012
81013+extern void pax_list_del_rcu(struct list_head *entry);
81014+
81015 /**
81016 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81017 * @n: the element to delete from the hash list.
81018diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81019index 9e7db9e..7d4fd72 100644
81020--- a/include/linux/reboot.h
81021+++ b/include/linux/reboot.h
81022@@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81023 */
81024
81025 extern void migrate_to_reboot_cpu(void);
81026-extern void machine_restart(char *cmd);
81027-extern void machine_halt(void);
81028-extern void machine_power_off(void);
81029+extern void machine_restart(char *cmd) __noreturn;
81030+extern void machine_halt(void) __noreturn;
81031+extern void machine_power_off(void) __noreturn;
81032
81033 extern void machine_shutdown(void);
81034 struct pt_regs;
81035@@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81036 */
81037
81038 extern void kernel_restart_prepare(char *cmd);
81039-extern void kernel_restart(char *cmd);
81040-extern void kernel_halt(void);
81041-extern void kernel_power_off(void);
81042+extern void kernel_restart(char *cmd) __noreturn;
81043+extern void kernel_halt(void) __noreturn;
81044+extern void kernel_power_off(void) __noreturn;
81045
81046 extern int C_A_D; /* for sysctl */
81047 void ctrl_alt_del(void);
81048@@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81049 * Emergency restart, callable from an interrupt handler.
81050 */
81051
81052-extern void emergency_restart(void);
81053+extern void emergency_restart(void) __noreturn;
81054 #include <asm/emergency-restart.h>
81055
81056 #endif /* _LINUX_REBOOT_H */
81057diff --git a/include/linux/regset.h b/include/linux/regset.h
81058index 8e0c9fe..ac4d221 100644
81059--- a/include/linux/regset.h
81060+++ b/include/linux/regset.h
81061@@ -161,7 +161,8 @@ struct user_regset {
81062 unsigned int align;
81063 unsigned int bias;
81064 unsigned int core_note_type;
81065-};
81066+} __do_const;
81067+typedef struct user_regset __no_const user_regset_no_const;
81068
81069 /**
81070 * struct user_regset_view - available regsets
81071diff --git a/include/linux/relay.h b/include/linux/relay.h
81072index d7c8359..818daf5 100644
81073--- a/include/linux/relay.h
81074+++ b/include/linux/relay.h
81075@@ -157,7 +157,7 @@ struct rchan_callbacks
81076 * The callback should return 0 if successful, negative if not.
81077 */
81078 int (*remove_buf_file)(struct dentry *dentry);
81079-};
81080+} __no_const;
81081
81082 /*
81083 * CONFIG_RELAY kernel API, kernel/relay.c
81084diff --git a/include/linux/rio.h b/include/linux/rio.h
81085index b71d573..2f940bd 100644
81086--- a/include/linux/rio.h
81087+++ b/include/linux/rio.h
81088@@ -355,7 +355,7 @@ struct rio_ops {
81089 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81090 u64 rstart, u32 size, u32 flags);
81091 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81092-};
81093+} __no_const;
81094
81095 #define RIO_RESOURCE_MEM 0x00000100
81096 #define RIO_RESOURCE_DOORBELL 0x00000200
81097diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81098index 6dacb93..6174423 100644
81099--- a/include/linux/rmap.h
81100+++ b/include/linux/rmap.h
81101@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81102 void anon_vma_init(void); /* create anon_vma_cachep */
81103 int anon_vma_prepare(struct vm_area_struct *);
81104 void unlink_anon_vmas(struct vm_area_struct *);
81105-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81106-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81107+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81108+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81109
81110 static inline void anon_vma_merge(struct vm_area_struct *vma,
81111 struct vm_area_struct *next)
81112diff --git a/include/linux/sched.h b/include/linux/sched.h
81113index 53f97eb..1d90705 100644
81114--- a/include/linux/sched.h
81115+++ b/include/linux/sched.h
81116@@ -63,6 +63,7 @@ struct bio_list;
81117 struct fs_struct;
81118 struct perf_event_context;
81119 struct blk_plug;
81120+struct linux_binprm;
81121
81122 /*
81123 * List of flags we want to share for kernel threads,
81124@@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
81125 extern int in_sched_functions(unsigned long addr);
81126
81127 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81128-extern signed long schedule_timeout(signed long timeout);
81129+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81130 extern signed long schedule_timeout_interruptible(signed long timeout);
81131 extern signed long schedule_timeout_killable(signed long timeout);
81132 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81133@@ -315,6 +316,19 @@ struct nsproxy;
81134 struct user_namespace;
81135
81136 #ifdef CONFIG_MMU
81137+
81138+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81139+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81140+#else
81141+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81142+{
81143+ return 0;
81144+}
81145+#endif
81146+
81147+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
81148+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
81149+
81150 extern void arch_pick_mmap_layout(struct mm_struct *mm);
81151 extern unsigned long
81152 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
81153@@ -600,6 +614,17 @@ struct signal_struct {
81154 #ifdef CONFIG_TASKSTATS
81155 struct taskstats *stats;
81156 #endif
81157+
81158+#ifdef CONFIG_GRKERNSEC
81159+ u32 curr_ip;
81160+ u32 saved_ip;
81161+ u32 gr_saddr;
81162+ u32 gr_daddr;
81163+ u16 gr_sport;
81164+ u16 gr_dport;
81165+ u8 used_accept:1;
81166+#endif
81167+
81168 #ifdef CONFIG_AUDIT
81169 unsigned audit_tty;
81170 unsigned audit_tty_log_passwd;
81171@@ -626,7 +651,7 @@ struct signal_struct {
81172 struct mutex cred_guard_mutex; /* guard against foreign influences on
81173 * credential calculations
81174 * (notably. ptrace) */
81175-};
81176+} __randomize_layout;
81177
81178 /*
81179 * Bits in flags field of signal_struct.
81180@@ -680,6 +705,14 @@ struct user_struct {
81181 struct key *session_keyring; /* UID's default session keyring */
81182 #endif
81183
81184+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
81185+ unsigned char kernel_banned;
81186+#endif
81187+#ifdef CONFIG_GRKERNSEC_BRUTE
81188+ unsigned char suid_banned;
81189+ unsigned long suid_ban_expires;
81190+#endif
81191+
81192 /* Hash table maintenance information */
81193 struct hlist_node uidhash_node;
81194 kuid_t uid;
81195@@ -687,7 +720,7 @@ struct user_struct {
81196 #ifdef CONFIG_PERF_EVENTS
81197 atomic_long_t locked_vm;
81198 #endif
81199-};
81200+} __randomize_layout;
81201
81202 extern int uids_sysfs_init(void);
81203
81204@@ -1162,8 +1195,8 @@ struct task_struct {
81205 struct list_head thread_group;
81206
81207 struct completion *vfork_done; /* for vfork() */
81208- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
81209- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81210+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
81211+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
81212
81213 cputime_t utime, stime, utimescaled, stimescaled;
81214 cputime_t gtime;
81215@@ -1188,11 +1221,6 @@ struct task_struct {
81216 struct task_cputime cputime_expires;
81217 struct list_head cpu_timers[3];
81218
81219-/* process credentials */
81220- const struct cred __rcu *real_cred; /* objective and real subjective task
81221- * credentials (COW) */
81222- const struct cred __rcu *cred; /* effective (overridable) subjective task
81223- * credentials (COW) */
81224 char comm[TASK_COMM_LEN]; /* executable name excluding path
81225 - access with [gs]et_task_comm (which lock
81226 it with task_lock())
81227@@ -1209,6 +1237,10 @@ struct task_struct {
81228 #endif
81229 /* CPU-specific state of this task */
81230 struct thread_struct thread;
81231+/* thread_info moved to task_struct */
81232+#ifdef CONFIG_X86
81233+ struct thread_info tinfo;
81234+#endif
81235 /* filesystem information */
81236 struct fs_struct *fs;
81237 /* open file information */
81238@@ -1282,6 +1314,10 @@ struct task_struct {
81239 gfp_t lockdep_reclaim_gfp;
81240 #endif
81241
81242+/* process credentials */
81243+ const struct cred __rcu *real_cred; /* objective and real subjective task
81244+ * credentials (COW) */
81245+
81246 /* journalling filesystem info */
81247 void *journal_info;
81248
81249@@ -1320,6 +1356,10 @@ struct task_struct {
81250 /* cg_list protected by css_set_lock and tsk->alloc_lock */
81251 struct list_head cg_list;
81252 #endif
81253+
81254+ const struct cred __rcu *cred; /* effective (overridable) subjective task
81255+ * credentials (COW) */
81256+
81257 #ifdef CONFIG_FUTEX
81258 struct robust_list_head __user *robust_list;
81259 #ifdef CONFIG_COMPAT
81260@@ -1454,7 +1494,78 @@ struct task_struct {
81261 unsigned int sequential_io;
81262 unsigned int sequential_io_avg;
81263 #endif
81264-};
81265+
81266+#ifdef CONFIG_GRKERNSEC
81267+ /* grsecurity */
81268+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81269+ u64 exec_id;
81270+#endif
81271+#ifdef CONFIG_GRKERNSEC_SETXID
81272+ const struct cred *delayed_cred;
81273+#endif
81274+ struct dentry *gr_chroot_dentry;
81275+ struct acl_subject_label *acl;
81276+ struct acl_subject_label *tmpacl;
81277+ struct acl_role_label *role;
81278+ struct file *exec_file;
81279+ unsigned long brute_expires;
81280+ u16 acl_role_id;
81281+ u8 inherited;
81282+ /* is this the task that authenticated to the special role */
81283+ u8 acl_sp_role;
81284+ u8 is_writable;
81285+ u8 brute;
81286+ u8 gr_is_chrooted;
81287+#endif
81288+
81289+} __randomize_layout;
81290+
81291+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
81292+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
81293+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
81294+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
81295+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
81296+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
81297+
81298+#ifdef CONFIG_PAX_SOFTMODE
81299+extern int pax_softmode;
81300+#endif
81301+
81302+extern int pax_check_flags(unsigned long *);
81303+#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
81304+
81305+/* if tsk != current then task_lock must be held on it */
81306+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
81307+static inline unsigned long pax_get_flags(struct task_struct *tsk)
81308+{
81309+ if (likely(tsk->mm))
81310+ return tsk->mm->pax_flags;
81311+ else
81312+ return 0UL;
81313+}
81314+
81315+/* if tsk != current then task_lock must be held on it */
81316+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
81317+{
81318+ if (likely(tsk->mm)) {
81319+ tsk->mm->pax_flags = flags;
81320+ return 0;
81321+ }
81322+ return -EINVAL;
81323+}
81324+#endif
81325+
81326+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
81327+extern void pax_set_initial_flags(struct linux_binprm *bprm);
81328+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
81329+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
81330+#endif
81331+
81332+struct path;
81333+extern char *pax_get_path(const struct path *path, char *buf, int buflen);
81334+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
81335+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
81336+extern void pax_report_refcount_overflow(struct pt_regs *regs);
81337
81338 /* Future-safe accessor for struct task_struct's cpus_allowed. */
81339 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
81340@@ -1531,7 +1642,7 @@ struct pid_namespace;
81341 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
81342 struct pid_namespace *ns);
81343
81344-static inline pid_t task_pid_nr(struct task_struct *tsk)
81345+static inline pid_t task_pid_nr(const struct task_struct *tsk)
81346 {
81347 return tsk->pid;
81348 }
81349@@ -1981,7 +2092,9 @@ void yield(void);
81350 extern struct exec_domain default_exec_domain;
81351
81352 union thread_union {
81353+#ifndef CONFIG_X86
81354 struct thread_info thread_info;
81355+#endif
81356 unsigned long stack[THREAD_SIZE/sizeof(long)];
81357 };
81358
81359@@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
81360 */
81361
81362 extern struct task_struct *find_task_by_vpid(pid_t nr);
81363+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
81364 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
81365 struct pid_namespace *ns);
81366
81367@@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
81368 extern void exit_itimers(struct signal_struct *);
81369 extern void flush_itimer_signals(void);
81370
81371-extern void do_group_exit(int);
81372+extern __noreturn void do_group_exit(int);
81373
81374 extern int allow_signal(int);
81375 extern int disallow_signal(int);
81376@@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
81377
81378 #endif
81379
81380-static inline int object_is_on_stack(void *obj)
81381+static inline int object_starts_on_stack(void *obj)
81382 {
81383- void *stack = task_stack_page(current);
81384+ const void *stack = task_stack_page(current);
81385
81386 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
81387 }
81388diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
81389index e3347c5..f682891 100644
81390--- a/include/linux/sched/sysctl.h
81391+++ b/include/linux/sched/sysctl.h
81392@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
81393 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
81394
81395 extern int sysctl_max_map_count;
81396+extern unsigned long sysctl_heap_stack_gap;
81397
81398 extern unsigned int sysctl_sched_latency;
81399 extern unsigned int sysctl_sched_min_granularity;
81400diff --git a/include/linux/security.h b/include/linux/security.h
81401index 5623a7f..7ae77be 100644
81402--- a/include/linux/security.h
81403+++ b/include/linux/security.h
81404@@ -27,6 +27,7 @@
81405 #include <linux/slab.h>
81406 #include <linux/err.h>
81407 #include <linux/string.h>
81408+#include <linux/grsecurity.h>
81409
81410 struct linux_binprm;
81411 struct cred;
81412@@ -116,8 +117,6 @@ struct seq_file;
81413
81414 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
81415
81416-void reset_security_ops(void);
81417-
81418 #ifdef CONFIG_MMU
81419 extern unsigned long mmap_min_addr;
81420 extern unsigned long dac_mmap_min_addr;
81421@@ -1718,7 +1717,7 @@ struct security_operations {
81422 struct audit_context *actx);
81423 void (*audit_rule_free) (void *lsmrule);
81424 #endif /* CONFIG_AUDIT */
81425-};
81426+} __randomize_layout;
81427
81428 /* prototypes */
81429 extern int security_init(void);
81430diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
81431index dc368b8..e895209 100644
81432--- a/include/linux/semaphore.h
81433+++ b/include/linux/semaphore.h
81434@@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
81435 }
81436
81437 extern void down(struct semaphore *sem);
81438-extern int __must_check down_interruptible(struct semaphore *sem);
81439+extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
81440 extern int __must_check down_killable(struct semaphore *sem);
81441 extern int __must_check down_trylock(struct semaphore *sem);
81442 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
81443diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
81444index 52e0097..09625ef 100644
81445--- a/include/linux/seq_file.h
81446+++ b/include/linux/seq_file.h
81447@@ -27,6 +27,9 @@ struct seq_file {
81448 struct mutex lock;
81449 const struct seq_operations *op;
81450 int poll_event;
81451+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
81452+ u64 exec_id;
81453+#endif
81454 #ifdef CONFIG_USER_NS
81455 struct user_namespace *user_ns;
81456 #endif
81457@@ -39,6 +42,7 @@ struct seq_operations {
81458 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
81459 int (*show) (struct seq_file *m, void *v);
81460 };
81461+typedef struct seq_operations __no_const seq_operations_no_const;
81462
81463 #define SEQ_SKIP 1
81464
81465diff --git a/include/linux/shm.h b/include/linux/shm.h
81466index 429c199..4d42e38 100644
81467--- a/include/linux/shm.h
81468+++ b/include/linux/shm.h
81469@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
81470
81471 /* The task created the shm object. NULL if the task is dead. */
81472 struct task_struct *shm_creator;
81473+#ifdef CONFIG_GRKERNSEC
81474+ time_t shm_createtime;
81475+ pid_t shm_lapid;
81476+#endif
81477 };
81478
81479 /* shm_mode upper byte flags */
81480diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
81481index 37cb679..dbaebc0 100644
81482--- a/include/linux/skbuff.h
81483+++ b/include/linux/skbuff.h
81484@@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
81485 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
81486 int node);
81487 struct sk_buff *build_skb(void *data, unsigned int frag_size);
81488-static inline struct sk_buff *alloc_skb(unsigned int size,
81489+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
81490 gfp_t priority)
81491 {
81492 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
81493@@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
81494 */
81495 static inline int skb_queue_empty(const struct sk_buff_head *list)
81496 {
81497- return list->next == (struct sk_buff *)list;
81498+ return list->next == (const struct sk_buff *)list;
81499 }
81500
81501 /**
81502@@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
81503 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81504 const struct sk_buff *skb)
81505 {
81506- return skb->next == (struct sk_buff *)list;
81507+ return skb->next == (const struct sk_buff *)list;
81508 }
81509
81510 /**
81511@@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
81512 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
81513 const struct sk_buff *skb)
81514 {
81515- return skb->prev == (struct sk_buff *)list;
81516+ return skb->prev == (const struct sk_buff *)list;
81517 }
81518
81519 /**
81520@@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
81521 return skb->inner_transport_header - skb->inner_network_header;
81522 }
81523
81524-static inline int skb_network_offset(const struct sk_buff *skb)
81525+static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
81526 {
81527 return skb_network_header(skb) - skb->data;
81528 }
81529@@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
81530 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
81531 */
81532 #ifndef NET_SKB_PAD
81533-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
81534+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
81535 #endif
81536
81537 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
81538@@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
81539 int *err);
81540 unsigned int datagram_poll(struct file *file, struct socket *sock,
81541 struct poll_table_struct *wait);
81542-int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81543+int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
81544 struct iovec *to, int size);
81545 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
81546 struct iovec *iov);
81547@@ -2618,6 +2618,9 @@ static inline void nf_reset(struct sk_buff *skb)
81548 nf_bridge_put(skb->nf_bridge);
81549 skb->nf_bridge = NULL;
81550 #endif
81551+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
81552+ skb->nf_trace = 0;
81553+#endif
81554 }
81555
81556 static inline void nf_reset_trace(struct sk_buff *skb)
81557diff --git a/include/linux/slab.h b/include/linux/slab.h
81558index 1e2f4fe..df49ca6 100644
81559--- a/include/linux/slab.h
81560+++ b/include/linux/slab.h
81561@@ -14,15 +14,29 @@
81562 #include <linux/gfp.h>
81563 #include <linux/types.h>
81564 #include <linux/workqueue.h>
81565-
81566+#include <linux/err.h>
81567
81568 /*
81569 * Flags to pass to kmem_cache_create().
81570 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
81571 */
81572 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
81573+
81574+#ifdef CONFIG_PAX_USERCOPY_SLABS
81575+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
81576+#else
81577+#define SLAB_USERCOPY 0x00000000UL
81578+#endif
81579+
81580 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
81581 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
81582+
81583+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81584+#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
81585+#else
81586+#define SLAB_NO_SANITIZE 0x00000000UL
81587+#endif
81588+
81589 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
81590 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
81591 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
81592@@ -98,10 +112,13 @@
81593 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
81594 * Both make kfree a no-op.
81595 */
81596-#define ZERO_SIZE_PTR ((void *)16)
81597+#define ZERO_SIZE_PTR \
81598+({ \
81599+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
81600+ (void *)(-MAX_ERRNO-1L); \
81601+})
81602
81603-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
81604- (unsigned long)ZERO_SIZE_PTR)
81605+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
81606
81607 #include <linux/kmemleak.h>
81608
81609@@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
81610 void kfree(const void *);
81611 void kzfree(const void *);
81612 size_t ksize(const void *);
81613+const char *check_heap_object(const void *ptr, unsigned long n);
81614+bool is_usercopy_object(const void *ptr);
81615
81616 /*
81617 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
81618@@ -174,7 +193,7 @@ struct kmem_cache {
81619 unsigned int align; /* Alignment as calculated */
81620 unsigned long flags; /* Active flags on the slab */
81621 const char *name; /* Slab name for sysfs */
81622- int refcount; /* Use counter */
81623+ atomic_t refcount; /* Use counter */
81624 void (*ctor)(void *); /* Called on object slot creation */
81625 struct list_head list; /* List of all slab caches on the system */
81626 };
81627@@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
81628 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81629 #endif
81630
81631+#ifdef CONFIG_PAX_USERCOPY_SLABS
81632+extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
81633+#endif
81634+
81635 /*
81636 * Figure out which kmalloc slab an allocation of a certain size
81637 * belongs to.
81638@@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
81639 * 2 = 120 .. 192 bytes
81640 * n = 2^(n-1) .. 2^n -1
81641 */
81642-static __always_inline int kmalloc_index(size_t size)
81643+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
81644 {
81645 if (!size)
81646 return 0;
81647@@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
81648 }
81649 #endif /* !CONFIG_SLOB */
81650
81651-void *__kmalloc(size_t size, gfp_t flags);
81652+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
81653 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
81654
81655 #ifdef CONFIG_NUMA
81656-void *__kmalloc_node(size_t size, gfp_t flags, int node);
81657+void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
81658 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
81659 #else
81660 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
81661diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
81662index 09bfffb..4fc80fb 100644
81663--- a/include/linux/slab_def.h
81664+++ b/include/linux/slab_def.h
81665@@ -36,7 +36,7 @@ struct kmem_cache {
81666 /* 4) cache creation/removal */
81667 const char *name;
81668 struct list_head list;
81669- int refcount;
81670+ atomic_t refcount;
81671 int object_size;
81672 int align;
81673
81674@@ -52,10 +52,14 @@ struct kmem_cache {
81675 unsigned long node_allocs;
81676 unsigned long node_frees;
81677 unsigned long node_overflow;
81678- atomic_t allochit;
81679- atomic_t allocmiss;
81680- atomic_t freehit;
81681- atomic_t freemiss;
81682+ atomic_unchecked_t allochit;
81683+ atomic_unchecked_t allocmiss;
81684+ atomic_unchecked_t freehit;
81685+ atomic_unchecked_t freemiss;
81686+#ifdef CONFIG_PAX_MEMORY_SANITIZE
81687+ atomic_unchecked_t sanitized;
81688+ atomic_unchecked_t not_sanitized;
81689+#endif
81690
81691 /*
81692 * If debugging is enabled, then the allocator can add additional
81693diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
81694index f56bfa9..8378a26 100644
81695--- a/include/linux/slub_def.h
81696+++ b/include/linux/slub_def.h
81697@@ -74,7 +74,7 @@ struct kmem_cache {
81698 struct kmem_cache_order_objects max;
81699 struct kmem_cache_order_objects min;
81700 gfp_t allocflags; /* gfp flags to use on each alloc */
81701- int refcount; /* Refcount for slab cache destroy */
81702+ atomic_t refcount; /* Refcount for slab cache destroy */
81703 void (*ctor)(void *);
81704 int inuse; /* Offset to metadata */
81705 int align; /* Alignment */
81706diff --git a/include/linux/smp.h b/include/linux/smp.h
81707index 5da22ee..71d8a28 100644
81708--- a/include/linux/smp.h
81709+++ b/include/linux/smp.h
81710@@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
81711 #endif
81712
81713 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
81714+#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
81715 #define put_cpu() preempt_enable()
81716+#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
81717
81718 /*
81719 * Callback to arch code if there's nosmp or maxcpus=0 on the
81720diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
81721index 54f91d3..be2c379 100644
81722--- a/include/linux/sock_diag.h
81723+++ b/include/linux/sock_diag.h
81724@@ -11,7 +11,7 @@ struct sock;
81725 struct sock_diag_handler {
81726 __u8 family;
81727 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
81728-};
81729+} __do_const;
81730
81731 int sock_diag_register(const struct sock_diag_handler *h);
81732 void sock_diag_unregister(const struct sock_diag_handler *h);
81733diff --git a/include/linux/sonet.h b/include/linux/sonet.h
81734index 680f9a3..f13aeb0 100644
81735--- a/include/linux/sonet.h
81736+++ b/include/linux/sonet.h
81737@@ -7,7 +7,7 @@
81738 #include <uapi/linux/sonet.h>
81739
81740 struct k_sonet_stats {
81741-#define __HANDLE_ITEM(i) atomic_t i
81742+#define __HANDLE_ITEM(i) atomic_unchecked_t i
81743 __SONET_ITEMS
81744 #undef __HANDLE_ITEM
81745 };
81746diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
81747index 07d8e53..dc934c9 100644
81748--- a/include/linux/sunrpc/addr.h
81749+++ b/include/linux/sunrpc/addr.h
81750@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
81751 {
81752 switch (sap->sa_family) {
81753 case AF_INET:
81754- return ntohs(((struct sockaddr_in *)sap)->sin_port);
81755+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
81756 case AF_INET6:
81757- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
81758+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
81759 }
81760 return 0;
81761 }
81762@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
81763 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
81764 const struct sockaddr *src)
81765 {
81766- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
81767+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
81768 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
81769
81770 dsin->sin_family = ssin->sin_family;
81771@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
81772 if (sa->sa_family != AF_INET6)
81773 return 0;
81774
81775- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
81776+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
81777 }
81778
81779 #endif /* _LINUX_SUNRPC_ADDR_H */
81780diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
81781index 8af2804..c7414ef 100644
81782--- a/include/linux/sunrpc/clnt.h
81783+++ b/include/linux/sunrpc/clnt.h
81784@@ -97,7 +97,7 @@ struct rpc_procinfo {
81785 unsigned int p_timer; /* Which RTT timer to use */
81786 u32 p_statidx; /* Which procedure to account */
81787 const char * p_name; /* name of procedure */
81788-};
81789+} __do_const;
81790
81791 #ifdef __KERNEL__
81792
81793diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
81794index 6eecfc2..7ada79d 100644
81795--- a/include/linux/sunrpc/svc.h
81796+++ b/include/linux/sunrpc/svc.h
81797@@ -410,7 +410,7 @@ struct svc_procedure {
81798 unsigned int pc_count; /* call count */
81799 unsigned int pc_cachetype; /* cache info (NFS) */
81800 unsigned int pc_xdrressize; /* maximum size of XDR reply */
81801-};
81802+} __do_const;
81803
81804 /*
81805 * Function prototypes.
81806diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
81807index 0b8e3e6..33e0a01 100644
81808--- a/include/linux/sunrpc/svc_rdma.h
81809+++ b/include/linux/sunrpc/svc_rdma.h
81810@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
81811 extern unsigned int svcrdma_max_requests;
81812 extern unsigned int svcrdma_max_req_size;
81813
81814-extern atomic_t rdma_stat_recv;
81815-extern atomic_t rdma_stat_read;
81816-extern atomic_t rdma_stat_write;
81817-extern atomic_t rdma_stat_sq_starve;
81818-extern atomic_t rdma_stat_rq_starve;
81819-extern atomic_t rdma_stat_rq_poll;
81820-extern atomic_t rdma_stat_rq_prod;
81821-extern atomic_t rdma_stat_sq_poll;
81822-extern atomic_t rdma_stat_sq_prod;
81823+extern atomic_unchecked_t rdma_stat_recv;
81824+extern atomic_unchecked_t rdma_stat_read;
81825+extern atomic_unchecked_t rdma_stat_write;
81826+extern atomic_unchecked_t rdma_stat_sq_starve;
81827+extern atomic_unchecked_t rdma_stat_rq_starve;
81828+extern atomic_unchecked_t rdma_stat_rq_poll;
81829+extern atomic_unchecked_t rdma_stat_rq_prod;
81830+extern atomic_unchecked_t rdma_stat_sq_poll;
81831+extern atomic_unchecked_t rdma_stat_sq_prod;
81832
81833 #define RPCRDMA_VERSION 1
81834
81835diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
81836index 8d71d65..f79586e 100644
81837--- a/include/linux/sunrpc/svcauth.h
81838+++ b/include/linux/sunrpc/svcauth.h
81839@@ -120,7 +120,7 @@ struct auth_ops {
81840 int (*release)(struct svc_rqst *rq);
81841 void (*domain_release)(struct auth_domain *);
81842 int (*set_client)(struct svc_rqst *rq);
81843-};
81844+} __do_const;
81845
81846 #define SVC_GARBAGE 1
81847 #define SVC_SYSERR 2
81848diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
81849index a5ffd32..0935dea 100644
81850--- a/include/linux/swiotlb.h
81851+++ b/include/linux/swiotlb.h
81852@@ -60,7 +60,8 @@ extern void
81853
81854 extern void
81855 swiotlb_free_coherent(struct device *hwdev, size_t size,
81856- void *vaddr, dma_addr_t dma_handle);
81857+ void *vaddr, dma_addr_t dma_handle,
81858+ struct dma_attrs *attrs);
81859
81860 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
81861 unsigned long offset, size_t size,
81862diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
81863index 94273bb..c2e05fc 100644
81864--- a/include/linux/syscalls.h
81865+++ b/include/linux/syscalls.h
81866@@ -97,8 +97,14 @@ struct sigaltstack;
81867 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
81868
81869 #define __SC_DECL(t, a) t a
81870+#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))
81871 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
81872-#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
81873+#define __SC_LONG(t, a) __typeof( \
81874+ __builtin_choose_expr( \
81875+ sizeof(t) > sizeof(int), \
81876+ (t) 0, \
81877+ __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
81878+ )) a
81879 #define __SC_CAST(t, a) (t) a
81880 #define __SC_ARGS(t, a) a
81881 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
81882@@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
81883 asmlinkage long sys_fsync(unsigned int fd);
81884 asmlinkage long sys_fdatasync(unsigned int fd);
81885 asmlinkage long sys_bdflush(int func, long data);
81886-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
81887- char __user *type, unsigned long flags,
81888+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
81889+ const char __user *type, unsigned long flags,
81890 void __user *data);
81891-asmlinkage long sys_umount(char __user *name, int flags);
81892-asmlinkage long sys_oldumount(char __user *name);
81893+asmlinkage long sys_umount(const char __user *name, int flags);
81894+asmlinkage long sys_oldumount(const char __user *name);
81895 asmlinkage long sys_truncate(const char __user *path, long length);
81896 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
81897 asmlinkage long sys_stat(const char __user *filename,
81898@@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
81899 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
81900 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
81901 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
81902- struct sockaddr __user *, int);
81903+ struct sockaddr __user *, int) __intentional_overflow(0);
81904 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
81905 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
81906 unsigned int vlen, unsigned flags);
81907diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
81908index 27b3b0b..e093dd9 100644
81909--- a/include/linux/syscore_ops.h
81910+++ b/include/linux/syscore_ops.h
81911@@ -16,7 +16,7 @@ struct syscore_ops {
81912 int (*suspend)(void);
81913 void (*resume)(void);
81914 void (*shutdown)(void);
81915-};
81916+} __do_const;
81917
81918 extern void register_syscore_ops(struct syscore_ops *ops);
81919 extern void unregister_syscore_ops(struct syscore_ops *ops);
81920diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
81921index 14a8ff2..fa95f3a 100644
81922--- a/include/linux/sysctl.h
81923+++ b/include/linux/sysctl.h
81924@@ -34,13 +34,13 @@ struct ctl_table_root;
81925 struct ctl_table_header;
81926 struct ctl_dir;
81927
81928-typedef struct ctl_table ctl_table;
81929-
81930 typedef int proc_handler (struct ctl_table *ctl, int write,
81931 void __user *buffer, size_t *lenp, loff_t *ppos);
81932
81933 extern int proc_dostring(struct ctl_table *, int,
81934 void __user *, size_t *, loff_t *);
81935+extern int proc_dostring_modpriv(struct ctl_table *, int,
81936+ void __user *, size_t *, loff_t *);
81937 extern int proc_dointvec(struct ctl_table *, int,
81938 void __user *, size_t *, loff_t *);
81939 extern int proc_dointvec_minmax(struct ctl_table *, int,
81940@@ -115,7 +115,9 @@ struct ctl_table
81941 struct ctl_table_poll *poll;
81942 void *extra1;
81943 void *extra2;
81944-};
81945+} __do_const __randomize_layout;
81946+typedef struct ctl_table __no_const ctl_table_no_const;
81947+typedef struct ctl_table ctl_table;
81948
81949 struct ctl_node {
81950 struct rb_node node;
81951diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81952index 6695040..3d4192d 100644
81953--- a/include/linux/sysfs.h
81954+++ b/include/linux/sysfs.h
81955@@ -33,7 +33,8 @@ struct attribute {
81956 struct lock_class_key *key;
81957 struct lock_class_key skey;
81958 #endif
81959-};
81960+} __do_const;
81961+typedef struct attribute __no_const attribute_no_const;
81962
81963 /**
81964 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81965@@ -62,7 +63,8 @@ struct attribute_group {
81966 struct attribute *, int);
81967 struct attribute **attrs;
81968 struct bin_attribute **bin_attrs;
81969-};
81970+} __do_const;
81971+typedef struct attribute_group __no_const attribute_group_no_const;
81972
81973 /**
81974 * Use these macros to make defining attributes easier. See include/linux/device.h
81975@@ -126,7 +128,8 @@ struct bin_attribute {
81976 char *, loff_t, size_t);
81977 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81978 struct vm_area_struct *vma);
81979-};
81980+} __do_const;
81981+typedef struct bin_attribute __no_const bin_attribute_no_const;
81982
81983 /**
81984 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81985diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81986index 387fa7d..3fcde6b 100644
81987--- a/include/linux/sysrq.h
81988+++ b/include/linux/sysrq.h
81989@@ -16,6 +16,7 @@
81990
81991 #include <linux/errno.h>
81992 #include <linux/types.h>
81993+#include <linux/compiler.h>
81994
81995 /* Possible values of bitmask for enabling sysrq functions */
81996 /* 0x0001 is reserved for enable everything */
81997@@ -33,7 +34,7 @@ struct sysrq_key_op {
81998 char *help_msg;
81999 char *action_msg;
82000 int enable_mask;
82001-};
82002+} __do_const;
82003
82004 #ifdef CONFIG_MAGIC_SYSRQ
82005
82006diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82007index fddbe20..0312de8 100644
82008--- a/include/linux/thread_info.h
82009+++ b/include/linux/thread_info.h
82010@@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
82011 #error "no set_restore_sigmask() provided and default one won't work"
82012 #endif
82013
82014+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
82015+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82016+{
82017+#ifndef CONFIG_PAX_USERCOPY_DEBUG
82018+ if (!__builtin_constant_p(n))
82019+#endif
82020+ __check_object_size(ptr, n, to_user);
82021+}
82022+
82023 #endif /* __KERNEL__ */
82024
82025 #endif /* _LINUX_THREAD_INFO_H */
82026diff --git a/include/linux/tty.h b/include/linux/tty.h
82027index 97d660e..6356755 100644
82028--- a/include/linux/tty.h
82029+++ b/include/linux/tty.h
82030@@ -196,7 +196,7 @@ struct tty_port {
82031 const struct tty_port_operations *ops; /* Port operations */
82032 spinlock_t lock; /* Lock protecting tty field */
82033 int blocked_open; /* Waiting to open */
82034- int count; /* Usage count */
82035+ atomic_t count; /* Usage count */
82036 wait_queue_head_t open_wait; /* Open waiters */
82037 wait_queue_head_t close_wait; /* Close waiters */
82038 wait_queue_head_t delta_msr_wait; /* Modem status change */
82039@@ -278,7 +278,7 @@ struct tty_struct {
82040 /* If the tty has a pending do_SAK, queue it here - akpm */
82041 struct work_struct SAK_work;
82042 struct tty_port *port;
82043-};
82044+} __randomize_layout;
82045
82046 /* Each of a tty's open files has private_data pointing to tty_file_private */
82047 struct tty_file_private {
82048@@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
82049 struct tty_struct *tty, struct file *filp);
82050 static inline int tty_port_users(struct tty_port *port)
82051 {
82052- return port->count + port->blocked_open;
82053+ return atomic_read(&port->count) + port->blocked_open;
82054 }
82055
82056 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82057diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82058index 756a609..89db85e 100644
82059--- a/include/linux/tty_driver.h
82060+++ b/include/linux/tty_driver.h
82061@@ -285,7 +285,7 @@ struct tty_operations {
82062 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82063 #endif
82064 const struct file_operations *proc_fops;
82065-};
82066+} __do_const __randomize_layout;
82067
82068 struct tty_driver {
82069 int magic; /* magic number for this structure */
82070@@ -319,7 +319,7 @@ struct tty_driver {
82071
82072 const struct tty_operations *ops;
82073 struct list_head tty_drivers;
82074-};
82075+} __randomize_layout;
82076
82077 extern struct list_head tty_drivers;
82078
82079diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82080index f15c898..207b7d1 100644
82081--- a/include/linux/tty_ldisc.h
82082+++ b/include/linux/tty_ldisc.h
82083@@ -211,7 +211,7 @@ struct tty_ldisc_ops {
82084
82085 struct module *owner;
82086
82087- int refcount;
82088+ atomic_t refcount;
82089 };
82090
82091 struct tty_ldisc {
82092diff --git a/include/linux/types.h b/include/linux/types.h
82093index 4d118ba..c3ee9bf 100644
82094--- a/include/linux/types.h
82095+++ b/include/linux/types.h
82096@@ -176,10 +176,26 @@ typedef struct {
82097 int counter;
82098 } atomic_t;
82099
82100+#ifdef CONFIG_PAX_REFCOUNT
82101+typedef struct {
82102+ int counter;
82103+} atomic_unchecked_t;
82104+#else
82105+typedef atomic_t atomic_unchecked_t;
82106+#endif
82107+
82108 #ifdef CONFIG_64BIT
82109 typedef struct {
82110 long counter;
82111 } atomic64_t;
82112+
82113+#ifdef CONFIG_PAX_REFCOUNT
82114+typedef struct {
82115+ long counter;
82116+} atomic64_unchecked_t;
82117+#else
82118+typedef atomic64_t atomic64_unchecked_t;
82119+#endif
82120 #endif
82121
82122 struct list_head {
82123diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
82124index 9d8cf05..0ed74dd 100644
82125--- a/include/linux/uaccess.h
82126+++ b/include/linux/uaccess.h
82127@@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
82128 long ret; \
82129 mm_segment_t old_fs = get_fs(); \
82130 \
82131- set_fs(KERNEL_DS); \
82132 pagefault_disable(); \
82133- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
82134- pagefault_enable(); \
82135+ set_fs(KERNEL_DS); \
82136+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
82137 set_fs(old_fs); \
82138+ pagefault_enable(); \
82139 ret; \
82140 })
82141
82142diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
82143index 8e522cbc..aa8572d 100644
82144--- a/include/linux/uidgid.h
82145+++ b/include/linux/uidgid.h
82146@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
82147
82148 #endif /* CONFIG_USER_NS */
82149
82150+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
82151+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
82152+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
82153+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
82154+
82155 #endif /* _LINUX_UIDGID_H */
82156diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
82157index 99c1b4d..562e6f3 100644
82158--- a/include/linux/unaligned/access_ok.h
82159+++ b/include/linux/unaligned/access_ok.h
82160@@ -4,34 +4,34 @@
82161 #include <linux/kernel.h>
82162 #include <asm/byteorder.h>
82163
82164-static inline u16 get_unaligned_le16(const void *p)
82165+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
82166 {
82167- return le16_to_cpup((__le16 *)p);
82168+ return le16_to_cpup((const __le16 *)p);
82169 }
82170
82171-static inline u32 get_unaligned_le32(const void *p)
82172+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
82173 {
82174- return le32_to_cpup((__le32 *)p);
82175+ return le32_to_cpup((const __le32 *)p);
82176 }
82177
82178-static inline u64 get_unaligned_le64(const void *p)
82179+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
82180 {
82181- return le64_to_cpup((__le64 *)p);
82182+ return le64_to_cpup((const __le64 *)p);
82183 }
82184
82185-static inline u16 get_unaligned_be16(const void *p)
82186+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
82187 {
82188- return be16_to_cpup((__be16 *)p);
82189+ return be16_to_cpup((const __be16 *)p);
82190 }
82191
82192-static inline u32 get_unaligned_be32(const void *p)
82193+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
82194 {
82195- return be32_to_cpup((__be32 *)p);
82196+ return be32_to_cpup((const __be32 *)p);
82197 }
82198
82199-static inline u64 get_unaligned_be64(const void *p)
82200+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
82201 {
82202- return be64_to_cpup((__be64 *)p);
82203+ return be64_to_cpup((const __be64 *)p);
82204 }
82205
82206 static inline void put_unaligned_le16(u16 val, void *p)
82207diff --git a/include/linux/usb.h b/include/linux/usb.h
82208index 7454865..29f4bfa 100644
82209--- a/include/linux/usb.h
82210+++ b/include/linux/usb.h
82211@@ -563,7 +563,7 @@ struct usb_device {
82212 int maxchild;
82213
82214 u32 quirks;
82215- atomic_t urbnum;
82216+ atomic_unchecked_t urbnum;
82217
82218 unsigned long active_duration;
82219
82220@@ -1641,7 +1641,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
82221
82222 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
82223 __u8 request, __u8 requesttype, __u16 value, __u16 index,
82224- void *data, __u16 size, int timeout);
82225+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
82226 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
82227 void *data, int len, int *actual_length, int timeout);
82228 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
82229diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
82230index e452ba6..78f8e80 100644
82231--- a/include/linux/usb/renesas_usbhs.h
82232+++ b/include/linux/usb/renesas_usbhs.h
82233@@ -39,7 +39,7 @@ enum {
82234 */
82235 struct renesas_usbhs_driver_callback {
82236 int (*notify_hotplug)(struct platform_device *pdev);
82237-};
82238+} __no_const;
82239
82240 /*
82241 * callback functions for platform
82242diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
82243index 4836ba3..603f6ee 100644
82244--- a/include/linux/user_namespace.h
82245+++ b/include/linux/user_namespace.h
82246@@ -33,7 +33,7 @@ struct user_namespace {
82247 struct key *persistent_keyring_register;
82248 struct rw_semaphore persistent_keyring_register_sem;
82249 #endif
82250-};
82251+} __randomize_layout;
82252
82253 extern struct user_namespace init_user_ns;
82254
82255diff --git a/include/linux/utsname.h b/include/linux/utsname.h
82256index 239e277..22a5cf5 100644
82257--- a/include/linux/utsname.h
82258+++ b/include/linux/utsname.h
82259@@ -24,7 +24,7 @@ struct uts_namespace {
82260 struct new_utsname name;
82261 struct user_namespace *user_ns;
82262 unsigned int proc_inum;
82263-};
82264+} __randomize_layout;
82265 extern struct uts_namespace init_uts_ns;
82266
82267 #ifdef CONFIG_UTS_NS
82268diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
82269index 6f8fbcf..4efc177 100644
82270--- a/include/linux/vermagic.h
82271+++ b/include/linux/vermagic.h
82272@@ -25,9 +25,42 @@
82273 #define MODULE_ARCH_VERMAGIC ""
82274 #endif
82275
82276+#ifdef CONFIG_PAX_REFCOUNT
82277+#define MODULE_PAX_REFCOUNT "REFCOUNT "
82278+#else
82279+#define MODULE_PAX_REFCOUNT ""
82280+#endif
82281+
82282+#ifdef CONSTIFY_PLUGIN
82283+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
82284+#else
82285+#define MODULE_CONSTIFY_PLUGIN ""
82286+#endif
82287+
82288+#ifdef STACKLEAK_PLUGIN
82289+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
82290+#else
82291+#define MODULE_STACKLEAK_PLUGIN ""
82292+#endif
82293+
82294+#ifdef RANDSTRUCT_PLUGIN
82295+#include <generated/randomize_layout_hash.h>
82296+#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
82297+#else
82298+#define MODULE_RANDSTRUCT_PLUGIN
82299+#endif
82300+
82301+#ifdef CONFIG_GRKERNSEC
82302+#define MODULE_GRSEC "GRSEC "
82303+#else
82304+#define MODULE_GRSEC ""
82305+#endif
82306+
82307 #define VERMAGIC_STRING \
82308 UTS_RELEASE " " \
82309 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
82310 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
82311- MODULE_ARCH_VERMAGIC
82312+ MODULE_ARCH_VERMAGIC \
82313+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
82314+ MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
82315
82316diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
82317index 502073a..a7de024 100644
82318--- a/include/linux/vga_switcheroo.h
82319+++ b/include/linux/vga_switcheroo.h
82320@@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
82321
82322 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
82323
82324-int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
82325-int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
82326+int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
82327+int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
82328 #else
82329
82330 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
82331@@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
82332
82333 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
82334
82335-static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82336-static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
82337+static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82338+static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
82339
82340 #endif
82341 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
82342diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
82343index 4b8a891..cb8df6e 100644
82344--- a/include/linux/vmalloc.h
82345+++ b/include/linux/vmalloc.h
82346@@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
82347 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
82348 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
82349 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
82350+
82351+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
82352+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
82353+#endif
82354+
82355 /* bits [20..32] reserved for arch specific ioremap internals */
82356
82357 /*
82358@@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
82359
82360 /* for /dev/kmem */
82361 extern long vread(char *buf, char *addr, unsigned long count);
82362-extern long vwrite(char *buf, char *addr, unsigned long count);
82363+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
82364
82365 /*
82366 * Internals. Dont't use..
82367diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
82368index a67b384..f52a537 100644
82369--- a/include/linux/vmstat.h
82370+++ b/include/linux/vmstat.h
82371@@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
82372 /*
82373 * Zone based page accounting with per cpu differentials.
82374 */
82375-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82376+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
82377
82378 static inline void zone_page_state_add(long x, struct zone *zone,
82379 enum zone_stat_item item)
82380 {
82381- atomic_long_add(x, &zone->vm_stat[item]);
82382- atomic_long_add(x, &vm_stat[item]);
82383+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
82384+ atomic_long_add_unchecked(x, &vm_stat[item]);
82385 }
82386
82387-static inline unsigned long global_page_state(enum zone_stat_item item)
82388+static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
82389 {
82390- long x = atomic_long_read(&vm_stat[item]);
82391+ long x = atomic_long_read_unchecked(&vm_stat[item]);
82392 #ifdef CONFIG_SMP
82393 if (x < 0)
82394 x = 0;
82395@@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
82396 return x;
82397 }
82398
82399-static inline unsigned long zone_page_state(struct zone *zone,
82400+static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
82401 enum zone_stat_item item)
82402 {
82403- long x = atomic_long_read(&zone->vm_stat[item]);
82404+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82405 #ifdef CONFIG_SMP
82406 if (x < 0)
82407 x = 0;
82408@@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
82409 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
82410 enum zone_stat_item item)
82411 {
82412- long x = atomic_long_read(&zone->vm_stat[item]);
82413+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
82414
82415 #ifdef CONFIG_SMP
82416 int cpu;
82417@@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
82418
82419 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
82420 {
82421- atomic_long_inc(&zone->vm_stat[item]);
82422- atomic_long_inc(&vm_stat[item]);
82423+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
82424+ atomic_long_inc_unchecked(&vm_stat[item]);
82425 }
82426
82427 static inline void __inc_zone_page_state(struct page *page,
82428@@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
82429
82430 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
82431 {
82432- atomic_long_dec(&zone->vm_stat[item]);
82433- atomic_long_dec(&vm_stat[item]);
82434+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
82435+ atomic_long_dec_unchecked(&vm_stat[item]);
82436 }
82437
82438 static inline void __dec_zone_page_state(struct page *page,
82439diff --git a/include/linux/xattr.h b/include/linux/xattr.h
82440index 91b0a68..0e9adf6 100644
82441--- a/include/linux/xattr.h
82442+++ b/include/linux/xattr.h
82443@@ -28,7 +28,7 @@ struct xattr_handler {
82444 size_t size, int handler_flags);
82445 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
82446 size_t size, int flags, int handler_flags);
82447-};
82448+} __do_const;
82449
82450 struct xattr {
82451 const char *name;
82452@@ -37,6 +37,9 @@ struct xattr {
82453 };
82454
82455 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
82456+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82457+ssize_t pax_getxattr(struct dentry *, void *, size_t);
82458+#endif
82459 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
82460 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
82461 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
82462diff --git a/include/linux/zlib.h b/include/linux/zlib.h
82463index 9c5a6b4..09c9438 100644
82464--- a/include/linux/zlib.h
82465+++ b/include/linux/zlib.h
82466@@ -31,6 +31,7 @@
82467 #define _ZLIB_H
82468
82469 #include <linux/zconf.h>
82470+#include <linux/compiler.h>
82471
82472 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
82473 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
82474@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
82475
82476 /* basic functions */
82477
82478-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
82479+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
82480 /*
82481 Returns the number of bytes that needs to be allocated for a per-
82482 stream workspace with the specified parameters. A pointer to this
82483diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
82484index c768c9f..bdcaa5a 100644
82485--- a/include/media/v4l2-dev.h
82486+++ b/include/media/v4l2-dev.h
82487@@ -76,7 +76,7 @@ struct v4l2_file_operations {
82488 int (*mmap) (struct file *, struct vm_area_struct *);
82489 int (*open) (struct file *);
82490 int (*release) (struct file *);
82491-};
82492+} __do_const;
82493
82494 /*
82495 * Newer version of video_device, handled by videodev2.c
82496diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
82497index c9b1593..a572459 100644
82498--- a/include/media/v4l2-device.h
82499+++ b/include/media/v4l2-device.h
82500@@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
82501 this function returns 0. If the name ends with a digit (e.g. cx18),
82502 then the name will be set to cx18-0 since cx180 looks really odd. */
82503 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
82504- atomic_t *instance);
82505+ atomic_unchecked_t *instance);
82506
82507 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
82508 Since the parent disappears this ensures that v4l2_dev doesn't have an
82509diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
82510index 9a36d92..0aafe2a 100644
82511--- a/include/net/9p/transport.h
82512+++ b/include/net/9p/transport.h
82513@@ -60,7 +60,7 @@ struct p9_trans_module {
82514 int (*cancel) (struct p9_client *, struct p9_req_t *req);
82515 int (*zc_request)(struct p9_client *, struct p9_req_t *,
82516 char *, char *, int , int, int, int);
82517-};
82518+} __do_const;
82519
82520 void v9fs_register_trans(struct p9_trans_module *m);
82521 void v9fs_unregister_trans(struct p9_trans_module *m);
82522diff --git a/include/net/af_unix.h b/include/net/af_unix.h
82523index a175ba4..196eb82 100644
82524--- a/include/net/af_unix.h
82525+++ b/include/net/af_unix.h
82526@@ -36,7 +36,7 @@ struct unix_skb_parms {
82527 u32 secid; /* Security ID */
82528 #endif
82529 u32 consumed;
82530-};
82531+} __randomize_layout;
82532
82533 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
82534 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
82535diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
82536index c853b16d..37fccb7 100644
82537--- a/include/net/bluetooth/l2cap.h
82538+++ b/include/net/bluetooth/l2cap.h
82539@@ -557,7 +557,7 @@ struct l2cap_ops {
82540 long (*get_sndtimeo) (struct l2cap_chan *chan);
82541 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
82542 unsigned long len, int nb);
82543-};
82544+} __do_const;
82545
82546 struct l2cap_conn {
82547 struct hci_conn *hcon;
82548diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
82549index f2ae33d..c457cf0 100644
82550--- a/include/net/caif/cfctrl.h
82551+++ b/include/net/caif/cfctrl.h
82552@@ -52,7 +52,7 @@ struct cfctrl_rsp {
82553 void (*radioset_rsp)(void);
82554 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
82555 struct cflayer *client_layer);
82556-};
82557+} __no_const;
82558
82559 /* Link Setup Parameters for CAIF-Links. */
82560 struct cfctrl_link_param {
82561@@ -101,8 +101,8 @@ struct cfctrl_request_info {
82562 struct cfctrl {
82563 struct cfsrvl serv;
82564 struct cfctrl_rsp res;
82565- atomic_t req_seq_no;
82566- atomic_t rsp_seq_no;
82567+ atomic_unchecked_t req_seq_no;
82568+ atomic_unchecked_t rsp_seq_no;
82569 struct list_head list;
82570 /* Protects from simultaneous access to first_req list */
82571 spinlock_t info_list_lock;
82572diff --git a/include/net/flow.h b/include/net/flow.h
82573index 65ce471..b7bbe9b 100644
82574--- a/include/net/flow.h
82575+++ b/include/net/flow.h
82576@@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
82577
82578 void flow_cache_flush(void);
82579 void flow_cache_flush_deferred(void);
82580-extern atomic_t flow_cache_genid;
82581+extern atomic_unchecked_t flow_cache_genid;
82582
82583 #endif
82584diff --git a/include/net/genetlink.h b/include/net/genetlink.h
82585index 1b177ed..a24a138 100644
82586--- a/include/net/genetlink.h
82587+++ b/include/net/genetlink.h
82588@@ -118,7 +118,7 @@ struct genl_ops {
82589 u8 cmd;
82590 u8 internal_flags;
82591 u8 flags;
82592-};
82593+} __do_const;
82594
82595 int __genl_register_family(struct genl_family *family);
82596
82597diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
82598index 734d9b5..48a9a4b 100644
82599--- a/include/net/gro_cells.h
82600+++ b/include/net/gro_cells.h
82601@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
82602 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
82603
82604 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
82605- atomic_long_inc(&dev->rx_dropped);
82606+ atomic_long_inc_unchecked(&dev->rx_dropped);
82607 kfree_skb(skb);
82608 return;
82609 }
82610diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
82611index c55aeed..b3393f4 100644
82612--- a/include/net/inet_connection_sock.h
82613+++ b/include/net/inet_connection_sock.h
82614@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
82615 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
82616 int (*bind_conflict)(const struct sock *sk,
82617 const struct inet_bind_bucket *tb, bool relax);
82618-};
82619+} __do_const;
82620
82621 /** inet_connection_sock - INET connection oriented sock
82622 *
82623diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
82624index f4e127a..c3d5e9c 100644
82625--- a/include/net/inetpeer.h
82626+++ b/include/net/inetpeer.h
82627@@ -47,8 +47,8 @@ struct inet_peer {
82628 */
82629 union {
82630 struct {
82631- atomic_t rid; /* Frag reception counter */
82632- atomic_t ip_id_count; /* IP ID for the next packet */
82633+ atomic_unchecked_t rid; /* Frag reception counter */
82634+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
82635 };
82636 struct rcu_head rcu;
82637 struct inet_peer *gc_next;
82638@@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
82639 /* can be called with or without local BH being disabled */
82640 static inline int inet_getid(struct inet_peer *p, int more)
82641 {
82642- int old, new;
82643+ int id;
82644 more++;
82645 inet_peer_refcheck(p);
82646- do {
82647- old = atomic_read(&p->ip_id_count);
82648- new = old + more;
82649- if (!new)
82650- new = 1;
82651- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
82652- return new;
82653+ id = atomic_add_return_unchecked(more, &p->ip_id_count);
82654+ if (!id)
82655+ id = atomic_inc_return_unchecked(&p->ip_id_count);
82656+ return id;
82657 }
82658
82659 #endif /* _NET_INETPEER_H */
82660diff --git a/include/net/ip.h b/include/net/ip.h
82661index 5a25f36..2e73203 100644
82662--- a/include/net/ip.h
82663+++ b/include/net/ip.h
82664@@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
82665
82666 void inet_get_local_port_range(struct net *net, int *low, int *high);
82667
82668-extern unsigned long *sysctl_local_reserved_ports;
82669+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
82670 static inline int inet_is_reserved_local_port(int port)
82671 {
82672 return test_bit(port, sysctl_local_reserved_ports);
82673diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
82674index 9922093..a1755d6 100644
82675--- a/include/net/ip_fib.h
82676+++ b/include/net/ip_fib.h
82677@@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
82678
82679 #define FIB_RES_SADDR(net, res) \
82680 ((FIB_RES_NH(res).nh_saddr_genid == \
82681- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
82682+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
82683 FIB_RES_NH(res).nh_saddr : \
82684 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
82685 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
82686diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
82687index 5679d92..2e7a690 100644
82688--- a/include/net/ip_vs.h
82689+++ b/include/net/ip_vs.h
82690@@ -558,7 +558,7 @@ struct ip_vs_conn {
82691 struct ip_vs_conn *control; /* Master control connection */
82692 atomic_t n_control; /* Number of controlled ones */
82693 struct ip_vs_dest *dest; /* real server */
82694- atomic_t in_pkts; /* incoming packet counter */
82695+ atomic_unchecked_t in_pkts; /* incoming packet counter */
82696
82697 /* packet transmitter for different forwarding methods. If it
82698 mangles the packet, it must return NF_DROP or better NF_STOLEN,
82699@@ -705,7 +705,7 @@ struct ip_vs_dest {
82700 __be16 port; /* port number of the server */
82701 union nf_inet_addr addr; /* IP address of the server */
82702 volatile unsigned int flags; /* dest status flags */
82703- atomic_t conn_flags; /* flags to copy to conn */
82704+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
82705 atomic_t weight; /* server weight */
82706
82707 atomic_t refcnt; /* reference counter */
82708@@ -960,11 +960,11 @@ struct netns_ipvs {
82709 /* ip_vs_lblc */
82710 int sysctl_lblc_expiration;
82711 struct ctl_table_header *lblc_ctl_header;
82712- struct ctl_table *lblc_ctl_table;
82713+ ctl_table_no_const *lblc_ctl_table;
82714 /* ip_vs_lblcr */
82715 int sysctl_lblcr_expiration;
82716 struct ctl_table_header *lblcr_ctl_header;
82717- struct ctl_table *lblcr_ctl_table;
82718+ ctl_table_no_const *lblcr_ctl_table;
82719 /* ip_vs_est */
82720 struct list_head est_list; /* estimator list */
82721 spinlock_t est_lock;
82722diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
82723index 0224402..dafaf94a 100644
82724--- a/include/net/irda/ircomm_tty.h
82725+++ b/include/net/irda/ircomm_tty.h
82726@@ -35,6 +35,7 @@
82727 #include <linux/termios.h>
82728 #include <linux/timer.h>
82729 #include <linux/tty.h> /* struct tty_struct */
82730+#include <asm/local.h>
82731
82732 #include <net/irda/irias_object.h>
82733 #include <net/irda/ircomm_core.h>
82734diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
82735index 714cc9a..ea05f3e 100644
82736--- a/include/net/iucv/af_iucv.h
82737+++ b/include/net/iucv/af_iucv.h
82738@@ -149,7 +149,7 @@ struct iucv_skb_cb {
82739 struct iucv_sock_list {
82740 struct hlist_head head;
82741 rwlock_t lock;
82742- atomic_t autobind_name;
82743+ atomic_unchecked_t autobind_name;
82744 };
82745
82746 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
82747diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
82748index f3be818..bf46196 100644
82749--- a/include/net/llc_c_ac.h
82750+++ b/include/net/llc_c_ac.h
82751@@ -87,7 +87,7 @@
82752 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
82753 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
82754
82755-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82756+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
82757
82758 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
82759 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
82760diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
82761index 3948cf1..83b28c4 100644
82762--- a/include/net/llc_c_ev.h
82763+++ b/include/net/llc_c_ev.h
82764@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
82765 return (struct llc_conn_state_ev *)skb->cb;
82766 }
82767
82768-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82769-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82770+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
82771+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
82772
82773 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
82774 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
82775diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
82776index 0e79cfb..f46db31 100644
82777--- a/include/net/llc_c_st.h
82778+++ b/include/net/llc_c_st.h
82779@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
82780 u8 next_state;
82781 llc_conn_ev_qfyr_t *ev_qualifiers;
82782 llc_conn_action_t *ev_actions;
82783-};
82784+} __do_const;
82785
82786 struct llc_conn_state {
82787 u8 current_state;
82788diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
82789index a61b98c..aade1eb 100644
82790--- a/include/net/llc_s_ac.h
82791+++ b/include/net/llc_s_ac.h
82792@@ -23,7 +23,7 @@
82793 #define SAP_ACT_TEST_IND 9
82794
82795 /* All action functions must look like this */
82796-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82797+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
82798
82799 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
82800 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
82801diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
82802index 567c681..cd73ac0 100644
82803--- a/include/net/llc_s_st.h
82804+++ b/include/net/llc_s_st.h
82805@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
82806 llc_sap_ev_t ev;
82807 u8 next_state;
82808 llc_sap_action_t *ev_actions;
82809-};
82810+} __do_const;
82811
82812 struct llc_sap_state {
82813 u8 curr_state;
82814diff --git a/include/net/mac80211.h b/include/net/mac80211.h
82815index 7ceed99..d3ffaa2 100644
82816--- a/include/net/mac80211.h
82817+++ b/include/net/mac80211.h
82818@@ -4407,7 +4407,7 @@ struct rate_control_ops {
82819 void (*add_sta_debugfs)(void *priv, void *priv_sta,
82820 struct dentry *dir);
82821 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
82822-};
82823+} __do_const;
82824
82825 static inline int rate_supported(struct ieee80211_sta *sta,
82826 enum ieee80211_band band,
82827diff --git a/include/net/neighbour.h b/include/net/neighbour.h
82828index 536501a..47b7982 100644
82829--- a/include/net/neighbour.h
82830+++ b/include/net/neighbour.h
82831@@ -123,7 +123,7 @@ struct neigh_ops {
82832 void (*error_report)(struct neighbour *, struct sk_buff *);
82833 int (*output)(struct neighbour *, struct sk_buff *);
82834 int (*connected_output)(struct neighbour *, struct sk_buff *);
82835-};
82836+} __do_const;
82837
82838 struct pneigh_entry {
82839 struct pneigh_entry *next;
82840@@ -163,7 +163,6 @@ struct neigh_table {
82841 void (*proxy_redo)(struct sk_buff *skb);
82842 char *id;
82843 struct neigh_parms parms;
82844- /* HACK. gc_* should follow parms without a gap! */
82845 int gc_interval;
82846 int gc_thresh1;
82847 int gc_thresh2;
82848@@ -178,7 +177,7 @@ struct neigh_table {
82849 struct neigh_statistics __percpu *stats;
82850 struct neigh_hash_table __rcu *nht;
82851 struct pneigh_entry **phash_buckets;
82852-};
82853+} __randomize_layout;
82854
82855 #define NEIGH_PRIV_ALIGN sizeof(long long)
82856 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
82857diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
82858index da68c9a..c4a0720 100644
82859--- a/include/net/net_namespace.h
82860+++ b/include/net/net_namespace.h
82861@@ -124,8 +124,8 @@ struct net {
82862 struct netns_ipvs *ipvs;
82863 #endif
82864 struct sock *diag_nlsk;
82865- atomic_t fnhe_genid;
82866-};
82867+ atomic_unchecked_t fnhe_genid;
82868+} __randomize_layout;
82869
82870 /*
82871 * ifindex generation is per-net namespace, and loopback is
82872@@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
82873 #define __net_init __init
82874 #define __net_exit __exit_refok
82875 #define __net_initdata __initdata
82876+#ifdef CONSTIFY_PLUGIN
82877 #define __net_initconst __initconst
82878+#else
82879+#define __net_initconst __initdata
82880+#endif
82881 #endif
82882
82883 struct pernet_operations {
82884@@ -291,7 +295,7 @@ struct pernet_operations {
82885 void (*exit_batch)(struct list_head *net_exit_list);
82886 int *id;
82887 size_t size;
82888-};
82889+} __do_const;
82890
82891 /*
82892 * Use these carefully. If you implement a network device and it
82893@@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
82894
82895 static inline int rt_genid_ipv4(struct net *net)
82896 {
82897- return atomic_read(&net->ipv4.rt_genid);
82898+ return atomic_read_unchecked(&net->ipv4.rt_genid);
82899 }
82900
82901 static inline void rt_genid_bump_ipv4(struct net *net)
82902 {
82903- atomic_inc(&net->ipv4.rt_genid);
82904+ atomic_inc_unchecked(&net->ipv4.rt_genid);
82905 }
82906
82907 #if IS_ENABLED(CONFIG_IPV6)
82908 static inline int rt_genid_ipv6(struct net *net)
82909 {
82910- return atomic_read(&net->ipv6.rt_genid);
82911+ return atomic_read_unchecked(&net->ipv6.rt_genid);
82912 }
82913
82914 static inline void rt_genid_bump_ipv6(struct net *net)
82915 {
82916- atomic_inc(&net->ipv6.rt_genid);
82917+ atomic_inc_unchecked(&net->ipv6.rt_genid);
82918 }
82919 #else
82920 static inline int rt_genid_ipv6(struct net *net)
82921@@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
82922
82923 static inline int fnhe_genid(struct net *net)
82924 {
82925- return atomic_read(&net->fnhe_genid);
82926+ return atomic_read_unchecked(&net->fnhe_genid);
82927 }
82928
82929 static inline void fnhe_genid_bump(struct net *net)
82930 {
82931- atomic_inc(&net->fnhe_genid);
82932+ atomic_inc_unchecked(&net->fnhe_genid);
82933 }
82934
82935 #endif /* __NET_NET_NAMESPACE_H */
82936diff --git a/include/net/netdma.h b/include/net/netdma.h
82937index 8ba8ce2..99b7fff 100644
82938--- a/include/net/netdma.h
82939+++ b/include/net/netdma.h
82940@@ -24,7 +24,7 @@
82941 #include <linux/dmaengine.h>
82942 #include <linux/skbuff.h>
82943
82944-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82945+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
82946 struct sk_buff *skb, int offset, struct iovec *to,
82947 size_t len, struct dma_pinned_list *pinned_list);
82948
82949diff --git a/include/net/netfilter/nf_conntrack_extend.h b/include/net/netfilter/nf_conntrack_extend.h
82950index 956b175..55d1504 100644
82951--- a/include/net/netfilter/nf_conntrack_extend.h
82952+++ b/include/net/netfilter/nf_conntrack_extend.h
82953@@ -47,8 +47,8 @@ enum nf_ct_ext_id {
82954 /* Extensions: optional stuff which isn't permanently in struct. */
82955 struct nf_ct_ext {
82956 struct rcu_head rcu;
82957- u8 offset[NF_CT_EXT_NUM];
82958- u8 len;
82959+ u16 offset[NF_CT_EXT_NUM];
82960+ u16 len;
82961 char data[0];
82962 };
82963
82964diff --git a/include/net/netlink.h b/include/net/netlink.h
82965index 2b47eaa..6d5bcc2 100644
82966--- a/include/net/netlink.h
82967+++ b/include/net/netlink.h
82968@@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
82969 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
82970 {
82971 if (mark)
82972- skb_trim(skb, (unsigned char *) mark - skb->data);
82973+ skb_trim(skb, (const unsigned char *) mark - skb->data);
82974 }
82975
82976 /**
82977diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82978index c9c0c53..53f24c3 100644
82979--- a/include/net/netns/conntrack.h
82980+++ b/include/net/netns/conntrack.h
82981@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82982 struct nf_proto_net {
82983 #ifdef CONFIG_SYSCTL
82984 struct ctl_table_header *ctl_table_header;
82985- struct ctl_table *ctl_table;
82986+ ctl_table_no_const *ctl_table;
82987 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82988 struct ctl_table_header *ctl_compat_header;
82989- struct ctl_table *ctl_compat_table;
82990+ ctl_table_no_const *ctl_compat_table;
82991 #endif
82992 #endif
82993 unsigned int users;
82994@@ -58,7 +58,7 @@ struct nf_ip_net {
82995 struct nf_icmp_net icmpv6;
82996 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82997 struct ctl_table_header *ctl_table_header;
82998- struct ctl_table *ctl_table;
82999+ ctl_table_no_const *ctl_table;
83000 #endif
83001 };
83002
83003diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83004index ee520cb..9a0fd88 100644
83005--- a/include/net/netns/ipv4.h
83006+++ b/include/net/netns/ipv4.h
83007@@ -72,7 +72,7 @@ struct netns_ipv4 {
83008
83009 kgid_t sysctl_ping_group_range[2];
83010
83011- atomic_t dev_addr_genid;
83012+ atomic_unchecked_t dev_addr_genid;
83013
83014 #ifdef CONFIG_IP_MROUTE
83015 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83016@@ -82,6 +82,6 @@ struct netns_ipv4 {
83017 struct fib_rules_ops *mr_rules_ops;
83018 #endif
83019 #endif
83020- atomic_t rt_genid;
83021+ atomic_unchecked_t rt_genid;
83022 };
83023 #endif
83024diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83025index 0fb2401..477d81c 100644
83026--- a/include/net/netns/ipv6.h
83027+++ b/include/net/netns/ipv6.h
83028@@ -71,8 +71,8 @@ struct netns_ipv6 {
83029 struct fib_rules_ops *mr6_rules_ops;
83030 #endif
83031 #endif
83032- atomic_t dev_addr_genid;
83033- atomic_t rt_genid;
83034+ atomic_unchecked_t dev_addr_genid;
83035+ atomic_unchecked_t rt_genid;
83036 };
83037
83038 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83039diff --git a/include/net/ping.h b/include/net/ping.h
83040index 90f4841..74446a8 100644
83041--- a/include/net/ping.h
83042+++ b/include/net/ping.h
83043@@ -56,7 +56,7 @@ struct ping_iter_state {
83044 extern struct proto ping_prot;
83045 extern struct ping_table ping_table;
83046 #if IS_ENABLED(CONFIG_IPV6)
83047-extern struct pingv6_ops pingv6_ops;
83048+extern struct pingv6_ops *pingv6_ops;
83049 #endif
83050
83051 struct pingfakehdr {
83052diff --git a/include/net/protocol.h b/include/net/protocol.h
83053index fbf7676..a5e21c3 100644
83054--- a/include/net/protocol.h
83055+++ b/include/net/protocol.h
83056@@ -44,7 +44,7 @@ struct net_protocol {
83057 void (*err_handler)(struct sk_buff *skb, u32 info);
83058 unsigned int no_policy:1,
83059 netns_ok:1;
83060-};
83061+} __do_const;
83062
83063 #if IS_ENABLED(CONFIG_IPV6)
83064 struct inet6_protocol {
83065@@ -57,7 +57,7 @@ struct inet6_protocol {
83066 u8 type, u8 code, int offset,
83067 __be32 info);
83068 unsigned int flags; /* INET6_PROTO_xxx */
83069-};
83070+} __do_const;
83071
83072 #define INET6_PROTO_NOPOLICY 0x1
83073 #define INET6_PROTO_FINAL 0x2
83074diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83075index bb13a18..e734116 100644
83076--- a/include/net/rtnetlink.h
83077+++ b/include/net/rtnetlink.h
83078@@ -79,7 +79,7 @@ struct rtnl_link_ops {
83079 const struct net_device *dev);
83080 unsigned int (*get_num_tx_queues)(void);
83081 unsigned int (*get_num_rx_queues)(void);
83082-};
83083+} __do_const;
83084
83085 int __rtnl_link_register(struct rtnl_link_ops *ops);
83086 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83087diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83088index 6bd44fe..96f364e 100644
83089--- a/include/net/sctp/checksum.h
83090+++ b/include/net/sctp/checksum.h
83091@@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83092 unsigned int offset)
83093 {
83094 struct sctphdr *sh = sctp_hdr(skb);
83095- __le32 ret, old = sh->checksum;
83096- const struct skb_checksum_ops ops = {
83097+ __le32 ret, old = sh->checksum;
83098+ static const struct skb_checksum_ops ops = {
83099 .update = sctp_csum_update,
83100 .combine = sctp_csum_combine,
83101 };
83102diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83103index 4ef75af..5aa073a 100644
83104--- a/include/net/sctp/sm.h
83105+++ b/include/net/sctp/sm.h
83106@@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83107 typedef struct {
83108 sctp_state_fn_t *fn;
83109 const char *name;
83110-} sctp_sm_table_entry_t;
83111+} __do_const sctp_sm_table_entry_t;
83112
83113 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83114 * currently in use.
83115@@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83116 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83117
83118 /* Extern declarations for major data structures. */
83119-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83120+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83121
83122
83123 /* Get the size of a DATA chunk payload. */
83124diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83125index 0a248b3..4dcbe5c 100644
83126--- a/include/net/sctp/structs.h
83127+++ b/include/net/sctp/structs.h
83128@@ -508,7 +508,7 @@ struct sctp_pf {
83129 struct sctp_association *asoc);
83130 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
83131 struct sctp_af *af;
83132-};
83133+} __do_const;
83134
83135
83136 /* Structure to track chunk fragments that have been acked, but peer
83137diff --git a/include/net/sock.h b/include/net/sock.h
83138index a2b3d4e..466983f 100644
83139--- a/include/net/sock.h
83140+++ b/include/net/sock.h
83141@@ -348,7 +348,7 @@ struct sock {
83142 unsigned int sk_napi_id;
83143 unsigned int sk_ll_usec;
83144 #endif
83145- atomic_t sk_drops;
83146+ atomic_unchecked_t sk_drops;
83147 int sk_rcvbuf;
83148
83149 struct sk_filter __rcu *sk_filter;
83150@@ -1022,7 +1022,7 @@ struct proto {
83151 void (*destroy_cgroup)(struct mem_cgroup *memcg);
83152 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
83153 #endif
83154-};
83155+} __randomize_layout;
83156
83157 /*
83158 * Bits in struct cg_proto.flags
83159@@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
83160 return ret >> PAGE_SHIFT;
83161 }
83162
83163-static inline long
83164+static inline long __intentional_overflow(-1)
83165 sk_memory_allocated(const struct sock *sk)
83166 {
83167 struct proto *prot = sk->sk_prot;
83168@@ -1354,7 +1354,7 @@ struct sock_iocb {
83169 struct scm_cookie *scm;
83170 struct msghdr *msg, async_msg;
83171 struct kiocb *kiocb;
83172-};
83173+} __randomize_layout;
83174
83175 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
83176 {
83177@@ -1818,7 +1818,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@@ -2080,7 +2080,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 197b020..10a7f03 100644
83197--- a/include/net/tcp.h
83198+++ b/include/net/tcp.h
83199@@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
83200 void tcp_xmit_retransmit_queue(struct sock *);
83201 void tcp_simple_retransmit(struct sock *);
83202 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
83203-int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83204+int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
83205
83206 void tcp_send_probe0(struct sock *);
83207 void tcp_send_partial(struct sock *);
83208@@ -712,8 +712,8 @@ struct tcp_skb_cb {
83209 struct inet6_skb_parm h6;
83210 #endif
83211 } header; /* For incoming frames */
83212- __u32 seq; /* Starting sequence number */
83213- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
83214+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
83215+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
83216 __u32 when; /* used to compute rtt's */
83217 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
83218
83219@@ -727,7 +727,7 @@ struct tcp_skb_cb {
83220
83221 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
83222 /* 1 byte hole */
83223- __u32 ack_seq; /* Sequence number ACK'd */
83224+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
83225 };
83226
83227 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
83228diff --git a/include/net/xfrm.h b/include/net/xfrm.h
83229index 6b82fdf..14d74d2 100644
83230--- a/include/net/xfrm.h
83231+++ b/include/net/xfrm.h
83232@@ -287,7 +287,6 @@ struct xfrm_dst;
83233 struct xfrm_policy_afinfo {
83234 unsigned short family;
83235 struct dst_ops *dst_ops;
83236- void (*garbage_collect)(struct net *net);
83237 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
83238 const xfrm_address_t *saddr,
83239 const xfrm_address_t *daddr);
83240@@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
83241 struct net_device *dev,
83242 const struct flowi *fl);
83243 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
83244-};
83245+} __do_const;
83246
83247 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
83248 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
83249@@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
83250 int (*transport_finish)(struct sk_buff *skb,
83251 int async);
83252 void (*local_error)(struct sk_buff *skb, u32 mtu);
83253-};
83254+} __do_const;
83255
83256 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
83257 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
83258@@ -429,7 +428,7 @@ struct xfrm_mode {
83259 struct module *owner;
83260 unsigned int encap;
83261 int flags;
83262-};
83263+} __do_const;
83264
83265 /* Flags for xfrm_mode. */
83266 enum {
83267@@ -526,7 +525,7 @@ struct xfrm_policy {
83268 struct timer_list timer;
83269
83270 struct flow_cache_object flo;
83271- atomic_t genid;
83272+ atomic_unchecked_t genid;
83273 u32 priority;
83274 u32 index;
83275 struct xfrm_mark mark;
83276@@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
83277 }
83278
83279 void xfrm_garbage_collect(struct net *net);
83280+void xfrm_garbage_collect_deferred(struct net *net);
83281
83282 #else
83283
83284@@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
83285 static inline void xfrm_garbage_collect(struct net *net)
83286 {
83287 }
83288+static inline void xfrm_garbage_collect_deferred(struct net *net)
83289+{
83290+}
83291 #endif
83292
83293 static __inline__
83294diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
83295index 1017e0b..227aa4d 100644
83296--- a/include/rdma/iw_cm.h
83297+++ b/include/rdma/iw_cm.h
83298@@ -122,7 +122,7 @@ struct iw_cm_verbs {
83299 int backlog);
83300
83301 int (*destroy_listen)(struct iw_cm_id *cm_id);
83302-};
83303+} __no_const;
83304
83305 /**
83306 * iw_create_cm_id - Create an IW CM identifier.
83307diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
83308index 52beadf..598734c 100644
83309--- a/include/scsi/libfc.h
83310+++ b/include/scsi/libfc.h
83311@@ -771,6 +771,7 @@ struct libfc_function_template {
83312 */
83313 void (*disc_stop_final) (struct fc_lport *);
83314 };
83315+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
83316
83317 /**
83318 * struct fc_disc - Discovery context
83319@@ -875,7 +876,7 @@ struct fc_lport {
83320 struct fc_vport *vport;
83321
83322 /* Operational Information */
83323- struct libfc_function_template tt;
83324+ libfc_function_template_no_const tt;
83325 u8 link_up;
83326 u8 qfull;
83327 enum fc_lport_state state;
83328diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
83329index d65fbec..f80fef2 100644
83330--- a/include/scsi/scsi_device.h
83331+++ b/include/scsi/scsi_device.h
83332@@ -180,9 +180,9 @@ struct scsi_device {
83333 unsigned int max_device_blocked; /* what device_blocked counts down from */
83334 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
83335
83336- atomic_t iorequest_cnt;
83337- atomic_t iodone_cnt;
83338- atomic_t ioerr_cnt;
83339+ atomic_unchecked_t iorequest_cnt;
83340+ atomic_unchecked_t iodone_cnt;
83341+ atomic_unchecked_t ioerr_cnt;
83342
83343 struct device sdev_gendev,
83344 sdev_dev;
83345diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
83346index b797e8f..8e2c3aa 100644
83347--- a/include/scsi/scsi_transport_fc.h
83348+++ b/include/scsi/scsi_transport_fc.h
83349@@ -751,7 +751,8 @@ struct fc_function_template {
83350 unsigned long show_host_system_hostname:1;
83351
83352 unsigned long disable_target_scan:1;
83353-};
83354+} __do_const;
83355+typedef struct fc_function_template __no_const fc_function_template_no_const;
83356
83357
83358 /**
83359diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
83360index ae6c3b8..fd748ac 100644
83361--- a/include/sound/compress_driver.h
83362+++ b/include/sound/compress_driver.h
83363@@ -128,7 +128,7 @@ struct snd_compr_ops {
83364 struct snd_compr_caps *caps);
83365 int (*get_codec_caps) (struct snd_compr_stream *stream,
83366 struct snd_compr_codec_caps *codec);
83367-};
83368+} __no_const;
83369
83370 /**
83371 * struct snd_compr: Compressed device
83372diff --git a/include/sound/soc.h b/include/sound/soc.h
83373index 1f741cb..8cefc08 100644
83374--- a/include/sound/soc.h
83375+++ b/include/sound/soc.h
83376@@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
83377 /* probe ordering - for components with runtime dependencies */
83378 int probe_order;
83379 int remove_order;
83380-};
83381+} __do_const;
83382
83383 /* SoC platform interface */
83384 struct snd_soc_platform_driver {
83385@@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
83386 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
83387 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
83388 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
83389-};
83390+} __do_const;
83391
83392 struct snd_soc_platform {
83393 const char *name;
83394diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
83395index e3569f8..6544ffd 100644
83396--- a/include/target/target_core_base.h
83397+++ b/include/target/target_core_base.h
83398@@ -687,7 +687,7 @@ struct se_device {
83399 atomic_long_t write_bytes;
83400 /* Active commands on this virtual SE device */
83401 atomic_t simple_cmds;
83402- atomic_t dev_ordered_id;
83403+ atomic_unchecked_t dev_ordered_id;
83404 atomic_t dev_ordered_sync;
83405 atomic_t dev_qf_count;
83406 int export_count;
83407diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
83408new file mode 100644
83409index 0000000..fb634b7
83410--- /dev/null
83411+++ b/include/trace/events/fs.h
83412@@ -0,0 +1,53 @@
83413+#undef TRACE_SYSTEM
83414+#define TRACE_SYSTEM fs
83415+
83416+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
83417+#define _TRACE_FS_H
83418+
83419+#include <linux/fs.h>
83420+#include <linux/tracepoint.h>
83421+
83422+TRACE_EVENT(do_sys_open,
83423+
83424+ TP_PROTO(const char *filename, int flags, int mode),
83425+
83426+ TP_ARGS(filename, flags, mode),
83427+
83428+ TP_STRUCT__entry(
83429+ __string( filename, filename )
83430+ __field( int, flags )
83431+ __field( int, mode )
83432+ ),
83433+
83434+ TP_fast_assign(
83435+ __assign_str(filename, filename);
83436+ __entry->flags = flags;
83437+ __entry->mode = mode;
83438+ ),
83439+
83440+ TP_printk("\"%s\" %x %o",
83441+ __get_str(filename), __entry->flags, __entry->mode)
83442+);
83443+
83444+TRACE_EVENT(open_exec,
83445+
83446+ TP_PROTO(const char *filename),
83447+
83448+ TP_ARGS(filename),
83449+
83450+ TP_STRUCT__entry(
83451+ __string( filename, filename )
83452+ ),
83453+
83454+ TP_fast_assign(
83455+ __assign_str(filename, filename);
83456+ ),
83457+
83458+ TP_printk("\"%s\"",
83459+ __get_str(filename))
83460+);
83461+
83462+#endif /* _TRACE_FS_H */
83463+
83464+/* This part must be outside protection */
83465+#include <trace/define_trace.h>
83466diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
83467index 1c09820..7f5ec79 100644
83468--- a/include/trace/events/irq.h
83469+++ b/include/trace/events/irq.h
83470@@ -36,7 +36,7 @@ struct softirq_action;
83471 */
83472 TRACE_EVENT(irq_handler_entry,
83473
83474- TP_PROTO(int irq, struct irqaction *action),
83475+ TP_PROTO(int irq, const struct irqaction *action),
83476
83477 TP_ARGS(irq, action),
83478
83479@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
83480 */
83481 TRACE_EVENT(irq_handler_exit,
83482
83483- TP_PROTO(int irq, struct irqaction *action, int ret),
83484+ TP_PROTO(int irq, const struct irqaction *action, int ret),
83485
83486 TP_ARGS(irq, action, ret),
83487
83488diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
83489index 7caf44c..23c6f27 100644
83490--- a/include/uapi/linux/a.out.h
83491+++ b/include/uapi/linux/a.out.h
83492@@ -39,6 +39,14 @@ enum machine_type {
83493 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
83494 };
83495
83496+/* Constants for the N_FLAGS field */
83497+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83498+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
83499+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
83500+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
83501+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83502+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83503+
83504 #if !defined (N_MAGIC)
83505 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
83506 #endif
83507diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
83508index d876736..ccce5c0 100644
83509--- a/include/uapi/linux/byteorder/little_endian.h
83510+++ b/include/uapi/linux/byteorder/little_endian.h
83511@@ -42,51 +42,51 @@
83512
83513 static inline __le64 __cpu_to_le64p(const __u64 *p)
83514 {
83515- return (__force __le64)*p;
83516+ return (__force const __le64)*p;
83517 }
83518-static inline __u64 __le64_to_cpup(const __le64 *p)
83519+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
83520 {
83521- return (__force __u64)*p;
83522+ return (__force const __u64)*p;
83523 }
83524 static inline __le32 __cpu_to_le32p(const __u32 *p)
83525 {
83526- return (__force __le32)*p;
83527+ return (__force const __le32)*p;
83528 }
83529 static inline __u32 __le32_to_cpup(const __le32 *p)
83530 {
83531- return (__force __u32)*p;
83532+ return (__force const __u32)*p;
83533 }
83534 static inline __le16 __cpu_to_le16p(const __u16 *p)
83535 {
83536- return (__force __le16)*p;
83537+ return (__force const __le16)*p;
83538 }
83539 static inline __u16 __le16_to_cpup(const __le16 *p)
83540 {
83541- return (__force __u16)*p;
83542+ return (__force const __u16)*p;
83543 }
83544 static inline __be64 __cpu_to_be64p(const __u64 *p)
83545 {
83546- return (__force __be64)__swab64p(p);
83547+ return (__force const __be64)__swab64p(p);
83548 }
83549 static inline __u64 __be64_to_cpup(const __be64 *p)
83550 {
83551- return __swab64p((__u64 *)p);
83552+ return __swab64p((const __u64 *)p);
83553 }
83554 static inline __be32 __cpu_to_be32p(const __u32 *p)
83555 {
83556- return (__force __be32)__swab32p(p);
83557+ return (__force const __be32)__swab32p(p);
83558 }
83559-static inline __u32 __be32_to_cpup(const __be32 *p)
83560+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
83561 {
83562- return __swab32p((__u32 *)p);
83563+ return __swab32p((const __u32 *)p);
83564 }
83565 static inline __be16 __cpu_to_be16p(const __u16 *p)
83566 {
83567- return (__force __be16)__swab16p(p);
83568+ return (__force const __be16)__swab16p(p);
83569 }
83570 static inline __u16 __be16_to_cpup(const __be16 *p)
83571 {
83572- return __swab16p((__u16 *)p);
83573+ return __swab16p((const __u16 *)p);
83574 }
83575 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
83576 #define __le64_to_cpus(x) do { (void)(x); } while (0)
83577diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
83578index ef6103b..d4e65dd 100644
83579--- a/include/uapi/linux/elf.h
83580+++ b/include/uapi/linux/elf.h
83581@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
83582 #define PT_GNU_EH_FRAME 0x6474e550
83583
83584 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
83585+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
83586+
83587+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
83588+
83589+/* Constants for the e_flags field */
83590+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
83591+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
83592+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
83593+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
83594+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
83595+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
83596
83597 /*
83598 * Extended Numbering
83599@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
83600 #define DT_DEBUG 21
83601 #define DT_TEXTREL 22
83602 #define DT_JMPREL 23
83603+#define DT_FLAGS 30
83604+ #define DF_TEXTREL 0x00000004
83605 #define DT_ENCODING 32
83606 #define OLD_DT_LOOS 0x60000000
83607 #define DT_LOOS 0x6000000d
83608@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
83609 #define PF_W 0x2
83610 #define PF_X 0x1
83611
83612+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
83613+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
83614+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
83615+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
83616+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
83617+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
83618+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
83619+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
83620+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
83621+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
83622+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
83623+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
83624+
83625 typedef struct elf32_phdr{
83626 Elf32_Word p_type;
83627 Elf32_Off p_offset;
83628@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
83629 #define EI_OSABI 7
83630 #define EI_PAD 8
83631
83632+#define EI_PAX 14
83633+
83634 #define ELFMAG0 0x7f /* EI_MAG */
83635 #define ELFMAG1 'E'
83636 #define ELFMAG2 'L'
83637diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
83638index aa169c4..6a2771d 100644
83639--- a/include/uapi/linux/personality.h
83640+++ b/include/uapi/linux/personality.h
83641@@ -30,6 +30,7 @@ enum {
83642 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
83643 ADDR_NO_RANDOMIZE | \
83644 ADDR_COMPAT_LAYOUT | \
83645+ ADDR_LIMIT_3GB | \
83646 MMAP_PAGE_ZERO)
83647
83648 /*
83649diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
83650index 7530e74..e714828 100644
83651--- a/include/uapi/linux/screen_info.h
83652+++ b/include/uapi/linux/screen_info.h
83653@@ -43,7 +43,8 @@ struct screen_info {
83654 __u16 pages; /* 0x32 */
83655 __u16 vesa_attributes; /* 0x34 */
83656 __u32 capabilities; /* 0x36 */
83657- __u8 _reserved[6]; /* 0x3a */
83658+ __u16 vesapm_size; /* 0x3a */
83659+ __u8 _reserved[4]; /* 0x3c */
83660 } __attribute__((packed));
83661
83662 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
83663diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
83664index 0e011eb..82681b1 100644
83665--- a/include/uapi/linux/swab.h
83666+++ b/include/uapi/linux/swab.h
83667@@ -43,7 +43,7 @@
83668 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
83669 */
83670
83671-static inline __attribute_const__ __u16 __fswab16(__u16 val)
83672+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
83673 {
83674 #ifdef __HAVE_BUILTIN_BSWAP16__
83675 return __builtin_bswap16(val);
83676@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
83677 #endif
83678 }
83679
83680-static inline __attribute_const__ __u32 __fswab32(__u32 val)
83681+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
83682 {
83683 #ifdef __HAVE_BUILTIN_BSWAP32__
83684 return __builtin_bswap32(val);
83685@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
83686 #endif
83687 }
83688
83689-static inline __attribute_const__ __u64 __fswab64(__u64 val)
83690+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
83691 {
83692 #ifdef __HAVE_BUILTIN_BSWAP64__
83693 return __builtin_bswap64(val);
83694diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
83695index 6d67213..552fdd9 100644
83696--- a/include/uapi/linux/sysctl.h
83697+++ b/include/uapi/linux/sysctl.h
83698@@ -155,8 +155,6 @@ enum
83699 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
83700 };
83701
83702-
83703-
83704 /* CTL_VM names: */
83705 enum
83706 {
83707diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
83708index 437f1b0..0eeb38d 100644
83709--- a/include/uapi/linux/videodev2.h
83710+++ b/include/uapi/linux/videodev2.h
83711@@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
83712 union {
83713 __s32 value;
83714 __s64 value64;
83715- char *string;
83716+ char __user *string;
83717 };
83718 } __attribute__ ((packed));
83719
83720diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
83721index e4629b9..6958086 100644
83722--- a/include/uapi/linux/xattr.h
83723+++ b/include/uapi/linux/xattr.h
83724@@ -63,5 +63,9 @@
83725 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
83726 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
83727
83728+/* User namespace */
83729+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
83730+#define XATTR_PAX_FLAGS_SUFFIX "flags"
83731+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
83732
83733 #endif /* _UAPI_LINUX_XATTR_H */
83734diff --git a/include/video/udlfb.h b/include/video/udlfb.h
83735index f9466fa..f4e2b81 100644
83736--- a/include/video/udlfb.h
83737+++ b/include/video/udlfb.h
83738@@ -53,10 +53,10 @@ struct dlfb_data {
83739 u32 pseudo_palette[256];
83740 int blank_mode; /*one of FB_BLANK_ */
83741 /* blit-only rendering path metrics, exposed through sysfs */
83742- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83743- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
83744- atomic_t bytes_sent; /* to usb, after compression including overhead */
83745- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
83746+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
83747+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
83748+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
83749+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
83750 };
83751
83752 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
83753diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
83754index 30f5362..8ed8ac9 100644
83755--- a/include/video/uvesafb.h
83756+++ b/include/video/uvesafb.h
83757@@ -122,6 +122,7 @@ struct uvesafb_par {
83758 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
83759 u8 pmi_setpal; /* PMI for palette changes */
83760 u16 *pmi_base; /* protected mode interface location */
83761+ u8 *pmi_code; /* protected mode code location */
83762 void *pmi_start;
83763 void *pmi_pal;
83764 u8 *vbe_state_orig; /*
83765diff --git a/init/Kconfig b/init/Kconfig
83766index 66e6759..1333b01 100644
83767--- a/init/Kconfig
83768+++ b/init/Kconfig
83769@@ -1079,6 +1079,7 @@ endif # CGROUPS
83770
83771 config CHECKPOINT_RESTORE
83772 bool "Checkpoint/restore support" if EXPERT
83773+ depends on !GRKERNSEC
83774 default n
83775 help
83776 Enables additional kernel features in a sake of checkpoint/restore.
83777@@ -1557,7 +1558,7 @@ config SLUB_DEBUG
83778
83779 config COMPAT_BRK
83780 bool "Disable heap randomization"
83781- default y
83782+ default n
83783 help
83784 Randomizing heap placement makes heap exploits harder, but it
83785 also breaks ancient binaries (including anything libc5 based).
83786@@ -1845,7 +1846,7 @@ config INIT_ALL_POSSIBLE
83787 config STOP_MACHINE
83788 bool
83789 default y
83790- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
83791+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
83792 help
83793 Need stop_machine() primitive.
83794
83795diff --git a/init/Makefile b/init/Makefile
83796index 7bc47ee..6da2dc7 100644
83797--- a/init/Makefile
83798+++ b/init/Makefile
83799@@ -2,6 +2,9 @@
83800 # Makefile for the linux kernel.
83801 #
83802
83803+ccflags-y := $(GCC_PLUGINS_CFLAGS)
83804+asflags-y := $(GCC_PLUGINS_AFLAGS)
83805+
83806 obj-y := main.o version.o mounts.o
83807 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
83808 obj-y += noinitramfs.o
83809diff --git a/init/do_mounts.c b/init/do_mounts.c
83810index 8e5addc..c96ea61 100644
83811--- a/init/do_mounts.c
83812+++ b/init/do_mounts.c
83813@@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
83814 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
83815 {
83816 struct super_block *s;
83817- int err = sys_mount(name, "/root", fs, flags, data);
83818+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
83819 if (err)
83820 return err;
83821
83822- sys_chdir("/root");
83823+ sys_chdir((const char __force_user *)"/root");
83824 s = current->fs->pwd.dentry->d_sb;
83825 ROOT_DEV = s->s_dev;
83826 printk(KERN_INFO
83827@@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
83828 va_start(args, fmt);
83829 vsprintf(buf, fmt, args);
83830 va_end(args);
83831- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
83832+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
83833 if (fd >= 0) {
83834 sys_ioctl(fd, FDEJECT, 0);
83835 sys_close(fd);
83836 }
83837 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
83838- fd = sys_open("/dev/console", O_RDWR, 0);
83839+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
83840 if (fd >= 0) {
83841 sys_ioctl(fd, TCGETS, (long)&termios);
83842 termios.c_lflag &= ~ICANON;
83843 sys_ioctl(fd, TCSETSF, (long)&termios);
83844- sys_read(fd, &c, 1);
83845+ sys_read(fd, (char __user *)&c, 1);
83846 termios.c_lflag |= ICANON;
83847 sys_ioctl(fd, TCSETSF, (long)&termios);
83848 sys_close(fd);
83849@@ -589,8 +589,8 @@ void __init prepare_namespace(void)
83850 mount_root();
83851 out:
83852 devtmpfs_mount("dev");
83853- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83854- sys_chroot(".");
83855+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83856+ sys_chroot((const char __force_user *)".");
83857 }
83858
83859 static bool is_tmpfs;
83860diff --git a/init/do_mounts.h b/init/do_mounts.h
83861index f5b978a..69dbfe8 100644
83862--- a/init/do_mounts.h
83863+++ b/init/do_mounts.h
83864@@ -15,15 +15,15 @@ extern int root_mountflags;
83865
83866 static inline int create_dev(char *name, dev_t dev)
83867 {
83868- sys_unlink(name);
83869- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
83870+ sys_unlink((char __force_user *)name);
83871+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
83872 }
83873
83874 #if BITS_PER_LONG == 32
83875 static inline u32 bstat(char *name)
83876 {
83877 struct stat64 stat;
83878- if (sys_stat64(name, &stat) != 0)
83879+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
83880 return 0;
83881 if (!S_ISBLK(stat.st_mode))
83882 return 0;
83883@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
83884 static inline u32 bstat(char *name)
83885 {
83886 struct stat stat;
83887- if (sys_newstat(name, &stat) != 0)
83888+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
83889 return 0;
83890 if (!S_ISBLK(stat.st_mode))
83891 return 0;
83892diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
83893index 3e0878e..8a9d7a0 100644
83894--- a/init/do_mounts_initrd.c
83895+++ b/init/do_mounts_initrd.c
83896@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
83897 {
83898 sys_unshare(CLONE_FS | CLONE_FILES);
83899 /* stdin/stdout/stderr for /linuxrc */
83900- sys_open("/dev/console", O_RDWR, 0);
83901+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
83902 sys_dup(0);
83903 sys_dup(0);
83904 /* move initrd over / and chdir/chroot in initrd root */
83905- sys_chdir("/root");
83906- sys_mount(".", "/", NULL, MS_MOVE, NULL);
83907- sys_chroot(".");
83908+ sys_chdir((const char __force_user *)"/root");
83909+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
83910+ sys_chroot((const char __force_user *)".");
83911 sys_setsid();
83912 return 0;
83913 }
83914@@ -59,8 +59,8 @@ static void __init handle_initrd(void)
83915 create_dev("/dev/root.old", Root_RAM0);
83916 /* mount initrd on rootfs' /root */
83917 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
83918- sys_mkdir("/old", 0700);
83919- sys_chdir("/old");
83920+ sys_mkdir((const char __force_user *)"/old", 0700);
83921+ sys_chdir((const char __force_user *)"/old");
83922
83923 /* try loading default modules from initrd */
83924 load_default_modules();
83925@@ -80,31 +80,31 @@ static void __init handle_initrd(void)
83926 current->flags &= ~PF_FREEZER_SKIP;
83927
83928 /* move initrd to rootfs' /old */
83929- sys_mount("..", ".", NULL, MS_MOVE, NULL);
83930+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
83931 /* switch root and cwd back to / of rootfs */
83932- sys_chroot("..");
83933+ sys_chroot((const char __force_user *)"..");
83934
83935 if (new_decode_dev(real_root_dev) == Root_RAM0) {
83936- sys_chdir("/old");
83937+ sys_chdir((const char __force_user *)"/old");
83938 return;
83939 }
83940
83941- sys_chdir("/");
83942+ sys_chdir((const char __force_user *)"/");
83943 ROOT_DEV = new_decode_dev(real_root_dev);
83944 mount_root();
83945
83946 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
83947- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
83948+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
83949 if (!error)
83950 printk("okay\n");
83951 else {
83952- int fd = sys_open("/dev/root.old", O_RDWR, 0);
83953+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
83954 if (error == -ENOENT)
83955 printk("/initrd does not exist. Ignored.\n");
83956 else
83957 printk("failed\n");
83958 printk(KERN_NOTICE "Unmounting old root\n");
83959- sys_umount("/old", MNT_DETACH);
83960+ sys_umount((char __force_user *)"/old", MNT_DETACH);
83961 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
83962 if (fd < 0) {
83963 error = fd;
83964@@ -127,11 +127,11 @@ int __init initrd_load(void)
83965 * mounted in the normal path.
83966 */
83967 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
83968- sys_unlink("/initrd.image");
83969+ sys_unlink((const char __force_user *)"/initrd.image");
83970 handle_initrd();
83971 return 1;
83972 }
83973 }
83974- sys_unlink("/initrd.image");
83975+ sys_unlink((const char __force_user *)"/initrd.image");
83976 return 0;
83977 }
83978diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
83979index 8cb6db5..d729f50 100644
83980--- a/init/do_mounts_md.c
83981+++ b/init/do_mounts_md.c
83982@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
83983 partitioned ? "_d" : "", minor,
83984 md_setup_args[ent].device_names);
83985
83986- fd = sys_open(name, 0, 0);
83987+ fd = sys_open((char __force_user *)name, 0, 0);
83988 if (fd < 0) {
83989 printk(KERN_ERR "md: open failed - cannot start "
83990 "array %s\n", name);
83991@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
83992 * array without it
83993 */
83994 sys_close(fd);
83995- fd = sys_open(name, 0, 0);
83996+ fd = sys_open((char __force_user *)name, 0, 0);
83997 sys_ioctl(fd, BLKRRPART, 0);
83998 }
83999 sys_close(fd);
84000@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84001
84002 wait_for_device_probe();
84003
84004- fd = sys_open("/dev/md0", 0, 0);
84005+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84006 if (fd >= 0) {
84007 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84008 sys_close(fd);
84009diff --git a/init/init_task.c b/init/init_task.c
84010index ba0a7f36..2bcf1d5 100644
84011--- a/init/init_task.c
84012+++ b/init/init_task.c
84013@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84014 * Initial thread structure. Alignment of this is handled by a special
84015 * linker map entry.
84016 */
84017+#ifdef CONFIG_X86
84018+union thread_union init_thread_union __init_task_data;
84019+#else
84020 union thread_union init_thread_union __init_task_data =
84021 { INIT_THREAD_INFO(init_task) };
84022+#endif
84023diff --git a/init/initramfs.c b/init/initramfs.c
84024index a67ef9d..2d17ed9 100644
84025--- a/init/initramfs.c
84026+++ b/init/initramfs.c
84027@@ -84,7 +84,7 @@ static void __init free_hash(void)
84028 }
84029 }
84030
84031-static long __init do_utime(char *filename, time_t mtime)
84032+static long __init do_utime(char __force_user *filename, time_t mtime)
84033 {
84034 struct timespec t[2];
84035
84036@@ -119,7 +119,7 @@ static void __init dir_utime(void)
84037 struct dir_entry *de, *tmp;
84038 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84039 list_del(&de->list);
84040- do_utime(de->name, de->mtime);
84041+ do_utime((char __force_user *)de->name, de->mtime);
84042 kfree(de->name);
84043 kfree(de);
84044 }
84045@@ -281,7 +281,7 @@ static int __init maybe_link(void)
84046 if (nlink >= 2) {
84047 char *old = find_link(major, minor, ino, mode, collected);
84048 if (old)
84049- return (sys_link(old, collected) < 0) ? -1 : 1;
84050+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84051 }
84052 return 0;
84053 }
84054@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84055 {
84056 struct stat st;
84057
84058- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84059+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84060 if (S_ISDIR(st.st_mode))
84061- sys_rmdir(path);
84062+ sys_rmdir((char __force_user *)path);
84063 else
84064- sys_unlink(path);
84065+ sys_unlink((char __force_user *)path);
84066 }
84067 }
84068
84069@@ -315,7 +315,7 @@ static int __init do_name(void)
84070 int openflags = O_WRONLY|O_CREAT;
84071 if (ml != 1)
84072 openflags |= O_TRUNC;
84073- wfd = sys_open(collected, openflags, mode);
84074+ wfd = sys_open((char __force_user *)collected, openflags, mode);
84075
84076 if (wfd >= 0) {
84077 sys_fchown(wfd, uid, gid);
84078@@ -327,17 +327,17 @@ static int __init do_name(void)
84079 }
84080 }
84081 } else if (S_ISDIR(mode)) {
84082- sys_mkdir(collected, mode);
84083- sys_chown(collected, uid, gid);
84084- sys_chmod(collected, mode);
84085+ sys_mkdir((char __force_user *)collected, mode);
84086+ sys_chown((char __force_user *)collected, uid, gid);
84087+ sys_chmod((char __force_user *)collected, mode);
84088 dir_add(collected, mtime);
84089 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84090 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84091 if (maybe_link() == 0) {
84092- sys_mknod(collected, mode, rdev);
84093- sys_chown(collected, uid, gid);
84094- sys_chmod(collected, mode);
84095- do_utime(collected, mtime);
84096+ sys_mknod((char __force_user *)collected, mode, rdev);
84097+ sys_chown((char __force_user *)collected, uid, gid);
84098+ sys_chmod((char __force_user *)collected, mode);
84099+ do_utime((char __force_user *)collected, mtime);
84100 }
84101 }
84102 return 0;
84103@@ -346,15 +346,15 @@ static int __init do_name(void)
84104 static int __init do_copy(void)
84105 {
84106 if (count >= body_len) {
84107- sys_write(wfd, victim, body_len);
84108+ sys_write(wfd, (char __force_user *)victim, body_len);
84109 sys_close(wfd);
84110- do_utime(vcollected, mtime);
84111+ do_utime((char __force_user *)vcollected, mtime);
84112 kfree(vcollected);
84113 eat(body_len);
84114 state = SkipIt;
84115 return 0;
84116 } else {
84117- sys_write(wfd, victim, count);
84118+ sys_write(wfd, (char __force_user *)victim, count);
84119 body_len -= count;
84120 eat(count);
84121 return 1;
84122@@ -365,9 +365,9 @@ static int __init do_symlink(void)
84123 {
84124 collected[N_ALIGN(name_len) + body_len] = '\0';
84125 clean_path(collected, 0);
84126- sys_symlink(collected + N_ALIGN(name_len), collected);
84127- sys_lchown(collected, uid, gid);
84128- do_utime(collected, mtime);
84129+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
84130+ sys_lchown((char __force_user *)collected, uid, gid);
84131+ do_utime((char __force_user *)collected, mtime);
84132 state = SkipIt;
84133 next_state = Reset;
84134 return 0;
84135@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
84136 {
84137 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
84138 if (err)
84139- panic(err); /* Failed to decompress INTERNAL initramfs */
84140+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
84141 if (initrd_start) {
84142 #ifdef CONFIG_BLK_DEV_RAM
84143 int fd;
84144diff --git a/init/main.c b/init/main.c
84145index febc511..f0851763 100644
84146--- a/init/main.c
84147+++ b/init/main.c
84148@@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
84149 extern void tc_init(void);
84150 #endif
84151
84152+extern void grsecurity_init(void);
84153+
84154 /*
84155 * Debug helper: via this flag we know that we are in 'early bootup code'
84156 * where only the boot processor is running with IRQ disabled. This means
84157@@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
84158
84159 __setup("reset_devices", set_reset_devices);
84160
84161+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
84162+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
84163+static int __init setup_grsec_proc_gid(char *str)
84164+{
84165+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
84166+ return 1;
84167+}
84168+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
84169+#endif
84170+
84171+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
84172+unsigned long pax_user_shadow_base __read_only;
84173+EXPORT_SYMBOL(pax_user_shadow_base);
84174+extern char pax_enter_kernel_user[];
84175+extern char pax_exit_kernel_user[];
84176+#endif
84177+
84178+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
84179+static int __init setup_pax_nouderef(char *str)
84180+{
84181+#ifdef CONFIG_X86_32
84182+ unsigned int cpu;
84183+ struct desc_struct *gdt;
84184+
84185+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
84186+ gdt = get_cpu_gdt_table(cpu);
84187+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
84188+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
84189+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
84190+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
84191+ }
84192+ loadsegment(ds, __KERNEL_DS);
84193+ loadsegment(es, __KERNEL_DS);
84194+ loadsegment(ss, __KERNEL_DS);
84195+#else
84196+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
84197+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
84198+ clone_pgd_mask = ~(pgdval_t)0UL;
84199+ pax_user_shadow_base = 0UL;
84200+ setup_clear_cpu_cap(X86_FEATURE_PCID);
84201+ setup_clear_cpu_cap(X86_FEATURE_INVPCID);
84202+#endif
84203+
84204+ return 0;
84205+}
84206+early_param("pax_nouderef", setup_pax_nouderef);
84207+
84208+#ifdef CONFIG_X86_64
84209+static int __init setup_pax_weakuderef(char *str)
84210+{
84211+ if (clone_pgd_mask != ~(pgdval_t)0UL)
84212+ pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
84213+ return 1;
84214+}
84215+__setup("pax_weakuderef", setup_pax_weakuderef);
84216+#endif
84217+#endif
84218+
84219+#ifdef CONFIG_PAX_SOFTMODE
84220+int pax_softmode;
84221+
84222+static int __init setup_pax_softmode(char *str)
84223+{
84224+ get_option(&str, &pax_softmode);
84225+ return 1;
84226+}
84227+__setup("pax_softmode=", setup_pax_softmode);
84228+#endif
84229+
84230 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
84231 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
84232 static const char *panic_later, *panic_param;
84233@@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
84234 {
84235 int count = preempt_count();
84236 int ret;
84237- char msgbuf[64];
84238+ const char *msg1 = "", *msg2 = "";
84239
84240 if (initcall_debug)
84241 ret = do_one_initcall_debug(fn);
84242 else
84243 ret = fn();
84244
84245- msgbuf[0] = 0;
84246-
84247 if (preempt_count() != count) {
84248- sprintf(msgbuf, "preemption imbalance ");
84249+ msg1 = " preemption imbalance";
84250 preempt_count_set(count);
84251 }
84252 if (irqs_disabled()) {
84253- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
84254+ msg2 = " disabled interrupts";
84255 local_irq_enable();
84256 }
84257- WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
84258+ WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
84259
84260+ add_latent_entropy();
84261 return ret;
84262 }
84263
84264@@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
84265 {
84266 argv_init[0] = init_filename;
84267 return do_execve(init_filename,
84268- (const char __user *const __user *)argv_init,
84269- (const char __user *const __user *)envp_init);
84270+ (const char __user *const __force_user *)argv_init,
84271+ (const char __user *const __force_user *)envp_init);
84272 }
84273
84274 static int try_to_run_init_process(const char *init_filename)
84275@@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
84276 return ret;
84277 }
84278
84279+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84280+extern int gr_init_ran;
84281+#endif
84282+
84283 static noinline void __init kernel_init_freeable(void);
84284
84285 static int __ref kernel_init(void *unused)
84286@@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
84287 ramdisk_execute_command, ret);
84288 }
84289
84290+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
84291+ /* if no initrd was used, be extra sure we enforce chroot restrictions */
84292+ gr_init_ran = 1;
84293+#endif
84294+
84295 /*
84296 * We try each of these until one succeeds.
84297 *
84298@@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
84299 do_basic_setup();
84300
84301 /* Open the /dev/console on the rootfs, this should never fail */
84302- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
84303+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
84304 pr_err("Warning: unable to open an initial console.\n");
84305
84306 (void) sys_dup(0);
84307@@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
84308 if (!ramdisk_execute_command)
84309 ramdisk_execute_command = "/init";
84310
84311- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
84312+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
84313 ramdisk_execute_command = NULL;
84314 prepare_namespace();
84315 }
84316
84317+ grsecurity_init();
84318+
84319 /*
84320 * Ok, we have completed the initial bootup, and
84321 * we're essentially up and running. Get rid of the
84322diff --git a/ipc/compat.c b/ipc/compat.c
84323index 892f658..e7c6320 100644
84324--- a/ipc/compat.c
84325+++ b/ipc/compat.c
84326@@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
84327 COMPAT_SHMLBA);
84328 if (err < 0)
84329 return err;
84330- return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
84331+ return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
84332 }
84333 case SHMDT:
84334 return sys_shmdt(compat_ptr(ptr));
84335diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
84336index b0e99de..09f385c 100644
84337--- a/ipc/ipc_sysctl.c
84338+++ b/ipc/ipc_sysctl.c
84339@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
84340 static int proc_ipc_dointvec(ctl_table *table, int write,
84341 void __user *buffer, size_t *lenp, loff_t *ppos)
84342 {
84343- struct ctl_table ipc_table;
84344+ ctl_table_no_const ipc_table;
84345
84346 memcpy(&ipc_table, table, sizeof(ipc_table));
84347 ipc_table.data = get_ipc(table);
84348@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
84349 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
84350 void __user *buffer, size_t *lenp, loff_t *ppos)
84351 {
84352- struct ctl_table ipc_table;
84353+ ctl_table_no_const ipc_table;
84354
84355 memcpy(&ipc_table, table, sizeof(ipc_table));
84356 ipc_table.data = get_ipc(table);
84357@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
84358 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84359 void __user *buffer, size_t *lenp, loff_t *ppos)
84360 {
84361- struct ctl_table ipc_table;
84362+ ctl_table_no_const ipc_table;
84363 size_t lenp_bef = *lenp;
84364 int rc;
84365
84366@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
84367 static int proc_ipc_doulongvec_minmax(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 memcpy(&ipc_table, table, sizeof(ipc_table));
84373 ipc_table.data = get_ipc(table);
84374
84375@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
84376 static int proc_ipcauto_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 size_t lenp_bef = *lenp;
84382 int oldval;
84383 int rc;
84384diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
84385index 5bb8bfe..a38ec05 100644
84386--- a/ipc/mq_sysctl.c
84387+++ b/ipc/mq_sysctl.c
84388@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
84389 static int proc_mq_dointvec(ctl_table *table, int write,
84390 void __user *buffer, size_t *lenp, loff_t *ppos)
84391 {
84392- struct ctl_table mq_table;
84393+ ctl_table_no_const mq_table;
84394 memcpy(&mq_table, table, sizeof(mq_table));
84395 mq_table.data = get_mq(table);
84396
84397@@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
84398 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
84399 void __user *buffer, size_t *lenp, loff_t *ppos)
84400 {
84401- struct ctl_table mq_table;
84402+ ctl_table_no_const mq_table;
84403 memcpy(&mq_table, table, sizeof(mq_table));
84404 mq_table.data = get_mq(table);
84405
84406diff --git a/ipc/mqueue.c b/ipc/mqueue.c
84407index b8d4aed..96a4fe8 100644
84408--- a/ipc/mqueue.c
84409+++ b/ipc/mqueue.c
84410@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
84411 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
84412 info->attr.mq_msgsize);
84413
84414+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
84415 spin_lock(&mq_lock);
84416 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
84417 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
84418diff --git a/ipc/msg.c b/ipc/msg.c
84419index 52770bf..1c60a6f 100644
84420--- a/ipc/msg.c
84421+++ b/ipc/msg.c
84422@@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
84423 return security_msg_queue_associate(msq, msgflg);
84424 }
84425
84426+static struct ipc_ops msg_ops = {
84427+ .getnew = newque,
84428+ .associate = msg_security,
84429+ .more_checks = NULL
84430+};
84431+
84432 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
84433 {
84434 struct ipc_namespace *ns;
84435- struct ipc_ops msg_ops;
84436 struct ipc_params msg_params;
84437
84438 ns = current->nsproxy->ipc_ns;
84439
84440- msg_ops.getnew = newque;
84441- msg_ops.associate = msg_security;
84442- msg_ops.more_checks = NULL;
84443-
84444 msg_params.key = key;
84445 msg_params.flg = msgflg;
84446
84447diff --git a/ipc/sem.c b/ipc/sem.c
84448index db9d241..bc8427c 100644
84449--- a/ipc/sem.c
84450+++ b/ipc/sem.c
84451@@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
84452 return 0;
84453 }
84454
84455+static struct ipc_ops sem_ops = {
84456+ .getnew = newary,
84457+ .associate = sem_security,
84458+ .more_checks = sem_more_checks
84459+};
84460+
84461 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84462 {
84463 struct ipc_namespace *ns;
84464- struct ipc_ops sem_ops;
84465 struct ipc_params sem_params;
84466
84467 ns = current->nsproxy->ipc_ns;
84468@@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
84469 if (nsems < 0 || nsems > ns->sc_semmsl)
84470 return -EINVAL;
84471
84472- sem_ops.getnew = newary;
84473- sem_ops.associate = sem_security;
84474- sem_ops.more_checks = sem_more_checks;
84475-
84476 sem_params.key = key;
84477 sem_params.flg = semflg;
84478 sem_params.u.nsems = nsems;
84479diff --git a/ipc/shm.c b/ipc/shm.c
84480index 7a51443..3a257d8 100644
84481--- a/ipc/shm.c
84482+++ b/ipc/shm.c
84483@@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
84484 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
84485 #endif
84486
84487+#ifdef CONFIG_GRKERNSEC
84488+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84489+ const time_t shm_createtime, const kuid_t cuid,
84490+ const int shmid);
84491+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
84492+ const time_t shm_createtime);
84493+#endif
84494+
84495 void shm_init_ns(struct ipc_namespace *ns)
84496 {
84497 ns->shm_ctlmax = SHMMAX;
84498@@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
84499 shp->shm_lprid = 0;
84500 shp->shm_atim = shp->shm_dtim = 0;
84501 shp->shm_ctim = get_seconds();
84502+#ifdef CONFIG_GRKERNSEC
84503+ {
84504+ struct timespec timeval;
84505+ do_posix_clock_monotonic_gettime(&timeval);
84506+
84507+ shp->shm_createtime = timeval.tv_sec;
84508+ }
84509+#endif
84510 shp->shm_segsz = size;
84511 shp->shm_nattch = 0;
84512 shp->shm_file = file;
84513@@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
84514 return 0;
84515 }
84516
84517+static struct ipc_ops shm_ops = {
84518+ .getnew = newseg,
84519+ .associate = shm_security,
84520+ .more_checks = shm_more_checks
84521+};
84522+
84523 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
84524 {
84525 struct ipc_namespace *ns;
84526- struct ipc_ops shm_ops;
84527 struct ipc_params shm_params;
84528
84529 ns = current->nsproxy->ipc_ns;
84530
84531- shm_ops.getnew = newseg;
84532- shm_ops.associate = shm_security;
84533- shm_ops.more_checks = shm_more_checks;
84534-
84535 shm_params.key = key;
84536 shm_params.flg = shmflg;
84537 shm_params.u.size = size;
84538@@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84539 f_mode = FMODE_READ | FMODE_WRITE;
84540 }
84541 if (shmflg & SHM_EXEC) {
84542+
84543+#ifdef CONFIG_PAX_MPROTECT
84544+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
84545+ goto out;
84546+#endif
84547+
84548 prot |= PROT_EXEC;
84549 acc_mode |= S_IXUGO;
84550 }
84551@@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84552 if (err)
84553 goto out_unlock;
84554
84555+#ifdef CONFIG_GRKERNSEC
84556+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
84557+ shp->shm_perm.cuid, shmid) ||
84558+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
84559+ err = -EACCES;
84560+ goto out_unlock;
84561+ }
84562+#endif
84563+
84564 ipc_lock_object(&shp->shm_perm);
84565
84566 /* check if shm_destroy() is tearing down shp */
84567@@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
84568 path = shp->shm_file->f_path;
84569 path_get(&path);
84570 shp->shm_nattch++;
84571+#ifdef CONFIG_GRKERNSEC
84572+ shp->shm_lapid = current->pid;
84573+#endif
84574 size = i_size_read(path.dentry->d_inode);
84575 ipc_unlock_object(&shp->shm_perm);
84576 rcu_read_unlock();
84577diff --git a/ipc/util.c b/ipc/util.c
84578index 3ae17a4..d67c32f 100644
84579--- a/ipc/util.c
84580+++ b/ipc/util.c
84581@@ -71,6 +71,8 @@ struct ipc_proc_iface {
84582 int (*show)(struct seq_file *, void *);
84583 };
84584
84585+extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
84586+
84587 static void ipc_memory_notifier(struct work_struct *work)
84588 {
84589 ipcns_notify(IPCNS_MEMCHANGED);
84590@@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
84591 granted_mode >>= 6;
84592 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
84593 granted_mode >>= 3;
84594+
84595+ if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
84596+ return -1;
84597+
84598 /* is there some bit set in requested_mode but not in granted_mode? */
84599 if ((requested_mode & ~granted_mode & 0007) &&
84600 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
84601diff --git a/kernel/acct.c b/kernel/acct.c
84602index 8d6e145..33e0b1e 100644
84603--- a/kernel/acct.c
84604+++ b/kernel/acct.c
84605@@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
84606 */
84607 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
84608 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
84609- file->f_op->write(file, (char *)&ac,
84610+ file->f_op->write(file, (char __force_user *)&ac,
84611 sizeof(acct_t), &file->f_pos);
84612 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
84613 set_fs(fs);
84614diff --git a/kernel/audit.c b/kernel/audit.c
84615index 15ec13a..986322e 100644
84616--- a/kernel/audit.c
84617+++ b/kernel/audit.c
84618@@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
84619 3) suppressed due to audit_rate_limit
84620 4) suppressed due to audit_backlog_limit
84621 */
84622-static atomic_t audit_lost = ATOMIC_INIT(0);
84623+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
84624
84625 /* The netlink socket. */
84626 static struct sock *audit_sock;
84627@@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
84628 unsigned long now;
84629 int print;
84630
84631- atomic_inc(&audit_lost);
84632+ atomic_inc_unchecked(&audit_lost);
84633
84634 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
84635
84636@@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
84637 printk(KERN_WARNING
84638 "audit: audit_lost=%d audit_rate_limit=%d "
84639 "audit_backlog_limit=%d\n",
84640- atomic_read(&audit_lost),
84641+ atomic_read_unchecked(&audit_lost),
84642 audit_rate_limit,
84643 audit_backlog_limit);
84644 audit_panic(message);
84645@@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84646 status_set.pid = audit_pid;
84647 status_set.rate_limit = audit_rate_limit;
84648 status_set.backlog_limit = audit_backlog_limit;
84649- status_set.lost = atomic_read(&audit_lost);
84650+ status_set.lost = atomic_read_unchecked(&audit_lost);
84651 status_set.backlog = skb_queue_len(&audit_skb_queue);
84652 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
84653 &status_set, sizeof(status_set));
84654@@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
84655 int i, avail, new_len;
84656 unsigned char *ptr;
84657 struct sk_buff *skb;
84658- static const unsigned char *hex = "0123456789ABCDEF";
84659+ static const unsigned char hex[] = "0123456789ABCDEF";
84660
84661 if (!ab)
84662 return;
84663diff --git a/kernel/auditsc.c b/kernel/auditsc.c
84664index ff32843..27fc708 100644
84665--- a/kernel/auditsc.c
84666+++ b/kernel/auditsc.c
84667@@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
84668 }
84669
84670 /* global counter which is incremented every time something logs in */
84671-static atomic_t session_id = ATOMIC_INIT(0);
84672+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
84673
84674 static int audit_set_loginuid_perm(kuid_t loginuid)
84675 {
84676@@ -2011,7 +2011,7 @@ int audit_set_loginuid(kuid_t loginuid)
84677
84678 /* are we setting or clearing? */
84679 if (uid_valid(loginuid))
84680- sessionid = atomic_inc_return(&session_id);
84681+ sessionid = atomic_inc_return_unchecked(&session_id);
84682
84683 task->sessionid = sessionid;
84684 task->loginuid = loginuid;
84685diff --git a/kernel/capability.c b/kernel/capability.c
84686index 4e66bf9..cdccecf 100644
84687--- a/kernel/capability.c
84688+++ b/kernel/capability.c
84689@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
84690 * before modification is attempted and the application
84691 * fails.
84692 */
84693+ if (tocopy > ARRAY_SIZE(kdata))
84694+ return -EFAULT;
84695+
84696 if (copy_to_user(dataptr, kdata, tocopy
84697 * sizeof(struct __user_cap_data_struct))) {
84698 return -EFAULT;
84699@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
84700 int ret;
84701
84702 rcu_read_lock();
84703- ret = security_capable(__task_cred(t), ns, cap);
84704+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
84705+ gr_task_is_capable(t, __task_cred(t), cap);
84706 rcu_read_unlock();
84707
84708- return (ret == 0);
84709+ return ret;
84710 }
84711
84712 /**
84713@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
84714 int ret;
84715
84716 rcu_read_lock();
84717- ret = security_capable_noaudit(__task_cred(t), ns, cap);
84718+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
84719 rcu_read_unlock();
84720
84721- return (ret == 0);
84722+ return ret;
84723 }
84724
84725 /**
84726@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
84727 BUG();
84728 }
84729
84730- if (security_capable(current_cred(), ns, cap) == 0) {
84731+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
84732 current->flags |= PF_SUPERPRIV;
84733 return true;
84734 }
84735@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
84736 }
84737 EXPORT_SYMBOL(ns_capable);
84738
84739+bool ns_capable_nolog(struct user_namespace *ns, int cap)
84740+{
84741+ if (unlikely(!cap_valid(cap))) {
84742+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
84743+ BUG();
84744+ }
84745+
84746+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
84747+ current->flags |= PF_SUPERPRIV;
84748+ return true;
84749+ }
84750+ return false;
84751+}
84752+EXPORT_SYMBOL(ns_capable_nolog);
84753+
84754 /**
84755 * file_ns_capable - Determine if the file's opener had a capability in effect
84756 * @file: The file we want to check
84757@@ -432,6 +451,12 @@ bool capable(int cap)
84758 }
84759 EXPORT_SYMBOL(capable);
84760
84761+bool capable_nolog(int cap)
84762+{
84763+ return ns_capable_nolog(&init_user_ns, cap);
84764+}
84765+EXPORT_SYMBOL(capable_nolog);
84766+
84767 /**
84768 * inode_capable - Check superior capability over inode
84769 * @inode: The inode in question
84770@@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
84771 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84772 }
84773 EXPORT_SYMBOL(inode_capable);
84774+
84775+bool inode_capable_nolog(const struct inode *inode, int cap)
84776+{
84777+ struct user_namespace *ns = current_user_ns();
84778+
84779+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
84780+}
84781+EXPORT_SYMBOL(inode_capable_nolog);
84782diff --git a/kernel/cgroup.c b/kernel/cgroup.c
84783index b44dd49..94c2826 100644
84784--- a/kernel/cgroup.c
84785+++ b/kernel/cgroup.c
84786@@ -5609,7 +5609,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
84787 struct css_set *cset = link->cset;
84788 struct task_struct *task;
84789 int count = 0;
84790- seq_printf(seq, "css_set %p\n", cset);
84791+ seq_printf(seq, "css_set %pK\n", cset);
84792 list_for_each_entry(task, &cset->tasks, cg_list) {
84793 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
84794 seq_puts(seq, " ...\n");
84795diff --git a/kernel/compat.c b/kernel/compat.c
84796index 0a09e48..b46b3d78 100644
84797--- a/kernel/compat.c
84798+++ b/kernel/compat.c
84799@@ -13,6 +13,7 @@
84800
84801 #include <linux/linkage.h>
84802 #include <linux/compat.h>
84803+#include <linux/module.h>
84804 #include <linux/errno.h>
84805 #include <linux/time.h>
84806 #include <linux/signal.h>
84807@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
84808 mm_segment_t oldfs;
84809 long ret;
84810
84811- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
84812+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
84813 oldfs = get_fs();
84814 set_fs(KERNEL_DS);
84815 ret = hrtimer_nanosleep_restart(restart);
84816@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
84817 oldfs = get_fs();
84818 set_fs(KERNEL_DS);
84819 ret = hrtimer_nanosleep(&tu,
84820- rmtp ? (struct timespec __user *)&rmt : NULL,
84821+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
84822 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
84823 set_fs(oldfs);
84824
84825@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
84826 mm_segment_t old_fs = get_fs();
84827
84828 set_fs(KERNEL_DS);
84829- ret = sys_sigpending((old_sigset_t __user *) &s);
84830+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
84831 set_fs(old_fs);
84832 if (ret == 0)
84833 ret = put_user(s, set);
84834@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
84835 mm_segment_t old_fs = get_fs();
84836
84837 set_fs(KERNEL_DS);
84838- ret = sys_old_getrlimit(resource, &r);
84839+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
84840 set_fs(old_fs);
84841
84842 if (!ret) {
84843@@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
84844 set_fs (KERNEL_DS);
84845 ret = sys_wait4(pid,
84846 (stat_addr ?
84847- (unsigned int __user *) &status : NULL),
84848- options, (struct rusage __user *) &r);
84849+ (unsigned int __force_user *) &status : NULL),
84850+ options, (struct rusage __force_user *) &r);
84851 set_fs (old_fs);
84852
84853 if (ret > 0) {
84854@@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
84855 memset(&info, 0, sizeof(info));
84856
84857 set_fs(KERNEL_DS);
84858- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
84859- uru ? (struct rusage __user *)&ru : NULL);
84860+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
84861+ uru ? (struct rusage __force_user *)&ru : NULL);
84862 set_fs(old_fs);
84863
84864 if ((ret < 0) || (info.si_signo == 0))
84865@@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
84866 oldfs = get_fs();
84867 set_fs(KERNEL_DS);
84868 err = sys_timer_settime(timer_id, flags,
84869- (struct itimerspec __user *) &newts,
84870- (struct itimerspec __user *) &oldts);
84871+ (struct itimerspec __force_user *) &newts,
84872+ (struct itimerspec __force_user *) &oldts);
84873 set_fs(oldfs);
84874 if (!err && old && put_compat_itimerspec(old, &oldts))
84875 return -EFAULT;
84876@@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
84877 oldfs = get_fs();
84878 set_fs(KERNEL_DS);
84879 err = sys_timer_gettime(timer_id,
84880- (struct itimerspec __user *) &ts);
84881+ (struct itimerspec __force_user *) &ts);
84882 set_fs(oldfs);
84883 if (!err && put_compat_itimerspec(setting, &ts))
84884 return -EFAULT;
84885@@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
84886 oldfs = get_fs();
84887 set_fs(KERNEL_DS);
84888 err = sys_clock_settime(which_clock,
84889- (struct timespec __user *) &ts);
84890+ (struct timespec __force_user *) &ts);
84891 set_fs(oldfs);
84892 return err;
84893 }
84894@@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
84895 oldfs = get_fs();
84896 set_fs(KERNEL_DS);
84897 err = sys_clock_gettime(which_clock,
84898- (struct timespec __user *) &ts);
84899+ (struct timespec __force_user *) &ts);
84900 set_fs(oldfs);
84901 if (!err && put_compat_timespec(&ts, tp))
84902 return -EFAULT;
84903@@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
84904
84905 oldfs = get_fs();
84906 set_fs(KERNEL_DS);
84907- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
84908+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
84909 set_fs(oldfs);
84910
84911 err = compat_put_timex(utp, &txc);
84912@@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
84913 oldfs = get_fs();
84914 set_fs(KERNEL_DS);
84915 err = sys_clock_getres(which_clock,
84916- (struct timespec __user *) &ts);
84917+ (struct timespec __force_user *) &ts);
84918 set_fs(oldfs);
84919 if (!err && tp && put_compat_timespec(&ts, tp))
84920 return -EFAULT;
84921@@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
84922 long err;
84923 mm_segment_t oldfs;
84924 struct timespec tu;
84925- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
84926+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
84927
84928- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
84929+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
84930 oldfs = get_fs();
84931 set_fs(KERNEL_DS);
84932 err = clock_nanosleep_restart(restart);
84933@@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
84934 oldfs = get_fs();
84935 set_fs(KERNEL_DS);
84936 err = sys_clock_nanosleep(which_clock, flags,
84937- (struct timespec __user *) &in,
84938- (struct timespec __user *) &out);
84939+ (struct timespec __force_user *) &in,
84940+ (struct timespec __force_user *) &out);
84941 set_fs(oldfs);
84942
84943 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
84944@@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
84945 mm_segment_t old_fs = get_fs();
84946
84947 set_fs(KERNEL_DS);
84948- ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
84949+ ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
84950 set_fs(old_fs);
84951 if (put_compat_timespec(&t, interval))
84952 return -EFAULT;
84953diff --git a/kernel/configs.c b/kernel/configs.c
84954index c18b1f1..b9a0132 100644
84955--- a/kernel/configs.c
84956+++ b/kernel/configs.c
84957@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
84958 struct proc_dir_entry *entry;
84959
84960 /* create the current config file */
84961+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
84962+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
84963+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
84964+ &ikconfig_file_ops);
84965+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
84966+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
84967+ &ikconfig_file_ops);
84968+#endif
84969+#else
84970 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
84971 &ikconfig_file_ops);
84972+#endif
84973+
84974 if (!entry)
84975 return -ENOMEM;
84976
84977diff --git a/kernel/cred.c b/kernel/cred.c
84978index e0573a4..3874e41 100644
84979--- a/kernel/cred.c
84980+++ b/kernel/cred.c
84981@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
84982 validate_creds(cred);
84983 alter_cred_subscribers(cred, -1);
84984 put_cred(cred);
84985+
84986+#ifdef CONFIG_GRKERNSEC_SETXID
84987+ cred = (struct cred *) tsk->delayed_cred;
84988+ if (cred != NULL) {
84989+ tsk->delayed_cred = NULL;
84990+ validate_creds(cred);
84991+ alter_cred_subscribers(cred, -1);
84992+ put_cred(cred);
84993+ }
84994+#endif
84995 }
84996
84997 /**
84998@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
84999 * Always returns 0 thus allowing this function to be tail-called at the end
85000 * of, say, sys_setgid().
85001 */
85002-int commit_creds(struct cred *new)
85003+static int __commit_creds(struct cred *new)
85004 {
85005 struct task_struct *task = current;
85006 const struct cred *old = task->real_cred;
85007@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85008
85009 get_cred(new); /* we will require a ref for the subj creds too */
85010
85011+ gr_set_role_label(task, new->uid, new->gid);
85012+
85013 /* dumpability changes */
85014 if (!uid_eq(old->euid, new->euid) ||
85015 !gid_eq(old->egid, new->egid) ||
85016@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
85017 put_cred(old);
85018 return 0;
85019 }
85020+#ifdef CONFIG_GRKERNSEC_SETXID
85021+extern int set_user(struct cred *new);
85022+
85023+void gr_delayed_cred_worker(void)
85024+{
85025+ const struct cred *new = current->delayed_cred;
85026+ struct cred *ncred;
85027+
85028+ current->delayed_cred = NULL;
85029+
85030+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85031+ // from doing get_cred on it when queueing this
85032+ put_cred(new);
85033+ return;
85034+ } else if (new == NULL)
85035+ return;
85036+
85037+ ncred = prepare_creds();
85038+ if (!ncred)
85039+ goto die;
85040+ // uids
85041+ ncred->uid = new->uid;
85042+ ncred->euid = new->euid;
85043+ ncred->suid = new->suid;
85044+ ncred->fsuid = new->fsuid;
85045+ // gids
85046+ ncred->gid = new->gid;
85047+ ncred->egid = new->egid;
85048+ ncred->sgid = new->sgid;
85049+ ncred->fsgid = new->fsgid;
85050+ // groups
85051+ if (set_groups(ncred, new->group_info) < 0) {
85052+ abort_creds(ncred);
85053+ goto die;
85054+ }
85055+ // caps
85056+ ncred->securebits = new->securebits;
85057+ ncred->cap_inheritable = new->cap_inheritable;
85058+ ncred->cap_permitted = new->cap_permitted;
85059+ ncred->cap_effective = new->cap_effective;
85060+ ncred->cap_bset = new->cap_bset;
85061+
85062+ if (set_user(ncred)) {
85063+ abort_creds(ncred);
85064+ goto die;
85065+ }
85066+
85067+ // from doing get_cred on it when queueing this
85068+ put_cred(new);
85069+
85070+ __commit_creds(ncred);
85071+ return;
85072+die:
85073+ // from doing get_cred on it when queueing this
85074+ put_cred(new);
85075+ do_group_exit(SIGKILL);
85076+}
85077+#endif
85078+
85079+int commit_creds(struct cred *new)
85080+{
85081+#ifdef CONFIG_GRKERNSEC_SETXID
85082+ int ret;
85083+ int schedule_it = 0;
85084+ struct task_struct *t;
85085+
85086+ /* we won't get called with tasklist_lock held for writing
85087+ and interrupts disabled as the cred struct in that case is
85088+ init_cred
85089+ */
85090+ if (grsec_enable_setxid && !current_is_single_threaded() &&
85091+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85092+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85093+ schedule_it = 1;
85094+ }
85095+ ret = __commit_creds(new);
85096+ if (schedule_it) {
85097+ rcu_read_lock();
85098+ read_lock(&tasklist_lock);
85099+ for (t = next_thread(current); t != current;
85100+ t = next_thread(t)) {
85101+ if (t->delayed_cred == NULL) {
85102+ t->delayed_cred = get_cred(new);
85103+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85104+ set_tsk_need_resched(t);
85105+ }
85106+ }
85107+ read_unlock(&tasklist_lock);
85108+ rcu_read_unlock();
85109+ }
85110+ return ret;
85111+#else
85112+ return __commit_creds(new);
85113+#endif
85114+}
85115+
85116 EXPORT_SYMBOL(commit_creds);
85117
85118 /**
85119diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
85120index 7d2f35e..1bafcd0 100644
85121--- a/kernel/debug/debug_core.c
85122+++ b/kernel/debug/debug_core.c
85123@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
85124 */
85125 static atomic_t masters_in_kgdb;
85126 static atomic_t slaves_in_kgdb;
85127-static atomic_t kgdb_break_tasklet_var;
85128+static atomic_unchecked_t kgdb_break_tasklet_var;
85129 atomic_t kgdb_setting_breakpoint;
85130
85131 struct task_struct *kgdb_usethread;
85132@@ -133,7 +133,7 @@ int kgdb_single_step;
85133 static pid_t kgdb_sstep_pid;
85134
85135 /* to keep track of the CPU which is doing the single stepping*/
85136-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85137+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
85138
85139 /*
85140 * If you are debugging a problem where roundup (the collection of
85141@@ -541,7 +541,7 @@ return_normal:
85142 * kernel will only try for the value of sstep_tries before
85143 * giving up and continuing on.
85144 */
85145- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
85146+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
85147 (kgdb_info[cpu].task &&
85148 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
85149 atomic_set(&kgdb_active, -1);
85150@@ -639,8 +639,8 @@ cpu_master_loop:
85151 }
85152
85153 kgdb_restore:
85154- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
85155- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
85156+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
85157+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
85158 if (kgdb_info[sstep_cpu].task)
85159 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
85160 else
85161@@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
85162 static void kgdb_tasklet_bpt(unsigned long ing)
85163 {
85164 kgdb_breakpoint();
85165- atomic_set(&kgdb_break_tasklet_var, 0);
85166+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
85167 }
85168
85169 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
85170
85171 void kgdb_schedule_breakpoint(void)
85172 {
85173- if (atomic_read(&kgdb_break_tasklet_var) ||
85174+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
85175 atomic_read(&kgdb_active) != -1 ||
85176 atomic_read(&kgdb_setting_breakpoint))
85177 return;
85178- atomic_inc(&kgdb_break_tasklet_var);
85179+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
85180 tasklet_schedule(&kgdb_tasklet_breakpoint);
85181 }
85182 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
85183diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
85184index 0b097c8..11dd5c5 100644
85185--- a/kernel/debug/kdb/kdb_main.c
85186+++ b/kernel/debug/kdb/kdb_main.c
85187@@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
85188 continue;
85189
85190 kdb_printf("%-20s%8u 0x%p ", mod->name,
85191- mod->core_size, (void *)mod);
85192+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
85193 #ifdef CONFIG_MODULE_UNLOAD
85194 kdb_printf("%4ld ", module_refcount(mod));
85195 #endif
85196@@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
85197 kdb_printf(" (Loading)");
85198 else
85199 kdb_printf(" (Live)");
85200- kdb_printf(" 0x%p", mod->module_core);
85201+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
85202
85203 #ifdef CONFIG_MODULE_UNLOAD
85204 {
85205diff --git a/kernel/events/core.c b/kernel/events/core.c
85206index 6ed1163..f36346e 100644
85207--- a/kernel/events/core.c
85208+++ b/kernel/events/core.c
85209@@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
85210 * 0 - disallow raw tracepoint access for unpriv
85211 * 1 - disallow cpu events for unpriv
85212 * 2 - disallow kernel profiling for unpriv
85213+ * 3 - disallow all unpriv perf event use
85214 */
85215-int sysctl_perf_event_paranoid __read_mostly = 1;
85216+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85217+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
85218+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
85219+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
85220+#else
85221+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
85222+#endif
85223
85224 /* Minimum for 512 kiB + 1 user control page */
85225 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
85226@@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
85227
85228 tmp *= sysctl_perf_cpu_time_max_percent;
85229 do_div(tmp, 100);
85230- ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
85231+ ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
85232 }
85233
85234 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
85235@@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
85236 update_perf_cpu_limits();
85237 }
85238
85239-static atomic64_t perf_event_id;
85240+static atomic64_unchecked_t perf_event_id;
85241
85242 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
85243 enum event_type_t event_type);
85244@@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
85245
85246 static inline u64 perf_event_count(struct perf_event *event)
85247 {
85248- return local64_read(&event->count) + atomic64_read(&event->child_count);
85249+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
85250 }
85251
85252 static u64 perf_event_read(struct perf_event *event)
85253@@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
85254 mutex_lock(&event->child_mutex);
85255 total += perf_event_read(event);
85256 *enabled += event->total_time_enabled +
85257- atomic64_read(&event->child_total_time_enabled);
85258+ atomic64_read_unchecked(&event->child_total_time_enabled);
85259 *running += event->total_time_running +
85260- atomic64_read(&event->child_total_time_running);
85261+ atomic64_read_unchecked(&event->child_total_time_running);
85262
85263 list_for_each_entry(child, &event->child_list, child_list) {
85264 total += perf_event_read(child);
85265@@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
85266 userpg->offset -= local64_read(&event->hw.prev_count);
85267
85268 userpg->time_enabled = enabled +
85269- atomic64_read(&event->child_total_time_enabled);
85270+ atomic64_read_unchecked(&event->child_total_time_enabled);
85271
85272 userpg->time_running = running +
85273- atomic64_read(&event->child_total_time_running);
85274+ atomic64_read_unchecked(&event->child_total_time_running);
85275
85276 arch_perf_update_userpage(userpg, now);
85277
85278@@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
85279
85280 /* Data. */
85281 sp = perf_user_stack_pointer(regs);
85282- rem = __output_copy_user(handle, (void *) sp, dump_size);
85283+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
85284 dyn_size = dump_size - rem;
85285
85286 perf_output_skip(handle, rem);
85287@@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
85288 values[n++] = perf_event_count(event);
85289 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
85290 values[n++] = enabled +
85291- atomic64_read(&event->child_total_time_enabled);
85292+ atomic64_read_unchecked(&event->child_total_time_enabled);
85293 }
85294 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
85295 values[n++] = running +
85296- atomic64_read(&event->child_total_time_running);
85297+ atomic64_read_unchecked(&event->child_total_time_running);
85298 }
85299 if (read_format & PERF_FORMAT_ID)
85300 values[n++] = primary_event_id(event);
85301@@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
85302 event->parent = parent_event;
85303
85304 event->ns = get_pid_ns(task_active_pid_ns(current));
85305- event->id = atomic64_inc_return(&perf_event_id);
85306+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
85307
85308 event->state = PERF_EVENT_STATE_INACTIVE;
85309
85310@@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
85311 if (flags & ~PERF_FLAG_ALL)
85312 return -EINVAL;
85313
85314+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
85315+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
85316+ return -EACCES;
85317+#endif
85318+
85319 err = perf_copy_attr(attr_uptr, &attr);
85320 if (err)
85321 return err;
85322@@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
85323 /*
85324 * Add back the child's count to the parent's count:
85325 */
85326- atomic64_add(child_val, &parent_event->child_count);
85327- atomic64_add(child_event->total_time_enabled,
85328+ atomic64_add_unchecked(child_val, &parent_event->child_count);
85329+ atomic64_add_unchecked(child_event->total_time_enabled,
85330 &parent_event->child_total_time_enabled);
85331- atomic64_add(child_event->total_time_running,
85332+ atomic64_add_unchecked(child_event->total_time_running,
85333 &parent_event->child_total_time_running);
85334
85335 /*
85336diff --git a/kernel/events/internal.h b/kernel/events/internal.h
85337index 569b2187..19940d9 100644
85338--- a/kernel/events/internal.h
85339+++ b/kernel/events/internal.h
85340@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
85341 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
85342 }
85343
85344-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
85345+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
85346 static inline unsigned long \
85347 func_name(struct perf_output_handle *handle, \
85348- const void *buf, unsigned long len) \
85349+ const void user *buf, unsigned long len) \
85350 { \
85351 unsigned long size, written; \
85352 \
85353@@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
85354 return 0;
85355 }
85356
85357-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
85358+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
85359
85360 static inline unsigned long
85361 memcpy_skip(void *dst, const void *src, unsigned long n)
85362@@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
85363 return 0;
85364 }
85365
85366-DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
85367+DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
85368
85369 #ifndef arch_perf_out_copy_user
85370 #define arch_perf_out_copy_user arch_perf_out_copy_user
85371@@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
85372 }
85373 #endif
85374
85375-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
85376+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
85377
85378 /* Callchain handling */
85379 extern struct perf_callchain_entry *
85380diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
85381index 24b7d6c..40cf797 100644
85382--- a/kernel/events/uprobes.c
85383+++ b/kernel/events/uprobes.c
85384@@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
85385 {
85386 struct page *page;
85387 uprobe_opcode_t opcode;
85388- int result;
85389+ long result;
85390
85391 pagefault_disable();
85392 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
85393diff --git a/kernel/exit.c b/kernel/exit.c
85394index a949819..a5f127d 100644
85395--- a/kernel/exit.c
85396+++ b/kernel/exit.c
85397@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
85398 struct task_struct *leader;
85399 int zap_leader;
85400 repeat:
85401+#ifdef CONFIG_NET
85402+ gr_del_task_from_ip_table(p);
85403+#endif
85404+
85405 /* don't need to get the RCU readlock here - the process is dead and
85406 * can't be modifying its own credentials. But shut RCU-lockdep up */
85407 rcu_read_lock();
85408@@ -329,7 +333,7 @@ int allow_signal(int sig)
85409 * know it'll be handled, so that they don't get converted to
85410 * SIGKILL or just silently dropped.
85411 */
85412- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
85413+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
85414 recalc_sigpending();
85415 spin_unlock_irq(&current->sighand->siglock);
85416 return 0;
85417@@ -698,6 +702,8 @@ void do_exit(long code)
85418 struct task_struct *tsk = current;
85419 int group_dead;
85420
85421+ set_fs(USER_DS);
85422+
85423 profile_task_exit(tsk);
85424
85425 WARN_ON(blk_needs_flush_plug(tsk));
85426@@ -714,7 +720,6 @@ void do_exit(long code)
85427 * mm_release()->clear_child_tid() from writing to a user-controlled
85428 * kernel address.
85429 */
85430- set_fs(USER_DS);
85431
85432 ptrace_event(PTRACE_EVENT_EXIT, code);
85433
85434@@ -773,6 +778,9 @@ void do_exit(long code)
85435 tsk->exit_code = code;
85436 taskstats_exit(tsk, group_dead);
85437
85438+ gr_acl_handle_psacct(tsk, code);
85439+ gr_acl_handle_exit();
85440+
85441 exit_mm(tsk);
85442
85443 if (group_dead)
85444@@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
85445 * Take down every thread in the group. This is called by fatal signals
85446 * as well as by sys_exit_group (below).
85447 */
85448-void
85449+__noreturn void
85450 do_group_exit(int exit_code)
85451 {
85452 struct signal_struct *sig = current->signal;
85453diff --git a/kernel/fork.c b/kernel/fork.c
85454index dfa736c..d170f9b 100644
85455--- a/kernel/fork.c
85456+++ b/kernel/fork.c
85457@@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
85458 *stackend = STACK_END_MAGIC; /* for overflow detection */
85459
85460 #ifdef CONFIG_CC_STACKPROTECTOR
85461- tsk->stack_canary = get_random_int();
85462+ tsk->stack_canary = pax_get_random_long();
85463 #endif
85464
85465 /*
85466@@ -345,12 +345,80 @@ free_tsk:
85467 }
85468
85469 #ifdef CONFIG_MMU
85470-static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85471+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
85472+{
85473+ struct vm_area_struct *tmp;
85474+ unsigned long charge;
85475+ struct file *file;
85476+ int retval;
85477+
85478+ charge = 0;
85479+ if (mpnt->vm_flags & VM_ACCOUNT) {
85480+ unsigned long len = vma_pages(mpnt);
85481+
85482+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85483+ goto fail_nomem;
85484+ charge = len;
85485+ }
85486+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85487+ if (!tmp)
85488+ goto fail_nomem;
85489+ *tmp = *mpnt;
85490+ tmp->vm_mm = mm;
85491+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
85492+ retval = vma_dup_policy(mpnt, tmp);
85493+ if (retval)
85494+ goto fail_nomem_policy;
85495+ if (anon_vma_fork(tmp, mpnt))
85496+ goto fail_nomem_anon_vma_fork;
85497+ tmp->vm_flags &= ~VM_LOCKED;
85498+ tmp->vm_next = tmp->vm_prev = NULL;
85499+ tmp->vm_mirror = NULL;
85500+ file = tmp->vm_file;
85501+ if (file) {
85502+ struct inode *inode = file_inode(file);
85503+ struct address_space *mapping = file->f_mapping;
85504+
85505+ get_file(file);
85506+ if (tmp->vm_flags & VM_DENYWRITE)
85507+ atomic_dec(&inode->i_writecount);
85508+ mutex_lock(&mapping->i_mmap_mutex);
85509+ if (tmp->vm_flags & VM_SHARED)
85510+ mapping->i_mmap_writable++;
85511+ flush_dcache_mmap_lock(mapping);
85512+ /* insert tmp into the share list, just after mpnt */
85513+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85514+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
85515+ else
85516+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
85517+ flush_dcache_mmap_unlock(mapping);
85518+ mutex_unlock(&mapping->i_mmap_mutex);
85519+ }
85520+
85521+ /*
85522+ * Clear hugetlb-related page reserves for children. This only
85523+ * affects MAP_PRIVATE mappings. Faults generated by the child
85524+ * are not guaranteed to succeed, even if read-only
85525+ */
85526+ if (is_vm_hugetlb_page(tmp))
85527+ reset_vma_resv_huge_pages(tmp);
85528+
85529+ return tmp;
85530+
85531+fail_nomem_anon_vma_fork:
85532+ mpol_put(vma_policy(tmp));
85533+fail_nomem_policy:
85534+ kmem_cache_free(vm_area_cachep, tmp);
85535+fail_nomem:
85536+ vm_unacct_memory(charge);
85537+ return NULL;
85538+}
85539+
85540+static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85541 {
85542 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
85543 struct rb_node **rb_link, *rb_parent;
85544 int retval;
85545- unsigned long charge;
85546
85547 uprobe_start_dup_mmap();
85548 down_write(&oldmm->mmap_sem);
85549@@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85550
85551 prev = NULL;
85552 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
85553- struct file *file;
85554-
85555 if (mpnt->vm_flags & VM_DONTCOPY) {
85556 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
85557 -vma_pages(mpnt));
85558 continue;
85559 }
85560- charge = 0;
85561- if (mpnt->vm_flags & VM_ACCOUNT) {
85562- unsigned long len = vma_pages(mpnt);
85563-
85564- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
85565- goto fail_nomem;
85566- charge = len;
85567- }
85568- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
85569- if (!tmp)
85570- goto fail_nomem;
85571- *tmp = *mpnt;
85572- INIT_LIST_HEAD(&tmp->anon_vma_chain);
85573- retval = vma_dup_policy(mpnt, tmp);
85574- if (retval)
85575- goto fail_nomem_policy;
85576- tmp->vm_mm = mm;
85577- if (anon_vma_fork(tmp, mpnt))
85578- goto fail_nomem_anon_vma_fork;
85579- tmp->vm_flags &= ~VM_LOCKED;
85580- tmp->vm_next = tmp->vm_prev = NULL;
85581- file = tmp->vm_file;
85582- if (file) {
85583- struct inode *inode = file_inode(file);
85584- struct address_space *mapping = file->f_mapping;
85585-
85586- get_file(file);
85587- if (tmp->vm_flags & VM_DENYWRITE)
85588- atomic_dec(&inode->i_writecount);
85589- mutex_lock(&mapping->i_mmap_mutex);
85590- if (tmp->vm_flags & VM_SHARED)
85591- mapping->i_mmap_writable++;
85592- flush_dcache_mmap_lock(mapping);
85593- /* insert tmp into the share list, just after mpnt */
85594- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
85595- vma_nonlinear_insert(tmp,
85596- &mapping->i_mmap_nonlinear);
85597- else
85598- vma_interval_tree_insert_after(tmp, mpnt,
85599- &mapping->i_mmap);
85600- flush_dcache_mmap_unlock(mapping);
85601- mutex_unlock(&mapping->i_mmap_mutex);
85602+ tmp = dup_vma(mm, oldmm, mpnt);
85603+ if (!tmp) {
85604+ retval = -ENOMEM;
85605+ goto out;
85606 }
85607
85608 /*
85609@@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
85610 if (retval)
85611 goto out;
85612 }
85613+
85614+#ifdef CONFIG_PAX_SEGMEXEC
85615+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
85616+ struct vm_area_struct *mpnt_m;
85617+
85618+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
85619+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
85620+
85621+ if (!mpnt->vm_mirror)
85622+ continue;
85623+
85624+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
85625+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
85626+ mpnt->vm_mirror = mpnt_m;
85627+ } else {
85628+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
85629+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
85630+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
85631+ mpnt->vm_mirror->vm_mirror = mpnt;
85632+ }
85633+ }
85634+ BUG_ON(mpnt_m);
85635+ }
85636+#endif
85637+
85638 /* a new mm has just been created */
85639 arch_dup_mmap(oldmm, mm);
85640 retval = 0;
85641@@ -468,14 +521,6 @@ out:
85642 up_write(&oldmm->mmap_sem);
85643 uprobe_end_dup_mmap();
85644 return retval;
85645-fail_nomem_anon_vma_fork:
85646- mpol_put(vma_policy(tmp));
85647-fail_nomem_policy:
85648- kmem_cache_free(vm_area_cachep, tmp);
85649-fail_nomem:
85650- retval = -ENOMEM;
85651- vm_unacct_memory(charge);
85652- goto out;
85653 }
85654
85655 static inline int mm_alloc_pgd(struct mm_struct *mm)
85656@@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
85657 return ERR_PTR(err);
85658
85659 mm = get_task_mm(task);
85660- if (mm && mm != current->mm &&
85661- !ptrace_may_access(task, mode)) {
85662+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
85663+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
85664 mmput(mm);
85665 mm = ERR_PTR(-EACCES);
85666 }
85667@@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
85668 spin_unlock(&fs->lock);
85669 return -EAGAIN;
85670 }
85671- fs->users++;
85672+ atomic_inc(&fs->users);
85673 spin_unlock(&fs->lock);
85674 return 0;
85675 }
85676 tsk->fs = copy_fs_struct(fs);
85677 if (!tsk->fs)
85678 return -ENOMEM;
85679+ /* Carry through gr_chroot_dentry and is_chrooted instead
85680+ of recomputing it here. Already copied when the task struct
85681+ is duplicated. This allows pivot_root to not be treated as
85682+ a chroot
85683+ */
85684+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
85685+
85686 return 0;
85687 }
85688
85689@@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
85690 * parts of the process environment (as per the clone
85691 * flags). The actual kick-off is left to the caller.
85692 */
85693-static struct task_struct *copy_process(unsigned long clone_flags,
85694+static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
85695 unsigned long stack_start,
85696 unsigned long stack_size,
85697 int __user *child_tidptr,
85698@@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85699 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
85700 #endif
85701 retval = -EAGAIN;
85702+
85703+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
85704+
85705 if (atomic_read(&p->real_cred->user->processes) >=
85706 task_rlimit(p, RLIMIT_NPROC)) {
85707 if (p->real_cred->user != INIT_USER &&
85708@@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
85709 goto bad_fork_free_pid;
85710 }
85711
85712+ /* synchronizes with gr_set_acls()
85713+ we need to call this past the point of no return for fork()
85714+ */
85715+ gr_copy_label(p);
85716+
85717 if (likely(p->pid)) {
85718 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
85719
85720@@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
85721 bad_fork_free:
85722 free_task(p);
85723 fork_out:
85724+ gr_log_forkfail(retval);
85725+
85726 return ERR_PTR(retval);
85727 }
85728
85729@@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
85730
85731 p = copy_process(clone_flags, stack_start, stack_size,
85732 child_tidptr, NULL, trace);
85733+ add_latent_entropy();
85734 /*
85735 * Do this prior waking up the new thread - the thread pointer
85736 * might get invalid after that point, if the thread exits quickly.
85737@@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
85738 if (clone_flags & CLONE_PARENT_SETTID)
85739 put_user(nr, parent_tidptr);
85740
85741+ gr_handle_brute_check();
85742+
85743 if (clone_flags & CLONE_VFORK) {
85744 p->vfork_done = &vfork;
85745 init_completion(&vfork);
85746@@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
85747 mm_cachep = kmem_cache_create("mm_struct",
85748 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
85749 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
85750- vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
85751+ vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
85752 mmap_init();
85753 nsproxy_cache_init();
85754 }
85755@@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
85756 return 0;
85757
85758 /* don't need lock here; in the worst case we'll do useless copy */
85759- if (fs->users == 1)
85760+ if (atomic_read(&fs->users) == 1)
85761 return 0;
85762
85763 *new_fsp = copy_fs_struct(fs);
85764@@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
85765 fs = current->fs;
85766 spin_lock(&fs->lock);
85767 current->fs = new_fs;
85768- if (--fs->users)
85769+ gr_set_chroot_entries(current, &current->fs->root);
85770+ if (atomic_dec_return(&fs->users))
85771 new_fs = NULL;
85772 else
85773 new_fs = fs;
85774diff --git a/kernel/futex.c b/kernel/futex.c
85775index 0d74e3a..59bea40 100644
85776--- a/kernel/futex.c
85777+++ b/kernel/futex.c
85778@@ -54,6 +54,7 @@
85779 #include <linux/mount.h>
85780 #include <linux/pagemap.h>
85781 #include <linux/syscalls.h>
85782+#include <linux/ptrace.h>
85783 #include <linux/signal.h>
85784 #include <linux/export.h>
85785 #include <linux/magic.h>
85786@@ -245,6 +246,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
85787 struct page *page, *page_head;
85788 int err, ro = 0;
85789
85790+#ifdef CONFIG_PAX_SEGMEXEC
85791+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
85792+ return -EFAULT;
85793+#endif
85794+
85795 /*
85796 * The futex address must be "naturally" aligned.
85797 */
85798@@ -444,7 +450,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
85799
85800 static int get_futex_value_locked(u32 *dest, u32 __user *from)
85801 {
85802- int ret;
85803+ unsigned long ret;
85804
85805 pagefault_disable();
85806 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
85807@@ -2737,6 +2743,7 @@ static void __init futex_detect_cmpxchg(void)
85808 {
85809 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
85810 u32 curval;
85811+ mm_segment_t oldfs;
85812
85813 /*
85814 * This will fail and we want it. Some arch implementations do
85815@@ -2748,8 +2755,11 @@ static void __init futex_detect_cmpxchg(void)
85816 * implementation, the non-functional ones will return
85817 * -ENOSYS.
85818 */
85819+ oldfs = get_fs();
85820+ set_fs(USER_DS);
85821 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
85822 futex_cmpxchg_enabled = 1;
85823+ set_fs(oldfs);
85824 #endif
85825 }
85826
85827diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
85828index f9f44fd..29885e4 100644
85829--- a/kernel/futex_compat.c
85830+++ b/kernel/futex_compat.c
85831@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
85832 return 0;
85833 }
85834
85835-static void __user *futex_uaddr(struct robust_list __user *entry,
85836+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
85837 compat_long_t futex_offset)
85838 {
85839 compat_uptr_t base = ptr_to_compat(entry);
85840diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
85841index f45b75b..bfac6d5 100644
85842--- a/kernel/gcov/base.c
85843+++ b/kernel/gcov/base.c
85844@@ -108,11 +108,6 @@ void gcov_enable_events(void)
85845 }
85846
85847 #ifdef CONFIG_MODULES
85848-static inline int within(void *addr, void *start, unsigned long size)
85849-{
85850- return ((addr >= start) && (addr < start + size));
85851-}
85852-
85853 /* Update list and generate events when modules are unloaded. */
85854 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85855 void *data)
85856@@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
85857
85858 /* Remove entries located in module from linked list. */
85859 while ((info = gcov_info_next(info))) {
85860- if (within(info, mod->module_core, mod->core_size)) {
85861+ if (within_module_core_rw((unsigned long)info, mod)) {
85862 gcov_info_unlink(prev, info);
85863 if (gcov_events_enabled)
85864 gcov_event(GCOV_REMOVE, info);
85865diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
85866index 383319b..56ebb13 100644
85867--- a/kernel/hrtimer.c
85868+++ b/kernel/hrtimer.c
85869@@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
85870 local_irq_restore(flags);
85871 }
85872
85873-static void run_hrtimer_softirq(struct softirq_action *h)
85874+static __latent_entropy void run_hrtimer_softirq(void)
85875 {
85876 hrtimer_peek_ahead_timers();
85877 }
85878diff --git a/kernel/irq_work.c b/kernel/irq_work.c
85879index 55fcce6..0e4cf34 100644
85880--- a/kernel/irq_work.c
85881+++ b/kernel/irq_work.c
85882@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
85883 return NOTIFY_OK;
85884 }
85885
85886-static struct notifier_block cpu_notify;
85887+static struct notifier_block cpu_notify = {
85888+ .notifier_call = irq_work_cpu_notify,
85889+ .priority = 0,
85890+};
85891
85892 static __init int irq_work_init_cpu_notifier(void)
85893 {
85894- cpu_notify.notifier_call = irq_work_cpu_notify;
85895- cpu_notify.priority = 0;
85896 register_cpu_notifier(&cpu_notify);
85897 return 0;
85898 }
85899diff --git a/kernel/jump_label.c b/kernel/jump_label.c
85900index 9019f15..9a3c42e 100644
85901--- a/kernel/jump_label.c
85902+++ b/kernel/jump_label.c
85903@@ -14,6 +14,7 @@
85904 #include <linux/err.h>
85905 #include <linux/static_key.h>
85906 #include <linux/jump_label_ratelimit.h>
85907+#include <linux/mm.h>
85908
85909 #ifdef HAVE_JUMP_LABEL
85910
85911@@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
85912
85913 size = (((unsigned long)stop - (unsigned long)start)
85914 / sizeof(struct jump_entry));
85915+ pax_open_kernel();
85916 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
85917+ pax_close_kernel();
85918 }
85919
85920 static void jump_label_update(struct static_key *key, int enable);
85921@@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
85922 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
85923 struct jump_entry *iter;
85924
85925+ pax_open_kernel();
85926 for (iter = iter_start; iter < iter_stop; iter++) {
85927 if (within_module_init(iter->code, mod))
85928 iter->code = 0;
85929 }
85930+ pax_close_kernel();
85931 }
85932
85933 static int
85934diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
85935index 3127ad5..159d880 100644
85936--- a/kernel/kallsyms.c
85937+++ b/kernel/kallsyms.c
85938@@ -11,6 +11,9 @@
85939 * Changed the compression method from stem compression to "table lookup"
85940 * compression (see scripts/kallsyms.c for a more complete description)
85941 */
85942+#ifdef CONFIG_GRKERNSEC_HIDESYM
85943+#define __INCLUDED_BY_HIDESYM 1
85944+#endif
85945 #include <linux/kallsyms.h>
85946 #include <linux/module.h>
85947 #include <linux/init.h>
85948@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
85949
85950 static inline int is_kernel_inittext(unsigned long addr)
85951 {
85952+ if (system_state != SYSTEM_BOOTING)
85953+ return 0;
85954+
85955 if (addr >= (unsigned long)_sinittext
85956 && addr <= (unsigned long)_einittext)
85957 return 1;
85958 return 0;
85959 }
85960
85961+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85962+#ifdef CONFIG_MODULES
85963+static inline int is_module_text(unsigned long addr)
85964+{
85965+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
85966+ return 1;
85967+
85968+ addr = ktla_ktva(addr);
85969+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
85970+}
85971+#else
85972+static inline int is_module_text(unsigned long addr)
85973+{
85974+ return 0;
85975+}
85976+#endif
85977+#endif
85978+
85979 static inline int is_kernel_text(unsigned long addr)
85980 {
85981 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
85982@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
85983
85984 static inline int is_kernel(unsigned long addr)
85985 {
85986+
85987+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85988+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
85989+ return 1;
85990+
85991+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
85992+#else
85993 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
85994+#endif
85995+
85996 return 1;
85997 return in_gate_area_no_mm(addr);
85998 }
85999
86000 static int is_ksym_addr(unsigned long addr)
86001 {
86002+
86003+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86004+ if (is_module_text(addr))
86005+ return 0;
86006+#endif
86007+
86008 if (all_var)
86009 return is_kernel(addr);
86010
86011@@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
86012
86013 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
86014 {
86015- iter->name[0] = '\0';
86016 iter->nameoff = get_symbol_offset(new_pos);
86017 iter->pos = new_pos;
86018 }
86019@@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
86020 {
86021 struct kallsym_iter *iter = m->private;
86022
86023+#ifdef CONFIG_GRKERNSEC_HIDESYM
86024+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
86025+ return 0;
86026+#endif
86027+
86028 /* Some debugging symbols have no name. Ignore them. */
86029 if (!iter->name[0])
86030 return 0;
86031@@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
86032 */
86033 type = iter->exported ? toupper(iter->type) :
86034 tolower(iter->type);
86035+
86036 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
86037 type, iter->name, iter->module_name);
86038 } else
86039@@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
86040 struct kallsym_iter *iter;
86041 int ret;
86042
86043- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
86044+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
86045 if (!iter)
86046 return -ENOMEM;
86047 reset_iter(iter, 0);
86048diff --git a/kernel/kcmp.c b/kernel/kcmp.c
86049index e30ac0f..3528cac 100644
86050--- a/kernel/kcmp.c
86051+++ b/kernel/kcmp.c
86052@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
86053 struct task_struct *task1, *task2;
86054 int ret;
86055
86056+#ifdef CONFIG_GRKERNSEC
86057+ return -ENOSYS;
86058+#endif
86059+
86060 rcu_read_lock();
86061
86062 /*
86063diff --git a/kernel/kexec.c b/kernel/kexec.c
86064index 9c97016..df438f8 100644
86065--- a/kernel/kexec.c
86066+++ b/kernel/kexec.c
86067@@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
86068 unsigned long flags)
86069 {
86070 struct compat_kexec_segment in;
86071- struct kexec_segment out, __user *ksegments;
86072+ struct kexec_segment out;
86073+ struct kexec_segment __user *ksegments;
86074 unsigned long i, result;
86075
86076 /* Don't allow clients that don't understand the native
86077diff --git a/kernel/kmod.c b/kernel/kmod.c
86078index b086006..b66f630 100644
86079--- a/kernel/kmod.c
86080+++ b/kernel/kmod.c
86081@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
86082 kfree(info->argv);
86083 }
86084
86085-static int call_modprobe(char *module_name, int wait)
86086+static int call_modprobe(char *module_name, char *module_param, int wait)
86087 {
86088 struct subprocess_info *info;
86089 static char *envp[] = {
86090@@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
86091 NULL
86092 };
86093
86094- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
86095+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
86096 if (!argv)
86097 goto out;
86098
86099@@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
86100 argv[1] = "-q";
86101 argv[2] = "--";
86102 argv[3] = module_name; /* check free_modprobe_argv() */
86103- argv[4] = NULL;
86104+ argv[4] = module_param;
86105+ argv[5] = NULL;
86106
86107 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
86108 NULL, free_modprobe_argv, NULL);
86109@@ -129,9 +130,8 @@ out:
86110 * If module auto-loading support is disabled then this function
86111 * becomes a no-operation.
86112 */
86113-int __request_module(bool wait, const char *fmt, ...)
86114+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
86115 {
86116- va_list args;
86117 char module_name[MODULE_NAME_LEN];
86118 unsigned int max_modprobes;
86119 int ret;
86120@@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
86121 if (!modprobe_path[0])
86122 return 0;
86123
86124- va_start(args, fmt);
86125- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
86126- va_end(args);
86127+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
86128 if (ret >= MODULE_NAME_LEN)
86129 return -ENAMETOOLONG;
86130
86131@@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
86132 if (ret)
86133 return ret;
86134
86135+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86136+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86137+ /* hack to workaround consolekit/udisks stupidity */
86138+ read_lock(&tasklist_lock);
86139+ if (!strcmp(current->comm, "mount") &&
86140+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
86141+ read_unlock(&tasklist_lock);
86142+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
86143+ return -EPERM;
86144+ }
86145+ read_unlock(&tasklist_lock);
86146+ }
86147+#endif
86148+
86149 /* If modprobe needs a service that is in a module, we get a recursive
86150 * loop. Limit the number of running kmod threads to max_threads/2 or
86151 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
86152@@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
86153
86154 trace_module_request(module_name, wait, _RET_IP_);
86155
86156- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86157+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
86158
86159 atomic_dec(&kmod_concurrent);
86160 return ret;
86161 }
86162+
86163+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
86164+{
86165+ va_list args;
86166+ int ret;
86167+
86168+ va_start(args, fmt);
86169+ ret = ____request_module(wait, module_param, fmt, args);
86170+ va_end(args);
86171+
86172+ return ret;
86173+}
86174+
86175+int __request_module(bool wait, const char *fmt, ...)
86176+{
86177+ va_list args;
86178+ int ret;
86179+
86180+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86181+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
86182+ char module_param[MODULE_NAME_LEN];
86183+
86184+ memset(module_param, 0, sizeof(module_param));
86185+
86186+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
86187+
86188+ va_start(args, fmt);
86189+ ret = ____request_module(wait, module_param, fmt, args);
86190+ va_end(args);
86191+
86192+ return ret;
86193+ }
86194+#endif
86195+
86196+ va_start(args, fmt);
86197+ ret = ____request_module(wait, NULL, fmt, args);
86198+ va_end(args);
86199+
86200+ return ret;
86201+}
86202+
86203 EXPORT_SYMBOL(__request_module);
86204 #endif /* CONFIG_MODULES */
86205
86206@@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
86207 */
86208 set_user_nice(current, 0);
86209
86210+#ifdef CONFIG_GRKERNSEC
86211+ /* this is race-free as far as userland is concerned as we copied
86212+ out the path to be used prior to this point and are now operating
86213+ on that copy
86214+ */
86215+ if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
86216+ strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
86217+ strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
86218+ printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
86219+ retval = -EPERM;
86220+ goto fail;
86221+ }
86222+#endif
86223+
86224 retval = -ENOMEM;
86225 new = prepare_kernel_cred(current);
86226 if (!new)
86227@@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
86228 commit_creds(new);
86229
86230 retval = do_execve(sub_info->path,
86231- (const char __user *const __user *)sub_info->argv,
86232- (const char __user *const __user *)sub_info->envp);
86233+ (const char __user *const __force_user *)sub_info->argv,
86234+ (const char __user *const __force_user *)sub_info->envp);
86235 if (!retval)
86236 return 0;
86237
86238@@ -260,6 +327,10 @@ static int call_helper(void *data)
86239
86240 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
86241 {
86242+#ifdef CONFIG_GRKERNSEC
86243+ kfree(info->path);
86244+ info->path = info->origpath;
86245+#endif
86246 if (info->cleanup)
86247 (*info->cleanup)(info);
86248 kfree(info);
86249@@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
86250 *
86251 * Thus the __user pointer cast is valid here.
86252 */
86253- sys_wait4(pid, (int __user *)&ret, 0, NULL);
86254+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
86255
86256 /*
86257 * If ret is 0, either ____call_usermodehelper failed and the
86258@@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
86259 goto out;
86260
86261 INIT_WORK(&sub_info->work, __call_usermodehelper);
86262+#ifdef CONFIG_GRKERNSEC
86263+ sub_info->origpath = path;
86264+ sub_info->path = kstrdup(path, gfp_mask);
86265+#else
86266 sub_info->path = path;
86267+#endif
86268 sub_info->argv = argv;
86269 sub_info->envp = envp;
86270
86271@@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
86272 static int proc_cap_handler(struct ctl_table *table, int write,
86273 void __user *buffer, size_t *lenp, loff_t *ppos)
86274 {
86275- struct ctl_table t;
86276+ ctl_table_no_const t;
86277 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
86278 kernel_cap_t new_cap;
86279 int err, i;
86280diff --git a/kernel/kprobes.c b/kernel/kprobes.c
86281index ceeadfc..11c18b6 100644
86282--- a/kernel/kprobes.c
86283+++ b/kernel/kprobes.c
86284@@ -31,6 +31,9 @@
86285 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
86286 * <prasanna@in.ibm.com> added function-return probes.
86287 */
86288+#ifdef CONFIG_GRKERNSEC_HIDESYM
86289+#define __INCLUDED_BY_HIDESYM 1
86290+#endif
86291 #include <linux/kprobes.h>
86292 #include <linux/hash.h>
86293 #include <linux/init.h>
86294@@ -135,12 +138,12 @@ enum kprobe_slot_state {
86295
86296 static void *alloc_insn_page(void)
86297 {
86298- return module_alloc(PAGE_SIZE);
86299+ return module_alloc_exec(PAGE_SIZE);
86300 }
86301
86302 static void free_insn_page(void *page)
86303 {
86304- module_free(NULL, page);
86305+ module_free_exec(NULL, page);
86306 }
86307
86308 struct kprobe_insn_cache kprobe_insn_slots = {
86309@@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
86310 kprobe_type = "k";
86311
86312 if (sym)
86313- seq_printf(pi, "%p %s %s+0x%x %s ",
86314+ seq_printf(pi, "%pK %s %s+0x%x %s ",
86315 p->addr, kprobe_type, sym, offset,
86316 (modname ? modname : " "));
86317 else
86318- seq_printf(pi, "%p %s %p ",
86319+ seq_printf(pi, "%pK %s %pK ",
86320 p->addr, kprobe_type, p->addr);
86321
86322 if (!pp)
86323diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
86324index 9659d38..bffd520 100644
86325--- a/kernel/ksysfs.c
86326+++ b/kernel/ksysfs.c
86327@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
86328 {
86329 if (count+1 > UEVENT_HELPER_PATH_LEN)
86330 return -ENOENT;
86331+ if (!capable(CAP_SYS_ADMIN))
86332+ return -EPERM;
86333 memcpy(uevent_helper, buf, count);
86334 uevent_helper[count] = '\0';
86335 if (count && uevent_helper[count-1] == '\n')
86336@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
86337 return count;
86338 }
86339
86340-static struct bin_attribute notes_attr = {
86341+static bin_attribute_no_const notes_attr __read_only = {
86342 .attr = {
86343 .name = "notes",
86344 .mode = S_IRUGO,
86345diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
86346index 576ba75..7c256e4 100644
86347--- a/kernel/locking/lockdep.c
86348+++ b/kernel/locking/lockdep.c
86349@@ -596,6 +596,10 @@ static int static_obj(void *obj)
86350 end = (unsigned long) &_end,
86351 addr = (unsigned long) obj;
86352
86353+#ifdef CONFIG_PAX_KERNEXEC
86354+ start = ktla_ktva(start);
86355+#endif
86356+
86357 /*
86358 * static variable?
86359 */
86360@@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
86361 if (!static_obj(lock->key)) {
86362 debug_locks_off();
86363 printk("INFO: trying to register non-static key.\n");
86364+ printk("lock:%pS key:%pS.\n", lock, lock->key);
86365 printk("the code is fine but needs lockdep annotation.\n");
86366 printk("turning off the locking correctness validator.\n");
86367 dump_stack();
86368@@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
86369 if (!class)
86370 return 0;
86371 }
86372- atomic_inc((atomic_t *)&class->ops);
86373+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
86374 if (very_verbose(class)) {
86375 printk("\nacquire class [%p] %s", class->key, class->name);
86376 if (class->name_version > 1)
86377diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
86378index ef43ac4..2720dfa 100644
86379--- a/kernel/locking/lockdep_proc.c
86380+++ b/kernel/locking/lockdep_proc.c
86381@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
86382 return 0;
86383 }
86384
86385- seq_printf(m, "%p", class->key);
86386+ seq_printf(m, "%pK", class->key);
86387 #ifdef CONFIG_DEBUG_LOCKDEP
86388 seq_printf(m, " OPS:%8ld", class->ops);
86389 #endif
86390@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
86391
86392 list_for_each_entry(entry, &class->locks_after, entry) {
86393 if (entry->distance == 1) {
86394- seq_printf(m, " -> [%p] ", entry->class->key);
86395+ seq_printf(m, " -> [%pK] ", entry->class->key);
86396 print_name(m, entry->class);
86397 seq_puts(m, "\n");
86398 }
86399@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
86400 if (!class->key)
86401 continue;
86402
86403- seq_printf(m, "[%p] ", class->key);
86404+ seq_printf(m, "[%pK] ", class->key);
86405 print_name(m, class);
86406 seq_puts(m, "\n");
86407 }
86408@@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86409 if (!i)
86410 seq_line(m, '-', 40-namelen, namelen);
86411
86412- snprintf(ip, sizeof(ip), "[<%p>]",
86413+ snprintf(ip, sizeof(ip), "[<%pK>]",
86414 (void *)class->contention_point[i]);
86415 seq_printf(m, "%40s %14lu %29s %pS\n",
86416 name, stats->contention_point[i],
86417@@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
86418 if (!i)
86419 seq_line(m, '-', 40-namelen, namelen);
86420
86421- snprintf(ip, sizeof(ip), "[<%p>]",
86422+ snprintf(ip, sizeof(ip), "[<%pK>]",
86423 (void *)class->contending_point[i]);
86424 seq_printf(m, "%40s %14lu %29s %pS\n",
86425 name, stats->contending_point[i],
86426diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
86427index 7e3443f..b2a1e6b 100644
86428--- a/kernel/locking/mutex-debug.c
86429+++ b/kernel/locking/mutex-debug.c
86430@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
86431 }
86432
86433 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86434- struct thread_info *ti)
86435+ struct task_struct *task)
86436 {
86437 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
86438
86439 /* Mark the current thread as blocked on the lock: */
86440- ti->task->blocked_on = waiter;
86441+ task->blocked_on = waiter;
86442 }
86443
86444 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86445- struct thread_info *ti)
86446+ struct task_struct *task)
86447 {
86448 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
86449- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
86450- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
86451- ti->task->blocked_on = NULL;
86452+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
86453+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
86454+ task->blocked_on = NULL;
86455
86456 list_del_init(&waiter->list);
86457 waiter->task = NULL;
86458diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
86459index 0799fd3..d06ae3b 100644
86460--- a/kernel/locking/mutex-debug.h
86461+++ b/kernel/locking/mutex-debug.h
86462@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
86463 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
86464 extern void debug_mutex_add_waiter(struct mutex *lock,
86465 struct mutex_waiter *waiter,
86466- struct thread_info *ti);
86467+ struct task_struct *task);
86468 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
86469- struct thread_info *ti);
86470+ struct task_struct *task);
86471 extern void debug_mutex_unlock(struct mutex *lock);
86472 extern void debug_mutex_init(struct mutex *lock, const char *name,
86473 struct lock_class_key *key);
86474diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
86475index 4dd6e4c..df52693 100644
86476--- a/kernel/locking/mutex.c
86477+++ b/kernel/locking/mutex.c
86478@@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
86479 node->locked = 1;
86480 return;
86481 }
86482- ACCESS_ONCE(prev->next) = node;
86483+ ACCESS_ONCE_RW(prev->next) = node;
86484 smp_wmb();
86485 /* Wait until the lock holder passes the lock down */
86486 while (!ACCESS_ONCE(node->locked))
86487@@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
86488 while (!(next = ACCESS_ONCE(node->next)))
86489 arch_mutex_cpu_relax();
86490 }
86491- ACCESS_ONCE(next->locked) = 1;
86492+ ACCESS_ONCE_RW(next->locked) = 1;
86493 smp_wmb();
86494 }
86495
86496@@ -520,7 +520,7 @@ slowpath:
86497 goto skip_wait;
86498
86499 debug_mutex_lock_common(lock, &waiter);
86500- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
86501+ debug_mutex_add_waiter(lock, &waiter, task);
86502
86503 /* add waiting tasks to the end of the waitqueue (FIFO): */
86504 list_add_tail(&waiter.list, &lock->wait_list);
86505@@ -564,7 +564,7 @@ slowpath:
86506 schedule_preempt_disabled();
86507 spin_lock_mutex(&lock->wait_lock, flags);
86508 }
86509- mutex_remove_waiter(lock, &waiter, current_thread_info());
86510+ mutex_remove_waiter(lock, &waiter, task);
86511 /* set it to 0 if there are no waiters left: */
86512 if (likely(list_empty(&lock->wait_list)))
86513 atomic_set(&lock->count, 0);
86514@@ -601,7 +601,7 @@ skip_wait:
86515 return 0;
86516
86517 err:
86518- mutex_remove_waiter(lock, &waiter, task_thread_info(task));
86519+ mutex_remove_waiter(lock, &waiter, task);
86520 spin_unlock_mutex(&lock->wait_lock, flags);
86521 debug_mutex_free_waiter(&waiter);
86522 mutex_release(&lock->dep_map, 1, ip);
86523diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
86524index 1d96dd0..994ff19 100644
86525--- a/kernel/locking/rtmutex-tester.c
86526+++ b/kernel/locking/rtmutex-tester.c
86527@@ -22,7 +22,7 @@
86528 #define MAX_RT_TEST_MUTEXES 8
86529
86530 static spinlock_t rttest_lock;
86531-static atomic_t rttest_event;
86532+static atomic_unchecked_t rttest_event;
86533
86534 struct test_thread_data {
86535 int opcode;
86536@@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86537
86538 case RTTEST_LOCKCONT:
86539 td->mutexes[td->opdata] = 1;
86540- td->event = atomic_add_return(1, &rttest_event);
86541+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86542 return 0;
86543
86544 case RTTEST_RESET:
86545@@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86546 return 0;
86547
86548 case RTTEST_RESETEVENT:
86549- atomic_set(&rttest_event, 0);
86550+ atomic_set_unchecked(&rttest_event, 0);
86551 return 0;
86552
86553 default:
86554@@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86555 return ret;
86556
86557 td->mutexes[id] = 1;
86558- td->event = atomic_add_return(1, &rttest_event);
86559+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86560 rt_mutex_lock(&mutexes[id]);
86561- td->event = atomic_add_return(1, &rttest_event);
86562+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86563 td->mutexes[id] = 4;
86564 return 0;
86565
86566@@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86567 return ret;
86568
86569 td->mutexes[id] = 1;
86570- td->event = atomic_add_return(1, &rttest_event);
86571+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86572 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
86573- td->event = atomic_add_return(1, &rttest_event);
86574+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86575 td->mutexes[id] = ret ? 0 : 4;
86576 return ret ? -EINTR : 0;
86577
86578@@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
86579 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
86580 return ret;
86581
86582- td->event = atomic_add_return(1, &rttest_event);
86583+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86584 rt_mutex_unlock(&mutexes[id]);
86585- td->event = atomic_add_return(1, &rttest_event);
86586+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86587 td->mutexes[id] = 0;
86588 return 0;
86589
86590@@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86591 break;
86592
86593 td->mutexes[dat] = 2;
86594- td->event = atomic_add_return(1, &rttest_event);
86595+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86596 break;
86597
86598 default:
86599@@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86600 return;
86601
86602 td->mutexes[dat] = 3;
86603- td->event = atomic_add_return(1, &rttest_event);
86604+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86605 break;
86606
86607 case RTTEST_LOCKNOWAIT:
86608@@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
86609 return;
86610
86611 td->mutexes[dat] = 1;
86612- td->event = atomic_add_return(1, &rttest_event);
86613+ td->event = atomic_add_return_unchecked(1, &rttest_event);
86614 return;
86615
86616 default:
86617diff --git a/kernel/module.c b/kernel/module.c
86618index f5a3b1e..97ebb15 100644
86619--- a/kernel/module.c
86620+++ b/kernel/module.c
86621@@ -61,6 +61,7 @@
86622 #include <linux/pfn.h>
86623 #include <linux/bsearch.h>
86624 #include <linux/fips.h>
86625+#include <linux/grsecurity.h>
86626 #include <uapi/linux/module.h>
86627 #include "module-internal.h"
86628
86629@@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
86630
86631 /* Bounds of module allocation, for speeding __module_address.
86632 * Protected by module_mutex. */
86633-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
86634+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
86635+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
86636
86637 int register_module_notifier(struct notifier_block * nb)
86638 {
86639@@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86640 return true;
86641
86642 list_for_each_entry_rcu(mod, &modules, list) {
86643- struct symsearch arr[] = {
86644+ struct symsearch modarr[] = {
86645 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
86646 NOT_GPL_ONLY, false },
86647 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
86648@@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
86649 if (mod->state == MODULE_STATE_UNFORMED)
86650 continue;
86651
86652- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
86653+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
86654 return true;
86655 }
86656 return false;
86657@@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
86658 if (!pcpusec->sh_size)
86659 return 0;
86660
86661- if (align > PAGE_SIZE) {
86662+ if (align-1 >= PAGE_SIZE) {
86663 pr_warn("%s: per-cpu alignment %li > %li\n",
86664 mod->name, align, PAGE_SIZE);
86665 align = PAGE_SIZE;
86666@@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
86667 static ssize_t show_coresize(struct module_attribute *mattr,
86668 struct module_kobject *mk, char *buffer)
86669 {
86670- return sprintf(buffer, "%u\n", mk->mod->core_size);
86671+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
86672 }
86673
86674 static struct module_attribute modinfo_coresize =
86675@@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
86676 static ssize_t show_initsize(struct module_attribute *mattr,
86677 struct module_kobject *mk, char *buffer)
86678 {
86679- return sprintf(buffer, "%u\n", mk->mod->init_size);
86680+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
86681 }
86682
86683 static struct module_attribute modinfo_initsize =
86684@@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
86685 goto bad_version;
86686 }
86687
86688+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86689+ /*
86690+ * avoid potentially printing jibberish on attempted load
86691+ * of a module randomized with a different seed
86692+ */
86693+ pr_warn("no symbol version for %s\n", symname);
86694+#else
86695 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
86696+#endif
86697 return 0;
86698
86699 bad_version:
86700+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86701+ /*
86702+ * avoid potentially printing jibberish on attempted load
86703+ * of a module randomized with a different seed
86704+ */
86705+ printk("attempted module disagrees about version of symbol %s\n",
86706+ symname);
86707+#else
86708 printk("%s: disagrees about version of symbol %s\n",
86709 mod->name, symname);
86710+#endif
86711 return 0;
86712 }
86713
86714@@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
86715 */
86716 #ifdef CONFIG_SYSFS
86717
86718-#ifdef CONFIG_KALLSYMS
86719+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
86720 static inline bool sect_empty(const Elf_Shdr *sect)
86721 {
86722 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
86723@@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
86724 {
86725 unsigned int notes, loaded, i;
86726 struct module_notes_attrs *notes_attrs;
86727- struct bin_attribute *nattr;
86728+ bin_attribute_no_const *nattr;
86729
86730 /* failed to create section attributes, so can't create notes */
86731 if (!mod->sect_attrs)
86732@@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
86733 static int module_add_modinfo_attrs(struct module *mod)
86734 {
86735 struct module_attribute *attr;
86736- struct module_attribute *temp_attr;
86737+ module_attribute_no_const *temp_attr;
86738 int error = 0;
86739 int i;
86740
86741@@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
86742
86743 static void unset_module_core_ro_nx(struct module *mod)
86744 {
86745- set_page_attributes(mod->module_core + mod->core_text_size,
86746- mod->module_core + mod->core_size,
86747+ set_page_attributes(mod->module_core_rw,
86748+ mod->module_core_rw + mod->core_size_rw,
86749 set_memory_x);
86750- set_page_attributes(mod->module_core,
86751- mod->module_core + mod->core_ro_size,
86752+ set_page_attributes(mod->module_core_rx,
86753+ mod->module_core_rx + mod->core_size_rx,
86754 set_memory_rw);
86755 }
86756
86757 static void unset_module_init_ro_nx(struct module *mod)
86758 {
86759- set_page_attributes(mod->module_init + mod->init_text_size,
86760- mod->module_init + mod->init_size,
86761+ set_page_attributes(mod->module_init_rw,
86762+ mod->module_init_rw + mod->init_size_rw,
86763 set_memory_x);
86764- set_page_attributes(mod->module_init,
86765- mod->module_init + mod->init_ro_size,
86766+ set_page_attributes(mod->module_init_rx,
86767+ mod->module_init_rx + mod->init_size_rx,
86768 set_memory_rw);
86769 }
86770
86771@@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
86772 list_for_each_entry_rcu(mod, &modules, list) {
86773 if (mod->state == MODULE_STATE_UNFORMED)
86774 continue;
86775- if ((mod->module_core) && (mod->core_text_size)) {
86776- set_page_attributes(mod->module_core,
86777- mod->module_core + mod->core_text_size,
86778+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86779+ set_page_attributes(mod->module_core_rx,
86780+ mod->module_core_rx + mod->core_size_rx,
86781 set_memory_rw);
86782 }
86783- if ((mod->module_init) && (mod->init_text_size)) {
86784- set_page_attributes(mod->module_init,
86785- mod->module_init + mod->init_text_size,
86786+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86787+ set_page_attributes(mod->module_init_rx,
86788+ mod->module_init_rx + mod->init_size_rx,
86789 set_memory_rw);
86790 }
86791 }
86792@@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
86793 list_for_each_entry_rcu(mod, &modules, list) {
86794 if (mod->state == MODULE_STATE_UNFORMED)
86795 continue;
86796- if ((mod->module_core) && (mod->core_text_size)) {
86797- set_page_attributes(mod->module_core,
86798- mod->module_core + mod->core_text_size,
86799+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
86800+ set_page_attributes(mod->module_core_rx,
86801+ mod->module_core_rx + mod->core_size_rx,
86802 set_memory_ro);
86803 }
86804- if ((mod->module_init) && (mod->init_text_size)) {
86805- set_page_attributes(mod->module_init,
86806- mod->module_init + mod->init_text_size,
86807+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
86808+ set_page_attributes(mod->module_init_rx,
86809+ mod->module_init_rx + mod->init_size_rx,
86810 set_memory_ro);
86811 }
86812 }
86813@@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
86814
86815 /* This may be NULL, but that's OK */
86816 unset_module_init_ro_nx(mod);
86817- module_free(mod, mod->module_init);
86818+ module_free(mod, mod->module_init_rw);
86819+ module_free_exec(mod, mod->module_init_rx);
86820 kfree(mod->args);
86821 percpu_modfree(mod);
86822
86823 /* Free lock-classes: */
86824- lockdep_free_key_range(mod->module_core, mod->core_size);
86825+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
86826+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
86827
86828 /* Finally, free the core (containing the module structure) */
86829 unset_module_core_ro_nx(mod);
86830- module_free(mod, mod->module_core);
86831+ module_free_exec(mod, mod->module_core_rx);
86832+ module_free(mod, mod->module_core_rw);
86833
86834 #ifdef CONFIG_MPU
86835 update_protections(current->mm);
86836@@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86837 int ret = 0;
86838 const struct kernel_symbol *ksym;
86839
86840+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86841+ int is_fs_load = 0;
86842+ int register_filesystem_found = 0;
86843+ char *p;
86844+
86845+ p = strstr(mod->args, "grsec_modharden_fs");
86846+ if (p) {
86847+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
86848+ /* copy \0 as well */
86849+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
86850+ is_fs_load = 1;
86851+ }
86852+#endif
86853+
86854 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
86855 const char *name = info->strtab + sym[i].st_name;
86856
86857+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86858+ /* it's a real shame this will never get ripped and copied
86859+ upstream! ;(
86860+ */
86861+ if (is_fs_load && !strcmp(name, "register_filesystem"))
86862+ register_filesystem_found = 1;
86863+#endif
86864+
86865 switch (sym[i].st_shndx) {
86866 case SHN_COMMON:
86867 /* We compiled with -fno-common. These are not
86868@@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86869 ksym = resolve_symbol_wait(mod, info, name);
86870 /* Ok if resolved. */
86871 if (ksym && !IS_ERR(ksym)) {
86872+ pax_open_kernel();
86873 sym[i].st_value = ksym->value;
86874+ pax_close_kernel();
86875 break;
86876 }
86877
86878@@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
86879 secbase = (unsigned long)mod_percpu(mod);
86880 else
86881 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
86882+ pax_open_kernel();
86883 sym[i].st_value += secbase;
86884+ pax_close_kernel();
86885 break;
86886 }
86887 }
86888
86889+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86890+ if (is_fs_load && !register_filesystem_found) {
86891+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
86892+ ret = -EPERM;
86893+ }
86894+#endif
86895+
86896 return ret;
86897 }
86898
86899@@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
86900 || s->sh_entsize != ~0UL
86901 || strstarts(sname, ".init"))
86902 continue;
86903- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
86904+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86905+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
86906+ else
86907+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
86908 pr_debug("\t%s\n", sname);
86909 }
86910- switch (m) {
86911- case 0: /* executable */
86912- mod->core_size = debug_align(mod->core_size);
86913- mod->core_text_size = mod->core_size;
86914- break;
86915- case 1: /* RO: text and ro-data */
86916- mod->core_size = debug_align(mod->core_size);
86917- mod->core_ro_size = mod->core_size;
86918- break;
86919- case 3: /* whole core */
86920- mod->core_size = debug_align(mod->core_size);
86921- break;
86922- }
86923 }
86924
86925 pr_debug("Init section allocation order:\n");
86926@@ -2104,23 +2149,13 @@ 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->init_size, s, i)
86931- | INIT_OFFSET_MASK);
86932+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
86933+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
86934+ else
86935+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
86936+ s->sh_entsize |= INIT_OFFSET_MASK;
86937 pr_debug("\t%s\n", sname);
86938 }
86939- switch (m) {
86940- case 0: /* executable */
86941- mod->init_size = debug_align(mod->init_size);
86942- mod->init_text_size = mod->init_size;
86943- break;
86944- case 1: /* RO: text and ro-data */
86945- mod->init_size = debug_align(mod->init_size);
86946- mod->init_ro_size = mod->init_size;
86947- break;
86948- case 3: /* whole init */
86949- mod->init_size = debug_align(mod->init_size);
86950- break;
86951- }
86952 }
86953 }
86954
86955@@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86956
86957 /* Put symbol section at end of init part of module. */
86958 symsect->sh_flags |= SHF_ALLOC;
86959- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
86960+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
86961 info->index.sym) | INIT_OFFSET_MASK;
86962 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
86963
86964@@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
86965 }
86966
86967 /* Append room for core symbols at end of core part. */
86968- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
86969- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
86970- mod->core_size += strtab_size;
86971+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
86972+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
86973+ mod->core_size_rx += strtab_size;
86974
86975 /* Put string table section at end of init part of module. */
86976 strsect->sh_flags |= SHF_ALLOC;
86977- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
86978+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
86979 info->index.str) | INIT_OFFSET_MASK;
86980 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
86981 }
86982@@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
86983 /* Make sure we get permanent strtab: don't use info->strtab. */
86984 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
86985
86986+ pax_open_kernel();
86987+
86988 /* Set types up while we still have access to sections. */
86989 for (i = 0; i < mod->num_symtab; i++)
86990 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
86991
86992- mod->core_symtab = dst = mod->module_core + info->symoffs;
86993- mod->core_strtab = s = mod->module_core + info->stroffs;
86994+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
86995+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
86996 src = mod->symtab;
86997 for (ndst = i = 0; i < mod->num_symtab; i++) {
86998 if (i == 0 ||
86999@@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
87000 }
87001 }
87002 mod->core_num_syms = ndst;
87003+
87004+ pax_close_kernel();
87005 }
87006 #else
87007 static inline void layout_symtab(struct module *mod, struct load_info *info)
87008@@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
87009 return vmalloc_exec(size);
87010 }
87011
87012-static void *module_alloc_update_bounds(unsigned long size)
87013+static void *module_alloc_update_bounds_rw(unsigned long size)
87014 {
87015 void *ret = module_alloc(size);
87016
87017 if (ret) {
87018 mutex_lock(&module_mutex);
87019 /* Update module bounds. */
87020- if ((unsigned long)ret < module_addr_min)
87021- module_addr_min = (unsigned long)ret;
87022- if ((unsigned long)ret + size > module_addr_max)
87023- module_addr_max = (unsigned long)ret + size;
87024+ if ((unsigned long)ret < module_addr_min_rw)
87025+ module_addr_min_rw = (unsigned long)ret;
87026+ if ((unsigned long)ret + size > module_addr_max_rw)
87027+ module_addr_max_rw = (unsigned long)ret + size;
87028+ mutex_unlock(&module_mutex);
87029+ }
87030+ return ret;
87031+}
87032+
87033+static void *module_alloc_update_bounds_rx(unsigned long size)
87034+{
87035+ void *ret = module_alloc_exec(size);
87036+
87037+ if (ret) {
87038+ mutex_lock(&module_mutex);
87039+ /* Update module bounds. */
87040+ if ((unsigned long)ret < module_addr_min_rx)
87041+ module_addr_min_rx = (unsigned long)ret;
87042+ if ((unsigned long)ret + size > module_addr_max_rx)
87043+ module_addr_max_rx = (unsigned long)ret + size;
87044 mutex_unlock(&module_mutex);
87045 }
87046 return ret;
87047@@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87048 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
87049
87050 if (info->index.sym == 0) {
87051+#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87052+ /*
87053+ * avoid potentially printing jibberish on attempted load
87054+ * of a module randomized with a different seed
87055+ */
87056+ pr_warn("module has no symbols (stripped?)\n");
87057+#else
87058 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
87059+#endif
87060 return ERR_PTR(-ENOEXEC);
87061 }
87062
87063@@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
87064 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87065 {
87066 const char *modmagic = get_modinfo(info, "vermagic");
87067+ const char *license = get_modinfo(info, "license");
87068 int err;
87069
87070+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
87071+ if (!license || !license_is_gpl_compatible(license))
87072+ return -ENOEXEC;
87073+#endif
87074+
87075 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
87076 modmagic = NULL;
87077
87078@@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
87079 }
87080
87081 /* Set up license info based on the info section */
87082- set_license(mod, get_modinfo(info, "license"));
87083+ set_license(mod, license);
87084
87085 return 0;
87086 }
87087@@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
87088 void *ptr;
87089
87090 /* Do the allocs. */
87091- ptr = module_alloc_update_bounds(mod->core_size);
87092+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
87093 /*
87094 * The pointer to this block is stored in the module structure
87095 * which is inside the block. Just mark it as not being a
87096@@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
87097 if (!ptr)
87098 return -ENOMEM;
87099
87100- memset(ptr, 0, mod->core_size);
87101- mod->module_core = ptr;
87102+ memset(ptr, 0, mod->core_size_rw);
87103+ mod->module_core_rw = ptr;
87104
87105- if (mod->init_size) {
87106- ptr = module_alloc_update_bounds(mod->init_size);
87107+ if (mod->init_size_rw) {
87108+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
87109 /*
87110 * The pointer to this block is stored in the module structure
87111 * which is inside the block. This block doesn't need to be
87112@@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
87113 */
87114 kmemleak_ignore(ptr);
87115 if (!ptr) {
87116- module_free(mod, mod->module_core);
87117+ module_free(mod, mod->module_core_rw);
87118 return -ENOMEM;
87119 }
87120- memset(ptr, 0, mod->init_size);
87121- mod->module_init = ptr;
87122+ memset(ptr, 0, mod->init_size_rw);
87123+ mod->module_init_rw = ptr;
87124 } else
87125- mod->module_init = NULL;
87126+ mod->module_init_rw = NULL;
87127+
87128+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
87129+ kmemleak_not_leak(ptr);
87130+ if (!ptr) {
87131+ if (mod->module_init_rw)
87132+ module_free(mod, mod->module_init_rw);
87133+ module_free(mod, mod->module_core_rw);
87134+ return -ENOMEM;
87135+ }
87136+
87137+ pax_open_kernel();
87138+ memset(ptr, 0, mod->core_size_rx);
87139+ pax_close_kernel();
87140+ mod->module_core_rx = ptr;
87141+
87142+ if (mod->init_size_rx) {
87143+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
87144+ kmemleak_ignore(ptr);
87145+ if (!ptr && mod->init_size_rx) {
87146+ module_free_exec(mod, mod->module_core_rx);
87147+ if (mod->module_init_rw)
87148+ module_free(mod, mod->module_init_rw);
87149+ module_free(mod, mod->module_core_rw);
87150+ return -ENOMEM;
87151+ }
87152+
87153+ pax_open_kernel();
87154+ memset(ptr, 0, mod->init_size_rx);
87155+ pax_close_kernel();
87156+ mod->module_init_rx = ptr;
87157+ } else
87158+ mod->module_init_rx = NULL;
87159
87160 /* Transfer each section which specifies SHF_ALLOC */
87161 pr_debug("final section addresses:\n");
87162@@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
87163 if (!(shdr->sh_flags & SHF_ALLOC))
87164 continue;
87165
87166- if (shdr->sh_entsize & INIT_OFFSET_MASK)
87167- dest = mod->module_init
87168- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87169- else
87170- dest = mod->module_core + shdr->sh_entsize;
87171+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
87172+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87173+ dest = mod->module_init_rw
87174+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87175+ else
87176+ dest = mod->module_init_rx
87177+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
87178+ } else {
87179+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
87180+ dest = mod->module_core_rw + shdr->sh_entsize;
87181+ else
87182+ dest = mod->module_core_rx + shdr->sh_entsize;
87183+ }
87184+
87185+ if (shdr->sh_type != SHT_NOBITS) {
87186+
87187+#ifdef CONFIG_PAX_KERNEXEC
87188+#ifdef CONFIG_X86_64
87189+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
87190+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
87191+#endif
87192+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
87193+ pax_open_kernel();
87194+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87195+ pax_close_kernel();
87196+ } else
87197+#endif
87198
87199- if (shdr->sh_type != SHT_NOBITS)
87200 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
87201+ }
87202 /* Update sh_addr to point to copy in image. */
87203- shdr->sh_addr = (unsigned long)dest;
87204+
87205+#ifdef CONFIG_PAX_KERNEXEC
87206+ if (shdr->sh_flags & SHF_EXECINSTR)
87207+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
87208+ else
87209+#endif
87210+
87211+ shdr->sh_addr = (unsigned long)dest;
87212 pr_debug("\t0x%lx %s\n",
87213 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
87214 }
87215@@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
87216 * Do it before processing of module parameters, so the module
87217 * can provide parameter accessor functions of its own.
87218 */
87219- if (mod->module_init)
87220- flush_icache_range((unsigned long)mod->module_init,
87221- (unsigned long)mod->module_init
87222- + mod->init_size);
87223- flush_icache_range((unsigned long)mod->module_core,
87224- (unsigned long)mod->module_core + mod->core_size);
87225+ if (mod->module_init_rx)
87226+ flush_icache_range((unsigned long)mod->module_init_rx,
87227+ (unsigned long)mod->module_init_rx
87228+ + mod->init_size_rx);
87229+ flush_icache_range((unsigned long)mod->module_core_rx,
87230+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
87231
87232 set_fs(old_fs);
87233 }
87234@@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
87235 static void module_deallocate(struct module *mod, struct load_info *info)
87236 {
87237 percpu_modfree(mod);
87238- module_free(mod, mod->module_init);
87239- module_free(mod, mod->module_core);
87240+ module_free_exec(mod, mod->module_init_rx);
87241+ module_free_exec(mod, mod->module_core_rx);
87242+ module_free(mod, mod->module_init_rw);
87243+ module_free(mod, mod->module_core_rw);
87244 }
87245
87246 int __weak module_finalize(const Elf_Ehdr *hdr,
87247@@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
87248 static int post_relocation(struct module *mod, const struct load_info *info)
87249 {
87250 /* Sort exception table now relocations are done. */
87251+ pax_open_kernel();
87252 sort_extable(mod->extable, mod->extable + mod->num_exentries);
87253+ pax_close_kernel();
87254
87255 /* Copy relocated percpu area over. */
87256 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
87257@@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
87258 MODULE_STATE_COMING, mod);
87259
87260 /* Set RO and NX regions for core */
87261- set_section_ro_nx(mod->module_core,
87262- mod->core_text_size,
87263- mod->core_ro_size,
87264- mod->core_size);
87265+ set_section_ro_nx(mod->module_core_rx,
87266+ mod->core_size_rx,
87267+ mod->core_size_rx,
87268+ mod->core_size_rx);
87269
87270 /* Set RO and NX regions for init */
87271- set_section_ro_nx(mod->module_init,
87272- mod->init_text_size,
87273- mod->init_ro_size,
87274- mod->init_size);
87275+ set_section_ro_nx(mod->module_init_rx,
87276+ mod->init_size_rx,
87277+ mod->init_size_rx,
87278+ mod->init_size_rx);
87279
87280 do_mod_ctors(mod);
87281 /* Start the module */
87282@@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
87283 mod->strtab = mod->core_strtab;
87284 #endif
87285 unset_module_init_ro_nx(mod);
87286- module_free(mod, mod->module_init);
87287- mod->module_init = NULL;
87288- mod->init_size = 0;
87289- mod->init_ro_size = 0;
87290- mod->init_text_size = 0;
87291+ module_free(mod, mod->module_init_rw);
87292+ module_free_exec(mod, mod->module_init_rx);
87293+ mod->module_init_rw = NULL;
87294+ mod->module_init_rx = NULL;
87295+ mod->init_size_rw = 0;
87296+ mod->init_size_rx = 0;
87297 mutex_unlock(&module_mutex);
87298 wake_up_all(&module_wq);
87299
87300@@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
87301 if (err)
87302 goto free_unload;
87303
87304+ /* Now copy in args */
87305+ mod->args = strndup_user(uargs, ~0UL >> 1);
87306+ if (IS_ERR(mod->args)) {
87307+ err = PTR_ERR(mod->args);
87308+ goto free_unload;
87309+ }
87310+
87311 /* Set up MODINFO_ATTR fields */
87312 setup_modinfo(mod, info);
87313
87314+#ifdef CONFIG_GRKERNSEC_MODHARDEN
87315+ {
87316+ char *p, *p2;
87317+
87318+ if (strstr(mod->args, "grsec_modharden_netdev")) {
87319+ 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);
87320+ err = -EPERM;
87321+ goto free_modinfo;
87322+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
87323+ p += sizeof("grsec_modharden_normal") - 1;
87324+ p2 = strstr(p, "_");
87325+ if (p2) {
87326+ *p2 = '\0';
87327+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
87328+ *p2 = '_';
87329+ }
87330+ err = -EPERM;
87331+ goto free_modinfo;
87332+ }
87333+ }
87334+#endif
87335+
87336 /* Fix up syms, so that st_value is a pointer to location. */
87337 err = simplify_symbols(mod, info);
87338 if (err < 0)
87339@@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
87340
87341 flush_module_icache(mod);
87342
87343- /* Now copy in args */
87344- mod->args = strndup_user(uargs, ~0UL >> 1);
87345- if (IS_ERR(mod->args)) {
87346- err = PTR_ERR(mod->args);
87347- goto free_arch_cleanup;
87348- }
87349-
87350 dynamic_debug_setup(info->debug, info->num_debug);
87351
87352 /* Finally it's fully formed, ready to start executing. */
87353@@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
87354 ddebug_cleanup:
87355 dynamic_debug_remove(info->debug);
87356 synchronize_sched();
87357- kfree(mod->args);
87358- free_arch_cleanup:
87359 module_arch_cleanup(mod);
87360 free_modinfo:
87361 free_modinfo(mod);
87362+ kfree(mod->args);
87363 free_unload:
87364 module_unload_free(mod);
87365 unlink_mod:
87366@@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
87367 unsigned long nextval;
87368
87369 /* At worse, next value is at end of module */
87370- if (within_module_init(addr, mod))
87371- nextval = (unsigned long)mod->module_init+mod->init_text_size;
87372+ if (within_module_init_rx(addr, mod))
87373+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
87374+ else if (within_module_init_rw(addr, mod))
87375+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
87376+ else if (within_module_core_rx(addr, mod))
87377+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
87378+ else if (within_module_core_rw(addr, mod))
87379+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
87380 else
87381- nextval = (unsigned long)mod->module_core+mod->core_text_size;
87382+ return NULL;
87383
87384 /* Scan for closest preceding symbol, and next symbol. (ELF
87385 starts real symbols at 1). */
87386@@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
87387 return 0;
87388
87389 seq_printf(m, "%s %u",
87390- mod->name, mod->init_size + mod->core_size);
87391+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
87392 print_unload_info(m, mod);
87393
87394 /* Informative for users. */
87395@@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
87396 mod->state == MODULE_STATE_COMING ? "Loading":
87397 "Live");
87398 /* Used by oprofile and other similar tools. */
87399- seq_printf(m, " 0x%pK", mod->module_core);
87400+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
87401
87402 /* Taints info */
87403 if (mod->taints)
87404@@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
87405
87406 static int __init proc_modules_init(void)
87407 {
87408+#ifndef CONFIG_GRKERNSEC_HIDESYM
87409+#ifdef CONFIG_GRKERNSEC_PROC_USER
87410+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87411+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87412+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
87413+#else
87414 proc_create("modules", 0, NULL, &proc_modules_operations);
87415+#endif
87416+#else
87417+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
87418+#endif
87419 return 0;
87420 }
87421 module_init(proc_modules_init);
87422@@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
87423 {
87424 struct module *mod;
87425
87426- if (addr < module_addr_min || addr > module_addr_max)
87427+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
87428+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
87429 return NULL;
87430
87431 list_for_each_entry_rcu(mod, &modules, list) {
87432 if (mod->state == MODULE_STATE_UNFORMED)
87433 continue;
87434- if (within_module_core(addr, mod)
87435- || within_module_init(addr, mod))
87436+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
87437 return mod;
87438 }
87439 return NULL;
87440@@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
87441 */
87442 struct module *__module_text_address(unsigned long addr)
87443 {
87444- struct module *mod = __module_address(addr);
87445+ struct module *mod;
87446+
87447+#ifdef CONFIG_X86_32
87448+ addr = ktla_ktva(addr);
87449+#endif
87450+
87451+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
87452+ return NULL;
87453+
87454+ mod = __module_address(addr);
87455+
87456 if (mod) {
87457 /* Make sure it's within the text section. */
87458- if (!within(addr, mod->module_init, mod->init_text_size)
87459- && !within(addr, mod->module_core, mod->core_text_size))
87460+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
87461 mod = NULL;
87462 }
87463 return mod;
87464diff --git a/kernel/notifier.c b/kernel/notifier.c
87465index 2d5cc4c..d9ea600 100644
87466--- a/kernel/notifier.c
87467+++ b/kernel/notifier.c
87468@@ -5,6 +5,7 @@
87469 #include <linux/rcupdate.h>
87470 #include <linux/vmalloc.h>
87471 #include <linux/reboot.h>
87472+#include <linux/mm.h>
87473
87474 /*
87475 * Notifier list for kernel code which wants to be called
87476@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
87477 while ((*nl) != NULL) {
87478 if (n->priority > (*nl)->priority)
87479 break;
87480- nl = &((*nl)->next);
87481+ nl = (struct notifier_block **)&((*nl)->next);
87482 }
87483- n->next = *nl;
87484+ pax_open_kernel();
87485+ *(const void **)&n->next = *nl;
87486 rcu_assign_pointer(*nl, n);
87487+ pax_close_kernel();
87488 return 0;
87489 }
87490
87491@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
87492 return 0;
87493 if (n->priority > (*nl)->priority)
87494 break;
87495- nl = &((*nl)->next);
87496+ nl = (struct notifier_block **)&((*nl)->next);
87497 }
87498- n->next = *nl;
87499+ pax_open_kernel();
87500+ *(const void **)&n->next = *nl;
87501 rcu_assign_pointer(*nl, n);
87502+ pax_close_kernel();
87503 return 0;
87504 }
87505
87506@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
87507 {
87508 while ((*nl) != NULL) {
87509 if ((*nl) == n) {
87510+ pax_open_kernel();
87511 rcu_assign_pointer(*nl, n->next);
87512+ pax_close_kernel();
87513 return 0;
87514 }
87515- nl = &((*nl)->next);
87516+ nl = (struct notifier_block **)&((*nl)->next);
87517 }
87518 return -ENOENT;
87519 }
87520diff --git a/kernel/padata.c b/kernel/padata.c
87521index 2abd25d..02c4faa 100644
87522--- a/kernel/padata.c
87523+++ b/kernel/padata.c
87524@@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
87525 * seq_nr mod. number of cpus in use.
87526 */
87527
87528- seq_nr = atomic_inc_return(&pd->seq_nr);
87529+ seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
87530 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
87531
87532 return padata_index_to_cpu(pd, cpu_index);
87533@@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
87534 padata_init_pqueues(pd);
87535 padata_init_squeues(pd);
87536 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
87537- atomic_set(&pd->seq_nr, -1);
87538+ atomic_set_unchecked(&pd->seq_nr, -1);
87539 atomic_set(&pd->reorder_objects, 0);
87540 atomic_set(&pd->refcnt, 0);
87541 pd->pinst = pinst;
87542diff --git a/kernel/panic.c b/kernel/panic.c
87543index c00b4ce..98c7d1a 100644
87544--- a/kernel/panic.c
87545+++ b/kernel/panic.c
87546@@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
87547 /*
87548 * Stop ourself in panic -- architecture code may override this
87549 */
87550-void __weak panic_smp_self_stop(void)
87551+void __weak __noreturn panic_smp_self_stop(void)
87552 {
87553 while (1)
87554 cpu_relax();
87555@@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
87556 disable_trace_on_warning();
87557
87558 pr_warn("------------[ cut here ]------------\n");
87559- pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
87560+ pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
87561 raw_smp_processor_id(), current->pid, file, line, caller);
87562
87563 if (args)
87564@@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
87565 */
87566 void __stack_chk_fail(void)
87567 {
87568- panic("stack-protector: Kernel stack is corrupted in: %p\n",
87569+ dump_stack();
87570+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
87571 __builtin_return_address(0));
87572 }
87573 EXPORT_SYMBOL(__stack_chk_fail);
87574diff --git a/kernel/pid.c b/kernel/pid.c
87575index 9b9a266..c20ef80 100644
87576--- a/kernel/pid.c
87577+++ b/kernel/pid.c
87578@@ -33,6 +33,7 @@
87579 #include <linux/rculist.h>
87580 #include <linux/bootmem.h>
87581 #include <linux/hash.h>
87582+#include <linux/security.h>
87583 #include <linux/pid_namespace.h>
87584 #include <linux/init_task.h>
87585 #include <linux/syscalls.h>
87586@@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
87587
87588 int pid_max = PID_MAX_DEFAULT;
87589
87590-#define RESERVED_PIDS 300
87591+#define RESERVED_PIDS 500
87592
87593 int pid_max_min = RESERVED_PIDS + 1;
87594 int pid_max_max = PID_MAX_LIMIT;
87595@@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
87596 */
87597 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
87598 {
87599+ struct task_struct *task;
87600+
87601 rcu_lockdep_assert(rcu_read_lock_held(),
87602 "find_task_by_pid_ns() needs rcu_read_lock()"
87603 " protection");
87604- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87605+
87606+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
87607+
87608+ if (gr_pid_is_chrooted(task))
87609+ return NULL;
87610+
87611+ return task;
87612 }
87613
87614 struct task_struct *find_task_by_vpid(pid_t vnr)
87615@@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
87616 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
87617 }
87618
87619+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
87620+{
87621+ rcu_lockdep_assert(rcu_read_lock_held(),
87622+ "find_task_by_pid_ns() needs rcu_read_lock()"
87623+ " protection");
87624+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
87625+}
87626+
87627 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
87628 {
87629 struct pid *pid;
87630diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
87631index 06c62de..a0ca23f 100644
87632--- a/kernel/pid_namespace.c
87633+++ b/kernel/pid_namespace.c
87634@@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
87635 void __user *buffer, size_t *lenp, loff_t *ppos)
87636 {
87637 struct pid_namespace *pid_ns = task_active_pid_ns(current);
87638- struct ctl_table tmp = *table;
87639+ ctl_table_no_const tmp = *table;
87640
87641 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
87642 return -EPERM;
87643@@ -318,7 +318,9 @@ static void *pidns_get(struct task_struct *task)
87644 struct pid_namespace *ns;
87645
87646 rcu_read_lock();
87647- ns = get_pid_ns(task_active_pid_ns(task));
87648+ ns = task_active_pid_ns(task);
87649+ if (ns)
87650+ get_pid_ns(ns);
87651 rcu_read_unlock();
87652
87653 return ns;
87654diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
87655index c7f31aa..2b44977 100644
87656--- a/kernel/posix-cpu-timers.c
87657+++ b/kernel/posix-cpu-timers.c
87658@@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
87659
87660 static __init int init_posix_cpu_timers(void)
87661 {
87662- struct k_clock process = {
87663+ static struct k_clock process = {
87664 .clock_getres = process_cpu_clock_getres,
87665 .clock_get = process_cpu_clock_get,
87666 .timer_create = process_cpu_timer_create,
87667 .nsleep = process_cpu_nsleep,
87668 .nsleep_restart = process_cpu_nsleep_restart,
87669 };
87670- struct k_clock thread = {
87671+ static struct k_clock thread = {
87672 .clock_getres = thread_cpu_clock_getres,
87673 .clock_get = thread_cpu_clock_get,
87674 .timer_create = thread_cpu_timer_create,
87675diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
87676index 424c2d4..679242f 100644
87677--- a/kernel/posix-timers.c
87678+++ b/kernel/posix-timers.c
87679@@ -43,6 +43,7 @@
87680 #include <linux/hash.h>
87681 #include <linux/posix-clock.h>
87682 #include <linux/posix-timers.h>
87683+#include <linux/grsecurity.h>
87684 #include <linux/syscalls.h>
87685 #include <linux/wait.h>
87686 #include <linux/workqueue.h>
87687@@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
87688 * which we beg off on and pass to do_sys_settimeofday().
87689 */
87690
87691-static struct k_clock posix_clocks[MAX_CLOCKS];
87692+static struct k_clock *posix_clocks[MAX_CLOCKS];
87693
87694 /*
87695 * These ones are defined below.
87696@@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
87697 */
87698 static __init int init_posix_timers(void)
87699 {
87700- struct k_clock clock_realtime = {
87701+ static struct k_clock clock_realtime = {
87702 .clock_getres = hrtimer_get_res,
87703 .clock_get = posix_clock_realtime_get,
87704 .clock_set = posix_clock_realtime_set,
87705@@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
87706 .timer_get = common_timer_get,
87707 .timer_del = common_timer_del,
87708 };
87709- struct k_clock clock_monotonic = {
87710+ static struct k_clock clock_monotonic = {
87711 .clock_getres = hrtimer_get_res,
87712 .clock_get = posix_ktime_get_ts,
87713 .nsleep = common_nsleep,
87714@@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
87715 .timer_get = common_timer_get,
87716 .timer_del = common_timer_del,
87717 };
87718- struct k_clock clock_monotonic_raw = {
87719+ static struct k_clock clock_monotonic_raw = {
87720 .clock_getres = hrtimer_get_res,
87721 .clock_get = posix_get_monotonic_raw,
87722 };
87723- struct k_clock clock_realtime_coarse = {
87724+ static struct k_clock clock_realtime_coarse = {
87725 .clock_getres = posix_get_coarse_res,
87726 .clock_get = posix_get_realtime_coarse,
87727 };
87728- struct k_clock clock_monotonic_coarse = {
87729+ static struct k_clock clock_monotonic_coarse = {
87730 .clock_getres = posix_get_coarse_res,
87731 .clock_get = posix_get_monotonic_coarse,
87732 };
87733- struct k_clock clock_tai = {
87734+ static struct k_clock clock_tai = {
87735 .clock_getres = hrtimer_get_res,
87736 .clock_get = posix_get_tai,
87737 .nsleep = common_nsleep,
87738@@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
87739 .timer_get = common_timer_get,
87740 .timer_del = common_timer_del,
87741 };
87742- struct k_clock clock_boottime = {
87743+ static struct k_clock clock_boottime = {
87744 .clock_getres = hrtimer_get_res,
87745 .clock_get = posix_get_boottime,
87746 .nsleep = common_nsleep,
87747@@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
87748 return;
87749 }
87750
87751- posix_clocks[clock_id] = *new_clock;
87752+ posix_clocks[clock_id] = new_clock;
87753 }
87754 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
87755
87756@@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
87757 return (id & CLOCKFD_MASK) == CLOCKFD ?
87758 &clock_posix_dynamic : &clock_posix_cpu;
87759
87760- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
87761+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
87762 return NULL;
87763- return &posix_clocks[id];
87764+ return posix_clocks[id];
87765 }
87766
87767 static int common_timer_create(struct k_itimer *new_timer)
87768@@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
87769 struct k_clock *kc = clockid_to_kclock(which_clock);
87770 struct k_itimer *new_timer;
87771 int error, new_timer_id;
87772- sigevent_t event;
87773+ sigevent_t event = { };
87774 int it_id_set = IT_ID_NOT_SET;
87775
87776 if (!kc)
87777@@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
87778 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
87779 return -EFAULT;
87780
87781+ /* only the CLOCK_REALTIME clock can be set, all other clocks
87782+ have their clock_set fptr set to a nosettime dummy function
87783+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
87784+ call common_clock_set, which calls do_sys_settimeofday, which
87785+ we hook
87786+ */
87787+
87788 return kc->clock_set(which_clock, &new_tp);
87789 }
87790
87791diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
87792index 2fac9cc..56fef29 100644
87793--- a/kernel/power/Kconfig
87794+++ b/kernel/power/Kconfig
87795@@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
87796 config HIBERNATION
87797 bool "Hibernation (aka 'suspend to disk')"
87798 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
87799+ depends on !GRKERNSEC_KMEM
87800+ depends on !PAX_MEMORY_SANITIZE
87801 select HIBERNATE_CALLBACKS
87802 select LZO_COMPRESS
87803 select LZO_DECOMPRESS
87804diff --git a/kernel/power/process.c b/kernel/power/process.c
87805index 06ec886..9dba35e 100644
87806--- a/kernel/power/process.c
87807+++ b/kernel/power/process.c
87808@@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
87809 unsigned int elapsed_msecs;
87810 bool wakeup = false;
87811 int sleep_usecs = USEC_PER_MSEC;
87812+ bool timedout = false;
87813
87814 do_gettimeofday(&start);
87815
87816@@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
87817
87818 while (true) {
87819 todo = 0;
87820+ if (time_after(jiffies, end_time))
87821+ timedout = true;
87822 read_lock(&tasklist_lock);
87823 do_each_thread(g, p) {
87824 if (p == current || !freeze_task(p))
87825 continue;
87826
87827- if (!freezer_should_skip(p))
87828+ if (!freezer_should_skip(p)) {
87829 todo++;
87830+ if (timedout) {
87831+ printk(KERN_ERR "Task refusing to freeze:\n");
87832+ sched_show_task(p);
87833+ }
87834+ }
87835 } while_each_thread(g, p);
87836 read_unlock(&tasklist_lock);
87837
87838@@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
87839 todo += wq_busy;
87840 }
87841
87842- if (!todo || time_after(jiffies, end_time))
87843+ if (!todo || timedout)
87844 break;
87845
87846 if (pm_wakeup_pending()) {
87847diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
87848index 97fb834..b972b27 100644
87849--- a/kernel/printk/printk.c
87850+++ b/kernel/printk/printk.c
87851@@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
87852 if (from_file && type != SYSLOG_ACTION_OPEN)
87853 return 0;
87854
87855+#ifdef CONFIG_GRKERNSEC_DMESG
87856+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
87857+ return -EPERM;
87858+#endif
87859+
87860 if (syslog_action_restricted(type)) {
87861 if (capable(CAP_SYSLOG))
87862 return 0;
87863diff --git a/kernel/profile.c b/kernel/profile.c
87864index 6631e1e..310c266 100644
87865--- a/kernel/profile.c
87866+++ b/kernel/profile.c
87867@@ -37,7 +37,7 @@ struct profile_hit {
87868 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
87869 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
87870
87871-static atomic_t *prof_buffer;
87872+static atomic_unchecked_t *prof_buffer;
87873 static unsigned long prof_len, prof_shift;
87874
87875 int prof_on __read_mostly;
87876@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
87877 hits[i].pc = 0;
87878 continue;
87879 }
87880- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87881+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87882 hits[i].hits = hits[i].pc = 0;
87883 }
87884 }
87885@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87886 * Add the current hit(s) and flush the write-queue out
87887 * to the global buffer:
87888 */
87889- atomic_add(nr_hits, &prof_buffer[pc]);
87890+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
87891 for (i = 0; i < NR_PROFILE_HIT; ++i) {
87892- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
87893+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
87894 hits[i].pc = hits[i].hits = 0;
87895 }
87896 out:
87897@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
87898 {
87899 unsigned long pc;
87900 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
87901- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87902+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
87903 }
87904 #endif /* !CONFIG_SMP */
87905
87906@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
87907 return -EFAULT;
87908 buf++; p++; count--; read++;
87909 }
87910- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
87911+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
87912 if (copy_to_user(buf, (void *)pnt, count))
87913 return -EFAULT;
87914 read += count;
87915@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
87916 }
87917 #endif
87918 profile_discard_flip_buffers();
87919- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
87920+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
87921 return count;
87922 }
87923
87924diff --git a/kernel/ptrace.c b/kernel/ptrace.c
87925index 1f4bcb3..99cf7ab 100644
87926--- a/kernel/ptrace.c
87927+++ b/kernel/ptrace.c
87928@@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
87929 if (seize)
87930 flags |= PT_SEIZED;
87931 rcu_read_lock();
87932- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87933+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
87934 flags |= PT_PTRACE_CAP;
87935 rcu_read_unlock();
87936 task->ptrace = flags;
87937@@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
87938 break;
87939 return -EIO;
87940 }
87941- if (copy_to_user(dst, buf, retval))
87942+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
87943 return -EFAULT;
87944 copied += retval;
87945 src += retval;
87946@@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
87947 bool seized = child->ptrace & PT_SEIZED;
87948 int ret = -EIO;
87949 siginfo_t siginfo, *si;
87950- void __user *datavp = (void __user *) data;
87951+ void __user *datavp = (__force void __user *) data;
87952 unsigned long __user *datalp = datavp;
87953 unsigned long flags;
87954
87955@@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
87956 goto out;
87957 }
87958
87959+ if (gr_handle_ptrace(child, request)) {
87960+ ret = -EPERM;
87961+ goto out_put_task_struct;
87962+ }
87963+
87964 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
87965 ret = ptrace_attach(child, request, addr, data);
87966 /*
87967 * Some architectures need to do book-keeping after
87968 * a ptrace attach.
87969 */
87970- if (!ret)
87971+ if (!ret) {
87972 arch_ptrace_attach(child);
87973+ gr_audit_ptrace(child);
87974+ }
87975 goto out_put_task_struct;
87976 }
87977
87978@@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
87979 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
87980 if (copied != sizeof(tmp))
87981 return -EIO;
87982- return put_user(tmp, (unsigned long __user *)data);
87983+ return put_user(tmp, (__force unsigned long __user *)data);
87984 }
87985
87986 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
87987@@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
87988 }
87989
87990 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87991- compat_long_t addr, compat_long_t data)
87992+ compat_ulong_t addr, compat_ulong_t data)
87993 {
87994 struct task_struct *child;
87995 long ret;
87996@@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
87997 goto out;
87998 }
87999
88000+ if (gr_handle_ptrace(child, request)) {
88001+ ret = -EPERM;
88002+ goto out_put_task_struct;
88003+ }
88004+
88005 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
88006 ret = ptrace_attach(child, request, addr, data);
88007 /*
88008 * Some architectures need to do book-keeping after
88009 * a ptrace attach.
88010 */
88011- if (!ret)
88012+ if (!ret) {
88013 arch_ptrace_attach(child);
88014+ gr_audit_ptrace(child);
88015+ }
88016 goto out_put_task_struct;
88017 }
88018
88019diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
88020index 01d5ccb..cdcbee6 100644
88021--- a/kernel/rcu/srcu.c
88022+++ b/kernel/rcu/srcu.c
88023@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
88024
88025 idx = ACCESS_ONCE(sp->completed) & 0x1;
88026 preempt_disable();
88027- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88028+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
88029 smp_mb(); /* B */ /* Avoid leaking the critical section. */
88030- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88031+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
88032 preempt_enable();
88033 return idx;
88034 }
88035diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
88036index 1254f31..16258dc 100644
88037--- a/kernel/rcu/tiny.c
88038+++ b/kernel/rcu/tiny.c
88039@@ -46,7 +46,7 @@
88040 /* Forward declarations for tiny_plugin.h. */
88041 struct rcu_ctrlblk;
88042 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
88043-static void rcu_process_callbacks(struct softirq_action *unused);
88044+static void rcu_process_callbacks(void);
88045 static void __call_rcu(struct rcu_head *head,
88046 void (*func)(struct rcu_head *rcu),
88047 struct rcu_ctrlblk *rcp);
88048@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
88049 false));
88050 }
88051
88052-static void rcu_process_callbacks(struct softirq_action *unused)
88053+static __latent_entropy void rcu_process_callbacks(void)
88054 {
88055 __rcu_process_callbacks(&rcu_sched_ctrlblk);
88056 __rcu_process_callbacks(&rcu_bh_ctrlblk);
88057diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
88058index 3929cd4..421624d 100644
88059--- a/kernel/rcu/torture.c
88060+++ b/kernel/rcu/torture.c
88061@@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
88062 { 0 };
88063 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
88064 { 0 };
88065-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88066-static atomic_t n_rcu_torture_alloc;
88067-static atomic_t n_rcu_torture_alloc_fail;
88068-static atomic_t n_rcu_torture_free;
88069-static atomic_t n_rcu_torture_mberror;
88070-static atomic_t n_rcu_torture_error;
88071+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
88072+static atomic_unchecked_t n_rcu_torture_alloc;
88073+static atomic_unchecked_t n_rcu_torture_alloc_fail;
88074+static atomic_unchecked_t n_rcu_torture_free;
88075+static atomic_unchecked_t n_rcu_torture_mberror;
88076+static atomic_unchecked_t n_rcu_torture_error;
88077 static long n_rcu_torture_barrier_error;
88078 static long n_rcu_torture_boost_ktrerror;
88079 static long n_rcu_torture_boost_rterror;
88080@@ -299,11 +299,11 @@ rcu_torture_alloc(void)
88081
88082 spin_lock_bh(&rcu_torture_lock);
88083 if (list_empty(&rcu_torture_freelist)) {
88084- atomic_inc(&n_rcu_torture_alloc_fail);
88085+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
88086 spin_unlock_bh(&rcu_torture_lock);
88087 return NULL;
88088 }
88089- atomic_inc(&n_rcu_torture_alloc);
88090+ atomic_inc_unchecked(&n_rcu_torture_alloc);
88091 p = rcu_torture_freelist.next;
88092 list_del_init(p);
88093 spin_unlock_bh(&rcu_torture_lock);
88094@@ -316,7 +316,7 @@ rcu_torture_alloc(void)
88095 static void
88096 rcu_torture_free(struct rcu_torture *p)
88097 {
88098- atomic_inc(&n_rcu_torture_free);
88099+ atomic_inc_unchecked(&n_rcu_torture_free);
88100 spin_lock_bh(&rcu_torture_lock);
88101 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
88102 spin_unlock_bh(&rcu_torture_lock);
88103@@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
88104 i = rp->rtort_pipe_count;
88105 if (i > RCU_TORTURE_PIPE_LEN)
88106 i = RCU_TORTURE_PIPE_LEN;
88107- atomic_inc(&rcu_torture_wcount[i]);
88108+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88109 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
88110 rp->rtort_mbtest = 0;
88111 rcu_torture_free(rp);
88112@@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
88113 i = old_rp->rtort_pipe_count;
88114 if (i > RCU_TORTURE_PIPE_LEN)
88115 i = RCU_TORTURE_PIPE_LEN;
88116- atomic_inc(&rcu_torture_wcount[i]);
88117+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88118 old_rp->rtort_pipe_count++;
88119 if (gp_normal == gp_exp)
88120 exp = !!(rcu_random(&rand) & 0x80);
88121@@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
88122 i = rp->rtort_pipe_count;
88123 if (i > RCU_TORTURE_PIPE_LEN)
88124 i = RCU_TORTURE_PIPE_LEN;
88125- atomic_inc(&rcu_torture_wcount[i]);
88126+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
88127 if (++rp->rtort_pipe_count >=
88128 RCU_TORTURE_PIPE_LEN) {
88129 rp->rtort_mbtest = 0;
88130@@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
88131 return;
88132 }
88133 if (p->rtort_mbtest == 0)
88134- atomic_inc(&n_rcu_torture_mberror);
88135+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88136 spin_lock(&rand_lock);
88137 cur_ops->read_delay(&rand);
88138 n_rcu_torture_timers++;
88139@@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
88140 continue;
88141 }
88142 if (p->rtort_mbtest == 0)
88143- atomic_inc(&n_rcu_torture_mberror);
88144+ atomic_inc_unchecked(&n_rcu_torture_mberror);
88145 cur_ops->read_delay(&rand);
88146 preempt_disable();
88147 pipe_count = p->rtort_pipe_count;
88148@@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
88149 rcu_torture_current,
88150 rcu_torture_current_version,
88151 list_empty(&rcu_torture_freelist),
88152- atomic_read(&n_rcu_torture_alloc),
88153- atomic_read(&n_rcu_torture_alloc_fail),
88154- atomic_read(&n_rcu_torture_free));
88155+ atomic_read_unchecked(&n_rcu_torture_alloc),
88156+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
88157+ atomic_read_unchecked(&n_rcu_torture_free));
88158 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
88159- atomic_read(&n_rcu_torture_mberror),
88160+ atomic_read_unchecked(&n_rcu_torture_mberror),
88161 n_rcu_torture_boost_ktrerror,
88162 n_rcu_torture_boost_rterror);
88163 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
88164@@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
88165 n_barrier_attempts,
88166 n_rcu_torture_barrier_error);
88167 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
88168- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
88169+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
88170 n_rcu_torture_barrier_error != 0 ||
88171 n_rcu_torture_boost_ktrerror != 0 ||
88172 n_rcu_torture_boost_rterror != 0 ||
88173 n_rcu_torture_boost_failure != 0 ||
88174 i > 1) {
88175 cnt += sprintf(&page[cnt], "!!! ");
88176- atomic_inc(&n_rcu_torture_error);
88177+ atomic_inc_unchecked(&n_rcu_torture_error);
88178 WARN_ON_ONCE(1);
88179 }
88180 cnt += sprintf(&page[cnt], "Reader Pipe: ");
88181@@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
88182 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
88183 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88184 cnt += sprintf(&page[cnt], " %d",
88185- atomic_read(&rcu_torture_wcount[i]));
88186+ atomic_read_unchecked(&rcu_torture_wcount[i]));
88187 }
88188 cnt += sprintf(&page[cnt], "\n");
88189 if (cur_ops->stats)
88190@@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
88191
88192 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
88193
88194- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88195+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
88196 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
88197 else if (n_online_successes != n_online_attempts ||
88198 n_offline_successes != n_offline_attempts)
88199@@ -1958,18 +1958,18 @@ rcu_torture_init(void)
88200
88201 rcu_torture_current = NULL;
88202 rcu_torture_current_version = 0;
88203- atomic_set(&n_rcu_torture_alloc, 0);
88204- atomic_set(&n_rcu_torture_alloc_fail, 0);
88205- atomic_set(&n_rcu_torture_free, 0);
88206- atomic_set(&n_rcu_torture_mberror, 0);
88207- atomic_set(&n_rcu_torture_error, 0);
88208+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
88209+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
88210+ atomic_set_unchecked(&n_rcu_torture_free, 0);
88211+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
88212+ atomic_set_unchecked(&n_rcu_torture_error, 0);
88213 n_rcu_torture_barrier_error = 0;
88214 n_rcu_torture_boost_ktrerror = 0;
88215 n_rcu_torture_boost_rterror = 0;
88216 n_rcu_torture_boost_failure = 0;
88217 n_rcu_torture_boosts = 0;
88218 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
88219- atomic_set(&rcu_torture_wcount[i], 0);
88220+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
88221 for_each_possible_cpu(cpu) {
88222 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
88223 per_cpu(rcu_torture_count, cpu)[i] = 0;
88224diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
88225index dd08198..5ccccbe 100644
88226--- a/kernel/rcu/tree.c
88227+++ b/kernel/rcu/tree.c
88228@@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
88229 rcu_prepare_for_idle(smp_processor_id());
88230 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88231 smp_mb__before_atomic_inc(); /* See above. */
88232- atomic_inc(&rdtp->dynticks);
88233+ atomic_inc_unchecked(&rdtp->dynticks);
88234 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
88235- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88236+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88237
88238 /*
88239 * It is illegal to enter an extended quiescent state while
88240@@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
88241 int user)
88242 {
88243 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
88244- atomic_inc(&rdtp->dynticks);
88245+ atomic_inc_unchecked(&rdtp->dynticks);
88246 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88247 smp_mb__after_atomic_inc(); /* See above. */
88248- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88249+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88250 rcu_cleanup_after_idle(smp_processor_id());
88251 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
88252 if (!user && !is_idle_task(current)) {
88253@@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
88254 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
88255
88256 if (rdtp->dynticks_nmi_nesting == 0 &&
88257- (atomic_read(&rdtp->dynticks) & 0x1))
88258+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
88259 return;
88260 rdtp->dynticks_nmi_nesting++;
88261 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
88262- atomic_inc(&rdtp->dynticks);
88263+ atomic_inc_unchecked(&rdtp->dynticks);
88264 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
88265 smp_mb__after_atomic_inc(); /* See above. */
88266- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
88267+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
88268 }
88269
88270 /**
88271@@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
88272 return;
88273 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
88274 smp_mb__before_atomic_inc(); /* See above. */
88275- atomic_inc(&rdtp->dynticks);
88276+ atomic_inc_unchecked(&rdtp->dynticks);
88277 smp_mb__after_atomic_inc(); /* Force delay to next write. */
88278- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
88279+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
88280 }
88281
88282 /**
88283@@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
88284 */
88285 bool notrace __rcu_is_watching(void)
88286 {
88287- return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88288+ return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
88289 }
88290
88291 /**
88292@@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
88293 static int dyntick_save_progress_counter(struct rcu_data *rdp,
88294 bool *isidle, unsigned long *maxj)
88295 {
88296- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
88297+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88298 rcu_sysidle_check_cpu(rdp, isidle, maxj);
88299 return (rdp->dynticks_snap & 0x1) == 0;
88300 }
88301@@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
88302 unsigned int curr;
88303 unsigned int snap;
88304
88305- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
88306+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
88307 snap = (unsigned int)rdp->dynticks_snap;
88308
88309 /*
88310@@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
88311 rdp = this_cpu_ptr(rsp->rda);
88312 rcu_preempt_check_blocked_tasks(rnp);
88313 rnp->qsmask = rnp->qsmaskinit;
88314- ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
88315+ ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
88316 WARN_ON_ONCE(rnp->completed != rsp->completed);
88317- ACCESS_ONCE(rnp->completed) = rsp->completed;
88318+ ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
88319 if (rnp == rdp->mynode)
88320 __note_gp_changes(rsp, rnp, rdp);
88321 rcu_preempt_boost_start_gp(rnp);
88322@@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
88323 */
88324 rcu_for_each_node_breadth_first(rsp, rnp) {
88325 raw_spin_lock_irq(&rnp->lock);
88326- ACCESS_ONCE(rnp->completed) = rsp->gpnum;
88327+ ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
88328 rdp = this_cpu_ptr(rsp->rda);
88329 if (rnp == rdp->mynode)
88330 __note_gp_changes(rsp, rnp, rdp);
88331@@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
88332 rsp->qlen += rdp->qlen;
88333 rdp->n_cbs_orphaned += rdp->qlen;
88334 rdp->qlen_lazy = 0;
88335- ACCESS_ONCE(rdp->qlen) = 0;
88336+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88337 }
88338
88339 /*
88340@@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
88341 }
88342 smp_mb(); /* List handling before counting for rcu_barrier(). */
88343 rdp->qlen_lazy -= count_lazy;
88344- ACCESS_ONCE(rdp->qlen) -= count;
88345+ ACCESS_ONCE_RW(rdp->qlen) -= count;
88346 rdp->n_cbs_invoked += count;
88347
88348 /* Reinstate batch limit if we have worked down the excess. */
88349@@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
88350 /*
88351 * Do RCU core processing for the current CPU.
88352 */
88353-static void rcu_process_callbacks(struct softirq_action *unused)
88354+static void rcu_process_callbacks(void)
88355 {
88356 struct rcu_state *rsp;
88357
88358@@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88359 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
88360 if (debug_rcu_head_queue(head)) {
88361 /* Probable double call_rcu(), so leak the callback. */
88362- ACCESS_ONCE(head->func) = rcu_leak_callback;
88363+ ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
88364 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
88365 return;
88366 }
88367@@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
88368 local_irq_restore(flags);
88369 return;
88370 }
88371- ACCESS_ONCE(rdp->qlen)++;
88372+ ACCESS_ONCE_RW(rdp->qlen)++;
88373 if (lazy)
88374 rdp->qlen_lazy++;
88375 else
88376@@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
88377 * counter wrap on a 32-bit system. Quite a few more CPUs would of
88378 * course be required on a 64-bit system.
88379 */
88380- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
88381+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
88382 (ulong)atomic_long_read(&rsp->expedited_done) +
88383 ULONG_MAX / 8)) {
88384 synchronize_sched();
88385- atomic_long_inc(&rsp->expedited_wrap);
88386+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
88387 return;
88388 }
88389
88390@@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
88391 * Take a ticket. Note that atomic_inc_return() implies a
88392 * full memory barrier.
88393 */
88394- snap = atomic_long_inc_return(&rsp->expedited_start);
88395+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
88396 firstsnap = snap;
88397 get_online_cpus();
88398 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
88399@@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
88400 synchronize_sched_expedited_cpu_stop,
88401 NULL) == -EAGAIN) {
88402 put_online_cpus();
88403- atomic_long_inc(&rsp->expedited_tryfail);
88404+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
88405
88406 /* Check to see if someone else did our work for us. */
88407 s = atomic_long_read(&rsp->expedited_done);
88408 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88409 /* ensure test happens before caller kfree */
88410 smp_mb__before_atomic_inc(); /* ^^^ */
88411- atomic_long_inc(&rsp->expedited_workdone1);
88412+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
88413 return;
88414 }
88415
88416@@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
88417 udelay(trycount * num_online_cpus());
88418 } else {
88419 wait_rcu_gp(call_rcu_sched);
88420- atomic_long_inc(&rsp->expedited_normal);
88421+ atomic_long_inc_unchecked(&rsp->expedited_normal);
88422 return;
88423 }
88424
88425@@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
88426 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
88427 /* ensure test happens before caller kfree */
88428 smp_mb__before_atomic_inc(); /* ^^^ */
88429- atomic_long_inc(&rsp->expedited_workdone2);
88430+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
88431 return;
88432 }
88433
88434@@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
88435 * period works for us.
88436 */
88437 get_online_cpus();
88438- snap = atomic_long_read(&rsp->expedited_start);
88439+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
88440 smp_mb(); /* ensure read is before try_stop_cpus(). */
88441 }
88442- atomic_long_inc(&rsp->expedited_stoppedcpus);
88443+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
88444
88445 /*
88446 * Everyone up to our most recent fetch is covered by our grace
88447@@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
88448 * than we did already did their update.
88449 */
88450 do {
88451- atomic_long_inc(&rsp->expedited_done_tries);
88452+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
88453 s = atomic_long_read(&rsp->expedited_done);
88454 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
88455 /* ensure test happens before caller kfree */
88456 smp_mb__before_atomic_inc(); /* ^^^ */
88457- atomic_long_inc(&rsp->expedited_done_lost);
88458+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
88459 break;
88460 }
88461 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
88462- atomic_long_inc(&rsp->expedited_done_exit);
88463+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
88464
88465 put_online_cpus();
88466 }
88467@@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88468 * ACCESS_ONCE() to prevent the compiler from speculating
88469 * the increment to precede the early-exit check.
88470 */
88471- ACCESS_ONCE(rsp->n_barrier_done)++;
88472+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88473 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
88474 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
88475 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
88476@@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
88477
88478 /* Increment ->n_barrier_done to prevent duplicate work. */
88479 smp_mb(); /* Keep increment after above mechanism. */
88480- ACCESS_ONCE(rsp->n_barrier_done)++;
88481+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
88482 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
88483 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
88484 smp_mb(); /* Keep increment before caller's subsequent code. */
88485@@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
88486 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
88487 init_callback_list(rdp);
88488 rdp->qlen_lazy = 0;
88489- ACCESS_ONCE(rdp->qlen) = 0;
88490+ ACCESS_ONCE_RW(rdp->qlen) = 0;
88491 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
88492 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
88493- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
88494+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
88495 rdp->cpu = cpu;
88496 rdp->rsp = rsp;
88497 rcu_boot_init_nocb_percpu_data(rdp);
88498@@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
88499 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
88500 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
88501 rcu_sysidle_init_percpu_data(rdp->dynticks);
88502- atomic_set(&rdp->dynticks->dynticks,
88503- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
88504+ atomic_set_unchecked(&rdp->dynticks->dynticks,
88505+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
88506 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
88507
88508 /* Add CPU to rcu_node bitmasks. */
88509diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
88510index 52be957..365ded3 100644
88511--- a/kernel/rcu/tree.h
88512+++ b/kernel/rcu/tree.h
88513@@ -87,11 +87,11 @@ struct rcu_dynticks {
88514 long long dynticks_nesting; /* Track irq/process nesting level. */
88515 /* Process level is worth LLONG_MAX/2. */
88516 int dynticks_nmi_nesting; /* Track NMI nesting level. */
88517- atomic_t dynticks; /* Even value for idle, else odd. */
88518+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
88519 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
88520 long long dynticks_idle_nesting;
88521 /* irq/process nesting level from idle. */
88522- atomic_t dynticks_idle; /* Even value for idle, else odd. */
88523+ atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
88524 /* "Idle" excludes userspace execution. */
88525 unsigned long dynticks_idle_jiffies;
88526 /* End of last non-NMI non-idle period. */
88527@@ -429,17 +429,17 @@ struct rcu_state {
88528 /* _rcu_barrier(). */
88529 /* End of fields guarded by barrier_mutex. */
88530
88531- atomic_long_t expedited_start; /* Starting ticket. */
88532- atomic_long_t expedited_done; /* Done ticket. */
88533- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
88534- atomic_long_t expedited_tryfail; /* # acquisition failures. */
88535- atomic_long_t expedited_workdone1; /* # done by others #1. */
88536- atomic_long_t expedited_workdone2; /* # done by others #2. */
88537- atomic_long_t expedited_normal; /* # fallbacks to normal. */
88538- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
88539- atomic_long_t expedited_done_tries; /* # tries to update _done. */
88540- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
88541- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
88542+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
88543+ atomic_long_t expedited_done; /* Done ticket. */
88544+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
88545+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
88546+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
88547+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
88548+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
88549+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
88550+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
88551+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
88552+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
88553
88554 unsigned long jiffies_force_qs; /* Time at which to invoke */
88555 /* force_quiescent_state(). */
88556diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
88557index 08a7652..3598c7e 100644
88558--- a/kernel/rcu/tree_plugin.h
88559+++ b/kernel/rcu/tree_plugin.h
88560@@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
88561 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
88562 {
88563 return !rcu_preempted_readers_exp(rnp) &&
88564- ACCESS_ONCE(rnp->expmask) == 0;
88565+ ACCESS_ONCE_RW(rnp->expmask) == 0;
88566 }
88567
88568 /*
88569@@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
88570
88571 /* Clean up and exit. */
88572 smp_mb(); /* ensure expedited GP seen before counter increment. */
88573- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
88574+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
88575 unlock_mb_ret:
88576 mutex_unlock(&sync_rcu_preempt_exp_mutex);
88577 mb_ret:
88578@@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
88579 free_cpumask_var(cm);
88580 }
88581
88582-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
88583+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
88584 .store = &rcu_cpu_kthread_task,
88585 .thread_should_run = rcu_cpu_kthread_should_run,
88586 .thread_fn = rcu_cpu_kthread,
88587@@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
88588 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
88589 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
88590 cpu, ticks_value, ticks_title,
88591- atomic_read(&rdtp->dynticks) & 0xfff,
88592+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
88593 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
88594 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
88595 fast_no_hz);
88596@@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
88597
88598 /* Enqueue the callback on the nocb list and update counts. */
88599 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
88600- ACCESS_ONCE(*old_rhpp) = rhp;
88601+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
88602 atomic_long_add(rhcount, &rdp->nocb_q_count);
88603 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
88604
88605@@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
88606 * Extract queued callbacks, update counts, and wait
88607 * for a grace period to elapse.
88608 */
88609- ACCESS_ONCE(rdp->nocb_head) = NULL;
88610+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
88611 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
88612 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
88613 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
88614- ACCESS_ONCE(rdp->nocb_p_count) += c;
88615- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
88616+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
88617+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
88618 rcu_nocb_wait_gp(rdp);
88619
88620 /* Each pass through the following loop invokes a callback. */
88621@@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
88622 list = next;
88623 }
88624 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
88625- ACCESS_ONCE(rdp->nocb_p_count) -= c;
88626- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
88627+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
88628+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
88629 rdp->n_nocbs_invoked += c;
88630 }
88631 return 0;
88632@@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
88633 t = kthread_run(rcu_nocb_kthread, rdp,
88634 "rcuo%c/%d", rsp->abbr, cpu);
88635 BUG_ON(IS_ERR(t));
88636- ACCESS_ONCE(rdp->nocb_kthread) = t;
88637+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
88638 }
88639 }
88640
88641@@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
88642
88643 /* Record start of fully idle period. */
88644 j = jiffies;
88645- ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
88646+ ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
88647 smp_mb__before_atomic_inc();
88648- atomic_inc(&rdtp->dynticks_idle);
88649+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88650 smp_mb__after_atomic_inc();
88651- WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
88652+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
88653 }
88654
88655 /*
88656@@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
88657
88658 /* Record end of idle period. */
88659 smp_mb__before_atomic_inc();
88660- atomic_inc(&rdtp->dynticks_idle);
88661+ atomic_inc_unchecked(&rdtp->dynticks_idle);
88662 smp_mb__after_atomic_inc();
88663- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
88664+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
88665
88666 /*
88667 * If we are the timekeeping CPU, we are permitted to be non-idle
88668@@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
88669 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
88670
88671 /* Pick up current idle and NMI-nesting counter and check. */
88672- cur = atomic_read(&rdtp->dynticks_idle);
88673+ cur = atomic_read_unchecked(&rdtp->dynticks_idle);
88674 if (cur & 0x1) {
88675 *isidle = false; /* We are not idle! */
88676 return;
88677@@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
88678 case RCU_SYSIDLE_NOT:
88679
88680 /* First time all are idle, so note a short idle period. */
88681- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88682+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
88683 break;
88684
88685 case RCU_SYSIDLE_SHORT:
88686@@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
88687 static void rcu_sysidle_cancel(void)
88688 {
88689 smp_mb();
88690- ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
88691+ ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
88692 }
88693
88694 /*
88695@@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
88696 smp_mb(); /* grace period precedes setting inuse. */
88697
88698 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
88699- ACCESS_ONCE(rshp->inuse) = 0;
88700+ ACCESS_ONCE_RW(rshp->inuse) = 0;
88701 }
88702
88703 /*
88704diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
88705index 3596797..f78391c 100644
88706--- a/kernel/rcu/tree_trace.c
88707+++ b/kernel/rcu/tree_trace.c
88708@@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
88709 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
88710 rdp->passed_quiesce, rdp->qs_pending);
88711 seq_printf(m, " dt=%d/%llx/%d df=%lu",
88712- atomic_read(&rdp->dynticks->dynticks),
88713+ atomic_read_unchecked(&rdp->dynticks->dynticks),
88714 rdp->dynticks->dynticks_nesting,
88715 rdp->dynticks->dynticks_nmi_nesting,
88716 rdp->dynticks_fqs);
88717@@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
88718 struct rcu_state *rsp = (struct rcu_state *)m->private;
88719
88720 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",
88721- atomic_long_read(&rsp->expedited_start),
88722+ atomic_long_read_unchecked(&rsp->expedited_start),
88723 atomic_long_read(&rsp->expedited_done),
88724- atomic_long_read(&rsp->expedited_wrap),
88725- atomic_long_read(&rsp->expedited_tryfail),
88726- atomic_long_read(&rsp->expedited_workdone1),
88727- atomic_long_read(&rsp->expedited_workdone2),
88728- atomic_long_read(&rsp->expedited_normal),
88729- atomic_long_read(&rsp->expedited_stoppedcpus),
88730- atomic_long_read(&rsp->expedited_done_tries),
88731- atomic_long_read(&rsp->expedited_done_lost),
88732- atomic_long_read(&rsp->expedited_done_exit));
88733+ atomic_long_read_unchecked(&rsp->expedited_wrap),
88734+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
88735+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
88736+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
88737+ atomic_long_read_unchecked(&rsp->expedited_normal),
88738+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
88739+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
88740+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
88741+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
88742 return 0;
88743 }
88744
88745diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
88746index 6cb3dff..dc5710f 100644
88747--- a/kernel/rcu/update.c
88748+++ b/kernel/rcu/update.c
88749@@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
88750 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
88751 */
88752 if (till_stall_check < 3) {
88753- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
88754+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
88755 till_stall_check = 3;
88756 } else if (till_stall_check > 300) {
88757- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
88758+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
88759 till_stall_check = 300;
88760 }
88761 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
88762diff --git a/kernel/resource.c b/kernel/resource.c
88763index 3f285dc..5755f62 100644
88764--- a/kernel/resource.c
88765+++ b/kernel/resource.c
88766@@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
88767
88768 static int __init ioresources_init(void)
88769 {
88770+#ifdef CONFIG_GRKERNSEC_PROC_ADD
88771+#ifdef CONFIG_GRKERNSEC_PROC_USER
88772+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
88773+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
88774+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88775+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
88776+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
88777+#endif
88778+#else
88779 proc_create("ioports", 0, NULL, &proc_ioports_operations);
88780 proc_create("iomem", 0, NULL, &proc_iomem_operations);
88781+#endif
88782 return 0;
88783 }
88784 __initcall(ioresources_init);
88785diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
88786index 4a07353..66b5291 100644
88787--- a/kernel/sched/auto_group.c
88788+++ b/kernel/sched/auto_group.c
88789@@ -11,7 +11,7 @@
88790
88791 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
88792 static struct autogroup autogroup_default;
88793-static atomic_t autogroup_seq_nr;
88794+static atomic_unchecked_t autogroup_seq_nr;
88795
88796 void __init autogroup_init(struct task_struct *init_task)
88797 {
88798@@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
88799
88800 kref_init(&ag->kref);
88801 init_rwsem(&ag->lock);
88802- ag->id = atomic_inc_return(&autogroup_seq_nr);
88803+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
88804 ag->tg = tg;
88805 #ifdef CONFIG_RT_GROUP_SCHED
88806 /*
88807diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
88808index a63f4dc..349bbb0 100644
88809--- a/kernel/sched/completion.c
88810+++ b/kernel/sched/completion.c
88811@@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
88812 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88813 * or number of jiffies left till timeout) if completed.
88814 */
88815-long __sched
88816+long __sched __intentional_overflow(-1)
88817 wait_for_completion_interruptible_timeout(struct completion *x,
88818 unsigned long timeout)
88819 {
88820@@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
88821 *
88822 * Return: -ERESTARTSYS if interrupted, 0 if completed.
88823 */
88824-int __sched wait_for_completion_killable(struct completion *x)
88825+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
88826 {
88827 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
88828 if (t == -ERESTARTSYS)
88829@@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
88830 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
88831 * or number of jiffies left till timeout) if completed.
88832 */
88833-long __sched
88834+long __sched __intentional_overflow(-1)
88835 wait_for_completion_killable_timeout(struct completion *x,
88836 unsigned long timeout)
88837 {
88838diff --git a/kernel/sched/core.c b/kernel/sched/core.c
88839index c677510..132bb14 100644
88840--- a/kernel/sched/core.c
88841+++ b/kernel/sched/core.c
88842@@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
88843 int sysctl_numa_balancing(struct ctl_table *table, int write,
88844 void __user *buffer, size_t *lenp, loff_t *ppos)
88845 {
88846- struct ctl_table t;
88847+ ctl_table_no_const t;
88848 int err;
88849 int state = numabalancing_enabled;
88850
88851@@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
88852 /* convert nice value [19,-20] to rlimit style value [1,40] */
88853 int nice_rlim = 20 - nice;
88854
88855+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
88856+
88857 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
88858 capable(CAP_SYS_NICE));
88859 }
88860@@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
88861 if (nice > 19)
88862 nice = 19;
88863
88864- if (increment < 0 && !can_nice(current, nice))
88865+ if (increment < 0 && (!can_nice(current, nice) ||
88866+ gr_handle_chroot_nice()))
88867 return -EPERM;
88868
88869 retval = security_task_setnice(current, nice);
88870@@ -3088,6 +3091,7 @@ recheck:
88871 unsigned long rlim_rtprio =
88872 task_rlimit(p, RLIMIT_RTPRIO);
88873
88874+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
88875 /* can't set/change the rt policy */
88876 if (policy != p->policy && !rlim_rtprio)
88877 return -EPERM;
88878@@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
88879
88880 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
88881
88882-static struct ctl_table sd_ctl_dir[] = {
88883+static ctl_table_no_const sd_ctl_dir[] __read_only = {
88884 {
88885 .procname = "sched_domain",
88886 .mode = 0555,
88887@@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
88888 {}
88889 };
88890
88891-static struct ctl_table *sd_alloc_ctl_entry(int n)
88892+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
88893 {
88894- struct ctl_table *entry =
88895+ ctl_table_no_const *entry =
88896 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
88897
88898 return entry;
88899 }
88900
88901-static void sd_free_ctl_entry(struct ctl_table **tablep)
88902+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
88903 {
88904- struct ctl_table *entry;
88905+ ctl_table_no_const *entry;
88906
88907 /*
88908 * In the intermediate directories, both the child directory and
88909@@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
88910 * will always be set. In the lowest directory the names are
88911 * static strings and all have proc handlers.
88912 */
88913- for (entry = *tablep; entry->mode; entry++) {
88914- if (entry->child)
88915- sd_free_ctl_entry(&entry->child);
88916+ for (entry = tablep; entry->mode; entry++) {
88917+ if (entry->child) {
88918+ sd_free_ctl_entry(entry->child);
88919+ pax_open_kernel();
88920+ entry->child = NULL;
88921+ pax_close_kernel();
88922+ }
88923 if (entry->proc_handler == NULL)
88924 kfree(entry->procname);
88925 }
88926
88927- kfree(*tablep);
88928- *tablep = NULL;
88929+ kfree(tablep);
88930 }
88931
88932 static int min_load_idx = 0;
88933 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
88934
88935 static void
88936-set_table_entry(struct ctl_table *entry,
88937+set_table_entry(ctl_table_no_const *entry,
88938 const char *procname, void *data, int maxlen,
88939 umode_t mode, proc_handler *proc_handler,
88940 bool load_idx)
88941@@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
88942 static struct ctl_table *
88943 sd_alloc_ctl_domain_table(struct sched_domain *sd)
88944 {
88945- struct ctl_table *table = sd_alloc_ctl_entry(13);
88946+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
88947
88948 if (table == NULL)
88949 return NULL;
88950@@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
88951 return table;
88952 }
88953
88954-static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
88955+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
88956 {
88957- struct ctl_table *entry, *table;
88958+ ctl_table_no_const *entry, *table;
88959 struct sched_domain *sd;
88960 int domain_num = 0, i;
88961 char buf[32];
88962@@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
88963 static void register_sched_domain_sysctl(void)
88964 {
88965 int i, cpu_num = num_possible_cpus();
88966- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
88967+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
88968 char buf[32];
88969
88970 WARN_ON(sd_ctl_dir[0].child);
88971+ pax_open_kernel();
88972 sd_ctl_dir[0].child = entry;
88973+ pax_close_kernel();
88974
88975 if (entry == NULL)
88976 return;
88977@@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
88978 if (sd_sysctl_header)
88979 unregister_sysctl_table(sd_sysctl_header);
88980 sd_sysctl_header = NULL;
88981- if (sd_ctl_dir[0].child)
88982- sd_free_ctl_entry(&sd_ctl_dir[0].child);
88983+ if (sd_ctl_dir[0].child) {
88984+ sd_free_ctl_entry(sd_ctl_dir[0].child);
88985+ pax_open_kernel();
88986+ sd_ctl_dir[0].child = NULL;
88987+ pax_close_kernel();
88988+ }
88989 }
88990 #else
88991 static void register_sched_domain_sysctl(void)
88992diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
88993index ce501de..1805320 100644
88994--- a/kernel/sched/fair.c
88995+++ b/kernel/sched/fair.c
88996@@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
88997
88998 static void reset_ptenuma_scan(struct task_struct *p)
88999 {
89000- ACCESS_ONCE(p->mm->numa_scan_seq)++;
89001+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
89002 p->mm->numa_scan_offset = 0;
89003 }
89004
89005@@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
89006 * run_rebalance_domains is triggered when needed from the scheduler tick.
89007 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
89008 */
89009-static void run_rebalance_domains(struct softirq_action *h)
89010+static __latent_entropy void run_rebalance_domains(void)
89011 {
89012 int this_cpu = smp_processor_id();
89013 struct rq *this_rq = cpu_rq(this_cpu);
89014diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
89015index 88c85b2..a1dec86 100644
89016--- a/kernel/sched/sched.h
89017+++ b/kernel/sched/sched.h
89018@@ -1035,7 +1035,7 @@ struct sched_class {
89019 #ifdef CONFIG_FAIR_GROUP_SCHED
89020 void (*task_move_group) (struct task_struct *p, int on_rq);
89021 #endif
89022-};
89023+} __do_const;
89024
89025 #define sched_class_highest (&stop_sched_class)
89026 #define for_each_class(class) \
89027diff --git a/kernel/signal.c b/kernel/signal.c
89028index 940b30e..7fd6041 100644
89029--- a/kernel/signal.c
89030+++ b/kernel/signal.c
89031@@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
89032
89033 int print_fatal_signals __read_mostly;
89034
89035-static void __user *sig_handler(struct task_struct *t, int sig)
89036+static __sighandler_t sig_handler(struct task_struct *t, int sig)
89037 {
89038 return t->sighand->action[sig - 1].sa.sa_handler;
89039 }
89040
89041-static int sig_handler_ignored(void __user *handler, int sig)
89042+static int sig_handler_ignored(__sighandler_t handler, int sig)
89043 {
89044 /* Is it explicitly or implicitly ignored? */
89045 return handler == SIG_IGN ||
89046@@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
89047
89048 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
89049 {
89050- void __user *handler;
89051+ __sighandler_t handler;
89052
89053 handler = sig_handler(t, sig);
89054
89055@@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
89056 atomic_inc(&user->sigpending);
89057 rcu_read_unlock();
89058
89059+ if (!override_rlimit)
89060+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
89061+
89062 if (override_rlimit ||
89063 atomic_read(&user->sigpending) <=
89064 task_rlimit(t, RLIMIT_SIGPENDING)) {
89065@@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
89066
89067 int unhandled_signal(struct task_struct *tsk, int sig)
89068 {
89069- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
89070+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
89071 if (is_global_init(tsk))
89072 return 1;
89073 if (handler != SIG_IGN && handler != SIG_DFL)
89074@@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
89075 }
89076 }
89077
89078+ /* allow glibc communication via tgkill to other threads in our
89079+ thread group */
89080+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
89081+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
89082+ && gr_handle_signal(t, sig))
89083+ return -EPERM;
89084+
89085 return security_task_kill(t, info, sig, 0);
89086 }
89087
89088@@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89089 return send_signal(sig, info, p, 1);
89090 }
89091
89092-static int
89093+int
89094 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89095 {
89096 return send_signal(sig, info, t, 0);
89097@@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89098 unsigned long int flags;
89099 int ret, blocked, ignored;
89100 struct k_sigaction *action;
89101+ int is_unhandled = 0;
89102
89103 spin_lock_irqsave(&t->sighand->siglock, flags);
89104 action = &t->sighand->action[sig-1];
89105@@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
89106 }
89107 if (action->sa.sa_handler == SIG_DFL)
89108 t->signal->flags &= ~SIGNAL_UNKILLABLE;
89109+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
89110+ is_unhandled = 1;
89111 ret = specific_send_sig_info(sig, info, t);
89112 spin_unlock_irqrestore(&t->sighand->siglock, flags);
89113
89114+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
89115+ normal operation */
89116+ if (is_unhandled) {
89117+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
89118+ gr_handle_crash(t, sig);
89119+ }
89120+
89121 return ret;
89122 }
89123
89124@@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
89125 ret = check_kill_permission(sig, info, p);
89126 rcu_read_unlock();
89127
89128- if (!ret && sig)
89129+ if (!ret && sig) {
89130 ret = do_send_sig_info(sig, info, p, true);
89131+ if (!ret)
89132+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
89133+ }
89134
89135 return ret;
89136 }
89137@@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
89138 int error = -ESRCH;
89139
89140 rcu_read_lock();
89141- p = find_task_by_vpid(pid);
89142+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
89143+ /* allow glibc communication via tgkill to other threads in our
89144+ thread group */
89145+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
89146+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
89147+ p = find_task_by_vpid_unrestricted(pid);
89148+ else
89149+#endif
89150+ p = find_task_by_vpid(pid);
89151 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
89152 error = check_kill_permission(sig, info, p);
89153 /*
89154@@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
89155 }
89156 seg = get_fs();
89157 set_fs(KERNEL_DS);
89158- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
89159- (stack_t __force __user *) &uoss,
89160+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
89161+ (stack_t __force_user *) &uoss,
89162 compat_user_stack_pointer());
89163 set_fs(seg);
89164 if (ret >= 0 && uoss_ptr) {
89165diff --git a/kernel/smpboot.c b/kernel/smpboot.c
89166index eb89e18..a4e6792 100644
89167--- a/kernel/smpboot.c
89168+++ b/kernel/smpboot.c
89169@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
89170 }
89171 smpboot_unpark_thread(plug_thread, cpu);
89172 }
89173- list_add(&plug_thread->list, &hotplug_threads);
89174+ pax_list_add(&plug_thread->list, &hotplug_threads);
89175 out:
89176 mutex_unlock(&smpboot_threads_lock);
89177 return ret;
89178@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
89179 {
89180 get_online_cpus();
89181 mutex_lock(&smpboot_threads_lock);
89182- list_del(&plug_thread->list);
89183+ pax_list_del(&plug_thread->list);
89184 smpboot_destroy_threads(plug_thread);
89185 mutex_unlock(&smpboot_threads_lock);
89186 put_online_cpus();
89187diff --git a/kernel/softirq.c b/kernel/softirq.c
89188index 11025cc..bc0e4dc 100644
89189--- a/kernel/softirq.c
89190+++ b/kernel/softirq.c
89191@@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
89192 EXPORT_SYMBOL(irq_stat);
89193 #endif
89194
89195-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
89196+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
89197
89198 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
89199
89200-char *softirq_to_name[NR_SOFTIRQS] = {
89201+const char * const softirq_to_name[NR_SOFTIRQS] = {
89202 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
89203 "TASKLET", "SCHED", "HRTIMER", "RCU"
89204 };
89205@@ -250,7 +250,7 @@ restart:
89206 kstat_incr_softirqs_this_cpu(vec_nr);
89207
89208 trace_softirq_entry(vec_nr);
89209- h->action(h);
89210+ h->action();
89211 trace_softirq_exit(vec_nr);
89212 if (unlikely(prev_count != preempt_count())) {
89213 printk(KERN_ERR "huh, entered softirq %u %s %p"
89214@@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
89215 or_softirq_pending(1UL << nr);
89216 }
89217
89218-void open_softirq(int nr, void (*action)(struct softirq_action *))
89219+void __init open_softirq(int nr, void (*action)(void))
89220 {
89221 softirq_vec[nr].action = action;
89222 }
89223@@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
89224
89225 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
89226
89227-static void tasklet_action(struct softirq_action *a)
89228+static __latent_entropy void tasklet_action(void)
89229 {
89230 struct tasklet_struct *list;
89231
89232@@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
89233 }
89234 }
89235
89236-static void tasklet_hi_action(struct softirq_action *a)
89237+static __latent_entropy void tasklet_hi_action(void)
89238 {
89239 struct tasklet_struct *list;
89240
89241@@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
89242 .notifier_call = cpu_callback
89243 };
89244
89245-static struct smp_hotplug_thread softirq_threads = {
89246+static struct smp_hotplug_thread softirq_threads __read_only = {
89247 .store = &ksoftirqd,
89248 .thread_should_run = ksoftirqd_should_run,
89249 .thread_fn = run_ksoftirqd,
89250diff --git a/kernel/sys.c b/kernel/sys.c
89251index c723113..46bf922 100644
89252--- a/kernel/sys.c
89253+++ b/kernel/sys.c
89254@@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
89255 error = -EACCES;
89256 goto out;
89257 }
89258+
89259+ if (gr_handle_chroot_setpriority(p, niceval)) {
89260+ error = -EACCES;
89261+ goto out;
89262+ }
89263+
89264 no_nice = security_task_setnice(p, niceval);
89265 if (no_nice) {
89266 error = no_nice;
89267@@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
89268 goto error;
89269 }
89270
89271+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
89272+ goto error;
89273+
89274 if (rgid != (gid_t) -1 ||
89275 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
89276 new->sgid = new->egid;
89277@@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
89278 old = current_cred();
89279
89280 retval = -EPERM;
89281+
89282+ if (gr_check_group_change(kgid, kgid, kgid))
89283+ goto error;
89284+
89285 if (ns_capable(old->user_ns, CAP_SETGID))
89286 new->gid = new->egid = new->sgid = new->fsgid = kgid;
89287 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
89288@@ -403,7 +416,7 @@ error:
89289 /*
89290 * change the user struct in a credentials set to match the new UID
89291 */
89292-static int set_user(struct cred *new)
89293+int set_user(struct cred *new)
89294 {
89295 struct user_struct *new_user;
89296
89297@@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
89298 goto error;
89299 }
89300
89301+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
89302+ goto error;
89303+
89304 if (!uid_eq(new->uid, old->uid)) {
89305 retval = set_user(new);
89306 if (retval < 0)
89307@@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
89308 old = current_cred();
89309
89310 retval = -EPERM;
89311+
89312+ if (gr_check_crash_uid(kuid))
89313+ goto error;
89314+ if (gr_check_user_change(kuid, kuid, kuid))
89315+ goto error;
89316+
89317 if (ns_capable(old->user_ns, CAP_SETUID)) {
89318 new->suid = new->uid = kuid;
89319 if (!uid_eq(kuid, old->uid)) {
89320@@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
89321 goto error;
89322 }
89323
89324+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
89325+ goto error;
89326+
89327 if (ruid != (uid_t) -1) {
89328 new->uid = kruid;
89329 if (!uid_eq(kruid, old->uid)) {
89330@@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
89331 goto error;
89332 }
89333
89334+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
89335+ goto error;
89336+
89337 if (rgid != (gid_t) -1)
89338 new->gid = krgid;
89339 if (egid != (gid_t) -1)
89340@@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
89341 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
89342 ns_capable(old->user_ns, CAP_SETUID)) {
89343 if (!uid_eq(kuid, old->fsuid)) {
89344+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
89345+ goto error;
89346+
89347 new->fsuid = kuid;
89348 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
89349 goto change_okay;
89350 }
89351 }
89352
89353+error:
89354 abort_creds(new);
89355 return old_fsuid;
89356
89357@@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
89358 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
89359 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
89360 ns_capable(old->user_ns, CAP_SETGID)) {
89361+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
89362+ goto error;
89363+
89364 if (!gid_eq(kgid, old->fsgid)) {
89365 new->fsgid = kgid;
89366 goto change_okay;
89367 }
89368 }
89369
89370+error:
89371 abort_creds(new);
89372 return old_fsgid;
89373
89374@@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
89375 return -EFAULT;
89376
89377 down_read(&uts_sem);
89378- error = __copy_to_user(&name->sysname, &utsname()->sysname,
89379+ error = __copy_to_user(name->sysname, &utsname()->sysname,
89380 __OLD_UTS_LEN);
89381 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
89382- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
89383+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
89384 __OLD_UTS_LEN);
89385 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
89386- error |= __copy_to_user(&name->release, &utsname()->release,
89387+ error |= __copy_to_user(name->release, &utsname()->release,
89388 __OLD_UTS_LEN);
89389 error |= __put_user(0, name->release + __OLD_UTS_LEN);
89390- error |= __copy_to_user(&name->version, &utsname()->version,
89391+ error |= __copy_to_user(name->version, &utsname()->version,
89392 __OLD_UTS_LEN);
89393 error |= __put_user(0, name->version + __OLD_UTS_LEN);
89394- error |= __copy_to_user(&name->machine, &utsname()->machine,
89395+ error |= __copy_to_user(name->machine, &utsname()->machine,
89396 __OLD_UTS_LEN);
89397 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
89398 up_read(&uts_sem);
89399@@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
89400 */
89401 new_rlim->rlim_cur = 1;
89402 }
89403+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
89404+ is changed to a lower value. Since tasks can be created by the same
89405+ user in between this limit change and an execve by this task, force
89406+ a recheck only for this task by setting PF_NPROC_EXCEEDED
89407+ */
89408+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
89409+ tsk->flags |= PF_NPROC_EXCEEDED;
89410 }
89411 if (!retval) {
89412 if (old_rlim)
89413diff --git a/kernel/sysctl.c b/kernel/sysctl.c
89414index 06962ba..a54d45e 100644
89415--- a/kernel/sysctl.c
89416+++ b/kernel/sysctl.c
89417@@ -93,7 +93,6 @@
89418
89419
89420 #if defined(CONFIG_SYSCTL)
89421-
89422 /* External variables not in a header file. */
89423 extern int sysctl_overcommit_memory;
89424 extern int sysctl_overcommit_ratio;
89425@@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
89426
89427 /* Constants used for minimum and maximum */
89428 #ifdef CONFIG_LOCKUP_DETECTOR
89429-static int sixty = 60;
89430+static int sixty __read_only = 60;
89431 #endif
89432
89433-static int zero;
89434-static int __maybe_unused one = 1;
89435-static int __maybe_unused two = 2;
89436-static int __maybe_unused three = 3;
89437-static unsigned long one_ul = 1;
89438-static int one_hundred = 100;
89439+static int neg_one __read_only = -1;
89440+static int zero __read_only = 0;
89441+static int __maybe_unused one __read_only = 1;
89442+static int __maybe_unused two __read_only = 2;
89443+static int __maybe_unused three __read_only = 3;
89444+static unsigned long one_ul __read_only = 1;
89445+static int one_hundred __read_only = 100;
89446 #ifdef CONFIG_PRINTK
89447-static int ten_thousand = 10000;
89448+static int ten_thousand __read_only = 10000;
89449 #endif
89450
89451 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
89452@@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
89453 void __user *buffer, size_t *lenp, loff_t *ppos);
89454 #endif
89455
89456-#ifdef CONFIG_PRINTK
89457 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89458 void __user *buffer, size_t *lenp, loff_t *ppos);
89459-#endif
89460
89461 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
89462 void __user *buffer, size_t *lenp, loff_t *ppos);
89463@@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
89464
89465 #endif
89466
89467+extern struct ctl_table grsecurity_table[];
89468+
89469 static struct ctl_table kern_table[];
89470 static struct ctl_table vm_table[];
89471 static struct ctl_table fs_table[];
89472@@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
89473 int sysctl_legacy_va_layout;
89474 #endif
89475
89476+#ifdef CONFIG_PAX_SOFTMODE
89477+static ctl_table pax_table[] = {
89478+ {
89479+ .procname = "softmode",
89480+ .data = &pax_softmode,
89481+ .maxlen = sizeof(unsigned int),
89482+ .mode = 0600,
89483+ .proc_handler = &proc_dointvec,
89484+ },
89485+
89486+ { }
89487+};
89488+#endif
89489+
89490 /* The default sysctl tables: */
89491
89492 static struct ctl_table sysctl_base_table[] = {
89493@@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
89494 #endif
89495
89496 static struct ctl_table kern_table[] = {
89497+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
89498+ {
89499+ .procname = "grsecurity",
89500+ .mode = 0500,
89501+ .child = grsecurity_table,
89502+ },
89503+#endif
89504+
89505+#ifdef CONFIG_PAX_SOFTMODE
89506+ {
89507+ .procname = "pax",
89508+ .mode = 0500,
89509+ .child = pax_table,
89510+ },
89511+#endif
89512+
89513 {
89514 .procname = "sched_child_runs_first",
89515 .data = &sysctl_sched_child_runs_first,
89516@@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
89517 .data = &modprobe_path,
89518 .maxlen = KMOD_PATH_LEN,
89519 .mode = 0644,
89520- .proc_handler = proc_dostring,
89521+ .proc_handler = proc_dostring_modpriv,
89522 },
89523 {
89524 .procname = "modules_disabled",
89525@@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
89526 .extra1 = &zero,
89527 .extra2 = &one,
89528 },
89529+#endif
89530 {
89531 .procname = "kptr_restrict",
89532 .data = &kptr_restrict,
89533 .maxlen = sizeof(int),
89534 .mode = 0644,
89535 .proc_handler = proc_dointvec_minmax_sysadmin,
89536+#ifdef CONFIG_GRKERNSEC_HIDESYM
89537+ .extra1 = &two,
89538+#else
89539 .extra1 = &zero,
89540+#endif
89541 .extra2 = &two,
89542 },
89543-#endif
89544 {
89545 .procname = "ngroups_max",
89546 .data = &ngroups_max,
89547@@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
89548 */
89549 {
89550 .procname = "perf_event_paranoid",
89551- .data = &sysctl_perf_event_paranoid,
89552- .maxlen = sizeof(sysctl_perf_event_paranoid),
89553+ .data = &sysctl_perf_event_legitimately_concerned,
89554+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
89555 .mode = 0644,
89556- .proc_handler = proc_dointvec,
89557+ /* go ahead, be a hero */
89558+ .proc_handler = proc_dointvec_minmax_sysadmin,
89559+ .extra1 = &neg_one,
89560+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
89561+ .extra2 = &three,
89562+#else
89563+ .extra2 = &two,
89564+#endif
89565 },
89566 {
89567 .procname = "perf_event_mlock_kb",
89568@@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
89569 .proc_handler = proc_dointvec_minmax,
89570 .extra1 = &zero,
89571 },
89572+ {
89573+ .procname = "heap_stack_gap",
89574+ .data = &sysctl_heap_stack_gap,
89575+ .maxlen = sizeof(sysctl_heap_stack_gap),
89576+ .mode = 0644,
89577+ .proc_handler = proc_doulongvec_minmax,
89578+ },
89579 #else
89580 {
89581 .procname = "nr_trim_pages",
89582@@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
89583 buffer, lenp, ppos);
89584 }
89585
89586+int proc_dostring_modpriv(struct ctl_table *table, int write,
89587+ void __user *buffer, size_t *lenp, loff_t *ppos)
89588+{
89589+ if (write && !capable(CAP_SYS_MODULE))
89590+ return -EPERM;
89591+
89592+ return _proc_do_string(table->data, table->maxlen, write,
89593+ buffer, lenp, ppos);
89594+}
89595+
89596 static size_t proc_skip_spaces(char **buf)
89597 {
89598 size_t ret;
89599@@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
89600 len = strlen(tmp);
89601 if (len > *size)
89602 len = *size;
89603+ if (len > sizeof(tmp))
89604+ len = sizeof(tmp);
89605 if (copy_to_user(*buf, tmp, len))
89606 return -EFAULT;
89607 *size -= len;
89608@@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
89609 static int proc_taint(struct ctl_table *table, int write,
89610 void __user *buffer, size_t *lenp, loff_t *ppos)
89611 {
89612- struct ctl_table t;
89613+ ctl_table_no_const t;
89614 unsigned long tmptaint = get_taint();
89615 int err;
89616
89617@@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
89618 return err;
89619 }
89620
89621-#ifdef CONFIG_PRINTK
89622 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89623 void __user *buffer, size_t *lenp, loff_t *ppos)
89624 {
89625@@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
89626
89627 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
89628 }
89629-#endif
89630
89631 struct do_proc_dointvec_minmax_conv_param {
89632 int *min;
89633@@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
89634 return -ENOSYS;
89635 }
89636
89637+int proc_dostring_modpriv(struct ctl_table *table, int write,
89638+ void __user *buffer, size_t *lenp, loff_t *ppos)
89639+{
89640+ return -ENOSYS;
89641+}
89642+
89643 int proc_dointvec(struct ctl_table *table, int write,
89644 void __user *buffer, size_t *lenp, loff_t *ppos)
89645 {
89646@@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
89647 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
89648 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
89649 EXPORT_SYMBOL(proc_dostring);
89650+EXPORT_SYMBOL(proc_dostring_modpriv);
89651 EXPORT_SYMBOL(proc_doulongvec_minmax);
89652 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
89653diff --git a/kernel/taskstats.c b/kernel/taskstats.c
89654index 13d2f7c..c93d0b0 100644
89655--- a/kernel/taskstats.c
89656+++ b/kernel/taskstats.c
89657@@ -28,9 +28,12 @@
89658 #include <linux/fs.h>
89659 #include <linux/file.h>
89660 #include <linux/pid_namespace.h>
89661+#include <linux/grsecurity.h>
89662 #include <net/genetlink.h>
89663 #include <linux/atomic.h>
89664
89665+extern int gr_is_taskstats_denied(int pid);
89666+
89667 /*
89668 * Maximum length of a cpumask that can be specified in
89669 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
89670@@ -576,6 +579,9 @@ err:
89671
89672 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
89673 {
89674+ if (gr_is_taskstats_denied(current->pid))
89675+ return -EACCES;
89676+
89677 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
89678 return cmd_attr_register_cpumask(info);
89679 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
89680diff --git a/kernel/time.c b/kernel/time.c
89681index 7c7964c..2a0d412 100644
89682--- a/kernel/time.c
89683+++ b/kernel/time.c
89684@@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
89685 return error;
89686
89687 if (tz) {
89688+ /* we log in do_settimeofday called below, so don't log twice
89689+ */
89690+ if (!tv)
89691+ gr_log_timechange();
89692+
89693 sys_tz = *tz;
89694 update_vsyscall_tz();
89695 if (firsttime) {
89696diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
89697index 88c9c65..7497ebc 100644
89698--- a/kernel/time/alarmtimer.c
89699+++ b/kernel/time/alarmtimer.c
89700@@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
89701 struct platform_device *pdev;
89702 int error = 0;
89703 int i;
89704- struct k_clock alarm_clock = {
89705+ static struct k_clock alarm_clock = {
89706 .clock_getres = alarm_clock_getres,
89707 .clock_get = alarm_clock_get,
89708 .timer_create = alarm_timer_create,
89709diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
89710index b415457..c26876d 100644
89711--- a/kernel/time/timekeeping.c
89712+++ b/kernel/time/timekeeping.c
89713@@ -15,6 +15,7 @@
89714 #include <linux/init.h>
89715 #include <linux/mm.h>
89716 #include <linux/sched.h>
89717+#include <linux/grsecurity.h>
89718 #include <linux/syscore_ops.h>
89719 #include <linux/clocksource.h>
89720 #include <linux/jiffies.h>
89721@@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
89722 if (!timespec_valid_strict(tv))
89723 return -EINVAL;
89724
89725+ gr_log_timechange();
89726+
89727 raw_spin_lock_irqsave(&timekeeper_lock, flags);
89728 write_seqcount_begin(&timekeeper_seq);
89729
89730diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
89731index 61ed862..3b52c65 100644
89732--- a/kernel/time/timer_list.c
89733+++ b/kernel/time/timer_list.c
89734@@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
89735
89736 static void print_name_offset(struct seq_file *m, void *sym)
89737 {
89738+#ifdef CONFIG_GRKERNSEC_HIDESYM
89739+ SEQ_printf(m, "<%p>", NULL);
89740+#else
89741 char symname[KSYM_NAME_LEN];
89742
89743 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
89744 SEQ_printf(m, "<%pK>", sym);
89745 else
89746 SEQ_printf(m, "%s", symname);
89747+#endif
89748 }
89749
89750 static void
89751@@ -119,7 +123,11 @@ next_one:
89752 static void
89753 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
89754 {
89755+#ifdef CONFIG_GRKERNSEC_HIDESYM
89756+ SEQ_printf(m, " .base: %p\n", NULL);
89757+#else
89758 SEQ_printf(m, " .base: %pK\n", base);
89759+#endif
89760 SEQ_printf(m, " .index: %d\n",
89761 base->index);
89762 SEQ_printf(m, " .resolution: %Lu nsecs\n",
89763@@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
89764 {
89765 struct proc_dir_entry *pe;
89766
89767+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89768+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
89769+#else
89770 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
89771+#endif
89772 if (!pe)
89773 return -ENOMEM;
89774 return 0;
89775diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
89776index 1fb08f2..ca4bb1e 100644
89777--- a/kernel/time/timer_stats.c
89778+++ b/kernel/time/timer_stats.c
89779@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
89780 static unsigned long nr_entries;
89781 static struct entry entries[MAX_ENTRIES];
89782
89783-static atomic_t overflow_count;
89784+static atomic_unchecked_t overflow_count;
89785
89786 /*
89787 * The entries are in a hash-table, for fast lookup:
89788@@ -140,7 +140,7 @@ static void reset_entries(void)
89789 nr_entries = 0;
89790 memset(entries, 0, sizeof(entries));
89791 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
89792- atomic_set(&overflow_count, 0);
89793+ atomic_set_unchecked(&overflow_count, 0);
89794 }
89795
89796 static struct entry *alloc_entry(void)
89797@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89798 if (likely(entry))
89799 entry->count++;
89800 else
89801- atomic_inc(&overflow_count);
89802+ atomic_inc_unchecked(&overflow_count);
89803
89804 out_unlock:
89805 raw_spin_unlock_irqrestore(lock, flags);
89806@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
89807
89808 static void print_name_offset(struct seq_file *m, unsigned long addr)
89809 {
89810+#ifdef CONFIG_GRKERNSEC_HIDESYM
89811+ seq_printf(m, "<%p>", NULL);
89812+#else
89813 char symname[KSYM_NAME_LEN];
89814
89815 if (lookup_symbol_name(addr, symname) < 0)
89816- seq_printf(m, "<%p>", (void *)addr);
89817+ seq_printf(m, "<%pK>", (void *)addr);
89818 else
89819 seq_printf(m, "%s", symname);
89820+#endif
89821 }
89822
89823 static int tstats_show(struct seq_file *m, void *v)
89824@@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
89825
89826 seq_puts(m, "Timer Stats Version: v0.3\n");
89827 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
89828- if (atomic_read(&overflow_count))
89829- seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
89830+ if (atomic_read_unchecked(&overflow_count))
89831+ seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
89832 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
89833
89834 for (i = 0; i < nr_entries; i++) {
89835@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
89836 {
89837 struct proc_dir_entry *pe;
89838
89839+#ifdef CONFIG_GRKERNSEC_PROC_ADD
89840+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
89841+#else
89842 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
89843+#endif
89844 if (!pe)
89845 return -ENOMEM;
89846 return 0;
89847diff --git a/kernel/timer.c b/kernel/timer.c
89848index accfd24..e00f0c0 100644
89849--- a/kernel/timer.c
89850+++ b/kernel/timer.c
89851@@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
89852 /*
89853 * This function runs timers and the timer-tq in bottom half context.
89854 */
89855-static void run_timer_softirq(struct softirq_action *h)
89856+static __latent_entropy void run_timer_softirq(void)
89857 {
89858 struct tvec_base *base = __this_cpu_read(tvec_bases);
89859
89860@@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
89861 *
89862 * In all cases the return value is guaranteed to be non-negative.
89863 */
89864-signed long __sched schedule_timeout(signed long timeout)
89865+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
89866 {
89867 struct timer_list timer;
89868 unsigned long expire;
89869diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
89870index f785aef..59f1b18 100644
89871--- a/kernel/trace/blktrace.c
89872+++ b/kernel/trace/blktrace.c
89873@@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
89874 struct blk_trace *bt = filp->private_data;
89875 char buf[16];
89876
89877- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
89878+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
89879
89880 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
89881 }
89882@@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
89883 return 1;
89884
89885 bt = buf->chan->private_data;
89886- atomic_inc(&bt->dropped);
89887+ atomic_inc_unchecked(&bt->dropped);
89888 return 0;
89889 }
89890
89891@@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
89892
89893 bt->dir = dir;
89894 bt->dev = dev;
89895- atomic_set(&bt->dropped, 0);
89896+ atomic_set_unchecked(&bt->dropped, 0);
89897 INIT_LIST_HEAD(&bt->running_list);
89898
89899 ret = -EIO;
89900diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
89901index 38463d2..68abe92 100644
89902--- a/kernel/trace/ftrace.c
89903+++ b/kernel/trace/ftrace.c
89904@@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
89905 if (unlikely(ftrace_disabled))
89906 return 0;
89907
89908+ ret = ftrace_arch_code_modify_prepare();
89909+ FTRACE_WARN_ON(ret);
89910+ if (ret)
89911+ return 0;
89912+
89913 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
89914+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
89915 if (ret) {
89916 ftrace_bug(ret, ip);
89917- return 0;
89918 }
89919- return 1;
89920+ return ret ? 0 : 1;
89921 }
89922
89923 /*
89924@@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
89925 if (!count)
89926 return 0;
89927
89928+ pax_open_kernel();
89929 sort(start, count, sizeof(*start),
89930 ftrace_cmp_ips, ftrace_swap_ips);
89931+ pax_close_kernel();
89932
89933 start_pg = ftrace_allocate_pages(count);
89934 if (!start_pg)
89935@@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
89936 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
89937
89938 static int ftrace_graph_active;
89939-static struct notifier_block ftrace_suspend_notifier;
89940-
89941 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
89942 {
89943 return 0;
89944@@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
89945 ftrace_graph_entry = ftrace_graph_entry_test;
89946 }
89947
89948+static struct notifier_block ftrace_suspend_notifier = {
89949+ .notifier_call = ftrace_suspend_notifier_call
89950+};
89951+
89952 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89953 trace_func_graph_ent_t entryfunc)
89954 {
89955@@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
89956 goto out;
89957 }
89958
89959- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
89960 register_pm_notifier(&ftrace_suspend_notifier);
89961
89962 ftrace_graph_active++;
89963diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
89964index 0e337ee..3370631 100644
89965--- a/kernel/trace/ring_buffer.c
89966+++ b/kernel/trace/ring_buffer.c
89967@@ -352,9 +352,9 @@ struct buffer_data_page {
89968 */
89969 struct buffer_page {
89970 struct list_head list; /* list of buffer pages */
89971- local_t write; /* index for next write */
89972+ local_unchecked_t write; /* index for next write */
89973 unsigned read; /* index for next read */
89974- local_t entries; /* entries on this page */
89975+ local_unchecked_t entries; /* entries on this page */
89976 unsigned long real_end; /* real end of data */
89977 struct buffer_data_page *page; /* Actual data page */
89978 };
89979@@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
89980 unsigned long last_overrun;
89981 local_t entries_bytes;
89982 local_t entries;
89983- local_t overrun;
89984- local_t commit_overrun;
89985+ local_unchecked_t overrun;
89986+ local_unchecked_t commit_overrun;
89987 local_t dropped_events;
89988 local_t committing;
89989 local_t commits;
89990@@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
89991 *
89992 * We add a counter to the write field to denote this.
89993 */
89994- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
89995- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
89996+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
89997+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
89998
89999 /*
90000 * Just make sure we have seen our old_write and synchronize
90001@@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
90002 * cmpxchg to only update if an interrupt did not already
90003 * do it for us. If the cmpxchg fails, we don't care.
90004 */
90005- (void)local_cmpxchg(&next_page->write, old_write, val);
90006- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
90007+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
90008+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
90009
90010 /*
90011 * No need to worry about races with clearing out the commit.
90012@@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
90013
90014 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
90015 {
90016- return local_read(&bpage->entries) & RB_WRITE_MASK;
90017+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
90018 }
90019
90020 static inline unsigned long rb_page_write(struct buffer_page *bpage)
90021 {
90022- return local_read(&bpage->write) & RB_WRITE_MASK;
90023+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
90024 }
90025
90026 static int
90027@@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
90028 * bytes consumed in ring buffer from here.
90029 * Increment overrun to account for the lost events.
90030 */
90031- local_add(page_entries, &cpu_buffer->overrun);
90032+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
90033 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90034 }
90035
90036@@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
90037 * it is our responsibility to update
90038 * the counters.
90039 */
90040- local_add(entries, &cpu_buffer->overrun);
90041+ local_add_unchecked(entries, &cpu_buffer->overrun);
90042 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
90043
90044 /*
90045@@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90046 if (tail == BUF_PAGE_SIZE)
90047 tail_page->real_end = 0;
90048
90049- local_sub(length, &tail_page->write);
90050+ local_sub_unchecked(length, &tail_page->write);
90051 return;
90052 }
90053
90054@@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90055 rb_event_set_padding(event);
90056
90057 /* Set the write back to the previous setting */
90058- local_sub(length, &tail_page->write);
90059+ local_sub_unchecked(length, &tail_page->write);
90060 return;
90061 }
90062
90063@@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
90064
90065 /* Set write to end of buffer */
90066 length = (tail + length) - BUF_PAGE_SIZE;
90067- local_sub(length, &tail_page->write);
90068+ local_sub_unchecked(length, &tail_page->write);
90069 }
90070
90071 /*
90072@@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90073 * about it.
90074 */
90075 if (unlikely(next_page == commit_page)) {
90076- local_inc(&cpu_buffer->commit_overrun);
90077+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90078 goto out_reset;
90079 }
90080
90081@@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
90082 cpu_buffer->tail_page) &&
90083 (cpu_buffer->commit_page ==
90084 cpu_buffer->reader_page))) {
90085- local_inc(&cpu_buffer->commit_overrun);
90086+ local_inc_unchecked(&cpu_buffer->commit_overrun);
90087 goto out_reset;
90088 }
90089 }
90090@@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90091 length += RB_LEN_TIME_EXTEND;
90092
90093 tail_page = cpu_buffer->tail_page;
90094- write = local_add_return(length, &tail_page->write);
90095+ write = local_add_return_unchecked(length, &tail_page->write);
90096
90097 /* set write to only the index of the write */
90098 write &= RB_WRITE_MASK;
90099@@ -2415,7 +2415,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
90100 kmemcheck_annotate_bitfield(event, bitfield);
90101 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
90102
90103- local_inc(&tail_page->entries);
90104+ local_inc_unchecked(&tail_page->entries);
90105
90106 /*
90107 * If this is the first commit on the page, then update
90108@@ -2448,7 +2448,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90109
90110 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
90111 unsigned long write_mask =
90112- local_read(&bpage->write) & ~RB_WRITE_MASK;
90113+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
90114 unsigned long event_length = rb_event_length(event);
90115 /*
90116 * This is on the tail page. It is possible that
90117@@ -2458,7 +2458,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
90118 */
90119 old_index += write_mask;
90120 new_index += write_mask;
90121- index = local_cmpxchg(&bpage->write, old_index, new_index);
90122+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
90123 if (index == old_index) {
90124 /* update counters */
90125 local_sub(event_length, &cpu_buffer->entries_bytes);
90126@@ -2850,7 +2850,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90127
90128 /* Do the likely case first */
90129 if (likely(bpage->page == (void *)addr)) {
90130- local_dec(&bpage->entries);
90131+ local_dec_unchecked(&bpage->entries);
90132 return;
90133 }
90134
90135@@ -2862,7 +2862,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
90136 start = bpage;
90137 do {
90138 if (bpage->page == (void *)addr) {
90139- local_dec(&bpage->entries);
90140+ local_dec_unchecked(&bpage->entries);
90141 return;
90142 }
90143 rb_inc_page(cpu_buffer, &bpage);
90144@@ -3146,7 +3146,7 @@ static inline unsigned long
90145 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
90146 {
90147 return local_read(&cpu_buffer->entries) -
90148- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
90149+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
90150 }
90151
90152 /**
90153@@ -3235,7 +3235,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
90154 return 0;
90155
90156 cpu_buffer = buffer->buffers[cpu];
90157- ret = local_read(&cpu_buffer->overrun);
90158+ ret = local_read_unchecked(&cpu_buffer->overrun);
90159
90160 return ret;
90161 }
90162@@ -3258,7 +3258,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
90163 return 0;
90164
90165 cpu_buffer = buffer->buffers[cpu];
90166- ret = local_read(&cpu_buffer->commit_overrun);
90167+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
90168
90169 return ret;
90170 }
90171@@ -3343,7 +3343,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
90172 /* if you care about this being correct, lock the buffer */
90173 for_each_buffer_cpu(buffer, cpu) {
90174 cpu_buffer = buffer->buffers[cpu];
90175- overruns += local_read(&cpu_buffer->overrun);
90176+ overruns += local_read_unchecked(&cpu_buffer->overrun);
90177 }
90178
90179 return overruns;
90180@@ -3519,8 +3519,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90181 /*
90182 * Reset the reader page to size zero.
90183 */
90184- local_set(&cpu_buffer->reader_page->write, 0);
90185- local_set(&cpu_buffer->reader_page->entries, 0);
90186+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90187+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90188 local_set(&cpu_buffer->reader_page->page->commit, 0);
90189 cpu_buffer->reader_page->real_end = 0;
90190
90191@@ -3554,7 +3554,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
90192 * want to compare with the last_overrun.
90193 */
90194 smp_mb();
90195- overwrite = local_read(&(cpu_buffer->overrun));
90196+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
90197
90198 /*
90199 * Here's the tricky part.
90200@@ -4124,8 +4124,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90201
90202 cpu_buffer->head_page
90203 = list_entry(cpu_buffer->pages, struct buffer_page, list);
90204- local_set(&cpu_buffer->head_page->write, 0);
90205- local_set(&cpu_buffer->head_page->entries, 0);
90206+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
90207+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
90208 local_set(&cpu_buffer->head_page->page->commit, 0);
90209
90210 cpu_buffer->head_page->read = 0;
90211@@ -4135,14 +4135,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
90212
90213 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
90214 INIT_LIST_HEAD(&cpu_buffer->new_pages);
90215- local_set(&cpu_buffer->reader_page->write, 0);
90216- local_set(&cpu_buffer->reader_page->entries, 0);
90217+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
90218+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
90219 local_set(&cpu_buffer->reader_page->page->commit, 0);
90220 cpu_buffer->reader_page->read = 0;
90221
90222 local_set(&cpu_buffer->entries_bytes, 0);
90223- local_set(&cpu_buffer->overrun, 0);
90224- local_set(&cpu_buffer->commit_overrun, 0);
90225+ local_set_unchecked(&cpu_buffer->overrun, 0);
90226+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
90227 local_set(&cpu_buffer->dropped_events, 0);
90228 local_set(&cpu_buffer->entries, 0);
90229 local_set(&cpu_buffer->committing, 0);
90230@@ -4547,8 +4547,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
90231 rb_init_page(bpage);
90232 bpage = reader->page;
90233 reader->page = *data_page;
90234- local_set(&reader->write, 0);
90235- local_set(&reader->entries, 0);
90236+ local_set_unchecked(&reader->write, 0);
90237+ local_set_unchecked(&reader->entries, 0);
90238 reader->read = 0;
90239 *data_page = bpage;
90240
90241diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
90242index 0a360ce..7bd800e 100644
90243--- a/kernel/trace/trace.c
90244+++ b/kernel/trace/trace.c
90245@@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
90246 return 0;
90247 }
90248
90249-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
90250+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
90251 {
90252 /* do nothing if flag is already set */
90253 if (!!(trace_flags & mask) == !!enabled)
90254diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
90255index ea189e0..a5b48c4 100644
90256--- a/kernel/trace/trace.h
90257+++ b/kernel/trace/trace.h
90258@@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
90259 void trace_printk_init_buffers(void);
90260 void trace_printk_start_comm(void);
90261 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
90262-int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
90263+int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
90264
90265 /*
90266 * Normal trace_printk() and friends allocates special buffers
90267diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
90268index 26dc348..8708ca7 100644
90269--- a/kernel/trace/trace_clock.c
90270+++ b/kernel/trace/trace_clock.c
90271@@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
90272 return now;
90273 }
90274
90275-static atomic64_t trace_counter;
90276+static atomic64_unchecked_t trace_counter;
90277
90278 /*
90279 * trace_clock_counter(): simply an atomic counter.
90280@@ -132,5 +132,5 @@ static atomic64_t trace_counter;
90281 */
90282 u64 notrace trace_clock_counter(void)
90283 {
90284- return atomic64_add_return(1, &trace_counter);
90285+ return atomic64_inc_return_unchecked(&trace_counter);
90286 }
90287diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
90288index ba983dc..911aaf9 100644
90289--- a/kernel/trace/trace_events.c
90290+++ b/kernel/trace/trace_events.c
90291@@ -1675,7 +1675,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
90292 return 0;
90293 }
90294
90295-struct ftrace_module_file_ops;
90296 static void __add_event_to_tracers(struct ftrace_event_call *call);
90297
90298 /* Add an additional event_call dynamically */
90299diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
90300index 0abd9b8..6a663a2 100644
90301--- a/kernel/trace/trace_mmiotrace.c
90302+++ b/kernel/trace/trace_mmiotrace.c
90303@@ -24,7 +24,7 @@ struct header_iter {
90304 static struct trace_array *mmio_trace_array;
90305 static bool overrun_detected;
90306 static unsigned long prev_overruns;
90307-static atomic_t dropped_count;
90308+static atomic_unchecked_t dropped_count;
90309
90310 static void mmio_reset_data(struct trace_array *tr)
90311 {
90312@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
90313
90314 static unsigned long count_overruns(struct trace_iterator *iter)
90315 {
90316- unsigned long cnt = atomic_xchg(&dropped_count, 0);
90317+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
90318 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
90319
90320 if (over > prev_overruns)
90321@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
90322 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
90323 sizeof(*entry), 0, pc);
90324 if (!event) {
90325- atomic_inc(&dropped_count);
90326+ atomic_inc_unchecked(&dropped_count);
90327 return;
90328 }
90329 entry = ring_buffer_event_data(event);
90330@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
90331 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
90332 sizeof(*entry), 0, pc);
90333 if (!event) {
90334- atomic_inc(&dropped_count);
90335+ atomic_inc_unchecked(&dropped_count);
90336 return;
90337 }
90338 entry = ring_buffer_event_data(event);
90339diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
90340index ed32284..884d6c3 100644
90341--- a/kernel/trace/trace_output.c
90342+++ b/kernel/trace/trace_output.c
90343@@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
90344
90345 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
90346 if (!IS_ERR(p)) {
90347- p = mangle_path(s->buffer + s->len, p, "\n");
90348+ p = mangle_path(s->buffer + s->len, p, "\n\\");
90349 if (p) {
90350 s->len = p - s->buffer;
90351 return 1;
90352@@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
90353 goto out;
90354 }
90355
90356+ pax_open_kernel();
90357 if (event->funcs->trace == NULL)
90358- event->funcs->trace = trace_nop_print;
90359+ *(void **)&event->funcs->trace = trace_nop_print;
90360 if (event->funcs->raw == NULL)
90361- event->funcs->raw = trace_nop_print;
90362+ *(void **)&event->funcs->raw = trace_nop_print;
90363 if (event->funcs->hex == NULL)
90364- event->funcs->hex = trace_nop_print;
90365+ *(void **)&event->funcs->hex = trace_nop_print;
90366 if (event->funcs->binary == NULL)
90367- event->funcs->binary = trace_nop_print;
90368+ *(void **)&event->funcs->binary = trace_nop_print;
90369+ pax_close_kernel();
90370
90371 key = event->type & (EVENT_HASHSIZE - 1);
90372
90373diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
90374index b20428c..4845a10 100644
90375--- a/kernel/trace/trace_stack.c
90376+++ b/kernel/trace/trace_stack.c
90377@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
90378 return;
90379
90380 /* we do not handle interrupt stacks yet */
90381- if (!object_is_on_stack(stack))
90382+ if (!object_starts_on_stack(stack))
90383 return;
90384
90385 local_irq_save(flags);
90386diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
90387index 240fb62..583473e 100644
90388--- a/kernel/user_namespace.c
90389+++ b/kernel/user_namespace.c
90390@@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
90391 !kgid_has_mapping(parent_ns, group))
90392 return -EPERM;
90393
90394+#ifdef CONFIG_GRKERNSEC
90395+ /*
90396+ * This doesn't really inspire confidence:
90397+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
90398+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
90399+ * Increases kernel attack surface in areas developers
90400+ * previously cared little about ("low importance due
90401+ * to requiring "root" capability")
90402+ * To be removed when this code receives *proper* review
90403+ */
90404+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
90405+ !capable(CAP_SETGID))
90406+ return -EPERM;
90407+#endif
90408+
90409 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
90410 if (!ns)
90411 return -ENOMEM;
90412@@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
90413 if (atomic_read(&current->mm->mm_users) > 1)
90414 return -EINVAL;
90415
90416- if (current->fs->users != 1)
90417+ if (atomic_read(&current->fs->users) != 1)
90418 return -EINVAL;
90419
90420 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
90421diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
90422index 4f69f9a..7c6f8f8 100644
90423--- a/kernel/utsname_sysctl.c
90424+++ b/kernel/utsname_sysctl.c
90425@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
90426 static int proc_do_uts_string(ctl_table *table, int write,
90427 void __user *buffer, size_t *lenp, loff_t *ppos)
90428 {
90429- struct ctl_table uts_table;
90430+ ctl_table_no_const uts_table;
90431 int r;
90432 memcpy(&uts_table, table, sizeof(uts_table));
90433 uts_table.data = get_uts(table, write);
90434diff --git a/kernel/watchdog.c b/kernel/watchdog.c
90435index 4431610..4265616 100644
90436--- a/kernel/watchdog.c
90437+++ b/kernel/watchdog.c
90438@@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
90439 static void watchdog_nmi_disable(unsigned int cpu) { return; }
90440 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
90441
90442-static struct smp_hotplug_thread watchdog_threads = {
90443+static struct smp_hotplug_thread watchdog_threads __read_only = {
90444 .store = &softlockup_watchdog,
90445 .thread_should_run = watchdog_should_run,
90446 .thread_fn = watchdog,
90447diff --git a/kernel/workqueue.c b/kernel/workqueue.c
90448index a8381cf..1ce1331 100644
90449--- a/kernel/workqueue.c
90450+++ b/kernel/workqueue.c
90451@@ -4678,7 +4678,7 @@ static void rebind_workers(struct worker_pool *pool)
90452 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
90453 worker_flags |= WORKER_REBOUND;
90454 worker_flags &= ~WORKER_UNBOUND;
90455- ACCESS_ONCE(worker->flags) = worker_flags;
90456+ ACCESS_ONCE_RW(worker->flags) = worker_flags;
90457 }
90458
90459 spin_unlock_irq(&pool->lock);
90460diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
90461index db25707..8b16430 100644
90462--- a/lib/Kconfig.debug
90463+++ b/lib/Kconfig.debug
90464@@ -845,7 +845,7 @@ config DEBUG_MUTEXES
90465
90466 config DEBUG_WW_MUTEX_SLOWPATH
90467 bool "Wait/wound mutex debugging: Slowpath testing"
90468- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90469+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90470 select DEBUG_LOCK_ALLOC
90471 select DEBUG_SPINLOCK
90472 select DEBUG_MUTEXES
90473@@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
90474
90475 config DEBUG_LOCK_ALLOC
90476 bool "Lock debugging: detect incorrect freeing of live locks"
90477- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90478+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90479 select DEBUG_SPINLOCK
90480 select DEBUG_MUTEXES
90481 select LOCKDEP
90482@@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
90483
90484 config PROVE_LOCKING
90485 bool "Lock debugging: prove locking correctness"
90486- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90487+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90488 select LOCKDEP
90489 select DEBUG_SPINLOCK
90490 select DEBUG_MUTEXES
90491@@ -923,7 +923,7 @@ config LOCKDEP
90492
90493 config LOCK_STAT
90494 bool "Lock usage statistics"
90495- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
90496+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
90497 select LOCKDEP
90498 select DEBUG_SPINLOCK
90499 select DEBUG_MUTEXES
90500@@ -1385,6 +1385,7 @@ config LATENCYTOP
90501 depends on DEBUG_KERNEL
90502 depends on STACKTRACE_SUPPORT
90503 depends on PROC_FS
90504+ depends on !GRKERNSEC_HIDESYM
90505 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
90506 select KALLSYMS
90507 select KALLSYMS_ALL
90508@@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90509 config DEBUG_STRICT_USER_COPY_CHECKS
90510 bool "Strict user copy size checks"
90511 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
90512- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
90513+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
90514 help
90515 Enabling this option turns a certain set of sanity checks for user
90516 copy operations into compile time failures.
90517@@ -1520,7 +1521,7 @@ endmenu # runtime tests
90518
90519 config PROVIDE_OHCI1394_DMA_INIT
90520 bool "Remote debugging over FireWire early on boot"
90521- depends on PCI && X86
90522+ depends on PCI && X86 && !GRKERNSEC
90523 help
90524 If you want to debug problems which hang or crash the kernel early
90525 on boot and the crashing machine has a FireWire port, you can use
90526@@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
90527
90528 config FIREWIRE_OHCI_REMOTE_DMA
90529 bool "Remote debugging over FireWire with firewire-ohci"
90530- depends on FIREWIRE_OHCI
90531+ depends on FIREWIRE_OHCI && !GRKERNSEC
90532 help
90533 This option lets you use the FireWire bus for remote debugging
90534 with help of the firewire-ohci driver. It enables unfiltered
90535diff --git a/lib/Makefile b/lib/Makefile
90536index 04944e9..f43eabe 100644
90537--- a/lib/Makefile
90538+++ b/lib/Makefile
90539@@ -50,7 +50,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
90540 obj-$(CONFIG_BTREE) += btree.o
90541 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
90542 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
90543-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
90544+obj-y += list_debug.o
90545 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
90546
90547 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
90548diff --git a/lib/bitmap.c b/lib/bitmap.c
90549index 06f7e4f..f3cf2b0 100644
90550--- a/lib/bitmap.c
90551+++ b/lib/bitmap.c
90552@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
90553 {
90554 int c, old_c, totaldigits, ndigits, nchunks, nbits;
90555 u32 chunk;
90556- const char __user __force *ubuf = (const char __user __force *)buf;
90557+ const char __user *ubuf = (const char __force_user *)buf;
90558
90559 bitmap_zero(maskp, nmaskbits);
90560
90561@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
90562 {
90563 if (!access_ok(VERIFY_READ, ubuf, ulen))
90564 return -EFAULT;
90565- return __bitmap_parse((const char __force *)ubuf,
90566+ return __bitmap_parse((const char __force_kernel *)ubuf,
90567 ulen, 1, maskp, nmaskbits);
90568
90569 }
90570@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
90571 {
90572 unsigned a, b;
90573 int c, old_c, totaldigits;
90574- const char __user __force *ubuf = (const char __user __force *)buf;
90575+ const char __user *ubuf = (const char __force_user *)buf;
90576 int exp_digit, in_range;
90577
90578 totaldigits = c = 0;
90579@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
90580 {
90581 if (!access_ok(VERIFY_READ, ubuf, ulen))
90582 return -EFAULT;
90583- return __bitmap_parselist((const char __force *)ubuf,
90584+ return __bitmap_parselist((const char __force_kernel *)ubuf,
90585 ulen, 1, maskp, nmaskbits);
90586 }
90587 EXPORT_SYMBOL(bitmap_parselist_user);
90588diff --git a/lib/bug.c b/lib/bug.c
90589index 1686034..a9c00c8 100644
90590--- a/lib/bug.c
90591+++ b/lib/bug.c
90592@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
90593 return BUG_TRAP_TYPE_NONE;
90594
90595 bug = find_bug(bugaddr);
90596+ if (!bug)
90597+ return BUG_TRAP_TYPE_NONE;
90598
90599 file = NULL;
90600 line = 0;
90601diff --git a/lib/debugobjects.c b/lib/debugobjects.c
90602index e0731c3..ad66444 100644
90603--- a/lib/debugobjects.c
90604+++ b/lib/debugobjects.c
90605@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
90606 if (limit > 4)
90607 return;
90608
90609- is_on_stack = object_is_on_stack(addr);
90610+ is_on_stack = object_starts_on_stack(addr);
90611 if (is_on_stack == onstack)
90612 return;
90613
90614diff --git a/lib/devres.c b/lib/devres.c
90615index 8235331..5881053 100644
90616--- a/lib/devres.c
90617+++ b/lib/devres.c
90618@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
90619 void devm_iounmap(struct device *dev, void __iomem *addr)
90620 {
90621 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
90622- (void *)addr));
90623+ (void __force *)addr));
90624 iounmap(addr);
90625 }
90626 EXPORT_SYMBOL(devm_iounmap);
90627@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
90628 {
90629 ioport_unmap(addr);
90630 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
90631- devm_ioport_map_match, (void *)addr));
90632+ devm_ioport_map_match, (void __force *)addr));
90633 }
90634 EXPORT_SYMBOL(devm_ioport_unmap);
90635 #endif /* CONFIG_HAS_IOPORT */
90636diff --git a/lib/div64.c b/lib/div64.c
90637index 4382ad7..08aa558 100644
90638--- a/lib/div64.c
90639+++ b/lib/div64.c
90640@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
90641 EXPORT_SYMBOL(__div64_32);
90642
90643 #ifndef div_s64_rem
90644-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90645+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
90646 {
90647 u64 quotient;
90648
90649@@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
90650 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
90651 */
90652 #ifndef div64_u64
90653-u64 div64_u64(u64 dividend, u64 divisor)
90654+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
90655 {
90656 u32 high = divisor >> 32;
90657 u64 quot;
90658diff --git a/lib/dma-debug.c b/lib/dma-debug.c
90659index d87a17a..ac0d79a 100644
90660--- a/lib/dma-debug.c
90661+++ b/lib/dma-debug.c
90662@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
90663
90664 void dma_debug_add_bus(struct bus_type *bus)
90665 {
90666- struct notifier_block *nb;
90667+ notifier_block_no_const *nb;
90668
90669 if (global_disable)
90670 return;
90671@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
90672
90673 static void check_for_stack(struct device *dev, void *addr)
90674 {
90675- if (object_is_on_stack(addr))
90676+ if (object_starts_on_stack(addr))
90677 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
90678 "stack [addr=%p]\n", addr);
90679 }
90680diff --git a/lib/inflate.c b/lib/inflate.c
90681index 013a761..c28f3fc 100644
90682--- a/lib/inflate.c
90683+++ b/lib/inflate.c
90684@@ -269,7 +269,7 @@ static void free(void *where)
90685 malloc_ptr = free_mem_ptr;
90686 }
90687 #else
90688-#define malloc(a) kmalloc(a, GFP_KERNEL)
90689+#define malloc(a) kmalloc((a), GFP_KERNEL)
90690 #define free(a) kfree(a)
90691 #endif
90692
90693diff --git a/lib/ioremap.c b/lib/ioremap.c
90694index 0c9216c..863bd89 100644
90695--- a/lib/ioremap.c
90696+++ b/lib/ioremap.c
90697@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
90698 unsigned long next;
90699
90700 phys_addr -= addr;
90701- pmd = pmd_alloc(&init_mm, pud, addr);
90702+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
90703 if (!pmd)
90704 return -ENOMEM;
90705 do {
90706@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
90707 unsigned long next;
90708
90709 phys_addr -= addr;
90710- pud = pud_alloc(&init_mm, pgd, addr);
90711+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
90712 if (!pud)
90713 return -ENOMEM;
90714 do {
90715diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
90716index bd2bea9..6b3c95e 100644
90717--- a/lib/is_single_threaded.c
90718+++ b/lib/is_single_threaded.c
90719@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
90720 struct task_struct *p, *t;
90721 bool ret;
90722
90723+ if (!mm)
90724+ return true;
90725+
90726 if (atomic_read(&task->signal->live) != 1)
90727 return false;
90728
90729diff --git a/lib/kobject.c b/lib/kobject.c
90730index 5b4b888..c2950f7 100644
90731--- a/lib/kobject.c
90732+++ b/lib/kobject.c
90733@@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
90734
90735
90736 static DEFINE_SPINLOCK(kobj_ns_type_lock);
90737-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
90738+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
90739
90740-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90741+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
90742 {
90743 enum kobj_ns_type type = ops->type;
90744 int error;
90745diff --git a/lib/list_debug.c b/lib/list_debug.c
90746index c24c2f7..f0296f4 100644
90747--- a/lib/list_debug.c
90748+++ b/lib/list_debug.c
90749@@ -11,7 +11,9 @@
90750 #include <linux/bug.h>
90751 #include <linux/kernel.h>
90752 #include <linux/rculist.h>
90753+#include <linux/mm.h>
90754
90755+#ifdef CONFIG_DEBUG_LIST
90756 /*
90757 * Insert a new entry between two known consecutive entries.
90758 *
90759@@ -19,21 +21,40 @@
90760 * the prev/next entries already!
90761 */
90762
90763+static bool __list_add_debug(struct list_head *new,
90764+ struct list_head *prev,
90765+ struct list_head *next)
90766+{
90767+ if (unlikely(next->prev != prev)) {
90768+ printk(KERN_ERR "list_add corruption. next->prev should be "
90769+ "prev (%p), but was %p. (next=%p).\n",
90770+ prev, next->prev, next);
90771+ BUG();
90772+ return false;
90773+ }
90774+ if (unlikely(prev->next != next)) {
90775+ printk(KERN_ERR "list_add corruption. prev->next should be "
90776+ "next (%p), but was %p. (prev=%p).\n",
90777+ next, prev->next, prev);
90778+ BUG();
90779+ return false;
90780+ }
90781+ if (unlikely(new == prev || new == next)) {
90782+ printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
90783+ new, prev, next);
90784+ BUG();
90785+ return false;
90786+ }
90787+ return true;
90788+}
90789+
90790 void __list_add(struct list_head *new,
90791- struct list_head *prev,
90792- struct list_head *next)
90793+ struct list_head *prev,
90794+ struct list_head *next)
90795 {
90796- WARN(next->prev != prev,
90797- "list_add corruption. next->prev should be "
90798- "prev (%p), but was %p. (next=%p).\n",
90799- prev, next->prev, next);
90800- WARN(prev->next != next,
90801- "list_add corruption. prev->next should be "
90802- "next (%p), but was %p. (prev=%p).\n",
90803- next, prev->next, prev);
90804- WARN(new == prev || new == next,
90805- "list_add double add: new=%p, prev=%p, next=%p.\n",
90806- new, prev, next);
90807+ if (!__list_add_debug(new, prev, next))
90808+ return;
90809+
90810 next->prev = new;
90811 new->next = next;
90812 new->prev = prev;
90813@@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
90814 }
90815 EXPORT_SYMBOL(__list_add);
90816
90817-void __list_del_entry(struct list_head *entry)
90818+static bool __list_del_entry_debug(struct list_head *entry)
90819 {
90820 struct list_head *prev, *next;
90821
90822 prev = entry->prev;
90823 next = entry->next;
90824
90825- if (WARN(next == LIST_POISON1,
90826- "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90827- entry, LIST_POISON1) ||
90828- WARN(prev == LIST_POISON2,
90829- "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90830- entry, LIST_POISON2) ||
90831- WARN(prev->next != entry,
90832- "list_del corruption. prev->next should be %p, "
90833- "but was %p\n", entry, prev->next) ||
90834- WARN(next->prev != entry,
90835- "list_del corruption. next->prev should be %p, "
90836- "but was %p\n", entry, next->prev))
90837+ if (unlikely(next == LIST_POISON1)) {
90838+ printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
90839+ entry, LIST_POISON1);
90840+ BUG();
90841+ return false;
90842+ }
90843+ if (unlikely(prev == LIST_POISON2)) {
90844+ printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
90845+ entry, LIST_POISON2);
90846+ BUG();
90847+ return false;
90848+ }
90849+ if (unlikely(entry->prev->next != entry)) {
90850+ printk(KERN_ERR "list_del corruption. prev->next should be %p, "
90851+ "but was %p\n", entry, prev->next);
90852+ BUG();
90853+ return false;
90854+ }
90855+ if (unlikely(entry->next->prev != entry)) {
90856+ printk(KERN_ERR "list_del corruption. next->prev should be %p, "
90857+ "but was %p\n", entry, next->prev);
90858+ BUG();
90859+ return false;
90860+ }
90861+ return true;
90862+}
90863+
90864+void __list_del_entry(struct list_head *entry)
90865+{
90866+ if (!__list_del_entry_debug(entry))
90867 return;
90868
90869- __list_del(prev, next);
90870+ __list_del(entry->prev, entry->next);
90871 }
90872 EXPORT_SYMBOL(__list_del_entry);
90873
90874@@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
90875 void __list_add_rcu(struct list_head *new,
90876 struct list_head *prev, struct list_head *next)
90877 {
90878- WARN(next->prev != prev,
90879- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
90880- prev, next->prev, next);
90881- WARN(prev->next != next,
90882- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
90883- next, prev->next, prev);
90884+ if (!__list_add_debug(new, prev, next))
90885+ return;
90886+
90887 new->next = next;
90888 new->prev = prev;
90889 rcu_assign_pointer(list_next_rcu(prev), new);
90890 next->prev = new;
90891 }
90892 EXPORT_SYMBOL(__list_add_rcu);
90893+#endif
90894+
90895+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
90896+{
90897+#ifdef CONFIG_DEBUG_LIST
90898+ if (!__list_add_debug(new, prev, next))
90899+ return;
90900+#endif
90901+
90902+ pax_open_kernel();
90903+ next->prev = new;
90904+ new->next = next;
90905+ new->prev = prev;
90906+ prev->next = new;
90907+ pax_close_kernel();
90908+}
90909+EXPORT_SYMBOL(__pax_list_add);
90910+
90911+void pax_list_del(struct list_head *entry)
90912+{
90913+#ifdef CONFIG_DEBUG_LIST
90914+ if (!__list_del_entry_debug(entry))
90915+ return;
90916+#endif
90917+
90918+ pax_open_kernel();
90919+ __list_del(entry->prev, entry->next);
90920+ entry->next = LIST_POISON1;
90921+ entry->prev = LIST_POISON2;
90922+ pax_close_kernel();
90923+}
90924+EXPORT_SYMBOL(pax_list_del);
90925+
90926+void pax_list_del_init(struct list_head *entry)
90927+{
90928+ pax_open_kernel();
90929+ __list_del(entry->prev, entry->next);
90930+ INIT_LIST_HEAD(entry);
90931+ pax_close_kernel();
90932+}
90933+EXPORT_SYMBOL(pax_list_del_init);
90934+
90935+void __pax_list_add_rcu(struct list_head *new,
90936+ struct list_head *prev, struct list_head *next)
90937+{
90938+#ifdef CONFIG_DEBUG_LIST
90939+ if (!__list_add_debug(new, prev, next))
90940+ return;
90941+#endif
90942+
90943+ pax_open_kernel();
90944+ new->next = next;
90945+ new->prev = prev;
90946+ rcu_assign_pointer(list_next_rcu(prev), new);
90947+ next->prev = new;
90948+ pax_close_kernel();
90949+}
90950+EXPORT_SYMBOL(__pax_list_add_rcu);
90951+
90952+void pax_list_del_rcu(struct list_head *entry)
90953+{
90954+#ifdef CONFIG_DEBUG_LIST
90955+ if (!__list_del_entry_debug(entry))
90956+ return;
90957+#endif
90958+
90959+ pax_open_kernel();
90960+ __list_del(entry->prev, entry->next);
90961+ entry->next = LIST_POISON1;
90962+ entry->prev = LIST_POISON2;
90963+ pax_close_kernel();
90964+}
90965+EXPORT_SYMBOL(pax_list_del_rcu);
90966diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
90967index 1a53d49..ace934c 100644
90968--- a/lib/percpu-refcount.c
90969+++ b/lib/percpu-refcount.c
90970@@ -29,7 +29,7 @@
90971 * can't hit 0 before we've added up all the percpu refs.
90972 */
90973
90974-#define PCPU_COUNT_BIAS (1U << 31)
90975+#define PCPU_COUNT_BIAS (1U << 30)
90976
90977 /**
90978 * percpu_ref_init - initialize a percpu refcount
90979diff --git a/lib/radix-tree.c b/lib/radix-tree.c
90980index 7811ed3..f80ca19 100644
90981--- a/lib/radix-tree.c
90982+++ b/lib/radix-tree.c
90983@@ -93,7 +93,7 @@ struct radix_tree_preload {
90984 int nr;
90985 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
90986 };
90987-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
90988+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
90989
90990 static inline void *ptr_to_indirect(void *ptr)
90991 {
90992diff --git a/lib/random32.c b/lib/random32.c
90993index 6148967..009bfe8 100644
90994--- a/lib/random32.c
90995+++ b/lib/random32.c
90996@@ -44,7 +44,7 @@
90997 static void __init prandom_state_selftest(void);
90998 #endif
90999
91000-static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
91001+static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
91002
91003 /**
91004 * prandom_u32_state - seeded pseudo-random number generator.
91005diff --git a/lib/rbtree.c b/lib/rbtree.c
91006index 65f4eff..2cfa167 100644
91007--- a/lib/rbtree.c
91008+++ b/lib/rbtree.c
91009@@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
91010 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
91011
91012 static const struct rb_augment_callbacks dummy_callbacks = {
91013- dummy_propagate, dummy_copy, dummy_rotate
91014+ .propagate = dummy_propagate,
91015+ .copy = dummy_copy,
91016+ .rotate = dummy_rotate
91017 };
91018
91019 void rb_insert_color(struct rb_node *node, struct rb_root *root)
91020diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
91021index bb2b201..46abaf9 100644
91022--- a/lib/strncpy_from_user.c
91023+++ b/lib/strncpy_from_user.c
91024@@ -21,7 +21,7 @@
91025 */
91026 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
91027 {
91028- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91029+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91030 long res = 0;
91031
91032 /*
91033diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
91034index a28df52..3d55877 100644
91035--- a/lib/strnlen_user.c
91036+++ b/lib/strnlen_user.c
91037@@ -26,7 +26,7 @@
91038 */
91039 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
91040 {
91041- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91042+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
91043 long align, res = 0;
91044 unsigned long c;
91045
91046diff --git a/lib/swiotlb.c b/lib/swiotlb.c
91047index e4399fa..5e8b214 100644
91048--- a/lib/swiotlb.c
91049+++ b/lib/swiotlb.c
91050@@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
91051
91052 void
91053 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
91054- dma_addr_t dev_addr)
91055+ dma_addr_t dev_addr, struct dma_attrs *attrs)
91056 {
91057 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
91058
91059diff --git a/lib/usercopy.c b/lib/usercopy.c
91060index 4f5b1dd..7cab418 100644
91061--- a/lib/usercopy.c
91062+++ b/lib/usercopy.c
91063@@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
91064 WARN(1, "Buffer overflow detected!\n");
91065 }
91066 EXPORT_SYMBOL(copy_from_user_overflow);
91067+
91068+void copy_to_user_overflow(void)
91069+{
91070+ WARN(1, "Buffer overflow detected!\n");
91071+}
91072+EXPORT_SYMBOL(copy_to_user_overflow);
91073diff --git a/lib/vsprintf.c b/lib/vsprintf.c
91074index 10909c5..653e1b8 100644
91075--- a/lib/vsprintf.c
91076+++ b/lib/vsprintf.c
91077@@ -16,6 +16,9 @@
91078 * - scnprintf and vscnprintf
91079 */
91080
91081+#ifdef CONFIG_GRKERNSEC_HIDESYM
91082+#define __INCLUDED_BY_HIDESYM 1
91083+#endif
91084 #include <stdarg.h>
91085 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
91086 #include <linux/types.h>
91087@@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
91088 return number(buf, end, *(const netdev_features_t *)addr, spec);
91089 }
91090
91091+#ifdef CONFIG_GRKERNSEC_HIDESYM
91092+int kptr_restrict __read_mostly = 2;
91093+#else
91094 int kptr_restrict __read_mostly;
91095+#endif
91096
91097 /*
91098 * Show a '%p' thing. A kernel extension is that the '%p' is followed
91099@@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
91100 * - 'f' For simple symbolic function names without offset
91101 * - 'S' For symbolic direct pointers with offset
91102 * - 's' For symbolic direct pointers without offset
91103+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
91104 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
91105 * - 'B' For backtraced symbolic direct pointers with offset
91106 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
91107@@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91108
91109 if (!ptr && *fmt != 'K') {
91110 /*
91111- * Print (null) with the same width as a pointer so it makes
91112+ * Print (nil) with the same width as a pointer so it makes
91113 * tabular output look nice.
91114 */
91115 if (spec.field_width == -1)
91116 spec.field_width = default_width;
91117- return string(buf, end, "(null)", spec);
91118+ return string(buf, end, "(nil)", spec);
91119 }
91120
91121 switch (*fmt) {
91122@@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91123 /* Fallthrough */
91124 case 'S':
91125 case 's':
91126+#ifdef CONFIG_GRKERNSEC_HIDESYM
91127+ break;
91128+#else
91129+ return symbol_string(buf, end, ptr, spec, fmt);
91130+#endif
91131+ case 'A':
91132 case 'B':
91133 return symbol_string(buf, end, ptr, spec, fmt);
91134 case 'R':
91135@@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91136 va_end(va);
91137 return buf;
91138 }
91139+ case 'P':
91140+ break;
91141 case 'K':
91142 /*
91143 * %pK cannot be used in IRQ context because its test
91144@@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
91145 ((const struct file *)ptr)->f_path.dentry,
91146 spec, fmt);
91147 }
91148+
91149+#ifdef CONFIG_GRKERNSEC_HIDESYM
91150+ /* 'P' = approved pointers to copy to userland,
91151+ as in the /proc/kallsyms case, as we make it display nothing
91152+ for non-root users, and the real contents for root users
91153+ Also ignore 'K' pointers, since we force their NULLing for non-root users
91154+ above
91155+ */
91156+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
91157+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
91158+ dump_stack();
91159+ ptr = NULL;
91160+ }
91161+#endif
91162+
91163 spec.flags |= SMALL;
91164 if (spec.field_width == -1) {
91165 spec.field_width = default_width;
91166@@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91167 typeof(type) value; \
91168 if (sizeof(type) == 8) { \
91169 args = PTR_ALIGN(args, sizeof(u32)); \
91170- *(u32 *)&value = *(u32 *)args; \
91171- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
91172+ *(u32 *)&value = *(const u32 *)args; \
91173+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
91174 } else { \
91175 args = PTR_ALIGN(args, sizeof(type)); \
91176- value = *(typeof(type) *)args; \
91177+ value = *(const typeof(type) *)args; \
91178 } \
91179 args += sizeof(type); \
91180 value; \
91181@@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
91182 case FORMAT_TYPE_STR: {
91183 const char *str_arg = args;
91184 args += strlen(str_arg) + 1;
91185- str = string(str, end, (char *)str_arg, spec);
91186+ str = string(str, end, str_arg, spec);
91187 break;
91188 }
91189
91190diff --git a/localversion-grsec b/localversion-grsec
91191new file mode 100644
91192index 0000000..7cd6065
91193--- /dev/null
91194+++ b/localversion-grsec
91195@@ -0,0 +1 @@
91196+-grsec
91197diff --git a/mm/Kconfig b/mm/Kconfig
91198index 723bbe0..ea624b1 100644
91199--- a/mm/Kconfig
91200+++ b/mm/Kconfig
91201@@ -326,10 +326,11 @@ config KSM
91202 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
91203
91204 config DEFAULT_MMAP_MIN_ADDR
91205- int "Low address space to protect from user allocation"
91206+ int "Low address space to protect from user allocation"
91207 depends on MMU
91208- default 4096
91209- help
91210+ default 32768 if ALPHA || ARM || PARISC || SPARC32
91211+ default 65536
91212+ help
91213 This is the portion of low virtual memory which should be protected
91214 from userspace allocation. Keeping a user from writing to low pages
91215 can help reduce the impact of kernel NULL pointer bugs.
91216@@ -360,7 +361,7 @@ config MEMORY_FAILURE
91217
91218 config HWPOISON_INJECT
91219 tristate "HWPoison pages injector"
91220- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
91221+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
91222 select PROC_PAGE_MONITOR
91223
91224 config NOMMU_INITIAL_TRIM_EXCESS
91225diff --git a/mm/backing-dev.c b/mm/backing-dev.c
91226index ce682f7..1fb54f9 100644
91227--- a/mm/backing-dev.c
91228+++ b/mm/backing-dev.c
91229@@ -12,7 +12,7 @@
91230 #include <linux/device.h>
91231 #include <trace/events/writeback.h>
91232
91233-static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
91234+static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
91235
91236 struct backing_dev_info default_backing_dev_info = {
91237 .name = "default",
91238@@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
91239 return err;
91240
91241 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
91242- atomic_long_inc_return(&bdi_seq));
91243+ atomic_long_inc_return_unchecked(&bdi_seq));
91244 if (err) {
91245 bdi_destroy(bdi);
91246 return err;
91247diff --git a/mm/filemap.c b/mm/filemap.c
91248index b7749a9..50d1123 100644
91249--- a/mm/filemap.c
91250+++ b/mm/filemap.c
91251@@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
91252 struct address_space *mapping = file->f_mapping;
91253
91254 if (!mapping->a_ops->readpage)
91255- return -ENOEXEC;
91256+ return -ENODEV;
91257 file_accessed(file);
91258 vma->vm_ops = &generic_file_vm_ops;
91259 return 0;
91260@@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
91261
91262 while (bytes) {
91263 char __user *buf = iov->iov_base + base;
91264- int copy = min(bytes, iov->iov_len - base);
91265+ size_t copy = min(bytes, iov->iov_len - base);
91266
91267 base = 0;
91268 left = __copy_from_user_inatomic(vaddr, buf, copy);
91269@@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
91270 BUG_ON(!in_atomic());
91271 kaddr = kmap_atomic(page);
91272 if (likely(i->nr_segs == 1)) {
91273- int left;
91274+ size_t left;
91275 char __user *buf = i->iov->iov_base + i->iov_offset;
91276 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
91277 copied = bytes - left;
91278@@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
91279
91280 kaddr = kmap(page);
91281 if (likely(i->nr_segs == 1)) {
91282- int left;
91283+ size_t left;
91284 char __user *buf = i->iov->iov_base + i->iov_offset;
91285 left = __copy_from_user(kaddr + offset, buf, bytes);
91286 copied = bytes - left;
91287@@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
91288 * zero-length segments (without overruning the iovec).
91289 */
91290 while (bytes || unlikely(i->count && !iov->iov_len)) {
91291- int copy;
91292+ size_t copy;
91293
91294 copy = min(bytes, iov->iov_len - base);
91295 BUG_ON(!i->count || i->count < copy);
91296@@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
91297 *pos = i_size_read(inode);
91298
91299 if (limit != RLIM_INFINITY) {
91300+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
91301 if (*pos >= limit) {
91302 send_sig(SIGXFSZ, current, 0);
91303 return -EFBIG;
91304diff --git a/mm/fremap.c b/mm/fremap.c
91305index bbc4d66..117b798 100644
91306--- a/mm/fremap.c
91307+++ b/mm/fremap.c
91308@@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
91309 retry:
91310 vma = find_vma(mm, start);
91311
91312+#ifdef CONFIG_PAX_SEGMEXEC
91313+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
91314+ goto out;
91315+#endif
91316+
91317 /*
91318 * Make sure the vma is shared, that it supports prefaulting,
91319 * and that the remapped range is valid and fully within
91320diff --git a/mm/highmem.c b/mm/highmem.c
91321index b32b70c..e512eb0 100644
91322--- a/mm/highmem.c
91323+++ b/mm/highmem.c
91324@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
91325 * So no dangers, even with speculative execution.
91326 */
91327 page = pte_page(pkmap_page_table[i]);
91328+ pax_open_kernel();
91329 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
91330-
91331+ pax_close_kernel();
91332 set_page_address(page, NULL);
91333 need_flush = 1;
91334 }
91335@@ -198,9 +199,11 @@ start:
91336 }
91337 }
91338 vaddr = PKMAP_ADDR(last_pkmap_nr);
91339+
91340+ pax_open_kernel();
91341 set_pte_at(&init_mm, vaddr,
91342 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
91343-
91344+ pax_close_kernel();
91345 pkmap_count[last_pkmap_nr] = 1;
91346 set_page_address(page, (void *)vaddr);
91347
91348diff --git a/mm/hugetlb.c b/mm/hugetlb.c
91349index dee6cf4..52b94f7 100644
91350--- a/mm/hugetlb.c
91351+++ b/mm/hugetlb.c
91352@@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
91353 struct hstate *h = &default_hstate;
91354 unsigned long tmp;
91355 int ret;
91356+ ctl_table_no_const hugetlb_table;
91357
91358 tmp = h->max_huge_pages;
91359
91360 if (write && h->order >= MAX_ORDER)
91361 return -EINVAL;
91362
91363- table->data = &tmp;
91364- table->maxlen = sizeof(unsigned long);
91365- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91366+ hugetlb_table = *table;
91367+ hugetlb_table.data = &tmp;
91368+ hugetlb_table.maxlen = sizeof(unsigned long);
91369+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91370 if (ret)
91371 goto out;
91372
91373@@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
91374 struct hstate *h = &default_hstate;
91375 unsigned long tmp;
91376 int ret;
91377+ ctl_table_no_const hugetlb_table;
91378
91379 tmp = h->nr_overcommit_huge_pages;
91380
91381 if (write && h->order >= MAX_ORDER)
91382 return -EINVAL;
91383
91384- table->data = &tmp;
91385- table->maxlen = sizeof(unsigned long);
91386- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
91387+ hugetlb_table = *table;
91388+ hugetlb_table.data = &tmp;
91389+ hugetlb_table.maxlen = sizeof(unsigned long);
91390+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
91391 if (ret)
91392 goto out;
91393
91394@@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
91395 return 1;
91396 }
91397
91398+#ifdef CONFIG_PAX_SEGMEXEC
91399+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
91400+{
91401+ struct mm_struct *mm = vma->vm_mm;
91402+ struct vm_area_struct *vma_m;
91403+ unsigned long address_m;
91404+ pte_t *ptep_m;
91405+
91406+ vma_m = pax_find_mirror_vma(vma);
91407+ if (!vma_m)
91408+ return;
91409+
91410+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91411+ address_m = address + SEGMEXEC_TASK_SIZE;
91412+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
91413+ get_page(page_m);
91414+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
91415+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
91416+}
91417+#endif
91418+
91419 /*
91420 * Hugetlb_cow() should be called with page lock of the original hugepage held.
91421 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
91422@@ -2712,6 +2737,11 @@ retry_avoidcopy:
91423 make_huge_pte(vma, new_page, 1));
91424 page_remove_rmap(old_page);
91425 hugepage_add_new_anon_rmap(new_page, vma, address);
91426+
91427+#ifdef CONFIG_PAX_SEGMEXEC
91428+ pax_mirror_huge_pte(vma, address, new_page);
91429+#endif
91430+
91431 /* Make the old page be freed below */
91432 new_page = old_page;
91433 }
91434@@ -2876,6 +2906,10 @@ retry:
91435 && (vma->vm_flags & VM_SHARED)));
91436 set_huge_pte_at(mm, address, ptep, new_pte);
91437
91438+#ifdef CONFIG_PAX_SEGMEXEC
91439+ pax_mirror_huge_pte(vma, address, page);
91440+#endif
91441+
91442 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
91443 /* Optimization, do the COW without a second fault */
91444 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
91445@@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91446 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
91447 struct hstate *h = hstate_vma(vma);
91448
91449+#ifdef CONFIG_PAX_SEGMEXEC
91450+ struct vm_area_struct *vma_m;
91451+#endif
91452+
91453 address &= huge_page_mask(h);
91454
91455 ptep = huge_pte_offset(mm, address);
91456@@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91457 VM_FAULT_SET_HINDEX(hstate_index(h));
91458 }
91459
91460+#ifdef CONFIG_PAX_SEGMEXEC
91461+ vma_m = pax_find_mirror_vma(vma);
91462+ if (vma_m) {
91463+ unsigned long address_m;
91464+
91465+ if (vma->vm_start > vma_m->vm_start) {
91466+ address_m = address;
91467+ address -= SEGMEXEC_TASK_SIZE;
91468+ vma = vma_m;
91469+ h = hstate_vma(vma);
91470+ } else
91471+ address_m = address + SEGMEXEC_TASK_SIZE;
91472+
91473+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
91474+ return VM_FAULT_OOM;
91475+ address_m &= HPAGE_MASK;
91476+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
91477+ }
91478+#endif
91479+
91480 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
91481 if (!ptep)
91482 return VM_FAULT_OOM;
91483diff --git a/mm/internal.h b/mm/internal.h
91484index 8b6cfd6..ec809a6 100644
91485--- a/mm/internal.h
91486+++ b/mm/internal.h
91487@@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
91488 * in mm/page_alloc.c
91489 */
91490 extern void __free_pages_bootmem(struct page *page, unsigned int order);
91491+extern void free_compound_page(struct page *page);
91492 extern void prep_compound_page(struct page *page, unsigned long order);
91493 #ifdef CONFIG_MEMORY_FAILURE
91494 extern bool is_free_buddy_page(struct page *page);
91495@@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
91496
91497 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
91498 unsigned long, unsigned long,
91499- unsigned long, unsigned long);
91500+ unsigned long, unsigned long) __intentional_overflow(-1);
91501
91502 extern void set_pageblock_order(void);
91503 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
91504diff --git a/mm/kmemleak.c b/mm/kmemleak.c
91505index 31f01c5..7015178 100644
91506--- a/mm/kmemleak.c
91507+++ b/mm/kmemleak.c
91508@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
91509
91510 for (i = 0; i < object->trace_len; i++) {
91511 void *ptr = (void *)object->trace[i];
91512- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
91513+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
91514 }
91515 }
91516
91517@@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
91518 return -ENOMEM;
91519 }
91520
91521- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
91522+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
91523 &kmemleak_fops);
91524 if (!dentry)
91525 pr_warning("Failed to create the debugfs kmemleak file\n");
91526diff --git a/mm/maccess.c b/mm/maccess.c
91527index d53adf9..03a24bf 100644
91528--- a/mm/maccess.c
91529+++ b/mm/maccess.c
91530@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
91531 set_fs(KERNEL_DS);
91532 pagefault_disable();
91533 ret = __copy_from_user_inatomic(dst,
91534- (__force const void __user *)src, size);
91535+ (const void __force_user *)src, size);
91536 pagefault_enable();
91537 set_fs(old_fs);
91538
91539@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
91540
91541 set_fs(KERNEL_DS);
91542 pagefault_disable();
91543- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
91544+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
91545 pagefault_enable();
91546 set_fs(old_fs);
91547
91548diff --git a/mm/madvise.c b/mm/madvise.c
91549index 539eeb9..e24a987 100644
91550--- a/mm/madvise.c
91551+++ b/mm/madvise.c
91552@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
91553 pgoff_t pgoff;
91554 unsigned long new_flags = vma->vm_flags;
91555
91556+#ifdef CONFIG_PAX_SEGMEXEC
91557+ struct vm_area_struct *vma_m;
91558+#endif
91559+
91560 switch (behavior) {
91561 case MADV_NORMAL:
91562 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
91563@@ -126,6 +130,13 @@ success:
91564 /*
91565 * vm_flags is protected by the mmap_sem held in write mode.
91566 */
91567+
91568+#ifdef CONFIG_PAX_SEGMEXEC
91569+ vma_m = pax_find_mirror_vma(vma);
91570+ if (vma_m)
91571+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
91572+#endif
91573+
91574 vma->vm_flags = new_flags;
91575
91576 out:
91577@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91578 struct vm_area_struct **prev,
91579 unsigned long start, unsigned long end)
91580 {
91581+
91582+#ifdef CONFIG_PAX_SEGMEXEC
91583+ struct vm_area_struct *vma_m;
91584+#endif
91585+
91586 *prev = vma;
91587 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
91588 return -EINVAL;
91589@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
91590 zap_page_range(vma, start, end - start, &details);
91591 } else
91592 zap_page_range(vma, start, end - start, NULL);
91593+
91594+#ifdef CONFIG_PAX_SEGMEXEC
91595+ vma_m = pax_find_mirror_vma(vma);
91596+ if (vma_m) {
91597+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
91598+ struct zap_details details = {
91599+ .nonlinear_vma = vma_m,
91600+ .last_index = ULONG_MAX,
91601+ };
91602+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
91603+ } else
91604+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
91605+ }
91606+#endif
91607+
91608 return 0;
91609 }
91610
91611@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
91612 if (end < start)
91613 return error;
91614
91615+#ifdef CONFIG_PAX_SEGMEXEC
91616+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
91617+ if (end > SEGMEXEC_TASK_SIZE)
91618+ return error;
91619+ } else
91620+#endif
91621+
91622+ if (end > TASK_SIZE)
91623+ return error;
91624+
91625 error = 0;
91626 if (end == start)
91627 return error;
91628diff --git a/mm/memory-failure.c b/mm/memory-failure.c
91629index 4566e8f..46be98c 100644
91630--- a/mm/memory-failure.c
91631+++ b/mm/memory-failure.c
91632@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
91633
91634 int sysctl_memory_failure_recovery __read_mostly = 1;
91635
91636-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91637+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
91638
91639 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
91640
91641@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
91642 pfn, t->comm, t->pid);
91643 si.si_signo = SIGBUS;
91644 si.si_errno = 0;
91645- si.si_addr = (void *)addr;
91646+ si.si_addr = (void __user *)addr;
91647 #ifdef __ARCH_SI_TRAPNO
91648 si.si_trapno = trapno;
91649 #endif
91650@@ -762,7 +762,7 @@ static struct page_state {
91651 unsigned long res;
91652 char *msg;
91653 int (*action)(struct page *p, unsigned long pfn);
91654-} error_states[] = {
91655+} __do_const error_states[] = {
91656 { reserved, reserved, "reserved kernel", me_kernel },
91657 /*
91658 * free pages are specially detected outside this table:
91659@@ -1062,7 +1062,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91660 nr_pages = 1 << compound_order(hpage);
91661 else /* normal page or thp */
91662 nr_pages = 1;
91663- atomic_long_add(nr_pages, &num_poisoned_pages);
91664+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
91665
91666 /*
91667 * We need/can do nothing about count=0 pages.
91668@@ -1092,7 +1092,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91669 if (!PageHWPoison(hpage)
91670 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
91671 || (p != hpage && TestSetPageHWPoison(hpage))) {
91672- atomic_long_sub(nr_pages, &num_poisoned_pages);
91673+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91674 return 0;
91675 }
91676 set_page_hwpoison_huge_page(hpage);
91677@@ -1161,7 +1161,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
91678 }
91679 if (hwpoison_filter(p)) {
91680 if (TestClearPageHWPoison(p))
91681- atomic_long_sub(nr_pages, &num_poisoned_pages);
91682+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91683 unlock_page(hpage);
91684 put_page(hpage);
91685 return 0;
91686@@ -1383,7 +1383,7 @@ int unpoison_memory(unsigned long pfn)
91687 return 0;
91688 }
91689 if (TestClearPageHWPoison(p))
91690- atomic_long_dec(&num_poisoned_pages);
91691+ atomic_long_dec_unchecked(&num_poisoned_pages);
91692 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
91693 return 0;
91694 }
91695@@ -1397,7 +1397,7 @@ int unpoison_memory(unsigned long pfn)
91696 */
91697 if (TestClearPageHWPoison(page)) {
91698 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
91699- atomic_long_sub(nr_pages, &num_poisoned_pages);
91700+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
91701 freeit = 1;
91702 if (PageHuge(page))
91703 clear_page_hwpoison_huge_page(page);
91704@@ -1522,11 +1522,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
91705 if (PageHuge(page)) {
91706 set_page_hwpoison_huge_page(hpage);
91707 dequeue_hwpoisoned_huge_page(hpage);
91708- atomic_long_add(1 << compound_order(hpage),
91709+ atomic_long_add_unchecked(1 << compound_order(hpage),
91710 &num_poisoned_pages);
91711 } else {
91712 SetPageHWPoison(page);
91713- atomic_long_inc(&num_poisoned_pages);
91714+ atomic_long_inc_unchecked(&num_poisoned_pages);
91715 }
91716 }
91717 return ret;
91718@@ -1565,7 +1565,7 @@ static int __soft_offline_page(struct page *page, int flags)
91719 put_page(page);
91720 pr_info("soft_offline: %#lx: invalidated\n", pfn);
91721 SetPageHWPoison(page);
91722- atomic_long_inc(&num_poisoned_pages);
91723+ atomic_long_inc_unchecked(&num_poisoned_pages);
91724 return 0;
91725 }
91726
91727@@ -1610,7 +1610,7 @@ static int __soft_offline_page(struct page *page, int flags)
91728 if (!is_free_buddy_page(page))
91729 pr_info("soft offline: %#lx: page leaked\n",
91730 pfn);
91731- atomic_long_inc(&num_poisoned_pages);
91732+ atomic_long_inc_unchecked(&num_poisoned_pages);
91733 }
91734 } else {
91735 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
91736@@ -1684,11 +1684,11 @@ int soft_offline_page(struct page *page, int flags)
91737 if (PageHuge(page)) {
91738 set_page_hwpoison_huge_page(hpage);
91739 dequeue_hwpoisoned_huge_page(hpage);
91740- atomic_long_add(1 << compound_order(hpage),
91741+ atomic_long_add_unchecked(1 << compound_order(hpage),
91742 &num_poisoned_pages);
91743 } else {
91744 SetPageHWPoison(page);
91745- atomic_long_inc(&num_poisoned_pages);
91746+ atomic_long_inc_unchecked(&num_poisoned_pages);
91747 }
91748 }
91749 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
91750diff --git a/mm/memory.c b/mm/memory.c
91751index dda27b9..c56b9d6 100644
91752--- a/mm/memory.c
91753+++ b/mm/memory.c
91754@@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91755 free_pte_range(tlb, pmd, addr);
91756 } while (pmd++, addr = next, addr != end);
91757
91758+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
91759 start &= PUD_MASK;
91760 if (start < floor)
91761 return;
91762@@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
91763 pmd = pmd_offset(pud, start);
91764 pud_clear(pud);
91765 pmd_free_tlb(tlb, pmd, start);
91766+#endif
91767+
91768 }
91769
91770 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91771@@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91772 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
91773 } while (pud++, addr = next, addr != end);
91774
91775+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
91776 start &= PGDIR_MASK;
91777 if (start < floor)
91778 return;
91779@@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
91780 pud = pud_offset(pgd, start);
91781 pgd_clear(pgd);
91782 pud_free_tlb(tlb, pud, start);
91783+#endif
91784+
91785 }
91786
91787 /*
91788@@ -1635,12 +1641,6 @@ no_page_table:
91789 return page;
91790 }
91791
91792-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
91793-{
91794- return stack_guard_page_start(vma, addr) ||
91795- stack_guard_page_end(vma, addr+PAGE_SIZE);
91796-}
91797-
91798 /**
91799 * __get_user_pages() - pin user pages in memory
91800 * @tsk: task_struct of target task
91801@@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91802
91803 i = 0;
91804
91805- do {
91806+ while (nr_pages) {
91807 struct vm_area_struct *vma;
91808
91809- vma = find_extend_vma(mm, start);
91810+ vma = find_vma(mm, start);
91811 if (!vma && in_gate_area(mm, start)) {
91812 unsigned long pg = start & PAGE_MASK;
91813 pgd_t *pgd;
91814@@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91815 goto next_page;
91816 }
91817
91818- if (!vma ||
91819+ if (!vma || start < vma->vm_start ||
91820 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
91821 !(vm_flags & vma->vm_flags))
91822 return i ? : -EFAULT;
91823@@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
91824 int ret;
91825 unsigned int fault_flags = 0;
91826
91827- /* For mlock, just skip the stack guard page. */
91828- if (foll_flags & FOLL_MLOCK) {
91829- if (stack_guard_page(vma, start))
91830- goto next_page;
91831- }
91832 if (foll_flags & FOLL_WRITE)
91833 fault_flags |= FAULT_FLAG_WRITE;
91834 if (nonblocking)
91835@@ -1892,7 +1887,7 @@ next_page:
91836 start += page_increm * PAGE_SIZE;
91837 nr_pages -= page_increm;
91838 } while (nr_pages && start < vma->vm_end);
91839- } while (nr_pages);
91840+ }
91841 return i;
91842 }
91843 EXPORT_SYMBOL(__get_user_pages);
91844@@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
91845 page_add_file_rmap(page);
91846 set_pte_at(mm, addr, pte, mk_pte(page, prot));
91847
91848+#ifdef CONFIG_PAX_SEGMEXEC
91849+ pax_mirror_file_pte(vma, addr, page, ptl);
91850+#endif
91851+
91852 retval = 0;
91853 pte_unmap_unlock(pte, ptl);
91854 return retval;
91855@@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
91856 if (!page_count(page))
91857 return -EINVAL;
91858 if (!(vma->vm_flags & VM_MIXEDMAP)) {
91859+
91860+#ifdef CONFIG_PAX_SEGMEXEC
91861+ struct vm_area_struct *vma_m;
91862+#endif
91863+
91864 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
91865 BUG_ON(vma->vm_flags & VM_PFNMAP);
91866 vma->vm_flags |= VM_MIXEDMAP;
91867+
91868+#ifdef CONFIG_PAX_SEGMEXEC
91869+ vma_m = pax_find_mirror_vma(vma);
91870+ if (vma_m)
91871+ vma_m->vm_flags |= VM_MIXEDMAP;
91872+#endif
91873+
91874 }
91875 return insert_page(vma, addr, page, vma->vm_page_prot);
91876 }
91877@@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
91878 unsigned long pfn)
91879 {
91880 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
91881+ BUG_ON(vma->vm_mirror);
91882
91883 if (addr < vma->vm_start || addr >= vma->vm_end)
91884 return -EFAULT;
91885@@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
91886
91887 BUG_ON(pud_huge(*pud));
91888
91889- pmd = pmd_alloc(mm, pud, addr);
91890+ pmd = (mm == &init_mm) ?
91891+ pmd_alloc_kernel(mm, pud, addr) :
91892+ pmd_alloc(mm, pud, addr);
91893 if (!pmd)
91894 return -ENOMEM;
91895 do {
91896@@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
91897 unsigned long next;
91898 int err;
91899
91900- pud = pud_alloc(mm, pgd, addr);
91901+ pud = (mm == &init_mm) ?
91902+ pud_alloc_kernel(mm, pgd, addr) :
91903+ pud_alloc(mm, pgd, addr);
91904 if (!pud)
91905 return -ENOMEM;
91906 do {
91907@@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
91908 copy_user_highpage(dst, src, va, vma);
91909 }
91910
91911+#ifdef CONFIG_PAX_SEGMEXEC
91912+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
91913+{
91914+ struct mm_struct *mm = vma->vm_mm;
91915+ spinlock_t *ptl;
91916+ pte_t *pte, entry;
91917+
91918+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
91919+ entry = *pte;
91920+ if (!pte_present(entry)) {
91921+ if (!pte_none(entry)) {
91922+ BUG_ON(pte_file(entry));
91923+ free_swap_and_cache(pte_to_swp_entry(entry));
91924+ pte_clear_not_present_full(mm, address, pte, 0);
91925+ }
91926+ } else {
91927+ struct page *page;
91928+
91929+ flush_cache_page(vma, address, pte_pfn(entry));
91930+ entry = ptep_clear_flush(vma, address, pte);
91931+ BUG_ON(pte_dirty(entry));
91932+ page = vm_normal_page(vma, address, entry);
91933+ if (page) {
91934+ update_hiwater_rss(mm);
91935+ if (PageAnon(page))
91936+ dec_mm_counter_fast(mm, MM_ANONPAGES);
91937+ else
91938+ dec_mm_counter_fast(mm, MM_FILEPAGES);
91939+ page_remove_rmap(page);
91940+ page_cache_release(page);
91941+ }
91942+ }
91943+ pte_unmap_unlock(pte, ptl);
91944+}
91945+
91946+/* PaX: if vma is mirrored, synchronize the mirror's PTE
91947+ *
91948+ * the ptl of the lower mapped page is held on entry and is not released on exit
91949+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
91950+ */
91951+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91952+{
91953+ struct mm_struct *mm = vma->vm_mm;
91954+ unsigned long address_m;
91955+ spinlock_t *ptl_m;
91956+ struct vm_area_struct *vma_m;
91957+ pmd_t *pmd_m;
91958+ pte_t *pte_m, entry_m;
91959+
91960+ BUG_ON(!page_m || !PageAnon(page_m));
91961+
91962+ vma_m = pax_find_mirror_vma(vma);
91963+ if (!vma_m)
91964+ return;
91965+
91966+ BUG_ON(!PageLocked(page_m));
91967+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91968+ address_m = address + SEGMEXEC_TASK_SIZE;
91969+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91970+ pte_m = pte_offset_map(pmd_m, address_m);
91971+ ptl_m = pte_lockptr(mm, pmd_m);
91972+ if (ptl != ptl_m) {
91973+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91974+ if (!pte_none(*pte_m))
91975+ goto out;
91976+ }
91977+
91978+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
91979+ page_cache_get(page_m);
91980+ page_add_anon_rmap(page_m, vma_m, address_m);
91981+ inc_mm_counter_fast(mm, MM_ANONPAGES);
91982+ set_pte_at(mm, address_m, pte_m, entry_m);
91983+ update_mmu_cache(vma_m, address_m, pte_m);
91984+out:
91985+ if (ptl != ptl_m)
91986+ spin_unlock(ptl_m);
91987+ pte_unmap(pte_m);
91988+ unlock_page(page_m);
91989+}
91990+
91991+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
91992+{
91993+ struct mm_struct *mm = vma->vm_mm;
91994+ unsigned long address_m;
91995+ spinlock_t *ptl_m;
91996+ struct vm_area_struct *vma_m;
91997+ pmd_t *pmd_m;
91998+ pte_t *pte_m, entry_m;
91999+
92000+ BUG_ON(!page_m || PageAnon(page_m));
92001+
92002+ vma_m = pax_find_mirror_vma(vma);
92003+ if (!vma_m)
92004+ return;
92005+
92006+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92007+ address_m = address + SEGMEXEC_TASK_SIZE;
92008+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92009+ pte_m = pte_offset_map(pmd_m, address_m);
92010+ ptl_m = pte_lockptr(mm, pmd_m);
92011+ if (ptl != ptl_m) {
92012+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92013+ if (!pte_none(*pte_m))
92014+ goto out;
92015+ }
92016+
92017+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
92018+ page_cache_get(page_m);
92019+ page_add_file_rmap(page_m);
92020+ inc_mm_counter_fast(mm, MM_FILEPAGES);
92021+ set_pte_at(mm, address_m, pte_m, entry_m);
92022+ update_mmu_cache(vma_m, address_m, pte_m);
92023+out:
92024+ if (ptl != ptl_m)
92025+ spin_unlock(ptl_m);
92026+ pte_unmap(pte_m);
92027+}
92028+
92029+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
92030+{
92031+ struct mm_struct *mm = vma->vm_mm;
92032+ unsigned long address_m;
92033+ spinlock_t *ptl_m;
92034+ struct vm_area_struct *vma_m;
92035+ pmd_t *pmd_m;
92036+ pte_t *pte_m, entry_m;
92037+
92038+ vma_m = pax_find_mirror_vma(vma);
92039+ if (!vma_m)
92040+ return;
92041+
92042+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92043+ address_m = address + SEGMEXEC_TASK_SIZE;
92044+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
92045+ pte_m = pte_offset_map(pmd_m, address_m);
92046+ ptl_m = pte_lockptr(mm, pmd_m);
92047+ if (ptl != ptl_m) {
92048+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
92049+ if (!pte_none(*pte_m))
92050+ goto out;
92051+ }
92052+
92053+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
92054+ set_pte_at(mm, address_m, pte_m, entry_m);
92055+out:
92056+ if (ptl != ptl_m)
92057+ spin_unlock(ptl_m);
92058+ pte_unmap(pte_m);
92059+}
92060+
92061+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
92062+{
92063+ struct page *page_m;
92064+ pte_t entry;
92065+
92066+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
92067+ goto out;
92068+
92069+ entry = *pte;
92070+ page_m = vm_normal_page(vma, address, entry);
92071+ if (!page_m)
92072+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
92073+ else if (PageAnon(page_m)) {
92074+ if (pax_find_mirror_vma(vma)) {
92075+ pte_unmap_unlock(pte, ptl);
92076+ lock_page(page_m);
92077+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
92078+ if (pte_same(entry, *pte))
92079+ pax_mirror_anon_pte(vma, address, page_m, ptl);
92080+ else
92081+ unlock_page(page_m);
92082+ }
92083+ } else
92084+ pax_mirror_file_pte(vma, address, page_m, ptl);
92085+
92086+out:
92087+ pte_unmap_unlock(pte, ptl);
92088+}
92089+#endif
92090+
92091 /*
92092 * This routine handles present pages, when users try to write
92093 * to a shared page. It is done by copying the page to a new address
92094@@ -2807,6 +3003,12 @@ gotten:
92095 */
92096 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92097 if (likely(pte_same(*page_table, orig_pte))) {
92098+
92099+#ifdef CONFIG_PAX_SEGMEXEC
92100+ if (pax_find_mirror_vma(vma))
92101+ BUG_ON(!trylock_page(new_page));
92102+#endif
92103+
92104 if (old_page) {
92105 if (!PageAnon(old_page)) {
92106 dec_mm_counter_fast(mm, MM_FILEPAGES);
92107@@ -2858,6 +3060,10 @@ gotten:
92108 page_remove_rmap(old_page);
92109 }
92110
92111+#ifdef CONFIG_PAX_SEGMEXEC
92112+ pax_mirror_anon_pte(vma, address, new_page, ptl);
92113+#endif
92114+
92115 /* Free the old page.. */
92116 new_page = old_page;
92117 ret |= VM_FAULT_WRITE;
92118@@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92119 swap_free(entry);
92120 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
92121 try_to_free_swap(page);
92122+
92123+#ifdef CONFIG_PAX_SEGMEXEC
92124+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
92125+#endif
92126+
92127 unlock_page(page);
92128 if (page != swapcache) {
92129 /*
92130@@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
92131
92132 /* No need to invalidate - it was non-present before */
92133 update_mmu_cache(vma, address, page_table);
92134+
92135+#ifdef CONFIG_PAX_SEGMEXEC
92136+ pax_mirror_anon_pte(vma, address, page, ptl);
92137+#endif
92138+
92139 unlock:
92140 pte_unmap_unlock(page_table, ptl);
92141 out:
92142@@ -3177,40 +3393,6 @@ out_release:
92143 }
92144
92145 /*
92146- * This is like a special single-page "expand_{down|up}wards()",
92147- * except we must first make sure that 'address{-|+}PAGE_SIZE'
92148- * doesn't hit another vma.
92149- */
92150-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
92151-{
92152- address &= PAGE_MASK;
92153- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
92154- struct vm_area_struct *prev = vma->vm_prev;
92155-
92156- /*
92157- * Is there a mapping abutting this one below?
92158- *
92159- * That's only ok if it's the same stack mapping
92160- * that has gotten split..
92161- */
92162- if (prev && prev->vm_end == address)
92163- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
92164-
92165- expand_downwards(vma, address - PAGE_SIZE);
92166- }
92167- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
92168- struct vm_area_struct *next = vma->vm_next;
92169-
92170- /* As VM_GROWSDOWN but s/below/above/ */
92171- if (next && next->vm_start == address + PAGE_SIZE)
92172- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
92173-
92174- expand_upwards(vma, address + PAGE_SIZE);
92175- }
92176- return 0;
92177-}
92178-
92179-/*
92180 * We enter with non-exclusive mmap_sem (to exclude vma changes,
92181 * but allow concurrent faults), and pte mapped but not yet locked.
92182 * We return with mmap_sem still held, but pte unmapped and unlocked.
92183@@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92184 unsigned long address, pte_t *page_table, pmd_t *pmd,
92185 unsigned int flags)
92186 {
92187- struct page *page;
92188+ struct page *page = NULL;
92189 spinlock_t *ptl;
92190 pte_t entry;
92191
92192- pte_unmap(page_table);
92193-
92194- /* Check if we need to add a guard page to the stack */
92195- if (check_stack_guard_page(vma, address) < 0)
92196- return VM_FAULT_SIGBUS;
92197-
92198- /* Use the zero-page for reads */
92199 if (!(flags & FAULT_FLAG_WRITE)) {
92200 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
92201 vma->vm_page_prot));
92202- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
92203+ ptl = pte_lockptr(mm, pmd);
92204+ spin_lock(ptl);
92205 if (!pte_none(*page_table))
92206 goto unlock;
92207 goto setpte;
92208 }
92209
92210 /* Allocate our own private page. */
92211+ pte_unmap(page_table);
92212+
92213 if (unlikely(anon_vma_prepare(vma)))
92214 goto oom;
92215 page = alloc_zeroed_user_highpage_movable(vma, address);
92216@@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
92217 if (!pte_none(*page_table))
92218 goto release;
92219
92220+#ifdef CONFIG_PAX_SEGMEXEC
92221+ if (pax_find_mirror_vma(vma))
92222+ BUG_ON(!trylock_page(page));
92223+#endif
92224+
92225 inc_mm_counter_fast(mm, MM_ANONPAGES);
92226 page_add_new_anon_rmap(page, vma, address);
92227 setpte:
92228@@ -3270,6 +3453,12 @@ setpte:
92229
92230 /* No need to invalidate - it was non-present before */
92231 update_mmu_cache(vma, address, page_table);
92232+
92233+#ifdef CONFIG_PAX_SEGMEXEC
92234+ if (page)
92235+ pax_mirror_anon_pte(vma, address, page, ptl);
92236+#endif
92237+
92238 unlock:
92239 pte_unmap_unlock(page_table, ptl);
92240 return 0;
92241@@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92242 */
92243 /* Only go through if we didn't race with anybody else... */
92244 if (likely(pte_same(*page_table, orig_pte))) {
92245+
92246+#ifdef CONFIG_PAX_SEGMEXEC
92247+ if (anon && pax_find_mirror_vma(vma))
92248+ BUG_ON(!trylock_page(page));
92249+#endif
92250+
92251 flush_icache_page(vma, page);
92252 entry = mk_pte(page, vma->vm_page_prot);
92253 if (flags & FAULT_FLAG_WRITE)
92254@@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92255
92256 /* no need to invalidate: a not-present page won't be cached */
92257 update_mmu_cache(vma, address, page_table);
92258+
92259+#ifdef CONFIG_PAX_SEGMEXEC
92260+ if (anon)
92261+ pax_mirror_anon_pte(vma, address, page, ptl);
92262+ else
92263+ pax_mirror_file_pte(vma, address, page, ptl);
92264+#endif
92265+
92266 } else {
92267 if (cow_page)
92268 mem_cgroup_uncharge_page(cow_page);
92269@@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
92270 if (flags & FAULT_FLAG_WRITE)
92271 flush_tlb_fix_spurious_fault(vma, address);
92272 }
92273+
92274+#ifdef CONFIG_PAX_SEGMEXEC
92275+ pax_mirror_pte(vma, address, pte, pmd, ptl);
92276+ return 0;
92277+#endif
92278+
92279 unlock:
92280 pte_unmap_unlock(pte, ptl);
92281 return 0;
92282@@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92283 pmd_t *pmd;
92284 pte_t *pte;
92285
92286+#ifdef CONFIG_PAX_SEGMEXEC
92287+ struct vm_area_struct *vma_m;
92288+#endif
92289+
92290 if (unlikely(is_vm_hugetlb_page(vma)))
92291 return hugetlb_fault(mm, vma, address, flags);
92292
92293+#ifdef CONFIG_PAX_SEGMEXEC
92294+ vma_m = pax_find_mirror_vma(vma);
92295+ if (vma_m) {
92296+ unsigned long address_m;
92297+ pgd_t *pgd_m;
92298+ pud_t *pud_m;
92299+ pmd_t *pmd_m;
92300+
92301+ if (vma->vm_start > vma_m->vm_start) {
92302+ address_m = address;
92303+ address -= SEGMEXEC_TASK_SIZE;
92304+ vma = vma_m;
92305+ } else
92306+ address_m = address + SEGMEXEC_TASK_SIZE;
92307+
92308+ pgd_m = pgd_offset(mm, address_m);
92309+ pud_m = pud_alloc(mm, pgd_m, address_m);
92310+ if (!pud_m)
92311+ return VM_FAULT_OOM;
92312+ pmd_m = pmd_alloc(mm, pud_m, address_m);
92313+ if (!pmd_m)
92314+ return VM_FAULT_OOM;
92315+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
92316+ return VM_FAULT_OOM;
92317+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
92318+ }
92319+#endif
92320+
92321 pgd = pgd_offset(mm, address);
92322 pud = pud_alloc(mm, pgd, address);
92323 if (!pud)
92324@@ -3830,6 +4071,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92325 spin_unlock(&mm->page_table_lock);
92326 return 0;
92327 }
92328+
92329+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
92330+{
92331+ pud_t *new = pud_alloc_one(mm, address);
92332+ if (!new)
92333+ return -ENOMEM;
92334+
92335+ smp_wmb(); /* See comment in __pte_alloc */
92336+
92337+ spin_lock(&mm->page_table_lock);
92338+ if (pgd_present(*pgd)) /* Another has populated it */
92339+ pud_free(mm, new);
92340+ else
92341+ pgd_populate_kernel(mm, pgd, new);
92342+ spin_unlock(&mm->page_table_lock);
92343+ return 0;
92344+}
92345 #endif /* __PAGETABLE_PUD_FOLDED */
92346
92347 #ifndef __PAGETABLE_PMD_FOLDED
92348@@ -3860,6 +4118,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
92349 spin_unlock(&mm->page_table_lock);
92350 return 0;
92351 }
92352+
92353+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
92354+{
92355+ pmd_t *new = pmd_alloc_one(mm, address);
92356+ if (!new)
92357+ return -ENOMEM;
92358+
92359+ smp_wmb(); /* See comment in __pte_alloc */
92360+
92361+ spin_lock(&mm->page_table_lock);
92362+#ifndef __ARCH_HAS_4LEVEL_HACK
92363+ if (pud_present(*pud)) /* Another has populated it */
92364+ pmd_free(mm, new);
92365+ else
92366+ pud_populate_kernel(mm, pud, new);
92367+#else
92368+ if (pgd_present(*pud)) /* Another has populated it */
92369+ pmd_free(mm, new);
92370+ else
92371+ pgd_populate_kernel(mm, pud, new);
92372+#endif /* __ARCH_HAS_4LEVEL_HACK */
92373+ spin_unlock(&mm->page_table_lock);
92374+ return 0;
92375+}
92376 #endif /* __PAGETABLE_PMD_FOLDED */
92377
92378 #if !defined(__HAVE_ARCH_GATE_AREA)
92379@@ -3873,7 +4155,7 @@ static int __init gate_vma_init(void)
92380 gate_vma.vm_start = FIXADDR_USER_START;
92381 gate_vma.vm_end = FIXADDR_USER_END;
92382 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
92383- gate_vma.vm_page_prot = __P101;
92384+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
92385
92386 return 0;
92387 }
92388@@ -4007,8 +4289,8 @@ out:
92389 return ret;
92390 }
92391
92392-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92393- void *buf, int len, int write)
92394+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
92395+ void *buf, size_t len, int write)
92396 {
92397 resource_size_t phys_addr;
92398 unsigned long prot = 0;
92399@@ -4034,8 +4316,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
92400 * Access another process' address space as given in mm. If non-NULL, use the
92401 * given task for page fault accounting.
92402 */
92403-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92404- unsigned long addr, void *buf, int len, int write)
92405+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92406+ unsigned long addr, void *buf, size_t len, int write)
92407 {
92408 struct vm_area_struct *vma;
92409 void *old_buf = buf;
92410@@ -4043,7 +4325,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92411 down_read(&mm->mmap_sem);
92412 /* ignore errors, just check how much was successfully transferred */
92413 while (len) {
92414- int bytes, ret, offset;
92415+ ssize_t bytes, ret, offset;
92416 void *maddr;
92417 struct page *page = NULL;
92418
92419@@ -4102,8 +4384,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
92420 *
92421 * The caller must hold a reference on @mm.
92422 */
92423-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92424- void *buf, int len, int write)
92425+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
92426+ void *buf, size_t len, int write)
92427 {
92428 return __access_remote_vm(NULL, mm, addr, buf, len, write);
92429 }
92430@@ -4113,11 +4395,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
92431 * Source/target buffer must be kernel space,
92432 * Do not walk the page table directly, use get_user_pages
92433 */
92434-int access_process_vm(struct task_struct *tsk, unsigned long addr,
92435- void *buf, int len, int write)
92436+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
92437+ void *buf, size_t len, int write)
92438 {
92439 struct mm_struct *mm;
92440- int ret;
92441+ ssize_t ret;
92442
92443 mm = get_task_mm(tsk);
92444 if (!mm)
92445diff --git a/mm/mempolicy.c b/mm/mempolicy.c
92446index cb2f3dd..fb80468 100644
92447--- a/mm/mempolicy.c
92448+++ b/mm/mempolicy.c
92449@@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92450 unsigned long vmstart;
92451 unsigned long vmend;
92452
92453+#ifdef CONFIG_PAX_SEGMEXEC
92454+ struct vm_area_struct *vma_m;
92455+#endif
92456+
92457 vma = find_vma(mm, start);
92458 if (!vma || vma->vm_start > start)
92459 return -EFAULT;
92460@@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
92461 err = vma_replace_policy(vma, new_pol);
92462 if (err)
92463 goto out;
92464+
92465+#ifdef CONFIG_PAX_SEGMEXEC
92466+ vma_m = pax_find_mirror_vma(vma);
92467+ if (vma_m) {
92468+ err = vma_replace_policy(vma_m, new_pol);
92469+ if (err)
92470+ goto out;
92471+ }
92472+#endif
92473+
92474 }
92475
92476 out:
92477@@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
92478
92479 if (end < start)
92480 return -EINVAL;
92481+
92482+#ifdef CONFIG_PAX_SEGMEXEC
92483+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92484+ if (end > SEGMEXEC_TASK_SIZE)
92485+ return -EINVAL;
92486+ } else
92487+#endif
92488+
92489+ if (end > TASK_SIZE)
92490+ return -EINVAL;
92491+
92492 if (end == start)
92493 return 0;
92494
92495@@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92496 */
92497 tcred = __task_cred(task);
92498 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92499- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92500- !capable(CAP_SYS_NICE)) {
92501+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92502 rcu_read_unlock();
92503 err = -EPERM;
92504 goto out_put;
92505@@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
92506 goto out;
92507 }
92508
92509+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
92510+ if (mm != current->mm &&
92511+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
92512+ mmput(mm);
92513+ err = -EPERM;
92514+ goto out;
92515+ }
92516+#endif
92517+
92518 err = do_migrate_pages(mm, old, new,
92519 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
92520
92521diff --git a/mm/migrate.c b/mm/migrate.c
92522index 9194375..75c81e2 100644
92523--- a/mm/migrate.c
92524+++ b/mm/migrate.c
92525@@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
92526 */
92527 tcred = __task_cred(task);
92528 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
92529- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
92530- !capable(CAP_SYS_NICE)) {
92531+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
92532 rcu_read_unlock();
92533 err = -EPERM;
92534 goto out;
92535diff --git a/mm/mlock.c b/mm/mlock.c
92536index 192e6ee..b044449 100644
92537--- a/mm/mlock.c
92538+++ b/mm/mlock.c
92539@@ -14,6 +14,7 @@
92540 #include <linux/pagevec.h>
92541 #include <linux/mempolicy.h>
92542 #include <linux/syscalls.h>
92543+#include <linux/security.h>
92544 #include <linux/sched.h>
92545 #include <linux/export.h>
92546 #include <linux/rmap.h>
92547@@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
92548 {
92549 unsigned long nstart, end, tmp;
92550 struct vm_area_struct * vma, * prev;
92551- int error;
92552+ int error = 0;
92553
92554 VM_BUG_ON(start & ~PAGE_MASK);
92555 VM_BUG_ON(len != PAGE_ALIGN(len));
92556@@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
92557 return -EINVAL;
92558 if (end == start)
92559 return 0;
92560+ if (end > TASK_SIZE)
92561+ return -EINVAL;
92562+
92563 vma = find_vma(current->mm, start);
92564 if (!vma || vma->vm_start > start)
92565 return -ENOMEM;
92566@@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
92567 for (nstart = start ; ; ) {
92568 vm_flags_t newflags;
92569
92570+#ifdef CONFIG_PAX_SEGMEXEC
92571+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92572+ break;
92573+#endif
92574+
92575 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
92576
92577 newflags = vma->vm_flags & ~VM_LOCKED;
92578@@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
92579 lock_limit >>= PAGE_SHIFT;
92580
92581 /* check against resource limits */
92582+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
92583 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
92584 error = do_mlock(start, len, 1);
92585 up_write(&current->mm->mmap_sem);
92586@@ -754,6 +764,11 @@ static int do_mlockall(int flags)
92587 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
92588 vm_flags_t newflags;
92589
92590+#ifdef CONFIG_PAX_SEGMEXEC
92591+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
92592+ break;
92593+#endif
92594+
92595 newflags = vma->vm_flags & ~VM_LOCKED;
92596 if (flags & MCL_CURRENT)
92597 newflags |= VM_LOCKED;
92598@@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
92599 lock_limit >>= PAGE_SHIFT;
92600
92601 ret = -ENOMEM;
92602+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
92603 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
92604 capable(CAP_IPC_LOCK))
92605 ret = do_mlockall(flags);
92606diff --git a/mm/mmap.c b/mm/mmap.c
92607index 546db74..650d1b9 100644
92608--- a/mm/mmap.c
92609+++ b/mm/mmap.c
92610@@ -36,6 +36,7 @@
92611 #include <linux/sched/sysctl.h>
92612 #include <linux/notifier.h>
92613 #include <linux/memory.h>
92614+#include <linux/random.h>
92615
92616 #include <asm/uaccess.h>
92617 #include <asm/cacheflush.h>
92618@@ -52,6 +53,16 @@
92619 #define arch_rebalance_pgtables(addr, len) (addr)
92620 #endif
92621
92622+static inline void verify_mm_writelocked(struct mm_struct *mm)
92623+{
92624+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
92625+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92626+ up_read(&mm->mmap_sem);
92627+ BUG();
92628+ }
92629+#endif
92630+}
92631+
92632 static void unmap_region(struct mm_struct *mm,
92633 struct vm_area_struct *vma, struct vm_area_struct *prev,
92634 unsigned long start, unsigned long end);
92635@@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
92636 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
92637 *
92638 */
92639-pgprot_t protection_map[16] = {
92640+pgprot_t protection_map[16] __read_only = {
92641 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
92642 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
92643 };
92644
92645-pgprot_t vm_get_page_prot(unsigned long vm_flags)
92646+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
92647 {
92648- return __pgprot(pgprot_val(protection_map[vm_flags &
92649+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
92650 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
92651 pgprot_val(arch_vm_get_page_prot(vm_flags)));
92652+
92653+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92654+ if (!(__supported_pte_mask & _PAGE_NX) &&
92655+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
92656+ (vm_flags & (VM_READ | VM_WRITE)))
92657+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
92658+#endif
92659+
92660+ return prot;
92661 }
92662 EXPORT_SYMBOL(vm_get_page_prot);
92663
92664@@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
92665 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
92666 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
92667 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
92668+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
92669 /*
92670 * Make sure vm_committed_as in one cacheline and not cacheline shared with
92671 * other variables. It can be updated by several CPUs frequently.
92672@@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
92673 struct vm_area_struct *next = vma->vm_next;
92674
92675 might_sleep();
92676+ BUG_ON(vma->vm_mirror);
92677 if (vma->vm_ops && vma->vm_ops->close)
92678 vma->vm_ops->close(vma);
92679 if (vma->vm_file)
92680@@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
92681 * not page aligned -Ram Gupta
92682 */
92683 rlim = rlimit(RLIMIT_DATA);
92684+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
92685 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
92686 (mm->end_data - mm->start_data) > rlim)
92687 goto out;
92688@@ -939,6 +962,12 @@ static int
92689 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
92690 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92691 {
92692+
92693+#ifdef CONFIG_PAX_SEGMEXEC
92694+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
92695+ return 0;
92696+#endif
92697+
92698 if (is_mergeable_vma(vma, file, vm_flags) &&
92699 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92700 if (vma->vm_pgoff == vm_pgoff)
92701@@ -958,6 +987,12 @@ static int
92702 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92703 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
92704 {
92705+
92706+#ifdef CONFIG_PAX_SEGMEXEC
92707+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
92708+ return 0;
92709+#endif
92710+
92711 if (is_mergeable_vma(vma, file, vm_flags) &&
92712 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
92713 pgoff_t vm_pglen;
92714@@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
92715 struct vm_area_struct *vma_merge(struct mm_struct *mm,
92716 struct vm_area_struct *prev, unsigned long addr,
92717 unsigned long end, unsigned long vm_flags,
92718- struct anon_vma *anon_vma, struct file *file,
92719+ struct anon_vma *anon_vma, struct file *file,
92720 pgoff_t pgoff, struct mempolicy *policy)
92721 {
92722 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
92723 struct vm_area_struct *area, *next;
92724 int err;
92725
92726+#ifdef CONFIG_PAX_SEGMEXEC
92727+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
92728+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
92729+
92730+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
92731+#endif
92732+
92733 /*
92734 * We later require that vma->vm_flags == vm_flags,
92735 * so this tests vma->vm_flags & VM_SPECIAL, too.
92736@@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92737 if (next && next->vm_end == end) /* cases 6, 7, 8 */
92738 next = next->vm_next;
92739
92740+#ifdef CONFIG_PAX_SEGMEXEC
92741+ if (prev)
92742+ prev_m = pax_find_mirror_vma(prev);
92743+ if (area)
92744+ area_m = pax_find_mirror_vma(area);
92745+ if (next)
92746+ next_m = pax_find_mirror_vma(next);
92747+#endif
92748+
92749 /*
92750 * Can it merge with the predecessor?
92751 */
92752@@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92753 /* cases 1, 6 */
92754 err = vma_adjust(prev, prev->vm_start,
92755 next->vm_end, prev->vm_pgoff, NULL);
92756- } else /* cases 2, 5, 7 */
92757+
92758+#ifdef CONFIG_PAX_SEGMEXEC
92759+ if (!err && prev_m)
92760+ err = vma_adjust(prev_m, prev_m->vm_start,
92761+ next_m->vm_end, prev_m->vm_pgoff, NULL);
92762+#endif
92763+
92764+ } else { /* cases 2, 5, 7 */
92765 err = vma_adjust(prev, prev->vm_start,
92766 end, prev->vm_pgoff, NULL);
92767+
92768+#ifdef CONFIG_PAX_SEGMEXEC
92769+ if (!err && prev_m)
92770+ err = vma_adjust(prev_m, prev_m->vm_start,
92771+ end_m, prev_m->vm_pgoff, NULL);
92772+#endif
92773+
92774+ }
92775 if (err)
92776 return NULL;
92777 khugepaged_enter_vma_merge(prev);
92778@@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
92779 mpol_equal(policy, vma_policy(next)) &&
92780 can_vma_merge_before(next, vm_flags,
92781 anon_vma, file, pgoff+pglen)) {
92782- if (prev && addr < prev->vm_end) /* case 4 */
92783+ if (prev && addr < prev->vm_end) { /* case 4 */
92784 err = vma_adjust(prev, prev->vm_start,
92785 addr, prev->vm_pgoff, NULL);
92786- else /* cases 3, 8 */
92787+
92788+#ifdef CONFIG_PAX_SEGMEXEC
92789+ if (!err && prev_m)
92790+ err = vma_adjust(prev_m, prev_m->vm_start,
92791+ addr_m, prev_m->vm_pgoff, NULL);
92792+#endif
92793+
92794+ } else { /* cases 3, 8 */
92795 err = vma_adjust(area, addr, next->vm_end,
92796 next->vm_pgoff - pglen, NULL);
92797+
92798+#ifdef CONFIG_PAX_SEGMEXEC
92799+ if (!err && area_m)
92800+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
92801+ next_m->vm_pgoff - pglen, NULL);
92802+#endif
92803+
92804+ }
92805 if (err)
92806 return NULL;
92807 khugepaged_enter_vma_merge(area);
92808@@ -1171,8 +1252,10 @@ none:
92809 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92810 struct file *file, long pages)
92811 {
92812- const unsigned long stack_flags
92813- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
92814+
92815+#ifdef CONFIG_PAX_RANDMMAP
92816+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92817+#endif
92818
92819 mm->total_vm += pages;
92820
92821@@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
92822 mm->shared_vm += pages;
92823 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
92824 mm->exec_vm += pages;
92825- } else if (flags & stack_flags)
92826+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
92827 mm->stack_vm += pages;
92828 }
92829 #endif /* CONFIG_PROC_FS */
92830@@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92831 * (the exception is when the underlying filesystem is noexec
92832 * mounted, in which case we dont add PROT_EXEC.)
92833 */
92834- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
92835+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
92836 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
92837 prot |= PROT_EXEC;
92838
92839@@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92840 /* Obtain the address to map to. we verify (or select) it and ensure
92841 * that it represents a valid section of the address space.
92842 */
92843- addr = get_unmapped_area(file, addr, len, pgoff, flags);
92844+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
92845 if (addr & ~PAGE_MASK)
92846 return addr;
92847
92848@@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92849 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
92850 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
92851
92852+#ifdef CONFIG_PAX_MPROTECT
92853+ if (mm->pax_flags & MF_PAX_MPROTECT) {
92854+
92855+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
92856+ if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
92857+ mm->binfmt->handle_mmap)
92858+ mm->binfmt->handle_mmap(file);
92859+#endif
92860+
92861+#ifndef CONFIG_PAX_MPROTECT_COMPAT
92862+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
92863+ gr_log_rwxmmap(file);
92864+
92865+#ifdef CONFIG_PAX_EMUPLT
92866+ vm_flags &= ~VM_EXEC;
92867+#else
92868+ return -EPERM;
92869+#endif
92870+
92871+ }
92872+
92873+ if (!(vm_flags & VM_EXEC))
92874+ vm_flags &= ~VM_MAYEXEC;
92875+#else
92876+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92877+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92878+#endif
92879+ else
92880+ vm_flags &= ~VM_MAYWRITE;
92881+ }
92882+#endif
92883+
92884+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92885+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
92886+ vm_flags &= ~VM_PAGEEXEC;
92887+#endif
92888+
92889 if (flags & MAP_LOCKED)
92890 if (!can_do_mlock())
92891 return -EPERM;
92892@@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92893 locked += mm->locked_vm;
92894 lock_limit = rlimit(RLIMIT_MEMLOCK);
92895 lock_limit >>= PAGE_SHIFT;
92896+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92897 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
92898 return -EAGAIN;
92899 }
92900@@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
92901 vm_flags |= VM_NORESERVE;
92902 }
92903
92904+ if (!gr_acl_handle_mmap(file, prot))
92905+ return -EACCES;
92906+
92907 addr = mmap_region(file, addr, len, vm_flags, pgoff);
92908 if (!IS_ERR_VALUE(addr) &&
92909 ((vm_flags & VM_LOCKED) ||
92910@@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
92911 vm_flags_t vm_flags = vma->vm_flags;
92912
92913 /* If it was private or non-writable, the write bit is already clear */
92914- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
92915+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
92916 return 0;
92917
92918 /* The backer wishes to know when pages are first written to? */
92919@@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92920 struct rb_node **rb_link, *rb_parent;
92921 unsigned long charged = 0;
92922
92923+#ifdef CONFIG_PAX_SEGMEXEC
92924+ struct vm_area_struct *vma_m = NULL;
92925+#endif
92926+
92927+ /*
92928+ * mm->mmap_sem is required to protect against another thread
92929+ * changing the mappings in case we sleep.
92930+ */
92931+ verify_mm_writelocked(mm);
92932+
92933 /* Check against address space limit. */
92934+
92935+#ifdef CONFIG_PAX_RANDMMAP
92936+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
92937+#endif
92938+
92939 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
92940 unsigned long nr_pages;
92941
92942@@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
92943
92944 /* Clear old maps */
92945 error = -ENOMEM;
92946-munmap_back:
92947 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92948 if (do_munmap(mm, addr, len))
92949 return -ENOMEM;
92950- goto munmap_back;
92951+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92952 }
92953
92954 /*
92955@@ -1543,6 +1681,16 @@ munmap_back:
92956 goto unacct_error;
92957 }
92958
92959+#ifdef CONFIG_PAX_SEGMEXEC
92960+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
92961+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92962+ if (!vma_m) {
92963+ error = -ENOMEM;
92964+ goto free_vma;
92965+ }
92966+ }
92967+#endif
92968+
92969 vma->vm_mm = mm;
92970 vma->vm_start = addr;
92971 vma->vm_end = addr + len;
92972@@ -1562,6 +1710,13 @@ munmap_back:
92973 if (error)
92974 goto unmap_and_free_vma;
92975
92976+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
92977+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
92978+ vma->vm_flags |= VM_PAGEEXEC;
92979+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92980+ }
92981+#endif
92982+
92983 /* Can addr have changed??
92984 *
92985 * Answer: Yes, several device drivers can do it in their
92986@@ -1595,6 +1750,12 @@ munmap_back:
92987 }
92988
92989 vma_link(mm, vma, prev, rb_link, rb_parent);
92990+
92991+#ifdef CONFIG_PAX_SEGMEXEC
92992+ if (vma_m)
92993+ BUG_ON(pax_mirror_vma(vma_m, vma));
92994+#endif
92995+
92996 /* Once vma denies write, undo our temporary denial count */
92997 if (vm_flags & VM_DENYWRITE)
92998 allow_write_access(file);
92999@@ -1603,6 +1764,7 @@ out:
93000 perf_event_mmap(vma);
93001
93002 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
93003+ track_exec_limit(mm, addr, addr + len, vm_flags);
93004 if (vm_flags & VM_LOCKED) {
93005 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
93006 vma == get_gate_vma(current->mm)))
93007@@ -1635,6 +1797,12 @@ unmap_and_free_vma:
93008 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
93009 charged = 0;
93010 free_vma:
93011+
93012+#ifdef CONFIG_PAX_SEGMEXEC
93013+ if (vma_m)
93014+ kmem_cache_free(vm_area_cachep, vma_m);
93015+#endif
93016+
93017 kmem_cache_free(vm_area_cachep, vma);
93018 unacct_error:
93019 if (charged)
93020@@ -1642,7 +1810,63 @@ unacct_error:
93021 return error;
93022 }
93023
93024-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93025+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
93026+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
93027+{
93028+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
93029+ return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
93030+
93031+ return 0;
93032+}
93033+#endif
93034+
93035+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
93036+{
93037+ if (!vma) {
93038+#ifdef CONFIG_STACK_GROWSUP
93039+ if (addr > sysctl_heap_stack_gap)
93040+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
93041+ else
93042+ vma = find_vma(current->mm, 0);
93043+ if (vma && (vma->vm_flags & VM_GROWSUP))
93044+ return false;
93045+#endif
93046+ return true;
93047+ }
93048+
93049+ if (addr + len > vma->vm_start)
93050+ return false;
93051+
93052+ if (vma->vm_flags & VM_GROWSDOWN)
93053+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
93054+#ifdef CONFIG_STACK_GROWSUP
93055+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
93056+ return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
93057+#endif
93058+ else if (offset)
93059+ return offset <= vma->vm_start - addr - len;
93060+
93061+ return true;
93062+}
93063+
93064+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
93065+{
93066+ if (vma->vm_start < len)
93067+ return -ENOMEM;
93068+
93069+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
93070+ if (offset <= vma->vm_start - len)
93071+ return vma->vm_start - len - offset;
93072+ else
93073+ return -ENOMEM;
93074+ }
93075+
93076+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
93077+ return vma->vm_start - len - sysctl_heap_stack_gap;
93078+ return -ENOMEM;
93079+}
93080+
93081+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
93082 {
93083 /*
93084 * We implement the search by looking for an rbtree node that
93085@@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
93086 }
93087 }
93088
93089- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
93090+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
93091 check_current:
93092 /* Check if current node has a suitable gap */
93093 if (gap_start > high_limit)
93094 return -ENOMEM;
93095+
93096+ if (gap_end - gap_start > info->threadstack_offset)
93097+ gap_start += info->threadstack_offset;
93098+ else
93099+ gap_start = gap_end;
93100+
93101+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93102+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93103+ gap_start += sysctl_heap_stack_gap;
93104+ else
93105+ gap_start = gap_end;
93106+ }
93107+ if (vma->vm_flags & VM_GROWSDOWN) {
93108+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93109+ gap_end -= sysctl_heap_stack_gap;
93110+ else
93111+ gap_end = gap_start;
93112+ }
93113 if (gap_end >= low_limit && gap_end - gap_start >= length)
93114 goto found;
93115
93116@@ -1744,7 +1986,7 @@ found:
93117 return gap_start;
93118 }
93119
93120-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
93121+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
93122 {
93123 struct mm_struct *mm = current->mm;
93124 struct vm_area_struct *vma;
93125@@ -1798,6 +2040,24 @@ check_current:
93126 gap_end = vma->vm_start;
93127 if (gap_end < low_limit)
93128 return -ENOMEM;
93129+
93130+ if (gap_end - gap_start > info->threadstack_offset)
93131+ gap_end -= info->threadstack_offset;
93132+ else
93133+ gap_end = gap_start;
93134+
93135+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
93136+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93137+ gap_start += sysctl_heap_stack_gap;
93138+ else
93139+ gap_start = gap_end;
93140+ }
93141+ if (vma->vm_flags & VM_GROWSDOWN) {
93142+ if (gap_end - gap_start > sysctl_heap_stack_gap)
93143+ gap_end -= sysctl_heap_stack_gap;
93144+ else
93145+ gap_end = gap_start;
93146+ }
93147 if (gap_start <= high_limit && gap_end - gap_start >= length)
93148 goto found;
93149
93150@@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93151 struct mm_struct *mm = current->mm;
93152 struct vm_area_struct *vma;
93153 struct vm_unmapped_area_info info;
93154+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93155
93156 if (len > TASK_SIZE - mmap_min_addr)
93157 return -ENOMEM;
93158@@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93159 if (flags & MAP_FIXED)
93160 return addr;
93161
93162+#ifdef CONFIG_PAX_RANDMMAP
93163+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93164+#endif
93165+
93166 if (addr) {
93167 addr = PAGE_ALIGN(addr);
93168 vma = find_vma(mm, addr);
93169 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93170- (!vma || addr + len <= vma->vm_start))
93171+ check_heap_stack_gap(vma, addr, len, offset))
93172 return addr;
93173 }
93174
93175@@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
93176 info.low_limit = mm->mmap_base;
93177 info.high_limit = TASK_SIZE;
93178 info.align_mask = 0;
93179+ info.threadstack_offset = offset;
93180 return vm_unmapped_area(&info);
93181 }
93182 #endif
93183@@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93184 struct mm_struct *mm = current->mm;
93185 unsigned long addr = addr0;
93186 struct vm_unmapped_area_info info;
93187+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
93188
93189 /* requested length too big for entire address space */
93190 if (len > TASK_SIZE - mmap_min_addr)
93191@@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93192 if (flags & MAP_FIXED)
93193 return addr;
93194
93195+#ifdef CONFIG_PAX_RANDMMAP
93196+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
93197+#endif
93198+
93199 /* requesting a specific address */
93200 if (addr) {
93201 addr = PAGE_ALIGN(addr);
93202 vma = find_vma(mm, addr);
93203 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
93204- (!vma || addr + len <= vma->vm_start))
93205+ check_heap_stack_gap(vma, addr, len, offset))
93206 return addr;
93207 }
93208
93209@@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93210 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
93211 info.high_limit = mm->mmap_base;
93212 info.align_mask = 0;
93213+ info.threadstack_offset = offset;
93214 addr = vm_unmapped_area(&info);
93215
93216 /*
93217@@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
93218 VM_BUG_ON(addr != -ENOMEM);
93219 info.flags = 0;
93220 info.low_limit = TASK_UNMAPPED_BASE;
93221+
93222+#ifdef CONFIG_PAX_RANDMMAP
93223+ if (mm->pax_flags & MF_PAX_RANDMMAP)
93224+ info.low_limit += mm->delta_mmap;
93225+#endif
93226+
93227 info.high_limit = TASK_SIZE;
93228 addr = vm_unmapped_area(&info);
93229 }
93230@@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
93231 return vma;
93232 }
93233
93234+#ifdef CONFIG_PAX_SEGMEXEC
93235+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
93236+{
93237+ struct vm_area_struct *vma_m;
93238+
93239+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
93240+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
93241+ BUG_ON(vma->vm_mirror);
93242+ return NULL;
93243+ }
93244+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
93245+ vma_m = vma->vm_mirror;
93246+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
93247+ BUG_ON(vma->vm_file != vma_m->vm_file);
93248+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
93249+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
93250+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
93251+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
93252+ return vma_m;
93253+}
93254+#endif
93255+
93256 /*
93257 * Verify that the stack growth is acceptable and
93258 * update accounting. This is shared with both the
93259@@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93260 return -ENOMEM;
93261
93262 /* Stack limit test */
93263+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
93264 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
93265 return -ENOMEM;
93266
93267@@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93268 locked = mm->locked_vm + grow;
93269 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
93270 limit >>= PAGE_SHIFT;
93271+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
93272 if (locked > limit && !capable(CAP_IPC_LOCK))
93273 return -ENOMEM;
93274 }
93275@@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
93276 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
93277 * vma is the last one with address > vma->vm_end. Have to extend vma.
93278 */
93279+#ifndef CONFIG_IA64
93280+static
93281+#endif
93282 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93283 {
93284 int error;
93285+ bool locknext;
93286
93287 if (!(vma->vm_flags & VM_GROWSUP))
93288 return -EFAULT;
93289
93290+ /* Also guard against wrapping around to address 0. */
93291+ if (address < PAGE_ALIGN(address+1))
93292+ address = PAGE_ALIGN(address+1);
93293+ else
93294+ return -ENOMEM;
93295+
93296 /*
93297 * We must make sure the anon_vma is allocated
93298 * so that the anon_vma locking is not a noop.
93299 */
93300 if (unlikely(anon_vma_prepare(vma)))
93301 return -ENOMEM;
93302+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
93303+ if (locknext && anon_vma_prepare(vma->vm_next))
93304+ return -ENOMEM;
93305 vma_lock_anon_vma(vma);
93306+ if (locknext)
93307+ vma_lock_anon_vma(vma->vm_next);
93308
93309 /*
93310 * vma->vm_start/vm_end cannot change under us because the caller
93311 * is required to hold the mmap_sem in read mode. We need the
93312- * anon_vma lock to serialize against concurrent expand_stacks.
93313- * Also guard against wrapping around to address 0.
93314+ * anon_vma locks to serialize against concurrent expand_stacks
93315+ * and expand_upwards.
93316 */
93317- if (address < PAGE_ALIGN(address+4))
93318- address = PAGE_ALIGN(address+4);
93319- else {
93320- vma_unlock_anon_vma(vma);
93321- return -ENOMEM;
93322- }
93323 error = 0;
93324
93325 /* Somebody else might have raced and expanded it already */
93326- if (address > vma->vm_end) {
93327+ 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)
93328+ error = -ENOMEM;
93329+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
93330 unsigned long size, grow;
93331
93332 size = address - vma->vm_start;
93333@@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
93334 }
93335 }
93336 }
93337+ if (locknext)
93338+ vma_unlock_anon_vma(vma->vm_next);
93339 vma_unlock_anon_vma(vma);
93340 khugepaged_enter_vma_merge(vma);
93341 validate_mm(vma->vm_mm);
93342@@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
93343 unsigned long address)
93344 {
93345 int error;
93346+ bool lockprev = false;
93347+ struct vm_area_struct *prev;
93348
93349 /*
93350 * We must make sure the anon_vma is allocated
93351@@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
93352 if (error)
93353 return error;
93354
93355+ prev = vma->vm_prev;
93356+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
93357+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
93358+#endif
93359+ if (lockprev && anon_vma_prepare(prev))
93360+ return -ENOMEM;
93361+ if (lockprev)
93362+ vma_lock_anon_vma(prev);
93363+
93364 vma_lock_anon_vma(vma);
93365
93366 /*
93367@@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
93368 */
93369
93370 /* Somebody else might have raced and expanded it already */
93371- if (address < vma->vm_start) {
93372+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
93373+ error = -ENOMEM;
93374+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
93375 unsigned long size, grow;
93376
93377+#ifdef CONFIG_PAX_SEGMEXEC
93378+ struct vm_area_struct *vma_m;
93379+
93380+ vma_m = pax_find_mirror_vma(vma);
93381+#endif
93382+
93383 size = vma->vm_end - address;
93384 grow = (vma->vm_start - address) >> PAGE_SHIFT;
93385
93386@@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
93387 vma->vm_pgoff -= grow;
93388 anon_vma_interval_tree_post_update_vma(vma);
93389 vma_gap_update(vma);
93390+
93391+#ifdef CONFIG_PAX_SEGMEXEC
93392+ if (vma_m) {
93393+ anon_vma_interval_tree_pre_update_vma(vma_m);
93394+ vma_m->vm_start -= grow << PAGE_SHIFT;
93395+ vma_m->vm_pgoff -= grow;
93396+ anon_vma_interval_tree_post_update_vma(vma_m);
93397+ vma_gap_update(vma_m);
93398+ }
93399+#endif
93400+
93401 spin_unlock(&vma->vm_mm->page_table_lock);
93402
93403+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
93404 perf_event_mmap(vma);
93405 }
93406 }
93407 }
93408 vma_unlock_anon_vma(vma);
93409+ if (lockprev)
93410+ vma_unlock_anon_vma(prev);
93411 khugepaged_enter_vma_merge(vma);
93412 validate_mm(vma->vm_mm);
93413 return error;
93414@@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
93415 do {
93416 long nrpages = vma_pages(vma);
93417
93418+#ifdef CONFIG_PAX_SEGMEXEC
93419+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
93420+ vma = remove_vma(vma);
93421+ continue;
93422+ }
93423+#endif
93424+
93425 if (vma->vm_flags & VM_ACCOUNT)
93426 nr_accounted += nrpages;
93427 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
93428@@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
93429 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
93430 vma->vm_prev = NULL;
93431 do {
93432+
93433+#ifdef CONFIG_PAX_SEGMEXEC
93434+ if (vma->vm_mirror) {
93435+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
93436+ vma->vm_mirror->vm_mirror = NULL;
93437+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
93438+ vma->vm_mirror = NULL;
93439+ }
93440+#endif
93441+
93442 vma_rb_erase(vma, &mm->mm_rb);
93443 mm->map_count--;
93444 tail_vma = vma;
93445@@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93446 struct vm_area_struct *new;
93447 int err = -ENOMEM;
93448
93449+#ifdef CONFIG_PAX_SEGMEXEC
93450+ struct vm_area_struct *vma_m, *new_m = NULL;
93451+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
93452+#endif
93453+
93454 if (is_vm_hugetlb_page(vma) && (addr &
93455 ~(huge_page_mask(hstate_vma(vma)))))
93456 return -EINVAL;
93457
93458+#ifdef CONFIG_PAX_SEGMEXEC
93459+ vma_m = pax_find_mirror_vma(vma);
93460+#endif
93461+
93462 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93463 if (!new)
93464 goto out_err;
93465
93466+#ifdef CONFIG_PAX_SEGMEXEC
93467+ if (vma_m) {
93468+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
93469+ if (!new_m) {
93470+ kmem_cache_free(vm_area_cachep, new);
93471+ goto out_err;
93472+ }
93473+ }
93474+#endif
93475+
93476 /* most fields are the same, copy all, and then fixup */
93477 *new = *vma;
93478
93479@@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93480 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
93481 }
93482
93483+#ifdef CONFIG_PAX_SEGMEXEC
93484+ if (vma_m) {
93485+ *new_m = *vma_m;
93486+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
93487+ new_m->vm_mirror = new;
93488+ new->vm_mirror = new_m;
93489+
93490+ if (new_below)
93491+ new_m->vm_end = addr_m;
93492+ else {
93493+ new_m->vm_start = addr_m;
93494+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
93495+ }
93496+ }
93497+#endif
93498+
93499 err = vma_dup_policy(vma, new);
93500 if (err)
93501 goto out_free_vma;
93502@@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93503 else
93504 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
93505
93506+#ifdef CONFIG_PAX_SEGMEXEC
93507+ if (!err && vma_m) {
93508+ struct mempolicy *pol = vma_policy(new);
93509+
93510+ if (anon_vma_clone(new_m, vma_m))
93511+ goto out_free_mpol;
93512+
93513+ mpol_get(pol);
93514+ set_vma_policy(new_m, pol);
93515+
93516+ if (new_m->vm_file)
93517+ get_file(new_m->vm_file);
93518+
93519+ if (new_m->vm_ops && new_m->vm_ops->open)
93520+ new_m->vm_ops->open(new_m);
93521+
93522+ if (new_below)
93523+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
93524+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
93525+ else
93526+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
93527+
93528+ if (err) {
93529+ if (new_m->vm_ops && new_m->vm_ops->close)
93530+ new_m->vm_ops->close(new_m);
93531+ if (new_m->vm_file)
93532+ fput(new_m->vm_file);
93533+ mpol_put(pol);
93534+ }
93535+ }
93536+#endif
93537+
93538 /* Success. */
93539 if (!err)
93540 return 0;
93541@@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93542 new->vm_ops->close(new);
93543 if (new->vm_file)
93544 fput(new->vm_file);
93545- unlink_anon_vmas(new);
93546 out_free_mpol:
93547 mpol_put(vma_policy(new));
93548 out_free_vma:
93549+
93550+#ifdef CONFIG_PAX_SEGMEXEC
93551+ if (new_m) {
93552+ unlink_anon_vmas(new_m);
93553+ kmem_cache_free(vm_area_cachep, new_m);
93554+ }
93555+#endif
93556+
93557+ unlink_anon_vmas(new);
93558 kmem_cache_free(vm_area_cachep, new);
93559 out_err:
93560 return err;
93561@@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
93562 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93563 unsigned long addr, int new_below)
93564 {
93565+
93566+#ifdef CONFIG_PAX_SEGMEXEC
93567+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93568+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
93569+ if (mm->map_count >= sysctl_max_map_count-1)
93570+ return -ENOMEM;
93571+ } else
93572+#endif
93573+
93574 if (mm->map_count >= sysctl_max_map_count)
93575 return -ENOMEM;
93576
93577@@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93578 * work. This now handles partial unmappings.
93579 * Jeremy Fitzhardinge <jeremy@goop.org>
93580 */
93581+#ifdef CONFIG_PAX_SEGMEXEC
93582 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93583 {
93584+ int ret = __do_munmap(mm, start, len);
93585+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
93586+ return ret;
93587+
93588+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
93589+}
93590+
93591+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93592+#else
93593+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93594+#endif
93595+{
93596 unsigned long end;
93597 struct vm_area_struct *vma, *prev, *last;
93598
93599+ /*
93600+ * mm->mmap_sem is required to protect against another thread
93601+ * changing the mappings in case we sleep.
93602+ */
93603+ verify_mm_writelocked(mm);
93604+
93605 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
93606 return -EINVAL;
93607
93608@@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
93609 /* Fix up all other VM information */
93610 remove_vma_list(mm, vma);
93611
93612+ track_exec_limit(mm, start, end, 0UL);
93613+
93614 return 0;
93615 }
93616
93617@@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
93618 int ret;
93619 struct mm_struct *mm = current->mm;
93620
93621+
93622+#ifdef CONFIG_PAX_SEGMEXEC
93623+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
93624+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
93625+ return -EINVAL;
93626+#endif
93627+
93628 down_write(&mm->mmap_sem);
93629 ret = do_munmap(mm, start, len);
93630 up_write(&mm->mmap_sem);
93631@@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
93632 return vm_munmap(addr, len);
93633 }
93634
93635-static inline void verify_mm_writelocked(struct mm_struct *mm)
93636-{
93637-#ifdef CONFIG_DEBUG_VM
93638- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93639- WARN_ON(1);
93640- up_read(&mm->mmap_sem);
93641- }
93642-#endif
93643-}
93644-
93645 /*
93646 * this is really a simplified "do_mmap". it only handles
93647 * anonymous maps. eventually we may be able to do some
93648@@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93649 struct rb_node ** rb_link, * rb_parent;
93650 pgoff_t pgoff = addr >> PAGE_SHIFT;
93651 int error;
93652+ unsigned long charged;
93653
93654 len = PAGE_ALIGN(len);
93655 if (!len)
93656@@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93657
93658 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
93659
93660+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
93661+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
93662+ flags &= ~VM_EXEC;
93663+
93664+#ifdef CONFIG_PAX_MPROTECT
93665+ if (mm->pax_flags & MF_PAX_MPROTECT)
93666+ flags &= ~VM_MAYEXEC;
93667+#endif
93668+
93669+ }
93670+#endif
93671+
93672 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
93673 if (error & ~PAGE_MASK)
93674 return error;
93675
93676+ charged = len >> PAGE_SHIFT;
93677+
93678 /*
93679 * mlock MCL_FUTURE?
93680 */
93681 if (mm->def_flags & VM_LOCKED) {
93682 unsigned long locked, lock_limit;
93683- locked = len >> PAGE_SHIFT;
93684+ locked = charged;
93685 locked += mm->locked_vm;
93686 lock_limit = rlimit(RLIMIT_MEMLOCK);
93687 lock_limit >>= PAGE_SHIFT;
93688@@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93689 /*
93690 * Clear old maps. this also does some error checking for us
93691 */
93692- munmap_back:
93693 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
93694 if (do_munmap(mm, addr, len))
93695 return -ENOMEM;
93696- goto munmap_back;
93697+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
93698 }
93699
93700 /* Check against address space limits *after* clearing old maps... */
93701- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
93702+ if (!may_expand_vm(mm, charged))
93703 return -ENOMEM;
93704
93705 if (mm->map_count > sysctl_max_map_count)
93706 return -ENOMEM;
93707
93708- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
93709+ if (security_vm_enough_memory_mm(mm, charged))
93710 return -ENOMEM;
93711
93712 /* Can we just expand an old private anonymous mapping? */
93713@@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93714 */
93715 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93716 if (!vma) {
93717- vm_unacct_memory(len >> PAGE_SHIFT);
93718+ vm_unacct_memory(charged);
93719 return -ENOMEM;
93720 }
93721
93722@@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
93723 vma_link(mm, vma, prev, rb_link, rb_parent);
93724 out:
93725 perf_event_mmap(vma);
93726- mm->total_vm += len >> PAGE_SHIFT;
93727+ mm->total_vm += charged;
93728 if (flags & VM_LOCKED)
93729- mm->locked_vm += (len >> PAGE_SHIFT);
93730+ mm->locked_vm += charged;
93731 vma->vm_flags |= VM_SOFTDIRTY;
93732+ track_exec_limit(mm, addr, addr + len, flags);
93733 return addr;
93734 }
93735
93736@@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
93737 while (vma) {
93738 if (vma->vm_flags & VM_ACCOUNT)
93739 nr_accounted += vma_pages(vma);
93740+ vma->vm_mirror = NULL;
93741 vma = remove_vma(vma);
93742 }
93743 vm_unacct_memory(nr_accounted);
93744@@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93745 struct vm_area_struct *prev;
93746 struct rb_node **rb_link, *rb_parent;
93747
93748+#ifdef CONFIG_PAX_SEGMEXEC
93749+ struct vm_area_struct *vma_m = NULL;
93750+#endif
93751+
93752+ if (security_mmap_addr(vma->vm_start))
93753+ return -EPERM;
93754+
93755 /*
93756 * The vm_pgoff of a purely anonymous vma should be irrelevant
93757 * until its first write fault, when page's anon_vma and index
93758@@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
93759 security_vm_enough_memory_mm(mm, vma_pages(vma)))
93760 return -ENOMEM;
93761
93762+#ifdef CONFIG_PAX_SEGMEXEC
93763+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
93764+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93765+ if (!vma_m)
93766+ return -ENOMEM;
93767+ }
93768+#endif
93769+
93770 vma_link(mm, vma, prev, rb_link, rb_parent);
93771+
93772+#ifdef CONFIG_PAX_SEGMEXEC
93773+ if (vma_m)
93774+ BUG_ON(pax_mirror_vma(vma_m, vma));
93775+#endif
93776+
93777 return 0;
93778 }
93779
93780@@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93781 struct rb_node **rb_link, *rb_parent;
93782 bool faulted_in_anon_vma = true;
93783
93784+ BUG_ON(vma->vm_mirror);
93785+
93786 /*
93787 * If anonymous vma has not yet been faulted, update new pgoff
93788 * to match new location, to increase its chance of merging.
93789@@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
93790 return NULL;
93791 }
93792
93793+#ifdef CONFIG_PAX_SEGMEXEC
93794+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
93795+{
93796+ struct vm_area_struct *prev_m;
93797+ struct rb_node **rb_link_m, *rb_parent_m;
93798+ struct mempolicy *pol_m;
93799+
93800+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
93801+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
93802+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
93803+ *vma_m = *vma;
93804+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
93805+ if (anon_vma_clone(vma_m, vma))
93806+ return -ENOMEM;
93807+ pol_m = vma_policy(vma_m);
93808+ mpol_get(pol_m);
93809+ set_vma_policy(vma_m, pol_m);
93810+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
93811+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
93812+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
93813+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
93814+ if (vma_m->vm_file)
93815+ get_file(vma_m->vm_file);
93816+ if (vma_m->vm_ops && vma_m->vm_ops->open)
93817+ vma_m->vm_ops->open(vma_m);
93818+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
93819+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
93820+ vma_m->vm_mirror = vma;
93821+ vma->vm_mirror = vma_m;
93822+ return 0;
93823+}
93824+#endif
93825+
93826 /*
93827 * Return true if the calling process may expand its vm space by the passed
93828 * number of pages
93829@@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
93830
93831 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
93832
93833+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
93834 if (cur + npages > lim)
93835 return 0;
93836 return 1;
93837@@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
93838 vma->vm_start = addr;
93839 vma->vm_end = addr + len;
93840
93841+#ifdef CONFIG_PAX_MPROTECT
93842+ if (mm->pax_flags & MF_PAX_MPROTECT) {
93843+#ifndef CONFIG_PAX_MPROTECT_COMPAT
93844+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
93845+ return -EPERM;
93846+ if (!(vm_flags & VM_EXEC))
93847+ vm_flags &= ~VM_MAYEXEC;
93848+#else
93849+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
93850+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
93851+#endif
93852+ else
93853+ vm_flags &= ~VM_MAYWRITE;
93854+ }
93855+#endif
93856+
93857 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
93858 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
93859
93860diff --git a/mm/mprotect.c b/mm/mprotect.c
93861index bb53a65..249c052 100644
93862--- a/mm/mprotect.c
93863+++ b/mm/mprotect.c
93864@@ -23,10 +23,18 @@
93865 #include <linux/mmu_notifier.h>
93866 #include <linux/migrate.h>
93867 #include <linux/perf_event.h>
93868+#include <linux/sched/sysctl.h>
93869+
93870+#ifdef CONFIG_PAX_MPROTECT
93871+#include <linux/elf.h>
93872+#include <linux/binfmts.h>
93873+#endif
93874+
93875 #include <asm/uaccess.h>
93876 #include <asm/pgtable.h>
93877 #include <asm/cacheflush.h>
93878 #include <asm/tlbflush.h>
93879+#include <asm/mmu_context.h>
93880
93881 #ifndef pgprot_modify
93882 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
93883@@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
93884 return pages;
93885 }
93886
93887+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93888+/* called while holding the mmap semaphor for writing except stack expansion */
93889+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
93890+{
93891+ unsigned long oldlimit, newlimit = 0UL;
93892+
93893+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
93894+ return;
93895+
93896+ spin_lock(&mm->page_table_lock);
93897+ oldlimit = mm->context.user_cs_limit;
93898+ if ((prot & VM_EXEC) && oldlimit < end)
93899+ /* USER_CS limit moved up */
93900+ newlimit = end;
93901+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
93902+ /* USER_CS limit moved down */
93903+ newlimit = start;
93904+
93905+ if (newlimit) {
93906+ mm->context.user_cs_limit = newlimit;
93907+
93908+#ifdef CONFIG_SMP
93909+ wmb();
93910+ cpus_clear(mm->context.cpu_user_cs_mask);
93911+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
93912+#endif
93913+
93914+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
93915+ }
93916+ spin_unlock(&mm->page_table_lock);
93917+ if (newlimit == end) {
93918+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
93919+
93920+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
93921+ if (is_vm_hugetlb_page(vma))
93922+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
93923+ else
93924+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
93925+ }
93926+}
93927+#endif
93928+
93929 int
93930 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93931 unsigned long start, unsigned long end, unsigned long newflags)
93932@@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93933 int error;
93934 int dirty_accountable = 0;
93935
93936+#ifdef CONFIG_PAX_SEGMEXEC
93937+ struct vm_area_struct *vma_m = NULL;
93938+ unsigned long start_m, end_m;
93939+
93940+ start_m = start + SEGMEXEC_TASK_SIZE;
93941+ end_m = end + SEGMEXEC_TASK_SIZE;
93942+#endif
93943+
93944 if (newflags == oldflags) {
93945 *pprev = vma;
93946 return 0;
93947 }
93948
93949+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
93950+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
93951+
93952+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
93953+ return -ENOMEM;
93954+
93955+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
93956+ return -ENOMEM;
93957+ }
93958+
93959 /*
93960 * If we make a private mapping writable we increase our commit;
93961 * but (without finer accounting) cannot reduce our commit if we
93962@@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
93963 }
93964 }
93965
93966+#ifdef CONFIG_PAX_SEGMEXEC
93967+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
93968+ if (start != vma->vm_start) {
93969+ error = split_vma(mm, vma, start, 1);
93970+ if (error)
93971+ goto fail;
93972+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
93973+ *pprev = (*pprev)->vm_next;
93974+ }
93975+
93976+ if (end != vma->vm_end) {
93977+ error = split_vma(mm, vma, end, 0);
93978+ if (error)
93979+ goto fail;
93980+ }
93981+
93982+ if (pax_find_mirror_vma(vma)) {
93983+ error = __do_munmap(mm, start_m, end_m - start_m);
93984+ if (error)
93985+ goto fail;
93986+ } else {
93987+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
93988+ if (!vma_m) {
93989+ error = -ENOMEM;
93990+ goto fail;
93991+ }
93992+ vma->vm_flags = newflags;
93993+ error = pax_mirror_vma(vma_m, vma);
93994+ if (error) {
93995+ vma->vm_flags = oldflags;
93996+ goto fail;
93997+ }
93998+ }
93999+ }
94000+#endif
94001+
94002 /*
94003 * First try to merge with previous and/or next vma.
94004 */
94005@@ -285,9 +389,21 @@ success:
94006 * vm_flags and vm_page_prot are protected by the mmap_sem
94007 * held in write mode.
94008 */
94009+
94010+#ifdef CONFIG_PAX_SEGMEXEC
94011+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
94012+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
94013+#endif
94014+
94015 vma->vm_flags = newflags;
94016+
94017+#ifdef CONFIG_PAX_MPROTECT
94018+ if (mm->binfmt && mm->binfmt->handle_mprotect)
94019+ mm->binfmt->handle_mprotect(vma, newflags);
94020+#endif
94021+
94022 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
94023- vm_get_page_prot(newflags));
94024+ vm_get_page_prot(vma->vm_flags));
94025
94026 if (vma_wants_writenotify(vma)) {
94027 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
94028@@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94029 end = start + len;
94030 if (end <= start)
94031 return -ENOMEM;
94032+
94033+#ifdef CONFIG_PAX_SEGMEXEC
94034+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
94035+ if (end > SEGMEXEC_TASK_SIZE)
94036+ return -EINVAL;
94037+ } else
94038+#endif
94039+
94040+ if (end > TASK_SIZE)
94041+ return -EINVAL;
94042+
94043 if (!arch_validate_prot(prot))
94044 return -EINVAL;
94045
94046@@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94047 /*
94048 * Does the application expect PROT_READ to imply PROT_EXEC:
94049 */
94050- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94051+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94052 prot |= PROT_EXEC;
94053
94054 vm_flags = calc_vm_prot_bits(prot);
94055@@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94056 if (start > vma->vm_start)
94057 prev = vma;
94058
94059+#ifdef CONFIG_PAX_MPROTECT
94060+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
94061+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
94062+#endif
94063+
94064 for (nstart = start ; ; ) {
94065 unsigned long newflags;
94066
94067@@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94068
94069 /* newflags >> 4 shift VM_MAY% in place of VM_% */
94070 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
94071+ if (prot & (PROT_WRITE | PROT_EXEC))
94072+ gr_log_rwxmprotect(vma);
94073+
94074+ error = -EACCES;
94075+ goto out;
94076+ }
94077+
94078+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
94079 error = -EACCES;
94080 goto out;
94081 }
94082@@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
94083 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
94084 if (error)
94085 goto out;
94086+
94087+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
94088+
94089 nstart = tmp;
94090
94091 if (nstart < prev->vm_end)
94092diff --git a/mm/mremap.c b/mm/mremap.c
94093index 0843feb..4f5b2e6 100644
94094--- a/mm/mremap.c
94095+++ b/mm/mremap.c
94096@@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
94097 continue;
94098 pte = ptep_get_and_clear(mm, old_addr, old_pte);
94099 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
94100+
94101+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
94102+ if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
94103+ pte = pte_exprotect(pte);
94104+#endif
94105+
94106 pte = move_soft_dirty_pte(pte);
94107 set_pte_at(mm, new_addr, new_pte, pte);
94108 }
94109@@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
94110 if (is_vm_hugetlb_page(vma))
94111 goto Einval;
94112
94113+#ifdef CONFIG_PAX_SEGMEXEC
94114+ if (pax_find_mirror_vma(vma))
94115+ goto Einval;
94116+#endif
94117+
94118 /* We can't remap across vm area boundaries */
94119 if (old_len > vma->vm_end - addr)
94120 goto Efault;
94121@@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
94122 unsigned long ret = -EINVAL;
94123 unsigned long charged = 0;
94124 unsigned long map_flags;
94125+ unsigned long pax_task_size = TASK_SIZE;
94126
94127 if (new_addr & ~PAGE_MASK)
94128 goto out;
94129
94130- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
94131+#ifdef CONFIG_PAX_SEGMEXEC
94132+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94133+ pax_task_size = SEGMEXEC_TASK_SIZE;
94134+#endif
94135+
94136+ pax_task_size -= PAGE_SIZE;
94137+
94138+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
94139 goto out;
94140
94141 /* Check if the location we're moving into overlaps the
94142 * old location at all, and fail if it does.
94143 */
94144- if ((new_addr <= addr) && (new_addr+new_len) > addr)
94145- goto out;
94146-
94147- if ((addr <= new_addr) && (addr+old_len) > new_addr)
94148+ if (addr + old_len > new_addr && new_addr + new_len > addr)
94149 goto out;
94150
94151 ret = do_munmap(mm, new_addr, new_len);
94152@@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94153 unsigned long ret = -EINVAL;
94154 unsigned long charged = 0;
94155 bool locked = false;
94156+ unsigned long pax_task_size = TASK_SIZE;
94157
94158 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
94159 return ret;
94160@@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94161 if (!new_len)
94162 return ret;
94163
94164+#ifdef CONFIG_PAX_SEGMEXEC
94165+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
94166+ pax_task_size = SEGMEXEC_TASK_SIZE;
94167+#endif
94168+
94169+ pax_task_size -= PAGE_SIZE;
94170+
94171+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
94172+ old_len > pax_task_size || addr > pax_task_size-old_len)
94173+ return ret;
94174+
94175 down_write(&current->mm->mmap_sem);
94176
94177 if (flags & MREMAP_FIXED) {
94178@@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94179 new_addr = addr;
94180 }
94181 ret = addr;
94182+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
94183 goto out;
94184 }
94185 }
94186@@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
94187 goto out;
94188 }
94189
94190+ map_flags = vma->vm_flags;
94191 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
94192+ if (!(ret & ~PAGE_MASK)) {
94193+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
94194+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
94195+ }
94196 }
94197 out:
94198 if (ret & ~PAGE_MASK)
94199diff --git a/mm/nommu.c b/mm/nommu.c
94200index fec093a..8162f74 100644
94201--- a/mm/nommu.c
94202+++ b/mm/nommu.c
94203@@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
94204 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
94205 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
94206 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
94207-int heap_stack_gap = 0;
94208
94209 atomic_long_t mmap_pages_allocated;
94210
94211@@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
94212 EXPORT_SYMBOL(find_vma);
94213
94214 /*
94215- * find a VMA
94216- * - we don't extend stack VMAs under NOMMU conditions
94217- */
94218-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
94219-{
94220- return find_vma(mm, addr);
94221-}
94222-
94223-/*
94224 * expand a stack to a given address
94225 * - not supported under NOMMU conditions
94226 */
94227@@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94228
94229 /* most fields are the same, copy all, and then fixup */
94230 *new = *vma;
94231+ INIT_LIST_HEAD(&new->anon_vma_chain);
94232 *region = *vma->vm_region;
94233 new->vm_region = region;
94234
94235@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
94236 }
94237 EXPORT_SYMBOL(generic_file_remap_pages);
94238
94239-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94240- unsigned long addr, void *buf, int len, int write)
94241+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94242+ unsigned long addr, void *buf, size_t len, int write)
94243 {
94244 struct vm_area_struct *vma;
94245
94246@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
94247 *
94248 * The caller must hold a reference on @mm.
94249 */
94250-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94251- void *buf, int len, int write)
94252+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
94253+ void *buf, size_t len, int write)
94254 {
94255 return __access_remote_vm(NULL, mm, addr, buf, len, write);
94256 }
94257@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
94258 * Access another process' address space.
94259 * - source/target buffer must be kernel space
94260 */
94261-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
94262+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
94263 {
94264 struct mm_struct *mm;
94265
94266diff --git a/mm/page-writeback.c b/mm/page-writeback.c
94267index 7106cb1..0805f48 100644
94268--- a/mm/page-writeback.c
94269+++ b/mm/page-writeback.c
94270@@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
94271 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
94272 * - the bdi dirty thresh drops quickly due to change of JBOD workload
94273 */
94274-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
94275+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
94276 unsigned long thresh,
94277 unsigned long bg_thresh,
94278 unsigned long dirty,
94279diff --git a/mm/page_alloc.c b/mm/page_alloc.c
94280index 589521d..314053a 100644
94281--- a/mm/page_alloc.c
94282+++ b/mm/page_alloc.c
94283@@ -61,6 +61,7 @@
94284 #include <linux/page-debug-flags.h>
94285 #include <linux/hugetlb.h>
94286 #include <linux/sched/rt.h>
94287+#include <linux/random.h>
94288
94289 #include <asm/sections.h>
94290 #include <asm/tlbflush.h>
94291@@ -354,7 +355,7 @@ out:
94292 * This usage means that zero-order pages may not be compound.
94293 */
94294
94295-static void free_compound_page(struct page *page)
94296+void free_compound_page(struct page *page)
94297 {
94298 __free_pages_ok(page, compound_order(page));
94299 }
94300@@ -714,6 +715,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94301 int i;
94302 int bad = 0;
94303
94304+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94305+ unsigned long index = 1UL << order;
94306+#endif
94307+
94308 trace_mm_page_free(page, order);
94309 kmemcheck_free_shadow(page, order);
94310
94311@@ -730,6 +735,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
94312 debug_check_no_obj_freed(page_address(page),
94313 PAGE_SIZE << order);
94314 }
94315+
94316+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94317+ for (; index; --index)
94318+ sanitize_highpage(page + index - 1);
94319+#endif
94320+
94321 arch_free_page(page, order);
94322 kernel_map_pages(page, 1 << order, 0);
94323
94324@@ -752,6 +763,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
94325 local_irq_restore(flags);
94326 }
94327
94328+#ifdef CONFIG_PAX_LATENT_ENTROPY
94329+bool __meminitdata extra_latent_entropy;
94330+
94331+static int __init setup_pax_extra_latent_entropy(char *str)
94332+{
94333+ extra_latent_entropy = true;
94334+ return 0;
94335+}
94336+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
94337+
94338+volatile u64 latent_entropy __latent_entropy;
94339+EXPORT_SYMBOL(latent_entropy);
94340+#endif
94341+
94342 void __init __free_pages_bootmem(struct page *page, unsigned int order)
94343 {
94344 unsigned int nr_pages = 1 << order;
94345@@ -767,6 +792,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
94346 __ClearPageReserved(p);
94347 set_page_count(p, 0);
94348
94349+#ifdef CONFIG_PAX_LATENT_ENTROPY
94350+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
94351+ u64 hash = 0;
94352+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
94353+ const u64 *data = lowmem_page_address(page);
94354+
94355+ for (index = 0; index < end; index++)
94356+ hash ^= hash + data[index];
94357+ latent_entropy ^= hash;
94358+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
94359+ }
94360+#endif
94361+
94362 page_zone(page)->managed_pages += nr_pages;
94363 set_page_refcounted(page);
94364 __free_pages(page, order);
94365@@ -872,8 +910,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
94366 arch_alloc_page(page, order);
94367 kernel_map_pages(page, 1 << order, 1);
94368
94369+#ifndef CONFIG_PAX_MEMORY_SANITIZE
94370 if (gfp_flags & __GFP_ZERO)
94371 prep_zero_page(page, order, gfp_flags);
94372+#endif
94373
94374 if (order && (gfp_flags & __GFP_COMP))
94375 prep_compound_page(page, order);
94376diff --git a/mm/page_io.c b/mm/page_io.c
94377index 8c79a47..a689e0d 100644
94378--- a/mm/page_io.c
94379+++ b/mm/page_io.c
94380@@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
94381 struct file *swap_file = sis->swap_file;
94382 struct address_space *mapping = swap_file->f_mapping;
94383 struct iovec iov = {
94384- .iov_base = kmap(page),
94385+ .iov_base = (void __force_user *)kmap(page),
94386 .iov_len = PAGE_SIZE,
94387 };
94388
94389diff --git a/mm/percpu.c b/mm/percpu.c
94390index 0d10def..6dc822d 100644
94391--- a/mm/percpu.c
94392+++ b/mm/percpu.c
94393@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
94394 static unsigned int pcpu_high_unit_cpu __read_mostly;
94395
94396 /* the address of the first chunk which starts with the kernel static area */
94397-void *pcpu_base_addr __read_mostly;
94398+void *pcpu_base_addr __read_only;
94399 EXPORT_SYMBOL_GPL(pcpu_base_addr);
94400
94401 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
94402diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
94403index fd26d04..0cea1b0 100644
94404--- a/mm/process_vm_access.c
94405+++ b/mm/process_vm_access.c
94406@@ -13,6 +13,7 @@
94407 #include <linux/uio.h>
94408 #include <linux/sched.h>
94409 #include <linux/highmem.h>
94410+#include <linux/security.h>
94411 #include <linux/ptrace.h>
94412 #include <linux/slab.h>
94413 #include <linux/syscalls.h>
94414@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94415 size_t iov_l_curr_offset = 0;
94416 ssize_t iov_len;
94417
94418+ return -ENOSYS; // PaX: until properly audited
94419+
94420 /*
94421 * Work out how many pages of struct pages we're going to need
94422 * when eventually calling get_user_pages
94423 */
94424 for (i = 0; i < riovcnt; i++) {
94425 iov_len = rvec[i].iov_len;
94426- if (iov_len > 0) {
94427- nr_pages_iov = ((unsigned long)rvec[i].iov_base
94428- + iov_len)
94429- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
94430- / PAGE_SIZE + 1;
94431- nr_pages = max(nr_pages, nr_pages_iov);
94432- }
94433+ if (iov_len <= 0)
94434+ continue;
94435+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
94436+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
94437+ nr_pages = max(nr_pages, nr_pages_iov);
94438 }
94439
94440 if (nr_pages == 0)
94441@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
94442 goto free_proc_pages;
94443 }
94444
94445+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
94446+ rc = -EPERM;
94447+ goto put_task_struct;
94448+ }
94449+
94450 mm = mm_access(task, PTRACE_MODE_ATTACH);
94451 if (!mm || IS_ERR(mm)) {
94452 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
94453diff --git a/mm/rmap.c b/mm/rmap.c
94454index 068522d..f539f21 100644
94455--- a/mm/rmap.c
94456+++ b/mm/rmap.c
94457@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94458 struct anon_vma *anon_vma = vma->anon_vma;
94459 struct anon_vma_chain *avc;
94460
94461+#ifdef CONFIG_PAX_SEGMEXEC
94462+ struct anon_vma_chain *avc_m = NULL;
94463+#endif
94464+
94465 might_sleep();
94466 if (unlikely(!anon_vma)) {
94467 struct mm_struct *mm = vma->vm_mm;
94468@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94469 if (!avc)
94470 goto out_enomem;
94471
94472+#ifdef CONFIG_PAX_SEGMEXEC
94473+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
94474+ if (!avc_m)
94475+ goto out_enomem_free_avc;
94476+#endif
94477+
94478 anon_vma = find_mergeable_anon_vma(vma);
94479 allocated = NULL;
94480 if (!anon_vma) {
94481@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94482 /* page_table_lock to protect against threads */
94483 spin_lock(&mm->page_table_lock);
94484 if (likely(!vma->anon_vma)) {
94485+
94486+#ifdef CONFIG_PAX_SEGMEXEC
94487+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
94488+
94489+ if (vma_m) {
94490+ BUG_ON(vma_m->anon_vma);
94491+ vma_m->anon_vma = anon_vma;
94492+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
94493+ avc_m = NULL;
94494+ }
94495+#endif
94496+
94497 vma->anon_vma = anon_vma;
94498 anon_vma_chain_link(vma, avc, anon_vma);
94499 allocated = NULL;
94500@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
94501
94502 if (unlikely(allocated))
94503 put_anon_vma(allocated);
94504+
94505+#ifdef CONFIG_PAX_SEGMEXEC
94506+ if (unlikely(avc_m))
94507+ anon_vma_chain_free(avc_m);
94508+#endif
94509+
94510 if (unlikely(avc))
94511 anon_vma_chain_free(avc);
94512 }
94513 return 0;
94514
94515 out_enomem_free_avc:
94516+
94517+#ifdef CONFIG_PAX_SEGMEXEC
94518+ if (avc_m)
94519+ anon_vma_chain_free(avc_m);
94520+#endif
94521+
94522 anon_vma_chain_free(avc);
94523 out_enomem:
94524 return -ENOMEM;
94525@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
94526 * Attach the anon_vmas from src to dst.
94527 * Returns 0 on success, -ENOMEM on failure.
94528 */
94529-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94530+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
94531 {
94532 struct anon_vma_chain *avc, *pavc;
94533 struct anon_vma *root = NULL;
94534@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
94535 * the corresponding VMA in the parent process is attached to.
94536 * Returns 0 on success, non-zero on failure.
94537 */
94538-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
94539+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
94540 {
94541 struct anon_vma_chain *avc;
94542 struct anon_vma *anon_vma;
94543@@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
94544 void __init anon_vma_init(void)
94545 {
94546 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
94547- 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
94548- anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
94549+ 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
94550+ anon_vma_ctor);
94551+ anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
94552+ SLAB_PANIC|SLAB_NO_SANITIZE);
94553 }
94554
94555 /*
94556diff --git a/mm/shmem.c b/mm/shmem.c
94557index 902a148..58f9d59 100644
94558--- a/mm/shmem.c
94559+++ b/mm/shmem.c
94560@@ -33,7 +33,7 @@
94561 #include <linux/swap.h>
94562 #include <linux/aio.h>
94563
94564-static struct vfsmount *shm_mnt;
94565+struct vfsmount *shm_mnt;
94566
94567 #ifdef CONFIG_SHMEM
94568 /*
94569@@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
94570 #define BOGO_DIRENT_SIZE 20
94571
94572 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
94573-#define SHORT_SYMLINK_LEN 128
94574+#define SHORT_SYMLINK_LEN 64
94575
94576 /*
94577 * shmem_fallocate and shmem_writepage communicate via inode->i_private
94578@@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
94579 static int shmem_xattr_validate(const char *name)
94580 {
94581 struct { const char *prefix; size_t len; } arr[] = {
94582+
94583+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94584+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
94585+#endif
94586+
94587 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
94588 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
94589 };
94590@@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
94591 if (err)
94592 return err;
94593
94594+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
94595+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
94596+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
94597+ return -EOPNOTSUPP;
94598+ if (size > 8)
94599+ return -EINVAL;
94600+ }
94601+#endif
94602+
94603 return simple_xattr_set(&info->xattrs, name, value, size, flags);
94604 }
94605
94606@@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
94607 int err = -ENOMEM;
94608
94609 /* Round up to L1_CACHE_BYTES to resist false sharing */
94610- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
94611- L1_CACHE_BYTES), GFP_KERNEL);
94612+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
94613 if (!sbinfo)
94614 return -ENOMEM;
94615
94616diff --git a/mm/slab.c b/mm/slab.c
94617index eb043bf..d82f5a8 100644
94618--- a/mm/slab.c
94619+++ b/mm/slab.c
94620@@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94621 if ((x)->max_freeable < i) \
94622 (x)->max_freeable = i; \
94623 } while (0)
94624-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
94625-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
94626-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
94627-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
94628+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
94629+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
94630+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
94631+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
94632+#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
94633+#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
94634 #else
94635 #define STATS_INC_ACTIVE(x) do { } while (0)
94636 #define STATS_DEC_ACTIVE(x) do { } while (0)
94637@@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
94638 #define STATS_INC_ALLOCMISS(x) do { } while (0)
94639 #define STATS_INC_FREEHIT(x) do { } while (0)
94640 #define STATS_INC_FREEMISS(x) do { } while (0)
94641+#define STATS_INC_SANITIZED(x) do { } while (0)
94642+#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
94643 #endif
94644
94645 #if DEBUG
94646@@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
94647 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
94648 */
94649 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
94650- const struct page *page, void *obj)
94651+ const struct page *page, const void *obj)
94652 {
94653 u32 offset = (obj - page->s_mem);
94654 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
94655@@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
94656 */
94657
94658 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
94659- kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
94660+ kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94661
94662 if (INDEX_AC != INDEX_NODE)
94663 kmalloc_caches[INDEX_NODE] =
94664 create_kmalloc_cache("kmalloc-node",
94665- kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
94666+ kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
94667
94668 slab_early_init = 0;
94669
94670@@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
94671 struct array_cache *ac = cpu_cache_get(cachep);
94672
94673 check_irq_off();
94674+
94675+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94676+ if (pax_sanitize_slab) {
94677+ if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
94678+ memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
94679+
94680+ if (cachep->ctor)
94681+ cachep->ctor(objp);
94682+
94683+ STATS_INC_SANITIZED(cachep);
94684+ } else
94685+ STATS_INC_NOT_SANITIZED(cachep);
94686+ }
94687+#endif
94688+
94689 kmemleak_free_recursive(objp, cachep->flags);
94690 objp = cache_free_debugcheck(cachep, objp, caller);
94691
94692@@ -3656,6 +3675,7 @@ void kfree(const void *objp)
94693
94694 if (unlikely(ZERO_OR_NULL_PTR(objp)))
94695 return;
94696+ VM_BUG_ON(!virt_addr_valid(objp));
94697 local_irq_save(flags);
94698 kfree_debugcheck(objp);
94699 c = virt_to_cache(objp);
94700@@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
94701 }
94702 /* cpu stats */
94703 {
94704- unsigned long allochit = atomic_read(&cachep->allochit);
94705- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
94706- unsigned long freehit = atomic_read(&cachep->freehit);
94707- unsigned long freemiss = atomic_read(&cachep->freemiss);
94708+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
94709+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
94710+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
94711+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
94712
94713 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
94714 allochit, allocmiss, freehit, freemiss);
94715 }
94716+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94717+ {
94718+ unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
94719+ unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
94720+
94721+ seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
94722+ }
94723+#endif
94724 #endif
94725 }
94726
94727@@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
94728 static int __init slab_proc_init(void)
94729 {
94730 #ifdef CONFIG_DEBUG_SLAB_LEAK
94731- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
94732+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
94733 #endif
94734 return 0;
94735 }
94736 module_init(slab_proc_init);
94737 #endif
94738
94739+bool is_usercopy_object(const void *ptr)
94740+{
94741+ struct page *page;
94742+ struct kmem_cache *cachep;
94743+
94744+ if (ZERO_OR_NULL_PTR(ptr))
94745+ return false;
94746+
94747+ if (!slab_is_available())
94748+ return false;
94749+
94750+ if (!virt_addr_valid(ptr))
94751+ return false;
94752+
94753+ page = virt_to_head_page(ptr);
94754+
94755+ if (!PageSlab(page))
94756+ return false;
94757+
94758+ cachep = page->slab_cache;
94759+ return cachep->flags & SLAB_USERCOPY;
94760+}
94761+
94762+#ifdef CONFIG_PAX_USERCOPY
94763+const char *check_heap_object(const void *ptr, unsigned long n)
94764+{
94765+ struct page *page;
94766+ struct kmem_cache *cachep;
94767+ unsigned int objnr;
94768+ unsigned long offset;
94769+
94770+ if (ZERO_OR_NULL_PTR(ptr))
94771+ return "<null>";
94772+
94773+ if (!virt_addr_valid(ptr))
94774+ return NULL;
94775+
94776+ page = virt_to_head_page(ptr);
94777+
94778+ if (!PageSlab(page))
94779+ return NULL;
94780+
94781+ cachep = page->slab_cache;
94782+ if (!(cachep->flags & SLAB_USERCOPY))
94783+ return cachep->name;
94784+
94785+ objnr = obj_to_index(cachep, page, ptr);
94786+ BUG_ON(objnr >= cachep->num);
94787+ offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
94788+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
94789+ return NULL;
94790+
94791+ return cachep->name;
94792+}
94793+#endif
94794+
94795 /**
94796 * ksize - get the actual amount of memory allocated for a given object
94797 * @objp: Pointer to the object
94798diff --git a/mm/slab.h b/mm/slab.h
94799index 0859c42..2f7b737 100644
94800--- a/mm/slab.h
94801+++ b/mm/slab.h
94802@@ -32,6 +32,15 @@ extern struct list_head slab_caches;
94803 /* The slab cache that manages slab cache information */
94804 extern struct kmem_cache *kmem_cache;
94805
94806+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94807+#ifdef CONFIG_X86_64
94808+#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
94809+#else
94810+#define PAX_MEMORY_SANITIZE_VALUE '\xff'
94811+#endif
94812+extern bool pax_sanitize_slab;
94813+#endif
94814+
94815 unsigned long calculate_alignment(unsigned long flags,
94816 unsigned long align, unsigned long size);
94817
94818@@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94819
94820 /* Legal flag mask for kmem_cache_create(), for various configurations */
94821 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
94822- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
94823+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
94824+ SLAB_USERCOPY | SLAB_NO_SANITIZE)
94825
94826 #if defined(CONFIG_DEBUG_SLAB)
94827 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
94828@@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
94829 return s;
94830
94831 page = virt_to_head_page(x);
94832+
94833+ BUG_ON(!PageSlab(page));
94834+
94835 cachep = page->slab_cache;
94836 if (slab_equal_or_root(cachep, s))
94837 return cachep;
94838diff --git a/mm/slab_common.c b/mm/slab_common.c
94839index 0b7bb39..334c328 100644
94840--- a/mm/slab_common.c
94841+++ b/mm/slab_common.c
94842@@ -23,11 +23,22 @@
94843
94844 #include "slab.h"
94845
94846-enum slab_state slab_state;
94847+enum slab_state slab_state __read_only;
94848 LIST_HEAD(slab_caches);
94849 DEFINE_MUTEX(slab_mutex);
94850 struct kmem_cache *kmem_cache;
94851
94852+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94853+bool pax_sanitize_slab __read_only = true;
94854+static int __init pax_sanitize_slab_setup(char *str)
94855+{
94856+ pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
94857+ printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
94858+ return 1;
94859+}
94860+__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
94861+#endif
94862+
94863 #ifdef CONFIG_DEBUG_VM
94864 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
94865 size_t size)
94866@@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
94867
94868 err = __kmem_cache_create(s, flags);
94869 if (!err) {
94870- s->refcount = 1;
94871+ atomic_set(&s->refcount, 1);
94872 list_add(&s->list, &slab_caches);
94873 memcg_cache_list_add(memcg, s);
94874 } else {
94875@@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
94876
94877 get_online_cpus();
94878 mutex_lock(&slab_mutex);
94879- s->refcount--;
94880- if (!s->refcount) {
94881+ if (atomic_dec_and_test(&s->refcount)) {
94882 list_del(&s->list);
94883
94884 if (!__kmem_cache_shutdown(s)) {
94885@@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
94886 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
94887 name, size, err);
94888
94889- s->refcount = -1; /* Exempt from merging for now */
94890+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
94891 }
94892
94893 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94894@@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
94895
94896 create_boot_cache(s, name, size, flags);
94897 list_add(&s->list, &slab_caches);
94898- s->refcount = 1;
94899+ atomic_set(&s->refcount, 1);
94900 return s;
94901 }
94902
94903@@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
94904 EXPORT_SYMBOL(kmalloc_dma_caches);
94905 #endif
94906
94907+#ifdef CONFIG_PAX_USERCOPY_SLABS
94908+struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
94909+EXPORT_SYMBOL(kmalloc_usercopy_caches);
94910+#endif
94911+
94912 /*
94913 * Conversion table for small slabs sizes / 8 to the index in the
94914 * kmalloc array. This is necessary for slabs < 192 since we have non power
94915@@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
94916 return kmalloc_dma_caches[index];
94917
94918 #endif
94919+
94920+#ifdef CONFIG_PAX_USERCOPY_SLABS
94921+ if (unlikely((flags & GFP_USERCOPY)))
94922+ return kmalloc_usercopy_caches[index];
94923+
94924+#endif
94925+
94926 return kmalloc_caches[index];
94927 }
94928
94929@@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
94930 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
94931 if (!kmalloc_caches[i]) {
94932 kmalloc_caches[i] = create_kmalloc_cache(NULL,
94933- 1 << i, flags);
94934+ 1 << i, SLAB_USERCOPY | flags);
94935 }
94936
94937 /*
94938@@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
94939 * earlier power of two caches
94940 */
94941 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
94942- kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
94943+ kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
94944
94945 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
94946- kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
94947+ kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
94948 }
94949
94950 /* Kmalloc array is now usable */
94951@@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
94952 }
94953 }
94954 #endif
94955+
94956+#ifdef CONFIG_PAX_USERCOPY_SLABS
94957+ for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
94958+ struct kmem_cache *s = kmalloc_caches[i];
94959+
94960+ if (s) {
94961+ int size = kmalloc_size(i);
94962+ char *n = kasprintf(GFP_NOWAIT,
94963+ "usercopy-kmalloc-%d", size);
94964+
94965+ BUG_ON(!n);
94966+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
94967+ size, SLAB_USERCOPY | flags);
94968+ }
94969+ }
94970+#endif
94971+
94972 }
94973 #endif /* !CONFIG_SLOB */
94974
94975@@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
94976 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
94977 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
94978 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
94979+#ifdef CONFIG_PAX_MEMORY_SANITIZE
94980+ seq_puts(m, " : pax <sanitized> <not_sanitized>");
94981+#endif
94982 #endif
94983 seq_putc(m, '\n');
94984 }
94985diff --git a/mm/slob.c b/mm/slob.c
94986index 4bf8809..98a6914 100644
94987--- a/mm/slob.c
94988+++ b/mm/slob.c
94989@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
94990 /*
94991 * Return the size of a slob block.
94992 */
94993-static slobidx_t slob_units(slob_t *s)
94994+static slobidx_t slob_units(const slob_t *s)
94995 {
94996 if (s->units > 0)
94997 return s->units;
94998@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
94999 /*
95000 * Return the next free slob block pointer after this one.
95001 */
95002-static slob_t *slob_next(slob_t *s)
95003+static slob_t *slob_next(const slob_t *s)
95004 {
95005 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
95006 slobidx_t next;
95007@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
95008 /*
95009 * Returns true if s is the last free block in its page.
95010 */
95011-static int slob_last(slob_t *s)
95012+static int slob_last(const slob_t *s)
95013 {
95014 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
95015 }
95016
95017-static void *slob_new_pages(gfp_t gfp, int order, int node)
95018+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
95019 {
95020- void *page;
95021+ struct page *page;
95022
95023 #ifdef CONFIG_NUMA
95024 if (node != NUMA_NO_NODE)
95025@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
95026 if (!page)
95027 return NULL;
95028
95029- return page_address(page);
95030+ __SetPageSlab(page);
95031+ return page;
95032 }
95033
95034-static void slob_free_pages(void *b, int order)
95035+static void slob_free_pages(struct page *sp, int order)
95036 {
95037 if (current->reclaim_state)
95038 current->reclaim_state->reclaimed_slab += 1 << order;
95039- free_pages((unsigned long)b, order);
95040+ __ClearPageSlab(sp);
95041+ page_mapcount_reset(sp);
95042+ sp->private = 0;
95043+ __free_pages(sp, order);
95044 }
95045
95046 /*
95047@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
95048
95049 /* Not enough space: must allocate a new page */
95050 if (!b) {
95051- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95052- if (!b)
95053+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
95054+ if (!sp)
95055 return NULL;
95056- sp = virt_to_page(b);
95057- __SetPageSlab(sp);
95058+ b = page_address(sp);
95059
95060 spin_lock_irqsave(&slob_lock, flags);
95061 sp->units = SLOB_UNITS(PAGE_SIZE);
95062 sp->freelist = b;
95063+ sp->private = 0;
95064 INIT_LIST_HEAD(&sp->list);
95065 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
95066 set_slob_page_free(sp, slob_list);
95067@@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
95068 if (slob_page_free(sp))
95069 clear_slob_page_free(sp);
95070 spin_unlock_irqrestore(&slob_lock, flags);
95071- __ClearPageSlab(sp);
95072- page_mapcount_reset(sp);
95073- slob_free_pages(b, 0);
95074+ slob_free_pages(sp, 0);
95075 return;
95076 }
95077
95078+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95079+ if (pax_sanitize_slab)
95080+ memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
95081+#endif
95082+
95083 if (!slob_page_free(sp)) {
95084 /* This slob page is about to become partially free. Easy! */
95085 sp->units = units;
95086@@ -424,11 +431,10 @@ out:
95087 */
95088
95089 static __always_inline void *
95090-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95091+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
95092 {
95093- unsigned int *m;
95094- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95095- void *ret;
95096+ slob_t *m;
95097+ void *ret = NULL;
95098
95099 gfp &= gfp_allowed_mask;
95100
95101@@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95102
95103 if (!m)
95104 return NULL;
95105- *m = size;
95106+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
95107+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
95108+ m[0].units = size;
95109+ m[1].units = align;
95110 ret = (void *)m + align;
95111
95112 trace_kmalloc_node(caller, ret,
95113 size, size + align, gfp, node);
95114 } else {
95115 unsigned int order = get_order(size);
95116+ struct page *page;
95117
95118 if (likely(order))
95119 gfp |= __GFP_COMP;
95120- ret = slob_new_pages(gfp, order, node);
95121+ page = slob_new_pages(gfp, order, node);
95122+ if (page) {
95123+ ret = page_address(page);
95124+ page->private = size;
95125+ }
95126
95127 trace_kmalloc_node(caller, ret,
95128 size, PAGE_SIZE << order, gfp, node);
95129 }
95130
95131- kmemleak_alloc(ret, size, 1, gfp);
95132+ return ret;
95133+}
95134+
95135+static __always_inline void *
95136+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
95137+{
95138+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95139+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
95140+
95141+ if (!ZERO_OR_NULL_PTR(ret))
95142+ kmemleak_alloc(ret, size, 1, gfp);
95143 return ret;
95144 }
95145
95146@@ -493,34 +517,112 @@ void kfree(const void *block)
95147 return;
95148 kmemleak_free(block);
95149
95150+ VM_BUG_ON(!virt_addr_valid(block));
95151 sp = virt_to_page(block);
95152- if (PageSlab(sp)) {
95153+ VM_BUG_ON(!PageSlab(sp));
95154+ if (!sp->private) {
95155 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95156- unsigned int *m = (unsigned int *)(block - align);
95157- slob_free(m, *m + align);
95158- } else
95159+ slob_t *m = (slob_t *)(block - align);
95160+ slob_free(m, m[0].units + align);
95161+ } else {
95162+ __ClearPageSlab(sp);
95163+ page_mapcount_reset(sp);
95164+ sp->private = 0;
95165 __free_pages(sp, compound_order(sp));
95166+ }
95167 }
95168 EXPORT_SYMBOL(kfree);
95169
95170+bool is_usercopy_object(const void *ptr)
95171+{
95172+ if (!slab_is_available())
95173+ return false;
95174+
95175+ // PAX: TODO
95176+
95177+ return false;
95178+}
95179+
95180+#ifdef CONFIG_PAX_USERCOPY
95181+const char *check_heap_object(const void *ptr, unsigned long n)
95182+{
95183+ struct page *page;
95184+ const slob_t *free;
95185+ const void *base;
95186+ unsigned long flags;
95187+
95188+ if (ZERO_OR_NULL_PTR(ptr))
95189+ return "<null>";
95190+
95191+ if (!virt_addr_valid(ptr))
95192+ return NULL;
95193+
95194+ page = virt_to_head_page(ptr);
95195+ if (!PageSlab(page))
95196+ return NULL;
95197+
95198+ if (page->private) {
95199+ base = page;
95200+ if (base <= ptr && n <= page->private - (ptr - base))
95201+ return NULL;
95202+ return "<slob>";
95203+ }
95204+
95205+ /* some tricky double walking to find the chunk */
95206+ spin_lock_irqsave(&slob_lock, flags);
95207+ base = (void *)((unsigned long)ptr & PAGE_MASK);
95208+ free = page->freelist;
95209+
95210+ while (!slob_last(free) && (void *)free <= ptr) {
95211+ base = free + slob_units(free);
95212+ free = slob_next(free);
95213+ }
95214+
95215+ while (base < (void *)free) {
95216+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
95217+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
95218+ int offset;
95219+
95220+ if (ptr < base + align)
95221+ break;
95222+
95223+ offset = ptr - base - align;
95224+ if (offset >= m) {
95225+ base += size;
95226+ continue;
95227+ }
95228+
95229+ if (n > m - offset)
95230+ break;
95231+
95232+ spin_unlock_irqrestore(&slob_lock, flags);
95233+ return NULL;
95234+ }
95235+
95236+ spin_unlock_irqrestore(&slob_lock, flags);
95237+ return "<slob>";
95238+}
95239+#endif
95240+
95241 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
95242 size_t ksize(const void *block)
95243 {
95244 struct page *sp;
95245 int align;
95246- unsigned int *m;
95247+ slob_t *m;
95248
95249 BUG_ON(!block);
95250 if (unlikely(block == ZERO_SIZE_PTR))
95251 return 0;
95252
95253 sp = virt_to_page(block);
95254- if (unlikely(!PageSlab(sp)))
95255- return PAGE_SIZE << compound_order(sp);
95256+ VM_BUG_ON(!PageSlab(sp));
95257+ if (sp->private)
95258+ return sp->private;
95259
95260 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
95261- m = (unsigned int *)(block - align);
95262- return SLOB_UNITS(*m) * SLOB_UNIT;
95263+ m = (slob_t *)(block - align);
95264+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
95265 }
95266 EXPORT_SYMBOL(ksize);
95267
95268@@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
95269
95270 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
95271 {
95272- void *b;
95273+ void *b = NULL;
95274
95275 flags &= gfp_allowed_mask;
95276
95277 lockdep_trace_alloc(flags);
95278
95279+#ifdef CONFIG_PAX_USERCOPY_SLABS
95280+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
95281+#else
95282 if (c->size < PAGE_SIZE) {
95283 b = slob_alloc(c->size, flags, c->align, node);
95284 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95285 SLOB_UNITS(c->size) * SLOB_UNIT,
95286 flags, node);
95287 } else {
95288- b = slob_new_pages(flags, get_order(c->size), node);
95289+ struct page *sp;
95290+
95291+ sp = slob_new_pages(flags, get_order(c->size), node);
95292+ if (sp) {
95293+ b = page_address(sp);
95294+ sp->private = c->size;
95295+ }
95296 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
95297 PAGE_SIZE << get_order(c->size),
95298 flags, node);
95299 }
95300+#endif
95301
95302 if (b && c->ctor)
95303 c->ctor(b);
95304@@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
95305
95306 static void __kmem_cache_free(void *b, int size)
95307 {
95308- if (size < PAGE_SIZE)
95309+ struct page *sp;
95310+
95311+ sp = virt_to_page(b);
95312+ BUG_ON(!PageSlab(sp));
95313+ if (!sp->private)
95314 slob_free(b, size);
95315 else
95316- slob_free_pages(b, get_order(size));
95317+ slob_free_pages(sp, get_order(size));
95318 }
95319
95320 static void kmem_rcu_free(struct rcu_head *head)
95321@@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
95322
95323 void kmem_cache_free(struct kmem_cache *c, void *b)
95324 {
95325+ int size = c->size;
95326+
95327+#ifdef CONFIG_PAX_USERCOPY_SLABS
95328+ if (size + c->align < PAGE_SIZE) {
95329+ size += c->align;
95330+ b -= c->align;
95331+ }
95332+#endif
95333+
95334 kmemleak_free_recursive(b, c->flags);
95335 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
95336 struct slob_rcu *slob_rcu;
95337- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
95338- slob_rcu->size = c->size;
95339+ slob_rcu = b + (size - sizeof(struct slob_rcu));
95340+ slob_rcu->size = size;
95341 call_rcu(&slob_rcu->head, kmem_rcu_free);
95342 } else {
95343- __kmem_cache_free(b, c->size);
95344+ __kmem_cache_free(b, size);
95345 }
95346
95347+#ifdef CONFIG_PAX_USERCOPY_SLABS
95348+ trace_kfree(_RET_IP_, b);
95349+#else
95350 trace_kmem_cache_free(_RET_IP_, b);
95351+#endif
95352+
95353 }
95354 EXPORT_SYMBOL(kmem_cache_free);
95355
95356diff --git a/mm/slub.c b/mm/slub.c
95357index 89490d9..c7b226a 100644
95358--- a/mm/slub.c
95359+++ b/mm/slub.c
95360@@ -207,7 +207,7 @@ struct track {
95361
95362 enum track_item { TRACK_ALLOC, TRACK_FREE };
95363
95364-#ifdef CONFIG_SYSFS
95365+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95366 static int sysfs_slab_add(struct kmem_cache *);
95367 static int sysfs_slab_alias(struct kmem_cache *, const char *);
95368 static void sysfs_slab_remove(struct kmem_cache *);
95369@@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
95370 if (!t->addr)
95371 return;
95372
95373- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
95374+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
95375 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
95376 #ifdef CONFIG_STACKTRACE
95377 {
95378@@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
95379
95380 slab_free_hook(s, x);
95381
95382+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95383+ if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
95384+ memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
95385+ if (s->ctor)
95386+ s->ctor(x);
95387+ }
95388+#endif
95389+
95390 redo:
95391 /*
95392 * Determine the currently cpus per cpu slab.
95393@@ -2710,7 +2718,7 @@ static int slub_min_objects;
95394 * Merge control. If this is set then no merging of slab caches will occur.
95395 * (Could be removed. This was introduced to pacify the merge skeptics.)
95396 */
95397-static int slub_nomerge;
95398+static int slub_nomerge = 1;
95399
95400 /*
95401 * Calculate the order of allocation given an slab object size.
95402@@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
95403 s->inuse = size;
95404
95405 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
95406+#ifdef CONFIG_PAX_MEMORY_SANITIZE
95407+ (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
95408+#endif
95409 s->ctor)) {
95410 /*
95411 * Relocate free pointer after the object if it is not
95412@@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
95413 EXPORT_SYMBOL(__kmalloc_node);
95414 #endif
95415
95416+bool is_usercopy_object(const void *ptr)
95417+{
95418+ struct page *page;
95419+ struct kmem_cache *s;
95420+
95421+ if (ZERO_OR_NULL_PTR(ptr))
95422+ return false;
95423+
95424+ if (!slab_is_available())
95425+ return false;
95426+
95427+ if (!virt_addr_valid(ptr))
95428+ return false;
95429+
95430+ page = virt_to_head_page(ptr);
95431+
95432+ if (!PageSlab(page))
95433+ return false;
95434+
95435+ s = page->slab_cache;
95436+ return s->flags & SLAB_USERCOPY;
95437+}
95438+
95439+#ifdef CONFIG_PAX_USERCOPY
95440+const char *check_heap_object(const void *ptr, unsigned long n)
95441+{
95442+ struct page *page;
95443+ struct kmem_cache *s;
95444+ unsigned long offset;
95445+
95446+ if (ZERO_OR_NULL_PTR(ptr))
95447+ return "<null>";
95448+
95449+ if (!virt_addr_valid(ptr))
95450+ return NULL;
95451+
95452+ page = virt_to_head_page(ptr);
95453+
95454+ if (!PageSlab(page))
95455+ return NULL;
95456+
95457+ s = page->slab_cache;
95458+ if (!(s->flags & SLAB_USERCOPY))
95459+ return s->name;
95460+
95461+ offset = (ptr - page_address(page)) % s->size;
95462+ if (offset <= s->object_size && n <= s->object_size - offset)
95463+ return NULL;
95464+
95465+ return s->name;
95466+}
95467+#endif
95468+
95469 size_t ksize(const void *object)
95470 {
95471 struct page *page;
95472@@ -3360,6 +3424,7 @@ void kfree(const void *x)
95473 if (unlikely(ZERO_OR_NULL_PTR(x)))
95474 return;
95475
95476+ VM_BUG_ON(!virt_addr_valid(x));
95477 page = virt_to_head_page(x);
95478 if (unlikely(!PageSlab(page))) {
95479 BUG_ON(!PageCompound(page));
95480@@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
95481 /*
95482 * We may have set a slab to be unmergeable during bootstrap.
95483 */
95484- if (s->refcount < 0)
95485+ if (atomic_read(&s->refcount) < 0)
95486 return 1;
95487
95488 return 0;
95489@@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95490
95491 s = find_mergeable(memcg, size, align, flags, name, ctor);
95492 if (s) {
95493- s->refcount++;
95494+ atomic_inc(&s->refcount);
95495 /*
95496 * Adjust the object sizes so that we clear
95497 * the complete object on kzalloc.
95498@@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
95499 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
95500
95501 if (sysfs_slab_alias(s, name)) {
95502- s->refcount--;
95503+ atomic_dec(&s->refcount);
95504 s = NULL;
95505 }
95506 }
95507@@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
95508 }
95509 #endif
95510
95511-#ifdef CONFIG_SYSFS
95512+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95513 static int count_inuse(struct page *page)
95514 {
95515 return page->inuse;
95516@@ -4241,12 +4306,12 @@ static void resiliency_test(void)
95517 validate_slab_cache(kmalloc_caches[9]);
95518 }
95519 #else
95520-#ifdef CONFIG_SYSFS
95521+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95522 static void resiliency_test(void) {};
95523 #endif
95524 #endif
95525
95526-#ifdef CONFIG_SYSFS
95527+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95528 enum slab_stat_type {
95529 SL_ALL, /* All slabs */
95530 SL_PARTIAL, /* Only partially allocated slabs */
95531@@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
95532
95533 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
95534 {
95535- return sprintf(buf, "%d\n", s->refcount - 1);
95536+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
95537 }
95538 SLAB_ATTR_RO(aliases);
95539
95540@@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
95541 SLAB_ATTR_RO(cache_dma);
95542 #endif
95543
95544+#ifdef CONFIG_PAX_USERCOPY_SLABS
95545+static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
95546+{
95547+ return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
95548+}
95549+SLAB_ATTR_RO(usercopy);
95550+#endif
95551+
95552 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
95553 {
95554 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
95555@@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
95556 #ifdef CONFIG_ZONE_DMA
95557 &cache_dma_attr.attr,
95558 #endif
95559+#ifdef CONFIG_PAX_USERCOPY_SLABS
95560+ &usercopy_attr.attr,
95561+#endif
95562 #ifdef CONFIG_NUMA
95563 &remote_node_defrag_ratio_attr.attr,
95564 #endif
95565@@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
95566 return name;
95567 }
95568
95569+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95570 static int sysfs_slab_add(struct kmem_cache *s)
95571 {
95572 int err;
95573@@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
95574 }
95575
95576 s->kobj.kset = slab_kset;
95577- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
95578+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
95579 if (err) {
95580 kobject_put(&s->kobj);
95581 return err;
95582@@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
95583 kobject_del(&s->kobj);
95584 kobject_put(&s->kobj);
95585 }
95586+#endif
95587
95588 /*
95589 * Need to buffer aliases during bootup until sysfs becomes
95590@@ -5216,6 +5294,7 @@ struct saved_alias {
95591
95592 static struct saved_alias *alias_list;
95593
95594+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
95595 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95596 {
95597 struct saved_alias *al;
95598@@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
95599 alias_list = al;
95600 return 0;
95601 }
95602+#endif
95603
95604 static int __init slab_sysfs_init(void)
95605 {
95606diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
95607index 27eeab3..7c3f7f2 100644
95608--- a/mm/sparse-vmemmap.c
95609+++ b/mm/sparse-vmemmap.c
95610@@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
95611 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95612 if (!p)
95613 return NULL;
95614- pud_populate(&init_mm, pud, p);
95615+ pud_populate_kernel(&init_mm, pud, p);
95616 }
95617 return pud;
95618 }
95619@@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
95620 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
95621 if (!p)
95622 return NULL;
95623- pgd_populate(&init_mm, pgd, p);
95624+ pgd_populate_kernel(&init_mm, pgd, p);
95625 }
95626 return pgd;
95627 }
95628diff --git a/mm/sparse.c b/mm/sparse.c
95629index 8cc7be0..d0f7d7a 100644
95630--- a/mm/sparse.c
95631+++ b/mm/sparse.c
95632@@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
95633
95634 for (i = 0; i < PAGES_PER_SECTION; i++) {
95635 if (PageHWPoison(&memmap[i])) {
95636- atomic_long_sub(1, &num_poisoned_pages);
95637+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
95638 ClearPageHWPoison(&memmap[i]);
95639 }
95640 }
95641diff --git a/mm/swap.c b/mm/swap.c
95642index 7010cf4..f0a56a4 100644
95643--- a/mm/swap.c
95644+++ b/mm/swap.c
95645@@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
95646
95647 __page_cache_release(page);
95648 dtor = get_compound_page_dtor(page);
95649+ if (!PageHuge(page))
95650+ BUG_ON(dtor != free_compound_page);
95651 (*dtor)(page);
95652 }
95653
95654diff --git a/mm/swapfile.c b/mm/swapfile.c
95655index 461fce2..363ae44 100644
95656--- a/mm/swapfile.c
95657+++ b/mm/swapfile.c
95658@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
95659
95660 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
95661 /* Activity counter to indicate that a swapon or swapoff has occurred */
95662-static atomic_t proc_poll_event = ATOMIC_INIT(0);
95663+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
95664
95665 static inline unsigned char swap_count(unsigned char ent)
95666 {
95667@@ -1958,7 +1958,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
95668 spin_unlock(&swap_lock);
95669
95670 err = 0;
95671- atomic_inc(&proc_poll_event);
95672+ atomic_inc_unchecked(&proc_poll_event);
95673 wake_up_interruptible(&proc_poll_wait);
95674
95675 out_dput:
95676@@ -1975,8 +1975,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
95677
95678 poll_wait(file, &proc_poll_wait, wait);
95679
95680- if (seq->poll_event != atomic_read(&proc_poll_event)) {
95681- seq->poll_event = atomic_read(&proc_poll_event);
95682+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
95683+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95684 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
95685 }
95686
95687@@ -2074,7 +2074,7 @@ static int swaps_open(struct inode *inode, struct file *file)
95688 return ret;
95689
95690 seq = file->private_data;
95691- seq->poll_event = atomic_read(&proc_poll_event);
95692+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
95693 return 0;
95694 }
95695
95696@@ -2533,7 +2533,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
95697 (frontswap_map) ? "FS" : "");
95698
95699 mutex_unlock(&swapon_mutex);
95700- atomic_inc(&proc_poll_event);
95701+ atomic_inc_unchecked(&proc_poll_event);
95702 wake_up_interruptible(&proc_poll_wait);
95703
95704 if (S_ISREG(inode->i_mode))
95705diff --git a/mm/util.c b/mm/util.c
95706index 808f375..e4764b5 100644
95707--- a/mm/util.c
95708+++ b/mm/util.c
95709@@ -297,6 +297,12 @@ done:
95710 void arch_pick_mmap_layout(struct mm_struct *mm)
95711 {
95712 mm->mmap_base = TASK_UNMAPPED_BASE;
95713+
95714+#ifdef CONFIG_PAX_RANDMMAP
95715+ if (mm->pax_flags & MF_PAX_RANDMMAP)
95716+ mm->mmap_base += mm->delta_mmap;
95717+#endif
95718+
95719 mm->get_unmapped_area = arch_get_unmapped_area;
95720 }
95721 #endif
95722diff --git a/mm/vmalloc.c b/mm/vmalloc.c
95723index 0fdf968..d6686e8 100644
95724--- a/mm/vmalloc.c
95725+++ b/mm/vmalloc.c
95726@@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
95727
95728 pte = pte_offset_kernel(pmd, addr);
95729 do {
95730- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95731- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95732+
95733+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95734+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
95735+ BUG_ON(!pte_exec(*pte));
95736+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
95737+ continue;
95738+ }
95739+#endif
95740+
95741+ {
95742+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
95743+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
95744+ }
95745 } while (pte++, addr += PAGE_SIZE, addr != end);
95746 }
95747
95748@@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
95749 pte = pte_alloc_kernel(pmd, addr);
95750 if (!pte)
95751 return -ENOMEM;
95752+
95753+ pax_open_kernel();
95754 do {
95755 struct page *page = pages[*nr];
95756
95757- if (WARN_ON(!pte_none(*pte)))
95758+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95759+ if (pgprot_val(prot) & _PAGE_NX)
95760+#endif
95761+
95762+ if (!pte_none(*pte)) {
95763+ pax_close_kernel();
95764+ WARN_ON(1);
95765 return -EBUSY;
95766- if (WARN_ON(!page))
95767+ }
95768+ if (!page) {
95769+ pax_close_kernel();
95770+ WARN_ON(1);
95771 return -ENOMEM;
95772+ }
95773 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
95774 (*nr)++;
95775 } while (pte++, addr += PAGE_SIZE, addr != end);
95776+ pax_close_kernel();
95777 return 0;
95778 }
95779
95780@@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
95781 pmd_t *pmd;
95782 unsigned long next;
95783
95784- pmd = pmd_alloc(&init_mm, pud, addr);
95785+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
95786 if (!pmd)
95787 return -ENOMEM;
95788 do {
95789@@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
95790 pud_t *pud;
95791 unsigned long next;
95792
95793- pud = pud_alloc(&init_mm, pgd, addr);
95794+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
95795 if (!pud)
95796 return -ENOMEM;
95797 do {
95798@@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
95799 if (addr >= MODULES_VADDR && addr < MODULES_END)
95800 return 1;
95801 #endif
95802+
95803+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
95804+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
95805+ return 1;
95806+#endif
95807+
95808 return is_vmalloc_addr(x);
95809 }
95810
95811@@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
95812
95813 if (!pgd_none(*pgd)) {
95814 pud_t *pud = pud_offset(pgd, addr);
95815+#ifdef CONFIG_X86
95816+ if (!pud_large(*pud))
95817+#endif
95818 if (!pud_none(*pud)) {
95819 pmd_t *pmd = pmd_offset(pud, addr);
95820+#ifdef CONFIG_X86
95821+ if (!pmd_large(*pmd))
95822+#endif
95823 if (!pmd_none(*pmd)) {
95824 pte_t *ptep, pte;
95825
95826@@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
95827 struct vm_struct *area;
95828
95829 BUG_ON(in_interrupt());
95830+
95831+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95832+ if (flags & VM_KERNEXEC) {
95833+ if (start != VMALLOC_START || end != VMALLOC_END)
95834+ return NULL;
95835+ start = (unsigned long)MODULES_EXEC_VADDR;
95836+ end = (unsigned long)MODULES_EXEC_END;
95837+ }
95838+#endif
95839+
95840 if (flags & VM_IOREMAP)
95841 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
95842
95843@@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
95844 if (count > totalram_pages)
95845 return NULL;
95846
95847+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95848+ if (!(pgprot_val(prot) & _PAGE_NX))
95849+ flags |= VM_KERNEXEC;
95850+#endif
95851+
95852 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
95853 __builtin_return_address(0));
95854 if (!area)
95855@@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
95856 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
95857 goto fail;
95858
95859+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
95860+ if (!(pgprot_val(prot) & _PAGE_NX))
95861+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
95862+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
95863+ else
95864+#endif
95865+
95866 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
95867 start, end, node, gfp_mask, caller);
95868 if (!area)
95869@@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
95870 * For tight control over page level allocator and protection flags
95871 * use __vmalloc() instead.
95872 */
95873-
95874 void *vmalloc_exec(unsigned long size)
95875 {
95876- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
95877+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
95878 NUMA_NO_NODE, __builtin_return_address(0));
95879 }
95880
95881@@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
95882 {
95883 struct vm_struct *area;
95884
95885+ BUG_ON(vma->vm_mirror);
95886+
95887 size = PAGE_ALIGN(size);
95888
95889 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
95890@@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
95891 v->addr, v->addr + v->size, v->size);
95892
95893 if (v->caller)
95894+#ifdef CONFIG_GRKERNSEC_HIDESYM
95895+ seq_printf(m, " %pK", v->caller);
95896+#else
95897 seq_printf(m, " %pS", v->caller);
95898+#endif
95899
95900 if (v->nr_pages)
95901 seq_printf(m, " pages=%d", v->nr_pages);
95902diff --git a/mm/vmstat.c b/mm/vmstat.c
95903index 7249614..2639fc7 100644
95904--- a/mm/vmstat.c
95905+++ b/mm/vmstat.c
95906@@ -20,6 +20,7 @@
95907 #include <linux/writeback.h>
95908 #include <linux/compaction.h>
95909 #include <linux/mm_inline.h>
95910+#include <linux/grsecurity.h>
95911
95912 #include "internal.h"
95913
95914@@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
95915 *
95916 * vm_stat contains the global counters
95917 */
95918-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95919+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
95920 EXPORT_SYMBOL(vm_stat);
95921
95922 #ifdef CONFIG_SMP
95923@@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
95924
95925 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95926 if (diff[i])
95927- atomic_long_add(diff[i], &vm_stat[i]);
95928+ atomic_long_add_unchecked(diff[i], &vm_stat[i]);
95929 }
95930
95931 /*
95932@@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
95933 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
95934 if (v) {
95935
95936- atomic_long_add(v, &zone->vm_stat[i]);
95937+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95938 global_diff[i] += v;
95939 #ifdef CONFIG_NUMA
95940 /* 3 seconds idle till flush */
95941@@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
95942
95943 v = p->vm_stat_diff[i];
95944 p->vm_stat_diff[i] = 0;
95945- atomic_long_add(v, &zone->vm_stat[i]);
95946+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95947 global_diff[i] += v;
95948 }
95949 }
95950@@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
95951 if (pset->vm_stat_diff[i]) {
95952 int v = pset->vm_stat_diff[i];
95953 pset->vm_stat_diff[i] = 0;
95954- atomic_long_add(v, &zone->vm_stat[i]);
95955- atomic_long_add(v, &vm_stat[i]);
95956+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
95957+ atomic_long_add_unchecked(v, &vm_stat[i]);
95958 }
95959 }
95960 #endif
95961@@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
95962 stat_items_size += sizeof(struct vm_event_state);
95963 #endif
95964
95965- v = kmalloc(stat_items_size, GFP_KERNEL);
95966+ v = kzalloc(stat_items_size, GFP_KERNEL);
95967 m->private = v;
95968 if (!v)
95969 return ERR_PTR(-ENOMEM);
95970+
95971+#ifdef CONFIG_GRKERNSEC_PROC_ADD
95972+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
95973+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
95974+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
95975+ && !in_group_p(grsec_proc_gid)
95976+#endif
95977+ )
95978+ return (unsigned long *)m->private + *pos;
95979+#endif
95980+#endif
95981+
95982 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
95983 v[i] = global_page_state(i);
95984 v += NR_VM_ZONE_STAT_ITEMS;
95985@@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
95986 put_online_cpus();
95987 #endif
95988 #ifdef CONFIG_PROC_FS
95989- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
95990- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
95991- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
95992- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
95993+ {
95994+ mode_t gr_mode = S_IRUGO;
95995+#ifdef CONFIG_GRKERNSEC_PROC_ADD
95996+ gr_mode = S_IRUSR;
95997+#endif
95998+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
95999+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
96000+ proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
96001+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
96002+ }
96003 #endif
96004 return 0;
96005 }
96006diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
96007index 9a87f5a..67aeeb2 100644
96008--- a/net/8021q/vlan.c
96009+++ b/net/8021q/vlan.c
96010@@ -474,7 +474,7 @@ out:
96011 return NOTIFY_DONE;
96012 }
96013
96014-static struct notifier_block vlan_notifier_block __read_mostly = {
96015+static struct notifier_block vlan_notifier_block = {
96016 .notifier_call = vlan_device_event,
96017 };
96018
96019@@ -549,8 +549,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
96020 err = -EPERM;
96021 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
96022 break;
96023- if ((args.u.name_type >= 0) &&
96024- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
96025+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
96026 struct vlan_net *vn;
96027
96028 vn = net_generic(net, vlan_net_id);
96029diff --git a/net/9p/client.c b/net/9p/client.c
96030index ee8fd6b..0469d50 100644
96031--- a/net/9p/client.c
96032+++ b/net/9p/client.c
96033@@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
96034 len - inline_len);
96035 } else {
96036 err = copy_from_user(ename + inline_len,
96037- uidata, len - inline_len);
96038+ (char __force_user *)uidata, len - inline_len);
96039 if (err) {
96040 err = -EFAULT;
96041 goto out_err;
96042@@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
96043 kernel_buf = 1;
96044 indata = data;
96045 } else
96046- indata = (__force char *)udata;
96047+ indata = (__force_kernel char *)udata;
96048 /*
96049 * response header len is 11
96050 * PDU Header(7) + IO Size (4)
96051@@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
96052 kernel_buf = 1;
96053 odata = data;
96054 } else
96055- odata = (char *)udata;
96056+ odata = (char __force_kernel *)udata;
96057 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
96058 P9_ZC_HDR_SZ, kernel_buf, "dqd",
96059 fid->fid, offset, rsize);
96060diff --git a/net/9p/mod.c b/net/9p/mod.c
96061index 6ab36ae..6f1841b 100644
96062--- a/net/9p/mod.c
96063+++ b/net/9p/mod.c
96064@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
96065 void v9fs_register_trans(struct p9_trans_module *m)
96066 {
96067 spin_lock(&v9fs_trans_lock);
96068- list_add_tail(&m->list, &v9fs_trans_list);
96069+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
96070 spin_unlock(&v9fs_trans_lock);
96071 }
96072 EXPORT_SYMBOL(v9fs_register_trans);
96073@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
96074 void v9fs_unregister_trans(struct p9_trans_module *m)
96075 {
96076 spin_lock(&v9fs_trans_lock);
96077- list_del_init(&m->list);
96078+ pax_list_del_init((struct list_head *)&m->list);
96079 spin_unlock(&v9fs_trans_lock);
96080 }
96081 EXPORT_SYMBOL(v9fs_unregister_trans);
96082diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
96083index 9321a77..ed2f256 100644
96084--- a/net/9p/trans_fd.c
96085+++ b/net/9p/trans_fd.c
96086@@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
96087 oldfs = get_fs();
96088 set_fs(get_ds());
96089 /* The cast to a user pointer is valid due to the set_fs() */
96090- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
96091+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
96092 set_fs(oldfs);
96093
96094 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
96095diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
96096index 876fbe8..8bbea9f 100644
96097--- a/net/atm/atm_misc.c
96098+++ b/net/atm/atm_misc.c
96099@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
96100 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
96101 return 1;
96102 atm_return(vcc, truesize);
96103- atomic_inc(&vcc->stats->rx_drop);
96104+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96105 return 0;
96106 }
96107 EXPORT_SYMBOL(atm_charge);
96108@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
96109 }
96110 }
96111 atm_return(vcc, guess);
96112- atomic_inc(&vcc->stats->rx_drop);
96113+ atomic_inc_unchecked(&vcc->stats->rx_drop);
96114 return NULL;
96115 }
96116 EXPORT_SYMBOL(atm_alloc_charge);
96117@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
96118
96119 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96120 {
96121-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96122+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96123 __SONET_ITEMS
96124 #undef __HANDLE_ITEM
96125 }
96126@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
96127
96128 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
96129 {
96130-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96131+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
96132 __SONET_ITEMS
96133 #undef __HANDLE_ITEM
96134 }
96135diff --git a/net/atm/lec.c b/net/atm/lec.c
96136index f23916b..dd4d26b 100644
96137--- a/net/atm/lec.c
96138+++ b/net/atm/lec.c
96139@@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
96140 }
96141
96142 static struct lane2_ops lane2_ops = {
96143- lane2_resolve, /* resolve, spec 3.1.3 */
96144- lane2_associate_req, /* associate_req, spec 3.1.4 */
96145- NULL /* associate indicator, spec 3.1.5 */
96146+ .resolve = lane2_resolve,
96147+ .associate_req = lane2_associate_req,
96148+ .associate_indicator = NULL
96149 };
96150
96151 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
96152diff --git a/net/atm/lec.h b/net/atm/lec.h
96153index 4149db1..f2ab682 100644
96154--- a/net/atm/lec.h
96155+++ b/net/atm/lec.h
96156@@ -48,7 +48,7 @@ struct lane2_ops {
96157 const u8 *tlvs, u32 sizeoftlvs);
96158 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
96159 const u8 *tlvs, u32 sizeoftlvs);
96160-};
96161+} __no_const;
96162
96163 /*
96164 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
96165diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
96166index d1b2d9a..d549f7f 100644
96167--- a/net/atm/mpoa_caches.c
96168+++ b/net/atm/mpoa_caches.c
96169@@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
96170
96171
96172 static struct in_cache_ops ingress_ops = {
96173- in_cache_add_entry, /* add_entry */
96174- in_cache_get, /* get */
96175- in_cache_get_with_mask, /* get_with_mask */
96176- in_cache_get_by_vcc, /* get_by_vcc */
96177- in_cache_put, /* put */
96178- in_cache_remove_entry, /* remove_entry */
96179- cache_hit, /* cache_hit */
96180- clear_count_and_expired, /* clear_count */
96181- check_resolving_entries, /* check_resolving */
96182- refresh_entries, /* refresh */
96183- in_destroy_cache /* destroy_cache */
96184+ .add_entry = in_cache_add_entry,
96185+ .get = in_cache_get,
96186+ .get_with_mask = in_cache_get_with_mask,
96187+ .get_by_vcc = in_cache_get_by_vcc,
96188+ .put = in_cache_put,
96189+ .remove_entry = in_cache_remove_entry,
96190+ .cache_hit = cache_hit,
96191+ .clear_count = clear_count_and_expired,
96192+ .check_resolving = check_resolving_entries,
96193+ .refresh = refresh_entries,
96194+ .destroy_cache = in_destroy_cache
96195 };
96196
96197 static struct eg_cache_ops egress_ops = {
96198- eg_cache_add_entry, /* add_entry */
96199- eg_cache_get_by_cache_id, /* get_by_cache_id */
96200- eg_cache_get_by_tag, /* get_by_tag */
96201- eg_cache_get_by_vcc, /* get_by_vcc */
96202- eg_cache_get_by_src_ip, /* get_by_src_ip */
96203- eg_cache_put, /* put */
96204- eg_cache_remove_entry, /* remove_entry */
96205- update_eg_cache_entry, /* update */
96206- clear_expired, /* clear_expired */
96207- eg_destroy_cache /* destroy_cache */
96208+ .add_entry = eg_cache_add_entry,
96209+ .get_by_cache_id = eg_cache_get_by_cache_id,
96210+ .get_by_tag = eg_cache_get_by_tag,
96211+ .get_by_vcc = eg_cache_get_by_vcc,
96212+ .get_by_src_ip = eg_cache_get_by_src_ip,
96213+ .put = eg_cache_put,
96214+ .remove_entry = eg_cache_remove_entry,
96215+ .update = update_eg_cache_entry,
96216+ .clear_expired = clear_expired,
96217+ .destroy_cache = eg_destroy_cache
96218 };
96219
96220
96221diff --git a/net/atm/proc.c b/net/atm/proc.c
96222index bbb6461..cf04016 100644
96223--- a/net/atm/proc.c
96224+++ b/net/atm/proc.c
96225@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
96226 const struct k_atm_aal_stats *stats)
96227 {
96228 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
96229- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
96230- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
96231- atomic_read(&stats->rx_drop));
96232+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
96233+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
96234+ atomic_read_unchecked(&stats->rx_drop));
96235 }
96236
96237 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
96238diff --git a/net/atm/resources.c b/net/atm/resources.c
96239index 0447d5d..3cf4728 100644
96240--- a/net/atm/resources.c
96241+++ b/net/atm/resources.c
96242@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
96243 static void copy_aal_stats(struct k_atm_aal_stats *from,
96244 struct atm_aal_stats *to)
96245 {
96246-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
96247+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
96248 __AAL_STAT_ITEMS
96249 #undef __HANDLE_ITEM
96250 }
96251@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
96252 static void subtract_aal_stats(struct k_atm_aal_stats *from,
96253 struct atm_aal_stats *to)
96254 {
96255-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
96256+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
96257 __AAL_STAT_ITEMS
96258 #undef __HANDLE_ITEM
96259 }
96260diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
96261index 919a5ce..cc6b444 100644
96262--- a/net/ax25/sysctl_net_ax25.c
96263+++ b/net/ax25/sysctl_net_ax25.c
96264@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
96265 {
96266 char path[sizeof("net/ax25/") + IFNAMSIZ];
96267 int k;
96268- struct ctl_table *table;
96269+ ctl_table_no_const *table;
96270
96271 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
96272 if (!table)
96273diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
96274index f7270b9..cd0d879 100644
96275--- a/net/batman-adv/bat_iv_ogm.c
96276+++ b/net/batman-adv/bat_iv_ogm.c
96277@@ -307,7 +307,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
96278
96279 /* randomize initial seqno to avoid collision */
96280 get_random_bytes(&random_seqno, sizeof(random_seqno));
96281- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96282+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
96283
96284 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
96285 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
96286@@ -894,9 +894,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
96287 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
96288
96289 /* change sequence number to network order */
96290- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
96291+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
96292 batadv_ogm_packet->seqno = htonl(seqno);
96293- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
96294+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
96295
96296 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
96297 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
96298@@ -1261,7 +1261,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
96299 return;
96300
96301 /* could be changed by schedule_own_packet() */
96302- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
96303+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
96304
96305 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
96306 has_directlink_flag = 1;
96307diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
96308index 6ddb614..ca7e886 100644
96309--- a/net/batman-adv/fragmentation.c
96310+++ b/net/batman-adv/fragmentation.c
96311@@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
96312 frag_header.packet_type = BATADV_UNICAST_FRAG;
96313 frag_header.version = BATADV_COMPAT_VERSION;
96314 frag_header.ttl = BATADV_TTL;
96315- frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
96316+ frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
96317 frag_header.reserved = 0;
96318 frag_header.no = 0;
96319 frag_header.total_size = htons(skb->len);
96320diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
96321index a8f99d1..11797ef 100644
96322--- a/net/batman-adv/soft-interface.c
96323+++ b/net/batman-adv/soft-interface.c
96324@@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
96325 primary_if->net_dev->dev_addr, ETH_ALEN);
96326
96327 /* set broadcast sequence number */
96328- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
96329+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
96330 bcast_packet->seqno = htonl(seqno);
96331
96332 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
96333@@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96334 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
96335
96336 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
96337- atomic_set(&bat_priv->bcast_seqno, 1);
96338+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
96339 atomic_set(&bat_priv->tt.vn, 0);
96340 atomic_set(&bat_priv->tt.local_changes, 0);
96341 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
96342@@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
96343
96344 /* randomize initial seqno to avoid collision */
96345 get_random_bytes(&random_seqno, sizeof(random_seqno));
96346- atomic_set(&bat_priv->frag_seqno, random_seqno);
96347+ atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
96348
96349 bat_priv->primary_if = NULL;
96350 bat_priv->num_ifaces = 0;
96351diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
96352index 91dd369..9c25750 100644
96353--- a/net/batman-adv/types.h
96354+++ b/net/batman-adv/types.h
96355@@ -56,7 +56,7 @@
96356 struct batadv_hard_iface_bat_iv {
96357 unsigned char *ogm_buff;
96358 int ogm_buff_len;
96359- atomic_t ogm_seqno;
96360+ atomic_unchecked_t ogm_seqno;
96361 };
96362
96363 /**
96364@@ -673,7 +673,7 @@ struct batadv_priv {
96365 atomic_t bonding;
96366 atomic_t fragmentation;
96367 atomic_t packet_size_max;
96368- atomic_t frag_seqno;
96369+ atomic_unchecked_t frag_seqno;
96370 #ifdef CONFIG_BATMAN_ADV_BLA
96371 atomic_t bridge_loop_avoidance;
96372 #endif
96373@@ -687,7 +687,7 @@ struct batadv_priv {
96374 #ifdef CONFIG_BATMAN_ADV_DEBUG
96375 atomic_t log_level;
96376 #endif
96377- atomic_t bcast_seqno;
96378+ atomic_unchecked_t bcast_seqno;
96379 atomic_t bcast_queue_left;
96380 atomic_t batman_queue_left;
96381 char num_ifaces;
96382diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
96383index 7552f9e..074ce29 100644
96384--- a/net/bluetooth/hci_sock.c
96385+++ b/net/bluetooth/hci_sock.c
96386@@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
96387 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
96388 }
96389
96390- len = min_t(unsigned int, len, sizeof(uf));
96391+ len = min((size_t)len, sizeof(uf));
96392 if (copy_from_user(&uf, optval, len)) {
96393 err = -EFAULT;
96394 break;
96395diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
96396index 4af3821..f2ba46c 100644
96397--- a/net/bluetooth/l2cap_core.c
96398+++ b/net/bluetooth/l2cap_core.c
96399@@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
96400 break;
96401
96402 case L2CAP_CONF_RFC:
96403- if (olen == sizeof(rfc))
96404- memcpy(&rfc, (void *)val, olen);
96405+ if (olen != sizeof(rfc))
96406+ break;
96407+
96408+ memcpy(&rfc, (void *)val, olen);
96409
96410 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
96411 rfc.mode != chan->mode)
96412diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
96413index 7cc24d2..e83f531 100644
96414--- a/net/bluetooth/l2cap_sock.c
96415+++ b/net/bluetooth/l2cap_sock.c
96416@@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96417 struct sock *sk = sock->sk;
96418 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
96419 struct l2cap_options opts;
96420- int len, err = 0;
96421+ int err = 0;
96422+ size_t len = optlen;
96423 u32 opt;
96424
96425 BT_DBG("sk %p", sk);
96426@@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
96427 opts.max_tx = chan->max_tx;
96428 opts.txwin_size = chan->tx_win;
96429
96430- len = min_t(unsigned int, sizeof(opts), optlen);
96431+ len = min(sizeof(opts), len);
96432 if (copy_from_user((char *) &opts, optval, len)) {
96433 err = -EFAULT;
96434 break;
96435@@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96436 struct bt_security sec;
96437 struct bt_power pwr;
96438 struct l2cap_conn *conn;
96439- int len, err = 0;
96440+ int err = 0;
96441+ size_t len = optlen;
96442 u32 opt;
96443
96444 BT_DBG("sk %p", sk);
96445@@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96446
96447 sec.level = BT_SECURITY_LOW;
96448
96449- len = min_t(unsigned int, sizeof(sec), optlen);
96450+ len = min(sizeof(sec), len);
96451 if (copy_from_user((char *) &sec, optval, len)) {
96452 err = -EFAULT;
96453 break;
96454@@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
96455
96456 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
96457
96458- len = min_t(unsigned int, sizeof(pwr), optlen);
96459+ len = min(sizeof(pwr), len);
96460 if (copy_from_user((char *) &pwr, optval, len)) {
96461 err = -EFAULT;
96462 break;
96463diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
96464index 3c2d3e4..884855a 100644
96465--- a/net/bluetooth/rfcomm/sock.c
96466+++ b/net/bluetooth/rfcomm/sock.c
96467@@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96468 struct sock *sk = sock->sk;
96469 struct bt_security sec;
96470 int err = 0;
96471- size_t len;
96472+ size_t len = optlen;
96473 u32 opt;
96474
96475 BT_DBG("sk %p", sk);
96476@@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
96477
96478 sec.level = BT_SECURITY_LOW;
96479
96480- len = min_t(unsigned int, sizeof(sec), optlen);
96481+ len = min(sizeof(sec), len);
96482 if (copy_from_user((char *) &sec, optval, len)) {
96483 err = -EFAULT;
96484 break;
96485diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
96486index 84fcf9f..e389b27 100644
96487--- a/net/bluetooth/rfcomm/tty.c
96488+++ b/net/bluetooth/rfcomm/tty.c
96489@@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
96490 BT_DBG("tty %p id %d", tty, tty->index);
96491
96492 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
96493- dev->channel, dev->port.count);
96494+ dev->channel, atomic_read(&dev->port.count));
96495
96496 err = tty_port_open(&dev->port, tty, filp);
96497 if (err)
96498@@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
96499 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
96500
96501 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
96502- dev->port.count);
96503+ atomic_read(&dev->port.count));
96504
96505 tty_port_close(&dev->port, tty, filp);
96506 }
96507diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
96508index ac78024..161a80c 100644
96509--- a/net/bridge/netfilter/ebtables.c
96510+++ b/net/bridge/netfilter/ebtables.c
96511@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96512 tmp.valid_hooks = t->table->valid_hooks;
96513 }
96514 mutex_unlock(&ebt_mutex);
96515- if (copy_to_user(user, &tmp, *len) != 0){
96516+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
96517 BUGPRINT("c2u Didn't work\n");
96518 ret = -EFAULT;
96519 break;
96520@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96521 goto out;
96522 tmp.valid_hooks = t->valid_hooks;
96523
96524- if (copy_to_user(user, &tmp, *len) != 0) {
96525+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96526 ret = -EFAULT;
96527 break;
96528 }
96529@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
96530 tmp.entries_size = t->table->entries_size;
96531 tmp.valid_hooks = t->table->valid_hooks;
96532
96533- if (copy_to_user(user, &tmp, *len) != 0) {
96534+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
96535 ret = -EFAULT;
96536 break;
96537 }
96538diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
96539index 0f45522..dab651f 100644
96540--- a/net/caif/cfctrl.c
96541+++ b/net/caif/cfctrl.c
96542@@ -10,6 +10,7 @@
96543 #include <linux/spinlock.h>
96544 #include <linux/slab.h>
96545 #include <linux/pkt_sched.h>
96546+#include <linux/sched.h>
96547 #include <net/caif/caif_layer.h>
96548 #include <net/caif/cfpkt.h>
96549 #include <net/caif/cfctrl.h>
96550@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
96551 memset(&dev_info, 0, sizeof(dev_info));
96552 dev_info.id = 0xff;
96553 cfsrvl_init(&this->serv, 0, &dev_info, false);
96554- atomic_set(&this->req_seq_no, 1);
96555- atomic_set(&this->rsp_seq_no, 1);
96556+ atomic_set_unchecked(&this->req_seq_no, 1);
96557+ atomic_set_unchecked(&this->rsp_seq_no, 1);
96558 this->serv.layer.receive = cfctrl_recv;
96559 sprintf(this->serv.layer.name, "ctrl");
96560 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
96561@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
96562 struct cfctrl_request_info *req)
96563 {
96564 spin_lock_bh(&ctrl->info_list_lock);
96565- atomic_inc(&ctrl->req_seq_no);
96566- req->sequence_no = atomic_read(&ctrl->req_seq_no);
96567+ atomic_inc_unchecked(&ctrl->req_seq_no);
96568+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
96569 list_add_tail(&req->list, &ctrl->list);
96570 spin_unlock_bh(&ctrl->info_list_lock);
96571 }
96572@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
96573 if (p != first)
96574 pr_warn("Requests are not received in order\n");
96575
96576- atomic_set(&ctrl->rsp_seq_no,
96577+ atomic_set_unchecked(&ctrl->rsp_seq_no,
96578 p->sequence_no);
96579 list_del(&p->list);
96580 goto out;
96581diff --git a/net/can/af_can.c b/net/can/af_can.c
96582index a27f8aa..67174a3 100644
96583--- a/net/can/af_can.c
96584+++ b/net/can/af_can.c
96585@@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
96586 };
96587
96588 /* notifier block for netdevice event */
96589-static struct notifier_block can_netdev_notifier __read_mostly = {
96590+static struct notifier_block can_netdev_notifier = {
96591 .notifier_call = can_notifier,
96592 };
96593
96594diff --git a/net/can/gw.c b/net/can/gw.c
96595index 3f9b0f3..fc6d4fa 100644
96596--- a/net/can/gw.c
96597+++ b/net/can/gw.c
96598@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
96599 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
96600
96601 static HLIST_HEAD(cgw_list);
96602-static struct notifier_block notifier;
96603
96604 static struct kmem_cache *cgw_cache __read_mostly;
96605
96606@@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
96607 return err;
96608 }
96609
96610+static struct notifier_block notifier = {
96611+ .notifier_call = cgw_notifier
96612+};
96613+
96614 static __init int cgw_module_init(void)
96615 {
96616 /* sanitize given module parameter */
96617@@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
96618 return -ENOMEM;
96619
96620 /* set notifier */
96621- notifier.notifier_call = cgw_notifier;
96622 register_netdevice_notifier(&notifier);
96623
96624 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
96625diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
96626index 464303f..9c30218 100644
96627--- a/net/ceph/messenger.c
96628+++ b/net/ceph/messenger.c
96629@@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
96630 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
96631
96632 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
96633-static atomic_t addr_str_seq = ATOMIC_INIT(0);
96634+static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
96635
96636 static struct page *zero_page; /* used in certain error cases */
96637
96638@@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
96639 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
96640 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
96641
96642- i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96643+ i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
96644 s = addr_str[i];
96645
96646 switch (ss->ss_family) {
96647diff --git a/net/compat.c b/net/compat.c
96648index f50161f..94fa415 100644
96649--- a/net/compat.c
96650+++ b/net/compat.c
96651@@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
96652 return -EFAULT;
96653 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
96654 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
96655- kmsg->msg_name = compat_ptr(tmp1);
96656- kmsg->msg_iov = compat_ptr(tmp2);
96657- kmsg->msg_control = compat_ptr(tmp3);
96658+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
96659+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
96660+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
96661 return 0;
96662 }
96663
96664@@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96665
96666 if (kern_msg->msg_namelen) {
96667 if (mode == VERIFY_READ) {
96668- int err = move_addr_to_kernel(kern_msg->msg_name,
96669+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
96670 kern_msg->msg_namelen,
96671 kern_address);
96672 if (err < 0)
96673@@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96674 kern_msg->msg_name = NULL;
96675
96676 tot_len = iov_from_user_compat_to_kern(kern_iov,
96677- (struct compat_iovec __user *)kern_msg->msg_iov,
96678+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
96679 kern_msg->msg_iovlen);
96680 if (tot_len >= 0)
96681 kern_msg->msg_iov = kern_iov;
96682@@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
96683
96684 #define CMSG_COMPAT_FIRSTHDR(msg) \
96685 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
96686- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
96687+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
96688 (struct compat_cmsghdr __user *)NULL)
96689
96690 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
96691 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
96692 (ucmlen) <= (unsigned long) \
96693 ((mhdr)->msg_controllen - \
96694- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
96695+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
96696
96697 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
96698 struct compat_cmsghdr __user *cmsg, int cmsg_len)
96699 {
96700 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
96701- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
96702+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
96703 msg->msg_controllen)
96704 return NULL;
96705 return (struct compat_cmsghdr __user *)ptr;
96706@@ -222,7 +222,7 @@ Efault:
96707
96708 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
96709 {
96710- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96711+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96712 struct compat_cmsghdr cmhdr;
96713 struct compat_timeval ctv;
96714 struct compat_timespec cts[3];
96715@@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
96716
96717 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
96718 {
96719- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
96720+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
96721 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
96722 int fdnum = scm->fp->count;
96723 struct file **fp = scm->fp->fp;
96724@@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
96725 return -EFAULT;
96726 old_fs = get_fs();
96727 set_fs(KERNEL_DS);
96728- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
96729+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
96730 set_fs(old_fs);
96731
96732 return err;
96733@@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
96734 len = sizeof(ktime);
96735 old_fs = get_fs();
96736 set_fs(KERNEL_DS);
96737- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
96738+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
96739 set_fs(old_fs);
96740
96741 if (!err) {
96742@@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96743 case MCAST_JOIN_GROUP:
96744 case MCAST_LEAVE_GROUP:
96745 {
96746- struct compat_group_req __user *gr32 = (void *)optval;
96747+ struct compat_group_req __user *gr32 = (void __user *)optval;
96748 struct group_req __user *kgr =
96749 compat_alloc_user_space(sizeof(struct group_req));
96750 u32 interface;
96751@@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96752 case MCAST_BLOCK_SOURCE:
96753 case MCAST_UNBLOCK_SOURCE:
96754 {
96755- struct compat_group_source_req __user *gsr32 = (void *)optval;
96756+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
96757 struct group_source_req __user *kgsr = compat_alloc_user_space(
96758 sizeof(struct group_source_req));
96759 u32 interface;
96760@@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
96761 }
96762 case MCAST_MSFILTER:
96763 {
96764- struct compat_group_filter __user *gf32 = (void *)optval;
96765+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96766 struct group_filter __user *kgf;
96767 u32 interface, fmode, numsrc;
96768
96769@@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
96770 char __user *optval, int __user *optlen,
96771 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
96772 {
96773- struct compat_group_filter __user *gf32 = (void *)optval;
96774+ struct compat_group_filter __user *gf32 = (void __user *)optval;
96775 struct group_filter __user *kgf;
96776 int __user *koptlen;
96777 u32 interface, fmode, numsrc;
96778@@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
96779
96780 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
96781 return -EINVAL;
96782- if (copy_from_user(a, args, nas[call]))
96783+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
96784 return -EFAULT;
96785 a0 = a[0];
96786 a1 = a[1];
96787diff --git a/net/core/datagram.c b/net/core/datagram.c
96788index a16ed7b..eb44d17 100644
96789--- a/net/core/datagram.c
96790+++ b/net/core/datagram.c
96791@@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
96792 }
96793
96794 kfree_skb(skb);
96795- atomic_inc(&sk->sk_drops);
96796+ atomic_inc_unchecked(&sk->sk_drops);
96797 sk_mem_reclaim_partial(sk);
96798
96799 return err;
96800diff --git a/net/core/dev.c b/net/core/dev.c
96801index 616eccf..31832d38 100644
96802--- a/net/core/dev.c
96803+++ b/net/core/dev.c
96804@@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
96805 {
96806 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
96807 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
96808- atomic_long_inc(&dev->rx_dropped);
96809+ atomic_long_inc_unchecked(&dev->rx_dropped);
96810 kfree_skb(skb);
96811 return NET_RX_DROP;
96812 }
96813 }
96814
96815 if (unlikely(!is_skb_forwardable(dev, skb))) {
96816- atomic_long_inc(&dev->rx_dropped);
96817+ atomic_long_inc_unchecked(&dev->rx_dropped);
96818 kfree_skb(skb);
96819 return NET_RX_DROP;
96820 }
96821@@ -2434,7 +2434,7 @@ static int illegal_highdma(const struct net_device *dev, struct sk_buff *skb)
96822
96823 struct dev_gso_cb {
96824 void (*destructor)(struct sk_buff *skb);
96825-};
96826+} __no_const;
96827
96828 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
96829
96830@@ -3224,7 +3224,7 @@ enqueue:
96831
96832 local_irq_restore(flags);
96833
96834- atomic_long_inc(&skb->dev->rx_dropped);
96835+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96836 kfree_skb(skb);
96837 return NET_RX_DROP;
96838 }
96839@@ -3296,7 +3296,7 @@ int netif_rx_ni(struct sk_buff *skb)
96840 }
96841 EXPORT_SYMBOL(netif_rx_ni);
96842
96843-static void net_tx_action(struct softirq_action *h)
96844+static __latent_entropy void net_tx_action(void)
96845 {
96846 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96847
96848@@ -3630,7 +3630,7 @@ ncls:
96849 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
96850 } else {
96851 drop:
96852- atomic_long_inc(&skb->dev->rx_dropped);
96853+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
96854 kfree_skb(skb);
96855 /* Jamal, now you will not able to escape explaining
96856 * me how you were going to use this. :-)
96857@@ -4290,7 +4290,7 @@ void netif_napi_del(struct napi_struct *napi)
96858 }
96859 EXPORT_SYMBOL(netif_napi_del);
96860
96861-static void net_rx_action(struct softirq_action *h)
96862+static __latent_entropy void net_rx_action(void)
96863 {
96864 struct softnet_data *sd = &__get_cpu_var(softnet_data);
96865 unsigned long time_limit = jiffies + 2;
96866@@ -6179,7 +6179,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
96867 } else {
96868 netdev_stats_to_stats64(storage, &dev->stats);
96869 }
96870- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
96871+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
96872 return storage;
96873 }
96874 EXPORT_SYMBOL(dev_get_stats);
96875diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
96876index 5b7d0e1..cb960fc 100644
96877--- a/net/core/dev_ioctl.c
96878+++ b/net/core/dev_ioctl.c
96879@@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
96880 if (no_module && capable(CAP_NET_ADMIN))
96881 no_module = request_module("netdev-%s", name);
96882 if (no_module && capable(CAP_SYS_MODULE)) {
96883+#ifdef CONFIG_GRKERNSEC_MODHARDEN
96884+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
96885+#else
96886 if (!request_module("%s", name))
96887 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
96888 name);
96889+#endif
96890 }
96891 }
96892 EXPORT_SYMBOL(dev_load);
96893diff --git a/net/core/filter.c b/net/core/filter.c
96894index ad30d62..21c0743 100644
96895--- a/net/core/filter.c
96896+++ b/net/core/filter.c
96897@@ -126,7 +126,7 @@ unsigned int sk_run_filter(const struct sk_buff *skb,
96898 void *ptr;
96899 u32 A = 0; /* Accumulator */
96900 u32 X = 0; /* Index Register */
96901- u32 mem[BPF_MEMWORDS]; /* Scratch Memory Store */
96902+ u32 mem[BPF_MEMWORDS] = {}; /* Scratch Memory Store */
96903 u32 tmp;
96904 int k;
96905
96906@@ -292,10 +292,10 @@ load_b:
96907 X = K;
96908 continue;
96909 case BPF_S_LD_MEM:
96910- A = mem[K];
96911+ A = mem[K&15];
96912 continue;
96913 case BPF_S_LDX_MEM:
96914- X = mem[K];
96915+ X = mem[K&15];
96916 continue;
96917 case BPF_S_MISC_TAX:
96918 X = A;
96919@@ -308,10 +308,10 @@ load_b:
96920 case BPF_S_RET_A:
96921 return A;
96922 case BPF_S_ST:
96923- mem[K] = A;
96924+ mem[K&15] = A;
96925 continue;
96926 case BPF_S_STX:
96927- mem[K] = X;
96928+ mem[K&15] = X;
96929 continue;
96930 case BPF_S_ANC_PROTOCOL:
96931 A = ntohs(skb->protocol);
96932@@ -355,6 +355,10 @@ load_b:
96933
96934 if (skb_is_nonlinear(skb))
96935 return 0;
96936+
96937+ if (skb->len < sizeof(struct nlattr))
96938+ return 0;
96939+
96940 if (A > skb->len - sizeof(struct nlattr))
96941 return 0;
96942
96943@@ -371,11 +375,15 @@ load_b:
96944
96945 if (skb_is_nonlinear(skb))
96946 return 0;
96947+
96948+ if (skb->len < sizeof(struct nlattr))
96949+ return 0;
96950+
96951 if (A > skb->len - sizeof(struct nlattr))
96952 return 0;
96953
96954 nla = (struct nlattr *)&skb->data[A];
96955- if (nla->nla_len > A - skb->len)
96956+ if (nla->nla_len > skb->len - A)
96957 return 0;
96958
96959 nla = nla_find_nested(nla, X);
96960@@ -391,9 +399,10 @@ load_b:
96961 continue;
96962 #endif
96963 default:
96964- WARN_RATELIMIT(1, "Unknown code:%u jt:%u tf:%u k:%u\n",
96965+ WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
96966 fentry->code, fentry->jt,
96967 fentry->jf, fentry->k);
96968+ BUG();
96969 return 0;
96970 }
96971 }
96972@@ -416,7 +425,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
96973 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
96974 int pc, ret = 0;
96975
96976- BUILD_BUG_ON(BPF_MEMWORDS > 16);
96977+ BUILD_BUG_ON(BPF_MEMWORDS != 16);
96978 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
96979 if (!masks)
96980 return -ENOMEM;
96981@@ -679,7 +688,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
96982 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
96983 if (!fp)
96984 return -ENOMEM;
96985- memcpy(fp->insns, fprog->filter, fsize);
96986+ memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
96987
96988 atomic_set(&fp->refcnt, 1);
96989 fp->len = fprog->len;
96990diff --git a/net/core/flow.c b/net/core/flow.c
96991index dfa602c..3103d88 100644
96992--- a/net/core/flow.c
96993+++ b/net/core/flow.c
96994@@ -61,7 +61,7 @@ struct flow_cache {
96995 struct timer_list rnd_timer;
96996 };
96997
96998-atomic_t flow_cache_genid = ATOMIC_INIT(0);
96999+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
97000 EXPORT_SYMBOL(flow_cache_genid);
97001 static struct flow_cache flow_cache_global;
97002 static struct kmem_cache *flow_cachep __read_mostly;
97003@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
97004
97005 static int flow_entry_valid(struct flow_cache_entry *fle)
97006 {
97007- if (atomic_read(&flow_cache_genid) != fle->genid)
97008+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
97009 return 0;
97010 if (fle->object && !fle->object->ops->check(fle->object))
97011 return 0;
97012@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
97013 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
97014 fcp->hash_count++;
97015 }
97016- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
97017+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
97018 flo = fle->object;
97019 if (!flo)
97020 goto ret_object;
97021@@ -279,7 +279,7 @@ nocache:
97022 }
97023 flo = resolver(net, key, family, dir, flo, ctx);
97024 if (fle) {
97025- fle->genid = atomic_read(&flow_cache_genid);
97026+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
97027 if (!IS_ERR(flo))
97028 fle->object = flo;
97029 else
97030diff --git a/net/core/iovec.c b/net/core/iovec.c
97031index b618694..192bbba 100644
97032--- a/net/core/iovec.c
97033+++ b/net/core/iovec.c
97034@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97035 if (m->msg_namelen) {
97036 if (mode == VERIFY_READ) {
97037 void __user *namep;
97038- namep = (void __user __force *) m->msg_name;
97039+ namep = (void __force_user *) m->msg_name;
97040 err = move_addr_to_kernel(namep, m->msg_namelen,
97041 address);
97042 if (err < 0)
97043@@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
97044 }
97045
97046 size = m->msg_iovlen * sizeof(struct iovec);
97047- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
97048+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
97049 return -EFAULT;
97050
97051 m->msg_iov = iov;
97052diff --git a/net/core/neighbour.c b/net/core/neighbour.c
97053index 43128dd..e4d4311 100644
97054--- a/net/core/neighbour.c
97055+++ b/net/core/neighbour.c
97056@@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
97057 void __user *buffer, size_t *lenp, loff_t *ppos)
97058 {
97059 int size, ret;
97060- struct ctl_table tmp = *ctl;
97061+ ctl_table_no_const tmp = *ctl;
97062
97063 tmp.extra1 = &zero;
97064 tmp.extra2 = &unres_qlen_max;
97065@@ -2983,11 +2983,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
97066 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
97067 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
97068 } else {
97069+ struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
97070 dev_name_source = "default";
97071- t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
97072- t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
97073- t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
97074- t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
97075+ t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
97076+ t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
97077+ t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
97078+ t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
97079 }
97080
97081
97082diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
97083index 2bf8329..7960607 100644
97084--- a/net/core/net-procfs.c
97085+++ b/net/core/net-procfs.c
97086@@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
97087 else
97088 seq_printf(seq, "%04x", ntohs(pt->type));
97089
97090+#ifdef CONFIG_GRKERNSEC_HIDESYM
97091+ seq_printf(seq, " %-8s %pf\n",
97092+ pt->dev ? pt->dev->name : "", NULL);
97093+#else
97094 seq_printf(seq, " %-8s %pf\n",
97095 pt->dev ? pt->dev->name : "", pt->func);
97096+#endif
97097 }
97098
97099 return 0;
97100diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
97101index f3edf96..3cd8b40 100644
97102--- a/net/core/net-sysfs.c
97103+++ b/net/core/net-sysfs.c
97104@@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
97105 }
97106 EXPORT_SYMBOL(netdev_class_remove_file_ns);
97107
97108-int netdev_kobject_init(void)
97109+int __init netdev_kobject_init(void)
97110 {
97111 kobj_ns_type_register(&net_ns_type_operations);
97112 return class_register(&net_class);
97113diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
97114index 81d3a9a..a0bd7a8 100644
97115--- a/net/core/net_namespace.c
97116+++ b/net/core/net_namespace.c
97117@@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
97118 int error;
97119 LIST_HEAD(net_exit_list);
97120
97121- list_add_tail(&ops->list, list);
97122+ pax_list_add_tail((struct list_head *)&ops->list, list);
97123 if (ops->init || (ops->id && ops->size)) {
97124 for_each_net(net) {
97125 error = ops_init(ops, net);
97126@@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
97127
97128 out_undo:
97129 /* If I have an error cleanup all namespaces I initialized */
97130- list_del(&ops->list);
97131+ pax_list_del((struct list_head *)&ops->list);
97132 ops_exit_list(ops, &net_exit_list);
97133 ops_free_list(ops, &net_exit_list);
97134 return error;
97135@@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
97136 struct net *net;
97137 LIST_HEAD(net_exit_list);
97138
97139- list_del(&ops->list);
97140+ pax_list_del((struct list_head *)&ops->list);
97141 for_each_net(net)
97142 list_add_tail(&net->exit_list, &net_exit_list);
97143 ops_exit_list(ops, &net_exit_list);
97144@@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
97145 mutex_lock(&net_mutex);
97146 error = register_pernet_operations(&pernet_list, ops);
97147 if (!error && (first_device == &pernet_list))
97148- first_device = &ops->list;
97149+ first_device = (struct list_head *)&ops->list;
97150 mutex_unlock(&net_mutex);
97151 return error;
97152 }
97153diff --git a/net/core/netpoll.c b/net/core/netpoll.c
97154index 9a46671..6b8cb72 100644
97155--- a/net/core/netpoll.c
97156+++ b/net/core/netpoll.c
97157@@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97158 struct udphdr *udph;
97159 struct iphdr *iph;
97160 struct ethhdr *eth;
97161- static atomic_t ip_ident;
97162+ static atomic_unchecked_t ip_ident;
97163 struct ipv6hdr *ip6h;
97164
97165 udp_len = len + sizeof(*udph);
97166@@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
97167 put_unaligned(0x45, (unsigned char *)iph);
97168 iph->tos = 0;
97169 put_unaligned(htons(ip_len), &(iph->tot_len));
97170- iph->id = htons(atomic_inc_return(&ip_ident));
97171+ iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
97172 iph->frag_off = 0;
97173 iph->ttl = 64;
97174 iph->protocol = IPPROTO_UDP;
97175diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
97176index cc706c9..21fcd84 100644
97177--- a/net/core/rtnetlink.c
97178+++ b/net/core/rtnetlink.c
97179@@ -58,7 +58,7 @@ struct rtnl_link {
97180 rtnl_doit_func doit;
97181 rtnl_dumpit_func dumpit;
97182 rtnl_calcit_func calcit;
97183-};
97184+} __no_const;
97185
97186 static DEFINE_MUTEX(rtnl_mutex);
97187
97188@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
97189 if (rtnl_link_ops_get(ops->kind))
97190 return -EEXIST;
97191
97192- if (!ops->dellink)
97193- ops->dellink = unregister_netdevice_queue;
97194+ if (!ops->dellink) {
97195+ pax_open_kernel();
97196+ *(void **)&ops->dellink = unregister_netdevice_queue;
97197+ pax_close_kernel();
97198+ }
97199
97200- list_add_tail(&ops->list, &link_ops);
97201+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
97202 return 0;
97203 }
97204 EXPORT_SYMBOL_GPL(__rtnl_link_register);
97205@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
97206 for_each_net(net) {
97207 __rtnl_kill_links(net, ops);
97208 }
97209- list_del(&ops->list);
97210+ pax_list_del((struct list_head *)&ops->list);
97211 }
97212 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
97213
97214diff --git a/net/core/scm.c b/net/core/scm.c
97215index b442e7e..6f5b5a2 100644
97216--- a/net/core/scm.c
97217+++ b/net/core/scm.c
97218@@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
97219 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97220 {
97221 struct cmsghdr __user *cm
97222- = (__force struct cmsghdr __user *)msg->msg_control;
97223+ = (struct cmsghdr __force_user *)msg->msg_control;
97224 struct cmsghdr cmhdr;
97225 int cmlen = CMSG_LEN(len);
97226 int err;
97227@@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
97228 err = -EFAULT;
97229 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
97230 goto out;
97231- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
97232+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
97233 goto out;
97234 cmlen = CMSG_SPACE(len);
97235 if (msg->msg_controllen < cmlen)
97236@@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
97237 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97238 {
97239 struct cmsghdr __user *cm
97240- = (__force struct cmsghdr __user*)msg->msg_control;
97241+ = (struct cmsghdr __force_user *)msg->msg_control;
97242
97243 int fdmax = 0;
97244 int fdnum = scm->fp->count;
97245@@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
97246 if (fdnum < fdmax)
97247 fdmax = fdnum;
97248
97249- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
97250+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
97251 i++, cmfptr++)
97252 {
97253 struct socket *sock;
97254diff --git a/net/core/skbuff.c b/net/core/skbuff.c
97255index 9a9898e..38cc3e3 100644
97256--- a/net/core/skbuff.c
97257+++ b/net/core/skbuff.c
97258@@ -2006,7 +2006,7 @@ EXPORT_SYMBOL(__skb_checksum);
97259 __wsum skb_checksum(const struct sk_buff *skb, int offset,
97260 int len, __wsum csum)
97261 {
97262- const struct skb_checksum_ops ops = {
97263+ static const struct skb_checksum_ops ops = {
97264 .update = csum_partial_ext,
97265 .combine = csum_block_add_ext,
97266 };
97267@@ -3124,13 +3124,15 @@ void __init skb_init(void)
97268 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
97269 sizeof(struct sk_buff),
97270 0,
97271- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97272+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97273+ SLAB_NO_SANITIZE,
97274 NULL);
97275 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
97276 (2*sizeof(struct sk_buff)) +
97277 sizeof(atomic_t),
97278 0,
97279- SLAB_HWCACHE_ALIGN|SLAB_PANIC,
97280+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|
97281+ SLAB_NO_SANITIZE,
97282 NULL);
97283 }
97284
97285diff --git a/net/core/sock.c b/net/core/sock.c
97286index 50db733..8e4aeb4 100644
97287--- a/net/core/sock.c
97288+++ b/net/core/sock.c
97289@@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97290 struct sk_buff_head *list = &sk->sk_receive_queue;
97291
97292 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
97293- atomic_inc(&sk->sk_drops);
97294+ atomic_inc_unchecked(&sk->sk_drops);
97295 trace_sock_rcvqueue_full(sk, skb);
97296 return -ENOMEM;
97297 }
97298@@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97299 return err;
97300
97301 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
97302- atomic_inc(&sk->sk_drops);
97303+ atomic_inc_unchecked(&sk->sk_drops);
97304 return -ENOBUFS;
97305 }
97306
97307@@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
97308 skb_dst_force(skb);
97309
97310 spin_lock_irqsave(&list->lock, flags);
97311- skb->dropcount = atomic_read(&sk->sk_drops);
97312+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
97313 __skb_queue_tail(list, skb);
97314 spin_unlock_irqrestore(&list->lock, flags);
97315
97316@@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97317 skb->dev = NULL;
97318
97319 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
97320- atomic_inc(&sk->sk_drops);
97321+ atomic_inc_unchecked(&sk->sk_drops);
97322 goto discard_and_relse;
97323 }
97324 if (nested)
97325@@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
97326 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
97327 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
97328 bh_unlock_sock(sk);
97329- atomic_inc(&sk->sk_drops);
97330+ atomic_inc_unchecked(&sk->sk_drops);
97331 goto discard_and_relse;
97332 }
97333
97334@@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97335 struct timeval tm;
97336 } v;
97337
97338- int lv = sizeof(int);
97339- int len;
97340+ unsigned int lv = sizeof(int);
97341+ unsigned int len;
97342
97343 if (get_user(len, optlen))
97344 return -EFAULT;
97345- if (len < 0)
97346+ if (len > INT_MAX)
97347 return -EINVAL;
97348
97349 memset(&v, 0, sizeof(v));
97350@@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97351
97352 case SO_PEERNAME:
97353 {
97354- char address[128];
97355+ char address[_K_SS_MAXSIZE];
97356
97357 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
97358 return -ENOTCONN;
97359- if (lv < len)
97360+ if (lv < len || sizeof address < len)
97361 return -EINVAL;
97362 if (copy_to_user(optval, address, len))
97363 return -EFAULT;
97364@@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
97365
97366 if (len > lv)
97367 len = lv;
97368- if (copy_to_user(optval, &v, len))
97369+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
97370 return -EFAULT;
97371 lenout:
97372 if (put_user(len, optlen))
97373@@ -2353,7 +2353,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
97374 */
97375 smp_wmb();
97376 atomic_set(&sk->sk_refcnt, 1);
97377- atomic_set(&sk->sk_drops, 0);
97378+ atomic_set_unchecked(&sk->sk_drops, 0);
97379 }
97380 EXPORT_SYMBOL(sock_init_data);
97381
97382@@ -2481,6 +2481,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
97383 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97384 int level, int type)
97385 {
97386+ struct sock_extended_err ee;
97387 struct sock_exterr_skb *serr;
97388 struct sk_buff *skb, *skb2;
97389 int copied, err;
97390@@ -2502,7 +2503,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
97391 sock_recv_timestamp(msg, sk, skb);
97392
97393 serr = SKB_EXT_ERR(skb);
97394- put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
97395+ ee = serr->ee;
97396+ put_cmsg(msg, level, type, sizeof ee, &ee);
97397
97398 msg->msg_flags |= MSG_ERRQUEUE;
97399 err = copied;
97400diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
97401index a0e9cf6..ef7f9ed 100644
97402--- a/net/core/sock_diag.c
97403+++ b/net/core/sock_diag.c
97404@@ -9,26 +9,33 @@
97405 #include <linux/inet_diag.h>
97406 #include <linux/sock_diag.h>
97407
97408-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
97409+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
97410 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
97411 static DEFINE_MUTEX(sock_diag_table_mutex);
97412
97413 int sock_diag_check_cookie(void *sk, __u32 *cookie)
97414 {
97415+#ifndef CONFIG_GRKERNSEC_HIDESYM
97416 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
97417 cookie[1] != INET_DIAG_NOCOOKIE) &&
97418 ((u32)(unsigned long)sk != cookie[0] ||
97419 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
97420 return -ESTALE;
97421 else
97422+#endif
97423 return 0;
97424 }
97425 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
97426
97427 void sock_diag_save_cookie(void *sk, __u32 *cookie)
97428 {
97429+#ifdef CONFIG_GRKERNSEC_HIDESYM
97430+ cookie[0] = 0;
97431+ cookie[1] = 0;
97432+#else
97433 cookie[0] = (u32)(unsigned long)sk;
97434 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
97435+#endif
97436 }
97437 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
97438
97439@@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
97440 mutex_lock(&sock_diag_table_mutex);
97441 if (sock_diag_handlers[hndl->family])
97442 err = -EBUSY;
97443- else
97444+ else {
97445+ pax_open_kernel();
97446 sock_diag_handlers[hndl->family] = hndl;
97447+ pax_close_kernel();
97448+ }
97449 mutex_unlock(&sock_diag_table_mutex);
97450
97451 return err;
97452@@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
97453
97454 mutex_lock(&sock_diag_table_mutex);
97455 BUG_ON(sock_diag_handlers[family] != hnld);
97456+ pax_open_kernel();
97457 sock_diag_handlers[family] = NULL;
97458+ pax_close_kernel();
97459 mutex_unlock(&sock_diag_table_mutex);
97460 }
97461 EXPORT_SYMBOL_GPL(sock_diag_unregister);
97462diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
97463index cca4441..5e616de 100644
97464--- a/net/core/sysctl_net_core.c
97465+++ b/net/core/sysctl_net_core.c
97466@@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
97467 {
97468 unsigned int orig_size, size;
97469 int ret, i;
97470- struct ctl_table tmp = {
97471+ ctl_table_no_const tmp = {
97472 .data = &size,
97473 .maxlen = sizeof(size),
97474 .mode = table->mode
97475@@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
97476 void __user *buffer, size_t *lenp, loff_t *ppos)
97477 {
97478 char id[IFNAMSIZ];
97479- struct ctl_table tbl = {
97480+ ctl_table_no_const tbl = {
97481 .data = id,
97482 .maxlen = IFNAMSIZ,
97483 };
97484@@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
97485
97486 static __net_init int sysctl_core_net_init(struct net *net)
97487 {
97488- struct ctl_table *tbl;
97489+ ctl_table_no_const *tbl = NULL;
97490
97491 net->core.sysctl_somaxconn = SOMAXCONN;
97492
97493- tbl = netns_core_table;
97494 if (!net_eq(net, &init_net)) {
97495- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
97496+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
97497 if (tbl == NULL)
97498 goto err_dup;
97499
97500@@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
97501 if (net->user_ns != &init_user_ns) {
97502 tbl[0].procname = NULL;
97503 }
97504- }
97505-
97506- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97507+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
97508+ } else
97509+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
97510 if (net->core.sysctl_hdr == NULL)
97511 goto err_reg;
97512
97513 return 0;
97514
97515 err_reg:
97516- if (tbl != netns_core_table)
97517- kfree(tbl);
97518+ kfree(tbl);
97519 err_dup:
97520 return -ENOMEM;
97521 }
97522@@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
97523 kfree(tbl);
97524 }
97525
97526-static __net_initdata struct pernet_operations sysctl_core_ops = {
97527+static __net_initconst struct pernet_operations sysctl_core_ops = {
97528 .init = sysctl_core_net_init,
97529 .exit = sysctl_core_net_exit,
97530 };
97531diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
97532index dd4d506..fb2fb87 100644
97533--- a/net/decnet/af_decnet.c
97534+++ b/net/decnet/af_decnet.c
97535@@ -465,6 +465,7 @@ static struct proto dn_proto = {
97536 .sysctl_rmem = sysctl_decnet_rmem,
97537 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
97538 .obj_size = sizeof(struct dn_sock),
97539+ .slab_flags = SLAB_USERCOPY,
97540 };
97541
97542 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
97543diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
97544index dd0dfb2..fdbc764 100644
97545--- a/net/decnet/dn_dev.c
97546+++ b/net/decnet/dn_dev.c
97547@@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
97548 .extra1 = &min_t3,
97549 .extra2 = &max_t3
97550 },
97551- {0}
97552+ { }
97553 },
97554 };
97555
97556diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
97557index 5325b54..a0d4d69 100644
97558--- a/net/decnet/sysctl_net_decnet.c
97559+++ b/net/decnet/sysctl_net_decnet.c
97560@@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
97561
97562 if (len > *lenp) len = *lenp;
97563
97564- if (copy_to_user(buffer, addr, len))
97565+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
97566 return -EFAULT;
97567
97568 *lenp = len;
97569@@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
97570
97571 if (len > *lenp) len = *lenp;
97572
97573- if (copy_to_user(buffer, devname, len))
97574+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
97575 return -EFAULT;
97576
97577 *lenp = len;
97578diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
97579index 1865fdf..581a595 100644
97580--- a/net/ieee802154/dgram.c
97581+++ b/net/ieee802154/dgram.c
97582@@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
97583 if (saddr) {
97584 saddr->family = AF_IEEE802154;
97585 saddr->addr = mac_cb(skb)->sa;
97586+ }
97587+ if (addr_len)
97588 *addr_len = sizeof(*saddr);
97589- }
97590
97591 if (flags & MSG_TRUNC)
97592 copied = skb->len;
97593diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
97594index e4d96d4..e1651da 100644
97595--- a/net/ipv4/af_inet.c
97596+++ b/net/ipv4/af_inet.c
97597@@ -1686,13 +1686,9 @@ static int __init inet_init(void)
97598
97599 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
97600
97601- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
97602- if (!sysctl_local_reserved_ports)
97603- goto out;
97604-
97605 rc = proto_register(&tcp_prot, 1);
97606 if (rc)
97607- goto out_free_reserved_ports;
97608+ goto out;
97609
97610 rc = proto_register(&udp_prot, 1);
97611 if (rc)
97612@@ -1799,8 +1795,6 @@ out_unregister_udp_proto:
97613 proto_unregister(&udp_prot);
97614 out_unregister_tcp_proto:
97615 proto_unregister(&tcp_prot);
97616-out_free_reserved_ports:
97617- kfree(sysctl_local_reserved_ports);
97618 goto out;
97619 }
97620
97621diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
97622index f4b34d8..c54a163 100644
97623--- a/net/ipv4/devinet.c
97624+++ b/net/ipv4/devinet.c
97625@@ -1534,7 +1534,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
97626 idx = 0;
97627 head = &net->dev_index_head[h];
97628 rcu_read_lock();
97629- cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
97630+ cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
97631 net->dev_base_seq;
97632 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97633 if (idx < s_idx)
97634@@ -1845,7 +1845,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
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@@ -2070,7 +2070,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
97644 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
97645 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
97646
97647-static struct devinet_sysctl_table {
97648+static const struct devinet_sysctl_table {
97649 struct ctl_table_header *sysctl_header;
97650 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
97651 } devinet_sysctl = {
97652@@ -2192,7 +2192,7 @@ static __net_init int devinet_init_net(struct net *net)
97653 int err;
97654 struct ipv4_devconf *all, *dflt;
97655 #ifdef CONFIG_SYSCTL
97656- struct ctl_table *tbl = ctl_forward_entry;
97657+ ctl_table_no_const *tbl = NULL;
97658 struct ctl_table_header *forw_hdr;
97659 #endif
97660
97661@@ -2210,7 +2210,7 @@ static __net_init int devinet_init_net(struct net *net)
97662 goto err_alloc_dflt;
97663
97664 #ifdef CONFIG_SYSCTL
97665- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
97666+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
97667 if (tbl == NULL)
97668 goto err_alloc_ctl;
97669
97670@@ -2230,7 +2230,10 @@ static __net_init int devinet_init_net(struct net *net)
97671 goto err_reg_dflt;
97672
97673 err = -ENOMEM;
97674- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97675+ if (!net_eq(net, &init_net))
97676+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
97677+ else
97678+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
97679 if (forw_hdr == NULL)
97680 goto err_reg_ctl;
97681 net->ipv4.forw_hdr = forw_hdr;
97682@@ -2246,8 +2249,7 @@ err_reg_ctl:
97683 err_reg_dflt:
97684 __devinet_sysctl_unregister(all);
97685 err_reg_all:
97686- if (tbl != ctl_forward_entry)
97687- kfree(tbl);
97688+ kfree(tbl);
97689 err_alloc_ctl:
97690 #endif
97691 if (dflt != &ipv4_devconf_dflt)
97692diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
97693index c7539e2..b455e51 100644
97694--- a/net/ipv4/fib_frontend.c
97695+++ b/net/ipv4/fib_frontend.c
97696@@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
97697 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97698 fib_sync_up(dev);
97699 #endif
97700- atomic_inc(&net->ipv4.dev_addr_genid);
97701+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97702 rt_cache_flush(dev_net(dev));
97703 break;
97704 case NETDEV_DOWN:
97705 fib_del_ifaddr(ifa, NULL);
97706- atomic_inc(&net->ipv4.dev_addr_genid);
97707+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97708 if (ifa->ifa_dev->ifa_list == NULL) {
97709 /* Last address was deleted from this interface.
97710 * Disable IP.
97711@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
97712 #ifdef CONFIG_IP_ROUTE_MULTIPATH
97713 fib_sync_up(dev);
97714 #endif
97715- atomic_inc(&net->ipv4.dev_addr_genid);
97716+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
97717 rt_cache_flush(net);
97718 break;
97719 case NETDEV_DOWN:
97720diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
97721index e63f47a..e5c531d 100644
97722--- a/net/ipv4/fib_semantics.c
97723+++ b/net/ipv4/fib_semantics.c
97724@@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
97725 nh->nh_saddr = inet_select_addr(nh->nh_dev,
97726 nh->nh_gw,
97727 nh->nh_parent->fib_scope);
97728- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
97729+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
97730
97731 return nh->nh_saddr;
97732 }
97733diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
97734index fc0e649..febfa65 100644
97735--- a/net/ipv4/inet_connection_sock.c
97736+++ b/net/ipv4/inet_connection_sock.c
97737@@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
97738 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
97739 #endif
97740
97741-unsigned long *sysctl_local_reserved_ports;
97742+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
97743 EXPORT_SYMBOL(sysctl_local_reserved_ports);
97744
97745 void inet_get_local_port_range(struct net *net, int *low, int *high)
97746diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
97747index 8b9cf27..0d8d592 100644
97748--- a/net/ipv4/inet_hashtables.c
97749+++ b/net/ipv4/inet_hashtables.c
97750@@ -18,6 +18,7 @@
97751 #include <linux/sched.h>
97752 #include <linux/slab.h>
97753 #include <linux/wait.h>
97754+#include <linux/security.h>
97755
97756 #include <net/inet_connection_sock.h>
97757 #include <net/inet_hashtables.h>
97758@@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
97759 return inet_ehashfn(net, laddr, lport, faddr, fport);
97760 }
97761
97762+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
97763+
97764 /*
97765 * Allocate and initialize a new local port bind bucket.
97766 * The bindhash mutex for snum's hash chain must be held here.
97767@@ -554,6 +557,8 @@ ok:
97768 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
97769 spin_unlock(&head->lock);
97770
97771+ gr_update_task_in_ip_table(current, inet_sk(sk));
97772+
97773 if (tw) {
97774 inet_twsk_deschedule(tw, death_row);
97775 while (twrefcnt) {
97776diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
97777index 33d5537..da337a4 100644
97778--- a/net/ipv4/inetpeer.c
97779+++ b/net/ipv4/inetpeer.c
97780@@ -503,8 +503,8 @@ relookup:
97781 if (p) {
97782 p->daddr = *daddr;
97783 atomic_set(&p->refcnt, 1);
97784- atomic_set(&p->rid, 0);
97785- atomic_set(&p->ip_id_count,
97786+ atomic_set_unchecked(&p->rid, 0);
97787+ atomic_set_unchecked(&p->ip_id_count,
97788 (daddr->family == AF_INET) ?
97789 secure_ip_id(daddr->addr.a4) :
97790 secure_ipv6_id(daddr->addr.a6));
97791diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
97792index 2481993..2d9a7a7 100644
97793--- a/net/ipv4/ip_fragment.c
97794+++ b/net/ipv4/ip_fragment.c
97795@@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
97796 return 0;
97797
97798 start = qp->rid;
97799- end = atomic_inc_return(&peer->rid);
97800+ end = atomic_inc_return_unchecked(&peer->rid);
97801 qp->rid = end;
97802
97803 rc = qp->q.fragments && (end - start) > max;
97804@@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
97805
97806 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97807 {
97808- struct ctl_table *table;
97809+ ctl_table_no_const *table = NULL;
97810 struct ctl_table_header *hdr;
97811
97812- table = ip4_frags_ns_ctl_table;
97813 if (!net_eq(net, &init_net)) {
97814- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97815+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
97816 if (table == NULL)
97817 goto err_alloc;
97818
97819@@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97820 /* Don't export sysctls to unprivileged users */
97821 if (net->user_ns != &init_user_ns)
97822 table[0].procname = NULL;
97823- }
97824+ hdr = register_net_sysctl(net, "net/ipv4", table);
97825+ } else
97826+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
97827
97828- hdr = register_net_sysctl(net, "net/ipv4", table);
97829 if (hdr == NULL)
97830 goto err_reg;
97831
97832@@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
97833 return 0;
97834
97835 err_reg:
97836- if (!net_eq(net, &init_net))
97837- kfree(table);
97838+ kfree(table);
97839 err_alloc:
97840 return -ENOMEM;
97841 }
97842diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
97843index d306360..1c1a1f1 100644
97844--- a/net/ipv4/ip_gre.c
97845+++ b/net/ipv4/ip_gre.c
97846@@ -115,7 +115,7 @@ static bool log_ecn_error = true;
97847 module_param(log_ecn_error, bool, 0644);
97848 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97849
97850-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
97851+static struct rtnl_link_ops ipgre_link_ops;
97852 static int ipgre_tunnel_init(struct net_device *dev);
97853
97854 static int ipgre_net_id __read_mostly;
97855@@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
97856 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
97857 };
97858
97859-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97860+static struct rtnl_link_ops ipgre_link_ops = {
97861 .kind = "gre",
97862 .maxtype = IFLA_GRE_MAX,
97863 .policy = ipgre_policy,
97864@@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
97865 .fill_info = ipgre_fill_info,
97866 };
97867
97868-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
97869+static struct rtnl_link_ops ipgre_tap_ops = {
97870 .kind = "gretap",
97871 .maxtype = IFLA_GRE_MAX,
97872 .policy = ipgre_policy,
97873diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
97874index ddf32a6..3fdeea9 100644
97875--- a/net/ipv4/ip_sockglue.c
97876+++ b/net/ipv4/ip_sockglue.c
97877@@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97878 len = min_t(unsigned int, len, opt->optlen);
97879 if (put_user(len, optlen))
97880 return -EFAULT;
97881- if (copy_to_user(optval, opt->__data, len))
97882+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
97883+ copy_to_user(optval, opt->__data, len))
97884 return -EFAULT;
97885 return 0;
97886 }
97887@@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
97888 if (sk->sk_type != SOCK_STREAM)
97889 return -ENOPROTOOPT;
97890
97891- msg.msg_control = optval;
97892+ msg.msg_control = (void __force_kernel *)optval;
97893 msg.msg_controllen = len;
97894 msg.msg_flags = flags;
97895
97896diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
97897index 52b802a..b725179 100644
97898--- a/net/ipv4/ip_vti.c
97899+++ b/net/ipv4/ip_vti.c
97900@@ -44,7 +44,7 @@
97901 #include <net/net_namespace.h>
97902 #include <net/netns/generic.h>
97903
97904-static struct rtnl_link_ops vti_link_ops __read_mostly;
97905+static struct rtnl_link_ops vti_link_ops;
97906
97907 static int vti_net_id __read_mostly;
97908 static int vti_tunnel_init(struct net_device *dev);
97909@@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
97910 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
97911 };
97912
97913-static struct rtnl_link_ops vti_link_ops __read_mostly = {
97914+static struct rtnl_link_ops vti_link_ops = {
97915 .kind = "vti",
97916 .maxtype = IFLA_VTI_MAX,
97917 .policy = vti_policy,
97918diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
97919index efa1138..20dbba0 100644
97920--- a/net/ipv4/ipconfig.c
97921+++ b/net/ipv4/ipconfig.c
97922@@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
97923
97924 mm_segment_t oldfs = get_fs();
97925 set_fs(get_ds());
97926- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97927+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97928 set_fs(oldfs);
97929 return res;
97930 }
97931@@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
97932
97933 mm_segment_t oldfs = get_fs();
97934 set_fs(get_ds());
97935- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
97936+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
97937 set_fs(oldfs);
97938 return res;
97939 }
97940@@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
97941
97942 mm_segment_t oldfs = get_fs();
97943 set_fs(get_ds());
97944- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
97945+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
97946 set_fs(oldfs);
97947 return res;
97948 }
97949diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
97950index fe3e9f7..4956990 100644
97951--- a/net/ipv4/ipip.c
97952+++ b/net/ipv4/ipip.c
97953@@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
97954 static int ipip_net_id __read_mostly;
97955
97956 static int ipip_tunnel_init(struct net_device *dev);
97957-static struct rtnl_link_ops ipip_link_ops __read_mostly;
97958+static struct rtnl_link_ops ipip_link_ops;
97959
97960 static int ipip_err(struct sk_buff *skb, u32 info)
97961 {
97962@@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
97963 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
97964 };
97965
97966-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
97967+static struct rtnl_link_ops ipip_link_ops = {
97968 .kind = "ipip",
97969 .maxtype = IFLA_IPTUN_MAX,
97970 .policy = ipip_policy,
97971diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
97972index 59da7cd..e318de1 100644
97973--- a/net/ipv4/netfilter/arp_tables.c
97974+++ b/net/ipv4/netfilter/arp_tables.c
97975@@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
97976 #endif
97977
97978 static int get_info(struct net *net, void __user *user,
97979- const int *len, int compat)
97980+ int len, int compat)
97981 {
97982 char name[XT_TABLE_MAXNAMELEN];
97983 struct xt_table *t;
97984 int ret;
97985
97986- if (*len != sizeof(struct arpt_getinfo)) {
97987- duprintf("length %u != %Zu\n", *len,
97988+ if (len != sizeof(struct arpt_getinfo)) {
97989+ duprintf("length %u != %Zu\n", len,
97990 sizeof(struct arpt_getinfo));
97991 return -EINVAL;
97992 }
97993@@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
97994 info.size = private->size;
97995 strcpy(info.name, name);
97996
97997- if (copy_to_user(user, &info, *len) != 0)
97998+ if (copy_to_user(user, &info, len) != 0)
97999 ret = -EFAULT;
98000 else
98001 ret = 0;
98002@@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
98003
98004 switch (cmd) {
98005 case ARPT_SO_GET_INFO:
98006- ret = get_info(sock_net(sk), user, len, 1);
98007+ ret = get_info(sock_net(sk), user, *len, 1);
98008 break;
98009 case ARPT_SO_GET_ENTRIES:
98010 ret = compat_get_entries(sock_net(sk), user, len);
98011@@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
98012
98013 switch (cmd) {
98014 case ARPT_SO_GET_INFO:
98015- ret = get_info(sock_net(sk), user, len, 0);
98016+ ret = get_info(sock_net(sk), user, *len, 0);
98017 break;
98018
98019 case ARPT_SO_GET_ENTRIES:
98020diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
98021index 718dfbd..cef4152 100644
98022--- a/net/ipv4/netfilter/ip_tables.c
98023+++ b/net/ipv4/netfilter/ip_tables.c
98024@@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
98025 #endif
98026
98027 static int get_info(struct net *net, void __user *user,
98028- const int *len, int compat)
98029+ int len, int compat)
98030 {
98031 char name[XT_TABLE_MAXNAMELEN];
98032 struct xt_table *t;
98033 int ret;
98034
98035- if (*len != sizeof(struct ipt_getinfo)) {
98036- duprintf("length %u != %zu\n", *len,
98037+ if (len != sizeof(struct ipt_getinfo)) {
98038+ duprintf("length %u != %zu\n", len,
98039 sizeof(struct ipt_getinfo));
98040 return -EINVAL;
98041 }
98042@@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
98043 info.size = private->size;
98044 strcpy(info.name, name);
98045
98046- if (copy_to_user(user, &info, *len) != 0)
98047+ if (copy_to_user(user, &info, len) != 0)
98048 ret = -EFAULT;
98049 else
98050 ret = 0;
98051@@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98052
98053 switch (cmd) {
98054 case IPT_SO_GET_INFO:
98055- ret = get_info(sock_net(sk), user, len, 1);
98056+ ret = get_info(sock_net(sk), user, *len, 1);
98057 break;
98058 case IPT_SO_GET_ENTRIES:
98059 ret = compat_get_entries(sock_net(sk), user, len);
98060@@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
98061
98062 switch (cmd) {
98063 case IPT_SO_GET_INFO:
98064- ret = get_info(sock_net(sk), user, len, 0);
98065+ ret = get_info(sock_net(sk), user, *len, 0);
98066 break;
98067
98068 case IPT_SO_GET_ENTRIES:
98069diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
98070index 242e7f4..76cc7ee 100644
98071--- a/net/ipv4/ping.c
98072+++ b/net/ipv4/ping.c
98073@@ -55,7 +55,7 @@
98074
98075
98076 struct ping_table ping_table;
98077-struct pingv6_ops pingv6_ops;
98078+struct pingv6_ops *pingv6_ops;
98079 EXPORT_SYMBOL_GPL(pingv6_ops);
98080
98081 static u16 ping_port_rover;
98082@@ -251,23 +251,28 @@ int ping_init_sock(struct sock *sk)
98083 struct group_info *group_info = get_current_groups();
98084 int i, j, count = group_info->ngroups;
98085 kgid_t low, high;
98086+ int ret = 0;
98087
98088 inet_get_ping_group_range_net(net, &low, &high);
98089 if (gid_lte(low, group) && gid_lte(group, high))
98090- return 0;
98091+ goto out_release_group;
98092
98093 for (i = 0; i < group_info->nblocks; i++) {
98094 int cp_count = min_t(int, NGROUPS_PER_BLOCK, count);
98095 for (j = 0; j < cp_count; j++) {
98096 kgid_t gid = group_info->blocks[i][j];
98097 if (gid_lte(low, gid) && gid_lte(gid, high))
98098- return 0;
98099+ goto out_release_group;
98100 }
98101
98102 count -= cp_count;
98103 }
98104
98105- return -EACCES;
98106+ ret = -EACCES;
98107+
98108+out_release_group:
98109+ put_group_info(group_info);
98110+ return ret;
98111 }
98112 EXPORT_SYMBOL_GPL(ping_init_sock);
98113
98114@@ -334,7 +339,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
98115 return -ENODEV;
98116 }
98117 }
98118- has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
98119+ has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
98120 scoped);
98121 rcu_read_unlock();
98122
98123@@ -542,7 +547,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98124 }
98125 #if IS_ENABLED(CONFIG_IPV6)
98126 } else if (skb->protocol == htons(ETH_P_IPV6)) {
98127- harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
98128+ harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
98129 #endif
98130 }
98131
98132@@ -560,7 +565,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
98133 info, (u8 *)icmph);
98134 #if IS_ENABLED(CONFIG_IPV6)
98135 } else if (family == AF_INET6) {
98136- pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
98137+ pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
98138 info, (u8 *)icmph);
98139 #endif
98140 }
98141@@ -830,6 +835,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98142 {
98143 struct inet_sock *isk = inet_sk(sk);
98144 int family = sk->sk_family;
98145+ struct sockaddr_in *sin;
98146+ struct sockaddr_in6 *sin6;
98147 struct sk_buff *skb;
98148 int copied, err;
98149
98150@@ -839,12 +846,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98151 if (flags & MSG_OOB)
98152 goto out;
98153
98154+ if (addr_len) {
98155+ if (family == AF_INET)
98156+ *addr_len = sizeof(*sin);
98157+ else if (family == AF_INET6 && addr_len)
98158+ *addr_len = sizeof(*sin6);
98159+ }
98160+
98161 if (flags & MSG_ERRQUEUE) {
98162 if (family == AF_INET) {
98163 return ip_recv_error(sk, msg, len, addr_len);
98164 #if IS_ENABLED(CONFIG_IPV6)
98165 } else if (family == AF_INET6) {
98166- return pingv6_ops.ipv6_recv_error(sk, msg, len,
98167+ return pingv6_ops->ipv6_recv_error(sk, msg, len,
98168 addr_len);
98169 #endif
98170 }
98171@@ -876,7 +890,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98172 sin->sin_port = 0 /* skb->h.uh->source */;
98173 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98174 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98175- *addr_len = sizeof(*sin);
98176 }
98177
98178 if (isk->cmsg_flags)
98179@@ -899,11 +912,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98180 sin6->sin6_scope_id =
98181 ipv6_iface_scope_id(&sin6->sin6_addr,
98182 IP6CB(skb)->iif);
98183- *addr_len = sizeof(*sin6);
98184 }
98185
98186 if (inet6_sk(sk)->rxopt.all)
98187- pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
98188+ pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
98189 #endif
98190 } else {
98191 BUG();
98192@@ -1093,7 +1105,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
98193 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98194 0, sock_i_ino(sp),
98195 atomic_read(&sp->sk_refcnt), sp,
98196- atomic_read(&sp->sk_drops));
98197+ atomic_read_unchecked(&sp->sk_drops));
98198 }
98199
98200 static int ping_v4_seq_show(struct seq_file *seq, void *v)
98201diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
98202index 23c3e5b..cdb8b36 100644
98203--- a/net/ipv4/raw.c
98204+++ b/net/ipv4/raw.c
98205@@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
98206 int raw_rcv(struct sock *sk, struct sk_buff *skb)
98207 {
98208 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
98209- atomic_inc(&sk->sk_drops);
98210+ atomic_inc_unchecked(&sk->sk_drops);
98211 kfree_skb(skb);
98212 return NET_RX_DROP;
98213 }
98214@@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98215 if (flags & MSG_OOB)
98216 goto out;
98217
98218+ if (addr_len)
98219+ *addr_len = sizeof(*sin);
98220+
98221 if (flags & MSG_ERRQUEUE) {
98222 err = ip_recv_error(sk, msg, len, addr_len);
98223 goto out;
98224@@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98225 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98226 sin->sin_port = 0;
98227 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98228- *addr_len = sizeof(*sin);
98229 }
98230 if (inet->cmsg_flags)
98231 ip_cmsg_recv(msg, skb);
98232@@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
98233
98234 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
98235 {
98236+ struct icmp_filter filter;
98237+
98238 if (optlen > sizeof(struct icmp_filter))
98239 optlen = sizeof(struct icmp_filter);
98240- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
98241+ if (copy_from_user(&filter, optval, optlen))
98242 return -EFAULT;
98243+ raw_sk(sk)->filter = filter;
98244 return 0;
98245 }
98246
98247 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
98248 {
98249 int len, ret = -EFAULT;
98250+ struct icmp_filter filter;
98251
98252 if (get_user(len, optlen))
98253 goto out;
98254@@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
98255 if (len > sizeof(struct icmp_filter))
98256 len = sizeof(struct icmp_filter);
98257 ret = -EFAULT;
98258- if (put_user(len, optlen) ||
98259- copy_to_user(optval, &raw_sk(sk)->filter, len))
98260+ filter = raw_sk(sk)->filter;
98261+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
98262 goto out;
98263 ret = 0;
98264 out: return ret;
98265@@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
98266 0, 0L, 0,
98267 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
98268 0, sock_i_ino(sp),
98269- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
98270+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
98271 }
98272
98273 static int raw_seq_show(struct seq_file *seq, void *v)
98274diff --git a/net/ipv4/route.c b/net/ipv4/route.c
98275index e611651f..0c17263 100644
98276--- a/net/ipv4/route.c
98277+++ b/net/ipv4/route.c
98278@@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
98279 .maxlen = sizeof(int),
98280 .mode = 0200,
98281 .proc_handler = ipv4_sysctl_rtcache_flush,
98282+ .extra1 = &init_net,
98283 },
98284 { },
98285 };
98286
98287 static __net_init int sysctl_route_net_init(struct net *net)
98288 {
98289- struct ctl_table *tbl;
98290+ ctl_table_no_const *tbl = NULL;
98291
98292- tbl = ipv4_route_flush_table;
98293 if (!net_eq(net, &init_net)) {
98294- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98295+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
98296 if (tbl == NULL)
98297 goto err_dup;
98298
98299 /* Don't export sysctls to unprivileged users */
98300 if (net->user_ns != &init_user_ns)
98301 tbl[0].procname = NULL;
98302- }
98303- tbl[0].extra1 = net;
98304+ tbl[0].extra1 = net;
98305+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98306+ } else
98307+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
98308
98309- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
98310 if (net->ipv4.route_hdr == NULL)
98311 goto err_reg;
98312 return 0;
98313
98314 err_reg:
98315- if (tbl != ipv4_route_flush_table)
98316- kfree(tbl);
98317+ kfree(tbl);
98318 err_dup:
98319 return -ENOMEM;
98320 }
98321@@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
98322
98323 static __net_init int rt_genid_init(struct net *net)
98324 {
98325- atomic_set(&net->ipv4.rt_genid, 0);
98326- atomic_set(&net->fnhe_genid, 0);
98327+ atomic_set_unchecked(&net->ipv4.rt_genid, 0);
98328+ atomic_set_unchecked(&net->fnhe_genid, 0);
98329 get_random_bytes(&net->ipv4.dev_addr_genid,
98330 sizeof(net->ipv4.dev_addr_genid));
98331 return 0;
98332diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
98333index 3d69ec8..57207b4 100644
98334--- a/net/ipv4/sysctl_net_ipv4.c
98335+++ b/net/ipv4/sysctl_net_ipv4.c
98336@@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
98337 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
98338 int ret;
98339 int range[2];
98340- struct ctl_table tmp = {
98341+ ctl_table_no_const tmp = {
98342 .data = &range,
98343 .maxlen = sizeof(range),
98344 .mode = table->mode,
98345@@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
98346 int ret;
98347 gid_t urange[2];
98348 kgid_t low, high;
98349- struct ctl_table tmp = {
98350+ ctl_table_no_const tmp = {
98351 .data = &urange,
98352 .maxlen = sizeof(urange),
98353 .mode = table->mode,
98354@@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
98355 void __user *buffer, size_t *lenp, loff_t *ppos)
98356 {
98357 char val[TCP_CA_NAME_MAX];
98358- struct ctl_table tbl = {
98359+ ctl_table_no_const tbl = {
98360 .data = val,
98361 .maxlen = TCP_CA_NAME_MAX,
98362 };
98363@@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
98364 void __user *buffer, size_t *lenp,
98365 loff_t *ppos)
98366 {
98367- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
98368+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
98369 int ret;
98370
98371 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98372@@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
98373 void __user *buffer, size_t *lenp,
98374 loff_t *ppos)
98375 {
98376- struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
98377+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
98378 int ret;
98379
98380 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
98381@@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
98382 void __user *buffer, size_t *lenp,
98383 loff_t *ppos)
98384 {
98385- struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98386+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
98387 struct tcp_fastopen_context *ctxt;
98388 int ret;
98389 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
98390@@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
98391 },
98392 {
98393 .procname = "ip_local_reserved_ports",
98394- .data = NULL, /* initialized in sysctl_ipv4_init */
98395+ .data = sysctl_local_reserved_ports,
98396 .maxlen = 65536,
98397 .mode = 0644,
98398 .proc_handler = proc_do_large_bitmap,
98399@@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
98400
98401 static __net_init int ipv4_sysctl_init_net(struct net *net)
98402 {
98403- struct ctl_table *table;
98404+ ctl_table_no_const *table = NULL;
98405
98406- table = ipv4_net_table;
98407 if (!net_eq(net, &init_net)) {
98408 int i;
98409
98410- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
98411+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
98412 if (table == NULL)
98413 goto err_alloc;
98414
98415@@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
98416 net->ipv4.sysctl_local_ports.range[0] = 32768;
98417 net->ipv4.sysctl_local_ports.range[1] = 61000;
98418
98419- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98420+ if (!net_eq(net, &init_net))
98421+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
98422+ else
98423+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
98424 if (net->ipv4.ipv4_hdr == NULL)
98425 goto err_reg;
98426
98427 return 0;
98428
98429 err_reg:
98430- if (!net_eq(net, &init_net))
98431- kfree(table);
98432+ kfree(table);
98433 err_alloc:
98434 return -ENOMEM;
98435 }
98436@@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
98437 static __init int sysctl_ipv4_init(void)
98438 {
98439 struct ctl_table_header *hdr;
98440- struct ctl_table *i;
98441-
98442- for (i = ipv4_table; i->procname; i++) {
98443- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
98444- i->data = sysctl_local_reserved_ports;
98445- break;
98446- }
98447- }
98448- if (!i->procname)
98449- return -EINVAL;
98450
98451 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
98452 if (hdr == NULL)
98453diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
98454index c53b7f3..a89aadd 100644
98455--- a/net/ipv4/tcp_input.c
98456+++ b/net/ipv4/tcp_input.c
98457@@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
98458 * without any lock. We want to make sure compiler wont store
98459 * intermediate values in this location.
98460 */
98461- ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
98462+ ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
98463 sk->sk_max_pacing_rate);
98464 }
98465
98466@@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
98467 * simplifies code)
98468 */
98469 static void
98470-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98471+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
98472 struct sk_buff *head, struct sk_buff *tail,
98473 u32 start, u32 end)
98474 {
98475@@ -5559,6 +5559,7 @@ discard:
98476 tcp_paws_reject(&tp->rx_opt, 0))
98477 goto discard_and_undo;
98478
98479+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
98480 if (th->syn) {
98481 /* We see SYN without ACK. It is attempt of
98482 * simultaneous connect with crossed SYNs.
98483@@ -5609,6 +5610,7 @@ discard:
98484 goto discard;
98485 #endif
98486 }
98487+#endif
98488 /* "fifth, if neither of the SYN or RST bits is set then
98489 * drop the segment and return."
98490 */
98491@@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
98492 goto discard;
98493
98494 if (th->syn) {
98495- if (th->fin)
98496+ if (th->fin || th->urg || th->psh)
98497 goto discard;
98498 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
98499 return 1;
98500diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
98501index 1d7b9dd..66749f8 100644
98502--- a/net/ipv4/tcp_ipv4.c
98503+++ b/net/ipv4/tcp_ipv4.c
98504@@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
98505 EXPORT_SYMBOL(sysctl_tcp_low_latency);
98506
98507
98508+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98509+extern int grsec_enable_blackhole;
98510+#endif
98511+
98512 #ifdef CONFIG_TCP_MD5SIG
98513 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
98514 __be32 daddr, __be32 saddr, const struct tcphdr *th);
98515@@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
98516 return 0;
98517
98518 reset:
98519+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98520+ if (!grsec_enable_blackhole)
98521+#endif
98522 tcp_v4_send_reset(rsk, skb);
98523 discard:
98524 kfree_skb(skb);
98525@@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
98526 TCP_SKB_CB(skb)->sacked = 0;
98527
98528 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98529- if (!sk)
98530+ if (!sk) {
98531+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98532+ ret = 1;
98533+#endif
98534 goto no_tcp_socket;
98535-
98536+ }
98537 process:
98538- if (sk->sk_state == TCP_TIME_WAIT)
98539+ if (sk->sk_state == TCP_TIME_WAIT) {
98540+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98541+ ret = 2;
98542+#endif
98543 goto do_time_wait;
98544+ }
98545
98546 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
98547 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98548@@ -2034,6 +2048,10 @@ csum_error:
98549 bad_packet:
98550 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98551 } else {
98552+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98553+ if (!grsec_enable_blackhole || (ret == 1 &&
98554+ (skb->dev->flags & IFF_LOOPBACK)))
98555+#endif
98556 tcp_v4_send_reset(NULL, skb);
98557 }
98558
98559diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
98560index 97b6841..0893357 100644
98561--- a/net/ipv4/tcp_minisocks.c
98562+++ b/net/ipv4/tcp_minisocks.c
98563@@ -27,6 +27,10 @@
98564 #include <net/inet_common.h>
98565 #include <net/xfrm.h>
98566
98567+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98568+extern int grsec_enable_blackhole;
98569+#endif
98570+
98571 int sysctl_tcp_syncookies __read_mostly = 1;
98572 EXPORT_SYMBOL(sysctl_tcp_syncookies);
98573
98574@@ -708,7 +712,10 @@ embryonic_reset:
98575 * avoid becoming vulnerable to outside attack aiming at
98576 * resetting legit local connections.
98577 */
98578- req->rsk_ops->send_reset(sk, skb);
98579+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98580+ if (!grsec_enable_blackhole)
98581+#endif
98582+ req->rsk_ops->send_reset(sk, skb);
98583 } else if (fastopen) { /* received a valid RST pkt */
98584 reqsk_fastopen_remove(sk, req, true);
98585 tcp_reset(sk);
98586diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
98587index 8b97d71..9d7ccf5 100644
98588--- a/net/ipv4/tcp_probe.c
98589+++ b/net/ipv4/tcp_probe.c
98590@@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
98591 if (cnt + width >= len)
98592 break;
98593
98594- if (copy_to_user(buf + cnt, tbuf, width))
98595+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
98596 return -EFAULT;
98597 cnt += width;
98598 }
98599diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
98600index 64f0354..a81b39d 100644
98601--- a/net/ipv4/tcp_timer.c
98602+++ b/net/ipv4/tcp_timer.c
98603@@ -22,6 +22,10 @@
98604 #include <linux/gfp.h>
98605 #include <net/tcp.h>
98606
98607+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98608+extern int grsec_lastack_retries;
98609+#endif
98610+
98611 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
98612 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
98613 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
98614@@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
98615 }
98616 }
98617
98618+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98619+ if ((sk->sk_state == TCP_LAST_ACK) &&
98620+ (grsec_lastack_retries > 0) &&
98621+ (grsec_lastack_retries < retry_until))
98622+ retry_until = grsec_lastack_retries;
98623+#endif
98624+
98625 if (retransmits_timed_out(sk, retry_until,
98626 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
98627 /* Has it gone just too far? */
98628diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
98629index a7e4729..2758946 100644
98630--- a/net/ipv4/udp.c
98631+++ b/net/ipv4/udp.c
98632@@ -87,6 +87,7 @@
98633 #include <linux/types.h>
98634 #include <linux/fcntl.h>
98635 #include <linux/module.h>
98636+#include <linux/security.h>
98637 #include <linux/socket.h>
98638 #include <linux/sockios.h>
98639 #include <linux/igmp.h>
98640@@ -113,6 +114,10 @@
98641 #include <net/busy_poll.h>
98642 #include "udp_impl.h"
98643
98644+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98645+extern int grsec_enable_blackhole;
98646+#endif
98647+
98648 struct udp_table udp_table __read_mostly;
98649 EXPORT_SYMBOL(udp_table);
98650
98651@@ -615,6 +620,9 @@ found:
98652 return s;
98653 }
98654
98655+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
98656+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
98657+
98658 /*
98659 * This routine is called by the ICMP module when it gets some
98660 * sort of error condition. If err < 0 then the socket should
98661@@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98662 dport = usin->sin_port;
98663 if (dport == 0)
98664 return -EINVAL;
98665+
98666+ err = gr_search_udp_sendmsg(sk, usin);
98667+ if (err)
98668+ return err;
98669 } else {
98670 if (sk->sk_state != TCP_ESTABLISHED)
98671 return -EDESTADDRREQ;
98672+
98673+ err = gr_search_udp_sendmsg(sk, NULL);
98674+ if (err)
98675+ return err;
98676+
98677 daddr = inet->inet_daddr;
98678 dport = inet->inet_dport;
98679 /* Open fast path for connected socket.
98680@@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
98681 IS_UDPLITE(sk));
98682 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98683 IS_UDPLITE(sk));
98684- atomic_inc(&sk->sk_drops);
98685+ atomic_inc_unchecked(&sk->sk_drops);
98686 __skb_unlink(skb, rcvq);
98687 __skb_queue_tail(&list_kill, skb);
98688 }
98689@@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
98690 int is_udplite = IS_UDPLITE(sk);
98691 bool slow;
98692
98693+ /*
98694+ * Check any passed addresses
98695+ */
98696+ if (addr_len)
98697+ *addr_len = sizeof(*sin);
98698+
98699 if (flags & MSG_ERRQUEUE)
98700 return ip_recv_error(sk, msg, len, addr_len);
98701
98702@@ -1243,6 +1266,10 @@ try_again:
98703 if (!skb)
98704 goto out;
98705
98706+ err = gr_search_udp_recvmsg(sk, skb);
98707+ if (err)
98708+ goto out_free;
98709+
98710 ulen = skb->len - sizeof(struct udphdr);
98711 copied = len;
98712 if (copied > ulen)
98713@@ -1276,7 +1303,7 @@ try_again:
98714 if (unlikely(err)) {
98715 trace_kfree_skb(skb, udp_recvmsg);
98716 if (!peeked) {
98717- atomic_inc(&sk->sk_drops);
98718+ atomic_inc_unchecked(&sk->sk_drops);
98719 UDP_INC_STATS_USER(sock_net(sk),
98720 UDP_MIB_INERRORS, is_udplite);
98721 }
98722@@ -1295,7 +1322,6 @@ try_again:
98723 sin->sin_port = udp_hdr(skb)->source;
98724 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98725 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
98726- *addr_len = sizeof(*sin);
98727 }
98728 if (inet->cmsg_flags)
98729 ip_cmsg_recv(msg, skb);
98730@@ -1566,7 +1592,7 @@ csum_error:
98731 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98732 drop:
98733 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98734- atomic_inc(&sk->sk_drops);
98735+ atomic_inc_unchecked(&sk->sk_drops);
98736 kfree_skb(skb);
98737 return -1;
98738 }
98739@@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98740 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98741
98742 if (!skb1) {
98743- atomic_inc(&sk->sk_drops);
98744+ atomic_inc_unchecked(&sk->sk_drops);
98745 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98746 IS_UDPLITE(sk));
98747 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98748@@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98749 goto csum_error;
98750
98751 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98752+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98753+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98754+#endif
98755 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
98756
98757 /*
98758@@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
98759 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
98760 0, sock_i_ino(sp),
98761 atomic_read(&sp->sk_refcnt), sp,
98762- atomic_read(&sp->sk_drops));
98763+ atomic_read_unchecked(&sp->sk_drops));
98764 }
98765
98766 int udp4_seq_show(struct seq_file *seq, void *v)
98767diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
98768index e1a6393..f634ce5 100644
98769--- a/net/ipv4/xfrm4_policy.c
98770+++ b/net/ipv4/xfrm4_policy.c
98771@@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
98772 fl4->flowi4_tos = iph->tos;
98773 }
98774
98775-static inline int xfrm4_garbage_collect(struct dst_ops *ops)
98776+static int xfrm4_garbage_collect(struct dst_ops *ops)
98777 {
98778 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
98779
98780- xfrm4_policy_afinfo.garbage_collect(net);
98781+ xfrm_garbage_collect_deferred(net);
98782 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
98783 }
98784
98785@@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
98786
98787 static int __net_init xfrm4_net_init(struct net *net)
98788 {
98789- struct ctl_table *table;
98790+ ctl_table_no_const *table = NULL;
98791 struct ctl_table_header *hdr;
98792
98793- table = xfrm4_policy_table;
98794 if (!net_eq(net, &init_net)) {
98795- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98796+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
98797 if (!table)
98798 goto err_alloc;
98799
98800 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
98801- }
98802-
98803- hdr = register_net_sysctl(net, "net/ipv4", table);
98804+ hdr = register_net_sysctl(net, "net/ipv4", table);
98805+ } else
98806+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
98807 if (!hdr)
98808 goto err_reg;
98809
98810@@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
98811 return 0;
98812
98813 err_reg:
98814- if (!net_eq(net, &init_net))
98815- kfree(table);
98816+ kfree(table);
98817 err_alloc:
98818 return -ENOMEM;
98819 }
98820diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
98821index 0e8ae69..0fc7350 100644
98822--- a/net/ipv6/addrconf.c
98823+++ b/net/ipv6/addrconf.c
98824@@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
98825 idx = 0;
98826 head = &net->dev_index_head[h];
98827 rcu_read_lock();
98828- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
98829+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
98830 net->dev_base_seq;
98831 hlist_for_each_entry_rcu(dev, head, index_hlist) {
98832 if (idx < s_idx)
98833@@ -2337,7 +2337,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
98834 p.iph.ihl = 5;
98835 p.iph.protocol = IPPROTO_IPV6;
98836 p.iph.ttl = 64;
98837- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
98838+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
98839
98840 if (ops->ndo_do_ioctl) {
98841 mm_segment_t oldfs = get_fs();
98842@@ -3967,7 +3967,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
98843 s_ip_idx = ip_idx = cb->args[2];
98844
98845 rcu_read_lock();
98846- cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98847+ cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
98848 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
98849 idx = 0;
98850 head = &net->dev_index_head[h];
98851@@ -4574,7 +4574,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
98852 dst_free(&ifp->rt->dst);
98853 break;
98854 }
98855- atomic_inc(&net->ipv6.dev_addr_genid);
98856+ atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
98857 rt_genid_bump_ipv6(net);
98858 }
98859
98860@@ -4595,7 +4595,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
98861 int *valp = ctl->data;
98862 int val = *valp;
98863 loff_t pos = *ppos;
98864- struct ctl_table lctl;
98865+ ctl_table_no_const lctl;
98866 int ret;
98867
98868 /*
98869@@ -4680,7 +4680,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
98870 int *valp = ctl->data;
98871 int val = *valp;
98872 loff_t pos = *ppos;
98873- struct ctl_table lctl;
98874+ ctl_table_no_const lctl;
98875 int ret;
98876
98877 /*
98878diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
98879index 4fbdb70..f6411f2 100644
98880--- a/net/ipv6/af_inet6.c
98881+++ b/net/ipv6/af_inet6.c
98882@@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
98883
98884 net->ipv6.sysctl.bindv6only = 0;
98885 net->ipv6.sysctl.icmpv6_time = 1*HZ;
98886- atomic_set(&net->ipv6.rt_genid, 0);
98887+ atomic_set_unchecked(&net->ipv6.rt_genid, 0);
98888
98889 err = ipv6_init_mibs(net);
98890 if (err)
98891diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
98892index 93b1aa3..e902855 100644
98893--- a/net/ipv6/datagram.c
98894+++ b/net/ipv6/datagram.c
98895@@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
98896 0,
98897 sock_i_ino(sp),
98898 atomic_read(&sp->sk_refcnt), sp,
98899- atomic_read(&sp->sk_drops));
98900+ atomic_read_unchecked(&sp->sk_drops));
98901 }
98902diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
98903index e2c9ff8..1e40285 100644
98904--- a/net/ipv6/icmp.c
98905+++ b/net/ipv6/icmp.c
98906@@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
98907
98908 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
98909 {
98910- struct ctl_table *table;
98911+ ctl_table_no_const *table;
98912
98913 table = kmemdup(ipv6_icmp_table_template,
98914 sizeof(ipv6_icmp_table_template),
98915diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
98916index 8acb286..840dd06 100644
98917--- a/net/ipv6/ip6_gre.c
98918+++ b/net/ipv6/ip6_gre.c
98919@@ -74,7 +74,7 @@ struct ip6gre_net {
98920 struct net_device *fb_tunnel_dev;
98921 };
98922
98923-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
98924+static struct rtnl_link_ops ip6gre_link_ops;
98925 static int ip6gre_tunnel_init(struct net_device *dev);
98926 static void ip6gre_tunnel_setup(struct net_device *dev);
98927 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
98928@@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
98929 }
98930
98931
98932-static struct inet6_protocol ip6gre_protocol __read_mostly = {
98933+static struct inet6_protocol ip6gre_protocol = {
98934 .handler = ip6gre_rcv,
98935 .err_handler = ip6gre_err,
98936 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
98937@@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
98938 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
98939 };
98940
98941-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98942+static struct rtnl_link_ops ip6gre_link_ops = {
98943 .kind = "ip6gre",
98944 .maxtype = IFLA_GRE_MAX,
98945 .policy = ip6gre_policy,
98946@@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
98947 .fill_info = ip6gre_fill_info,
98948 };
98949
98950-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
98951+static struct rtnl_link_ops ip6gre_tap_ops = {
98952 .kind = "ip6gretap",
98953 .maxtype = IFLA_GRE_MAX,
98954 .policy = ip6gre_policy,
98955diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
98956index 7881965..9cf62c4 100644
98957--- a/net/ipv6/ip6_tunnel.c
98958+++ b/net/ipv6/ip6_tunnel.c
98959@@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98960
98961 static int ip6_tnl_dev_init(struct net_device *dev);
98962 static void ip6_tnl_dev_setup(struct net_device *dev);
98963-static struct rtnl_link_ops ip6_link_ops __read_mostly;
98964+static struct rtnl_link_ops ip6_link_ops;
98965
98966 static int ip6_tnl_net_id __read_mostly;
98967 struct ip6_tnl_net {
98968@@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
98969 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
98970 };
98971
98972-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
98973+static struct rtnl_link_ops ip6_link_ops = {
98974 .kind = "ip6tnl",
98975 .maxtype = IFLA_IPTUN_MAX,
98976 .policy = ip6_tnl_policy,
98977diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
98978index 7b42d5e..1eff693 100644
98979--- a/net/ipv6/ip6_vti.c
98980+++ b/net/ipv6/ip6_vti.c
98981@@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
98982
98983 static int vti6_dev_init(struct net_device *dev);
98984 static void vti6_dev_setup(struct net_device *dev);
98985-static struct rtnl_link_ops vti6_link_ops __read_mostly;
98986+static struct rtnl_link_ops vti6_link_ops;
98987
98988 static int vti6_net_id __read_mostly;
98989 struct vti6_net {
98990@@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
98991 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
98992 };
98993
98994-static struct rtnl_link_ops vti6_link_ops __read_mostly = {
98995+static struct rtnl_link_ops vti6_link_ops = {
98996 .kind = "vti6",
98997 .maxtype = IFLA_VTI_MAX,
98998 .policy = vti6_policy,
98999diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
99000index 1c6ce31..299e566 100644
99001--- a/net/ipv6/ipv6_sockglue.c
99002+++ b/net/ipv6/ipv6_sockglue.c
99003@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
99004 if (sk->sk_type != SOCK_STREAM)
99005 return -ENOPROTOOPT;
99006
99007- msg.msg_control = optval;
99008+ msg.msg_control = (void __force_kernel *)optval;
99009 msg.msg_controllen = len;
99010 msg.msg_flags = flags;
99011
99012diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
99013index 710238f..0fd1816 100644
99014--- a/net/ipv6/netfilter/ip6_tables.c
99015+++ b/net/ipv6/netfilter/ip6_tables.c
99016@@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
99017 #endif
99018
99019 static int get_info(struct net *net, void __user *user,
99020- const int *len, int compat)
99021+ int len, int compat)
99022 {
99023 char name[XT_TABLE_MAXNAMELEN];
99024 struct xt_table *t;
99025 int ret;
99026
99027- if (*len != sizeof(struct ip6t_getinfo)) {
99028- duprintf("length %u != %zu\n", *len,
99029+ if (len != sizeof(struct ip6t_getinfo)) {
99030+ duprintf("length %u != %zu\n", len,
99031 sizeof(struct ip6t_getinfo));
99032 return -EINVAL;
99033 }
99034@@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
99035 info.size = private->size;
99036 strcpy(info.name, name);
99037
99038- if (copy_to_user(user, &info, *len) != 0)
99039+ if (copy_to_user(user, &info, len) != 0)
99040 ret = -EFAULT;
99041 else
99042 ret = 0;
99043@@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99044
99045 switch (cmd) {
99046 case IP6T_SO_GET_INFO:
99047- ret = get_info(sock_net(sk), user, len, 1);
99048+ ret = get_info(sock_net(sk), user, *len, 1);
99049 break;
99050 case IP6T_SO_GET_ENTRIES:
99051 ret = compat_get_entries(sock_net(sk), user, len);
99052@@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99053
99054 switch (cmd) {
99055 case IP6T_SO_GET_INFO:
99056- ret = get_info(sock_net(sk), user, len, 0);
99057+ ret = get_info(sock_net(sk), user, *len, 0);
99058 break;
99059
99060 case IP6T_SO_GET_ENTRIES:
99061diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
99062index 767ab8d..c5ec70a 100644
99063--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
99064+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
99065@@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
99066
99067 static int nf_ct_frag6_sysctl_register(struct net *net)
99068 {
99069- struct ctl_table *table;
99070+ ctl_table_no_const *table = NULL;
99071 struct ctl_table_header *hdr;
99072
99073- table = nf_ct_frag6_sysctl_table;
99074 if (!net_eq(net, &init_net)) {
99075- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
99076+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
99077 GFP_KERNEL);
99078 if (table == NULL)
99079 goto err_alloc;
99080@@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99081 table[0].data = &net->nf_frag.frags.timeout;
99082 table[1].data = &net->nf_frag.frags.low_thresh;
99083 table[2].data = &net->nf_frag.frags.high_thresh;
99084- }
99085-
99086- hdr = register_net_sysctl(net, "net/netfilter", table);
99087+ hdr = register_net_sysctl(net, "net/netfilter", table);
99088+ } else
99089+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
99090 if (hdr == NULL)
99091 goto err_reg;
99092
99093@@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
99094 return 0;
99095
99096 err_reg:
99097- if (!net_eq(net, &init_net))
99098- kfree(table);
99099+ kfree(table);
99100 err_alloc:
99101 return -ENOMEM;
99102 }
99103diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
99104index 827f795..7e28e82 100644
99105--- a/net/ipv6/output_core.c
99106+++ b/net/ipv6/output_core.c
99107@@ -9,8 +9,8 @@
99108
99109 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99110 {
99111- static atomic_t ipv6_fragmentation_id;
99112- int old, new;
99113+ static atomic_unchecked_t ipv6_fragmentation_id;
99114+ int id;
99115
99116 #if IS_ENABLED(CONFIG_IPV6)
99117 if (rt && !(rt->dst.flags & DST_NOPEER)) {
99118@@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
99119 }
99120 }
99121 #endif
99122- do {
99123- old = atomic_read(&ipv6_fragmentation_id);
99124- new = old + 1;
99125- if (!new)
99126- new = 1;
99127- } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
99128- fhdr->identification = htonl(new);
99129+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99130+ if (!id)
99131+ id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
99132+ fhdr->identification = htonl(id);
99133 }
99134 EXPORT_SYMBOL(ipv6_select_ident);
99135
99136diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
99137index 3a1f1f3..11d95bf 100644
99138--- a/net/ipv6/ping.c
99139+++ b/net/ipv6/ping.c
99140@@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
99141 };
99142 #endif
99143
99144+static struct pingv6_ops real_pingv6_ops = {
99145+ .ipv6_recv_error = ipv6_recv_error,
99146+ .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
99147+ .icmpv6_err_convert = icmpv6_err_convert,
99148+ .ipv6_icmp_error = ipv6_icmp_error,
99149+ .ipv6_chk_addr = ipv6_chk_addr,
99150+};
99151+
99152+static struct pingv6_ops dummy_pingv6_ops = {
99153+ .ipv6_recv_error = dummy_ipv6_recv_error,
99154+ .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
99155+ .icmpv6_err_convert = dummy_icmpv6_err_convert,
99156+ .ipv6_icmp_error = dummy_ipv6_icmp_error,
99157+ .ipv6_chk_addr = dummy_ipv6_chk_addr,
99158+};
99159+
99160 int __init pingv6_init(void)
99161 {
99162 #ifdef CONFIG_PROC_FS
99163@@ -253,11 +269,7 @@ int __init pingv6_init(void)
99164 if (ret)
99165 return ret;
99166 #endif
99167- pingv6_ops.ipv6_recv_error = ipv6_recv_error;
99168- pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
99169- pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
99170- pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
99171- pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
99172+ pingv6_ops = &real_pingv6_ops;
99173 return inet6_register_protosw(&pingv6_protosw);
99174 }
99175
99176@@ -266,11 +278,7 @@ int __init pingv6_init(void)
99177 */
99178 void pingv6_exit(void)
99179 {
99180- pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
99181- pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
99182- pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
99183- pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
99184- pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
99185+ pingv6_ops = &dummy_pingv6_ops;
99186 #ifdef CONFIG_PROC_FS
99187 unregister_pernet_subsys(&ping_v6_net_ops);
99188 #endif
99189diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
99190index b6bb87e..06cc9ed 100644
99191--- a/net/ipv6/raw.c
99192+++ b/net/ipv6/raw.c
99193@@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
99194 {
99195 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
99196 skb_checksum_complete(skb)) {
99197- atomic_inc(&sk->sk_drops);
99198+ atomic_inc_unchecked(&sk->sk_drops);
99199 kfree_skb(skb);
99200 return NET_RX_DROP;
99201 }
99202@@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99203 struct raw6_sock *rp = raw6_sk(sk);
99204
99205 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
99206- atomic_inc(&sk->sk_drops);
99207+ atomic_inc_unchecked(&sk->sk_drops);
99208 kfree_skb(skb);
99209 return NET_RX_DROP;
99210 }
99211@@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
99212
99213 if (inet->hdrincl) {
99214 if (skb_checksum_complete(skb)) {
99215- atomic_inc(&sk->sk_drops);
99216+ atomic_inc_unchecked(&sk->sk_drops);
99217 kfree_skb(skb);
99218 return NET_RX_DROP;
99219 }
99220@@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99221 if (flags & MSG_OOB)
99222 return -EOPNOTSUPP;
99223
99224+ if (addr_len)
99225+ *addr_len=sizeof(*sin6);
99226+
99227 if (flags & MSG_ERRQUEUE)
99228 return ipv6_recv_error(sk, msg, len, addr_len);
99229
99230@@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99231 sin6->sin6_flowinfo = 0;
99232 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
99233 IP6CB(skb)->iif);
99234- *addr_len = sizeof(*sin6);
99235 }
99236
99237 sock_recv_ts_and_drops(msg, sk, skb);
99238@@ -606,7 +608,7 @@ out:
99239 return err;
99240 }
99241
99242-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
99243+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
99244 struct flowi6 *fl6, struct dst_entry **dstp,
99245 unsigned int flags)
99246 {
99247@@ -918,12 +920,15 @@ do_confirm:
99248 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
99249 char __user *optval, int optlen)
99250 {
99251+ struct icmp6_filter filter;
99252+
99253 switch (optname) {
99254 case ICMPV6_FILTER:
99255 if (optlen > sizeof(struct icmp6_filter))
99256 optlen = sizeof(struct icmp6_filter);
99257- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
99258+ if (copy_from_user(&filter, optval, optlen))
99259 return -EFAULT;
99260+ raw6_sk(sk)->filter = filter;
99261 return 0;
99262 default:
99263 return -ENOPROTOOPT;
99264@@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99265 char __user *optval, int __user *optlen)
99266 {
99267 int len;
99268+ struct icmp6_filter filter;
99269
99270 switch (optname) {
99271 case ICMPV6_FILTER:
99272@@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
99273 len = sizeof(struct icmp6_filter);
99274 if (put_user(len, optlen))
99275 return -EFAULT;
99276- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
99277+ filter = raw6_sk(sk)->filter;
99278+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
99279 return -EFAULT;
99280 return 0;
99281 default:
99282diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
99283index cc85a9b..526a133 100644
99284--- a/net/ipv6/reassembly.c
99285+++ b/net/ipv6/reassembly.c
99286@@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
99287
99288 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99289 {
99290- struct ctl_table *table;
99291+ ctl_table_no_const *table = NULL;
99292 struct ctl_table_header *hdr;
99293
99294- table = ip6_frags_ns_ctl_table;
99295 if (!net_eq(net, &init_net)) {
99296- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99297+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
99298 if (table == NULL)
99299 goto err_alloc;
99300
99301@@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99302 /* Don't export sysctls to unprivileged users */
99303 if (net->user_ns != &init_user_ns)
99304 table[0].procname = NULL;
99305- }
99306+ hdr = register_net_sysctl(net, "net/ipv6", table);
99307+ } else
99308+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
99309
99310- hdr = register_net_sysctl(net, "net/ipv6", table);
99311 if (hdr == NULL)
99312 goto err_reg;
99313
99314@@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
99315 return 0;
99316
99317 err_reg:
99318- if (!net_eq(net, &init_net))
99319- kfree(table);
99320+ kfree(table);
99321 err_alloc:
99322 return -ENOMEM;
99323 }
99324diff --git a/net/ipv6/route.c b/net/ipv6/route.c
99325index 40b6e69..d346b14 100644
99326--- a/net/ipv6/route.c
99327+++ b/net/ipv6/route.c
99328@@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
99329
99330 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
99331 {
99332- struct ctl_table *table;
99333+ ctl_table_no_const *table;
99334
99335 table = kmemdup(ipv6_route_table_template,
99336 sizeof(ipv6_route_table_template),
99337diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
99338index d3005b3..b36df4a 100644
99339--- a/net/ipv6/sit.c
99340+++ b/net/ipv6/sit.c
99341@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
99342 static void ipip6_dev_free(struct net_device *dev);
99343 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
99344 __be32 *v4dst);
99345-static struct rtnl_link_ops sit_link_ops __read_mostly;
99346+static struct rtnl_link_ops sit_link_ops;
99347
99348 static int sit_net_id __read_mostly;
99349 struct sit_net {
99350@@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
99351 unregister_netdevice_queue(dev, head);
99352 }
99353
99354-static struct rtnl_link_ops sit_link_ops __read_mostly = {
99355+static struct rtnl_link_ops sit_link_ops = {
99356 .kind = "sit",
99357 .maxtype = IFLA_IPTUN_MAX,
99358 .policy = ipip6_policy,
99359diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
99360index 107b2f1..72741a9 100644
99361--- a/net/ipv6/sysctl_net_ipv6.c
99362+++ b/net/ipv6/sysctl_net_ipv6.c
99363@@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
99364
99365 static int __net_init ipv6_sysctl_net_init(struct net *net)
99366 {
99367- struct ctl_table *ipv6_table;
99368+ ctl_table_no_const *ipv6_table;
99369 struct ctl_table *ipv6_route_table;
99370 struct ctl_table *ipv6_icmp_table;
99371 int err;
99372diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
99373index f67033b..6f974fc 100644
99374--- a/net/ipv6/tcp_ipv6.c
99375+++ b/net/ipv6/tcp_ipv6.c
99376@@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
99377 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
99378 }
99379
99380+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99381+extern int grsec_enable_blackhole;
99382+#endif
99383+
99384 static void tcp_v6_hash(struct sock *sk)
99385 {
99386 if (sk->sk_state != TCP_CLOSE) {
99387@@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
99388 return 0;
99389
99390 reset:
99391+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99392+ if (!grsec_enable_blackhole)
99393+#endif
99394 tcp_v6_send_reset(sk, skb);
99395 discard:
99396 if (opt_skb)
99397@@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
99398 TCP_SKB_CB(skb)->sacked = 0;
99399
99400 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
99401- if (!sk)
99402+ if (!sk) {
99403+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99404+ ret = 1;
99405+#endif
99406 goto no_tcp_socket;
99407+ }
99408
99409 process:
99410- if (sk->sk_state == TCP_TIME_WAIT)
99411+ if (sk->sk_state == TCP_TIME_WAIT) {
99412+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99413+ ret = 2;
99414+#endif
99415 goto do_time_wait;
99416+ }
99417
99418 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
99419 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
99420@@ -1536,6 +1551,10 @@ csum_error:
99421 bad_packet:
99422 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
99423 } else {
99424+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99425+ if (!grsec_enable_blackhole || (ret == 1 &&
99426+ (skb->dev->flags & IFF_LOOPBACK)))
99427+#endif
99428 tcp_v6_send_reset(NULL, skb);
99429 }
99430
99431diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
99432index 089c741..cfee117 100644
99433--- a/net/ipv6/udp.c
99434+++ b/net/ipv6/udp.c
99435@@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
99436 udp_ipv6_hash_secret + net_hash_mix(net));
99437 }
99438
99439+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99440+extern int grsec_enable_blackhole;
99441+#endif
99442+
99443 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
99444 {
99445 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
99446@@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
99447 int is_udp4;
99448 bool slow;
99449
99450+ if (addr_len)
99451+ *addr_len = sizeof(struct sockaddr_in6);
99452+
99453 if (flags & MSG_ERRQUEUE)
99454 return ipv6_recv_error(sk, msg, len, addr_len);
99455
99456@@ -435,7 +442,7 @@ try_again:
99457 if (unlikely(err)) {
99458 trace_kfree_skb(skb, udpv6_recvmsg);
99459 if (!peeked) {
99460- atomic_inc(&sk->sk_drops);
99461+ atomic_inc_unchecked(&sk->sk_drops);
99462 if (is_udp4)
99463 UDP_INC_STATS_USER(sock_net(sk),
99464 UDP_MIB_INERRORS,
99465@@ -477,7 +484,7 @@ try_again:
99466 ipv6_iface_scope_id(&sin6->sin6_addr,
99467 IP6CB(skb)->iif);
99468 }
99469- *addr_len = sizeof(*sin6);
99470+
99471 }
99472 if (is_udp4) {
99473 if (inet->cmsg_flags)
99474@@ -685,7 +692,7 @@ csum_error:
99475 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
99476 drop:
99477 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
99478- atomic_inc(&sk->sk_drops);
99479+ atomic_inc_unchecked(&sk->sk_drops);
99480 kfree_skb(skb);
99481 return -1;
99482 }
99483@@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
99484 if (likely(skb1 == NULL))
99485 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
99486 if (!skb1) {
99487- atomic_inc(&sk->sk_drops);
99488+ atomic_inc_unchecked(&sk->sk_drops);
99489 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
99490 IS_UDPLITE(sk));
99491 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
99492@@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
99493 goto csum_error;
99494
99495 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
99496+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
99497+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
99498+#endif
99499 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
99500
99501 kfree_skb(skb);
99502diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
99503index 5f8e128..865d38e 100644
99504--- a/net/ipv6/xfrm6_policy.c
99505+++ b/net/ipv6/xfrm6_policy.c
99506@@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
99507 }
99508 }
99509
99510-static inline int xfrm6_garbage_collect(struct dst_ops *ops)
99511+static int xfrm6_garbage_collect(struct dst_ops *ops)
99512 {
99513 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
99514
99515- xfrm6_policy_afinfo.garbage_collect(net);
99516+ xfrm_garbage_collect_deferred(net);
99517 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
99518 }
99519
99520@@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
99521
99522 static int __net_init xfrm6_net_init(struct net *net)
99523 {
99524- struct ctl_table *table;
99525+ ctl_table_no_const *table = NULL;
99526 struct ctl_table_header *hdr;
99527
99528- table = xfrm6_policy_table;
99529 if (!net_eq(net, &init_net)) {
99530- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99531+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
99532 if (!table)
99533 goto err_alloc;
99534
99535 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
99536- }
99537+ hdr = register_net_sysctl(net, "net/ipv6", table);
99538+ } else
99539+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
99540
99541- hdr = register_net_sysctl(net, "net/ipv6", table);
99542 if (!hdr)
99543 goto err_reg;
99544
99545@@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
99546 return 0;
99547
99548 err_reg:
99549- if (!net_eq(net, &init_net))
99550- kfree(table);
99551+ kfree(table);
99552 err_alloc:
99553 return -ENOMEM;
99554 }
99555diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
99556index 41ac7938..75e3bb1 100644
99557--- a/net/irda/ircomm/ircomm_tty.c
99558+++ b/net/irda/ircomm/ircomm_tty.c
99559@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99560 add_wait_queue(&port->open_wait, &wait);
99561
99562 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
99563- __FILE__, __LINE__, tty->driver->name, port->count);
99564+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99565
99566 spin_lock_irqsave(&port->lock, flags);
99567 if (!tty_hung_up_p(filp))
99568- port->count--;
99569+ atomic_dec(&port->count);
99570 port->blocked_open++;
99571 spin_unlock_irqrestore(&port->lock, flags);
99572
99573@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99574 }
99575
99576 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
99577- __FILE__, __LINE__, tty->driver->name, port->count);
99578+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99579
99580 schedule();
99581 }
99582@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
99583
99584 spin_lock_irqsave(&port->lock, flags);
99585 if (!tty_hung_up_p(filp))
99586- port->count++;
99587+ atomic_inc(&port->count);
99588 port->blocked_open--;
99589 spin_unlock_irqrestore(&port->lock, flags);
99590
99591 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
99592- __FILE__, __LINE__, tty->driver->name, port->count);
99593+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
99594
99595 if (!retval)
99596 port->flags |= ASYNC_NORMAL_ACTIVE;
99597@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
99598
99599 /* ++ is not atomic, so this should be protected - Jean II */
99600 spin_lock_irqsave(&self->port.lock, flags);
99601- self->port.count++;
99602+ atomic_inc(&self->port.count);
99603 spin_unlock_irqrestore(&self->port.lock, flags);
99604 tty_port_tty_set(&self->port, tty);
99605
99606 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
99607- self->line, self->port.count);
99608+ self->line, atomic_read(&self->port.count));
99609
99610 /* Not really used by us, but lets do it anyway */
99611 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
99612@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
99613 tty_kref_put(port->tty);
99614 }
99615 port->tty = NULL;
99616- port->count = 0;
99617+ atomic_set(&port->count, 0);
99618 spin_unlock_irqrestore(&port->lock, flags);
99619
99620 wake_up_interruptible(&port->open_wait);
99621@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
99622 seq_putc(m, '\n');
99623
99624 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
99625- seq_printf(m, "Open count: %d\n", self->port.count);
99626+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
99627 seq_printf(m, "Max data size: %d\n", self->max_data_size);
99628 seq_printf(m, "Max header size: %d\n", self->max_header_size);
99629
99630diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
99631index c4b7218..3e83259 100644
99632--- a/net/iucv/af_iucv.c
99633+++ b/net/iucv/af_iucv.c
99634@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
99635
99636 write_lock_bh(&iucv_sk_list.lock);
99637
99638- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
99639+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99640 while (__iucv_get_sock_by_name(name)) {
99641 sprintf(name, "%08x",
99642- atomic_inc_return(&iucv_sk_list.autobind_name));
99643+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
99644 }
99645
99646 write_unlock_bh(&iucv_sk_list.lock);
99647diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
99648index cd5b8ec..f205e6b 100644
99649--- a/net/iucv/iucv.c
99650+++ b/net/iucv/iucv.c
99651@@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
99652 return NOTIFY_OK;
99653 }
99654
99655-static struct notifier_block __refdata iucv_cpu_notifier = {
99656+static struct notifier_block iucv_cpu_notifier = {
99657 .notifier_call = iucv_cpu_notify,
99658 };
99659
99660diff --git a/net/key/af_key.c b/net/key/af_key.c
99661index 545f047..9757a9d 100644
99662--- a/net/key/af_key.c
99663+++ b/net/key/af_key.c
99664@@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
99665 static u32 get_acqseq(void)
99666 {
99667 u32 res;
99668- static atomic_t acqseq;
99669+ static atomic_unchecked_t acqseq;
99670
99671 do {
99672- res = atomic_inc_return(&acqseq);
99673+ res = atomic_inc_return_unchecked(&acqseq);
99674 } while (!res);
99675 return res;
99676 }
99677diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
99678index da1a1ce..571db8d 100644
99679--- a/net/l2tp/l2tp_ip.c
99680+++ b/net/l2tp/l2tp_ip.c
99681@@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99682 if (flags & MSG_OOB)
99683 goto out;
99684
99685+ if (addr_len)
99686+ *addr_len = sizeof(*sin);
99687+
99688 skb = skb_recv_datagram(sk, flags, noblock, &err);
99689 if (!skb)
99690 goto out;
99691@@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
99692 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99693 sin->sin_port = 0;
99694 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99695- *addr_len = sizeof(*sin);
99696 }
99697 if (inet->cmsg_flags)
99698 ip_cmsg_recv(msg, skb);
99699diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
99700index b4b61b2..ac84a257 100644
99701--- a/net/mac80211/cfg.c
99702+++ b/net/mac80211/cfg.c
99703@@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
99704 ret = ieee80211_vif_use_channel(sdata, chandef,
99705 IEEE80211_CHANCTX_EXCLUSIVE);
99706 }
99707- } else if (local->open_count == local->monitors) {
99708+ } else if (local_read(&local->open_count) == local->monitors) {
99709 local->_oper_chandef = *chandef;
99710 ieee80211_hw_config(local, 0);
99711 }
99712@@ -3311,7 +3311,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
99713 else
99714 local->probe_req_reg--;
99715
99716- if (!local->open_count)
99717+ if (!local_read(&local->open_count))
99718 break;
99719
99720 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
99721@@ -3774,8 +3774,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
99722 if (chanctx_conf) {
99723 *chandef = chanctx_conf->def;
99724 ret = 0;
99725- } else if (local->open_count > 0 &&
99726- local->open_count == local->monitors &&
99727+ } else if (local_read(&local->open_count) > 0 &&
99728+ local_read(&local->open_count) == local->monitors &&
99729 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
99730 if (local->use_chanctx)
99731 *chandef = local->monitor_chandef;
99732diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
99733index 4aea4e7..9e698d1 100644
99734--- a/net/mac80211/ieee80211_i.h
99735+++ b/net/mac80211/ieee80211_i.h
99736@@ -28,6 +28,7 @@
99737 #include <net/ieee80211_radiotap.h>
99738 #include <net/cfg80211.h>
99739 #include <net/mac80211.h>
99740+#include <asm/local.h>
99741 #include "key.h"
99742 #include "sta_info.h"
99743 #include "debug.h"
99744@@ -961,7 +962,7 @@ struct ieee80211_local {
99745 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
99746 spinlock_t queue_stop_reason_lock;
99747
99748- int open_count;
99749+ local_t open_count;
99750 int monitors, cooked_mntrs;
99751 /* number of interfaces with corresponding FIF_ flags */
99752 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
99753diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
99754index a075791..1d0027f 100644
99755--- a/net/mac80211/iface.c
99756+++ b/net/mac80211/iface.c
99757@@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99758 break;
99759 }
99760
99761- if (local->open_count == 0) {
99762+ if (local_read(&local->open_count) == 0) {
99763 res = drv_start(local);
99764 if (res)
99765 goto err_del_bss;
99766@@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99767 res = drv_add_interface(local, sdata);
99768 if (res)
99769 goto err_stop;
99770- } else if (local->monitors == 0 && local->open_count == 0) {
99771+ } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
99772 res = ieee80211_add_virtual_monitor(local);
99773 if (res)
99774 goto err_stop;
99775@@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99776 atomic_inc(&local->iff_promiscs);
99777
99778 if (coming_up)
99779- local->open_count++;
99780+ local_inc(&local->open_count);
99781
99782 if (hw_reconf_flags)
99783 ieee80211_hw_config(local, hw_reconf_flags);
99784@@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
99785 err_del_interface:
99786 drv_remove_interface(local, sdata);
99787 err_stop:
99788- if (!local->open_count)
99789+ if (!local_read(&local->open_count))
99790 drv_stop(local);
99791 err_del_bss:
99792 sdata->bss = NULL;
99793@@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99794 }
99795
99796 if (going_down)
99797- local->open_count--;
99798+ local_dec(&local->open_count);
99799
99800 switch (sdata->vif.type) {
99801 case NL80211_IFTYPE_AP_VLAN:
99802@@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99803 }
99804 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
99805
99806- if (local->open_count == 0)
99807+ if (local_read(&local->open_count) == 0)
99808 ieee80211_clear_tx_pending(local);
99809
99810 /*
99811@@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99812
99813 ieee80211_recalc_ps(local, -1);
99814
99815- if (local->open_count == 0) {
99816+ if (local_read(&local->open_count) == 0) {
99817 ieee80211_stop_device(local);
99818
99819 /* no reconfiguring after stop! */
99820@@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
99821 ieee80211_configure_filter(local);
99822 ieee80211_hw_config(local, hw_reconf_flags);
99823
99824- if (local->monitors == local->open_count)
99825+ if (local->monitors == local_read(&local->open_count))
99826 ieee80211_add_virtual_monitor(local);
99827 }
99828
99829diff --git a/net/mac80211/main.c b/net/mac80211/main.c
99830index 7d1c3ac..b62dd29 100644
99831--- a/net/mac80211/main.c
99832+++ b/net/mac80211/main.c
99833@@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
99834 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
99835 IEEE80211_CONF_CHANGE_POWER);
99836
99837- if (changed && local->open_count) {
99838+ if (changed && local_read(&local->open_count)) {
99839 ret = drv_config(local, changed);
99840 /*
99841 * Goal:
99842diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
99843index 3401262..d5cd68d 100644
99844--- a/net/mac80211/pm.c
99845+++ b/net/mac80211/pm.c
99846@@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99847 struct ieee80211_sub_if_data *sdata;
99848 struct sta_info *sta;
99849
99850- if (!local->open_count)
99851+ if (!local_read(&local->open_count))
99852 goto suspend;
99853
99854 ieee80211_scan_cancel(local);
99855@@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99856 cancel_work_sync(&local->dynamic_ps_enable_work);
99857 del_timer_sync(&local->dynamic_ps_timer);
99858
99859- local->wowlan = wowlan && local->open_count;
99860+ local->wowlan = wowlan && local_read(&local->open_count);
99861 if (local->wowlan) {
99862 int err = drv_suspend(local, wowlan);
99863 if (err < 0) {
99864@@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
99865 WARN_ON(!list_empty(&local->chanctx_list));
99866
99867 /* stop hardware - this must stop RX */
99868- if (local->open_count)
99869+ if (local_read(&local->open_count))
99870 ieee80211_stop_device(local);
99871
99872 suspend:
99873diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
99874index 22b223f..ab70070 100644
99875--- a/net/mac80211/rate.c
99876+++ b/net/mac80211/rate.c
99877@@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
99878
99879 ASSERT_RTNL();
99880
99881- if (local->open_count)
99882+ if (local_read(&local->open_count))
99883 return -EBUSY;
99884
99885 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
99886diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
99887index 6ff1346..936ca9a 100644
99888--- a/net/mac80211/rc80211_pid_debugfs.c
99889+++ b/net/mac80211/rc80211_pid_debugfs.c
99890@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
99891
99892 spin_unlock_irqrestore(&events->lock, status);
99893
99894- if (copy_to_user(buf, pb, p))
99895+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
99896 return -EFAULT;
99897
99898 return p;
99899diff --git a/net/mac80211/util.c b/net/mac80211/util.c
99900index 9f9b9bd..d6fcf59 100644
99901--- a/net/mac80211/util.c
99902+++ b/net/mac80211/util.c
99903@@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99904 }
99905 #endif
99906 /* everything else happens only if HW was up & running */
99907- if (!local->open_count)
99908+ if (!local_read(&local->open_count))
99909 goto wake_up;
99910
99911 /*
99912@@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
99913 local->in_reconfig = false;
99914 barrier();
99915
99916- if (local->monitors == local->open_count && local->monitors > 0)
99917+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
99918 ieee80211_add_virtual_monitor(local);
99919
99920 /*
99921diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
99922index c3398cd..98ad3b4 100644
99923--- a/net/netfilter/Kconfig
99924+++ b/net/netfilter/Kconfig
99925@@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
99926
99927 To compile it as a module, choose M here. If unsure, say N.
99928
99929+config NETFILTER_XT_MATCH_GRADM
99930+ tristate '"gradm" match support'
99931+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
99932+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
99933+ ---help---
99934+ The gradm match allows to match on grsecurity RBAC being enabled.
99935+ It is useful when iptables rules are applied early on bootup to
99936+ prevent connections to the machine (except from a trusted host)
99937+ while the RBAC system is disabled.
99938+
99939 config NETFILTER_XT_MATCH_HASHLIMIT
99940 tristate '"hashlimit" match support'
99941 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
99942diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
99943index 394483b..ed51f2d 100644
99944--- a/net/netfilter/Makefile
99945+++ b/net/netfilter/Makefile
99946@@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
99947 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
99948 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
99949 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
99950+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
99951 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
99952 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
99953 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
99954diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
99955index bac7e01..1d7a31a 100644
99956--- a/net/netfilter/ipset/ip_set_core.c
99957+++ b/net/netfilter/ipset/ip_set_core.c
99958@@ -1950,7 +1950,7 @@ done:
99959 return ret;
99960 }
99961
99962-static struct nf_sockopt_ops so_set __read_mostly = {
99963+static struct nf_sockopt_ops so_set = {
99964 .pf = PF_INET,
99965 .get_optmin = SO_IP_SET,
99966 .get_optmax = SO_IP_SET + 1,
99967diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
99968index 4c8e5c0..5a79b4d 100644
99969--- a/net/netfilter/ipvs/ip_vs_conn.c
99970+++ b/net/netfilter/ipvs/ip_vs_conn.c
99971@@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
99972 /* Increase the refcnt counter of the dest */
99973 ip_vs_dest_hold(dest);
99974
99975- conn_flags = atomic_read(&dest->conn_flags);
99976+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
99977 if (cp->protocol != IPPROTO_UDP)
99978 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
99979 flags = cp->flags;
99980@@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
99981
99982 cp->control = NULL;
99983 atomic_set(&cp->n_control, 0);
99984- atomic_set(&cp->in_pkts, 0);
99985+ atomic_set_unchecked(&cp->in_pkts, 0);
99986
99987 cp->packet_xmit = NULL;
99988 cp->app = NULL;
99989@@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
99990
99991 /* Don't drop the entry if its number of incoming packets is not
99992 located in [0, 8] */
99993- i = atomic_read(&cp->in_pkts);
99994+ i = atomic_read_unchecked(&cp->in_pkts);
99995 if (i > 8 || i < 0) return 0;
99996
99997 if (!todrop_rate[i]) return 0;
99998diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
99999index 4f26ee4..6a9d7c3 100644
100000--- a/net/netfilter/ipvs/ip_vs_core.c
100001+++ b/net/netfilter/ipvs/ip_vs_core.c
100002@@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
100003 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
100004 /* do not touch skb anymore */
100005
100006- atomic_inc(&cp->in_pkts);
100007+ atomic_inc_unchecked(&cp->in_pkts);
100008 ip_vs_conn_put(cp);
100009 return ret;
100010 }
100011@@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
100012 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
100013 pkts = sysctl_sync_threshold(ipvs);
100014 else
100015- pkts = atomic_add_return(1, &cp->in_pkts);
100016+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100017
100018 if (ipvs->sync_state & IP_VS_STATE_MASTER)
100019 ip_vs_sync_conn(net, cp, pkts);
100020diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
100021index 35be035..50f8834 100644
100022--- a/net/netfilter/ipvs/ip_vs_ctl.c
100023+++ b/net/netfilter/ipvs/ip_vs_ctl.c
100024@@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
100025 */
100026 ip_vs_rs_hash(ipvs, dest);
100027 }
100028- atomic_set(&dest->conn_flags, conn_flags);
100029+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
100030
100031 /* bind the service */
100032 old_svc = rcu_dereference_protected(dest->svc, 1);
100033@@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
100034 * align with netns init in ip_vs_control_net_init()
100035 */
100036
100037-static struct ctl_table vs_vars[] = {
100038+static ctl_table_no_const vs_vars[] __read_only = {
100039 {
100040 .procname = "amemthresh",
100041 .maxlen = sizeof(int),
100042@@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100043 " %-7s %-6d %-10d %-10d\n",
100044 &dest->addr.in6,
100045 ntohs(dest->port),
100046- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100047+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100048 atomic_read(&dest->weight),
100049 atomic_read(&dest->activeconns),
100050 atomic_read(&dest->inactconns));
100051@@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
100052 "%-7s %-6d %-10d %-10d\n",
100053 ntohl(dest->addr.ip),
100054 ntohs(dest->port),
100055- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
100056+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
100057 atomic_read(&dest->weight),
100058 atomic_read(&dest->activeconns),
100059 atomic_read(&dest->inactconns));
100060@@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
100061
100062 entry.addr = dest->addr.ip;
100063 entry.port = dest->port;
100064- entry.conn_flags = atomic_read(&dest->conn_flags);
100065+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
100066 entry.weight = atomic_read(&dest->weight);
100067 entry.u_threshold = dest->u_threshold;
100068 entry.l_threshold = dest->l_threshold;
100069@@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
100070 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
100071 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
100072 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
100073- (atomic_read(&dest->conn_flags) &
100074+ (atomic_read_unchecked(&dest->conn_flags) &
100075 IP_VS_CONN_F_FWD_MASK)) ||
100076 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
100077 atomic_read(&dest->weight)) ||
100078@@ -3580,7 +3580,7 @@ out:
100079 }
100080
100081
100082-static const struct genl_ops ip_vs_genl_ops[] __read_mostly = {
100083+static const struct genl_ops ip_vs_genl_ops[] = {
100084 {
100085 .cmd = IPVS_CMD_NEW_SERVICE,
100086 .flags = GENL_ADMIN_PERM,
100087@@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
100088 {
100089 int idx;
100090 struct netns_ipvs *ipvs = net_ipvs(net);
100091- struct ctl_table *tbl;
100092+ ctl_table_no_const *tbl;
100093
100094 atomic_set(&ipvs->dropentry, 0);
100095 spin_lock_init(&ipvs->dropentry_lock);
100096diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
100097index ca056a3..9cf01ef 100644
100098--- a/net/netfilter/ipvs/ip_vs_lblc.c
100099+++ b/net/netfilter/ipvs/ip_vs_lblc.c
100100@@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
100101 * IPVS LBLC sysctl table
100102 */
100103 #ifdef CONFIG_SYSCTL
100104-static struct ctl_table vs_vars_table[] = {
100105+static ctl_table_no_const vs_vars_table[] __read_only = {
100106 {
100107 .procname = "lblc_expiration",
100108 .data = NULL,
100109diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
100110index 3f21a2f..a112e85 100644
100111--- a/net/netfilter/ipvs/ip_vs_lblcr.c
100112+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
100113@@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
100114 * IPVS LBLCR sysctl table
100115 */
100116
100117-static struct ctl_table vs_vars_table[] = {
100118+static ctl_table_no_const vs_vars_table[] __read_only = {
100119 {
100120 .procname = "lblcr_expiration",
100121 .data = NULL,
100122diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
100123index f63c238..1b87f8a 100644
100124--- a/net/netfilter/ipvs/ip_vs_sync.c
100125+++ b/net/netfilter/ipvs/ip_vs_sync.c
100126@@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
100127 cp = cp->control;
100128 if (cp) {
100129 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100130- pkts = atomic_add_return(1, &cp->in_pkts);
100131+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100132 else
100133 pkts = sysctl_sync_threshold(ipvs);
100134 ip_vs_sync_conn(net, cp->control, pkts);
100135@@ -771,7 +771,7 @@ control:
100136 if (!cp)
100137 return;
100138 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
100139- pkts = atomic_add_return(1, &cp->in_pkts);
100140+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
100141 else
100142 pkts = sysctl_sync_threshold(ipvs);
100143 goto sloop;
100144@@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
100145
100146 if (opt)
100147 memcpy(&cp->in_seq, opt, sizeof(*opt));
100148- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100149+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
100150 cp->state = state;
100151 cp->old_state = cp->state;
100152 /*
100153diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
100154index c47444e..b0961c6 100644
100155--- a/net/netfilter/ipvs/ip_vs_xmit.c
100156+++ b/net/netfilter/ipvs/ip_vs_xmit.c
100157@@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
100158 else
100159 rc = NF_ACCEPT;
100160 /* do not touch skb anymore */
100161- atomic_inc(&cp->in_pkts);
100162+ atomic_inc_unchecked(&cp->in_pkts);
100163 goto out;
100164 }
100165
100166@@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
100167 else
100168 rc = NF_ACCEPT;
100169 /* do not touch skb anymore */
100170- atomic_inc(&cp->in_pkts);
100171+ atomic_inc_unchecked(&cp->in_pkts);
100172 goto out;
100173 }
100174
100175diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
100176index a4b5e2a..13b1de3 100644
100177--- a/net/netfilter/nf_conntrack_acct.c
100178+++ b/net/netfilter/nf_conntrack_acct.c
100179@@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
100180 #ifdef CONFIG_SYSCTL
100181 static int nf_conntrack_acct_init_sysctl(struct net *net)
100182 {
100183- struct ctl_table *table;
100184+ ctl_table_no_const *table;
100185
100186 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
100187 GFP_KERNEL);
100188diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
100189index 43549eb..0bbeace 100644
100190--- a/net/netfilter/nf_conntrack_core.c
100191+++ b/net/netfilter/nf_conntrack_core.c
100192@@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
100193 #define DYING_NULLS_VAL ((1<<30)+1)
100194 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
100195
100196+#ifdef CONFIG_GRKERNSEC_HIDESYM
100197+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
100198+#endif
100199+
100200 int nf_conntrack_init_net(struct net *net)
100201 {
100202 int ret;
100203@@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
100204 goto err_stat;
100205 }
100206
100207+#ifdef CONFIG_GRKERNSEC_HIDESYM
100208+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
100209+#else
100210 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
100211+#endif
100212 if (!net->ct.slabname) {
100213 ret = -ENOMEM;
100214 goto err_slabname;
100215diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
100216index 1df1761..ce8b88a 100644
100217--- a/net/netfilter/nf_conntrack_ecache.c
100218+++ b/net/netfilter/nf_conntrack_ecache.c
100219@@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
100220 #ifdef CONFIG_SYSCTL
100221 static int nf_conntrack_event_init_sysctl(struct net *net)
100222 {
100223- struct ctl_table *table;
100224+ ctl_table_no_const *table;
100225
100226 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
100227 GFP_KERNEL);
100228diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
100229index 974a2a4..52cc6ff 100644
100230--- a/net/netfilter/nf_conntrack_helper.c
100231+++ b/net/netfilter/nf_conntrack_helper.c
100232@@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
100233
100234 static int nf_conntrack_helper_init_sysctl(struct net *net)
100235 {
100236- struct ctl_table *table;
100237+ ctl_table_no_const *table;
100238
100239 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
100240 GFP_KERNEL);
100241diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
100242index ce30041..3861b5d 100644
100243--- a/net/netfilter/nf_conntrack_proto.c
100244+++ b/net/netfilter/nf_conntrack_proto.c
100245@@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
100246
100247 static void
100248 nf_ct_unregister_sysctl(struct ctl_table_header **header,
100249- struct ctl_table **table,
100250+ ctl_table_no_const **table,
100251 unsigned int users)
100252 {
100253 if (users > 0)
100254diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
100255index 59359be..cb372f9 100644
100256--- a/net/netfilter/nf_conntrack_proto_dccp.c
100257+++ b/net/netfilter/nf_conntrack_proto_dccp.c
100258@@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
100259 out_invalid:
100260 if (LOG_INVALID(net, IPPROTO_DCCP))
100261 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
100262- NULL, msg);
100263+ NULL, "%s", msg);
100264 return false;
100265 }
100266
100267@@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
100268
100269 out_invalid:
100270 if (LOG_INVALID(net, IPPROTO_DCCP))
100271- nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
100272+ nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
100273 return -NF_ACCEPT;
100274 }
100275
100276diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
100277index f641751..d3c5b51 100644
100278--- a/net/netfilter/nf_conntrack_standalone.c
100279+++ b/net/netfilter/nf_conntrack_standalone.c
100280@@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
100281
100282 static int nf_conntrack_standalone_init_sysctl(struct net *net)
100283 {
100284- struct ctl_table *table;
100285+ ctl_table_no_const *table;
100286
100287 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
100288 GFP_KERNEL);
100289diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
100290index 7a394df..bd91a8a 100644
100291--- a/net/netfilter/nf_conntrack_timestamp.c
100292+++ b/net/netfilter/nf_conntrack_timestamp.c
100293@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
100294 #ifdef CONFIG_SYSCTL
100295 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
100296 {
100297- struct ctl_table *table;
100298+ ctl_table_no_const *table;
100299
100300 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
100301 GFP_KERNEL);
100302diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
100303index 85296d4..8becdec 100644
100304--- a/net/netfilter/nf_log.c
100305+++ b/net/netfilter/nf_log.c
100306@@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
100307
100308 #ifdef CONFIG_SYSCTL
100309 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
100310-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
100311+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
100312
100313 static int nf_log_proc_dostring(struct ctl_table *table, int write,
100314 void __user *buffer, size_t *lenp, loff_t *ppos)
100315@@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
100316 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
100317 mutex_unlock(&nf_log_mutex);
100318 } else {
100319+ ctl_table_no_const nf_log_table = *table;
100320+
100321 mutex_lock(&nf_log_mutex);
100322 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
100323 lockdep_is_held(&nf_log_mutex));
100324 if (!logger)
100325- table->data = "NONE";
100326+ nf_log_table.data = "NONE";
100327 else
100328- table->data = logger->name;
100329- r = proc_dostring(table, write, buffer, lenp, ppos);
100330+ nf_log_table.data = logger->name;
100331+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
100332 mutex_unlock(&nf_log_mutex);
100333 }
100334
100335diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
100336index f042ae5..30ea486 100644
100337--- a/net/netfilter/nf_sockopt.c
100338+++ b/net/netfilter/nf_sockopt.c
100339@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
100340 }
100341 }
100342
100343- list_add(&reg->list, &nf_sockopts);
100344+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
100345 out:
100346 mutex_unlock(&nf_sockopt_mutex);
100347 return ret;
100348@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
100349 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
100350 {
100351 mutex_lock(&nf_sockopt_mutex);
100352- list_del(&reg->list);
100353+ pax_list_del((struct list_head *)&reg->list);
100354 mutex_unlock(&nf_sockopt_mutex);
100355 }
100356 EXPORT_SYMBOL(nf_unregister_sockopt);
100357diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c
100358index 71a9f49..c09b60c 100644
100359--- a/net/netfilter/nf_tables_api.c
100360+++ b/net/netfilter/nf_tables_api.c
100361@@ -148,8 +148,8 @@ static int nf_tables_chain_type_lookup(const struct nft_af_info *afi,
100362 #ifdef CONFIG_MODULES
100363 if (type < 0 && autoload) {
100364 nfnl_unlock(NFNL_SUBSYS_NFTABLES);
100365- request_module("nft-chain-%u-%*.s", afi->family,
100366- nla_len(nla)-1, (const char *)nla_data(nla));
100367+ request_module("nft-chain-%u-%.*s", afi->family,
100368+ nla_len(nla), (const char *)nla_data(nla));
100369 nfnl_lock(NFNL_SUBSYS_NFTABLES);
100370 type = __nf_tables_chain_type_lookup(afi->family, nla);
100371 }
100372@@ -1916,7 +1916,8 @@ static const struct nft_set_ops *nft_select_set_ops(const struct nlattr * const
100373
100374 static const struct nla_policy nft_set_policy[NFTA_SET_MAX + 1] = {
100375 [NFTA_SET_TABLE] = { .type = NLA_STRING },
100376- [NFTA_SET_NAME] = { .type = NLA_STRING },
100377+ [NFTA_SET_NAME] = { .type = NLA_STRING,
100378+ .len = IFNAMSIZ - 1 },
100379 [NFTA_SET_FLAGS] = { .type = NLA_U32 },
100380 [NFTA_SET_KEY_TYPE] = { .type = NLA_U32 },
100381 [NFTA_SET_KEY_LEN] = { .type = NLA_U32 },
100382diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
100383index a155d19..726b0f2 100644
100384--- a/net/netfilter/nfnetlink_log.c
100385+++ b/net/netfilter/nfnetlink_log.c
100386@@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
100387 struct nfnl_log_net {
100388 spinlock_t instances_lock;
100389 struct hlist_head instance_table[INSTANCE_BUCKETS];
100390- atomic_t global_seq;
100391+ atomic_unchecked_t global_seq;
100392 };
100393
100394 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
100395@@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
100396 /* global sequence number */
100397 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
100398 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
100399- htonl(atomic_inc_return(&log->global_seq))))
100400+ htonl(atomic_inc_return_unchecked(&log->global_seq))))
100401 goto nla_put_failure;
100402
100403 if (data_len) {
100404diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
100405index da0c1f4..f79737a 100644
100406--- a/net/netfilter/nft_compat.c
100407+++ b/net/netfilter/nft_compat.c
100408@@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
100409 /* We want to reuse existing compat_to_user */
100410 old_fs = get_fs();
100411 set_fs(KERNEL_DS);
100412- t->compat_to_user(out, in);
100413+ t->compat_to_user((void __force_user *)out, in);
100414 set_fs(old_fs);
100415 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
100416 kfree(out);
100417@@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
100418 /* We want to reuse existing compat_to_user */
100419 old_fs = get_fs();
100420 set_fs(KERNEL_DS);
100421- m->compat_to_user(out, in);
100422+ m->compat_to_user((void __force_user *)out, in);
100423 set_fs(old_fs);
100424 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
100425 kfree(out);
100426diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
100427new file mode 100644
100428index 0000000..c566332
100429--- /dev/null
100430+++ b/net/netfilter/xt_gradm.c
100431@@ -0,0 +1,51 @@
100432+/*
100433+ * gradm match for netfilter
100434